clcd.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. enum {
  64. /* individual formats */
  65. CLCD_CAP_RGB444 = (1 << 0),
  66. CLCD_CAP_RGB5551 = (1 << 1),
  67. CLCD_CAP_RGB565 = (1 << 2),
  68. CLCD_CAP_RGB888 = (1 << 3),
  69. CLCD_CAP_BGR444 = (1 << 4),
  70. CLCD_CAP_BGR5551 = (1 << 5),
  71. CLCD_CAP_BGR565 = (1 << 6),
  72. CLCD_CAP_BGR888 = (1 << 7),
  73. /* connection layouts */
  74. CLCD_CAP_444 = CLCD_CAP_RGB444 | CLCD_CAP_BGR444,
  75. CLCD_CAP_5551 = CLCD_CAP_RGB5551 | CLCD_CAP_BGR5551,
  76. CLCD_CAP_565 = CLCD_CAP_RGB565 | CLCD_CAP_BGR565,
  77. CLCD_CAP_888 = CLCD_CAP_RGB888 | CLCD_CAP_BGR888,
  78. /* red/blue ordering */
  79. CLCD_CAP_RGB = CLCD_CAP_RGB444 | CLCD_CAP_RGB5551 |
  80. CLCD_CAP_RGB565 | CLCD_CAP_RGB888,
  81. CLCD_CAP_BGR = CLCD_CAP_BGR444 | CLCD_CAP_BGR5551 |
  82. CLCD_CAP_BGR565 | CLCD_CAP_BGR888,
  83. CLCD_CAP_ALL = CLCD_CAP_BGR | CLCD_CAP_RGB,
  84. };
  85. struct clcd_panel {
  86. struct fb_videomode mode;
  87. signed short width; /* width in mm */
  88. signed short height; /* height in mm */
  89. u32 tim2;
  90. u32 tim3;
  91. u32 cntl;
  92. u32 caps;
  93. unsigned int bpp:8,
  94. fixedtimings:1,
  95. grayscale:1;
  96. unsigned int connector;
  97. };
  98. struct clcd_regs {
  99. u32 tim0;
  100. u32 tim1;
  101. u32 tim2;
  102. u32 tim3;
  103. u32 cntl;
  104. unsigned long pixclock;
  105. };
  106. struct clcd_fb;
  107. /*
  108. * the board-type specific routines
  109. */
  110. struct clcd_board {
  111. const char *name;
  112. /*
  113. * Optional. Hardware capability flags.
  114. */
  115. u32 caps;
  116. /*
  117. * Optional. Check whether the var structure is acceptable
  118. * for this display.
  119. */
  120. int (*check)(struct clcd_fb *fb, struct fb_var_screeninfo *var);
  121. /*
  122. * Compulsary. Decode fb->fb.var into regs->*. In the case of
  123. * fixed timing, set regs->* to the register values required.
  124. */
  125. void (*decode)(struct clcd_fb *fb, struct clcd_regs *regs);
  126. /*
  127. * Optional. Disable any extra display hardware.
  128. */
  129. void (*disable)(struct clcd_fb *);
  130. /*
  131. * Optional. Enable any extra display hardware.
  132. */
  133. void (*enable)(struct clcd_fb *);
  134. /*
  135. * Setup platform specific parts of CLCD driver
  136. */
  137. int (*setup)(struct clcd_fb *);
  138. /*
  139. * mmap the framebuffer memory
  140. */
  141. int (*mmap)(struct clcd_fb *, struct vm_area_struct *);
  142. /*
  143. * Remove platform specific parts of CLCD driver
  144. */
  145. void (*remove)(struct clcd_fb *);
  146. };
  147. struct amba_device;
  148. struct clk;
  149. /* this data structure describes each frame buffer device we find */
  150. struct clcd_fb {
  151. struct fb_info fb;
  152. struct amba_device *dev;
  153. struct clk *clk;
  154. struct clcd_panel *panel;
  155. struct clcd_board *board;
  156. void *board_data;
  157. void __iomem *regs;
  158. u16 off_ienb;
  159. u16 off_cntl;
  160. u32 clcd_cntl;
  161. u32 cmap[16];
  162. bool clk_enabled;
  163. };
  164. static inline void clcdfb_decode(struct clcd_fb *fb, struct clcd_regs *regs)
  165. {
  166. struct fb_var_screeninfo *var = &fb->fb.var;
  167. u32 val, cpl;
  168. /*
  169. * Program the CLCD controller registers and start the CLCD
  170. */
  171. val = ((var->xres / 16) - 1) << 2;
  172. val |= (var->hsync_len - 1) << 8;
  173. val |= (var->right_margin - 1) << 16;
  174. val |= (var->left_margin - 1) << 24;
  175. regs->tim0 = val;
  176. val = var->yres;
  177. if (fb->panel->cntl & CNTL_LCDDUAL)
  178. val /= 2;
  179. val -= 1;
  180. val |= (var->vsync_len - 1) << 10;
  181. val |= var->lower_margin << 16;
  182. val |= var->upper_margin << 24;
  183. regs->tim1 = val;
  184. val = fb->panel->tim2;
  185. val |= var->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : TIM2_IHS;
  186. val |= var->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : TIM2_IVS;
  187. cpl = var->xres_virtual;
  188. if (fb->panel->cntl & CNTL_LCDTFT) /* TFT */
  189. /* / 1 */;
  190. else if (!var->grayscale) /* STN color */
  191. cpl = cpl * 8 / 3;
  192. else if (fb->panel->cntl & CNTL_LCDMONO8) /* STN monochrome, 8bit */
  193. cpl /= 8;
  194. else /* STN monochrome, 4bit */
  195. cpl /= 4;
  196. regs->tim2 = val | ((cpl - 1) << 16);
  197. regs->tim3 = fb->panel->tim3;
  198. val = fb->panel->cntl;
  199. if (var->grayscale)
  200. val |= CNTL_LCDBW;
  201. if (fb->panel->caps && fb->board->caps &&
  202. var->bits_per_pixel >= 16) {
  203. /*
  204. * if board and panel supply capabilities, we can support
  205. * changing BGR/RGB depending on supplied parameters
  206. */
  207. if (var->red.offset == 0)
  208. val &= ~CNTL_BGR;
  209. else
  210. val |= CNTL_BGR;
  211. }
  212. switch (var->bits_per_pixel) {
  213. case 1:
  214. val |= CNTL_LCDBPP1;
  215. break;
  216. case 2:
  217. val |= CNTL_LCDBPP2;
  218. break;
  219. case 4:
  220. val |= CNTL_LCDBPP4;
  221. break;
  222. case 8:
  223. val |= CNTL_LCDBPP8;
  224. break;
  225. case 16:
  226. /*
  227. * PL110 cannot choose between 5551 and 565 modes in its
  228. * control register. It is possible to use 565 with
  229. * custom external wiring.
  230. */
  231. if (amba_part(fb->dev) == 0x110 ||
  232. var->green.length == 5)
  233. val |= CNTL_LCDBPP16;
  234. else if (var->green.length == 6)
  235. val |= CNTL_LCDBPP16_565;
  236. else
  237. val |= CNTL_LCDBPP16_444;
  238. break;
  239. case 32:
  240. val |= CNTL_LCDBPP24;
  241. break;
  242. }
  243. regs->cntl = val;
  244. regs->pixclock = var->pixclock;
  245. }
  246. static inline int clcdfb_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
  247. {
  248. var->xres_virtual = var->xres = (var->xres + 15) & ~15;
  249. var->yres_virtual = var->yres = (var->yres + 1) & ~1;
  250. #define CHECK(e,l,h) (var->e < l || var->e > h)
  251. if (CHECK(right_margin, (5+1), 256) || /* back porch */
  252. CHECK(left_margin, (5+1), 256) || /* front porch */
  253. CHECK(hsync_len, (5+1), 256) ||
  254. var->xres > 4096 ||
  255. var->lower_margin > 255 || /* back porch */
  256. var->upper_margin > 255 || /* front porch */
  257. var->vsync_len > 32 ||
  258. var->yres > 1024)
  259. return -EINVAL;
  260. #undef CHECK
  261. /* single panel mode: PCD = max(PCD, 1) */
  262. /* dual panel mode: PCD = max(PCD, 5) */
  263. /*
  264. * You can't change the grayscale setting, and
  265. * we can only do non-interlaced video.
  266. */
  267. if (var->grayscale != fb->fb.var.grayscale ||
  268. (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  269. return -EINVAL;
  270. #define CHECK(e) (var->e != fb->fb.var.e)
  271. if (fb->panel->fixedtimings &&
  272. (CHECK(xres) ||
  273. CHECK(yres) ||
  274. CHECK(bits_per_pixel) ||
  275. CHECK(pixclock) ||
  276. CHECK(left_margin) ||
  277. CHECK(right_margin) ||
  278. CHECK(upper_margin) ||
  279. CHECK(lower_margin) ||
  280. CHECK(hsync_len) ||
  281. CHECK(vsync_len) ||
  282. CHECK(sync)))
  283. return -EINVAL;
  284. #undef CHECK
  285. var->nonstd = 0;
  286. var->accel_flags = 0;
  287. return 0;
  288. }