Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Geode LX framebuffer driver.
0004  *
0005  * Copyright (C) 2007 Advanced Micro Devices, Inc.
0006  * Built from gxfb (which is Copyright (C) 2006 Arcom Control Systems Ltd.)
0007  */
0008 
0009 #include <linux/module.h>
0010 #include <linux/kernel.h>
0011 #include <linux/errno.h>
0012 #include <linux/string.h>
0013 #include <linux/console.h>
0014 #include <linux/mm.h>
0015 #include <linux/suspend.h>
0016 #include <linux/delay.h>
0017 #include <linux/fb.h>
0018 #include <linux/init.h>
0019 #include <linux/pci.h>
0020 #include <linux/uaccess.h>
0021 
0022 #include <asm/olpc.h>
0023 
0024 #include "lxfb.h"
0025 
0026 static char *mode_option;
0027 static int noclear, nopanel, nocrt;
0028 static int vram;
0029 static int vt_switch;
0030 
0031 /* Most of these modes are sorted in ascending order, but
0032  * since the first entry in this table is the "default" mode,
0033  * we try to make it something sane - 640x480-60 is sane
0034  */
0035 
0036 static struct fb_videomode geode_modedb[] = {
0037     /* 640x480-60 */
0038     { NULL, 60, 640, 480, 39682, 48, 8, 25, 2, 88, 2,
0039       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0040       FB_VMODE_NONINTERLACED, 0 },
0041     /* 640x400-70 */
0042     { NULL, 70, 640, 400, 39770, 40, 8, 28, 5, 96, 2,
0043       FB_SYNC_HOR_HIGH_ACT,
0044       FB_VMODE_NONINTERLACED, 0 },
0045     /* 640x480-70 */
0046     { NULL, 70, 640, 480, 35014, 88, 24, 15, 2, 64, 3,
0047       0, FB_VMODE_NONINTERLACED, 0 },
0048     /* 640x480-72 */
0049     { NULL, 72, 640, 480, 32102, 120, 16, 20, 1, 40, 3,
0050       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0051       FB_VMODE_NONINTERLACED, 0 },
0052     /* 640x480-75 */
0053     { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
0054       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0055       FB_VMODE_NONINTERLACED, 0 },
0056     /* 640x480-85 */
0057     { NULL, 85, 640, 480, 27780, 80, 56, 25, 1, 56, 3,
0058       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0059       FB_VMODE_NONINTERLACED, 0 },
0060     /* 640x480-90 */
0061     { NULL, 90, 640, 480, 26392, 96, 32, 22, 1, 64, 3,
0062       0, FB_VMODE_NONINTERLACED, 0 },
0063     /* 640x480-100 */
0064     { NULL, 100, 640, 480, 23167, 104, 40, 25, 1, 64, 3,
0065       0, FB_VMODE_NONINTERLACED, 0 },
0066     /* 640x480-60 */
0067     { NULL, 60, 640, 480, 39682, 48, 16, 25, 10, 88, 2,
0068       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0069       FB_VMODE_NONINTERLACED, 0 },
0070     /* 800x600-56 */
0071     { NULL, 56, 800, 600, 27901, 128, 24, 22, 1, 72, 2,
0072       0, FB_VMODE_NONINTERLACED, 0 },
0073     /* 800x600-60 */
0074     { NULL, 60, 800, 600, 25131, 72, 32, 23, 1, 136, 4,
0075       0, FB_VMODE_NONINTERLACED, 0 },
0076     /* 800x600-70 */
0077     { NULL, 70, 800, 600, 21873, 120, 40, 21, 4, 80, 3,
0078       0, FB_VMODE_NONINTERLACED, 0 },
0079     /* 800x600-72 */
0080     { NULL, 72, 800, 600, 20052, 64, 56, 23, 37, 120, 6,
0081       0, FB_VMODE_NONINTERLACED, 0 },
0082     /* 800x600-75 */
0083     { NULL, 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3,
0084       0, FB_VMODE_NONINTERLACED, 0 },
0085     /* 800x600-85 */
0086     { NULL, 85, 800, 600, 17790, 152, 32, 27, 1, 64, 3,
0087       0, FB_VMODE_NONINTERLACED, 0 },
0088     /* 800x600-90 */
0089     { NULL, 90, 800, 600, 16648, 128, 40, 28, 1, 88, 3,
0090       0, FB_VMODE_NONINTERLACED, 0 },
0091     /* 800x600-100 */
0092     { NULL, 100, 800, 600, 14667, 136, 48, 27, 1, 88, 3,
0093       0, FB_VMODE_NONINTERLACED, 0 },
0094     /* 800x600-60 */
0095     { NULL, 60, 800, 600, 25131, 88, 40, 23, 1, 128, 4,
0096       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0097       FB_VMODE_NONINTERLACED, 0 },
0098     /* 1024x768-60 */
0099     { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
0100       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0101       FB_VMODE_NONINTERLACED, 0 },
0102     /* 1024x768-70 */
0103     { NULL, 70, 1024, 768, 13346, 144, 24, 29, 3, 136, 6,
0104       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0105       FB_VMODE_NONINTERLACED, 0 },
0106     /* 1024x768-72 */
0107     { NULL, 72, 1024, 768, 12702, 168, 56, 29, 4, 112, 3,
0108       0, FB_VMODE_NONINTERLACED, 0 },
0109     /* 1024x768-75 */
0110     { NULL, 75, 1024, 768, 12703, 176, 16, 28, 1, 96, 3,
0111       0, FB_VMODE_NONINTERLACED, 0 },
0112     /* 1024x768-85 */
0113     { NULL, 85, 1024, 768, 10581, 208, 48, 36, 1, 96, 3,
0114       0, FB_VMODE_NONINTERLACED, 0 },
0115     /* 1024x768-90 */
0116     { NULL, 90, 1024, 768, 9981, 176, 64, 37, 1, 112, 3,
0117       0, FB_VMODE_NONINTERLACED, 0 },
0118     /* 1024x768-100 */
0119     { NULL, 100, 1024, 768, 8825, 184, 72, 42, 1, 112, 3,
0120       0, FB_VMODE_NONINTERLACED, 0 },
0121     /* 1024x768-60 */
0122     { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
0123       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0124       FB_VMODE_NONINTERLACED, 0 },
0125     /* 1152x864-60 */
0126     { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
0127       0, FB_VMODE_NONINTERLACED, 0 },
0128     /* 1152x864-70 */
0129     { NULL, 70, 1152, 864, 10254, 192, 72, 32, 8, 120, 3,
0130       0, FB_VMODE_NONINTERLACED, 0 },
0131     /* 1152x864-72 */
0132     { NULL, 72, 1152, 864, 9866, 200, 72, 33, 7, 128, 3,
0133       0, FB_VMODE_NONINTERLACED, 0 },
0134     /* 1152x864-75 */
0135     { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
0136       0, FB_VMODE_NONINTERLACED, 0 },
0137     /* 1152x864-85 */
0138     { NULL, 85, 1152, 864, 8357, 200, 72, 37, 3, 128, 3,
0139       0, FB_VMODE_NONINTERLACED, 0 },
0140     /* 1152x864-90 */
0141     { NULL, 90, 1152, 864, 7719, 208, 80, 42, 9, 128, 3,
0142       0, FB_VMODE_NONINTERLACED, 0 },
0143     /* 1152x864-100 */
0144     { NULL, 100, 1152, 864, 6947, 208, 80, 48, 3, 128, 3,
0145       0, FB_VMODE_NONINTERLACED, 0 },
0146     /* 1152x864-60 */
0147     { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
0148       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0149       FB_VMODE_NONINTERLACED, 0 },
0150     /* 1280x1024-60 */
0151     { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
0152       0, FB_VMODE_NONINTERLACED, 0 },
0153     /* 1280x1024-70 */
0154     { NULL, 70, 1280, 1024, 7719, 224, 88, 38, 6, 136, 3,
0155       0, FB_VMODE_NONINTERLACED, 0 },
0156     /* 1280x1024-72 */
0157     { NULL, 72, 1280, 1024, 7490, 224, 88, 39, 7, 136, 3,
0158       0, FB_VMODE_NONINTERLACED, 0 },
0159     /* 1280x1024-75 */
0160     { NULL, 75, 1280, 1024, 7409, 248, 16, 38, 1, 144, 3,
0161       0, FB_VMODE_NONINTERLACED, 0 },
0162     /* 1280x1024-85 */
0163     { NULL, 85, 1280, 1024, 6351, 224, 64, 44, 1, 160, 3,
0164       0, FB_VMODE_NONINTERLACED, 0 },
0165     /* 1280x1024-90 */
0166     { NULL, 90, 1280, 1024, 5791, 240, 96, 51, 12, 144, 3,
0167       0, FB_VMODE_NONINTERLACED, 0 },
0168     /* 1280x1024-100 */
0169     { NULL, 100, 1280, 1024, 5212, 240, 96, 57, 6, 144, 3,
0170       0, FB_VMODE_NONINTERLACED, 0 },
0171     /* 1280x1024-60 */
0172     { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
0173       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0174       FB_VMODE_NONINTERLACED, 0 },
0175     /* 1600x1200-60 */
0176     { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
0177       0, FB_VMODE_NONINTERLACED, 0 },
0178     /* 1600x1200-70 */
0179     { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
0180       0, FB_VMODE_NONINTERLACED, 0 },
0181     /* 1600x1200-72 */
0182     { NULL, 72, 1600, 1200, 5053, 288, 112, 47, 13, 176, 3,
0183       0, FB_VMODE_NONINTERLACED, 0 },
0184     /* 1600x1200-75 */
0185     { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
0186       0, FB_VMODE_NONINTERLACED, 0 },
0187     /* 1600x1200-85 */
0188     { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
0189       0, FB_VMODE_NONINTERLACED, 0 },
0190     /* 1600x1200-90 */
0191     { NULL, 90, 1600, 1200, 3981, 304, 128, 60, 1, 176, 3,
0192       0, FB_VMODE_NONINTERLACED, 0 },
0193     /* 1600x1200-100 */
0194     { NULL, 100, 1600, 1200, 3563, 304, 128, 67, 1, 176, 3,
0195       0, FB_VMODE_NONINTERLACED, 0 },
0196     /* 1600x1200-60 */
0197     { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
0198       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0199       FB_VMODE_NONINTERLACED, 0 },
0200     /* 1920x1440-60 */
0201     { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 208, 3,
0202       0, FB_VMODE_NONINTERLACED, 0 },
0203     /* 1920x1440-70 */
0204     { NULL, 70, 1920, 1440, 3593, 360, 152, 55, 8, 208, 3,
0205       0, FB_VMODE_NONINTERLACED, 0 },
0206     /* 1920x1440-72 */
0207     { NULL, 72, 1920, 1440, 3472, 360, 152, 68, 4, 208, 3,
0208       0, FB_VMODE_NONINTERLACED, 0 },
0209     /* 1920x1440-75 */
0210     { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
0211       0, FB_VMODE_NONINTERLACED, 0 },
0212     /* 1920x1440-85 */
0213     { NULL, 85, 1920, 1440, 2929, 368, 152, 68, 1, 216, 3,
0214       0, FB_VMODE_NONINTERLACED, 0 },
0215 };
0216 
0217 static struct fb_videomode olpc_dcon_modedb[] = {
0218     /* The only mode the DCON has is 1200x900 */
0219     { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3,
0220       FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0221       FB_VMODE_NONINTERLACED, 0 }
0222 };
0223 
0224 static void get_modedb(struct fb_videomode **modedb, unsigned int *size)
0225 {
0226     if (olpc_has_dcon()) {
0227         *modedb = (struct fb_videomode *) olpc_dcon_modedb;
0228         *size = ARRAY_SIZE(olpc_dcon_modedb);
0229     } else {
0230         *modedb = (struct fb_videomode *) geode_modedb;
0231         *size = ARRAY_SIZE(geode_modedb);
0232     }
0233 }
0234 
0235 static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
0236 {
0237     if (var->xres > 1920 || var->yres > 1440)
0238         return -EINVAL;
0239 
0240     if (var->bits_per_pixel == 32) {
0241         var->red.offset   = 16; var->red.length   = 8;
0242         var->green.offset =  8; var->green.length = 8;
0243         var->blue.offset  =  0; var->blue.length  = 8;
0244     } else if (var->bits_per_pixel == 16) {
0245         var->red.offset   = 11; var->red.length   = 5;
0246         var->green.offset =  5; var->green.length = 6;
0247         var->blue.offset  =  0; var->blue.length  = 5;
0248     } else if (var->bits_per_pixel == 8) {
0249         var->red.offset   = 0; var->red.length   = 8;
0250         var->green.offset = 0; var->green.length = 8;
0251         var->blue.offset  = 0; var->blue.length  = 8;
0252     } else
0253         return -EINVAL;
0254 
0255     var->transp.offset = 0; var->transp.length = 0;
0256 
0257     /* Enough video memory? */
0258     if ((lx_get_pitch(var->xres, var->bits_per_pixel) * var->yres)
0259         > info->fix.smem_len)
0260       return -EINVAL;
0261 
0262     return 0;
0263 }
0264 
0265 static int lxfb_set_par(struct fb_info *info)
0266 {
0267     if (info->var.bits_per_pixel > 8)
0268         info->fix.visual = FB_VISUAL_TRUECOLOR;
0269     else
0270         info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
0271 
0272     info->fix.line_length = lx_get_pitch(info->var.xres,
0273         info->var.bits_per_pixel);
0274 
0275     lx_set_mode(info);
0276     return 0;
0277 }
0278 
0279 static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
0280 {
0281     chan &= 0xffff;
0282     chan >>= 16 - bf->length;
0283     return chan << bf->offset;
0284 }
0285 
0286 static int lxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
0287                unsigned blue, unsigned transp,
0288                struct fb_info *info)
0289 {
0290     if (info->var.grayscale) {
0291         /* grayscale = 0.30*R + 0.59*G + 0.11*B */
0292         red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
0293     }
0294 
0295     /* Truecolor has hardware independent palette */
0296     if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
0297         u32 *pal = info->pseudo_palette;
0298         u32 v;
0299 
0300         if (regno >= 16)
0301             return -EINVAL;
0302 
0303         v  = chan_to_field(red, &info->var.red);
0304         v |= chan_to_field(green, &info->var.green);
0305         v |= chan_to_field(blue, &info->var.blue);
0306 
0307         pal[regno] = v;
0308     } else {
0309         if (regno >= 256)
0310             return -EINVAL;
0311 
0312         lx_set_palette_reg(info, regno, red, green, blue);
0313     }
0314 
0315     return 0;
0316 }
0317 
0318 static int lxfb_blank(int blank_mode, struct fb_info *info)
0319 {
0320     return lx_blank_display(info, blank_mode);
0321 }
0322 
0323 
0324 static int lxfb_map_video_memory(struct fb_info *info, struct pci_dev *dev)
0325 {
0326     struct lxfb_par *par = info->par;
0327     int ret;
0328 
0329     ret = pci_enable_device(dev);
0330 
0331     if (ret)
0332         return ret;
0333 
0334     ret = pci_request_region(dev, 0, "lxfb-framebuffer");
0335 
0336     if (ret)
0337         return ret;
0338 
0339     ret = pci_request_region(dev, 1, "lxfb-gp");
0340 
0341     if (ret)
0342         return ret;
0343 
0344     ret = pci_request_region(dev, 2, "lxfb-vg");
0345 
0346     if (ret)
0347         return ret;
0348 
0349     ret = pci_request_region(dev, 3, "lxfb-vp");
0350 
0351     if (ret)
0352         return ret;
0353 
0354     info->fix.smem_start = pci_resource_start(dev, 0);
0355     info->fix.smem_len = vram ? vram : lx_framebuffer_size();
0356 
0357     info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
0358 
0359     ret = -ENOMEM;
0360 
0361     if (info->screen_base == NULL)
0362         return ret;
0363 
0364     par->gp_regs = pci_ioremap_bar(dev, 1);
0365 
0366     if (par->gp_regs == NULL)
0367         return ret;
0368 
0369     par->dc_regs = pci_ioremap_bar(dev, 2);
0370 
0371     if (par->dc_regs == NULL)
0372         return ret;
0373 
0374     par->vp_regs = pci_ioremap_bar(dev, 3);
0375 
0376     if (par->vp_regs == NULL)
0377         return ret;
0378 
0379     write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
0380     write_dc(par, DC_GLIU0_MEM_OFFSET, info->fix.smem_start & 0xFF000000);
0381     write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
0382 
0383     dev_info(&dev->dev, "%d KB of video memory at 0x%lx\n",
0384          info->fix.smem_len / 1024, info->fix.smem_start);
0385 
0386     return 0;
0387 }
0388 
0389 static const struct fb_ops lxfb_ops = {
0390     .owner      = THIS_MODULE,
0391     .fb_check_var   = lxfb_check_var,
0392     .fb_set_par = lxfb_set_par,
0393     .fb_setcolreg   = lxfb_setcolreg,
0394     .fb_blank       = lxfb_blank,
0395     /* No HW acceleration for now. */
0396     .fb_fillrect    = cfb_fillrect,
0397     .fb_copyarea    = cfb_copyarea,
0398     .fb_imageblit   = cfb_imageblit,
0399 };
0400 
0401 static struct fb_info *lxfb_init_fbinfo(struct device *dev)
0402 {
0403     struct lxfb_par *par;
0404     struct fb_info *info;
0405 
0406     /* Alloc enough space for the pseudo palette. */
0407     info = framebuffer_alloc(sizeof(struct lxfb_par) + sizeof(u32) * 16,
0408                  dev);
0409     if (!info)
0410         return NULL;
0411 
0412     par = info->par;
0413 
0414     strcpy(info->fix.id, "Geode LX");
0415 
0416     info->fix.type      = FB_TYPE_PACKED_PIXELS;
0417     info->fix.type_aux  = 0;
0418     info->fix.xpanstep  = 0;
0419     info->fix.ypanstep  = 0;
0420     info->fix.ywrapstep = 0;
0421     info->fix.accel     = FB_ACCEL_NONE;
0422 
0423     info->var.nonstd    = 0;
0424     info->var.activate  = FB_ACTIVATE_NOW;
0425     info->var.height    = -1;
0426     info->var.width = -1;
0427     info->var.accel_flags = 0;
0428     info->var.vmode = FB_VMODE_NONINTERLACED;
0429 
0430     info->fbops     = &lxfb_ops;
0431     info->flags     = FBINFO_DEFAULT;
0432     info->node      = -1;
0433 
0434     info->pseudo_palette    = (void *)par + sizeof(struct lxfb_par);
0435 
0436     if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
0437         framebuffer_release(info);
0438         return NULL;
0439     }
0440 
0441     info->var.grayscale = 0;
0442 
0443     return info;
0444 }
0445 
0446 static int __maybe_unused lxfb_suspend(struct device *dev)
0447 {
0448     struct fb_info *info = dev_get_drvdata(dev);
0449 
0450     console_lock();
0451     lx_powerdown(info);
0452     fb_set_suspend(info, 1);
0453     console_unlock();
0454 
0455     /* there's no point in setting PCI states; we emulate PCI, so
0456      * we don't end up getting power savings anyways */
0457 
0458     return 0;
0459 }
0460 
0461 static int __maybe_unused lxfb_resume(struct device *dev)
0462 {
0463     struct fb_info *info = dev_get_drvdata(dev);
0464     int ret;
0465 
0466     console_lock();
0467     ret = lx_powerup(info);
0468     if (ret) {
0469         printk(KERN_ERR "lxfb:  power up failed!\n");
0470         return ret;
0471     }
0472 
0473     fb_set_suspend(info, 0);
0474     console_unlock();
0475     return 0;
0476 }
0477 
0478 static int lxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
0479 {
0480     struct lxfb_par *par;
0481     struct fb_info *info;
0482     int ret;
0483 
0484     struct fb_videomode *modedb_ptr;
0485     unsigned int modedb_size;
0486 
0487     info = lxfb_init_fbinfo(&pdev->dev);
0488 
0489     if (info == NULL)
0490         return -ENOMEM;
0491 
0492     par = info->par;
0493 
0494     ret = lxfb_map_video_memory(info, pdev);
0495 
0496     if (ret < 0) {
0497         dev_err(&pdev->dev,
0498             "failed to map frame buffer or controller registers\n");
0499         goto err;
0500     }
0501 
0502     /* Set up the desired outputs */
0503 
0504     par->output = 0;
0505     par->output |= (nopanel) ? 0 : OUTPUT_PANEL;
0506     par->output |= (nocrt) ? 0 : OUTPUT_CRT;
0507 
0508     /* Set up the mode database */
0509 
0510     get_modedb(&modedb_ptr, &modedb_size);
0511     ret = fb_find_mode(&info->var, info, mode_option,
0512                modedb_ptr, modedb_size, NULL, 16);
0513 
0514     if (ret == 0 || ret == 4) {
0515         dev_err(&pdev->dev, "could not find valid video mode\n");
0516         ret = -EINVAL;
0517         goto err;
0518     }
0519 
0520     /* Clear the screen of garbage, unless noclear was specified,
0521      * in which case we assume the user knows what he is doing */
0522 
0523     if (!noclear)
0524         memset_io(info->screen_base, 0, info->fix.smem_len);
0525 
0526     /* Set the mode */
0527 
0528     lxfb_check_var(&info->var, info);
0529     lxfb_set_par(info);
0530 
0531     pm_set_vt_switch(vt_switch);
0532 
0533     if (register_framebuffer(info) < 0) {
0534         ret = -EINVAL;
0535         goto err;
0536     }
0537     pci_set_drvdata(pdev, info);
0538     fb_info(info, "%s frame buffer device\n", info->fix.id);
0539 
0540     return 0;
0541 
0542 err:
0543     if (info->screen_base) {
0544         iounmap(info->screen_base);
0545         pci_release_region(pdev, 0);
0546     }
0547     if (par->gp_regs) {
0548         iounmap(par->gp_regs);
0549         pci_release_region(pdev, 1);
0550     }
0551     if (par->dc_regs) {
0552         iounmap(par->dc_regs);
0553         pci_release_region(pdev, 2);
0554     }
0555     if (par->vp_regs) {
0556         iounmap(par->vp_regs);
0557         pci_release_region(pdev, 3);
0558     }
0559 
0560     fb_dealloc_cmap(&info->cmap);
0561     framebuffer_release(info);
0562 
0563     return ret;
0564 }
0565 
0566 static void lxfb_remove(struct pci_dev *pdev)
0567 {
0568     struct fb_info *info = pci_get_drvdata(pdev);
0569     struct lxfb_par *par = info->par;
0570 
0571     unregister_framebuffer(info);
0572 
0573     iounmap(info->screen_base);
0574     pci_release_region(pdev, 0);
0575 
0576     iounmap(par->gp_regs);
0577     pci_release_region(pdev, 1);
0578 
0579     iounmap(par->dc_regs);
0580     pci_release_region(pdev, 2);
0581 
0582     iounmap(par->vp_regs);
0583     pci_release_region(pdev, 3);
0584 
0585     fb_dealloc_cmap(&info->cmap);
0586     framebuffer_release(info);
0587 }
0588 
0589 static struct pci_device_id lxfb_id_table[] = {
0590     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LX_VIDEO) },
0591     { 0, }
0592 };
0593 
0594 MODULE_DEVICE_TABLE(pci, lxfb_id_table);
0595 
0596 static const struct dev_pm_ops lxfb_pm_ops = {
0597 #ifdef CONFIG_PM_SLEEP
0598     .suspend    = lxfb_suspend,
0599     .resume     = lxfb_resume,
0600     .freeze     = NULL,
0601     .thaw       = lxfb_resume,
0602     .poweroff   = NULL,
0603     .restore    = lxfb_resume,
0604 #endif
0605 };
0606 
0607 static struct pci_driver lxfb_driver = {
0608     .name       = "lxfb",
0609     .id_table   = lxfb_id_table,
0610     .probe      = lxfb_probe,
0611     .remove     = lxfb_remove,
0612     .driver.pm  = &lxfb_pm_ops,
0613 };
0614 
0615 #ifndef MODULE
0616 static int __init lxfb_setup(char *options)
0617 {
0618     char *opt;
0619 
0620     if (!options || !*options)
0621         return 0;
0622 
0623     while ((opt = strsep(&options, ",")) != NULL) {
0624         if (!*opt)
0625             continue;
0626 
0627         if (!strcmp(opt, "noclear"))
0628             noclear = 1;
0629         else if (!strcmp(opt, "nopanel"))
0630             nopanel = 1;
0631         else if (!strcmp(opt, "nocrt"))
0632             nocrt = 1;
0633         else
0634             mode_option = opt;
0635     }
0636 
0637     return 0;
0638 }
0639 #endif
0640 
0641 static int __init lxfb_init(void)
0642 {
0643 #ifndef MODULE
0644     char *option = NULL;
0645 
0646     if (fb_get_options("lxfb", &option))
0647         return -ENODEV;
0648 
0649     lxfb_setup(option);
0650 #endif
0651     return pci_register_driver(&lxfb_driver);
0652 }
0653 static void __exit lxfb_cleanup(void)
0654 {
0655     pci_unregister_driver(&lxfb_driver);
0656 }
0657 
0658 module_init(lxfb_init);
0659 module_exit(lxfb_cleanup);
0660 
0661 module_param(mode_option, charp, 0);
0662 MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
0663 
0664 module_param(vram, int, 0);
0665 MODULE_PARM_DESC(vram, "video memory size");
0666 
0667 module_param(vt_switch, int, 0);
0668 MODULE_PARM_DESC(vt_switch, "enable VT switch during suspend/resume");
0669 
0670 MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode LX");
0671 MODULE_LICENSE("GPL");