blob: 4db6b48a87155b1f7316ad6f5145d37922edec8f [file] [log] [blame]
Vitaly Wool36c93662006-07-03 00:24:19 -07001/*
2 * drivers/video/pnx4008/pnxrgbfb.c
3 *
4 * PNX4008's framebuffer support
5 *
6 * Author: Grigory Tolstolytkin <gtolstolytkin@ru.mvista.com>
7 * Based on Philips Semiconductors's code
8 *
9 * Copyrght (c) 2005 MontaVista Software, Inc.
10 * Copyright (c) 2005 Philips Semiconductors
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/mm.h>
21#include <linux/slab.h>
22#include <linux/vmalloc.h>
23#include <linux/delay.h>
24#include <linux/interrupt.h>
25#include <linux/fb.h>
26#include <linux/init.h>
27#include <linux/platform_device.h>
28
Vitaly Wool36c93662006-07-03 00:24:19 -070029#include "sdum.h"
30#include "fbcommon.h"
31
32static u32 colreg[16];
33
34static struct fb_var_screeninfo rgbfb_var __initdata = {
35 .xres = LCD_X_RES,
36 .yres = LCD_Y_RES,
37 .xres_virtual = LCD_X_RES,
38 .yres_virtual = LCD_Y_RES,
39 .bits_per_pixel = 32,
40 .red.offset = 16,
41 .red.length = 8,
42 .green.offset = 8,
43 .green.length = 8,
44 .blue.offset = 0,
45 .blue.length = 8,
46 .left_margin = 0,
47 .right_margin = 0,
48 .upper_margin = 0,
49 .lower_margin = 0,
50 .vmode = FB_VMODE_NONINTERLACED,
51};
52static struct fb_fix_screeninfo rgbfb_fix __initdata = {
53 .id = "RGBFB",
54 .line_length = LCD_X_RES * LCD_BBP,
55 .type = FB_TYPE_PACKED_PIXELS,
56 .visual = FB_VISUAL_TRUECOLOR,
57 .xpanstep = 0,
58 .ypanstep = 0,
59 .ywrapstep = 0,
60 .accel = FB_ACCEL_NONE,
61};
62
63static int channel_owned;
64
65static int no_cursor(struct fb_info *info, struct fb_cursor *cursor)
66{
67 return 0;
68}
69
70static int rgbfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
71 u_int transp, struct fb_info *info)
72{
73 if (regno > 15)
74 return 1;
75
76 colreg[regno] = ((red & 0xff00) << 8) | (green & 0xff00) |
77 ((blue & 0xff00) >> 8);
78 return 0;
79}
80
81static int rgbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
82{
83 return pnx4008_sdum_mmap(info, vma, NULL);
84}
85
86static struct fb_ops rgbfb_ops = {
87 .fb_mmap = rgbfb_mmap,
88 .fb_setcolreg = rgbfb_setcolreg,
89 .fb_fillrect = cfb_fillrect,
90 .fb_copyarea = cfb_copyarea,
91 .fb_imageblit = cfb_imageblit,
92};
93
94static int rgbfb_remove(struct platform_device *pdev)
95{
96 struct fb_info *info = platform_get_drvdata(pdev);
97
98 if (info) {
99 unregister_framebuffer(info);
100 fb_dealloc_cmap(&info->cmap);
101 framebuffer_release(info);
102 platform_set_drvdata(pdev, NULL);
Vitaly Wool36c93662006-07-03 00:24:19 -0700103 }
104
105 pnx4008_free_dum_channel(channel_owned, pdev->id);
106 pnx4008_set_dum_exit_notification(pdev->id);
107
108 return 0;
109}
110
111static int __devinit rgbfb_probe(struct platform_device *pdev)
112{
113 struct fb_info *info;
114 struct dumchannel_uf chan_uf;
115 int ret;
116 char *option;
117
118 info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev);
119 if (!info) {
120 ret = -ENOMEM;
121 goto err;
122 }
123
124 pnx4008_get_fb_addresses(FB_TYPE_RGB, (void **)&info->screen_base,
125 (dma_addr_t *) &rgbfb_fix.smem_start,
126 &rgbfb_fix.smem_len);
127
128 if ((ret = pnx4008_alloc_dum_channel(pdev->id)) < 0)
129 goto err0;
130 else {
131 channel_owned = ret;
132 chan_uf.channelnr = channel_owned;
133 chan_uf.dirty = (u32 *) NULL;
134 chan_uf.source = (u32 *) rgbfb_fix.smem_start;
135 chan_uf.x_offset = 0;
136 chan_uf.y_offset = 0;
137 chan_uf.width = LCD_X_RES;
138 chan_uf.height = LCD_Y_RES;
139
140 if ((ret = pnx4008_put_dum_channel_uf(chan_uf, pdev->id))< 0)
141 goto err1;
142
143 if ((ret =
144 pnx4008_set_dum_channel_sync(channel_owned, CONF_SYNC_ON,
145 pdev->id)) < 0)
146 goto err1;
147
148 if ((ret =
149 pnx4008_set_dum_channel_dirty_detect(channel_owned,
150 CONF_DIRTYDETECTION_ON,
151 pdev->id)) < 0)
152 goto err1;
153 }
154
Vitaly Wool3b9c10d2006-11-16 01:19:14 -0800155 if (!fb_get_options("pnxrgbfb", &option) && option &&
156 !strcmp(option, "nocursor"))
Vitaly Wool36c93662006-07-03 00:24:19 -0700157 rgbfb_ops.fb_cursor = no_cursor;
158
159 info->node = -1;
160 info->flags = FBINFO_FLAG_DEFAULT;
161 info->fbops = &rgbfb_ops;
162 info->fix = rgbfb_fix;
163 info->var = rgbfb_var;
164 info->screen_size = rgbfb_fix.smem_len;
165 info->pseudo_palette = info->par;
166 info->par = NULL;
167
168 ret = fb_alloc_cmap(&info->cmap, 256, 0);
169 if (ret < 0)
Julia Lawall7a6278e2008-05-12 14:02:16 -0700170 goto err1;
Vitaly Wool36c93662006-07-03 00:24:19 -0700171
172 ret = register_framebuffer(info);
173 if (ret < 0)
Julia Lawall7a6278e2008-05-12 14:02:16 -0700174 goto err2;
Vitaly Wool36c93662006-07-03 00:24:19 -0700175 platform_set_drvdata(pdev, info);
176
177 return 0;
178
Vitaly Wool36c93662006-07-03 00:24:19 -0700179err2:
Julia Lawall7a6278e2008-05-12 14:02:16 -0700180 fb_dealloc_cmap(&info->cmap);
Vitaly Wool36c93662006-07-03 00:24:19 -0700181err1:
182 pnx4008_free_dum_channel(channel_owned, pdev->id);
183err0:
Julia Lawall7a6278e2008-05-12 14:02:16 -0700184 framebuffer_release(info);
Vitaly Wool36c93662006-07-03 00:24:19 -0700185err:
186 return ret;
187}
188
189static struct platform_driver rgbfb_driver = {
190 .driver = {
Vitaly Wool84a763e2006-11-16 01:19:11 -0800191 .name = "pnx4008-rgbfb",
Vitaly Wool36c93662006-07-03 00:24:19 -0700192 },
193 .probe = rgbfb_probe,
194 .remove = rgbfb_remove,
195};
196
197static int __init rgbfb_init(void)
198{
199 return platform_driver_register(&rgbfb_driver);
200}
201
202static void __exit rgbfb_exit(void)
203{
204 platform_driver_unregister(&rgbfb_driver);
205}
206
207module_init(rgbfb_init);
208module_exit(rgbfb_exit);
209
210MODULE_LICENSE("GPL");