2 * framebuffer driver for Intel Based Mac's
4 * (c) 2006 Edgar Hucek <gimli@dark-green.com>
5 * Original imac driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
9 #include <linux/delay.h>
10 #include <linux/errno.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/ioport.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>
24 #include <video/vga.h>
26 typedef enum _MAC_TYPE {
34 /* --------------------------------------------------------------------- */
36 static struct fb_var_screeninfo imacfb_defined __initdata = {
37 .activate = FB_ACTIVATE_NOW,
44 .vmode = FB_VMODE_NONINTERLACED,
47 static struct fb_fix_screeninfo imacfb_fix __initdata = {
49 .type = FB_TYPE_PACKED_PIXELS,
50 .accel = FB_ACCEL_NONE,
51 .visual = FB_VISUAL_TRUECOLOR,
55 static int model = M_NEW;
56 static int manual_height;
57 static int manual_width;
59 #define DEFAULT_FB_MEM 1024*1024*16
61 /* --------------------------------------------------------------------- */
63 static int imacfb_setcolreg(unsigned regno, unsigned red, unsigned green,
64 unsigned blue, unsigned transp,
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.
74 if (regno >= info->cmap.len)
81 ((u32 *)(info->pseudo_palette))[regno] =
82 (red << info->var.red.offset) |
83 (green << info->var.green.offset) |
84 (blue << info->var.blue.offset);
89 static struct fb_ops imacfb_ops = {
91 .fb_setcolreg = imacfb_setcolreg,
92 .fb_fillrect = cfb_fillrect,
93 .fb_copyarea = cfb_copyarea,
94 .fb_imageblit = cfb_imageblit,
97 static int __init imacfb_setup(char *options)
101 if (!options || !*options)
104 while ((this_opt = strsep(&options, ",")) != NULL) {
105 if (!*this_opt) continue;
107 if (!strcmp(this_opt, "inverse"))
109 else if (!strcmp(this_opt, "i17"))
111 else if (!strcmp(this_opt, "i20"))
113 else if (!strcmp(this_opt, "mini"))
115 else if (!strcmp(this_opt, "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);
125 static int __init imacfb_probe(struct platform_device *dev)
127 struct fb_info *info;
129 unsigned int size_vmode;
130 unsigned int size_remap;
131 unsigned int size_total;
133 screen_info.lfb_depth = 32;
134 screen_info.lfb_size = DEFAULT_FB_MEM / 0x10000;
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;
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;
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;
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;
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;
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;
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;
187 /* size_vmode -- that is the amount of memory needed for the
188 * used video mode, i.e. the minimum amount of
190 size_vmode = imacfb_defined.yres * imacfb_fix.line_length;
192 /* size_total -- all video memory we have. Used for
193 * entries, ressource allocation and bounds
195 size_total = screen_info.lfb_size * 65536;
196 if (size_total < size_vmode)
197 size_total = size_vmode;
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;
211 screen_info.imacpm_seg = 0;
214 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) {
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 */
222 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
225 goto err_release_mem;
227 info->pseudo_palette = info->par;
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 "
234 imacfb_fix.smem_len, imacfb_fix.smem_start);
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,
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;
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;
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;
269 printk(KERN_INFO "imacfb: %s: "
270 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
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,
278 screen_info.green_pos,
279 screen_info.blue_pos);
281 imacfb_fix.ypanstep = 0;
282 imacfb_fix.ywrapstep = 0;
284 /* request failure does not faze us, as vgacon probably has this
285 * region already (FIXME) */
286 request_region(0x3c0, 32, "imacfb");
288 info->fbops = &imacfb_ops;
289 info->var = imacfb_defined;
290 info->fix = imacfb_fix;
291 info->flags = FBINFO_FLAG_DEFAULT;
293 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
297 if (register_framebuffer(info)<0) {
301 printk(KERN_INFO "fb%d: %s frame buffer device\n",
302 info->node, info->fix.id);
306 fb_dealloc_cmap(&info->cmap);
308 iounmap(info->screen_base);
309 framebuffer_release(info);
311 release_mem_region(imacfb_fix.smem_start, size_total);
315 static struct platform_driver imacfb_driver = {
316 .probe = imacfb_probe,
322 static struct platform_device imacfb_device = {
326 static int __init imacfb_init(void)
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);
337 ret = platform_device_register(&imacfb_device);
339 platform_driver_unregister(&imacfb_driver);
343 module_init(imacfb_init);
345 MODULE_LICENSE("GPL");