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