omap3_display.c 12 KB

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