[kernel] refresh 2.6.32 patches
[openwrt.git] / target / linux / goldfish / patches-2.6.30 / 0128--ARM-goldfish-fb-Add-fb-driver-for-goldfish.patch
1 From f8101c780fdc050eda9f93c94f8841de9f384b4f Mon Sep 17 00:00:00 2001
2 From: =?utf-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= <arve@google.com>
3 Date: Fri, 29 Jun 2007 22:14:27 -0700
4 Subject: [PATCH 128/134] [ARM] goldfish: fb: Add fb driver for goldfish.
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=utf-8
7 Content-Transfer-Encoding: 8bit
8
9 Supports panning for double buffering.
10
11 Signed-off-by: Mike A. Chan <mikechan@google.com>
12 Signed-off-by: Arve Hjønnevåg <arve@android.com>
13 ---
14 drivers/video/Kconfig | 9 ++
15 drivers/video/Makefile | 1 +
16 drivers/video/goldfishfb.c | 334 ++++++++++++++++++++++++++++++++++++++++++++
17 3 files changed, 344 insertions(+), 0 deletions(-)
18 create mode 100644 drivers/video/goldfishfb.c
19
20 --- a/drivers/video/Kconfig
21 +++ b/drivers/video/Kconfig
22 @@ -2005,6 +2005,15 @@ config FB_XILINX
23 framebuffer. ML300 carries a 640*480 LCD display on the board,
24 ML403 uses a standard DB15 VGA connector.
25
26 +config FB_GOLDFISH
27 + tristate "Goldfish Framebuffer"
28 + depends on FB
29 + select FB_CFB_FILLRECT
30 + select FB_CFB_COPYAREA
31 + select FB_CFB_IMAGEBLIT
32 + ---help---
33 + Framebuffer driver for Goldfish Virtual Platform
34 +
35 config FB_COBALT
36 tristate "Cobalt server LCD frame buffer support"
37 depends on FB && MIPS_COBALT
38 --- a/drivers/video/Makefile
39 +++ b/drivers/video/Makefile
40 @@ -92,6 +92,7 @@ obj-$(CONFIG_FB_ATMEL) += atmel_lcdfb
41 obj-$(CONFIG_FB_PVR2) += pvr2fb.o
42 obj-$(CONFIG_FB_VOODOO1) += sstfb.o
43 obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
44 +obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
45 obj-$(CONFIG_FB_68328) += 68328fb.o
46 obj-$(CONFIG_FB_GBE) += gbefb.o
47 obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
48 --- /dev/null
49 +++ b/drivers/video/goldfishfb.c
50 @@ -0,0 +1,334 @@
51 +/* drivers/video/goldfishfb.c
52 +**
53 +** Copyright (C) 2007 Google, Inc.
54 +**
55 +** This software is licensed under the terms of the GNU General Public
56 +** License version 2, as published by the Free Software Foundation, and
57 +** may be copied, distributed, and modified under those terms.
58 +**
59 +** This program is distributed in the hope that it will be useful,
60 +** but WITHOUT ANY WARRANTY; without even the implied warranty of
61 +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62 +** GNU General Public License for more details.
63 +**
64 +*/
65 +
66 +#include <linux/module.h>
67 +#include <linux/kernel.h>
68 +#include <linux/dma-mapping.h>
69 +#include <linux/errno.h>
70 +#include <linux/string.h>
71 +#include <linux/slab.h>
72 +#include <linux/delay.h>
73 +#include <linux/mm.h>
74 +#include <linux/fb.h>
75 +#include <linux/init.h>
76 +#include <linux/interrupt.h>
77 +#include <linux/ioport.h>
78 +#include <linux/platform_device.h>
79 +#ifdef CONFIG_ANDROID_POWER
80 +#include <linux/android_power.h>
81 +#endif
82 +
83 +#include <mach/hardware.h>
84 +
85 +enum {
86 + FB_GET_WIDTH = 0x00,
87 + FB_GET_HEIGHT = 0x04,
88 + FB_INT_STATUS = 0x08,
89 + FB_INT_ENABLE = 0x0c,
90 + FB_SET_BASE = 0x10,
91 + FB_SET_ROTATION = 0x14,
92 + FB_SET_BLANK = 0x18,
93 + FB_GET_PHYS_WIDTH = 0x1c,
94 + FB_GET_PHYS_HEIGHT = 0x20,
95 +
96 + FB_INT_VSYNC = 1U << 0,
97 + FB_INT_BASE_UPDATE_DONE = 1U << 1
98 +};
99 +
100 +struct goldfish_fb {
101 + uint32_t reg_base;
102 + int irq;
103 + spinlock_t lock;
104 + wait_queue_head_t wait;
105 + int base_update_count;
106 + int rotation;
107 + struct fb_info fb;
108 + u32 cmap[16];
109 +#ifdef CONFIG_ANDROID_POWER
110 + android_early_suspend_t early_suspend;
111 +#endif
112 +};
113 +
114 +static irqreturn_t
115 +goldfish_fb_interrupt(int irq, void *dev_id)
116 +{
117 + unsigned long irq_flags;
118 + struct goldfish_fb *fb = dev_id;
119 + uint32_t status;
120 +
121 + spin_lock_irqsave(&fb->lock, irq_flags);
122 + status = readl(fb->reg_base + FB_INT_STATUS);
123 + if(status & FB_INT_BASE_UPDATE_DONE) {
124 + fb->base_update_count++;
125 + wake_up(&fb->wait);
126 + }
127 + spin_unlock_irqrestore(&fb->lock, irq_flags);
128 + return status ? IRQ_HANDLED : IRQ_NONE;
129 +}
130 +
131 +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
132 +{
133 + unsigned int mask = (1 << bf->length) - 1;
134 +
135 + return (val >> (16 - bf->length) & mask) << bf->offset;
136 +}
137 +
138 +static int
139 +goldfish_fb_setcolreg(unsigned int regno, unsigned int red, unsigned int green,
140 + unsigned int blue, unsigned int transp, struct fb_info *info)
141 +{
142 + struct goldfish_fb *fb = container_of(info, struct goldfish_fb, fb);
143 +
144 + if (regno < 16) {
145 + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
146 + convert_bitfield(blue, &fb->fb.var.blue) |
147 + convert_bitfield(green, &fb->fb.var.green) |
148 + convert_bitfield(red, &fb->fb.var.red);
149 + return 0;
150 + }
151 + else {
152 + return 1;
153 + }
154 +}
155 +
156 +static int goldfish_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
157 +{
158 + if((var->rotate & 1) != (info->var.rotate & 1)) {
159 + if((var->xres != info->var.yres) ||
160 + (var->yres != info->var.xres) ||
161 + (var->xres_virtual != info->var.yres) ||
162 + (var->yres_virtual > info->var.xres * 2) ||
163 + (var->yres_virtual < info->var.xres )) {
164 + return -EINVAL;
165 + }
166 + }
167 + else {
168 + if((var->xres != info->var.xres) ||
169 + (var->yres != info->var.yres) ||
170 + (var->xres_virtual != info->var.xres) ||
171 + (var->yres_virtual > info->var.yres * 2) ||
172 + (var->yres_virtual < info->var.yres )) {
173 + return -EINVAL;
174 + }
175 + }
176 + if((var->xoffset != info->var.xoffset) ||
177 + (var->bits_per_pixel != info->var.bits_per_pixel) ||
178 + (var->grayscale != info->var.grayscale)) {
179 + return -EINVAL;
180 + }
181 + return 0;
182 +}
183 +
184 +static int goldfish_fb_set_par(struct fb_info *info)
185 +{
186 + struct goldfish_fb *fb = container_of(info, struct goldfish_fb, fb);
187 + if(fb->rotation != fb->fb.var.rotate) {
188 + info->fix.line_length = info->var.xres * 2;
189 + fb->rotation = fb->fb.var.rotate;
190 + writel(fb->rotation, fb->reg_base + FB_SET_ROTATION);
191 + }
192 + return 0;
193 +}
194 +
195 +
196 +static int goldfish_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
197 +{
198 + unsigned long irq_flags;
199 + int base_update_count;
200 + struct goldfish_fb *fb = container_of(info, struct goldfish_fb, fb);
201 +
202 + spin_lock_irqsave(&fb->lock, irq_flags);
203 + base_update_count = fb->base_update_count;
204 + writel(fb->fb.fix.smem_start + fb->fb.var.xres * 2 * var->yoffset, fb->reg_base + FB_SET_BASE);
205 + spin_unlock_irqrestore(&fb->lock, irq_flags);
206 + wait_event_timeout(fb->wait, fb->base_update_count != base_update_count, HZ / 15);
207 + if(fb->base_update_count == base_update_count)
208 + printk("goldfish_fb_pan_display: timeout wating for base update\n");
209 + return 0;
210 +}
211 +
212 +#ifdef CONFIG_ANDROID_POWER
213 +static void goldfish_fb_early_suspend(android_early_suspend_t *h)
214 +{
215 + struct goldfish_fb *fb = container_of(h, struct goldfish_fb, early_suspend);
216 + writel(1, fb->reg_base + FB_SET_BLANK);
217 +}
218 +
219 +static void goldfish_fb_late_resume(android_early_suspend_t *h)
220 +{
221 + struct goldfish_fb *fb = container_of(h, struct goldfish_fb, early_suspend);
222 + writel(0, fb->reg_base + FB_SET_BLANK);
223 +}
224 +#endif
225 +
226 +static struct fb_ops goldfish_fb_ops = {
227 + .owner = THIS_MODULE,
228 + .fb_check_var = goldfish_fb_check_var,
229 + .fb_set_par = goldfish_fb_set_par,
230 + .fb_setcolreg = goldfish_fb_setcolreg,
231 + .fb_pan_display = goldfish_fb_pan_display,
232 + .fb_fillrect = cfb_fillrect,
233 + .fb_copyarea = cfb_copyarea,
234 + .fb_imageblit = cfb_imageblit,
235 +};
236 +
237 +
238 +static int goldfish_fb_probe(struct platform_device *pdev)
239 +{
240 + int ret;
241 + struct resource *r;
242 + struct goldfish_fb *fb;
243 + size_t framesize;
244 + uint32_t width, height;
245 + dma_addr_t fbpaddr;
246 +
247 + fb = kzalloc(sizeof(*fb), GFP_KERNEL);
248 + if(fb == NULL) {
249 + ret = -ENOMEM;
250 + goto err_fb_alloc_failed;
251 + }
252 + spin_lock_init(&fb->lock);
253 + init_waitqueue_head(&fb->wait);
254 + platform_set_drvdata(pdev, fb);
255 +
256 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
257 + if(r == NULL) {
258 + ret = -ENODEV;
259 + goto err_no_io_base;
260 + }
261 + fb->reg_base = IO_ADDRESS(r->start - IO_START);
262 +
263 + fb->irq = platform_get_irq(pdev, 0);
264 + if(fb->irq < 0) {
265 + ret = -ENODEV;
266 + goto err_no_irq;
267 + }
268 +
269 + width = readl(fb->reg_base + FB_GET_WIDTH);
270 + height = readl(fb->reg_base + FB_GET_HEIGHT);
271 +
272 + fb->fb.fbops = &goldfish_fb_ops;
273 + fb->fb.flags = FBINFO_FLAG_DEFAULT;
274 + fb->fb.pseudo_palette = fb->cmap;
275 + //strncpy(fb->fb.fix.id, clcd_name, sizeof(fb->fb.fix.id));
276 + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
277 + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
278 + fb->fb.fix.line_length = width * 2;
279 + fb->fb.fix.accel = FB_ACCEL_NONE;
280 + fb->fb.fix.ypanstep = 1;
281 +
282 + fb->fb.var.xres = width;
283 + fb->fb.var.yres = height;
284 + fb->fb.var.xres_virtual = width;
285 + fb->fb.var.yres_virtual = height * 2;
286 + fb->fb.var.bits_per_pixel = 16;
287 + fb->fb.var.activate = FB_ACTIVATE_NOW;
288 + fb->fb.var.height = readl(fb->reg_base + FB_GET_PHYS_HEIGHT);
289 + fb->fb.var.width = readl(fb->reg_base + FB_GET_PHYS_WIDTH);
290 +
291 + fb->fb.var.red.offset = 11;
292 + fb->fb.var.red.length = 5;
293 + fb->fb.var.green.offset = 5;
294 + fb->fb.var.green.length = 6;
295 + fb->fb.var.blue.offset = 0;
296 + fb->fb.var.blue.length = 5;
297 +
298 + framesize = width * height * 2 * 2;
299 + fb->fb.screen_base = dma_alloc_writecombine(&pdev->dev, framesize,
300 + &fbpaddr, GFP_KERNEL);
301 + printk("allocating frame buffer %d * %d, got %p\n", width, height, fb->fb.screen_base);
302 + if(fb->fb.screen_base == 0) {
303 + ret = -ENOMEM;
304 + goto err_alloc_screen_base_failed;
305 + }
306 + fb->fb.fix.smem_start = fbpaddr;
307 + fb->fb.fix.smem_len = framesize;
308 +
309 + ret = fb_set_var(&fb->fb, &fb->fb.var);
310 + if(ret)
311 + goto err_fb_set_var_failed;
312 +
313 + ret = request_irq(fb->irq, goldfish_fb_interrupt, IRQF_SHARED, pdev->name, fb);
314 + if(ret)
315 + goto err_request_irq_failed;
316 +
317 + writel(FB_INT_BASE_UPDATE_DONE, fb->reg_base + FB_INT_ENABLE);
318 + goldfish_fb_pan_display(&fb->fb.var, &fb->fb); // updates base
319 +
320 + ret = register_framebuffer(&fb->fb);
321 + if(ret)
322 + goto err_register_framebuffer_failed;
323 +
324 +#ifdef CONFIG_ANDROID_POWER
325 + fb->early_suspend.suspend = goldfish_fb_early_suspend;
326 + fb->early_suspend.resume = goldfish_fb_late_resume;
327 + android_register_early_suspend(&fb->early_suspend);
328 +#endif
329 +
330 + return 0;
331 +
332 +
333 +err_register_framebuffer_failed:
334 + free_irq(fb->irq, fb);
335 +err_request_irq_failed:
336 +err_fb_set_var_failed:
337 + dma_free_writecombine(&pdev->dev, framesize, fb->fb.screen_base, fb->fb.fix.smem_start);
338 +err_alloc_screen_base_failed:
339 +err_no_irq:
340 +err_no_io_base:
341 + kfree(fb);
342 +err_fb_alloc_failed:
343 + return ret;
344 +}
345 +
346 +static int goldfish_fb_remove(struct platform_device *pdev)
347 +{
348 + size_t framesize;
349 + struct goldfish_fb *fb = platform_get_drvdata(pdev);
350 +
351 + framesize = fb->fb.var.xres_virtual * fb->fb.var.yres_virtual * 2;
352 +
353 +#ifdef CONFIG_ANDROID_POWER
354 + android_unregister_early_suspend(&fb->early_suspend);
355 +#endif
356 + unregister_framebuffer(&fb->fb);
357 + free_irq(fb->irq, fb);
358 + dma_free_writecombine(&pdev->dev, framesize, fb->fb.screen_base, fb->fb.fix.smem_start);
359 + kfree(fb);
360 + return 0;
361 +}
362 +
363 +
364 +static struct platform_driver goldfish_fb_driver = {
365 + .probe = goldfish_fb_probe,
366 + .remove = goldfish_fb_remove,
367 + .driver = {
368 + .name = "goldfish_fb"
369 + }
370 +};
371 +
372 +static int __init goldfish_fb_init(void)
373 +{
374 + return platform_driver_register(&goldfish_fb_driver);
375 +}
376 +
377 +static void __exit goldfish_fb_exit(void)
378 +{
379 + platform_driver_unregister(&goldfish_fb_driver);
380 +}
381 +
382 +module_init(goldfish_fb_init);
383 +module_exit(goldfish_fb_exit);
384 +
This page took 0.051894 seconds and 5 git commands to generate.