1 /* linux/drivers/video/sm501fb.c
3 * Copyright (c) 2006 Simtec Electronics
4 * Vincent Sanders <vince@simtec.co.uk>
5 * Ben Dooks <ben@simtec.co.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Framebuffer driver for the Silicon Motion SM501
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
19 #include <linux/tty.h>
20 #include <linux/slab.h>
21 #include <linux/delay.h>
23 #include <linux/init.h>
24 #include <linux/vmalloc.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/interrupt.h>
27 #include <linux/workqueue.h>
28 #include <linux/wait.h>
29 #include <linux/platform_device.h>
30 #include <linux/clk.h>
33 #include <asm/uaccess.h>
34 #include <asm/div64.h>
40 #include <linux/sm501.h>
41 #include <linux/sm501-regs.h>
43 #define NR_PALETTE 256
45 enum sm501_controller {
50 /* SM501 memory adress */
53 unsigned long sm_addr;
57 /* private data that is shared between all frambuffers* */
60 struct fb_info *fb[2]; /* fb info for both heads */
61 struct resource *fbmem_res; /* framebuffer resource */
62 struct resource *regs_res; /* registers resource */
63 struct sm501_platdata_fb *pdata; /* our platform data */
65 unsigned long pm_crt_ctrl; /* pm: crt ctrl save */
68 int swap_endian; /* set to swap rgb=>bgr */
69 void __iomem *regs; /* remapped registers */
70 void __iomem *fbmem; /* remapped framebuffer */
71 size_t fbmem_len; /* length of remapped region */
74 /* per-framebuffer private data */
76 u32 pseudo_palette[16];
78 enum sm501_controller head;
79 struct sm501_mem cursor;
80 struct sm501_mem screen;
85 void __iomem *cursor_regs;
86 struct sm501fb_info *info;
89 /* Helper functions */
91 static inline int h_total(struct fb_var_screeninfo *var)
93 return var->xres + var->left_margin +
94 var->right_margin + var->hsync_len;
97 static inline int v_total(struct fb_var_screeninfo *var)
99 return var->yres + var->upper_margin +
100 var->lower_margin + var->vsync_len;
103 /* sm501fb_sync_regs()
105 * This call is mainly for PCI bus systems where we need to
106 * ensure that any writes to the bus are completed before the
107 * next phase, or after completing a function.
110 static inline void sm501fb_sync_regs(struct sm501fb_info *info)
117 * This is an attempt to lay out memory for the two framebuffers and
120 * |fbmem_res->start fbmem_res->end|
122 * |fb[0].fix.smem_start | |fb[1].fix.smem_start | 2K |
123 * |-> fb[0].fix.smem_len <-| spare |-> fb[1].fix.smem_len <-|-> cursors <-|
125 * The "spare" space is for the 2d engine data
126 * the fixed is space for the cursors (2x1Kbyte)
128 * we need to allocate memory for the 2D acceleration engine
129 * command list and the data for the engine to deal with.
131 * - all allocations must be 128bit aligned
132 * - cursors are 64x64x2 bits (1Kbyte)
136 #define SM501_MEMF_CURSOR (1)
137 #define SM501_MEMF_PANEL (2)
138 #define SM501_MEMF_CRT (4)
139 #define SM501_MEMF_ACCEL (8)
141 static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
142 unsigned int why, size_t size)
144 unsigned int ptr = 0;
147 case SM501_MEMF_CURSOR:
148 ptr = inf->fbmem_len - size;
149 inf->fbmem_len = ptr;
152 case SM501_MEMF_PANEL:
153 ptr = inf->fbmem_len - size;
154 if (ptr < inf->fb[0]->fix.smem_len)
163 case SM501_MEMF_ACCEL:
164 ptr = inf->fb[0]->fix.smem_len;
167 (inf->fb[1]->fix.smem_start - inf->fbmem_res->start))
177 mem->k_addr = inf->fbmem + ptr;
179 dev_dbg(inf->dev, "%s: result %08lx, %p - %u, %zd\n",
180 __func__, mem->sm_addr, mem->k_addr, why, size);
187 * Converts a period in picoseconds to Hz.
189 * Note, we try to keep this in Hz to minimise rounding with
190 * the limited PLL settings on the SM501.
193 static unsigned long sm501fb_ps_to_hz(unsigned long psvalue)
195 unsigned long long numerator=1000000000000ULL;
197 /* 10^12 / picosecond period gives frequency in Hz */
198 do_div(numerator, psvalue);
199 return (unsigned long)numerator;
202 /* sm501fb_hz_to_ps is identical to the oposite transform */
204 #define sm501fb_hz_to_ps(x) sm501fb_ps_to_hz(x)
206 /* sm501fb_setup_gamma
208 * Programs a linear 1.0 gamma ramp in case the gamma
209 * correction is enabled without programming anything else.
212 static void sm501fb_setup_gamma(struct sm501fb_info *fbi,
213 unsigned long palette)
215 unsigned long value = 0;
218 /* set gamma values */
219 for (offset = 0; offset < 256 * 4; offset += 4) {
220 writel(value, fbi->regs + palette + offset);
221 value += 0x010101; /* Advance RGB by 1,1,1.*/
227 * check common variables for both panel and crt
230 static int sm501fb_check_var(struct fb_var_screeninfo *var,
231 struct fb_info *info)
233 struct sm501fb_par *par = info->par;
234 struct sm501fb_info *sm = par->info;
237 /* check we can fit these values into the registers */
239 if (var->hsync_len > 255 || var->vsync_len > 255)
242 if ((var->xres + var->right_margin) >= 4096)
245 if ((var->yres + var->lower_margin) > 2048)
248 /* hard limits of device */
250 if (h_total(var) > 4096 || v_total(var) > 2048)
253 /* check our line length is going to be 128 bit aligned */
255 tmp = (var->xres * var->bits_per_pixel) / 8;
259 /* check the virtual size */
261 if (var->xres_virtual > 4096 || var->yres_virtual > 2048)
264 /* can cope with 8,16 or 32bpp */
266 if (var->bits_per_pixel <= 8)
267 var->bits_per_pixel = 8;
268 else if (var->bits_per_pixel <= 16)
269 var->bits_per_pixel = 16;
270 else if (var->bits_per_pixel == 24)
271 var->bits_per_pixel = 32;
273 /* set r/g/b positions and validate bpp */
274 switch(var->bits_per_pixel) {
276 var->red.length = var->bits_per_pixel;
278 var->green.length = var->bits_per_pixel;
279 var->green.offset = 0;
280 var->blue.length = var->bits_per_pixel;
281 var->blue.offset = 0;
282 var->transp.length = 0;
287 if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
288 var->red.offset = 11;
289 var->green.offset = 5;
290 var->blue.offset = 0;
292 var->blue.offset = 11;
293 var->green.offset = 5;
298 var->green.length = 6;
299 var->blue.length = 5;
300 var->transp.length = 0;
304 if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
305 var->transp.offset = 0;
307 var->green.offset = 16;
308 var->blue.offset = 24;
310 var->transp.offset = 24;
311 var->red.offset = 16;
312 var->green.offset = 8;
313 var->blue.offset = 0;
317 var->green.length = 8;
318 var->blue.length = 8;
319 var->transp.length = 0;
330 * sm501fb_check_var_crt():
332 * check the parameters for the CRT head, and either bring them
333 * back into range, or return -EINVAL.
336 static int sm501fb_check_var_crt(struct fb_var_screeninfo *var,
337 struct fb_info *info)
339 return sm501fb_check_var(var, info);
342 /* sm501fb_check_var_pnl():
344 * check the parameters for the CRT head, and either bring them
345 * back into range, or return -EINVAL.
348 static int sm501fb_check_var_pnl(struct fb_var_screeninfo *var,
349 struct fb_info *info)
351 return sm501fb_check_var(var, info);
354 /* sm501fb_set_par_common
356 * set common registers for framebuffers
359 static int sm501fb_set_par_common(struct fb_info *info,
360 struct fb_var_screeninfo *var)
362 struct sm501fb_par *par = info->par;
363 struct sm501fb_info *fbi = par->info;
364 unsigned long pixclock; /* pixelclock in Hz */
365 unsigned long sm501pixclock; /* pixelclock the 501 can achive in Hz */
366 unsigned int mem_type;
367 unsigned int clock_type;
368 unsigned int head_addr;
370 dev_dbg(fbi->dev, "%s: %dx%d, bpp = %d, virtual %dx%d\n",
371 __func__, var->xres, var->yres, var->bits_per_pixel,
372 var->xres_virtual, var->yres_virtual);
376 mem_type = SM501_MEMF_CRT;
377 clock_type = SM501_CLOCK_V2XCLK;
378 head_addr = SM501_DC_CRT_FB_ADDR;
382 mem_type = SM501_MEMF_PANEL;
383 clock_type = SM501_CLOCK_P2XCLK;
384 head_addr = SM501_DC_PANEL_FB_ADDR;
388 mem_type = 0; /* stop compiler warnings */
393 switch (var->bits_per_pixel) {
395 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
399 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
403 info->fix.visual = FB_VISUAL_TRUECOLOR;
407 /* allocate fb memory within 501 */
408 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel)/8;
409 info->fix.smem_len = info->fix.line_length * var->yres_virtual;
411 dev_dbg(fbi->dev, "%s: line length = %u\n", __func__,
412 info->fix.line_length);
414 if (sm501_alloc_mem(fbi, &par->screen, mem_type,
415 info->fix.smem_len)) {
416 dev_err(fbi->dev, "no memory available\n");
420 info->fix.smem_start = fbi->fbmem_res->start + par->screen.sm_addr;
422 info->screen_base = fbi->fbmem + par->screen.sm_addr;
423 info->screen_size = info->fix.smem_len;
425 /* set start of framebuffer to the screen */
427 writel(par->screen.sm_addr | SM501_ADDR_FLIP, fbi->regs + head_addr);
429 /* program CRT clock */
431 pixclock = sm501fb_ps_to_hz(var->pixclock);
433 sm501pixclock = sm501_set_clock(fbi->dev->parent, clock_type,
436 /* update fb layer with actual clock used */
437 var->pixclock = sm501fb_hz_to_ps(sm501pixclock);
439 dev_dbg(fbi->dev, "%s: pixclock(ps) = %u, pixclock(Hz) = %lu, "
440 "sm501pixclock = %lu, error = %ld%%\n",
441 __func__, var->pixclock, pixclock, sm501pixclock,
442 ((pixclock - sm501pixclock)*100)/pixclock);
447 /* sm501fb_set_par_geometry
449 * set the geometry registers for specified framebuffer.
452 static void sm501fb_set_par_geometry(struct fb_info *info,
453 struct fb_var_screeninfo *var)
455 struct sm501fb_par *par = info->par;
456 struct sm501fb_info *fbi = par->info;
457 void __iomem *base = fbi->regs;
460 if (par->head == HEAD_CRT)
461 base += SM501_DC_CRT_H_TOT;
463 base += SM501_DC_PANEL_H_TOT;
465 /* set framebuffer width and display width */
467 reg = info->fix.line_length;
468 reg |= ((var->xres * var->bits_per_pixel)/8) << 16;
470 writel(reg, fbi->regs + (par->head == HEAD_CRT ?
471 SM501_DC_CRT_FB_OFFSET : SM501_DC_PANEL_FB_OFFSET));
473 /* program horizontal total */
475 reg = (h_total(var) - 1) << 16;
476 reg |= (var->xres - 1);
478 writel(reg, base + SM501_OFF_DC_H_TOT);
480 /* program horizontal sync */
482 reg = var->hsync_len << 16;
483 reg |= var->xres + var->right_margin - 1;
485 writel(reg, base + SM501_OFF_DC_H_SYNC);
487 /* program vertical total */
489 reg = (v_total(var) - 1) << 16;
490 reg |= (var->yres - 1);
492 writel(reg, base + SM501_OFF_DC_V_TOT);
494 /* program vertical sync */
495 reg = var->vsync_len << 16;
496 reg |= var->yres + var->lower_margin - 1;
498 writel(reg, base + SM501_OFF_DC_V_SYNC);
503 * pan the CRT display output within an virtual framebuffer
506 static int sm501fb_pan_crt(struct fb_var_screeninfo *var,
507 struct fb_info *info)
509 struct sm501fb_par *par = info->par;
510 struct sm501fb_info *fbi = par->info;
511 unsigned int bytes_pixel = var->bits_per_pixel / 8;
515 xoffs = var->xoffset * bytes_pixel;
517 reg = readl(fbi->regs + SM501_DC_CRT_CONTROL);
519 reg &= ~SM501_DC_CRT_CONTROL_PIXEL_MASK;
520 reg |= ((xoffs & 15) / bytes_pixel) << 4;
521 writel(reg, fbi->regs + SM501_DC_CRT_CONTROL);
523 reg = (par->screen.sm_addr + xoffs +
524 var->yoffset * info->fix.line_length);
525 writel(reg | SM501_ADDR_FLIP, fbi->regs + SM501_DC_CRT_FB_ADDR);
527 sm501fb_sync_regs(fbi);
533 * pan the panel display output within an virtual framebuffer
536 static int sm501fb_pan_pnl(struct fb_var_screeninfo *var,
537 struct fb_info *info)
539 struct sm501fb_par *par = info->par;
540 struct sm501fb_info *fbi = par->info;
543 reg = var->xoffset | (var->xres_virtual << 16);
544 writel(reg, fbi->regs + SM501_DC_PANEL_FB_WIDTH);
546 reg = var->yoffset | (var->yres_virtual << 16);
547 writel(reg, fbi->regs + SM501_DC_PANEL_FB_HEIGHT);
549 sm501fb_sync_regs(fbi);
553 /* sm501fb_set_par_crt
555 * Set the CRT video mode from the fb_info structure
558 static int sm501fb_set_par_crt(struct fb_info *info)
560 struct sm501fb_par *par = info->par;
561 struct sm501fb_info *fbi = par->info;
562 struct fb_var_screeninfo *var = &info->var;
563 unsigned long control; /* control register */
566 /* activate new configuration */
568 dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
570 /* enable CRT DAC - note 0 is on!*/
571 sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
573 control = readl(fbi->regs + SM501_DC_CRT_CONTROL);
575 control &= (SM501_DC_CRT_CONTROL_PIXEL_MASK |
576 SM501_DC_CRT_CONTROL_GAMMA |
577 SM501_DC_CRT_CONTROL_BLANK |
578 SM501_DC_CRT_CONTROL_SEL |
579 SM501_DC_CRT_CONTROL_CP |
580 SM501_DC_CRT_CONTROL_TVP);
582 /* set the sync polarities before we check data source */
584 if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
585 control |= SM501_DC_CRT_CONTROL_HSP;
587 if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
588 control |= SM501_DC_CRT_CONTROL_VSP;
590 if ((control & SM501_DC_CRT_CONTROL_SEL) == 0) {
591 /* the head is displaying panel data... */
593 sm501_alloc_mem(fbi, &par->screen, SM501_MEMF_CRT, 0);
597 ret = sm501fb_set_par_common(info, var);
599 dev_err(fbi->dev, "failed to set common parameters\n");
603 sm501fb_pan_crt(var, info);
604 sm501fb_set_par_geometry(info, var);
606 control |= SM501_FIFO_3; /* fill if >3 free slots */
608 switch(var->bits_per_pixel) {
610 control |= SM501_DC_CRT_CONTROL_8BPP;
614 control |= SM501_DC_CRT_CONTROL_16BPP;
618 control |= SM501_DC_CRT_CONTROL_32BPP;
619 sm501fb_setup_gamma(fbi, SM501_DC_CRT_PALETTE);
626 control |= SM501_DC_CRT_CONTROL_SEL; /* CRT displays CRT data */
627 control |= SM501_DC_CRT_CONTROL_TE; /* enable CRT timing */
628 control |= SM501_DC_CRT_CONTROL_ENABLE; /* enable CRT plane */
631 dev_dbg(fbi->dev, "new control is %08lx\n", control);
633 writel(control, fbi->regs + SM501_DC_CRT_CONTROL);
634 sm501fb_sync_regs(fbi);
639 static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
641 unsigned long control;
642 void __iomem *ctrl_reg = fbi->regs + SM501_DC_PANEL_CONTROL;
644 control = readl(ctrl_reg);
646 if (to && (control & SM501_DC_PANEL_CONTROL_VDD) == 0) {
647 /* enable panel power */
649 control |= SM501_DC_PANEL_CONTROL_VDD; /* FPVDDEN */
650 writel(control, ctrl_reg);
651 sm501fb_sync_regs(fbi);
654 control |= SM501_DC_PANEL_CONTROL_DATA; /* DATA */
655 writel(control, ctrl_reg);
656 sm501fb_sync_regs(fbi);
659 control |= SM501_DC_PANEL_CONTROL_BIAS; /* VBIASEN */
660 writel(control, ctrl_reg);
661 sm501fb_sync_regs(fbi);
664 control |= SM501_DC_PANEL_CONTROL_FPEN;
665 writel(control, ctrl_reg);
667 } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) {
668 /* disable panel power */
670 control &= ~SM501_DC_PANEL_CONTROL_FPEN;
671 writel(control, ctrl_reg);
672 sm501fb_sync_regs(fbi);
675 control &= ~SM501_DC_PANEL_CONTROL_BIAS;
676 writel(control, ctrl_reg);
677 sm501fb_sync_regs(fbi);
680 control &= ~SM501_DC_PANEL_CONTROL_DATA;
681 writel(control, ctrl_reg);
682 sm501fb_sync_regs(fbi);
685 control &= ~SM501_DC_PANEL_CONTROL_VDD;
686 writel(control, ctrl_reg);
687 sm501fb_sync_regs(fbi);
691 sm501fb_sync_regs(fbi);
694 /* sm501fb_set_par_pnl
696 * Set the panel video mode from the fb_info structure
699 static int sm501fb_set_par_pnl(struct fb_info *info)
701 struct sm501fb_par *par = info->par;
702 struct sm501fb_info *fbi = par->info;
703 struct fb_var_screeninfo *var = &info->var;
704 unsigned long control;
708 dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
710 /* activate this new configuration */
712 ret = sm501fb_set_par_common(info, var);
716 sm501fb_pan_pnl(var, info);
717 sm501fb_set_par_geometry(info, var);
719 /* update control register */
721 control = readl(fbi->regs + SM501_DC_PANEL_CONTROL);
722 control &= (SM501_DC_PANEL_CONTROL_GAMMA |
723 SM501_DC_PANEL_CONTROL_VDD |
724 SM501_DC_PANEL_CONTROL_DATA |
725 SM501_DC_PANEL_CONTROL_BIAS |
726 SM501_DC_PANEL_CONTROL_FPEN |
727 SM501_DC_PANEL_CONTROL_CP |
728 SM501_DC_PANEL_CONTROL_CK |
729 SM501_DC_PANEL_CONTROL_HP |
730 SM501_DC_PANEL_CONTROL_VP |
731 SM501_DC_PANEL_CONTROL_HPD |
732 SM501_DC_PANEL_CONTROL_VPD);
734 control |= SM501_FIFO_3; /* fill if >3 free slots */
736 switch(var->bits_per_pixel) {
738 control |= SM501_DC_PANEL_CONTROL_8BPP;
742 control |= SM501_DC_PANEL_CONTROL_16BPP;
746 control |= SM501_DC_PANEL_CONTROL_32BPP;
747 sm501fb_setup_gamma(fbi, SM501_DC_PANEL_PALETTE);
754 writel(0x0, fbi->regs + SM501_DC_PANEL_PANNING_CONTROL);
756 /* panel plane top left and bottom right location */
758 writel(0x00, fbi->regs + SM501_DC_PANEL_TL_LOC);
761 reg |= (var->yres - 1) << 16;
763 writel(reg, fbi->regs + SM501_DC_PANEL_BR_LOC);
765 /* program panel control register */
767 control |= SM501_DC_PANEL_CONTROL_TE; /* enable PANEL timing */
768 control |= SM501_DC_PANEL_CONTROL_EN; /* enable PANEL gfx plane */
770 if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
771 control |= SM501_DC_PANEL_CONTROL_HSP;
773 if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
774 control |= SM501_DC_PANEL_CONTROL_VSP;
776 writel(control, fbi->regs + SM501_DC_PANEL_CONTROL);
777 sm501fb_sync_regs(fbi);
779 /* power the panel up */
780 sm501fb_panel_power(fbi, 1);
787 * convert a colour value into a field position
792 static inline unsigned int chan_to_field(unsigned int chan,
793 struct fb_bitfield *bf)
796 chan >>= 16 - bf->length;
797 return chan << bf->offset;
802 * set the colour mapping for modes that support palettised data
805 static int sm501fb_setcolreg(unsigned regno,
806 unsigned red, unsigned green, unsigned blue,
807 unsigned transp, struct fb_info *info)
809 struct sm501fb_par *par = info->par;
810 struct sm501fb_info *fbi = par->info;
811 void __iomem *base = fbi->regs;
814 if (par->head == HEAD_CRT)
815 base += SM501_DC_CRT_PALETTE;
817 base += SM501_DC_PANEL_PALETTE;
819 switch (info->fix.visual) {
820 case FB_VISUAL_TRUECOLOR:
821 /* true-colour, use pseuo-palette */
824 u32 *pal = par->pseudo_palette;
826 val = chan_to_field(red, &info->var.red);
827 val |= chan_to_field(green, &info->var.green);
828 val |= chan_to_field(blue, &info->var.blue);
834 case FB_VISUAL_PSEUDOCOLOR:
836 val = (red >> 8) << 16;
837 val |= (green >> 8) << 8;
840 writel(val, base + (regno * 4));
846 return 1; /* unknown type */
854 * Blank or un-blank the panel interface
857 static int sm501fb_blank_pnl(int blank_mode, struct fb_info *info)
859 struct sm501fb_par *par = info->par;
860 struct sm501fb_info *fbi = par->info;
862 dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
864 switch (blank_mode) {
865 case FB_BLANK_POWERDOWN:
866 sm501fb_panel_power(fbi, 0);
869 case FB_BLANK_UNBLANK:
870 sm501fb_panel_power(fbi, 1);
873 case FB_BLANK_NORMAL:
874 case FB_BLANK_VSYNC_SUSPEND:
875 case FB_BLANK_HSYNC_SUSPEND:
885 * Blank or un-blank the crt interface
888 static int sm501fb_blank_crt(int blank_mode, struct fb_info *info)
890 struct sm501fb_par *par = info->par;
891 struct sm501fb_info *fbi = par->info;
894 dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
896 ctrl = readl(fbi->regs + SM501_DC_CRT_CONTROL);
898 switch (blank_mode) {
899 case FB_BLANK_POWERDOWN:
900 ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
901 sm501_misc_control(fbi->dev->parent, SM501_MISC_DAC_POWER, 0);
903 case FB_BLANK_NORMAL:
904 ctrl |= SM501_DC_CRT_CONTROL_BLANK;
907 case FB_BLANK_UNBLANK:
908 ctrl &= ~SM501_DC_CRT_CONTROL_BLANK;
909 ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
910 sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
913 case FB_BLANK_VSYNC_SUSPEND:
914 case FB_BLANK_HSYNC_SUSPEND:
920 writel(ctrl, fbi->regs + SM501_DC_CRT_CONTROL);
921 sm501fb_sync_regs(fbi);
928 * set or change the hardware cursor parameters
931 static int sm501fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
933 struct sm501fb_par *par = info->par;
934 struct sm501fb_info *fbi = par->info;
935 void __iomem *base = fbi->regs;
936 unsigned long hwc_addr;
937 unsigned long fg, bg;
939 dev_dbg(fbi->dev, "%s(%p,%p)\n", __func__, info, cursor);
941 if (par->head == HEAD_CRT)
942 base += SM501_DC_CRT_HWC_BASE;
944 base += SM501_DC_PANEL_HWC_BASE;
946 /* check not being asked to exceed capabilities */
948 if (cursor->image.width > 64)
951 if (cursor->image.height > 64)
954 if (cursor->image.depth > 1)
957 hwc_addr = readl(base + SM501_OFF_HWC_ADDR);
960 writel(hwc_addr | SM501_HWC_EN, base + SM501_OFF_HWC_ADDR);
962 writel(hwc_addr & ~SM501_HWC_EN, base + SM501_OFF_HWC_ADDR);
965 if (cursor->set & FB_CUR_SETPOS) {
966 unsigned int x = cursor->image.dx;
967 unsigned int y = cursor->image.dy;
969 if (x >= 2048 || y >= 2048 )
972 dev_dbg(fbi->dev, "set position %d,%d\n", x, y);
974 //y += cursor->image.height;
976 writel(x | (y << 16), base + SM501_OFF_HWC_LOC);
979 if (cursor->set & FB_CUR_SETCMAP) {
980 unsigned int bg_col = cursor->image.bg_color;
981 unsigned int fg_col = cursor->image.fg_color;
983 dev_dbg(fbi->dev, "%s: update cmap (%08x,%08x)\n",
984 __func__, bg_col, fg_col);
986 bg = ((info->cmap.red[bg_col] & 0xF8) << 8) |
987 ((info->cmap.green[bg_col] & 0xFC) << 3) |
988 ((info->cmap.blue[bg_col] & 0xF8) >> 3);
990 fg = ((info->cmap.red[fg_col] & 0xF8) << 8) |
991 ((info->cmap.green[fg_col] & 0xFC) << 3) |
992 ((info->cmap.blue[fg_col] & 0xF8) >> 3);
994 dev_dbg(fbi->dev, "fgcol %08lx, bgcol %08lx\n", fg, bg);
996 writel(bg, base + SM501_OFF_HWC_COLOR_1_2);
997 writel(fg, base + SM501_OFF_HWC_COLOR_3);
1000 if (cursor->set & FB_CUR_SETSIZE ||
1001 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE)) {
1002 /* SM501 cursor is a two bpp 64x64 bitmap this routine
1003 * clears it to transparent then combines the cursor
1004 * shape plane with the colour plane to set the
1007 const unsigned char *pcol = cursor->image.data;
1008 const unsigned char *pmsk = cursor->mask;
1009 void __iomem *dst = par->cursor.k_addr;
1010 unsigned char dcol = 0;
1011 unsigned char dmsk = 0;
1014 dev_dbg(fbi->dev, "%s: setting shape (%d,%d)\n",
1015 __func__, cursor->image.width, cursor->image.height);
1017 for (op = 0; op < (64*64*2)/8; op+=4)
1018 writel(0x0, dst + op);
1020 for (y = 0; y < cursor->image.height; y++) {
1021 for (x = 0; x < cursor->image.width; x++) {
1031 op = (dcol & 1) ? 1 : 3;
1032 op <<= ((x % 4) * 2);
1034 op |= readb(dst + (x / 4));
1035 writeb(op, dst + (x / 4));
1042 sm501fb_sync_regs(fbi); /* ensure cursor data flushed */
1046 /* sm501fb_crtsrc_show
1048 * device attribute code to show where the crt output is sourced from
1051 static ssize_t sm501fb_crtsrc_show(struct device *dev,
1052 struct device_attribute *attr, char *buf)
1054 struct sm501fb_info *info = dev_get_drvdata(dev);
1057 ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1058 ctrl &= SM501_DC_CRT_CONTROL_SEL;
1060 return snprintf(buf, PAGE_SIZE, "%s\n", ctrl ? "crt" : "panel");
1063 /* sm501fb_crtsrc_show
1065 * device attribute code to set where the crt output is sourced from
1068 static ssize_t sm501fb_crtsrc_store(struct device *dev,
1069 struct device_attribute *attr,
1070 const char *buf, size_t len)
1072 struct sm501fb_info *info = dev_get_drvdata(dev);
1073 enum sm501_controller head;
1079 if (strnicmp(buf, "crt", 3) == 0)
1081 else if (strnicmp(buf, "panel", 5) == 0)
1086 dev_info(dev, "setting crt source to head %d\n", head);
1088 ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1090 if (head == HEAD_CRT) {
1091 ctrl |= SM501_DC_CRT_CONTROL_SEL;
1092 ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
1093 ctrl |= SM501_DC_CRT_CONTROL_TE;
1095 ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
1096 ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
1097 ctrl &= ~SM501_DC_CRT_CONTROL_TE;
1100 writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
1101 sm501fb_sync_regs(info);
1106 /* Prepare the device_attr for registration with sysfs later */
1107 static DEVICE_ATTR(crt_src, 0666, sm501fb_crtsrc_show, sm501fb_crtsrc_store);
1109 /* sm501fb_show_regs
1111 * show the primary sm501 registers
1113 static int sm501fb_show_regs(struct sm501fb_info *info, char *ptr,
1114 unsigned int start, unsigned int len)
1116 void __iomem *mem = info->regs;
1120 for (reg = start; reg < (len + start); reg += 4)
1121 ptr += sprintf(ptr, "%08x = %08x\n", reg, readl(mem + reg));
1126 /* sm501fb_debug_show_crt
1128 * show the crt control and cursor registers
1131 static ssize_t sm501fb_debug_show_crt(struct device *dev,
1132 struct device_attribute *attr, char *buf)
1134 struct sm501fb_info *info = dev_get_drvdata(dev);
1137 ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_CONTROL, 0x40);
1138 ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_HWC_BASE, 0x10);
1143 static DEVICE_ATTR(fbregs_crt, 0444, sm501fb_debug_show_crt, NULL);
1145 /* sm501fb_debug_show_pnl
1147 * show the panel control and cursor registers
1150 static ssize_t sm501fb_debug_show_pnl(struct device *dev,
1151 struct device_attribute *attr, char *buf)
1153 struct sm501fb_info *info = dev_get_drvdata(dev);
1156 ptr += sm501fb_show_regs(info, ptr, 0x0, 0x40);
1157 ptr += sm501fb_show_regs(info, ptr, SM501_DC_PANEL_HWC_BASE, 0x10);
1162 static DEVICE_ATTR(fbregs_pnl, 0444, sm501fb_debug_show_pnl, NULL);
1164 /* framebuffer ops */
1166 static struct fb_ops sm501fb_ops_crt = {
1167 .owner = THIS_MODULE,
1168 .fb_check_var = sm501fb_check_var_crt,
1169 .fb_set_par = sm501fb_set_par_crt,
1170 .fb_blank = sm501fb_blank_crt,
1171 .fb_setcolreg = sm501fb_setcolreg,
1172 .fb_pan_display = sm501fb_pan_crt,
1173 .fb_cursor = sm501fb_cursor,
1174 .fb_fillrect = cfb_fillrect,
1175 .fb_copyarea = cfb_copyarea,
1176 .fb_imageblit = cfb_imageblit,
1179 static struct fb_ops sm501fb_ops_pnl = {
1180 .owner = THIS_MODULE,
1181 .fb_check_var = sm501fb_check_var_pnl,
1182 .fb_set_par = sm501fb_set_par_pnl,
1183 .fb_pan_display = sm501fb_pan_pnl,
1184 .fb_blank = sm501fb_blank_pnl,
1185 .fb_setcolreg = sm501fb_setcolreg,
1186 .fb_cursor = sm501fb_cursor,
1187 .fb_fillrect = cfb_fillrect,
1188 .fb_copyarea = cfb_copyarea,
1189 .fb_imageblit = cfb_imageblit,
1192 /* sm501fb_info_alloc
1194 * creates and initialises an sm501fb_info structure
1197 static struct sm501fb_info *sm501fb_info_alloc(struct fb_info *fbinfo_crt,
1198 struct fb_info *fbinfo_pnl)
1200 struct sm501fb_info *info;
1201 struct sm501fb_par *par;
1203 info = kzalloc(sizeof(struct sm501fb_info), GFP_KERNEL);
1205 /* set the references back */
1207 par = fbinfo_crt->par;
1209 par->head = HEAD_CRT;
1210 fbinfo_crt->pseudo_palette = &par->pseudo_palette;
1212 par = fbinfo_pnl->par;
1214 par->head = HEAD_PANEL;
1215 fbinfo_pnl->pseudo_palette = &par->pseudo_palette;
1217 /* store the two fbs into our info */
1218 info->fb[HEAD_CRT] = fbinfo_crt;
1219 info->fb[HEAD_PANEL] = fbinfo_pnl;
1225 /* sm501_init_cursor
1227 * initialise hw cursor parameters
1230 static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base)
1232 struct sm501fb_par *par = fbi->par;
1233 struct sm501fb_info *info = par->info;
1236 par->cursor_regs = info->regs + reg_base;
1238 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024);
1242 /* initialise the colour registers */
1244 writel(par->cursor.sm_addr, par->cursor_regs + SM501_OFF_HWC_ADDR);
1246 writel(0x00, par->cursor_regs + SM501_OFF_HWC_LOC);
1247 writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_1_2);
1248 writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_3);
1249 sm501fb_sync_regs(info);
1254 /* sm501fb_info_start
1256 * fills the par structure claiming resources and remapping etc.
1259 static int sm501fb_start(struct sm501fb_info *info,
1260 struct platform_device *pdev)
1262 struct resource *res;
1266 info->dev = dev = &pdev->dev;
1267 platform_set_drvdata(pdev, info);
1269 info->irq = ret = platform_get_irq(pdev, 0);
1271 /* we currently do not use the IRQ */
1272 dev_warn(dev, "no irq for device\n");
1275 /* allocate, reserve and remap resources for registers */
1276 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1278 dev_err(dev, "no resource definition for registers\n");
1283 info->regs_res = request_mem_region(res->start,
1284 res->end - res->start,
1287 if (info->regs_res == NULL) {
1288 dev_err(dev, "cannot claim registers\n");
1293 info->regs = ioremap(res->start, (res->end - res->start)+1);
1294 if (info->regs == NULL) {
1295 dev_err(dev, "cannot remap registers\n");
1300 /* allocate, reserve resources for framebuffer */
1301 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
1303 dev_err(dev, "no memory resource defined\n");
1308 info->fbmem_res = request_mem_region(res->start,
1309 (res->end - res->start)+1,
1311 if (info->fbmem_res == NULL) {
1312 dev_err(dev, "cannot claim framebuffer\n");
1317 info->fbmem = ioremap(res->start, (res->end - res->start)+1);
1318 if (info->fbmem == NULL) {
1319 dev_err(dev, "cannot remap framebuffer\n");
1323 info->fbmem_len = (res->end - res->start)+1;
1325 /* enable display controller */
1326 sm501_unit_power(dev->parent, SM501_GATE_DISPLAY, 1);
1330 sm501_init_cursor(info->fb[HEAD_CRT], SM501_DC_CRT_HWC_ADDR);
1331 sm501_init_cursor(info->fb[HEAD_PANEL], SM501_DC_PANEL_HWC_ADDR);
1333 return 0; /* everything is setup */
1336 release_resource(info->fbmem_res);
1337 kfree(info->fbmem_res);
1340 iounmap(info->regs);
1343 release_resource(info->regs_res);
1344 kfree(info->regs_res);
1350 static void sm501fb_stop(struct sm501fb_info *info)
1352 /* disable display controller */
1353 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
1355 iounmap(info->fbmem);
1356 release_resource(info->fbmem_res);
1357 kfree(info->fbmem_res);
1359 iounmap(info->regs);
1360 release_resource(info->regs_res);
1361 kfree(info->regs_res);
1364 static void sm501fb_info_release(struct sm501fb_info *info)
1369 static int sm501fb_init_fb(struct fb_info *fb,
1370 enum sm501_controller head,
1373 struct sm501_platdata_fbsub *pd;
1374 struct sm501fb_par *par = fb->par;
1375 struct sm501fb_info *info = par->info;
1377 unsigned int enable;
1382 pd = info->pdata->fb_crt;
1383 ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1384 enable = (ctrl & SM501_DC_CRT_CONTROL_ENABLE) ? 1 : 0;
1386 /* ensure we set the correct source register */
1387 if (info->pdata->fb_route != SM501_FB_CRT_PANEL) {
1388 ctrl |= SM501_DC_CRT_CONTROL_SEL;
1389 writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
1395 pd = info->pdata->fb_pnl;
1396 ctrl = readl(info->regs + SM501_DC_PANEL_CONTROL);
1397 enable = (ctrl & SM501_DC_PANEL_CONTROL_EN) ? 1 : 0;
1401 pd = NULL; /* stop compiler warnings */
1407 dev_info(info->dev, "fb %s %sabled at start\n",
1408 fbname, enable ? "en" : "dis");
1410 /* check to see if our routing allows this */
1412 if (head == HEAD_CRT && info->pdata->fb_route == SM501_FB_CRT_PANEL) {
1413 ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
1414 writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
1418 strlcpy(fb->fix.id, fbname, sizeof(fb->fix.id));
1421 (head == HEAD_CRT) ? &sm501fb_ops_crt : &sm501fb_ops_pnl,
1422 sizeof(struct fb_ops));
1424 /* update ops dependant on what we've been passed */
1426 if ((pd->flags & SM501FB_FLAG_USE_HWCURSOR) == 0)
1427 par->ops.fb_cursor = NULL;
1429 fb->fbops = &par->ops;
1430 fb->flags = FBINFO_FLAG_DEFAULT |
1431 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
1435 fb->fix.type = FB_TYPE_PACKED_PIXELS;
1436 fb->fix.type_aux = 0;
1437 fb->fix.xpanstep = 1;
1438 fb->fix.ypanstep = 1;
1439 fb->fix.ywrapstep = 0;
1440 fb->fix.accel = FB_ACCEL_NONE;
1445 fb->var.activate = FB_ACTIVATE_NOW;
1446 fb->var.accel_flags = 0;
1447 fb->var.vmode = FB_VMODE_NONINTERLACED;
1448 fb->var.bits_per_pixel = 16;
1450 if (enable && (pd->flags & SM501FB_FLAG_USE_INIT_MODE) && 0) {
1451 /* TODO read the mode from the current display */
1455 dev_info(info->dev, "using supplied mode\n");
1456 fb_videomode_to_var(&fb->var, pd->def_mode);
1458 fb->var.bits_per_pixel = pd->def_bpp ? pd->def_bpp : 8;
1459 fb->var.xres_virtual = fb->var.xres;
1460 fb->var.yres_virtual = fb->var.yres;
1462 ret = fb_find_mode(&fb->var, fb,
1463 NULL, NULL, 0, NULL, 8);
1465 if (ret == 0 || ret == 4) {
1467 "failed to get initial mode\n");
1473 /* initialise and set the palette */
1474 fb_alloc_cmap(&fb->cmap, NR_PALETTE, 0);
1475 fb_set_cmap(&fb->cmap, fb);
1477 ret = (fb->fbops->fb_check_var)(&fb->var, fb);
1479 dev_err(info->dev, "check_var() failed on initial setup?\n");
1481 /* ensure we've activated our new configuration */
1482 (fb->fbops->fb_set_par)(fb);
1487 /* default platform data if none is supplied (ie, PCI device) */
1489 static struct sm501_platdata_fbsub sm501fb_pdata_crt = {
1490 .flags = (SM501FB_FLAG_USE_INIT_MODE |
1491 SM501FB_FLAG_USE_HWCURSOR |
1492 SM501FB_FLAG_USE_HWACCEL |
1493 SM501FB_FLAG_DISABLE_AT_EXIT),
1497 static struct sm501_platdata_fbsub sm501fb_pdata_pnl = {
1498 .flags = (SM501FB_FLAG_USE_INIT_MODE |
1499 SM501FB_FLAG_USE_HWCURSOR |
1500 SM501FB_FLAG_USE_HWACCEL |
1501 SM501FB_FLAG_DISABLE_AT_EXIT),
1504 static struct sm501_platdata_fb sm501fb_def_pdata = {
1505 .fb_route = SM501_FB_OWN,
1506 .fb_crt = &sm501fb_pdata_crt,
1507 .fb_pnl = &sm501fb_pdata_pnl,
1510 static char driver_name_crt[] = "sm501fb-crt";
1511 static char driver_name_pnl[] = "sm501fb-panel";
1513 static int __init sm501fb_probe(struct platform_device *pdev)
1515 struct sm501fb_info *info;
1516 struct device *dev = &pdev->dev;
1517 struct fb_info *fbinfo_crt;
1518 struct fb_info *fbinfo_pnl;
1521 /* allocate our framebuffers */
1523 fbinfo_crt = framebuffer_alloc(sizeof(struct sm501fb_par), dev);
1524 if (fbinfo_crt == NULL) {
1525 dev_err(dev, "cannot allocate crt framebuffer\n");
1529 fbinfo_pnl = framebuffer_alloc(sizeof(struct sm501fb_par), dev);
1530 if (fbinfo_pnl == NULL) {
1531 dev_err(dev, "cannot allocate panel framebuffer\n");
1533 goto fbinfo_crt_alloc_fail;
1536 info = sm501fb_info_alloc(fbinfo_crt, fbinfo_pnl);
1538 dev_err(dev, "cannot allocate par\n");
1540 goto sm501fb_alloc_fail;
1543 if (dev->parent->platform_data) {
1544 struct sm501_platdata *pd = dev->parent->platform_data;
1545 info->pdata = pd->fb;
1548 if (info->pdata == NULL) {
1549 dev_info(dev, "using default configuration data\n");
1550 info->pdata = &sm501fb_def_pdata;
1553 /* start the framebuffers */
1555 ret = sm501fb_start(info, pdev);
1557 dev_err(dev, "cannot initialise SM501\n");
1558 goto sm501fb_start_fail;
1561 /* CRT framebuffer setup */
1563 ret = sm501fb_init_fb(fbinfo_crt, HEAD_CRT, driver_name_crt);
1565 dev_err(dev, "cannot initialise CRT fb\n");
1566 goto sm501fb_start_fail;
1569 /* Panel framebuffer setup */
1571 ret = sm501fb_init_fb(fbinfo_pnl, HEAD_PANEL, driver_name_pnl);
1573 dev_err(dev, "cannot initialise Panel fb\n");
1574 goto sm501fb_start_fail;
1577 /* register framebuffers */
1579 ret = register_framebuffer(fbinfo_crt);
1581 dev_err(dev, "failed to register CRT fb (%d)\n", ret);
1582 goto register_crt_fail;
1585 ret = register_framebuffer(fbinfo_pnl);
1587 dev_err(dev, "failed to register panel fb (%d)\n", ret);
1588 goto register_pnl_fail;
1591 dev_info(dev, "fb%d: %s frame buffer device\n",
1592 fbinfo_crt->node, fbinfo_crt->fix.id);
1594 dev_info(dev, "fb%d: %s frame buffer device\n",
1595 fbinfo_pnl->node, fbinfo_pnl->fix.id);
1597 /* create device files */
1599 ret = device_create_file(dev, &dev_attr_crt_src);
1603 ret = device_create_file(dev, &dev_attr_fbregs_pnl);
1605 goto fbregs_pnl_fail;
1607 ret = device_create_file(dev, &dev_attr_fbregs_crt);
1609 goto fbregs_crt_fail;
1611 /* we registered, return ok */
1615 device_remove_file(dev, &dev_attr_fbregs_pnl);
1618 device_remove_file(dev, &dev_attr_crt_src);
1621 unregister_framebuffer(fbinfo_pnl);
1624 unregister_framebuffer(fbinfo_crt);
1630 sm501fb_info_release(info);
1633 framebuffer_release(fbinfo_pnl);
1635 fbinfo_crt_alloc_fail:
1636 framebuffer_release(fbinfo_crt);
1645 static int sm501fb_remove(struct platform_device *pdev)
1647 struct sm501fb_info *info = platform_get_drvdata(pdev);
1648 struct fb_info *fbinfo_crt = info->fb[0];
1649 struct fb_info *fbinfo_pnl = info->fb[1];
1651 device_remove_file(&pdev->dev, &dev_attr_fbregs_crt);
1652 device_remove_file(&pdev->dev, &dev_attr_fbregs_pnl);
1653 device_remove_file(&pdev->dev, &dev_attr_crt_src);
1655 unregister_framebuffer(fbinfo_crt);
1656 unregister_framebuffer(fbinfo_pnl);
1659 sm501fb_info_release(info);
1661 framebuffer_release(fbinfo_pnl);
1662 framebuffer_release(fbinfo_crt);
1669 static int sm501fb_suspend_fb(struct sm501fb_info *info,
1670 enum sm501_controller head)
1672 struct fb_info *fbi = info->fb[head];
1673 struct sm501fb_par *par = fbi->par;
1675 if (par->screen.size == 0)
1678 /* backup copies in case chip is powered down over suspend */
1680 par->store_fb = vmalloc(par->screen.size);
1681 if (par->store_fb == NULL) {
1682 dev_err(info->dev, "no memory to store screen\n");
1686 par->store_cursor = vmalloc(par->cursor.size);
1687 if (par->store_cursor == NULL) {
1688 dev_err(info->dev, "no memory to store cursor\n");
1692 dev_dbg(info->dev, "suspending screen to %p\n", par->store_fb);
1693 dev_dbg(info->dev, "suspending cursor to %p\n", par->store_cursor);
1695 memcpy_fromio(par->store_fb, par->screen.k_addr, par->screen.size);
1696 memcpy_fromio(par->store_cursor, par->cursor.k_addr, par->cursor.size);
1697 /* blank the relevant interface to ensure unit power minimised */
1698 (par->ops.fb_blank)(FB_BLANK_POWERDOWN, fbi);
1703 vfree(par->store_fb);
1704 par->store_fb = NULL;
1709 static void sm501fb_resume_fb(struct sm501fb_info *info,
1710 enum sm501_controller head)
1712 struct fb_info *fbi = info->fb[head];
1713 struct sm501fb_par *par = fbi->par;
1715 if (par->screen.size == 0)
1718 /* re-activate the configuration */
1720 (par->ops.fb_set_par)(fbi);
1722 /* restore the data */
1724 dev_dbg(info->dev, "restoring screen from %p\n", par->store_fb);
1725 dev_dbg(info->dev, "restoring cursor from %p\n", par->store_cursor);
1728 memcpy_toio(par->screen.k_addr, par->store_fb,
1731 if (par->store_cursor)
1732 memcpy_toio(par->cursor.k_addr, par->store_cursor,
1735 vfree(par->store_fb);
1736 vfree(par->store_cursor);
1740 /* suspend and resume support */
1742 static int sm501fb_suspend(struct platform_device *pdev, pm_message_t state)
1744 struct sm501fb_info *info = platform_get_drvdata(pdev);
1746 /* store crt control to resume with */
1747 info->pm_crt_ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1749 sm501fb_suspend_fb(info, HEAD_CRT);
1750 sm501fb_suspend_fb(info, HEAD_PANEL);
1752 /* turn off the clocks, in case the device is not powered down */
1753 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
1758 #define SM501_CRT_CTRL_SAVE (SM501_DC_CRT_CONTROL_TVP | \
1759 SM501_DC_CRT_CONTROL_SEL)
1762 static int sm501fb_resume(struct platform_device *pdev)
1764 struct sm501fb_info *info = platform_get_drvdata(pdev);
1765 unsigned long crt_ctrl;
1767 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 1);
1769 /* restore the items we want to be saved for crt control */
1771 crt_ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
1772 crt_ctrl &= ~SM501_CRT_CTRL_SAVE;
1773 crt_ctrl |= info->pm_crt_ctrl & SM501_CRT_CTRL_SAVE;
1774 writel(crt_ctrl, info->regs + SM501_DC_CRT_CONTROL);
1776 sm501fb_resume_fb(info, HEAD_CRT);
1777 sm501fb_resume_fb(info, HEAD_PANEL);
1783 #define sm501fb_suspend NULL
1784 #define sm501fb_resume NULL
1787 static struct platform_driver sm501fb_driver = {
1788 .probe = sm501fb_probe,
1789 .remove = sm501fb_remove,
1790 .suspend = sm501fb_suspend,
1791 .resume = sm501fb_resume,
1794 .owner = THIS_MODULE,
1798 static int __devinit sm501fb_init(void)
1800 return platform_driver_register(&sm501fb_driver);
1803 static void __exit sm501fb_cleanup(void)
1805 platform_driver_unregister(&sm501fb_driver);
1808 module_init(sm501fb_init);
1809 module_exit(sm501fb_cleanup);
1811 MODULE_AUTHOR("Ben Dooks, Vincent Sanders");
1812 MODULE_DESCRIPTION("SM501 Framebuffer driver");
1813 MODULE_LICENSE("GPL v2");