1 /* drivers/video/s1d13xxxfb.c
3 * (c) 2004 Simtec Electronics
4 * (c) 2005 Thibaut VARENE <varenet@parisc-linux.org>
5 * (c) 2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
7 * Driver for Epson S1D13xxx series framebuffer chips
10 * linux/drivers/video/skeletonfb.c
11 * linux/drivers/video/epson1355fb.c
12 * linux/drivers/video/epson/s1d13xxxfb.c (2.4 driver by Epson)
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
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
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/delay.h>
27 #include <linux/types.h>
28 #include <linux/errno.h>
30 #include <linux/mman.h>
32 #include <linux/spinlock_types.h>
33 #include <linux/spinlock.h>
37 #include <video/s1d13xxxfb.h>
39 #define PFX "s1d13xxxfb: "
40 #define BLIT "s1d13xxxfb_bitblt: "
43 * set this to enable debugging on general functions
46 #define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0)
48 #define dbg(fmt, args...) do { } while (0)
52 * set this to enable debugging on 2D acceleration
55 #define dbg_blit(fmt, args...) do { printk(KERN_INFO BLIT fmt, ## args); } while (0)
57 #define dbg_blit(fmt, args...) do { } while (0)
61 * we make sure only one bitblt operation is running
63 static DEFINE_SPINLOCK(s1d13xxxfb_bitblt_lock);
66 * list of card production ids
68 static const int s1d13xxxfb_prod_ids[] = {
75 * List of card strings
77 static const char *s1d13xxxfb_prod_names[] = {
84 * here we define the default struct fb_fix_screeninfo
86 static struct fb_fix_screeninfo __devinitdata s1d13xxxfb_fix = {
88 .type = FB_TYPE_PACKED_PIXELS,
89 .visual = FB_VISUAL_PSEUDOCOLOR,
93 .accel = FB_ACCEL_NONE,
97 s1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno)
99 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
100 regno=((regno & 1) ? (regno & ~1L) : (regno + 1));
102 return readb(par->regs + regno);
106 s1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value)
108 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
109 regno=((regno & 1) ? (regno & ~1L) : (regno + 1));
111 writeb(value, par->regs + regno);
115 s1d13xxxfb_runinit(struct s1d13xxxfb_par *par,
116 const struct s1d13xxxfb_regval *initregs,
117 const unsigned int size)
121 for (i = 0; i < size; i++) {
122 if ((initregs[i].addr == S1DREG_DELAYOFF) ||
123 (initregs[i].addr == S1DREG_DELAYON))
124 mdelay((int)initregs[i].value);
126 s1d13xxxfb_writereg(par, initregs[i].addr, initregs[i].value);
130 /* make sure the hardware can cope with us */
135 lcd_enable(struct s1d13xxxfb_par *par, int enable)
137 u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
144 s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode);
148 crt_enable(struct s1d13xxxfb_par *par, int enable)
150 u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
157 s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode);
161 /*************************************************************
162 framebuffer control functions
163 *************************************************************/
165 s1d13xxxfb_setup_pseudocolour(struct fb_info *info)
167 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
169 info->var.red.length = 4;
170 info->var.green.length = 4;
171 info->var.blue.length = 4;
175 s1d13xxxfb_setup_truecolour(struct fb_info *info)
177 info->fix.visual = FB_VISUAL_TRUECOLOR;
178 info->var.bits_per_pixel = 16;
180 info->var.red.length = 5;
181 info->var.red.offset = 11;
183 info->var.green.length = 6;
184 info->var.green.offset = 5;
186 info->var.blue.length = 5;
187 info->var.blue.offset = 0;
191 * s1d13xxxfb_set_par - Alters the hardware state.
192 * @info: frame buffer structure
194 * Using the fb_var_screeninfo in fb_info we set the depth of the
195 * framebuffer. This function alters the par AND the
196 * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
197 * fb_info since we are using that data. This means we depend on the
198 * data in var inside fb_info to be supported by the hardware.
199 * xxxfb_check_var is always called before xxxfb_set_par to ensure this.
201 * XXX TODO: write proper s1d13xxxfb_check_var(), without which that
202 * function is quite useless.
205 s1d13xxxfb_set_par(struct fb_info *info)
207 struct s1d13xxxfb_par *s1dfb = info->par;
210 dbg("s1d13xxxfb_set_par: bpp=%d\n", info->var.bits_per_pixel);
212 if ((s1dfb->display & 0x01)) /* LCD */
213 val = s1d13xxxfb_readreg(s1dfb, S1DREG_LCD_DISP_MODE); /* read colour control */
215 val = s1d13xxxfb_readreg(s1dfb, S1DREG_CRT_DISP_MODE); /* read colour control */
219 switch (info->var.bits_per_pixel) {
221 dbg("pseudo colour 4\n");
222 s1d13xxxfb_setup_pseudocolour(info);
226 dbg("pseudo colour 8\n");
227 s1d13xxxfb_setup_pseudocolour(info);
231 dbg("true colour\n");
232 s1d13xxxfb_setup_truecolour(info);
237 dbg("bpp not supported!\n");
241 dbg("writing %02x to display mode register\n", val);
243 if ((s1dfb->display & 0x01)) /* LCD */
244 s1d13xxxfb_writereg(s1dfb, S1DREG_LCD_DISP_MODE, val);
246 s1d13xxxfb_writereg(s1dfb, S1DREG_CRT_DISP_MODE, val);
248 info->fix.line_length = info->var.xres * info->var.bits_per_pixel;
249 info->fix.line_length /= 8;
251 dbg("setting line_length to %d\n", info->fix.line_length);
259 * s1d13xxxfb_setcolreg - sets a color register.
260 * @regno: Which register in the CLUT we are programming
261 * @red: The red value which can be up to 16 bits wide
262 * @green: The green value which can be up to 16 bits wide
263 * @blue: The blue value which can be up to 16 bits wide.
264 * @transp: If supported the alpha value which can be up to 16 bits wide.
265 * @info: frame buffer info structure
267 * Returns negative errno on error, or zero on success.
270 s1d13xxxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
271 u_int transp, struct fb_info *info)
273 struct s1d13xxxfb_par *s1dfb = info->par;
274 unsigned int pseudo_val;
276 if (regno >= S1D_PALETTE_SIZE)
279 dbg("s1d13xxxfb_setcolreg: %d: rgb=%d,%d,%d, tr=%d\n",
280 regno, red, green, blue, transp);
282 if (info->var.grayscale)
283 red = green = blue = (19595*red + 38470*green + 7471*blue) >> 16;
285 switch (info->fix.visual) {
286 case FB_VISUAL_TRUECOLOR:
290 /* deal with creating pseudo-palette entries */
292 pseudo_val = (red >> 11) << info->var.red.offset;
293 pseudo_val |= (green >> 10) << info->var.green.offset;
294 pseudo_val |= (blue >> 11) << info->var.blue.offset;
296 dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n",
299 #if defined(CONFIG_PLAT_MAPPI)
300 ((u32 *)info->pseudo_palette)[regno] = cpu_to_le16(pseudo_val);
302 ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
306 case FB_VISUAL_PSEUDOCOLOR:
307 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_ADDR, regno);
308 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, red);
309 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, green);
310 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, blue);
317 dbg("s1d13xxxfb_setcolreg: done\n");
323 * s1d13xxxfb_blank - blanks the display.
324 * @blank_mode: the blank mode we want.
325 * @info: frame buffer structure that represents a single frame buffer
327 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
328 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
329 * video mode which doesn't support it. Implements VESA suspend
330 * and powerdown modes on hardware that supports disabling hsync/vsync:
331 * blank_mode == 2: suspend vsync
332 * blank_mode == 3: suspend hsync
333 * blank_mode == 4: powerdown
335 * Returns negative errno on error, or zero on success.
338 s1d13xxxfb_blank(int blank_mode, struct fb_info *info)
340 struct s1d13xxxfb_par *par = info->par;
342 dbg("s1d13xxxfb_blank: blank=%d, info=%p\n", blank_mode, info);
344 switch (blank_mode) {
345 case FB_BLANK_UNBLANK:
346 case FB_BLANK_NORMAL:
347 if ((par->display & 0x01) != 0)
349 if ((par->display & 0x02) != 0)
352 case FB_BLANK_VSYNC_SUSPEND:
353 case FB_BLANK_HSYNC_SUSPEND:
355 case FB_BLANK_POWERDOWN:
363 /* let fbcon do a soft blank for us */
364 return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
368 * s1d13xxxfb_pan_display - Pans the display.
369 * @var: frame buffer variable screen structure
370 * @info: frame buffer structure that represents a single frame buffer
372 * Pan (or wrap, depending on the `vmode' field) the display using the
373 * `yoffset' field of the `var' structure (`xoffset' not yet supported).
374 * If the values don't fit, return -EINVAL.
376 * Returns negative errno on error, or zero on success.
379 s1d13xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
381 struct s1d13xxxfb_par *par = info->par;
384 if (var->xoffset != 0) /* not yet ... */
387 if (var->yoffset + info->var.yres > info->var.yres_virtual)
390 start = (info->fix.line_length >> 1) * var->yoffset;
392 if ((par->display & 0x01)) {
394 s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START0, (start & 0xff));
395 s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START1, ((start >> 8) & 0xff));
396 s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START2, ((start >> 16) & 0x0f));
399 s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START0, (start & 0xff));
400 s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START1, ((start >> 8) & 0xff));
401 s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START2, ((start >> 16) & 0x0f));
407 /************************************************************
408 functions to handle bitblt acceleration
409 ************************************************************/
412 * bltbit_wait_bitset - waits for change in register value
413 * @info : framebuffer structure
414 * @bit : value expected in register
417 * waits until value changes INTO bit
420 bltbit_wait_bitset(struct fb_info *info, u8 bit, int timeout)
422 while (!(s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0) & bit)) {
425 dbg_blit("wait_bitset timeout\n");
434 * bltbit_wait_bitclear - waits for change in register value
435 * @info : frambuffer structure
436 * @bit : value currently in register
439 * waits until value changes FROM bit
443 bltbit_wait_bitclear(struct fb_info *info, u8 bit, int timeout)
445 while (s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0) & bit) {
448 dbg_blit("wait_bitclear timeout\n");
457 * bltbit_fifo_status - checks the current status of the fifo
458 * @info : framebuffer structure
460 * returns number of free words in buffer
463 bltbit_fifo_status(struct fb_info *info)
467 status = s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0);
469 /* its empty so room for 16 words */
470 if (status & BBLT_FIFO_EMPTY)
473 /* its full so we dont want to add */
474 if (status & BBLT_FIFO_FULL)
477 /* its atleast half full but we can add one atleast */
478 if (status & BBLT_FIFO_NOT_FULL)
485 * s1d13xxxfb_bitblt_copyarea - accelerated copyarea function
486 * @info : framebuffer structure
487 * @area : fb_copyarea structure
489 * supports (atleast) S1D13506
493 s1d13xxxfb_bitblt_copyarea(struct fb_info *info, const struct fb_copyarea *area)
498 u16 sx = area->sx, sy = area->sy;
499 u16 dx = area->dx, dy = area->dy;
500 u16 width = area->width, height = area->height;
503 spin_lock(&s1d13xxxfb_bitblt_lock);
505 /* bytes per xres line */
506 bpp = (info->var.bits_per_pixel >> 3);
507 stride = bpp * info->var.xres;
509 /* reverse, calculate the last pixel in rectangle */
510 if ((dy > sy) || ((dy == sy) && (dx >= sx))) {
511 dst = (((dy + height - 1) * stride) + (bpp * (dx + width - 1)));
512 src = (((sy + height - 1) * stride) + (bpp * (sx + width - 1)));
514 /* not reverse, calculate the first pixel in rectangle */
515 } else { /* (y * xres) + (bpp * x) */
516 dst = (dy * stride) + (bpp * dx);
517 src = (sy * stride) + (bpp * sx);
520 /* set source adress */
521 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START0, (src & 0xff));
522 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START1, (src >> 8) & 0x00ff);
523 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START2, (src >> 16) & 0x00ff);
525 /* set destination adress */
526 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dst & 0xff));
527 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, (dst >> 8) & 0x00ff);
528 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, (dst >> 16) & 0x00ff);
530 /* program height and width */
531 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, (width & 0xff) - 1);
532 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (width >> 8));
534 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, (height & 0xff) - 1);
535 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (height >> 8));
537 /* negative direction ROP */
539 dbg_blit("(copyarea) negative rop\n");
540 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x03);
541 } else /* positive direction ROP */ {
542 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x02);
543 dbg_blit("(copyarea) positive rop\n");
546 /* set for rectangel mode and not linear */
547 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0);
549 /* setup the bpp 1 = 16bpp, 0 = 8bpp*/
550 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (bpp >> 1));
552 /* set words per xres */
553 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (stride >> 1) & 0xff);
554 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (stride >> 9));
556 dbg_blit("(copyarea) dx=%d, dy=%d\n", dx, dy);
557 dbg_blit("(copyarea) sx=%d, sy=%d\n", sx, sy);
558 dbg_blit("(copyarea) width=%d, height=%d\n", width - 1, height - 1);
559 dbg_blit("(copyarea) stride=%d\n", stride);
560 dbg_blit("(copyarea) bpp=%d=0x0%d, mem_offset1=%d, mem_offset2=%d\n", bpp, (bpp >> 1),
561 (stride >> 1) & 0xff, stride >> 9);
563 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CC_EXP, 0x0c);
565 /* initialize the engine */
566 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80);
568 /* wait to complete */
569 bltbit_wait_bitclear(info, 0x80, 8000);
571 spin_unlock(&s1d13xxxfb_bitblt_lock);
576 * s1d13xxxfb_bitblt_solidfill - accelerated solidfill function
577 * @info : framebuffer structure
578 * @rect : fb_fillrect structure
580 * supports (atleast 13506)
584 s1d13xxxfb_bitblt_solidfill(struct fb_info *info, const struct fb_fillrect *rect)
586 u32 screen_stride, dest;
588 u16 bpp = (info->var.bits_per_pixel >> 3);
591 spin_lock(&s1d13xxxfb_bitblt_lock);
593 /* bytes per x width */
594 screen_stride = (bpp * info->var.xres);
596 /* bytes to starting point */
597 dest = ((rect->dy * screen_stride) + (bpp * rect->dx));
599 dbg_blit("(solidfill) dx=%d, dy=%d, stride=%d, dest=%d\n"
600 "(solidfill) : rect_width=%d, rect_height=%d\n",
601 rect->dx, rect->dy, screen_stride, dest,
602 rect->width - 1, rect->height - 1);
604 dbg_blit("(solidfill) : xres=%d, yres=%d, bpp=%d\n",
605 info->var.xres, info->var.yres,
606 info->var.bits_per_pixel);
607 dbg_blit("(solidfill) : rop=%d\n", rect->rop);
609 /* We split the destination into the three registers */
610 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dest & 0x00ff));
611 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, ((dest >> 8) & 0x00ff));
612 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, ((dest >> 16) & 0x00ff));
614 /* give information regarding rectangel width */
615 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, ((rect->width) & 0x00ff) - 1);
616 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (rect->width >> 8));
618 /* give information regarding rectangel height */
619 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, ((rect->height) & 0x00ff) - 1);
620 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (rect->height >> 8));
622 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
623 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
624 fg = ((u32 *)info->pseudo_palette)[rect->color];
625 dbg_blit("(solidfill) truecolor/directcolor\n");
626 dbg_blit("(solidfill) pseudo_palette[%d] = %d\n", rect->color, fg);
629 dbg_blit("(solidfill) color = %d\n", rect->color);
632 /* set foreground color */
633 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC0, (fg & 0xff));
634 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC1, (fg >> 8) & 0xff);
636 /* set rectangual region of memory (rectangle and not linear) */
637 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0);
639 /* set operation mode SOLID_FILL */
640 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, BBLT_SOLID_FILL);
642 /* set bits per pixel (1 = 16bpp, 0 = 8bpp) */
643 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (info->var.bits_per_pixel >> 4));
645 /* set the memory offset for the bblt in word sizes */
646 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (screen_stride >> 1) & 0x00ff);
647 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (screen_stride >> 9));
649 /* and away we go.... */
650 s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80);
652 /* wait until its done */
653 bltbit_wait_bitclear(info, 0x80, 8000);
655 /* let others play */
656 spin_unlock(&s1d13xxxfb_bitblt_lock);
659 /* framebuffer information structures */
660 static struct fb_ops s1d13xxxfb_fbops = {
661 .owner = THIS_MODULE,
662 .fb_set_par = s1d13xxxfb_set_par,
663 .fb_setcolreg = s1d13xxxfb_setcolreg,
664 .fb_blank = s1d13xxxfb_blank,
666 .fb_pan_display = s1d13xxxfb_pan_display,
668 /* gets replaced at chip detection time */
669 .fb_fillrect = cfb_fillrect,
670 .fb_copyarea = cfb_copyarea,
671 .fb_imageblit = cfb_imageblit,
674 static int s1d13xxxfb_width_tab[2][4] __devinitdata = {
680 * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to
682 * @info: frame buffer structure
684 * We setup the framebuffer structures according to the current
685 * hardware setup. On some machines, the BIOS will have filled
686 * the chip registers with such info, on others, these values will
687 * have been written in some init procedure. In any case, the
688 * software values needs to match the hardware ones. This is what
689 * this function ensures.
691 * Note: some of the hardcoded values here might need some love to
692 * work on various chips, and might need to no longer be hardcoded.
694 static void __devinit
695 s1d13xxxfb_fetch_hw_state(struct fb_info *info)
697 struct fb_var_screeninfo *var = &info->var;
698 struct fb_fix_screeninfo *fix = &info->fix;
699 struct s1d13xxxfb_par *par = info->par;
703 u32 xres_virtual, yres_virtual;
705 int is_color, is_dual, is_tft;
706 int lcd_enabled, crt_enabled;
708 fix->type = FB_TYPE_PACKED_PIXELS;
711 par->display = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
712 crt_enabled = (par->display & 0x02) != 0;
713 lcd_enabled = (par->display & 0x01) != 0;
715 if (lcd_enabled && crt_enabled)
716 printk(KERN_WARNING PFX "Warning: LCD and CRT detected, using LCD\n");
719 display = s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_MODE);
721 display = s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_MODE);
723 bpp = display & 0x07;
728 var->bits_per_pixel = 8;
729 var->red.offset = var->green.offset = var->blue.offset = 0;
730 var->red.length = var->green.length = var->blue.length = 8;
733 s1d13xxxfb_setup_truecolour(info);
736 dbg("bpp: %i\n", bpp);
738 fb_alloc_cmap(&info->cmap, 256, 0);
741 panel = s1d13xxxfb_readreg(par, S1DREG_PANEL_TYPE);
742 is_color = (panel & 0x04) != 0;
743 is_dual = (panel & 0x02) != 0;
744 is_tft = (panel & 0x01) != 0;
745 lcd_bpp = s1d13xxxfb_width_tab[is_tft][(panel >> 4) & 3];
748 xres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_HWIDTH) + 1) * 8;
749 yres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT0) +
750 ((s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT1) & 0x03) << 8) + 1);
752 offset = (s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF0) +
753 ((s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF1) & 0x7) << 8));
755 xres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_HWIDTH) + 1) * 8;
756 yres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT0) +
757 ((s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT1) & 0x03) << 8) + 1);
759 offset = (s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF0) +
760 ((s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF1) & 0x7) << 8));
762 xres_virtual = offset * 16 / var->bits_per_pixel;
763 yres_virtual = fix->smem_len / (offset * 2);
767 var->xres_virtual = xres_virtual;
768 var->yres_virtual = yres_virtual;
769 var->xoffset = var->yoffset = 0;
771 fix->line_length = offset * 2;
773 var->grayscale = !is_color;
775 var->activate = FB_ACTIVATE_NOW;
777 dbg(PFX "bpp=%d, lcd_bpp=%d, "
778 "crt_enabled=%d, lcd_enabled=%d\n",
779 var->bits_per_pixel, lcd_bpp, crt_enabled, lcd_enabled);
780 dbg(PFX "xres=%d, yres=%d, vxres=%d, vyres=%d "
781 "is_color=%d, is_dual=%d, is_tft=%d\n",
782 xres, yres, xres_virtual, yres_virtual, is_color, is_dual, is_tft);
787 s1d13xxxfb_remove(struct platform_device *pdev)
789 struct fb_info *info = platform_get_drvdata(pdev);
790 struct s1d13xxxfb_par *par = NULL;
794 if (par && par->regs) {
795 /* disable output & enable powersave */
796 s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, 0x00);
797 s1d13xxxfb_writereg(par, S1DREG_PS_CNF, 0x11);
801 fb_dealloc_cmap(&info->cmap);
803 if (info->screen_base)
804 iounmap(info->screen_base);
806 framebuffer_release(info);
809 release_mem_region(pdev->resource[0].start,
810 pdev->resource[0].end - pdev->resource[0].start +1);
811 release_mem_region(pdev->resource[1].start,
812 pdev->resource[1].end - pdev->resource[1].start +1);
817 s1d13xxxfb_probe(struct platform_device *pdev)
819 struct s1d13xxxfb_par *default_par;
820 struct fb_info *info;
821 struct s1d13xxxfb_pdata *pdata = NULL;
824 u8 revision, prod_id;
826 dbg("probe called: device is %p\n", pdev);
828 printk(KERN_INFO "Epson S1D13XXX FB Driver\n");
830 /* enable platform-dependent hardware glue, if any */
831 if (pdev->dev.platform_data)
832 pdata = pdev->dev.platform_data;
834 if (pdata && pdata->platform_init_video)
835 pdata->platform_init_video();
837 if (pdev->num_resources != 2) {
838 dev_err(&pdev->dev, "invalid num_resources: %i\n",
839 pdev->num_resources);
844 /* resource[0] is VRAM, resource[1] is registers */
845 if (pdev->resource[0].flags != IORESOURCE_MEM
846 || pdev->resource[1].flags != IORESOURCE_MEM) {
847 dev_err(&pdev->dev, "invalid resource type\n");
852 if (!request_mem_region(pdev->resource[0].start,
853 pdev->resource[0].end - pdev->resource[0].start +1, "s1d13xxxfb mem")) {
854 dev_dbg(&pdev->dev, "request_mem_region failed\n");
859 if (!request_mem_region(pdev->resource[1].start,
860 pdev->resource[1].end - pdev->resource[1].start +1, "s1d13xxxfb regs")) {
861 dev_dbg(&pdev->dev, "request_mem_region failed\n");
866 info = framebuffer_alloc(sizeof(struct s1d13xxxfb_par) + sizeof(u32) * 256, &pdev->dev);
872 platform_set_drvdata(pdev, info);
873 default_par = info->par;
874 default_par->regs = ioremap_nocache(pdev->resource[1].start,
875 pdev->resource[1].end - pdev->resource[1].start +1);
876 if (!default_par->regs) {
877 printk(KERN_ERR PFX "unable to map registers\n");
881 info->pseudo_palette = default_par->pseudo_palette;
883 info->screen_base = ioremap_nocache(pdev->resource[0].start,
884 pdev->resource[0].end - pdev->resource[0].start +1);
886 if (!info->screen_base) {
887 printk(KERN_ERR PFX "unable to map framebuffer\n");
892 /* production id is top 6 bits */
893 prod_id = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) >> 2;
894 /* revision id is lower 2 bits */
895 revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) & 0x3;
898 for (i = 0; i < ARRAY_SIZE(s1d13xxxfb_prod_ids); i++) {
899 if (prod_id == s1d13xxxfb_prod_ids[i]) {
900 /* looks like we got it in our list */
901 default_par->prod_id = prod_id;
902 default_par->revision = revision;
909 printk(KERN_INFO PFX "chip production id %i = %s\n",
910 prod_id, s1d13xxxfb_prod_names[i]);
911 printk(KERN_INFO PFX "chip revision %i\n", revision);
914 "unknown chip production id %i, revision %i\n",
916 printk(KERN_INFO PFX "please contant maintainer\n");
920 info->fix = s1d13xxxfb_fix;
921 info->fix.mmio_start = pdev->resource[1].start;
922 info->fix.mmio_len = pdev->resource[1].end - pdev->resource[1].start + 1;
923 info->fix.smem_start = pdev->resource[0].start;
924 info->fix.smem_len = pdev->resource[0].end - pdev->resource[0].start + 1;
926 printk(KERN_INFO PFX "regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n",
927 default_par->regs, info->fix.smem_len / 1024, info->screen_base);
929 info->par = default_par;
930 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
931 info->fbops = &s1d13xxxfb_fbops;
934 case S1D13506_PROD_ID: /* activate acceleration */
935 s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
936 s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
937 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
938 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
944 /* perform "manual" chip initialization, if needed */
945 if (pdata && pdata->initregs)
946 s1d13xxxfb_runinit(info->par, pdata->initregs, pdata->initregssize);
948 s1d13xxxfb_fetch_hw_state(info);
950 if (register_framebuffer(info) < 0) {
955 printk(KERN_INFO "fb%d: %s frame buffer device\n",
956 info->node, info->fix.id);
961 s1d13xxxfb_remove(pdev);
967 static int s1d13xxxfb_suspend(struct platform_device *dev, pm_message_t state)
969 struct fb_info *info = platform_get_drvdata(dev);
970 struct s1d13xxxfb_par *s1dfb = info->par;
971 struct s1d13xxxfb_pdata *pdata = NULL;
973 /* disable display */
974 lcd_enable(s1dfb, 0);
975 crt_enable(s1dfb, 0);
977 if (dev->dev.platform_data)
978 pdata = dev->dev.platform_data;
981 if (!s1dfb->disp_save)
982 s1dfb->disp_save = kmalloc(info->fix.smem_len, GFP_KERNEL);
984 if (!s1dfb->disp_save) {
985 printk(KERN_ERR PFX "no memory to save screen");
989 memcpy_fromio(s1dfb->disp_save, info->screen_base, info->fix.smem_len);
991 s1dfb->disp_save = NULL;
994 if (!s1dfb->regs_save)
995 s1dfb->regs_save = kmalloc(info->fix.mmio_len, GFP_KERNEL);
997 if (!s1dfb->regs_save) {
998 printk(KERN_ERR PFX "no memory to save registers");
1002 /* backup all registers */
1003 memcpy_fromio(s1dfb->regs_save, s1dfb->regs, info->fix.mmio_len);
1005 /* now activate power save mode */
1006 s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x11);
1008 if (pdata && pdata->platform_suspend_video)
1009 return pdata->platform_suspend_video();
1014 static int s1d13xxxfb_resume(struct platform_device *dev)
1016 struct fb_info *info = platform_get_drvdata(dev);
1017 struct s1d13xxxfb_par *s1dfb = info->par;
1018 struct s1d13xxxfb_pdata *pdata = NULL;
1020 /* awaken the chip */
1021 s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10);
1023 /* do not let go until SDRAM "wakes up" */
1024 while ((s1d13xxxfb_readreg(s1dfb, S1DREG_PS_STATUS) & 0x01))
1027 if (dev->dev.platform_data)
1028 pdata = dev->dev.platform_data;
1030 if (s1dfb->regs_save) {
1031 /* will write RO regs, *should* get away with it :) */
1032 memcpy_toio(s1dfb->regs, s1dfb->regs_save, info->fix.mmio_len);
1033 kfree(s1dfb->regs_save);
1036 if (s1dfb->disp_save) {
1037 memcpy_toio(info->screen_base, s1dfb->disp_save,
1038 info->fix.smem_len);
1039 kfree(s1dfb->disp_save); /* XXX kmalloc()'d when? */
1042 if ((s1dfb->display & 0x01) != 0)
1043 lcd_enable(s1dfb, 1);
1044 if ((s1dfb->display & 0x02) != 0)
1045 crt_enable(s1dfb, 1);
1047 if (pdata && pdata->platform_resume_video)
1048 return pdata->platform_resume_video();
1052 #endif /* CONFIG_PM */
1054 static struct platform_driver s1d13xxxfb_driver = {
1055 .probe = s1d13xxxfb_probe,
1056 .remove = s1d13xxxfb_remove,
1058 .suspend = s1d13xxxfb_suspend,
1059 .resume = s1d13xxxfb_resume,
1062 .name = S1D_DEVICENAME,
1068 s1d13xxxfb_init(void)
1072 if (fb_get_options("s1d13xxxfb", NULL))
1076 return platform_driver_register(&s1d13xxxfb_driver);
1081 s1d13xxxfb_exit(void)
1083 platform_driver_unregister(&s1d13xxxfb_driver);
1086 module_init(s1d13xxxfb_init);
1087 module_exit(s1d13xxxfb_exit);
1090 MODULE_LICENSE("GPL");
1091 MODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices");
1092 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>");