[ACPI] fix EC access width
[linux-2.6/kmemtrace.git] / drivers / video / s1d13xxxfb.c
blobb637c389e4f480945c5c9f8b0775605496bd6d25
1 /* drivers/video/s1d13xxxfb.c
3 * (c) 2004 Simtec Electronics
4 * (c) 2005 Thibaut VARENE <varenet@parisc-linux.org>
6 * Driver for Epson S1D13xxx series framebuffer chips
8 * Adapted from
9 * linux/drivers/video/skeletonfb.c
10 * linux/drivers/video/epson1355fb.c
11 * linux/drivers/video/epson/s1d13xxxfb.c (2.4 driver by Epson)
13 * Note, currently only tested on S1D13806 with 16bit CRT.
14 * As such, this driver might still contain some hardcoded bits relating to
15 * S1D13806.
16 * Making it work on other S1D13XXX chips should merely be a matter of adding
17 * a few switch()s, some missing glue here and there maybe, and split header
18 * files.
20 * TODO: - handle dual screen display (CRT and LCD at the same time).
21 * - check_var(), mode change, etc.
22 * - PM untested.
23 * - Accelerated interfaces.
24 * - Probably not SMP safe :)
26 * This file is subject to the terms and conditions of the GNU General Public
27 * License. See the file COPYING in the main directory of this archive for
28 * more details.
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/device.h>
34 #include <linux/delay.h>
36 #include <linux/types.h>
37 #include <linux/errno.h>
38 #include <linux/mm.h>
39 #include <linux/mman.h>
40 #include <linux/fb.h>
42 #include <asm/io.h>
44 #include <video/s1d13xxxfb.h>
46 #define PFX "s1d13xxxfb: "
48 #if 0
49 #define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0)
50 #else
51 #define dbg(fmt, args...) do { } while (0)
52 #endif
55 * Here we define the default struct fb_fix_screeninfo
57 static struct fb_fix_screeninfo __devinitdata s1d13xxxfb_fix = {
58 .id = S1D_FBID,
59 .type = FB_TYPE_PACKED_PIXELS,
60 .visual = FB_VISUAL_PSEUDOCOLOR,
61 .xpanstep = 0,
62 .ypanstep = 1,
63 .ywrapstep = 0,
64 .accel = FB_ACCEL_NONE,
67 static inline u8
68 s1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno)
70 return readb(par->regs + regno);
73 static inline void
74 s1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value)
76 writeb(value, par->regs + regno);
79 static inline void
80 s1d13xxxfb_runinit(struct s1d13xxxfb_par *par,
81 const struct s1d13xxxfb_regval *initregs,
82 const unsigned int size)
84 int i;
86 for (i = 0; i < size; i++) {
87 if ((initregs[i].addr == S1DREG_DELAYOFF) ||
88 (initregs[i].addr == S1DREG_DELAYON))
89 mdelay((int)initregs[i].value);
90 else {
91 s1d13xxxfb_writereg(par, initregs[i].addr, initregs[i].value);
95 /* make sure the hardware can cope with us */
96 mdelay(1);
99 static inline void
100 lcd_enable(struct s1d13xxxfb_par *par, int enable)
102 u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
104 if (enable)
105 mode |= 0x01;
106 else
107 mode &= ~0x01;
109 s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode);
112 static inline void
113 crt_enable(struct s1d13xxxfb_par *par, int enable)
115 u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
117 if (enable)
118 mode |= 0x02;
119 else
120 mode &= ~0x02;
122 s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode);
125 /* framebuffer control routines */
127 static inline void
128 s1d13xxxfb_setup_pseudocolour(struct fb_info *info)
130 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
132 info->var.red.length = 4;
133 info->var.green.length = 4;
134 info->var.blue.length = 4;
137 static inline void
138 s1d13xxxfb_setup_truecolour(struct fb_info *info)
140 info->fix.visual = FB_VISUAL_TRUECOLOR;
141 info->var.bits_per_pixel = 16;
143 info->var.red.length = 5;
144 info->var.red.offset = 11;
146 info->var.green.length = 6;
147 info->var.green.offset = 5;
149 info->var.blue.length = 5;
150 info->var.blue.offset = 0;
154 * s1d13xxxfb_set_par - Alters the hardware state.
155 * @info: frame buffer structure
157 * Using the fb_var_screeninfo in fb_info we set the depth of the
158 * framebuffer. This function alters the par AND the
159 * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
160 * fb_info since we are using that data. This means we depend on the
161 * data in var inside fb_info to be supported by the hardware.
162 * xxxfb_check_var is always called before xxxfb_set_par to ensure this.
164 * XXX TODO: write proper s1d13xxxfb_check_var(), without which that
165 * function is quite useless.
167 static int
168 s1d13xxxfb_set_par(struct fb_info *info)
170 struct s1d13xxxfb_par *s1dfb = info->par;
171 unsigned int val;
173 dbg("s1d13xxxfb_set_par: bpp=%d\n", info->var.bits_per_pixel);
175 if ((s1dfb->display & 0x01)) /* LCD */
176 val = s1d13xxxfb_readreg(s1dfb, S1DREG_LCD_DISP_MODE); /* read colour control */
177 else /* CRT */
178 val = s1d13xxxfb_readreg(s1dfb, S1DREG_CRT_DISP_MODE); /* read colour control */
180 val &= ~0x07;
182 switch (info->var.bits_per_pixel) {
183 case 4:
184 dbg("pseudo colour 4\n");
185 s1d13xxxfb_setup_pseudocolour(info);
186 val |= 2;
187 break;
188 case 8:
189 dbg("pseudo colour 8\n");
190 s1d13xxxfb_setup_pseudocolour(info);
191 val |= 3;
192 break;
193 case 16:
194 dbg("true colour\n");
195 s1d13xxxfb_setup_truecolour(info);
196 val |= 5;
197 break;
199 default:
200 dbg("bpp not supported!\n");
201 return -EINVAL;
204 dbg("writing %02x to display mode register\n", val);
206 if ((s1dfb->display & 0x01)) /* LCD */
207 s1d13xxxfb_writereg(s1dfb, S1DREG_LCD_DISP_MODE, val);
208 else /* CRT */
209 s1d13xxxfb_writereg(s1dfb, S1DREG_CRT_DISP_MODE, val);
211 info->fix.line_length = info->var.xres * info->var.bits_per_pixel;
212 info->fix.line_length /= 8;
214 dbg("setting line_length to %d\n", info->fix.line_length);
216 dbg("done setup\n");
218 return 0;
222 * s1d13xxxfb_setcolreg - sets a color register.
223 * @regno: Which register in the CLUT we are programming
224 * @red: The red value which can be up to 16 bits wide
225 * @green: The green value which can be up to 16 bits wide
226 * @blue: The blue value which can be up to 16 bits wide.
227 * @transp: If supported the alpha value which can be up to 16 bits wide.
228 * @info: frame buffer info structure
230 * Returns negative errno on error, or zero on success.
232 static int
233 s1d13xxxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
234 u_int transp, struct fb_info *info)
236 struct s1d13xxxfb_par *s1dfb = info->par;
237 unsigned int pseudo_val;
239 if (regno >= S1D_PALETTE_SIZE)
240 return -EINVAL;
242 dbg("s1d13xxxfb_setcolreg: %d: rgb=%d,%d,%d, tr=%d\n",
243 regno, red, green, blue, transp);
245 if (info->var.grayscale)
246 red = green = blue = (19595*red + 38470*green + 7471*blue) >> 16;
248 switch (info->fix.visual) {
249 case FB_VISUAL_TRUECOLOR:
250 if (regno >= 16)
251 return -EINVAL;
253 /* deal with creating pseudo-palette entries */
255 pseudo_val = (red >> 11) << info->var.red.offset;
256 pseudo_val |= (green >> 10) << info->var.green.offset;
257 pseudo_val |= (blue >> 11) << info->var.blue.offset;
259 dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n",
260 regno, pseudo_val);
262 ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
264 break;
265 case FB_VISUAL_PSEUDOCOLOR:
266 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_ADDR, regno);
267 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, red);
268 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, green);
269 s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, blue);
271 break;
272 default:
273 return -ENOSYS;
276 dbg("s1d13xxxfb_setcolreg: done\n");
278 return 0;
282 * s1d13xxxfb_blank - blanks the display.
283 * @blank_mode: the blank mode we want.
284 * @info: frame buffer structure that represents a single frame buffer
286 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
287 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
288 * video mode which doesn't support it. Implements VESA suspend
289 * and powerdown modes on hardware that supports disabling hsync/vsync:
290 * blank_mode == 2: suspend vsync
291 * blank_mode == 3: suspend hsync
292 * blank_mode == 4: powerdown
294 * Returns negative errno on error, or zero on success.
296 static int
297 s1d13xxxfb_blank(int blank_mode, struct fb_info *info)
299 struct s1d13xxxfb_par *par = info->par;
301 dbg("s1d13xxxfb_blank: blank=%d, info=%p\n", blank_mode, info);
303 switch (blank_mode) {
304 case FB_BLANK_UNBLANK:
305 case FB_BLANK_NORMAL:
306 if ((par->display & 0x01) != 0)
307 lcd_enable(par, 1);
308 if ((par->display & 0x02) != 0)
309 crt_enable(par, 1);
310 break;
311 case FB_BLANK_VSYNC_SUSPEND:
312 case FB_BLANK_HSYNC_SUSPEND:
313 break;
314 case FB_BLANK_POWERDOWN:
315 lcd_enable(par, 0);
316 crt_enable(par, 0);
317 break;
318 default:
319 return -EINVAL;
322 /* let fbcon do a soft blank for us */
323 return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
327 * s1d13xxxfb_pan_display - Pans the display.
328 * @var: frame buffer variable screen structure
329 * @info: frame buffer structure that represents a single frame buffer
331 * Pan (or wrap, depending on the `vmode' field) the display using the
332 * `yoffset' field of the `var' structure (`xoffset' not yet supported).
333 * If the values don't fit, return -EINVAL.
335 * Returns negative errno on error, or zero on success.
337 static int
338 s1d13xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
340 struct s1d13xxxfb_par *par = info->par;
341 u32 start;
343 if (var->xoffset != 0) /* not yet ... */
344 return -EINVAL;
346 if (var->yoffset + info->var.yres > info->var.yres_virtual)
347 return -EINVAL;
349 start = (info->fix.line_length >> 1) * var->yoffset;
351 if ((par->display & 0x01)) {
352 /* LCD */
353 s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START0, (start & 0xff));
354 s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START1, ((start >> 8) & 0xff));
355 s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START2, ((start >> 16) & 0x0f));
356 } else {
357 /* CRT */
358 s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START0, (start & 0xff));
359 s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START1, ((start >> 8) & 0xff));
360 s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START2, ((start >> 16) & 0x0f));
363 return 0;
367 /* framebuffer information structures */
369 static struct fb_ops s1d13xxxfb_fbops = {
370 .owner = THIS_MODULE,
371 .fb_set_par = s1d13xxxfb_set_par,
372 .fb_setcolreg = s1d13xxxfb_setcolreg,
373 .fb_blank = s1d13xxxfb_blank,
375 .fb_pan_display = s1d13xxxfb_pan_display,
377 /* to be replaced by any acceleration we can */
378 .fb_fillrect = cfb_fillrect,
379 .fb_copyarea = cfb_copyarea,
380 .fb_imageblit = cfb_imageblit,
381 .fb_cursor = soft_cursor
384 static int s1d13xxxfb_width_tab[2][4] __devinitdata = {
385 {4, 8, 16, -1},
386 {9, 12, 18, -1},
390 * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to
391 * hardware setup.
392 * @info: frame buffer structure
394 * We setup the framebuffer structures according to the current
395 * hardware setup. On some machines, the BIOS will have filled
396 * the chip registers with such info, on others, these values will
397 * have been written in some init procedure. In any case, the
398 * software values needs to match the hardware ones. This is what
399 * this function ensures.
401 * Note: some of the hardcoded values here might need some love to
402 * work on various chips, and might need to no longer be hardcoded.
404 static void __devinit
405 s1d13xxxfb_fetch_hw_state(struct fb_info *info)
407 struct fb_var_screeninfo *var = &info->var;
408 struct fb_fix_screeninfo *fix = &info->fix;
409 struct s1d13xxxfb_par *par = info->par;
410 u8 panel, display;
411 u16 offset;
412 u32 xres, yres;
413 u32 xres_virtual, yres_virtual;
414 int bpp, lcd_bpp;
415 int is_color, is_dual, is_tft;
416 int lcd_enabled, crt_enabled;
418 fix->type = FB_TYPE_PACKED_PIXELS;
420 /* general info */
421 par->display = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE);
422 crt_enabled = (par->display & 0x02) != 0;
423 lcd_enabled = (par->display & 0x01) != 0;
425 if (lcd_enabled && crt_enabled)
426 printk(KERN_WARNING PFX "Warning: LCD and CRT detected, using LCD\n");
428 if (lcd_enabled)
429 display = s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_MODE);
430 else /* CRT */
431 display = s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_MODE);
433 bpp = display & 0x07;
435 switch (bpp) {
436 case 2: /* 4 bpp */
437 case 3: /* 8 bpp */
438 var->bits_per_pixel = 8;
439 var->red.offset = var->green.offset = var->blue.offset = 0;
440 var->red.length = var->green.length = var->blue.length = 8;
441 break;
442 case 5: /* 16 bpp */
443 s1d13xxxfb_setup_truecolour(info);
444 break;
445 default:
446 dbg("bpp: %i\n", bpp);
448 fb_alloc_cmap(&info->cmap, 256, 0);
450 /* LCD info */
451 panel = s1d13xxxfb_readreg(par, S1DREG_PANEL_TYPE);
452 is_color = (panel & 0x04) != 0;
453 is_dual = (panel & 0x02) != 0;
454 is_tft = (panel & 0x01) != 0;
455 lcd_bpp = s1d13xxxfb_width_tab[is_tft][(panel >> 4) & 3];
457 if (lcd_enabled) {
458 xres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_HWIDTH) + 1) * 8;
459 yres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT0) +
460 ((s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT1) & 0x03) << 8) + 1);
462 offset = (s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF0) +
463 ((s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF1) & 0x7) << 8));
464 } else { /* crt */
465 xres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_HWIDTH) + 1) * 8;
466 yres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT0) +
467 ((s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT1) & 0x03) << 8) + 1);
469 offset = (s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF0) +
470 ((s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF1) & 0x7) << 8));
472 xres_virtual = offset * 16 / var->bits_per_pixel;
473 yres_virtual = fix->smem_len / (offset * 2);
475 var->xres = xres;
476 var->yres = yres;
477 var->xres_virtual = xres_virtual;
478 var->yres_virtual = yres_virtual;
479 var->xoffset = var->yoffset = 0;
481 fix->line_length = offset * 2;
483 var->grayscale = !is_color;
485 var->activate = FB_ACTIVATE_NOW;
487 dbg(PFX "bpp=%d, lcd_bpp=%d, "
488 "crt_enabled=%d, lcd_enabled=%d\n",
489 var->bits_per_pixel, lcd_bpp, crt_enabled, lcd_enabled);
490 dbg(PFX "xres=%d, yres=%d, vxres=%d, vyres=%d "
491 "is_color=%d, is_dual=%d, is_tft=%d\n",
492 xres, yres, xres_virtual, yres_virtual, is_color, is_dual, is_tft);
496 static int __devexit
497 s1d13xxxfb_remove(struct device *dev)
499 struct fb_info *info = dev_get_drvdata(dev);
500 struct platform_device *pdev = to_platform_device(dev);
501 struct s1d13xxxfb_par *par = NULL;
503 if (info) {
504 par = info->par;
505 if (par && par->regs) {
506 /* disable output & enable powersave */
507 s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, 0x00);
508 s1d13xxxfb_writereg(par, S1DREG_PS_CNF, 0x11);
509 iounmap(par->regs);
512 fb_dealloc_cmap(&info->cmap);
514 if (info->screen_base)
515 iounmap(info->screen_base);
517 framebuffer_release(info);
520 release_mem_region(pdev->resource[0].start,
521 pdev->resource[0].end - pdev->resource[0].start +1);
522 release_mem_region(pdev->resource[1].start,
523 pdev->resource[1].end - pdev->resource[1].start +1);
524 return 0;
527 static int __devinit
528 s1d13xxxfb_probe(struct device *dev)
530 struct platform_device *pdev = to_platform_device(dev);
531 struct s1d13xxxfb_par *default_par;
532 struct fb_info *info;
533 struct s1d13xxxfb_pdata *pdata = NULL;
534 int ret = 0;
535 u8 revision;
537 dbg("probe called: device is %p\n", dev);
539 printk(KERN_INFO "Epson S1D13XXX FB Driver\n");
541 /* enable platform-dependent hardware glue, if any */
542 if (dev->platform_data)
543 pdata = dev->platform_data;
545 if (pdata && pdata->platform_init_video)
546 pdata->platform_init_video();
549 if (pdev->num_resources != 2) {
550 dev_err(&pdev->dev, "invalid num_resources: %i\n",
551 pdev->num_resources);
552 ret = -ENODEV;
553 goto bail;
556 /* resource[0] is VRAM, resource[1] is registers */
557 if (pdev->resource[0].flags != IORESOURCE_MEM
558 || pdev->resource[1].flags != IORESOURCE_MEM) {
559 dev_err(&pdev->dev, "invalid resource type\n");
560 ret = -ENODEV;
561 goto bail;
564 if (!request_mem_region(pdev->resource[0].start,
565 pdev->resource[0].end - pdev->resource[0].start +1, "s1d13xxxfb mem")) {
566 dev_dbg(dev, "request_mem_region failed\n");
567 ret = -EBUSY;
568 goto bail;
571 if (!request_mem_region(pdev->resource[1].start,
572 pdev->resource[1].end - pdev->resource[1].start +1, "s1d13xxxfb regs")) {
573 dev_dbg(dev, "request_mem_region failed\n");
574 ret = -EBUSY;
575 goto bail;
578 info = framebuffer_alloc(sizeof(struct s1d13xxxfb_par) + sizeof(u32) * 256, &pdev->dev);
579 if (!info) {
580 ret = -ENOMEM;
581 goto bail;
584 default_par = info->par;
585 default_par->regs = ioremap_nocache(pdev->resource[1].start,
586 pdev->resource[1].end - pdev->resource[1].start +1);
587 if (!default_par->regs) {
588 printk(KERN_ERR PFX "unable to map registers\n");
589 ret = -ENOMEM;
590 goto bail;
592 info->pseudo_palette = default_par->pseudo_palette;
594 info->screen_base = ioremap_nocache(pdev->resource[0].start,
595 pdev->resource[0].end - pdev->resource[0].start +1);
597 if (!info->screen_base) {
598 printk(KERN_ERR PFX "unable to map framebuffer\n");
599 ret = -ENOMEM;
600 goto bail;
603 revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE);
604 if ((revision >> 2) != S1D_CHIP_REV) {
605 printk(KERN_INFO PFX "chip not found: %i\n", (revision >> 2));
606 ret = -ENODEV;
607 goto bail;
610 info->fix = s1d13xxxfb_fix;
611 info->fix.mmio_start = pdev->resource[1].start;
612 info->fix.mmio_len = pdev->resource[1].end - pdev->resource[1].start +1;
613 info->fix.smem_start = pdev->resource[0].start;
614 info->fix.smem_len = pdev->resource[0].end - pdev->resource[0].start +1;
616 printk(KERN_INFO PFX "regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n",
617 default_par->regs, info->fix.smem_len / 1024, info->screen_base);
619 info->par = default_par;
620 info->fbops = &s1d13xxxfb_fbops;
621 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
623 /* perform "manual" chip initialization, if needed */
624 if (pdata && pdata->initregs)
625 s1d13xxxfb_runinit(info->par, pdata->initregs, pdata->initregssize);
627 s1d13xxxfb_fetch_hw_state(info);
629 if (register_framebuffer(info) < 0) {
630 ret = -EINVAL;
631 goto bail;
634 dev_set_drvdata(&pdev->dev, info);
636 printk(KERN_INFO "fb%d: %s frame buffer device\n",
637 info->node, info->fix.id);
639 return 0;
641 bail:
642 s1d13xxxfb_remove(dev);
643 return ret;
647 #ifdef CONFIG_PM
648 static int s1d13xxxfb_suspend(struct device *dev, u32 state, u32 level)
650 struct fb_info *info = dev_get_drvdata(dev);
651 struct s1d13xxxfb_par *s1dfb = info->par;
652 struct s1d13xxxfb_pdata *pdata = NULL;
654 /* disable display */
655 lcd_enable(s1dfb, 0);
656 crt_enable(s1dfb, 0);
658 if (dev->platform_data)
659 pdata = dev->platform_data;
661 #if 0
662 if (!s1dfb->disp_save)
663 s1dfb->disp_save = kmalloc(info->fix.smem_len, GFP_KERNEL);
665 if (!s1dfb->disp_save) {
666 printk(KERN_ERR PFX "no memory to save screen");
667 return -ENOMEM;
670 memcpy_fromio(s1dfb->disp_save, info->screen_base, info->fix.smem_len);
671 #else
672 s1dfb->disp_save = NULL;
673 #endif
675 if (!s1dfb->regs_save)
676 s1dfb->regs_save = kmalloc(info->fix.mmio_len, GFP_KERNEL);
678 if (!s1dfb->regs_save) {
679 printk(KERN_ERR PFX "no memory to save registers");
680 return -ENOMEM;
683 /* backup all registers */
684 memcpy_fromio(s1dfb->regs_save, s1dfb->regs, info->fix.mmio_len);
686 /* now activate power save mode */
687 s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x11);
689 if (pdata && pdata->platform_suspend_video)
690 return pdata->platform_suspend_video();
691 else
692 return 0;
695 static int s1d13xxxfb_resume(struct device *dev, u32 level)
697 struct fb_info *info = dev_get_drvdata(dev);
698 struct s1d13xxxfb_par *s1dfb = info->par;
699 struct s1d13xxxfb_pdata *pdata = NULL;
701 if (level != RESUME_ENABLE)
702 return 0;
704 /* awaken the chip */
705 s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10);
707 /* do not let go until SDRAM "wakes up" */
708 while ((s1d13xxxfb_readreg(s1dfb, S1DREG_PS_STATUS) & 0x01))
709 udelay(10);
711 if (dev->platform_data)
712 pdata = dev->platform_data;
714 if (s1dfb->regs_save) {
715 /* will write RO regs, *should* get away with it :) */
716 memcpy_toio(s1dfb->regs, s1dfb->regs_save, info->fix.mmio_len);
717 kfree(s1dfb->regs_save);
720 if (s1dfb->disp_save) {
721 memcpy_toio(info->screen_base, s1dfb->disp_save,
722 info->fix.smem_len);
723 kfree(s1dfb->disp_save); /* XXX kmalloc()'d when? */
726 if ((s1dfb->display & 0x01) != 0)
727 lcd_enable(s1dfb, 1);
728 if ((s1dfb->display & 0x02) != 0)
729 crt_enable(s1dfb, 1);
731 if (pdata && pdata->platform_resume_video)
732 return pdata->platform_resume_video();
733 else
734 return 0;
736 #endif /* CONFIG_PM */
738 static struct device_driver s1d13xxxfb_driver = {
739 .name = S1D_DEVICENAME,
740 .bus = &platform_bus_type,
741 .probe = s1d13xxxfb_probe,
742 .remove = s1d13xxxfb_remove,
743 #ifdef CONFIG_PM
744 .suspend = s1d13xxxfb_suspend,
745 .resume = s1d13xxxfb_resume
746 #endif
750 static int __init
751 s1d13xxxfb_init(void)
753 if (fb_get_options("s1d13xxxfb", NULL))
754 return -ENODEV;
756 return driver_register(&s1d13xxxfb_driver);
760 static void __exit
761 s1d13xxxfb_exit(void)
763 driver_unregister(&s1d13xxxfb_driver);
766 module_init(s1d13xxxfb_init);
767 module_exit(s1d13xxxfb_exit);
770 MODULE_LICENSE("GPL");
771 MODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices");
772 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>");