amba_clcd.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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/config.h>
  13. #include <linux/fb.h>
  14. /*
  15. * CLCD Controller Internal Register addresses
  16. */
  17. #define CLCD_TIM0 0x00000000
  18. #define CLCD_TIM1 0x00000004
  19. #define CLCD_TIM2 0x00000008
  20. #define CLCD_TIM3 0x0000000c
  21. #define CLCD_UBAS 0x00000010
  22. #define CLCD_LBAS 0x00000014
  23. #ifndef CONFIG_ARCH_VERSATILE
  24. #define CLCD_IENB 0x00000018
  25. #define CLCD_CNTL 0x0000001c
  26. #else
  27. /*
  28. * Someone rearranged these two registers on the Versatile
  29. * platform...
  30. */
  31. #define CLCD_IENB 0x0000001c
  32. #define CLCD_CNTL 0x00000018
  33. #endif
  34. #define CLCD_STAT 0x00000020
  35. #define CLCD_INTR 0x00000024
  36. #define CLCD_UCUR 0x00000028
  37. #define CLCD_LCUR 0x0000002C
  38. #define CLCD_PALL 0x00000200
  39. #define CLCD_PALETTE 0x00000200
  40. #define TIM2_CLKSEL (1 << 5)
  41. #define TIM2_IVS (1 << 11)
  42. #define TIM2_IHS (1 << 12)
  43. #define TIM2_IPC (1 << 13)
  44. #define TIM2_IOE (1 << 14)
  45. #define TIM2_BCD (1 << 26)
  46. #define CNTL_LCDEN (1 << 0)
  47. #define CNTL_LCDBPP1 (0 << 1)
  48. #define CNTL_LCDBPP2 (1 << 1)
  49. #define CNTL_LCDBPP4 (2 << 1)
  50. #define CNTL_LCDBPP8 (3 << 1)
  51. #define CNTL_LCDBPP16 (4 << 1)
  52. #define CNTL_LCDBPP24 (5 << 1)
  53. #define CNTL_LCDBW (1 << 4)
  54. #define CNTL_LCDTFT (1 << 5)
  55. #define CNTL_LCDMONO8 (1 << 6)
  56. #define CNTL_LCDDUAL (1 << 7)
  57. #define CNTL_BGR (1 << 8)
  58. #define CNTL_BEBO (1 << 9)
  59. #define CNTL_BEPO (1 << 10)
  60. #define CNTL_LCDPWR (1 << 11)
  61. #define CNTL_LCDVCOMP(x) ((x) << 12)
  62. #define CNTL_LDMAFIFOTIME (1 << 15)
  63. #define CNTL_WATERMARK (1 << 16)
  64. struct clcd_panel {
  65. struct fb_videomode mode;
  66. signed short width; /* width in mm */
  67. signed short height; /* height in mm */
  68. u32 tim2;
  69. u32 tim3;
  70. u32 cntl;
  71. unsigned int bpp:8,
  72. fixedtimings:1,
  73. grayscale:1;
  74. unsigned int connector;
  75. };
  76. struct clcd_regs {
  77. u32 tim0;
  78. u32 tim1;
  79. u32 tim2;
  80. u32 tim3;
  81. u32 cntl;
  82. unsigned long pixclock;
  83. };
  84. struct clcd_fb;
  85. /*
  86. * the board-type specific routines
  87. */
  88. struct clcd_board {
  89. const char *name;
  90. /*
  91. * Optional. Check whether the var structure is acceptable
  92. * for this display.
  93. */
  94. int (*check)(struct clcd_fb *fb, struct fb_var_screeninfo *var);
  95. /*
  96. * Compulsary. Decode fb->fb.var into regs->*. In the case of
  97. * fixed timing, set regs->* to the register values required.
  98. */
  99. void (*decode)(struct clcd_fb *fb, struct clcd_regs *regs);
  100. /*
  101. * Optional. Disable any extra display hardware.
  102. */
  103. void (*disable)(struct clcd_fb *);
  104. /*
  105. * Optional. Enable any extra display hardware.
  106. */
  107. void (*enable)(struct clcd_fb *);
  108. /*
  109. * Setup platform specific parts of CLCD driver
  110. */
  111. int (*setup)(struct clcd_fb *);
  112. /*
  113. * mmap the framebuffer memory
  114. */
  115. int (*mmap)(struct clcd_fb *, struct vm_area_struct *);
  116. /*
  117. * Remove platform specific parts of CLCD driver
  118. */
  119. void (*remove)(struct clcd_fb *);
  120. };
  121. struct amba_device;
  122. struct clk;
  123. /* this data structure describes each frame buffer device we find */
  124. struct clcd_fb {
  125. struct fb_info fb;
  126. struct amba_device *dev;
  127. struct clk *clk;
  128. struct clcd_panel *panel;
  129. struct clcd_board *board;
  130. void *board_data;
  131. void __iomem *regs;
  132. u32 clcd_cntl;
  133. u32 cmap[16];
  134. };
  135. static inline void clcdfb_decode(struct clcd_fb *fb, struct clcd_regs *regs)
  136. {
  137. u32 val, cpl;
  138. /*
  139. * Program the CLCD controller registers and start the CLCD
  140. */
  141. val = ((fb->fb.var.xres / 16) - 1) << 2;
  142. val |= (fb->fb.var.hsync_len - 1) << 8;
  143. val |= (fb->fb.var.right_margin - 1) << 16;
  144. val |= (fb->fb.var.left_margin - 1) << 24;
  145. regs->tim0 = val;
  146. val = fb->fb.var.yres;
  147. if (fb->panel->cntl & CNTL_LCDDUAL)
  148. val /= 2;
  149. val -= 1;
  150. val |= (fb->fb.var.vsync_len - 1) << 10;
  151. val |= fb->fb.var.lower_margin << 16;
  152. val |= fb->fb.var.upper_margin << 24;
  153. regs->tim1 = val;
  154. val = fb->panel->tim2;
  155. val |= fb->fb.var.sync & FB_SYNC_HOR_HIGH_ACT ? 0 : TIM2_IHS;
  156. val |= fb->fb.var.sync & FB_SYNC_VERT_HIGH_ACT ? 0 : TIM2_IVS;
  157. cpl = fb->fb.var.xres_virtual;
  158. if (fb->panel->cntl & CNTL_LCDTFT) /* TFT */
  159. /* / 1 */;
  160. else if (!fb->fb.var.grayscale) /* STN color */
  161. cpl = cpl * 8 / 3;
  162. else if (fb->panel->cntl & CNTL_LCDMONO8) /* STN monochrome, 8bit */
  163. cpl /= 8;
  164. else /* STN monochrome, 4bit */
  165. cpl /= 4;
  166. regs->tim2 = val | ((cpl - 1) << 16);
  167. regs->tim3 = fb->panel->tim3;
  168. val = fb->panel->cntl;
  169. if (fb->fb.var.grayscale)
  170. val |= CNTL_LCDBW;
  171. switch (fb->fb.var.bits_per_pixel) {
  172. case 1:
  173. val |= CNTL_LCDBPP1;
  174. break;
  175. case 2:
  176. val |= CNTL_LCDBPP2;
  177. break;
  178. case 4:
  179. val |= CNTL_LCDBPP4;
  180. break;
  181. case 8:
  182. val |= CNTL_LCDBPP8;
  183. break;
  184. case 16:
  185. val |= CNTL_LCDBPP16;
  186. break;
  187. case 32:
  188. val |= CNTL_LCDBPP24;
  189. break;
  190. }
  191. regs->cntl = val;
  192. regs->pixclock = fb->fb.var.pixclock;
  193. }
  194. static inline int clcdfb_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
  195. {
  196. var->xres_virtual = var->xres = (var->xres + 15) & ~15;
  197. var->yres_virtual = var->yres = (var->yres + 1) & ~1;
  198. #define CHECK(e,l,h) (var->e < l || var->e > h)
  199. if (CHECK(right_margin, (5+1), 256) || /* back porch */
  200. CHECK(left_margin, (5+1), 256) || /* front porch */
  201. CHECK(hsync_len, (5+1), 256) ||
  202. var->xres > 4096 ||
  203. var->lower_margin > 255 || /* back porch */
  204. var->upper_margin > 255 || /* front porch */
  205. var->vsync_len > 32 ||
  206. var->yres > 1024)
  207. return -EINVAL;
  208. #undef CHECK
  209. /* single panel mode: PCD = max(PCD, 1) */
  210. /* dual panel mode: PCD = max(PCD, 5) */
  211. /*
  212. * You can't change the grayscale setting, and
  213. * we can only do non-interlaced video.
  214. */
  215. if (var->grayscale != fb->fb.var.grayscale ||
  216. (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  217. return -EINVAL;
  218. #define CHECK(e) (var->e != fb->fb.var.e)
  219. if (fb->panel->fixedtimings &&
  220. (CHECK(xres) ||
  221. CHECK(yres) ||
  222. CHECK(bits_per_pixel) ||
  223. CHECK(pixclock) ||
  224. CHECK(left_margin) ||
  225. CHECK(right_margin) ||
  226. CHECK(upper_margin) ||
  227. CHECK(lower_margin) ||
  228. CHECK(hsync_len) ||
  229. CHECK(vsync_len) ||
  230. CHECK(sync)))
  231. return -EINVAL;
  232. #undef CHECK
  233. var->nonstd = 0;
  234. var->accel_flags = 0;
  235. return 0;
  236. }