blob: 16d2b5eda80c1ac5bda7e066be4f2bc2cb321e35 [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 *
Javier M. Mellid0beb30d2012-06-10 13:12:23 +020018 * Framebuffer driver for Silicon Motion SM710, SM712, SM721 and SM722 chips
Wu Zhangjind7edf472009-11-23 10:28:24 +080019 */
20
Wu Zhangjind7edf472009-11-23 10:28:24 +080021#include <linux/io.h>
22#include <linux/fb.h>
23#include <linux/pci.h>
24#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Wu Zhangjind7edf472009-11-23 10:28:24 +080026#include <linux/uaccess.h>
Paul Gortmaker99c97852011-07-03 15:49:50 -040027#include <linux/module.h>
Wu Zhangjind7edf472009-11-23 10:28:24 +080028#include <linux/console.h>
29#include <linux/screen_info.h>
30
31#ifdef CONFIG_PM
32#include <linux/pm.h>
33#endif
34
Javier M. Mellid925aa662012-06-10 13:12:24 +020035#include "sm7xx.h"
Wu Zhangjind7edf472009-11-23 10:28:24 +080036
Javier M. Melliddc762c42011-05-07 03:11:58 +020037struct screen_info smtc_screen_info;
38
Wu Zhangjind7edf472009-11-23 10:28:24 +080039/*
40* Private structure
41*/
42struct smtcfb_info {
Wu Zhangjind7edf472009-11-23 10:28:24 +080043 struct fb_info fb;
Javier M. Mellid9be467d2012-04-26 20:45:53 +020044 struct pci_dev *pdev;
Wu Zhangjind7edf472009-11-23 10:28:24 +080045
Wu Zhangjind7edf472009-11-23 10:28:24 +080046 u16 chipID;
47 unsigned char __iomem *m_pMMIO;
48 char __iomem *m_pLFB;
49 char *m_pDPR;
50 char *m_pVPR;
51 char *m_pCPR;
52
53 u_int width;
54 u_int height;
55 u_int hz;
Javier M. Mellid50b238b2012-06-26 06:00:15 +020056
Wu Zhangjind7edf472009-11-23 10:28:24 +080057 u8 chipRevID;
58};
59
60struct vesa_mode_table {
61 char mode_index[6];
62 u16 lfb_width;
63 u16 lfb_height;
64 u16 lfb_depth;
65};
66
67static struct vesa_mode_table vesa_mode[] = {
68 {"0x301", 640, 480, 8},
69 {"0x303", 800, 600, 8},
Javier M. Mellid3b70a262011-04-30 17:44:26 +020070 {"0x305", 1024, 768, 8},
Wu Zhangjind7edf472009-11-23 10:28:24 +080071 {"0x307", 1280, 1024, 8},
72
73 {"0x311", 640, 480, 16},
74 {"0x314", 800, 600, 16},
Javier M. Mellid3b70a262011-04-30 17:44:26 +020075 {"0x317", 1024, 768, 16},
Wu Zhangjind7edf472009-11-23 10:28:24 +080076 {"0x31A", 1280, 1024, 16},
77
78 {"0x312", 640, 480, 24},
79 {"0x315", 800, 600, 24},
Javier M. Mellid3b70a262011-04-30 17:44:26 +020080 {"0x318", 1024, 768, 24},
Wu Zhangjind7edf472009-11-23 10:28:24 +080081 {"0x31B", 1280, 1024, 24},
82};
83
84char __iomem *smtc_RegBaseAddress; /* Memory Map IO starting address */
85char __iomem *smtc_VRAMBaseAddress; /* video memory starting address */
86
Wu Zhangjind7edf472009-11-23 10:28:24 +080087static u32 colreg[17];
Wu Zhangjind7edf472009-11-23 10:28:24 +080088
Javier M. Melliddc762c42011-05-07 03:11:58 +020089static struct fb_var_screeninfo smtcfb_var = {
90 .xres = 1024,
91 .yres = 600,
92 .xres_virtual = 1024,
93 .yres_virtual = 600,
94 .bits_per_pixel = 16,
95 .red = {16, 8, 0},
96 .green = {8, 8, 0},
97 .blue = {0, 8, 0},
98 .activate = FB_ACTIVATE_NOW,
99 .height = -1,
100 .width = -1,
101 .vmode = FB_VMODE_NONINTERLACED,
102};
103
104static struct fb_fix_screeninfo smtcfb_fix = {
105 .id = "sm712fb",
106 .type = FB_TYPE_PACKED_PIXELS,
107 .visual = FB_VISUAL_TRUECOLOR,
108 .line_length = 800 * 3,
109 .accel = FB_ACCEL_SMI_LYNX,
110};
111
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200112static void sm712_set_timing(struct smtcfb_info *sfb)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800113{
114 int i = 0, j = 0;
115 u32 m_nScreenStride;
116
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200117 dev_dbg(&sfb->pdev->dev,
118 "sfb->width=%d sfb->height=%d "
119 "sfb->fb.var.bits_per_pixel=%d sfb->hz=%d\n",
120 sfb->width, sfb->height, sfb->fb.var.bits_per_pixel, sfb->hz);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800121
122 for (j = 0; j < numVGAModes; j++) {
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200123 if (VGAMode[j].mmSizeX == sfb->width &&
124 VGAMode[j].mmSizeY == sfb->height &&
Wu Zhangjind7edf472009-11-23 10:28:24 +0800125 VGAMode[j].bpp == sfb->fb.var.bits_per_pixel &&
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200126 VGAMode[j].hz == sfb->hz) {
Wu Zhangjind7edf472009-11-23 10:28:24 +0800127
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200128 dev_dbg(&sfb->pdev->dev,
129 "VGAMode[j].mmSizeX=%d VGAMode[j].mmSizeY=%d "
Javier M. Mellidbfdd4032012-04-26 20:45:51 +0200130 "VGAMode[j].bpp=%d VGAMode[j].hz=%d\n",
131 VGAMode[j].mmSizeX, VGAMode[j].mmSizeY,
132 VGAMode[j].bpp, VGAMode[j].hz);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800133
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200134 dev_dbg(&sfb->pdev->dev, "VGAMode index=%d\n", j);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800135
136 smtc_mmiowb(0x0, 0x3c6);
137
138 smtc_seqw(0, 0x1);
139
140 smtc_mmiowb(VGAMode[j].Init_MISC, 0x3c2);
141
142 /* init SEQ register SR00 - SR04 */
143 for (i = 0; i < SIZE_SR00_SR04; i++)
144 smtc_seqw(i, VGAMode[j].Init_SR00_SR04[i]);
145
146 /* init SEQ register SR10 - SR24 */
147 for (i = 0; i < SIZE_SR10_SR24; i++)
148 smtc_seqw(i + 0x10,
149 VGAMode[j].Init_SR10_SR24[i]);
150
151 /* init SEQ register SR30 - SR75 */
152 for (i = 0; i < SIZE_SR30_SR75; i++)
153 if (((i + 0x30) != 0x62) \
154 && ((i + 0x30) != 0x6a) \
155 && ((i + 0x30) != 0x6b))
156 smtc_seqw(i + 0x30,
157 VGAMode[j].Init_SR30_SR75[i]);
158
159 /* init SEQ register SR80 - SR93 */
160 for (i = 0; i < SIZE_SR80_SR93; i++)
161 smtc_seqw(i + 0x80,
162 VGAMode[j].Init_SR80_SR93[i]);
163
164 /* init SEQ register SRA0 - SRAF */
165 for (i = 0; i < SIZE_SRA0_SRAF; i++)
166 smtc_seqw(i + 0xa0,
167 VGAMode[j].Init_SRA0_SRAF[i]);
168
169 /* init Graphic register GR00 - GR08 */
170 for (i = 0; i < SIZE_GR00_GR08; i++)
171 smtc_grphw(i, VGAMode[j].Init_GR00_GR08[i]);
172
173 /* init Attribute register AR00 - AR14 */
174 for (i = 0; i < SIZE_AR00_AR14; i++)
175 smtc_attrw(i, VGAMode[j].Init_AR00_AR14[i]);
176
177 /* init CRTC register CR00 - CR18 */
178 for (i = 0; i < SIZE_CR00_CR18; i++)
179 smtc_crtcw(i, VGAMode[j].Init_CR00_CR18[i]);
180
181 /* init CRTC register CR30 - CR4D */
182 for (i = 0; i < SIZE_CR30_CR4D; i++)
183 smtc_crtcw(i + 0x30,
184 VGAMode[j].Init_CR30_CR4D[i]);
185
186 /* init CRTC register CR90 - CRA7 */
187 for (i = 0; i < SIZE_CR90_CRA7; i++)
188 smtc_crtcw(i + 0x90,
189 VGAMode[j].Init_CR90_CRA7[i]);
190 }
191 }
192 smtc_mmiowb(0x67, 0x3c2);
193
194 /* set VPR registers */
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200195 writel(0x0, sfb->m_pVPR + 0x0C);
196 writel(0x0, sfb->m_pVPR + 0x40);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800197
198 /* set data width */
199 m_nScreenStride =
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200200 (sfb->width * sfb->fb.var.bits_per_pixel) / 64;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800201 switch (sfb->fb.var.bits_per_pixel) {
202 case 8:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200203 writel(0x0, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800204 break;
205 case 16:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200206 writel(0x00020000, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800207 break;
208 case 24:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200209 writel(0x00040000, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800210 break;
211 case 32:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200212 writel(0x00030000, sfb->m_pVPR + 0x0);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800213 break;
214 }
215 writel((u32) (((m_nScreenStride + 2) << 16) | m_nScreenStride),
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200216 sfb->m_pVPR + 0x10);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800217
218}
219
220static void sm712_setpalette(int regno, unsigned red, unsigned green,
221 unsigned blue, struct fb_info *info)
222{
Javier M. Mellid50b238b2012-06-26 06:00:15 +0200223 /* set bit 5:4 = 01 (write LCD RAM only) */
224 smtc_seqw(0x66, (smtc_seqr(0x66) & 0xC3) | 0x10);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800225
Wu Zhangjind7edf472009-11-23 10:28:24 +0800226 smtc_mmiowb(regno, dac_reg);
227 smtc_mmiowb(red >> 10, dac_val);
228 smtc_mmiowb(green >> 10, dac_val);
229 smtc_mmiowb(blue >> 10, dac_val);
230}
231
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200232static void smtc_set_timing(struct smtcfb_info *sfb)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800233{
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200234 switch (sfb->chipID) {
Wu Zhangjind7edf472009-11-23 10:28:24 +0800235 case 0x710:
236 case 0x712:
237 case 0x720:
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200238 sm712_set_timing(sfb);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800239 break;
240 }
241}
242
Wu Zhangjind7edf472009-11-23 10:28:24 +0800243/* chan_to_field
244 *
245 * convert a colour value into a field position
246 *
247 * from pxafb.c
248 */
249
250static inline unsigned int chan_to_field(unsigned int chan,
251 struct fb_bitfield *bf)
252{
253 chan &= 0xffff;
254 chan >>= 16 - bf->length;
255 return chan << bf->offset;
256}
257
Javier M. Mellidacbaa0b2012-04-26 20:45:55 +0200258static int smtc_blank(int blank_mode, struct fb_info *info)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800259{
260 /* clear DPMS setting */
261 switch (blank_mode) {
262 case FB_BLANK_UNBLANK:
263 /* Screen On: HSync: On, VSync : On */
264 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
265 smtc_seqw(0x6a, 0x16);
266 smtc_seqw(0x6b, 0x02);
267 smtc_seqw(0x21, (smtc_seqr(0x21) & 0x77));
268 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
269 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
270 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
271 smtc_seqw(0x31, (smtc_seqr(0x31) | 0x03));
272 break;
273 case FB_BLANK_NORMAL:
274 /* Screen Off: HSync: On, VSync : On Soft blank */
275 smtc_seqw(0x01, (smtc_seqr(0x01) & (~0x20)));
276 smtc_seqw(0x6a, 0x16);
277 smtc_seqw(0x6b, 0x02);
278 smtc_seqw(0x22, (smtc_seqr(0x22) & (~0x30)));
279 smtc_seqw(0x23, (smtc_seqr(0x23) & (~0xc0)));
280 smtc_seqw(0x24, (smtc_seqr(0x24) | 0x01));
281 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
282 break;
283 case FB_BLANK_VSYNC_SUSPEND:
284 /* Screen On: HSync: On, VSync : Off */
285 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
286 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
287 smtc_seqw(0x6a, 0x0c);
288 smtc_seqw(0x6b, 0x02);
289 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
290 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x20));
291 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0x20));
292 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
293 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
294 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
295 break;
296 case FB_BLANK_HSYNC_SUSPEND:
297 /* Screen On: HSync: Off, VSync : On */
298 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
299 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
300 smtc_seqw(0x6a, 0x0c);
301 smtc_seqw(0x6b, 0x02);
302 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
303 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x10));
304 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
305 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
306 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
307 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
308 break;
309 case FB_BLANK_POWERDOWN:
310 /* Screen On: HSync: Off, VSync : Off */
311 smtc_seqw(0x01, (smtc_seqr(0x01) | 0x20));
312 smtc_seqw(0x20, (smtc_seqr(0x20) & (~0xB0)));
313 smtc_seqw(0x6a, 0x0c);
314 smtc_seqw(0x6b, 0x02);
315 smtc_seqw(0x21, (smtc_seqr(0x21) | 0x88));
316 smtc_seqw(0x22, ((smtc_seqr(0x22) & (~0x30)) | 0x30));
317 smtc_seqw(0x23, ((smtc_seqr(0x23) & (~0xc0)) | 0xD8));
318 smtc_seqw(0x24, (smtc_seqr(0x24) & (~0x01)));
319 smtc_seqw(0x31, ((smtc_seqr(0x31) & (~0x07)) | 0x00));
320 smtc_seqw(0x34, (smtc_seqr(0x34) | 0x80));
321 break;
322 default:
323 return -EINVAL;
324 }
325
326 return 0;
327}
328
329static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green,
330 unsigned blue, unsigned trans, struct fb_info *info)
331{
332 struct smtcfb_info *sfb = (struct smtcfb_info *)info;
333 u32 val;
334
335 if (regno > 255)
336 return 1;
337
338 switch (sfb->fb.fix.visual) {
339 case FB_VISUAL_DIRECTCOLOR:
340 case FB_VISUAL_TRUECOLOR:
341 /*
Justin P. Mattock7756d3e8b2012-06-25 07:28:25 -0700342 * 16/32 bit true-colour, use pseudo-palette for 16 base color
Wu Zhangjind7edf472009-11-23 10:28:24 +0800343 */
344 if (regno < 16) {
345 if (sfb->fb.var.bits_per_pixel == 16) {
346 u32 *pal = sfb->fb.pseudo_palette;
347 val = chan_to_field(red, &sfb->fb.var.red);
348 val |= chan_to_field(green, \
349 &sfb->fb.var.green);
350 val |= chan_to_field(blue, &sfb->fb.var.blue);
351#ifdef __BIG_ENDIAN
352 pal[regno] =
353 ((red & 0xf800) >> 8) |
354 ((green & 0xe000) >> 13) |
355 ((green & 0x1c00) << 3) |
356 ((blue & 0xf800) >> 3);
357#else
358 pal[regno] = val;
359#endif
360 } else {
361 u32 *pal = sfb->fb.pseudo_palette;
362 val = chan_to_field(red, &sfb->fb.var.red);
363 val |= chan_to_field(green, \
364 &sfb->fb.var.green);
365 val |= chan_to_field(blue, &sfb->fb.var.blue);
366#ifdef __BIG_ENDIAN
367 val =
368 (val & 0xff00ff00 >> 8) |
369 (val & 0x00ff00ff << 8);
370#endif
371 pal[regno] = val;
372 }
373 }
374 break;
375
376 case FB_VISUAL_PSEUDOCOLOR:
377 /* color depth 8 bit */
378 sm712_setpalette(regno, red, green, blue, info);
379 break;
380
381 default:
382 return 1; /* unknown type */
383 }
384
385 return 0;
386
387}
388
389#ifdef __BIG_ENDIAN
Josenivaldo Benito Jrc8100d22012-02-12 19:03:14 -0200390static ssize_t smtcfb_read(struct fb_info *info, char __user *buf, size_t
Wu Zhangjind7edf472009-11-23 10:28:24 +0800391 count, loff_t *ppos)
392{
393 unsigned long p = *ppos;
394
395 u32 *buffer, *dst;
396 u32 __iomem *src;
397 int c, i, cnt = 0, err = 0;
398 unsigned long total_size;
399
400 if (!info || !info->screen_base)
401 return -ENODEV;
402
403 if (info->state != FBINFO_STATE_RUNNING)
404 return -EPERM;
405
406 total_size = info->screen_size;
407
408 if (total_size == 0)
409 total_size = info->fix.smem_len;
410
411 if (p >= total_size)
412 return 0;
413
414 if (count >= total_size)
415 count = total_size;
416
417 if (count + p > total_size)
418 count = total_size - p;
419
420 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
421 if (!buffer)
422 return -ENOMEM;
423
424 src = (u32 __iomem *) (info->screen_base + p);
425
426 if (info->fbops->fb_sync)
427 info->fbops->fb_sync(info);
428
429 while (count) {
430 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
431 dst = buffer;
432 for (i = c >> 2; i--;) {
433 *dst = fb_readl(src++);
434 *dst =
435 (*dst & 0xff00ff00 >> 8) |
436 (*dst & 0x00ff00ff << 8);
437 dst++;
438 }
439 if (c & 3) {
440 u8 *dst8 = (u8 *) dst;
441 u8 __iomem *src8 = (u8 __iomem *) src;
442
443 for (i = c & 3; i--;) {
444 if (i & 1) {
445 *dst8++ = fb_readb(++src8);
446 } else {
447 *dst8++ = fb_readb(--src8);
448 src8 += 2;
449 }
450 }
451 src = (u32 __iomem *) src8;
452 }
453
454 if (copy_to_user(buf, buffer, c)) {
455 err = -EFAULT;
456 break;
457 }
458 *ppos += c;
459 buf += c;
460 cnt += c;
461 count -= c;
462 }
463
464 kfree(buffer);
465
466 return (err) ? err : cnt;
467}
468
469static ssize_t
470smtcfb_write(struct fb_info *info, const char __user *buf, size_t count,
471 loff_t *ppos)
472{
473 unsigned long p = *ppos;
474
475 u32 *buffer, *src;
476 u32 __iomem *dst;
477 int c, i, cnt = 0, err = 0;
478 unsigned long total_size;
479
480 if (!info || !info->screen_base)
481 return -ENODEV;
482
483 if (info->state != FBINFO_STATE_RUNNING)
484 return -EPERM;
485
486 total_size = info->screen_size;
487
488 if (total_size == 0)
489 total_size = info->fix.smem_len;
490
491 if (p > total_size)
492 return -EFBIG;
493
494 if (count > total_size) {
495 err = -EFBIG;
496 count = total_size;
497 }
498
499 if (count + p > total_size) {
500 if (!err)
501 err = -ENOSPC;
502
503 count = total_size - p;
504 }
505
506 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
507 if (!buffer)
508 return -ENOMEM;
509
510 dst = (u32 __iomem *) (info->screen_base + p);
511
512 if (info->fbops->fb_sync)
513 info->fbops->fb_sync(info);
514
515 while (count) {
516 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
517 src = buffer;
518
519 if (copy_from_user(src, buf, c)) {
520 err = -EFAULT;
521 break;
522 }
523
524 for (i = c >> 2; i--;) {
525 fb_writel((*src & 0xff00ff00 >> 8) |
526 (*src & 0x00ff00ff << 8), dst++);
527 src++;
528 }
529 if (c & 3) {
530 u8 *src8 = (u8 *) src;
531 u8 __iomem *dst8 = (u8 __iomem *) dst;
532
533 for (i = c & 3; i--;) {
534 if (i & 1) {
535 fb_writeb(*src8++, ++dst8);
536 } else {
537 fb_writeb(*src8++, --dst8);
538 dst8 += 2;
539 }
540 }
541 dst = (u32 __iomem *) dst8;
542 }
543
544 *ppos += c;
545 buf += c;
546 cnt += c;
547 count -= c;
548 }
549
550 kfree(buffer);
551
552 return (cnt) ? cnt : err;
553}
554#endif /* ! __BIG_ENDIAN */
555
Wu Zhangjind7edf472009-11-23 10:28:24 +0800556void smtcfb_setmode(struct smtcfb_info *sfb)
557{
558 switch (sfb->fb.var.bits_per_pixel) {
559 case 32:
Javier M. Mellidf2047392012-06-26 06:00:17 +0200560 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
561 sfb->fb.fix.line_length = sfb->fb.var.xres * 4;
562 sfb->fb.var.red.length = 8;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800563 sfb->fb.var.green.length = 8;
Javier M. Mellidf2047392012-06-26 06:00:17 +0200564 sfb->fb.var.blue.length = 8;
565 sfb->fb.var.red.offset = 16;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800566 sfb->fb.var.green.offset = 8;
Javier M. Mellidf2047392012-06-26 06:00:17 +0200567 sfb->fb.var.blue.offset = 0;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800568 break;
569 case 24:
Javier M. Mellidf2047392012-06-26 06:00:17 +0200570 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
571 sfb->fb.fix.line_length = sfb->fb.var.xres * 3;
572 sfb->fb.var.red.length = 8;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800573 sfb->fb.var.green.length = 8;
Javier M. Mellidf2047392012-06-26 06:00:17 +0200574 sfb->fb.var.blue.length = 8;
575 sfb->fb.var.red.offset = 16;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800576 sfb->fb.var.green.offset = 8;
Javier M. Mellidf2047392012-06-26 06:00:17 +0200577 sfb->fb.var.blue.offset = 0;
578 break;
579 case 8:
580 sfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
581 sfb->fb.fix.line_length = sfb->fb.var.xres;
582 sfb->fb.var.red.length = 3;
583 sfb->fb.var.green.length = 3;
584 sfb->fb.var.blue.length = 2;
585 sfb->fb.var.red.offset = 5;
586 sfb->fb.var.green.offset = 2;
587 sfb->fb.var.blue.offset = 0;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800588 break;
589 case 16:
590 default:
Javier M. Mellidf2047392012-06-26 06:00:17 +0200591 sfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
592 sfb->fb.fix.line_length = sfb->fb.var.xres * 2;
593 sfb->fb.var.red.length = 5;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800594 sfb->fb.var.green.length = 6;
Javier M. Mellidf2047392012-06-26 06:00:17 +0200595 sfb->fb.var.blue.length = 5;
596 sfb->fb.var.red.offset = 11;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800597 sfb->fb.var.green.offset = 5;
Javier M. Mellidf2047392012-06-26 06:00:17 +0200598 sfb->fb.var.blue.offset = 0;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800599 break;
600 }
601
Javier M. Mellidf2047392012-06-26 06:00:17 +0200602 sfb->width = sfb->fb.var.xres;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200603 sfb->height = sfb->fb.var.yres;
604 sfb->hz = 60;
605 smtc_set_timing(sfb);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800606}
607
Javier M. Melliddc762c42011-05-07 03:11:58 +0200608static int smtc_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
609{
610 /* sanity checks */
611 if (var->xres_virtual < var->xres)
612 var->xres_virtual = var->xres;
613
614 if (var->yres_virtual < var->yres)
615 var->yres_virtual = var->yres;
616
617 /* set valid default bpp */
618 if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16) &&
619 (var->bits_per_pixel != 24) && (var->bits_per_pixel != 32))
620 var->bits_per_pixel = 16;
621
622 return 0;
623}
624
625static int smtc_set_par(struct fb_info *info)
626{
627 struct smtcfb_info *sfb = (struct smtcfb_info *)info;
628
629 smtcfb_setmode(sfb);
630
631 return 0;
632}
633
634static struct fb_ops smtcfb_ops = {
635 .owner = THIS_MODULE,
636 .fb_check_var = smtc_check_var,
637 .fb_set_par = smtc_set_par,
638 .fb_setcolreg = smtc_setcolreg,
Javier M. Mellidacbaa0b2012-04-26 20:45:55 +0200639 .fb_blank = smtc_blank,
Javier M. Melliddc762c42011-05-07 03:11:58 +0200640 .fb_fillrect = cfb_fillrect,
641 .fb_imageblit = cfb_imageblit,
642 .fb_copyarea = cfb_copyarea,
643#ifdef __BIG_ENDIAN
644 .fb_read = smtcfb_read,
645 .fb_write = smtcfb_write,
646#endif
647};
648
Wu Zhangjind7edf472009-11-23 10:28:24 +0800649/*
650 * Alloc struct smtcfb_info and assign the default value
651 */
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200652static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *pdev, char *name)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800653{
654 struct smtcfb_info *sfb;
655
anish kumar617a0c72011-05-19 20:58:51 +0530656 sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800657
658 if (!sfb)
659 return NULL;
660
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200661 sfb->pdev = pdev;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800662
663 /*** Init sfb->fb with default value ***/
664 sfb->fb.flags = FBINFO_FLAG_DEFAULT;
665 sfb->fb.fbops = &smtcfb_ops;
666 sfb->fb.var = smtcfb_var;
667 sfb->fb.fix = smtcfb_fix;
668
669 strcpy(sfb->fb.fix.id, name);
670
671 sfb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
672 sfb->fb.fix.type_aux = 0;
673 sfb->fb.fix.xpanstep = 0;
674 sfb->fb.fix.ypanstep = 0;
675 sfb->fb.fix.ywrapstep = 0;
676 sfb->fb.fix.accel = FB_ACCEL_SMI_LYNX;
677
678 sfb->fb.var.nonstd = 0;
679 sfb->fb.var.activate = FB_ACTIVATE_NOW;
680 sfb->fb.var.height = -1;
681 sfb->fb.var.width = -1;
682 /* text mode acceleration */
683 sfb->fb.var.accel_flags = FB_ACCELF_TEXT;
684 sfb->fb.var.vmode = FB_VMODE_NONINTERLACED;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200685
686 sfb->fb.par = sfb;
687
Wu Zhangjind7edf472009-11-23 10:28:24 +0800688 sfb->fb.pseudo_palette = colreg;
689
690 return sfb;
691}
692
693/*
Javier M. Mellid128e8612012-06-26 06:00:16 +0200694 * free struct smtcfb_info
695 */
696static void smtc_free_fb_info(struct smtcfb_info *sfb)
697{
698 kfree(sfb);
699}
700
701/*
Wu Zhangjind7edf472009-11-23 10:28:24 +0800702 * Unmap in the memory mapped IO registers
703 */
704
705static void smtc_unmap_mmio(struct smtcfb_info *sfb)
706{
707 if (sfb && smtc_RegBaseAddress)
708 smtc_RegBaseAddress = NULL;
709}
710
711/*
712 * Map in the screen memory
713 */
714
715static int smtc_map_smem(struct smtcfb_info *sfb,
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200716 struct pci_dev *pdev, u_long smem_len)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800717{
Javier M. Mellid67c4e9f2012-06-10 13:12:22 +0200718
719 sfb->fb.fix.smem_start = pci_resource_start(pdev, 0);
720
Wu Zhangjind7edf472009-11-23 10:28:24 +0800721#ifdef __BIG_ENDIAN
Javier M. Mellid67c4e9f2012-06-10 13:12:22 +0200722 if (sfb->fb.var.bits_per_pixel == 32)
723 sfb->fb.fix.smem_start += 0x800000;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800724#endif
Wu Zhangjind7edf472009-11-23 10:28:24 +0800725
726 sfb->fb.fix.smem_len = smem_len;
727
728 sfb->fb.screen_base = smtc_VRAMBaseAddress;
729
730 if (!sfb->fb.screen_base) {
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200731 dev_err(&pdev->dev,
732 "%s: unable to map screen memory\n", sfb->fb.fix.id);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800733 return -ENOMEM;
734 }
735
736 return 0;
737}
738
739/*
740 * Unmap in the screen memory
741 *
742 */
743static void smtc_unmap_smem(struct smtcfb_info *sfb)
744{
745 if (sfb && sfb->fb.screen_base) {
746 iounmap(sfb->fb.screen_base);
747 sfb->fb.screen_base = NULL;
748 }
749}
750
751/*
Javier M. Mellid0beb30d2012-06-10 13:12:23 +0200752 * We need to wake up the device and make sure its in linear memory mode.
Wu Zhangjind7edf472009-11-23 10:28:24 +0800753 */
754static inline void sm7xx_init_hw(void)
755{
756 outb_p(0x18, 0x3c4);
757 outb_p(0x11, 0x3c5);
758}
759
Wu Zhangjind7edf472009-11-23 10:28:24 +0800760/*
761 * sm712vga_setup - process command line options, get vga parameter
762 * @options: string of options
763 * Returns zero.
764 *
765 */
Javier M. Melliddc762c42011-05-07 03:11:58 +0200766static int __init sm712vga_setup(char *options)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800767{
768 int index;
769
Javier M. Mellidbfdd4032012-04-26 20:45:51 +0200770 if (!options || !*options)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800771 return -EINVAL;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800772
773 smtc_screen_info.lfb_width = 0;
774 smtc_screen_info.lfb_height = 0;
775 smtc_screen_info.lfb_depth = 0;
776
Javier M. Mellidbfdd4032012-04-26 20:45:51 +0200777 pr_debug("sm712vga_setup = %s\n", options);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800778
779 for (index = 0;
anish kumar1639c8a2011-05-19 20:58:42 +0530780 index < ARRAY_SIZE(vesa_mode);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800781 index++) {
782 if (strstr(options, vesa_mode[index].mode_index)) {
783 smtc_screen_info.lfb_width = vesa_mode[index].lfb_width;
784 smtc_screen_info.lfb_height =
785 vesa_mode[index].lfb_height;
786 smtc_screen_info.lfb_depth = vesa_mode[index].lfb_depth;
787 return 0;
788 }
789 }
790
791 return -1;
792}
793__setup("vga=", sm712vga_setup);
794
Wu Zhangjinb99e1942010-07-18 03:16:28 +0800795static int __devinit smtcfb_pci_probe(struct pci_dev *pdev,
Wu Zhangjind7edf472009-11-23 10:28:24 +0800796 const struct pci_device_id *ent)
797{
798 struct smtcfb_info *sfb;
799 u_long smem_size = 0x00800000; /* default 8MB */
800 char name[16];
801 int err;
802 unsigned long pFramebufferPhysical;
803
Javier M. Mellid5c40fb32012-04-26 20:45:54 +0200804 dev_info(&pdev->dev, "Silicon Motion display driver.");
Wu Zhangjind7edf472009-11-23 10:28:24 +0800805
806 err = pci_enable_device(pdev); /* enable SMTC chip */
Wu Zhangjind7edf472009-11-23 10:28:24 +0800807 if (err)
808 return err;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800809
Wu Zhangjind7edf472009-11-23 10:28:24 +0800810 sfb = smtc_alloc_fb_info(pdev, name);
811
812 if (!sfb)
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400813 goto failed_free;
Javier M. Mellid86f31252012-04-26 20:45:49 +0200814
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200815 sfb->chipID = ent->device;
816 sprintf(name, "sm%Xfb", sfb->chipID);
817
Wu Zhangjind7edf472009-11-23 10:28:24 +0800818 pci_set_drvdata(pdev, sfb);
819
820 sm7xx_init_hw();
821
822 /*get mode parameter from smtc_screen_info */
823 if (smtc_screen_info.lfb_width != 0) {
824 sfb->fb.var.xres = smtc_screen_info.lfb_width;
825 sfb->fb.var.yres = smtc_screen_info.lfb_height;
826 sfb->fb.var.bits_per_pixel = smtc_screen_info.lfb_depth;
827 } else {
828 /* default resolution 1024x600 16bit mode */
829 sfb->fb.var.xres = SCREEN_X_RES;
830 sfb->fb.var.yres = SCREEN_Y_RES;
831 sfb->fb.var.bits_per_pixel = SCREEN_BPP;
832 }
833
834#ifdef __BIG_ENDIAN
835 if (sfb->fb.var.bits_per_pixel == 24)
836 sfb->fb.var.bits_per_pixel = (smtc_screen_info.lfb_depth = 32);
837#endif
838 /* Map address and memory detection */
839 pFramebufferPhysical = pci_resource_start(pdev, 0);
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200840 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chipRevID);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800841
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200842 switch (sfb->chipID) {
Wu Zhangjind7edf472009-11-23 10:28:24 +0800843 case 0x710:
844 case 0x712:
845 sfb->fb.fix.mmio_start = pFramebufferPhysical + 0x00400000;
846 sfb->fb.fix.mmio_len = 0x00400000;
847 smem_size = SM712_VIDEOMEMORYSIZE;
848#ifdef __BIG_ENDIAN
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200849 sfb->m_pLFB = (smtc_VRAMBaseAddress =
Wu Zhangjind7edf472009-11-23 10:28:24 +0800850 ioremap(pFramebufferPhysical, 0x00c00000));
851#else
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200852 sfb->m_pLFB = (smtc_VRAMBaseAddress =
Wu Zhangjind7edf472009-11-23 10:28:24 +0800853 ioremap(pFramebufferPhysical, 0x00800000));
854#endif
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200855 sfb->m_pMMIO = (smtc_RegBaseAddress =
Wu Zhangjind7edf472009-11-23 10:28:24 +0800856 smtc_VRAMBaseAddress + 0x00700000);
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200857 sfb->m_pDPR = smtc_VRAMBaseAddress + 0x00408000;
858 sfb->m_pVPR = sfb->m_pLFB + 0x0040c000;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800859#ifdef __BIG_ENDIAN
860 if (sfb->fb.var.bits_per_pixel == 32) {
861 smtc_VRAMBaseAddress += 0x800000;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200862 sfb->m_pLFB += 0x800000;
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200863 dev_info(&pdev->dev,
864 "smtc_VRAMBaseAddress=%p sfb->m_pLFB=%p",
865 smtc_VRAMBaseAddress, sfb->m_pLFB);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800866 }
867#endif
868 if (!smtc_RegBaseAddress) {
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200869 dev_err(&pdev->dev,
870 "%s: unable to map memory mapped IO!",
Wu Zhangjind7edf472009-11-23 10:28:24 +0800871 sfb->fb.fix.id);
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400872 err = -ENOMEM;
873 goto failed_fb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800874 }
875
876 /* set MCLK = 14.31818 * (0x16 / 0x2) */
877 smtc_seqw(0x6a, 0x16);
878 smtc_seqw(0x6b, 0x02);
879 smtc_seqw(0x62, 0x3e);
880 /* enable PCI burst */
881 smtc_seqw(0x17, 0x20);
882 /* enable word swap */
883#ifdef __BIG_ENDIAN
884 if (sfb->fb.var.bits_per_pixel == 32)
885 smtc_seqw(0x17, 0x30);
886#endif
Wu Zhangjind7edf472009-11-23 10:28:24 +0800887 break;
888 case 0x720:
889 sfb->fb.fix.mmio_start = pFramebufferPhysical;
890 sfb->fb.fix.mmio_len = 0x00200000;
891 smem_size = SM722_VIDEOMEMORYSIZE;
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200892 sfb->m_pDPR = ioremap(pFramebufferPhysical, 0x00a00000);
893 sfb->m_pLFB = (smtc_VRAMBaseAddress =
894 sfb->m_pDPR + 0x00200000);
895 sfb->m_pMMIO = (smtc_RegBaseAddress =
896 sfb->m_pDPR + 0x000c0000);
897 sfb->m_pVPR = sfb->m_pDPR + 0x800;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800898
899 smtc_seqw(0x62, 0xff);
900 smtc_seqw(0x6a, 0x0d);
901 smtc_seqw(0x6b, 0x02);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800902 break;
903 default:
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200904 dev_err(&pdev->dev,
905 "No valid Silicon Motion display chip was detected!");
Wu Zhangjind7edf472009-11-23 10:28:24 +0800906
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400907 goto failed_fb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800908 }
909
910 /* can support 32 bpp */
911 if (15 == sfb->fb.var.bits_per_pixel)
912 sfb->fb.var.bits_per_pixel = 16;
913
914 sfb->fb.var.xres_virtual = sfb->fb.var.xres;
915 sfb->fb.var.yres_virtual = sfb->fb.var.yres;
916 err = smtc_map_smem(sfb, pdev, smem_size);
917 if (err)
918 goto failed;
919
920 smtcfb_setmode(sfb);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800921
922 err = register_framebuffer(&sfb->fb);
923 if (err < 0)
924 goto failed;
925
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200926 dev_info(&pdev->dev,
Javier M. Mellid9be467d2012-04-26 20:45:53 +0200927 "Silicon Motion SM%X Rev%X primary display mode %dx%d-%d Init Complete.",
928 sfb->chipID, sfb->chipRevID, sfb->fb.var.xres,
929 sfb->fb.var.yres, sfb->fb.var.bits_per_pixel);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800930
931 return 0;
932
anish kumar1639c8a2011-05-19 20:58:42 +0530933failed:
Javier M. Mellid6f54b092012-04-26 20:45:52 +0200934 dev_err(&pdev->dev, "Silicon Motion, Inc. primary display init fail.");
Wu Zhangjind7edf472009-11-23 10:28:24 +0800935
936 smtc_unmap_smem(sfb);
937 smtc_unmap_mmio(sfb);
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400938failed_fb:
Wu Zhangjind7edf472009-11-23 10:28:24 +0800939 smtc_free_fb_info(sfb);
940
Kulikov Vasiliy918e3592010-08-06 23:53:23 +0400941failed_free:
942 pci_disable_device(pdev);
943
Wu Zhangjind7edf472009-11-23 10:28:24 +0800944 return err;
945}
946
Javier M. Mellid0beb30d2012-06-10 13:12:23 +0200947/*
948 * 0x710 (LynxEM)
949 * 0x712 (LynxEM+)
950 * 0x720 (Lynx3DM, Lynx3DM+)
951 */
Namhyung Kim6f475b72010-12-10 01:40:25 +0900952static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
Peter Huewec0fe6022011-11-27 15:12:57 +0100953 { PCI_DEVICE(0x126f, 0x710), },
954 { PCI_DEVICE(0x126f, 0x712), },
955 { PCI_DEVICE(0x126f, 0x720), },
Wu Zhangjind7edf472009-11-23 10:28:24 +0800956 {0,}
957};
958
Wu Zhangjind7edf472009-11-23 10:28:24 +0800959static void __devexit smtcfb_pci_remove(struct pci_dev *pdev)
960{
961 struct smtcfb_info *sfb;
962
963 sfb = pci_get_drvdata(pdev);
964 pci_set_drvdata(pdev, NULL);
965 smtc_unmap_smem(sfb);
966 smtc_unmap_mmio(sfb);
967 unregister_framebuffer(&sfb->fb);
968 smtc_free_fb_info(sfb);
969}
970
Javier M. Mellid392a0022011-03-30 16:24:10 +0200971#ifdef CONFIG_PM
Javier M. Mellid59815672011-04-30 17:44:25 +0200972static int smtcfb_pci_suspend(struct device *device)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800973{
Javier M. Mellid59815672011-04-30 17:44:25 +0200974 struct pci_dev *pdev = to_pci_dev(device);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800975 struct smtcfb_info *sfb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800976
977 sfb = pci_get_drvdata(pdev);
978
Justin P. Mattock7756d3e8b2012-06-25 07:28:25 -0700979 /* set the hw in sleep mode use external clock and self memory refresh
Wu Zhangjind7edf472009-11-23 10:28:24 +0800980 * so that we can turn off internal PLLs later on
981 */
982 smtc_seqw(0x20, (smtc_seqr(0x20) | 0xc0));
983 smtc_seqw(0x69, (smtc_seqr(0x69) & 0xf7));
984
Javier M. Mellid59815672011-04-30 17:44:25 +0200985 console_lock();
986 fb_set_suspend(&sfb->fb, 1);
987 console_unlock();
Wu Zhangjind7edf472009-11-23 10:28:24 +0800988
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300989 /* additionally turn off all function blocks including internal PLLs */
Wu Zhangjind7edf472009-11-23 10:28:24 +0800990 smtc_seqw(0x21, 0xff);
991
992 return 0;
993}
994
Javier M. Mellid59815672011-04-30 17:44:25 +0200995static int smtcfb_pci_resume(struct device *device)
Wu Zhangjind7edf472009-11-23 10:28:24 +0800996{
Javier M. Mellid59815672011-04-30 17:44:25 +0200997 struct pci_dev *pdev = to_pci_dev(device);
Wu Zhangjind7edf472009-11-23 10:28:24 +0800998 struct smtcfb_info *sfb;
Wu Zhangjind7edf472009-11-23 10:28:24 +0800999
1000 sfb = pci_get_drvdata(pdev);
1001
Wu Zhangjind7edf472009-11-23 10:28:24 +08001002 /* reinit hardware */
1003 sm7xx_init_hw();
Javier M. Mellid9be467d2012-04-26 20:45:53 +02001004 switch (sfb->chipID) {
Wu Zhangjind7edf472009-11-23 10:28:24 +08001005 case 0x710:
1006 case 0x712:
1007 /* set MCLK = 14.31818 * (0x16 / 0x2) */
1008 smtc_seqw(0x6a, 0x16);
1009 smtc_seqw(0x6b, 0x02);
1010 smtc_seqw(0x62, 0x3e);
1011 /* enable PCI burst */
1012 smtc_seqw(0x17, 0x20);
1013#ifdef __BIG_ENDIAN
1014 if (sfb->fb.var.bits_per_pixel == 32)
1015 smtc_seqw(0x17, 0x30);
1016#endif
1017 break;
1018 case 0x720:
1019 smtc_seqw(0x62, 0xff);
1020 smtc_seqw(0x6a, 0x0d);
1021 smtc_seqw(0x6b, 0x02);
1022 break;
1023 }
1024
1025 smtc_seqw(0x34, (smtc_seqr(0x34) | 0xc0));
1026 smtc_seqw(0x33, ((smtc_seqr(0x33) | 0x08) & 0xfb));
1027
1028 smtcfb_setmode(sfb);
1029
Torben Hohnac751ef2011-01-25 15:07:35 -08001030 console_lock();
Wu Zhangjind7edf472009-11-23 10:28:24 +08001031 fb_set_suspend(&sfb->fb, 0);
Torben Hohnac751ef2011-01-25 15:07:35 -08001032 console_unlock();
Wu Zhangjind7edf472009-11-23 10:28:24 +08001033
1034 return 0;
1035}
Wu Zhangjind7edf472009-11-23 10:28:24 +08001036
Javier M. Mellid59815672011-04-30 17:44:25 +02001037static const struct dev_pm_ops sm7xx_pm_ops = {
1038 .suspend = smtcfb_pci_suspend,
1039 .resume = smtcfb_pci_resume,
1040 .freeze = smtcfb_pci_suspend,
1041 .thaw = smtcfb_pci_resume,
1042 .poweroff = smtcfb_pci_suspend,
1043 .restore = smtcfb_pci_resume,
1044};
1045
1046#define SM7XX_PM_OPS (&sm7xx_pm_ops)
1047
1048#else /* !CONFIG_PM */
1049
1050#define SM7XX_PM_OPS NULL
1051
1052#endif /* !CONFIG_PM */
1053
Wu Zhangjind7edf472009-11-23 10:28:24 +08001054static struct pci_driver smtcfb_driver = {
1055 .name = "smtcfb",
1056 .id_table = smtcfb_pci_table,
1057 .probe = smtcfb_pci_probe,
1058 .remove = __devexit_p(smtcfb_pci_remove),
Javier M. Mellid59815672011-04-30 17:44:25 +02001059 .driver.pm = SM7XX_PM_OPS,
Wu Zhangjind7edf472009-11-23 10:28:24 +08001060};
1061
1062static int __init smtcfb_init(void)
1063{
1064 return pci_register_driver(&smtcfb_driver);
1065}
1066
1067static void __exit smtcfb_exit(void)
1068{
1069 pci_unregister_driver(&smtcfb_driver);
1070}
1071
1072module_init(smtcfb_init);
1073module_exit(smtcfb_exit);
1074
1075MODULE_AUTHOR("Siliconmotion ");
1076MODULE_DESCRIPTION("Framebuffer driver for SMI Graphic Cards");
1077MODULE_LICENSE("GPL");