blob: 2cd9b74d222545ea771d653cf1d558be43c2173b [file] [log] [blame]
Jordan Crouse3968cb492007-07-31 00:37:40 -07001/*
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>
19#include <linux/slab.h>
Andres Salomon564820d2008-04-28 02:15:28 -070020#include <linux/suspend.h>
Jordan Crouse3968cb492007-07-31 00:37:40 -070021#include <linux/delay.h>
22#include <linux/fb.h>
23#include <linux/init.h>
24#include <linux/pci.h>
25#include <linux/uaccess.h>
26
27#include "lxfb.h"
28
29static char *mode_option;
30static int noclear, nopanel, nocrt;
Andres Salomonc805df32008-04-28 02:15:27 -070031static int vram;
Andres Salomon564820d2008-04-28 02:15:28 -070032static int vt_switch;
Jordan Crouse3968cb492007-07-31 00:37:40 -070033
34/* Most of these modes are sorted in ascending order, but
35 * since the first entry in this table is the "default" mode,
36 * we try to make it something sane - 640x480-60 is sane
37 */
38
Andres Salomon3553a2f2008-04-28 02:15:31 -070039static struct fb_videomode geode_modedb[] __initdata = {
Jordan Crouse3968cb492007-07-31 00:37:40 -070040 /* 640x480-60 */
41 { NULL, 60, 640, 480, 39682, 48, 8, 25, 2, 88, 2,
42 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
43 FB_VMODE_NONINTERLACED, 0 },
44 /* 640x400-70 */
45 { NULL, 70, 640, 400, 39770, 40, 8, 28, 5, 96, 2,
46 FB_SYNC_HOR_HIGH_ACT,
47 FB_VMODE_NONINTERLACED, 0 },
48 /* 640x480-70 */
49 { NULL, 70, 640, 480, 35014, 88, 24, 15, 2, 64, 3,
50 0, FB_VMODE_NONINTERLACED, 0 },
51 /* 640x480-72 */
52 { NULL, 72, 640, 480, 32102, 120, 16, 20, 1, 40, 3,
53 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
54 FB_VMODE_NONINTERLACED, 0 },
55 /* 640x480-75 */
56 { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
57 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
58 FB_VMODE_NONINTERLACED, 0 },
59 /* 640x480-85 */
60 { NULL, 85, 640, 480, 27780, 80, 56, 25, 1, 56, 3,
61 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
62 FB_VMODE_NONINTERLACED, 0 },
63 /* 640x480-90 */
64 { NULL, 90, 640, 480, 26392, 96, 32, 22, 1, 64, 3,
65 0, FB_VMODE_NONINTERLACED, 0 },
66 /* 640x480-100 */
67 { NULL, 100, 640, 480, 23167, 104, 40, 25, 1, 64, 3,
68 0, FB_VMODE_NONINTERLACED, 0 },
69 /* 640x480-60 */
70 { NULL, 60, 640, 480, 39682, 48, 16, 25, 10, 88, 2,
71 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
72 FB_VMODE_NONINTERLACED, 0 },
73 /* 800x600-56 */
74 { NULL, 56, 800, 600, 27901, 128, 24, 22, 1, 72, 2,
75 0, FB_VMODE_NONINTERLACED, 0 },
76 /* 800x600-60 */
77 { NULL, 60, 800, 600, 25131, 72, 32, 23, 1, 136, 4,
78 0, FB_VMODE_NONINTERLACED, 0 },
79 /* 800x600-70 */
80 { NULL, 70, 800, 600, 21873, 120, 40, 21, 4, 80, 3,
81 0, FB_VMODE_NONINTERLACED, 0 },
82 /* 800x600-72 */
83 { NULL, 72, 800, 600, 20052, 64, 56, 23, 37, 120, 6,
84 0, FB_VMODE_NONINTERLACED, 0 },
85 /* 800x600-75 */
86 { NULL, 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3,
87 0, FB_VMODE_NONINTERLACED, 0 },
88 /* 800x600-85 */
89 { NULL, 85, 800, 600, 17790, 152, 32, 27, 1, 64, 3,
90 0, FB_VMODE_NONINTERLACED, 0 },
91 /* 800x600-90 */
92 { NULL, 90, 800, 600, 16648, 128, 40, 28, 1, 88, 3,
93 0, FB_VMODE_NONINTERLACED, 0 },
94 /* 800x600-100 */
95 { NULL, 100, 800, 600, 14667, 136, 48, 27, 1, 88, 3,
96 0, FB_VMODE_NONINTERLACED, 0 },
97 /* 800x600-60 */
98 { NULL, 60, 800, 600, 25131, 88, 40, 23, 1, 128, 4,
99 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
100 FB_VMODE_NONINTERLACED, 0 },
101 /* 1024x768-60 */
102 { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
103 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
104 FB_VMODE_NONINTERLACED, 0 },
105 /* 1024x768-70 */
106 { NULL, 70, 1024, 768, 13346, 144, 24, 29, 3, 136, 6,
107 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
108 FB_VMODE_NONINTERLACED, 0 },
109 /* 1024x768-72 */
110 { NULL, 72, 1024, 768, 12702, 168, 56, 29, 4, 112, 3,
111 0, FB_VMODE_NONINTERLACED, 0 },
112 /* 1024x768-75 */
113 { NULL, 75, 1024, 768, 12703, 176, 16, 28, 1, 96, 3,
114 0, FB_VMODE_NONINTERLACED, 0 },
115 /* 1024x768-85 */
116 { NULL, 85, 1024, 768, 10581, 208, 48, 36, 1, 96, 3,
117 0, FB_VMODE_NONINTERLACED, 0 },
118 /* 1024x768-90 */
119 { NULL, 90, 1024, 768, 9981, 176, 64, 37, 1, 112, 3,
120 0, FB_VMODE_NONINTERLACED, 0 },
121 /* 1024x768-100 */
122 { NULL, 100, 1024, 768, 8825, 184, 72, 42, 1, 112, 3,
123 0, FB_VMODE_NONINTERLACED, 0 },
124 /* 1024x768-60 */
125 { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
126 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
127 FB_VMODE_NONINTERLACED, 0 },
128 /* 1152x864-60 */
129 { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
130 0, FB_VMODE_NONINTERLACED, 0 },
131 /* 1152x864-70 */
132 { NULL, 70, 1152, 864, 10254, 192, 72, 32, 8, 120, 3,
133 0, FB_VMODE_NONINTERLACED, 0 },
134 /* 1152x864-72 */
135 { NULL, 72, 1152, 864, 9866, 200, 72, 33, 7, 128, 3,
136 0, FB_VMODE_NONINTERLACED, 0 },
137 /* 1152x864-75 */
138 { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
139 0, FB_VMODE_NONINTERLACED, 0 },
140 /* 1152x864-85 */
141 { NULL, 85, 1152, 864, 8357, 200, 72, 37, 3, 128, 3,
142 0, FB_VMODE_NONINTERLACED, 0 },
143 /* 1152x864-90 */
144 { NULL, 90, 1152, 864, 7719, 208, 80, 42, 9, 128, 3,
145 0, FB_VMODE_NONINTERLACED, 0 },
146 /* 1152x864-100 */
147 { NULL, 100, 1152, 864, 6947, 208, 80, 48, 3, 128, 3,
148 0, FB_VMODE_NONINTERLACED, 0 },
149 /* 1152x864-60 */
150 { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
151 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
152 FB_VMODE_NONINTERLACED, 0 },
153 /* 1280x1024-60 */
154 { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
155 0, FB_VMODE_NONINTERLACED, 0 },
156 /* 1280x1024-70 */
157 { NULL, 70, 1280, 1024, 7719, 224, 88, 38, 6, 136, 3,
158 0, FB_VMODE_NONINTERLACED, 0 },
159 /* 1280x1024-72 */
160 { NULL, 72, 1280, 1024, 7490, 224, 88, 39, 7, 136, 3,
161 0, FB_VMODE_NONINTERLACED, 0 },
162 /* 1280x1024-75 */
163 { NULL, 75, 1280, 1024, 7409, 248, 16, 38, 1, 144, 3,
164 0, FB_VMODE_NONINTERLACED, 0 },
165 /* 1280x1024-85 */
166 { NULL, 85, 1280, 1024, 6351, 224, 64, 44, 1, 160, 3,
167 0, FB_VMODE_NONINTERLACED, 0 },
168 /* 1280x1024-90 */
169 { NULL, 90, 1280, 1024, 5791, 240, 96, 51, 12, 144, 3,
170 0, FB_VMODE_NONINTERLACED, 0 },
171 /* 1280x1024-100 */
172 { NULL, 100, 1280, 1024, 5212, 240, 96, 57, 6, 144, 3,
173 0, FB_VMODE_NONINTERLACED, 0 },
174 /* 1280x1024-60 */
175 { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
176 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
177 FB_VMODE_NONINTERLACED, 0 },
178 /* 1600x1200-60 */
179 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
180 0, FB_VMODE_NONINTERLACED, 0 },
181 /* 1600x1200-70 */
182 { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
183 0, FB_VMODE_NONINTERLACED, 0 },
184 /* 1600x1200-72 */
185 { NULL, 72, 1600, 1200, 5053, 288, 112, 47, 13, 176, 3,
186 0, FB_VMODE_NONINTERLACED, 0 },
187 /* 1600x1200-75 */
188 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
189 0, FB_VMODE_NONINTERLACED, 0 },
190 /* 1600x1200-85 */
191 { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
192 0, FB_VMODE_NONINTERLACED, 0 },
193 /* 1600x1200-90 */
194 { NULL, 90, 1600, 1200, 3981, 304, 128, 60, 1, 176, 3,
195 0, FB_VMODE_NONINTERLACED, 0 },
196 /* 1600x1200-100 */
197 { NULL, 100, 1600, 1200, 3563, 304, 128, 67, 1, 176, 3,
198 0, FB_VMODE_NONINTERLACED, 0 },
199 /* 1600x1200-60 */
200 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
201 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
202 FB_VMODE_NONINTERLACED, 0 },
203 /* 1920x1440-60 */
204 { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 208, 3,
205 0, FB_VMODE_NONINTERLACED, 0 },
206 /* 1920x1440-70 */
207 { NULL, 70, 1920, 1440, 3593, 360, 152, 55, 8, 208, 3,
208 0, FB_VMODE_NONINTERLACED, 0 },
209 /* 1920x1440-72 */
210 { NULL, 72, 1920, 1440, 3472, 360, 152, 68, 4, 208, 3,
211 0, FB_VMODE_NONINTERLACED, 0 },
212 /* 1920x1440-75 */
213 { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
214 0, FB_VMODE_NONINTERLACED, 0 },
215 /* 1920x1440-85 */
216 { NULL, 85, 1920, 1440, 2929, 368, 152, 68, 1, 216, 3,
217 0, FB_VMODE_NONINTERLACED, 0 },
218};
219
Andres Salomon3553a2f2008-04-28 02:15:31 -0700220#ifdef CONFIG_OLPC
221#include <asm/olpc.h>
222
223static struct fb_videomode olpc_dcon_modedb[] __initdata = {
224 /* The only mode the DCON has is 1200x900 */
225 { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3,
226 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
227 FB_VMODE_NONINTERLACED, 0 }
228};
229
230static void __init get_modedb(struct fb_videomode **modedb, unsigned int *size)
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
242static void __init get_modedb(struct fb_videomode **modedb, unsigned int *size)
243{
244 *modedb = (struct fb_videomode *) geode_modedb;
245 *size = ARRAY_SIZE(geode_modedb);
246}
247#endif
248
Jordan Crouse3968cb492007-07-31 00:37:40 -0700249static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
250{
251 if (var->xres > 1920 || var->yres > 1440)
252 return -EINVAL;
253
254 if (var->bits_per_pixel == 32) {
255 var->red.offset = 16; var->red.length = 8;
256 var->green.offset = 8; var->green.length = 8;
257 var->blue.offset = 0; var->blue.length = 8;
258 } else if (var->bits_per_pixel == 16) {
259 var->red.offset = 11; var->red.length = 5;
260 var->green.offset = 5; var->green.length = 6;
261 var->blue.offset = 0; var->blue.length = 5;
262 } else if (var->bits_per_pixel == 8) {
263 var->red.offset = 0; var->red.length = 8;
264 var->green.offset = 0; var->green.length = 8;
265 var->blue.offset = 0; var->blue.length = 8;
266 } else
267 return -EINVAL;
268
269 var->transp.offset = 0; var->transp.length = 0;
270
271 /* Enough video memory? */
272 if ((lx_get_pitch(var->xres, var->bits_per_pixel) * var->yres)
273 > info->fix.smem_len)
274 return -EINVAL;
275
276 return 0;
277}
278
279static int lxfb_set_par(struct fb_info *info)
280{
281 if (info->var.bits_per_pixel > 8) {
282 info->fix.visual = FB_VISUAL_TRUECOLOR;
283 fb_dealloc_cmap(&info->cmap);
284 } else {
285 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
286 fb_alloc_cmap(&info->cmap, 1<<info->var.bits_per_pixel, 0);
287 }
288
289 info->fix.line_length = lx_get_pitch(info->var.xres,
290 info->var.bits_per_pixel);
291
292 lx_set_mode(info);
293 return 0;
294}
295
296static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
297{
298 chan &= 0xffff;
299 chan >>= 16 - bf->length;
300 return chan << bf->offset;
301}
302
303static int lxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
304 unsigned blue, unsigned transp,
305 struct fb_info *info)
306{
307 if (info->var.grayscale) {
308 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
309 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
310 }
311
312 /* Truecolor has hardware independent palette */
313 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
314 u32 *pal = info->pseudo_palette;
315 u32 v;
316
317 if (regno >= 16)
318 return -EINVAL;
319
320 v = chan_to_field(red, &info->var.red);
321 v |= chan_to_field(green, &info->var.green);
322 v |= chan_to_field(blue, &info->var.blue);
323
324 pal[regno] = v;
325 } else {
326 if (regno >= 256)
327 return -EINVAL;
328
329 lx_set_palette_reg(info, regno, red, green, blue);
330 }
331
332 return 0;
333}
334
335static int lxfb_blank(int blank_mode, struct fb_info *info)
336{
337 return lx_blank_display(info, blank_mode);
338}
339
340
341static int __init lxfb_map_video_memory(struct fb_info *info,
342 struct pci_dev *dev)
343{
344 struct lxfb_par *par = info->par;
345 int ret;
346
347 ret = pci_enable_device(dev);
348
349 if (ret)
350 return ret;
351
352 ret = pci_request_region(dev, 0, "lxfb-framebuffer");
353
354 if (ret)
355 return ret;
356
357 ret = pci_request_region(dev, 1, "lxfb-gp");
358
359 if (ret)
360 return ret;
361
362 ret = pci_request_region(dev, 2, "lxfb-vg");
363
364 if (ret)
365 return ret;
366
Andres Salomon31f51fa2008-04-28 02:15:25 -0700367 ret = pci_request_region(dev, 3, "lxfb-vp");
Jordan Crouse3968cb492007-07-31 00:37:40 -0700368
369 if (ret)
370 return ret;
371
372 info->fix.smem_start = pci_resource_start(dev, 0);
Andres Salomonc805df32008-04-28 02:15:27 -0700373 info->fix.smem_len = vram ? vram : lx_framebuffer_size();
Jordan Crouse3968cb492007-07-31 00:37:40 -0700374
375 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
376
377 ret = -ENOMEM;
378
379 if (info->screen_base == NULL)
380 return ret;
381
382 par->gp_regs = ioremap(pci_resource_start(dev, 1),
383 pci_resource_len(dev, 1));
384
385 if (par->gp_regs == NULL)
386 return ret;
387
388 par->dc_regs = ioremap(pci_resource_start(dev, 2),
389 pci_resource_len(dev, 2));
390
391 if (par->dc_regs == NULL)
392 return ret;
393
Andres Salomon31f51fa2008-04-28 02:15:25 -0700394 par->vp_regs = ioremap(pci_resource_start(dev, 3),
Jordan Crouse3968cb492007-07-31 00:37:40 -0700395 pci_resource_len(dev, 3));
396
Andres Salomon31f51fa2008-04-28 02:15:25 -0700397 if (par->vp_regs == NULL)
Jordan Crouse3968cb492007-07-31 00:37:40 -0700398 return ret;
399
Andres Salomonf5c90e82008-04-28 02:15:24 -0700400 write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
401 write_dc(par, DC_GLIU0_MEM_OFFSET, info->fix.smem_start & 0xFF000000);
402 write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
Jordan Crouse3968cb492007-07-31 00:37:40 -0700403
404 dev_info(&dev->dev, "%d KB of video memory at 0x%lx\n",
405 info->fix.smem_len / 1024, info->fix.smem_start);
406
407 return 0;
408}
409
410static struct fb_ops lxfb_ops = {
411 .owner = THIS_MODULE,
412 .fb_check_var = lxfb_check_var,
413 .fb_set_par = lxfb_set_par,
414 .fb_setcolreg = lxfb_setcolreg,
415 .fb_blank = lxfb_blank,
416 /* No HW acceleration for now. */
417 .fb_fillrect = cfb_fillrect,
418 .fb_copyarea = cfb_copyarea,
419 .fb_imageblit = cfb_imageblit,
420};
421
422static struct fb_info * __init lxfb_init_fbinfo(struct device *dev)
423{
424 struct lxfb_par *par;
425 struct fb_info *info;
426
427 /* Alloc enough space for the pseudo palette. */
428 info = framebuffer_alloc(sizeof(struct lxfb_par) + sizeof(u32) * 16,
429 dev);
430 if (!info)
431 return NULL;
432
433 par = info->par;
434
435 strcpy(info->fix.id, "Geode LX");
436
437 info->fix.type = FB_TYPE_PACKED_PIXELS;
438 info->fix.type_aux = 0;
439 info->fix.xpanstep = 0;
440 info->fix.ypanstep = 0;
441 info->fix.ywrapstep = 0;
442 info->fix.accel = FB_ACCEL_NONE;
443
444 info->var.nonstd = 0;
445 info->var.activate = FB_ACTIVATE_NOW;
446 info->var.height = -1;
447 info->var.width = -1;
448 info->var.accel_flags = 0;
449 info->var.vmode = FB_VMODE_NONINTERLACED;
450
451 info->fbops = &lxfb_ops;
452 info->flags = FBINFO_DEFAULT;
453 info->node = -1;
454
455 info->pseudo_palette = (void *)par + sizeof(struct lxfb_par);
456
457 info->var.grayscale = 0;
458
459 return info;
460}
461
Andres Salomonf694e532008-04-28 02:15:27 -0700462#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
Jordan Crouse3968cb492007-07-31 00:37:40 -0700501static int __init lxfb_probe(struct pci_dev *pdev,
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;
Andres Salomon3553a2f2008-04-28 02:15:31 -0700509 unsigned int modedb_size;
Jordan Crouse3968cb492007-07-31 00:37:40 -0700510
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
Andres Salomon3553a2f2008-04-28 02:15:31 -0700534 get_modedb(&modedb_ptr, &modedb_size);
Jordan Crouse3968cb492007-07-31 00:37:40 -0700535 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
Andres Salomon564820d2008-04-28 02:15:28 -0700555 pm_set_vt_switch(vt_switch);
556
Jordan Crouse3968cb492007-07-31 00:37:40 -0700557 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 }
Andres Salomon31f51fa2008-04-28 02:15:25 -0700580 if (par->vp_regs) {
581 iounmap(par->vp_regs);
Jordan Crouse3968cb492007-07-31 00:37:40 -0700582 pci_release_region(pdev, 3);
583 }
584
585 if (info)
586 framebuffer_release(info);
587
588 return ret;
589}
590
591static void lxfb_remove(struct pci_dev *pdev)
592{
593 struct fb_info *info = pci_get_drvdata(pdev);
594 struct lxfb_par *par = info->par;
595
596 unregister_framebuffer(info);
597
598 iounmap(info->screen_base);
599 pci_release_region(pdev, 0);
600
601 iounmap(par->gp_regs);
602 pci_release_region(pdev, 1);
603
604 iounmap(par->dc_regs);
605 pci_release_region(pdev, 2);
606
Andres Salomon31f51fa2008-04-28 02:15:25 -0700607 iounmap(par->vp_regs);
Jordan Crouse3968cb492007-07-31 00:37:40 -0700608 pci_release_region(pdev, 3);
609
610 pci_set_drvdata(pdev, NULL);
611 framebuffer_release(info);
612}
613
614static struct pci_device_id lxfb_id_table[] = {
615 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LX_VIDEO) },
616 { 0, }
617};
618
619MODULE_DEVICE_TABLE(pci, lxfb_id_table);
620
621static struct pci_driver lxfb_driver = {
622 .name = "lxfb",
623 .id_table = lxfb_id_table,
624 .probe = lxfb_probe,
625 .remove = lxfb_remove,
Andres Salomonf694e532008-04-28 02:15:27 -0700626 .suspend = lxfb_suspend,
627 .resume = lxfb_resume,
Jordan Crouse3968cb492007-07-31 00:37:40 -0700628};
629
630#ifndef MODULE
631static int __init lxfb_setup(char *options)
632{
633 char *opt;
634
635 if (!options || !*options)
636 return 0;
637
Eugene Teo42b558d2007-10-16 01:28:51 -0700638 while ((opt = strsep(&options, ",")) != NULL) {
Jordan Crouse3968cb492007-07-31 00:37:40 -0700639 if (!*opt)
640 continue;
641
Andres Salomonc805df32008-04-28 02:15:27 -0700642 if (!strcmp(opt, "noclear"))
Jordan Crouse3968cb492007-07-31 00:37:40 -0700643 noclear = 1;
644 else if (!strcmp(opt, "nopanel"))
645 nopanel = 1;
646 else if (!strcmp(opt, "nocrt"))
647 nocrt = 1;
648 else
649 mode_option = opt;
650 }
651
652 return 0;
653}
654#endif
655
656static int __init lxfb_init(void)
657{
658#ifndef MODULE
659 char *option = NULL;
660
661 if (fb_get_options("lxfb", &option))
662 return -ENODEV;
663
664 lxfb_setup(option);
665#endif
666 return pci_register_driver(&lxfb_driver);
667}
668static void __exit lxfb_cleanup(void)
669{
670 pci_unregister_driver(&lxfb_driver);
671}
672
673module_init(lxfb_init);
674module_exit(lxfb_cleanup);
675
676module_param(mode_option, charp, 0);
677MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
678
Andres Salomonc805df32008-04-28 02:15:27 -0700679module_param(vram, int, 0);
680MODULE_PARM_DESC(vram, "video memory size");
Jordan Crouse3968cb492007-07-31 00:37:40 -0700681
Andres Salomon564820d2008-04-28 02:15:28 -0700682module_param(vt_switch, int, 0);
683MODULE_PARM_DESC(vt_switch, "enable VT switch during suspend/resume");
684
Jordan Crouse3968cb492007-07-31 00:37:40 -0700685MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode LX");
686MODULE_LICENSE("GPL");