panel-simple.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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. #include <video/display_timing.h>
  34. #include <video/videomode.h>
  35. struct panel_desc {
  36. const struct drm_display_mode *modes;
  37. unsigned int num_modes;
  38. const struct display_timing *timings;
  39. unsigned int num_timings;
  40. unsigned int bpc;
  41. struct {
  42. unsigned int width;
  43. unsigned int height;
  44. } size;
  45. /**
  46. * @prepare: the time (in milliseconds) that it takes for the panel to
  47. * become ready and start receiving video data
  48. * @enable: the time (in milliseconds) that it takes for the panel to
  49. * display the first valid frame after starting to receive
  50. * video data
  51. * @disable: the time (in milliseconds) that it takes for the panel to
  52. * turn the display off (no content is visible)
  53. * @unprepare: the time (in milliseconds) that it takes for the panel
  54. * to power itself down completely
  55. */
  56. struct {
  57. unsigned int prepare;
  58. unsigned int enable;
  59. unsigned int disable;
  60. unsigned int unprepare;
  61. } delay;
  62. u32 bus_format;
  63. };
  64. struct panel_simple {
  65. struct drm_panel base;
  66. bool prepared;
  67. bool enabled;
  68. const struct panel_desc *desc;
  69. struct backlight_device *backlight;
  70. struct regulator *supply;
  71. struct i2c_adapter *ddc;
  72. struct gpio_desc *enable_gpio;
  73. };
  74. static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
  75. {
  76. return container_of(panel, struct panel_simple, base);
  77. }
  78. static int panel_simple_get_fixed_modes(struct panel_simple *panel)
  79. {
  80. struct drm_connector *connector = panel->base.connector;
  81. struct drm_device *drm = panel->base.drm;
  82. struct drm_display_mode *mode;
  83. unsigned int i, num = 0;
  84. if (!panel->desc)
  85. return 0;
  86. for (i = 0; i < panel->desc->num_timings; i++) {
  87. const struct display_timing *dt = &panel->desc->timings[i];
  88. struct videomode vm;
  89. videomode_from_timing(dt, &vm);
  90. mode = drm_mode_create(drm);
  91. if (!mode) {
  92. dev_err(drm->dev, "failed to add mode %ux%u\n",
  93. dt->hactive.typ, dt->vactive.typ);
  94. continue;
  95. }
  96. drm_display_mode_from_videomode(&vm, mode);
  97. drm_mode_set_name(mode);
  98. drm_mode_probed_add(connector, mode);
  99. num++;
  100. }
  101. for (i = 0; i < panel->desc->num_modes; i++) {
  102. const struct drm_display_mode *m = &panel->desc->modes[i];
  103. mode = drm_mode_duplicate(drm, m);
  104. if (!mode) {
  105. dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
  106. m->hdisplay, m->vdisplay, m->vrefresh);
  107. continue;
  108. }
  109. drm_mode_set_name(mode);
  110. drm_mode_probed_add(connector, mode);
  111. num++;
  112. }
  113. connector->display_info.bpc = panel->desc->bpc;
  114. connector->display_info.width_mm = panel->desc->size.width;
  115. connector->display_info.height_mm = panel->desc->size.height;
  116. if (panel->desc->bus_format)
  117. drm_display_info_set_bus_formats(&connector->display_info,
  118. &panel->desc->bus_format, 1);
  119. return num;
  120. }
  121. static int panel_simple_disable(struct drm_panel *panel)
  122. {
  123. struct panel_simple *p = to_panel_simple(panel);
  124. if (!p->enabled)
  125. return 0;
  126. if (p->backlight) {
  127. p->backlight->props.power = FB_BLANK_POWERDOWN;
  128. backlight_update_status(p->backlight);
  129. }
  130. if (p->desc->delay.disable)
  131. msleep(p->desc->delay.disable);
  132. p->enabled = false;
  133. return 0;
  134. }
  135. static int panel_simple_unprepare(struct drm_panel *panel)
  136. {
  137. struct panel_simple *p = to_panel_simple(panel);
  138. if (!p->prepared)
  139. return 0;
  140. if (p->enable_gpio)
  141. gpiod_set_value_cansleep(p->enable_gpio, 0);
  142. regulator_disable(p->supply);
  143. if (p->desc->delay.unprepare)
  144. msleep(p->desc->delay.unprepare);
  145. p->prepared = false;
  146. return 0;
  147. }
  148. static int panel_simple_prepare(struct drm_panel *panel)
  149. {
  150. struct panel_simple *p = to_panel_simple(panel);
  151. int err;
  152. if (p->prepared)
  153. return 0;
  154. err = regulator_enable(p->supply);
  155. if (err < 0) {
  156. dev_err(panel->dev, "failed to enable supply: %d\n", err);
  157. return err;
  158. }
  159. if (p->enable_gpio)
  160. gpiod_set_value_cansleep(p->enable_gpio, 1);
  161. if (p->desc->delay.prepare)
  162. msleep(p->desc->delay.prepare);
  163. p->prepared = true;
  164. return 0;
  165. }
  166. static int panel_simple_enable(struct drm_panel *panel)
  167. {
  168. struct panel_simple *p = to_panel_simple(panel);
  169. if (p->enabled)
  170. return 0;
  171. if (p->desc->delay.enable)
  172. msleep(p->desc->delay.enable);
  173. if (p->backlight) {
  174. p->backlight->props.power = FB_BLANK_UNBLANK;
  175. backlight_update_status(p->backlight);
  176. }
  177. p->enabled = true;
  178. return 0;
  179. }
  180. static int panel_simple_get_modes(struct drm_panel *panel)
  181. {
  182. struct panel_simple *p = to_panel_simple(panel);
  183. int num = 0;
  184. /* probe EDID if a DDC bus is available */
  185. if (p->ddc) {
  186. struct edid *edid = drm_get_edid(panel->connector, p->ddc);
  187. drm_mode_connector_update_edid_property(panel->connector, edid);
  188. if (edid) {
  189. num += drm_add_edid_modes(panel->connector, edid);
  190. kfree(edid);
  191. }
  192. }
  193. /* add hard-coded panel modes */
  194. num += panel_simple_get_fixed_modes(p);
  195. return num;
  196. }
  197. static int panel_simple_get_timings(struct drm_panel *panel,
  198. unsigned int num_timings,
  199. struct display_timing *timings)
  200. {
  201. struct panel_simple *p = to_panel_simple(panel);
  202. unsigned int i;
  203. if (p->desc->num_timings < num_timings)
  204. num_timings = p->desc->num_timings;
  205. if (timings)
  206. for (i = 0; i < num_timings; i++)
  207. timings[i] = p->desc->timings[i];
  208. return p->desc->num_timings;
  209. }
  210. static const struct drm_panel_funcs panel_simple_funcs = {
  211. .disable = panel_simple_disable,
  212. .unprepare = panel_simple_unprepare,
  213. .prepare = panel_simple_prepare,
  214. .enable = panel_simple_enable,
  215. .get_modes = panel_simple_get_modes,
  216. .get_timings = panel_simple_get_timings,
  217. };
  218. static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
  219. {
  220. struct device_node *backlight, *ddc;
  221. struct panel_simple *panel;
  222. int err;
  223. panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
  224. if (!panel)
  225. return -ENOMEM;
  226. panel->enabled = false;
  227. panel->prepared = false;
  228. panel->desc = desc;
  229. panel->supply = devm_regulator_get(dev, "power");
  230. if (IS_ERR(panel->supply))
  231. return PTR_ERR(panel->supply);
  232. panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
  233. GPIOD_OUT_LOW);
  234. if (IS_ERR(panel->enable_gpio)) {
  235. err = PTR_ERR(panel->enable_gpio);
  236. dev_err(dev, "failed to request GPIO: %d\n", err);
  237. return err;
  238. }
  239. backlight = of_parse_phandle(dev->of_node, "backlight", 0);
  240. if (backlight) {
  241. panel->backlight = of_find_backlight_by_node(backlight);
  242. of_node_put(backlight);
  243. if (!panel->backlight)
  244. return -EPROBE_DEFER;
  245. }
  246. ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
  247. if (ddc) {
  248. panel->ddc = of_find_i2c_adapter_by_node(ddc);
  249. of_node_put(ddc);
  250. if (!panel->ddc) {
  251. err = -EPROBE_DEFER;
  252. goto free_backlight;
  253. }
  254. }
  255. drm_panel_init(&panel->base);
  256. panel->base.dev = dev;
  257. panel->base.funcs = &panel_simple_funcs;
  258. err = drm_panel_add(&panel->base);
  259. if (err < 0)
  260. goto free_ddc;
  261. dev_set_drvdata(dev, panel);
  262. return 0;
  263. free_ddc:
  264. if (panel->ddc)
  265. put_device(&panel->ddc->dev);
  266. free_backlight:
  267. if (panel->backlight)
  268. put_device(&panel->backlight->dev);
  269. return err;
  270. }
  271. static int panel_simple_remove(struct device *dev)
  272. {
  273. struct panel_simple *panel = dev_get_drvdata(dev);
  274. drm_panel_detach(&panel->base);
  275. drm_panel_remove(&panel->base);
  276. panel_simple_disable(&panel->base);
  277. if (panel->ddc)
  278. put_device(&panel->ddc->dev);
  279. if (panel->backlight)
  280. put_device(&panel->backlight->dev);
  281. return 0;
  282. }
  283. static void panel_simple_shutdown(struct device *dev)
  284. {
  285. struct panel_simple *panel = dev_get_drvdata(dev);
  286. panel_simple_disable(&panel->base);
  287. }
  288. static const struct drm_display_mode ampire_am800480r3tmqwa1h_mode = {
  289. .clock = 33333,
  290. .hdisplay = 800,
  291. .hsync_start = 800 + 0,
  292. .hsync_end = 800 + 0 + 255,
  293. .htotal = 800 + 0 + 255 + 0,
  294. .vdisplay = 480,
  295. .vsync_start = 480 + 2,
  296. .vsync_end = 480 + 2 + 45,
  297. .vtotal = 480 + 2 + 45 + 0,
  298. .vrefresh = 60,
  299. .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
  300. };
  301. static const struct panel_desc ampire_am800480r3tmqwa1h = {
  302. .modes = &ampire_am800480r3tmqwa1h_mode,
  303. .num_modes = 1,
  304. .bpc = 6,
  305. .size = {
  306. .width = 152,
  307. .height = 91,
  308. },
  309. .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
  310. };
  311. static const struct drm_display_mode auo_b101aw03_mode = {
  312. .clock = 51450,
  313. .hdisplay = 1024,
  314. .hsync_start = 1024 + 156,
  315. .hsync_end = 1024 + 156 + 8,
  316. .htotal = 1024 + 156 + 8 + 156,
  317. .vdisplay = 600,
  318. .vsync_start = 600 + 16,
  319. .vsync_end = 600 + 16 + 6,
  320. .vtotal = 600 + 16 + 6 + 16,
  321. .vrefresh = 60,
  322. };
  323. static const struct panel_desc auo_b101aw03 = {
  324. .modes = &auo_b101aw03_mode,
  325. .num_modes = 1,
  326. .bpc = 6,
  327. .size = {
  328. .width = 223,
  329. .height = 125,
  330. },
  331. };
  332. static const struct drm_display_mode auo_b101ean01_mode = {
  333. .clock = 72500,
  334. .hdisplay = 1280,
  335. .hsync_start = 1280 + 119,
  336. .hsync_end = 1280 + 119 + 32,
  337. .htotal = 1280 + 119 + 32 + 21,
  338. .vdisplay = 800,
  339. .vsync_start = 800 + 4,
  340. .vsync_end = 800 + 4 + 20,
  341. .vtotal = 800 + 4 + 20 + 8,
  342. .vrefresh = 60,
  343. };
  344. static const struct panel_desc auo_b101ean01 = {
  345. .modes = &auo_b101ean01_mode,
  346. .num_modes = 1,
  347. .bpc = 6,
  348. .size = {
  349. .width = 217,
  350. .height = 136,
  351. },
  352. };
  353. static const struct drm_display_mode auo_b101xtn01_mode = {
  354. .clock = 72000,
  355. .hdisplay = 1366,
  356. .hsync_start = 1366 + 20,
  357. .hsync_end = 1366 + 20 + 70,
  358. .htotal = 1366 + 20 + 70,
  359. .vdisplay = 768,
  360. .vsync_start = 768 + 14,
  361. .vsync_end = 768 + 14 + 42,
  362. .vtotal = 768 + 14 + 42,
  363. .vrefresh = 60,
  364. .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
  365. };
  366. static const struct panel_desc auo_b101xtn01 = {
  367. .modes = &auo_b101xtn01_mode,
  368. .num_modes = 1,
  369. .bpc = 6,
  370. .size = {
  371. .width = 223,
  372. .height = 125,
  373. },
  374. };
  375. static const struct drm_display_mode auo_b116xw03_mode = {
  376. .clock = 70589,
  377. .hdisplay = 1366,
  378. .hsync_start = 1366 + 40,
  379. .hsync_end = 1366 + 40 + 40,
  380. .htotal = 1366 + 40 + 40 + 32,
  381. .vdisplay = 768,
  382. .vsync_start = 768 + 10,
  383. .vsync_end = 768 + 10 + 12,
  384. .vtotal = 768 + 10 + 12 + 6,
  385. .vrefresh = 60,
  386. };
  387. static const struct panel_desc auo_b116xw03 = {
  388. .modes = &auo_b116xw03_mode,
  389. .num_modes = 1,
  390. .bpc = 6,
  391. .size = {
  392. .width = 256,
  393. .height = 144,
  394. },
  395. };
  396. static const struct drm_display_mode auo_b133xtn01_mode = {
  397. .clock = 69500,
  398. .hdisplay = 1366,
  399. .hsync_start = 1366 + 48,
  400. .hsync_end = 1366 + 48 + 32,
  401. .htotal = 1366 + 48 + 32 + 20,
  402. .vdisplay = 768,
  403. .vsync_start = 768 + 3,
  404. .vsync_end = 768 + 3 + 6,
  405. .vtotal = 768 + 3 + 6 + 13,
  406. .vrefresh = 60,
  407. };
  408. static const struct panel_desc auo_b133xtn01 = {
  409. .modes = &auo_b133xtn01_mode,
  410. .num_modes = 1,
  411. .bpc = 6,
  412. .size = {
  413. .width = 293,
  414. .height = 165,
  415. },
  416. };
  417. static const struct drm_display_mode auo_b133htn01_mode = {
  418. .clock = 150660,
  419. .hdisplay = 1920,
  420. .hsync_start = 1920 + 172,
  421. .hsync_end = 1920 + 172 + 80,
  422. .htotal = 1920 + 172 + 80 + 60,
  423. .vdisplay = 1080,
  424. .vsync_start = 1080 + 25,
  425. .vsync_end = 1080 + 25 + 10,
  426. .vtotal = 1080 + 25 + 10 + 10,
  427. .vrefresh = 60,
  428. };
  429. static const struct panel_desc auo_b133htn01 = {
  430. .modes = &auo_b133htn01_mode,
  431. .num_modes = 1,
  432. .bpc = 6,
  433. .size = {
  434. .width = 293,
  435. .height = 165,
  436. },
  437. .delay = {
  438. .prepare = 105,
  439. .enable = 20,
  440. .unprepare = 50,
  441. },
  442. };
  443. static const struct drm_display_mode avic_tm070ddh03_mode = {
  444. .clock = 51200,
  445. .hdisplay = 1024,
  446. .hsync_start = 1024 + 160,
  447. .hsync_end = 1024 + 160 + 4,
  448. .htotal = 1024 + 160 + 4 + 156,
  449. .vdisplay = 600,
  450. .vsync_start = 600 + 17,
  451. .vsync_end = 600 + 17 + 1,
  452. .vtotal = 600 + 17 + 1 + 17,
  453. .vrefresh = 60,
  454. };
  455. static const struct panel_desc avic_tm070ddh03 = {
  456. .modes = &avic_tm070ddh03_mode,
  457. .num_modes = 1,
  458. .bpc = 8,
  459. .size = {
  460. .width = 154,
  461. .height = 90,
  462. },
  463. .delay = {
  464. .prepare = 20,
  465. .enable = 200,
  466. .disable = 200,
  467. },
  468. };
  469. static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
  470. .clock = 72070,
  471. .hdisplay = 1366,
  472. .hsync_start = 1366 + 58,
  473. .hsync_end = 1366 + 58 + 58,
  474. .htotal = 1366 + 58 + 58 + 58,
  475. .vdisplay = 768,
  476. .vsync_start = 768 + 4,
  477. .vsync_end = 768 + 4 + 4,
  478. .vtotal = 768 + 4 + 4 + 4,
  479. .vrefresh = 60,
  480. };
  481. static const struct panel_desc chunghwa_claa101wa01a = {
  482. .modes = &chunghwa_claa101wa01a_mode,
  483. .num_modes = 1,
  484. .bpc = 6,
  485. .size = {
  486. .width = 220,
  487. .height = 120,
  488. },
  489. };
  490. static const struct drm_display_mode chunghwa_claa101wb01_mode = {
  491. .clock = 69300,
  492. .hdisplay = 1366,
  493. .hsync_start = 1366 + 48,
  494. .hsync_end = 1366 + 48 + 32,
  495. .htotal = 1366 + 48 + 32 + 20,
  496. .vdisplay = 768,
  497. .vsync_start = 768 + 16,
  498. .vsync_end = 768 + 16 + 8,
  499. .vtotal = 768 + 16 + 8 + 16,
  500. .vrefresh = 60,
  501. };
  502. static const struct panel_desc chunghwa_claa101wb01 = {
  503. .modes = &chunghwa_claa101wb01_mode,
  504. .num_modes = 1,
  505. .bpc = 6,
  506. .size = {
  507. .width = 223,
  508. .height = 125,
  509. },
  510. };
  511. static const struct drm_display_mode edt_et057090dhu_mode = {
  512. .clock = 25175,
  513. .hdisplay = 640,
  514. .hsync_start = 640 + 16,
  515. .hsync_end = 640 + 16 + 30,
  516. .htotal = 640 + 16 + 30 + 114,
  517. .vdisplay = 480,
  518. .vsync_start = 480 + 10,
  519. .vsync_end = 480 + 10 + 3,
  520. .vtotal = 480 + 10 + 3 + 32,
  521. .vrefresh = 60,
  522. .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
  523. };
  524. static const struct panel_desc edt_et057090dhu = {
  525. .modes = &edt_et057090dhu_mode,
  526. .num_modes = 1,
  527. .bpc = 6,
  528. .size = {
  529. .width = 115,
  530. .height = 86,
  531. },
  532. };
  533. static const struct drm_display_mode edt_etm0700g0dh6_mode = {
  534. .clock = 33260,
  535. .hdisplay = 800,
  536. .hsync_start = 800 + 40,
  537. .hsync_end = 800 + 40 + 128,
  538. .htotal = 800 + 40 + 128 + 88,
  539. .vdisplay = 480,
  540. .vsync_start = 480 + 10,
  541. .vsync_end = 480 + 10 + 2,
  542. .vtotal = 480 + 10 + 2 + 33,
  543. .vrefresh = 60,
  544. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  545. };
  546. static const struct panel_desc edt_etm0700g0dh6 = {
  547. .modes = &edt_etm0700g0dh6_mode,
  548. .num_modes = 1,
  549. .bpc = 6,
  550. .size = {
  551. .width = 152,
  552. .height = 91,
  553. },
  554. };
  555. static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
  556. .clock = 32260,
  557. .hdisplay = 800,
  558. .hsync_start = 800 + 168,
  559. .hsync_end = 800 + 168 + 64,
  560. .htotal = 800 + 168 + 64 + 88,
  561. .vdisplay = 480,
  562. .vsync_start = 480 + 37,
  563. .vsync_end = 480 + 37 + 2,
  564. .vtotal = 480 + 37 + 2 + 8,
  565. .vrefresh = 60,
  566. };
  567. static const struct panel_desc foxlink_fl500wvr00_a0t = {
  568. .modes = &foxlink_fl500wvr00_a0t_mode,
  569. .num_modes = 1,
  570. .bpc = 8,
  571. .size = {
  572. .width = 108,
  573. .height = 65,
  574. },
  575. .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
  576. };
  577. static const struct drm_display_mode giantplus_gpg482739qs5_mode = {
  578. .clock = 9000,
  579. .hdisplay = 480,
  580. .hsync_start = 480 + 5,
  581. .hsync_end = 480 + 5 + 1,
  582. .htotal = 480 + 5 + 1 + 40,
  583. .vdisplay = 272,
  584. .vsync_start = 272 + 8,
  585. .vsync_end = 272 + 8 + 1,
  586. .vtotal = 272 + 8 + 1 + 8,
  587. .vrefresh = 60,
  588. };
  589. static const struct panel_desc giantplus_gpg482739qs5 = {
  590. .modes = &giantplus_gpg482739qs5_mode,
  591. .num_modes = 1,
  592. .bpc = 8,
  593. .size = {
  594. .width = 95,
  595. .height = 54,
  596. },
  597. .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
  598. };
  599. static const struct display_timing hannstar_hsd070pww1_timing = {
  600. .pixelclock = { 64300000, 71100000, 82000000 },
  601. .hactive = { 1280, 1280, 1280 },
  602. .hfront_porch = { 1, 1, 10 },
  603. .hback_porch = { 1, 1, 10 },
  604. .hsync_len = { 52, 158, 661 },
  605. .vactive = { 800, 800, 800 },
  606. .vfront_porch = { 1, 1, 10 },
  607. .vback_porch = { 1, 1, 10 },
  608. .vsync_len = { 1, 21, 203 },
  609. .flags = DISPLAY_FLAGS_DE_HIGH,
  610. };
  611. static const struct panel_desc hannstar_hsd070pww1 = {
  612. .timings = &hannstar_hsd070pww1_timing,
  613. .num_timings = 1,
  614. .bpc = 6,
  615. .size = {
  616. .width = 151,
  617. .height = 94,
  618. },
  619. };
  620. static const struct drm_display_mode hitachi_tx23d38vm0caa_mode = {
  621. .clock = 33333,
  622. .hdisplay = 800,
  623. .hsync_start = 800 + 85,
  624. .hsync_end = 800 + 85 + 86,
  625. .htotal = 800 + 85 + 86 + 85,
  626. .vdisplay = 480,
  627. .vsync_start = 480 + 16,
  628. .vsync_end = 480 + 16 + 13,
  629. .vtotal = 480 + 16 + 13 + 16,
  630. .vrefresh = 60,
  631. };
  632. static const struct panel_desc hitachi_tx23d38vm0caa = {
  633. .modes = &hitachi_tx23d38vm0caa_mode,
  634. .num_modes = 1,
  635. .bpc = 6,
  636. .size = {
  637. .width = 195,
  638. .height = 117,
  639. },
  640. };
  641. static const struct drm_display_mode innolux_at043tn24_mode = {
  642. .clock = 9000,
  643. .hdisplay = 480,
  644. .hsync_start = 480 + 2,
  645. .hsync_end = 480 + 2 + 41,
  646. .htotal = 480 + 2 + 41 + 2,
  647. .vdisplay = 272,
  648. .vsync_start = 272 + 2,
  649. .vsync_end = 272 + 2 + 11,
  650. .vtotal = 272 + 2 + 11 + 2,
  651. .vrefresh = 60,
  652. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  653. };
  654. static const struct panel_desc innolux_at043tn24 = {
  655. .modes = &innolux_at043tn24_mode,
  656. .num_modes = 1,
  657. .bpc = 8,
  658. .size = {
  659. .width = 95,
  660. .height = 54,
  661. },
  662. .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
  663. };
  664. static const struct drm_display_mode innolux_g121i1_l01_mode = {
  665. .clock = 71000,
  666. .hdisplay = 1280,
  667. .hsync_start = 1280 + 64,
  668. .hsync_end = 1280 + 64 + 32,
  669. .htotal = 1280 + 64 + 32 + 64,
  670. .vdisplay = 800,
  671. .vsync_start = 800 + 9,
  672. .vsync_end = 800 + 9 + 6,
  673. .vtotal = 800 + 9 + 6 + 9,
  674. .vrefresh = 60,
  675. };
  676. static const struct panel_desc innolux_g121i1_l01 = {
  677. .modes = &innolux_g121i1_l01_mode,
  678. .num_modes = 1,
  679. .bpc = 6,
  680. .size = {
  681. .width = 261,
  682. .height = 163,
  683. },
  684. };
  685. static const struct drm_display_mode innolux_n116bge_mode = {
  686. .clock = 76420,
  687. .hdisplay = 1366,
  688. .hsync_start = 1366 + 136,
  689. .hsync_end = 1366 + 136 + 30,
  690. .htotal = 1366 + 136 + 30 + 60,
  691. .vdisplay = 768,
  692. .vsync_start = 768 + 8,
  693. .vsync_end = 768 + 8 + 12,
  694. .vtotal = 768 + 8 + 12 + 12,
  695. .vrefresh = 60,
  696. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  697. };
  698. static const struct panel_desc innolux_n116bge = {
  699. .modes = &innolux_n116bge_mode,
  700. .num_modes = 1,
  701. .bpc = 6,
  702. .size = {
  703. .width = 256,
  704. .height = 144,
  705. },
  706. };
  707. static const struct drm_display_mode innolux_n156bge_l21_mode = {
  708. .clock = 69300,
  709. .hdisplay = 1366,
  710. .hsync_start = 1366 + 16,
  711. .hsync_end = 1366 + 16 + 34,
  712. .htotal = 1366 + 16 + 34 + 50,
  713. .vdisplay = 768,
  714. .vsync_start = 768 + 2,
  715. .vsync_end = 768 + 2 + 6,
  716. .vtotal = 768 + 2 + 6 + 12,
  717. .vrefresh = 60,
  718. };
  719. static const struct panel_desc innolux_n156bge_l21 = {
  720. .modes = &innolux_n156bge_l21_mode,
  721. .num_modes = 1,
  722. .bpc = 6,
  723. .size = {
  724. .width = 344,
  725. .height = 193,
  726. },
  727. };
  728. static const struct drm_display_mode innolux_zj070na_01p_mode = {
  729. .clock = 51501,
  730. .hdisplay = 1024,
  731. .hsync_start = 1024 + 128,
  732. .hsync_end = 1024 + 128 + 64,
  733. .htotal = 1024 + 128 + 64 + 128,
  734. .vdisplay = 600,
  735. .vsync_start = 600 + 16,
  736. .vsync_end = 600 + 16 + 4,
  737. .vtotal = 600 + 16 + 4 + 16,
  738. .vrefresh = 60,
  739. };
  740. static const struct panel_desc innolux_zj070na_01p = {
  741. .modes = &innolux_zj070na_01p_mode,
  742. .num_modes = 1,
  743. .bpc = 6,
  744. .size = {
  745. .width = 1024,
  746. .height = 600,
  747. },
  748. };
  749. static const struct drm_display_mode lg_lp129qe_mode = {
  750. .clock = 285250,
  751. .hdisplay = 2560,
  752. .hsync_start = 2560 + 48,
  753. .hsync_end = 2560 + 48 + 32,
  754. .htotal = 2560 + 48 + 32 + 80,
  755. .vdisplay = 1700,
  756. .vsync_start = 1700 + 3,
  757. .vsync_end = 1700 + 3 + 10,
  758. .vtotal = 1700 + 3 + 10 + 36,
  759. .vrefresh = 60,
  760. };
  761. static const struct panel_desc lg_lp129qe = {
  762. .modes = &lg_lp129qe_mode,
  763. .num_modes = 1,
  764. .bpc = 8,
  765. .size = {
  766. .width = 272,
  767. .height = 181,
  768. },
  769. };
  770. static const struct drm_display_mode ortustech_com43h4m85ulc_mode = {
  771. .clock = 25000,
  772. .hdisplay = 480,
  773. .hsync_start = 480 + 10,
  774. .hsync_end = 480 + 10 + 10,
  775. .htotal = 480 + 10 + 10 + 15,
  776. .vdisplay = 800,
  777. .vsync_start = 800 + 3,
  778. .vsync_end = 800 + 3 + 3,
  779. .vtotal = 800 + 3 + 3 + 3,
  780. .vrefresh = 60,
  781. };
  782. static const struct panel_desc ortustech_com43h4m85ulc = {
  783. .modes = &ortustech_com43h4m85ulc_mode,
  784. .num_modes = 1,
  785. .bpc = 8,
  786. .size = {
  787. .width = 56,
  788. .height = 93,
  789. },
  790. .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
  791. };
  792. static const struct drm_display_mode samsung_ltn101nt05_mode = {
  793. .clock = 54030,
  794. .hdisplay = 1024,
  795. .hsync_start = 1024 + 24,
  796. .hsync_end = 1024 + 24 + 136,
  797. .htotal = 1024 + 24 + 136 + 160,
  798. .vdisplay = 600,
  799. .vsync_start = 600 + 3,
  800. .vsync_end = 600 + 3 + 6,
  801. .vtotal = 600 + 3 + 6 + 61,
  802. .vrefresh = 60,
  803. };
  804. static const struct panel_desc samsung_ltn101nt05 = {
  805. .modes = &samsung_ltn101nt05_mode,
  806. .num_modes = 1,
  807. .bpc = 6,
  808. .size = {
  809. .width = 1024,
  810. .height = 600,
  811. },
  812. };
  813. static const struct drm_display_mode samsung_ltn140at29_301_mode = {
  814. .clock = 76300,
  815. .hdisplay = 1366,
  816. .hsync_start = 1366 + 64,
  817. .hsync_end = 1366 + 64 + 48,
  818. .htotal = 1366 + 64 + 48 + 128,
  819. .vdisplay = 768,
  820. .vsync_start = 768 + 2,
  821. .vsync_end = 768 + 2 + 5,
  822. .vtotal = 768 + 2 + 5 + 17,
  823. .vrefresh = 60,
  824. };
  825. static const struct panel_desc samsung_ltn140at29_301 = {
  826. .modes = &samsung_ltn140at29_301_mode,
  827. .num_modes = 1,
  828. .bpc = 6,
  829. .size = {
  830. .width = 320,
  831. .height = 187,
  832. },
  833. };
  834. static const struct drm_display_mode shelly_sca07010_bfn_lnn_mode = {
  835. .clock = 33300,
  836. .hdisplay = 800,
  837. .hsync_start = 800 + 1,
  838. .hsync_end = 800 + 1 + 64,
  839. .htotal = 800 + 1 + 64 + 64,
  840. .vdisplay = 480,
  841. .vsync_start = 480 + 1,
  842. .vsync_end = 480 + 1 + 23,
  843. .vtotal = 480 + 1 + 23 + 22,
  844. .vrefresh = 60,
  845. };
  846. static const struct panel_desc shelly_sca07010_bfn_lnn = {
  847. .modes = &shelly_sca07010_bfn_lnn_mode,
  848. .num_modes = 1,
  849. .size = {
  850. .width = 152,
  851. .height = 91,
  852. },
  853. .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
  854. };
  855. static const struct of_device_id platform_of_match[] = {
  856. {
  857. .compatible = "ampire,am800480r3tmqwa1h",
  858. .data = &ampire_am800480r3tmqwa1h,
  859. }, {
  860. .compatible = "auo,b101aw03",
  861. .data = &auo_b101aw03,
  862. }, {
  863. .compatible = "auo,b101ean01",
  864. .data = &auo_b101ean01,
  865. }, {
  866. .compatible = "auo,b101xtn01",
  867. .data = &auo_b101xtn01,
  868. }, {
  869. .compatible = "auo,b116xw03",
  870. .data = &auo_b116xw03,
  871. }, {
  872. .compatible = "auo,b133htn01",
  873. .data = &auo_b133htn01,
  874. }, {
  875. .compatible = "auo,b133xtn01",
  876. .data = &auo_b133xtn01,
  877. }, {
  878. .compatible = "avic,tm070ddh03",
  879. .data = &avic_tm070ddh03,
  880. }, {
  881. .compatible = "chunghwa,claa101wa01a",
  882. .data = &chunghwa_claa101wa01a
  883. }, {
  884. .compatible = "chunghwa,claa101wb01",
  885. .data = &chunghwa_claa101wb01
  886. }, {
  887. .compatible = "edt,et057090dhu",
  888. .data = &edt_et057090dhu,
  889. }, {
  890. .compatible = "edt,et070080dh6",
  891. .data = &edt_etm0700g0dh6,
  892. }, {
  893. .compatible = "edt,etm0700g0dh6",
  894. .data = &edt_etm0700g0dh6,
  895. }, {
  896. .compatible = "foxlink,fl500wvr00-a0t",
  897. .data = &foxlink_fl500wvr00_a0t,
  898. }, {
  899. .compatible = "giantplus,gpg482739qs5",
  900. .data = &giantplus_gpg482739qs5
  901. }, {
  902. .compatible = "hannstar,hsd070pww1",
  903. .data = &hannstar_hsd070pww1,
  904. }, {
  905. .compatible = "hit,tx23d38vm0caa",
  906. .data = &hitachi_tx23d38vm0caa
  907. }, {
  908. .compatible = "innolux,at043tn24",
  909. .data = &innolux_at043tn24,
  910. }, {
  911. .compatible ="innolux,g121i1-l01",
  912. .data = &innolux_g121i1_l01
  913. }, {
  914. .compatible = "innolux,n116bge",
  915. .data = &innolux_n116bge,
  916. }, {
  917. .compatible = "innolux,n156bge-l21",
  918. .data = &innolux_n156bge_l21,
  919. }, {
  920. .compatible = "innolux,zj070na-01p",
  921. .data = &innolux_zj070na_01p,
  922. }, {
  923. .compatible = "lg,lp129qe",
  924. .data = &lg_lp129qe,
  925. }, {
  926. .compatible = "ortustech,com43h4m85ulc",
  927. .data = &ortustech_com43h4m85ulc,
  928. }, {
  929. .compatible = "samsung,ltn101nt05",
  930. .data = &samsung_ltn101nt05,
  931. }, {
  932. .compatible = "samsung,ltn140at29-301",
  933. .data = &samsung_ltn140at29_301,
  934. }, {
  935. .compatible = "shelly,sca07010-bfn-lnn",
  936. .data = &shelly_sca07010_bfn_lnn,
  937. }, {
  938. /* sentinel */
  939. }
  940. };
  941. MODULE_DEVICE_TABLE(of, platform_of_match);
  942. static int panel_simple_platform_probe(struct platform_device *pdev)
  943. {
  944. const struct of_device_id *id;
  945. id = of_match_node(platform_of_match, pdev->dev.of_node);
  946. if (!id)
  947. return -ENODEV;
  948. return panel_simple_probe(&pdev->dev, id->data);
  949. }
  950. static int panel_simple_platform_remove(struct platform_device *pdev)
  951. {
  952. return panel_simple_remove(&pdev->dev);
  953. }
  954. static void panel_simple_platform_shutdown(struct platform_device *pdev)
  955. {
  956. panel_simple_shutdown(&pdev->dev);
  957. }
  958. static struct platform_driver panel_simple_platform_driver = {
  959. .driver = {
  960. .name = "panel-simple",
  961. .of_match_table = platform_of_match,
  962. },
  963. .probe = panel_simple_platform_probe,
  964. .remove = panel_simple_platform_remove,
  965. .shutdown = panel_simple_platform_shutdown,
  966. };
  967. struct panel_desc_dsi {
  968. struct panel_desc desc;
  969. unsigned long flags;
  970. enum mipi_dsi_pixel_format format;
  971. unsigned int lanes;
  972. };
  973. static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
  974. .clock = 71000,
  975. .hdisplay = 800,
  976. .hsync_start = 800 + 32,
  977. .hsync_end = 800 + 32 + 1,
  978. .htotal = 800 + 32 + 1 + 57,
  979. .vdisplay = 1280,
  980. .vsync_start = 1280 + 28,
  981. .vsync_end = 1280 + 28 + 1,
  982. .vtotal = 1280 + 28 + 1 + 14,
  983. .vrefresh = 60,
  984. };
  985. static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
  986. .desc = {
  987. .modes = &lg_ld070wx3_sl01_mode,
  988. .num_modes = 1,
  989. .bpc = 8,
  990. .size = {
  991. .width = 94,
  992. .height = 151,
  993. },
  994. },
  995. .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
  996. .format = MIPI_DSI_FMT_RGB888,
  997. .lanes = 4,
  998. };
  999. static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
  1000. .clock = 67000,
  1001. .hdisplay = 720,
  1002. .hsync_start = 720 + 12,
  1003. .hsync_end = 720 + 12 + 4,
  1004. .htotal = 720 + 12 + 4 + 112,
  1005. .vdisplay = 1280,
  1006. .vsync_start = 1280 + 8,
  1007. .vsync_end = 1280 + 8 + 4,
  1008. .vtotal = 1280 + 8 + 4 + 12,
  1009. .vrefresh = 60,
  1010. };
  1011. static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
  1012. .desc = {
  1013. .modes = &lg_lh500wx1_sd03_mode,
  1014. .num_modes = 1,
  1015. .bpc = 8,
  1016. .size = {
  1017. .width = 62,
  1018. .height = 110,
  1019. },
  1020. },
  1021. .flags = MIPI_DSI_MODE_VIDEO,
  1022. .format = MIPI_DSI_FMT_RGB888,
  1023. .lanes = 4,
  1024. };
  1025. static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
  1026. .clock = 157200,
  1027. .hdisplay = 1920,
  1028. .hsync_start = 1920 + 154,
  1029. .hsync_end = 1920 + 154 + 16,
  1030. .htotal = 1920 + 154 + 16 + 32,
  1031. .vdisplay = 1200,
  1032. .vsync_start = 1200 + 17,
  1033. .vsync_end = 1200 + 17 + 2,
  1034. .vtotal = 1200 + 17 + 2 + 16,
  1035. .vrefresh = 60,
  1036. };
  1037. static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
  1038. .desc = {
  1039. .modes = &panasonic_vvx10f004b00_mode,
  1040. .num_modes = 1,
  1041. .bpc = 8,
  1042. .size = {
  1043. .width = 217,
  1044. .height = 136,
  1045. },
  1046. },
  1047. .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
  1048. MIPI_DSI_CLOCK_NON_CONTINUOUS,
  1049. .format = MIPI_DSI_FMT_RGB888,
  1050. .lanes = 4,
  1051. };
  1052. static const struct of_device_id dsi_of_match[] = {
  1053. {
  1054. .compatible = "lg,ld070wx3-sl01",
  1055. .data = &lg_ld070wx3_sl01
  1056. }, {
  1057. .compatible = "lg,lh500wx1-sd03",
  1058. .data = &lg_lh500wx1_sd03
  1059. }, {
  1060. .compatible = "panasonic,vvx10f004b00",
  1061. .data = &panasonic_vvx10f004b00
  1062. }, {
  1063. /* sentinel */
  1064. }
  1065. };
  1066. MODULE_DEVICE_TABLE(of, dsi_of_match);
  1067. static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
  1068. {
  1069. const struct panel_desc_dsi *desc;
  1070. const struct of_device_id *id;
  1071. int err;
  1072. id = of_match_node(dsi_of_match, dsi->dev.of_node);
  1073. if (!id)
  1074. return -ENODEV;
  1075. desc = id->data;
  1076. err = panel_simple_probe(&dsi->dev, &desc->desc);
  1077. if (err < 0)
  1078. return err;
  1079. dsi->mode_flags = desc->flags;
  1080. dsi->format = desc->format;
  1081. dsi->lanes = desc->lanes;
  1082. return mipi_dsi_attach(dsi);
  1083. }
  1084. static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
  1085. {
  1086. int err;
  1087. err = mipi_dsi_detach(dsi);
  1088. if (err < 0)
  1089. dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
  1090. return panel_simple_remove(&dsi->dev);
  1091. }
  1092. static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
  1093. {
  1094. panel_simple_shutdown(&dsi->dev);
  1095. }
  1096. static struct mipi_dsi_driver panel_simple_dsi_driver = {
  1097. .driver = {
  1098. .name = "panel-simple-dsi",
  1099. .of_match_table = dsi_of_match,
  1100. },
  1101. .probe = panel_simple_dsi_probe,
  1102. .remove = panel_simple_dsi_remove,
  1103. .shutdown = panel_simple_dsi_shutdown,
  1104. };
  1105. static int __init panel_simple_init(void)
  1106. {
  1107. int err;
  1108. err = platform_driver_register(&panel_simple_platform_driver);
  1109. if (err < 0)
  1110. return err;
  1111. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
  1112. err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
  1113. if (err < 0)
  1114. return err;
  1115. }
  1116. return 0;
  1117. }
  1118. module_init(panel_simple_init);
  1119. static void __exit panel_simple_exit(void)
  1120. {
  1121. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
  1122. mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
  1123. platform_driver_unregister(&panel_simple_platform_driver);
  1124. }
  1125. module_exit(panel_simple_exit);
  1126. MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
  1127. MODULE_DESCRIPTION("DRM Driver for Simple Panels");
  1128. MODULE_LICENSE("GPL and additional rights");