Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/video/geode/gx1fb_core.c |
| 3 | * -- Geode GX1 framebuffer driver |
| 4 | * |
| 5 | * Copyright (C) 2005 Arcom Control Systems Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your 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/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/slab.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/fb.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/pci.h> |
| 23 | |
| 24 | #include "geodefb.h" |
| 25 | #include "display_gx1.h" |
| 26 | #include "video_cs5530.h" |
| 27 | |
| 28 | static char mode_option[32] = "640x480-16@60"; |
| 29 | static int crt_option = 1; |
| 30 | static char panel_option[32] = ""; |
| 31 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 32 | /* Modes relevant to the GX1 (taken from modedb.c) */ |
| 33 | static const struct fb_videomode __initdata gx1_modedb[] = { |
| 34 | /* 640x480-60 VESA */ |
| 35 | { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2, |
| 36 | 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 37 | /* 640x480-75 VESA */ |
| 38 | { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3, |
| 39 | 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 40 | /* 640x480-85 VESA */ |
| 41 | { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3, |
| 42 | 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 43 | /* 800x600-60 VESA */ |
| 44 | { NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4, |
| 45 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 46 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 47 | /* 800x600-75 VESA */ |
| 48 | { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3, |
| 49 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 50 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 51 | /* 800x600-85 VESA */ |
| 52 | { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3, |
| 53 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 54 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 55 | /* 1024x768-60 VESA */ |
| 56 | { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6, |
| 57 | 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 58 | /* 1024x768-75 VESA */ |
| 59 | { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3, |
| 60 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 61 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 62 | /* 1024x768-85 VESA */ |
| 63 | { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3, |
| 64 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 65 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 66 | /* 1280x960-60 VESA */ |
| 67 | { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3, |
| 68 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 69 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 70 | /* 1280x960-85 VESA */ |
| 71 | { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3, |
| 72 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 73 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 74 | /* 1280x1024-60 VESA */ |
| 75 | { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3, |
| 76 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 77 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 78 | /* 1280x1024-75 VESA */ |
| 79 | { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3, |
| 80 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 81 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 82 | /* 1280x1024-85 VESA */ |
| 83 | { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3, |
| 84 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 85 | FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, |
| 86 | }; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | static int gx1_line_delta(int xres, int bpp) |
| 89 | { |
| 90 | int line_delta = xres * (bpp >> 3); |
| 91 | |
| 92 | if (line_delta > 2048) |
| 93 | line_delta = 4096; |
| 94 | else if (line_delta > 1024) |
| 95 | line_delta = 2048; |
| 96 | else |
| 97 | line_delta = 1024; |
| 98 | return line_delta; |
| 99 | } |
| 100 | |
| 101 | static int gx1fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 102 | { |
| 103 | struct geodefb_par *par = info->par; |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /* Maximum resolution is 1280x1024. */ |
| 106 | if (var->xres > 1280 || var->yres > 1024) |
| 107 | return -EINVAL; |
| 108 | |
| 109 | if (par->panel_x && (var->xres > par->panel_x || var->yres > par->panel_y)) |
| 110 | return -EINVAL; |
| 111 | |
| 112 | /* Only 16 bpp and 8 bpp is supported by the hardware. */ |
| 113 | if (var->bits_per_pixel == 16) { |
| 114 | var->red.offset = 11; var->red.length = 5; |
| 115 | var->green.offset = 5; var->green.length = 6; |
| 116 | var->blue.offset = 0; var->blue.length = 5; |
| 117 | var->transp.offset = 0; var->transp.length = 0; |
| 118 | } else if (var->bits_per_pixel == 8) { |
| 119 | var->red.offset = 0; var->red.length = 8; |
| 120 | var->green.offset = 0; var->green.length = 8; |
| 121 | var->blue.offset = 0; var->blue.length = 8; |
| 122 | var->transp.offset = 0; var->transp.length = 0; |
| 123 | } else |
| 124 | return -EINVAL; |
| 125 | |
| 126 | /* Enough video memory? */ |
| 127 | if (gx1_line_delta(var->xres, var->bits_per_pixel) * var->yres > info->fix.smem_len) |
| 128 | return -EINVAL; |
| 129 | |
| 130 | /* FIXME: Check timing parameters here? */ |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static int gx1fb_set_par(struct fb_info *info) |
| 136 | { |
| 137 | struct geodefb_par *par = info->par; |
| 138 | |
Andres Salomon | 35887b1 | 2009-02-11 13:04:23 -0800 | [diff] [blame] | 139 | if (info->var.bits_per_pixel == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
Andres Salomon | 35887b1 | 2009-02-11 13:04:23 -0800 | [diff] [blame] | 141 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | info->fix.line_length = gx1_line_delta(info->var.xres, info->var.bits_per_pixel); |
| 145 | |
| 146 | par->dc_ops->set_mode(info); |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf) |
| 152 | { |
| 153 | chan &= 0xffff; |
| 154 | chan >>= 16 - bf->length; |
| 155 | return chan << bf->offset; |
| 156 | } |
| 157 | |
| 158 | static int gx1fb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 159 | unsigned blue, unsigned transp, |
| 160 | struct fb_info *info) |
| 161 | { |
| 162 | struct geodefb_par *par = info->par; |
| 163 | |
| 164 | if (info->var.grayscale) { |
| 165 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ |
| 166 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; |
| 167 | } |
| 168 | |
| 169 | /* Truecolor has hardware independent palette */ |
| 170 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 171 | u32 *pal = info->pseudo_palette; |
| 172 | u32 v; |
| 173 | |
| 174 | if (regno >= 16) |
| 175 | return -EINVAL; |
| 176 | |
| 177 | v = chan_to_field(red, &info->var.red); |
| 178 | v |= chan_to_field(green, &info->var.green); |
| 179 | v |= chan_to_field(blue, &info->var.blue); |
| 180 | |
| 181 | pal[regno] = v; |
| 182 | } else { |
| 183 | if (regno >= 256) |
| 184 | return -EINVAL; |
| 185 | |
| 186 | par->dc_ops->set_palette_reg(info, regno, red, green, blue); |
| 187 | } |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static int gx1fb_blank(int blank_mode, struct fb_info *info) |
| 193 | { |
| 194 | struct geodefb_par *par = info->par; |
| 195 | |
| 196 | return par->vid_ops->blank_display(info, blank_mode); |
| 197 | } |
| 198 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 199 | static int __init gx1fb_map_video_memory(struct fb_info *info, struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
| 201 | struct geodefb_par *par = info->par; |
| 202 | unsigned gx_base; |
| 203 | int fb_len; |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 204 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | gx_base = gx1_gx_base(); |
| 207 | if (!gx_base) |
| 208 | return -ENODEV; |
| 209 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 210 | ret = pci_enable_device(dev); |
| 211 | if (ret < 0) |
| 212 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
David Vrabel | a80da73 | 2006-01-14 13:21:23 -0800 | [diff] [blame] | 214 | ret = pci_request_region(dev, 0, "gx1fb (video)"); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 215 | if (ret < 0) |
| 216 | return ret; |
Arjan van de Ven | 3c36aa5 | 2009-01-06 14:42:28 -0800 | [diff] [blame] | 217 | par->vid_regs = pci_ioremap_bar(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | if (!par->vid_regs) |
| 219 | return -ENOMEM; |
| 220 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 221 | if (!request_mem_region(gx_base + 0x8300, 0x100, "gx1fb (display controller)")) |
| 222 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | par->dc_regs = ioremap(gx_base + 0x8300, 0x100); |
| 224 | if (!par->dc_regs) |
| 225 | return -ENOMEM; |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | if ((fb_len = gx1_frame_buffer_size()) < 0) |
| 228 | return -ENOMEM; |
David Vrabel | a80da73 | 2006-01-14 13:21:23 -0800 | [diff] [blame] | 229 | info->fix.smem_start = gx_base + 0x800000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | info->fix.smem_len = fb_len; |
| 231 | info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len); |
| 232 | if (!info->screen_base) |
| 233 | return -ENOMEM; |
| 234 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 235 | dev_info(&dev->dev, "%d Kibyte of video memory at 0x%lx\n", |
| 236 | info->fix.smem_len / 1024, info->fix.smem_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int parse_panel_option(struct fb_info *info) |
| 242 | { |
| 243 | struct geodefb_par *par = info->par; |
| 244 | |
| 245 | if (strcmp(panel_option, "") != 0) { |
| 246 | int x, y; |
| 247 | char *s; |
| 248 | x = simple_strtol(panel_option, &s, 10); |
| 249 | if (!x) |
| 250 | return -EINVAL; |
| 251 | y = simple_strtol(s + 1, NULL, 10); |
| 252 | if (!y) |
| 253 | return -EINVAL; |
| 254 | par->panel_x = x; |
| 255 | par->panel_y = y; |
| 256 | } |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static struct fb_ops gx1fb_ops = { |
| 261 | .owner = THIS_MODULE, |
| 262 | .fb_check_var = gx1fb_check_var, |
| 263 | .fb_set_par = gx1fb_set_par, |
| 264 | .fb_setcolreg = gx1fb_setcolreg, |
| 265 | .fb_blank = gx1fb_blank, |
| 266 | /* No HW acceleration for now. */ |
| 267 | .fb_fillrect = cfb_fillrect, |
| 268 | .fb_copyarea = cfb_copyarea, |
| 269 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 272 | static struct fb_info * __init gx1fb_init_fbinfo(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | struct geodefb_par *par; |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 275 | struct fb_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | /* Alloc enough space for the pseudo palette. */ |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 278 | info = framebuffer_alloc(sizeof(struct geodefb_par) + sizeof(u32) * 16, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (!info) |
| 280 | return NULL; |
| 281 | |
| 282 | par = info->par; |
| 283 | |
| 284 | strcpy(info->fix.id, "GX1"); |
| 285 | |
| 286 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 287 | info->fix.type_aux = 0; |
| 288 | info->fix.xpanstep = 0; |
| 289 | info->fix.ypanstep = 0; |
| 290 | info->fix.ywrapstep = 0; |
| 291 | info->fix.accel = FB_ACCEL_NONE; |
| 292 | |
| 293 | info->var.nonstd = 0; |
| 294 | info->var.activate = FB_ACTIVATE_NOW; |
| 295 | info->var.height = -1; |
| 296 | info->var.width = -1; |
| 297 | info->var.accel_flags = 0; |
| 298 | info->var.vmode = FB_VMODE_NONINTERLACED; |
| 299 | |
| 300 | info->fbops = &gx1fb_ops; |
| 301 | info->flags = FBINFO_DEFAULT; |
| 302 | info->node = -1; |
| 303 | |
| 304 | info->pseudo_palette = (void *)par + sizeof(struct geodefb_par); |
| 305 | |
| 306 | info->var.grayscale = 0; |
| 307 | |
| 308 | /* CRT and panel options */ |
| 309 | par->enable_crt = crt_option; |
| 310 | if (parse_panel_option(info) < 0) |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 311 | printk(KERN_WARNING "gx1fb: invalid 'panel' option -- disabling flat panel\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (!par->panel_x) |
| 313 | par->enable_crt = 1; /* fall back to CRT if no panel is specified */ |
| 314 | |
Andres Salomon | 35887b1 | 2009-02-11 13:04:23 -0800 | [diff] [blame] | 315 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 316 | framebuffer_release(info); |
| 317 | return NULL; |
| 318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | return info; |
| 320 | } |
| 321 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 322 | static int __init gx1fb_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 324 | struct geodefb_par *par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | struct fb_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | int ret; |
| 327 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 328 | info = gx1fb_init_fbinfo(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | if (!info) |
| 330 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | par = info->par; |
| 332 | |
| 333 | /* GX1 display controller and CS5530 video device */ |
| 334 | par->dc_ops = &gx1_dc_ops; |
| 335 | par->vid_ops = &cs5530_vid_ops; |
| 336 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 337 | if ((ret = gx1fb_map_video_memory(info, pdev)) < 0) { |
| 338 | dev_err(&pdev->dev, "failed to map frame buffer or controller registers\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | goto err; |
| 340 | } |
| 341 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 342 | ret = fb_find_mode(&info->var, info, mode_option, |
| 343 | gx1_modedb, ARRAY_SIZE(gx1_modedb), NULL, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | if (ret == 0 || ret == 4) { |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 345 | dev_err(&pdev->dev, "could not find valid video mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | ret = -EINVAL; |
| 347 | goto err; |
| 348 | } |
| 349 | |
| 350 | /* Clear the frame buffer of garbage. */ |
| 351 | memset_io(info->screen_base, 0, info->fix.smem_len); |
| 352 | |
| 353 | gx1fb_check_var(&info->var, info); |
| 354 | gx1fb_set_par(info); |
| 355 | |
| 356 | if (register_framebuffer(info) < 0) { |
| 357 | ret = -EINVAL; |
| 358 | goto err; |
| 359 | } |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 360 | pci_set_drvdata(pdev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id); |
| 362 | return 0; |
| 363 | |
| 364 | err: |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 365 | if (info->screen_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | iounmap(info->screen_base); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 367 | pci_release_region(pdev, 0); |
| 368 | } |
| 369 | if (par->vid_regs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | iounmap(par->vid_regs); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 371 | pci_release_region(pdev, 1); |
| 372 | } |
| 373 | if (par->dc_regs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | iounmap(par->dc_regs); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 375 | release_mem_region(gx1_gx_base() + 0x8300, 0x100); |
| 376 | } |
| 377 | |
Andres Salomon | 35887b1 | 2009-02-11 13:04:23 -0800 | [diff] [blame] | 378 | if (info) { |
| 379 | fb_dealloc_cmap(&info->cmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | framebuffer_release(info); |
Andres Salomon | 35887b1 | 2009-02-11 13:04:23 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return ret; |
| 384 | } |
| 385 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 386 | static void gx1fb_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 388 | struct fb_info *info = pci_get_drvdata(pdev); |
| 389 | struct geodefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | unregister_framebuffer(info); |
| 392 | |
| 393 | iounmap((void __iomem *)info->screen_base); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 394 | pci_release_region(pdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 396 | iounmap(par->vid_regs); |
| 397 | pci_release_region(pdev, 1); |
| 398 | |
| 399 | iounmap(par->dc_regs); |
| 400 | release_mem_region(gx1_gx_base() + 0x8300, 0x100); |
| 401 | |
Andres Salomon | 35887b1 | 2009-02-11 13:04:23 -0800 | [diff] [blame] | 402 | fb_dealloc_cmap(&info->cmap); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 403 | pci_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | framebuffer_release(info); |
| 406 | } |
| 407 | |
Alexey Dobriyan | c7b5447 | 2007-02-12 00:55:02 -0800 | [diff] [blame] | 408 | #ifndef MODULE |
| 409 | static void __init gx1fb_setup(char *options) |
| 410 | { |
| 411 | char *this_opt; |
| 412 | |
| 413 | if (!options || !*options) |
| 414 | return; |
| 415 | |
| 416 | while ((this_opt = strsep(&options, ","))) { |
| 417 | if (!*this_opt) |
| 418 | continue; |
| 419 | |
| 420 | if (!strncmp(this_opt, "mode:", 5)) |
| 421 | strlcpy(mode_option, this_opt + 5, sizeof(mode_option)); |
| 422 | else if (!strncmp(this_opt, "crt:", 4)) |
| 423 | crt_option = !!simple_strtoul(this_opt + 4, NULL, 0); |
| 424 | else if (!strncmp(this_opt, "panel:", 6)) |
| 425 | strlcpy(panel_option, this_opt + 6, sizeof(panel_option)); |
| 426 | else |
| 427 | strlcpy(mode_option, this_opt, sizeof(mode_option)); |
| 428 | } |
| 429 | } |
| 430 | #endif |
| 431 | |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 432 | static struct pci_device_id gx1fb_id_table[] = { |
| 433 | { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_VIDEO, |
| 434 | PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, |
| 435 | 0xff0000, 0 }, |
| 436 | { 0, } |
| 437 | }; |
| 438 | |
| 439 | MODULE_DEVICE_TABLE(pci, gx1fb_id_table); |
| 440 | |
| 441 | static struct pci_driver gx1fb_driver = { |
| 442 | .name = "gx1fb", |
| 443 | .id_table = gx1fb_id_table, |
| 444 | .probe = gx1fb_probe, |
| 445 | .remove = gx1fb_remove, |
| 446 | }; |
| 447 | |
| 448 | static int __init gx1fb_init(void) |
| 449 | { |
| 450 | #ifndef MODULE |
Alexey Dobriyan | c7b5447 | 2007-02-12 00:55:02 -0800 | [diff] [blame] | 451 | char *option = NULL; |
| 452 | |
| 453 | if (fb_get_options("gx1fb", &option)) |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 454 | return -ENODEV; |
Alexey Dobriyan | c7b5447 | 2007-02-12 00:55:02 -0800 | [diff] [blame] | 455 | gx1fb_setup(option); |
David Vrabel | 53eed4e | 2005-09-09 13:04:32 -0700 | [diff] [blame] | 456 | #endif |
| 457 | return pci_register_driver(&gx1fb_driver); |
| 458 | } |
| 459 | |
| 460 | static void __exit gx1fb_cleanup(void) |
| 461 | { |
| 462 | pci_unregister_driver(&gx1fb_driver); |
| 463 | } |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | module_init(gx1fb_init); |
| 466 | module_exit(gx1fb_cleanup); |
| 467 | |
| 468 | module_param_string(mode, mode_option, sizeof(mode_option), 0444); |
| 469 | MODULE_PARM_DESC(mode, "video mode (<x>x<y>[-<bpp>][@<refr>])"); |
| 470 | |
| 471 | module_param_named(crt, crt_option, int, 0444); |
| 472 | MODULE_PARM_DESC(crt, "enable CRT output. 0 = off, 1 = on (default)"); |
| 473 | |
| 474 | module_param_string(panel, panel_option, sizeof(panel_option), 0444); |
| 475 | MODULE_PARM_DESC(panel, "size of attached flat panel (<x>x<y>)"); |
| 476 | |
| 477 | MODULE_DESCRIPTION("framebuffer driver for the AMD Geode GX1"); |
| 478 | MODULE_LICENSE("GPL"); |