s1d13xxxfb.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. /* drivers/video/s1d13xxxfb.c
  2. *
  3. * (c) 2004 Simtec Electronics
  4. * (c) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. * (c) 2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
  6. *
  7. * Driver for Epson S1D13xxx series framebuffer chips
  8. *
  9. * Adapted from
  10. * linux/drivers/video/skeletonfb.c
  11. * linux/drivers/video/epson1355fb.c
  12. * linux/drivers/video/epson/s1d13xxxfb.c (2.4 driver by Epson)
  13. *
  14. * TODO: - handle dual screen display (CRT and LCD at the same time).
  15. * - check_var(), mode change, etc.
  16. * - probably not SMP safe :)
  17. * - support all bitblt operations on all cards
  18. *
  19. * This file is subject to the terms and conditions of the GNU General Public
  20. * License. See the file COPYING in the main directory of this archive for
  21. * more details.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/delay.h>
  26. #include <linux/types.h>
  27. #include <linux/errno.h>
  28. #include <linux/mm.h>
  29. #include <linux/mman.h>
  30. #include <linux/fb.h>
  31. #include <linux/spinlock_types.h>
  32. #include <linux/spinlock.h>
  33. #include <linux/slab.h>
  34. #include <linux/io.h>
  35. #include <video/s1d13xxxfb.h>
  36. #define PFX "s1d13xxxfb: "
  37. #define BLIT "s1d13xxxfb_bitblt: "
  38. /*
  39. * set this to enable debugging on general functions
  40. */
  41. #if 0
  42. #define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0)
  43. #else
  44. #define dbg(fmt, args...) do { } while (0)
  45. #endif
  46. /*
  47. * set this to enable debugging on 2D acceleration
  48. */
  49. #if 0
  50. #define dbg_blit(fmt, args...) do { printk(KERN_INFO BLIT fmt, ## args); } while (0)
  51. #else
  52. #define dbg_blit(fmt, args...) do { } while (0)
  53. #endif
  54. /*
  55. * we make sure only one bitblt operation is running
  56. */
  57. static DEFINE_SPINLOCK(s1d13xxxfb_bitblt_lock);
  58. /*
  59. * list of card production ids
  60. */
  61. static const int s1d13xxxfb_prod_ids[] = {
  62. S1D13505_PROD_ID,
  63. S1D13506_PROD_ID,
  64. S1D13806_PROD_ID,
  65. };
  66. /*
  67. * List of card strings
  68. */
  69. static const char *s1d13xxxfb_prod_names[] = {
  70. "S1D13505",
  71. "S1D13506",
  72. "S1D13806",
  73. };
  74. /*
  75. * here we define the default struct fb_fix_screeninfo
  76. */
  77. static struct fb_fix_screeninfo s1d13xxxfb_fix = {
  78. .id = S1D_FBID,
  79. .type = FB_TYPE_PACKED_PIXELS,
  80. .visual = FB_VISUAL_PSEUDOCOLOR,
  81. .xpanstep = 0,
  82. .ypanstep = 1,
  83. .ywrapstep = 0,
  84. .accel = FB_ACCEL_NONE,
  85. };
  86. static inline u8
  87. s1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno)
  88. {
  89. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
  90. regno=((regno & 1) ? (regno & ~1L) : (regno + 1));
  91. #endif
  92. return readb(par->regs + regno);
  93. }
  94. static inline void
  95. s1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value)
  96. {
  97. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
  98. regno=((regno & 1) ? (regno & ~1L) : (regno + 1));
  99. #endif
  100. writeb(value, par->regs + regno);
  101. }
  102. static inline void
  103. s1d13xxxfb_runinit(struct s1d13xxxfb_par *par,
  104. const struct s1d13xxxfb_regval *initregs,
  105. const unsigned int size)
  106. {
  107. int i;
  108. for (i = 0; i < size; i++) {
  109. if ((initregs[i].addr == S1DREG_DELAYOFF) ||
  110. (initregs[i].addr == S1DREG_DELAYON))
  111. mdelay((int)initregs[i].value);
  112. else {
  113. s1d13xxxfb_writereg(par, initregs[i].addr, initregs[i].value);
  114. }
  115. }
  116. /* make sure the hardware can cope with us */
  117. mdelay(1);
  118. }
  119. static inline void
  120. lcd_enable(struct s1d13xxxfb_par *par, int enable)
  121. {
  122. u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
  123. if (enable)
  124. mode |= 0x01;
  125. else
  126. mode &= ~0x01;
  127. s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode);
  128. }
  129. static inline void
  130. crt_enable(struct s1d13xxxfb_par *par, int enable)
  131. {
  132. u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
  133. if (enable)
  134. mode |= 0x02;
  135. else
  136. mode &= ~0x02;
  137. s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode);
  138. }
  139. /*************************************************************
  140. framebuffer control functions
  141. *************************************************************/
  142. static inline void
  143. s1d13xxxfb_setup_pseudocolour(struct fb_info *info)
  144. {
  145. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  146. info->var.red.length = 4;
  147. info->var.green.length = 4;
  148. info->var.blue.length = 4;
  149. }
  150. static inline void
  151. s1d13xxxfb_setup_truecolour(struct fb_info *info)
  152. {
  153. info->fix.visual = FB_VISUAL_TRUECOLOR;
  154. info->var.bits_per_pixel = 16;
  155. info->var.red.length = 5;
  156. info->var.red.offset = 11;
  157. info->var.green.length = 6;
  158. info->var.green.offset = 5;
  159. info->var.blue.length = 5;
  160. info->var.blue.offset = 0;
  161. }
  162. /**
  163. * s1d13xxxfb_set_par - Alters the hardware state.
  164. * @info: frame buffer structure
  165. *
  166. * Using the fb_var_screeninfo in fb_info we set the depth of the
  167. * framebuffer. This function alters the par AND the
  168. * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
  169. * fb_info since we are using that data. This means we depend on the
  170. * data in var inside fb_info to be supported by the hardware.
  171. * xxxfb_check_var is always called before xxxfb_set_par to ensure this.
  172. *
  173. * XXX TODO: write proper s1d13xxxfb_check_var(), without which that
  174. * function is quite useless.
  175. */
  176. static int
  177. s1d13xxxfb_set_par(struct fb_info *info)
  178. {
  179. struct s1d13xxxfb_par *s1dfb = info->par;
  180. unsigned int val;
  181. dbg("s1d13xxxfb_set_par: bpp=%d\n", info->var.bits_per_pixel);
  182. if ((s1dfb->display & 0x01)) /* LCD */
  183. val = s1d13xxxfb_readreg(s1dfb, S1DREG_LCD_DISP_MODE); /* read colour control */
  184. else /* CRT */
  185. val = s1d13xxxfb_readreg(s1dfb, S1DREG_CRT_DISP_MODE); /* read colour control */
  186. val &= ~0x07;
  187. switch (info->var.bits_per_pixel) {
  188. case 4:
  189. dbg("pseudo colour 4\n");
  190. s1d13xxxfb_setup_pseudocolour(info);
  191. val |= 2;
  192. break;
  193. case 8:
  194. dbg("pseudo colour 8\n");
  195. s1d13xxxfb_setup_pseudocolour(info);
  196. val |= 3;
  197. break;
  198. case 16:
  199. dbg("true colour\n");
  200. s1d13xxxfb_setup_truecolour(info);
  201. val |= 5;
  202. break;
  203. default:
  204. dbg("bpp not supported!\n");
  205. return -EINVAL;
  206. }
  207. dbg("writing %02x to display mode register\n", val);
  208. if ((s1dfb->display & 0x01)) /* LCD */
  209. s1d13xxxfb_writereg(s1dfb, S1DREG_LCD_DISP_MODE, val);
  210. else /* CRT */
  211. s1d13xxxfb_writereg(s1dfb, S1DREG_CRT_DISP_MODE, val);
  212. info->fix.line_length = info->var.xres * info->var.bits_per_pixel;
  213. info->fix.line_length /= 8;
  214. dbg("setting line_length to %d\n", info->fix.line_length);
  215. dbg("done setup\n");
  216. return 0;
  217. }
  218. /**
  219. * s1d13xxxfb_setcolreg - sets a color register.
  220. * @regno: Which register in the CLUT we are programming
  221. * @red: The red value which can be up to 16 bits wide
  222. * @green: The green value which can be up to 16 bits wide
  223. * @blue: The blue value which can be up to 16 bits wide.
  224. * @transp: If supported the alpha value which can be up to 16 bits wide.
  225. * @info: frame buffer info structure
  226. *
  227. * Returns negative errno on error, or zero on success.
  228. */
  229. static int
  230. s1d13xxxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  231. u_int transp, struct fb_info *info)
  232. {
  233. struct s1d13xxxfb_par *s1dfb = info->par;
  234. unsigned int pseudo_val;
  235. if (regno >= S1D_PALETTE_SIZE)
  236. return -EINVAL;
  237. dbg("s1d13xxxfb_setcolreg: %d: rgb=%d,%d,%d, tr=%d\n",
  238. regno, red, green, blue, transp);
  239. if (info->var.grayscale)
  240. red = green = blue = (19595*red + 38470*green + 7471*blue) >> 16;
  241. switch (info->fix.visual) {
  242. case FB_VISUAL_TRUECOLOR:
  243. if (regno >= 16)
  244. return -EINVAL;
  245. /* deal with creating pseudo-palette entries */
  246. pseudo_val = (red >> 11) << info->var.red.offset;
  247. pseudo_val |= (green >> 10) << info->var.green.offset;
  248. pseudo_val |= (blue >> 11) << info->var.blue.offset;
  249. dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n",
  250. regno, pseudo_val);
  251. #if defined(CONFIG_PLAT_MAPPI)
  252. ((u32 *)info->pseudo_palette)[regno] = cpu_to_le16(pseudo_val);
  253. #else
  254. ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
  255. #endif
  256. break;
  257. case FB_VISUAL_PSEUDOCOLOR:
  258. s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_ADDR, regno);
  259. s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, red);
  260. s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, green);
  261. s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, blue);
  262. break;
  263. default:
  264. return -ENOSYS;
  265. }
  266. dbg("s1d13xxxfb_setcolreg: done\n");
  267. return 0;
  268. }
  269. /**
  270. * s1d13xxxfb_blank - blanks the display.
  271. * @blank_mode: the blank mode we want.
  272. * @info: frame buffer structure that represents a single frame buffer
  273. *
  274. * Blank the screen if blank_mode != 0, else unblank. Return 0 if
  275. * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
  276. * video mode which doesn't support it. Implements VESA suspend
  277. * and powerdown modes on hardware that supports disabling hsync/vsync:
  278. * blank_mode == 2: suspend vsync
  279. * blank_mode == 3: suspend hsync
  280. * blank_mode == 4: powerdown
  281. *
  282. * Returns negative errno on error, or zero on success.
  283. */
  284. static int
  285. s1d13xxxfb_blank(int blank_mode, struct fb_info *info)
  286. {
  287. struct s1d13xxxfb_par *par = info->par;
  288. dbg("s1d13xxxfb_blank: blank=%d, info=%p\n", blank_mode, info);
  289. switch (blank_mode) {
  290. case FB_BLANK_UNBLANK:
  291. case FB_BLANK_NORMAL:
  292. if ((par->display & 0x01) != 0)
  293. lcd_enable(par, 1);
  294. if ((par->display & 0x02) != 0)
  295. crt_enable(par, 1);
  296. break;
  297. case FB_BLANK_VSYNC_SUSPEND:
  298. case FB_BLANK_HSYNC_SUSPEND:
  299. break;
  300. case FB_BLANK_POWERDOWN:
  301. lcd_enable(par, 0);
  302. crt_enable(par, 0);
  303. break;
  304. default:
  305. return -EINVAL;
  306. }
  307. /* let fbcon do a soft blank for us */
  308. return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
  309. }
  310. /**
  311. * s1d13xxxfb_pan_display - Pans the display.
  312. * @var: frame buffer variable screen structure
  313. * @info: frame buffer structure that represents a single frame buffer
  314. *
  315. * Pan (or wrap, depending on the `vmode' field) the display using the
  316. * `yoffset' field of the `var' structure (`xoffset' not yet supported).
  317. * If the values don't fit, return -EINVAL.
  318. *
  319. * Returns negative errno on error, or zero on success.
  320. */
  321. static int
  322. s1d13xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  323. {
  324. struct s1d13xxxfb_par *par = info->par;
  325. u32 start;
  326. if (var->xoffset != 0) /* not yet ... */
  327. return -EINVAL;
  328. if (var->yoffset + info->var.yres > info->var.yres_virtual)
  329. return -EINVAL;
  330. start = (info->fix.line_length >> 1) * var->yoffset;
  331. if ((par->display & 0x01)) {
  332. /* LCD */
  333. s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START0, (start & 0xff));
  334. s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START1, ((start >> 8) & 0xff));
  335. s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START2, ((start >> 16) & 0x0f));
  336. } else {
  337. /* CRT */
  338. s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START0, (start & 0xff));
  339. s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START1, ((start >> 8) & 0xff));
  340. s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START2, ((start >> 16) & 0x0f));
  341. }
  342. return 0;
  343. }
  344. /************************************************************
  345. functions to handle bitblt acceleration
  346. ************************************************************/
  347. /**
  348. * bltbit_wait_bitclear - waits for change in register value
  349. * @info : frambuffer structure
  350. * @bit : value currently in register
  351. * @timeout : ...
  352. *
  353. * waits until value changes FROM bit
  354. *
  355. */
  356. static u8
  357. bltbit_wait_bitclear(struct fb_info *info, u8 bit, int timeout)
  358. {
  359. while (s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0) & bit) {
  360. udelay(10);
  361. if (!--timeout) {
  362. dbg_blit("wait_bitclear timeout\n");
  363. break;
  364. }
  365. }
  366. return timeout;
  367. }
  368. /*
  369. * s1d13xxxfb_bitblt_copyarea - accelerated copyarea function
  370. * @info : framebuffer structure
  371. * @area : fb_copyarea structure
  372. *
  373. * supports (atleast) S1D13506
  374. *
  375. */
  376. static void
  377. s1d13xxxfb_bitblt_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  378. {
  379. u32 dst, src;
  380. u32 stride;
  381. u16 reverse = 0;
  382. u16 sx = area->sx, sy = area->sy;
  383. u16 dx = area->dx, dy = area->dy;
  384. u16 width = area->width, height = area->height;
  385. u16 bpp;
  386. spin_lock(&s1d13xxxfb_bitblt_lock);
  387. /* bytes per xres line */
  388. bpp = (info->var.bits_per_pixel >> 3);
  389. stride = bpp * info->var.xres;
  390. /* reverse, calculate the last pixel in rectangle */
  391. if ((dy > sy) || ((dy == sy) && (dx >= sx))) {
  392. dst = (((dy + height - 1) * stride) + (bpp * (dx + width - 1)));
  393. src = (((sy + height - 1) * stride) + (bpp * (sx + width - 1)));
  394. reverse = 1;
  395. /* not reverse, calculate the first pixel in rectangle */
  396. } else { /* (y * xres) + (bpp * x) */
  397. dst = (dy * stride) + (bpp * dx);
  398. src = (sy * stride) + (bpp * sx);
  399. }
  400. /* set source address */
  401. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START0, (src & 0xff));
  402. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START1, (src >> 8) & 0x00ff);
  403. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START2, (src >> 16) & 0x00ff);
  404. /* set destination address */
  405. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dst & 0xff));
  406. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, (dst >> 8) & 0x00ff);
  407. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, (dst >> 16) & 0x00ff);
  408. /* program height and width */
  409. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, (width & 0xff) - 1);
  410. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (width >> 8));
  411. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, (height & 0xff) - 1);
  412. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (height >> 8));
  413. /* negative direction ROP */
  414. if (reverse == 1) {
  415. dbg_blit("(copyarea) negative rop\n");
  416. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x03);
  417. } else /* positive direction ROP */ {
  418. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x02);
  419. dbg_blit("(copyarea) positive rop\n");
  420. }
  421. /* set for rectangel mode and not linear */
  422. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0);
  423. /* setup the bpp 1 = 16bpp, 0 = 8bpp*/
  424. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (bpp >> 1));
  425. /* set words per xres */
  426. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (stride >> 1) & 0xff);
  427. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (stride >> 9));
  428. dbg_blit("(copyarea) dx=%d, dy=%d\n", dx, dy);
  429. dbg_blit("(copyarea) sx=%d, sy=%d\n", sx, sy);
  430. dbg_blit("(copyarea) width=%d, height=%d\n", width - 1, height - 1);
  431. dbg_blit("(copyarea) stride=%d\n", stride);
  432. dbg_blit("(copyarea) bpp=%d=0x0%d, mem_offset1=%d, mem_offset2=%d\n", bpp, (bpp >> 1),
  433. (stride >> 1) & 0xff, stride >> 9);
  434. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CC_EXP, 0x0c);
  435. /* initialize the engine */
  436. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80);
  437. /* wait to complete */
  438. bltbit_wait_bitclear(info, 0x80, 8000);
  439. spin_unlock(&s1d13xxxfb_bitblt_lock);
  440. }
  441. /**
  442. *
  443. * s1d13xxxfb_bitblt_solidfill - accelerated solidfill function
  444. * @info : framebuffer structure
  445. * @rect : fb_fillrect structure
  446. *
  447. * supports (atleast 13506)
  448. *
  449. **/
  450. static void
  451. s1d13xxxfb_bitblt_solidfill(struct fb_info *info, const struct fb_fillrect *rect)
  452. {
  453. u32 screen_stride, dest;
  454. u32 fg;
  455. u16 bpp = (info->var.bits_per_pixel >> 3);
  456. /* grab spinlock */
  457. spin_lock(&s1d13xxxfb_bitblt_lock);
  458. /* bytes per x width */
  459. screen_stride = (bpp * info->var.xres);
  460. /* bytes to starting point */
  461. dest = ((rect->dy * screen_stride) + (bpp * rect->dx));
  462. dbg_blit("(solidfill) dx=%d, dy=%d, stride=%d, dest=%d\n"
  463. "(solidfill) : rect_width=%d, rect_height=%d\n",
  464. rect->dx, rect->dy, screen_stride, dest,
  465. rect->width - 1, rect->height - 1);
  466. dbg_blit("(solidfill) : xres=%d, yres=%d, bpp=%d\n",
  467. info->var.xres, info->var.yres,
  468. info->var.bits_per_pixel);
  469. dbg_blit("(solidfill) : rop=%d\n", rect->rop);
  470. /* We split the destination into the three registers */
  471. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dest & 0x00ff));
  472. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, ((dest >> 8) & 0x00ff));
  473. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, ((dest >> 16) & 0x00ff));
  474. /* give information regarding rectangel width */
  475. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, ((rect->width) & 0x00ff) - 1);
  476. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (rect->width >> 8));
  477. /* give information regarding rectangel height */
  478. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, ((rect->height) & 0x00ff) - 1);
  479. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (rect->height >> 8));
  480. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  481. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  482. fg = ((u32 *)info->pseudo_palette)[rect->color];
  483. dbg_blit("(solidfill) truecolor/directcolor\n");
  484. dbg_blit("(solidfill) pseudo_palette[%d] = %d\n", rect->color, fg);
  485. } else {
  486. fg = rect->color;
  487. dbg_blit("(solidfill) color = %d\n", rect->color);
  488. }
  489. /* set foreground color */
  490. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC0, (fg & 0xff));
  491. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC1, (fg >> 8) & 0xff);
  492. /* set rectangual region of memory (rectangle and not linear) */
  493. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0);
  494. /* set operation mode SOLID_FILL */
  495. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, BBLT_SOLID_FILL);
  496. /* set bits per pixel (1 = 16bpp, 0 = 8bpp) */
  497. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (info->var.bits_per_pixel >> 4));
  498. /* set the memory offset for the bblt in word sizes */
  499. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (screen_stride >> 1) & 0x00ff);
  500. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (screen_stride >> 9));
  501. /* and away we go.... */
  502. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80);
  503. /* wait until its done */
  504. bltbit_wait_bitclear(info, 0x80, 8000);
  505. /* let others play */
  506. spin_unlock(&s1d13xxxfb_bitblt_lock);
  507. }
  508. /* framebuffer information structures */
  509. static struct fb_ops s1d13xxxfb_fbops = {
  510. .owner = THIS_MODULE,
  511. .fb_set_par = s1d13xxxfb_set_par,
  512. .fb_setcolreg = s1d13xxxfb_setcolreg,
  513. .fb_blank = s1d13xxxfb_blank,
  514. .fb_pan_display = s1d13xxxfb_pan_display,
  515. /* gets replaced at chip detection time */
  516. .fb_fillrect = cfb_fillrect,
  517. .fb_copyarea = cfb_copyarea,
  518. .fb_imageblit = cfb_imageblit,
  519. };
  520. static int s1d13xxxfb_width_tab[2][4] = {
  521. {4, 8, 16, -1},
  522. {9, 12, 18, -1},
  523. };
  524. /**
  525. * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to
  526. * hardware setup.
  527. * @info: frame buffer structure
  528. *
  529. * We setup the framebuffer structures according to the current
  530. * hardware setup. On some machines, the BIOS will have filled
  531. * the chip registers with such info, on others, these values will
  532. * have been written in some init procedure. In any case, the
  533. * software values needs to match the hardware ones. This is what
  534. * this function ensures.
  535. *
  536. * Note: some of the hardcoded values here might need some love to
  537. * work on various chips, and might need to no longer be hardcoded.
  538. */
  539. static void s1d13xxxfb_fetch_hw_state(struct fb_info *info)
  540. {
  541. struct fb_var_screeninfo *var = &info->var;
  542. struct fb_fix_screeninfo *fix = &info->fix;
  543. struct s1d13xxxfb_par *par = info->par;
  544. u8 panel, display;
  545. u16 offset;
  546. u32 xres, yres;
  547. u32 xres_virtual, yres_virtual;
  548. int bpp, lcd_bpp;
  549. int is_color, is_dual, is_tft;
  550. int lcd_enabled, crt_enabled;
  551. fix->type = FB_TYPE_PACKED_PIXELS;
  552. /* general info */
  553. par->display = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
  554. crt_enabled = (par->display & 0x02) != 0;
  555. lcd_enabled = (par->display & 0x01) != 0;
  556. if (lcd_enabled && crt_enabled)
  557. printk(KERN_WARNING PFX "Warning: LCD and CRT detected, using LCD\n");
  558. if (lcd_enabled)
  559. display = s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_MODE);
  560. else /* CRT */
  561. display = s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_MODE);
  562. bpp = display & 0x07;
  563. switch (bpp) {
  564. case 2: /* 4 bpp */
  565. case 3: /* 8 bpp */
  566. var->bits_per_pixel = 8;
  567. var->red.offset = var->green.offset = var->blue.offset = 0;
  568. var->red.length = var->green.length = var->blue.length = 8;
  569. break;
  570. case 5: /* 16 bpp */
  571. s1d13xxxfb_setup_truecolour(info);
  572. break;
  573. default:
  574. dbg("bpp: %i\n", bpp);
  575. }
  576. fb_alloc_cmap(&info->cmap, 256, 0);
  577. /* LCD info */
  578. panel = s1d13xxxfb_readreg(par, S1DREG_PANEL_TYPE);
  579. is_color = (panel & 0x04) != 0;
  580. is_dual = (panel & 0x02) != 0;
  581. is_tft = (panel & 0x01) != 0;
  582. lcd_bpp = s1d13xxxfb_width_tab[is_tft][(panel >> 4) & 3];
  583. if (lcd_enabled) {
  584. xres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_HWIDTH) + 1) * 8;
  585. yres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT0) +
  586. ((s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT1) & 0x03) << 8) + 1);
  587. offset = (s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF0) +
  588. ((s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF1) & 0x7) << 8));
  589. } else { /* crt */
  590. xres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_HWIDTH) + 1) * 8;
  591. yres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT0) +
  592. ((s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT1) & 0x03) << 8) + 1);
  593. offset = (s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF0) +
  594. ((s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF1) & 0x7) << 8));
  595. }
  596. xres_virtual = offset * 16 / var->bits_per_pixel;
  597. yres_virtual = fix->smem_len / (offset * 2);
  598. var->xres = xres;
  599. var->yres = yres;
  600. var->xres_virtual = xres_virtual;
  601. var->yres_virtual = yres_virtual;
  602. var->xoffset = var->yoffset = 0;
  603. fix->line_length = offset * 2;
  604. var->grayscale = !is_color;
  605. var->activate = FB_ACTIVATE_NOW;
  606. dbg(PFX "bpp=%d, lcd_bpp=%d, "
  607. "crt_enabled=%d, lcd_enabled=%d\n",
  608. var->bits_per_pixel, lcd_bpp, crt_enabled, lcd_enabled);
  609. dbg(PFX "xres=%d, yres=%d, vxres=%d, vyres=%d "
  610. "is_color=%d, is_dual=%d, is_tft=%d\n",
  611. xres, yres, xres_virtual, yres_virtual, is_color, is_dual, is_tft);
  612. }
  613. static int
  614. s1d13xxxfb_remove(struct platform_device *pdev)
  615. {
  616. struct fb_info *info = platform_get_drvdata(pdev);
  617. struct s1d13xxxfb_par *par = NULL;
  618. if (info) {
  619. par = info->par;
  620. if (par && par->regs) {
  621. /* disable output & enable powersave */
  622. s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, 0x00);
  623. s1d13xxxfb_writereg(par, S1DREG_PS_CNF, 0x11);
  624. iounmap(par->regs);
  625. }
  626. fb_dealloc_cmap(&info->cmap);
  627. if (info->screen_base)
  628. iounmap(info->screen_base);
  629. framebuffer_release(info);
  630. }
  631. release_mem_region(pdev->resource[0].start,
  632. pdev->resource[0].end - pdev->resource[0].start +1);
  633. release_mem_region(pdev->resource[1].start,
  634. pdev->resource[1].end - pdev->resource[1].start +1);
  635. return 0;
  636. }
  637. static int s1d13xxxfb_probe(struct platform_device *pdev)
  638. {
  639. struct s1d13xxxfb_par *default_par;
  640. struct fb_info *info;
  641. struct s1d13xxxfb_pdata *pdata = NULL;
  642. int ret = 0;
  643. int i;
  644. u8 revision, prod_id;
  645. dbg("probe called: device is %p\n", pdev);
  646. printk(KERN_INFO "Epson S1D13XXX FB Driver\n");
  647. /* enable platform-dependent hardware glue, if any */
  648. if (dev_get_platdata(&pdev->dev))
  649. pdata = dev_get_platdata(&pdev->dev);
  650. if (pdata && pdata->platform_init_video)
  651. pdata->platform_init_video();
  652. if (pdev->num_resources != 2) {
  653. dev_err(&pdev->dev, "invalid num_resources: %i\n",
  654. pdev->num_resources);
  655. ret = -ENODEV;
  656. goto bail;
  657. }
  658. /* resource[0] is VRAM, resource[1] is registers */
  659. if (pdev->resource[0].flags != IORESOURCE_MEM
  660. || pdev->resource[1].flags != IORESOURCE_MEM) {
  661. dev_err(&pdev->dev, "invalid resource type\n");
  662. ret = -ENODEV;
  663. goto bail;
  664. }
  665. if (!request_mem_region(pdev->resource[0].start,
  666. pdev->resource[0].end - pdev->resource[0].start +1, "s1d13xxxfb mem")) {
  667. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  668. ret = -EBUSY;
  669. goto bail;
  670. }
  671. if (!request_mem_region(pdev->resource[1].start,
  672. pdev->resource[1].end - pdev->resource[1].start +1, "s1d13xxxfb regs")) {
  673. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  674. ret = -EBUSY;
  675. goto bail;
  676. }
  677. info = framebuffer_alloc(sizeof(struct s1d13xxxfb_par) + sizeof(u32) * 256, &pdev->dev);
  678. if (!info) {
  679. ret = -ENOMEM;
  680. goto bail;
  681. }
  682. platform_set_drvdata(pdev, info);
  683. default_par = info->par;
  684. default_par->regs = ioremap_nocache(pdev->resource[1].start,
  685. pdev->resource[1].end - pdev->resource[1].start +1);
  686. if (!default_par->regs) {
  687. printk(KERN_ERR PFX "unable to map registers\n");
  688. ret = -ENOMEM;
  689. goto bail;
  690. }
  691. info->pseudo_palette = default_par->pseudo_palette;
  692. info->screen_base = ioremap_nocache(pdev->resource[0].start,
  693. pdev->resource[0].end - pdev->resource[0].start +1);
  694. if (!info->screen_base) {
  695. printk(KERN_ERR PFX "unable to map framebuffer\n");
  696. ret = -ENOMEM;
  697. goto bail;
  698. }
  699. /* production id is top 6 bits */
  700. prod_id = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) >> 2;
  701. /* revision id is lower 2 bits */
  702. revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) & 0x3;
  703. ret = -ENODEV;
  704. for (i = 0; i < ARRAY_SIZE(s1d13xxxfb_prod_ids); i++) {
  705. if (prod_id == s1d13xxxfb_prod_ids[i]) {
  706. /* looks like we got it in our list */
  707. default_par->prod_id = prod_id;
  708. default_par->revision = revision;
  709. ret = 0;
  710. break;
  711. }
  712. }
  713. if (!ret) {
  714. printk(KERN_INFO PFX "chip production id %i = %s\n",
  715. prod_id, s1d13xxxfb_prod_names[i]);
  716. printk(KERN_INFO PFX "chip revision %i\n", revision);
  717. } else {
  718. printk(KERN_INFO PFX
  719. "unknown chip production id %i, revision %i\n",
  720. prod_id, revision);
  721. printk(KERN_INFO PFX "please contact maintainer\n");
  722. goto bail;
  723. }
  724. info->fix = s1d13xxxfb_fix;
  725. info->fix.mmio_start = pdev->resource[1].start;
  726. info->fix.mmio_len = pdev->resource[1].end - pdev->resource[1].start + 1;
  727. info->fix.smem_start = pdev->resource[0].start;
  728. info->fix.smem_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  729. printk(KERN_INFO PFX "regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n",
  730. default_par->regs, info->fix.smem_len / 1024, info->screen_base);
  731. info->par = default_par;
  732. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  733. info->fbops = &s1d13xxxfb_fbops;
  734. switch(prod_id) {
  735. case S1D13506_PROD_ID: /* activate acceleration */
  736. s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
  737. s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
  738. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
  739. FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
  740. break;
  741. default:
  742. break;
  743. }
  744. /* perform "manual" chip initialization, if needed */
  745. if (pdata && pdata->initregs)
  746. s1d13xxxfb_runinit(info->par, pdata->initregs, pdata->initregssize);
  747. s1d13xxxfb_fetch_hw_state(info);
  748. if (register_framebuffer(info) < 0) {
  749. ret = -EINVAL;
  750. goto bail;
  751. }
  752. fb_info(info, "%s frame buffer device\n", info->fix.id);
  753. return 0;
  754. bail:
  755. s1d13xxxfb_remove(pdev);
  756. return ret;
  757. }
  758. #ifdef CONFIG_PM
  759. static int s1d13xxxfb_suspend(struct platform_device *dev, pm_message_t state)
  760. {
  761. struct fb_info *info = platform_get_drvdata(dev);
  762. struct s1d13xxxfb_par *s1dfb = info->par;
  763. struct s1d13xxxfb_pdata *pdata = NULL;
  764. /* disable display */
  765. lcd_enable(s1dfb, 0);
  766. crt_enable(s1dfb, 0);
  767. if (dev_get_platdata(&dev->dev))
  768. pdata = dev_get_platdata(&dev->dev);
  769. #if 0
  770. if (!s1dfb->disp_save)
  771. s1dfb->disp_save = kmalloc(info->fix.smem_len, GFP_KERNEL);
  772. if (!s1dfb->disp_save) {
  773. printk(KERN_ERR PFX "no memory to save screen");
  774. return -ENOMEM;
  775. }
  776. memcpy_fromio(s1dfb->disp_save, info->screen_base, info->fix.smem_len);
  777. #else
  778. s1dfb->disp_save = NULL;
  779. #endif
  780. if (!s1dfb->regs_save)
  781. s1dfb->regs_save = kmalloc(info->fix.mmio_len, GFP_KERNEL);
  782. if (!s1dfb->regs_save) {
  783. printk(KERN_ERR PFX "no memory to save registers");
  784. return -ENOMEM;
  785. }
  786. /* backup all registers */
  787. memcpy_fromio(s1dfb->regs_save, s1dfb->regs, info->fix.mmio_len);
  788. /* now activate power save mode */
  789. s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x11);
  790. if (pdata && pdata->platform_suspend_video)
  791. return pdata->platform_suspend_video();
  792. else
  793. return 0;
  794. }
  795. static int s1d13xxxfb_resume(struct platform_device *dev)
  796. {
  797. struct fb_info *info = platform_get_drvdata(dev);
  798. struct s1d13xxxfb_par *s1dfb = info->par;
  799. struct s1d13xxxfb_pdata *pdata = NULL;
  800. /* awaken the chip */
  801. s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10);
  802. /* do not let go until SDRAM "wakes up" */
  803. while ((s1d13xxxfb_readreg(s1dfb, S1DREG_PS_STATUS) & 0x01))
  804. udelay(10);
  805. if (dev_get_platdata(&dev->dev))
  806. pdata = dev_get_platdata(&dev->dev);
  807. if (s1dfb->regs_save) {
  808. /* will write RO regs, *should* get away with it :) */
  809. memcpy_toio(s1dfb->regs, s1dfb->regs_save, info->fix.mmio_len);
  810. kfree(s1dfb->regs_save);
  811. }
  812. if (s1dfb->disp_save) {
  813. memcpy_toio(info->screen_base, s1dfb->disp_save,
  814. info->fix.smem_len);
  815. kfree(s1dfb->disp_save); /* XXX kmalloc()'d when? */
  816. }
  817. if ((s1dfb->display & 0x01) != 0)
  818. lcd_enable(s1dfb, 1);
  819. if ((s1dfb->display & 0x02) != 0)
  820. crt_enable(s1dfb, 1);
  821. if (pdata && pdata->platform_resume_video)
  822. return pdata->platform_resume_video();
  823. else
  824. return 0;
  825. }
  826. #endif /* CONFIG_PM */
  827. static struct platform_driver s1d13xxxfb_driver = {
  828. .probe = s1d13xxxfb_probe,
  829. .remove = s1d13xxxfb_remove,
  830. #ifdef CONFIG_PM
  831. .suspend = s1d13xxxfb_suspend,
  832. .resume = s1d13xxxfb_resume,
  833. #endif
  834. .driver = {
  835. .name = S1D_DEVICENAME,
  836. },
  837. };
  838. static int __init
  839. s1d13xxxfb_init(void)
  840. {
  841. #ifndef MODULE
  842. if (fb_get_options("s1d13xxxfb", NULL))
  843. return -ENODEV;
  844. #endif
  845. return platform_driver_register(&s1d13xxxfb_driver);
  846. }
  847. static void __exit
  848. s1d13xxxfb_exit(void)
  849. {
  850. platform_driver_unregister(&s1d13xxxfb_driver);
  851. }
  852. module_init(s1d13xxxfb_init);
  853. module_exit(s1d13xxxfb_exit);
  854. MODULE_LICENSE("GPL");
  855. MODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices");
  856. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>");