blob: 2c172d6cd65fa3efce611ae02c00580dec7d6976 [file] [log] [blame]
Wu Zhangjind7edf472009-11-23 10:28:24 +08001/*
2 * Silicon Motion SM7XX frame buffer device
3 *
4 * Copyright (C) 2006 Silicon Motion Technology Corp.
Javier M. Mellid86f31252012-04-26 20:45:49 +02005 * Authors: Ge Wang, gewang@siliconmotion.com
6 * Boyod boyod.yang@siliconmotion.com.cn
Wu Zhangjind7edf472009-11-23 10:28:24 +08007 *
8 * Copyright (C) 2009 Lemote, Inc.
Javier M. Mellid86f31252012-04-26 20:45:49 +02009 * Author: Wu Zhangjin, wuzhangjin@gmail.com
Wu Zhangjind7edf472009-11-23 10:28:24 +080010 *
Javier M. Melliddc762c42011-05-07 03:11:58 +020011 * Copyright (C) 2011 Igalia, S.L.
Javier M. Mellid86f31252012-04-26 20:45:49 +020012 * Author: Javier M. Mellid <jmunhoz@igalia.com>
Javier M. Melliddc762c42011-05-07 03:11:58 +020013 *
Javier M. Mellid86f31252012-04-26 20:45:49 +020014 * 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
16 * more details.
Wu Zhangjind7edf472009-11-23 10:28:24 +080017 *
Wu Zhangjind7edf472009-11-23 10:28:24 +080018 */
19
Wu Zhangjind7edf472009-11-23 10:28:24 +080020#include <linux/io.h>
21#include <linux/fb.h>
22#include <linux/pci.h>
23#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Wu Zhangjind7edf472009-11-23 10:28:24 +080025#include <linux/uaccess.h>
Paul Gortmaker99c97852011-07-03 15:49:50 -040026#include <linux/module.h>
Wu Zhangjind7edf472009-11-23 10:28:24 +080027#include <linux/console.h>
28#include <linux/screen_info.h>
29
30#ifdef CONFIG_PM
31#include <linux/pm.h>
32#endif
33
Wu Zhangjind7edf472009-11-23 10:28:24 +080034#include "smtcfb.h"
Wu Zhangjind7edf472009-11-23 10:28:24 +080035
Javier M. Melliddc762c42011-05-07 03:11:58 +020036struct screen_info smtc_screen_info;
37
Wu Zhangjind7edf472009-11-23 10:28:24 +080038/*
39* Private structure
40*/
41struct smtcfb_info {
Wu Zhangjind7edf472009-11-23 10:28:24 +080042 struct fb_info fb;
Javier M. Mellid9be467d2012-04-26 20:45:53 +020043 struct pci_dev *pdev;
Wu Zhangjind7edf472009-11-23 10:28:24 +080044 struct {
45 u8 red, green, blue;
46 } palette[NR_RGB];
Wu Zhangjind7edf472009-11-23 10:28:24 +080047 u_int palette_size;
Wu Zhangjind7edf472009-11-23 10:28:24 +080048
Wu Zhangjind7edf472009-11-23 10:28:24 +080049 u16 chipID;
50 unsigned char __iomem *m_pMMIO;
51 char __iomem *m_pLFB;
52 char *m_pDPR;
53 char *m_pVPR;
54 char *m_pCPR;
55
56 u_int width;
57 u_int height;
58 u_int hz;
59 u_long BaseAddressInVRAM;
60 u8 chipRevID;
61};
62
63struct vesa_mode_table {
64 char mode_index[6];
65 u16 lfb_width;
66 u16 lfb_height;
67 u16 lfb_depth;
68};
69
70static struct vesa_mode_table vesa_mode[] = {
71 {"0x301", 640, 480, 8},
72 {"0x303", 800, 600, 8},
Javier M. Mellid3b70a262011-04-30 17:44:26 +020073 {"0x305", 1024, 768, 8},
Wu Zhangjind7edf472009-11-23 10:28:24 +080074 {"0x307", 1280, 1024, 8},
75
76 {"0x311", 640, 480, 16},
77 {"0x314", 800, 600, 16},
Javier M. Mellid3b70a262011-04-30 17:44:26 +020078 {"0x317", 1024, 768, 16},
Wu Zhangjind7edf472009-11-23 10:28:24 +080079 {"0x31A", 1280, 1024, 16},
80
81 {"0x312", 640, 480, 24},
82 {"0x315", 800, 600, 24},
Javier M. Mellid3b70a262011-04-30 17:44:26 +020083 {"0x318", 1024, 768, 24},
Wu Zhangjind7edf472009-11-23 10:28:24 +080084 {"0x31B", 1280, 1024, 24},
85};
86
87char __iomem *smtc_RegBaseAddress; /* Memory Map IO starting address */
88char __iomem *smtc_VRAMBaseAddress; /* video memory starting address */
89
Wu Zhangjind7edf472009-11-23 10:28:24 +080090static u32 colreg[17];
Wu Zhangjind7edf472009-11-23 10:28:24 +080091
Javier M. Melliddc762c42011-05-07 03:11:58 +020092static struct fb_var_screeninfo smtcfb_var = {
93 .xres = 1024,
94 .yres = 600,
95 .xres_virtual = 1024,
96 .yres_virtual = 600,
97 .bits_per_pixel = 16,
98 .red = {16, 8, 0},
99 .green = {8, 8, 0},
100 .blue = {0, 8, 0},
101 .activate = FB_ACTIVATE_NOW,
102 .height = -1,
103 .width = -1,
104 .vmode = FB_VMODE_NONINTERLACED,
105};
106
107static struct fb_fix_screeninfo smtcfb_fix = {
108 .id = "sm712fb",
109 .type = FB_TYPE_PACKED_PIXELS,
110 .visual = FB_VISUAL_TRUECOLOR,
111 .line_length = 800 * 3,
112 .accel = FB_ACCEL_SMI_LYNX,
113};
114
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200115static void sm712_set_timing(struct smtcfb_info *sfb)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800116{
117 int i = 0, j = 0;
118 u32 m_nScreenStride;
119
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200120 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);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800124
125 for (j = 0; j < numVGAModes; j++) {
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200126 if (VGAMode[j].mmSizeX == sfb->width &&
127 VGAMode[j].mmSizeY == sfb->height &&
Wu Zhangjind7edf472009-11-23 10:28:24 +0800128 VGAMode[j].bpp == sfb->fb.var.bits_per_pixel &&
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200129 VGAMode[j].hz == sfb->hz) {
Wu Zhangjind7edf472009-11-23 10:28:24 +0800130
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200131 dev_dbg(&sfb->pdev->dev,
132 "VGAMode[j].mmSizeX=%d VGAMode[j].mmSizeY=%d "
Javier M. Mellidbfdd4032012-04-26 20:45:51 +0200133 "VGAMode[j].bpp=%d VGAMode[j].hz=%d\n",
134 VGAMode[j].mmSizeX, VGAMode[j].mmSizeY,
135 VGAMode[j].bpp, VGAMode[j].hz);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800136
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200137 dev_dbg(&sfb->pdev->dev, "VGAMode index=%d\n", j);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800138
139 smtc_mmiowb(0x0, 0x3c6);
140
141 smtc_seqw(0, 0x1);
142
143 smtc_mmiowb(VGAMode[j].Init_MISC, 0x3c2);
144
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]);
148
149 /* init SEQ register SR10 - SR24 */
150 for (i = 0; i < SIZE_SR10_SR24; i++)
151 smtc_seqw(i + 0x10,
152 VGAMode[j].Init_SR10_SR24[i]);
153
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))
159 smtc_seqw(i + 0x30,
160 VGAMode[j].Init_SR30_SR75[i]);
161
162 /* init SEQ register SR80 - SR93 */
163 for (i = 0; i < SIZE_SR80_SR93; i++)
164 smtc_seqw(i + 0x80,
165 VGAMode[j].Init_SR80_SR93[i]);
166
167 /* init SEQ register SRA0 - SRAF */
168 for (i = 0; i < SIZE_SRA0_SRAF; i++)
169 smtc_seqw(i + 0xa0,
170 VGAMode[j].Init_SRA0_SRAF[i]);
171
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]);
175
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]);
179
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]);
183
184 /* init CRTC register CR30 - CR4D */
185 for (i = 0; i < SIZE_CR30_CR4D; i++)
186 smtc_crtcw(i + 0x30,
187 VGAMode[j].Init_CR30_CR4D[i]);
188
189 /* init CRTC register CR90 - CRA7 */
190 for (i = 0; i < SIZE_CR90_CRA7; i++)
191 smtc_crtcw(i + 0x90,
192 VGAMode[j].Init_CR90_CRA7[i]);
193 }
194 }
195 smtc_mmiowb(0x67, 0x3c2);
196
197 /* set VPR registers */
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200198 writel(0x0, sfb->m_pVPR + 0x0C);
199 writel(0x0, sfb->m_pVPR + 0x40);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800200
201 /* set data width */
202 m_nScreenStride =
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200203 (sfb->width * sfb->fb.var.bits_per_pixel) / 64;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800204 switch (sfb->fb.var.bits_per_pixel) {
205 case 8:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200206 writel(0x0, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800207 break;
208 case 16:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200209 writel(0x00020000, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800210 break;
211 case 24:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200212 writel(0x00040000, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800213 break;
214 case 32:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200215 writel(0x00030000, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800216 break;
217 }
218 writel((u32) (((m_nScreenStride + 2) << 16) | m_nScreenStride),
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200219 sfb->m_pVPR + 0x10);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800220
221}
222
223static void sm712_setpalette(int regno, unsigned red, unsigned green,
224 unsigned blue, struct fb_info *info)
225{
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200226 struct smtcfb_info *sfb = info->par;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800227
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200228 if (sfb->BaseAddressInVRAM)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800229 /*
230 * second display palette for dual head. Enable CRT RAM, 6-bit
231 * RAM
232 */
233 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x20);
234 else
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);
241}
242
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200243static void smtc_set_timing(struct smtcfb_info *sfb)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800244{
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200245 switch (sfb->chipID) {
Wu Zhangjind7edf472009-11-23 10:28:24 +0800246 case 0x710:
247 case 0x712:
248 case 0x720:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200249 sm712_set_timing(sfb);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800250 break;
251 }
252}
253
Wu Zhangjind7edf472009-11-23 10:28:24 +0800254/* chan_to_field
255 *
256 * convert a colour value into a field position
257 *
258 * from pxafb.c
259 */
260
261static inline unsigned int chan_to_field(unsigned int chan,
262 struct fb_bitfield *bf)
263{
264 chan &= 0xffff;
265 chan >>= 16 - bf->length;
266 return chan << bf->offset;
267}
268
Javier M. Mellidacbaa0b2012-04-26 20:45:55 +0200269static int smtc_blank(int blank_mode, struct fb_info *info)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800270{
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));
283 break;
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));
293 break;
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));
306 break;
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));
319 break;
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));
332 break;
333 default:
334 return -EINVAL;
335 }
336
337 return 0;
338}
339
340static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green,
341 unsigned blue, unsigned trans, struct fb_info *info)
342{
343 struct smtcfb_info *sfb = (struct smtcfb_info *)info;
344 u32 val;
345
346 if (regno > 255)
347 return 1;
348
349 switch (sfb->fb.fix.visual) {
350 case FB_VISUAL_DIRECTCOLOR:
351 case FB_VISUAL_TRUECOLOR:
352 /*
353 * 16/32 bit true-colour, use pseuo-palette for 16 base color
354 */
355 if (regno < 16) {
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, \
360 &sfb->fb.var.green);
361 val |= chan_to_field(blue, &sfb->fb.var.blue);
362#ifdef __BIG_ENDIAN
363 pal[regno] =
364 ((red & 0xf800) >> 8) |
365 ((green & 0xe000) >> 13) |
366 ((green & 0x1c00) << 3) |
367 ((blue & 0xf800) >> 3);
368#else
369 pal[regno] = val;
370#endif
371 } else {
372 u32 *pal = sfb->fb.pseudo_palette;
373 val = chan_to_field(red, &sfb->fb.var.red);
374 val |= chan_to_field(green, \
375 &sfb->fb.var.green);
376 val |= chan_to_field(blue, &sfb->fb.var.blue);
377#ifdef __BIG_ENDIAN
378 val =
379 (val & 0xff00ff00 >> 8) |
380 (val & 0x00ff00ff << 8);
381#endif
382 pal[regno] = val;
383 }
384 }
385 break;
386
387 case FB_VISUAL_PSEUDOCOLOR:
388 /* color depth 8 bit */
389 sm712_setpalette(regno, red, green, blue, info);
390 break;
391
392 default:
393 return 1; /* unknown type */
394 }
395
396 return 0;
397
398}
399
400#ifdef __BIG_ENDIAN
Josenivaldo Benito Jrc8100d22012-02-12 19:03:14 -0200401static ssize_t smtcfb_read(struct fb_info *info, char __user *buf, size_t
Wu Zhangjind7edf472009-11-23 10:28:24 +0800402 count, loff_t *ppos)
403{
404 unsigned long p = *ppos;
405
406 u32 *buffer, *dst;
407 u32 __iomem *src;
408 int c, i, cnt = 0, err = 0;
409 unsigned long total_size;
410
411 if (!info || !info->screen_base)
412 return -ENODEV;
413
414 if (info->state != FBINFO_STATE_RUNNING)
415 return -EPERM;
416
417 total_size = info->screen_size;
418
419 if (total_size == 0)
420 total_size = info->fix.smem_len;
421
422 if (p >= total_size)
423 return 0;
424
425 if (count >= total_size)
426 count = total_size;
427
428 if (count + p > total_size)
429 count = total_size - p;
430
431 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
432 if (!buffer)
433 return -ENOMEM;
434
435 src = (u32 __iomem *) (info->screen_base + p);
436
437 if (info->fbops->fb_sync)
438 info->fbops->fb_sync(info);
439
440 while (count) {
441 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
442 dst = buffer;
443 for (i = c >> 2; i--;) {
444 *dst = fb_readl(src++);
445 *dst =
446 (*dst & 0xff00ff00 >> 8) |
447 (*dst & 0x00ff00ff << 8);
448 dst++;
449 }
450 if (c & 3) {
451 u8 *dst8 = (u8 *) dst;
452 u8 __iomem *src8 = (u8 __iomem *) src;
453
454 for (i = c & 3; i--;) {
455 if (i & 1) {
456 *dst8++ = fb_readb(++src8);
457 } else {
458 *dst8++ = fb_readb(--src8);
459 src8 += 2;
460 }
461 }
462 src = (u32 __iomem *) src8;
463 }
464
465 if (copy_to_user(buf, buffer, c)) {
466 err = -EFAULT;
467 break;
468 }
469 *ppos += c;
470 buf += c;
471 cnt += c;
472 count -= c;
473 }
474
475 kfree(buffer);
476
477 return (err) ? err : cnt;
478}
479
480static ssize_t
481smtcfb_write(struct fb_info *info, const char __user *buf, size_t count,
482 loff_t *ppos)
483{
484 unsigned long p = *ppos;
485
486 u32 *buffer, *src;
487 u32 __iomem *dst;
488 int c, i, cnt = 0, err = 0;
489 unsigned long total_size;
490
491 if (!info || !info->screen_base)
492 return -ENODEV;
493
494 if (info->state != FBINFO_STATE_RUNNING)
495 return -EPERM;
496
497 total_size = info->screen_size;
498
499 if (total_size == 0)
500 total_size = info->fix.smem_len;
501
502 if (p > total_size)
503 return -EFBIG;
504
505 if (count > total_size) {
506 err = -EFBIG;
507 count = total_size;
508 }
509
510 if (count + p > total_size) {
511 if (!err)
512 err = -ENOSPC;
513
514 count = total_size - p;
515 }
516
517 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
518 if (!buffer)
519 return -ENOMEM;
520
521 dst = (u32 __iomem *) (info->screen_base + p);
522
523 if (info->fbops->fb_sync)
524 info->fbops->fb_sync(info);
525
526 while (count) {
527 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
528 src = buffer;
529
530 if (copy_from_user(src, buf, c)) {
531 err = -EFAULT;
532 break;
533 }
534
535 for (i = c >> 2; i--;) {
536 fb_writel((*src & 0xff00ff00 >> 8) |
537 (*src & 0x00ff00ff << 8), dst++);
538 src++;
539 }
540 if (c & 3) {
541 u8 *src8 = (u8 *) src;
542 u8 __iomem *dst8 = (u8 __iomem *) dst;
543
544 for (i = c & 3; i--;) {
545 if (i & 1) {
546 fb_writeb(*src8++, ++dst8);
547 } else {
548 fb_writeb(*src8++, --dst8);
549 dst8 += 2;
550 }
551 }
552 dst = (u32 __iomem *) dst8;
553 }
554
555 *ppos += c;
556 buf += c;
557 cnt += c;
558 count -= c;
559 }
560
561 kfree(buffer);
562
563 return (cnt) ? cnt : err;
564}
565#endif /* ! __BIG_ENDIAN */
566
Wu Zhangjind7edf472009-11-23 10:28:24 +0800567void smtcfb_setmode(struct smtcfb_info *sfb)
568{
569 switch (sfb->fb.var.bits_per_pixel) {
570 case 32:
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;
579
580 break;
581 case 8:
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;
590 break;
591 case 24:
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;
597
598 sfb->fb.var.red.offset = 16;
599 sfb->fb.var.green.offset = 8;
600 sfb->fb.var.blue.offset = 0;
601
602 break;
603 case 16:
604 default:
605 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
606 sfb->fb.fix.line_length = sfb->fb.var.xres * 2;
607
608 sfb->fb.var.red.length = 5;
609 sfb->fb.var.green.length = 6;
610 sfb->fb.var.blue.length = 5;
611
612 sfb->fb.var.red.offset = 11;
613 sfb->fb.var.green.offset = 5;
614 sfb->fb.var.blue.offset = 0;
615
616 break;
617 }
618
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200619 sfb->width = sfb->fb.var.xres;
620 sfb->height = sfb->fb.var.yres;
621 sfb->hz = 60;
622 smtc_set_timing(sfb);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800623}
624
Javier M. Melliddc762c42011-05-07 03:11:58 +0200625static int smtc_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
626{
627 /* sanity checks */
628 if (var->xres_virtual < var->xres)
629 var->xres_virtual = var->xres;
630
631 if (var->yres_virtual < var->yres)
632 var->yres_virtual = var->yres;
633
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;
638
639 return 0;
640}
641
642static int smtc_set_par(struct fb_info *info)
643{
644 struct smtcfb_info *sfb = (struct smtcfb_info *)info;
645
646 smtcfb_setmode(sfb);
647
648 return 0;
649}
650
651static 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,
Javier M. Mellidacbaa0b2012-04-26 20:45:55 +0200656 .fb_blank = smtc_blank,
Javier M. Melliddc762c42011-05-07 03:11:58 +0200657 .fb_fillrect = cfb_fillrect,
658 .fb_imageblit = cfb_imageblit,
659 .fb_copyarea = cfb_copyarea,
660#ifdef __BIG_ENDIAN
661 .fb_read = smtcfb_read,
662 .fb_write = smtcfb_write,
663#endif
664};
665
Wu Zhangjind7edf472009-11-23 10:28:24 +0800666/*
667 * Alloc struct smtcfb_info and assign the default value
668 */
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200669static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *pdev, char *name)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800670{
671 struct smtcfb_info *sfb;
672
anish kumar617a0c72011-05-19 20:58:51 +0530673 sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800674
675 if (!sfb)
676 return NULL;
677
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200678 sfb->pdev = pdev;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800679
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;
685
686 strcpy(sfb->fb.fix.id, name);
687
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;
694
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;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200702
703 sfb->fb.par = sfb;
704
Wu Zhangjind7edf472009-11-23 10:28:24 +0800705 sfb->fb.pseudo_palette = colreg;
706
707 return sfb;
708}
709
710/*
711 * Unmap in the memory mapped IO registers
712 */
713
714static void smtc_unmap_mmio(struct smtcfb_info *sfb)
715{
716 if (sfb && smtc_RegBaseAddress)
717 smtc_RegBaseAddress = NULL;
718}
719
720/*
721 * Map in the screen memory
722 */
723
724static int smtc_map_smem(struct smtcfb_info *sfb,
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200725 struct pci_dev *pdev, u_long smem_len)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800726{
Javier M. Mellid67c4e9f2012-06-10 13:12:22 +0200727
728 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
729
Wu Zhangjind7edf472009-11-23 10:28:24 +0800730#ifdef __BIG_ENDIAN
Javier M. Mellid67c4e9f2012-06-10 13:12:22 +0200731 if (sfb->fb.var.bits_per_pixel == 32)
732 sfb->fb.fix.smem_start += 0x800000;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800733#endif
Wu Zhangjind7edf472009-11-23 10:28:24 +0800734
735 sfb->fb.fix.smem_len = smem_len;
736
737 sfb->fb.screen_base = smtc_VRAMBaseAddress;
738
739 if (!sfb->fb.screen_base) {
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200740 dev_err(&pdev->dev,
741 "%s: unable to map screen memory\n", sfb->fb.fix.id);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800742 return -ENOMEM;
743 }
744
745 return 0;
746}
747
748/*
749 * Unmap in the screen memory
750 *
751 */
752static void smtc_unmap_smem(struct smtcfb_info *sfb)
753{
754 if (sfb && sfb->fb.screen_base) {
755 iounmap(sfb->fb.screen_base);
756 sfb->fb.screen_base = NULL;
757 }
758}
759
760/*
761 * We need to wake up the LynxEM+, and make sure its in linear memory mode.
762 */
763static inline void sm7xx_init_hw(void)
764{
765 outb_p(0x18, 0x3c4);
766 outb_p(0x11, 0x3c5);
767}
768
769static void smtc_free_fb_info(struct smtcfb_info *sfb)
770{
771 if (sfb) {
772 fb_alloc_cmap(&sfb->fb.cmap, 0, 0);
773 kfree(sfb);
774 }
775}
776
777/*
778 * sm712vga_setup - process command line options, get vga parameter
779 * @options: string of options
780 * Returns zero.
781 *
782 */
Javier M. Melliddc762c42011-05-07 03:11:58 +0200783static int __init sm712vga_setup(char *options)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800784{
785 int index;
786
Javier M. Mellidbfdd4032012-04-26 20:45:51 +0200787 if (!options || !*options)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800788 return -EINVAL;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800789
790 smtc_screen_info.lfb_width = 0;
791 smtc_screen_info.lfb_height = 0;
792 smtc_screen_info.lfb_depth = 0;
793
Javier M. Mellidbfdd4032012-04-26 20:45:51 +0200794 pr_debug("sm712vga_setup = %s\n", options);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800795
796 for (index = 0;
anish kumar1639c8a2011-05-19 20:58:42 +0530797 index < ARRAY_SIZE(vesa_mode);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800798 index++) {
799 if (strstr(options, vesa_mode[index].mode_index)) {
800 smtc_screen_info.lfb_width = vesa_mode[index].lfb_width;
801 smtc_screen_info.lfb_height =
802 vesa_mode[index].lfb_height;
803 smtc_screen_info.lfb_depth = vesa_mode[index].lfb_depth;
804 return 0;
805 }
806 }
807
808 return -1;
809}
810__setup("vga=", sm712vga_setup);
811
Wu Zhangjinb99e1942010-07-18 03:16:28 +0800812static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
Wu Zhangjind7edf472009-11-23 10:28:24 +0800813 const struct pci_device_id *ent)
814{
815 struct smtcfb_info *sfb;
816 u_long smem_size = 0x00800000; /* default 8MB */
817 char name[16];
818 int err;
819 unsigned long pFramebufferPhysical;
820
Javier M. Mellid5c40fb32012-04-26 20:45:54 +0200821 dev_info(&pdev->dev, "Silicon Motion display driver.");
Wu Zhangjind7edf472009-11-23 10:28:24 +0800822
823 err = pci_enable_device(pdev); /* enable SMTC chip */
Wu Zhangjind7edf472009-11-23 10:28:24 +0800824 if (err)
825 return err;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800826
Wu Zhangjind7edf472009-11-23 10:28:24 +0800827 sfb = smtc_alloc_fb_info(pdev, name);
828
829 if (!sfb)
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400830 goto failed_free;
Javier M. Mellid86f31252012-04-26 20:45:49 +0200831
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200832 sfb->chipID = ent->device;
833 sprintf(name, "sm%Xfb", sfb->chipID);
834
Wu Zhangjind7edf472009-11-23 10:28:24 +0800835 pci_set_drvdata(pdev, sfb);
836
837 sm7xx_init_hw();
838
839 /*get mode parameter from smtc_screen_info */
840 if (smtc_screen_info.lfb_width != 0) {
841 sfb->fb.var.xres = smtc_screen_info.lfb_width;
842 sfb->fb.var.yres = smtc_screen_info.lfb_height;
843 sfb->fb.var.bits_per_pixel = smtc_screen_info.lfb_depth;
844 } else {
845 /* default resolution 1024x600 16bit mode */
846 sfb->fb.var.xres = SCREEN_X_RES;
847 sfb->fb.var.yres = SCREEN_Y_RES;
848 sfb->fb.var.bits_per_pixel = SCREEN_BPP;
849 }
850
851#ifdef __BIG_ENDIAN
852 if (sfb->fb.var.bits_per_pixel == 24)
853 sfb->fb.var.bits_per_pixel = (smtc_screen_info.lfb_depth = 32);
854#endif
855 /* Map address and memory detection */
856 pFramebufferPhysical = pci_resource_start(pdev, 0);
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200857 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chipRevID);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800858
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200859 switch (sfb->chipID) {
Wu Zhangjind7edf472009-11-23 10:28:24 +0800860 case 0x710:
861 case 0x712:
862 sfb->fb.fix.mmio_start = pFramebufferPhysical + 0x00400000;
863 sfb->fb.fix.mmio_len = 0x00400000;
864 smem_size = SM712_VIDEOMEMORYSIZE;
865#ifdef __BIG_ENDIAN
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200866 sfb->m_pLFB = (smtc_VRAMBaseAddress =
Wu Zhangjind7edf472009-11-23 10:28:24 +0800867 ioremap(pFramebufferPhysical, 0x00c00000));
868#else
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200869 sfb->m_pLFB = (smtc_VRAMBaseAddress =
Wu Zhangjind7edf472009-11-23 10:28:24 +0800870 ioremap(pFramebufferPhysical, 0x00800000));
871#endif
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200872 sfb->m_pMMIO = (smtc_RegBaseAddress =
Wu Zhangjind7edf472009-11-23 10:28:24 +0800873 smtc_VRAMBaseAddress + 0x00700000);
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200874 sfb->m_pDPR = smtc_VRAMBaseAddress + 0x00408000;
875 sfb->m_pVPR = sfb->m_pLFB + 0x0040c000;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800876#ifdef __BIG_ENDIAN
877 if (sfb->fb.var.bits_per_pixel == 32) {
878 smtc_VRAMBaseAddress += 0x800000;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200879 sfb->m_pLFB += 0x800000;
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200880 dev_info(&pdev->dev,
881 "smtc_VRAMBaseAddress=%p sfb->m_pLFB=%p",
882 smtc_VRAMBaseAddress, sfb->m_pLFB);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800883 }
884#endif
885 if (!smtc_RegBaseAddress) {
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200886 dev_err(&pdev->dev,
887 "%s: unable to map memory mapped IO!",
Wu Zhangjind7edf472009-11-23 10:28:24 +0800888 sfb->fb.fix.id);
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400889 err = -ENOMEM;
890 goto failed_fb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800891 }
892
893 /* set MCLK = 14.31818 * (0x16 / 0x2) */
894 smtc_seqw(0x6a, 0x16);
895 smtc_seqw(0x6b, 0x02);
896 smtc_seqw(0x62, 0x3e);
897 /* enable PCI burst */
898 smtc_seqw(0x17, 0x20);
899 /* enable word swap */
900#ifdef __BIG_ENDIAN
901 if (sfb->fb.var.bits_per_pixel == 32)
902 smtc_seqw(0x17, 0x30);
903#endif
Wu Zhangjind7edf472009-11-23 10:28:24 +0800904 break;
905 case 0x720:
906 sfb->fb.fix.mmio_start = pFramebufferPhysical;
907 sfb->fb.fix.mmio_len = 0x00200000;
908 smem_size = SM722_VIDEOMEMORYSIZE;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200909 sfb->m_pDPR = ioremap(pFramebufferPhysical, 0x00a00000);
910 sfb->m_pLFB = (smtc_VRAMBaseAddress =
911 sfb->m_pDPR + 0x00200000);
912 sfb->m_pMMIO = (smtc_RegBaseAddress =
913 sfb->m_pDPR + 0x000c0000);
914 sfb->m_pVPR = sfb->m_pDPR + 0x800;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800915
916 smtc_seqw(0x62, 0xff);
917 smtc_seqw(0x6a, 0x0d);
918 smtc_seqw(0x6b, 0x02);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800919 break;
920 default:
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200921 dev_err(&pdev->dev,
922 "No valid Silicon Motion display chip was detected!");
Wu Zhangjind7edf472009-11-23 10:28:24 +0800923
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400924 goto failed_fb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800925 }
926
927 /* can support 32 bpp */
928 if (15 == sfb->fb.var.bits_per_pixel)
929 sfb->fb.var.bits_per_pixel = 16;
930
931 sfb->fb.var.xres_virtual = sfb->fb.var.xres;
932 sfb->fb.var.yres_virtual = sfb->fb.var.yres;
933 err = smtc_map_smem(sfb, pdev, smem_size);
934 if (err)
935 goto failed;
936
937 smtcfb_setmode(sfb);
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300938 /* Primary display starting from 0 position */
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200939 sfb->BaseAddressInVRAM = 0;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800940
941 err = register_framebuffer(&sfb->fb);
942 if (err < 0)
943 goto failed;
944
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200945 dev_info(&pdev->dev,
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200946 "Silicon Motion SM%X Rev%X primary display mode %dx%d-%d Init Complete.",
947 sfb->chipID, sfb->chipRevID, sfb->fb.var.xres,
948 sfb->fb.var.yres, sfb->fb.var.bits_per_pixel);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800949
950 return 0;
951
anish kumar1639c8a2011-05-19 20:58:42 +0530952failed:
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200953 dev_err(&pdev->dev, "Silicon Motion, Inc. primary display init fail.");
Wu Zhangjind7edf472009-11-23 10:28:24 +0800954
955 smtc_unmap_smem(sfb);
956 smtc_unmap_mmio(sfb);
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400957failed_fb:
Wu Zhangjind7edf472009-11-23 10:28:24 +0800958 smtc_free_fb_info(sfb);
959
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400960failed_free:
961 pci_disable_device(pdev);
962
Wu Zhangjind7edf472009-11-23 10:28:24 +0800963 return err;
964}
965
966
Namhyung Kim6f475b72010-12-10 01:40:25 +0900967static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
Peter Huewec0fe6022011-11-27 15:12:57 +0100968 { PCI_DEVICE(0x126f, 0x710), },
969 { PCI_DEVICE(0x126f, 0x712), },
970 { PCI_DEVICE(0x126f, 0x720), },
Wu Zhangjind7edf472009-11-23 10:28:24 +0800971 {0,}
972};
973
974
Wu Zhangjind7edf472009-11-23 10:28:24 +0800975static void __devexit smtcfb_pci_remove(struct pci_dev *pdev)
976{
977 struct smtcfb_info *sfb;
978
979 sfb = pci_get_drvdata(pdev);
980 pci_set_drvdata(pdev, NULL);
981 smtc_unmap_smem(sfb);
982 smtc_unmap_mmio(sfb);
983 unregister_framebuffer(&sfb->fb);
984 smtc_free_fb_info(sfb);
985}
986
Javier M. Mellid392a0022011-03-30 16:24:10 +0200987#ifdef CONFIG_PM
Javier M. Mellid59815672011-04-30 17:44:25 +0200988static int smtcfb_pci_suspend(struct device *device)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800989{
Javier M. Mellid59815672011-04-30 17:44:25 +0200990 struct pci_dev *pdev = to_pci_dev(device);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800991 struct smtcfb_info *sfb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800992
993 sfb = pci_get_drvdata(pdev);
994
995 /* set the hw in sleep mode use externel clock and self memory refresh
996 * so that we can turn off internal PLLs later on
997 */
998 smtc_seqw(0x20, (smtc_seqr(0x20) | 0xc0));
999 smtc_seqw(0x69, (smtc_seqr(0x69) & 0xf7));
1000
Javier M. Mellid59815672011-04-30 17:44:25 +02001001 console_lock();
1002 fb_set_suspend(&sfb->fb, 1);
1003 console_unlock();
Wu Zhangjind7edf472009-11-23 10:28:24 +08001004
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001005 /* additionally turn off all function blocks including internal PLLs */
Wu Zhangjind7edf472009-11-23 10:28:24 +08001006 smtc_seqw(0x21, 0xff);
1007
1008 return 0;
1009}
1010
Javier M. Mellid59815672011-04-30 17:44:25 +02001011static int smtcfb_pci_resume(struct device *device)
Wu Zhangjind7edf472009-11-23 10:28:24 +08001012{
Javier M. Mellid59815672011-04-30 17:44:25 +02001013 struct pci_dev *pdev = to_pci_dev(device);
Wu Zhangjind7edf472009-11-23 10:28:24 +08001014 struct smtcfb_info *sfb;
Wu Zhangjind7edf472009-11-23 10:28:24 +08001015
1016 sfb = pci_get_drvdata(pdev);
1017
Wu Zhangjind7edf472009-11-23 10:28:24 +08001018 /* reinit hardware */
1019 sm7xx_init_hw();
Javier M. Mellid9be467d2012-04-26 20:45:53 +02001020 switch (sfb->chipID) {
Wu Zhangjind7edf472009-11-23 10:28:24 +08001021 case 0x710:
1022 case 0x712:
1023 /* set MCLK = 14.31818 * (0x16 / 0x2) */
1024 smtc_seqw(0x6a, 0x16);
1025 smtc_seqw(0x6b, 0x02);
1026 smtc_seqw(0x62, 0x3e);
1027 /* enable PCI burst */
1028 smtc_seqw(0x17, 0x20);
1029#ifdef __BIG_ENDIAN
1030 if (sfb->fb.var.bits_per_pixel == 32)
1031 smtc_seqw(0x17, 0x30);
1032#endif
1033 break;
1034 case 0x720:
1035 smtc_seqw(0x62, 0xff);
1036 smtc_seqw(0x6a, 0x0d);
1037 smtc_seqw(0x6b, 0x02);
1038 break;
1039 }
1040
1041 smtc_seqw(0x34, (smtc_seqr(0x34) | 0xc0));
1042 smtc_seqw(0x33, ((smtc_seqr(0x33) | 0x08) & 0xfb));
1043
1044 smtcfb_setmode(sfb);
1045
Torben Hohnac751ef2011-01-25 15:07:35 -08001046 console_lock();
Wu Zhangjind7edf472009-11-23 10:28:24 +08001047 fb_set_suspend(&sfb->fb, 0);
Torben Hohnac751ef2011-01-25 15:07:35 -08001048 console_unlock();
Wu Zhangjind7edf472009-11-23 10:28:24 +08001049
1050 return 0;
1051}
Wu Zhangjind7edf472009-11-23 10:28:24 +08001052
Javier M. Mellid59815672011-04-30 17:44:25 +02001053static const struct dev_pm_ops sm7xx_pm_ops = {
1054 .suspend = smtcfb_pci_suspend,
1055 .resume = smtcfb_pci_resume,
1056 .freeze = smtcfb_pci_suspend,
1057 .thaw = smtcfb_pci_resume,
1058 .poweroff = smtcfb_pci_suspend,
1059 .restore = smtcfb_pci_resume,
1060};
1061
1062#define SM7XX_PM_OPS (&sm7xx_pm_ops)
1063
1064#else /* !CONFIG_PM */
1065
1066#define SM7XX_PM_OPS NULL
1067
1068#endif /* !CONFIG_PM */
1069
Wu Zhangjind7edf472009-11-23 10:28:24 +08001070static struct pci_driver smtcfb_driver = {
1071 .name = "smtcfb",
1072 .id_table = smtcfb_pci_table,
1073 .probe = smtcfb_pci_probe,
1074 .remove = __devexit_p(smtcfb_pci_remove),
Javier M. Mellid59815672011-04-30 17:44:25 +02001075 .driver.pm = SM7XX_PM_OPS,
Wu Zhangjind7edf472009-11-23 10:28:24 +08001076};
1077
1078static int __init smtcfb_init(void)
1079{
1080 return pci_register_driver(&smtcfb_driver);
1081}
1082
1083static void __exit smtcfb_exit(void)
1084{
1085 pci_unregister_driver(&smtcfb_driver);
1086}
1087
1088module_init(smtcfb_init);
1089module_exit(smtcfb_exit);
1090
1091MODULE_AUTHOR("Siliconmotion ");
1092MODULE_DESCRIPTION("Framebuffer driver for SMI Graphic Cards");
1093MODULE_LICENSE("GPL");