2 * Geode LX framebuffer driver.
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 * Built from gxfb (which is Copyright (C) 2006 Arcom Control Systems Ltd.)
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.
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>
19 #include <linux/slab.h>
20 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/pci.h>
24 #include <linux/uaccess.h>
28 static char *mode_option;
29 static int noclear, nopanel, nocrt;
32 /* Most of these modes are sorted in ascending order, but
33 * since the first entry in this table is the "default" mode,
34 * we try to make it something sane - 640x480-60 is sane
37 const struct fb_videomode geode_modedb[] __initdata = {
39 { NULL, 60, 640, 480, 39682, 48, 8, 25, 2, 88, 2,
40 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
41 FB_VMODE_NONINTERLACED, 0 },
43 { NULL, 70, 640, 400, 39770, 40, 8, 28, 5, 96, 2,
45 FB_VMODE_NONINTERLACED, 0 },
47 { NULL, 70, 640, 480, 35014, 88, 24, 15, 2, 64, 3,
48 0, FB_VMODE_NONINTERLACED, 0 },
50 { NULL, 72, 640, 480, 32102, 120, 16, 20, 1, 40, 3,
51 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
52 FB_VMODE_NONINTERLACED, 0 },
54 { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
55 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
56 FB_VMODE_NONINTERLACED, 0 },
58 { NULL, 85, 640, 480, 27780, 80, 56, 25, 1, 56, 3,
59 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
60 FB_VMODE_NONINTERLACED, 0 },
62 { NULL, 90, 640, 480, 26392, 96, 32, 22, 1, 64, 3,
63 0, FB_VMODE_NONINTERLACED, 0 },
65 { NULL, 100, 640, 480, 23167, 104, 40, 25, 1, 64, 3,
66 0, FB_VMODE_NONINTERLACED, 0 },
68 { NULL, 60, 640, 480, 39682, 48, 16, 25, 10, 88, 2,
69 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
70 FB_VMODE_NONINTERLACED, 0 },
72 { NULL, 56, 800, 600, 27901, 128, 24, 22, 1, 72, 2,
73 0, FB_VMODE_NONINTERLACED, 0 },
75 { NULL, 60, 800, 600, 25131, 72, 32, 23, 1, 136, 4,
76 0, FB_VMODE_NONINTERLACED, 0 },
78 { NULL, 70, 800, 600, 21873, 120, 40, 21, 4, 80, 3,
79 0, FB_VMODE_NONINTERLACED, 0 },
81 { NULL, 72, 800, 600, 20052, 64, 56, 23, 37, 120, 6,
82 0, FB_VMODE_NONINTERLACED, 0 },
84 { NULL, 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3,
85 0, FB_VMODE_NONINTERLACED, 0 },
87 { NULL, 85, 800, 600, 17790, 152, 32, 27, 1, 64, 3,
88 0, FB_VMODE_NONINTERLACED, 0 },
90 { NULL, 90, 800, 600, 16648, 128, 40, 28, 1, 88, 3,
91 0, FB_VMODE_NONINTERLACED, 0 },
93 { NULL, 100, 800, 600, 14667, 136, 48, 27, 1, 88, 3,
94 0, FB_VMODE_NONINTERLACED, 0 },
96 { NULL, 60, 800, 600, 25131, 88, 40, 23, 1, 128, 4,
97 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
98 FB_VMODE_NONINTERLACED, 0 },
100 { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
101 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
102 FB_VMODE_NONINTERLACED, 0 },
104 { NULL, 70, 1024, 768, 13346, 144, 24, 29, 3, 136, 6,
105 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
106 FB_VMODE_NONINTERLACED, 0 },
108 { NULL, 72, 1024, 768, 12702, 168, 56, 29, 4, 112, 3,
109 0, FB_VMODE_NONINTERLACED, 0 },
111 { NULL, 75, 1024, 768, 12703, 176, 16, 28, 1, 96, 3,
112 0, FB_VMODE_NONINTERLACED, 0 },
114 { NULL, 85, 1024, 768, 10581, 208, 48, 36, 1, 96, 3,
115 0, FB_VMODE_NONINTERLACED, 0 },
117 { NULL, 90, 1024, 768, 9981, 176, 64, 37, 1, 112, 3,
118 0, FB_VMODE_NONINTERLACED, 0 },
120 { NULL, 100, 1024, 768, 8825, 184, 72, 42, 1, 112, 3,
121 0, FB_VMODE_NONINTERLACED, 0 },
123 { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
124 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
125 FB_VMODE_NONINTERLACED, 0 },
127 { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
128 0, FB_VMODE_NONINTERLACED, 0 },
130 { NULL, 70, 1152, 864, 10254, 192, 72, 32, 8, 120, 3,
131 0, FB_VMODE_NONINTERLACED, 0 },
133 { NULL, 72, 1152, 864, 9866, 200, 72, 33, 7, 128, 3,
134 0, FB_VMODE_NONINTERLACED, 0 },
136 { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
137 0, FB_VMODE_NONINTERLACED, 0 },
139 { NULL, 85, 1152, 864, 8357, 200, 72, 37, 3, 128, 3,
140 0, FB_VMODE_NONINTERLACED, 0 },
142 { NULL, 90, 1152, 864, 7719, 208, 80, 42, 9, 128, 3,
143 0, FB_VMODE_NONINTERLACED, 0 },
145 { NULL, 100, 1152, 864, 6947, 208, 80, 48, 3, 128, 3,
146 0, FB_VMODE_NONINTERLACED, 0 },
148 { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
149 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
150 FB_VMODE_NONINTERLACED, 0 },
152 { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
153 0, FB_VMODE_NONINTERLACED, 0 },
155 { NULL, 70, 1280, 1024, 7719, 224, 88, 38, 6, 136, 3,
156 0, FB_VMODE_NONINTERLACED, 0 },
158 { NULL, 72, 1280, 1024, 7490, 224, 88, 39, 7, 136, 3,
159 0, FB_VMODE_NONINTERLACED, 0 },
161 { NULL, 75, 1280, 1024, 7409, 248, 16, 38, 1, 144, 3,
162 0, FB_VMODE_NONINTERLACED, 0 },
164 { NULL, 85, 1280, 1024, 6351, 224, 64, 44, 1, 160, 3,
165 0, FB_VMODE_NONINTERLACED, 0 },
167 { NULL, 90, 1280, 1024, 5791, 240, 96, 51, 12, 144, 3,
168 0, FB_VMODE_NONINTERLACED, 0 },
170 { NULL, 100, 1280, 1024, 5212, 240, 96, 57, 6, 144, 3,
171 0, FB_VMODE_NONINTERLACED, 0 },
173 { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
174 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
175 FB_VMODE_NONINTERLACED, 0 },
177 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
178 0, FB_VMODE_NONINTERLACED, 0 },
180 { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
181 0, FB_VMODE_NONINTERLACED, 0 },
183 { NULL, 72, 1600, 1200, 5053, 288, 112, 47, 13, 176, 3,
184 0, FB_VMODE_NONINTERLACED, 0 },
186 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
187 0, FB_VMODE_NONINTERLACED, 0 },
189 { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
190 0, FB_VMODE_NONINTERLACED, 0 },
192 { NULL, 90, 1600, 1200, 3981, 304, 128, 60, 1, 176, 3,
193 0, FB_VMODE_NONINTERLACED, 0 },
195 { NULL, 100, 1600, 1200, 3563, 304, 128, 67, 1, 176, 3,
196 0, FB_VMODE_NONINTERLACED, 0 },
198 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
199 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
200 FB_VMODE_NONINTERLACED, 0 },
202 { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 208, 3,
203 0, FB_VMODE_NONINTERLACED, 0 },
205 { NULL, 70, 1920, 1440, 3593, 360, 152, 55, 8, 208, 3,
206 0, FB_VMODE_NONINTERLACED, 0 },
208 { NULL, 72, 1920, 1440, 3472, 360, 152, 68, 4, 208, 3,
209 0, FB_VMODE_NONINTERLACED, 0 },
211 { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
212 0, FB_VMODE_NONINTERLACED, 0 },
214 { NULL, 85, 1920, 1440, 2929, 368, 152, 68, 1, 216, 3,
215 0, FB_VMODE_NONINTERLACED, 0 },
218 static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
220 if (var->xres > 1920 || var->yres > 1440)
223 if (var->bits_per_pixel == 32) {
224 var->red.offset = 16; var->red.length = 8;
225 var->green.offset = 8; var->green.length = 8;
226 var->blue.offset = 0; var->blue.length = 8;
227 } else if (var->bits_per_pixel == 16) {
228 var->red.offset = 11; var->red.length = 5;
229 var->green.offset = 5; var->green.length = 6;
230 var->blue.offset = 0; var->blue.length = 5;
231 } else if (var->bits_per_pixel == 8) {
232 var->red.offset = 0; var->red.length = 8;
233 var->green.offset = 0; var->green.length = 8;
234 var->blue.offset = 0; var->blue.length = 8;
238 var->transp.offset = 0; var->transp.length = 0;
240 /* Enough video memory? */
241 if ((lx_get_pitch(var->xres, var->bits_per_pixel) * var->yres)
242 > info->fix.smem_len)
248 static int lxfb_set_par(struct fb_info *info)
250 if (info->var.bits_per_pixel > 8) {
251 info->fix.visual = FB_VISUAL_TRUECOLOR;
252 fb_dealloc_cmap(&info->cmap);
254 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
255 fb_alloc_cmap(&info->cmap, 1<<info->var.bits_per_pixel, 0);
258 info->fix.line_length = lx_get_pitch(info->var.xres,
259 info->var.bits_per_pixel);
265 static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
268 chan >>= 16 - bf->length;
269 return chan << bf->offset;
272 static int lxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
273 unsigned blue, unsigned transp,
274 struct fb_info *info)
276 if (info->var.grayscale) {
277 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
278 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
281 /* Truecolor has hardware independent palette */
282 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
283 u32 *pal = info->pseudo_palette;
289 v = chan_to_field(red, &info->var.red);
290 v |= chan_to_field(green, &info->var.green);
291 v |= chan_to_field(blue, &info->var.blue);
298 lx_set_palette_reg(info, regno, red, green, blue);
304 static int lxfb_blank(int blank_mode, struct fb_info *info)
306 return lx_blank_display(info, blank_mode);
310 static int __init lxfb_map_video_memory(struct fb_info *info,
313 struct lxfb_par *par = info->par;
316 ret = pci_enable_device(dev);
321 ret = pci_request_region(dev, 0, "lxfb-framebuffer");
326 ret = pci_request_region(dev, 1, "lxfb-gp");
331 ret = pci_request_region(dev, 2, "lxfb-vg");
336 ret = pci_request_region(dev, 3, "lxfb-vip");
341 info->fix.smem_start = pci_resource_start(dev, 0);
342 info->fix.smem_len = fbsize ? fbsize : lx_framebuffer_size();
344 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
348 if (info->screen_base == NULL)
351 par->gp_regs = ioremap(pci_resource_start(dev, 1),
352 pci_resource_len(dev, 1));
354 if (par->gp_regs == NULL)
357 par->dc_regs = ioremap(pci_resource_start(dev, 2),
358 pci_resource_len(dev, 2));
360 if (par->dc_regs == NULL)
363 par->df_regs = ioremap(pci_resource_start(dev, 3),
364 pci_resource_len(dev, 3));
366 if (par->df_regs == NULL)
369 writel(DC_UNLOCK_CODE, par->dc_regs + DC_UNLOCK);
371 writel(info->fix.smem_start & 0xFF000000,
372 par->dc_regs + DC_PHY_MEM_OFFSET);
374 writel(0, par->dc_regs + DC_UNLOCK);
376 dev_info(&dev->dev, "%d KB of video memory at 0x%lx\n",
377 info->fix.smem_len / 1024, info->fix.smem_start);
382 static struct fb_ops lxfb_ops = {
383 .owner = THIS_MODULE,
384 .fb_check_var = lxfb_check_var,
385 .fb_set_par = lxfb_set_par,
386 .fb_setcolreg = lxfb_setcolreg,
387 .fb_blank = lxfb_blank,
388 /* No HW acceleration for now. */
389 .fb_fillrect = cfb_fillrect,
390 .fb_copyarea = cfb_copyarea,
391 .fb_imageblit = cfb_imageblit,
394 static struct fb_info * __init lxfb_init_fbinfo(struct device *dev)
396 struct lxfb_par *par;
397 struct fb_info *info;
399 /* Alloc enough space for the pseudo palette. */
400 info = framebuffer_alloc(sizeof(struct lxfb_par) + sizeof(u32) * 16,
407 strcpy(info->fix.id, "Geode LX");
409 info->fix.type = FB_TYPE_PACKED_PIXELS;
410 info->fix.type_aux = 0;
411 info->fix.xpanstep = 0;
412 info->fix.ypanstep = 0;
413 info->fix.ywrapstep = 0;
414 info->fix.accel = FB_ACCEL_NONE;
416 info->var.nonstd = 0;
417 info->var.activate = FB_ACTIVATE_NOW;
418 info->var.height = -1;
419 info->var.width = -1;
420 info->var.accel_flags = 0;
421 info->var.vmode = FB_VMODE_NONINTERLACED;
423 info->fbops = &lxfb_ops;
424 info->flags = FBINFO_DEFAULT;
427 info->pseudo_palette = (void *)par + sizeof(struct lxfb_par);
429 info->var.grayscale = 0;
434 static int __init lxfb_probe(struct pci_dev *pdev,
435 const struct pci_device_id *id)
437 struct lxfb_par *par;
438 struct fb_info *info;
441 struct fb_videomode *modedb_ptr;
444 info = lxfb_init_fbinfo(&pdev->dev);
451 ret = lxfb_map_video_memory(info, pdev);
455 "failed to map frame buffer or controller registers\n");
459 /* Set up the desired outputs */
462 par->output |= (nopanel) ? 0 : OUTPUT_PANEL;
463 par->output |= (nocrt) ? 0 : OUTPUT_CRT;
465 /* Set up the mode database */
467 modedb_ptr = (struct fb_videomode *) geode_modedb;
468 modedb_size = ARRAY_SIZE(geode_modedb);
470 ret = fb_find_mode(&info->var, info, mode_option,
471 modedb_ptr, modedb_size, NULL, 16);
473 if (ret == 0 || ret == 4) {
474 dev_err(&pdev->dev, "could not find valid video mode\n");
479 /* Clear the screen of garbage, unless noclear was specified,
480 * in which case we assume the user knows what he is doing */
483 memset_io(info->screen_base, 0, info->fix.smem_len);
487 lxfb_check_var(&info->var, info);
490 if (register_framebuffer(info) < 0) {
494 pci_set_drvdata(pdev, info);
495 printk(KERN_INFO "fb%d: %s frame buffer device\n",
496 info->node, info->fix.id);
501 if (info->screen_base) {
502 iounmap(info->screen_base);
503 pci_release_region(pdev, 0);
506 iounmap(par->gp_regs);
507 pci_release_region(pdev, 1);
510 iounmap(par->dc_regs);
511 pci_release_region(pdev, 2);
514 iounmap(par->df_regs);
515 pci_release_region(pdev, 3);
519 framebuffer_release(info);
524 static void lxfb_remove(struct pci_dev *pdev)
526 struct fb_info *info = pci_get_drvdata(pdev);
527 struct lxfb_par *par = info->par;
529 unregister_framebuffer(info);
531 iounmap(info->screen_base);
532 pci_release_region(pdev, 0);
534 iounmap(par->gp_regs);
535 pci_release_region(pdev, 1);
537 iounmap(par->dc_regs);
538 pci_release_region(pdev, 2);
540 iounmap(par->df_regs);
541 pci_release_region(pdev, 3);
543 pci_set_drvdata(pdev, NULL);
544 framebuffer_release(info);
547 static struct pci_device_id lxfb_id_table[] = {
548 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LX_VIDEO) },
552 MODULE_DEVICE_TABLE(pci, lxfb_id_table);
554 static struct pci_driver lxfb_driver = {
556 .id_table = lxfb_id_table,
558 .remove = lxfb_remove,
562 static int __init lxfb_setup(char *options)
566 if (!options || !*options)
570 char *opt = strsep(&options, ",");
578 if (!strncmp(opt, "fbsize:", 7))
579 fbsize = simple_strtoul(opt+7, NULL, 0);
580 else if (!strcmp(opt, "noclear"))
582 else if (!strcmp(opt, "nopanel"))
584 else if (!strcmp(opt, "nocrt"))
594 static int __init lxfb_init(void)
599 if (fb_get_options("lxfb", &option))
604 return pci_register_driver(&lxfb_driver);
606 static void __exit lxfb_cleanup(void)
608 pci_unregister_driver(&lxfb_driver);
611 module_init(lxfb_init);
612 module_exit(lxfb_cleanup);
614 module_param(mode_option, charp, 0);
615 MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
617 module_param(fbsize, int, 0);
618 MODULE_PARM_DESC(fbsize, "video memory size");
620 MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode LX");
621 MODULE_LICENSE("GPL");