Bez tytułu

z Fiery Tapir, 9 miesiące temu, napisane w C, wyświetlone 86 razy. [paste_expire] 1 miesiąc.
URL https://pastebin.k4be.pl/view/0ceb94fe Udostępnij
Pobierz wklejkę lub Pokaż surowy tekst
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3.  * Copyright (C) 2021, SONEL - based on Somlabs driver
  4.  */
  5.  
  6. #include <linux/backlight.h>
  7. #include <linux/delay.h>
  8. #include <linux/device.h>
  9. #include <linux/err.h>
  10. #include <linux/errno.h>
  11. #include <linux/fb.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14.  
  15. #include <linux/gpio/consumer.h>
  16. #include <linux/regulator/consumer.h>
  17.  
  18. #include <drm/drm_mipi_dsi.h>
  19. #include <drm/drm_modes.h>
  20. #include <drm/drm_panel.h>
  21.  
  22. #include <video/mipi_display.h>
  23.  
  24. #include <video/of_videomode.h>
  25. #include <video/videomode.h>
  26.  
  27. #include <drm/drm_print.h>
  28. #include <drm/drm_crtc.h>
  29. #include <drm/drm_mipi_dsi.h>
  30. #include <linux/of.h>
  31.  
  32. #include <linux/of_platform.h>
  33. #include <linux/platform_device.h>
  34.  
  35. static const u32 ph720128t003_bus_formats[] = {
  36.         MEDIA_BUS_FMT_RGB888_1X24,
  37.         MEDIA_BUS_FMT_RGB666_1X18,
  38.         MEDIA_BUS_FMT_RGB565_1X16,
  39. };
  40.  
  41. struct ph720128t003 {
  42.         struct drm_panel        panel;
  43.         struct mipi_dsi_device  *dsi;
  44.  
  45.         struct gpio_desc        *reset;
  46.         struct backlight_device *backlight;
  47.  
  48.         struct regulator        *power;
  49.  
  50.         bool prepared;
  51.         bool enabled;
  52.  
  53.         struct videomode vm;
  54.         u32 width_mm;
  55.         u32 height_mm;
  56. };
  57.  
  58. struct ph720128t003_instr {
  59.         u8 cmd;
  60.         u8 data;
  61. };
  62.  
  63. #define CMD_INSTR(CMD, DATA)     {.cmd = CMD, .data = DATA}
  64.  
  65.  
  66. static const struct ph720128t003_instr ph720128t003_init_data[] = {
  67.         CMD_INSTR(0xFF, 0x03),
  68.         CMD_INSTR(0x01, 0x00),
  69.         CMD_INSTR(0x02, 0x00),
  70.         CMD_INSTR(0x03, 0x73),
  71.         CMD_INSTR(0x04, 0x73),
  72.         CMD_INSTR(0x05, 0x00),
  73.         CMD_INSTR(0x06, 0x06),
  74.         CMD_INSTR(0x07, 0x02),
  75.         CMD_INSTR(0x08, 0x00),
  76.         CMD_INSTR(0x09, 0x01),
  77.         CMD_INSTR(0x0A, 0x01),
  78.         CMD_INSTR(0x0B, 0x01),
  79.         CMD_INSTR(0x0C, 0x01),
  80.         CMD_INSTR(0x0D, 0x01),
  81.         CMD_INSTR(0x0E, 0x01),
  82.         CMD_INSTR(0x0F, 0x35),
  83.         CMD_INSTR(0x10, 0x35),
  84.         CMD_INSTR(0x11, 0x00),
  85.         CMD_INSTR(0x12, 0x00),
  86.         CMD_INSTR(0x13, 0x01),
  87.         CMD_INSTR(0x14, 0x00),
  88.         CMD_INSTR(0x15, 0x00),
  89.         CMD_INSTR(0x16, 0x00),
  90.         CMD_INSTR(0x17, 0x00),
  91.         CMD_INSTR(0x18, 0x00),
  92.         CMD_INSTR(0x19, 0x00),
  93.         CMD_INSTR(0x1A, 0x00),
  94.         CMD_INSTR(0x1B, 0x00),
  95.         CMD_INSTR(0x1C, 0x00),
  96.         CMD_INSTR(0x1D, 0x00),
  97.         CMD_INSTR(0x1E, 0xC0),
  98.         CMD_INSTR(0x1F, 0x80),
  99.         CMD_INSTR(0x20, 0x03),
  100.         CMD_INSTR(0x21, 0x04),
  101.         CMD_INSTR(0x22, 0x00),
  102.         CMD_INSTR(0x23, 0x00),
  103.         CMD_INSTR(0x24, 0x00),
  104.         CMD_INSTR(0x25, 0x00),
  105.         CMD_INSTR(0x26, 0x00),
  106.         CMD_INSTR(0x27, 0x00),
  107.         CMD_INSTR(0x28, 0x33),
  108.         CMD_INSTR(0x29, 0x02),
  109.         CMD_INSTR(0x2A, 0x00),
  110.         CMD_INSTR(0x2B, 0x00),
  111.         CMD_INSTR(0x2C, 0x00),
  112.         CMD_INSTR(0x2D, 0x00),
  113.         CMD_INSTR(0x2E, 0x00),
  114.         CMD_INSTR(0x2F, 0x00),
  115.         CMD_INSTR(0x30, 0x00),
  116.         CMD_INSTR(0x31, 0x00),
  117.         CMD_INSTR(0x32, 0x00),
  118.         CMD_INSTR(0x33, 0x00),
  119.         CMD_INSTR(0x34, 0x03),
  120.         CMD_INSTR(0x35, 0x00),
  121.         CMD_INSTR(0x36, 0x03),
  122.         CMD_INSTR(0x37, 0x00),
  123.         CMD_INSTR(0x38, 0x00),
  124.         CMD_INSTR(0x39, 0x00),
  125.         CMD_INSTR(0x3A, 0x00),
  126.         CMD_INSTR(0x3B, 0x00),
  127.         CMD_INSTR(0x3C, 0x00),
  128.         CMD_INSTR(0x3D, 0x00),
  129.         CMD_INSTR(0x3E, 0x00),
  130.         CMD_INSTR(0x3F, 0x00),
  131.         CMD_INSTR(0x40, 0x00),
  132.         CMD_INSTR(0x41, 0x00),
  133.         CMD_INSTR(0x42, 0x00),
  134.         CMD_INSTR(0x43, 0x00),
  135.         CMD_INSTR(0x44, 0x00),
  136.         CMD_INSTR(0x50, 0x01),
  137.         CMD_INSTR(0x51, 0x23),
  138.         CMD_INSTR(0x52, 0x45),
  139.         CMD_INSTR(0x53, 0x67),
  140.         CMD_INSTR(0x54, 0x89),
  141.         CMD_INSTR(0x55, 0xAB),
  142.         CMD_INSTR(0x56, 0x01),
  143.         CMD_INSTR(0x57, 0x23),
  144.         CMD_INSTR(0x58, 0x45),
  145.         CMD_INSTR(0x59, 0x67),
  146.         CMD_INSTR(0x5A, 0x89),
  147.         CMD_INSTR(0x5B, 0xAB),
  148.         CMD_INSTR(0x5C, 0xCD),
  149.         CMD_INSTR(0x5D, 0xEF),
  150.         CMD_INSTR(0x5E, 0x10),
  151.         CMD_INSTR(0x5F, 0x09),
  152.         CMD_INSTR(0x60, 0x08),
  153.         CMD_INSTR(0x61, 0x0F),
  154.         CMD_INSTR(0x62, 0x0E),
  155.         CMD_INSTR(0x63, 0x0D),
  156.         CMD_INSTR(0x64, 0x0C),
  157.         CMD_INSTR(0x65, 0x02),
  158.         CMD_INSTR(0x66, 0x02),
  159.         CMD_INSTR(0x67, 0x02),
  160.         CMD_INSTR(0x68, 0x02),
  161.         CMD_INSTR(0x69, 0x02),
  162.         CMD_INSTR(0x6A, 0x02),
  163.         CMD_INSTR(0x6B, 0x02),
  164.         CMD_INSTR(0x6C, 0x02),
  165.         CMD_INSTR(0x6D, 0x02),
  166.         CMD_INSTR(0x6E, 0x02),
  167.         CMD_INSTR(0x6F, 0x02),
  168.         CMD_INSTR(0x70, 0x02),
  169.         CMD_INSTR(0x71, 0x06),
  170.         CMD_INSTR(0x72, 0x07),
  171.         CMD_INSTR(0x73, 0x02),
  172.         CMD_INSTR(0x74, 0x02),
  173.         CMD_INSTR(0x75, 0x06),
  174.         CMD_INSTR(0x76, 0x07),
  175.         CMD_INSTR(0x77, 0x0E),
  176.         CMD_INSTR(0x78, 0x0F),
  177.         CMD_INSTR(0x79, 0x0C),
  178.         CMD_INSTR(0x7A, 0x0D),
  179.         CMD_INSTR(0x7B, 0x02),
  180.         CMD_INSTR(0x7C, 0x02),
  181.         CMD_INSTR(0x7D, 0x02),
  182.         CMD_INSTR(0x7E, 0x02),
  183.         CMD_INSTR(0x7F, 0x02),
  184.         CMD_INSTR(0x80, 0x02),
  185.         CMD_INSTR(0x81, 0x02),
  186.         CMD_INSTR(0x82, 0x02),
  187.         CMD_INSTR(0x83, 0x02),
  188.         CMD_INSTR(0x84, 0x02),
  189.         CMD_INSTR(0x85, 0x02),
  190.         CMD_INSTR(0x86, 0x02),
  191.         CMD_INSTR(0x87, 0x09),
  192.         CMD_INSTR(0x88, 0x08),
  193.         CMD_INSTR(0x89, 0x02),
  194.         CMD_INSTR(0x8A, 0x02),
  195.         CMD_INSTR(0xFF, 0x04),
  196.         CMD_INSTR(0x6C, 0x15),
  197.         CMD_INSTR(0x6E, 0x2A),
  198.         CMD_INSTR(0x6F, 0x57),
  199.         CMD_INSTR(0x3A, 0xA4),
  200.         CMD_INSTR(0x8D, 0x1A),
  201.         CMD_INSTR(0x87, 0xBA),
  202.         CMD_INSTR(0x26, 0x76),
  203.         CMD_INSTR(0xB2, 0xD1),
  204.         CMD_INSTR(0xFF, 0x01),
  205.         CMD_INSTR(0x22, 0x0A),
  206.         CMD_INSTR(0x31, 0x00),
  207.         CMD_INSTR(0x53, 0x35),
  208.         CMD_INSTR(0x55, 0x50),
  209.         CMD_INSTR(0x50, 0xAF),
  210.         CMD_INSTR(0x51, 0xAF),
  211.         CMD_INSTR(0x60, 0x14),
  212.         CMD_INSTR(0xA0, 0x08),
  213.         CMD_INSTR(0xA1, 0x1D),
  214.         CMD_INSTR(0xA2, 0x2C),
  215.         CMD_INSTR(0xA3, 0x14),
  216.         CMD_INSTR(0xA4, 0x19),
  217.         CMD_INSTR(0xA5, 0x2E),
  218.         CMD_INSTR(0xA6, 0x22),
  219.         CMD_INSTR(0xA7, 0x23),
  220.         CMD_INSTR(0xA8, 0x97),
  221.         CMD_INSTR(0xA9, 0x1E),
  222.         CMD_INSTR(0xAA, 0x29),
  223.         CMD_INSTR(0xAB, 0x7B),
  224.         CMD_INSTR(0xAC, 0x18),
  225.         CMD_INSTR(0xAD, 0x17),
  226.         CMD_INSTR(0xAE, 0x4B),
  227.         CMD_INSTR(0xAF, 0x1F),
  228.         CMD_INSTR(0xB0, 0x27),
  229.         CMD_INSTR(0xB1, 0x52),
  230.         CMD_INSTR(0xB2, 0x63),
  231.         CMD_INSTR(0xB3, 0x39),
  232.         CMD_INSTR(0xC0, 0x08),
  233.         CMD_INSTR(0xC1, 0x1D),
  234.         CMD_INSTR(0xC2, 0x2C),
  235.         CMD_INSTR(0xC3, 0x14),
  236.         CMD_INSTR(0xC4, 0x19),
  237.         CMD_INSTR(0xC5, 0x2E),
  238.         CMD_INSTR(0xC6, 0x22),
  239.         CMD_INSTR(0xC7, 0x23),
  240.         CMD_INSTR(0xC8, 0x97),
  241.         CMD_INSTR(0xC9, 0x1E),
  242.         CMD_INSTR(0xCA, 0x29),
  243.         CMD_INSTR(0xCB, 0x7B),
  244.         CMD_INSTR(0xCC, 0x18),
  245.         CMD_INSTR(0xCD, 0x17),
  246.         CMD_INSTR(0xCE, 0x4B),
  247.         CMD_INSTR(0xCF, 0x1F),
  248.         CMD_INSTR(0xD0, 0x27),
  249.         CMD_INSTR(0xD1, 0x52),
  250.         CMD_INSTR(0xD2, 0x63),
  251.         CMD_INSTR(0xD3, 0x39),
  252.         CMD_INSTR(0xFF, 0x00),
  253. };
  254.  
  255. static inline struct ph720128t003 *panel_to_ph720128t003(struct drm_panel *panel)
  256. {
  257.         return container_of(panel, struct ph720128t003, panel);
  258. }
  259.  
  260. /*
  261.  * The panel seems to accept some private DCS commands that map
  262.  * directly to registers.
  263.  *
  264.  * It is organised by page, with each page having its own set of
  265.  * registers, and the first page looks like it's holding the standard
  266.  * DCS commands.
  267.  *
  268.  * So before any attempt at sending a command or data, we have to be
  269.  * sure if we're in the right page or not.
  270.  */
  271. static int ph720128t003_switch_page(struct mipi_dsi_device *dsi, u8 page)
  272. {
  273.         u8 buf[4] = { 0xff, 0x98, 0x81, page };
  274.  
  275.         return mipi_dsi_dcs_write_buffer(dsi, buf, sizeof(buf));
  276. }
  277.  
  278. static int ph720128t003_send_cmd_data(struct mipi_dsi_device *dsi, u8 cmd, u8 data)
  279. {
  280.         u8 buf[2] = { cmd, data };
  281.         return mipi_dsi_dcs_write_buffer(dsi, buf, sizeof(buf));
  282. }
  283.  
  284. static int ph720128t003_init(struct mipi_dsi_device *dsi)
  285. {
  286.         size_t i;
  287.         int ret = 0;
  288.         for (i = 0; i < ARRAY_SIZE(ph720128t003_init_data); i++) {
  289.                 const struct ph720128t003_instr *instr = &ph720128t003_init_data[i];
  290.  
  291.                 if (instr->cmd == 0xFF) {
  292.                         printk(KERN_ERR "switch_page, cmd: %02X\n", instr->cmd);
  293.                         ret = ph720128t003_switch_page(dsi, instr->data);
  294.                 } else {
  295.                         printk(KERN_ERR "send_cmd, cmd: %02X\n", instr->cmd);
  296.                         ret = ph720128t003_send_cmd_data(dsi, instr->cmd,
  297.                                                       instr->data);
  298.                 }
  299.                 if (ret < 0) {
  300.                         dev_err(&dsi->dev, "Error when setting device @ %lu (cmd: %08X)\n", i, instr->cmd);
  301.                         return ret;
  302.                 }
  303.         }
  304.         if(ret > 0) {
  305.                 ret = 0;
  306.         }
  307.         return ret;
  308. }
  309.  
  310. static int ph720128t003_prepare(struct drm_panel *panel)
  311. {
  312.         struct ph720128t003 *ctx = panel_to_ph720128t003(panel);
  313.  
  314.         if (ctx->reset) {
  315.  
  316.                 gpiod_set_value(ctx->reset, 0);
  317.                 usleep_range(20000, 25000);
  318.  
  319.                 gpiod_set_value(ctx->reset, 1);
  320.                 usleep_range(20000, 25000);
  321.         }
  322.  
  323.         ctx->prepared = true;
  324.  
  325.         return 0;
  326. }
  327.  
  328. static int ph720128t003_unprepare(struct drm_panel *panel)
  329. {
  330.         struct ph720128t003 *ctx = panel_to_ph720128t003(panel);
  331.                 struct device *dev = &ctx->dsi->dev;
  332.  
  333.         if (!ctx->prepared)
  334.                 return 0;
  335.  
  336.         if (ctx->enabled) {
  337.                 DRM_DEV_ERROR(dev, "Panel still enabled!\n");
  338.                 return -EPERM;
  339.         }
  340.  
  341.         if (ctx->reset != NULL) {
  342.                 gpiod_set_value(ctx->reset, 1);
  343.                 usleep_range(15000, 17000);
  344.                 gpiod_set_value(ctx->reset, 0);
  345.         }
  346.  
  347.         ctx->prepared = false;
  348.         return 0;
  349. }
  350.  
  351. static int ph720128t003_enable(struct drm_panel *panel)
  352. {
  353.         struct ph720128t003 *ctx = panel_to_ph720128t003(panel);
  354.         struct mipi_dsi_device *dsi = ctx->dsi;
  355.         struct device *dev = &dsi->dev;
  356.         u16 brightness;
  357.         int ret;
  358.         u8 buf[2] = {0};
  359.  
  360.         if (ctx->enabled)
  361.                 return 0;
  362.  
  363.         if (!ctx->prepared) {
  364.                 DRM_DEV_ERROR(dev, "Panel not prepared!\n");
  365.                 return -EPERM;
  366.         }
  367.  
  368.         dsi->mode_flags |= MIPI_DSI_MODE_LPM;   //?????
  369.  
  370.         ph720128t003_init(dsi);
  371.  
  372.         usleep_range(15000, 17000);
  373.  
  374.  
  375.         ret = ph720128t003_switch_page(dsi, 0);
  376.         if (ret) {
  377.                 DRM_DEV_ERROR(dev, "Error entering command mode");
  378.                 goto fail;
  379.         }
  380.         buf[0] = MIPI_DCS_EXIT_SLEEP_MODE;
  381.         buf[1] = 0;
  382.         ret = mipi_dsi_dcs_write_buffer(dsi, buf, 2);
  383.         if (ret) {
  384.                 DRM_DEV_ERROR(dev, "Error sending exit sleep cmd");
  385.                 goto fail;
  386.         }
  387.         mdelay(120);
  388.         buf[0] = MIPI_DCS_SET_DISPLAY_ON;
  389.         ret = mipi_dsi_dcs_write_buffer(dsi, buf, 2);
  390.         if (ret) {
  391.                 DRM_DEV_ERROR(dev, "Error sending display on cmd");
  392.                 goto fail;
  393.         }
  394.  
  395.         // /* Exit sleep mode */
  396.         // ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
  397.         // if (ret < 0) {
  398.         //      DRM_DEV_ERROR(dev, "Failed to exit sleep mode (%d)\n", ret);
  399.         //      goto fail;
  400.         // }
  401.  
  402.         // usleep_range(5000, 10000);
  403.  
  404.         // ret = mipi_dsi_dcs_set_display_on(dsi);
  405.         // if (ret < 0) {
  406.         //      DRM_DEV_ERROR(dev, "Failed to set display ON (%d)\n", ret);
  407.         //      goto fail;
  408.         // }
  409.  
  410.         backlight_enable(ctx->backlight);
  411.  
  412.         ctx->enabled = true;
  413.         dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
  414.  
  415.         return 0;
  416. fail:
  417.         //if (ctx->reset != NULL)
  418.         //      gpiod_set_value(ctx->reset, 0);
  419.  
  420.         return ret;
  421. }
  422.  
  423. static int ph720128t003_disable(struct drm_panel *panel)
  424. {
  425.         struct ph720128t003 *ctx = panel_to_ph720128t003(panel);
  426.         struct mipi_dsi_device *dsi = ctx->dsi;
  427.         struct device *dev = &dsi->dev;
  428.         int ret;
  429.  
  430.         if (!ctx->enabled)
  431.                 return 0;
  432.  
  433.         dsi->mode_flags |= MIPI_DSI_MODE_LPM;
  434.  
  435.         backlight_disable(ctx->backlight);
  436.  
  437.         usleep_range(10000, 15000);
  438.  
  439.         ret = mipi_dsi_dcs_set_display_off(dsi);
  440.         if (ret < 0) {
  441.                 DRM_DEV_ERROR(dev, "Failed to set display OFF (%d)\n", ret);
  442.                 //return ret;
  443.         }
  444.  
  445.         usleep_range(5000, 10000);
  446.  
  447.         ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
  448.         if (ret < 0) {
  449.                 DRM_DEV_ERROR(dev, "Failed to enter sleep mode (%d)\n", ret);
  450.                 //return ret;
  451.         }
  452.  
  453.         ctx->enabled = false;
  454.  
  455.         return 0;
  456. }
  457.  
  458. static int ph720128t003_get_modes(struct drm_panel *panel, struct drm_connector *connector)
  459. {
  460.         struct ph720128t003 *ctx = panel_to_ph720128t003(panel);
  461.         struct device *dev = &ctx->dsi->dev;
  462.         struct drm_display_mode *mode;
  463.         u32 *bus_flags = &connector->display_info.bus_flags;
  464.         int ret;
  465.  
  466.         DRM_DEV_INFO(dev, "get modes\n");
  467.  
  468.         mode = drm_mode_create(connector->dev);
  469.         if (!mode) {
  470.                 DRM_DEV_ERROR(dev, "Failed to create display mode!\n");
  471.                 return 0;
  472.         }
  473.  
  474.         drm_display_mode_from_videomode(&ctx->vm, mode);
  475.         mode->width_mm = ctx->width_mm;
  476.         mode->height_mm = ctx->height_mm;
  477.         connector->display_info.width_mm = ctx->width_mm;
  478.         connector->display_info.height_mm = ctx->height_mm;
  479.         mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  480.  
  481.         if (ctx->vm.flags & DISPLAY_FLAGS_DE_HIGH)
  482.                 *bus_flags |= DRM_BUS_FLAG_DE_HIGH;
  483.         if (ctx->vm.flags & DISPLAY_FLAGS_DE_LOW)
  484.                 *bus_flags |= DRM_BUS_FLAG_DE_LOW;
  485.         if (ctx->vm.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
  486.                 *bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE;
  487.         if (ctx->vm.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  488.                 *bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE;
  489.  
  490.         ret = drm_display_info_set_bus_formats(&connector->display_info,
  491.                         ph720128t003_bus_formats, ARRAY_SIZE(ph720128t003_bus_formats));
  492.         if (ret) {
  493.                 DRM_DEV_ERROR(dev, "failed to set display bus format (error:%d)!\n", ret);
  494.                 return ret;
  495.         }
  496.  
  497.         drm_mode_probed_add(connector, mode);
  498.  
  499.         return 1;
  500. }
  501.  
  502. static const struct drm_panel_funcs ph720128t003_funcs = {
  503.         .prepare        = ph720128t003_prepare,
  504.         .unprepare      = ph720128t003_unprepare,
  505.         .enable         = ph720128t003_enable,
  506.         .disable        = ph720128t003_disable,
  507.         .get_modes      = ph720128t003_get_modes,
  508. };
  509.  
  510. /*
  511.  */
  512. static const struct display_timing ph720128t003_default_timing = {
  513.         .pixelclock.typ   = 55000000,
  514.         .hactive.typ      = 720,
  515.         .hfront_porch.typ = 50,
  516.         .hsync_len.typ    = 20,
  517.         .hback_porch.typ  = 50,
  518.         .vactive.typ      = 1280,
  519.         .vfront_porch.typ = 9,
  520.         .vsync_len.typ    = 3,
  521.         .vback_porch.typ  = 13,
  522.         .flags = DISPLAY_FLAGS_HSYNC_LOW |
  523.                  DISPLAY_FLAGS_VSYNC_LOW |
  524.                  DISPLAY_FLAGS_DE_LOW |
  525.                  DISPLAY_FLAGS_PIXDATA_NEGEDGE,
  526. };
  527.  
  528. static int ph720128t003_dsi_probe(struct mipi_dsi_device *dsi)
  529. {
  530.         struct device *dev = &dsi->dev;
  531.         struct device_node *np;
  532.         struct ph720128t003 *ctx;
  533.         int ret;
  534.  
  535.         DRM_DEV_INFO(dev, "\n");
  536.  
  537.         ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
  538.         if (!ctx)
  539.                 return -ENOMEM;
  540.  
  541.         mipi_dsi_set_drvdata(dsi, ctx);
  542.         ctx->dsi = dsi;
  543.  
  544.         dsi->format = MIPI_DSI_FMT_RGB888;
  545.         dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | MIPI_DSI_MODE_LPM;
  546. //      dsi->mode_flags |= MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_VIDEO_HSE;
  547.         dsi->lanes = 2;
  548.  
  549.         videomode_from_timing(&ph720128t003_default_timing, &ctx->vm);
  550.  
  551.         ctx->width_mm = 90;
  552.         ctx->height_mm = 152;
  553.  
  554.         ctx->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
  555.  
  556.         if (IS_ERR(ctx->reset))
  557.                 ctx->reset = NULL;
  558.         else
  559.                 gpiod_set_value(ctx->reset, 1);
  560.  
  561.         np = of_parse_phandle(dsi->dev.of_node, "backlight", 0);
  562.         if (np) {
  563.                 ctx->backlight = of_find_backlight_by_node(np);
  564.                 of_node_put(np);
  565.  
  566.                 if (!ctx->backlight)
  567.                         return -EPROBE_DEFER;
  568.         }
  569.  
  570.         drm_panel_init(&ctx->panel,&dsi->dev,&ph720128t003_funcs, DRM_MODE_CONNECTOR_DSI);
  571.         ctx->panel.dev = &dsi->dev;
  572.         ctx->panel.funcs = &ph720128t003_funcs;
  573.         dev_set_drvdata(dev, ctx);
  574.  
  575.         drm_panel_add(&ctx->panel);
  576.  
  577.         return mipi_dsi_attach(dsi);
  578. }
  579.  
  580. static int ph720128t003_dsi_remove(struct mipi_dsi_device *dsi)
  581. {
  582.         struct ph720128t003 *ctx = mipi_dsi_get_drvdata(dsi);
  583.  
  584.         mipi_dsi_detach(dsi);
  585.         drm_panel_remove(&ctx->panel);
  586.  
  587.         if (ctx->backlight)
  588.                 put_device(&ctx->backlight->dev);
  589.  
  590.         return 0;
  591. }
  592.  
  593. static const struct of_device_id ph720128t003_of_match[] = {
  594.         { .compatible = "powertip,ph720128t003" },
  595.         { }
  596. };
  597. MODULE_DEVICE_TABLE(of, ph720128t003_of_match);
  598.  
  599. static struct mipi_dsi_driver ph720128t003_dsi_driver = {
  600.         .probe          = ph720128t003_dsi_probe,
  601.         .remove         = ph720128t003_dsi_remove,
  602.         .driver = {
  603.                 .name           = "ph720128t003-dsi",
  604.                 .of_match_table = ph720128t003_of_match,
  605.         },
  606. };
  607. module_mipi_dsi_driver(ph720128t003_dsi_driver);
  608. /*
  609. static int ph720128t003_platform_probe(struct platform_device *pdev)
  610. {
  611.         const struct of_device_id *id;
  612.  
  613.         id = of_match_node(ph720128t003_of_match, pdev->dev.of_node);
  614.         if (!id)
  615.                 return -ENODEV;
  616.  
  617.         return ph720128t003_dsi_probe(&pdev->dev, id->data);
  618. }
  619.  
  620. static int ph720128t003_platform_remove(struct platform_device *pdev)
  621. {
  622.         return ph720128t003_dsi_remove(&pdev->dev);
  623. }
  624.  
  625. static struct platform_driver ph720128t003_platform_driver = {
  626.         .probe          = ph720128t003_platform_probe,
  627.         .remove         = ph720128t003_platform_remove,
  628.         .driver = {
  629.                 .name           = "ph720128t003-dsi",
  630.                 .of_match_table = ph720128t003_of_match,
  631.         },
  632. };
  633.  
  634. module_platform_driver(ph720128t003_platform_driver);
  635. */
  636. MODULE_AUTHOR("Arkadiusz Karas <arkadiusz.karas@somlabs.com>");
  637. MODULE_DESCRIPTION("Powertip PH720128T003 Controller Driver");
  638. MODULE_LICENSE("GPL v2");
  639.  

odpowiedź "Bez tytułu"

Tutaj możesz odpowiedzieć na wklejkę z góry

captcha