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 * Copyright (C) 2011 Igalia, S.L.
12 * Author: Javier M. Mellid <jmunhoz@igalia.com>
14 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file COPYING in the main directory of this archive for
22 #include <linux/pci.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/uaccess.h>
26 #include <linux/module.h>
27 #include <linux/console.h>
28 #include <linux/screen_info.h>
36 struct screen_info smtc_screen_info;
50 unsigned char __iomem *m_pMMIO;
59 u_long BaseAddressInVRAM;
63 struct vesa_mode_table {
70 static struct vesa_mode_table vesa_mode[] = {
71 {"0x301", 640, 480, 8},
72 {"0x303", 800, 600, 8},
73 {"0x305", 1024, 768, 8},
74 {"0x307", 1280, 1024, 8},
76 {"0x311", 640, 480, 16},
77 {"0x314", 800, 600, 16},
78 {"0x317", 1024, 768, 16},
79 {"0x31A", 1280, 1024, 16},
81 {"0x312", 640, 480, 24},
82 {"0x315", 800, 600, 24},
83 {"0x318", 1024, 768, 24},
84 {"0x31B", 1280, 1024, 24},
87 char __iomem *smtc_RegBaseAddress; /* Memory Map IO starting address */
88 char __iomem *smtc_VRAMBaseAddress; /* video memory starting address */
90 static u32 colreg[17];
92 static struct fb_var_screeninfo smtcfb_var = {
101 .activate = FB_ACTIVATE_NOW,
104 .vmode = FB_VMODE_NONINTERLACED,
107 static struct fb_fix_screeninfo smtcfb_fix = {
109 .type = FB_TYPE_PACKED_PIXELS,
110 .visual = FB_VISUAL_TRUECOLOR,
111 .line_length = 800 * 3,
112 .accel = FB_ACCEL_SMI_LYNX,
115 static void sm712_set_timing(struct smtcfb_info *sfb)
120 dev_dbg(&sfb->pdev->dev,
121 "sfb->width=%d sfb->height=%d "
122 "sfb->fb.var.bits_per_pixel=%d sfb->hz=%d\n",
123 sfb->width, sfb->height, sfb->fb.var.bits_per_pixel, sfb->hz);
125 for (j = 0; j < numVGAModes; j++) {
126 if (VGAMode[j].mmSizeX == sfb->width &&
127 VGAMode[j].mmSizeY == sfb->height &&
128 VGAMode[j].bpp == sfb->fb.var.bits_per_pixel &&
129 VGAMode[j].hz == sfb->hz) {
131 dev_dbg(&sfb->pdev->dev,
132 "VGAMode[j].mmSizeX=%d VGAMode[j].mmSizeY=%d "
133 "VGAMode[j].bpp=%d VGAMode[j].hz=%d\n",
134 VGAMode[j].mmSizeX, VGAMode[j].mmSizeY,
135 VGAMode[j].bpp, VGAMode[j].hz);
137 dev_dbg(&sfb->pdev->dev, "VGAMode index=%d\n", j);
139 smtc_mmiowb(0x0, 0x3c6);
143 smtc_mmiowb(VGAMode[j].Init_MISC, 0x3c2);
145 /* init SEQ register SR00 - SR04 */
146 for (i = 0; i < SIZE_SR00_SR04; i++)
147 smtc_seqw(i, VGAMode[j].Init_SR00_SR04[i]);
149 /* init SEQ register SR10 - SR24 */
150 for (i = 0; i < SIZE_SR10_SR24; i++)
152 VGAMode[j].Init_SR10_SR24[i]);
154 /* init SEQ register SR30 - SR75 */
155 for (i = 0; i < SIZE_SR30_SR75; i++)
156 if (((i + 0x30) != 0x62) \
157 && ((i + 0x30) != 0x6a) \
158 && ((i + 0x30) != 0x6b))
160 VGAMode[j].Init_SR30_SR75[i]);
162 /* init SEQ register SR80 - SR93 */
163 for (i = 0; i < SIZE_SR80_SR93; i++)
165 VGAMode[j].Init_SR80_SR93[i]);
167 /* init SEQ register SRA0 - SRAF */
168 for (i = 0; i < SIZE_SRA0_SRAF; i++)
170 VGAMode[j].Init_SRA0_SRAF[i]);
172 /* init Graphic register GR00 - GR08 */
173 for (i = 0; i < SIZE_GR00_GR08; i++)
174 smtc_grphw(i, VGAMode[j].Init_GR00_GR08[i]);
176 /* init Attribute register AR00 - AR14 */
177 for (i = 0; i < SIZE_AR00_AR14; i++)
178 smtc_attrw(i, VGAMode[j].Init_AR00_AR14[i]);
180 /* init CRTC register CR00 - CR18 */
181 for (i = 0; i < SIZE_CR00_CR18; i++)
182 smtc_crtcw(i, VGAMode[j].Init_CR00_CR18[i]);
184 /* init CRTC register CR30 - CR4D */
185 for (i = 0; i < SIZE_CR30_CR4D; i++)
187 VGAMode[j].Init_CR30_CR4D[i]);
189 /* init CRTC register CR90 - CRA7 */
190 for (i = 0; i < SIZE_CR90_CRA7; i++)
192 VGAMode[j].Init_CR90_CRA7[i]);
195 smtc_mmiowb(0x67, 0x3c2);
197 /* set VPR registers */
198 writel(0x0, sfb->m_pVPR + 0x0C);
199 writel(0x0, sfb->m_pVPR + 0x40);
203 (sfb->width * sfb->fb.var.bits_per_pixel) / 64;
204 switch (sfb->fb.var.bits_per_pixel) {
206 writel(0x0, sfb->m_pVPR + 0x0);
209 writel(0x00020000, sfb->m_pVPR + 0x0);
212 writel(0x00040000, sfb->m_pVPR + 0x0);
215 writel(0x00030000, sfb->m_pVPR + 0x0);
218 writel((u32) (((m_nScreenStride + 2) << 16) | m_nScreenStride),
223 static void sm712_setpalette(int regno, unsigned red, unsigned green,
224 unsigned blue, struct fb_info *info)
226 struct smtcfb_info *sfb = info->par;
228 if (sfb->BaseAddressInVRAM)
230 * second display palette for dual head. Enable CRT RAM, 6-bit
233 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x20);
235 /* primary display palette. Enable LCD RAM only, 6-bit RAM */
236 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x10);
237 smtc_mmiowb(regno, dac_reg);
238 smtc_mmiowb(red >> 10, dac_val);
239 smtc_mmiowb(green >> 10, dac_val);
240 smtc_mmiowb(blue >> 10, dac_val);
243 static void smtc_set_timing(struct smtcfb_info *sfb)
245 switch (sfb->chipID) {
249 sm712_set_timing(sfb);
256 * convert a colour value into a field position
261 static inline unsigned int chan_to_field(unsigned int chan,
262 struct fb_bitfield *bf)
265 chan >>= 16 - bf->length;
266 return chan << bf->offset;
269 static int smtc_blank(int blank_mode, struct fb_info *info)
271 /* clear DPMS setting */
272 switch (blank_mode) {
273 case FB_BLANK_UNBLANK:
274 /* Screen On: HSync: On, VSync : On */
275 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
276 smtc_seqw(0x6a, 0x16);
277 smtc_seqw(0x6b, 0x02);
278 smtc_seqw(0x21, (smtc_seqr(0x21) & 0x77));
279 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
280 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
281 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
282 smtc_seqw(0x31, (smtc_seqr(0x31) | 0x03));
284 case FB_BLANK_NORMAL:
285 /* Screen Off: HSync: On, VSync : On Soft blank */
286 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
287 smtc_seqw(0x6a, 0x16);
288 smtc_seqw(0x6b, 0x02);
289 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
290 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
291 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
292 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
294 case FB_BLANK_VSYNC_SUSPEND:
295 /* Screen On: HSync: On, VSync : Off */
296 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
297 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
298 smtc_seqw(0x6a, 0x0c);
299 smtc_seqw(0x6b, 0x02);
300 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
301 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x20));
302 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0x20));
303 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
304 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
305 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
307 case FB_BLANK_HSYNC_SUSPEND:
308 /* Screen On: HSync: Off, VSync : On */
309 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
310 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
311 smtc_seqw(0x6a, 0x0c);
312 smtc_seqw(0x6b, 0x02);
313 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
314 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x10));
315 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
316 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
317 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
318 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
320 case FB_BLANK_POWERDOWN:
321 /* Screen On: HSync: Off, VSync : Off */
322 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
323 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
324 smtc_seqw(0x6a, 0x0c);
325 smtc_seqw(0x6b, 0x02);
326 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
327 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x30));
328 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
329 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
330 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
331 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
340 static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green,
341 unsigned blue, unsigned trans, struct fb_info *info)
343 struct smtcfb_info *sfb = (struct smtcfb_info *)info;
349 switch (sfb->fb.fix.visual) {
350 case FB_VISUAL_DIRECTCOLOR:
351 case FB_VISUAL_TRUECOLOR:
353 * 16/32 bit true-colour, use pseuo-palette for 16 base color
356 if (sfb->fb.var.bits_per_pixel == 16) {
357 u32 *pal = sfb->fb.pseudo_palette;
358 val = chan_to_field(red, &sfb->fb.var.red);
359 val |= chan_to_field(green, \
361 val |= chan_to_field(blue, &sfb->fb.var.blue);
364 ((red & 0xf800) >> 8) |
365 ((green & 0xe000) >> 13) |
366 ((green & 0x1c00) << 3) |
367 ((blue & 0xf800) >> 3);
372 u32 *pal = sfb->fb.pseudo_palette;
373 val = chan_to_field(red, &sfb->fb.var.red);
374 val |= chan_to_field(green, \
376 val |= chan_to_field(blue, &sfb->fb.var.blue);
379 (val & 0xff00ff00 >> 8) |
380 (val & 0x00ff00ff << 8);
387 case FB_VISUAL_PSEUDOCOLOR:
388 /* color depth 8 bit */
389 sm712_setpalette(regno, red, green, blue, info);
393 return 1; /* unknown type */
401 static ssize_t smtcfb_read(struct fb_info *info, char __user *buf, size_t
404 unsigned long p = *ppos;
408 int c, i, cnt = 0, err = 0;
409 unsigned long total_size;
411 if (!info || !info->screen_base)
414 if (info->state != FBINFO_STATE_RUNNING)
417 total_size = info->screen_size;
420 total_size = info->fix.smem_len;
425 if (count >= total_size)
428 if (count + p > total_size)
429 count = total_size - p;
431 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
435 src = (u32 __iomem *) (info->screen_base + p);
437 if (info->fbops->fb_sync)
438 info->fbops->fb_sync(info);
441 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
443 for (i = c >> 2; i--;) {
444 *dst = fb_readl(src++);
446 (*dst & 0xff00ff00 >> 8) |
447 (*dst & 0x00ff00ff << 8);
451 u8 *dst8 = (u8 *) dst;
452 u8 __iomem *src8 = (u8 __iomem *) src;
454 for (i = c & 3; i--;) {
456 *dst8++ = fb_readb(++src8);
458 *dst8++ = fb_readb(--src8);
462 src = (u32 __iomem *) src8;
465 if (copy_to_user(buf, buffer, c)) {
477 return (err) ? err : cnt;
481 smtcfb_write(struct fb_info *info, const char __user *buf, size_t count,
484 unsigned long p = *ppos;
488 int c, i, cnt = 0, err = 0;
489 unsigned long total_size;
491 if (!info || !info->screen_base)
494 if (info->state != FBINFO_STATE_RUNNING)
497 total_size = info->screen_size;
500 total_size = info->fix.smem_len;
505 if (count > total_size) {
510 if (count + p > total_size) {
514 count = total_size - p;
517 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
521 dst = (u32 __iomem *) (info->screen_base + p);
523 if (info->fbops->fb_sync)
524 info->fbops->fb_sync(info);
527 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
530 if (copy_from_user(src, buf, c)) {
535 for (i = c >> 2; i--;) {
536 fb_writel((*src & 0xff00ff00 >> 8) |
537 (*src & 0x00ff00ff << 8), dst++);
541 u8 *src8 = (u8 *) src;
542 u8 __iomem *dst8 = (u8 __iomem *) dst;
544 for (i = c & 3; i--;) {
546 fb_writeb(*src8++, ++dst8);
548 fb_writeb(*src8++, --dst8);
552 dst = (u32 __iomem *) dst8;
563 return (cnt) ? cnt : err;
565 #endif /* ! __BIG_ENDIAN */
567 void smtcfb_setmode(struct smtcfb_info *sfb)
569 switch (sfb->fb.var.bits_per_pixel) {
571 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
572 sfb->fb.fix.line_length = sfb->fb.var.xres * 4;
573 sfb->fb.var.red.length = 8;
574 sfb->fb.var.green.length = 8;
575 sfb->fb.var.blue.length = 8;
576 sfb->fb.var.red.offset = 16;
577 sfb->fb.var.green.offset = 8;
578 sfb->fb.var.blue.offset = 0;
582 sfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
583 sfb->fb.fix.line_length = sfb->fb.var.xres;
584 sfb->fb.var.red.offset = 5;
585 sfb->fb.var.red.length = 3;
586 sfb->fb.var.green.offset = 2;
587 sfb->fb.var.green.length = 3;
588 sfb->fb.var.blue.offset = 0;
589 sfb->fb.var.blue.length = 2;
592 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
593 sfb->fb.fix.line_length = sfb->fb.var.xres * 3;
594 sfb->fb.var.red.length = 8;
595 sfb->fb.var.green.length = 8;
596 sfb->fb.var.blue.length = 8;
598 sfb->fb.var.red.offset = 16;
599 sfb->fb.var.green.offset = 8;
600 sfb->fb.var.blue.offset = 0;
605 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
606 sfb->fb.fix.line_length = sfb->fb.var.xres * 2;
608 sfb->fb.var.red.length = 5;
609 sfb->fb.var.green.length = 6;
610 sfb->fb.var.blue.length = 5;
612 sfb->fb.var.red.offset = 11;
613 sfb->fb.var.green.offset = 5;
614 sfb->fb.var.blue.offset = 0;
619 sfb->width = sfb->fb.var.xres;
620 sfb->height = sfb->fb.var.yres;
622 smtc_set_timing(sfb);
625 static int smtc_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
628 if (var->xres_virtual < var->xres)
629 var->xres_virtual = var->xres;
631 if (var->yres_virtual < var->yres)
632 var->yres_virtual = var->yres;
634 /* set valid default bpp */
635 if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16) &&
636 (var->bits_per_pixel != 24) && (var->bits_per_pixel != 32))
637 var->bits_per_pixel = 16;
642 static int smtc_set_par(struct fb_info *info)
644 struct smtcfb_info *sfb = (struct smtcfb_info *)info;
651 static struct fb_ops smtcfb_ops = {
652 .owner = THIS_MODULE,
653 .fb_check_var = smtc_check_var,
654 .fb_set_par = smtc_set_par,
655 .fb_setcolreg = smtc_setcolreg,
656 .fb_blank = smtc_blank,
657 .fb_fillrect = cfb_fillrect,
658 .fb_imageblit = cfb_imageblit,
659 .fb_copyarea = cfb_copyarea,
661 .fb_read = smtcfb_read,
662 .fb_write = smtcfb_write,
667 * Alloc struct smtcfb_info and assign the default value
669 static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *pdev, char *name)
671 struct smtcfb_info *sfb;
673 sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);
680 /*** Init sfb->fb with default value ***/
681 sfb->fb.flags = FBINFO_FLAG_DEFAULT;
682 sfb->fb.fbops = &smtcfb_ops;
683 sfb->fb.var = smtcfb_var;
684 sfb->fb.fix = smtcfb_fix;
686 strcpy(sfb->fb.fix.id, name);
688 sfb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
689 sfb->fb.fix.type_aux = 0;
690 sfb->fb.fix.xpanstep = 0;
691 sfb->fb.fix.ypanstep = 0;
692 sfb->fb.fix.ywrapstep = 0;
693 sfb->fb.fix.accel = FB_ACCEL_SMI_LYNX;
695 sfb->fb.var.nonstd = 0;
696 sfb->fb.var.activate = FB_ACTIVATE_NOW;
697 sfb->fb.var.height = -1;
698 sfb->fb.var.width = -1;
699 /* text mode acceleration */
700 sfb->fb.var.accel_flags = FB_ACCELF_TEXT;
701 sfb->fb.var.vmode = FB_VMODE_NONINTERLACED;
705 sfb->fb.pseudo_palette = colreg;
711 * Unmap in the memory mapped IO registers
714 static void smtc_unmap_mmio(struct smtcfb_info *sfb)
716 if (sfb && smtc_RegBaseAddress)
717 smtc_RegBaseAddress = NULL;
721 * Map in the screen memory
724 static int smtc_map_smem(struct smtcfb_info *sfb,
725 struct pci_dev *pdev, u_long smem_len)
727 if (sfb->fb.var.bits_per_pixel == 32) {
729 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0)
732 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
735 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
738 sfb->fb.fix.smem_len = smem_len;
740 sfb->fb.screen_base = smtc_VRAMBaseAddress;
742 if (!sfb->fb.screen_base) {
744 "%s: unable to map screen memory\n", sfb->fb.fix.id);
752 * Unmap in the screen memory
755 static void smtc_unmap_smem(struct smtcfb_info *sfb)
757 if (sfb && sfb->fb.screen_base) {
758 iounmap(sfb->fb.screen_base);
759 sfb->fb.screen_base = NULL;
764 * We need to wake up the LynxEM+, and make sure its in linear memory mode.
766 static inline void sm7xx_init_hw(void)
772 static void smtc_free_fb_info(struct smtcfb_info *sfb)
775 fb_alloc_cmap(&sfb->fb.cmap, 0, 0);
781 * sm712vga_setup - process command line options, get vga parameter
782 * @options: string of options
786 static int __init sm712vga_setup(char *options)
790 if (!options || !*options)
793 smtc_screen_info.lfb_width = 0;
794 smtc_screen_info.lfb_height = 0;
795 smtc_screen_info.lfb_depth = 0;
797 pr_debug("sm712vga_setup = %s\n", options);
800 index < ARRAY_SIZE(vesa_mode);
802 if (strstr(options, vesa_mode[index].mode_index)) {
803 smtc_screen_info.lfb_width = vesa_mode[index].lfb_width;
804 smtc_screen_info.lfb_height =
805 vesa_mode[index].lfb_height;
806 smtc_screen_info.lfb_depth = vesa_mode[index].lfb_depth;
813 __setup("vga=", sm712vga_setup);
815 static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
816 const struct pci_device_id *ent)
818 struct smtcfb_info *sfb;
819 u_long smem_size = 0x00800000; /* default 8MB */
822 unsigned long pFramebufferPhysical;
824 dev_info(&pdev->dev, "Silicon Motion display driver.");
826 err = pci_enable_device(pdev); /* enable SMTC chip */
830 sfb = smtc_alloc_fb_info(pdev, name);
835 sfb->chipID = ent->device;
836 sprintf(name, "sm%Xfb", sfb->chipID);
838 pci_set_drvdata(pdev, sfb);
842 /*get mode parameter from smtc_screen_info */
843 if (smtc_screen_info.lfb_width != 0) {
844 sfb->fb.var.xres = smtc_screen_info.lfb_width;
845 sfb->fb.var.yres = smtc_screen_info.lfb_height;
846 sfb->fb.var.bits_per_pixel = smtc_screen_info.lfb_depth;
848 /* default resolution 1024x600 16bit mode */
849 sfb->fb.var.xres = SCREEN_X_RES;
850 sfb->fb.var.yres = SCREEN_Y_RES;
851 sfb->fb.var.bits_per_pixel = SCREEN_BPP;
855 if (sfb->fb.var.bits_per_pixel == 24)
856 sfb->fb.var.bits_per_pixel = (smtc_screen_info.lfb_depth = 32);
858 /* Map address and memory detection */
859 pFramebufferPhysical = pci_resource_start(pdev, 0);
860 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chipRevID);
862 switch (sfb->chipID) {
865 sfb->fb.fix.mmio_start = pFramebufferPhysical + 0x00400000;
866 sfb->fb.fix.mmio_len = 0x00400000;
867 smem_size = SM712_VIDEOMEMORYSIZE;
869 sfb->m_pLFB = (smtc_VRAMBaseAddress =
870 ioremap(pFramebufferPhysical, 0x00c00000));
872 sfb->m_pLFB = (smtc_VRAMBaseAddress =
873 ioremap(pFramebufferPhysical, 0x00800000));
875 sfb->m_pMMIO = (smtc_RegBaseAddress =
876 smtc_VRAMBaseAddress + 0x00700000);
877 sfb->m_pDPR = smtc_VRAMBaseAddress + 0x00408000;
878 sfb->m_pVPR = sfb->m_pLFB + 0x0040c000;
880 if (sfb->fb.var.bits_per_pixel == 32) {
881 smtc_VRAMBaseAddress += 0x800000;
882 sfb->m_pLFB += 0x800000;
884 "smtc_VRAMBaseAddress=%p sfb->m_pLFB=%p",
885 smtc_VRAMBaseAddress, sfb->m_pLFB);
888 if (!smtc_RegBaseAddress) {
890 "%s: unable to map memory mapped IO!",
896 /* set MCLK = 14.31818 * (0x16 / 0x2) */
897 smtc_seqw(0x6a, 0x16);
898 smtc_seqw(0x6b, 0x02);
899 smtc_seqw(0x62, 0x3e);
900 /* enable PCI burst */
901 smtc_seqw(0x17, 0x20);
902 /* enable word swap */
904 if (sfb->fb.var.bits_per_pixel == 32)
905 smtc_seqw(0x17, 0x30);
909 sfb->fb.fix.mmio_start = pFramebufferPhysical;
910 sfb->fb.fix.mmio_len = 0x00200000;
911 smem_size = SM722_VIDEOMEMORYSIZE;
912 sfb->m_pDPR = ioremap(pFramebufferPhysical, 0x00a00000);
913 sfb->m_pLFB = (smtc_VRAMBaseAddress =
914 sfb->m_pDPR + 0x00200000);
915 sfb->m_pMMIO = (smtc_RegBaseAddress =
916 sfb->m_pDPR + 0x000c0000);
917 sfb->m_pVPR = sfb->m_pDPR + 0x800;
919 smtc_seqw(0x62, 0xff);
920 smtc_seqw(0x6a, 0x0d);
921 smtc_seqw(0x6b, 0x02);
925 "No valid Silicon Motion display chip was detected!");
930 /* can support 32 bpp */
931 if (15 == sfb->fb.var.bits_per_pixel)
932 sfb->fb.var.bits_per_pixel = 16;
934 sfb->fb.var.xres_virtual = sfb->fb.var.xres;
935 sfb->fb.var.yres_virtual = sfb->fb.var.yres;
936 err = smtc_map_smem(sfb, pdev, smem_size);
941 /* Primary display starting from 0 position */
942 sfb->BaseAddressInVRAM = 0;
944 err = register_framebuffer(&sfb->fb);
949 "Silicon Motion SM%X Rev%X primary display mode %dx%d-%d Init Complete.",
950 sfb->chipID, sfb->chipRevID, sfb->fb.var.xres,
951 sfb->fb.var.yres, sfb->fb.var.bits_per_pixel);
956 dev_err(&pdev->dev, "Silicon Motion, Inc. primary display init fail.");
958 smtc_unmap_smem(sfb);
959 smtc_unmap_mmio(sfb);
961 smtc_free_fb_info(sfb);
964 pci_disable_device(pdev);
970 static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
971 { PCI_DEVICE(0x126f, 0x710), },
972 { PCI_DEVICE(0x126f, 0x712), },
973 { PCI_DEVICE(0x126f, 0x720), },
978 static void __devexit smtcfb_pci_remove(struct pci_dev *pdev)
980 struct smtcfb_info *sfb;
982 sfb = pci_get_drvdata(pdev);
983 pci_set_drvdata(pdev, NULL);
984 smtc_unmap_smem(sfb);
985 smtc_unmap_mmio(sfb);
986 unregister_framebuffer(&sfb->fb);
987 smtc_free_fb_info(sfb);
991 static int smtcfb_pci_suspend(struct device *device)
993 struct pci_dev *pdev = to_pci_dev(device);
994 struct smtcfb_info *sfb;
996 sfb = pci_get_drvdata(pdev);
998 /* set the hw in sleep mode use externel clock and self memory refresh
999 * so that we can turn off internal PLLs later on
1001 smtc_seqw(0x20, (smtc_seqr(0x20) | 0xc0));
1002 smtc_seqw(0x69, (smtc_seqr(0x69) & 0xf7));
1005 fb_set_suspend(&sfb->fb, 1);
1008 /* additionally turn off all function blocks including internal PLLs */
1009 smtc_seqw(0x21, 0xff);
1014 static int smtcfb_pci_resume(struct device *device)
1016 struct pci_dev *pdev = to_pci_dev(device);
1017 struct smtcfb_info *sfb;
1019 sfb = pci_get_drvdata(pdev);
1021 /* reinit hardware */
1023 switch (sfb->chipID) {
1026 /* set MCLK = 14.31818 * (0x16 / 0x2) */
1027 smtc_seqw(0x6a, 0x16);
1028 smtc_seqw(0x6b, 0x02);
1029 smtc_seqw(0x62, 0x3e);
1030 /* enable PCI burst */
1031 smtc_seqw(0x17, 0x20);
1033 if (sfb->fb.var.bits_per_pixel == 32)
1034 smtc_seqw(0x17, 0x30);
1038 smtc_seqw(0x62, 0xff);
1039 smtc_seqw(0x6a, 0x0d);
1040 smtc_seqw(0x6b, 0x02);
1044 smtc_seqw(0x34, (smtc_seqr(0x34) | 0xc0));
1045 smtc_seqw(0x33, ((smtc_seqr(0x33) | 0x08) & 0xfb));
1047 smtcfb_setmode(sfb);
1050 fb_set_suspend(&sfb->fb, 0);
1056 static const struct dev_pm_ops sm7xx_pm_ops = {
1057 .suspend = smtcfb_pci_suspend,
1058 .resume = smtcfb_pci_resume,
1059 .freeze = smtcfb_pci_suspend,
1060 .thaw = smtcfb_pci_resume,
1061 .poweroff = smtcfb_pci_suspend,
1062 .restore = smtcfb_pci_resume,
1065 #define SM7XX_PM_OPS (&sm7xx_pm_ops)
1067 #else /* !CONFIG_PM */
1069 #define SM7XX_PM_OPS NULL
1071 #endif /* !CONFIG_PM */
1073 static struct pci_driver smtcfb_driver = {
1075 .id_table = smtcfb_pci_table,
1076 .probe = smtcfb_pci_probe,
1077 .remove = __devexit_p(smtcfb_pci_remove),
1078 .driver.pm = SM7XX_PM_OPS,
1081 static int __init smtcfb_init(void)
1083 return pci_register_driver(&smtcfb_driver);
1086 static void __exit smtcfb_exit(void)
1088 pci_unregister_driver(&smtcfb_driver);
1091 module_init(smtcfb_init);
1092 module_exit(smtcfb_exit);
1094 MODULE_AUTHOR("Siliconmotion ");
1095 MODULE_DESCRIPTION("Framebuffer driver for SMI Graphic Cards");
1096 MODULE_LICENSE("GPL");