s1d13xxxfb.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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 <asm/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 __devinitdata 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_bitset - waits for change in register value
  349. * @info : framebuffer structure
  350. * @bit : value expected in register
  351. * @timeout : ...
  352. *
  353. * waits until value changes INTO bit
  354. */
  355. static u8
  356. bltbit_wait_bitset(struct fb_info *info, u8 bit, int timeout)
  357. {
  358. while (!(s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0) & bit)) {
  359. udelay(10);
  360. if (!--timeout) {
  361. dbg_blit("wait_bitset timeout\n");
  362. break;
  363. }
  364. }
  365. return timeout;
  366. }
  367. /**
  368. * bltbit_wait_bitclear - waits for change in register value
  369. * @info : frambuffer structure
  370. * @bit : value currently in register
  371. * @timeout : ...
  372. *
  373. * waits until value changes FROM bit
  374. *
  375. */
  376. static u8
  377. bltbit_wait_bitclear(struct fb_info *info, u8 bit, int timeout)
  378. {
  379. while (s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0) & bit) {
  380. udelay(10);
  381. if (!--timeout) {
  382. dbg_blit("wait_bitclear timeout\n");
  383. break;
  384. }
  385. }
  386. return timeout;
  387. }
  388. /**
  389. * bltbit_fifo_status - checks the current status of the fifo
  390. * @info : framebuffer structure
  391. *
  392. * returns number of free words in buffer
  393. */
  394. static u8
  395. bltbit_fifo_status(struct fb_info *info)
  396. {
  397. u8 status;
  398. status = s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0);
  399. /* its empty so room for 16 words */
  400. if (status & BBLT_FIFO_EMPTY)
  401. return 16;
  402. /* its full so we dont want to add */
  403. if (status & BBLT_FIFO_FULL)
  404. return 0;
  405. /* its atleast half full but we can add one atleast */
  406. if (status & BBLT_FIFO_NOT_FULL)
  407. return 1;
  408. return 0;
  409. }
  410. /*
  411. * s1d13xxxfb_bitblt_copyarea - accelerated copyarea function
  412. * @info : framebuffer structure
  413. * @area : fb_copyarea structure
  414. *
  415. * supports (atleast) S1D13506
  416. *
  417. */
  418. static void
  419. s1d13xxxfb_bitblt_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  420. {
  421. u32 dst, src;
  422. u32 stride;
  423. u16 reverse = 0;
  424. u16 sx = area->sx, sy = area->sy;
  425. u16 dx = area->dx, dy = area->dy;
  426. u16 width = area->width, height = area->height;
  427. u16 bpp;
  428. spin_lock(&s1d13xxxfb_bitblt_lock);
  429. /* bytes per xres line */
  430. bpp = (info->var.bits_per_pixel >> 3);
  431. stride = bpp * info->var.xres;
  432. /* reverse, calculate the last pixel in rectangle */
  433. if ((dy > sy) || ((dy == sy) && (dx >= sx))) {
  434. dst = (((dy + height - 1) * stride) + (bpp * (dx + width - 1)));
  435. src = (((sy + height - 1) * stride) + (bpp * (sx + width - 1)));
  436. reverse = 1;
  437. /* not reverse, calculate the first pixel in rectangle */
  438. } else { /* (y * xres) + (bpp * x) */
  439. dst = (dy * stride) + (bpp * dx);
  440. src = (sy * stride) + (bpp * sx);
  441. }
  442. /* set source address */
  443. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START0, (src & 0xff));
  444. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START1, (src >> 8) & 0x00ff);
  445. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START2, (src >> 16) & 0x00ff);
  446. /* set destination address */
  447. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dst & 0xff));
  448. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, (dst >> 8) & 0x00ff);
  449. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, (dst >> 16) & 0x00ff);
  450. /* program height and width */
  451. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, (width & 0xff) - 1);
  452. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (width >> 8));
  453. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, (height & 0xff) - 1);
  454. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (height >> 8));
  455. /* negative direction ROP */
  456. if (reverse == 1) {
  457. dbg_blit("(copyarea) negative rop\n");
  458. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x03);
  459. } else /* positive direction ROP */ {
  460. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x02);
  461. dbg_blit("(copyarea) positive rop\n");
  462. }
  463. /* set for rectangel mode and not linear */
  464. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0);
  465. /* setup the bpp 1 = 16bpp, 0 = 8bpp*/
  466. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (bpp >> 1));
  467. /* set words per xres */
  468. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (stride >> 1) & 0xff);
  469. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (stride >> 9));
  470. dbg_blit("(copyarea) dx=%d, dy=%d\n", dx, dy);
  471. dbg_blit("(copyarea) sx=%d, sy=%d\n", sx, sy);
  472. dbg_blit("(copyarea) width=%d, height=%d\n", width - 1, height - 1);
  473. dbg_blit("(copyarea) stride=%d\n", stride);
  474. dbg_blit("(copyarea) bpp=%d=0x0%d, mem_offset1=%d, mem_offset2=%d\n", bpp, (bpp >> 1),
  475. (stride >> 1) & 0xff, stride >> 9);
  476. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CC_EXP, 0x0c);
  477. /* initialize the engine */
  478. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80);
  479. /* wait to complete */
  480. bltbit_wait_bitclear(info, 0x80, 8000);
  481. spin_unlock(&s1d13xxxfb_bitblt_lock);
  482. }
  483. /**
  484. *
  485. * s1d13xxxfb_bitblt_solidfill - accelerated solidfill function
  486. * @info : framebuffer structure
  487. * @rect : fb_fillrect structure
  488. *
  489. * supports (atleast 13506)
  490. *
  491. **/
  492. static void
  493. s1d13xxxfb_bitblt_solidfill(struct fb_info *info, const struct fb_fillrect *rect)
  494. {
  495. u32 screen_stride, dest;
  496. u32 fg;
  497. u16 bpp = (info->var.bits_per_pixel >> 3);
  498. /* grab spinlock */
  499. spin_lock(&s1d13xxxfb_bitblt_lock);
  500. /* bytes per x width */
  501. screen_stride = (bpp * info->var.xres);
  502. /* bytes to starting point */
  503. dest = ((rect->dy * screen_stride) + (bpp * rect->dx));
  504. dbg_blit("(solidfill) dx=%d, dy=%d, stride=%d, dest=%d\n"
  505. "(solidfill) : rect_width=%d, rect_height=%d\n",
  506. rect->dx, rect->dy, screen_stride, dest,
  507. rect->width - 1, rect->height - 1);
  508. dbg_blit("(solidfill) : xres=%d, yres=%d, bpp=%d\n",
  509. info->var.xres, info->var.yres,
  510. info->var.bits_per_pixel);
  511. dbg_blit("(solidfill) : rop=%d\n", rect->rop);
  512. /* We split the destination into the three registers */
  513. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dest & 0x00ff));
  514. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, ((dest >> 8) & 0x00ff));
  515. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, ((dest >> 16) & 0x00ff));
  516. /* give information regarding rectangel width */
  517. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, ((rect->width) & 0x00ff) - 1);
  518. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (rect->width >> 8));
  519. /* give information regarding rectangel height */
  520. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, ((rect->height) & 0x00ff) - 1);
  521. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (rect->height >> 8));
  522. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  523. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  524. fg = ((u32 *)info->pseudo_palette)[rect->color];
  525. dbg_blit("(solidfill) truecolor/directcolor\n");
  526. dbg_blit("(solidfill) pseudo_palette[%d] = %d\n", rect->color, fg);
  527. } else {
  528. fg = rect->color;
  529. dbg_blit("(solidfill) color = %d\n", rect->color);
  530. }
  531. /* set foreground color */
  532. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC0, (fg & 0xff));
  533. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC1, (fg >> 8) & 0xff);
  534. /* set rectangual region of memory (rectangle and not linear) */
  535. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0);
  536. /* set operation mode SOLID_FILL */
  537. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, BBLT_SOLID_FILL);
  538. /* set bits per pixel (1 = 16bpp, 0 = 8bpp) */
  539. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (info->var.bits_per_pixel >> 4));
  540. /* set the memory offset for the bblt in word sizes */
  541. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (screen_stride >> 1) & 0x00ff);
  542. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (screen_stride >> 9));
  543. /* and away we go.... */
  544. s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80);
  545. /* wait until its done */
  546. bltbit_wait_bitclear(info, 0x80, 8000);
  547. /* let others play */
  548. spin_unlock(&s1d13xxxfb_bitblt_lock);
  549. }
  550. /* framebuffer information structures */
  551. static struct fb_ops s1d13xxxfb_fbops = {
  552. .owner = THIS_MODULE,
  553. .fb_set_par = s1d13xxxfb_set_par,
  554. .fb_setcolreg = s1d13xxxfb_setcolreg,
  555. .fb_blank = s1d13xxxfb_blank,
  556. .fb_pan_display = s1d13xxxfb_pan_display,
  557. /* gets replaced at chip detection time */
  558. .fb_fillrect = cfb_fillrect,
  559. .fb_copyarea = cfb_copyarea,
  560. .fb_imageblit = cfb_imageblit,
  561. };
  562. static int s1d13xxxfb_width_tab[2][4] __devinitdata = {
  563. {4, 8, 16, -1},
  564. {9, 12, 18, -1},
  565. };
  566. /**
  567. * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to
  568. * hardware setup.
  569. * @info: frame buffer structure
  570. *
  571. * We setup the framebuffer structures according to the current
  572. * hardware setup. On some machines, the BIOS will have filled
  573. * the chip registers with such info, on others, these values will
  574. * have been written in some init procedure. In any case, the
  575. * software values needs to match the hardware ones. This is what
  576. * this function ensures.
  577. *
  578. * Note: some of the hardcoded values here might need some love to
  579. * work on various chips, and might need to no longer be hardcoded.
  580. */
  581. static void __devinit
  582. s1d13xxxfb_fetch_hw_state(struct fb_info *info)
  583. {
  584. struct fb_var_screeninfo *var = &info->var;
  585. struct fb_fix_screeninfo *fix = &info->fix;
  586. struct s1d13xxxfb_par *par = info->par;
  587. u8 panel, display;
  588. u16 offset;
  589. u32 xres, yres;
  590. u32 xres_virtual, yres_virtual;
  591. int bpp, lcd_bpp;
  592. int is_color, is_dual, is_tft;
  593. int lcd_enabled, crt_enabled;
  594. fix->type = FB_TYPE_PACKED_PIXELS;
  595. /* general info */
  596. par->display = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
  597. crt_enabled = (par->display & 0x02) != 0;
  598. lcd_enabled = (par->display & 0x01) != 0;
  599. if (lcd_enabled && crt_enabled)
  600. printk(KERN_WARNING PFX "Warning: LCD and CRT detected, using LCD\n");
  601. if (lcd_enabled)
  602. display = s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_MODE);
  603. else /* CRT */
  604. display = s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_MODE);
  605. bpp = display & 0x07;
  606. switch (bpp) {
  607. case 2: /* 4 bpp */
  608. case 3: /* 8 bpp */
  609. var->bits_per_pixel = 8;
  610. var->red.offset = var->green.offset = var->blue.offset = 0;
  611. var->red.length = var->green.length = var->blue.length = 8;
  612. break;
  613. case 5: /* 16 bpp */
  614. s1d13xxxfb_setup_truecolour(info);
  615. break;
  616. default:
  617. dbg("bpp: %i\n", bpp);
  618. }
  619. fb_alloc_cmap(&info->cmap, 256, 0);
  620. /* LCD info */
  621. panel = s1d13xxxfb_readreg(par, S1DREG_PANEL_TYPE);
  622. is_color = (panel & 0x04) != 0;
  623. is_dual = (panel & 0x02) != 0;
  624. is_tft = (panel & 0x01) != 0;
  625. lcd_bpp = s1d13xxxfb_width_tab[is_tft][(panel >> 4) & 3];
  626. if (lcd_enabled) {
  627. xres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_HWIDTH) + 1) * 8;
  628. yres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT0) +
  629. ((s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT1) & 0x03) << 8) + 1);
  630. offset = (s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF0) +
  631. ((s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF1) & 0x7) << 8));
  632. } else { /* crt */
  633. xres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_HWIDTH) + 1) * 8;
  634. yres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT0) +
  635. ((s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT1) & 0x03) << 8) + 1);
  636. offset = (s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF0) +
  637. ((s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF1) & 0x7) << 8));
  638. }
  639. xres_virtual = offset * 16 / var->bits_per_pixel;
  640. yres_virtual = fix->smem_len / (offset * 2);
  641. var->xres = xres;
  642. var->yres = yres;
  643. var->xres_virtual = xres_virtual;
  644. var->yres_virtual = yres_virtual;
  645. var->xoffset = var->yoffset = 0;
  646. fix->line_length = offset * 2;
  647. var->grayscale = !is_color;
  648. var->activate = FB_ACTIVATE_NOW;
  649. dbg(PFX "bpp=%d, lcd_bpp=%d, "
  650. "crt_enabled=%d, lcd_enabled=%d\n",
  651. var->bits_per_pixel, lcd_bpp, crt_enabled, lcd_enabled);
  652. dbg(PFX "xres=%d, yres=%d, vxres=%d, vyres=%d "
  653. "is_color=%d, is_dual=%d, is_tft=%d\n",
  654. xres, yres, xres_virtual, yres_virtual, is_color, is_dual, is_tft);
  655. }
  656. static int
  657. s1d13xxxfb_remove(struct platform_device *pdev)
  658. {
  659. struct fb_info *info = platform_get_drvdata(pdev);
  660. struct s1d13xxxfb_par *par = NULL;
  661. if (info) {
  662. par = info->par;
  663. if (par && par->regs) {
  664. /* disable output & enable powersave */
  665. s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, 0x00);
  666. s1d13xxxfb_writereg(par, S1DREG_PS_CNF, 0x11);
  667. iounmap(par->regs);
  668. }
  669. fb_dealloc_cmap(&info->cmap);
  670. if (info->screen_base)
  671. iounmap(info->screen_base);
  672. framebuffer_release(info);
  673. }
  674. release_mem_region(pdev->resource[0].start,
  675. pdev->resource[0].end - pdev->resource[0].start +1);
  676. release_mem_region(pdev->resource[1].start,
  677. pdev->resource[1].end - pdev->resource[1].start +1);
  678. return 0;
  679. }
  680. static int __devinit
  681. s1d13xxxfb_probe(struct platform_device *pdev)
  682. {
  683. struct s1d13xxxfb_par *default_par;
  684. struct fb_info *info;
  685. struct s1d13xxxfb_pdata *pdata = NULL;
  686. int ret = 0;
  687. int i;
  688. u8 revision, prod_id;
  689. dbg("probe called: device is %p\n", pdev);
  690. printk(KERN_INFO "Epson S1D13XXX FB Driver\n");
  691. /* enable platform-dependent hardware glue, if any */
  692. if (pdev->dev.platform_data)
  693. pdata = pdev->dev.platform_data;
  694. if (pdata && pdata->platform_init_video)
  695. pdata->platform_init_video();
  696. if (pdev->num_resources != 2) {
  697. dev_err(&pdev->dev, "invalid num_resources: %i\n",
  698. pdev->num_resources);
  699. ret = -ENODEV;
  700. goto bail;
  701. }
  702. /* resource[0] is VRAM, resource[1] is registers */
  703. if (pdev->resource[0].flags != IORESOURCE_MEM
  704. || pdev->resource[1].flags != IORESOURCE_MEM) {
  705. dev_err(&pdev->dev, "invalid resource type\n");
  706. ret = -ENODEV;
  707. goto bail;
  708. }
  709. if (!request_mem_region(pdev->resource[0].start,
  710. pdev->resource[0].end - pdev->resource[0].start +1, "s1d13xxxfb mem")) {
  711. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  712. ret = -EBUSY;
  713. goto bail;
  714. }
  715. if (!request_mem_region(pdev->resource[1].start,
  716. pdev->resource[1].end - pdev->resource[1].start +1, "s1d13xxxfb regs")) {
  717. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  718. ret = -EBUSY;
  719. goto bail;
  720. }
  721. info = framebuffer_alloc(sizeof(struct s1d13xxxfb_par) + sizeof(u32) * 256, &pdev->dev);
  722. if (!info) {
  723. ret = -ENOMEM;
  724. goto bail;
  725. }
  726. platform_set_drvdata(pdev, info);
  727. default_par = info->par;
  728. default_par->regs = ioremap_nocache(pdev->resource[1].start,
  729. pdev->resource[1].end - pdev->resource[1].start +1);
  730. if (!default_par->regs) {
  731. printk(KERN_ERR PFX "unable to map registers\n");
  732. ret = -ENOMEM;
  733. goto bail;
  734. }
  735. info->pseudo_palette = default_par->pseudo_palette;
  736. info->screen_base = ioremap_nocache(pdev->resource[0].start,
  737. pdev->resource[0].end - pdev->resource[0].start +1);
  738. if (!info->screen_base) {
  739. printk(KERN_ERR PFX "unable to map framebuffer\n");
  740. ret = -ENOMEM;
  741. goto bail;
  742. }
  743. /* production id is top 6 bits */
  744. prod_id = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) >> 2;
  745. /* revision id is lower 2 bits */
  746. revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) & 0x3;
  747. ret = -ENODEV;
  748. for (i = 0; i < ARRAY_SIZE(s1d13xxxfb_prod_ids); i++) {
  749. if (prod_id == s1d13xxxfb_prod_ids[i]) {
  750. /* looks like we got it in our list */
  751. default_par->prod_id = prod_id;
  752. default_par->revision = revision;
  753. ret = 0;
  754. break;
  755. }
  756. }
  757. if (!ret) {
  758. printk(KERN_INFO PFX "chip production id %i = %s\n",
  759. prod_id, s1d13xxxfb_prod_names[i]);
  760. printk(KERN_INFO PFX "chip revision %i\n", revision);
  761. } else {
  762. printk(KERN_INFO PFX
  763. "unknown chip production id %i, revision %i\n",
  764. prod_id, revision);
  765. printk(KERN_INFO PFX "please contant maintainer\n");
  766. goto bail;
  767. }
  768. info->fix = s1d13xxxfb_fix;
  769. info->fix.mmio_start = pdev->resource[1].start;
  770. info->fix.mmio_len = pdev->resource[1].end - pdev->resource[1].start + 1;
  771. info->fix.smem_start = pdev->resource[0].start;
  772. info->fix.smem_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  773. printk(KERN_INFO PFX "regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n",
  774. default_par->regs, info->fix.smem_len / 1024, info->screen_base);
  775. info->par = default_par;
  776. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  777. info->fbops = &s1d13xxxfb_fbops;
  778. switch(prod_id) {
  779. case S1D13506_PROD_ID: /* activate acceleration */
  780. s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
  781. s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
  782. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
  783. FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
  784. break;
  785. default:
  786. break;
  787. }
  788. /* perform "manual" chip initialization, if needed */
  789. if (pdata && pdata->initregs)
  790. s1d13xxxfb_runinit(info->par, pdata->initregs, pdata->initregssize);
  791. s1d13xxxfb_fetch_hw_state(info);
  792. if (register_framebuffer(info) < 0) {
  793. ret = -EINVAL;
  794. goto bail;
  795. }
  796. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  797. info->node, info->fix.id);
  798. return 0;
  799. bail:
  800. s1d13xxxfb_remove(pdev);
  801. return ret;
  802. }
  803. #ifdef CONFIG_PM
  804. static int s1d13xxxfb_suspend(struct platform_device *dev, pm_message_t state)
  805. {
  806. struct fb_info *info = platform_get_drvdata(dev);
  807. struct s1d13xxxfb_par *s1dfb = info->par;
  808. struct s1d13xxxfb_pdata *pdata = NULL;
  809. /* disable display */
  810. lcd_enable(s1dfb, 0);
  811. crt_enable(s1dfb, 0);
  812. if (dev->dev.platform_data)
  813. pdata = dev->dev.platform_data;
  814. #if 0
  815. if (!s1dfb->disp_save)
  816. s1dfb->disp_save = kmalloc(info->fix.smem_len, GFP_KERNEL);
  817. if (!s1dfb->disp_save) {
  818. printk(KERN_ERR PFX "no memory to save screen");
  819. return -ENOMEM;
  820. }
  821. memcpy_fromio(s1dfb->disp_save, info->screen_base, info->fix.smem_len);
  822. #else
  823. s1dfb->disp_save = NULL;
  824. #endif
  825. if (!s1dfb->regs_save)
  826. s1dfb->regs_save = kmalloc(info->fix.mmio_len, GFP_KERNEL);
  827. if (!s1dfb->regs_save) {
  828. printk(KERN_ERR PFX "no memory to save registers");
  829. return -ENOMEM;
  830. }
  831. /* backup all registers */
  832. memcpy_fromio(s1dfb->regs_save, s1dfb->regs, info->fix.mmio_len);
  833. /* now activate power save mode */
  834. s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x11);
  835. if (pdata && pdata->platform_suspend_video)
  836. return pdata->platform_suspend_video();
  837. else
  838. return 0;
  839. }
  840. static int s1d13xxxfb_resume(struct platform_device *dev)
  841. {
  842. struct fb_info *info = platform_get_drvdata(dev);
  843. struct s1d13xxxfb_par *s1dfb = info->par;
  844. struct s1d13xxxfb_pdata *pdata = NULL;
  845. /* awaken the chip */
  846. s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10);
  847. /* do not let go until SDRAM "wakes up" */
  848. while ((s1d13xxxfb_readreg(s1dfb, S1DREG_PS_STATUS) & 0x01))
  849. udelay(10);
  850. if (dev->dev.platform_data)
  851. pdata = dev->dev.platform_data;
  852. if (s1dfb->regs_save) {
  853. /* will write RO regs, *should* get away with it :) */
  854. memcpy_toio(s1dfb->regs, s1dfb->regs_save, info->fix.mmio_len);
  855. kfree(s1dfb->regs_save);
  856. }
  857. if (s1dfb->disp_save) {
  858. memcpy_toio(info->screen_base, s1dfb->disp_save,
  859. info->fix.smem_len);
  860. kfree(s1dfb->disp_save); /* XXX kmalloc()'d when? */
  861. }
  862. if ((s1dfb->display & 0x01) != 0)
  863. lcd_enable(s1dfb, 1);
  864. if ((s1dfb->display & 0x02) != 0)
  865. crt_enable(s1dfb, 1);
  866. if (pdata && pdata->platform_resume_video)
  867. return pdata->platform_resume_video();
  868. else
  869. return 0;
  870. }
  871. #endif /* CONFIG_PM */
  872. static struct platform_driver s1d13xxxfb_driver = {
  873. .probe = s1d13xxxfb_probe,
  874. .remove = s1d13xxxfb_remove,
  875. #ifdef CONFIG_PM
  876. .suspend = s1d13xxxfb_suspend,
  877. .resume = s1d13xxxfb_resume,
  878. #endif
  879. .driver = {
  880. .name = S1D_DEVICENAME,
  881. },
  882. };
  883. static int __init
  884. s1d13xxxfb_init(void)
  885. {
  886. #ifndef MODULE
  887. if (fb_get_options("s1d13xxxfb", NULL))
  888. return -ENODEV;
  889. #endif
  890. return platform_driver_register(&s1d13xxxfb_driver);
  891. }
  892. static void __exit
  893. s1d13xxxfb_exit(void)
  894. {
  895. platform_driver_unregister(&s1d13xxxfb_driver);
  896. }
  897. module_init(s1d13xxxfb_init);
  898. module_exit(s1d13xxxfb_exit);
  899. MODULE_LICENSE("GPL");
  900. MODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices");
  901. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>");