panel-boe-himax8279d.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019, Huaqin Telecom Technology Co., Ltd
  4. *
  5. * Author: Jerry Han <jerry.han.hq@gmail.com>
  6. *
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/gpio/consumer.h>
  14. #include <linux/regulator/consumer.h>
  15. #include <drm/drm_device.h>
  16. #include <drm/drm_mipi_dsi.h>
  17. #include <drm/drm_modes.h>
  18. #include <drm/drm_panel.h>
  19. #include <video/mipi_display.h>
  20. struct panel_cmd {
  21. char cmd;
  22. char data;
  23. };
  24. struct panel_desc {
  25. const struct drm_display_mode *display_mode;
  26. unsigned int bpc;
  27. unsigned int width_mm;
  28. unsigned int height_mm;
  29. unsigned long mode_flags;
  30. enum mipi_dsi_pixel_format format;
  31. unsigned int lanes;
  32. const struct panel_cmd *on_cmds;
  33. unsigned int on_cmds_num;
  34. };
  35. struct panel_info {
  36. struct drm_panel base;
  37. struct mipi_dsi_device *link;
  38. const struct panel_desc *desc;
  39. struct gpio_desc *enable_gpio;
  40. struct gpio_desc *pp33_gpio;
  41. struct gpio_desc *pp18_gpio;
  42. bool prepared;
  43. bool enabled;
  44. };
  45. static inline struct panel_info *to_panel_info(struct drm_panel *panel)
  46. {
  47. return container_of(panel, struct panel_info, base);
  48. }
  49. static void disable_gpios(struct panel_info *pinfo)
  50. {
  51. gpiod_set_value(pinfo->enable_gpio, 0);
  52. gpiod_set_value(pinfo->pp33_gpio, 0);
  53. gpiod_set_value(pinfo->pp18_gpio, 0);
  54. }
  55. static int send_mipi_cmds(struct drm_panel *panel, const struct panel_cmd *cmds)
  56. {
  57. struct panel_info *pinfo = to_panel_info(panel);
  58. unsigned int i = 0;
  59. int err;
  60. for (i = 0; i < pinfo->desc->on_cmds_num; i++) {
  61. err = mipi_dsi_dcs_write_buffer(pinfo->link, &cmds[i],
  62. sizeof(struct panel_cmd));
  63. if (err < 0)
  64. return err;
  65. }
  66. return 0;
  67. }
  68. static int boe_panel_disable(struct drm_panel *panel)
  69. {
  70. struct panel_info *pinfo = to_panel_info(panel);
  71. int err;
  72. if (!pinfo->enabled)
  73. return 0;
  74. err = mipi_dsi_dcs_set_display_off(pinfo->link);
  75. if (err < 0) {
  76. dev_err(panel->dev, "failed to set display off: %d\n", err);
  77. return err;
  78. }
  79. pinfo->enabled = false;
  80. return 0;
  81. }
  82. static int boe_panel_unprepare(struct drm_panel *panel)
  83. {
  84. struct panel_info *pinfo = to_panel_info(panel);
  85. int err;
  86. if (!pinfo->prepared)
  87. return 0;
  88. err = mipi_dsi_dcs_set_display_off(pinfo->link);
  89. if (err < 0)
  90. dev_err(panel->dev, "failed to set display off: %d\n", err);
  91. err = mipi_dsi_dcs_enter_sleep_mode(pinfo->link);
  92. if (err < 0)
  93. dev_err(panel->dev, "failed to enter sleep mode: %d\n", err);
  94. /* sleep_mode_delay: 1ms - 2ms */
  95. usleep_range(1000, 2000);
  96. disable_gpios(pinfo);
  97. pinfo->prepared = false;
  98. return 0;
  99. }
  100. static int boe_panel_prepare(struct drm_panel *panel)
  101. {
  102. struct panel_info *pinfo = to_panel_info(panel);
  103. int err;
  104. if (pinfo->prepared)
  105. return 0;
  106. gpiod_set_value(pinfo->pp18_gpio, 1);
  107. /* T1: 5ms - 6ms */
  108. usleep_range(5000, 6000);
  109. gpiod_set_value(pinfo->pp33_gpio, 1);
  110. /* reset sequence */
  111. /* T2: 14ms - 15ms */
  112. usleep_range(14000, 15000);
  113. gpiod_set_value(pinfo->enable_gpio, 1);
  114. /* T3: 1ms - 2ms */
  115. usleep_range(1000, 2000);
  116. gpiod_set_value(pinfo->enable_gpio, 0);
  117. /* T4: 1ms - 2ms */
  118. usleep_range(1000, 2000);
  119. gpiod_set_value(pinfo->enable_gpio, 1);
  120. /* T5: 5ms - 6ms */
  121. usleep_range(5000, 6000);
  122. /* send init code */
  123. err = send_mipi_cmds(panel, pinfo->desc->on_cmds);
  124. if (err < 0) {
  125. dev_err(panel->dev, "failed to send DCS Init Code: %d\n", err);
  126. goto poweroff;
  127. }
  128. err = mipi_dsi_dcs_exit_sleep_mode(pinfo->link);
  129. if (err < 0) {
  130. dev_err(panel->dev, "failed to exit sleep mode: %d\n", err);
  131. goto poweroff;
  132. }
  133. /* T6: 120ms - 121ms */
  134. usleep_range(120000, 121000);
  135. err = mipi_dsi_dcs_set_display_on(pinfo->link);
  136. if (err < 0) {
  137. dev_err(panel->dev, "failed to set display on: %d\n", err);
  138. goto poweroff;
  139. }
  140. /* T7: 20ms - 21ms */
  141. usleep_range(20000, 21000);
  142. pinfo->prepared = true;
  143. return 0;
  144. poweroff:
  145. disable_gpios(pinfo);
  146. return err;
  147. }
  148. static int boe_panel_enable(struct drm_panel *panel)
  149. {
  150. struct panel_info *pinfo = to_panel_info(panel);
  151. int ret;
  152. if (pinfo->enabled)
  153. return 0;
  154. usleep_range(120000, 121000);
  155. ret = mipi_dsi_dcs_set_display_on(pinfo->link);
  156. if (ret < 0) {
  157. dev_err(panel->dev, "failed to set display on: %d\n", ret);
  158. return ret;
  159. }
  160. pinfo->enabled = true;
  161. return 0;
  162. }
  163. static int boe_panel_get_modes(struct drm_panel *panel,
  164. struct drm_connector *connector)
  165. {
  166. struct panel_info *pinfo = to_panel_info(panel);
  167. const struct drm_display_mode *m = pinfo->desc->display_mode;
  168. struct drm_display_mode *mode;
  169. mode = drm_mode_duplicate(connector->dev, m);
  170. if (!mode) {
  171. dev_err(pinfo->base.dev, "failed to add mode %ux%u@%u\n",
  172. m->hdisplay, m->vdisplay, drm_mode_vrefresh(m));
  173. return -ENOMEM;
  174. }
  175. drm_mode_set_name(mode);
  176. drm_mode_probed_add(connector, mode);
  177. connector->display_info.width_mm = pinfo->desc->width_mm;
  178. connector->display_info.height_mm = pinfo->desc->height_mm;
  179. connector->display_info.bpc = pinfo->desc->bpc;
  180. return 1;
  181. }
  182. static const struct drm_panel_funcs panel_funcs = {
  183. .disable = boe_panel_disable,
  184. .unprepare = boe_panel_unprepare,
  185. .prepare = boe_panel_prepare,
  186. .enable = boe_panel_enable,
  187. .get_modes = boe_panel_get_modes,
  188. };
  189. static const struct drm_display_mode default_display_mode = {
  190. .clock = 159420,
  191. .hdisplay = 1200,
  192. .hsync_start = 1200 + 80,
  193. .hsync_end = 1200 + 80 + 60,
  194. .htotal = 1200 + 80 + 60 + 24,
  195. .vdisplay = 1920,
  196. .vsync_start = 1920 + 10,
  197. .vsync_end = 1920 + 10 + 14,
  198. .vtotal = 1920 + 10 + 14 + 4,
  199. };
  200. /* 8 inch */
  201. static const struct panel_cmd boe_himax8279d8p_on_cmds[] = {
  202. { 0xB0, 0x05 },
  203. { 0xB1, 0xE5 },
  204. { 0xB3, 0x52 },
  205. { 0xC0, 0x00 },
  206. { 0xC2, 0x57 },
  207. { 0xD9, 0x85 },
  208. { 0xB0, 0x01 },
  209. { 0xC8, 0x00 },
  210. { 0xC9, 0x00 },
  211. { 0xCC, 0x26 },
  212. { 0xCD, 0x26 },
  213. { 0xDC, 0x00 },
  214. { 0xDD, 0x00 },
  215. { 0xE0, 0x26 },
  216. { 0xE1, 0x26 },
  217. { 0xB0, 0x03 },
  218. { 0xC3, 0x2A },
  219. { 0xE7, 0x2A },
  220. { 0xC5, 0x2A },
  221. { 0xDE, 0x2A },
  222. { 0xBC, 0x02 },
  223. { 0xCB, 0x02 },
  224. { 0xB0, 0x00 },
  225. { 0xB6, 0x03 },
  226. { 0xBA, 0x8B },
  227. { 0xBF, 0x15 },
  228. { 0xC0, 0x18 },
  229. { 0xC2, 0x14 },
  230. { 0xC3, 0x02 },
  231. { 0xC4, 0x14 },
  232. { 0xC5, 0x02 },
  233. { 0xCC, 0x0A },
  234. { 0xB0, 0x06 },
  235. { 0xC0, 0xA5 },
  236. { 0xD5, 0x20 },
  237. { 0xC0, 0x00 },
  238. { 0xB0, 0x02 },
  239. { 0xC0, 0x00 },
  240. { 0xC1, 0x02 },
  241. { 0xC2, 0x06 },
  242. { 0xC3, 0x16 },
  243. { 0xC4, 0x0E },
  244. { 0xC5, 0x18 },
  245. { 0xC6, 0x26 },
  246. { 0xC7, 0x32 },
  247. { 0xC8, 0x3F },
  248. { 0xC9, 0x3F },
  249. { 0xCA, 0x3F },
  250. { 0xCB, 0x3F },
  251. { 0xCC, 0x3D },
  252. { 0xCD, 0x2F },
  253. { 0xCE, 0x2F },
  254. { 0xCF, 0x2F },
  255. { 0xD0, 0x07 },
  256. { 0xD2, 0x00 },
  257. { 0xD3, 0x02 },
  258. { 0xD4, 0x06 },
  259. { 0xD5, 0x12 },
  260. { 0xD6, 0x0A },
  261. { 0xD7, 0x14 },
  262. { 0xD8, 0x22 },
  263. { 0xD9, 0x2E },
  264. { 0xDA, 0x3D },
  265. { 0xDB, 0x3F },
  266. { 0xDC, 0x3F },
  267. { 0xDD, 0x3F },
  268. { 0xDE, 0x3D },
  269. { 0xDF, 0x2F },
  270. { 0xE0, 0x2F },
  271. { 0xE1, 0x2F },
  272. { 0xE2, 0x07 },
  273. { 0xB0, 0x07 },
  274. { 0xB1, 0x18 },
  275. { 0xB2, 0x19 },
  276. { 0xB3, 0x2E },
  277. { 0xB4, 0x52 },
  278. { 0xB5, 0x72 },
  279. { 0xB6, 0x8C },
  280. { 0xB7, 0xBD },
  281. { 0xB8, 0xEB },
  282. { 0xB9, 0x47 },
  283. { 0xBA, 0x96 },
  284. { 0xBB, 0x1E },
  285. { 0xBC, 0x90 },
  286. { 0xBD, 0x93 },
  287. { 0xBE, 0xFA },
  288. { 0xBF, 0x56 },
  289. { 0xC0, 0x8C },
  290. { 0xC1, 0xB7 },
  291. { 0xC2, 0xCC },
  292. { 0xC3, 0xDF },
  293. { 0xC4, 0xE8 },
  294. { 0xC5, 0xF0 },
  295. { 0xC6, 0xF8 },
  296. { 0xC7, 0xFA },
  297. { 0xC8, 0xFC },
  298. { 0xC9, 0x00 },
  299. { 0xCA, 0x00 },
  300. { 0xCB, 0x5A },
  301. { 0xCC, 0xAF },
  302. { 0xCD, 0xFF },
  303. { 0xCE, 0xFF },
  304. { 0xB0, 0x08 },
  305. { 0xB1, 0x04 },
  306. { 0xB2, 0x15 },
  307. { 0xB3, 0x2D },
  308. { 0xB4, 0x51 },
  309. { 0xB5, 0x72 },
  310. { 0xB6, 0x8D },
  311. { 0xB7, 0xBE },
  312. { 0xB8, 0xED },
  313. { 0xB9, 0x4A },
  314. { 0xBA, 0x9A },
  315. { 0xBB, 0x23 },
  316. { 0xBC, 0x95 },
  317. { 0xBD, 0x98 },
  318. { 0xBE, 0xFF },
  319. { 0xBF, 0x59 },
  320. { 0xC0, 0x8E },
  321. { 0xC1, 0xB9 },
  322. { 0xC2, 0xCD },
  323. { 0xC3, 0xDF },
  324. { 0xC4, 0xE8 },
  325. { 0xC5, 0xF0 },
  326. { 0xC6, 0xF8 },
  327. { 0xC7, 0xFA },
  328. { 0xC8, 0xFC },
  329. { 0xC9, 0x00 },
  330. { 0xCA, 0x00 },
  331. { 0xCB, 0x5A },
  332. { 0xCC, 0xAF },
  333. { 0xCD, 0xFF },
  334. { 0xCE, 0xFF },
  335. { 0xB0, 0x09 },
  336. { 0xB1, 0x04 },
  337. { 0xB2, 0x2C },
  338. { 0xB3, 0x36 },
  339. { 0xB4, 0x53 },
  340. { 0xB5, 0x73 },
  341. { 0xB6, 0x8E },
  342. { 0xB7, 0xC0 },
  343. { 0xB8, 0xEF },
  344. { 0xB9, 0x4C },
  345. { 0xBA, 0x9D },
  346. { 0xBB, 0x25 },
  347. { 0xBC, 0x96 },
  348. { 0xBD, 0x9A },
  349. { 0xBE, 0x01 },
  350. { 0xBF, 0x59 },
  351. { 0xC0, 0x8E },
  352. { 0xC1, 0xB9 },
  353. { 0xC2, 0xCD },
  354. { 0xC3, 0xDF },
  355. { 0xC4, 0xE8 },
  356. { 0xC5, 0xF0 },
  357. { 0xC6, 0xF8 },
  358. { 0xC7, 0xFA },
  359. { 0xC8, 0xFC },
  360. { 0xC9, 0x00 },
  361. { 0xCA, 0x00 },
  362. { 0xCB, 0x5A },
  363. { 0xCC, 0xBF },
  364. { 0xCD, 0xFF },
  365. { 0xCE, 0xFF },
  366. { 0xB0, 0x0A },
  367. { 0xB1, 0x18 },
  368. { 0xB2, 0x19 },
  369. { 0xB3, 0x2E },
  370. { 0xB4, 0x52 },
  371. { 0xB5, 0x72 },
  372. { 0xB6, 0x8C },
  373. { 0xB7, 0xBD },
  374. { 0xB8, 0xEB },
  375. { 0xB9, 0x47 },
  376. { 0xBA, 0x96 },
  377. { 0xBB, 0x1E },
  378. { 0xBC, 0x90 },
  379. { 0xBD, 0x93 },
  380. { 0xBE, 0xFA },
  381. { 0xBF, 0x56 },
  382. { 0xC0, 0x8C },
  383. { 0xC1, 0xB7 },
  384. { 0xC2, 0xCC },
  385. { 0xC3, 0xDF },
  386. { 0xC4, 0xE8 },
  387. { 0xC5, 0xF0 },
  388. { 0xC6, 0xF8 },
  389. { 0xC7, 0xFA },
  390. { 0xC8, 0xFC },
  391. { 0xC9, 0x00 },
  392. { 0xCA, 0x00 },
  393. { 0xCB, 0x5A },
  394. { 0xCC, 0xAF },
  395. { 0xCD, 0xFF },
  396. { 0xCE, 0xFF },
  397. { 0xB0, 0x0B },
  398. { 0xB1, 0x04 },
  399. { 0xB2, 0x15 },
  400. { 0xB3, 0x2D },
  401. { 0xB4, 0x51 },
  402. { 0xB5, 0x72 },
  403. { 0xB6, 0x8D },
  404. { 0xB7, 0xBE },
  405. { 0xB8, 0xED },
  406. { 0xB9, 0x4A },
  407. { 0xBA, 0x9A },
  408. { 0xBB, 0x23 },
  409. { 0xBC, 0x95 },
  410. { 0xBD, 0x98 },
  411. { 0xBE, 0xFF },
  412. { 0xBF, 0x59 },
  413. { 0xC0, 0x8E },
  414. { 0xC1, 0xB9 },
  415. { 0xC2, 0xCD },
  416. { 0xC3, 0xDF },
  417. { 0xC4, 0xE8 },
  418. { 0xC5, 0xF0 },
  419. { 0xC6, 0xF8 },
  420. { 0xC7, 0xFA },
  421. { 0xC8, 0xFC },
  422. { 0xC9, 0x00 },
  423. { 0xCA, 0x00 },
  424. { 0xCB, 0x5A },
  425. { 0xCC, 0xAF },
  426. { 0xCD, 0xFF },
  427. { 0xCE, 0xFF },
  428. { 0xB0, 0x0C },
  429. { 0xB1, 0x04 },
  430. { 0xB2, 0x2C },
  431. { 0xB3, 0x36 },
  432. { 0xB4, 0x53 },
  433. { 0xB5, 0x73 },
  434. { 0xB6, 0x8E },
  435. { 0xB7, 0xC0 },
  436. { 0xB8, 0xEF },
  437. { 0xB9, 0x4C },
  438. { 0xBA, 0x9D },
  439. { 0xBB, 0x25 },
  440. { 0xBC, 0x96 },
  441. { 0xBD, 0x9A },
  442. { 0xBE, 0x01 },
  443. { 0xBF, 0x59 },
  444. { 0xC0, 0x8E },
  445. { 0xC1, 0xB9 },
  446. { 0xC2, 0xCD },
  447. { 0xC3, 0xDF },
  448. { 0xC4, 0xE8 },
  449. { 0xC5, 0xF0 },
  450. { 0xC6, 0xF8 },
  451. { 0xC7, 0xFA },
  452. { 0xC8, 0xFC },
  453. { 0xC9, 0x00 },
  454. { 0xCA, 0x00 },
  455. { 0xCB, 0x5A },
  456. { 0xCC, 0xBF },
  457. { 0xCD, 0xFF },
  458. { 0xCE, 0xFF },
  459. { 0xB0, 0x04 },
  460. { 0xB5, 0x02 },
  461. { 0xB6, 0x01 },
  462. };
  463. static const struct panel_desc boe_himax8279d8p_panel_desc = {
  464. .display_mode = &default_display_mode,
  465. .bpc = 8,
  466. .width_mm = 107,
  467. .height_mm = 172,
  468. .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
  469. MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM,
  470. .format = MIPI_DSI_FMT_RGB888,
  471. .lanes = 4,
  472. .on_cmds = boe_himax8279d8p_on_cmds,
  473. .on_cmds_num = 260,
  474. };
  475. /* 10 inch */
  476. static const struct panel_cmd boe_himax8279d10p_on_cmds[] = {
  477. { 0xB0, 0x05 },
  478. { 0xB1, 0xE5 },
  479. { 0xB3, 0x52 },
  480. { 0xB0, 0x00 },
  481. { 0xB6, 0x03 },
  482. { 0xBA, 0x8B },
  483. { 0xBF, 0x1A },
  484. { 0xC0, 0x0F },
  485. { 0xC2, 0x0C },
  486. { 0xC3, 0x02 },
  487. { 0xC4, 0x0C },
  488. { 0xC5, 0x02 },
  489. { 0xB0, 0x01 },
  490. { 0xE0, 0x26 },
  491. { 0xE1, 0x26 },
  492. { 0xDC, 0x00 },
  493. { 0xDD, 0x00 },
  494. { 0xCC, 0x26 },
  495. { 0xCD, 0x26 },
  496. { 0xC8, 0x00 },
  497. { 0xC9, 0x00 },
  498. { 0xD2, 0x03 },
  499. { 0xD3, 0x03 },
  500. { 0xE6, 0x04 },
  501. { 0xE7, 0x04 },
  502. { 0xC4, 0x09 },
  503. { 0xC5, 0x09 },
  504. { 0xD8, 0x0A },
  505. { 0xD9, 0x0A },
  506. { 0xC2, 0x0B },
  507. { 0xC3, 0x0B },
  508. { 0xD6, 0x0C },
  509. { 0xD7, 0x0C },
  510. { 0xC0, 0x05 },
  511. { 0xC1, 0x05 },
  512. { 0xD4, 0x06 },
  513. { 0xD5, 0x06 },
  514. { 0xCA, 0x07 },
  515. { 0xCB, 0x07 },
  516. { 0xDE, 0x08 },
  517. { 0xDF, 0x08 },
  518. { 0xB0, 0x02 },
  519. { 0xC0, 0x00 },
  520. { 0xC1, 0x0D },
  521. { 0xC2, 0x17 },
  522. { 0xC3, 0x26 },
  523. { 0xC4, 0x31 },
  524. { 0xC5, 0x1C },
  525. { 0xC6, 0x2C },
  526. { 0xC7, 0x33 },
  527. { 0xC8, 0x31 },
  528. { 0xC9, 0x37 },
  529. { 0xCA, 0x37 },
  530. { 0xCB, 0x37 },
  531. { 0xCC, 0x39 },
  532. { 0xCD, 0x2E },
  533. { 0xCE, 0x2F },
  534. { 0xCF, 0x2F },
  535. { 0xD0, 0x07 },
  536. { 0xD2, 0x00 },
  537. { 0xD3, 0x0D },
  538. { 0xD4, 0x17 },
  539. { 0xD5, 0x26 },
  540. { 0xD6, 0x31 },
  541. { 0xD7, 0x3F },
  542. { 0xD8, 0x3F },
  543. { 0xD9, 0x3F },
  544. { 0xDA, 0x3F },
  545. { 0xDB, 0x37 },
  546. { 0xDC, 0x37 },
  547. { 0xDD, 0x37 },
  548. { 0xDE, 0x39 },
  549. { 0xDF, 0x2E },
  550. { 0xE0, 0x2F },
  551. { 0xE1, 0x2F },
  552. { 0xE2, 0x07 },
  553. { 0xB0, 0x03 },
  554. { 0xC8, 0x0B },
  555. { 0xC9, 0x07 },
  556. { 0xC3, 0x00 },
  557. { 0xE7, 0x00 },
  558. { 0xC5, 0x2A },
  559. { 0xDE, 0x2A },
  560. { 0xCA, 0x43 },
  561. { 0xC9, 0x07 },
  562. { 0xE4, 0xC0 },
  563. { 0xE5, 0x0D },
  564. { 0xCB, 0x01 },
  565. { 0xBC, 0x01 },
  566. { 0xB0, 0x06 },
  567. { 0xB8, 0xA5 },
  568. { 0xC0, 0xA5 },
  569. { 0xC7, 0x0F },
  570. { 0xD5, 0x32 },
  571. { 0xB8, 0x00 },
  572. { 0xC0, 0x00 },
  573. { 0xBC, 0x00 },
  574. { 0xB0, 0x07 },
  575. { 0xB1, 0x00 },
  576. { 0xB2, 0x05 },
  577. { 0xB3, 0x10 },
  578. { 0xB4, 0x22 },
  579. { 0xB5, 0x36 },
  580. { 0xB6, 0x4A },
  581. { 0xB7, 0x6C },
  582. { 0xB8, 0x9A },
  583. { 0xB9, 0xD7 },
  584. { 0xBA, 0x17 },
  585. { 0xBB, 0x92 },
  586. { 0xBC, 0x15 },
  587. { 0xBD, 0x18 },
  588. { 0xBE, 0x8C },
  589. { 0xBF, 0x00 },
  590. { 0xC0, 0x3A },
  591. { 0xC1, 0x72 },
  592. { 0xC2, 0x8C },
  593. { 0xC3, 0xA5 },
  594. { 0xC4, 0xB1 },
  595. { 0xC5, 0xBE },
  596. { 0xC6, 0xCA },
  597. { 0xC7, 0xD1 },
  598. { 0xC8, 0xD4 },
  599. { 0xC9, 0x00 },
  600. { 0xCA, 0x00 },
  601. { 0xCB, 0x16 },
  602. { 0xCC, 0xAF },
  603. { 0xCD, 0xFF },
  604. { 0xCE, 0xFF },
  605. { 0xB0, 0x08 },
  606. { 0xB1, 0x04 },
  607. { 0xB2, 0x05 },
  608. { 0xB3, 0x11 },
  609. { 0xB4, 0x24 },
  610. { 0xB5, 0x39 },
  611. { 0xB6, 0x4E },
  612. { 0xB7, 0x72 },
  613. { 0xB8, 0xA3 },
  614. { 0xB9, 0xE1 },
  615. { 0xBA, 0x25 },
  616. { 0xBB, 0xA8 },
  617. { 0xBC, 0x2E },
  618. { 0xBD, 0x32 },
  619. { 0xBE, 0xAD },
  620. { 0xBF, 0x28 },
  621. { 0xC0, 0x63 },
  622. { 0xC1, 0x9B },
  623. { 0xC2, 0xB5 },
  624. { 0xC3, 0xCF },
  625. { 0xC4, 0xDB },
  626. { 0xC5, 0xE8 },
  627. { 0xC6, 0xF5 },
  628. { 0xC7, 0xFA },
  629. { 0xC8, 0xFC },
  630. { 0xC9, 0x00 },
  631. { 0xCA, 0x00 },
  632. { 0xCB, 0x16 },
  633. { 0xCC, 0xAF },
  634. { 0xCD, 0xFF },
  635. { 0xCE, 0xFF },
  636. { 0xB0, 0x09 },
  637. { 0xB1, 0x04 },
  638. { 0xB2, 0x04 },
  639. { 0xB3, 0x0F },
  640. { 0xB4, 0x22 },
  641. { 0xB5, 0x37 },
  642. { 0xB6, 0x4D },
  643. { 0xB7, 0x71 },
  644. { 0xB8, 0xA2 },
  645. { 0xB9, 0xE1 },
  646. { 0xBA, 0x26 },
  647. { 0xBB, 0xA9 },
  648. { 0xBC, 0x2F },
  649. { 0xBD, 0x33 },
  650. { 0xBE, 0xAC },
  651. { 0xBF, 0x24 },
  652. { 0xC0, 0x5D },
  653. { 0xC1, 0x94 },
  654. { 0xC2, 0xAC },
  655. { 0xC3, 0xC5 },
  656. { 0xC4, 0xD1 },
  657. { 0xC5, 0xDC },
  658. { 0xC6, 0xE8 },
  659. { 0xC7, 0xED },
  660. { 0xC8, 0xF0 },
  661. { 0xC9, 0x00 },
  662. { 0xCA, 0x00 },
  663. { 0xCB, 0x16 },
  664. { 0xCC, 0xAF },
  665. { 0xCD, 0xFF },
  666. { 0xCE, 0xFF },
  667. { 0xB0, 0x0A },
  668. { 0xB1, 0x00 },
  669. { 0xB2, 0x05 },
  670. { 0xB3, 0x10 },
  671. { 0xB4, 0x22 },
  672. { 0xB5, 0x36 },
  673. { 0xB6, 0x4A },
  674. { 0xB7, 0x6C },
  675. { 0xB8, 0x9A },
  676. { 0xB9, 0xD7 },
  677. { 0xBA, 0x17 },
  678. { 0xBB, 0x92 },
  679. { 0xBC, 0x15 },
  680. { 0xBD, 0x18 },
  681. { 0xBE, 0x8C },
  682. { 0xBF, 0x00 },
  683. { 0xC0, 0x3A },
  684. { 0xC1, 0x72 },
  685. { 0xC2, 0x8C },
  686. { 0xC3, 0xA5 },
  687. { 0xC4, 0xB1 },
  688. { 0xC5, 0xBE },
  689. { 0xC6, 0xCA },
  690. { 0xC7, 0xD1 },
  691. { 0xC8, 0xD4 },
  692. { 0xC9, 0x00 },
  693. { 0xCA, 0x00 },
  694. { 0xCB, 0x16 },
  695. { 0xCC, 0xAF },
  696. { 0xCD, 0xFF },
  697. { 0xCE, 0xFF },
  698. { 0xB0, 0x0B },
  699. { 0xB1, 0x04 },
  700. { 0xB2, 0x05 },
  701. { 0xB3, 0x11 },
  702. { 0xB4, 0x24 },
  703. { 0xB5, 0x39 },
  704. { 0xB6, 0x4E },
  705. { 0xB7, 0x72 },
  706. { 0xB8, 0xA3 },
  707. { 0xB9, 0xE1 },
  708. { 0xBA, 0x25 },
  709. { 0xBB, 0xA8 },
  710. { 0xBC, 0x2E },
  711. { 0xBD, 0x32 },
  712. { 0xBE, 0xAD },
  713. { 0xBF, 0x28 },
  714. { 0xC0, 0x63 },
  715. { 0xC1, 0x9B },
  716. { 0xC2, 0xB5 },
  717. { 0xC3, 0xCF },
  718. { 0xC4, 0xDB },
  719. { 0xC5, 0xE8 },
  720. { 0xC6, 0xF5 },
  721. { 0xC7, 0xFA },
  722. { 0xC8, 0xFC },
  723. { 0xC9, 0x00 },
  724. { 0xCA, 0x00 },
  725. { 0xCB, 0x16 },
  726. { 0xCC, 0xAF },
  727. { 0xCD, 0xFF },
  728. { 0xCE, 0xFF },
  729. { 0xB0, 0x0C },
  730. { 0xB1, 0x04 },
  731. { 0xB2, 0x04 },
  732. { 0xB3, 0x0F },
  733. { 0xB4, 0x22 },
  734. { 0xB5, 0x37 },
  735. { 0xB6, 0x4D },
  736. { 0xB7, 0x71 },
  737. { 0xB8, 0xA2 },
  738. { 0xB9, 0xE1 },
  739. { 0xBA, 0x26 },
  740. { 0xBB, 0xA9 },
  741. { 0xBC, 0x2F },
  742. { 0xBD, 0x33 },
  743. { 0xBE, 0xAC },
  744. { 0xBF, 0x24 },
  745. { 0xC0, 0x5D },
  746. { 0xC1, 0x94 },
  747. { 0xC2, 0xAC },
  748. { 0xC3, 0xC5 },
  749. { 0xC4, 0xD1 },
  750. { 0xC5, 0xDC },
  751. { 0xC6, 0xE8 },
  752. { 0xC7, 0xED },
  753. { 0xC8, 0xF0 },
  754. { 0xC9, 0x00 },
  755. { 0xCA, 0x00 },
  756. { 0xCB, 0x16 },
  757. { 0xCC, 0xAF },
  758. { 0xCD, 0xFF },
  759. { 0xCE, 0xFF },
  760. };
  761. static const struct panel_desc boe_himax8279d10p_panel_desc = {
  762. .display_mode = &default_display_mode,
  763. .bpc = 8,
  764. .width_mm = 135,
  765. .height_mm = 216,
  766. .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
  767. MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM,
  768. .format = MIPI_DSI_FMT_RGB888,
  769. .lanes = 4,
  770. .on_cmds = boe_himax8279d10p_on_cmds,
  771. .on_cmds_num = 283,
  772. };
  773. static const struct of_device_id panel_of_match[] = {
  774. {
  775. .compatible = "boe,himax8279d8p",
  776. .data = &boe_himax8279d8p_panel_desc,
  777. },
  778. {
  779. .compatible = "boe,himax8279d10p",
  780. .data = &boe_himax8279d10p_panel_desc,
  781. },
  782. {
  783. /* sentinel */
  784. }
  785. };
  786. MODULE_DEVICE_TABLE(of, panel_of_match);
  787. static int panel_add(struct panel_info *pinfo)
  788. {
  789. struct device *dev = &pinfo->link->dev;
  790. int ret;
  791. pinfo->pp18_gpio = devm_gpiod_get(dev, "pp18", GPIOD_OUT_HIGH);
  792. if (IS_ERR(pinfo->pp18_gpio)) {
  793. ret = PTR_ERR(pinfo->pp18_gpio);
  794. if (ret != -EPROBE_DEFER)
  795. dev_err(dev, "failed to get pp18 gpio: %d\n", ret);
  796. return ret;
  797. }
  798. pinfo->pp33_gpio = devm_gpiod_get(dev, "pp33", GPIOD_OUT_HIGH);
  799. if (IS_ERR(pinfo->pp33_gpio)) {
  800. ret = PTR_ERR(pinfo->pp33_gpio);
  801. if (ret != -EPROBE_DEFER)
  802. dev_err(dev, "failed to get pp33 gpio: %d\n", ret);
  803. return ret;
  804. }
  805. pinfo->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
  806. if (IS_ERR(pinfo->enable_gpio)) {
  807. ret = PTR_ERR(pinfo->enable_gpio);
  808. if (ret != -EPROBE_DEFER)
  809. dev_err(dev, "failed to get enable gpio: %d\n", ret);
  810. return ret;
  811. }
  812. drm_panel_init(&pinfo->base, dev, &panel_funcs,
  813. DRM_MODE_CONNECTOR_DSI);
  814. ret = drm_panel_of_backlight(&pinfo->base);
  815. if (ret)
  816. return ret;
  817. drm_panel_add(&pinfo->base);
  818. return 0;
  819. }
  820. static int panel_probe(struct mipi_dsi_device *dsi)
  821. {
  822. struct panel_info *pinfo;
  823. const struct panel_desc *desc;
  824. int err;
  825. pinfo = devm_kzalloc(&dsi->dev, sizeof(*pinfo), GFP_KERNEL);
  826. if (!pinfo)
  827. return -ENOMEM;
  828. desc = of_device_get_match_data(&dsi->dev);
  829. dsi->mode_flags = desc->mode_flags;
  830. dsi->format = desc->format;
  831. dsi->lanes = desc->lanes;
  832. pinfo->desc = desc;
  833. pinfo->link = dsi;
  834. mipi_dsi_set_drvdata(dsi, pinfo);
  835. err = panel_add(pinfo);
  836. if (err < 0)
  837. return err;
  838. err = mipi_dsi_attach(dsi);
  839. if (err < 0)
  840. drm_panel_remove(&pinfo->base);
  841. return err;
  842. }
  843. static int panel_remove(struct mipi_dsi_device *dsi)
  844. {
  845. struct panel_info *pinfo = mipi_dsi_get_drvdata(dsi);
  846. int err;
  847. err = boe_panel_disable(&pinfo->base);
  848. if (err < 0)
  849. dev_err(&dsi->dev, "failed to disable panel: %d\n", err);
  850. err = boe_panel_unprepare(&pinfo->base);
  851. if (err < 0)
  852. dev_err(&dsi->dev, "failed to unprepare panel: %d\n", err);
  853. err = mipi_dsi_detach(dsi);
  854. if (err < 0)
  855. dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
  856. drm_panel_remove(&pinfo->base);
  857. return 0;
  858. }
  859. static void panel_shutdown(struct mipi_dsi_device *dsi)
  860. {
  861. struct panel_info *pinfo = mipi_dsi_get_drvdata(dsi);
  862. boe_panel_disable(&pinfo->base);
  863. boe_panel_unprepare(&pinfo->base);
  864. }
  865. static struct mipi_dsi_driver panel_driver = {
  866. .driver = {
  867. .name = "panel-boe-himax8279d",
  868. .of_match_table = panel_of_match,
  869. },
  870. .probe = panel_probe,
  871. .remove = panel_remove,
  872. .shutdown = panel_shutdown,
  873. };
  874. module_mipi_dsi_driver(panel_driver);
  875. MODULE_AUTHOR("Jerry Han <jerry.han.hq@gmail.com>");
  876. MODULE_DESCRIPTION("Boe Himax8279d driver");
  877. MODULE_LICENSE("GPL v2");