blob: cc6f48bba36be34f167710f0be7ed7e50da601fa [file] [log] [blame]
David S. Miller2d378b92010-03-13 16:25:03 -08001/* sunxvr1000.c: Sun XVR-1000 driver for sparc64 systems
2 *
3 * Copyright (C) 2010 David S. Miller (davem@davemloft.net)
4 */
5
6#include <linux/module.h>
7#include <linux/kernel.h>
David S. Miller2d378b92010-03-13 16:25:03 -08008#include <linux/fb.h>
9#include <linux/init.h>
10#include <linux/of_device.h>
11
12struct gfb_info {
13 struct fb_info *info;
14
15 char __iomem *fb_base;
16 unsigned long fb_base_phys;
17
18 struct device_node *of_node;
19
20 unsigned int width;
21 unsigned int height;
22 unsigned int depth;
23 unsigned int fb_size;
24
25 u32 pseudo_palette[16];
26};
27
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080028static int gfb_get_props(struct gfb_info *gp)
David S. Miller2d378b92010-03-13 16:25:03 -080029{
30 gp->width = of_getintprop_default(gp->of_node, "width", 0);
31 gp->height = of_getintprop_default(gp->of_node, "height", 0);
32 gp->depth = of_getintprop_default(gp->of_node, "depth", 32);
33
34 if (!gp->width || !gp->height) {
35 printk(KERN_ERR "gfb: Critical properties missing for %s\n",
36 gp->of_node->full_name);
37 return -EINVAL;
38 }
39
40 return 0;
41}
42
43static int gfb_setcolreg(unsigned regno,
44 unsigned red, unsigned green, unsigned blue,
45 unsigned transp, struct fb_info *info)
46{
47 u32 value;
48
49 if (regno < 16) {
50 red >>= 8;
51 green >>= 8;
52 blue >>= 8;
53
54 value = (blue << 16) | (green << 8) | red;
55 ((u32 *)info->pseudo_palette)[regno] = value;
56 }
57
58 return 0;
59}
60
61static struct fb_ops gfb_ops = {
62 .owner = THIS_MODULE,
63 .fb_setcolreg = gfb_setcolreg,
64 .fb_fillrect = cfb_fillrect,
65 .fb_copyarea = cfb_copyarea,
66 .fb_imageblit = cfb_imageblit,
67};
68
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080069static int gfb_set_fbinfo(struct gfb_info *gp)
David S. Miller2d378b92010-03-13 16:25:03 -080070{
71 struct fb_info *info = gp->info;
72 struct fb_var_screeninfo *var = &info->var;
73
74 info->flags = FBINFO_DEFAULT;
75 info->fbops = &gfb_ops;
76 info->screen_base = gp->fb_base;
77 info->screen_size = gp->fb_size;
78
79 info->pseudo_palette = gp->pseudo_palette;
80
81 /* Fill fix common fields */
82 strlcpy(info->fix.id, "gfb", sizeof(info->fix.id));
83 info->fix.smem_start = gp->fb_base_phys;
84 info->fix.smem_len = gp->fb_size;
85 info->fix.type = FB_TYPE_PACKED_PIXELS;
86 if (gp->depth == 32 || gp->depth == 24)
87 info->fix.visual = FB_VISUAL_TRUECOLOR;
88 else
89 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
90
91 var->xres = gp->width;
92 var->yres = gp->height;
93 var->xres_virtual = var->xres;
94 var->yres_virtual = var->yres;
95 var->bits_per_pixel = gp->depth;
96
97 var->red.offset = 0;
98 var->red.length = 8;
99 var->green.offset = 8;
100 var->green.length = 8;
101 var->blue.offset = 16;
102 var->blue.length = 8;
103 var->transp.offset = 0;
104 var->transp.length = 0;
105
106 if (fb_alloc_cmap(&info->cmap, 256, 0)) {
107 printk(KERN_ERR "gfb: Cannot allocate color map.\n");
108 return -ENOMEM;
109 }
110
111 return 0;
112}
113
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800114static int gfb_probe(struct platform_device *op)
David S. Miller2d378b92010-03-13 16:25:03 -0800115{
Grant Likely61c7a082010-04-13 16:12:29 -0700116 struct device_node *dp = op->dev.of_node;
David S. Miller2d378b92010-03-13 16:25:03 -0800117 struct fb_info *info;
118 struct gfb_info *gp;
119 int err;
120
121 info = framebuffer_alloc(sizeof(struct gfb_info), &op->dev);
122 if (!info) {
123 printk(KERN_ERR "gfb: Cannot allocate fb_info\n");
124 err = -ENOMEM;
125 goto err_out;
126 }
127
128 gp = info->par;
129 gp->info = info;
130 gp->of_node = dp;
131
132 gp->fb_base_phys = op->resource[6].start;
133
134 err = gfb_get_props(gp);
135 if (err)
136 goto err_release_fb;
137
138 /* Framebuffer length is the same regardless of resolution. */
139 info->fix.line_length = 16384;
140 gp->fb_size = info->fix.line_length * gp->height;
141
142 gp->fb_base = of_ioremap(&op->resource[6], 0,
143 gp->fb_size, "gfb fb");
Peter Senna Tschudin6a1e5f82012-09-18 14:07:52 +0200144 if (!gp->fb_base) {
145 err = -ENOMEM;
David S. Miller2d378b92010-03-13 16:25:03 -0800146 goto err_release_fb;
Peter Senna Tschudin6a1e5f82012-09-18 14:07:52 +0200147 }
David S. Miller2d378b92010-03-13 16:25:03 -0800148
149 err = gfb_set_fbinfo(gp);
150 if (err)
151 goto err_unmap_fb;
152
153 printk("gfb: Found device at %s\n", dp->full_name);
154
155 err = register_framebuffer(info);
156 if (err < 0) {
157 printk(KERN_ERR "gfb: Could not register framebuffer %s\n",
158 dp->full_name);
159 goto err_unmap_fb;
160 }
161
162 dev_set_drvdata(&op->dev, info);
163
164 return 0;
165
166err_unmap_fb:
167 of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
168
169err_release_fb:
170 framebuffer_release(info);
171
172err_out:
173 return err;
174}
175
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800176static int gfb_remove(struct platform_device *op)
David S. Miller2d378b92010-03-13 16:25:03 -0800177{
178 struct fb_info *info = dev_get_drvdata(&op->dev);
179 struct gfb_info *gp = info->par;
180
181 unregister_framebuffer(info);
182
183 iounmap(gp->fb_base);
184
185 of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
186
187 framebuffer_release(info);
188
189 dev_set_drvdata(&op->dev, NULL);
190
191 return 0;
192}
193
194static const struct of_device_id gfb_match[] = {
195 {
196 .name = "SUNW,gfb",
197 },
198 {},
199};
200MODULE_DEVICE_TABLE(of, ffb_match);
201
Grant Likely28541d02011-02-22 21:07:43 -0700202static struct platform_driver gfb_driver = {
David S. Miller2d378b92010-03-13 16:25:03 -0800203 .probe = gfb_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800204 .remove = gfb_remove,
Grant Likely40182942010-04-13 16:13:02 -0700205 .driver = {
206 .name = "gfb",
207 .owner = THIS_MODULE,
208 .of_match_table = gfb_match,
209 },
David S. Miller2d378b92010-03-13 16:25:03 -0800210};
211
212static int __init gfb_init(void)
213{
214 if (fb_get_options("gfb", NULL))
215 return -ENODEV;
216
Grant Likely28541d02011-02-22 21:07:43 -0700217 return platform_driver_register(&gfb_driver);
David S. Miller2d378b92010-03-13 16:25:03 -0800218}
219
220static void __exit gfb_exit(void)
221{
Grant Likely28541d02011-02-22 21:07:43 -0700222 platform_driver_unregister(&gfb_driver);
David S. Miller2d378b92010-03-13 16:25:03 -0800223}
224
225module_init(gfb_init);
226module_exit(gfb_exit);
227
228MODULE_DESCRIPTION("framebuffer driver for Sun XVR-1000 graphics");
229MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
230MODULE_VERSION("1.0");
231MODULE_LICENSE("GPL");