16b818c53SJagan Teki // SPDX-License-Identifier: GPL-2.0+ 26b818c53SJagan Teki /* 36b818c53SJagan Teki * Copyright (c) 2019 Radxa Limited 46b818c53SJagan Teki * Copyright (c) 2022 Edgeble AI Technologies Pvt. Ltd. 56b818c53SJagan Teki * 66b818c53SJagan Teki * Author: 76b818c53SJagan Teki * - Jagan Teki <jagan@amarulasolutions.com> 86b818c53SJagan Teki * - Stephen Chen <stephen@radxa.com> 96b818c53SJagan Teki */ 106b818c53SJagan Teki 116b818c53SJagan Teki #include <drm/drm_mipi_dsi.h> 126b818c53SJagan Teki #include <drm/drm_modes.h> 136b818c53SJagan Teki #include <drm/drm_panel.h> 146b818c53SJagan Teki #include <drm/drm_print.h> 156b818c53SJagan Teki 166b818c53SJagan Teki #include <linux/gpio/consumer.h> 176b818c53SJagan Teki #include <linux/delay.h> 186b818c53SJagan Teki #include <linux/module.h> 19*722d4f06SRob Herring #include <linux/of.h> 206b818c53SJagan Teki #include <linux/regulator/consumer.h> 216b818c53SJagan Teki 226b818c53SJagan Teki #define JD9365DA_INIT_CMD_LEN 2 236b818c53SJagan Teki 246b818c53SJagan Teki struct jadard_init_cmd { 256b818c53SJagan Teki u8 data[JD9365DA_INIT_CMD_LEN]; 266b818c53SJagan Teki }; 276b818c53SJagan Teki 286b818c53SJagan Teki struct jadard_panel_desc { 296b818c53SJagan Teki const struct drm_display_mode mode; 306b818c53SJagan Teki unsigned int lanes; 316b818c53SJagan Teki enum mipi_dsi_pixel_format format; 326b818c53SJagan Teki const struct jadard_init_cmd *init_cmds; 336b818c53SJagan Teki u32 num_init_cmds; 346b818c53SJagan Teki }; 356b818c53SJagan Teki 366b818c53SJagan Teki struct jadard { 376b818c53SJagan Teki struct drm_panel panel; 386b818c53SJagan Teki struct mipi_dsi_device *dsi; 396b818c53SJagan Teki const struct jadard_panel_desc *desc; 406b818c53SJagan Teki 416b818c53SJagan Teki struct regulator *vdd; 426b818c53SJagan Teki struct regulator *vccio; 436b818c53SJagan Teki struct gpio_desc *reset; 446b818c53SJagan Teki }; 456b818c53SJagan Teki 466b818c53SJagan Teki static inline struct jadard *panel_to_jadard(struct drm_panel *panel) 476b818c53SJagan Teki { 486b818c53SJagan Teki return container_of(panel, struct jadard, panel); 496b818c53SJagan Teki } 506b818c53SJagan Teki 516b818c53SJagan Teki static int jadard_enable(struct drm_panel *panel) 526b818c53SJagan Teki { 536b818c53SJagan Teki struct device *dev = panel->dev; 546b818c53SJagan Teki struct jadard *jadard = panel_to_jadard(panel); 556b818c53SJagan Teki const struct jadard_panel_desc *desc = jadard->desc; 566b818c53SJagan Teki struct mipi_dsi_device *dsi = jadard->dsi; 576b818c53SJagan Teki unsigned int i; 586b818c53SJagan Teki int err; 596b818c53SJagan Teki 606b818c53SJagan Teki msleep(10); 616b818c53SJagan Teki 626b818c53SJagan Teki for (i = 0; i < desc->num_init_cmds; i++) { 636b818c53SJagan Teki const struct jadard_init_cmd *cmd = &desc->init_cmds[i]; 646b818c53SJagan Teki 656b818c53SJagan Teki err = mipi_dsi_dcs_write_buffer(dsi, cmd->data, JD9365DA_INIT_CMD_LEN); 666b818c53SJagan Teki if (err < 0) 676b818c53SJagan Teki return err; 686b818c53SJagan Teki } 696b818c53SJagan Teki 706b818c53SJagan Teki msleep(120); 716b818c53SJagan Teki 726b818c53SJagan Teki err = mipi_dsi_dcs_exit_sleep_mode(dsi); 736b818c53SJagan Teki if (err < 0) 746b818c53SJagan Teki DRM_DEV_ERROR(dev, "failed to exit sleep mode ret = %d\n", err); 756b818c53SJagan Teki 766b818c53SJagan Teki err = mipi_dsi_dcs_set_display_on(dsi); 776b818c53SJagan Teki if (err < 0) 786b818c53SJagan Teki DRM_DEV_ERROR(dev, "failed to set display on ret = %d\n", err); 796b818c53SJagan Teki 806b818c53SJagan Teki return 0; 816b818c53SJagan Teki } 826b818c53SJagan Teki 836b818c53SJagan Teki static int jadard_disable(struct drm_panel *panel) 846b818c53SJagan Teki { 856b818c53SJagan Teki struct device *dev = panel->dev; 866b818c53SJagan Teki struct jadard *jadard = panel_to_jadard(panel); 876b818c53SJagan Teki int ret; 886b818c53SJagan Teki 896b818c53SJagan Teki ret = mipi_dsi_dcs_set_display_off(jadard->dsi); 906b818c53SJagan Teki if (ret < 0) 916b818c53SJagan Teki DRM_DEV_ERROR(dev, "failed to set display off: %d\n", ret); 926b818c53SJagan Teki 936b818c53SJagan Teki ret = mipi_dsi_dcs_enter_sleep_mode(jadard->dsi); 946b818c53SJagan Teki if (ret < 0) 956b818c53SJagan Teki DRM_DEV_ERROR(dev, "failed to enter sleep mode: %d\n", ret); 966b818c53SJagan Teki 976b818c53SJagan Teki return 0; 986b818c53SJagan Teki } 996b818c53SJagan Teki 1006b818c53SJagan Teki static int jadard_prepare(struct drm_panel *panel) 1016b818c53SJagan Teki { 1026b818c53SJagan Teki struct jadard *jadard = panel_to_jadard(panel); 1036b818c53SJagan Teki int ret; 1046b818c53SJagan Teki 1056b818c53SJagan Teki ret = regulator_enable(jadard->vccio); 1066b818c53SJagan Teki if (ret) 1076b818c53SJagan Teki return ret; 1086b818c53SJagan Teki 1096b818c53SJagan Teki ret = regulator_enable(jadard->vdd); 1106b818c53SJagan Teki if (ret) 1116b818c53SJagan Teki return ret; 1126b818c53SJagan Teki 1136b818c53SJagan Teki gpiod_set_value(jadard->reset, 1); 1146b818c53SJagan Teki msleep(5); 1156b818c53SJagan Teki 1166b818c53SJagan Teki gpiod_set_value(jadard->reset, 0); 1176b818c53SJagan Teki msleep(10); 1186b818c53SJagan Teki 1196b818c53SJagan Teki gpiod_set_value(jadard->reset, 1); 1206b818c53SJagan Teki msleep(120); 1216b818c53SJagan Teki 1226b818c53SJagan Teki return 0; 1236b818c53SJagan Teki } 1246b818c53SJagan Teki 1256b818c53SJagan Teki static int jadard_unprepare(struct drm_panel *panel) 1266b818c53SJagan Teki { 1276b818c53SJagan Teki struct jadard *jadard = panel_to_jadard(panel); 1286b818c53SJagan Teki 1296b818c53SJagan Teki gpiod_set_value(jadard->reset, 1); 1306b818c53SJagan Teki msleep(120); 1316b818c53SJagan Teki 1326b818c53SJagan Teki regulator_disable(jadard->vdd); 1336b818c53SJagan Teki regulator_disable(jadard->vccio); 1346b818c53SJagan Teki 1356b818c53SJagan Teki return 0; 1366b818c53SJagan Teki } 1376b818c53SJagan Teki 1386b818c53SJagan Teki static int jadard_get_modes(struct drm_panel *panel, 1396b818c53SJagan Teki struct drm_connector *connector) 1406b818c53SJagan Teki { 1416b818c53SJagan Teki struct jadard *jadard = panel_to_jadard(panel); 1426b818c53SJagan Teki const struct drm_display_mode *desc_mode = &jadard->desc->mode; 1436b818c53SJagan Teki struct drm_display_mode *mode; 1446b818c53SJagan Teki 1456b818c53SJagan Teki mode = drm_mode_duplicate(connector->dev, desc_mode); 1466b818c53SJagan Teki if (!mode) { 1476b818c53SJagan Teki DRM_DEV_ERROR(&jadard->dsi->dev, "failed to add mode %ux%ux@%u\n", 1486b818c53SJagan Teki desc_mode->hdisplay, desc_mode->vdisplay, 1496b818c53SJagan Teki drm_mode_vrefresh(desc_mode)); 1506b818c53SJagan Teki return -ENOMEM; 1516b818c53SJagan Teki } 1526b818c53SJagan Teki 1536b818c53SJagan Teki drm_mode_set_name(mode); 1546b818c53SJagan Teki drm_mode_probed_add(connector, mode); 1556b818c53SJagan Teki 1566b818c53SJagan Teki connector->display_info.width_mm = mode->width_mm; 1576b818c53SJagan Teki connector->display_info.height_mm = mode->height_mm; 1586b818c53SJagan Teki 1596b818c53SJagan Teki return 1; 1606b818c53SJagan Teki } 1616b818c53SJagan Teki 1626b818c53SJagan Teki static const struct drm_panel_funcs jadard_funcs = { 1636b818c53SJagan Teki .disable = jadard_disable, 1646b818c53SJagan Teki .unprepare = jadard_unprepare, 1656b818c53SJagan Teki .prepare = jadard_prepare, 1666b818c53SJagan Teki .enable = jadard_enable, 1676b818c53SJagan Teki .get_modes = jadard_get_modes, 1686b818c53SJagan Teki }; 1696b818c53SJagan Teki 170413ebc48SJagan Teki static const struct jadard_init_cmd radxa_display_8hd_ad002_init_cmds[] = { 171413ebc48SJagan Teki { .data = { 0xE0, 0x00 } }, 172413ebc48SJagan Teki { .data = { 0xE1, 0x93 } }, 173413ebc48SJagan Teki { .data = { 0xE2, 0x65 } }, 174413ebc48SJagan Teki { .data = { 0xE3, 0xF8 } }, 175413ebc48SJagan Teki { .data = { 0x80, 0x03 } }, 176413ebc48SJagan Teki { .data = { 0xE0, 0x01 } }, 177413ebc48SJagan Teki { .data = { 0x00, 0x00 } }, 178413ebc48SJagan Teki { .data = { 0x01, 0x7E } }, 179413ebc48SJagan Teki { .data = { 0x03, 0x00 } }, 180413ebc48SJagan Teki { .data = { 0x04, 0x65 } }, 181413ebc48SJagan Teki { .data = { 0x0C, 0x74 } }, 182413ebc48SJagan Teki { .data = { 0x17, 0x00 } }, 183413ebc48SJagan Teki { .data = { 0x18, 0xB7 } }, 184413ebc48SJagan Teki { .data = { 0x19, 0x00 } }, 185413ebc48SJagan Teki { .data = { 0x1A, 0x00 } }, 186413ebc48SJagan Teki { .data = { 0x1B, 0xB7 } }, 187413ebc48SJagan Teki { .data = { 0x1C, 0x00 } }, 188413ebc48SJagan Teki { .data = { 0x24, 0xFE } }, 189413ebc48SJagan Teki { .data = { 0x37, 0x19 } }, 190413ebc48SJagan Teki { .data = { 0x38, 0x05 } }, 191413ebc48SJagan Teki { .data = { 0x39, 0x00 } }, 192413ebc48SJagan Teki { .data = { 0x3A, 0x01 } }, 193413ebc48SJagan Teki { .data = { 0x3B, 0x01 } }, 194413ebc48SJagan Teki { .data = { 0x3C, 0x70 } }, 195413ebc48SJagan Teki { .data = { 0x3D, 0xFF } }, 196413ebc48SJagan Teki { .data = { 0x3E, 0xFF } }, 197413ebc48SJagan Teki { .data = { 0x3F, 0xFF } }, 198413ebc48SJagan Teki { .data = { 0x40, 0x06 } }, 199413ebc48SJagan Teki { .data = { 0x41, 0xA0 } }, 200413ebc48SJagan Teki { .data = { 0x43, 0x1E } }, 201413ebc48SJagan Teki { .data = { 0x44, 0x0F } }, 202413ebc48SJagan Teki { .data = { 0x45, 0x28 } }, 203413ebc48SJagan Teki { .data = { 0x4B, 0x04 } }, 204413ebc48SJagan Teki { .data = { 0x55, 0x02 } }, 205413ebc48SJagan Teki { .data = { 0x56, 0x01 } }, 206413ebc48SJagan Teki { .data = { 0x57, 0xA9 } }, 207413ebc48SJagan Teki { .data = { 0x58, 0x0A } }, 208413ebc48SJagan Teki { .data = { 0x59, 0x0A } }, 209413ebc48SJagan Teki { .data = { 0x5A, 0x37 } }, 210413ebc48SJagan Teki { .data = { 0x5B, 0x19 } }, 211413ebc48SJagan Teki { .data = { 0x5D, 0x78 } }, 212413ebc48SJagan Teki { .data = { 0x5E, 0x63 } }, 213413ebc48SJagan Teki { .data = { 0x5F, 0x54 } }, 214413ebc48SJagan Teki { .data = { 0x60, 0x49 } }, 215413ebc48SJagan Teki { .data = { 0x61, 0x45 } }, 216413ebc48SJagan Teki { .data = { 0x62, 0x38 } }, 217413ebc48SJagan Teki { .data = { 0x63, 0x3D } }, 218413ebc48SJagan Teki { .data = { 0x64, 0x28 } }, 219413ebc48SJagan Teki { .data = { 0x65, 0x43 } }, 220413ebc48SJagan Teki { .data = { 0x66, 0x41 } }, 221413ebc48SJagan Teki { .data = { 0x67, 0x43 } }, 222413ebc48SJagan Teki { .data = { 0x68, 0x62 } }, 223413ebc48SJagan Teki { .data = { 0x69, 0x50 } }, 224413ebc48SJagan Teki { .data = { 0x6A, 0x57 } }, 225413ebc48SJagan Teki { .data = { 0x6B, 0x49 } }, 226413ebc48SJagan Teki { .data = { 0x6C, 0x44 } }, 227413ebc48SJagan Teki { .data = { 0x6D, 0x37 } }, 228413ebc48SJagan Teki { .data = { 0x6E, 0x23 } }, 229413ebc48SJagan Teki { .data = { 0x6F, 0x10 } }, 230413ebc48SJagan Teki { .data = { 0x70, 0x78 } }, 231413ebc48SJagan Teki { .data = { 0x71, 0x63 } }, 232413ebc48SJagan Teki { .data = { 0x72, 0x54 } }, 233413ebc48SJagan Teki { .data = { 0x73, 0x49 } }, 234413ebc48SJagan Teki { .data = { 0x74, 0x45 } }, 235413ebc48SJagan Teki { .data = { 0x75, 0x38 } }, 236413ebc48SJagan Teki { .data = { 0x76, 0x3D } }, 237413ebc48SJagan Teki { .data = { 0x77, 0x28 } }, 238413ebc48SJagan Teki { .data = { 0x78, 0x43 } }, 239413ebc48SJagan Teki { .data = { 0x79, 0x41 } }, 240413ebc48SJagan Teki { .data = { 0x7A, 0x43 } }, 241413ebc48SJagan Teki { .data = { 0x7B, 0x62 } }, 242413ebc48SJagan Teki { .data = { 0x7C, 0x50 } }, 243413ebc48SJagan Teki { .data = { 0x7D, 0x57 } }, 244413ebc48SJagan Teki { .data = { 0x7E, 0x49 } }, 245413ebc48SJagan Teki { .data = { 0x7F, 0x44 } }, 246413ebc48SJagan Teki { .data = { 0x80, 0x37 } }, 247413ebc48SJagan Teki { .data = { 0x81, 0x23 } }, 248413ebc48SJagan Teki { .data = { 0x82, 0x10 } }, 249413ebc48SJagan Teki { .data = { 0xE0, 0x02 } }, 250413ebc48SJagan Teki { .data = { 0x00, 0x47 } }, 251413ebc48SJagan Teki { .data = { 0x01, 0x47 } }, 252413ebc48SJagan Teki { .data = { 0x02, 0x45 } }, 253413ebc48SJagan Teki { .data = { 0x03, 0x45 } }, 254413ebc48SJagan Teki { .data = { 0x04, 0x4B } }, 255413ebc48SJagan Teki { .data = { 0x05, 0x4B } }, 256413ebc48SJagan Teki { .data = { 0x06, 0x49 } }, 257413ebc48SJagan Teki { .data = { 0x07, 0x49 } }, 258413ebc48SJagan Teki { .data = { 0x08, 0x41 } }, 259413ebc48SJagan Teki { .data = { 0x09, 0x1F } }, 260413ebc48SJagan Teki { .data = { 0x0A, 0x1F } }, 261413ebc48SJagan Teki { .data = { 0x0B, 0x1F } }, 262413ebc48SJagan Teki { .data = { 0x0C, 0x1F } }, 263413ebc48SJagan Teki { .data = { 0x0D, 0x1F } }, 264413ebc48SJagan Teki { .data = { 0x0E, 0x1F } }, 265413ebc48SJagan Teki { .data = { 0x0F, 0x5F } }, 266413ebc48SJagan Teki { .data = { 0x10, 0x5F } }, 267413ebc48SJagan Teki { .data = { 0x11, 0x57 } }, 268413ebc48SJagan Teki { .data = { 0x12, 0x77 } }, 269413ebc48SJagan Teki { .data = { 0x13, 0x35 } }, 270413ebc48SJagan Teki { .data = { 0x14, 0x1F } }, 271413ebc48SJagan Teki { .data = { 0x15, 0x1F } }, 272413ebc48SJagan Teki { .data = { 0x16, 0x46 } }, 273413ebc48SJagan Teki { .data = { 0x17, 0x46 } }, 274413ebc48SJagan Teki { .data = { 0x18, 0x44 } }, 275413ebc48SJagan Teki { .data = { 0x19, 0x44 } }, 276413ebc48SJagan Teki { .data = { 0x1A, 0x4A } }, 277413ebc48SJagan Teki { .data = { 0x1B, 0x4A } }, 278413ebc48SJagan Teki { .data = { 0x1C, 0x48 } }, 279413ebc48SJagan Teki { .data = { 0x1D, 0x48 } }, 280413ebc48SJagan Teki { .data = { 0x1E, 0x40 } }, 281413ebc48SJagan Teki { .data = { 0x1F, 0x1F } }, 282413ebc48SJagan Teki { .data = { 0x20, 0x1F } }, 283413ebc48SJagan Teki { .data = { 0x21, 0x1F } }, 284413ebc48SJagan Teki { .data = { 0x22, 0x1F } }, 285413ebc48SJagan Teki { .data = { 0x23, 0x1F } }, 286413ebc48SJagan Teki { .data = { 0x24, 0x1F } }, 287413ebc48SJagan Teki { .data = { 0x25, 0x5F } }, 288413ebc48SJagan Teki { .data = { 0x26, 0x5F } }, 289413ebc48SJagan Teki { .data = { 0x27, 0x57 } }, 290413ebc48SJagan Teki { .data = { 0x28, 0x77 } }, 291413ebc48SJagan Teki { .data = { 0x29, 0x35 } }, 292413ebc48SJagan Teki { .data = { 0x2A, 0x1F } }, 293413ebc48SJagan Teki { .data = { 0x2B, 0x1F } }, 294413ebc48SJagan Teki { .data = { 0x58, 0x40 } }, 295413ebc48SJagan Teki { .data = { 0x59, 0x00 } }, 296413ebc48SJagan Teki { .data = { 0x5A, 0x00 } }, 297413ebc48SJagan Teki { .data = { 0x5B, 0x10 } }, 298413ebc48SJagan Teki { .data = { 0x5C, 0x06 } }, 299413ebc48SJagan Teki { .data = { 0x5D, 0x40 } }, 300413ebc48SJagan Teki { .data = { 0x5E, 0x01 } }, 301413ebc48SJagan Teki { .data = { 0x5F, 0x02 } }, 302413ebc48SJagan Teki { .data = { 0x60, 0x30 } }, 303413ebc48SJagan Teki { .data = { 0x61, 0x01 } }, 304413ebc48SJagan Teki { .data = { 0x62, 0x02 } }, 305413ebc48SJagan Teki { .data = { 0x63, 0x03 } }, 306413ebc48SJagan Teki { .data = { 0x64, 0x6B } }, 307413ebc48SJagan Teki { .data = { 0x65, 0x05 } }, 308413ebc48SJagan Teki { .data = { 0x66, 0x0C } }, 309413ebc48SJagan Teki { .data = { 0x67, 0x73 } }, 310413ebc48SJagan Teki { .data = { 0x68, 0x09 } }, 311413ebc48SJagan Teki { .data = { 0x69, 0x03 } }, 312413ebc48SJagan Teki { .data = { 0x6A, 0x56 } }, 313413ebc48SJagan Teki { .data = { 0x6B, 0x08 } }, 314413ebc48SJagan Teki { .data = { 0x6C, 0x00 } }, 315413ebc48SJagan Teki { .data = { 0x6D, 0x04 } }, 316413ebc48SJagan Teki { .data = { 0x6E, 0x04 } }, 317413ebc48SJagan Teki { .data = { 0x6F, 0x88 } }, 318413ebc48SJagan Teki { .data = { 0x70, 0x00 } }, 319413ebc48SJagan Teki { .data = { 0x71, 0x00 } }, 320413ebc48SJagan Teki { .data = { 0x72, 0x06 } }, 321413ebc48SJagan Teki { .data = { 0x73, 0x7B } }, 322413ebc48SJagan Teki { .data = { 0x74, 0x00 } }, 323413ebc48SJagan Teki { .data = { 0x75, 0xF8 } }, 324413ebc48SJagan Teki { .data = { 0x76, 0x00 } }, 325413ebc48SJagan Teki { .data = { 0x77, 0xD5 } }, 326413ebc48SJagan Teki { .data = { 0x78, 0x2E } }, 327413ebc48SJagan Teki { .data = { 0x79, 0x12 } }, 328413ebc48SJagan Teki { .data = { 0x7A, 0x03 } }, 329413ebc48SJagan Teki { .data = { 0x7B, 0x00 } }, 330413ebc48SJagan Teki { .data = { 0x7C, 0x00 } }, 331413ebc48SJagan Teki { .data = { 0x7D, 0x03 } }, 332413ebc48SJagan Teki { .data = { 0x7E, 0x7B } }, 333413ebc48SJagan Teki { .data = { 0xE0, 0x04 } }, 334413ebc48SJagan Teki { .data = { 0x00, 0x0E } }, 335413ebc48SJagan Teki { .data = { 0x02, 0xB3 } }, 336413ebc48SJagan Teki { .data = { 0x09, 0x60 } }, 337413ebc48SJagan Teki { .data = { 0x0E, 0x2A } }, 338413ebc48SJagan Teki { .data = { 0x36, 0x59 } }, 339413ebc48SJagan Teki { .data = { 0xE0, 0x00 } }, 340413ebc48SJagan Teki }; 341413ebc48SJagan Teki 342413ebc48SJagan Teki static const struct jadard_panel_desc radxa_display_8hd_ad002_desc = { 343413ebc48SJagan Teki .mode = { 344413ebc48SJagan Teki .clock = 70000, 345413ebc48SJagan Teki 346413ebc48SJagan Teki .hdisplay = 800, 347413ebc48SJagan Teki .hsync_start = 800 + 40, 348413ebc48SJagan Teki .hsync_end = 800 + 40 + 18, 349413ebc48SJagan Teki .htotal = 800 + 40 + 18 + 20, 350413ebc48SJagan Teki 351413ebc48SJagan Teki .vdisplay = 1280, 352413ebc48SJagan Teki .vsync_start = 1280 + 20, 353413ebc48SJagan Teki .vsync_end = 1280 + 20 + 4, 354413ebc48SJagan Teki .vtotal = 1280 + 20 + 4 + 20, 355413ebc48SJagan Teki 356413ebc48SJagan Teki .width_mm = 127, 357413ebc48SJagan Teki .height_mm = 199, 358413ebc48SJagan Teki .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, 359413ebc48SJagan Teki }, 360413ebc48SJagan Teki .lanes = 4, 361413ebc48SJagan Teki .format = MIPI_DSI_FMT_RGB888, 362413ebc48SJagan Teki .init_cmds = radxa_display_8hd_ad002_init_cmds, 363413ebc48SJagan Teki .num_init_cmds = ARRAY_SIZE(radxa_display_8hd_ad002_init_cmds), 364413ebc48SJagan Teki }; 365413ebc48SJagan Teki 3666b818c53SJagan Teki static const struct jadard_init_cmd cz101b4001_init_cmds[] = { 3676b818c53SJagan Teki { .data = { 0xE0, 0x00 } }, 3686b818c53SJagan Teki { .data = { 0xE1, 0x93 } }, 3696b818c53SJagan Teki { .data = { 0xE2, 0x65 } }, 3706b818c53SJagan Teki { .data = { 0xE3, 0xF8 } }, 3716b818c53SJagan Teki { .data = { 0x80, 0x03 } }, 3726b818c53SJagan Teki { .data = { 0xE0, 0x01 } }, 3736b818c53SJagan Teki { .data = { 0x00, 0x00 } }, 3746b818c53SJagan Teki { .data = { 0x01, 0x3B } }, 3756b818c53SJagan Teki { .data = { 0x0C, 0x74 } }, 3766b818c53SJagan Teki { .data = { 0x17, 0x00 } }, 3776b818c53SJagan Teki { .data = { 0x18, 0xAF } }, 3786b818c53SJagan Teki { .data = { 0x19, 0x00 } }, 3796b818c53SJagan Teki { .data = { 0x1A, 0x00 } }, 3806b818c53SJagan Teki { .data = { 0x1B, 0xAF } }, 3816b818c53SJagan Teki { .data = { 0x1C, 0x00 } }, 3826b818c53SJagan Teki { .data = { 0x35, 0x26 } }, 3836b818c53SJagan Teki { .data = { 0x37, 0x09 } }, 3846b818c53SJagan Teki { .data = { 0x38, 0x04 } }, 3856b818c53SJagan Teki { .data = { 0x39, 0x00 } }, 3866b818c53SJagan Teki { .data = { 0x3A, 0x01 } }, 3876b818c53SJagan Teki { .data = { 0x3C, 0x78 } }, 3886b818c53SJagan Teki { .data = { 0x3D, 0xFF } }, 3896b818c53SJagan Teki { .data = { 0x3E, 0xFF } }, 3906b818c53SJagan Teki { .data = { 0x3F, 0x7F } }, 3916b818c53SJagan Teki { .data = { 0x40, 0x06 } }, 3926b818c53SJagan Teki { .data = { 0x41, 0xA0 } }, 3936b818c53SJagan Teki { .data = { 0x42, 0x81 } }, 3946b818c53SJagan Teki { .data = { 0x43, 0x14 } }, 3956b818c53SJagan Teki { .data = { 0x44, 0x23 } }, 3966b818c53SJagan Teki { .data = { 0x45, 0x28 } }, 3976b818c53SJagan Teki { .data = { 0x55, 0x02 } }, 3986b818c53SJagan Teki { .data = { 0x57, 0x69 } }, 3996b818c53SJagan Teki { .data = { 0x59, 0x0A } }, 4006b818c53SJagan Teki { .data = { 0x5A, 0x2A } }, 4016b818c53SJagan Teki { .data = { 0x5B, 0x17 } }, 4026b818c53SJagan Teki { .data = { 0x5D, 0x7F } }, 4036b818c53SJagan Teki { .data = { 0x5E, 0x6B } }, 4046b818c53SJagan Teki { .data = { 0x5F, 0x5C } }, 4056b818c53SJagan Teki { .data = { 0x60, 0x4F } }, 4066b818c53SJagan Teki { .data = { 0x61, 0x4D } }, 4076b818c53SJagan Teki { .data = { 0x62, 0x3F } }, 4086b818c53SJagan Teki { .data = { 0x63, 0x42 } }, 4096b818c53SJagan Teki { .data = { 0x64, 0x2B } }, 4106b818c53SJagan Teki { .data = { 0x65, 0x44 } }, 4116b818c53SJagan Teki { .data = { 0x66, 0x43 } }, 4126b818c53SJagan Teki { .data = { 0x67, 0x43 } }, 4136b818c53SJagan Teki { .data = { 0x68, 0x63 } }, 4146b818c53SJagan Teki { .data = { 0x69, 0x52 } }, 4156b818c53SJagan Teki { .data = { 0x6A, 0x5A } }, 4166b818c53SJagan Teki { .data = { 0x6B, 0x4F } }, 4176b818c53SJagan Teki { .data = { 0x6C, 0x4E } }, 4186b818c53SJagan Teki { .data = { 0x6D, 0x20 } }, 4196b818c53SJagan Teki { .data = { 0x6E, 0x0F } }, 4206b818c53SJagan Teki { .data = { 0x6F, 0x00 } }, 4216b818c53SJagan Teki { .data = { 0x70, 0x7F } }, 4226b818c53SJagan Teki { .data = { 0x71, 0x6B } }, 4236b818c53SJagan Teki { .data = { 0x72, 0x5C } }, 4246b818c53SJagan Teki { .data = { 0x73, 0x4F } }, 4256b818c53SJagan Teki { .data = { 0x74, 0x4D } }, 4266b818c53SJagan Teki { .data = { 0x75, 0x3F } }, 4276b818c53SJagan Teki { .data = { 0x76, 0x42 } }, 4286b818c53SJagan Teki { .data = { 0x77, 0x2B } }, 4296b818c53SJagan Teki { .data = { 0x78, 0x44 } }, 4306b818c53SJagan Teki { .data = { 0x79, 0x43 } }, 4316b818c53SJagan Teki { .data = { 0x7A, 0x43 } }, 4326b818c53SJagan Teki { .data = { 0x7B, 0x63 } }, 4336b818c53SJagan Teki { .data = { 0x7C, 0x52 } }, 4346b818c53SJagan Teki { .data = { 0x7D, 0x5A } }, 4356b818c53SJagan Teki { .data = { 0x7E, 0x4F } }, 4366b818c53SJagan Teki { .data = { 0x7F, 0x4E } }, 4376b818c53SJagan Teki { .data = { 0x80, 0x20 } }, 4386b818c53SJagan Teki { .data = { 0x81, 0x0F } }, 4396b818c53SJagan Teki { .data = { 0x82, 0x00 } }, 4406b818c53SJagan Teki { .data = { 0xE0, 0x02 } }, 4416b818c53SJagan Teki { .data = { 0x00, 0x02 } }, 4426b818c53SJagan Teki { .data = { 0x01, 0x02 } }, 4436b818c53SJagan Teki { .data = { 0x02, 0x00 } }, 4446b818c53SJagan Teki { .data = { 0x03, 0x00 } }, 4456b818c53SJagan Teki { .data = { 0x04, 0x1E } }, 4466b818c53SJagan Teki { .data = { 0x05, 0x1E } }, 4476b818c53SJagan Teki { .data = { 0x06, 0x1F } }, 4486b818c53SJagan Teki { .data = { 0x07, 0x1F } }, 4496b818c53SJagan Teki { .data = { 0x08, 0x1F } }, 4506b818c53SJagan Teki { .data = { 0x09, 0x17 } }, 4516b818c53SJagan Teki { .data = { 0x0A, 0x17 } }, 4526b818c53SJagan Teki { .data = { 0x0B, 0x37 } }, 4536b818c53SJagan Teki { .data = { 0x0C, 0x37 } }, 4546b818c53SJagan Teki { .data = { 0x0D, 0x47 } }, 4556b818c53SJagan Teki { .data = { 0x0E, 0x47 } }, 4566b818c53SJagan Teki { .data = { 0x0F, 0x45 } }, 4576b818c53SJagan Teki { .data = { 0x10, 0x45 } }, 4586b818c53SJagan Teki { .data = { 0x11, 0x4B } }, 4596b818c53SJagan Teki { .data = { 0x12, 0x4B } }, 4606b818c53SJagan Teki { .data = { 0x13, 0x49 } }, 4616b818c53SJagan Teki { .data = { 0x14, 0x49 } }, 4626b818c53SJagan Teki { .data = { 0x15, 0x1F } }, 4636b818c53SJagan Teki { .data = { 0x16, 0x01 } }, 4646b818c53SJagan Teki { .data = { 0x17, 0x01 } }, 4656b818c53SJagan Teki { .data = { 0x18, 0x00 } }, 4666b818c53SJagan Teki { .data = { 0x19, 0x00 } }, 4676b818c53SJagan Teki { .data = { 0x1A, 0x1E } }, 4686b818c53SJagan Teki { .data = { 0x1B, 0x1E } }, 4696b818c53SJagan Teki { .data = { 0x1C, 0x1F } }, 4706b818c53SJagan Teki { .data = { 0x1D, 0x1F } }, 4716b818c53SJagan Teki { .data = { 0x1E, 0x1F } }, 4726b818c53SJagan Teki { .data = { 0x1F, 0x17 } }, 4736b818c53SJagan Teki { .data = { 0x20, 0x17 } }, 4746b818c53SJagan Teki { .data = { 0x21, 0x37 } }, 4756b818c53SJagan Teki { .data = { 0x22, 0x37 } }, 4766b818c53SJagan Teki { .data = { 0x23, 0x46 } }, 4776b818c53SJagan Teki { .data = { 0x24, 0x46 } }, 4786b818c53SJagan Teki { .data = { 0x25, 0x44 } }, 4796b818c53SJagan Teki { .data = { 0x26, 0x44 } }, 4806b818c53SJagan Teki { .data = { 0x27, 0x4A } }, 4816b818c53SJagan Teki { .data = { 0x28, 0x4A } }, 4826b818c53SJagan Teki { .data = { 0x29, 0x48 } }, 4836b818c53SJagan Teki { .data = { 0x2A, 0x48 } }, 4846b818c53SJagan Teki { .data = { 0x2B, 0x1F } }, 4856b818c53SJagan Teki { .data = { 0x2C, 0x01 } }, 4866b818c53SJagan Teki { .data = { 0x2D, 0x01 } }, 4876b818c53SJagan Teki { .data = { 0x2E, 0x00 } }, 4886b818c53SJagan Teki { .data = { 0x2F, 0x00 } }, 4896b818c53SJagan Teki { .data = { 0x30, 0x1F } }, 4906b818c53SJagan Teki { .data = { 0x31, 0x1F } }, 4916b818c53SJagan Teki { .data = { 0x32, 0x1E } }, 4926b818c53SJagan Teki { .data = { 0x33, 0x1E } }, 4936b818c53SJagan Teki { .data = { 0x34, 0x1F } }, 4946b818c53SJagan Teki { .data = { 0x35, 0x17 } }, 4956b818c53SJagan Teki { .data = { 0x36, 0x17 } }, 4966b818c53SJagan Teki { .data = { 0x37, 0x37 } }, 4976b818c53SJagan Teki { .data = { 0x38, 0x37 } }, 4986b818c53SJagan Teki { .data = { 0x39, 0x08 } }, 4996b818c53SJagan Teki { .data = { 0x3A, 0x08 } }, 5006b818c53SJagan Teki { .data = { 0x3B, 0x0A } }, 5016b818c53SJagan Teki { .data = { 0x3C, 0x0A } }, 5026b818c53SJagan Teki { .data = { 0x3D, 0x04 } }, 5036b818c53SJagan Teki { .data = { 0x3E, 0x04 } }, 5046b818c53SJagan Teki { .data = { 0x3F, 0x06 } }, 5056b818c53SJagan Teki { .data = { 0x40, 0x06 } }, 5066b818c53SJagan Teki { .data = { 0x41, 0x1F } }, 5076b818c53SJagan Teki { .data = { 0x42, 0x02 } }, 5086b818c53SJagan Teki { .data = { 0x43, 0x02 } }, 5096b818c53SJagan Teki { .data = { 0x44, 0x00 } }, 5106b818c53SJagan Teki { .data = { 0x45, 0x00 } }, 5116b818c53SJagan Teki { .data = { 0x46, 0x1F } }, 5126b818c53SJagan Teki { .data = { 0x47, 0x1F } }, 5136b818c53SJagan Teki { .data = { 0x48, 0x1E } }, 5146b818c53SJagan Teki { .data = { 0x49, 0x1E } }, 5156b818c53SJagan Teki { .data = { 0x4A, 0x1F } }, 5166b818c53SJagan Teki { .data = { 0x4B, 0x17 } }, 5176b818c53SJagan Teki { .data = { 0x4C, 0x17 } }, 5186b818c53SJagan Teki { .data = { 0x4D, 0x37 } }, 5196b818c53SJagan Teki { .data = { 0x4E, 0x37 } }, 5206b818c53SJagan Teki { .data = { 0x4F, 0x09 } }, 5216b818c53SJagan Teki { .data = { 0x50, 0x09 } }, 5226b818c53SJagan Teki { .data = { 0x51, 0x0B } }, 5236b818c53SJagan Teki { .data = { 0x52, 0x0B } }, 5246b818c53SJagan Teki { .data = { 0x53, 0x05 } }, 5256b818c53SJagan Teki { .data = { 0x54, 0x05 } }, 5266b818c53SJagan Teki { .data = { 0x55, 0x07 } }, 5276b818c53SJagan Teki { .data = { 0x56, 0x07 } }, 5286b818c53SJagan Teki { .data = { 0x57, 0x1F } }, 5296b818c53SJagan Teki { .data = { 0x58, 0x40 } }, 5306b818c53SJagan Teki { .data = { 0x5B, 0x30 } }, 5316b818c53SJagan Teki { .data = { 0x5C, 0x16 } }, 5326b818c53SJagan Teki { .data = { 0x5D, 0x34 } }, 5336b818c53SJagan Teki { .data = { 0x5E, 0x05 } }, 5346b818c53SJagan Teki { .data = { 0x5F, 0x02 } }, 5356b818c53SJagan Teki { .data = { 0x63, 0x00 } }, 5366b818c53SJagan Teki { .data = { 0x64, 0x6A } }, 5376b818c53SJagan Teki { .data = { 0x67, 0x73 } }, 5386b818c53SJagan Teki { .data = { 0x68, 0x1D } }, 5396b818c53SJagan Teki { .data = { 0x69, 0x08 } }, 5406b818c53SJagan Teki { .data = { 0x6A, 0x6A } }, 5416b818c53SJagan Teki { .data = { 0x6B, 0x08 } }, 5426b818c53SJagan Teki { .data = { 0x6C, 0x00 } }, 5436b818c53SJagan Teki { .data = { 0x6D, 0x00 } }, 5446b818c53SJagan Teki { .data = { 0x6E, 0x00 } }, 5456b818c53SJagan Teki { .data = { 0x6F, 0x88 } }, 5466b818c53SJagan Teki { .data = { 0x75, 0xFF } }, 5476b818c53SJagan Teki { .data = { 0x77, 0xDD } }, 5486b818c53SJagan Teki { .data = { 0x78, 0x3F } }, 5496b818c53SJagan Teki { .data = { 0x79, 0x15 } }, 5506b818c53SJagan Teki { .data = { 0x7A, 0x17 } }, 5516b818c53SJagan Teki { .data = { 0x7D, 0x14 } }, 5526b818c53SJagan Teki { .data = { 0x7E, 0x82 } }, 5536b818c53SJagan Teki { .data = { 0xE0, 0x04 } }, 5546b818c53SJagan Teki { .data = { 0x00, 0x0E } }, 5556b818c53SJagan Teki { .data = { 0x02, 0xB3 } }, 5566b818c53SJagan Teki { .data = { 0x09, 0x61 } }, 5576b818c53SJagan Teki { .data = { 0x0E, 0x48 } }, 5586b818c53SJagan Teki { .data = { 0xE0, 0x00 } }, 5596b818c53SJagan Teki { .data = { 0xE6, 0x02 } }, 5606b818c53SJagan Teki { .data = { 0xE7, 0x0C } }, 5616b818c53SJagan Teki }; 5626b818c53SJagan Teki 5636b818c53SJagan Teki static const struct jadard_panel_desc cz101b4001_desc = { 5646b818c53SJagan Teki .mode = { 5656b818c53SJagan Teki .clock = 70000, 5666b818c53SJagan Teki 5676b818c53SJagan Teki .hdisplay = 800, 5686b818c53SJagan Teki .hsync_start = 800 + 40, 5696b818c53SJagan Teki .hsync_end = 800 + 40 + 18, 5706b818c53SJagan Teki .htotal = 800 + 40 + 18 + 20, 5716b818c53SJagan Teki 5726b818c53SJagan Teki .vdisplay = 1280, 5736b818c53SJagan Teki .vsync_start = 1280 + 20, 5746b818c53SJagan Teki .vsync_end = 1280 + 20 + 4, 5756b818c53SJagan Teki .vtotal = 1280 + 20 + 4 + 20, 5766b818c53SJagan Teki 5776b818c53SJagan Teki .width_mm = 62, 5786b818c53SJagan Teki .height_mm = 110, 5796b818c53SJagan Teki .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, 5806b818c53SJagan Teki }, 5816b818c53SJagan Teki .lanes = 4, 5826b818c53SJagan Teki .format = MIPI_DSI_FMT_RGB888, 5836b818c53SJagan Teki .init_cmds = cz101b4001_init_cmds, 5846b818c53SJagan Teki .num_init_cmds = ARRAY_SIZE(cz101b4001_init_cmds), 5856b818c53SJagan Teki }; 5866b818c53SJagan Teki 5876b818c53SJagan Teki static int jadard_dsi_probe(struct mipi_dsi_device *dsi) 5886b818c53SJagan Teki { 5896b818c53SJagan Teki struct device *dev = &dsi->dev; 5906b818c53SJagan Teki const struct jadard_panel_desc *desc; 5916b818c53SJagan Teki struct jadard *jadard; 5926b818c53SJagan Teki int ret; 5936b818c53SJagan Teki 5946b818c53SJagan Teki jadard = devm_kzalloc(&dsi->dev, sizeof(*jadard), GFP_KERNEL); 5956b818c53SJagan Teki if (!jadard) 5966b818c53SJagan Teki return -ENOMEM; 5976b818c53SJagan Teki 5986b818c53SJagan Teki desc = of_device_get_match_data(dev); 5996b818c53SJagan Teki dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | 6006b818c53SJagan Teki MIPI_DSI_MODE_NO_EOT_PACKET; 6016b818c53SJagan Teki dsi->format = desc->format; 6026b818c53SJagan Teki dsi->lanes = desc->lanes; 6036b818c53SJagan Teki 6046b818c53SJagan Teki jadard->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); 6056b818c53SJagan Teki if (IS_ERR(jadard->reset)) { 6066b818c53SJagan Teki DRM_DEV_ERROR(&dsi->dev, "failed to get our reset GPIO\n"); 6076b818c53SJagan Teki return PTR_ERR(jadard->reset); 6086b818c53SJagan Teki } 6096b818c53SJagan Teki 6106b818c53SJagan Teki jadard->vdd = devm_regulator_get(dev, "vdd"); 6116b818c53SJagan Teki if (IS_ERR(jadard->vdd)) { 6126b818c53SJagan Teki DRM_DEV_ERROR(&dsi->dev, "failed to get vdd regulator\n"); 6136b818c53SJagan Teki return PTR_ERR(jadard->vdd); 6146b818c53SJagan Teki } 6156b818c53SJagan Teki 6166b818c53SJagan Teki jadard->vccio = devm_regulator_get(dev, "vccio"); 6176b818c53SJagan Teki if (IS_ERR(jadard->vccio)) { 6186b818c53SJagan Teki DRM_DEV_ERROR(&dsi->dev, "failed to get vccio regulator\n"); 6196b818c53SJagan Teki return PTR_ERR(jadard->vccio); 6206b818c53SJagan Teki } 6216b818c53SJagan Teki 6226b818c53SJagan Teki drm_panel_init(&jadard->panel, dev, &jadard_funcs, 6236b818c53SJagan Teki DRM_MODE_CONNECTOR_DSI); 6246b818c53SJagan Teki 6256b818c53SJagan Teki ret = drm_panel_of_backlight(&jadard->panel); 6266b818c53SJagan Teki if (ret) 6276b818c53SJagan Teki return ret; 6286b818c53SJagan Teki 6296b818c53SJagan Teki drm_panel_add(&jadard->panel); 6306b818c53SJagan Teki 6316b818c53SJagan Teki mipi_dsi_set_drvdata(dsi, jadard); 6326b818c53SJagan Teki jadard->dsi = dsi; 6336b818c53SJagan Teki jadard->desc = desc; 6346b818c53SJagan Teki 6356b818c53SJagan Teki ret = mipi_dsi_attach(dsi); 6366b818c53SJagan Teki if (ret < 0) 6376b818c53SJagan Teki drm_panel_remove(&jadard->panel); 6386b818c53SJagan Teki 6396b818c53SJagan Teki return ret; 6406b818c53SJagan Teki } 6416b818c53SJagan Teki 6426b818c53SJagan Teki static void jadard_dsi_remove(struct mipi_dsi_device *dsi) 6436b818c53SJagan Teki { 6446b818c53SJagan Teki struct jadard *jadard = mipi_dsi_get_drvdata(dsi); 6456b818c53SJagan Teki 6466b818c53SJagan Teki mipi_dsi_detach(dsi); 6476b818c53SJagan Teki drm_panel_remove(&jadard->panel); 6486b818c53SJagan Teki } 6496b818c53SJagan Teki 6506b818c53SJagan Teki static const struct of_device_id jadard_of_match[] = { 65118d2f6d9SJagan Teki { 65218d2f6d9SJagan Teki .compatible = "chongzhou,cz101b4001", 65318d2f6d9SJagan Teki .data = &cz101b4001_desc 65418d2f6d9SJagan Teki }, 65518d2f6d9SJagan Teki { 65618d2f6d9SJagan Teki .compatible = "radxa,display-10hd-ad001", 65718d2f6d9SJagan Teki .data = &cz101b4001_desc 65818d2f6d9SJagan Teki }, 659413ebc48SJagan Teki { 660413ebc48SJagan Teki .compatible = "radxa,display-8hd-ad002", 661413ebc48SJagan Teki .data = &radxa_display_8hd_ad002_desc 662413ebc48SJagan Teki }, 6636b818c53SJagan Teki { /* sentinel */ } 6646b818c53SJagan Teki }; 6656b818c53SJagan Teki MODULE_DEVICE_TABLE(of, jadard_of_match); 6666b818c53SJagan Teki 6676b818c53SJagan Teki static struct mipi_dsi_driver jadard_driver = { 6686b818c53SJagan Teki .probe = jadard_dsi_probe, 6696b818c53SJagan Teki .remove = jadard_dsi_remove, 6706b818c53SJagan Teki .driver = { 6716b818c53SJagan Teki .name = "jadard-jd9365da", 6726b818c53SJagan Teki .of_match_table = jadard_of_match, 6736b818c53SJagan Teki }, 6746b818c53SJagan Teki }; 6756b818c53SJagan Teki module_mipi_dsi_driver(jadard_driver); 6766b818c53SJagan Teki 6776b818c53SJagan Teki MODULE_AUTHOR("Jagan Teki <jagan@edgeble.ai>"); 6786b818c53SJagan Teki MODULE_AUTHOR("Stephen Chen <stephen@radxa.com>"); 6796b818c53SJagan Teki MODULE_DESCRIPTION("Jadard JD9365DA-H3 WXGA DSI panel"); 6806b818c53SJagan Teki MODULE_LICENSE("GPL"); 681