blob: fb37f6e053915a62c82564d6b929df8a9d044426 [file] [log] [blame]
Paul Gortmaker27844cb2016-02-21 22:13:11 -05001/* sunxvr1000.c: Sun XVR-1000 fb driver for sparc64 systems
2 *
3 * License: GPL
David S. Miller2d378b92010-03-13 16:25:03 -08004 *
5 * Copyright (C) 2010 David S. Miller (davem@davemloft.net)
6 */
7
David S. Miller2d378b92010-03-13 16:25:03 -08008#include <linux/kernel.h>
David S. Miller2d378b92010-03-13 16:25:03 -08009#include <linux/fb.h>
10#include <linux/init.h>
11#include <linux/of_device.h>
12
13struct gfb_info {
14 struct fb_info *info;
15
16 char __iomem *fb_base;
17 unsigned long fb_base_phys;
18
19 struct device_node *of_node;
20
21 unsigned int width;
22 unsigned int height;
23 unsigned int depth;
24 unsigned int fb_size;
25
26 u32 pseudo_palette[16];
27};
28
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080029static int gfb_get_props(struct gfb_info *gp)
David S. Miller2d378b92010-03-13 16:25:03 -080030{
31 gp->width = of_getintprop_default(gp->of_node, "width", 0);
32 gp->height = of_getintprop_default(gp->of_node, "height", 0);
33 gp->depth = of_getintprop_default(gp->of_node, "depth", 32);
34
35 if (!gp->width || !gp->height) {
36 printk(KERN_ERR "gfb: Critical properties missing for %s\n",
37 gp->of_node->full_name);
38 return -EINVAL;
39 }
40
41 return 0;
42}
43
44static int gfb_setcolreg(unsigned regno,
45 unsigned red, unsigned green, unsigned blue,
46 unsigned transp, struct fb_info *info)
47{
48 u32 value;
49
50 if (regno < 16) {
51 red >>= 8;
52 green >>= 8;
53 blue >>= 8;
54
55 value = (blue << 16) | (green << 8) | red;
56 ((u32 *)info->pseudo_palette)[regno] = value;
57 }
58
59 return 0;
60}
61
62static struct fb_ops gfb_ops = {
63 .owner = THIS_MODULE,
64 .fb_setcolreg = gfb_setcolreg,
65 .fb_fillrect = cfb_fillrect,
66 .fb_copyarea = cfb_copyarea,
67 .fb_imageblit = cfb_imageblit,
68};
69
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -080070static int gfb_set_fbinfo(struct gfb_info *gp)
David S. Miller2d378b92010-03-13 16:25:03 -080071{
72 struct fb_info *info = gp->info;
73 struct fb_var_screeninfo *var = &info->var;
74
75 info->flags = FBINFO_DEFAULT;
76 info->fbops = &gfb_ops;
77 info->screen_base = gp->fb_base;
78 info->screen_size = gp->fb_size;
79
80 info->pseudo_palette = gp->pseudo_palette;
81
82 /* Fill fix common fields */
83 strlcpy(info->fix.id, "gfb", sizeof(info->fix.id));
84 info->fix.smem_start = gp->fb_base_phys;
85 info->fix.smem_len = gp->fb_size;
86 info->fix.type = FB_TYPE_PACKED_PIXELS;
87 if (gp->depth == 32 || gp->depth == 24)
88 info->fix.visual = FB_VISUAL_TRUECOLOR;
89 else
90 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
91
92 var->xres = gp->width;
93 var->yres = gp->height;
94 var->xres_virtual = var->xres;
95 var->yres_virtual = var->yres;
96 var->bits_per_pixel = gp->depth;
97
98 var->red.offset = 0;
99 var->red.length = 8;
100 var->green.offset = 8;
101 var->green.length = 8;
102 var->blue.offset = 16;
103 var->blue.length = 8;
104 var->transp.offset = 0;
105 var->transp.length = 0;
106
107 if (fb_alloc_cmap(&info->cmap, 256, 0)) {
108 printk(KERN_ERR "gfb: Cannot allocate color map.\n");
109 return -ENOMEM;
110 }
111
112 return 0;
113}
114
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800115static int gfb_probe(struct platform_device *op)
David S. Miller2d378b92010-03-13 16:25:03 -0800116{
Grant Likely61c7a082010-04-13 16:12:29 -0700117 struct device_node *dp = op->dev.of_node;
David S. Miller2d378b92010-03-13 16:25:03 -0800118 struct fb_info *info;
119 struct gfb_info *gp;
120 int err;
121
122 info = framebuffer_alloc(sizeof(struct gfb_info), &op->dev);
123 if (!info) {
124 printk(KERN_ERR "gfb: Cannot allocate fb_info\n");
125 err = -ENOMEM;
126 goto err_out;
127 }
128
129 gp = info->par;
130 gp->info = info;
131 gp->of_node = dp;
132
133 gp->fb_base_phys = op->resource[6].start;
134
135 err = gfb_get_props(gp);
136 if (err)
137 goto err_release_fb;
138
139 /* Framebuffer length is the same regardless of resolution. */
140 info->fix.line_length = 16384;
141 gp->fb_size = info->fix.line_length * gp->height;
142
143 gp->fb_base = of_ioremap(&op->resource[6], 0,
144 gp->fb_size, "gfb fb");
Peter Senna Tschudin6a1e5f82012-09-18 14:07:52 +0200145 if (!gp->fb_base) {
146 err = -ENOMEM;
David S. Miller2d378b92010-03-13 16:25:03 -0800147 goto err_release_fb;
Peter Senna Tschudin6a1e5f82012-09-18 14:07:52 +0200148 }
David S. Miller2d378b92010-03-13 16:25:03 -0800149
150 err = gfb_set_fbinfo(gp);
151 if (err)
152 goto err_unmap_fb;
153
154 printk("gfb: Found device at %s\n", dp->full_name);
155
156 err = register_framebuffer(info);
157 if (err < 0) {
158 printk(KERN_ERR "gfb: Could not register framebuffer %s\n",
159 dp->full_name);
160 goto err_unmap_fb;
161 }
162
163 dev_set_drvdata(&op->dev, info);
164
165 return 0;
166
167err_unmap_fb:
168 of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
169
170err_release_fb:
171 framebuffer_release(info);
172
173err_out:
174 return err;
175}
176
David S. Miller2d378b92010-03-13 16:25:03 -0800177static const struct of_device_id gfb_match[] = {
178 {
179 .name = "SUNW,gfb",
180 },
181 {},
182};
David S. Miller2d378b92010-03-13 16:25:03 -0800183
Grant Likely28541d02011-02-22 21:07:43 -0700184static struct platform_driver gfb_driver = {
David S. Miller2d378b92010-03-13 16:25:03 -0800185 .probe = gfb_probe,
Grant Likely40182942010-04-13 16:13:02 -0700186 .driver = {
Paul Gortmaker27844cb2016-02-21 22:13:11 -0500187 .name = "gfb",
188 .of_match_table = gfb_match,
189 .suppress_bind_attrs = true,
Grant Likely40182942010-04-13 16:13:02 -0700190 },
David S. Miller2d378b92010-03-13 16:25:03 -0800191};
192
193static int __init gfb_init(void)
194{
195 if (fb_get_options("gfb", NULL))
196 return -ENODEV;
197
Grant Likely28541d02011-02-22 21:07:43 -0700198 return platform_driver_register(&gfb_driver);
David S. Miller2d378b92010-03-13 16:25:03 -0800199}
Paul Gortmaker27844cb2016-02-21 22:13:11 -0500200device_initcall(gfb_init);