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
18 * Framebuffer driver for Silicon Motion SM710, SM712, SM721 and SM722 chips
23 #include <linux/pci.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/uaccess.h>
27 #include <linux/module.h>
28 #include <linux/console.h>
29 #include <linux/screen_info.h>
37 struct screen_info smtc_screen_info;
48 unsigned char __iomem *m_pMMIO;
59 struct vesa_mode_table {
66 static struct vesa_mode_table vesa_mode[] = {
67 {"0x301", 640, 480, 8},
68 {"0x303", 800, 600, 8},
69 {"0x305", 1024, 768, 8},
70 {"0x307", 1280, 1024, 8},
72 {"0x311", 640, 480, 16},
73 {"0x314", 800, 600, 16},
74 {"0x317", 1024, 768, 16},
75 {"0x31A", 1280, 1024, 16},
77 {"0x312", 640, 480, 24},
78 {"0x315", 800, 600, 24},
79 {"0x318", 1024, 768, 24},
80 {"0x31B", 1280, 1024, 24},
83 char __iomem *smtc_RegBaseAddress; /* Memory Map IO starting address */
84 char __iomem *smtc_VRAMBaseAddress; /* video memory starting address */
86 static u32 colreg[17];
88 static struct fb_var_screeninfo smtcfb_var = {
97 .activate = FB_ACTIVATE_NOW,
100 .vmode = FB_VMODE_NONINTERLACED,
103 static struct fb_fix_screeninfo smtcfb_fix = {
105 .type = FB_TYPE_PACKED_PIXELS,
106 .visual = FB_VISUAL_TRUECOLOR,
107 .line_length = 800 * 3,
108 .accel = FB_ACCEL_SMI_LYNX,
111 static void sm712_set_timing(struct smtcfb_info *sfb)
116 dev_dbg(&sfb->pdev->dev,
117 "sfb->width=%d sfb->height=%d "
118 "sfb->fb.var.bits_per_pixel=%d sfb->hz=%d\n",
119 sfb->width, sfb->height, sfb->fb.var.bits_per_pixel, sfb->hz);
121 for (j = 0; j < numVGAModes; j++) {
122 if (VGAMode[j].mmSizeX == sfb->width &&
123 VGAMode[j].mmSizeY == sfb->height &&
124 VGAMode[j].bpp == sfb->fb.var.bits_per_pixel &&
125 VGAMode[j].hz == sfb->hz) {
127 dev_dbg(&sfb->pdev->dev,
128 "VGAMode[j].mmSizeX=%d VGAMode[j].mmSizeY=%d "
129 "VGAMode[j].bpp=%d VGAMode[j].hz=%d\n",
130 VGAMode[j].mmSizeX, VGAMode[j].mmSizeY,
131 VGAMode[j].bpp, VGAMode[j].hz);
133 dev_dbg(&sfb->pdev->dev, "VGAMode index=%d\n", j);
135 smtc_mmiowb(0x0, 0x3c6);
139 smtc_mmiowb(VGAMode[j].Init_MISC, 0x3c2);
141 /* init SEQ register SR00 - SR04 */
142 for (i = 0; i < SIZE_SR00_SR04; i++)
143 smtc_seqw(i, VGAMode[j].Init_SR00_SR04[i]);
145 /* init SEQ register SR10 - SR24 */
146 for (i = 0; i < SIZE_SR10_SR24; i++)
148 VGAMode[j].Init_SR10_SR24[i]);
150 /* init SEQ register SR30 - SR75 */
151 for (i = 0; i < SIZE_SR30_SR75; i++)
152 if (((i + 0x30) != 0x62) \
153 && ((i + 0x30) != 0x6a) \
154 && ((i + 0x30) != 0x6b))
156 VGAMode[j].Init_SR30_SR75[i]);
158 /* init SEQ register SR80 - SR93 */
159 for (i = 0; i < SIZE_SR80_SR93; i++)
161 VGAMode[j].Init_SR80_SR93[i]);
163 /* init SEQ register SRA0 - SRAF */
164 for (i = 0; i < SIZE_SRA0_SRAF; i++)
166 VGAMode[j].Init_SRA0_SRAF[i]);
168 /* init Graphic register GR00 - GR08 */
169 for (i = 0; i < SIZE_GR00_GR08; i++)
170 smtc_grphw(i, VGAMode[j].Init_GR00_GR08[i]);
172 /* init Attribute register AR00 - AR14 */
173 for (i = 0; i < SIZE_AR00_AR14; i++)
174 smtc_attrw(i, VGAMode[j].Init_AR00_AR14[i]);
176 /* init CRTC register CR00 - CR18 */
177 for (i = 0; i < SIZE_CR00_CR18; i++)
178 smtc_crtcw(i, VGAMode[j].Init_CR00_CR18[i]);
180 /* init CRTC register CR30 - CR4D */
181 for (i = 0; i < SIZE_CR30_CR4D; i++)
183 VGAMode[j].Init_CR30_CR4D[i]);
185 /* init CRTC register CR90 - CRA7 */
186 for (i = 0; i < SIZE_CR90_CRA7; i++)
188 VGAMode[j].Init_CR90_CRA7[i]);
191 smtc_mmiowb(0x67, 0x3c2);
193 /* set VPR registers */
194 writel(0x0, sfb->m_pVPR + 0x0C);
195 writel(0x0, sfb->m_pVPR + 0x40);
199 (sfb->width * sfb->fb.var.bits_per_pixel) / 64;
200 switch (sfb->fb.var.bits_per_pixel) {
202 writel(0x0, sfb->m_pVPR + 0x0);
205 writel(0x00020000, sfb->m_pVPR + 0x0);
208 writel(0x00040000, sfb->m_pVPR + 0x0);
211 writel(0x00030000, sfb->m_pVPR + 0x0);
214 writel((u32) (((m_nScreenStride + 2) << 16) | m_nScreenStride),
219 static void sm712_setpalette(int regno, unsigned red, unsigned green,
220 unsigned blue, struct fb_info *info)
222 /* set bit 5:4 = 01 (write LCD RAM only) */
223 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x10);
225 smtc_mmiowb(regno, dac_reg);
226 smtc_mmiowb(red >> 10, dac_val);
227 smtc_mmiowb(green >> 10, dac_val);
228 smtc_mmiowb(blue >> 10, dac_val);
231 static void smtc_set_timing(struct smtcfb_info *sfb)
233 switch (sfb->chip_id) {
237 sm712_set_timing(sfb);
244 * convert a colour value into a field position
249 static inline unsigned int chan_to_field(unsigned int chan,
250 struct fb_bitfield *bf)
253 chan >>= 16 - bf->length;
254 return chan << bf->offset;
257 static int smtc_blank(int blank_mode, struct fb_info *info)
259 /* clear DPMS setting */
260 switch (blank_mode) {
261 case FB_BLANK_UNBLANK:
262 /* Screen On: HSync: On, VSync : On */
263 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
264 smtc_seqw(0x6a, 0x16);
265 smtc_seqw(0x6b, 0x02);
266 smtc_seqw(0x21, (smtc_seqr(0x21) & 0x77));
267 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
268 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
269 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
270 smtc_seqw(0x31, (smtc_seqr(0x31) | 0x03));
272 case FB_BLANK_NORMAL:
273 /* Screen Off: HSync: On, VSync : On Soft blank */
274 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
275 smtc_seqw(0x6a, 0x16);
276 smtc_seqw(0x6b, 0x02);
277 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
278 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
279 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
280 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
282 case FB_BLANK_VSYNC_SUSPEND:
283 /* Screen On: HSync: On, VSync : Off */
284 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
285 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
286 smtc_seqw(0x6a, 0x0c);
287 smtc_seqw(0x6b, 0x02);
288 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
289 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x20));
290 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0x20));
291 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
292 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
293 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
295 case FB_BLANK_HSYNC_SUSPEND:
296 /* Screen On: HSync: Off, VSync : On */
297 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
298 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
299 smtc_seqw(0x6a, 0x0c);
300 smtc_seqw(0x6b, 0x02);
301 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
302 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x10));
303 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
304 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
305 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
306 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
308 case FB_BLANK_POWERDOWN:
309 /* Screen On: HSync: Off, VSync : Off */
310 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
311 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
312 smtc_seqw(0x6a, 0x0c);
313 smtc_seqw(0x6b, 0x02);
314 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
315 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x30));
316 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
317 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
318 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
319 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
328 static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green,
329 unsigned blue, unsigned trans, struct fb_info *info)
331 struct smtcfb_info *sfb;
339 switch (sfb->fb.fix.visual) {
340 case FB_VISUAL_DIRECTCOLOR:
341 case FB_VISUAL_TRUECOLOR:
343 * 16/32 bit true-colour, use pseudo-palette for 16 base color
346 if (sfb->fb.var.bits_per_pixel == 16) {
347 u32 *pal = sfb->fb.pseudo_palette;
348 val = chan_to_field(red, &sfb->fb.var.red);
349 val |= chan_to_field(green, \
351 val |= chan_to_field(blue, &sfb->fb.var.blue);
354 ((red & 0xf800) >> 8) |
355 ((green & 0xe000) >> 13) |
356 ((green & 0x1c00) << 3) |
357 ((blue & 0xf800) >> 3);
362 u32 *pal = sfb->fb.pseudo_palette;
363 val = chan_to_field(red, &sfb->fb.var.red);
364 val |= chan_to_field(green, \
366 val |= chan_to_field(blue, &sfb->fb.var.blue);
369 (val & 0xff00ff00 >> 8) |
370 (val & 0x00ff00ff << 8);
377 case FB_VISUAL_PSEUDOCOLOR:
378 /* color depth 8 bit */
379 sm712_setpalette(regno, red, green, blue, info);
383 return 1; /* unknown type */
391 static ssize_t smtcfb_read(struct fb_info *info, char __user *buf, size_t
394 unsigned long p = *ppos;
398 int c, i, cnt = 0, err = 0;
399 unsigned long total_size;
401 if (!info || !info->screen_base)
404 if (info->state != FBINFO_STATE_RUNNING)
407 total_size = info->screen_size;
410 total_size = info->fix.smem_len;
415 if (count >= total_size)
418 if (count + p > total_size)
419 count = total_size - p;
421 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
425 src = (u32 __iomem *) (info->screen_base + p);
427 if (info->fbops->fb_sync)
428 info->fbops->fb_sync(info);
431 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
433 for (i = c >> 2; i--;) {
434 *dst = fb_readl(src++);
436 (*dst & 0xff00ff00 >> 8) |
437 (*dst & 0x00ff00ff << 8);
441 u8 *dst8 = (u8 *) dst;
442 u8 __iomem *src8 = (u8 __iomem *) src;
444 for (i = c & 3; i--;) {
446 *dst8++ = fb_readb(++src8);
448 *dst8++ = fb_readb(--src8);
452 src = (u32 __iomem *) src8;
455 if (copy_to_user(buf, buffer, c)) {
467 return (err) ? err : cnt;
471 smtcfb_write(struct fb_info *info, const char __user *buf, size_t count,
474 unsigned long p = *ppos;
478 int c, i, cnt = 0, err = 0;
479 unsigned long total_size;
481 if (!info || !info->screen_base)
484 if (info->state != FBINFO_STATE_RUNNING)
487 total_size = info->screen_size;
490 total_size = info->fix.smem_len;
495 if (count > total_size) {
500 if (count + p > total_size) {
504 count = total_size - p;
507 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
511 dst = (u32 __iomem *) (info->screen_base + p);
513 if (info->fbops->fb_sync)
514 info->fbops->fb_sync(info);
517 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
520 if (copy_from_user(src, buf, c)) {
525 for (i = c >> 2; i--;) {
526 fb_writel((*src & 0xff00ff00 >> 8) |
527 (*src & 0x00ff00ff << 8), dst++);
531 u8 *src8 = (u8 *) src;
532 u8 __iomem *dst8 = (u8 __iomem *) dst;
534 for (i = c & 3; i--;) {
536 fb_writeb(*src8++, ++dst8);
538 fb_writeb(*src8++, --dst8);
542 dst = (u32 __iomem *) dst8;
553 return (cnt) ? cnt : err;
555 #endif /* ! __BIG_ENDIAN */
557 void smtcfb_setmode(struct smtcfb_info *sfb)
559 switch (sfb->fb.var.bits_per_pixel) {
561 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
562 sfb->fb.fix.line_length = sfb->fb.var.xres * 4;
563 sfb->fb.var.red.length = 8;
564 sfb->fb.var.green.length = 8;
565 sfb->fb.var.blue.length = 8;
566 sfb->fb.var.red.offset = 16;
567 sfb->fb.var.green.offset = 8;
568 sfb->fb.var.blue.offset = 0;
571 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
572 sfb->fb.fix.line_length = sfb->fb.var.xres * 3;
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;
581 sfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
582 sfb->fb.fix.line_length = sfb->fb.var.xres;
583 sfb->fb.var.red.length = 3;
584 sfb->fb.var.green.length = 3;
585 sfb->fb.var.blue.length = 2;
586 sfb->fb.var.red.offset = 5;
587 sfb->fb.var.green.offset = 2;
588 sfb->fb.var.blue.offset = 0;
592 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
593 sfb->fb.fix.line_length = sfb->fb.var.xres * 2;
594 sfb->fb.var.red.length = 5;
595 sfb->fb.var.green.length = 6;
596 sfb->fb.var.blue.length = 5;
597 sfb->fb.var.red.offset = 11;
598 sfb->fb.var.green.offset = 5;
599 sfb->fb.var.blue.offset = 0;
603 sfb->width = sfb->fb.var.xres;
604 sfb->height = sfb->fb.var.yres;
606 smtc_set_timing(sfb);
609 static int smtc_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
612 if (var->xres_virtual < var->xres)
613 var->xres_virtual = var->xres;
615 if (var->yres_virtual < var->yres)
616 var->yres_virtual = var->yres;
618 /* set valid default bpp */
619 if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16) &&
620 (var->bits_per_pixel != 24) && (var->bits_per_pixel != 32))
621 var->bits_per_pixel = 16;
626 static int smtc_set_par(struct fb_info *info)
628 smtcfb_setmode(info->par);
633 static struct fb_ops smtcfb_ops = {
634 .owner = THIS_MODULE,
635 .fb_check_var = smtc_check_var,
636 .fb_set_par = smtc_set_par,
637 .fb_setcolreg = smtc_setcolreg,
638 .fb_blank = smtc_blank,
639 .fb_fillrect = cfb_fillrect,
640 .fb_imageblit = cfb_imageblit,
641 .fb_copyarea = cfb_copyarea,
643 .fb_read = smtcfb_read,
644 .fb_write = smtcfb_write,
649 * Alloc struct smtcfb_info and assign the default value
651 static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *pdev, char *name)
653 struct smtcfb_info *sfb;
655 sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);
662 /*** Init sfb->fb with default value ***/
663 sfb->fb.flags = FBINFO_FLAG_DEFAULT;
664 sfb->fb.fbops = &smtcfb_ops;
665 sfb->fb.var = smtcfb_var;
666 sfb->fb.fix = smtcfb_fix;
668 strcpy(sfb->fb.fix.id, name);
670 sfb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
671 sfb->fb.fix.type_aux = 0;
672 sfb->fb.fix.xpanstep = 0;
673 sfb->fb.fix.ypanstep = 0;
674 sfb->fb.fix.ywrapstep = 0;
675 sfb->fb.fix.accel = FB_ACCEL_SMI_LYNX;
677 sfb->fb.var.nonstd = 0;
678 sfb->fb.var.activate = FB_ACTIVATE_NOW;
679 sfb->fb.var.height = -1;
680 sfb->fb.var.width = -1;
681 /* text mode acceleration */
682 sfb->fb.var.accel_flags = FB_ACCELF_TEXT;
683 sfb->fb.var.vmode = FB_VMODE_NONINTERLACED;
687 sfb->fb.pseudo_palette = colreg;
693 * free struct smtcfb_info
695 static void smtc_free_fb_info(struct smtcfb_info *sfb)
701 * Unmap in the memory mapped IO registers
704 static void smtc_unmap_mmio(struct smtcfb_info *sfb)
706 if (sfb && smtc_RegBaseAddress)
707 smtc_RegBaseAddress = NULL;
711 * Map in the screen memory
714 static int smtc_map_smem(struct smtcfb_info *sfb,
715 struct pci_dev *pdev, u_long smem_len)
718 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
721 if (sfb->fb.var.bits_per_pixel == 32)
722 sfb->fb.fix.smem_start += 0x800000;
725 sfb->fb.fix.smem_len = smem_len;
727 sfb->fb.screen_base = smtc_VRAMBaseAddress;
729 if (!sfb->fb.screen_base) {
731 "%s: unable to map screen memory\n", sfb->fb.fix.id);
739 * Unmap in the screen memory
742 static void smtc_unmap_smem(struct smtcfb_info *sfb)
744 if (sfb && sfb->fb.screen_base) {
745 iounmap(sfb->fb.screen_base);
746 sfb->fb.screen_base = NULL;
751 * We need to wake up the device and make sure its in linear memory mode.
753 static inline void sm7xx_init_hw(void)
760 * sm712vga_setup - process command line options, get vga parameter
761 * @options: string of options
765 static int __init sm712vga_setup(char *options)
769 if (!options || !*options)
772 smtc_screen_info.lfb_width = 0;
773 smtc_screen_info.lfb_height = 0;
774 smtc_screen_info.lfb_depth = 0;
776 pr_debug("sm712vga_setup = %s\n", options);
779 index < ARRAY_SIZE(vesa_mode);
781 if (strstr(options, vesa_mode[index].mode_index)) {
782 smtc_screen_info.lfb_width = vesa_mode[index].lfb_width;
783 smtc_screen_info.lfb_height =
784 vesa_mode[index].lfb_height;
785 smtc_screen_info.lfb_depth = vesa_mode[index].lfb_depth;
792 __setup("vga=", sm712vga_setup);
794 static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
795 const struct pci_device_id *ent)
797 struct smtcfb_info *sfb;
798 u_long smem_size = 0x00800000; /* default 8MB */
801 unsigned long pFramebufferPhysical;
803 dev_info(&pdev->dev, "Silicon Motion display driver.");
805 err = pci_enable_device(pdev); /* enable SMTC chip */
809 sfb = smtc_alloc_fb_info(pdev, name);
814 sfb->chip_id = ent->device;
815 sprintf(name, "sm%Xfb", sfb->chip_id);
817 pci_set_drvdata(pdev, sfb);
821 /*get mode parameter from smtc_screen_info */
822 if (smtc_screen_info.lfb_width != 0) {
823 sfb->fb.var.xres = smtc_screen_info.lfb_width;
824 sfb->fb.var.yres = smtc_screen_info.lfb_height;
825 sfb->fb.var.bits_per_pixel = smtc_screen_info.lfb_depth;
827 /* default resolution 1024x600 16bit mode */
828 sfb->fb.var.xres = SCREEN_X_RES;
829 sfb->fb.var.yres = SCREEN_Y_RES;
830 sfb->fb.var.bits_per_pixel = SCREEN_BPP;
834 if (sfb->fb.var.bits_per_pixel == 24)
835 sfb->fb.var.bits_per_pixel = (smtc_screen_info.lfb_depth = 32);
837 /* Map address and memory detection */
838 pFramebufferPhysical = pci_resource_start(pdev, 0);
839 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chip_rev_id);
841 switch (sfb->chip_id) {
844 sfb->fb.fix.mmio_start = pFramebufferPhysical + 0x00400000;
845 sfb->fb.fix.mmio_len = 0x00400000;
846 smem_size = SM712_VIDEOMEMORYSIZE;
848 sfb->m_pLFB = (smtc_VRAMBaseAddress =
849 ioremap(pFramebufferPhysical, 0x00c00000));
851 sfb->m_pLFB = (smtc_VRAMBaseAddress =
852 ioremap(pFramebufferPhysical, 0x00800000));
854 sfb->m_pMMIO = (smtc_RegBaseAddress =
855 smtc_VRAMBaseAddress + 0x00700000);
856 sfb->m_pDPR = smtc_VRAMBaseAddress + 0x00408000;
857 sfb->m_pVPR = sfb->m_pLFB + 0x0040c000;
859 if (sfb->fb.var.bits_per_pixel == 32) {
860 smtc_VRAMBaseAddress += 0x800000;
861 sfb->m_pLFB += 0x800000;
863 "smtc_VRAMBaseAddress=%p sfb->m_pLFB=%p",
864 smtc_VRAMBaseAddress, sfb->m_pLFB);
867 if (!smtc_RegBaseAddress) {
869 "%s: unable to map memory mapped IO!",
875 /* set MCLK = 14.31818 * (0x16 / 0x2) */
876 smtc_seqw(0x6a, 0x16);
877 smtc_seqw(0x6b, 0x02);
878 smtc_seqw(0x62, 0x3e);
879 /* enable PCI burst */
880 smtc_seqw(0x17, 0x20);
881 /* enable word swap */
883 if (sfb->fb.var.bits_per_pixel == 32)
884 smtc_seqw(0x17, 0x30);
888 sfb->fb.fix.mmio_start = pFramebufferPhysical;
889 sfb->fb.fix.mmio_len = 0x00200000;
890 smem_size = SM722_VIDEOMEMORYSIZE;
891 sfb->m_pDPR = ioremap(pFramebufferPhysical, 0x00a00000);
892 sfb->m_pLFB = (smtc_VRAMBaseAddress =
893 sfb->m_pDPR + 0x00200000);
894 sfb->m_pMMIO = (smtc_RegBaseAddress =
895 sfb->m_pDPR + 0x000c0000);
896 sfb->m_pVPR = sfb->m_pDPR + 0x800;
898 smtc_seqw(0x62, 0xff);
899 smtc_seqw(0x6a, 0x0d);
900 smtc_seqw(0x6b, 0x02);
904 "No valid Silicon Motion display chip was detected!");
909 /* can support 32 bpp */
910 if (15 == sfb->fb.var.bits_per_pixel)
911 sfb->fb.var.bits_per_pixel = 16;
913 sfb->fb.var.xres_virtual = sfb->fb.var.xres;
914 sfb->fb.var.yres_virtual = sfb->fb.var.yres;
915 err = smtc_map_smem(sfb, pdev, smem_size);
921 err = register_framebuffer(&sfb->fb);
926 "Silicon Motion SM%X Rev%X primary display mode %dx%d-%d Init Complete.",
927 sfb->chip_id, sfb->chip_rev_id, sfb->fb.var.xres,
928 sfb->fb.var.yres, sfb->fb.var.bits_per_pixel);
933 dev_err(&pdev->dev, "Silicon Motion, Inc. primary display init fail.");
935 smtc_unmap_smem(sfb);
936 smtc_unmap_mmio(sfb);
938 smtc_free_fb_info(sfb);
941 pci_disable_device(pdev);
949 * 0x720 (Lynx3DM, Lynx3DM+)
951 static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
952 { PCI_DEVICE(0x126f, 0x710), },
953 { PCI_DEVICE(0x126f, 0x712), },
954 { PCI_DEVICE(0x126f, 0x720), },
958 static void __devexit smtcfb_pci_remove(struct pci_dev *pdev)
960 struct smtcfb_info *sfb;
962 sfb = pci_get_drvdata(pdev);
963 pci_set_drvdata(pdev, NULL);
964 smtc_unmap_smem(sfb);
965 smtc_unmap_mmio(sfb);
966 unregister_framebuffer(&sfb->fb);
967 smtc_free_fb_info(sfb);
971 static int smtcfb_pci_suspend(struct device *device)
973 struct pci_dev *pdev = to_pci_dev(device);
974 struct smtcfb_info *sfb;
976 sfb = pci_get_drvdata(pdev);
978 /* set the hw in sleep mode use external clock and self memory refresh
979 * so that we can turn off internal PLLs later on
981 smtc_seqw(0x20, (smtc_seqr(0x20) | 0xc0));
982 smtc_seqw(0x69, (smtc_seqr(0x69) & 0xf7));
985 fb_set_suspend(&sfb->fb, 1);
988 /* additionally turn off all function blocks including internal PLLs */
989 smtc_seqw(0x21, 0xff);
994 static int smtcfb_pci_resume(struct device *device)
996 struct pci_dev *pdev = to_pci_dev(device);
997 struct smtcfb_info *sfb;
999 sfb = pci_get_drvdata(pdev);
1001 /* reinit hardware */
1003 switch (sfb->chip_id) {
1006 /* set MCLK = 14.31818 * (0x16 / 0x2) */
1007 smtc_seqw(0x6a, 0x16);
1008 smtc_seqw(0x6b, 0x02);
1009 smtc_seqw(0x62, 0x3e);
1010 /* enable PCI burst */
1011 smtc_seqw(0x17, 0x20);
1013 if (sfb->fb.var.bits_per_pixel == 32)
1014 smtc_seqw(0x17, 0x30);
1018 smtc_seqw(0x62, 0xff);
1019 smtc_seqw(0x6a, 0x0d);
1020 smtc_seqw(0x6b, 0x02);
1024 smtc_seqw(0x34, (smtc_seqr(0x34) | 0xc0));
1025 smtc_seqw(0x33, ((smtc_seqr(0x33) | 0x08) & 0xfb));
1027 smtcfb_setmode(sfb);
1030 fb_set_suspend(&sfb->fb, 0);
1036 static const struct dev_pm_ops sm7xx_pm_ops = {
1037 .suspend = smtcfb_pci_suspend,
1038 .resume = smtcfb_pci_resume,
1039 .freeze = smtcfb_pci_suspend,
1040 .thaw = smtcfb_pci_resume,
1041 .poweroff = smtcfb_pci_suspend,
1042 .restore = smtcfb_pci_resume,
1045 #define SM7XX_PM_OPS (&sm7xx_pm_ops)
1047 #else /* !CONFIG_PM */
1049 #define SM7XX_PM_OPS NULL
1051 #endif /* !CONFIG_PM */
1053 static struct pci_driver smtcfb_driver = {
1055 .id_table = smtcfb_pci_table,
1056 .probe = smtcfb_pci_probe,
1057 .remove = __devexit_p(smtcfb_pci_remove),
1058 .driver.pm = SM7XX_PM_OPS,
1061 static int __init smtcfb_init(void)
1063 return pci_register_driver(&smtcfb_driver);
1066 static void __exit smtcfb_exit(void)
1068 pci_unregister_driver(&smtcfb_driver);
1071 module_init(smtcfb_init);
1072 module_exit(smtcfb_exit);
1074 MODULE_AUTHOR("Siliconmotion ");
1075 MODULE_DESCRIPTION("Framebuffer driver for SMI Graphic Cards");
1076 MODULE_LICENSE("GPL");