18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/delay.h> 78c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 88c2ecf20Sopenharmony_ci#include <linux/module.h> 98c2ecf20Sopenharmony_ci#include <linux/of.h> 108c2ecf20Sopenharmony_ci#include <linux/of_device.h> 118c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <video/mipi_display.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <drm/drm_crtc.h> 168c2ecf20Sopenharmony_ci#include <drm/drm_device.h> 178c2ecf20Sopenharmony_ci#include <drm/drm_mipi_dsi.h> 188c2ecf20Sopenharmony_ci#include <drm/drm_modes.h> 198c2ecf20Sopenharmony_ci#include <drm/drm_panel.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistruct panel_init_cmd { 228c2ecf20Sopenharmony_ci size_t len; 238c2ecf20Sopenharmony_ci const char *data; 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define _INIT_CMD(...) { \ 278c2ecf20Sopenharmony_ci .len = sizeof((char[]){__VA_ARGS__}), \ 288c2ecf20Sopenharmony_ci .data = (char[]){__VA_ARGS__} } 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct panel_desc { 318c2ecf20Sopenharmony_ci const struct drm_display_mode *mode; 328c2ecf20Sopenharmony_ci unsigned int bpc; 338c2ecf20Sopenharmony_ci struct { 348c2ecf20Sopenharmony_ci unsigned int width; 358c2ecf20Sopenharmony_ci unsigned int height; 368c2ecf20Sopenharmony_ci } size; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci unsigned long flags; 398c2ecf20Sopenharmony_ci enum mipi_dsi_pixel_format format; 408c2ecf20Sopenharmony_ci const struct panel_init_cmd *init_cmds; 418c2ecf20Sopenharmony_ci unsigned int lanes; 428c2ecf20Sopenharmony_ci const char * const *supply_names; 438c2ecf20Sopenharmony_ci unsigned int num_supplies; 448c2ecf20Sopenharmony_ci unsigned int sleep_mode_delay; 458c2ecf20Sopenharmony_ci unsigned int power_down_delay; 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistruct innolux_panel { 498c2ecf20Sopenharmony_ci struct drm_panel base; 508c2ecf20Sopenharmony_ci struct mipi_dsi_device *link; 518c2ecf20Sopenharmony_ci const struct panel_desc *desc; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci struct regulator_bulk_data *supplies; 548c2ecf20Sopenharmony_ci struct gpio_desc *enable_gpio; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci bool prepared; 578c2ecf20Sopenharmony_ci bool enabled; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic inline struct innolux_panel *to_innolux_panel(struct drm_panel *panel) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci return container_of(panel, struct innolux_panel, base); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic int innolux_panel_disable(struct drm_panel *panel) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci struct innolux_panel *innolux = to_innolux_panel(panel); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (!innolux->enabled) 708c2ecf20Sopenharmony_ci return 0; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci innolux->enabled = false; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic int innolux_panel_unprepare(struct drm_panel *panel) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci struct innolux_panel *innolux = to_innolux_panel(panel); 808c2ecf20Sopenharmony_ci int err; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (!innolux->prepared) 838c2ecf20Sopenharmony_ci return 0; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci err = mipi_dsi_dcs_set_display_off(innolux->link); 868c2ecf20Sopenharmony_ci if (err < 0) 878c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to set display off: %d\n", err); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci err = mipi_dsi_dcs_enter_sleep_mode(innolux->link); 908c2ecf20Sopenharmony_ci if (err < 0) { 918c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to enter sleep mode: %d\n", err); 928c2ecf20Sopenharmony_ci return err; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci if (innolux->desc->sleep_mode_delay) 968c2ecf20Sopenharmony_ci msleep(innolux->desc->sleep_mode_delay); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(innolux->enable_gpio, 0); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci if (innolux->desc->power_down_delay) 1018c2ecf20Sopenharmony_ci msleep(innolux->desc->power_down_delay); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci err = regulator_bulk_disable(innolux->desc->num_supplies, 1048c2ecf20Sopenharmony_ci innolux->supplies); 1058c2ecf20Sopenharmony_ci if (err < 0) 1068c2ecf20Sopenharmony_ci return err; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci innolux->prepared = false; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci return 0; 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic int innolux_panel_prepare(struct drm_panel *panel) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci struct innolux_panel *innolux = to_innolux_panel(panel); 1168c2ecf20Sopenharmony_ci int err; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci if (innolux->prepared) 1198c2ecf20Sopenharmony_ci return 0; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(innolux->enable_gpio, 0); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci err = regulator_bulk_enable(innolux->desc->num_supplies, 1248c2ecf20Sopenharmony_ci innolux->supplies); 1258c2ecf20Sopenharmony_ci if (err < 0) 1268c2ecf20Sopenharmony_ci return err; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci /* p079zca: t2 (20ms), p097pfg: t4 (15ms) */ 1298c2ecf20Sopenharmony_ci usleep_range(20000, 21000); 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(innolux->enable_gpio, 1); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* p079zca: t4, p097pfg: t5 */ 1348c2ecf20Sopenharmony_ci usleep_range(20000, 21000); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci if (innolux->desc->init_cmds) { 1378c2ecf20Sopenharmony_ci const struct panel_init_cmd *cmds = 1388c2ecf20Sopenharmony_ci innolux->desc->init_cmds; 1398c2ecf20Sopenharmony_ci unsigned int i; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci for (i = 0; cmds[i].len != 0; i++) { 1428c2ecf20Sopenharmony_ci const struct panel_init_cmd *cmd = &cmds[i]; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci err = mipi_dsi_generic_write(innolux->link, cmd->data, 1458c2ecf20Sopenharmony_ci cmd->len); 1468c2ecf20Sopenharmony_ci if (err < 0) { 1478c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to write command %u\n", i); 1488c2ecf20Sopenharmony_ci goto poweroff; 1498c2ecf20Sopenharmony_ci } 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci /* 1528c2ecf20Sopenharmony_ci * Included by random guessing, because without this 1538c2ecf20Sopenharmony_ci * (or at least, some delay), the panel sometimes 1548c2ecf20Sopenharmony_ci * didn't appear to pick up the command sequence. 1558c2ecf20Sopenharmony_ci */ 1568c2ecf20Sopenharmony_ci err = mipi_dsi_dcs_nop(innolux->link); 1578c2ecf20Sopenharmony_ci if (err < 0) { 1588c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to send DCS nop: %d\n", err); 1598c2ecf20Sopenharmony_ci goto poweroff; 1608c2ecf20Sopenharmony_ci } 1618c2ecf20Sopenharmony_ci } 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci err = mipi_dsi_dcs_exit_sleep_mode(innolux->link); 1658c2ecf20Sopenharmony_ci if (err < 0) { 1668c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to exit sleep mode: %d\n", err); 1678c2ecf20Sopenharmony_ci goto poweroff; 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci /* T6: 120ms - 1000ms*/ 1718c2ecf20Sopenharmony_ci msleep(120); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci err = mipi_dsi_dcs_set_display_on(innolux->link); 1748c2ecf20Sopenharmony_ci if (err < 0) { 1758c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to set display on: %d\n", err); 1768c2ecf20Sopenharmony_ci goto poweroff; 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci /* T7: 5ms */ 1808c2ecf20Sopenharmony_ci usleep_range(5000, 6000); 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci innolux->prepared = true; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci return 0; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cipoweroff: 1878c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(innolux->enable_gpio, 0); 1888c2ecf20Sopenharmony_ci regulator_bulk_disable(innolux->desc->num_supplies, innolux->supplies); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci return err; 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic int innolux_panel_enable(struct drm_panel *panel) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci struct innolux_panel *innolux = to_innolux_panel(panel); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (innolux->enabled) 1988c2ecf20Sopenharmony_ci return 0; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci innolux->enabled = true; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci return 0; 2038c2ecf20Sopenharmony_ci} 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistatic const char * const innolux_p079zca_supply_names[] = { 2068c2ecf20Sopenharmony_ci "power", 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic const struct drm_display_mode innolux_p079zca_mode = { 2108c2ecf20Sopenharmony_ci .clock = 56900, 2118c2ecf20Sopenharmony_ci .hdisplay = 768, 2128c2ecf20Sopenharmony_ci .hsync_start = 768 + 40, 2138c2ecf20Sopenharmony_ci .hsync_end = 768 + 40 + 40, 2148c2ecf20Sopenharmony_ci .htotal = 768 + 40 + 40 + 40, 2158c2ecf20Sopenharmony_ci .vdisplay = 1024, 2168c2ecf20Sopenharmony_ci .vsync_start = 1024 + 20, 2178c2ecf20Sopenharmony_ci .vsync_end = 1024 + 20 + 4, 2188c2ecf20Sopenharmony_ci .vtotal = 1024 + 20 + 4 + 20, 2198c2ecf20Sopenharmony_ci}; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_cistatic const struct panel_desc innolux_p079zca_panel_desc = { 2228c2ecf20Sopenharmony_ci .mode = &innolux_p079zca_mode, 2238c2ecf20Sopenharmony_ci .bpc = 8, 2248c2ecf20Sopenharmony_ci .size = { 2258c2ecf20Sopenharmony_ci .width = 120, 2268c2ecf20Sopenharmony_ci .height = 160, 2278c2ecf20Sopenharmony_ci }, 2288c2ecf20Sopenharmony_ci .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | 2298c2ecf20Sopenharmony_ci MIPI_DSI_MODE_LPM, 2308c2ecf20Sopenharmony_ci .format = MIPI_DSI_FMT_RGB888, 2318c2ecf20Sopenharmony_ci .lanes = 4, 2328c2ecf20Sopenharmony_ci .supply_names = innolux_p079zca_supply_names, 2338c2ecf20Sopenharmony_ci .num_supplies = ARRAY_SIZE(innolux_p079zca_supply_names), 2348c2ecf20Sopenharmony_ci .power_down_delay = 80, /* T8: 80ms - 1000ms */ 2358c2ecf20Sopenharmony_ci}; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistatic const char * const innolux_p097pfg_supply_names[] = { 2388c2ecf20Sopenharmony_ci "avdd", 2398c2ecf20Sopenharmony_ci "avee", 2408c2ecf20Sopenharmony_ci}; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic const struct drm_display_mode innolux_p097pfg_mode = { 2438c2ecf20Sopenharmony_ci .clock = 229000, 2448c2ecf20Sopenharmony_ci .hdisplay = 1536, 2458c2ecf20Sopenharmony_ci .hsync_start = 1536 + 100, 2468c2ecf20Sopenharmony_ci .hsync_end = 1536 + 100 + 24, 2478c2ecf20Sopenharmony_ci .htotal = 1536 + 100 + 24 + 100, 2488c2ecf20Sopenharmony_ci .vdisplay = 2048, 2498c2ecf20Sopenharmony_ci .vsync_start = 2048 + 100, 2508c2ecf20Sopenharmony_ci .vsync_end = 2048 + 100 + 2, 2518c2ecf20Sopenharmony_ci .vtotal = 2048 + 100 + 2 + 18, 2528c2ecf20Sopenharmony_ci}; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci/* 2558c2ecf20Sopenharmony_ci * Display manufacturer failed to provide init sequencing according to 2568c2ecf20Sopenharmony_ci * https://chromium-review.googlesource.com/c/chromiumos/third_party/coreboot/+/892065/ 2578c2ecf20Sopenharmony_ci * so the init sequence stems from a register dump of a working panel. 2588c2ecf20Sopenharmony_ci */ 2598c2ecf20Sopenharmony_cistatic const struct panel_init_cmd innolux_p097pfg_init_cmds[] = { 2608c2ecf20Sopenharmony_ci /* page 0 */ 2618c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x00), 2628c2ecf20Sopenharmony_ci _INIT_CMD(0xB1, 0xE8, 0x11), 2638c2ecf20Sopenharmony_ci _INIT_CMD(0xB2, 0x25, 0x02), 2648c2ecf20Sopenharmony_ci _INIT_CMD(0xB5, 0x08, 0x00), 2658c2ecf20Sopenharmony_ci _INIT_CMD(0xBC, 0x0F, 0x00), 2668c2ecf20Sopenharmony_ci _INIT_CMD(0xB8, 0x03, 0x06, 0x00, 0x00), 2678c2ecf20Sopenharmony_ci _INIT_CMD(0xBD, 0x01, 0x90, 0x14, 0x14), 2688c2ecf20Sopenharmony_ci _INIT_CMD(0x6F, 0x01), 2698c2ecf20Sopenharmony_ci _INIT_CMD(0xC0, 0x03), 2708c2ecf20Sopenharmony_ci _INIT_CMD(0x6F, 0x02), 2718c2ecf20Sopenharmony_ci _INIT_CMD(0xC1, 0x0D), 2728c2ecf20Sopenharmony_ci _INIT_CMD(0xD9, 0x01, 0x09, 0x70), 2738c2ecf20Sopenharmony_ci _INIT_CMD(0xC5, 0x12, 0x21, 0x00), 2748c2ecf20Sopenharmony_ci _INIT_CMD(0xBB, 0x93, 0x93), 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* page 1 */ 2778c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x01), 2788c2ecf20Sopenharmony_ci _INIT_CMD(0xB3, 0x3C, 0x3C), 2798c2ecf20Sopenharmony_ci _INIT_CMD(0xB4, 0x0F, 0x0F), 2808c2ecf20Sopenharmony_ci _INIT_CMD(0xB9, 0x45, 0x45), 2818c2ecf20Sopenharmony_ci _INIT_CMD(0xBA, 0x14, 0x14), 2828c2ecf20Sopenharmony_ci _INIT_CMD(0xCA, 0x02), 2838c2ecf20Sopenharmony_ci _INIT_CMD(0xCE, 0x04), 2848c2ecf20Sopenharmony_ci _INIT_CMD(0xC3, 0x9B, 0x9B), 2858c2ecf20Sopenharmony_ci _INIT_CMD(0xD8, 0xC0, 0x03), 2868c2ecf20Sopenharmony_ci _INIT_CMD(0xBC, 0x82, 0x01), 2878c2ecf20Sopenharmony_ci _INIT_CMD(0xBD, 0x9E, 0x01), 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci /* page 2 */ 2908c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x02), 2918c2ecf20Sopenharmony_ci _INIT_CMD(0xB0, 0x82), 2928c2ecf20Sopenharmony_ci _INIT_CMD(0xD1, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x82, 0x00, 0xA5, 2938c2ecf20Sopenharmony_ci 0x00, 0xC1, 0x00, 0xEA, 0x01, 0x0D, 0x01, 0x40), 2948c2ecf20Sopenharmony_ci _INIT_CMD(0xD2, 0x01, 0x6A, 0x01, 0xA8, 0x01, 0xDC, 0x02, 0x29, 2958c2ecf20Sopenharmony_ci 0x02, 0x67, 0x02, 0x68, 0x02, 0xA8, 0x02, 0xF0), 2968c2ecf20Sopenharmony_ci _INIT_CMD(0xD3, 0x03, 0x19, 0x03, 0x49, 0x03, 0x67, 0x03, 0x8C, 2978c2ecf20Sopenharmony_ci 0x03, 0xA6, 0x03, 0xC7, 0x03, 0xDE, 0x03, 0xEC), 2988c2ecf20Sopenharmony_ci _INIT_CMD(0xD4, 0x03, 0xFF, 0x03, 0xFF), 2998c2ecf20Sopenharmony_ci _INIT_CMD(0xE0, 0x00, 0x00, 0x00, 0x86, 0x00, 0xC5, 0x00, 0xE5, 3008c2ecf20Sopenharmony_ci 0x00, 0xFF, 0x01, 0x26, 0x01, 0x45, 0x01, 0x75), 3018c2ecf20Sopenharmony_ci _INIT_CMD(0xE1, 0x01, 0x9C, 0x01, 0xD5, 0x02, 0x05, 0x02, 0x4D, 3028c2ecf20Sopenharmony_ci 0x02, 0x86, 0x02, 0x87, 0x02, 0xC3, 0x03, 0x03), 3038c2ecf20Sopenharmony_ci _INIT_CMD(0xE2, 0x03, 0x2A, 0x03, 0x56, 0x03, 0x72, 0x03, 0x94, 3048c2ecf20Sopenharmony_ci 0x03, 0xAC, 0x03, 0xCB, 0x03, 0xE0, 0x03, 0xED), 3058c2ecf20Sopenharmony_ci _INIT_CMD(0xE3, 0x03, 0xFF, 0x03, 0xFF), 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci /* page 3 */ 3088c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x03), 3098c2ecf20Sopenharmony_ci _INIT_CMD(0xB0, 0x00, 0x00, 0x00, 0x00), 3108c2ecf20Sopenharmony_ci _INIT_CMD(0xB1, 0x00, 0x00, 0x00, 0x00), 3118c2ecf20Sopenharmony_ci _INIT_CMD(0xB2, 0x00, 0x00, 0x06, 0x04, 0x01, 0x40, 0x85), 3128c2ecf20Sopenharmony_ci _INIT_CMD(0xB3, 0x10, 0x07, 0xFC, 0x04, 0x01, 0x40, 0x80), 3138c2ecf20Sopenharmony_ci _INIT_CMD(0xB6, 0xF0, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 3148c2ecf20Sopenharmony_ci 0x40, 0x80), 3158c2ecf20Sopenharmony_ci _INIT_CMD(0xBA, 0xC5, 0x07, 0x00, 0x04, 0x11, 0x25, 0x8C), 3168c2ecf20Sopenharmony_ci _INIT_CMD(0xBB, 0xC5, 0x07, 0x00, 0x03, 0x11, 0x25, 0x8C), 3178c2ecf20Sopenharmony_ci _INIT_CMD(0xC0, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x80, 0x80), 3188c2ecf20Sopenharmony_ci _INIT_CMD(0xC1, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x80, 0x80), 3198c2ecf20Sopenharmony_ci _INIT_CMD(0xC4, 0x00, 0x00), 3208c2ecf20Sopenharmony_ci _INIT_CMD(0xEF, 0x41), 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci /* page 4 */ 3238c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x04), 3248c2ecf20Sopenharmony_ci _INIT_CMD(0xEC, 0x4C), 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* page 5 */ 3278c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x05), 3288c2ecf20Sopenharmony_ci _INIT_CMD(0xB0, 0x13, 0x03, 0x03, 0x01), 3298c2ecf20Sopenharmony_ci _INIT_CMD(0xB1, 0x30, 0x00), 3308c2ecf20Sopenharmony_ci _INIT_CMD(0xB2, 0x02, 0x02, 0x00), 3318c2ecf20Sopenharmony_ci _INIT_CMD(0xB3, 0x82, 0x23, 0x82, 0x9D), 3328c2ecf20Sopenharmony_ci _INIT_CMD(0xB4, 0xC5, 0x75, 0x24, 0x57), 3338c2ecf20Sopenharmony_ci _INIT_CMD(0xB5, 0x00, 0xD4, 0x72, 0x11, 0x11, 0xAB, 0x0A), 3348c2ecf20Sopenharmony_ci _INIT_CMD(0xB6, 0x00, 0x00, 0xD5, 0x72, 0x24, 0x56), 3358c2ecf20Sopenharmony_ci _INIT_CMD(0xB7, 0x5C, 0xDC, 0x5C, 0x5C), 3368c2ecf20Sopenharmony_ci _INIT_CMD(0xB9, 0x0C, 0x00, 0x00, 0x01, 0x00), 3378c2ecf20Sopenharmony_ci _INIT_CMD(0xC0, 0x75, 0x11, 0x11, 0x54, 0x05), 3388c2ecf20Sopenharmony_ci _INIT_CMD(0xC6, 0x00, 0x00, 0x00, 0x00), 3398c2ecf20Sopenharmony_ci _INIT_CMD(0xD0, 0x00, 0x48, 0x08, 0x00, 0x00), 3408c2ecf20Sopenharmony_ci _INIT_CMD(0xD1, 0x00, 0x48, 0x09, 0x00, 0x00), 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci /* page 6 */ 3438c2ecf20Sopenharmony_ci _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x06), 3448c2ecf20Sopenharmony_ci _INIT_CMD(0xB0, 0x02, 0x32, 0x32, 0x08, 0x2F), 3458c2ecf20Sopenharmony_ci _INIT_CMD(0xB1, 0x2E, 0x15, 0x14, 0x13, 0x12), 3468c2ecf20Sopenharmony_ci _INIT_CMD(0xB2, 0x11, 0x10, 0x00, 0x3D, 0x3D), 3478c2ecf20Sopenharmony_ci _INIT_CMD(0xB3, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D), 3488c2ecf20Sopenharmony_ci _INIT_CMD(0xB4, 0x3D, 0x32), 3498c2ecf20Sopenharmony_ci _INIT_CMD(0xB5, 0x03, 0x32, 0x32, 0x09, 0x2F), 3508c2ecf20Sopenharmony_ci _INIT_CMD(0xB6, 0x2E, 0x1B, 0x1A, 0x19, 0x18), 3518c2ecf20Sopenharmony_ci _INIT_CMD(0xB7, 0x17, 0x16, 0x01, 0x3D, 0x3D), 3528c2ecf20Sopenharmony_ci _INIT_CMD(0xB8, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D), 3538c2ecf20Sopenharmony_ci _INIT_CMD(0xB9, 0x3D, 0x32), 3548c2ecf20Sopenharmony_ci _INIT_CMD(0xC0, 0x01, 0x32, 0x32, 0x09, 0x2F), 3558c2ecf20Sopenharmony_ci _INIT_CMD(0xC1, 0x2E, 0x1A, 0x1B, 0x16, 0x17), 3568c2ecf20Sopenharmony_ci _INIT_CMD(0xC2, 0x18, 0x19, 0x03, 0x3D, 0x3D), 3578c2ecf20Sopenharmony_ci _INIT_CMD(0xC3, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D), 3588c2ecf20Sopenharmony_ci _INIT_CMD(0xC4, 0x3D, 0x32), 3598c2ecf20Sopenharmony_ci _INIT_CMD(0xC5, 0x00, 0x32, 0x32, 0x08, 0x2F), 3608c2ecf20Sopenharmony_ci _INIT_CMD(0xC6, 0x2E, 0x14, 0x15, 0x10, 0x11), 3618c2ecf20Sopenharmony_ci _INIT_CMD(0xC7, 0x12, 0x13, 0x02, 0x3D, 0x3D), 3628c2ecf20Sopenharmony_ci _INIT_CMD(0xC8, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D), 3638c2ecf20Sopenharmony_ci _INIT_CMD(0xC9, 0x3D, 0x32), 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci {}, 3668c2ecf20Sopenharmony_ci}; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_cistatic const struct panel_desc innolux_p097pfg_panel_desc = { 3698c2ecf20Sopenharmony_ci .mode = &innolux_p097pfg_mode, 3708c2ecf20Sopenharmony_ci .bpc = 8, 3718c2ecf20Sopenharmony_ci .size = { 3728c2ecf20Sopenharmony_ci .width = 147, 3738c2ecf20Sopenharmony_ci .height = 196, 3748c2ecf20Sopenharmony_ci }, 3758c2ecf20Sopenharmony_ci .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | 3768c2ecf20Sopenharmony_ci MIPI_DSI_MODE_LPM, 3778c2ecf20Sopenharmony_ci .format = MIPI_DSI_FMT_RGB888, 3788c2ecf20Sopenharmony_ci .init_cmds = innolux_p097pfg_init_cmds, 3798c2ecf20Sopenharmony_ci .lanes = 4, 3808c2ecf20Sopenharmony_ci .supply_names = innolux_p097pfg_supply_names, 3818c2ecf20Sopenharmony_ci .num_supplies = ARRAY_SIZE(innolux_p097pfg_supply_names), 3828c2ecf20Sopenharmony_ci .sleep_mode_delay = 100, /* T15 */ 3838c2ecf20Sopenharmony_ci}; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_cistatic int innolux_panel_get_modes(struct drm_panel *panel, 3868c2ecf20Sopenharmony_ci struct drm_connector *connector) 3878c2ecf20Sopenharmony_ci{ 3888c2ecf20Sopenharmony_ci struct innolux_panel *innolux = to_innolux_panel(panel); 3898c2ecf20Sopenharmony_ci const struct drm_display_mode *m = innolux->desc->mode; 3908c2ecf20Sopenharmony_ci struct drm_display_mode *mode; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci mode = drm_mode_duplicate(connector->dev, m); 3938c2ecf20Sopenharmony_ci if (!mode) { 3948c2ecf20Sopenharmony_ci dev_err(panel->dev, "failed to add mode %ux%u@%u\n", 3958c2ecf20Sopenharmony_ci m->hdisplay, m->vdisplay, drm_mode_vrefresh(m)); 3968c2ecf20Sopenharmony_ci return -ENOMEM; 3978c2ecf20Sopenharmony_ci } 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci drm_mode_set_name(mode); 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci drm_mode_probed_add(connector, mode); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci connector->display_info.width_mm = innolux->desc->size.width; 4048c2ecf20Sopenharmony_ci connector->display_info.height_mm = innolux->desc->size.height; 4058c2ecf20Sopenharmony_ci connector->display_info.bpc = innolux->desc->bpc; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci return 1; 4088c2ecf20Sopenharmony_ci} 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_cistatic const struct drm_panel_funcs innolux_panel_funcs = { 4118c2ecf20Sopenharmony_ci .disable = innolux_panel_disable, 4128c2ecf20Sopenharmony_ci .unprepare = innolux_panel_unprepare, 4138c2ecf20Sopenharmony_ci .prepare = innolux_panel_prepare, 4148c2ecf20Sopenharmony_ci .enable = innolux_panel_enable, 4158c2ecf20Sopenharmony_ci .get_modes = innolux_panel_get_modes, 4168c2ecf20Sopenharmony_ci}; 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_cistatic const struct of_device_id innolux_of_match[] = { 4198c2ecf20Sopenharmony_ci { .compatible = "innolux,p079zca", 4208c2ecf20Sopenharmony_ci .data = &innolux_p079zca_panel_desc 4218c2ecf20Sopenharmony_ci }, 4228c2ecf20Sopenharmony_ci { .compatible = "innolux,p097pfg", 4238c2ecf20Sopenharmony_ci .data = &innolux_p097pfg_panel_desc 4248c2ecf20Sopenharmony_ci }, 4258c2ecf20Sopenharmony_ci { } 4268c2ecf20Sopenharmony_ci}; 4278c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, innolux_of_match); 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic int innolux_panel_add(struct mipi_dsi_device *dsi, 4308c2ecf20Sopenharmony_ci const struct panel_desc *desc) 4318c2ecf20Sopenharmony_ci{ 4328c2ecf20Sopenharmony_ci struct innolux_panel *innolux; 4338c2ecf20Sopenharmony_ci struct device *dev = &dsi->dev; 4348c2ecf20Sopenharmony_ci int err, i; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci innolux = devm_kzalloc(dev, sizeof(*innolux), GFP_KERNEL); 4378c2ecf20Sopenharmony_ci if (!innolux) 4388c2ecf20Sopenharmony_ci return -ENOMEM; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci innolux->desc = desc; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci innolux->supplies = devm_kcalloc(dev, desc->num_supplies, 4438c2ecf20Sopenharmony_ci sizeof(*innolux->supplies), 4448c2ecf20Sopenharmony_ci GFP_KERNEL); 4458c2ecf20Sopenharmony_ci if (!innolux->supplies) 4468c2ecf20Sopenharmony_ci return -ENOMEM; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci for (i = 0; i < desc->num_supplies; i++) 4498c2ecf20Sopenharmony_ci innolux->supplies[i].supply = desc->supply_names[i]; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci err = devm_regulator_bulk_get(dev, desc->num_supplies, 4528c2ecf20Sopenharmony_ci innolux->supplies); 4538c2ecf20Sopenharmony_ci if (err < 0) 4548c2ecf20Sopenharmony_ci return err; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci innolux->enable_gpio = devm_gpiod_get_optional(dev, "enable", 4578c2ecf20Sopenharmony_ci GPIOD_OUT_HIGH); 4588c2ecf20Sopenharmony_ci if (IS_ERR(innolux->enable_gpio)) { 4598c2ecf20Sopenharmony_ci err = PTR_ERR(innolux->enable_gpio); 4608c2ecf20Sopenharmony_ci dev_dbg(dev, "failed to get enable gpio: %d\n", err); 4618c2ecf20Sopenharmony_ci innolux->enable_gpio = NULL; 4628c2ecf20Sopenharmony_ci } 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci drm_panel_init(&innolux->base, dev, &innolux_panel_funcs, 4658c2ecf20Sopenharmony_ci DRM_MODE_CONNECTOR_DSI); 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci err = drm_panel_of_backlight(&innolux->base); 4688c2ecf20Sopenharmony_ci if (err) 4698c2ecf20Sopenharmony_ci return err; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci drm_panel_add(&innolux->base); 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci mipi_dsi_set_drvdata(dsi, innolux); 4748c2ecf20Sopenharmony_ci innolux->link = dsi; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci return 0; 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_cistatic void innolux_panel_del(struct innolux_panel *innolux) 4808c2ecf20Sopenharmony_ci{ 4818c2ecf20Sopenharmony_ci drm_panel_remove(&innolux->base); 4828c2ecf20Sopenharmony_ci} 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_cistatic int innolux_panel_probe(struct mipi_dsi_device *dsi) 4858c2ecf20Sopenharmony_ci{ 4868c2ecf20Sopenharmony_ci const struct panel_desc *desc; 4878c2ecf20Sopenharmony_ci struct innolux_panel *innolux; 4888c2ecf20Sopenharmony_ci int err; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci desc = of_device_get_match_data(&dsi->dev); 4918c2ecf20Sopenharmony_ci dsi->mode_flags = desc->flags; 4928c2ecf20Sopenharmony_ci dsi->format = desc->format; 4938c2ecf20Sopenharmony_ci dsi->lanes = desc->lanes; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci err = innolux_panel_add(dsi, desc); 4968c2ecf20Sopenharmony_ci if (err < 0) 4978c2ecf20Sopenharmony_ci return err; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci err = mipi_dsi_attach(dsi); 5008c2ecf20Sopenharmony_ci if (err < 0) { 5018c2ecf20Sopenharmony_ci innolux = mipi_dsi_get_drvdata(dsi); 5028c2ecf20Sopenharmony_ci innolux_panel_del(innolux); 5038c2ecf20Sopenharmony_ci return err; 5048c2ecf20Sopenharmony_ci } 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci return 0; 5078c2ecf20Sopenharmony_ci} 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_cistatic int innolux_panel_remove(struct mipi_dsi_device *dsi) 5108c2ecf20Sopenharmony_ci{ 5118c2ecf20Sopenharmony_ci struct innolux_panel *innolux = mipi_dsi_get_drvdata(dsi); 5128c2ecf20Sopenharmony_ci int err; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci err = drm_panel_unprepare(&innolux->base); 5158c2ecf20Sopenharmony_ci if (err < 0) 5168c2ecf20Sopenharmony_ci dev_err(&dsi->dev, "failed to unprepare panel: %d\n", err); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci err = drm_panel_disable(&innolux->base); 5198c2ecf20Sopenharmony_ci if (err < 0) 5208c2ecf20Sopenharmony_ci dev_err(&dsi->dev, "failed to disable panel: %d\n", err); 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci err = mipi_dsi_detach(dsi); 5238c2ecf20Sopenharmony_ci if (err < 0) 5248c2ecf20Sopenharmony_ci dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err); 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci innolux_panel_del(innolux); 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci return 0; 5298c2ecf20Sopenharmony_ci} 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cistatic void innolux_panel_shutdown(struct mipi_dsi_device *dsi) 5328c2ecf20Sopenharmony_ci{ 5338c2ecf20Sopenharmony_ci struct innolux_panel *innolux = mipi_dsi_get_drvdata(dsi); 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci drm_panel_unprepare(&innolux->base); 5368c2ecf20Sopenharmony_ci drm_panel_disable(&innolux->base); 5378c2ecf20Sopenharmony_ci} 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_cistatic struct mipi_dsi_driver innolux_panel_driver = { 5408c2ecf20Sopenharmony_ci .driver = { 5418c2ecf20Sopenharmony_ci .name = "panel-innolux-p079zca", 5428c2ecf20Sopenharmony_ci .of_match_table = innolux_of_match, 5438c2ecf20Sopenharmony_ci }, 5448c2ecf20Sopenharmony_ci .probe = innolux_panel_probe, 5458c2ecf20Sopenharmony_ci .remove = innolux_panel_remove, 5468c2ecf20Sopenharmony_ci .shutdown = innolux_panel_shutdown, 5478c2ecf20Sopenharmony_ci}; 5488c2ecf20Sopenharmony_cimodule_mipi_dsi_driver(innolux_panel_driver); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ciMODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); 5518c2ecf20Sopenharmony_ciMODULE_AUTHOR("Lin Huang <hl@rock-chips.com>"); 5528c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Innolux P079ZCA panel driver"); 5538c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 554