clcd.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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_LCDBPP24 (5 << 1)
  51. #define CNTL_LCDBW (1 << 4)
  52. #define CNTL_LCDTFT (1 << 5)
  53. #define CNTL_LCDMONO8 (1 << 6)
  54. #define CNTL_LCDDUAL (1 << 7)
  55. #define CNTL_BGR (1 << 8)
  56. #define CNTL_BEBO (1 << 9)
  57. #define CNTL_BEPO (1 << 10)
  58. #define CNTL_LCDPWR (1 << 11)
  59. #define CNTL_LCDVCOMP(x) ((x) << 12)
  60. #define CNTL_LDMAFIFOTIME (1 << 15)
  61. #define CNTL_WATERMARK (1 << 16)
  62. struct clcd_panel {
  63. struct fb_videomode mode;
  64. signed short width; /* width in mm */
  65. signed short height; /* height in mm */
  66. u32 tim2;
  67. u32 tim3;
  68. u32 cntl;
  69. unsigned int bpp:8,
  70. fixedtimings:1,
  71. grayscale:1;
  72. unsigned int connector;
  73. };
  74. struct clcd_regs {
  75. u32 tim0;
  76. u32 tim1;
  77. u32 tim2;
  78. u32 tim3;
  79. u32 cntl;
  80. unsigned long pixclock;
  81. };
  82. struct clcd_fb;
  83. /*
  84. * the board-type specific routines
  85. */
  86. struct clcd_board {
  87. const char *name;
  88. /*
  89. * Optional. Check whether the var structure is acceptable
  90. * for this display.
  91. */
  92. int (*check)(struct clcd_fb *fb, struct fb_var_screeninfo *var);
  93. /*
  94. * Compulsary. Decode fb->fb.var into regs->*. In the case of
  95. * fixed timing, set regs->* to the register values required.
  96. */
  97. void (*decode)(struct clcd_fb *fb, struct clcd_regs *regs);
  98. /*
  99. * Optional. Disable any extra display hardware.
  100. */
  101. void (*disable)(struct clcd_fb *);
  102. /*
  103. * Optional. Enable any extra display hardware.
  104. */
  105. void (*enable)(struct clcd_fb *);
  106. /*
  107. * Setup platform specific parts of CLCD driver
  108. */
  109. int (*setup)(struct clcd_fb *);
  110. /*
  111. * mmap the framebuffer memory
  112. */
  113. int (*mmap)(struct clcd_fb *, struct vm_area_struct *);
  114. /*
  115. * Remove platform specific parts of CLCD driver
  116. */
  117. void (*remove)(struct clcd_fb *);
  118. };
  119. struct amba_device;
  120. struct clk;
  121. /* this data structure describes each frame buffer device we find */
  122. struct clcd_fb {
  123. struct fb_info fb;
  124. struct amba_device *dev;
  125. struct clk *clk;
  126. struct clcd_panel *panel;
  127. struct clcd_board *board;
  128. void *board_data;
  129. void __iomem *regs;
  130. u16 off_ienb;
  131. u16 off_cntl;
  132. u32 clcd_cntl;
  133. u32 cmap[16];
  134. bool clk_enabled;
  135. };
  136. static inline void clcdfb_decode(struct clcd_fb *fb, struct clcd_regs *regs)
  137. {
  138. u32 val, cpl;
  139. /*
  140. * Program the CLCD controller registers and start the CLCD
  141. */
  142. val = ((fb->fb.var.xres / 16) - 1) << 2;
  143. val |= (fb->fb.var.hsync_len - 1) << 8;
  144. val |= (fb->fb.var.right_margin - 1) << 16;
  145. val |= (fb->fb.var.left_margin - 1) << 24;
  146. regs->tim0 = val;
  147. val = fb->fb.var.yres;
  148. if (fb->panel->cntl & CNTL_LCDDUAL)
  149. val /= 2;
  150. val -= 1;
  151. val |= (fb->fb.var.vsync_len - 1) << 10;
  152. val |= fb->fb.var.lower_margin << 16;
  153. val |= fb->fb.var.upper_margin << 24;
  154. regs->tim1 = val;
  155. val = fb->panel->tim2;
  156. val |= fb->fb.var.sync & FB_SYNC_HOR_HIGH_ACT ? 0 : TIM2_IHS;
  157. val |= fb->fb.var.sync & FB_SYNC_VERT_HIGH_ACT ? 0 : TIM2_IVS;
  158. cpl = fb->fb.var.xres_virtual;
  159. if (fb->panel->cntl & CNTL_LCDTFT) /* TFT */
  160. /* / 1 */;
  161. else if (!fb->fb.var.grayscale) /* STN color */
  162. cpl = cpl * 8 / 3;
  163. else if (fb->panel->cntl & CNTL_LCDMONO8) /* STN monochrome, 8bit */
  164. cpl /= 8;
  165. else /* STN monochrome, 4bit */
  166. cpl /= 4;
  167. regs->tim2 = val | ((cpl - 1) << 16);
  168. regs->tim3 = fb->panel->tim3;
  169. val = fb->panel->cntl;
  170. if (fb->fb.var.grayscale)
  171. val |= CNTL_LCDBW;
  172. switch (fb->fb.var.bits_per_pixel) {
  173. case 1:
  174. val |= CNTL_LCDBPP1;
  175. break;
  176. case 2:
  177. val |= CNTL_LCDBPP2;
  178. break;
  179. case 4:
  180. val |= CNTL_LCDBPP4;
  181. break;
  182. case 8:
  183. val |= CNTL_LCDBPP8;
  184. break;
  185. case 16:
  186. /*
  187. * PL110 cannot choose between 5551 and 565 modes in
  188. * its control register
  189. */
  190. if ((fb->dev->periphid & 0x000fffff) == 0x00041110)
  191. val |= CNTL_LCDBPP16;
  192. else if (fb->fb.var.green.length == 5)
  193. val |= CNTL_LCDBPP16;
  194. else
  195. val |= CNTL_LCDBPP16_565;
  196. break;
  197. case 32:
  198. val |= CNTL_LCDBPP24;
  199. break;
  200. }
  201. regs->cntl = val;
  202. regs->pixclock = fb->fb.var.pixclock;
  203. }
  204. static inline int clcdfb_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
  205. {
  206. var->xres_virtual = var->xres = (var->xres + 15) & ~15;
  207. var->yres_virtual = var->yres = (var->yres + 1) & ~1;
  208. #define CHECK(e,l,h) (var->e < l || var->e > h)
  209. if (CHECK(right_margin, (5+1), 256) || /* back porch */
  210. CHECK(left_margin, (5+1), 256) || /* front porch */
  211. CHECK(hsync_len, (5+1), 256) ||
  212. var->xres > 4096 ||
  213. var->lower_margin > 255 || /* back porch */
  214. var->upper_margin > 255 || /* front porch */
  215. var->vsync_len > 32 ||
  216. var->yres > 1024)
  217. return -EINVAL;
  218. #undef CHECK
  219. /* single panel mode: PCD = max(PCD, 1) */
  220. /* dual panel mode: PCD = max(PCD, 5) */
  221. /*
  222. * You can't change the grayscale setting, and
  223. * we can only do non-interlaced video.
  224. */
  225. if (var->grayscale != fb->fb.var.grayscale ||
  226. (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  227. return -EINVAL;
  228. #define CHECK(e) (var->e != fb->fb.var.e)
  229. if (fb->panel->fixedtimings &&
  230. (CHECK(xres) ||
  231. CHECK(yres) ||
  232. CHECK(bits_per_pixel) ||
  233. CHECK(pixclock) ||
  234. CHECK(left_margin) ||
  235. CHECK(right_margin) ||
  236. CHECK(upper_margin) ||
  237. CHECK(lower_margin) ||
  238. CHECK(hsync_len) ||
  239. CHECK(vsync_len) ||
  240. CHECK(sync)))
  241. return -EINVAL;
  242. #undef CHECK
  243. var->nonstd = 0;
  244. var->accel_flags = 0;
  245. return 0;
  246. }