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>
31 #include <linux/console.h>
34 #include <asm/uaccess.h>
35 #include <asm/div64.h>
41 #include <linux/sm501.h>
42 #include <linux/sm501-regs.h>
44 #define NR_PALETTE 256
46 enum sm501_controller
{
51 /* SM501 memory address */
54 unsigned long sm_addr
;
58 /* private data that is shared between all frambuffers* */
61 struct fb_info
*fb
[2]; /* fb info for both heads */
62 struct resource
*fbmem_res
; /* framebuffer resource */
63 struct resource
*regs_res
; /* registers resource */
64 struct sm501_platdata_fb
*pdata
; /* our platform data */
66 unsigned long pm_crt_ctrl
; /* pm: crt ctrl save */
69 int swap_endian
; /* set to swap rgb=>bgr */
70 void __iomem
*regs
; /* remapped registers */
71 void __iomem
*fbmem
; /* remapped framebuffer */
72 size_t fbmem_len
; /* length of remapped region */
75 /* per-framebuffer private data */
77 u32 pseudo_palette
[16];
79 enum sm501_controller head
;
80 struct sm501_mem cursor
;
81 struct sm501_mem screen
;
86 void __iomem
*cursor_regs
;
87 struct sm501fb_info
*info
;
90 /* Helper functions */
92 static inline int h_total(struct fb_var_screeninfo
*var
)
94 return var
->xres
+ var
->left_margin
+
95 var
->right_margin
+ var
->hsync_len
;
98 static inline int v_total(struct fb_var_screeninfo
*var
)
100 return var
->yres
+ var
->upper_margin
+
101 var
->lower_margin
+ var
->vsync_len
;
104 /* sm501fb_sync_regs()
106 * This call is mainly for PCI bus systems where we need to
107 * ensure that any writes to the bus are completed before the
108 * next phase, or after completing a function.
111 static inline void sm501fb_sync_regs(struct sm501fb_info
*info
)
118 * This is an attempt to lay out memory for the two framebuffers and
121 * |fbmem_res->start fbmem_res->end|
123 * |fb[0].fix.smem_start | |fb[1].fix.smem_start | 2K |
124 * |-> fb[0].fix.smem_len <-| spare |-> fb[1].fix.smem_len <-|-> cursors <-|
126 * The "spare" space is for the 2d engine data
127 * the fixed is space for the cursors (2x1Kbyte)
129 * we need to allocate memory for the 2D acceleration engine
130 * command list and the data for the engine to deal with.
132 * - all allocations must be 128bit aligned
133 * - cursors are 64x64x2 bits (1Kbyte)
137 #define SM501_MEMF_CURSOR (1)
138 #define SM501_MEMF_PANEL (2)
139 #define SM501_MEMF_CRT (4)
140 #define SM501_MEMF_ACCEL (8)
142 static int sm501_alloc_mem(struct sm501fb_info
*inf
, struct sm501_mem
*mem
,
143 unsigned int why
, size_t size
)
145 unsigned int ptr
= 0;
148 case SM501_MEMF_CURSOR
:
149 ptr
= inf
->fbmem_len
- size
;
150 inf
->fbmem_len
= ptr
;
153 case SM501_MEMF_PANEL
:
154 ptr
= inf
->fbmem_len
- size
;
155 if (ptr
< inf
->fb
[0]->fix
.smem_len
)
164 case SM501_MEMF_ACCEL
:
165 ptr
= inf
->fb
[0]->fix
.smem_len
;
168 (inf
->fb
[1]->fix
.smem_start
- inf
->fbmem_res
->start
))
178 mem
->k_addr
= inf
->fbmem
+ ptr
;
180 dev_dbg(inf
->dev
, "%s: result %08lx, %p - %u, %zd\n",
181 __func__
, mem
->sm_addr
, mem
->k_addr
, why
, size
);
188 * Converts a period in picoseconds to Hz.
190 * Note, we try to keep this in Hz to minimise rounding with
191 * the limited PLL settings on the SM501.
194 static unsigned long sm501fb_ps_to_hz(unsigned long psvalue
)
196 unsigned long long numerator
=1000000000000ULL;
198 /* 10^12 / picosecond period gives frequency in Hz */
199 do_div(numerator
, psvalue
);
200 return (unsigned long)numerator
;
203 /* sm501fb_hz_to_ps is identical to the oposite transform */
205 #define sm501fb_hz_to_ps(x) sm501fb_ps_to_hz(x)
207 /* sm501fb_setup_gamma
209 * Programs a linear 1.0 gamma ramp in case the gamma
210 * correction is enabled without programming anything else.
213 static void sm501fb_setup_gamma(struct sm501fb_info
*fbi
,
214 unsigned long palette
)
216 unsigned long value
= 0;
219 /* set gamma values */
220 for (offset
= 0; offset
< 256 * 4; offset
+= 4) {
221 writel(value
, fbi
->regs
+ palette
+ offset
);
222 value
+= 0x010101; /* Advance RGB by 1,1,1.*/
228 * check common variables for both panel and crt
231 static int sm501fb_check_var(struct fb_var_screeninfo
*var
,
232 struct fb_info
*info
)
234 struct sm501fb_par
*par
= info
->par
;
235 struct sm501fb_info
*sm
= par
->info
;
238 /* check we can fit these values into the registers */
240 if (var
->hsync_len
> 255 || var
->vsync_len
> 255)
243 if ((var
->xres
+ var
->right_margin
) >= 4096)
246 if ((var
->yres
+ var
->lower_margin
) > 2048)
249 /* hard limits of device */
251 if (h_total(var
) > 4096 || v_total(var
) > 2048)
254 /* check our line length is going to be 128 bit aligned */
256 tmp
= (var
->xres
* var
->bits_per_pixel
) / 8;
260 /* check the virtual size */
262 if (var
->xres_virtual
> 4096 || var
->yres_virtual
> 2048)
265 /* can cope with 8,16 or 32bpp */
267 if (var
->bits_per_pixel
<= 8)
268 var
->bits_per_pixel
= 8;
269 else if (var
->bits_per_pixel
<= 16)
270 var
->bits_per_pixel
= 16;
271 else if (var
->bits_per_pixel
== 24)
272 var
->bits_per_pixel
= 32;
274 /* set r/g/b positions and validate bpp */
275 switch(var
->bits_per_pixel
) {
277 var
->red
.length
= var
->bits_per_pixel
;
279 var
->green
.length
= var
->bits_per_pixel
;
280 var
->green
.offset
= 0;
281 var
->blue
.length
= var
->bits_per_pixel
;
282 var
->blue
.offset
= 0;
283 var
->transp
.length
= 0;
288 if (sm
->pdata
->flags
& SM501_FBPD_SWAP_FB_ENDIAN
) {
289 var
->red
.offset
= 11;
290 var
->green
.offset
= 5;
291 var
->blue
.offset
= 0;
293 var
->blue
.offset
= 11;
294 var
->green
.offset
= 5;
299 var
->green
.length
= 6;
300 var
->blue
.length
= 5;
301 var
->transp
.length
= 0;
305 if (sm
->pdata
->flags
& SM501_FBPD_SWAP_FB_ENDIAN
) {
306 var
->transp
.offset
= 0;
308 var
->green
.offset
= 16;
309 var
->blue
.offset
= 24;
311 var
->transp
.offset
= 24;
312 var
->red
.offset
= 16;
313 var
->green
.offset
= 8;
314 var
->blue
.offset
= 0;
318 var
->green
.length
= 8;
319 var
->blue
.length
= 8;
320 var
->transp
.length
= 0;
331 * sm501fb_check_var_crt():
333 * check the parameters for the CRT head, and either bring them
334 * back into range, or return -EINVAL.
337 static int sm501fb_check_var_crt(struct fb_var_screeninfo
*var
,
338 struct fb_info
*info
)
340 return sm501fb_check_var(var
, info
);
343 /* sm501fb_check_var_pnl():
345 * check the parameters for the CRT head, and either bring them
346 * back into range, or return -EINVAL.
349 static int sm501fb_check_var_pnl(struct fb_var_screeninfo
*var
,
350 struct fb_info
*info
)
352 return sm501fb_check_var(var
, info
);
355 /* sm501fb_set_par_common
357 * set common registers for framebuffers
360 static int sm501fb_set_par_common(struct fb_info
*info
,
361 struct fb_var_screeninfo
*var
)
363 struct sm501fb_par
*par
= info
->par
;
364 struct sm501fb_info
*fbi
= par
->info
;
365 unsigned long pixclock
; /* pixelclock in Hz */
366 unsigned long sm501pixclock
; /* pixelclock the 501 can achive in Hz */
367 unsigned int mem_type
;
368 unsigned int clock_type
;
369 unsigned int head_addr
;
371 dev_dbg(fbi
->dev
, "%s: %dx%d, bpp = %d, virtual %dx%d\n",
372 __func__
, var
->xres
, var
->yres
, var
->bits_per_pixel
,
373 var
->xres_virtual
, var
->yres_virtual
);
377 mem_type
= SM501_MEMF_CRT
;
378 clock_type
= SM501_CLOCK_V2XCLK
;
379 head_addr
= SM501_DC_CRT_FB_ADDR
;
383 mem_type
= SM501_MEMF_PANEL
;
384 clock_type
= SM501_CLOCK_P2XCLK
;
385 head_addr
= SM501_DC_PANEL_FB_ADDR
;
389 mem_type
= 0; /* stop compiler warnings */
394 switch (var
->bits_per_pixel
) {
396 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
400 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
404 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
408 /* allocate fb memory within 501 */
409 info
->fix
.line_length
= (var
->xres_virtual
* var
->bits_per_pixel
)/8;
410 info
->fix
.smem_len
= info
->fix
.line_length
* var
->yres_virtual
;
412 dev_dbg(fbi
->dev
, "%s: line length = %u\n", __func__
,
413 info
->fix
.line_length
);
415 if (sm501_alloc_mem(fbi
, &par
->screen
, mem_type
,
416 info
->fix
.smem_len
)) {
417 dev_err(fbi
->dev
, "no memory available\n");
421 info
->fix
.smem_start
= fbi
->fbmem_res
->start
+ par
->screen
.sm_addr
;
423 info
->screen_base
= fbi
->fbmem
+ par
->screen
.sm_addr
;
424 info
->screen_size
= info
->fix
.smem_len
;
426 /* set start of framebuffer to the screen */
428 writel(par
->screen
.sm_addr
| SM501_ADDR_FLIP
, fbi
->regs
+ head_addr
);
430 /* program CRT clock */
432 pixclock
= sm501fb_ps_to_hz(var
->pixclock
);
434 sm501pixclock
= sm501_set_clock(fbi
->dev
->parent
, clock_type
,
437 /* update fb layer with actual clock used */
438 var
->pixclock
= sm501fb_hz_to_ps(sm501pixclock
);
440 dev_dbg(fbi
->dev
, "%s: pixclock(ps) = %u, pixclock(Hz) = %lu, "
441 "sm501pixclock = %lu, error = %ld%%\n",
442 __func__
, var
->pixclock
, pixclock
, sm501pixclock
,
443 ((pixclock
- sm501pixclock
)*100)/pixclock
);
448 /* sm501fb_set_par_geometry
450 * set the geometry registers for specified framebuffer.
453 static void sm501fb_set_par_geometry(struct fb_info
*info
,
454 struct fb_var_screeninfo
*var
)
456 struct sm501fb_par
*par
= info
->par
;
457 struct sm501fb_info
*fbi
= par
->info
;
458 void __iomem
*base
= fbi
->regs
;
461 if (par
->head
== HEAD_CRT
)
462 base
+= SM501_DC_CRT_H_TOT
;
464 base
+= SM501_DC_PANEL_H_TOT
;
466 /* set framebuffer width and display width */
468 reg
= info
->fix
.line_length
;
469 reg
|= ((var
->xres
* var
->bits_per_pixel
)/8) << 16;
471 writel(reg
, fbi
->regs
+ (par
->head
== HEAD_CRT
?
472 SM501_DC_CRT_FB_OFFSET
: SM501_DC_PANEL_FB_OFFSET
));
474 /* program horizontal total */
476 reg
= (h_total(var
) - 1) << 16;
477 reg
|= (var
->xres
- 1);
479 writel(reg
, base
+ SM501_OFF_DC_H_TOT
);
481 /* program horizontal sync */
483 reg
= var
->hsync_len
<< 16;
484 reg
|= var
->xres
+ var
->right_margin
- 1;
486 writel(reg
, base
+ SM501_OFF_DC_H_SYNC
);
488 /* program vertical total */
490 reg
= (v_total(var
) - 1) << 16;
491 reg
|= (var
->yres
- 1);
493 writel(reg
, base
+ SM501_OFF_DC_V_TOT
);
495 /* program vertical sync */
496 reg
= var
->vsync_len
<< 16;
497 reg
|= var
->yres
+ var
->lower_margin
- 1;
499 writel(reg
, base
+ SM501_OFF_DC_V_SYNC
);
504 * pan the CRT display output within an virtual framebuffer
507 static int sm501fb_pan_crt(struct fb_var_screeninfo
*var
,
508 struct fb_info
*info
)
510 struct sm501fb_par
*par
= info
->par
;
511 struct sm501fb_info
*fbi
= par
->info
;
512 unsigned int bytes_pixel
= var
->bits_per_pixel
/ 8;
516 xoffs
= var
->xoffset
* bytes_pixel
;
518 reg
= readl(fbi
->regs
+ SM501_DC_CRT_CONTROL
);
520 reg
&= ~SM501_DC_CRT_CONTROL_PIXEL_MASK
;
521 reg
|= ((xoffs
& 15) / bytes_pixel
) << 4;
522 writel(reg
, fbi
->regs
+ SM501_DC_CRT_CONTROL
);
524 reg
= (par
->screen
.sm_addr
+ xoffs
+
525 var
->yoffset
* info
->fix
.line_length
);
526 writel(reg
| SM501_ADDR_FLIP
, fbi
->regs
+ SM501_DC_CRT_FB_ADDR
);
528 sm501fb_sync_regs(fbi
);
534 * pan the panel display output within an virtual framebuffer
537 static int sm501fb_pan_pnl(struct fb_var_screeninfo
*var
,
538 struct fb_info
*info
)
540 struct sm501fb_par
*par
= info
->par
;
541 struct sm501fb_info
*fbi
= par
->info
;
544 reg
= var
->xoffset
| (var
->xres_virtual
<< 16);
545 writel(reg
, fbi
->regs
+ SM501_DC_PANEL_FB_WIDTH
);
547 reg
= var
->yoffset
| (var
->yres_virtual
<< 16);
548 writel(reg
, fbi
->regs
+ SM501_DC_PANEL_FB_HEIGHT
);
550 sm501fb_sync_regs(fbi
);
554 /* sm501fb_set_par_crt
556 * Set the CRT video mode from the fb_info structure
559 static int sm501fb_set_par_crt(struct fb_info
*info
)
561 struct sm501fb_par
*par
= info
->par
;
562 struct sm501fb_info
*fbi
= par
->info
;
563 struct fb_var_screeninfo
*var
= &info
->var
;
564 unsigned long control
; /* control register */
567 /* activate new configuration */
569 dev_dbg(fbi
->dev
, "%s(%p)\n", __func__
, info
);
571 /* enable CRT DAC - note 0 is on!*/
572 sm501_misc_control(fbi
->dev
->parent
, 0, SM501_MISC_DAC_POWER
);
574 control
= readl(fbi
->regs
+ SM501_DC_CRT_CONTROL
);
576 control
&= (SM501_DC_CRT_CONTROL_PIXEL_MASK
|
577 SM501_DC_CRT_CONTROL_GAMMA
|
578 SM501_DC_CRT_CONTROL_BLANK
|
579 SM501_DC_CRT_CONTROL_SEL
|
580 SM501_DC_CRT_CONTROL_CP
|
581 SM501_DC_CRT_CONTROL_TVP
);
583 /* set the sync polarities before we check data source */
585 if ((var
->sync
& FB_SYNC_HOR_HIGH_ACT
) == 0)
586 control
|= SM501_DC_CRT_CONTROL_HSP
;
588 if ((var
->sync
& FB_SYNC_VERT_HIGH_ACT
) == 0)
589 control
|= SM501_DC_CRT_CONTROL_VSP
;
591 if ((control
& SM501_DC_CRT_CONTROL_SEL
) == 0) {
592 /* the head is displaying panel data... */
594 sm501_alloc_mem(fbi
, &par
->screen
, SM501_MEMF_CRT
, 0);
598 ret
= sm501fb_set_par_common(info
, var
);
600 dev_err(fbi
->dev
, "failed to set common parameters\n");
604 sm501fb_pan_crt(var
, info
);
605 sm501fb_set_par_geometry(info
, var
);
607 control
|= SM501_FIFO_3
; /* fill if >3 free slots */
609 switch(var
->bits_per_pixel
) {
611 control
|= SM501_DC_CRT_CONTROL_8BPP
;
615 control
|= SM501_DC_CRT_CONTROL_16BPP
;
619 control
|= SM501_DC_CRT_CONTROL_32BPP
;
620 sm501fb_setup_gamma(fbi
, SM501_DC_CRT_PALETTE
);
627 control
|= SM501_DC_CRT_CONTROL_SEL
; /* CRT displays CRT data */
628 control
|= SM501_DC_CRT_CONTROL_TE
; /* enable CRT timing */
629 control
|= SM501_DC_CRT_CONTROL_ENABLE
; /* enable CRT plane */
632 dev_dbg(fbi
->dev
, "new control is %08lx\n", control
);
634 writel(control
, fbi
->regs
+ SM501_DC_CRT_CONTROL
);
635 sm501fb_sync_regs(fbi
);
640 static void sm501fb_panel_power(struct sm501fb_info
*fbi
, int to
)
642 unsigned long control
;
643 void __iomem
*ctrl_reg
= fbi
->regs
+ SM501_DC_PANEL_CONTROL
;
644 struct sm501_platdata_fbsub
*pd
= fbi
->pdata
->fb_pnl
;
646 control
= readl(ctrl_reg
);
648 if (to
&& (control
& SM501_DC_PANEL_CONTROL_VDD
) == 0) {
649 /* enable panel power */
651 control
|= SM501_DC_PANEL_CONTROL_VDD
; /* FPVDDEN */
652 writel(control
, ctrl_reg
);
653 sm501fb_sync_regs(fbi
);
656 control
|= SM501_DC_PANEL_CONTROL_DATA
; /* DATA */
657 writel(control
, ctrl_reg
);
658 sm501fb_sync_regs(fbi
);
661 if (pd
->flags
& SM501FB_FLAG_PANEL_USE_VBIASEN
) {
662 control
|= SM501_DC_PANEL_CONTROL_BIAS
; /* VBIASEN */
663 writel(control
, ctrl_reg
);
664 sm501fb_sync_regs(fbi
);
668 if (pd
->flags
& SM501FB_FLAG_PANEL_USE_FPEN
) {
669 control
|= SM501_DC_PANEL_CONTROL_FPEN
;
670 writel(control
, ctrl_reg
);
671 sm501fb_sync_regs(fbi
);
674 } else if (!to
&& (control
& SM501_DC_PANEL_CONTROL_VDD
) != 0) {
675 /* disable panel power */
676 if (pd
->flags
& SM501FB_FLAG_PANEL_USE_FPEN
) {
677 control
&= ~SM501_DC_PANEL_CONTROL_FPEN
;
678 writel(control
, ctrl_reg
);
679 sm501fb_sync_regs(fbi
);
683 if (pd
->flags
& SM501FB_FLAG_PANEL_USE_VBIASEN
) {
684 control
&= ~SM501_DC_PANEL_CONTROL_BIAS
;
685 writel(control
, ctrl_reg
);
686 sm501fb_sync_regs(fbi
);
690 control
&= ~SM501_DC_PANEL_CONTROL_DATA
;
691 writel(control
, ctrl_reg
);
692 sm501fb_sync_regs(fbi
);
695 control
&= ~SM501_DC_PANEL_CONTROL_VDD
;
696 writel(control
, ctrl_reg
);
697 sm501fb_sync_regs(fbi
);
701 sm501fb_sync_regs(fbi
);
704 /* sm501fb_set_par_pnl
706 * Set the panel video mode from the fb_info structure
709 static int sm501fb_set_par_pnl(struct fb_info
*info
)
711 struct sm501fb_par
*par
= info
->par
;
712 struct sm501fb_info
*fbi
= par
->info
;
713 struct fb_var_screeninfo
*var
= &info
->var
;
714 unsigned long control
;
718 dev_dbg(fbi
->dev
, "%s(%p)\n", __func__
, info
);
720 /* activate this new configuration */
722 ret
= sm501fb_set_par_common(info
, var
);
726 sm501fb_pan_pnl(var
, info
);
727 sm501fb_set_par_geometry(info
, var
);
729 /* update control register */
731 control
= readl(fbi
->regs
+ SM501_DC_PANEL_CONTROL
);
732 control
&= (SM501_DC_PANEL_CONTROL_GAMMA
|
733 SM501_DC_PANEL_CONTROL_VDD
|
734 SM501_DC_PANEL_CONTROL_DATA
|
735 SM501_DC_PANEL_CONTROL_BIAS
|
736 SM501_DC_PANEL_CONTROL_FPEN
|
737 SM501_DC_PANEL_CONTROL_CP
|
738 SM501_DC_PANEL_CONTROL_CK
|
739 SM501_DC_PANEL_CONTROL_HP
|
740 SM501_DC_PANEL_CONTROL_VP
|
741 SM501_DC_PANEL_CONTROL_HPD
|
742 SM501_DC_PANEL_CONTROL_VPD
);
744 control
|= SM501_FIFO_3
; /* fill if >3 free slots */
746 switch(var
->bits_per_pixel
) {
748 control
|= SM501_DC_PANEL_CONTROL_8BPP
;
752 control
|= SM501_DC_PANEL_CONTROL_16BPP
;
756 control
|= SM501_DC_PANEL_CONTROL_32BPP
;
757 sm501fb_setup_gamma(fbi
, SM501_DC_PANEL_PALETTE
);
764 writel(0x0, fbi
->regs
+ SM501_DC_PANEL_PANNING_CONTROL
);
766 /* panel plane top left and bottom right location */
768 writel(0x00, fbi
->regs
+ SM501_DC_PANEL_TL_LOC
);
771 reg
|= (var
->yres
- 1) << 16;
773 writel(reg
, fbi
->regs
+ SM501_DC_PANEL_BR_LOC
);
775 /* program panel control register */
777 control
|= SM501_DC_PANEL_CONTROL_TE
; /* enable PANEL timing */
778 control
|= SM501_DC_PANEL_CONTROL_EN
; /* enable PANEL gfx plane */
780 if ((var
->sync
& FB_SYNC_HOR_HIGH_ACT
) == 0)
781 control
|= SM501_DC_PANEL_CONTROL_HSP
;
783 if ((var
->sync
& FB_SYNC_VERT_HIGH_ACT
) == 0)
784 control
|= SM501_DC_PANEL_CONTROL_VSP
;
786 writel(control
, fbi
->regs
+ SM501_DC_PANEL_CONTROL
);
787 sm501fb_sync_regs(fbi
);
789 /* ensure the panel interface is not tristated at this point */
791 sm501_modify_reg(fbi
->dev
->parent
, SM501_SYSTEM_CONTROL
,
792 0, SM501_SYSCTRL_PANEL_TRISTATE
);
794 /* power the panel up */
795 sm501fb_panel_power(fbi
, 1);
802 * convert a colour value into a field position
807 static inline unsigned int chan_to_field(unsigned int chan
,
808 struct fb_bitfield
*bf
)
811 chan
>>= 16 - bf
->length
;
812 return chan
<< bf
->offset
;
817 * set the colour mapping for modes that support palettised data
820 static int sm501fb_setcolreg(unsigned regno
,
821 unsigned red
, unsigned green
, unsigned blue
,
822 unsigned transp
, struct fb_info
*info
)
824 struct sm501fb_par
*par
= info
->par
;
825 struct sm501fb_info
*fbi
= par
->info
;
826 void __iomem
*base
= fbi
->regs
;
829 if (par
->head
== HEAD_CRT
)
830 base
+= SM501_DC_CRT_PALETTE
;
832 base
+= SM501_DC_PANEL_PALETTE
;
834 switch (info
->fix
.visual
) {
835 case FB_VISUAL_TRUECOLOR
:
836 /* true-colour, use pseuo-palette */
839 u32
*pal
= par
->pseudo_palette
;
841 val
= chan_to_field(red
, &info
->var
.red
);
842 val
|= chan_to_field(green
, &info
->var
.green
);
843 val
|= chan_to_field(blue
, &info
->var
.blue
);
849 case FB_VISUAL_PSEUDOCOLOR
:
851 val
= (red
>> 8) << 16;
852 val
|= (green
>> 8) << 8;
855 writel(val
, base
+ (regno
* 4));
861 return 1; /* unknown type */
869 * Blank or un-blank the panel interface
872 static int sm501fb_blank_pnl(int blank_mode
, struct fb_info
*info
)
874 struct sm501fb_par
*par
= info
->par
;
875 struct sm501fb_info
*fbi
= par
->info
;
877 dev_dbg(fbi
->dev
, "%s(mode=%d, %p)\n", __func__
, blank_mode
, info
);
879 switch (blank_mode
) {
880 case FB_BLANK_POWERDOWN
:
881 sm501fb_panel_power(fbi
, 0);
884 case FB_BLANK_UNBLANK
:
885 sm501fb_panel_power(fbi
, 1);
888 case FB_BLANK_NORMAL
:
889 case FB_BLANK_VSYNC_SUSPEND
:
890 case FB_BLANK_HSYNC_SUSPEND
:
900 * Blank or un-blank the crt interface
903 static int sm501fb_blank_crt(int blank_mode
, struct fb_info
*info
)
905 struct sm501fb_par
*par
= info
->par
;
906 struct sm501fb_info
*fbi
= par
->info
;
909 dev_dbg(fbi
->dev
, "%s(mode=%d, %p)\n", __func__
, blank_mode
, info
);
911 ctrl
= readl(fbi
->regs
+ SM501_DC_CRT_CONTROL
);
913 switch (blank_mode
) {
914 case FB_BLANK_POWERDOWN
:
915 ctrl
&= ~SM501_DC_CRT_CONTROL_ENABLE
;
916 sm501_misc_control(fbi
->dev
->parent
, SM501_MISC_DAC_POWER
, 0);
918 case FB_BLANK_NORMAL
:
919 ctrl
|= SM501_DC_CRT_CONTROL_BLANK
;
922 case FB_BLANK_UNBLANK
:
923 ctrl
&= ~SM501_DC_CRT_CONTROL_BLANK
;
924 ctrl
|= SM501_DC_CRT_CONTROL_ENABLE
;
925 sm501_misc_control(fbi
->dev
->parent
, 0, SM501_MISC_DAC_POWER
);
928 case FB_BLANK_VSYNC_SUSPEND
:
929 case FB_BLANK_HSYNC_SUSPEND
:
935 writel(ctrl
, fbi
->regs
+ SM501_DC_CRT_CONTROL
);
936 sm501fb_sync_regs(fbi
);
943 * set or change the hardware cursor parameters
946 static int sm501fb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
948 struct sm501fb_par
*par
= info
->par
;
949 struct sm501fb_info
*fbi
= par
->info
;
950 void __iomem
*base
= fbi
->regs
;
951 unsigned long hwc_addr
;
952 unsigned long fg
, bg
;
954 dev_dbg(fbi
->dev
, "%s(%p,%p)\n", __func__
, info
, cursor
);
956 if (par
->head
== HEAD_CRT
)
957 base
+= SM501_DC_CRT_HWC_BASE
;
959 base
+= SM501_DC_PANEL_HWC_BASE
;
961 /* check not being asked to exceed capabilities */
963 if (cursor
->image
.width
> 64)
966 if (cursor
->image
.height
> 64)
969 if (cursor
->image
.depth
> 1)
972 hwc_addr
= readl(base
+ SM501_OFF_HWC_ADDR
);
975 writel(hwc_addr
| SM501_HWC_EN
, base
+ SM501_OFF_HWC_ADDR
);
977 writel(hwc_addr
& ~SM501_HWC_EN
, base
+ SM501_OFF_HWC_ADDR
);
980 if (cursor
->set
& FB_CUR_SETPOS
) {
981 unsigned int x
= cursor
->image
.dx
;
982 unsigned int y
= cursor
->image
.dy
;
984 if (x
>= 2048 || y
>= 2048 )
987 dev_dbg(fbi
->dev
, "set position %d,%d\n", x
, y
);
989 //y += cursor->image.height;
991 writel(x
| (y
<< 16), base
+ SM501_OFF_HWC_LOC
);
994 if (cursor
->set
& FB_CUR_SETCMAP
) {
995 unsigned int bg_col
= cursor
->image
.bg_color
;
996 unsigned int fg_col
= cursor
->image
.fg_color
;
998 dev_dbg(fbi
->dev
, "%s: update cmap (%08x,%08x)\n",
999 __func__
, bg_col
, fg_col
);
1001 bg
= ((info
->cmap
.red
[bg_col
] & 0xF8) << 8) |
1002 ((info
->cmap
.green
[bg_col
] & 0xFC) << 3) |
1003 ((info
->cmap
.blue
[bg_col
] & 0xF8) >> 3);
1005 fg
= ((info
->cmap
.red
[fg_col
] & 0xF8) << 8) |
1006 ((info
->cmap
.green
[fg_col
] & 0xFC) << 3) |
1007 ((info
->cmap
.blue
[fg_col
] & 0xF8) >> 3);
1009 dev_dbg(fbi
->dev
, "fgcol %08lx, bgcol %08lx\n", fg
, bg
);
1011 writel(bg
, base
+ SM501_OFF_HWC_COLOR_1_2
);
1012 writel(fg
, base
+ SM501_OFF_HWC_COLOR_3
);
1015 if (cursor
->set
& FB_CUR_SETSIZE
||
1016 cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
)) {
1017 /* SM501 cursor is a two bpp 64x64 bitmap this routine
1018 * clears it to transparent then combines the cursor
1019 * shape plane with the colour plane to set the
1022 const unsigned char *pcol
= cursor
->image
.data
;
1023 const unsigned char *pmsk
= cursor
->mask
;
1024 void __iomem
*dst
= par
->cursor
.k_addr
;
1025 unsigned char dcol
= 0;
1026 unsigned char dmsk
= 0;
1029 dev_dbg(fbi
->dev
, "%s: setting shape (%d,%d)\n",
1030 __func__
, cursor
->image
.width
, cursor
->image
.height
);
1032 for (op
= 0; op
< (64*64*2)/8; op
+=4)
1033 writel(0x0, dst
+ op
);
1035 for (y
= 0; y
< cursor
->image
.height
; y
++) {
1036 for (x
= 0; x
< cursor
->image
.width
; x
++) {
1046 op
= (dcol
& 1) ? 1 : 3;
1047 op
<<= ((x
% 4) * 2);
1049 op
|= readb(dst
+ (x
/ 4));
1050 writeb(op
, dst
+ (x
/ 4));
1057 sm501fb_sync_regs(fbi
); /* ensure cursor data flushed */
1061 /* sm501fb_crtsrc_show
1063 * device attribute code to show where the crt output is sourced from
1066 static ssize_t
sm501fb_crtsrc_show(struct device
*dev
,
1067 struct device_attribute
*attr
, char *buf
)
1069 struct sm501fb_info
*info
= dev_get_drvdata(dev
);
1072 ctrl
= readl(info
->regs
+ SM501_DC_CRT_CONTROL
);
1073 ctrl
&= SM501_DC_CRT_CONTROL_SEL
;
1075 return snprintf(buf
, PAGE_SIZE
, "%s\n", ctrl
? "crt" : "panel");
1078 /* sm501fb_crtsrc_show
1080 * device attribute code to set where the crt output is sourced from
1083 static ssize_t
sm501fb_crtsrc_store(struct device
*dev
,
1084 struct device_attribute
*attr
,
1085 const char *buf
, size_t len
)
1087 struct sm501fb_info
*info
= dev_get_drvdata(dev
);
1088 enum sm501_controller head
;
1094 if (strnicmp(buf
, "crt", 3) == 0)
1096 else if (strnicmp(buf
, "panel", 5) == 0)
1101 dev_info(dev
, "setting crt source to head %d\n", head
);
1103 ctrl
= readl(info
->regs
+ SM501_DC_CRT_CONTROL
);
1105 if (head
== HEAD_CRT
) {
1106 ctrl
|= SM501_DC_CRT_CONTROL_SEL
;
1107 ctrl
|= SM501_DC_CRT_CONTROL_ENABLE
;
1108 ctrl
|= SM501_DC_CRT_CONTROL_TE
;
1110 ctrl
&= ~SM501_DC_CRT_CONTROL_SEL
;
1111 ctrl
&= ~SM501_DC_CRT_CONTROL_ENABLE
;
1112 ctrl
&= ~SM501_DC_CRT_CONTROL_TE
;
1115 writel(ctrl
, info
->regs
+ SM501_DC_CRT_CONTROL
);
1116 sm501fb_sync_regs(info
);
1121 /* Prepare the device_attr for registration with sysfs later */
1122 static DEVICE_ATTR(crt_src
, 0666, sm501fb_crtsrc_show
, sm501fb_crtsrc_store
);
1124 /* sm501fb_show_regs
1126 * show the primary sm501 registers
1128 static int sm501fb_show_regs(struct sm501fb_info
*info
, char *ptr
,
1129 unsigned int start
, unsigned int len
)
1131 void __iomem
*mem
= info
->regs
;
1135 for (reg
= start
; reg
< (len
+ start
); reg
+= 4)
1136 ptr
+= sprintf(ptr
, "%08x = %08x\n", reg
, readl(mem
+ reg
));
1141 /* sm501fb_debug_show_crt
1143 * show the crt control and cursor registers
1146 static ssize_t
sm501fb_debug_show_crt(struct device
*dev
,
1147 struct device_attribute
*attr
, char *buf
)
1149 struct sm501fb_info
*info
= dev_get_drvdata(dev
);
1152 ptr
+= sm501fb_show_regs(info
, ptr
, SM501_DC_CRT_CONTROL
, 0x40);
1153 ptr
+= sm501fb_show_regs(info
, ptr
, SM501_DC_CRT_HWC_BASE
, 0x10);
1158 static DEVICE_ATTR(fbregs_crt
, 0444, sm501fb_debug_show_crt
, NULL
);
1160 /* sm501fb_debug_show_pnl
1162 * show the panel control and cursor registers
1165 static ssize_t
sm501fb_debug_show_pnl(struct device
*dev
,
1166 struct device_attribute
*attr
, char *buf
)
1168 struct sm501fb_info
*info
= dev_get_drvdata(dev
);
1171 ptr
+= sm501fb_show_regs(info
, ptr
, 0x0, 0x40);
1172 ptr
+= sm501fb_show_regs(info
, ptr
, SM501_DC_PANEL_HWC_BASE
, 0x10);
1177 static DEVICE_ATTR(fbregs_pnl
, 0444, sm501fb_debug_show_pnl
, NULL
);
1179 /* framebuffer ops */
1181 static struct fb_ops sm501fb_ops_crt
= {
1182 .owner
= THIS_MODULE
,
1183 .fb_check_var
= sm501fb_check_var_crt
,
1184 .fb_set_par
= sm501fb_set_par_crt
,
1185 .fb_blank
= sm501fb_blank_crt
,
1186 .fb_setcolreg
= sm501fb_setcolreg
,
1187 .fb_pan_display
= sm501fb_pan_crt
,
1188 .fb_cursor
= sm501fb_cursor
,
1189 .fb_fillrect
= cfb_fillrect
,
1190 .fb_copyarea
= cfb_copyarea
,
1191 .fb_imageblit
= cfb_imageblit
,
1194 static struct fb_ops sm501fb_ops_pnl
= {
1195 .owner
= THIS_MODULE
,
1196 .fb_check_var
= sm501fb_check_var_pnl
,
1197 .fb_set_par
= sm501fb_set_par_pnl
,
1198 .fb_pan_display
= sm501fb_pan_pnl
,
1199 .fb_blank
= sm501fb_blank_pnl
,
1200 .fb_setcolreg
= sm501fb_setcolreg
,
1201 .fb_cursor
= sm501fb_cursor
,
1202 .fb_fillrect
= cfb_fillrect
,
1203 .fb_copyarea
= cfb_copyarea
,
1204 .fb_imageblit
= cfb_imageblit
,
1207 /* sm501fb_info_alloc
1209 * creates and initialises an sm501fb_info structure
1212 static struct sm501fb_info
*sm501fb_info_alloc(struct fb_info
*fbinfo_crt
,
1213 struct fb_info
*fbinfo_pnl
)
1215 struct sm501fb_info
*info
;
1216 struct sm501fb_par
*par
;
1218 info
= kzalloc(sizeof(struct sm501fb_info
), GFP_KERNEL
);
1220 /* set the references back */
1222 par
= fbinfo_crt
->par
;
1224 par
->head
= HEAD_CRT
;
1225 fbinfo_crt
->pseudo_palette
= &par
->pseudo_palette
;
1227 par
= fbinfo_pnl
->par
;
1229 par
->head
= HEAD_PANEL
;
1230 fbinfo_pnl
->pseudo_palette
= &par
->pseudo_palette
;
1232 /* store the two fbs into our info */
1233 info
->fb
[HEAD_CRT
] = fbinfo_crt
;
1234 info
->fb
[HEAD_PANEL
] = fbinfo_pnl
;
1240 /* sm501_init_cursor
1242 * initialise hw cursor parameters
1245 static int sm501_init_cursor(struct fb_info
*fbi
, unsigned int reg_base
)
1247 struct sm501fb_par
*par
= fbi
->par
;
1248 struct sm501fb_info
*info
= par
->info
;
1251 par
->cursor_regs
= info
->regs
+ reg_base
;
1253 ret
= sm501_alloc_mem(info
, &par
->cursor
, SM501_MEMF_CURSOR
, 1024);
1257 /* initialise the colour registers */
1259 writel(par
->cursor
.sm_addr
, par
->cursor_regs
+ SM501_OFF_HWC_ADDR
);
1261 writel(0x00, par
->cursor_regs
+ SM501_OFF_HWC_LOC
);
1262 writel(0x00, par
->cursor_regs
+ SM501_OFF_HWC_COLOR_1_2
);
1263 writel(0x00, par
->cursor_regs
+ SM501_OFF_HWC_COLOR_3
);
1264 sm501fb_sync_regs(info
);
1269 /* sm501fb_info_start
1271 * fills the par structure claiming resources and remapping etc.
1274 static int sm501fb_start(struct sm501fb_info
*info
,
1275 struct platform_device
*pdev
)
1277 struct resource
*res
;
1282 info
->dev
= dev
= &pdev
->dev
;
1283 platform_set_drvdata(pdev
, info
);
1285 info
->irq
= ret
= platform_get_irq(pdev
, 0);
1287 /* we currently do not use the IRQ */
1288 dev_warn(dev
, "no irq for device\n");
1291 /* allocate, reserve and remap resources for registers */
1292 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1294 dev_err(dev
, "no resource definition for registers\n");
1299 info
->regs_res
= request_mem_region(res
->start
,
1300 res
->end
- res
->start
,
1303 if (info
->regs_res
== NULL
) {
1304 dev_err(dev
, "cannot claim registers\n");
1309 info
->regs
= ioremap(res
->start
, (res
->end
- res
->start
)+1);
1310 if (info
->regs
== NULL
) {
1311 dev_err(dev
, "cannot remap registers\n");
1316 /* allocate, reserve resources for framebuffer */
1317 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 2);
1319 dev_err(dev
, "no memory resource defined\n");
1324 info
->fbmem_res
= request_mem_region(res
->start
,
1325 (res
->end
- res
->start
)+1,
1327 if (info
->fbmem_res
== NULL
) {
1328 dev_err(dev
, "cannot claim framebuffer\n");
1333 info
->fbmem
= ioremap(res
->start
, (res
->end
- res
->start
)+1);
1334 if (info
->fbmem
== NULL
) {
1335 dev_err(dev
, "cannot remap framebuffer\n");
1339 info
->fbmem_len
= (res
->end
- res
->start
)+1;
1341 /* clear framebuffer memory - avoids garbage data on unused fb */
1342 memset(info
->fbmem
, 0, info
->fbmem_len
);
1344 /* clear palette ram - undefined at power on */
1345 for (k
= 0; k
< (256 * 3); k
++)
1346 writel(0, info
->regs
+ SM501_DC_PANEL_PALETTE
+ (k
* 4));
1348 /* enable display controller */
1349 sm501_unit_power(dev
->parent
, SM501_GATE_DISPLAY
, 1);
1353 sm501_init_cursor(info
->fb
[HEAD_CRT
], SM501_DC_CRT_HWC_ADDR
);
1354 sm501_init_cursor(info
->fb
[HEAD_PANEL
], SM501_DC_PANEL_HWC_ADDR
);
1356 return 0; /* everything is setup */
1359 release_resource(info
->fbmem_res
);
1360 kfree(info
->fbmem_res
);
1363 iounmap(info
->regs
);
1366 release_resource(info
->regs_res
);
1367 kfree(info
->regs_res
);
1373 static void sm501fb_stop(struct sm501fb_info
*info
)
1375 /* disable display controller */
1376 sm501_unit_power(info
->dev
->parent
, SM501_GATE_DISPLAY
, 0);
1378 iounmap(info
->fbmem
);
1379 release_resource(info
->fbmem_res
);
1380 kfree(info
->fbmem_res
);
1382 iounmap(info
->regs
);
1383 release_resource(info
->regs_res
);
1384 kfree(info
->regs_res
);
1387 static void sm501fb_info_release(struct sm501fb_info
*info
)
1392 static int sm501fb_init_fb(struct fb_info
*fb
,
1393 enum sm501_controller head
,
1396 struct sm501_platdata_fbsub
*pd
;
1397 struct sm501fb_par
*par
= fb
->par
;
1398 struct sm501fb_info
*info
= par
->info
;
1400 unsigned int enable
;
1405 pd
= info
->pdata
->fb_crt
;
1406 ctrl
= readl(info
->regs
+ SM501_DC_CRT_CONTROL
);
1407 enable
= (ctrl
& SM501_DC_CRT_CONTROL_ENABLE
) ? 1 : 0;
1409 /* ensure we set the correct source register */
1410 if (info
->pdata
->fb_route
!= SM501_FB_CRT_PANEL
) {
1411 ctrl
|= SM501_DC_CRT_CONTROL_SEL
;
1412 writel(ctrl
, info
->regs
+ SM501_DC_CRT_CONTROL
);
1418 pd
= info
->pdata
->fb_pnl
;
1419 ctrl
= readl(info
->regs
+ SM501_DC_PANEL_CONTROL
);
1420 enable
= (ctrl
& SM501_DC_PANEL_CONTROL_EN
) ? 1 : 0;
1424 pd
= NULL
; /* stop compiler warnings */
1430 dev_info(info
->dev
, "fb %s %sabled at start\n",
1431 fbname
, enable
? "en" : "dis");
1433 /* check to see if our routing allows this */
1435 if (head
== HEAD_CRT
&& info
->pdata
->fb_route
== SM501_FB_CRT_PANEL
) {
1436 ctrl
&= ~SM501_DC_CRT_CONTROL_SEL
;
1437 writel(ctrl
, info
->regs
+ SM501_DC_CRT_CONTROL
);
1441 strlcpy(fb
->fix
.id
, fbname
, sizeof(fb
->fix
.id
));
1444 (head
== HEAD_CRT
) ? &sm501fb_ops_crt
: &sm501fb_ops_pnl
,
1445 sizeof(struct fb_ops
));
1447 /* update ops dependant on what we've been passed */
1449 if ((pd
->flags
& SM501FB_FLAG_USE_HWCURSOR
) == 0)
1450 par
->ops
.fb_cursor
= NULL
;
1452 fb
->fbops
= &par
->ops
;
1453 fb
->flags
= FBINFO_FLAG_DEFAULT
|
1454 FBINFO_HWACCEL_XPAN
| FBINFO_HWACCEL_YPAN
;
1458 fb
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1459 fb
->fix
.type_aux
= 0;
1460 fb
->fix
.xpanstep
= 1;
1461 fb
->fix
.ypanstep
= 1;
1462 fb
->fix
.ywrapstep
= 0;
1463 fb
->fix
.accel
= FB_ACCEL_NONE
;
1468 fb
->var
.activate
= FB_ACTIVATE_NOW
;
1469 fb
->var
.accel_flags
= 0;
1470 fb
->var
.vmode
= FB_VMODE_NONINTERLACED
;
1471 fb
->var
.bits_per_pixel
= 16;
1473 if (enable
&& (pd
->flags
& SM501FB_FLAG_USE_INIT_MODE
) && 0) {
1474 /* TODO read the mode from the current display */
1478 dev_info(info
->dev
, "using supplied mode\n");
1479 fb_videomode_to_var(&fb
->var
, pd
->def_mode
);
1481 fb
->var
.bits_per_pixel
= pd
->def_bpp
? pd
->def_bpp
: 8;
1482 fb
->var
.xres_virtual
= fb
->var
.xres
;
1483 fb
->var
.yres_virtual
= fb
->var
.yres
;
1485 ret
= fb_find_mode(&fb
->var
, fb
,
1486 NULL
, NULL
, 0, NULL
, 8);
1488 if (ret
== 0 || ret
== 4) {
1490 "failed to get initial mode\n");
1496 /* initialise and set the palette */
1497 fb_alloc_cmap(&fb
->cmap
, NR_PALETTE
, 0);
1498 fb_set_cmap(&fb
->cmap
, fb
);
1500 ret
= (fb
->fbops
->fb_check_var
)(&fb
->var
, fb
);
1502 dev_err(info
->dev
, "check_var() failed on initial setup?\n");
1504 /* ensure we've activated our new configuration */
1505 (fb
->fbops
->fb_set_par
)(fb
);
1510 /* default platform data if none is supplied (ie, PCI device) */
1512 static struct sm501_platdata_fbsub sm501fb_pdata_crt
= {
1513 .flags
= (SM501FB_FLAG_USE_INIT_MODE
|
1514 SM501FB_FLAG_USE_HWCURSOR
|
1515 SM501FB_FLAG_USE_HWACCEL
|
1516 SM501FB_FLAG_DISABLE_AT_EXIT
),
1520 static struct sm501_platdata_fbsub sm501fb_pdata_pnl
= {
1521 .flags
= (SM501FB_FLAG_USE_INIT_MODE
|
1522 SM501FB_FLAG_USE_HWCURSOR
|
1523 SM501FB_FLAG_USE_HWACCEL
|
1524 SM501FB_FLAG_DISABLE_AT_EXIT
),
1527 static struct sm501_platdata_fb sm501fb_def_pdata
= {
1528 .fb_route
= SM501_FB_OWN
,
1529 .fb_crt
= &sm501fb_pdata_crt
,
1530 .fb_pnl
= &sm501fb_pdata_pnl
,
1533 static char driver_name_crt
[] = "sm501fb-crt";
1534 static char driver_name_pnl
[] = "sm501fb-panel";
1536 static int __init
sm501fb_probe(struct platform_device
*pdev
)
1538 struct sm501fb_info
*info
;
1539 struct device
*dev
= &pdev
->dev
;
1540 struct fb_info
*fbinfo_crt
;
1541 struct fb_info
*fbinfo_pnl
;
1544 /* allocate our framebuffers */
1546 fbinfo_crt
= framebuffer_alloc(sizeof(struct sm501fb_par
), dev
);
1547 if (fbinfo_crt
== NULL
) {
1548 dev_err(dev
, "cannot allocate crt framebuffer\n");
1552 fbinfo_pnl
= framebuffer_alloc(sizeof(struct sm501fb_par
), dev
);
1553 if (fbinfo_pnl
== NULL
) {
1554 dev_err(dev
, "cannot allocate panel framebuffer\n");
1556 goto fbinfo_crt_alloc_fail
;
1559 info
= sm501fb_info_alloc(fbinfo_crt
, fbinfo_pnl
);
1561 dev_err(dev
, "cannot allocate par\n");
1563 goto sm501fb_alloc_fail
;
1566 if (dev
->parent
->platform_data
) {
1567 struct sm501_platdata
*pd
= dev
->parent
->platform_data
;
1568 info
->pdata
= pd
->fb
;
1571 if (info
->pdata
== NULL
) {
1572 dev_info(dev
, "using default configuration data\n");
1573 info
->pdata
= &sm501fb_def_pdata
;
1576 /* start the framebuffers */
1578 ret
= sm501fb_start(info
, pdev
);
1580 dev_err(dev
, "cannot initialise SM501\n");
1581 goto sm501fb_start_fail
;
1584 /* CRT framebuffer setup */
1586 ret
= sm501fb_init_fb(fbinfo_crt
, HEAD_CRT
, driver_name_crt
);
1588 dev_err(dev
, "cannot initialise CRT fb\n");
1589 goto sm501fb_start_fail
;
1592 /* Panel framebuffer setup */
1594 ret
= sm501fb_init_fb(fbinfo_pnl
, HEAD_PANEL
, driver_name_pnl
);
1596 dev_err(dev
, "cannot initialise Panel fb\n");
1597 goto sm501fb_start_fail
;
1600 /* register framebuffers */
1602 ret
= register_framebuffer(fbinfo_crt
);
1604 dev_err(dev
, "failed to register CRT fb (%d)\n", ret
);
1605 goto register_crt_fail
;
1608 ret
= register_framebuffer(fbinfo_pnl
);
1610 dev_err(dev
, "failed to register panel fb (%d)\n", ret
);
1611 goto register_pnl_fail
;
1614 dev_info(dev
, "fb%d: %s frame buffer device\n",
1615 fbinfo_crt
->node
, fbinfo_crt
->fix
.id
);
1617 dev_info(dev
, "fb%d: %s frame buffer device\n",
1618 fbinfo_pnl
->node
, fbinfo_pnl
->fix
.id
);
1620 /* create device files */
1622 ret
= device_create_file(dev
, &dev_attr_crt_src
);
1626 ret
= device_create_file(dev
, &dev_attr_fbregs_pnl
);
1628 goto fbregs_pnl_fail
;
1630 ret
= device_create_file(dev
, &dev_attr_fbregs_crt
);
1632 goto fbregs_crt_fail
;
1634 /* we registered, return ok */
1638 device_remove_file(dev
, &dev_attr_fbregs_pnl
);
1641 device_remove_file(dev
, &dev_attr_crt_src
);
1644 unregister_framebuffer(fbinfo_pnl
);
1647 unregister_framebuffer(fbinfo_crt
);
1653 sm501fb_info_release(info
);
1656 framebuffer_release(fbinfo_pnl
);
1658 fbinfo_crt_alloc_fail
:
1659 framebuffer_release(fbinfo_crt
);
1668 static int sm501fb_remove(struct platform_device
*pdev
)
1670 struct sm501fb_info
*info
= platform_get_drvdata(pdev
);
1671 struct fb_info
*fbinfo_crt
= info
->fb
[0];
1672 struct fb_info
*fbinfo_pnl
= info
->fb
[1];
1674 device_remove_file(&pdev
->dev
, &dev_attr_fbregs_crt
);
1675 device_remove_file(&pdev
->dev
, &dev_attr_fbregs_pnl
);
1676 device_remove_file(&pdev
->dev
, &dev_attr_crt_src
);
1678 unregister_framebuffer(fbinfo_crt
);
1679 unregister_framebuffer(fbinfo_pnl
);
1682 sm501fb_info_release(info
);
1684 framebuffer_release(fbinfo_pnl
);
1685 framebuffer_release(fbinfo_crt
);
1692 static int sm501fb_suspend_fb(struct sm501fb_info
*info
,
1693 enum sm501_controller head
)
1695 struct fb_info
*fbi
= info
->fb
[head
];
1696 struct sm501fb_par
*par
= fbi
->par
;
1698 if (par
->screen
.size
== 0)
1701 /* blank the relevant interface to ensure unit power minimised */
1702 (par
->ops
.fb_blank
)(FB_BLANK_POWERDOWN
, fbi
);
1704 /* tell console/fb driver we are suspending */
1706 acquire_console_sem();
1707 fb_set_suspend(fbi
, 1);
1708 release_console_sem();
1710 /* backup copies in case chip is powered down over suspend */
1712 par
->store_fb
= vmalloc(par
->screen
.size
);
1713 if (par
->store_fb
== NULL
) {
1714 dev_err(info
->dev
, "no memory to store screen\n");
1718 par
->store_cursor
= vmalloc(par
->cursor
.size
);
1719 if (par
->store_cursor
== NULL
) {
1720 dev_err(info
->dev
, "no memory to store cursor\n");
1724 dev_dbg(info
->dev
, "suspending screen to %p\n", par
->store_fb
);
1725 dev_dbg(info
->dev
, "suspending cursor to %p\n", par
->store_cursor
);
1727 memcpy_fromio(par
->store_fb
, par
->screen
.k_addr
, par
->screen
.size
);
1728 memcpy_fromio(par
->store_cursor
, par
->cursor
.k_addr
, par
->cursor
.size
);
1733 vfree(par
->store_fb
);
1734 par
->store_fb
= NULL
;
1739 static void sm501fb_resume_fb(struct sm501fb_info
*info
,
1740 enum sm501_controller head
)
1742 struct fb_info
*fbi
= info
->fb
[head
];
1743 struct sm501fb_par
*par
= fbi
->par
;
1745 if (par
->screen
.size
== 0)
1748 /* re-activate the configuration */
1750 (par
->ops
.fb_set_par
)(fbi
);
1752 /* restore the data */
1754 dev_dbg(info
->dev
, "restoring screen from %p\n", par
->store_fb
);
1755 dev_dbg(info
->dev
, "restoring cursor from %p\n", par
->store_cursor
);
1758 memcpy_toio(par
->screen
.k_addr
, par
->store_fb
,
1761 if (par
->store_cursor
)
1762 memcpy_toio(par
->cursor
.k_addr
, par
->store_cursor
,
1765 acquire_console_sem();
1766 fb_set_suspend(fbi
, 0);
1767 release_console_sem();
1769 vfree(par
->store_fb
);
1770 vfree(par
->store_cursor
);
1774 /* suspend and resume support */
1776 static int sm501fb_suspend(struct platform_device
*pdev
, pm_message_t state
)
1778 struct sm501fb_info
*info
= platform_get_drvdata(pdev
);
1780 /* store crt control to resume with */
1781 info
->pm_crt_ctrl
= readl(info
->regs
+ SM501_DC_CRT_CONTROL
);
1783 sm501fb_suspend_fb(info
, HEAD_CRT
);
1784 sm501fb_suspend_fb(info
, HEAD_PANEL
);
1786 /* turn off the clocks, in case the device is not powered down */
1787 sm501_unit_power(info
->dev
->parent
, SM501_GATE_DISPLAY
, 0);
1792 #define SM501_CRT_CTRL_SAVE (SM501_DC_CRT_CONTROL_TVP | \
1793 SM501_DC_CRT_CONTROL_SEL)
1796 static int sm501fb_resume(struct platform_device
*pdev
)
1798 struct sm501fb_info
*info
= platform_get_drvdata(pdev
);
1799 unsigned long crt_ctrl
;
1801 sm501_unit_power(info
->dev
->parent
, SM501_GATE_DISPLAY
, 1);
1803 /* restore the items we want to be saved for crt control */
1805 crt_ctrl
= readl(info
->regs
+ SM501_DC_CRT_CONTROL
);
1806 crt_ctrl
&= ~SM501_CRT_CTRL_SAVE
;
1807 crt_ctrl
|= info
->pm_crt_ctrl
& SM501_CRT_CTRL_SAVE
;
1808 writel(crt_ctrl
, info
->regs
+ SM501_DC_CRT_CONTROL
);
1810 sm501fb_resume_fb(info
, HEAD_CRT
);
1811 sm501fb_resume_fb(info
, HEAD_PANEL
);
1817 #define sm501fb_suspend NULL
1818 #define sm501fb_resume NULL
1821 static struct platform_driver sm501fb_driver
= {
1822 .probe
= sm501fb_probe
,
1823 .remove
= sm501fb_remove
,
1824 .suspend
= sm501fb_suspend
,
1825 .resume
= sm501fb_resume
,
1828 .owner
= THIS_MODULE
,
1832 static int __devinit
sm501fb_init(void)
1834 return platform_driver_register(&sm501fb_driver
);
1837 static void __exit
sm501fb_cleanup(void)
1839 platform_driver_unregister(&sm501fb_driver
);
1842 module_init(sm501fb_init
);
1843 module_exit(sm501fb_cleanup
);
1845 MODULE_AUTHOR("Ben Dooks, Vincent Sanders");
1846 MODULE_DESCRIPTION("SM501 Framebuffer driver");
1847 MODULE_LICENSE("GPL v2");