panel-simple.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. /*
  2. * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the
  12. * next paragraph) shall be included in all copies or substantial portions
  13. * of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <linux/backlight.h>
  24. #include <linux/gpio/consumer.h>
  25. #include <linux/module.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/regulator/consumer.h>
  29. #include <drm/drmP.h>
  30. #include <drm/drm_crtc.h>
  31. #include <drm/drm_mipi_dsi.h>
  32. #include <drm/drm_panel.h>
  33. struct panel_desc {
  34. const struct drm_display_mode *modes;
  35. unsigned int num_modes;
  36. unsigned int bpc;
  37. struct {
  38. unsigned int width;
  39. unsigned int height;
  40. } size;
  41. /**
  42. * @prepare: the time (in milliseconds) that it takes for the panel to
  43. * become ready and start receiving video data
  44. * @enable: the time (in milliseconds) that it takes for the panel to
  45. * display the first valid frame after starting to receive
  46. * video data
  47. * @disable: the time (in milliseconds) that it takes for the panel to
  48. * turn the display off (no content is visible)
  49. * @unprepare: the time (in milliseconds) that it takes for the panel
  50. * to power itself down completely
  51. */
  52. struct {
  53. unsigned int prepare;
  54. unsigned int enable;
  55. unsigned int disable;
  56. unsigned int unprepare;
  57. } delay;
  58. };
  59. struct panel_simple {
  60. struct drm_panel base;
  61. bool prepared;
  62. bool enabled;
  63. const struct panel_desc *desc;
  64. struct backlight_device *backlight;
  65. struct regulator *supply;
  66. struct i2c_adapter *ddc;
  67. struct gpio_desc *enable_gpio;
  68. };
  69. static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
  70. {
  71. return container_of(panel, struct panel_simple, base);
  72. }
  73. static int panel_simple_get_fixed_modes(struct panel_simple *panel)
  74. {
  75. struct drm_connector *connector = panel->base.connector;
  76. struct drm_device *drm = panel->base.drm;
  77. struct drm_display_mode *mode;
  78. unsigned int i, num = 0;
  79. if (!panel->desc)
  80. return 0;
  81. for (i = 0; i < panel->desc->num_modes; i++) {
  82. const struct drm_display_mode *m = &panel->desc->modes[i];
  83. mode = drm_mode_duplicate(drm, m);
  84. if (!mode) {
  85. dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
  86. m->hdisplay, m->vdisplay, m->vrefresh);
  87. continue;
  88. }
  89. drm_mode_set_name(mode);
  90. drm_mode_probed_add(connector, mode);
  91. num++;
  92. }
  93. connector->display_info.bpc = panel->desc->bpc;
  94. connector->display_info.width_mm = panel->desc->size.width;
  95. connector->display_info.height_mm = panel->desc->size.height;
  96. return num;
  97. }
  98. static int panel_simple_disable(struct drm_panel *panel)
  99. {
  100. struct panel_simple *p = to_panel_simple(panel);
  101. if (!p->enabled)
  102. return 0;
  103. if (p->backlight) {
  104. p->backlight->props.power = FB_BLANK_POWERDOWN;
  105. backlight_update_status(p->backlight);
  106. }
  107. if (p->desc->delay.disable)
  108. msleep(p->desc->delay.disable);
  109. p->enabled = false;
  110. return 0;
  111. }
  112. static int panel_simple_unprepare(struct drm_panel *panel)
  113. {
  114. struct panel_simple *p = to_panel_simple(panel);
  115. if (!p->prepared)
  116. return 0;
  117. if (p->enable_gpio)
  118. gpiod_set_value_cansleep(p->enable_gpio, 0);
  119. regulator_disable(p->supply);
  120. if (p->desc->delay.unprepare)
  121. msleep(p->desc->delay.unprepare);
  122. p->prepared = false;
  123. return 0;
  124. }
  125. static int panel_simple_prepare(struct drm_panel *panel)
  126. {
  127. struct panel_simple *p = to_panel_simple(panel);
  128. int err;
  129. if (p->prepared)
  130. return 0;
  131. err = regulator_enable(p->supply);
  132. if (err < 0) {
  133. dev_err(panel->dev, "failed to enable supply: %d\n", err);
  134. return err;
  135. }
  136. if (p->enable_gpio)
  137. gpiod_set_value_cansleep(p->enable_gpio, 1);
  138. if (p->desc->delay.prepare)
  139. msleep(p->desc->delay.prepare);
  140. p->prepared = true;
  141. return 0;
  142. }
  143. static int panel_simple_enable(struct drm_panel *panel)
  144. {
  145. struct panel_simple *p = to_panel_simple(panel);
  146. if (p->enabled)
  147. return 0;
  148. if (p->desc->delay.enable)
  149. msleep(p->desc->delay.enable);
  150. if (p->backlight) {
  151. p->backlight->props.power = FB_BLANK_UNBLANK;
  152. backlight_update_status(p->backlight);
  153. }
  154. p->enabled = true;
  155. return 0;
  156. }
  157. static int panel_simple_get_modes(struct drm_panel *panel)
  158. {
  159. struct panel_simple *p = to_panel_simple(panel);
  160. int num = 0;
  161. /* probe EDID if a DDC bus is available */
  162. if (p->ddc) {
  163. struct edid *edid = drm_get_edid(panel->connector, p->ddc);
  164. drm_mode_connector_update_edid_property(panel->connector, edid);
  165. if (edid) {
  166. num += drm_add_edid_modes(panel->connector, edid);
  167. kfree(edid);
  168. }
  169. }
  170. /* add hard-coded panel modes */
  171. num += panel_simple_get_fixed_modes(p);
  172. return num;
  173. }
  174. static const struct drm_panel_funcs panel_simple_funcs = {
  175. .disable = panel_simple_disable,
  176. .unprepare = panel_simple_unprepare,
  177. .prepare = panel_simple_prepare,
  178. .enable = panel_simple_enable,
  179. .get_modes = panel_simple_get_modes,
  180. };
  181. static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
  182. {
  183. struct device_node *backlight, *ddc;
  184. struct panel_simple *panel;
  185. int err;
  186. panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
  187. if (!panel)
  188. return -ENOMEM;
  189. panel->enabled = false;
  190. panel->prepared = false;
  191. panel->desc = desc;
  192. panel->supply = devm_regulator_get(dev, "power");
  193. if (IS_ERR(panel->supply))
  194. return PTR_ERR(panel->supply);
  195. panel->enable_gpio = devm_gpiod_get_optional(dev, "enable");
  196. if (IS_ERR(panel->enable_gpio)) {
  197. err = PTR_ERR(panel->enable_gpio);
  198. dev_err(dev, "failed to request GPIO: %d\n", err);
  199. return err;
  200. }
  201. if (panel->enable_gpio) {
  202. err = gpiod_direction_output(panel->enable_gpio, 0);
  203. if (err < 0) {
  204. dev_err(dev, "failed to setup GPIO: %d\n", err);
  205. return err;
  206. }
  207. }
  208. backlight = of_parse_phandle(dev->of_node, "backlight", 0);
  209. if (backlight) {
  210. panel->backlight = of_find_backlight_by_node(backlight);
  211. of_node_put(backlight);
  212. if (!panel->backlight)
  213. return -EPROBE_DEFER;
  214. }
  215. ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
  216. if (ddc) {
  217. panel->ddc = of_find_i2c_adapter_by_node(ddc);
  218. of_node_put(ddc);
  219. if (!panel->ddc) {
  220. err = -EPROBE_DEFER;
  221. goto free_backlight;
  222. }
  223. }
  224. drm_panel_init(&panel->base);
  225. panel->base.dev = dev;
  226. panel->base.funcs = &panel_simple_funcs;
  227. err = drm_panel_add(&panel->base);
  228. if (err < 0)
  229. goto free_ddc;
  230. dev_set_drvdata(dev, panel);
  231. return 0;
  232. free_ddc:
  233. if (panel->ddc)
  234. put_device(&panel->ddc->dev);
  235. free_backlight:
  236. if (panel->backlight)
  237. put_device(&panel->backlight->dev);
  238. return err;
  239. }
  240. static int panel_simple_remove(struct device *dev)
  241. {
  242. struct panel_simple *panel = dev_get_drvdata(dev);
  243. drm_panel_detach(&panel->base);
  244. drm_panel_remove(&panel->base);
  245. panel_simple_disable(&panel->base);
  246. if (panel->ddc)
  247. put_device(&panel->ddc->dev);
  248. if (panel->backlight)
  249. put_device(&panel->backlight->dev);
  250. return 0;
  251. }
  252. static void panel_simple_shutdown(struct device *dev)
  253. {
  254. struct panel_simple *panel = dev_get_drvdata(dev);
  255. panel_simple_disable(&panel->base);
  256. }
  257. static const struct drm_display_mode auo_b101aw03_mode = {
  258. .clock = 51450,
  259. .hdisplay = 1024,
  260. .hsync_start = 1024 + 156,
  261. .hsync_end = 1024 + 156 + 8,
  262. .htotal = 1024 + 156 + 8 + 156,
  263. .vdisplay = 600,
  264. .vsync_start = 600 + 16,
  265. .vsync_end = 600 + 16 + 6,
  266. .vtotal = 600 + 16 + 6 + 16,
  267. .vrefresh = 60,
  268. };
  269. static const struct panel_desc auo_b101aw03 = {
  270. .modes = &auo_b101aw03_mode,
  271. .num_modes = 1,
  272. .bpc = 6,
  273. .size = {
  274. .width = 223,
  275. .height = 125,
  276. },
  277. };
  278. static const struct drm_display_mode auo_b101xtn01_mode = {
  279. .clock = 72000,
  280. .hdisplay = 1366,
  281. .hsync_start = 1366 + 20,
  282. .hsync_end = 1366 + 20 + 70,
  283. .htotal = 1366 + 20 + 70,
  284. .vdisplay = 768,
  285. .vsync_start = 768 + 14,
  286. .vsync_end = 768 + 14 + 42,
  287. .vtotal = 768 + 14 + 42,
  288. .vrefresh = 60,
  289. .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
  290. };
  291. static const struct panel_desc auo_b101xtn01 = {
  292. .modes = &auo_b101xtn01_mode,
  293. .num_modes = 1,
  294. .bpc = 6,
  295. .size = {
  296. .width = 223,
  297. .height = 125,
  298. },
  299. };
  300. static const struct drm_display_mode auo_b133xtn01_mode = {
  301. .clock = 69500,
  302. .hdisplay = 1366,
  303. .hsync_start = 1366 + 48,
  304. .hsync_end = 1366 + 48 + 32,
  305. .htotal = 1366 + 48 + 32 + 20,
  306. .vdisplay = 768,
  307. .vsync_start = 768 + 3,
  308. .vsync_end = 768 + 3 + 6,
  309. .vtotal = 768 + 3 + 6 + 13,
  310. .vrefresh = 60,
  311. };
  312. static const struct panel_desc auo_b133xtn01 = {
  313. .modes = &auo_b133xtn01_mode,
  314. .num_modes = 1,
  315. .bpc = 6,
  316. .size = {
  317. .width = 293,
  318. .height = 165,
  319. },
  320. };
  321. static const struct drm_display_mode auo_b133htn01_mode = {
  322. .clock = 150660,
  323. .hdisplay = 1920,
  324. .hsync_start = 1920 + 172,
  325. .hsync_end = 1920 + 172 + 80,
  326. .htotal = 1920 + 172 + 80 + 60,
  327. .vdisplay = 1080,
  328. .vsync_start = 1080 + 25,
  329. .vsync_end = 1080 + 25 + 10,
  330. .vtotal = 1080 + 25 + 10 + 10,
  331. .vrefresh = 60,
  332. };
  333. static const struct panel_desc auo_b133htn01 = {
  334. .modes = &auo_b133htn01_mode,
  335. .num_modes = 1,
  336. .size = {
  337. .width = 293,
  338. .height = 165,
  339. },
  340. .delay = {
  341. .prepare = 105,
  342. .enable = 20,
  343. .unprepare = 50,
  344. },
  345. };
  346. static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
  347. .clock = 72070,
  348. .hdisplay = 1366,
  349. .hsync_start = 1366 + 58,
  350. .hsync_end = 1366 + 58 + 58,
  351. .htotal = 1366 + 58 + 58 + 58,
  352. .vdisplay = 768,
  353. .vsync_start = 768 + 4,
  354. .vsync_end = 768 + 4 + 4,
  355. .vtotal = 768 + 4 + 4 + 4,
  356. .vrefresh = 60,
  357. };
  358. static const struct panel_desc chunghwa_claa101wa01a = {
  359. .modes = &chunghwa_claa101wa01a_mode,
  360. .num_modes = 1,
  361. .bpc = 6,
  362. .size = {
  363. .width = 220,
  364. .height = 120,
  365. },
  366. };
  367. static const struct drm_display_mode chunghwa_claa101wb01_mode = {
  368. .clock = 69300,
  369. .hdisplay = 1366,
  370. .hsync_start = 1366 + 48,
  371. .hsync_end = 1366 + 48 + 32,
  372. .htotal = 1366 + 48 + 32 + 20,
  373. .vdisplay = 768,
  374. .vsync_start = 768 + 16,
  375. .vsync_end = 768 + 16 + 8,
  376. .vtotal = 768 + 16 + 8 + 16,
  377. .vrefresh = 60,
  378. };
  379. static const struct panel_desc chunghwa_claa101wb01 = {
  380. .modes = &chunghwa_claa101wb01_mode,
  381. .num_modes = 1,
  382. .bpc = 6,
  383. .size = {
  384. .width = 223,
  385. .height = 125,
  386. },
  387. };
  388. static const struct drm_display_mode edt_et057090dhu_mode = {
  389. .clock = 25175,
  390. .hdisplay = 640,
  391. .hsync_start = 640 + 16,
  392. .hsync_end = 640 + 16 + 30,
  393. .htotal = 640 + 16 + 30 + 114,
  394. .vdisplay = 480,
  395. .vsync_start = 480 + 10,
  396. .vsync_end = 480 + 10 + 3,
  397. .vtotal = 480 + 10 + 3 + 32,
  398. .vrefresh = 60,
  399. .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
  400. };
  401. static const struct panel_desc edt_et057090dhu = {
  402. .modes = &edt_et057090dhu_mode,
  403. .num_modes = 1,
  404. .bpc = 6,
  405. .size = {
  406. .width = 115,
  407. .height = 86,
  408. },
  409. };
  410. static const struct drm_display_mode edt_etm0700g0dh6_mode = {
  411. .clock = 33260,
  412. .hdisplay = 800,
  413. .hsync_start = 800 + 40,
  414. .hsync_end = 800 + 40 + 128,
  415. .htotal = 800 + 40 + 128 + 88,
  416. .vdisplay = 480,
  417. .vsync_start = 480 + 10,
  418. .vsync_end = 480 + 10 + 2,
  419. .vtotal = 480 + 10 + 2 + 33,
  420. .vrefresh = 60,
  421. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  422. };
  423. static const struct panel_desc edt_etm0700g0dh6 = {
  424. .modes = &edt_etm0700g0dh6_mode,
  425. .num_modes = 1,
  426. .bpc = 6,
  427. .size = {
  428. .width = 152,
  429. .height = 91,
  430. },
  431. };
  432. static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
  433. .clock = 32260,
  434. .hdisplay = 800,
  435. .hsync_start = 800 + 168,
  436. .hsync_end = 800 + 168 + 64,
  437. .htotal = 800 + 168 + 64 + 88,
  438. .vdisplay = 480,
  439. .vsync_start = 480 + 37,
  440. .vsync_end = 480 + 37 + 2,
  441. .vtotal = 480 + 37 + 2 + 8,
  442. .vrefresh = 60,
  443. };
  444. static const struct panel_desc foxlink_fl500wvr00_a0t = {
  445. .modes = &foxlink_fl500wvr00_a0t_mode,
  446. .num_modes = 1,
  447. .size = {
  448. .width = 108,
  449. .height = 65,
  450. },
  451. };
  452. static const struct drm_display_mode innolux_n116bge_mode = {
  453. .clock = 71000,
  454. .hdisplay = 1366,
  455. .hsync_start = 1366 + 64,
  456. .hsync_end = 1366 + 64 + 6,
  457. .htotal = 1366 + 64 + 6 + 64,
  458. .vdisplay = 768,
  459. .vsync_start = 768 + 8,
  460. .vsync_end = 768 + 8 + 4,
  461. .vtotal = 768 + 8 + 4 + 8,
  462. .vrefresh = 60,
  463. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  464. };
  465. static const struct panel_desc innolux_n116bge = {
  466. .modes = &innolux_n116bge_mode,
  467. .num_modes = 1,
  468. .bpc = 6,
  469. .size = {
  470. .width = 256,
  471. .height = 144,
  472. },
  473. };
  474. static const struct drm_display_mode innolux_n156bge_l21_mode = {
  475. .clock = 69300,
  476. .hdisplay = 1366,
  477. .hsync_start = 1366 + 16,
  478. .hsync_end = 1366 + 16 + 34,
  479. .htotal = 1366 + 16 + 34 + 50,
  480. .vdisplay = 768,
  481. .vsync_start = 768 + 2,
  482. .vsync_end = 768 + 2 + 6,
  483. .vtotal = 768 + 2 + 6 + 12,
  484. .vrefresh = 60,
  485. };
  486. static const struct panel_desc innolux_n156bge_l21 = {
  487. .modes = &innolux_n156bge_l21_mode,
  488. .num_modes = 1,
  489. .bpc = 6,
  490. .size = {
  491. .width = 344,
  492. .height = 193,
  493. },
  494. };
  495. static const struct drm_display_mode lg_lp129qe_mode = {
  496. .clock = 285250,
  497. .hdisplay = 2560,
  498. .hsync_start = 2560 + 48,
  499. .hsync_end = 2560 + 48 + 32,
  500. .htotal = 2560 + 48 + 32 + 80,
  501. .vdisplay = 1700,
  502. .vsync_start = 1700 + 3,
  503. .vsync_end = 1700 + 3 + 10,
  504. .vtotal = 1700 + 3 + 10 + 36,
  505. .vrefresh = 60,
  506. };
  507. static const struct panel_desc lg_lp129qe = {
  508. .modes = &lg_lp129qe_mode,
  509. .num_modes = 1,
  510. .bpc = 8,
  511. .size = {
  512. .width = 272,
  513. .height = 181,
  514. },
  515. };
  516. static const struct drm_display_mode samsung_ltn101nt05_mode = {
  517. .clock = 54030,
  518. .hdisplay = 1024,
  519. .hsync_start = 1024 + 24,
  520. .hsync_end = 1024 + 24 + 136,
  521. .htotal = 1024 + 24 + 136 + 160,
  522. .vdisplay = 600,
  523. .vsync_start = 600 + 3,
  524. .vsync_end = 600 + 3 + 6,
  525. .vtotal = 600 + 3 + 6 + 61,
  526. .vrefresh = 60,
  527. };
  528. static const struct panel_desc samsung_ltn101nt05 = {
  529. .modes = &samsung_ltn101nt05_mode,
  530. .num_modes = 1,
  531. .bpc = 6,
  532. .size = {
  533. .width = 1024,
  534. .height = 600,
  535. },
  536. };
  537. static const struct of_device_id platform_of_match[] = {
  538. {
  539. .compatible = "auo,b101aw03",
  540. .data = &auo_b101aw03,
  541. }, {
  542. .compatible = "auo,b101xtn01",
  543. .data = &auo_b101xtn01,
  544. }, {
  545. .compatible = "auo,b133htn01",
  546. .data = &auo_b133htn01,
  547. }, {
  548. .compatible = "auo,b133xtn01",
  549. .data = &auo_b133xtn01,
  550. }, {
  551. .compatible = "chunghwa,claa101wa01a",
  552. .data = &chunghwa_claa101wa01a
  553. }, {
  554. .compatible = "chunghwa,claa101wb01",
  555. .data = &chunghwa_claa101wb01
  556. }, {
  557. .compatible = "edt,et057090dhu",
  558. .data = &edt_et057090dhu,
  559. }, {
  560. .compatible = "edt,et070080dh6",
  561. .data = &edt_etm0700g0dh6,
  562. }, {
  563. .compatible = "edt,etm0700g0dh6",
  564. .data = &edt_etm0700g0dh6,
  565. }, {
  566. .compatible = "foxlink,fl500wvr00-a0t",
  567. .data = &foxlink_fl500wvr00_a0t,
  568. }, {
  569. .compatible = "innolux,n116bge",
  570. .data = &innolux_n116bge,
  571. }, {
  572. .compatible = "innolux,n156bge-l21",
  573. .data = &innolux_n156bge_l21,
  574. }, {
  575. .compatible = "lg,lp129qe",
  576. .data = &lg_lp129qe,
  577. }, {
  578. .compatible = "samsung,ltn101nt05",
  579. .data = &samsung_ltn101nt05,
  580. }, {
  581. /* sentinel */
  582. }
  583. };
  584. MODULE_DEVICE_TABLE(of, platform_of_match);
  585. static int panel_simple_platform_probe(struct platform_device *pdev)
  586. {
  587. const struct of_device_id *id;
  588. id = of_match_node(platform_of_match, pdev->dev.of_node);
  589. if (!id)
  590. return -ENODEV;
  591. return panel_simple_probe(&pdev->dev, id->data);
  592. }
  593. static int panel_simple_platform_remove(struct platform_device *pdev)
  594. {
  595. return panel_simple_remove(&pdev->dev);
  596. }
  597. static void panel_simple_platform_shutdown(struct platform_device *pdev)
  598. {
  599. panel_simple_shutdown(&pdev->dev);
  600. }
  601. static struct platform_driver panel_simple_platform_driver = {
  602. .driver = {
  603. .name = "panel-simple",
  604. .owner = THIS_MODULE,
  605. .of_match_table = platform_of_match,
  606. },
  607. .probe = panel_simple_platform_probe,
  608. .remove = panel_simple_platform_remove,
  609. .shutdown = panel_simple_platform_shutdown,
  610. };
  611. struct panel_desc_dsi {
  612. struct panel_desc desc;
  613. unsigned long flags;
  614. enum mipi_dsi_pixel_format format;
  615. unsigned int lanes;
  616. };
  617. static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
  618. .clock = 71000,
  619. .hdisplay = 800,
  620. .hsync_start = 800 + 32,
  621. .hsync_end = 800 + 32 + 1,
  622. .htotal = 800 + 32 + 1 + 57,
  623. .vdisplay = 1280,
  624. .vsync_start = 1280 + 28,
  625. .vsync_end = 1280 + 28 + 1,
  626. .vtotal = 1280 + 28 + 1 + 14,
  627. .vrefresh = 60,
  628. };
  629. static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
  630. .desc = {
  631. .modes = &lg_ld070wx3_sl01_mode,
  632. .num_modes = 1,
  633. .size = {
  634. .width = 94,
  635. .height = 151,
  636. },
  637. },
  638. .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
  639. .format = MIPI_DSI_FMT_RGB888,
  640. .lanes = 4,
  641. };
  642. static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
  643. .clock = 67000,
  644. .hdisplay = 720,
  645. .hsync_start = 720 + 12,
  646. .hsync_end = 720 + 12 + 4,
  647. .htotal = 720 + 12 + 4 + 112,
  648. .vdisplay = 1280,
  649. .vsync_start = 1280 + 8,
  650. .vsync_end = 1280 + 8 + 4,
  651. .vtotal = 1280 + 8 + 4 + 12,
  652. .vrefresh = 60,
  653. };
  654. static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
  655. .desc = {
  656. .modes = &lg_lh500wx1_sd03_mode,
  657. .num_modes = 1,
  658. .size = {
  659. .width = 62,
  660. .height = 110,
  661. },
  662. },
  663. .flags = MIPI_DSI_MODE_VIDEO,
  664. .format = MIPI_DSI_FMT_RGB888,
  665. .lanes = 4,
  666. };
  667. static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
  668. .clock = 157200,
  669. .hdisplay = 1920,
  670. .hsync_start = 1920 + 154,
  671. .hsync_end = 1920 + 154 + 16,
  672. .htotal = 1920 + 154 + 16 + 32,
  673. .vdisplay = 1200,
  674. .vsync_start = 1200 + 17,
  675. .vsync_end = 1200 + 17 + 2,
  676. .vtotal = 1200 + 17 + 2 + 16,
  677. .vrefresh = 60,
  678. };
  679. static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
  680. .desc = {
  681. .modes = &panasonic_vvx10f004b00_mode,
  682. .num_modes = 1,
  683. .size = {
  684. .width = 217,
  685. .height = 136,
  686. },
  687. },
  688. .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
  689. MIPI_DSI_CLOCK_NON_CONTINUOUS,
  690. .format = MIPI_DSI_FMT_RGB888,
  691. .lanes = 4,
  692. };
  693. static const struct of_device_id dsi_of_match[] = {
  694. {
  695. .compatible = "lg,ld070wx3-sl01",
  696. .data = &lg_ld070wx3_sl01
  697. }, {
  698. .compatible = "lg,lh500wx1-sd03",
  699. .data = &lg_lh500wx1_sd03
  700. }, {
  701. .compatible = "panasonic,vvx10f004b00",
  702. .data = &panasonic_vvx10f004b00
  703. }, {
  704. /* sentinel */
  705. }
  706. };
  707. MODULE_DEVICE_TABLE(of, dsi_of_match);
  708. static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
  709. {
  710. const struct panel_desc_dsi *desc;
  711. const struct of_device_id *id;
  712. int err;
  713. id = of_match_node(dsi_of_match, dsi->dev.of_node);
  714. if (!id)
  715. return -ENODEV;
  716. desc = id->data;
  717. err = panel_simple_probe(&dsi->dev, &desc->desc);
  718. if (err < 0)
  719. return err;
  720. dsi->mode_flags = desc->flags;
  721. dsi->format = desc->format;
  722. dsi->lanes = desc->lanes;
  723. return mipi_dsi_attach(dsi);
  724. }
  725. static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
  726. {
  727. int err;
  728. err = mipi_dsi_detach(dsi);
  729. if (err < 0)
  730. dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
  731. return panel_simple_remove(&dsi->dev);
  732. }
  733. static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
  734. {
  735. panel_simple_shutdown(&dsi->dev);
  736. }
  737. static struct mipi_dsi_driver panel_simple_dsi_driver = {
  738. .driver = {
  739. .name = "panel-simple-dsi",
  740. .owner = THIS_MODULE,
  741. .of_match_table = dsi_of_match,
  742. },
  743. .probe = panel_simple_dsi_probe,
  744. .remove = panel_simple_dsi_remove,
  745. .shutdown = panel_simple_dsi_shutdown,
  746. };
  747. static int __init panel_simple_init(void)
  748. {
  749. int err;
  750. err = platform_driver_register(&panel_simple_platform_driver);
  751. if (err < 0)
  752. return err;
  753. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
  754. err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
  755. if (err < 0)
  756. return err;
  757. }
  758. return 0;
  759. }
  760. module_init(panel_simple_init);
  761. static void __exit panel_simple_exit(void)
  762. {
  763. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
  764. mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
  765. platform_driver_unregister(&panel_simple_platform_driver);
  766. }
  767. module_exit(panel_simple_exit);
  768. MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
  769. MODULE_DESCRIPTION("DRM Driver for Simple Panels");
  770. MODULE_LICENSE("GPL and additional rights");