clcd.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /*
  2. * linux/include/asm-arm/hardware/amba_clcd.h -- Integrator LCD panel.
  3. *
  4. * David A Rusling
  5. *
  6. * Copyright (C) 2001 ARM Limited
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/fb.h>
  13. /*
  14. * CLCD Controller Internal Register addresses
  15. */
  16. #define CLCD_TIM0 0x00000000
  17. #define CLCD_TIM1 0x00000004
  18. #define CLCD_TIM2 0x00000008
  19. #define CLCD_TIM3 0x0000000c
  20. #define CLCD_UBAS 0x00000010
  21. #define CLCD_LBAS 0x00000014
  22. #define CLCD_PL110_IENB 0x00000018
  23. #define CLCD_PL110_CNTL 0x0000001c
  24. #define CLCD_PL110_STAT 0x00000020
  25. #define CLCD_PL110_INTR 0x00000024
  26. #define CLCD_PL110_UCUR 0x00000028
  27. #define CLCD_PL110_LCUR 0x0000002C
  28. #define CLCD_PL111_CNTL 0x00000018
  29. #define CLCD_PL111_IENB 0x0000001c
  30. #define CLCD_PL111_RIS 0x00000020
  31. #define CLCD_PL111_MIS 0x00000024
  32. #define CLCD_PL111_ICR 0x00000028
  33. #define CLCD_PL111_UCUR 0x0000002c
  34. #define CLCD_PL111_LCUR 0x00000030
  35. #define CLCD_PALL 0x00000200
  36. #define CLCD_PALETTE 0x00000200
  37. #define TIM2_CLKSEL (1 << 5)
  38. #define TIM2_IVS (1 << 11)
  39. #define TIM2_IHS (1 << 12)
  40. #define TIM2_IPC (1 << 13)
  41. #define TIM2_IOE (1 << 14)
  42. #define TIM2_BCD (1 << 26)
  43. #define CNTL_LCDEN (1 << 0)
  44. #define CNTL_LCDBPP1 (0 << 1)
  45. #define CNTL_LCDBPP2 (1 << 1)
  46. #define CNTL_LCDBPP4 (2 << 1)
  47. #define CNTL_LCDBPP8 (3 << 1)
  48. #define CNTL_LCDBPP16 (4 << 1)
  49. #define CNTL_LCDBPP16_565 (6 << 1)
  50. #define CNTL_LCDBPP16_444 (7 << 1)
  51. #define CNTL_LCDBPP24 (5 << 1)
  52. #define CNTL_LCDBW (1 << 4)
  53. #define CNTL_LCDTFT (1 << 5)
  54. #define CNTL_LCDMONO8 (1 << 6)
  55. #define CNTL_LCDDUAL (1 << 7)
  56. #define CNTL_BGR (1 << 8)
  57. #define CNTL_BEBO (1 << 9)
  58. #define CNTL_BEPO (1 << 10)
  59. #define CNTL_LCDPWR (1 << 11)
  60. #define CNTL_LCDVCOMP(x) ((x) << 12)
  61. #define CNTL_LDMAFIFOTIME (1 << 15)
  62. #define CNTL_WATERMARK (1 << 16)
  63. /* ST Microelectronics variant bits */
  64. #define CNTL_ST_1XBPP_444 0x0
  65. #define CNTL_ST_1XBPP_5551 (1 << 17)
  66. #define CNTL_ST_1XBPP_565 (1 << 18)
  67. #define CNTL_ST_CDWID_12 0x0
  68. #define CNTL_ST_CDWID_16 (1 << 19)
  69. #define CNTL_ST_CDWID_18 (1 << 20)
  70. #define CNTL_ST_CDWID_24 ((1 << 19)|(1 << 20))
  71. #define CNTL_ST_CEAEN (1 << 21)
  72. #define CNTL_ST_LCDBPP24_PACKED (6 << 1)
  73. enum {
  74. /* individual formats */
  75. CLCD_CAP_RGB444 = (1 << 0),
  76. CLCD_CAP_RGB5551 = (1 << 1),
  77. CLCD_CAP_RGB565 = (1 << 2),
  78. CLCD_CAP_RGB888 = (1 << 3),
  79. CLCD_CAP_BGR444 = (1 << 4),
  80. CLCD_CAP_BGR5551 = (1 << 5),
  81. CLCD_CAP_BGR565 = (1 << 6),
  82. CLCD_CAP_BGR888 = (1 << 7),
  83. /* connection layouts */
  84. CLCD_CAP_444 = CLCD_CAP_RGB444 | CLCD_CAP_BGR444,
  85. CLCD_CAP_5551 = CLCD_CAP_RGB5551 | CLCD_CAP_BGR5551,
  86. CLCD_CAP_565 = CLCD_CAP_RGB565 | CLCD_CAP_BGR565,
  87. CLCD_CAP_888 = CLCD_CAP_RGB888 | CLCD_CAP_BGR888,
  88. /* red/blue ordering */
  89. CLCD_CAP_RGB = CLCD_CAP_RGB444 | CLCD_CAP_RGB5551 |
  90. CLCD_CAP_RGB565 | CLCD_CAP_RGB888,
  91. CLCD_CAP_BGR = CLCD_CAP_BGR444 | CLCD_CAP_BGR5551 |
  92. CLCD_CAP_BGR565 | CLCD_CAP_BGR888,
  93. CLCD_CAP_ALL = CLCD_CAP_BGR | CLCD_CAP_RGB,
  94. };
  95. struct backlight_device;
  96. struct clcd_panel {
  97. struct fb_videomode mode;
  98. signed short width; /* width in mm */
  99. signed short height; /* height in mm */
  100. u32 tim2;
  101. u32 tim3;
  102. u32 cntl;
  103. u32 caps;
  104. unsigned int bpp:8,
  105. fixedtimings:1,
  106. grayscale:1;
  107. unsigned int connector;
  108. struct backlight_device *backlight;
  109. /*
  110. * If the B/R lines are switched between the CLCD
  111. * and the panel we need to know this and not try to
  112. * compensate with the BGR bit in the control register.
  113. */
  114. bool bgr_connection;
  115. };
  116. struct clcd_regs {
  117. u32 tim0;
  118. u32 tim1;
  119. u32 tim2;
  120. u32 tim3;
  121. u32 cntl;
  122. unsigned long pixclock;
  123. };
  124. struct clcd_fb;
  125. /*
  126. * the board-type specific routines
  127. */
  128. struct clcd_board {
  129. const char *name;
  130. /*
  131. * Optional. Hardware capability flags.
  132. */
  133. u32 caps;
  134. /*
  135. * Optional. Check whether the var structure is acceptable
  136. * for this display.
  137. */
  138. int (*check)(struct clcd_fb *fb, struct fb_var_screeninfo *var);
  139. /*
  140. * Compulsory. Decode fb->fb.var into regs->*. In the case of
  141. * fixed timing, set regs->* to the register values required.
  142. */
  143. void (*decode)(struct clcd_fb *fb, struct clcd_regs *regs);
  144. /*
  145. * Optional. Disable any extra display hardware.
  146. */
  147. void (*disable)(struct clcd_fb *);
  148. /*
  149. * Optional. Enable any extra display hardware.
  150. */
  151. void (*enable)(struct clcd_fb *);
  152. /*
  153. * Setup platform specific parts of CLCD driver
  154. */
  155. int (*setup)(struct clcd_fb *);
  156. /*
  157. * mmap the framebuffer memory
  158. */
  159. int (*mmap)(struct clcd_fb *, struct vm_area_struct *);
  160. /*
  161. * Remove platform specific parts of CLCD driver
  162. */
  163. void (*remove)(struct clcd_fb *);
  164. };
  165. struct amba_device;
  166. struct clk;
  167. /**
  168. * struct clcd_vendor_data - holds hardware (IP-block) vendor-specific
  169. * variant information
  170. *
  171. * @clock_timregs: the CLCD needs to be clocked when accessing the
  172. * timer registers, or the hardware will hang.
  173. * @packed_24_bit_pixels: this variant supports 24bit packed pixel data,
  174. * so that RGB accesses 3 bytes at a time, not just on even 32bit
  175. * boundaries, packing the pixel data in memory. ST Microelectronics
  176. * have this.
  177. * @st_bitmux_control: ST Microelectronics have implemented output
  178. * bit line multiplexing into the CLCD control register. This indicates
  179. * that we need to use this.
  180. * @init_board: custom board init function for this variant
  181. * @init_panel: custom panel init function for this variant
  182. */
  183. struct clcd_vendor_data {
  184. bool clock_timregs;
  185. bool packed_24_bit_pixels;
  186. bool st_bitmux_control;
  187. int (*init_board)(struct amba_device *adev,
  188. struct clcd_board *board);
  189. int (*init_panel)(struct clcd_fb *fb,
  190. struct device_node *panel);
  191. };
  192. /* this data structure describes each frame buffer device we find */
  193. struct clcd_fb {
  194. struct fb_info fb;
  195. struct amba_device *dev;
  196. struct clk *clk;
  197. struct clcd_vendor_data *vendor;
  198. struct clcd_panel *panel;
  199. struct clcd_board *board;
  200. void *board_data;
  201. void __iomem *regs;
  202. u16 off_ienb;
  203. u16 off_cntl;
  204. u32 clcd_cntl;
  205. u32 cmap[16];
  206. bool clk_enabled;
  207. };
  208. static inline void clcdfb_decode(struct clcd_fb *fb, struct clcd_regs *regs)
  209. {
  210. struct fb_var_screeninfo *var = &fb->fb.var;
  211. u32 val, cpl;
  212. /*
  213. * Program the CLCD controller registers and start the CLCD
  214. */
  215. val = ((var->xres / 16) - 1) << 2;
  216. val |= (var->hsync_len - 1) << 8;
  217. val |= (var->right_margin - 1) << 16;
  218. val |= (var->left_margin - 1) << 24;
  219. regs->tim0 = val;
  220. val = var->yres;
  221. if (fb->panel->cntl & CNTL_LCDDUAL)
  222. val /= 2;
  223. val -= 1;
  224. val |= (var->vsync_len - 1) << 10;
  225. val |= var->lower_margin << 16;
  226. val |= var->upper_margin << 24;
  227. regs->tim1 = val;
  228. val = fb->panel->tim2;
  229. val |= var->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : TIM2_IHS;
  230. val |= var->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : TIM2_IVS;
  231. cpl = var->xres_virtual;
  232. if (fb->panel->cntl & CNTL_LCDTFT) /* TFT */
  233. /* / 1 */;
  234. else if (!var->grayscale) /* STN color */
  235. cpl = cpl * 8 / 3;
  236. else if (fb->panel->cntl & CNTL_LCDMONO8) /* STN monochrome, 8bit */
  237. cpl /= 8;
  238. else /* STN monochrome, 4bit */
  239. cpl /= 4;
  240. regs->tim2 = val | ((cpl - 1) << 16);
  241. regs->tim3 = fb->panel->tim3;
  242. val = fb->panel->cntl;
  243. if (var->grayscale)
  244. val |= CNTL_LCDBW;
  245. if (fb->panel->caps && fb->board->caps && var->bits_per_pixel >= 16) {
  246. /*
  247. * if board and panel supply capabilities, we can support
  248. * changing BGR/RGB depending on supplied parameters. Here
  249. * we switch to what the framebuffer is providing if need
  250. * be, so if the framebuffer is BGR but the display connection
  251. * is RGB (first case) we switch it around. Vice versa mutatis
  252. * mutandis if the framebuffer is RGB but the display connection
  253. * is BGR, we flip it around.
  254. */
  255. if (var->red.offset == 0)
  256. val &= ~CNTL_BGR;
  257. else
  258. val |= CNTL_BGR;
  259. if (fb->panel->bgr_connection)
  260. val ^= CNTL_BGR;
  261. }
  262. switch (var->bits_per_pixel) {
  263. case 1:
  264. val |= CNTL_LCDBPP1;
  265. break;
  266. case 2:
  267. val |= CNTL_LCDBPP2;
  268. break;
  269. case 4:
  270. val |= CNTL_LCDBPP4;
  271. break;
  272. case 8:
  273. val |= CNTL_LCDBPP8;
  274. break;
  275. case 16:
  276. /*
  277. * PL110 cannot choose between 5551 and 565 modes in its
  278. * control register. It is possible to use 565 with
  279. * custom external wiring.
  280. */
  281. if (amba_part(fb->dev) == 0x110 ||
  282. var->green.length == 5)
  283. val |= CNTL_LCDBPP16;
  284. else if (var->green.length == 6)
  285. val |= CNTL_LCDBPP16_565;
  286. else
  287. val |= CNTL_LCDBPP16_444;
  288. break;
  289. case 24:
  290. /* Modified variant supporting 24 bit packed pixels */
  291. val |= CNTL_ST_LCDBPP24_PACKED;
  292. break;
  293. case 32:
  294. val |= CNTL_LCDBPP24;
  295. break;
  296. }
  297. regs->cntl = val;
  298. regs->pixclock = var->pixclock;
  299. }
  300. static inline int clcdfb_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
  301. {
  302. var->xres_virtual = var->xres = (var->xres + 15) & ~15;
  303. var->yres_virtual = var->yres = (var->yres + 1) & ~1;
  304. #define CHECK(e,l,h) (var->e < l || var->e > h)
  305. if (CHECK(right_margin, (5+1), 256) || /* back porch */
  306. CHECK(left_margin, (5+1), 256) || /* front porch */
  307. CHECK(hsync_len, (5+1), 256) ||
  308. var->xres > 4096 ||
  309. var->lower_margin > 255 || /* back porch */
  310. var->upper_margin > 255 || /* front porch */
  311. var->vsync_len > 32 ||
  312. var->yres > 1024)
  313. return -EINVAL;
  314. #undef CHECK
  315. /* single panel mode: PCD = max(PCD, 1) */
  316. /* dual panel mode: PCD = max(PCD, 5) */
  317. /*
  318. * You can't change the grayscale setting, and
  319. * we can only do non-interlaced video.
  320. */
  321. if (var->grayscale != fb->fb.var.grayscale ||
  322. (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  323. return -EINVAL;
  324. #define CHECK(e) (var->e != fb->fb.var.e)
  325. if (fb->panel->fixedtimings &&
  326. (CHECK(xres) ||
  327. CHECK(yres) ||
  328. CHECK(bits_per_pixel) ||
  329. CHECK(pixclock) ||
  330. CHECK(left_margin) ||
  331. CHECK(right_margin) ||
  332. CHECK(upper_margin) ||
  333. CHECK(lower_margin) ||
  334. CHECK(hsync_len) ||
  335. CHECK(vsync_len) ||
  336. CHECK(sync)))
  337. return -EINVAL;
  338. #undef CHECK
  339. var->nonstd = 0;
  340. var->accel_flags = 0;
  341. return 0;
  342. }