lcds.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2017 FriendlyARM (www.arm9.net)
  4. */
  5. #include <config.h>
  6. #include <common.h>
  7. #include <errno.h>
  8. #include <fdtdec.h>
  9. #include <fdt_support.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/nexell.h>
  12. #include <asm/arch/display.h>
  13. #include <asm/arch/nx_gpio.h>
  14. #include "nxp-fb.h"
  15. /*
  16. * param @module_index for nx_gpio APIs and will be removed
  17. * after support pinctrl
  18. */
  19. #ifndef PAD_GPIO_A
  20. #define PAD_GPIO_A 0
  21. #endif
  22. static inline void common_gpio_init(void)
  23. {
  24. /* PVCLK */
  25. nx_gpio_set_fast_slew(PAD_GPIO_A, 0, 1);
  26. }
  27. static void s70_gpio_init(void)
  28. {
  29. int i;
  30. /* PVCLK */
  31. nx_gpio_set_drive_strength(PAD_GPIO_A, 0, 1);
  32. /* RGB24 */
  33. for (i = 1; i < 25; i++)
  34. nx_gpio_set_drive_strength(PAD_GPIO_A, i, 2);
  35. /* HS/VS/DE */
  36. for (; i < 28; i++)
  37. nx_gpio_set_drive_strength(PAD_GPIO_A, i, 1);
  38. }
  39. static void s702_gpio_init(void)
  40. {
  41. int i;
  42. common_gpio_init();
  43. nx_gpio_set_drive_strength(PAD_GPIO_A, 0, 2);
  44. for (i = 1; i < 25; i++)
  45. nx_gpio_set_drive_strength(PAD_GPIO_A, i, 0);
  46. for (; i < 28; i++)
  47. nx_gpio_set_drive_strength(PAD_GPIO_A, i, 1);
  48. }
  49. static void s430_gpio_init(void)
  50. {
  51. int i;
  52. for (i = 0; i < 28; i++)
  53. nx_gpio_set_drive_strength(PAD_GPIO_A, i, 1);
  54. }
  55. static void hd101_gpio_init(void)
  56. {
  57. int i;
  58. common_gpio_init();
  59. nx_gpio_set_drive_strength(PAD_GPIO_A, 0, 2);
  60. for (i = 1; i < 25; i++)
  61. nx_gpio_set_drive_strength(PAD_GPIO_A, i, 1);
  62. nx_gpio_set_drive_strength(PAD_GPIO_A, 27, 1);
  63. }
  64. static void hd700_gpio_init(void)
  65. {
  66. hd101_gpio_init();
  67. }
  68. /* NXP display configs for supported LCD */
  69. static struct nxp_lcd wxga_hd700 = {
  70. .width = 800,
  71. .height = 1280,
  72. .p_width = 94,
  73. .p_height = 151,
  74. .bpp = 24,
  75. .freq = 60,
  76. .timing = {
  77. .h_fp = 20,
  78. .h_bp = 20,
  79. .h_sw = 24,
  80. .v_fp = 4,
  81. .v_fpe = 1,
  82. .v_bp = 4,
  83. .v_bpe = 1,
  84. .v_sw = 8,
  85. },
  86. .polarity = {
  87. .rise_vclk = 0,
  88. .inv_hsync = 0,
  89. .inv_vsync = 0,
  90. .inv_vden = 0,
  91. },
  92. .gpio_init = hd700_gpio_init,
  93. };
  94. static struct nxp_lcd wvga_s70 = {
  95. .width = 800,
  96. .height = 480,
  97. .p_width = 155,
  98. .p_height = 93,
  99. .bpp = 24,
  100. .freq = 61,
  101. .timing = {
  102. .h_fp = 48,
  103. .h_bp = 36,
  104. .h_sw = 10,
  105. .v_fp = 22,
  106. .v_fpe = 1,
  107. .v_bp = 15,
  108. .v_bpe = 1,
  109. .v_sw = 8,
  110. },
  111. .polarity = {
  112. .rise_vclk = 0,
  113. .inv_hsync = 1,
  114. .inv_vsync = 1,
  115. .inv_vden = 0,
  116. },
  117. .gpio_init = s70_gpio_init,
  118. };
  119. static struct nxp_lcd wvga_s702 = {
  120. .width = 800,
  121. .height = 480,
  122. .p_width = 155,
  123. .p_height = 93,
  124. .bpp = 24,
  125. .freq = 61,
  126. .timing = {
  127. .h_fp = 44,
  128. .h_bp = 26,
  129. .h_sw = 20,
  130. .v_fp = 22,
  131. .v_fpe = 1,
  132. .v_bp = 15,
  133. .v_bpe = 1,
  134. .v_sw = 8,
  135. },
  136. .polarity = {
  137. .rise_vclk = 1,
  138. .inv_hsync = 1,
  139. .inv_vsync = 1,
  140. .inv_vden = 0,
  141. },
  142. .gpio_init = s702_gpio_init,
  143. };
  144. static struct nxp_lcd wvga_s70d = {
  145. .width = 800,
  146. .height = 480,
  147. .p_width = 155,
  148. .p_height = 93,
  149. .bpp = 24,
  150. .freq = 61,
  151. .timing = {
  152. .h_fp = 80,
  153. .h_bp = 78,
  154. .h_sw = 10,
  155. .v_fp = 22,
  156. .v_fpe = 1,
  157. .v_bp = 24,
  158. .v_bpe = 1,
  159. .v_sw = 8,
  160. },
  161. .polarity = {
  162. .rise_vclk = 0,
  163. .inv_hsync = 1,
  164. .inv_vsync = 1,
  165. .inv_vden = 0,
  166. },
  167. .gpio_init = s702_gpio_init,
  168. };
  169. static struct nxp_lcd wvga_w50 = {
  170. .width = 800,
  171. .height = 480,
  172. .p_width = 108,
  173. .p_height = 64,
  174. .bpp = 24,
  175. .freq = 61,
  176. .timing = {
  177. .h_fp = 40,
  178. .h_bp = 40,
  179. .h_sw = 48,
  180. .v_fp = 20,
  181. .v_fpe = 1,
  182. .v_bp = 20,
  183. .v_bpe = 1,
  184. .v_sw = 12,
  185. },
  186. .polarity = {
  187. .rise_vclk = 0,
  188. .inv_hsync = 1,
  189. .inv_vsync = 1,
  190. .inv_vden = 0,
  191. },
  192. .gpio_init = s70_gpio_init,
  193. };
  194. static struct nxp_lcd wvga_s430 = {
  195. .width = 480,
  196. .height = 800,
  197. .p_width = 108,
  198. .p_height = 64,
  199. .bpp = 24,
  200. .freq = 60,
  201. .timing = {
  202. .h_fp = 64,
  203. .h_bp = 0,
  204. .h_sw = 16,
  205. .v_fp = 32,
  206. .v_fpe = 1,
  207. .v_bp = 0,
  208. .v_bpe = 1,
  209. .v_sw = 16,
  210. },
  211. .polarity = {
  212. .rise_vclk = 1,
  213. .inv_hsync = 1,
  214. .inv_vsync = 1,
  215. .inv_vden = 0,
  216. },
  217. .gpio_init = s430_gpio_init,
  218. };
  219. static struct nxp_lcd wsvga_w101 = {
  220. .width = 1024,
  221. .height = 600,
  222. .p_width = 204,
  223. .p_height = 120,
  224. .bpp = 24,
  225. .freq = 60,
  226. .timing = {
  227. .h_fp = 40,
  228. .h_bp = 40,
  229. .h_sw = 200,
  230. .v_fp = 8,
  231. .v_fpe = 1,
  232. .v_bp = 8,
  233. .v_bpe = 1,
  234. .v_sw = 16,
  235. },
  236. .polarity = {
  237. .rise_vclk = 1,
  238. .inv_hsync = 1,
  239. .inv_vsync = 1,
  240. .inv_vden = 0,
  241. },
  242. };
  243. static struct nxp_lcd wsvga_x710 = {
  244. .width = 1024,
  245. .height = 600,
  246. .p_width = 154,
  247. .p_height = 90,
  248. .bpp = 24,
  249. .freq = 61,
  250. .timing = {
  251. .h_fp = 84,
  252. .h_bp = 84,
  253. .h_sw = 88,
  254. .v_fp = 10,
  255. .v_fpe = 1,
  256. .v_bp = 10,
  257. .v_bpe = 1,
  258. .v_sw = 20,
  259. },
  260. .polarity = {
  261. .rise_vclk = 0,
  262. .inv_hsync = 1,
  263. .inv_vsync = 1,
  264. .inv_vden = 0,
  265. },
  266. .gpio_init = hd101_gpio_init,
  267. };
  268. static struct nxp_lcd xga_a97 = {
  269. .width = 1024,
  270. .height = 768,
  271. .p_width = 200,
  272. .p_height = 150,
  273. .bpp = 24,
  274. .freq = 61,
  275. .timing = {
  276. .h_fp = 12,
  277. .h_bp = 12,
  278. .h_sw = 4,
  279. .v_fp = 8,
  280. .v_fpe = 1,
  281. .v_bp = 8,
  282. .v_bpe = 1,
  283. .v_sw = 4,
  284. },
  285. .polarity = {
  286. .rise_vclk = 0,
  287. .inv_hsync = 1,
  288. .inv_vsync = 1,
  289. .inv_vden = 0,
  290. },
  291. };
  292. static struct nxp_lcd xga_lq150 = {
  293. .width = 1024,
  294. .height = 768,
  295. .p_width = 304,
  296. .p_height = 228,
  297. .bpp = 24,
  298. .freq = 60,
  299. .timing = {
  300. .h_fp = 12,
  301. .h_bp = 12,
  302. .h_sw = 40,
  303. .v_fp = 8,
  304. .v_fpe = 1,
  305. .v_bp = 8,
  306. .v_bpe = 1,
  307. .v_sw = 40,
  308. },
  309. .polarity = {
  310. .rise_vclk = 0,
  311. .inv_hsync = 1,
  312. .inv_vsync = 1,
  313. .inv_vden = 0,
  314. },
  315. };
  316. static struct nxp_lcd vga_l80 = {
  317. .width = 640,
  318. .height = 480,
  319. .p_width = 160,
  320. .p_height = 120,
  321. .bpp = 32,
  322. .freq = 60,
  323. .timing = {
  324. .h_fp = 35,
  325. .h_bp = 53,
  326. .h_sw = 73,
  327. .v_fp = 3,
  328. .v_fpe = 1,
  329. .v_bp = 29,
  330. .v_bpe = 1,
  331. .v_sw = 6,
  332. },
  333. .polarity = {
  334. .rise_vclk = 0,
  335. .inv_hsync = 1,
  336. .inv_vsync = 1,
  337. .inv_vden = 0,
  338. },
  339. };
  340. static struct nxp_lcd wxga_bp101 = {
  341. .width = 1280,
  342. .height = 800,
  343. .p_width = 218,
  344. .p_height = 136,
  345. .bpp = 24,
  346. .freq = 60,
  347. .timing = {
  348. .h_fp = 20,
  349. .h_bp = 20,
  350. .h_sw = 24,
  351. .v_fp = 4,
  352. .v_fpe = 1,
  353. .v_bp = 4,
  354. .v_bpe = 1,
  355. .v_sw = 8,
  356. },
  357. .polarity = {
  358. .rise_vclk = 1,
  359. .inv_hsync = 1,
  360. .inv_vsync = 1,
  361. .inv_vden = 0,
  362. },
  363. };
  364. static struct nxp_lcd wxga_hd101 = {
  365. .width = 1280,
  366. .height = 800,
  367. .p_width = 218,
  368. .p_height = 136,
  369. .bpp = 24,
  370. .freq = 60,
  371. .timing = {
  372. .h_fp = 16,
  373. .h_bp = 16,
  374. .h_sw = 30,
  375. .v_fp = 8,
  376. .v_fpe = 1,
  377. .v_bp = 8,
  378. .v_bpe = 1,
  379. .v_sw = 12,
  380. },
  381. .polarity = {
  382. .rise_vclk = 1,
  383. .inv_hsync = 0,
  384. .inv_vsync = 0,
  385. .inv_vden = 0,
  386. },
  387. .gpio_init = hd101_gpio_init,
  388. };
  389. static struct nxp_lcd hvga_h43 = {
  390. .width = 480,
  391. .height = 272,
  392. .p_width = 96,
  393. .p_height = 54,
  394. .bpp = 32,
  395. .freq = 65,
  396. .timing = {
  397. .h_fp = 5,
  398. .h_bp = 40,
  399. .h_sw = 2,
  400. .v_fp = 8,
  401. .v_fpe = 1,
  402. .v_bp = 8,
  403. .v_bpe = 1,
  404. .v_sw = 2,
  405. },
  406. .polarity = {
  407. .rise_vclk = 0,
  408. .inv_hsync = 1,
  409. .inv_vsync = 1,
  410. .inv_vden = 0,
  411. },
  412. };
  413. static struct nxp_lcd hvga_p43 = {
  414. .width = 480,
  415. .height = 272,
  416. .p_width = 96,
  417. .p_height = 54,
  418. .bpp = 32,
  419. .freq = 65,
  420. .timing = {
  421. .h_fp = 5,
  422. .h_bp = 40,
  423. .h_sw = 2,
  424. .v_fp = 8,
  425. .v_fpe = 1,
  426. .v_bp = 9,
  427. .v_bpe = 1,
  428. .v_sw = 2,
  429. },
  430. .polarity = {
  431. .rise_vclk = 1,
  432. .inv_hsync = 1,
  433. .inv_vsync = 1,
  434. .inv_vden = 0,
  435. },
  436. };
  437. static struct nxp_lcd qvga_w35 = {
  438. .width = 320,
  439. .height = 240,
  440. .p_width = 70,
  441. .p_height = 52,
  442. .bpp = 16,
  443. .freq = 65,
  444. .timing = {
  445. .h_fp = 4,
  446. .h_bp = 70,
  447. .h_sw = 4,
  448. .v_fp = 4,
  449. .v_fpe = 1,
  450. .v_bp = 12,
  451. .v_bpe = 1,
  452. .v_sw = 4,
  453. },
  454. .polarity = {
  455. .rise_vclk = 1,
  456. .inv_hsync = 0,
  457. .inv_vsync = 0,
  458. .inv_vden = 0,
  459. },
  460. };
  461. /* HDMI */
  462. static struct nxp_lcd hdmi_def = {
  463. .width = 1920,
  464. .height = 1080,
  465. .p_width = 480,
  466. .p_height = 320,
  467. .bpp = 24,
  468. .freq = 60,
  469. .timing = {
  470. .h_fp = 12,
  471. .h_bp = 12,
  472. .h_sw = 4,
  473. .v_fp = 8,
  474. .v_fpe = 1,
  475. .v_bp = 8,
  476. .v_bpe = 1,
  477. .v_sw = 4,
  478. },
  479. .polarity = {
  480. .rise_vclk = 0,
  481. .inv_hsync = 1,
  482. .inv_vsync = 1,
  483. .inv_vden = 0,
  484. },
  485. };
  486. static struct hdmi_config {
  487. char *name;
  488. int width;
  489. int height;
  490. } bd_hdmi_config[] = {
  491. { "HDMI1080P60", 1920, 1080 },
  492. { "HDMI1080I60", 1920, 1080 },
  493. { "HDMI1080P30", 1920, 1080 },
  494. { "HDMI1080P50", 1920, 1080 },
  495. { "HDMI1080I50", 1920, 1080 },
  496. { "HDMI1080P60D", 960, 536 },
  497. { "HDMI1080I60D", 960, 536 },
  498. { "HDMI1080P30D", 960, 536 },
  499. { "HDMI1080P50D", 960, 536 },
  500. { "HDMI1080I50D", 960, 536 },
  501. { "HDMI720P60", 1280, 720 },
  502. { "HDMI720P60D", 640, 360 },
  503. { "HDMI720P50", 1280, 720 },
  504. { "HDMI720P50D", 640, 360 },
  505. { "HDMI576P16X9", 720, 576 },
  506. { "HDMI576P16X9D", 720, 576 },
  507. { "HDMI576P4X3", 720, 576 },
  508. { "HDMI576P4X3D", 720, 576 },
  509. { "HDMI480P16X9", 720, 480 },
  510. { "HDMI480P16X9D", 720, 480 },
  511. { "HDMI480P4X3", 720, 480 },
  512. { "HDMI480P4X3D", 720, 480 },
  513. };
  514. /* Try to guess LCD panel by kernel command line, or
  515. * using *HD101* as default
  516. */
  517. static struct {
  518. int id;
  519. char *name;
  520. struct nxp_lcd *lcd;
  521. int dpi;
  522. int ctp;
  523. enum lcd_format fmt;
  524. } bd_lcd_config[] = {
  525. { 25, "HD101", &wxga_hd101, 0, 1, LCD_RGB },
  526. { 32, "HD101B", &wxga_hd101, 0, 1, LCD_RGB },
  527. { 18, "HD700", &wxga_hd700, 213, 1, LCD_RGB },
  528. { 30, "HD702", &wxga_hd700, 213, 1, LCD_RGB },
  529. { 33, "H70", &wxga_hd700, 213, 0, LCD_VESA },
  530. { 3, "S70", &wvga_s70, 128, 1, LCD_RGB },
  531. { 36, "S701", &wvga_s70, 128, 1, LCD_RGB },
  532. { 24, "S702", &wvga_s702, 128, 3, LCD_RGB },
  533. { 26, "S70D", &wvga_s70d, 128, 0, LCD_RGB },
  534. { 14, "H43", &hvga_h43, 0, 0, LCD_RGB },
  535. { 19, "P43", &hvga_p43, 0, 0, LCD_RGB },
  536. { 8, "W35", &qvga_w35, 0, 0, LCD_RGB },
  537. { 28, "X710", &wsvga_x710, 0, 1, LCD_RGB },
  538. { 31, "S430", &wvga_s430, 180, 1, LCD_RGB },
  539. { 4, "W50", &wvga_w50, 0, 0, LCD_RGB },
  540. /* TODO: Testing */
  541. { 15, "W101", &wsvga_w101, 0, 1, LCD_RGB },
  542. { 5, "L80", &vga_l80, 0, 1, LCD_RGB },
  543. { -1, "A97", &xga_a97, 0, 0, LCD_RGB },
  544. { -1, "LQ150", &xga_lq150, 0, 1, LCD_RGB },
  545. { -1, "BP101", &wxga_bp101, 0, 1, LCD_RGB },
  546. /* Pls keep it at last */
  547. { 128, "HDMI", &hdmi_def, 0, 0, LCD_HDMI },
  548. };
  549. static int lcd_idx;
  550. int bd_setup_lcd_by_id(int id)
  551. {
  552. int i;
  553. for (i = 0; i < ARRAY_SIZE(bd_lcd_config); i++) {
  554. if (bd_lcd_config[i].id == id) {
  555. lcd_idx = i;
  556. break;
  557. }
  558. }
  559. if (i >= ARRAY_SIZE(bd_lcd_config)) {
  560. /* NOT found */
  561. return -19;
  562. }
  563. return bd_lcd_config[i].id;
  564. }
  565. int bd_setup_lcd_by_name(char *str)
  566. {
  567. char *delim;
  568. int i;
  569. delim = strchr(str, ',');
  570. if (delim)
  571. *delim++ = '\0';
  572. if (!strncasecmp("HDMI", str, 4)) {
  573. struct hdmi_config *cfg = &bd_hdmi_config[0];
  574. struct nxp_lcd *lcd;
  575. lcd_idx = ARRAY_SIZE(bd_lcd_config) - 1;
  576. lcd = bd_lcd_config[lcd_idx].lcd;
  577. for (i = 0; i < ARRAY_SIZE(bd_hdmi_config); i++, cfg++) {
  578. if (!strcasecmp(cfg->name, str)) {
  579. lcd->width = cfg->width;
  580. lcd->height = cfg->height;
  581. bd_lcd_config[lcd_idx].name = cfg->name;
  582. goto __ret;
  583. }
  584. }
  585. }
  586. for (i = 0; i < ARRAY_SIZE(bd_lcd_config); i++) {
  587. if (!strcasecmp(bd_lcd_config[i].name, str)) {
  588. lcd_idx = i;
  589. break;
  590. }
  591. }
  592. __ret:
  593. return 0;
  594. }
  595. struct nxp_lcd *bd_get_lcd(void)
  596. {
  597. return bd_lcd_config[lcd_idx].lcd;
  598. }
  599. const char *bd_get_lcd_name(void)
  600. {
  601. return bd_lcd_config[lcd_idx].name;
  602. }
  603. enum lcd_format bd_get_lcd_format(void)
  604. {
  605. return bd_lcd_config[lcd_idx].fmt;
  606. }
  607. int bd_get_lcd_density(void)
  608. {
  609. return bd_lcd_config[lcd_idx].dpi;
  610. }
  611. #if CONFIG_IS_ENABLED(OF_CONTROL)
  612. int bd_fixup_lcd_fdt(void *blob, struct nxp_lcd *lcd)
  613. {
  614. return 0;
  615. }
  616. #endif