clcd.h 6.8 KB

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