omap3_display.c 12 KB

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