2 * Silicon Motion SM7XX frame buffer device
4 * Copyright (C) 2006 Silicon Motion Technology Corp.
5 * Authors: Ge Wang, gewang@siliconmotion.com
6 * Boyod boyod.yang@siliconmotion.com.cn
8 * Copyright (C) 2009 Lemote, Inc.
9 * Author: Wu Zhangjin, wuzhangjin@gmail.com
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive for
15 * Version 0.10.26192.21.01
16 * - Add PowerPC/Big endian support
17 * - Verified on 2.6.19.2
18 * Boyod.yang <boyod.yang@siliconmotion.com.cn>
20 * Version 0.09.2621.00.01
21 * - Only support Linux Kernel's version 2.6.21
22 * Boyod.yang <boyod.yang@siliconmotion.com.cn>
25 * - Only support Linux Kernel's version 2.6.12
26 * Boyod.yang <boyod.yang@siliconmotion.com.cn>
31 #include <linux/pci.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/uaccess.h>
35 #include <linux/console.h>
36 #include <linux/screen_info.h>
42 struct screen_info smtc_screen_info
;
47 #define smdbg(format, arg...) printk(KERN_DEBUG format , ## arg)
49 #define smdbg(format, arg...)
57 * The following is a pointer to be passed into the
58 * functions below. The modules outside the main
59 * voyager.c driver have no knowledge as to what
60 * is within this structure.
63 struct display_switch
*dispsw
;
79 unsigned char __iomem
*m_pMMIO
;
88 u_long BaseAddressInVRAM
;
92 struct vesa_mode_table
{
99 static struct vesa_mode_table vesa_mode
[] = {
100 {"0x301", 640, 480, 8},
101 {"0x303", 800, 600, 8},
102 {"0x305", 1024, 768, 8},
103 {"0x307", 1280, 1024, 8},
105 {"0x311", 640, 480, 16},
106 {"0x314", 800, 600, 16},
107 {"0x317", 1024, 768, 16},
108 {"0x31A", 1280, 1024, 16},
110 {"0x312", 640, 480, 24},
111 {"0x315", 800, 600, 24},
112 {"0x318", 1024, 768, 24},
113 {"0x31B", 1280, 1024, 24},
116 char __iomem
*smtc_RegBaseAddress
; /* Memory Map IO starting address */
117 char __iomem
*smtc_VRAMBaseAddress
; /* video memory starting address */
119 static u32 colreg
[17];
120 static struct par_info hw
; /* hardware information */
122 u16 smtc_ChipIDs
[] = {
128 #define numSMTCchipIDs (sizeof(smtc_ChipIDs) / sizeof(u16))
130 static void sm712_set_timing(struct smtcfb_info
*sfb
,
131 struct par_info
*ppar_info
)
136 smdbg("\nppar_info->width = %d ppar_info->height = %d"
137 "sfb->fb.var.bits_per_pixel = %d ppar_info->hz = %d\n",
138 ppar_info
->width
, ppar_info
->height
,
139 sfb
->fb
.var
.bits_per_pixel
, ppar_info
->hz
);
141 for (j
= 0; j
< numVGAModes
; j
++) {
142 if (VGAMode
[j
].mmSizeX
== ppar_info
->width
&&
143 VGAMode
[j
].mmSizeY
== ppar_info
->height
&&
144 VGAMode
[j
].bpp
== sfb
->fb
.var
.bits_per_pixel
&&
145 VGAMode
[j
].hz
== ppar_info
->hz
) {
147 smdbg("\nVGAMode[j].mmSizeX = %d VGAMode[j].mmSizeY ="
148 "%d VGAMode[j].bpp = %d"
149 "VGAMode[j].hz=%d\n",
150 VGAMode
[j
].mmSizeX
, VGAMode
[j
].mmSizeY
,
151 VGAMode
[j
].bpp
, VGAMode
[j
].hz
);
153 smdbg("VGAMode index=%d\n", j
);
155 smtc_mmiowb(0x0, 0x3c6);
159 smtc_mmiowb(VGAMode
[j
].Init_MISC
, 0x3c2);
161 /* init SEQ register SR00 - SR04 */
162 for (i
= 0; i
< SIZE_SR00_SR04
; i
++)
163 smtc_seqw(i
, VGAMode
[j
].Init_SR00_SR04
[i
]);
165 /* init SEQ register SR10 - SR24 */
166 for (i
= 0; i
< SIZE_SR10_SR24
; i
++)
168 VGAMode
[j
].Init_SR10_SR24
[i
]);
170 /* init SEQ register SR30 - SR75 */
171 for (i
= 0; i
< SIZE_SR30_SR75
; i
++)
172 if (((i
+ 0x30) != 0x62) \
173 && ((i
+ 0x30) != 0x6a) \
174 && ((i
+ 0x30) != 0x6b))
176 VGAMode
[j
].Init_SR30_SR75
[i
]);
178 /* init SEQ register SR80 - SR93 */
179 for (i
= 0; i
< SIZE_SR80_SR93
; i
++)
181 VGAMode
[j
].Init_SR80_SR93
[i
]);
183 /* init SEQ register SRA0 - SRAF */
184 for (i
= 0; i
< SIZE_SRA0_SRAF
; i
++)
186 VGAMode
[j
].Init_SRA0_SRAF
[i
]);
188 /* init Graphic register GR00 - GR08 */
189 for (i
= 0; i
< SIZE_GR00_GR08
; i
++)
190 smtc_grphw(i
, VGAMode
[j
].Init_GR00_GR08
[i
]);
192 /* init Attribute register AR00 - AR14 */
193 for (i
= 0; i
< SIZE_AR00_AR14
; i
++)
194 smtc_attrw(i
, VGAMode
[j
].Init_AR00_AR14
[i
]);
196 /* init CRTC register CR00 - CR18 */
197 for (i
= 0; i
< SIZE_CR00_CR18
; i
++)
198 smtc_crtcw(i
, VGAMode
[j
].Init_CR00_CR18
[i
]);
200 /* init CRTC register CR30 - CR4D */
201 for (i
= 0; i
< SIZE_CR30_CR4D
; i
++)
203 VGAMode
[j
].Init_CR30_CR4D
[i
]);
205 /* init CRTC register CR90 - CRA7 */
206 for (i
= 0; i
< SIZE_CR90_CRA7
; i
++)
208 VGAMode
[j
].Init_CR90_CRA7
[i
]);
211 smtc_mmiowb(0x67, 0x3c2);
213 /* set VPR registers */
214 writel(0x0, ppar_info
->m_pVPR
+ 0x0C);
215 writel(0x0, ppar_info
->m_pVPR
+ 0x40);
219 (ppar_info
->width
* sfb
->fb
.var
.bits_per_pixel
) / 64;
220 switch (sfb
->fb
.var
.bits_per_pixel
) {
222 writel(0x0, ppar_info
->m_pVPR
+ 0x0);
225 writel(0x00020000, ppar_info
->m_pVPR
+ 0x0);
228 writel(0x00040000, ppar_info
->m_pVPR
+ 0x0);
231 writel(0x00030000, ppar_info
->m_pVPR
+ 0x0);
234 writel((u32
) (((m_nScreenStride
+ 2) << 16) | m_nScreenStride
),
235 ppar_info
->m_pVPR
+ 0x10);
239 static void sm712_setpalette(int regno
, unsigned red
, unsigned green
,
240 unsigned blue
, struct fb_info
*info
)
242 struct par_info
*cur_par
= (struct par_info
*)info
->par
;
244 if (cur_par
->BaseAddressInVRAM
)
246 * second display palette for dual head. Enable CRT RAM, 6-bit
249 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x20);
251 /* primary display palette. Enable LCD RAM only, 6-bit RAM */
252 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x10);
253 smtc_mmiowb(regno
, dac_reg
);
254 smtc_mmiowb(red
>> 10, dac_val
);
255 smtc_mmiowb(green
>> 10, dac_val
);
256 smtc_mmiowb(blue
>> 10, dac_val
);
259 static void smtc_set_timing(struct smtcfb_info
*sfb
, struct par_info
262 switch (ppar_info
->chipID
) {
266 sm712_set_timing(sfb
, ppar_info
);
271 static struct fb_var_screeninfo smtcfb_var
= {
274 .xres_virtual
= 1024,
276 .bits_per_pixel
= 16,
280 .activate
= FB_ACTIVATE_NOW
,
283 .vmode
= FB_VMODE_NONINTERLACED
,
286 static struct fb_fix_screeninfo smtcfb_fix
= {
288 .type
= FB_TYPE_PACKED_PIXELS
,
289 .visual
= FB_VISUAL_TRUECOLOR
,
290 .line_length
= 800 * 3,
291 .accel
= FB_ACCEL_SMI_LYNX
,
296 * convert a colour value into a field position
301 static inline unsigned int chan_to_field(unsigned int chan
,
302 struct fb_bitfield
*bf
)
305 chan
>>= 16 - bf
->length
;
306 return chan
<< bf
->offset
;
309 static int cfb_blank(int blank_mode
, struct fb_info
*info
)
311 /* clear DPMS setting */
312 switch (blank_mode
) {
313 case FB_BLANK_UNBLANK
:
314 /* Screen On: HSync: On, VSync : On */
315 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
316 smtc_seqw(0x6a, 0x16);
317 smtc_seqw(0x6b, 0x02);
318 smtc_seqw(0x21, (smtc_seqr(0x21) & 0x77));
319 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
320 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
321 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
322 smtc_seqw(0x31, (smtc_seqr(0x31) | 0x03));
324 case FB_BLANK_NORMAL
:
325 /* Screen Off: HSync: On, VSync : On Soft blank */
326 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
327 smtc_seqw(0x6a, 0x16);
328 smtc_seqw(0x6b, 0x02);
329 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
330 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
331 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
332 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
334 case FB_BLANK_VSYNC_SUSPEND
:
335 /* Screen On: HSync: On, VSync : Off */
336 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
337 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
338 smtc_seqw(0x6a, 0x0c);
339 smtc_seqw(0x6b, 0x02);
340 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
341 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x20));
342 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0x20));
343 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
344 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
345 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
347 case FB_BLANK_HSYNC_SUSPEND
:
348 /* Screen On: HSync: Off, VSync : On */
349 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
350 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
351 smtc_seqw(0x6a, 0x0c);
352 smtc_seqw(0x6b, 0x02);
353 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
354 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x10));
355 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
356 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
357 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
358 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
360 case FB_BLANK_POWERDOWN
:
361 /* Screen On: HSync: Off, VSync : Off */
362 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
363 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
364 smtc_seqw(0x6a, 0x0c);
365 smtc_seqw(0x6b, 0x02);
366 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
367 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x30));
368 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
369 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
370 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
371 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
380 static int smtc_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
381 unsigned blue
, unsigned trans
, struct fb_info
*info
)
383 struct smtcfb_info
*sfb
= (struct smtcfb_info
*)info
;
389 switch (sfb
->fb
.fix
.visual
) {
390 case FB_VISUAL_DIRECTCOLOR
:
391 case FB_VISUAL_TRUECOLOR
:
393 * 16/32 bit true-colour, use pseuo-palette for 16 base color
396 if (sfb
->fb
.var
.bits_per_pixel
== 16) {
397 u32
*pal
= sfb
->fb
.pseudo_palette
;
398 val
= chan_to_field(red
, &sfb
->fb
.var
.red
);
399 val
|= chan_to_field(green
, \
401 val
|= chan_to_field(blue
, &sfb
->fb
.var
.blue
);
404 ((red
& 0xf800) >> 8) |
405 ((green
& 0xe000) >> 13) |
406 ((green
& 0x1c00) << 3) |
407 ((blue
& 0xf800) >> 3);
412 u32
*pal
= sfb
->fb
.pseudo_palette
;
413 val
= chan_to_field(red
, &sfb
->fb
.var
.red
);
414 val
|= chan_to_field(green
, \
416 val
|= chan_to_field(blue
, &sfb
->fb
.var
.blue
);
419 (val
& 0xff00ff00 >> 8) |
420 (val
& 0x00ff00ff << 8);
427 case FB_VISUAL_PSEUDOCOLOR
:
428 /* color depth 8 bit */
429 sm712_setpalette(regno
, red
, green
, blue
, info
);
433 return 1; /* unknown type */
441 static ssize_t
smtcfb_read(struct fb_info
*info
, char __user
* buf
, size_t
444 unsigned long p
= *ppos
;
448 int c
, i
, cnt
= 0, err
= 0;
449 unsigned long total_size
;
451 if (!info
|| !info
->screen_base
)
454 if (info
->state
!= FBINFO_STATE_RUNNING
)
457 total_size
= info
->screen_size
;
460 total_size
= info
->fix
.smem_len
;
465 if (count
>= total_size
)
468 if (count
+ p
> total_size
)
469 count
= total_size
- p
;
471 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
, GFP_KERNEL
);
475 src
= (u32 __iomem
*) (info
->screen_base
+ p
);
477 if (info
->fbops
->fb_sync
)
478 info
->fbops
->fb_sync(info
);
481 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
483 for (i
= c
>> 2; i
--;) {
484 *dst
= fb_readl(src
++);
486 (*dst
& 0xff00ff00 >> 8) |
487 (*dst
& 0x00ff00ff << 8);
491 u8
*dst8
= (u8
*) dst
;
492 u8 __iomem
*src8
= (u8 __iomem
*) src
;
494 for (i
= c
& 3; i
--;) {
496 *dst8
++ = fb_readb(++src8
);
498 *dst8
++ = fb_readb(--src8
);
502 src
= (u32 __iomem
*) src8
;
505 if (copy_to_user(buf
, buffer
, c
)) {
517 return (err
) ? err
: cnt
;
521 smtcfb_write(struct fb_info
*info
, const char __user
*buf
, size_t count
,
524 unsigned long p
= *ppos
;
528 int c
, i
, cnt
= 0, err
= 0;
529 unsigned long total_size
;
531 if (!info
|| !info
->screen_base
)
534 if (info
->state
!= FBINFO_STATE_RUNNING
)
537 total_size
= info
->screen_size
;
540 total_size
= info
->fix
.smem_len
;
545 if (count
> total_size
) {
550 if (count
+ p
> total_size
) {
554 count
= total_size
- p
;
557 buffer
= kmalloc((count
> PAGE_SIZE
) ? PAGE_SIZE
: count
, GFP_KERNEL
);
561 dst
= (u32 __iomem
*) (info
->screen_base
+ p
);
563 if (info
->fbops
->fb_sync
)
564 info
->fbops
->fb_sync(info
);
567 c
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
570 if (copy_from_user(src
, buf
, c
)) {
575 for (i
= c
>> 2; i
--;) {
576 fb_writel((*src
& 0xff00ff00 >> 8) |
577 (*src
& 0x00ff00ff << 8), dst
++);
581 u8
*src8
= (u8
*) src
;
582 u8 __iomem
*dst8
= (u8 __iomem
*) dst
;
584 for (i
= c
& 3; i
--;) {
586 fb_writeb(*src8
++, ++dst8
);
588 fb_writeb(*src8
++, --dst8
);
592 dst
= (u32 __iomem
*) dst8
;
603 return (cnt
) ? cnt
: err
;
605 #endif /* ! __BIG_ENDIAN */
607 static struct fb_ops smtcfb_ops
= {
608 .owner
= THIS_MODULE
,
609 .fb_setcolreg
= smtc_setcolreg
,
610 .fb_blank
= cfb_blank
,
611 .fb_fillrect
= cfb_fillrect
,
612 .fb_imageblit
= cfb_imageblit
,
613 .fb_copyarea
= cfb_copyarea
,
615 .fb_read
= smtcfb_read
,
616 .fb_write
= smtcfb_write
,
621 void smtcfb_setmode(struct smtcfb_info
*sfb
)
623 switch (sfb
->fb
.var
.bits_per_pixel
) {
625 sfb
->fb
.fix
.visual
= FB_VISUAL_TRUECOLOR
;
626 sfb
->fb
.fix
.line_length
= sfb
->fb
.var
.xres
* 4;
627 sfb
->fb
.var
.red
.length
= 8;
628 sfb
->fb
.var
.green
.length
= 8;
629 sfb
->fb
.var
.blue
.length
= 8;
630 sfb
->fb
.var
.red
.offset
= 16;
631 sfb
->fb
.var
.green
.offset
= 8;
632 sfb
->fb
.var
.blue
.offset
= 0;
636 sfb
->fb
.fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
637 sfb
->fb
.fix
.line_length
= sfb
->fb
.var
.xres
;
638 sfb
->fb
.var
.red
.offset
= 5;
639 sfb
->fb
.var
.red
.length
= 3;
640 sfb
->fb
.var
.green
.offset
= 2;
641 sfb
->fb
.var
.green
.length
= 3;
642 sfb
->fb
.var
.blue
.offset
= 0;
643 sfb
->fb
.var
.blue
.length
= 2;
646 sfb
->fb
.fix
.visual
= FB_VISUAL_TRUECOLOR
;
647 sfb
->fb
.fix
.line_length
= sfb
->fb
.var
.xres
* 3;
648 sfb
->fb
.var
.red
.length
= 8;
649 sfb
->fb
.var
.green
.length
= 8;
650 sfb
->fb
.var
.blue
.length
= 8;
652 sfb
->fb
.var
.red
.offset
= 16;
653 sfb
->fb
.var
.green
.offset
= 8;
654 sfb
->fb
.var
.blue
.offset
= 0;
659 sfb
->fb
.fix
.visual
= FB_VISUAL_TRUECOLOR
;
660 sfb
->fb
.fix
.line_length
= sfb
->fb
.var
.xres
* 2;
662 sfb
->fb
.var
.red
.length
= 5;
663 sfb
->fb
.var
.green
.length
= 6;
664 sfb
->fb
.var
.blue
.length
= 5;
666 sfb
->fb
.var
.red
.offset
= 11;
667 sfb
->fb
.var
.green
.offset
= 5;
668 sfb
->fb
.var
.blue
.offset
= 0;
673 hw
.width
= sfb
->fb
.var
.xres
;
674 hw
.height
= sfb
->fb
.var
.yres
;
676 smtc_set_timing(sfb
, &hw
);
680 * Alloc struct smtcfb_info and assign the default value
682 static struct smtcfb_info
*smtc_alloc_fb_info(struct pci_dev
*dev
,
685 struct smtcfb_info
*sfb
;
687 sfb
= kzalloc(sizeof(struct smtcfb_info
), GFP_KERNEL
);
695 /*** Init sfb->fb with default value ***/
696 sfb
->fb
.flags
= FBINFO_FLAG_DEFAULT
;
697 sfb
->fb
.fbops
= &smtcfb_ops
;
698 sfb
->fb
.var
= smtcfb_var
;
699 sfb
->fb
.fix
= smtcfb_fix
;
701 strcpy(sfb
->fb
.fix
.id
, name
);
703 sfb
->fb
.fix
.type
= FB_TYPE_PACKED_PIXELS
;
704 sfb
->fb
.fix
.type_aux
= 0;
705 sfb
->fb
.fix
.xpanstep
= 0;
706 sfb
->fb
.fix
.ypanstep
= 0;
707 sfb
->fb
.fix
.ywrapstep
= 0;
708 sfb
->fb
.fix
.accel
= FB_ACCEL_SMI_LYNX
;
710 sfb
->fb
.var
.nonstd
= 0;
711 sfb
->fb
.var
.activate
= FB_ACTIVATE_NOW
;
712 sfb
->fb
.var
.height
= -1;
713 sfb
->fb
.var
.width
= -1;
714 /* text mode acceleration */
715 sfb
->fb
.var
.accel_flags
= FB_ACCELF_TEXT
;
716 sfb
->fb
.var
.vmode
= FB_VMODE_NONINTERLACED
;
718 sfb
->fb
.pseudo_palette
= colreg
;
724 * Unmap in the memory mapped IO registers
727 static void smtc_unmap_mmio(struct smtcfb_info
*sfb
)
729 if (sfb
&& smtc_RegBaseAddress
)
730 smtc_RegBaseAddress
= NULL
;
734 * Map in the screen memory
737 static int smtc_map_smem(struct smtcfb_info
*sfb
,
738 struct pci_dev
*dev
, u_long smem_len
)
740 if (sfb
->fb
.var
.bits_per_pixel
== 32) {
742 sfb
->fb
.fix
.smem_start
= pci_resource_start(dev
, 0)
745 sfb
->fb
.fix
.smem_start
= pci_resource_start(dev
, 0);
748 sfb
->fb
.fix
.smem_start
= pci_resource_start(dev
, 0);
751 sfb
->fb
.fix
.smem_len
= smem_len
;
753 sfb
->fb
.screen_base
= smtc_VRAMBaseAddress
;
755 if (!sfb
->fb
.screen_base
) {
756 printk(KERN_INFO
"%s: unable to map screen memory\n",
765 * Unmap in the screen memory
768 static void smtc_unmap_smem(struct smtcfb_info
*sfb
)
770 if (sfb
&& sfb
->fb
.screen_base
) {
771 iounmap(sfb
->fb
.screen_base
);
772 sfb
->fb
.screen_base
= NULL
;
777 * We need to wake up the LynxEM+, and make sure its in linear memory mode.
779 static inline void sm7xx_init_hw(void)
785 static void smtc_free_fb_info(struct smtcfb_info
*sfb
)
788 fb_alloc_cmap(&sfb
->fb
.cmap
, 0, 0);
794 * sm712vga_setup - process command line options, get vga parameter
795 * @options: string of options
799 static int __init __maybe_unused
sm712vga_setup(char *options
)
803 if (!options
|| !*options
) {
804 smdbg("\n No vga parameter\n");
808 smtc_screen_info
.lfb_width
= 0;
809 smtc_screen_info
.lfb_height
= 0;
810 smtc_screen_info
.lfb_depth
= 0;
812 smdbg("\nsm712vga_setup = %s\n", options
);
815 index
< (sizeof(vesa_mode
) / sizeof(struct vesa_mode_table
));
817 if (strstr(options
, vesa_mode
[index
].mode_index
)) {
818 smtc_screen_info
.lfb_width
= vesa_mode
[index
].lfb_width
;
819 smtc_screen_info
.lfb_height
=
820 vesa_mode
[index
].lfb_height
;
821 smtc_screen_info
.lfb_depth
= vesa_mode
[index
].lfb_depth
;
828 __setup("vga=", sm712vga_setup
);
830 /* Jason (08/13/2009)
831 * Original init function changed to probe method to be used by pci_drv
832 * process used to detect chips replaced with kernel process in pci_drv
834 static int __devinit
smtcfb_pci_probe(struct pci_dev
*pdev
,
835 const struct pci_device_id
*ent
)
837 struct smtcfb_info
*sfb
;
838 u_long smem_size
= 0x00800000; /* default 8MB */
841 unsigned long pFramebufferPhysical
;
844 "Silicon Motion display driver " SMTC_LINUX_FB_VERSION
"\n");
846 err
= pci_enable_device(pdev
); /* enable SMTC chip */
851 hw
.chipID
= ent
->device
;
852 sprintf(name
, "sm%Xfb", hw
.chipID
);
854 sfb
= smtc_alloc_fb_info(pdev
, name
);
858 /* Jason (08/13/2009)
859 * Store fb_info to be further used when suspending and resuming
861 pci_set_drvdata(pdev
, sfb
);
865 /*get mode parameter from smtc_screen_info */
866 if (smtc_screen_info
.lfb_width
!= 0) {
867 sfb
->fb
.var
.xres
= smtc_screen_info
.lfb_width
;
868 sfb
->fb
.var
.yres
= smtc_screen_info
.lfb_height
;
869 sfb
->fb
.var
.bits_per_pixel
= smtc_screen_info
.lfb_depth
;
871 /* default resolution 1024x600 16bit mode */
872 sfb
->fb
.var
.xres
= SCREEN_X_RES
;
873 sfb
->fb
.var
.yres
= SCREEN_Y_RES
;
874 sfb
->fb
.var
.bits_per_pixel
= SCREEN_BPP
;
878 if (sfb
->fb
.var
.bits_per_pixel
== 24)
879 sfb
->fb
.var
.bits_per_pixel
= (smtc_screen_info
.lfb_depth
= 32);
881 /* Map address and memory detection */
882 pFramebufferPhysical
= pci_resource_start(pdev
, 0);
883 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
.chipRevID
);
888 sfb
->fb
.fix
.mmio_start
= pFramebufferPhysical
+ 0x00400000;
889 sfb
->fb
.fix
.mmio_len
= 0x00400000;
890 smem_size
= SM712_VIDEOMEMORYSIZE
;
892 hw
.m_pLFB
= (smtc_VRAMBaseAddress
=
893 ioremap(pFramebufferPhysical
, 0x00c00000));
895 hw
.m_pLFB
= (smtc_VRAMBaseAddress
=
896 ioremap(pFramebufferPhysical
, 0x00800000));
898 hw
.m_pMMIO
= (smtc_RegBaseAddress
=
899 smtc_VRAMBaseAddress
+ 0x00700000);
900 hw
.m_pDPR
= smtc_VRAMBaseAddress
+ 0x00408000;
901 hw
.m_pVPR
= hw
.m_pLFB
+ 0x0040c000;
903 if (sfb
->fb
.var
.bits_per_pixel
== 32) {
904 smtc_VRAMBaseAddress
+= 0x800000;
905 hw
.m_pLFB
+= 0x800000;
907 "\nsmtc_VRAMBaseAddress=%p hw.m_pLFB=%p\n",
908 smtc_VRAMBaseAddress
, hw
.m_pLFB
);
911 if (!smtc_RegBaseAddress
) {
913 "%s: unable to map memory mapped IO\n",
919 /* set MCLK = 14.31818 * (0x16 / 0x2) */
920 smtc_seqw(0x6a, 0x16);
921 smtc_seqw(0x6b, 0x02);
922 smtc_seqw(0x62, 0x3e);
923 /* enable PCI burst */
924 smtc_seqw(0x17, 0x20);
925 /* enable word swap */
927 if (sfb
->fb
.var
.bits_per_pixel
== 32)
928 smtc_seqw(0x17, 0x30);
932 sfb
->fb
.fix
.mmio_start
= pFramebufferPhysical
;
933 sfb
->fb
.fix
.mmio_len
= 0x00200000;
934 smem_size
= SM722_VIDEOMEMORYSIZE
;
935 hw
.m_pDPR
= ioremap(pFramebufferPhysical
, 0x00a00000);
936 hw
.m_pLFB
= (smtc_VRAMBaseAddress
=
937 hw
.m_pDPR
+ 0x00200000);
938 hw
.m_pMMIO
= (smtc_RegBaseAddress
=
939 hw
.m_pDPR
+ 0x000c0000);
940 hw
.m_pVPR
= hw
.m_pDPR
+ 0x800;
942 smtc_seqw(0x62, 0xff);
943 smtc_seqw(0x6a, 0x0d);
944 smtc_seqw(0x6b, 0x02);
948 "No valid Silicon Motion display chip was detected!\n");
953 /* can support 32 bpp */
954 if (15 == sfb
->fb
.var
.bits_per_pixel
)
955 sfb
->fb
.var
.bits_per_pixel
= 16;
957 sfb
->fb
.var
.xres_virtual
= sfb
->fb
.var
.xres
;
958 sfb
->fb
.var
.yres_virtual
= sfb
->fb
.var
.yres
;
959 err
= smtc_map_smem(sfb
, pdev
, smem_size
);
964 /* Primary display starting from 0 position */
965 hw
.BaseAddressInVRAM
= 0;
968 err
= register_framebuffer(&sfb
->fb
);
972 printk(KERN_INFO
"Silicon Motion SM%X Rev%X primary display mode"
973 "%dx%d-%d Init Complete.\n", hw
.chipID
, hw
.chipRevID
,
974 sfb
->fb
.var
.xres
, sfb
->fb
.var
.yres
,
975 sfb
->fb
.var
.bits_per_pixel
);
980 printk(KERN_INFO
"Silicon Motion, Inc. primary display init fail\n");
982 smtc_unmap_smem(sfb
);
983 smtc_unmap_mmio(sfb
);
985 smtc_free_fb_info(sfb
);
988 pci_disable_device(pdev
);
994 /* Jason (08/11/2009) PCI_DRV wrapper essential structs */
995 static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table
) = {
996 {0x126f, 0x710, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
997 {0x126f, 0x712, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
998 {0x126f, 0x720, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
1003 /* Jason (08/14/2009)
1004 * do some clean up when the driver module is removed
1006 static void __devexit
smtcfb_pci_remove(struct pci_dev
*pdev
)
1008 struct smtcfb_info
*sfb
;
1010 sfb
= pci_get_drvdata(pdev
);
1011 pci_set_drvdata(pdev
, NULL
);
1012 smtc_unmap_smem(sfb
);
1013 smtc_unmap_mmio(sfb
);
1014 unregister_framebuffer(&sfb
->fb
);
1015 smtc_free_fb_info(sfb
);
1019 static int smtcfb_pci_suspend(struct device
*device
)
1021 struct pci_dev
*pdev
= to_pci_dev(device
);
1022 struct smtcfb_info
*sfb
;
1024 sfb
= pci_get_drvdata(pdev
);
1026 /* set the hw in sleep mode use externel clock and self memory refresh
1027 * so that we can turn off internal PLLs later on
1029 smtc_seqw(0x20, (smtc_seqr(0x20) | 0xc0));
1030 smtc_seqw(0x69, (smtc_seqr(0x69) & 0xf7));
1033 fb_set_suspend(&sfb
->fb
, 1);
1036 /* additionally turn off all function blocks including internal PLLs */
1037 smtc_seqw(0x21, 0xff);
1042 static int smtcfb_pci_resume(struct device
*device
)
1044 struct pci_dev
*pdev
= to_pci_dev(device
);
1045 struct smtcfb_info
*sfb
;
1047 sfb
= pci_get_drvdata(pdev
);
1049 /* reinit hardware */
1051 switch (hw
.chipID
) {
1054 /* set MCLK = 14.31818 * (0x16 / 0x2) */
1055 smtc_seqw(0x6a, 0x16);
1056 smtc_seqw(0x6b, 0x02);
1057 smtc_seqw(0x62, 0x3e);
1058 /* enable PCI burst */
1059 smtc_seqw(0x17, 0x20);
1061 if (sfb
->fb
.var
.bits_per_pixel
== 32)
1062 smtc_seqw(0x17, 0x30);
1066 smtc_seqw(0x62, 0xff);
1067 smtc_seqw(0x6a, 0x0d);
1068 smtc_seqw(0x6b, 0x02);
1072 smtc_seqw(0x34, (smtc_seqr(0x34) | 0xc0));
1073 smtc_seqw(0x33, ((smtc_seqr(0x33) | 0x08) & 0xfb));
1075 smtcfb_setmode(sfb
);
1078 fb_set_suspend(&sfb
->fb
, 0);
1084 static const struct dev_pm_ops sm7xx_pm_ops
= {
1085 .suspend
= smtcfb_pci_suspend
,
1086 .resume
= smtcfb_pci_resume
,
1087 .freeze
= smtcfb_pci_suspend
,
1088 .thaw
= smtcfb_pci_resume
,
1089 .poweroff
= smtcfb_pci_suspend
,
1090 .restore
= smtcfb_pci_resume
,
1093 #define SM7XX_PM_OPS (&sm7xx_pm_ops)
1095 #else /* !CONFIG_PM */
1097 #define SM7XX_PM_OPS NULL
1099 #endif /* !CONFIG_PM */
1101 static struct pci_driver smtcfb_driver
= {
1103 .id_table
= smtcfb_pci_table
,
1104 .probe
= smtcfb_pci_probe
,
1105 .remove
= __devexit_p(smtcfb_pci_remove
),
1106 .driver
.pm
= SM7XX_PM_OPS
,
1109 static int __init
smtcfb_init(void)
1111 return pci_register_driver(&smtcfb_driver
);
1114 static void __exit
smtcfb_exit(void)
1116 pci_unregister_driver(&smtcfb_driver
);
1119 module_init(smtcfb_init
);
1120 module_exit(smtcfb_exit
);
1122 MODULE_AUTHOR("Siliconmotion ");
1123 MODULE_DESCRIPTION("Framebuffer driver for SMI Graphic Cards");
1124 MODULE_LICENSE("GPL");