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>
34 #include <linux/slab.h>
38 #include <video/s1d13xxxfb.h>
40 #define PFX "s1d13xxxfb: "
41 #define BLIT "s1d13xxxfb_bitblt: "
44 * set this to enable debugging on general functions
47 #define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0)
49 #define dbg(fmt, args...) do { } while (0)
53 * set this to enable debugging on 2D acceleration
56 #define dbg_blit(fmt, args...) do { printk(KERN_INFO BLIT fmt, ## args); } while (0)
58 #define dbg_blit(fmt, args...) do { } while (0)
62 * we make sure only one bitblt operation is running
64 static DEFINE_SPINLOCK(s1d13xxxfb_bitblt_lock
);
67 * list of card production ids
69 static const int s1d13xxxfb_prod_ids
[] = {
76 * List of card strings
78 static const char *s1d13xxxfb_prod_names
[] = {
85 * here we define the default struct fb_fix_screeninfo
87 static struct fb_fix_screeninfo s1d13xxxfb_fix
= {
89 .type
= FB_TYPE_PACKED_PIXELS
,
90 .visual
= FB_VISUAL_PSEUDOCOLOR
,
94 .accel
= FB_ACCEL_NONE
,
98 s1d13xxxfb_readreg(struct s1d13xxxfb_par
*par
, u16 regno
)
100 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
101 regno
=((regno
& 1) ? (regno
& ~1L) : (regno
+ 1));
103 return readb(par
->regs
+ regno
);
107 s1d13xxxfb_writereg(struct s1d13xxxfb_par
*par
, u16 regno
, u8 value
)
109 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
110 regno
=((regno
& 1) ? (regno
& ~1L) : (regno
+ 1));
112 writeb(value
, par
->regs
+ regno
);
116 s1d13xxxfb_runinit(struct s1d13xxxfb_par
*par
,
117 const struct s1d13xxxfb_regval
*initregs
,
118 const unsigned int size
)
122 for (i
= 0; i
< size
; i
++) {
123 if ((initregs
[i
].addr
== S1DREG_DELAYOFF
) ||
124 (initregs
[i
].addr
== S1DREG_DELAYON
))
125 mdelay((int)initregs
[i
].value
);
127 s1d13xxxfb_writereg(par
, initregs
[i
].addr
, initregs
[i
].value
);
131 /* make sure the hardware can cope with us */
136 lcd_enable(struct s1d13xxxfb_par
*par
, int enable
)
138 u8 mode
= s1d13xxxfb_readreg(par
, S1DREG_COM_DISP_MODE
);
145 s1d13xxxfb_writereg(par
, S1DREG_COM_DISP_MODE
, mode
);
149 crt_enable(struct s1d13xxxfb_par
*par
, int enable
)
151 u8 mode
= s1d13xxxfb_readreg(par
, S1DREG_COM_DISP_MODE
);
158 s1d13xxxfb_writereg(par
, S1DREG_COM_DISP_MODE
, mode
);
162 /*************************************************************
163 framebuffer control functions
164 *************************************************************/
166 s1d13xxxfb_setup_pseudocolour(struct fb_info
*info
)
168 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
170 info
->var
.red
.length
= 4;
171 info
->var
.green
.length
= 4;
172 info
->var
.blue
.length
= 4;
176 s1d13xxxfb_setup_truecolour(struct fb_info
*info
)
178 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
179 info
->var
.bits_per_pixel
= 16;
181 info
->var
.red
.length
= 5;
182 info
->var
.red
.offset
= 11;
184 info
->var
.green
.length
= 6;
185 info
->var
.green
.offset
= 5;
187 info
->var
.blue
.length
= 5;
188 info
->var
.blue
.offset
= 0;
192 * s1d13xxxfb_set_par - Alters the hardware state.
193 * @info: frame buffer structure
195 * Using the fb_var_screeninfo in fb_info we set the depth of the
196 * framebuffer. This function alters the par AND the
197 * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
198 * fb_info since we are using that data. This means we depend on the
199 * data in var inside fb_info to be supported by the hardware.
200 * xxxfb_check_var is always called before xxxfb_set_par to ensure this.
202 * XXX TODO: write proper s1d13xxxfb_check_var(), without which that
203 * function is quite useless.
206 s1d13xxxfb_set_par(struct fb_info
*info
)
208 struct s1d13xxxfb_par
*s1dfb
= info
->par
;
211 dbg("s1d13xxxfb_set_par: bpp=%d\n", info
->var
.bits_per_pixel
);
213 if ((s1dfb
->display
& 0x01)) /* LCD */
214 val
= s1d13xxxfb_readreg(s1dfb
, S1DREG_LCD_DISP_MODE
); /* read colour control */
216 val
= s1d13xxxfb_readreg(s1dfb
, S1DREG_CRT_DISP_MODE
); /* read colour control */
220 switch (info
->var
.bits_per_pixel
) {
222 dbg("pseudo colour 4\n");
223 s1d13xxxfb_setup_pseudocolour(info
);
227 dbg("pseudo colour 8\n");
228 s1d13xxxfb_setup_pseudocolour(info
);
232 dbg("true colour\n");
233 s1d13xxxfb_setup_truecolour(info
);
238 dbg("bpp not supported!\n");
242 dbg("writing %02x to display mode register\n", val
);
244 if ((s1dfb
->display
& 0x01)) /* LCD */
245 s1d13xxxfb_writereg(s1dfb
, S1DREG_LCD_DISP_MODE
, val
);
247 s1d13xxxfb_writereg(s1dfb
, S1DREG_CRT_DISP_MODE
, val
);
249 info
->fix
.line_length
= info
->var
.xres
* info
->var
.bits_per_pixel
;
250 info
->fix
.line_length
/= 8;
252 dbg("setting line_length to %d\n", info
->fix
.line_length
);
260 * s1d13xxxfb_setcolreg - sets a color register.
261 * @regno: Which register in the CLUT we are programming
262 * @red: The red value which can be up to 16 bits wide
263 * @green: The green value which can be up to 16 bits wide
264 * @blue: The blue value which can be up to 16 bits wide.
265 * @transp: If supported the alpha value which can be up to 16 bits wide.
266 * @info: frame buffer info structure
268 * Returns negative errno on error, or zero on success.
271 s1d13xxxfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
272 u_int transp
, struct fb_info
*info
)
274 struct s1d13xxxfb_par
*s1dfb
= info
->par
;
275 unsigned int pseudo_val
;
277 if (regno
>= S1D_PALETTE_SIZE
)
280 dbg("s1d13xxxfb_setcolreg: %d: rgb=%d,%d,%d, tr=%d\n",
281 regno
, red
, green
, blue
, transp
);
283 if (info
->var
.grayscale
)
284 red
= green
= blue
= (19595*red
+ 38470*green
+ 7471*blue
) >> 16;
286 switch (info
->fix
.visual
) {
287 case FB_VISUAL_TRUECOLOR
:
291 /* deal with creating pseudo-palette entries */
293 pseudo_val
= (red
>> 11) << info
->var
.red
.offset
;
294 pseudo_val
|= (green
>> 10) << info
->var
.green
.offset
;
295 pseudo_val
|= (blue
>> 11) << info
->var
.blue
.offset
;
297 dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n",
300 #if defined(CONFIG_PLAT_MAPPI)
301 ((u32
*)info
->pseudo_palette
)[regno
] = cpu_to_le16(pseudo_val
);
303 ((u32
*)info
->pseudo_palette
)[regno
] = pseudo_val
;
307 case FB_VISUAL_PSEUDOCOLOR
:
308 s1d13xxxfb_writereg(s1dfb
, S1DREG_LKUP_ADDR
, regno
);
309 s1d13xxxfb_writereg(s1dfb
, S1DREG_LKUP_DATA
, red
);
310 s1d13xxxfb_writereg(s1dfb
, S1DREG_LKUP_DATA
, green
);
311 s1d13xxxfb_writereg(s1dfb
, S1DREG_LKUP_DATA
, blue
);
318 dbg("s1d13xxxfb_setcolreg: done\n");
324 * s1d13xxxfb_blank - blanks the display.
325 * @blank_mode: the blank mode we want.
326 * @info: frame buffer structure that represents a single frame buffer
328 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
329 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
330 * video mode which doesn't support it. Implements VESA suspend
331 * and powerdown modes on hardware that supports disabling hsync/vsync:
332 * blank_mode == 2: suspend vsync
333 * blank_mode == 3: suspend hsync
334 * blank_mode == 4: powerdown
336 * Returns negative errno on error, or zero on success.
339 s1d13xxxfb_blank(int blank_mode
, struct fb_info
*info
)
341 struct s1d13xxxfb_par
*par
= info
->par
;
343 dbg("s1d13xxxfb_blank: blank=%d, info=%p\n", blank_mode
, info
);
345 switch (blank_mode
) {
346 case FB_BLANK_UNBLANK
:
347 case FB_BLANK_NORMAL
:
348 if ((par
->display
& 0x01) != 0)
350 if ((par
->display
& 0x02) != 0)
353 case FB_BLANK_VSYNC_SUSPEND
:
354 case FB_BLANK_HSYNC_SUSPEND
:
356 case FB_BLANK_POWERDOWN
:
364 /* let fbcon do a soft blank for us */
365 return ((blank_mode
== FB_BLANK_NORMAL
) ? 1 : 0);
369 * s1d13xxxfb_pan_display - Pans the display.
370 * @var: frame buffer variable screen structure
371 * @info: frame buffer structure that represents a single frame buffer
373 * Pan (or wrap, depending on the `vmode' field) the display using the
374 * `yoffset' field of the `var' structure (`xoffset' not yet supported).
375 * If the values don't fit, return -EINVAL.
377 * Returns negative errno on error, or zero on success.
380 s1d13xxxfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
382 struct s1d13xxxfb_par
*par
= info
->par
;
385 if (var
->xoffset
!= 0) /* not yet ... */
388 if (var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
391 start
= (info
->fix
.line_length
>> 1) * var
->yoffset
;
393 if ((par
->display
& 0x01)) {
395 s1d13xxxfb_writereg(par
, S1DREG_LCD_DISP_START0
, (start
& 0xff));
396 s1d13xxxfb_writereg(par
, S1DREG_LCD_DISP_START1
, ((start
>> 8) & 0xff));
397 s1d13xxxfb_writereg(par
, S1DREG_LCD_DISP_START2
, ((start
>> 16) & 0x0f));
400 s1d13xxxfb_writereg(par
, S1DREG_CRT_DISP_START0
, (start
& 0xff));
401 s1d13xxxfb_writereg(par
, S1DREG_CRT_DISP_START1
, ((start
>> 8) & 0xff));
402 s1d13xxxfb_writereg(par
, S1DREG_CRT_DISP_START2
, ((start
>> 16) & 0x0f));
408 /************************************************************
409 functions to handle bitblt acceleration
410 ************************************************************/
413 * bltbit_wait_bitclear - waits for change in register value
414 * @info : frambuffer structure
415 * @bit : value currently in register
418 * waits until value changes FROM bit
422 bltbit_wait_bitclear(struct fb_info
*info
, u8 bit
, int timeout
)
424 while (s1d13xxxfb_readreg(info
->par
, S1DREG_BBLT_CTL0
) & bit
) {
427 dbg_blit("wait_bitclear timeout\n");
436 * s1d13xxxfb_bitblt_copyarea - accelerated copyarea function
437 * @info : framebuffer structure
438 * @area : fb_copyarea structure
440 * supports (atleast) S1D13506
444 s1d13xxxfb_bitblt_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
449 u16 sx
= area
->sx
, sy
= area
->sy
;
450 u16 dx
= area
->dx
, dy
= area
->dy
;
451 u16 width
= area
->width
, height
= area
->height
;
454 spin_lock(&s1d13xxxfb_bitblt_lock
);
456 /* bytes per xres line */
457 bpp
= (info
->var
.bits_per_pixel
>> 3);
458 stride
= bpp
* info
->var
.xres
;
460 /* reverse, calculate the last pixel in rectangle */
461 if ((dy
> sy
) || ((dy
== sy
) && (dx
>= sx
))) {
462 dst
= (((dy
+ height
- 1) * stride
) + (bpp
* (dx
+ width
- 1)));
463 src
= (((sy
+ height
- 1) * stride
) + (bpp
* (sx
+ width
- 1)));
465 /* not reverse, calculate the first pixel in rectangle */
466 } else { /* (y * xres) + (bpp * x) */
467 dst
= (dy
* stride
) + (bpp
* dx
);
468 src
= (sy
* stride
) + (bpp
* sx
);
471 /* set source address */
472 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_SRC_START0
, (src
& 0xff));
473 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_SRC_START1
, (src
>> 8) & 0x00ff);
474 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_SRC_START2
, (src
>> 16) & 0x00ff);
476 /* set destination address */
477 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_DST_START0
, (dst
& 0xff));
478 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_DST_START1
, (dst
>> 8) & 0x00ff);
479 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_DST_START2
, (dst
>> 16) & 0x00ff);
481 /* program height and width */
482 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_WIDTH0
, (width
& 0xff) - 1);
483 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_WIDTH1
, (width
>> 8));
485 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_HEIGHT0
, (height
& 0xff) - 1);
486 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_HEIGHT1
, (height
>> 8));
488 /* negative direction ROP */
490 dbg_blit("(copyarea) negative rop\n");
491 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_OP
, 0x03);
492 } else /* positive direction ROP */ {
493 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_OP
, 0x02);
494 dbg_blit("(copyarea) positive rop\n");
497 /* set for rectangel mode and not linear */
498 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CTL0
, 0x0);
500 /* setup the bpp 1 = 16bpp, 0 = 8bpp*/
501 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CTL1
, (bpp
>> 1));
503 /* set words per xres */
504 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_MEM_OFF0
, (stride
>> 1) & 0xff);
505 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_MEM_OFF1
, (stride
>> 9));
507 dbg_blit("(copyarea) dx=%d, dy=%d\n", dx
, dy
);
508 dbg_blit("(copyarea) sx=%d, sy=%d\n", sx
, sy
);
509 dbg_blit("(copyarea) width=%d, height=%d\n", width
- 1, height
- 1);
510 dbg_blit("(copyarea) stride=%d\n", stride
);
511 dbg_blit("(copyarea) bpp=%d=0x0%d, mem_offset1=%d, mem_offset2=%d\n", bpp
, (bpp
>> 1),
512 (stride
>> 1) & 0xff, stride
>> 9);
514 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CC_EXP
, 0x0c);
516 /* initialize the engine */
517 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CTL0
, 0x80);
519 /* wait to complete */
520 bltbit_wait_bitclear(info
, 0x80, 8000);
522 spin_unlock(&s1d13xxxfb_bitblt_lock
);
527 * s1d13xxxfb_bitblt_solidfill - accelerated solidfill function
528 * @info : framebuffer structure
529 * @rect : fb_fillrect structure
531 * supports (atleast 13506)
535 s1d13xxxfb_bitblt_solidfill(struct fb_info
*info
, const struct fb_fillrect
*rect
)
537 u32 screen_stride
, dest
;
539 u16 bpp
= (info
->var
.bits_per_pixel
>> 3);
542 spin_lock(&s1d13xxxfb_bitblt_lock
);
544 /* bytes per x width */
545 screen_stride
= (bpp
* info
->var
.xres
);
547 /* bytes to starting point */
548 dest
= ((rect
->dy
* screen_stride
) + (bpp
* rect
->dx
));
550 dbg_blit("(solidfill) dx=%d, dy=%d, stride=%d, dest=%d\n"
551 "(solidfill) : rect_width=%d, rect_height=%d\n",
552 rect
->dx
, rect
->dy
, screen_stride
, dest
,
553 rect
->width
- 1, rect
->height
- 1);
555 dbg_blit("(solidfill) : xres=%d, yres=%d, bpp=%d\n",
556 info
->var
.xres
, info
->var
.yres
,
557 info
->var
.bits_per_pixel
);
558 dbg_blit("(solidfill) : rop=%d\n", rect
->rop
);
560 /* We split the destination into the three registers */
561 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_DST_START0
, (dest
& 0x00ff));
562 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_DST_START1
, ((dest
>> 8) & 0x00ff));
563 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_DST_START2
, ((dest
>> 16) & 0x00ff));
565 /* give information regarding rectangel width */
566 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_WIDTH0
, ((rect
->width
) & 0x00ff) - 1);
567 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_WIDTH1
, (rect
->width
>> 8));
569 /* give information regarding rectangel height */
570 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_HEIGHT0
, ((rect
->height
) & 0x00ff) - 1);
571 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_HEIGHT1
, (rect
->height
>> 8));
573 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
||
574 info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
575 fg
= ((u32
*)info
->pseudo_palette
)[rect
->color
];
576 dbg_blit("(solidfill) truecolor/directcolor\n");
577 dbg_blit("(solidfill) pseudo_palette[%d] = %d\n", rect
->color
, fg
);
580 dbg_blit("(solidfill) color = %d\n", rect
->color
);
583 /* set foreground color */
584 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_FGC0
, (fg
& 0xff));
585 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_FGC1
, (fg
>> 8) & 0xff);
587 /* set rectangual region of memory (rectangle and not linear) */
588 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CTL0
, 0x0);
590 /* set operation mode SOLID_FILL */
591 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_OP
, BBLT_SOLID_FILL
);
593 /* set bits per pixel (1 = 16bpp, 0 = 8bpp) */
594 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CTL1
, (info
->var
.bits_per_pixel
>> 4));
596 /* set the memory offset for the bblt in word sizes */
597 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_MEM_OFF0
, (screen_stride
>> 1) & 0x00ff);
598 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_MEM_OFF1
, (screen_stride
>> 9));
600 /* and away we go.... */
601 s1d13xxxfb_writereg(info
->par
, S1DREG_BBLT_CTL0
, 0x80);
603 /* wait until its done */
604 bltbit_wait_bitclear(info
, 0x80, 8000);
606 /* let others play */
607 spin_unlock(&s1d13xxxfb_bitblt_lock
);
610 /* framebuffer information structures */
611 static struct fb_ops s1d13xxxfb_fbops
= {
612 .owner
= THIS_MODULE
,
613 .fb_set_par
= s1d13xxxfb_set_par
,
614 .fb_setcolreg
= s1d13xxxfb_setcolreg
,
615 .fb_blank
= s1d13xxxfb_blank
,
617 .fb_pan_display
= s1d13xxxfb_pan_display
,
619 /* gets replaced at chip detection time */
620 .fb_fillrect
= cfb_fillrect
,
621 .fb_copyarea
= cfb_copyarea
,
622 .fb_imageblit
= cfb_imageblit
,
625 static int s1d13xxxfb_width_tab
[2][4] = {
631 * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to
633 * @info: frame buffer structure
635 * We setup the framebuffer structures according to the current
636 * hardware setup. On some machines, the BIOS will have filled
637 * the chip registers with such info, on others, these values will
638 * have been written in some init procedure. In any case, the
639 * software values needs to match the hardware ones. This is what
640 * this function ensures.
642 * Note: some of the hardcoded values here might need some love to
643 * work on various chips, and might need to no longer be hardcoded.
645 static void s1d13xxxfb_fetch_hw_state(struct fb_info
*info
)
647 struct fb_var_screeninfo
*var
= &info
->var
;
648 struct fb_fix_screeninfo
*fix
= &info
->fix
;
649 struct s1d13xxxfb_par
*par
= info
->par
;
653 u32 xres_virtual
, yres_virtual
;
655 int is_color
, is_dual
, is_tft
;
656 int lcd_enabled
, crt_enabled
;
658 fix
->type
= FB_TYPE_PACKED_PIXELS
;
661 par
->display
= s1d13xxxfb_readreg(par
, S1DREG_COM_DISP_MODE
);
662 crt_enabled
= (par
->display
& 0x02) != 0;
663 lcd_enabled
= (par
->display
& 0x01) != 0;
665 if (lcd_enabled
&& crt_enabled
)
666 printk(KERN_WARNING PFX
"Warning: LCD and CRT detected, using LCD\n");
669 display
= s1d13xxxfb_readreg(par
, S1DREG_LCD_DISP_MODE
);
671 display
= s1d13xxxfb_readreg(par
, S1DREG_CRT_DISP_MODE
);
673 bpp
= display
& 0x07;
678 var
->bits_per_pixel
= 8;
679 var
->red
.offset
= var
->green
.offset
= var
->blue
.offset
= 0;
680 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
683 s1d13xxxfb_setup_truecolour(info
);
686 dbg("bpp: %i\n", bpp
);
688 fb_alloc_cmap(&info
->cmap
, 256, 0);
691 panel
= s1d13xxxfb_readreg(par
, S1DREG_PANEL_TYPE
);
692 is_color
= (panel
& 0x04) != 0;
693 is_dual
= (panel
& 0x02) != 0;
694 is_tft
= (panel
& 0x01) != 0;
695 lcd_bpp
= s1d13xxxfb_width_tab
[is_tft
][(panel
>> 4) & 3];
698 xres
= (s1d13xxxfb_readreg(par
, S1DREG_LCD_DISP_HWIDTH
) + 1) * 8;
699 yres
= (s1d13xxxfb_readreg(par
, S1DREG_LCD_DISP_VHEIGHT0
) +
700 ((s1d13xxxfb_readreg(par
, S1DREG_LCD_DISP_VHEIGHT1
) & 0x03) << 8) + 1);
702 offset
= (s1d13xxxfb_readreg(par
, S1DREG_LCD_MEM_OFF0
) +
703 ((s1d13xxxfb_readreg(par
, S1DREG_LCD_MEM_OFF1
) & 0x7) << 8));
705 xres
= (s1d13xxxfb_readreg(par
, S1DREG_CRT_DISP_HWIDTH
) + 1) * 8;
706 yres
= (s1d13xxxfb_readreg(par
, S1DREG_CRT_DISP_VHEIGHT0
) +
707 ((s1d13xxxfb_readreg(par
, S1DREG_CRT_DISP_VHEIGHT1
) & 0x03) << 8) + 1);
709 offset
= (s1d13xxxfb_readreg(par
, S1DREG_CRT_MEM_OFF0
) +
710 ((s1d13xxxfb_readreg(par
, S1DREG_CRT_MEM_OFF1
) & 0x7) << 8));
712 xres_virtual
= offset
* 16 / var
->bits_per_pixel
;
713 yres_virtual
= fix
->smem_len
/ (offset
* 2);
717 var
->xres_virtual
= xres_virtual
;
718 var
->yres_virtual
= yres_virtual
;
719 var
->xoffset
= var
->yoffset
= 0;
721 fix
->line_length
= offset
* 2;
723 var
->grayscale
= !is_color
;
725 var
->activate
= FB_ACTIVATE_NOW
;
727 dbg(PFX
"bpp=%d, lcd_bpp=%d, "
728 "crt_enabled=%d, lcd_enabled=%d\n",
729 var
->bits_per_pixel
, lcd_bpp
, crt_enabled
, lcd_enabled
);
730 dbg(PFX
"xres=%d, yres=%d, vxres=%d, vyres=%d "
731 "is_color=%d, is_dual=%d, is_tft=%d\n",
732 xres
, yres
, xres_virtual
, yres_virtual
, is_color
, is_dual
, is_tft
);
737 s1d13xxxfb_remove(struct platform_device
*pdev
)
739 struct fb_info
*info
= platform_get_drvdata(pdev
);
740 struct s1d13xxxfb_par
*par
= NULL
;
744 if (par
&& par
->regs
) {
745 /* disable output & enable powersave */
746 s1d13xxxfb_writereg(par
, S1DREG_COM_DISP_MODE
, 0x00);
747 s1d13xxxfb_writereg(par
, S1DREG_PS_CNF
, 0x11);
751 fb_dealloc_cmap(&info
->cmap
);
753 if (info
->screen_base
)
754 iounmap(info
->screen_base
);
756 framebuffer_release(info
);
759 release_mem_region(pdev
->resource
[0].start
,
760 pdev
->resource
[0].end
- pdev
->resource
[0].start
+1);
761 release_mem_region(pdev
->resource
[1].start
,
762 pdev
->resource
[1].end
- pdev
->resource
[1].start
+1);
766 static int s1d13xxxfb_probe(struct platform_device
*pdev
)
768 struct s1d13xxxfb_par
*default_par
;
769 struct fb_info
*info
;
770 struct s1d13xxxfb_pdata
*pdata
= NULL
;
773 u8 revision
, prod_id
;
775 dbg("probe called: device is %p\n", pdev
);
777 printk(KERN_INFO
"Epson S1D13XXX FB Driver\n");
779 /* enable platform-dependent hardware glue, if any */
780 if (dev_get_platdata(&pdev
->dev
))
781 pdata
= dev_get_platdata(&pdev
->dev
);
783 if (pdata
&& pdata
->platform_init_video
)
784 pdata
->platform_init_video();
786 if (pdev
->num_resources
!= 2) {
787 dev_err(&pdev
->dev
, "invalid num_resources: %i\n",
788 pdev
->num_resources
);
793 /* resource[0] is VRAM, resource[1] is registers */
794 if (pdev
->resource
[0].flags
!= IORESOURCE_MEM
795 || pdev
->resource
[1].flags
!= IORESOURCE_MEM
) {
796 dev_err(&pdev
->dev
, "invalid resource type\n");
801 if (!request_mem_region(pdev
->resource
[0].start
,
802 pdev
->resource
[0].end
- pdev
->resource
[0].start
+1, "s1d13xxxfb mem")) {
803 dev_dbg(&pdev
->dev
, "request_mem_region failed\n");
808 if (!request_mem_region(pdev
->resource
[1].start
,
809 pdev
->resource
[1].end
- pdev
->resource
[1].start
+1, "s1d13xxxfb regs")) {
810 dev_dbg(&pdev
->dev
, "request_mem_region failed\n");
815 info
= framebuffer_alloc(sizeof(struct s1d13xxxfb_par
) + sizeof(u32
) * 256, &pdev
->dev
);
821 platform_set_drvdata(pdev
, info
);
822 default_par
= info
->par
;
823 default_par
->regs
= ioremap_nocache(pdev
->resource
[1].start
,
824 pdev
->resource
[1].end
- pdev
->resource
[1].start
+1);
825 if (!default_par
->regs
) {
826 printk(KERN_ERR PFX
"unable to map registers\n");
830 info
->pseudo_palette
= default_par
->pseudo_palette
;
832 info
->screen_base
= ioremap_nocache(pdev
->resource
[0].start
,
833 pdev
->resource
[0].end
- pdev
->resource
[0].start
+1);
835 if (!info
->screen_base
) {
836 printk(KERN_ERR PFX
"unable to map framebuffer\n");
841 /* production id is top 6 bits */
842 prod_id
= s1d13xxxfb_readreg(default_par
, S1DREG_REV_CODE
) >> 2;
843 /* revision id is lower 2 bits */
844 revision
= s1d13xxxfb_readreg(default_par
, S1DREG_REV_CODE
) & 0x3;
847 for (i
= 0; i
< ARRAY_SIZE(s1d13xxxfb_prod_ids
); i
++) {
848 if (prod_id
== s1d13xxxfb_prod_ids
[i
]) {
849 /* looks like we got it in our list */
850 default_par
->prod_id
= prod_id
;
851 default_par
->revision
= revision
;
858 printk(KERN_INFO PFX
"chip production id %i = %s\n",
859 prod_id
, s1d13xxxfb_prod_names
[i
]);
860 printk(KERN_INFO PFX
"chip revision %i\n", revision
);
863 "unknown chip production id %i, revision %i\n",
865 printk(KERN_INFO PFX
"please contact maintainer\n");
869 info
->fix
= s1d13xxxfb_fix
;
870 info
->fix
.mmio_start
= pdev
->resource
[1].start
;
871 info
->fix
.mmio_len
= pdev
->resource
[1].end
- pdev
->resource
[1].start
+ 1;
872 info
->fix
.smem_start
= pdev
->resource
[0].start
;
873 info
->fix
.smem_len
= pdev
->resource
[0].end
- pdev
->resource
[0].start
+ 1;
875 printk(KERN_INFO PFX
"regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n",
876 default_par
->regs
, info
->fix
.smem_len
/ 1024, info
->screen_base
);
878 info
->par
= default_par
;
879 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
880 info
->fbops
= &s1d13xxxfb_fbops
;
883 case S1D13506_PROD_ID
: /* activate acceleration */
884 s1d13xxxfb_fbops
.fb_fillrect
= s1d13xxxfb_bitblt_solidfill
;
885 s1d13xxxfb_fbops
.fb_copyarea
= s1d13xxxfb_bitblt_copyarea
;
886 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
|
887 FBINFO_HWACCEL_FILLRECT
| FBINFO_HWACCEL_COPYAREA
;
893 /* perform "manual" chip initialization, if needed */
894 if (pdata
&& pdata
->initregs
)
895 s1d13xxxfb_runinit(info
->par
, pdata
->initregs
, pdata
->initregssize
);
897 s1d13xxxfb_fetch_hw_state(info
);
899 if (register_framebuffer(info
) < 0) {
904 fb_info(info
, "%s frame buffer device\n", info
->fix
.id
);
909 s1d13xxxfb_remove(pdev
);
915 static int s1d13xxxfb_suspend(struct platform_device
*dev
, pm_message_t state
)
917 struct fb_info
*info
= platform_get_drvdata(dev
);
918 struct s1d13xxxfb_par
*s1dfb
= info
->par
;
919 struct s1d13xxxfb_pdata
*pdata
= NULL
;
921 /* disable display */
922 lcd_enable(s1dfb
, 0);
923 crt_enable(s1dfb
, 0);
925 if (dev_get_platdata(&dev
->dev
))
926 pdata
= dev_get_platdata(&dev
->dev
);
929 if (!s1dfb
->disp_save
)
930 s1dfb
->disp_save
= kmalloc(info
->fix
.smem_len
, GFP_KERNEL
);
932 if (!s1dfb
->disp_save
) {
933 printk(KERN_ERR PFX
"no memory to save screen");
937 memcpy_fromio(s1dfb
->disp_save
, info
->screen_base
, info
->fix
.smem_len
);
939 s1dfb
->disp_save
= NULL
;
942 if (!s1dfb
->regs_save
)
943 s1dfb
->regs_save
= kmalloc(info
->fix
.mmio_len
, GFP_KERNEL
);
945 if (!s1dfb
->regs_save
) {
946 printk(KERN_ERR PFX
"no memory to save registers");
950 /* backup all registers */
951 memcpy_fromio(s1dfb
->regs_save
, s1dfb
->regs
, info
->fix
.mmio_len
);
953 /* now activate power save mode */
954 s1d13xxxfb_writereg(s1dfb
, S1DREG_PS_CNF
, 0x11);
956 if (pdata
&& pdata
->platform_suspend_video
)
957 return pdata
->platform_suspend_video();
962 static int s1d13xxxfb_resume(struct platform_device
*dev
)
964 struct fb_info
*info
= platform_get_drvdata(dev
);
965 struct s1d13xxxfb_par
*s1dfb
= info
->par
;
966 struct s1d13xxxfb_pdata
*pdata
= NULL
;
968 /* awaken the chip */
969 s1d13xxxfb_writereg(s1dfb
, S1DREG_PS_CNF
, 0x10);
971 /* do not let go until SDRAM "wakes up" */
972 while ((s1d13xxxfb_readreg(s1dfb
, S1DREG_PS_STATUS
) & 0x01))
975 if (dev_get_platdata(&dev
->dev
))
976 pdata
= dev_get_platdata(&dev
->dev
);
978 if (s1dfb
->regs_save
) {
979 /* will write RO regs, *should* get away with it :) */
980 memcpy_toio(s1dfb
->regs
, s1dfb
->regs_save
, info
->fix
.mmio_len
);
981 kfree(s1dfb
->regs_save
);
984 if (s1dfb
->disp_save
) {
985 memcpy_toio(info
->screen_base
, s1dfb
->disp_save
,
987 kfree(s1dfb
->disp_save
); /* XXX kmalloc()'d when? */
990 if ((s1dfb
->display
& 0x01) != 0)
991 lcd_enable(s1dfb
, 1);
992 if ((s1dfb
->display
& 0x02) != 0)
993 crt_enable(s1dfb
, 1);
995 if (pdata
&& pdata
->platform_resume_video
)
996 return pdata
->platform_resume_video();
1000 #endif /* CONFIG_PM */
1002 static struct platform_driver s1d13xxxfb_driver
= {
1003 .probe
= s1d13xxxfb_probe
,
1004 .remove
= s1d13xxxfb_remove
,
1006 .suspend
= s1d13xxxfb_suspend
,
1007 .resume
= s1d13xxxfb_resume
,
1010 .name
= S1D_DEVICENAME
,
1016 s1d13xxxfb_init(void)
1020 if (fb_get_options("s1d13xxxfb", NULL
))
1024 return platform_driver_register(&s1d13xxxfb_driver
);
1029 s1d13xxxfb_exit(void)
1031 platform_driver_unregister(&s1d13xxxfb_driver
);
1034 module_init(s1d13xxxfb_init
);
1035 module_exit(s1d13xxxfb_exit
);
1038 MODULE_LICENSE("GPL");
1039 MODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices");
1040 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>");