amba_clcd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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;
  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 - 1;
  147. val |= (fb->fb.var.vsync_len - 1) << 10;
  148. val |= fb->fb.var.lower_margin << 16;
  149. val |= fb->fb.var.upper_margin << 24;
  150. regs->tim1 = val;
  151. val = fb->panel->tim2;
  152. val |= fb->fb.var.sync & FB_SYNC_HOR_HIGH_ACT ? 0 : TIM2_IHS;
  153. val |= fb->fb.var.sync & FB_SYNC_VERT_HIGH_ACT ? 0 : TIM2_IVS;
  154. if (fb->panel->cntl & CNTL_LCDTFT)
  155. val |= (fb->fb.var.xres_virtual - 1) << 16;
  156. else if (fb->panel->cntl & CNTL_LCDBW)
  157. printk("what value for CPL for stnmono panels?");
  158. else
  159. val |= ((fb->fb.var.xres_virtual * 8 / 3) - 1) << 16;
  160. regs->tim2 = val;
  161. regs->tim3 = fb->panel->tim3;
  162. val = fb->panel->cntl;
  163. if (fb->fb.var.grayscale)
  164. val |= CNTL_LCDBW;
  165. switch (fb->fb.var.bits_per_pixel) {
  166. case 1:
  167. val |= CNTL_LCDBPP1;
  168. break;
  169. case 2:
  170. val |= CNTL_LCDBPP2;
  171. break;
  172. case 4:
  173. val |= CNTL_LCDBPP4;
  174. break;
  175. case 8:
  176. val |= CNTL_LCDBPP8;
  177. break;
  178. case 16:
  179. val |= CNTL_LCDBPP16;
  180. break;
  181. case 24:
  182. val |= CNTL_LCDBPP24;
  183. break;
  184. }
  185. regs->cntl = val;
  186. regs->pixclock = fb->fb.var.pixclock;
  187. }
  188. static inline int clcdfb_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
  189. {
  190. var->xres_virtual = var->xres = (var->xres + 7) & ~7;
  191. var->yres_virtual = var->yres;
  192. #define CHECK(e,l,h) (var->e < l || var->e > h)
  193. if (CHECK(right_margin, (5+1), 256) || /* back porch */
  194. CHECK(left_margin, (5+1), 256) || /* front porch */
  195. CHECK(hsync_len, (5+1), 256) ||
  196. var->xres > 4096 ||
  197. var->lower_margin > 255 || /* back porch */
  198. var->upper_margin > 255 || /* front porch */
  199. var->vsync_len > 32 ||
  200. var->yres > 1024)
  201. return -EINVAL;
  202. #undef CHECK
  203. /* single panel mode: PCD = max(PCD, 1) */
  204. /* dual panel mode: PCD = max(PCD, 5) */
  205. /*
  206. * You can't change the grayscale setting, and
  207. * we can only do non-interlaced video.
  208. */
  209. if (var->grayscale != fb->fb.var.grayscale ||
  210. (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  211. return -EINVAL;
  212. #define CHECK(e) (var->e != fb->fb.var.e)
  213. if (fb->panel->fixedtimings &&
  214. (CHECK(xres) ||
  215. CHECK(yres) ||
  216. CHECK(bits_per_pixel) ||
  217. CHECK(pixclock) ||
  218. CHECK(left_margin) ||
  219. CHECK(right_margin) ||
  220. CHECK(upper_margin) ||
  221. CHECK(lower_margin) ||
  222. CHECK(hsync_len) ||
  223. CHECK(vsync_len) ||
  224. CHECK(sync)))
  225. return -EINVAL;
  226. #undef CHECK
  227. var->nonstd = 0;
  228. var->accel_flags = 0;
  229. return 0;
  230. }