]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/video/geode/lxfb_core.c
Merge branch 'omap-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[net-next-2.6.git] / drivers / video / geode / lxfb_core.c
CommitLineData
3968cb49
JC
1/*
2 * Geode LX framebuffer driver.
3 *
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 * Built from gxfb (which is Copyright (C) 2006 Arcom Control Systems Ltd.)
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/errno.h>
16#include <linux/string.h>
17#include <linux/console.h>
18#include <linux/mm.h>
564820d4 19#include <linux/suspend.h>
3968cb49
JC
20#include <linux/delay.h>
21#include <linux/fb.h>
22#include <linux/init.h>
23#include <linux/pci.h>
24#include <linux/uaccess.h>
25
26#include "lxfb.h"
27
28static char *mode_option;
29static int noclear, nopanel, nocrt;
c805df3d 30static int vram;
564820d4 31static int vt_switch;
3968cb49
JC
32
33/* Most of these modes are sorted in ascending order, but
34 * since the first entry in this table is the "default" mode,
35 * we try to make it something sane - 640x480-60 is sane
36 */
37
12c46b33 38static struct fb_videomode geode_modedb[] __devinitdata = {
3968cb49
JC
39 /* 640x480-60 */
40 { NULL, 60, 640, 480, 39682, 48, 8, 25, 2, 88, 2,
41 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
42 FB_VMODE_NONINTERLACED, 0 },
43 /* 640x400-70 */
44 { NULL, 70, 640, 400, 39770, 40, 8, 28, 5, 96, 2,
45 FB_SYNC_HOR_HIGH_ACT,
46 FB_VMODE_NONINTERLACED, 0 },
47 /* 640x480-70 */
48 { NULL, 70, 640, 480, 35014, 88, 24, 15, 2, 64, 3,
49 0, FB_VMODE_NONINTERLACED, 0 },
50 /* 640x480-72 */
51 { NULL, 72, 640, 480, 32102, 120, 16, 20, 1, 40, 3,
52 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
53 FB_VMODE_NONINTERLACED, 0 },
54 /* 640x480-75 */
55 { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
56 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
57 FB_VMODE_NONINTERLACED, 0 },
58 /* 640x480-85 */
59 { NULL, 85, 640, 480, 27780, 80, 56, 25, 1, 56, 3,
60 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
61 FB_VMODE_NONINTERLACED, 0 },
62 /* 640x480-90 */
63 { NULL, 90, 640, 480, 26392, 96, 32, 22, 1, 64, 3,
64 0, FB_VMODE_NONINTERLACED, 0 },
65 /* 640x480-100 */
66 { NULL, 100, 640, 480, 23167, 104, 40, 25, 1, 64, 3,
67 0, FB_VMODE_NONINTERLACED, 0 },
68 /* 640x480-60 */
69 { NULL, 60, 640, 480, 39682, 48, 16, 25, 10, 88, 2,
70 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
71 FB_VMODE_NONINTERLACED, 0 },
72 /* 800x600-56 */
73 { NULL, 56, 800, 600, 27901, 128, 24, 22, 1, 72, 2,
74 0, FB_VMODE_NONINTERLACED, 0 },
75 /* 800x600-60 */
76 { NULL, 60, 800, 600, 25131, 72, 32, 23, 1, 136, 4,
77 0, FB_VMODE_NONINTERLACED, 0 },
78 /* 800x600-70 */
79 { NULL, 70, 800, 600, 21873, 120, 40, 21, 4, 80, 3,
80 0, FB_VMODE_NONINTERLACED, 0 },
81 /* 800x600-72 */
82 { NULL, 72, 800, 600, 20052, 64, 56, 23, 37, 120, 6,
83 0, FB_VMODE_NONINTERLACED, 0 },
84 /* 800x600-75 */
85 { NULL, 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3,
86 0, FB_VMODE_NONINTERLACED, 0 },
87 /* 800x600-85 */
88 { NULL, 85, 800, 600, 17790, 152, 32, 27, 1, 64, 3,
89 0, FB_VMODE_NONINTERLACED, 0 },
90 /* 800x600-90 */
91 { NULL, 90, 800, 600, 16648, 128, 40, 28, 1, 88, 3,
92 0, FB_VMODE_NONINTERLACED, 0 },
93 /* 800x600-100 */
94 { NULL, 100, 800, 600, 14667, 136, 48, 27, 1, 88, 3,
95 0, FB_VMODE_NONINTERLACED, 0 },
96 /* 800x600-60 */
97 { NULL, 60, 800, 600, 25131, 88, 40, 23, 1, 128, 4,
98 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
99 FB_VMODE_NONINTERLACED, 0 },
100 /* 1024x768-60 */
101 { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
102 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
103 FB_VMODE_NONINTERLACED, 0 },
104 /* 1024x768-70 */
105 { NULL, 70, 1024, 768, 13346, 144, 24, 29, 3, 136, 6,
106 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
107 FB_VMODE_NONINTERLACED, 0 },
108 /* 1024x768-72 */
109 { NULL, 72, 1024, 768, 12702, 168, 56, 29, 4, 112, 3,
110 0, FB_VMODE_NONINTERLACED, 0 },
111 /* 1024x768-75 */
112 { NULL, 75, 1024, 768, 12703, 176, 16, 28, 1, 96, 3,
113 0, FB_VMODE_NONINTERLACED, 0 },
114 /* 1024x768-85 */
115 { NULL, 85, 1024, 768, 10581, 208, 48, 36, 1, 96, 3,
116 0, FB_VMODE_NONINTERLACED, 0 },
117 /* 1024x768-90 */
118 { NULL, 90, 1024, 768, 9981, 176, 64, 37, 1, 112, 3,
119 0, FB_VMODE_NONINTERLACED, 0 },
120 /* 1024x768-100 */
121 { NULL, 100, 1024, 768, 8825, 184, 72, 42, 1, 112, 3,
122 0, FB_VMODE_NONINTERLACED, 0 },
123 /* 1024x768-60 */
124 { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
125 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
126 FB_VMODE_NONINTERLACED, 0 },
127 /* 1152x864-60 */
128 { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
129 0, FB_VMODE_NONINTERLACED, 0 },
130 /* 1152x864-70 */
131 { NULL, 70, 1152, 864, 10254, 192, 72, 32, 8, 120, 3,
132 0, FB_VMODE_NONINTERLACED, 0 },
133 /* 1152x864-72 */
134 { NULL, 72, 1152, 864, 9866, 200, 72, 33, 7, 128, 3,
135 0, FB_VMODE_NONINTERLACED, 0 },
136 /* 1152x864-75 */
137 { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
138 0, FB_VMODE_NONINTERLACED, 0 },
139 /* 1152x864-85 */
140 { NULL, 85, 1152, 864, 8357, 200, 72, 37, 3, 128, 3,
141 0, FB_VMODE_NONINTERLACED, 0 },
142 /* 1152x864-90 */
143 { NULL, 90, 1152, 864, 7719, 208, 80, 42, 9, 128, 3,
144 0, FB_VMODE_NONINTERLACED, 0 },
145 /* 1152x864-100 */
146 { NULL, 100, 1152, 864, 6947, 208, 80, 48, 3, 128, 3,
147 0, FB_VMODE_NONINTERLACED, 0 },
148 /* 1152x864-60 */
149 { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
150 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
151 FB_VMODE_NONINTERLACED, 0 },
152 /* 1280x1024-60 */
153 { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
154 0, FB_VMODE_NONINTERLACED, 0 },
155 /* 1280x1024-70 */
156 { NULL, 70, 1280, 1024, 7719, 224, 88, 38, 6, 136, 3,
157 0, FB_VMODE_NONINTERLACED, 0 },
158 /* 1280x1024-72 */
159 { NULL, 72, 1280, 1024, 7490, 224, 88, 39, 7, 136, 3,
160 0, FB_VMODE_NONINTERLACED, 0 },
161 /* 1280x1024-75 */
162 { NULL, 75, 1280, 1024, 7409, 248, 16, 38, 1, 144, 3,
163 0, FB_VMODE_NONINTERLACED, 0 },
164 /* 1280x1024-85 */
165 { NULL, 85, 1280, 1024, 6351, 224, 64, 44, 1, 160, 3,
166 0, FB_VMODE_NONINTERLACED, 0 },
167 /* 1280x1024-90 */
168 { NULL, 90, 1280, 1024, 5791, 240, 96, 51, 12, 144, 3,
169 0, FB_VMODE_NONINTERLACED, 0 },
170 /* 1280x1024-100 */
171 { NULL, 100, 1280, 1024, 5212, 240, 96, 57, 6, 144, 3,
172 0, FB_VMODE_NONINTERLACED, 0 },
173 /* 1280x1024-60 */
174 { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
175 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
176 FB_VMODE_NONINTERLACED, 0 },
177 /* 1600x1200-60 */
178 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
179 0, FB_VMODE_NONINTERLACED, 0 },
180 /* 1600x1200-70 */
181 { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
182 0, FB_VMODE_NONINTERLACED, 0 },
183 /* 1600x1200-72 */
184 { NULL, 72, 1600, 1200, 5053, 288, 112, 47, 13, 176, 3,
185 0, FB_VMODE_NONINTERLACED, 0 },
186 /* 1600x1200-75 */
187 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
188 0, FB_VMODE_NONINTERLACED, 0 },
189 /* 1600x1200-85 */
190 { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
191 0, FB_VMODE_NONINTERLACED, 0 },
192 /* 1600x1200-90 */
193 { NULL, 90, 1600, 1200, 3981, 304, 128, 60, 1, 176, 3,
194 0, FB_VMODE_NONINTERLACED, 0 },
195 /* 1600x1200-100 */
196 { NULL, 100, 1600, 1200, 3563, 304, 128, 67, 1, 176, 3,
197 0, FB_VMODE_NONINTERLACED, 0 },
198 /* 1600x1200-60 */
199 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
200 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
201 FB_VMODE_NONINTERLACED, 0 },
202 /* 1920x1440-60 */
203 { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 208, 3,
204 0, FB_VMODE_NONINTERLACED, 0 },
205 /* 1920x1440-70 */
206 { NULL, 70, 1920, 1440, 3593, 360, 152, 55, 8, 208, 3,
207 0, FB_VMODE_NONINTERLACED, 0 },
208 /* 1920x1440-72 */
209 { NULL, 72, 1920, 1440, 3472, 360, 152, 68, 4, 208, 3,
210 0, FB_VMODE_NONINTERLACED, 0 },
211 /* 1920x1440-75 */
212 { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
213 0, FB_VMODE_NONINTERLACED, 0 },
214 /* 1920x1440-85 */
215 { NULL, 85, 1920, 1440, 2929, 368, 152, 68, 1, 216, 3,
216 0, FB_VMODE_NONINTERLACED, 0 },
217};
218
3553a2fa
AS
219#ifdef CONFIG_OLPC
220#include <asm/olpc.h>
221
12c46b33 222static struct fb_videomode olpc_dcon_modedb[] __devinitdata = {
3553a2fa
AS
223 /* The only mode the DCON has is 1200x900 */
224 { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3,
225 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
226 FB_VMODE_NONINTERLACED, 0 }
227};
228
12c46b33
AS
229static void __devinit get_modedb(struct fb_videomode **modedb,
230 unsigned int *size)
3553a2fa
AS
231{
232 if (olpc_has_dcon()) {
233 *modedb = (struct fb_videomode *) olpc_dcon_modedb;
234 *size = ARRAY_SIZE(olpc_dcon_modedb);
235 } else {
236 *modedb = (struct fb_videomode *) geode_modedb;
237 *size = ARRAY_SIZE(geode_modedb);
238 }
239}
240
241#else
12c46b33
AS
242static void __devinit get_modedb(struct fb_videomode **modedb,
243 unsigned int *size)
3553a2fa
AS
244{
245 *modedb = (struct fb_videomode *) geode_modedb;
246 *size = ARRAY_SIZE(geode_modedb);
247}
248#endif
249
3968cb49
JC
250static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
251{
252 if (var->xres > 1920 || var->yres > 1440)
253 return -EINVAL;
254
255 if (var->bits_per_pixel == 32) {
256 var->red.offset = 16; var->red.length = 8;
257 var->green.offset = 8; var->green.length = 8;
258 var->blue.offset = 0; var->blue.length = 8;
259 } else if (var->bits_per_pixel == 16) {
260 var->red.offset = 11; var->red.length = 5;
261 var->green.offset = 5; var->green.length = 6;
262 var->blue.offset = 0; var->blue.length = 5;
263 } else if (var->bits_per_pixel == 8) {
264 var->red.offset = 0; var->red.length = 8;
265 var->green.offset = 0; var->green.length = 8;
266 var->blue.offset = 0; var->blue.length = 8;
267 } else
268 return -EINVAL;
269
270 var->transp.offset = 0; var->transp.length = 0;
271
272 /* Enough video memory? */
273 if ((lx_get_pitch(var->xres, var->bits_per_pixel) * var->yres)
274 > info->fix.smem_len)
275 return -EINVAL;
276
277 return 0;
278}
279
280static int lxfb_set_par(struct fb_info *info)
281{
067f1293 282 if (info->var.bits_per_pixel > 8)
3968cb49 283 info->fix.visual = FB_VISUAL_TRUECOLOR;
067f1293 284 else
3968cb49 285 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
3968cb49
JC
286
287 info->fix.line_length = lx_get_pitch(info->var.xres,
288 info->var.bits_per_pixel);
289
290 lx_set_mode(info);
291 return 0;
292}
293
294static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
295{
296 chan &= 0xffff;
297 chan >>= 16 - bf->length;
298 return chan << bf->offset;
299}
300
301static int lxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
302 unsigned blue, unsigned transp,
303 struct fb_info *info)
304{
305 if (info->var.grayscale) {
306 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
307 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
308 }
309
310 /* Truecolor has hardware independent palette */
311 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
312 u32 *pal = info->pseudo_palette;
313 u32 v;
314
315 if (regno >= 16)
316 return -EINVAL;
317
318 v = chan_to_field(red, &info->var.red);
319 v |= chan_to_field(green, &info->var.green);
320 v |= chan_to_field(blue, &info->var.blue);
321
322 pal[regno] = v;
323 } else {
324 if (regno >= 256)
325 return -EINVAL;
326
327 lx_set_palette_reg(info, regno, red, green, blue);
328 }
329
330 return 0;
331}
332
333static int lxfb_blank(int blank_mode, struct fb_info *info)
334{
335 return lx_blank_display(info, blank_mode);
336}
337
338
12c46b33 339static int __devinit lxfb_map_video_memory(struct fb_info *info,
3968cb49
JC
340 struct pci_dev *dev)
341{
342 struct lxfb_par *par = info->par;
343 int ret;
344
345 ret = pci_enable_device(dev);
346
347 if (ret)
348 return ret;
349
350 ret = pci_request_region(dev, 0, "lxfb-framebuffer");
351
352 if (ret)
353 return ret;
354
355 ret = pci_request_region(dev, 1, "lxfb-gp");
356
357 if (ret)
358 return ret;
359
360 ret = pci_request_region(dev, 2, "lxfb-vg");
361
362 if (ret)
363 return ret;
364
31f51fa8 365 ret = pci_request_region(dev, 3, "lxfb-vp");
3968cb49
JC
366
367 if (ret)
368 return ret;
369
370 info->fix.smem_start = pci_resource_start(dev, 0);
c805df3d 371 info->fix.smem_len = vram ? vram : lx_framebuffer_size();
3968cb49
JC
372
373 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
374
375 ret = -ENOMEM;
376
377 if (info->screen_base == NULL)
378 return ret;
379
3c36aa5c 380 par->gp_regs = pci_ioremap_bar(dev, 1);
3968cb49
JC
381
382 if (par->gp_regs == NULL)
383 return ret;
384
3c36aa5c 385 par->dc_regs = pci_ioremap_bar(dev, 2);
3968cb49
JC
386
387 if (par->dc_regs == NULL)
388 return ret;
389
3c36aa5c 390 par->vp_regs = pci_ioremap_bar(dev, 3);
3968cb49 391
31f51fa8 392 if (par->vp_regs == NULL)
3968cb49
JC
393 return ret;
394
f5c90e85
AS
395 write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
396 write_dc(par, DC_GLIU0_MEM_OFFSET, info->fix.smem_start & 0xFF000000);
397 write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
3968cb49
JC
398
399 dev_info(&dev->dev, "%d KB of video memory at 0x%lx\n",
400 info->fix.smem_len / 1024, info->fix.smem_start);
401
402 return 0;
403}
404
405static struct fb_ops lxfb_ops = {
406 .owner = THIS_MODULE,
407 .fb_check_var = lxfb_check_var,
408 .fb_set_par = lxfb_set_par,
409 .fb_setcolreg = lxfb_setcolreg,
410 .fb_blank = lxfb_blank,
411 /* No HW acceleration for now. */
412 .fb_fillrect = cfb_fillrect,
413 .fb_copyarea = cfb_copyarea,
414 .fb_imageblit = cfb_imageblit,
415};
416
12c46b33 417static struct fb_info * __devinit lxfb_init_fbinfo(struct device *dev)
3968cb49
JC
418{
419 struct lxfb_par *par;
420 struct fb_info *info;
421
422 /* Alloc enough space for the pseudo palette. */
423 info = framebuffer_alloc(sizeof(struct lxfb_par) + sizeof(u32) * 16,
424 dev);
425 if (!info)
426 return NULL;
427
428 par = info->par;
429
430 strcpy(info->fix.id, "Geode LX");
431
432 info->fix.type = FB_TYPE_PACKED_PIXELS;
433 info->fix.type_aux = 0;
434 info->fix.xpanstep = 0;
435 info->fix.ypanstep = 0;
436 info->fix.ywrapstep = 0;
437 info->fix.accel = FB_ACCEL_NONE;
438
439 info->var.nonstd = 0;
440 info->var.activate = FB_ACTIVATE_NOW;
441 info->var.height = -1;
442 info->var.width = -1;
443 info->var.accel_flags = 0;
444 info->var.vmode = FB_VMODE_NONINTERLACED;
445
446 info->fbops = &lxfb_ops;
447 info->flags = FBINFO_DEFAULT;
448 info->node = -1;
449
450 info->pseudo_palette = (void *)par + sizeof(struct lxfb_par);
451
067f1293
MLP
452 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
453 framebuffer_release(info);
454 return NULL;
455 }
456
3968cb49
JC
457 info->var.grayscale = 0;
458
459 return info;
460}
461
f694e53b
AS
462#ifdef CONFIG_PM
463static int lxfb_suspend(struct pci_dev *pdev, pm_message_t state)
464{
465 struct fb_info *info = pci_get_drvdata(pdev);
466
467 if (state.event == PM_EVENT_SUSPEND) {
468 acquire_console_sem();
469 lx_powerdown(info);
470 fb_set_suspend(info, 1);
471 release_console_sem();
472 }
473
474 /* there's no point in setting PCI states; we emulate PCI, so
475 * we don't end up getting power savings anyways */
476
477 return 0;
478}
479
480static int lxfb_resume(struct pci_dev *pdev)
481{
482 struct fb_info *info = pci_get_drvdata(pdev);
483 int ret;
484
485 acquire_console_sem();
486 ret = lx_powerup(info);
487 if (ret) {
488 printk(KERN_ERR "lxfb: power up failed!\n");
489 return ret;
490 }
491
492 fb_set_suspend(info, 0);
493 release_console_sem();
494 return 0;
495}
496#else
497#define lxfb_suspend NULL
498#define lxfb_resume NULL
499#endif
500
12c46b33 501static int __devinit lxfb_probe(struct pci_dev *pdev,
3968cb49
JC
502 const struct pci_device_id *id)
503{
504 struct lxfb_par *par;
505 struct fb_info *info;
506 int ret;
507
508 struct fb_videomode *modedb_ptr;
3553a2fa 509 unsigned int modedb_size;
3968cb49
JC
510
511 info = lxfb_init_fbinfo(&pdev->dev);
512
513 if (info == NULL)
514 return -ENOMEM;
515
516 par = info->par;
517
518 ret = lxfb_map_video_memory(info, pdev);
519
520 if (ret < 0) {
521 dev_err(&pdev->dev,
522 "failed to map frame buffer or controller registers\n");
523 goto err;
524 }
525
526 /* Set up the desired outputs */
527
528 par->output = 0;
529 par->output |= (nopanel) ? 0 : OUTPUT_PANEL;
530 par->output |= (nocrt) ? 0 : OUTPUT_CRT;
531
532 /* Set up the mode database */
533
3553a2fa 534 get_modedb(&modedb_ptr, &modedb_size);
3968cb49
JC
535 ret = fb_find_mode(&info->var, info, mode_option,
536 modedb_ptr, modedb_size, NULL, 16);
537
538 if (ret == 0 || ret == 4) {
539 dev_err(&pdev->dev, "could not find valid video mode\n");
540 ret = -EINVAL;
541 goto err;
542 }
543
544 /* Clear the screen of garbage, unless noclear was specified,
545 * in which case we assume the user knows what he is doing */
546
547 if (!noclear)
548 memset_io(info->screen_base, 0, info->fix.smem_len);
549
550 /* Set the mode */
551
552 lxfb_check_var(&info->var, info);
553 lxfb_set_par(info);
554
564820d4
AS
555 pm_set_vt_switch(vt_switch);
556
3968cb49
JC
557 if (register_framebuffer(info) < 0) {
558 ret = -EINVAL;
559 goto err;
560 }
561 pci_set_drvdata(pdev, info);
562 printk(KERN_INFO "fb%d: %s frame buffer device\n",
563 info->node, info->fix.id);
564
565 return 0;
566
567err:
568 if (info->screen_base) {
569 iounmap(info->screen_base);
570 pci_release_region(pdev, 0);
571 }
572 if (par->gp_regs) {
573 iounmap(par->gp_regs);
574 pci_release_region(pdev, 1);
575 }
576 if (par->dc_regs) {
577 iounmap(par->dc_regs);
578 pci_release_region(pdev, 2);
579 }
31f51fa8
AS
580 if (par->vp_regs) {
581 iounmap(par->vp_regs);
3968cb49
JC
582 pci_release_region(pdev, 3);
583 }
584
067f1293
MLP
585 if (info) {
586 fb_dealloc_cmap(&info->cmap);
3968cb49 587 framebuffer_release(info);
067f1293 588 }
3968cb49
JC
589
590 return ret;
591}
592
12c46b33 593static void __devexit lxfb_remove(struct pci_dev *pdev)
3968cb49
JC
594{
595 struct fb_info *info = pci_get_drvdata(pdev);
596 struct lxfb_par *par = info->par;
597
598 unregister_framebuffer(info);
599
600 iounmap(info->screen_base);
601 pci_release_region(pdev, 0);
602
603 iounmap(par->gp_regs);
604 pci_release_region(pdev, 1);
605
606 iounmap(par->dc_regs);
607 pci_release_region(pdev, 2);
608
31f51fa8 609 iounmap(par->vp_regs);
3968cb49
JC
610 pci_release_region(pdev, 3);
611
067f1293 612 fb_dealloc_cmap(&info->cmap);
3968cb49
JC
613 pci_set_drvdata(pdev, NULL);
614 framebuffer_release(info);
615}
616
617static struct pci_device_id lxfb_id_table[] = {
618 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LX_VIDEO) },
619 { 0, }
620};
621
622MODULE_DEVICE_TABLE(pci, lxfb_id_table);
623
624static struct pci_driver lxfb_driver = {
625 .name = "lxfb",
626 .id_table = lxfb_id_table,
627 .probe = lxfb_probe,
628 .remove = lxfb_remove,
f694e53b
AS
629 .suspend = lxfb_suspend,
630 .resume = lxfb_resume,
3968cb49
JC
631};
632
633#ifndef MODULE
634static int __init lxfb_setup(char *options)
635{
636 char *opt;
637
638 if (!options || !*options)
639 return 0;
640
42b558d5 641 while ((opt = strsep(&options, ",")) != NULL) {
3968cb49
JC
642 if (!*opt)
643 continue;
644
c805df3d 645 if (!strcmp(opt, "noclear"))
3968cb49
JC
646 noclear = 1;
647 else if (!strcmp(opt, "nopanel"))
648 nopanel = 1;
649 else if (!strcmp(opt, "nocrt"))
650 nocrt = 1;
651 else
652 mode_option = opt;
653 }
654
655 return 0;
656}
657#endif
658
659static int __init lxfb_init(void)
660{
661#ifndef MODULE
662 char *option = NULL;
663
664 if (fb_get_options("lxfb", &option))
665 return -ENODEV;
666
667 lxfb_setup(option);
668#endif
669 return pci_register_driver(&lxfb_driver);
670}
671static void __exit lxfb_cleanup(void)
672{
673 pci_unregister_driver(&lxfb_driver);
674}
675
676module_init(lxfb_init);
677module_exit(lxfb_cleanup);
678
679module_param(mode_option, charp, 0);
680MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
681
c805df3d
AS
682module_param(vram, int, 0);
683MODULE_PARM_DESC(vram, "video memory size");
3968cb49 684
564820d4
AS
685module_param(vt_switch, int, 0);
686MODULE_PARM_DESC(vt_switch, "enable VT switch during suspend/resume");
687
3968cb49
JC
688MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode LX");
689MODULE_LICENSE("GPL");