iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / video / sunxvr2500.c
blobc3869a96ab5877162ea6e72960f7d0fdf73e9cd1
1 /* s3d.c: Sun 3DLABS XVR-2500 et al. driver for sparc64 systems
3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
4 */
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/slab.h>
9 #include <linux/fb.h>
10 #include <linux/pci.h>
11 #include <linux/init.h>
13 #include <asm/io.h>
14 #include <asm/prom.h>
15 #include <asm/of_device.h>
17 struct s3d_info {
18 struct fb_info *info;
19 struct pci_dev *pdev;
21 char __iomem *fb_base;
22 unsigned long fb_base_phys;
24 struct device_node *of_node;
26 unsigned int width;
27 unsigned int height;
28 unsigned int depth;
29 unsigned int fb_size;
31 u32 pseudo_palette[16];
34 static int __devinit s3d_get_props(struct s3d_info *sp)
36 sp->width = of_getintprop_default(sp->of_node, "width", 0);
37 sp->height = of_getintprop_default(sp->of_node, "height", 0);
38 sp->depth = of_getintprop_default(sp->of_node, "depth", 8);
40 if (!sp->width || !sp->height) {
41 printk(KERN_ERR "s3d: Critical properties missing for %s\n",
42 pci_name(sp->pdev));
43 return -EINVAL;
46 return 0;
49 static int s3d_setcolreg(unsigned regno,
50 unsigned red, unsigned green, unsigned blue,
51 unsigned transp, struct fb_info *info)
53 u32 value;
55 if (regno < 16) {
56 red >>= 8;
57 green >>= 8;
58 blue >>= 8;
60 value = (blue << 24) | (green << 16) | (red << 8);
61 ((u32 *)info->pseudo_palette)[regno] = value;
64 return 0;
67 static struct fb_ops s3d_ops = {
68 .owner = THIS_MODULE,
69 .fb_setcolreg = s3d_setcolreg,
70 .fb_fillrect = cfb_fillrect,
71 .fb_copyarea = cfb_copyarea,
72 .fb_imageblit = cfb_imageblit,
75 static int __devinit s3d_set_fbinfo(struct s3d_info *sp)
77 struct fb_info *info = sp->info;
78 struct fb_var_screeninfo *var = &info->var;
80 info->flags = FBINFO_DEFAULT;
81 info->fbops = &s3d_ops;
82 info->screen_base = sp->fb_base;
83 info->screen_size = sp->fb_size;
85 info->pseudo_palette = sp->pseudo_palette;
87 /* Fill fix common fields */
88 strlcpy(info->fix.id, "s3d", sizeof(info->fix.id));
89 info->fix.smem_start = sp->fb_base_phys;
90 info->fix.smem_len = sp->fb_size;
91 info->fix.type = FB_TYPE_PACKED_PIXELS;
92 if (sp->depth == 32 || sp->depth == 24)
93 info->fix.visual = FB_VISUAL_TRUECOLOR;
94 else
95 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
97 var->xres = sp->width;
98 var->yres = sp->height;
99 var->xres_virtual = var->xres;
100 var->yres_virtual = var->yres;
101 var->bits_per_pixel = sp->depth;
103 var->red.offset = 8;
104 var->red.length = 8;
105 var->green.offset = 16;
106 var->green.length = 8;
107 var->blue.offset = 24;
108 var->blue.length = 8;
109 var->transp.offset = 0;
110 var->transp.length = 0;
112 if (fb_alloc_cmap(&info->cmap, 256, 0)) {
113 printk(KERN_ERR "s3d: Cannot allocate color map.\n");
114 return -ENOMEM;
117 return 0;
120 static int __devinit s3d_pci_register(struct pci_dev *pdev,
121 const struct pci_device_id *ent)
123 struct fb_info *info;
124 struct s3d_info *sp;
125 int err;
127 err = pci_enable_device(pdev);
128 if (err < 0) {
129 printk(KERN_ERR "s3d: Cannot enable PCI device %s\n",
130 pci_name(pdev));
131 goto err_out;
134 info = framebuffer_alloc(sizeof(struct s3d_info), &pdev->dev);
135 if (!info) {
136 printk(KERN_ERR "s3d: Cannot allocate fb_info\n");
137 err = -ENOMEM;
138 goto err_disable;
141 sp = info->par;
142 sp->info = info;
143 sp->pdev = pdev;
144 sp->of_node = pci_device_to_OF_node(pdev);
145 if (!sp->of_node) {
146 printk(KERN_ERR "s3d: Cannot find OF node of %s\n",
147 pci_name(pdev));
148 err = -ENODEV;
149 goto err_release_fb;
152 sp->fb_base_phys = pci_resource_start (pdev, 1);
154 err = pci_request_region(pdev, 1, "s3d framebuffer");
155 if (err < 0) {
156 printk("s3d: Cannot request region 1 for %s\n",
157 pci_name(pdev));
158 goto err_release_fb;
161 err = s3d_get_props(sp);
162 if (err)
163 goto err_release_pci;
165 /* XXX 'linebytes' is often wrong, it is equal to the width
166 * XXX with depth of 32 on my XVR-2500 which is clearly not
167 * XXX right. So we don't try to use it.
169 switch (sp->depth) {
170 case 8:
171 info->fix.line_length = sp->width;
172 break;
173 case 16:
174 info->fix.line_length = sp->width * 2;
175 break;
176 case 24:
177 info->fix.line_length = sp->width * 3;
178 break;
179 case 32:
180 info->fix.line_length = sp->width * 4;
181 break;
183 sp->fb_size = info->fix.line_length * sp->height;
185 sp->fb_base = ioremap(sp->fb_base_phys, sp->fb_size);
186 if (!sp->fb_base)
187 goto err_release_pci;
189 err = s3d_set_fbinfo(sp);
190 if (err)
191 goto err_unmap_fb;
193 pci_set_drvdata(pdev, info);
195 printk("s3d: Found device at %s\n", pci_name(pdev));
197 err = register_framebuffer(info);
198 if (err < 0) {
199 printk(KERN_ERR "s3d: Could not register framebuffer %s\n",
200 pci_name(pdev));
201 goto err_unmap_fb;
204 return 0;
206 err_unmap_fb:
207 iounmap(sp->fb_base);
209 err_release_pci:
210 pci_release_region(pdev, 1);
212 err_release_fb:
213 framebuffer_release(info);
215 err_disable:
216 pci_disable_device(pdev);
218 err_out:
219 return err;
222 static void __devexit s3d_pci_unregister(struct pci_dev *pdev)
224 struct fb_info *info = pci_get_drvdata(pdev);
225 struct s3d_info *sp = info->par;
227 unregister_framebuffer(info);
229 iounmap(sp->fb_base);
231 pci_release_region(pdev, 1);
233 framebuffer_release(info);
235 pci_disable_device(pdev);
238 static struct pci_device_id s3d_pci_table[] = {
239 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x002c), },
240 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x002d), },
241 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x002e), },
242 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x002f), },
243 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x0030), },
244 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x0031), },
245 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x0032), },
246 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS, 0x0033), },
247 { 0, }
250 static struct pci_driver s3d_driver = {
251 .name = "s3d",
252 .id_table = s3d_pci_table,
253 .probe = s3d_pci_register,
254 .remove = __devexit_p(s3d_pci_unregister),
257 static int __init s3d_init(void)
259 if (fb_get_options("s3d", NULL))
260 return -ENODEV;
262 return pci_register_driver(&s3d_driver);
265 static void __exit s3d_exit(void)
267 pci_unregister_driver(&s3d_driver);
270 module_init(s3d_init);
271 module_exit(s3d_exit);
273 MODULE_DESCRIPTION("framebuffer driver for Sun XVR-2500 graphics");
274 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
275 MODULE_VERSION("1.0");
276 MODULE_LICENSE("GPL");