diff options
-rw-r--r-- | drivers/video/Kconfig | 9 | ||||
-rw-r--r-- | drivers/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/video/imacfb.c | 345 |
3 files changed, 355 insertions, 0 deletions
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 2a265e1c7cbc..17de4c84db69 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig | |||
@@ -550,6 +550,15 @@ config FB_VESA | |||
550 | You will get a boot time penguin logo at no additional cost. Please | 550 | You will get a boot time penguin logo at no additional cost. Please |
551 | read <file:Documentation/fb/vesafb.txt>. If unsure, say Y. | 551 | read <file:Documentation/fb/vesafb.txt>. If unsure, say Y. |
552 | 552 | ||
553 | config FB_IMAC | ||
554 | bool "Intel-based Macintosh Framebuffer Support" | ||
555 | depends on (FB = y) && X86 | ||
556 | select FB_CFB_FILLRECT | ||
557 | select FB_CFB_COPYAREA | ||
558 | select FB_CFB_IMAGEBLIT | ||
559 | help | ||
560 | This is the frame buffer device driver for the Intel-based Macintosh | ||
561 | |||
553 | config FB_HGA | 562 | config FB_HGA |
554 | tristate "Hercules mono graphics support" | 563 | tristate "Hercules mono graphics support" |
555 | depends on FB && X86 | 564 | depends on FB && X86 |
diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 23de3b2c7856..b7dfee209cd0 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile | |||
@@ -97,6 +97,7 @@ obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o | |||
97 | 97 | ||
98 | # Platform or fallback drivers go here | 98 | # Platform or fallback drivers go here |
99 | obj-$(CONFIG_FB_VESA) += vesafb.o | 99 | obj-$(CONFIG_FB_VESA) += vesafb.o |
100 | obj-$(CONFIG_FB_IMAC) += imacfb.o | ||
100 | obj-$(CONFIG_FB_VGA16) += vga16fb.o vgastate.o | 101 | obj-$(CONFIG_FB_VGA16) += vga16fb.o vgastate.o |
101 | obj-$(CONFIG_FB_OF) += offb.o | 102 | obj-$(CONFIG_FB_OF) += offb.o |
102 | 103 | ||
diff --git a/drivers/video/imacfb.c b/drivers/video/imacfb.c new file mode 100644 index 000000000000..7b1c168c834d --- /dev/null +++ b/drivers/video/imacfb.c | |||
@@ -0,0 +1,345 @@ | |||
1 | /* | ||
2 | * framebuffer driver for Intel Based Mac's | ||
3 | * | ||
4 | * (c) 2006 Edgar Hucek <gimli@dark-green.com> | ||
5 | * Original imac driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de> | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include <linux/delay.h> | ||
10 | #include <linux/errno.h> | ||
11 | #include <linux/fb.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/ioport.h> | ||
15 | #include <linux/mm.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/string.h> | ||
20 | #include <linux/tty.h> | ||
21 | |||
22 | #include <asm/io.h> | ||
23 | |||
24 | #include <video/vga.h> | ||
25 | |||
26 | typedef enum _MAC_TYPE { | ||
27 | M_I17, | ||
28 | M_I20, | ||
29 | M_MINI, | ||
30 | M_MACBOOK, | ||
31 | M_NEW | ||
32 | } MAC_TYPE; | ||
33 | |||
34 | /* --------------------------------------------------------------------- */ | ||
35 | |||
36 | static struct fb_var_screeninfo imacfb_defined __initdata = { | ||
37 | .activate = FB_ACTIVATE_NOW, | ||
38 | .height = -1, | ||
39 | .width = -1, | ||
40 | .right_margin = 32, | ||
41 | .upper_margin = 16, | ||
42 | .lower_margin = 4, | ||
43 | .vsync_len = 4, | ||
44 | .vmode = FB_VMODE_NONINTERLACED, | ||
45 | }; | ||
46 | |||
47 | static struct fb_fix_screeninfo imacfb_fix __initdata = { | ||
48 | .id = "IMAC VGA", | ||
49 | .type = FB_TYPE_PACKED_PIXELS, | ||
50 | .accel = FB_ACCEL_NONE, | ||
51 | .visual = FB_VISUAL_TRUECOLOR, | ||
52 | }; | ||
53 | |||
54 | static int inverse; | ||
55 | static int model = M_NEW; | ||
56 | static int manual_height; | ||
57 | static int manual_width; | ||
58 | |||
59 | #define DEFAULT_FB_MEM 1024*1024*16 | ||
60 | |||
61 | /* --------------------------------------------------------------------- */ | ||
62 | |||
63 | static int imacfb_setcolreg(unsigned regno, unsigned red, unsigned green, | ||
64 | unsigned blue, unsigned transp, | ||
65 | struct fb_info *info) | ||
66 | { | ||
67 | /* | ||
68 | * Set a single color register. The values supplied are | ||
69 | * already rounded down to the hardware's capabilities | ||
70 | * (according to the entries in the `var' structure). Return | ||
71 | * != 0 for invalid regno. | ||
72 | */ | ||
73 | |||
74 | if (regno >= info->cmap.len) | ||
75 | return 1; | ||
76 | |||
77 | if (regno < 16) { | ||
78 | red >>= 8; | ||
79 | green >>= 8; | ||
80 | blue >>= 8; | ||
81 | ((u32 *)(info->pseudo_palette))[regno] = | ||
82 | (red << info->var.red.offset) | | ||
83 | (green << info->var.green.offset) | | ||
84 | (blue << info->var.blue.offset); | ||
85 | } | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static struct fb_ops imacfb_ops = { | ||
90 | .owner = THIS_MODULE, | ||
91 | .fb_setcolreg = imacfb_setcolreg, | ||
92 | .fb_fillrect = cfb_fillrect, | ||
93 | .fb_copyarea = cfb_copyarea, | ||
94 | .fb_imageblit = cfb_imageblit, | ||
95 | }; | ||
96 | |||
97 | static int __init imacfb_setup(char *options) | ||
98 | { | ||
99 | char *this_opt; | ||
100 | |||
101 | if (!options || !*options) | ||
102 | return 0; | ||
103 | |||
104 | while ((this_opt = strsep(&options, ",")) != NULL) { | ||
105 | if (!*this_opt) continue; | ||
106 | |||
107 | if (!strcmp(this_opt, "inverse")) | ||
108 | inverse = 1; | ||
109 | else if (!strcmp(this_opt, "i17")) | ||
110 | model = M_I17; | ||
111 | else if (!strcmp(this_opt, "i20")) | ||
112 | model = M_I20; | ||
113 | else if (!strcmp(this_opt, "mini")) | ||
114 | model = M_MINI; | ||
115 | else if (!strcmp(this_opt, "macbook")) | ||
116 | model = M_MACBOOK; | ||
117 | else if (!strncmp(this_opt, "height:", 7)) | ||
118 | manual_height = simple_strtoul(this_opt+7, NULL, 0); | ||
119 | else if (!strncmp(this_opt, "width:", 6)) | ||
120 | manual_width = simple_strtoul(this_opt+6, NULL, 0); | ||
121 | } | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static int __init imacfb_probe(struct platform_device *dev) | ||
126 | { | ||
127 | struct fb_info *info; | ||
128 | int err; | ||
129 | unsigned int size_vmode; | ||
130 | unsigned int size_remap; | ||
131 | unsigned int size_total; | ||
132 | |||
133 | screen_info.lfb_depth = 32; | ||
134 | screen_info.lfb_size = DEFAULT_FB_MEM / 0x10000; | ||
135 | screen_info.pages=1; | ||
136 | screen_info.blue_size = 8; | ||
137 | screen_info.blue_pos = 0; | ||
138 | screen_info.green_size = 8; | ||
139 | screen_info.green_pos = 8; | ||
140 | screen_info.red_size = 8; | ||
141 | screen_info.red_pos = 16; | ||
142 | screen_info.rsvd_size = 8; | ||
143 | screen_info.rsvd_pos = 24; | ||
144 | |||
145 | switch (model) { | ||
146 | case M_I17: | ||
147 | screen_info.lfb_width = 1440; | ||
148 | screen_info.lfb_height = 900; | ||
149 | screen_info.lfb_linelength = 1472 * 4; | ||
150 | screen_info.lfb_base = 0x80010000; | ||
151 | break; | ||
152 | case M_NEW: | ||
153 | case M_I20: | ||
154 | screen_info.lfb_width = 1680; | ||
155 | screen_info.lfb_height = 1050; | ||
156 | screen_info.lfb_linelength = 1728 * 4; | ||
157 | screen_info.lfb_base = 0x80010000; | ||
158 | break; | ||
159 | case M_MINI: | ||
160 | screen_info.lfb_width = 1024; | ||
161 | screen_info.lfb_height = 768; | ||
162 | screen_info.lfb_linelength = 2048 * 4; | ||
163 | screen_info.lfb_base = 0x80000000; | ||
164 | break; | ||
165 | case M_MACBOOK: | ||
166 | screen_info.lfb_width = 1280; | ||
167 | screen_info.lfb_height = 800; | ||
168 | screen_info.lfb_linelength = 2048 * 4; | ||
169 | screen_info.lfb_base = 0x80000000; | ||
170 | break; | ||
171 | } | ||
172 | |||
173 | /* if the user wants to manually specify height/width, | ||
174 | we will override the defaults */ | ||
175 | /* TODO: eventually get auto-detection working */ | ||
176 | if (manual_height > 0) | ||
177 | screen_info.lfb_height = manual_height; | ||
178 | if (manual_width > 0) | ||
179 | screen_info.lfb_width = manual_width; | ||
180 | |||
181 | imacfb_fix.smem_start = screen_info.lfb_base; | ||
182 | imacfb_defined.bits_per_pixel = screen_info.lfb_depth; | ||
183 | imacfb_defined.xres = screen_info.lfb_width; | ||
184 | imacfb_defined.yres = screen_info.lfb_height; | ||
185 | imacfb_fix.line_length = screen_info.lfb_linelength; | ||
186 | |||
187 | /* size_vmode -- that is the amount of memory needed for the | ||
188 | * used video mode, i.e. the minimum amount of | ||
189 | * memory we need. */ | ||
190 | size_vmode = imacfb_defined.yres * imacfb_fix.line_length; | ||
191 | |||
192 | /* size_total -- all video memory we have. Used for | ||
193 | * entries, ressource allocation and bounds | ||
194 | * checking. */ | ||
195 | size_total = screen_info.lfb_size * 65536; | ||
196 | if (size_total < size_vmode) | ||
197 | size_total = size_vmode; | ||
198 | |||
199 | /* size_remap -- the amount of video memory we are going to | ||
200 | * use for imacfb. With modern cards it is no | ||
201 | * option to simply use size_total as that | ||
202 | * wastes plenty of kernel address space. */ | ||
203 | size_remap = size_vmode * 2; | ||
204 | if (size_remap < size_vmode) | ||
205 | size_remap = size_vmode; | ||
206 | if (size_remap > size_total) | ||
207 | size_remap = size_total; | ||
208 | imacfb_fix.smem_len = size_remap; | ||
209 | |||
210 | #ifndef __i386__ | ||
211 | screen_info.imacpm_seg = 0; | ||
212 | #endif | ||
213 | |||
214 | if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) { | ||
215 | printk(KERN_WARNING | ||
216 | "imacfb: cannot reserve video memory at 0x%lx\n", | ||
217 | imacfb_fix.smem_start); | ||
218 | /* We cannot make this fatal. Sometimes this comes from magic | ||
219 | spaces our resource handlers simply don't know about */ | ||
220 | } | ||
221 | |||
222 | info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev); | ||
223 | if (!info) { | ||
224 | err = -ENOMEM; | ||
225 | goto err_release_mem; | ||
226 | } | ||
227 | info->pseudo_palette = info->par; | ||
228 | info->par = NULL; | ||
229 | |||
230 | info->screen_base = ioremap(imacfb_fix.smem_start, imacfb_fix.smem_len); | ||
231 | if (!info->screen_base) { | ||
232 | printk(KERN_ERR "imacfb: abort, cannot ioremap video memory " | ||
233 | "0x%x @ 0x%lx\n", | ||
234 | imacfb_fix.smem_len, imacfb_fix.smem_start); | ||
235 | err = -EIO; | ||
236 | goto err_unmap; | ||
237 | } | ||
238 | |||
239 | printk(KERN_INFO "imacfb: framebuffer at 0x%lx, mapped to 0x%p, " | ||
240 | "using %dk, total %dk\n", | ||
241 | imacfb_fix.smem_start, info->screen_base, | ||
242 | size_remap/1024, size_total/1024); | ||
243 | printk(KERN_INFO "imacfb: mode is %dx%dx%d, linelength=%d, pages=%d\n", | ||
244 | imacfb_defined.xres, imacfb_defined.yres, | ||
245 | imacfb_defined.bits_per_pixel, imacfb_fix.line_length, | ||
246 | screen_info.pages); | ||
247 | |||
248 | imacfb_defined.xres_virtual = imacfb_defined.xres; | ||
249 | imacfb_defined.yres_virtual = imacfb_fix.smem_len / | ||
250 | imacfb_fix.line_length; | ||
251 | printk(KERN_INFO "imacfb: scrolling: redraw\n"); | ||
252 | imacfb_defined.yres_virtual = imacfb_defined.yres; | ||
253 | |||
254 | /* some dummy values for timing to make fbset happy */ | ||
255 | imacfb_defined.pixclock = 10000000 / imacfb_defined.xres * | ||
256 | 1000 / imacfb_defined.yres; | ||
257 | imacfb_defined.left_margin = (imacfb_defined.xres / 8) & 0xf8; | ||
258 | imacfb_defined.hsync_len = (imacfb_defined.xres / 8) & 0xf8; | ||
259 | |||
260 | imacfb_defined.red.offset = screen_info.red_pos; | ||
261 | imacfb_defined.red.length = screen_info.red_size; | ||
262 | imacfb_defined.green.offset = screen_info.green_pos; | ||
263 | imacfb_defined.green.length = screen_info.green_size; | ||
264 | imacfb_defined.blue.offset = screen_info.blue_pos; | ||
265 | imacfb_defined.blue.length = screen_info.blue_size; | ||
266 | imacfb_defined.transp.offset = screen_info.rsvd_pos; | ||
267 | imacfb_defined.transp.length = screen_info.rsvd_size; | ||
268 | |||
269 | printk(KERN_INFO "imacfb: %s: " | ||
270 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", | ||
271 | "Truecolor", | ||
272 | screen_info.rsvd_size, | ||
273 | screen_info.red_size, | ||
274 | screen_info.green_size, | ||
275 | screen_info.blue_size, | ||
276 | screen_info.rsvd_pos, | ||
277 | screen_info.red_pos, | ||
278 | screen_info.green_pos, | ||
279 | screen_info.blue_pos); | ||
280 | |||
281 | imacfb_fix.ypanstep = 0; | ||
282 | imacfb_fix.ywrapstep = 0; | ||
283 | |||
284 | /* request failure does not faze us, as vgacon probably has this | ||
285 | * region already (FIXME) */ | ||
286 | request_region(0x3c0, 32, "imacfb"); | ||
287 | |||
288 | info->fbops = &imacfb_ops; | ||
289 | info->var = imacfb_defined; | ||
290 | info->fix = imacfb_fix; | ||
291 | info->flags = FBINFO_FLAG_DEFAULT; | ||
292 | |||
293 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { | ||
294 | err = -ENOMEM; | ||
295 | goto err_unmap; | ||
296 | } | ||
297 | if (register_framebuffer(info)<0) { | ||
298 | err = -EINVAL; | ||
299 | goto err_fb_dealoc; | ||
300 | } | ||
301 | printk(KERN_INFO "fb%d: %s frame buffer device\n", | ||
302 | info->node, info->fix.id); | ||
303 | return 0; | ||
304 | |||
305 | err_fb_dealoc: | ||
306 | fb_dealloc_cmap(&info->cmap); | ||
307 | err_unmap: | ||
308 | iounmap(info->screen_base); | ||
309 | framebuffer_release(info); | ||
310 | err_release_mem: | ||
311 | release_mem_region(imacfb_fix.smem_start, size_total); | ||
312 | return err; | ||
313 | } | ||
314 | |||
315 | static struct platform_driver imacfb_driver = { | ||
316 | .probe = imacfb_probe, | ||
317 | .driver = { | ||
318 | .name = "imacfb", | ||
319 | }, | ||
320 | }; | ||
321 | |||
322 | static struct platform_device imacfb_device = { | ||
323 | .name = "imacfb", | ||
324 | }; | ||
325 | |||
326 | static int __init imacfb_init(void) | ||
327 | { | ||
328 | int ret; | ||
329 | char *option = NULL; | ||
330 | |||
331 | /* ignore error return of fb_get_options */ | ||
332 | fb_get_options("imacfb", &option); | ||
333 | imacfb_setup(option); | ||
334 | ret = platform_driver_register(&imacfb_driver); | ||
335 | |||
336 | if (!ret) { | ||
337 | ret = platform_device_register(&imacfb_device); | ||
338 | if (ret) | ||
339 | platform_driver_unregister(&imacfb_driver); | ||
340 | } | ||
341 | return ret; | ||
342 | } | ||
343 | module_init(imacfb_init); | ||
344 | |||
345 | MODULE_LICENSE("GPL"); | ||