当前位置:   article > 正文

RK3399 Android 7.1 新mipi副屏旋转_mipi屏翻转

mipi屏翻转

一、整体思路

手上的项目兼容了一款新mipi副屏,如果想了解,可以去看看

RK3399 Android 7.1 MIPI副屏兼容

兼容副屏后,已经能正常点亮,休眠唤醒也正常了,还剩一个问题:显示为竖屏,要改为横屏。

我参考了同事的做法,就是先在dev下创建一个设备文件/dev/dsi-panel-id,上层open该设备文件后通过ioctl方式访问kernel层,将kernel层的储存屏id的变量传递给上层。最后在上层判断屏id区别是新旧屏,如果是新屏,就旋转。

二、代码分析

1、kernel层

drivers/gpu/drm/panel/panel-simple.c

  1. diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
  2. index db392b8..01dba51 100644
  3. --- a/drivers/gpu/drm/panel/panel-simple.c
  4. +++ b/drivers/gpu/drm/panel/panel-simple.c
  5. @@ -40,6 +40,9 @@
  6. #include <linux/of_graph.h>
  7. #include <video/videomode.h>
  8. +static char panel_id; //储存读取dts的panel id
  9. +
  10. +
  11. struct cmd_ctrl_hdr {
  12. u8 dtype; /* data type */
  13. u8 wait; /* ms */
  14. @@ -2351,6 +2354,106 @@ static const struct of_device_id dsi_of_match[] = {
  15. };
  16. MODULE_DEVICE_TABLE(of, dsi_of_match);
  17. +/*---------------------------liyj ---------------------------------------------------------------------------*/
  18. +
  19. +static struct class *dsi_panel_class = NULL;
  20. +static struct device *dsi_panel_device = NULL;
  21. +static struct miscdevice dsi_pane_id_device;
  22. +#define NO_PANEL_ID 0XFF
  23. +#define DSI_PANEL_ID_MAGIC 0xFA
  24. +#define DSI_PANEL_ID_GET _IOR(DSI_PANEL_ID_MAGIC, 0x01, char) //自定义一个ioctl命令,用于上层与kernel层的交互
  25. +
  26. //下面会有一个函数在sys文件系统下创建/sys/class/panel/dsi-panel节点,在控制台下使用cat id会回调id_show函数
  27. +static ssize_t id_show(struct device *dev,
  28. + struct device_attribute *attr, char *buf)
  29. +{
  30. + return sprintf(buf, "%d",panel_id);
  31. +}
  32. +
  33. +static DEVICE_ATTR_RO(id);
  34. //在sys文件系统下创建/sys/class/panel/dsi-panel节点
  35. +static int telpo_create_panel_sysfs_dir(void)
  36. +{
  37. + printk("---liyj--- FILE : %s enter func : %s LINE : %d\n",__FILE__,__func__,__LINE__);
  38. + dsi_panel_class = class_create(THIS_MODULE, "panel");
  39. + if (IS_ERR(dsi_panel_class))
  40. + return PTR_ERR(dsi_panel_class);
  41. +
  42. + dsi_panel_device = device_create(dsi_panel_class, NULL, MKDEV(0, 0), NULL, "dsi-panel");
  43. + if (IS_ERR(dsi_panel_device)) {
  44. + class_destroy(dsi_panel_class);
  45. + return PTR_ERR(dsi_panel_device);
  46. + }
  47. +
  48. + return device_create_file(dsi_panel_device, &dev_attr_id);
  49. +}
  50. +static int dsi_panel_id_dev_open(struct inode *inode, struct file *filp)
  51. +{
  52. + return 0;
  53. +}
  54. +
  55. +
  56. //上层与kernel层交互的通道
  57. +static long dsi_panel_id_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  58. +{
  59. + switch (cmd) {
  60. + case DSI_PANEL_ID_GET:
  61. + printk("***liyj***copy_to_user start\n");
  62. + if(copy_to_user((void * __user)arg,&panel_id,sizeof(panel_id)))
  63. + {
  64. + printk("***liyj***copy_to_user failed\n");
  65. + }
  66. + break;
  67. + default:
  68. + printk("get dsi panel id err\n");
  69. + return -EINVAL;
  70. + }
  71. + return 0;
  72. +}
  73. +
  74. +static const struct file_operations dsi_panel_id_dev_fops =
  75. +{
  76. + .owner = THIS_MODULE,
  77. + .llseek = no_llseek,
  78. + .open = dsi_panel_id_dev_open,
  79. + .unlocked_ioctl = dsi_panel_id_dev_ioctl,
  80. + .compat_ioctl = dsi_panel_id_dev_ioctl,
  81. +};
  82. //在dev下创建一个设备节点,用于上层跟kernel层的交互
  83. +static int telpo_create_panel_misc_dev(void)
  84. +{
  85. + int ret;
  86. +
  87. + printk("---liyj--- FILE : %s enter func : %s LINE : %d\n",__FILE__,__func__,__LINE__);
  88. + dsi_pane_id_device.minor = MISC_DYNAMIC_MINOR;
  89. + dsi_pane_id_device.name = "dsi-panel-id";
  90. + dsi_pane_id_device.fops = &dsi_panel_id_dev_fops;
  91. +
  92. + ret = misc_register(&dsi_pane_id_device);
  93. + if (ret) {
  94. + pr_err("%s :dsi panel is misc register failed\n", __FILE__);
  95. + return -ENODEV;
  96. + }
  97. + return 0;
  98. +}
  99. +
  100. +
  101. +static char get_panel_id(struct device *dev)
  102. +{
  103. + char g_panel_id ;
  104. + int len;
  105. + int ret;
  106. + struct device_node *np = dev->of_node;
  107. + //g_panel_id = of_get_property(np,"id",&len);
  108. + of_property_read_u8(np,"id",&g_panel_id); //读取dts中panel节点的id
  109. + printk("---liyj--- g_panel_id = %x\n",g_panel_id);
  110. + return g_panel_id;
  111. +}
  112. +/*---------------------------liyj ---------------------------------------------------------------------------*/
  113. +
  114. static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
  115. {
  116. struct panel_simple *panel;
  117. @@ -2360,6 +2463,7 @@ static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
  118. int err;
  119. u32 val;
  120. +
  121. id = of_match_node(dsi_of_match, dsi->dev.of_node);
  122. if (!id)
  123. return -ENODEV;
  124. @@ -2390,6 +2494,14 @@ static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
  125. if (!of_property_read_u32(dsi->dev.of_node, "dsi,lanes", &val))
  126. dsi->lanes = val;
  127. +//liyj add start
  128. + panel_id = get_panel_id(&dsi->dev);
  129. + if (panel_id != NO_PANEL_ID) {
  130. + telpo_create_panel_sysfs_dir();
  131. + telpo_create_panel_misc_dev();
  132. + }
  133. +
  134. +//liyj add end
  135. return mipi_dsi_attach(dsi);
  136. }

dts中新屏节点的配置

  1. &dsi {
  2. status = "okay";
  3. rockchip,lane-rate = <528>;
  4. enable-gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
  5. panel@0 {
  6. compatible = "simple-panel-dsi";
  7. reg = <0>;
  8. ............
  9. ............
  10. num = <0>;
  11. id = [93]; //新屏的id
  12. id-reg = <0xda>; //要读取的id寄存器
  13. ............
  14. ............
  15. }
  16. ............
  17. }

2、上层

system/core/drmservice/drmservice.c

  1. diff --git a/system/core/drmservice/drmservice.c b/system/core/drmservice/drmservice.c
  2. index 4640716..61cd86d 100755
  3. --- a/system/core/drmservice/drmservice.c
  4. +++ b/system/core/drmservice/drmservice.c
  5. @@ -1074,6 +1074,59 @@ void copy_dir(const char *old_path,const char *new_path)
  6. }
  7. +#define DSI_PANEL_ID_MAGIC 0xFA
  8. +#define DSI_PANEL_ID_GET _IOR(DSI_PANEL_ID_MAGIC, 0x01,char)
  9. +#define DSI_PANEL_ID_DEV_PATH "/dev/dsi-panel-id"
  10. +#define NO_PANEL_ID 0xff
  11. +#define PANEL_OLD 0 //old panel
  12. +#define PANEL_NEW 147 //new panel 新屏id,我的新屏id是0x93,十进制就是147
  13. +static void get_dsi_panel_id(void)
  14. +{
  15. + int fd = -1;
  16. + char id = NO_PANEL_ID;
  17. + int ret;
  18. + char model_value[PROPERTY_VALUE_MAX] = {0};
  19. + property_get("ro.internal.model", model_value, "");
  20. +
  21. + fd = open(DSI_PANEL_ID_DEV_PATH, O_RDONLY); //1、打开设备文件
  22. + if (fd > 0) {
  23. + SLOGE("---liyj--- fd > 0");
  24. + ret = ioctl(fd, DSI_PANEL_ID_GET, &id); //2、通过自定义的cmd跟kernel交互,获取panel id
  25. + if(ret <0)
  26. + {
  27. + SLOGE("---liyj--- ioctl failed\n");
  28. + }
  29. + SLOGE("---liyj--- id = %d\n",id);
  30. + close(fd);
  31. + }
  32. + if (id == NO_PANEL_ID)
  33. + return;
  34. +
  35. + if (!(strcmp(model_value, "TPS680C"))) {
  36. + ALOGE("set TPS680C panel");
  37. + switch (id) {
  38. + case PANEL_OLD:
  39. + ALOGE("set panel as PANEL_OLD");
  40. + property_set("persist.sys.rotation.efull-1", "true");
  41. + property_set("persist.sys.rotation.einit", "0");
  42. + break;
  43. + case PANEL_NEW: //新屏
  44. + ALOGE("set panel as PANEL_NEW");
  45. + property_set("persist.sys.rotation.efull-1", "false");
  46. + property_set("persist.sys.rotation.einit", "3"); //旋转270度
  47. + break;
  48. + default:
  49. + SLOGD("not support panel id, set PANEL_NEW as default");
  50. + property_set("persist.sys.rotation.efull-1", "false");
  51. + property_set("persist.sys.rotation.einit", "3");
  52. + break;
  53. + }
  54. + } else {
  55. + ALOGE("no model panel set");
  56. + }
  57. +}
  58. +
  59. /** * Program entry pointer */
  60. @@ -1091,6 +1144,8 @@ int main( int argc, char *argv[] )
  61. SLOGE("get prop_board_platform,prop_board_platform = %s , diff=%d",prop_board_platform,
  62. strcmp(prop_board_platform,"rk3399"));
  63. + get_dsi_panel_id(); //函数调用,获取panel id
  64. +
  65. //get hid data
  66. rknand_sys_storage_test_hid();
  67. SLOGE("Get HID data:%s", hid_buf_idb);

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号