1 /* sunxvr2500.c: Sun 3DLABS XVR-2500 et al. fb driver for sparc64 systems
5 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
8 #include <linux/kernel.h>
10 #include <linux/pci.h>
11 #include <linux/init.h>
12 #include <linux/of_device.h>
20 char __iomem
*fb_base
;
21 unsigned long fb_base_phys
;
23 struct device_node
*of_node
;
30 u32 pseudo_palette
[16];
33 static int s3d_get_props(struct s3d_info
*sp
)
35 sp
->width
= of_getintprop_default(sp
->of_node
, "width", 0);
36 sp
->height
= of_getintprop_default(sp
->of_node
, "height", 0);
37 sp
->depth
= of_getintprop_default(sp
->of_node
, "depth", 8);
39 if (!sp
->width
|| !sp
->height
) {
40 printk(KERN_ERR
"s3d: Critical properties missing for %s\n",
48 static int s3d_setcolreg(unsigned regno
,
49 unsigned red
, unsigned green
, unsigned blue
,
50 unsigned transp
, struct fb_info
*info
)
59 value
= (blue
<< 24) | (green
<< 16) | (red
<< 8);
60 ((u32
*)info
->pseudo_palette
)[regno
] = value
;
66 static struct fb_ops s3d_ops
= {
68 .fb_setcolreg
= s3d_setcolreg
,
69 .fb_fillrect
= cfb_fillrect
,
70 .fb_copyarea
= cfb_copyarea
,
71 .fb_imageblit
= cfb_imageblit
,
74 static int s3d_set_fbinfo(struct s3d_info
*sp
)
76 struct fb_info
*info
= sp
->info
;
77 struct fb_var_screeninfo
*var
= &info
->var
;
79 info
->flags
= FBINFO_DEFAULT
;
80 info
->fbops
= &s3d_ops
;
81 info
->screen_base
= sp
->fb_base
;
82 info
->screen_size
= sp
->fb_size
;
84 info
->pseudo_palette
= sp
->pseudo_palette
;
86 /* Fill fix common fields */
87 strlcpy(info
->fix
.id
, "s3d", sizeof(info
->fix
.id
));
88 info
->fix
.smem_start
= sp
->fb_base_phys
;
89 info
->fix
.smem_len
= sp
->fb_size
;
90 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
91 if (sp
->depth
== 32 || sp
->depth
== 24)
92 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
94 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
96 var
->xres
= sp
->width
;
97 var
->yres
= sp
->height
;
98 var
->xres_virtual
= var
->xres
;
99 var
->yres_virtual
= var
->yres
;
100 var
->bits_per_pixel
= sp
->depth
;
104 var
->green
.offset
= 16;
105 var
->green
.length
= 8;
106 var
->blue
.offset
= 24;
107 var
->blue
.length
= 8;
108 var
->transp
.offset
= 0;
109 var
->transp
.length
= 0;
111 if (fb_alloc_cmap(&info
->cmap
, 256, 0)) {
112 printk(KERN_ERR
"s3d: Cannot allocate color map.\n");
119 static int s3d_pci_register(struct pci_dev
*pdev
,
120 const struct pci_device_id
*ent
)
122 struct fb_info
*info
;
126 err
= pci_enable_device(pdev
);
128 printk(KERN_ERR
"s3d: Cannot enable PCI device %s\n",
133 info
= framebuffer_alloc(sizeof(struct s3d_info
), &pdev
->dev
);
135 printk(KERN_ERR
"s3d: Cannot allocate fb_info\n");
143 sp
->of_node
= pci_device_to_OF_node(pdev
);
145 printk(KERN_ERR
"s3d: Cannot find OF node of %s\n",
151 sp
->fb_base_phys
= pci_resource_start (pdev
, 1);
153 err
= pci_request_region(pdev
, 1, "s3d framebuffer");
155 printk("s3d: Cannot request region 1 for %s\n",
160 err
= s3d_get_props(sp
);
162 goto err_release_pci
;
164 /* XXX 'linebytes' is often wrong, it is equal to the width
165 * XXX with depth of 32 on my XVR-2500 which is clearly not
166 * XXX right. So we don't try to use it.
170 info
->fix
.line_length
= sp
->width
;
173 info
->fix
.line_length
= sp
->width
* 2;
176 info
->fix
.line_length
= sp
->width
* 3;
179 info
->fix
.line_length
= sp
->width
* 4;
182 sp
->fb_size
= info
->fix
.line_length
* sp
->height
;
184 sp
->fb_base
= ioremap(sp
->fb_base_phys
, sp
->fb_size
);
187 goto err_release_pci
;
190 err
= s3d_set_fbinfo(sp
);
194 pci_set_drvdata(pdev
, info
);
196 printk("s3d: Found device at %s\n", pci_name(pdev
));
198 err
= register_framebuffer(info
);
200 printk(KERN_ERR
"s3d: Could not register framebuffer %s\n",
208 iounmap(sp
->fb_base
);
211 pci_release_region(pdev
, 1);
214 framebuffer_release(info
);
217 pci_disable_device(pdev
);
223 static struct pci_device_id s3d_pci_table
[] = {
224 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x002c), },
225 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x002d), },
226 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x002e), },
227 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x002f), },
228 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x0030), },
229 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x0031), },
230 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x0032), },
231 { PCI_DEVICE(PCI_VENDOR_ID_3DLABS
, 0x0033), },
235 static struct pci_driver s3d_driver
= {
237 .suppress_bind_attrs
= true,
240 .id_table
= s3d_pci_table
,
241 .probe
= s3d_pci_register
,
244 static int __init
s3d_init(void)
246 if (fb_get_options("s3d", NULL
))
249 return pci_register_driver(&s3d_driver
);
251 device_initcall(s3d_init
);