omap3_display.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012 - 2013 CompuLab, Ltd. <www.compulab.co.il>
  4. *
  5. * Authors: Nikita Kiryanov <nikita@compulab.co.il>
  6. *
  7. * Parsing code based on linux/drivers/video/pxafb.c
  8. */
  9. #include <common.h>
  10. #include <asm/gpio.h>
  11. #include <asm/io.h>
  12. #include <env.h>
  13. #include <stdio_dev.h>
  14. #include <asm/arch/dss.h>
  15. #include <lcd.h>
  16. #include <scf0403_lcd.h>
  17. #include <asm/arch-omap3/dss.h>
  18. enum display_type {
  19. NONE,
  20. DVI,
  21. DVI_CUSTOM,
  22. DATA_IMAGE, /* #define CONFIG_SCF0403_LCD to use */
  23. };
  24. #define CMAP_ADDR 0x80100000
  25. /*
  26. * The frame buffer is allocated before we have the chance to parse user input.
  27. * To make sure enough memory is allocated for all resolutions, we define
  28. * vl_{col | row} to the maximal resolution supported by OMAP3.
  29. */
  30. vidinfo_t panel_info = {
  31. .vl_col = 1400,
  32. .vl_row = 1050,
  33. .vl_bpix = LCD_BPP,
  34. .cmap = (ushort *)CMAP_ADDR,
  35. };
  36. static struct panel_config panel_cfg;
  37. static enum display_type lcd_def;
  38. /*
  39. * A note on DVI presets;
  40. * U-Boot can convert 8 bit BMP data to 16 bit BMP data, and OMAP DSS can
  41. * convert 16 bit data into 24 bit data. Thus, GFXFORMAT_RGB16 allows us to
  42. * support two BMP types with one setting.
  43. */
  44. static const struct panel_config preset_dvi_640X480 = {
  45. .lcd_size = PANEL_LCD_SIZE(640, 480),
  46. .timing_h = DSS_HBP(48) | DSS_HFP(16) | DSS_HSW(96),
  47. .timing_v = DSS_VBP(33) | DSS_VFP(10) | DSS_VSW(2),
  48. .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
  49. .divisor = 12 | (1 << 16),
  50. .data_lines = LCD_INTERFACE_24_BIT,
  51. .panel_type = ACTIVE_DISPLAY,
  52. .load_mode = 2,
  53. .gfx_format = GFXFORMAT_RGB16,
  54. };
  55. static const struct panel_config preset_dvi_800X600 = {
  56. .lcd_size = PANEL_LCD_SIZE(800, 600),
  57. .timing_h = DSS_HBP(88) | DSS_HFP(40) | DSS_HSW(128),
  58. .timing_v = DSS_VBP(23) | DSS_VFP(1) | DSS_VSW(4),
  59. .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
  60. .divisor = 8 | (1 << 16),
  61. .data_lines = LCD_INTERFACE_24_BIT,
  62. .panel_type = ACTIVE_DISPLAY,
  63. .load_mode = 2,
  64. .gfx_format = GFXFORMAT_RGB16,
  65. };
  66. static const struct panel_config preset_dvi_1024X768 = {
  67. .lcd_size = PANEL_LCD_SIZE(1024, 768),
  68. .timing_h = DSS_HBP(160) | DSS_HFP(24) | DSS_HSW(136),
  69. .timing_v = DSS_VBP(29) | DSS_VFP(3) | DSS_VSW(6),
  70. .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
  71. .divisor = 5 | (1 << 16),
  72. .data_lines = LCD_INTERFACE_24_BIT,
  73. .panel_type = ACTIVE_DISPLAY,
  74. .load_mode = 2,
  75. .gfx_format = GFXFORMAT_RGB16,
  76. };
  77. static const struct panel_config preset_dvi_1152X864 = {
  78. .lcd_size = PANEL_LCD_SIZE(1152, 864),
  79. .timing_h = DSS_HBP(256) | DSS_HFP(64) | DSS_HSW(128),
  80. .timing_v = DSS_VBP(32) | DSS_VFP(1) | DSS_VSW(3),
  81. .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
  82. .divisor = 4 | (1 << 16),
  83. .data_lines = LCD_INTERFACE_24_BIT,
  84. .panel_type = ACTIVE_DISPLAY,
  85. .load_mode = 2,
  86. .gfx_format = GFXFORMAT_RGB16,
  87. };
  88. static const struct panel_config preset_dvi_1280X960 = {
  89. .lcd_size = PANEL_LCD_SIZE(1280, 960),
  90. .timing_h = DSS_HBP(312) | DSS_HFP(96) | DSS_HSW(112),
  91. .timing_v = DSS_VBP(36) | DSS_VFP(1) | DSS_VSW(3),
  92. .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
  93. .divisor = 3 | (1 << 16),
  94. .data_lines = LCD_INTERFACE_24_BIT,
  95. .panel_type = ACTIVE_DISPLAY,
  96. .load_mode = 2,
  97. .gfx_format = GFXFORMAT_RGB16,
  98. };
  99. static const struct panel_config preset_dvi_1280X1024 = {
  100. .lcd_size = PANEL_LCD_SIZE(1280, 1024),
  101. .timing_h = DSS_HBP(248) | DSS_HFP(48) | DSS_HSW(112),
  102. .timing_v = DSS_VBP(38) | DSS_VFP(1) | DSS_VSW(3),
  103. .pol_freq = DSS_IHS | DSS_IVS | DSS_IPC,
  104. .divisor = 3 | (1 << 16),
  105. .data_lines = LCD_INTERFACE_24_BIT,
  106. .panel_type = ACTIVE_DISPLAY,
  107. .load_mode = 2,
  108. .gfx_format = GFXFORMAT_RGB16,
  109. };
  110. static const struct panel_config preset_dataimage_480X800 = {
  111. .lcd_size = PANEL_LCD_SIZE(480, 800),
  112. .timing_h = DSS_HBP(2) | DSS_HFP(2) | DSS_HSW(2),
  113. .timing_v = DSS_VBP(17) | DSS_VFP(20) | DSS_VSW(3),
  114. .pol_freq = DSS_IVS | DSS_IHS | DSS_IPC | DSS_ONOFF,
  115. .divisor = 10 | (1 << 10),
  116. .data_lines = LCD_INTERFACE_18_BIT,
  117. .panel_type = ACTIVE_DISPLAY,
  118. .load_mode = 2,
  119. .gfx_format = GFXFORMAT_RGB16,
  120. };
  121. /*
  122. * set_resolution_params()
  123. *
  124. * Due to usage of multiple display related APIs resolution data is located in
  125. * more than one place. This function updates them all.
  126. */
  127. static void set_resolution_params(int x, int y)
  128. {
  129. panel_cfg.lcd_size = PANEL_LCD_SIZE(x, y);
  130. panel_info.vl_col = x;
  131. panel_info.vl_row = y;
  132. lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
  133. }
  134. static void set_preset(const struct panel_config preset, int x_res, int y_res)
  135. {
  136. panel_cfg = preset;
  137. set_resolution_params(x_res, y_res);
  138. }
  139. static enum display_type set_dvi_preset(const struct panel_config preset,
  140. int x_res, int y_res)
  141. {
  142. set_preset(preset, x_res, y_res);
  143. return DVI;
  144. }
  145. static enum display_type set_dataimage_preset(const struct panel_config preset,
  146. int x_res, int y_res)
  147. {
  148. set_preset(preset, x_res, y_res);
  149. return DATA_IMAGE;
  150. }
  151. /*
  152. * parse_mode() - parse the mode parameter of custom lcd settings
  153. *
  154. * @mode: <res_x>x<res_y>
  155. *
  156. * Returns -1 on error, 0 on success.
  157. */
  158. static int parse_mode(const char *mode)
  159. {
  160. unsigned int modelen = strlen(mode);
  161. int res_specified = 0;
  162. unsigned int xres = 0, yres = 0;
  163. int yres_specified = 0;
  164. int i;
  165. for (i = modelen - 1; i >= 0; i--) {
  166. switch (mode[i]) {
  167. case 'x':
  168. if (!yres_specified) {
  169. yres = simple_strtoul(&mode[i + 1], NULL, 0);
  170. yres_specified = 1;
  171. } else {
  172. goto done_parsing;
  173. }
  174. break;
  175. case '0' ... '9':
  176. break;
  177. default:
  178. goto done_parsing;
  179. }
  180. }
  181. if (i < 0 && yres_specified) {
  182. xres = simple_strtoul(mode, NULL, 0);
  183. res_specified = 1;
  184. }
  185. done_parsing:
  186. if (res_specified) {
  187. set_resolution_params(xres, yres);
  188. } else {
  189. printf("LCD: invalid mode: %s\n", mode);
  190. return -1;
  191. }
  192. return 0;
  193. }
  194. #define PIXEL_CLK_NUMERATOR (26 * 432 / 39)
  195. /*
  196. * parse_pixclock() - Parse the pixclock parameter of custom lcd settings
  197. *
  198. * @pixclock: the desired pixel clock
  199. *
  200. * Returns -1 on error, 0 on success.
  201. *
  202. * Handling the pixel_clock:
  203. *
  204. * Pixel clock is defined in the OMAP35x TRM as follows:
  205. * pixel_clock =
  206. * (SYS_CLK * 2 * PRCM.CM_CLKSEL2_PLL[18:8]) /
  207. * (DSS.DISPC_DIVISOR[23:16] * DSS.DISPC_DIVISOR[6:0] *
  208. * PRCM.CM_CLKSEL_DSS[4:0] * (PRCM.CM_CLKSEL2_PLL[6:0] + 1))
  209. *
  210. * In practice, this means that in order to set the
  211. * divisor for the desired pixel clock one needs to
  212. * solve the following equation:
  213. *
  214. * 26 * 432 / (39 * <pixel_clock>) = DSS.DISPC_DIVISOR[6:0]
  215. *
  216. * NOTE: the explicit equation above is reduced. Do not
  217. * try to infer anything from these numbers.
  218. */
  219. static int parse_pixclock(char *pixclock)
  220. {
  221. int divisor, pixclock_val;
  222. char *pixclk_start = pixclock;
  223. pixclock_val = dectoul(pixclock, &pixclock);
  224. divisor = DIV_ROUND_UP(PIXEL_CLK_NUMERATOR, pixclock_val);
  225. /* 0 and 1 are illegal values for PCD */
  226. if (divisor <= 1)
  227. divisor = 2;
  228. panel_cfg.divisor = divisor | (1 << 16);
  229. if (pixclock[0] != '\0') {
  230. printf("LCD: invalid value for pixclock:%s\n", pixclk_start);
  231. return -1;
  232. }
  233. return 0;
  234. }
  235. /*
  236. * parse_setting() - parse a single setting of custom lcd parameters
  237. *
  238. * @setting: The custom lcd setting <name>:<value>
  239. *
  240. * Returns -1 on failure, 0 on success.
  241. */
  242. static int parse_setting(char *setting)
  243. {
  244. int num_val;
  245. char *setting_start = setting;
  246. if (!strncmp(setting, "mode:", 5)) {
  247. return parse_mode(setting + 5);
  248. } else if (!strncmp(setting, "pixclock:", 9)) {
  249. return parse_pixclock(setting + 9);
  250. } else if (!strncmp(setting, "left:", 5)) {
  251. num_val = simple_strtoul(setting + 5, &setting, 0);
  252. panel_cfg.timing_h |= DSS_HBP(num_val);
  253. } else if (!strncmp(setting, "right:", 6)) {
  254. num_val = simple_strtoul(setting + 6, &setting, 0);
  255. panel_cfg.timing_h |= DSS_HFP(num_val);
  256. } else if (!strncmp(setting, "upper:", 6)) {
  257. num_val = simple_strtoul(setting + 6, &setting, 0);
  258. panel_cfg.timing_v |= DSS_VBP(num_val);
  259. } else if (!strncmp(setting, "lower:", 6)) {
  260. num_val = simple_strtoul(setting + 6, &setting, 0);
  261. panel_cfg.timing_v |= DSS_VFP(num_val);
  262. } else if (!strncmp(setting, "hsynclen:", 9)) {
  263. num_val = simple_strtoul(setting + 9, &setting, 0);
  264. panel_cfg.timing_h |= DSS_HSW(num_val);
  265. } else if (!strncmp(setting, "vsynclen:", 9)) {
  266. num_val = simple_strtoul(setting + 9, &setting, 0);
  267. panel_cfg.timing_v |= DSS_VSW(num_val);
  268. } else if (!strncmp(setting, "hsync:", 6)) {
  269. if (simple_strtoul(setting + 6, &setting, 0) == 0)
  270. panel_cfg.pol_freq |= DSS_IHS;
  271. else
  272. panel_cfg.pol_freq &= ~DSS_IHS;
  273. } else if (!strncmp(setting, "vsync:", 6)) {
  274. if (simple_strtoul(setting + 6, &setting, 0) == 0)
  275. panel_cfg.pol_freq |= DSS_IVS;
  276. else
  277. panel_cfg.pol_freq &= ~DSS_IVS;
  278. } else if (!strncmp(setting, "outputen:", 9)) {
  279. if (simple_strtoul(setting + 9, &setting, 0) == 0)
  280. panel_cfg.pol_freq |= DSS_IEO;
  281. else
  282. panel_cfg.pol_freq &= ~DSS_IEO;
  283. } else if (!strncmp(setting, "pixclockpol:", 12)) {
  284. if (simple_strtoul(setting + 12, &setting, 0) == 0)
  285. panel_cfg.pol_freq |= DSS_IPC;
  286. else
  287. panel_cfg.pol_freq &= ~DSS_IPC;
  288. } else if (!strncmp(setting, "active", 6)) {
  289. panel_cfg.panel_type = ACTIVE_DISPLAY;
  290. return 0; /* Avoid sanity check below */
  291. } else if (!strncmp(setting, "passive", 7)) {
  292. panel_cfg.panel_type = PASSIVE_DISPLAY;
  293. return 0; /* Avoid sanity check below */
  294. } else if (!strncmp(setting, "display:", 8)) {
  295. if (!strncmp(setting + 8, "dvi", 3)) {
  296. lcd_def = DVI_CUSTOM;
  297. return 0; /* Avoid sanity check below */
  298. }
  299. } else {
  300. printf("LCD: unknown option %s\n", setting_start);
  301. return -1;
  302. }
  303. if (setting[0] != '\0') {
  304. printf("LCD: invalid value for %s\n", setting_start);
  305. return -1;
  306. }
  307. return 0;
  308. }
  309. /*
  310. * env_parse_customlcd() - parse custom lcd params from an environment variable.
  311. *
  312. * @custom_lcd_params: The environment variable containing the lcd params.
  313. *
  314. * Returns -1 on failure, 0 on success.
  315. */
  316. static int parse_customlcd(char *custom_lcd_params)
  317. {
  318. char params_cpy[160];
  319. char *setting;
  320. strncpy(params_cpy, custom_lcd_params, 160);
  321. setting = strtok(params_cpy, ",");
  322. while (setting) {
  323. if (parse_setting(setting) < 0)
  324. return -1;
  325. setting = strtok(NULL, ",");
  326. }
  327. /* Currently we don't support changing this via custom lcd params */
  328. panel_cfg.data_lines = LCD_INTERFACE_24_BIT;
  329. panel_cfg.gfx_format = GFXFORMAT_RGB16; /* See dvi predefines note */
  330. return 0;
  331. }
  332. /*
  333. * env_parse_displaytype() - parse display type.
  334. *
  335. * Parses the environment variable "displaytype", which contains the
  336. * name of the display type or preset, in which case it applies its
  337. * configurations.
  338. *
  339. * Returns the type of display that was specified.
  340. */
  341. static enum display_type env_parse_displaytype(char *displaytype)
  342. {
  343. if (!strncmp(displaytype, "dvi640x480", 10))
  344. return set_dvi_preset(preset_dvi_640X480, 640, 480);
  345. else if (!strncmp(displaytype, "dvi800x600", 10))
  346. return set_dvi_preset(preset_dvi_800X600, 800, 600);
  347. else if (!strncmp(displaytype, "dvi1024x768", 11))
  348. return set_dvi_preset(preset_dvi_1024X768, 1024, 768);
  349. else if (!strncmp(displaytype, "dvi1152x864", 11))
  350. return set_dvi_preset(preset_dvi_1152X864, 1152, 864);
  351. else if (!strncmp(displaytype, "dvi1280x960", 11))
  352. return set_dvi_preset(preset_dvi_1280X960, 1280, 960);
  353. else if (!strncmp(displaytype, "dvi1280x1024", 12))
  354. return set_dvi_preset(preset_dvi_1280X1024, 1280, 1024);
  355. else if (!strncmp(displaytype, "dataimage480x800", 16))
  356. return set_dataimage_preset(preset_dataimage_480X800, 480, 800);
  357. return NONE;
  358. }
  359. void lcd_ctrl_init(void *lcdbase)
  360. {
  361. struct prcm *prcm = (struct prcm *)PRCM_BASE;
  362. char *custom_lcd;
  363. char *displaytype = env_get("displaytype");
  364. if (displaytype == NULL)
  365. return;
  366. lcd_def = env_parse_displaytype(displaytype);
  367. /* If we did not recognize the preset, check if it's an env variable */
  368. if (lcd_def == NONE) {
  369. custom_lcd = env_get(displaytype);
  370. if (custom_lcd == NULL || parse_customlcd(custom_lcd) < 0)
  371. return;
  372. }
  373. panel_cfg.frame_buffer = lcdbase;
  374. omap3_dss_panel_config(&panel_cfg);
  375. /*
  376. * Pixel clock is defined with many divisions and only few
  377. * multiplications of the system clock. Since DSS FCLK divisor is set
  378. * to 16 by default, we need to set it to a smaller value, like 3
  379. * (chosen via trial and error).
  380. */
  381. clrsetbits_le32(&prcm->clksel_dss, 0xF, 3);
  382. }
  383. #ifdef CONFIG_SCF0403_LCD
  384. static void scf0403_enable(void)
  385. {
  386. gpio_direction_output(58, 1);
  387. scf0403_init(157);
  388. }
  389. #else
  390. static inline void scf0403_enable(void) {}
  391. #endif
  392. void lcd_enable(void)
  393. {
  394. switch (lcd_def) {
  395. case NONE:
  396. return;
  397. case DVI:
  398. case DVI_CUSTOM:
  399. gpio_direction_output(54, 0); /* Turn on DVI */
  400. break;
  401. case DATA_IMAGE:
  402. scf0403_enable();
  403. break;
  404. }
  405. omap3_dss_enable();
  406. }
  407. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) {}