panel-novatek-nt35950.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Novatek NT35950 DriverIC panels driver
  4. *
  5. * Copyright (c) 2021 AngeloGioacchino Del Regno
  6. * <[email protected]>
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/gpio/consumer.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/of_graph.h>
  13. #include <linux/regulator/consumer.h>
  14. #include <drm/drm_connector.h>
  15. #include <drm/drm_crtc.h>
  16. #include <drm/drm_mipi_dsi.h>
  17. #include <drm/drm_modes.h>
  18. #include <drm/drm_panel.h>
  19. #define MCS_CMD_MAUCCTR 0xf0 /* Manufacturer command enable */
  20. #define MCS_PARAM_SCALER_FUNCTION 0x58 /* Scale-up function */
  21. #define MCS_PARAM_SCALEUP_MODE 0xc9
  22. #define MCS_SCALEUP_SIMPLE 0x0
  23. #define MCS_SCALEUP_BILINEAR BIT(0)
  24. #define MCS_SCALEUP_DUPLICATE (BIT(0) | BIT(4))
  25. /* VESA Display Stream Compression param */
  26. #define MCS_PARAM_VESA_DSC_ON 0x03
  27. /* Data Compression mode */
  28. #define MCS_PARAM_DATA_COMPRESSION 0x90
  29. #define MCS_DATA_COMPRESSION_NONE 0x00
  30. #define MCS_DATA_COMPRESSION_FBC 0x02
  31. #define MCS_DATA_COMPRESSION_DSC 0x03
  32. /* Display Output control */
  33. #define MCS_PARAM_DISP_OUTPUT_CTRL 0xb4
  34. #define MCS_DISP_OUT_SRAM_EN BIT(0)
  35. #define MCS_DISP_OUT_VIDEO_MODE BIT(4)
  36. /* VESA Display Stream Compression setting */
  37. #define MCS_PARAM_VESA_DSC_SETTING 0xc0
  38. /* SubPixel Rendering (SPR) */
  39. #define MCS_PARAM_SPR_EN 0xe3
  40. #define MCS_PARAM_SPR_MODE 0xef
  41. #define MCS_SPR_MODE_YYG_RAINBOW_RGB 0x01
  42. #define NT35950_VREG_MAX 4
  43. struct nt35950 {
  44. struct drm_panel panel;
  45. struct drm_connector *connector;
  46. struct mipi_dsi_device *dsi[2];
  47. struct regulator_bulk_data vregs[NT35950_VREG_MAX];
  48. struct gpio_desc *reset_gpio;
  49. const struct nt35950_panel_desc *desc;
  50. int cur_mode;
  51. u8 last_page;
  52. bool prepared;
  53. };
  54. struct nt35950_panel_mode {
  55. const struct drm_display_mode mode;
  56. bool enable_sram;
  57. bool is_video_mode;
  58. u8 scaler_on;
  59. u8 scaler_mode;
  60. u8 compression;
  61. u8 spr_en;
  62. u8 spr_mode;
  63. };
  64. struct nt35950_panel_desc {
  65. const char *model_name;
  66. const struct mipi_dsi_device_info dsi_info;
  67. const struct nt35950_panel_mode *mode_data;
  68. bool is_dual_dsi;
  69. u8 num_lanes;
  70. u8 num_modes;
  71. };
  72. static inline struct nt35950 *to_nt35950(struct drm_panel *panel)
  73. {
  74. return container_of(panel, struct nt35950, panel);
  75. }
  76. #define dsi_dcs_write_seq(dsi, seq...) do { \
  77. static const u8 d[] = { seq }; \
  78. int ret; \
  79. ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \
  80. if (ret < 0) \
  81. return ret; \
  82. } while (0)
  83. static void nt35950_reset(struct nt35950 *nt)
  84. {
  85. gpiod_set_value_cansleep(nt->reset_gpio, 1);
  86. usleep_range(12000, 13000);
  87. gpiod_set_value_cansleep(nt->reset_gpio, 0);
  88. usleep_range(300, 400);
  89. gpiod_set_value_cansleep(nt->reset_gpio, 1);
  90. usleep_range(12000, 13000);
  91. }
  92. /*
  93. * nt35950_set_cmd2_page - Select manufacturer control (CMD2) page
  94. * @nt: Main driver structure
  95. * @page: Page number (0-7)
  96. *
  97. * Return: Number of transferred bytes or negative number on error
  98. */
  99. static int nt35950_set_cmd2_page(struct nt35950 *nt, u8 page)
  100. {
  101. const u8 mauc_cmd2_page[] = { MCS_CMD_MAUCCTR, 0x55, 0xaa, 0x52,
  102. 0x08, page };
  103. int ret;
  104. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], mauc_cmd2_page,
  105. ARRAY_SIZE(mauc_cmd2_page));
  106. if (ret < 0)
  107. return ret;
  108. nt->last_page = page;
  109. return 0;
  110. }
  111. /*
  112. * nt35950_set_data_compression - Set data compression mode
  113. * @nt: Main driver structure
  114. * @comp_mode: Compression mode
  115. *
  116. * Return: Number of transferred bytes or negative number on error
  117. */
  118. static int nt35950_set_data_compression(struct nt35950 *nt, u8 comp_mode)
  119. {
  120. u8 cmd_data_compression[] = { MCS_PARAM_DATA_COMPRESSION, comp_mode };
  121. u8 cmd_vesa_dsc_on[] = { MCS_PARAM_VESA_DSC_ON, !!comp_mode };
  122. u8 cmd_vesa_dsc_setting[] = { MCS_PARAM_VESA_DSC_SETTING, 0x03 };
  123. u8 last_page = nt->last_page;
  124. int ret;
  125. /* Set CMD2 Page 0 if we're not there yet */
  126. if (last_page != 0) {
  127. ret = nt35950_set_cmd2_page(nt, 0);
  128. if (ret < 0)
  129. return ret;
  130. }
  131. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_data_compression,
  132. ARRAY_SIZE(cmd_data_compression));
  133. if (ret < 0)
  134. return ret;
  135. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_vesa_dsc_on,
  136. ARRAY_SIZE(cmd_vesa_dsc_on));
  137. if (ret < 0)
  138. return ret;
  139. /* Set the vesa dsc setting on Page 4 */
  140. ret = nt35950_set_cmd2_page(nt, 4);
  141. if (ret < 0)
  142. return ret;
  143. /* Display Stream Compression setting, always 0x03 */
  144. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_vesa_dsc_setting,
  145. ARRAY_SIZE(cmd_vesa_dsc_setting));
  146. if (ret < 0)
  147. return ret;
  148. /* Get back to the previously set page */
  149. return nt35950_set_cmd2_page(nt, last_page);
  150. }
  151. /*
  152. * nt35950_set_scaler - Enable/disable resolution upscaling
  153. * @nt: Main driver structure
  154. * @scale_up: Scale up function control
  155. *
  156. * Return: Number of transferred bytes or negative number on error
  157. */
  158. static int nt35950_set_scaler(struct nt35950 *nt, u8 scale_up)
  159. {
  160. u8 cmd_scaler[] = { MCS_PARAM_SCALER_FUNCTION, scale_up };
  161. return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_scaler,
  162. ARRAY_SIZE(cmd_scaler));
  163. }
  164. /*
  165. * nt35950_set_scale_mode - Resolution upscaling mode
  166. * @nt: Main driver structure
  167. * @mode: Scaler mode (MCS_DATA_COMPRESSION_*)
  168. *
  169. * Return: Number of transferred bytes or negative number on error
  170. */
  171. static int nt35950_set_scale_mode(struct nt35950 *nt, u8 mode)
  172. {
  173. u8 cmd_scaler[] = { MCS_PARAM_SCALEUP_MODE, mode };
  174. return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_scaler,
  175. ARRAY_SIZE(cmd_scaler));
  176. }
  177. /*
  178. * nt35950_inject_black_image - Display a completely black image
  179. * @nt: Main driver structure
  180. *
  181. * After IC setup, the attached panel may show random data
  182. * due to driveric behavior changes (resolution, compression,
  183. * scaling, etc). This function, called after parameters setup,
  184. * makes the driver ic to output a completely black image to
  185. * the display.
  186. * It makes sense to push a black image before sending the sleep-out
  187. * and display-on commands.
  188. *
  189. * Return: Number of transferred bytes or negative number on error
  190. */
  191. static int nt35950_inject_black_image(struct nt35950 *nt)
  192. {
  193. const u8 cmd0_black_img[] = { 0x6f, 0x01 };
  194. const u8 cmd1_black_img[] = { 0xf3, 0x10 };
  195. u8 cmd_test[] = { 0xff, 0xaa, 0x55, 0xa5, 0x80 };
  196. int ret;
  197. /* Enable test command */
  198. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_test, ARRAY_SIZE(cmd_test));
  199. if (ret < 0)
  200. return ret;
  201. /* Send a black image */
  202. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd0_black_img,
  203. ARRAY_SIZE(cmd0_black_img));
  204. if (ret < 0)
  205. return ret;
  206. ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd1_black_img,
  207. ARRAY_SIZE(cmd1_black_img));
  208. if (ret < 0)
  209. return ret;
  210. /* Disable test command */
  211. cmd_test[ARRAY_SIZE(cmd_test) - 1] = 0x00;
  212. return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_test, ARRAY_SIZE(cmd_test));
  213. }
  214. /*
  215. * nt35950_set_dispout - Set Display Output register parameters
  216. * @nt: Main driver structure
  217. *
  218. * Return: Number of transferred bytes or negative number on error
  219. */
  220. static int nt35950_set_dispout(struct nt35950 *nt)
  221. {
  222. u8 cmd_dispout[] = { MCS_PARAM_DISP_OUTPUT_CTRL, 0x00 };
  223. const struct nt35950_panel_mode *mode_data = nt->desc->mode_data;
  224. if (mode_data[nt->cur_mode].is_video_mode)
  225. cmd_dispout[1] |= MCS_DISP_OUT_VIDEO_MODE;
  226. if (mode_data[nt->cur_mode].enable_sram)
  227. cmd_dispout[1] |= MCS_DISP_OUT_SRAM_EN;
  228. return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_dispout,
  229. ARRAY_SIZE(cmd_dispout));
  230. }
  231. static int nt35950_get_current_mode(struct nt35950 *nt)
  232. {
  233. struct drm_connector *connector = nt->connector;
  234. struct drm_crtc_state *crtc_state;
  235. int i;
  236. /* Return the default (first) mode if no info available yet */
  237. if (!connector->state || !connector->state->crtc)
  238. return 0;
  239. crtc_state = connector->state->crtc->state;
  240. for (i = 0; i < nt->desc->num_modes; i++) {
  241. if (drm_mode_match(&crtc_state->mode,
  242. &nt->desc->mode_data[i].mode,
  243. DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_CLOCK))
  244. return i;
  245. }
  246. return 0;
  247. }
  248. static int nt35950_on(struct nt35950 *nt)
  249. {
  250. const struct nt35950_panel_mode *mode_data = nt->desc->mode_data;
  251. struct mipi_dsi_device *dsi = nt->dsi[0];
  252. struct device *dev = &dsi->dev;
  253. int ret;
  254. nt->cur_mode = nt35950_get_current_mode(nt);
  255. nt->dsi[0]->mode_flags |= MIPI_DSI_MODE_LPM;
  256. nt->dsi[1]->mode_flags |= MIPI_DSI_MODE_LPM;
  257. ret = nt35950_set_cmd2_page(nt, 0);
  258. if (ret < 0)
  259. return ret;
  260. ret = nt35950_set_data_compression(nt, mode_data[nt->cur_mode].compression);
  261. if (ret < 0)
  262. return ret;
  263. ret = nt35950_set_scale_mode(nt, mode_data[nt->cur_mode].scaler_mode);
  264. if (ret < 0)
  265. return ret;
  266. ret = nt35950_set_scaler(nt, mode_data[nt->cur_mode].scaler_on);
  267. if (ret < 0)
  268. return ret;
  269. ret = nt35950_set_dispout(nt);
  270. if (ret < 0)
  271. return ret;
  272. ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
  273. if (ret < 0) {
  274. dev_err(dev, "Failed to set tear on: %d\n", ret);
  275. return ret;
  276. }
  277. ret = mipi_dsi_dcs_set_tear_scanline(dsi, 0);
  278. if (ret < 0) {
  279. dev_err(dev, "Failed to set tear scanline: %d\n", ret);
  280. return ret;
  281. }
  282. /* CMD2 Page 1 */
  283. ret = nt35950_set_cmd2_page(nt, 1);
  284. if (ret < 0)
  285. return ret;
  286. /* Unknown command */
  287. dsi_dcs_write_seq(dsi, 0xd4, 0x88, 0x88);
  288. /* CMD2 Page 7 */
  289. ret = nt35950_set_cmd2_page(nt, 7);
  290. if (ret < 0)
  291. return ret;
  292. /* Enable SubPixel Rendering */
  293. dsi_dcs_write_seq(dsi, MCS_PARAM_SPR_EN, 0x01);
  294. /* SPR Mode: YYG Rainbow-RGB */
  295. dsi_dcs_write_seq(dsi, MCS_PARAM_SPR_MODE, MCS_SPR_MODE_YYG_RAINBOW_RGB);
  296. /* CMD3 */
  297. ret = nt35950_inject_black_image(nt);
  298. if (ret < 0)
  299. return ret;
  300. ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
  301. if (ret < 0)
  302. return ret;
  303. msleep(120);
  304. ret = mipi_dsi_dcs_set_display_on(dsi);
  305. if (ret < 0)
  306. return ret;
  307. msleep(120);
  308. nt->dsi[0]->mode_flags &= ~MIPI_DSI_MODE_LPM;
  309. nt->dsi[1]->mode_flags &= ~MIPI_DSI_MODE_LPM;
  310. return 0;
  311. }
  312. static int nt35950_off(struct nt35950 *nt)
  313. {
  314. struct device *dev = &nt->dsi[0]->dev;
  315. int ret;
  316. ret = mipi_dsi_dcs_set_display_off(nt->dsi[0]);
  317. if (ret < 0) {
  318. dev_err(dev, "Failed to set display off: %d\n", ret);
  319. goto set_lpm;
  320. }
  321. usleep_range(10000, 11000);
  322. ret = mipi_dsi_dcs_enter_sleep_mode(nt->dsi[0]);
  323. if (ret < 0) {
  324. dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
  325. goto set_lpm;
  326. }
  327. msleep(150);
  328. set_lpm:
  329. nt->dsi[0]->mode_flags |= MIPI_DSI_MODE_LPM;
  330. nt->dsi[1]->mode_flags |= MIPI_DSI_MODE_LPM;
  331. return 0;
  332. }
  333. static int nt35950_sharp_init_vregs(struct nt35950 *nt, struct device *dev)
  334. {
  335. int ret;
  336. nt->vregs[0].supply = "vddio";
  337. nt->vregs[1].supply = "avdd";
  338. nt->vregs[2].supply = "avee";
  339. nt->vregs[3].supply = "dvdd";
  340. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(nt->vregs),
  341. nt->vregs);
  342. if (ret < 0)
  343. return ret;
  344. ret = regulator_is_supported_voltage(nt->vregs[0].consumer,
  345. 1750000, 1950000);
  346. if (!ret)
  347. return -EINVAL;
  348. ret = regulator_is_supported_voltage(nt->vregs[1].consumer,
  349. 5200000, 5900000);
  350. if (!ret)
  351. return -EINVAL;
  352. /* AVEE is negative: -5.90V to -5.20V */
  353. ret = regulator_is_supported_voltage(nt->vregs[2].consumer,
  354. 5200000, 5900000);
  355. if (!ret)
  356. return -EINVAL;
  357. ret = regulator_is_supported_voltage(nt->vregs[3].consumer,
  358. 1300000, 1400000);
  359. if (!ret)
  360. return -EINVAL;
  361. return 0;
  362. }
  363. static int nt35950_prepare(struct drm_panel *panel)
  364. {
  365. struct nt35950 *nt = to_nt35950(panel);
  366. struct device *dev = &nt->dsi[0]->dev;
  367. int ret;
  368. if (nt->prepared)
  369. return 0;
  370. ret = regulator_enable(nt->vregs[0].consumer);
  371. if (ret)
  372. return ret;
  373. usleep_range(2000, 5000);
  374. ret = regulator_enable(nt->vregs[3].consumer);
  375. if (ret)
  376. goto end;
  377. usleep_range(15000, 18000);
  378. ret = regulator_enable(nt->vregs[1].consumer);
  379. if (ret)
  380. goto end;
  381. ret = regulator_enable(nt->vregs[2].consumer);
  382. if (ret)
  383. goto end;
  384. usleep_range(12000, 13000);
  385. nt35950_reset(nt);
  386. ret = nt35950_on(nt);
  387. if (ret < 0) {
  388. dev_err(dev, "Failed to initialize panel: %d\n", ret);
  389. goto end;
  390. }
  391. nt->prepared = true;
  392. end:
  393. if (ret < 0) {
  394. regulator_bulk_disable(ARRAY_SIZE(nt->vregs), nt->vregs);
  395. return ret;
  396. }
  397. return 0;
  398. }
  399. static int nt35950_unprepare(struct drm_panel *panel)
  400. {
  401. struct nt35950 *nt = to_nt35950(panel);
  402. struct device *dev = &nt->dsi[0]->dev;
  403. int ret;
  404. if (!nt->prepared)
  405. return 0;
  406. ret = nt35950_off(nt);
  407. if (ret < 0)
  408. dev_err(dev, "Failed to deinitialize panel: %d\n", ret);
  409. gpiod_set_value_cansleep(nt->reset_gpio, 0);
  410. regulator_bulk_disable(ARRAY_SIZE(nt->vregs), nt->vregs);
  411. nt->prepared = false;
  412. return 0;
  413. }
  414. static int nt35950_get_modes(struct drm_panel *panel,
  415. struct drm_connector *connector)
  416. {
  417. struct nt35950 *nt = to_nt35950(panel);
  418. int i;
  419. for (i = 0; i < nt->desc->num_modes; i++) {
  420. struct drm_display_mode *mode;
  421. mode = drm_mode_duplicate(connector->dev,
  422. &nt->desc->mode_data[i].mode);
  423. if (!mode)
  424. return -ENOMEM;
  425. drm_mode_set_name(mode);
  426. mode->type |= DRM_MODE_TYPE_DRIVER;
  427. if (nt->desc->num_modes == 1)
  428. mode->type |= DRM_MODE_TYPE_PREFERRED;
  429. drm_mode_probed_add(connector, mode);
  430. }
  431. connector->display_info.bpc = 8;
  432. connector->display_info.height_mm = nt->desc->mode_data[0].mode.height_mm;
  433. connector->display_info.width_mm = nt->desc->mode_data[0].mode.width_mm;
  434. nt->connector = connector;
  435. return nt->desc->num_modes;
  436. }
  437. static const struct drm_panel_funcs nt35950_panel_funcs = {
  438. .prepare = nt35950_prepare,
  439. .unprepare = nt35950_unprepare,
  440. .get_modes = nt35950_get_modes,
  441. };
  442. static int nt35950_probe(struct mipi_dsi_device *dsi)
  443. {
  444. struct device *dev = &dsi->dev;
  445. struct device_node *dsi_r;
  446. struct mipi_dsi_host *dsi_r_host;
  447. struct nt35950 *nt;
  448. const struct mipi_dsi_device_info *info;
  449. int i, num_dsis = 1, ret;
  450. nt = devm_kzalloc(dev, sizeof(*nt), GFP_KERNEL);
  451. if (!nt)
  452. return -ENOMEM;
  453. ret = nt35950_sharp_init_vregs(nt, dev);
  454. if (ret)
  455. return dev_err_probe(dev, ret, "Regulator init failure.\n");
  456. nt->desc = of_device_get_match_data(dev);
  457. if (!nt->desc)
  458. return -ENODEV;
  459. nt->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
  460. if (IS_ERR(nt->reset_gpio)) {
  461. return dev_err_probe(dev, PTR_ERR(nt->reset_gpio),
  462. "Failed to get reset gpio\n");
  463. }
  464. /* If the panel is connected on two DSIs then DSI0 left, DSI1 right */
  465. if (nt->desc->is_dual_dsi) {
  466. info = &nt->desc->dsi_info;
  467. dsi_r = of_graph_get_remote_node(dsi->dev.of_node, 1, -1);
  468. if (!dsi_r) {
  469. dev_err(dev, "Cannot get secondary DSI node.\n");
  470. return -ENODEV;
  471. }
  472. dsi_r_host = of_find_mipi_dsi_host_by_node(dsi_r);
  473. of_node_put(dsi_r);
  474. if (!dsi_r_host) {
  475. dev_err(dev, "Cannot get secondary DSI host\n");
  476. return -EPROBE_DEFER;
  477. }
  478. nt->dsi[1] = mipi_dsi_device_register_full(dsi_r_host, info);
  479. if (!nt->dsi[1]) {
  480. dev_err(dev, "Cannot get secondary DSI node\n");
  481. return -ENODEV;
  482. }
  483. num_dsis++;
  484. }
  485. nt->dsi[0] = dsi;
  486. mipi_dsi_set_drvdata(dsi, nt);
  487. drm_panel_init(&nt->panel, dev, &nt35950_panel_funcs,
  488. DRM_MODE_CONNECTOR_DSI);
  489. ret = drm_panel_of_backlight(&nt->panel);
  490. if (ret) {
  491. if (num_dsis == 2)
  492. mipi_dsi_device_unregister(nt->dsi[1]);
  493. return dev_err_probe(dev, ret, "Failed to get backlight\n");
  494. }
  495. drm_panel_add(&nt->panel);
  496. for (i = 0; i < num_dsis; i++) {
  497. nt->dsi[i]->lanes = nt->desc->num_lanes;
  498. nt->dsi[i]->format = MIPI_DSI_FMT_RGB888;
  499. nt->dsi[i]->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS |
  500. MIPI_DSI_MODE_LPM;
  501. if (nt->desc->mode_data[0].is_video_mode)
  502. nt->dsi[i]->mode_flags |= MIPI_DSI_MODE_VIDEO;
  503. ret = mipi_dsi_attach(nt->dsi[i]);
  504. if (ret < 0) {
  505. /* If we fail to attach to either host, we're done */
  506. if (num_dsis == 2)
  507. mipi_dsi_device_unregister(nt->dsi[1]);
  508. return dev_err_probe(dev, ret,
  509. "Cannot attach to DSI%d host.\n", i);
  510. }
  511. }
  512. /* Make sure to set RESX LOW before starting the power-on sequence */
  513. gpiod_set_value_cansleep(nt->reset_gpio, 0);
  514. return 0;
  515. }
  516. static void nt35950_remove(struct mipi_dsi_device *dsi)
  517. {
  518. struct nt35950 *nt = mipi_dsi_get_drvdata(dsi);
  519. int ret;
  520. ret = mipi_dsi_detach(nt->dsi[0]);
  521. if (ret < 0)
  522. dev_err(&dsi->dev,
  523. "Failed to detach from DSI0 host: %d\n", ret);
  524. if (nt->dsi[1]) {
  525. ret = mipi_dsi_detach(nt->dsi[1]);
  526. if (ret < 0)
  527. dev_err(&dsi->dev,
  528. "Failed to detach from DSI1 host: %d\n", ret);
  529. mipi_dsi_device_unregister(nt->dsi[1]);
  530. }
  531. drm_panel_remove(&nt->panel);
  532. }
  533. static const struct nt35950_panel_mode sharp_ls055d1sx04_modes[] = {
  534. {
  535. /* 1920x1080 60Hz no compression */
  536. .mode = {
  537. .clock = 214537,
  538. .hdisplay = 1080,
  539. .hsync_start = 1080 + 400,
  540. .hsync_end = 1080 + 400 + 40,
  541. .htotal = 1080 + 400 + 40 + 300,
  542. .vdisplay = 1920,
  543. .vsync_start = 1920 + 12,
  544. .vsync_end = 1920 + 12 + 2,
  545. .vtotal = 1920 + 12 + 2 + 10,
  546. .width_mm = 68,
  547. .height_mm = 121,
  548. },
  549. .compression = MCS_DATA_COMPRESSION_NONE,
  550. .enable_sram = true,
  551. .is_video_mode = false,
  552. .scaler_on = 1,
  553. .scaler_mode = MCS_SCALEUP_DUPLICATE,
  554. },
  555. /* TODO: Add 2160x3840 60Hz when DSC is supported */
  556. };
  557. static const struct nt35950_panel_desc sharp_ls055d1sx04 = {
  558. .model_name = "Sharp LS055D1SX04",
  559. .dsi_info = {
  560. .type = "LS055D1SX04",
  561. .channel = 0,
  562. .node = NULL,
  563. },
  564. .mode_data = sharp_ls055d1sx04_modes,
  565. .num_modes = ARRAY_SIZE(sharp_ls055d1sx04_modes),
  566. .is_dual_dsi = true,
  567. .num_lanes = 4,
  568. };
  569. static const struct of_device_id nt35950_of_match[] = {
  570. { .compatible = "sharp,ls055d1sx04", .data = &sharp_ls055d1sx04 },
  571. { }
  572. };
  573. MODULE_DEVICE_TABLE(of, nt35950_of_match);
  574. static struct mipi_dsi_driver nt35950_driver = {
  575. .probe = nt35950_probe,
  576. .remove = nt35950_remove,
  577. .driver = {
  578. .name = "panel-novatek-nt35950",
  579. .of_match_table = nt35950_of_match,
  580. },
  581. };
  582. module_mipi_dsi_driver(nt35950_driver);
  583. MODULE_AUTHOR("AngeloGioacchino Del Regno <[email protected]>");
  584. MODULE_DESCRIPTION("Novatek NT35950 DriverIC panels driver");
  585. MODULE_LICENSE("GPL v2");