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;
210 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) {
212 "imacfb: cannot reserve video memory at 0x%lx\n",
213 imacfb_fix.smem_start);
214 /* We cannot make this fatal. Sometimes this comes from magic
215 spaces our resource handlers simply don't know about */
218 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
221 goto err_release_mem;
223 info->pseudo_palette = info->par;
226 info->screen_base = ioremap(imacfb_fix.smem_start, imacfb_fix.smem_len);
227 if (!info->screen_base) {
228 printk(KERN_ERR "imacfb: abort, cannot ioremap video memory "
230 imacfb_fix.smem_len, imacfb_fix.smem_start);
235 printk(KERN_INFO "imacfb: framebuffer at 0x%lx, mapped to 0x%p, "
236 "using %dk, total %dk\n",
237 imacfb_fix.smem_start, info->screen_base,
238 size_remap/1024, size_total/1024);
239 printk(KERN_INFO "imacfb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
240 imacfb_defined.xres, imacfb_defined.yres,
241 imacfb_defined.bits_per_pixel, imacfb_fix.line_length,
244 imacfb_defined.xres_virtual = imacfb_defined.xres;
245 imacfb_defined.yres_virtual = imacfb_fix.smem_len /
246 imacfb_fix.line_length;
247 printk(KERN_INFO "imacfb: scrolling: redraw\n");
248 imacfb_defined.yres_virtual = imacfb_defined.yres;
250 /* some dummy values for timing to make fbset happy */
251 imacfb_defined.pixclock = 10000000 / imacfb_defined.xres *
252 1000 / imacfb_defined.yres;
253 imacfb_defined.left_margin = (imacfb_defined.xres / 8) & 0xf8;
254 imacfb_defined.hsync_len = (imacfb_defined.xres / 8) & 0xf8;
256 imacfb_defined.red.offset = screen_info.red_pos;
257 imacfb_defined.red.length = screen_info.red_size;
258 imacfb_defined.green.offset = screen_info.green_pos;
259 imacfb_defined.green.length = screen_info.green_size;
260 imacfb_defined.blue.offset = screen_info.blue_pos;
261 imacfb_defined.blue.length = screen_info.blue_size;
262 imacfb_defined.transp.offset = screen_info.rsvd_pos;
263 imacfb_defined.transp.length = screen_info.rsvd_size;
265 printk(KERN_INFO "imacfb: %s: "
266 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
268 screen_info.rsvd_size,
269 screen_info.red_size,
270 screen_info.green_size,
271 screen_info.blue_size,
272 screen_info.rsvd_pos,
274 screen_info.green_pos,
275 screen_info.blue_pos);
277 imacfb_fix.ypanstep = 0;
278 imacfb_fix.ywrapstep = 0;
280 /* request failure does not faze us, as vgacon probably has this
281 * region already (FIXME) */
282 request_region(0x3c0, 32, "imacfb");
284 info->fbops = &imacfb_ops;
285 info->var = imacfb_defined;
286 info->fix = imacfb_fix;
287 info->flags = FBINFO_FLAG_DEFAULT;
289 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
293 if (register_framebuffer(info)<0) {
297 printk(KERN_INFO "fb%d: %s frame buffer device\n",
298 info->node, info->fix.id);
302 fb_dealloc_cmap(&info->cmap);
304 iounmap(info->screen_base);
305 framebuffer_release(info);
307 release_mem_region(imacfb_fix.smem_start, size_total);
311 static struct platform_driver imacfb_driver = {
312 .probe = imacfb_probe,
318 static struct platform_device imacfb_device = {
322 static int __init imacfb_init(void)
327 /* ignore error return of fb_get_options */
328 fb_get_options("imacfb", &option);
329 imacfb_setup(option);
330 ret = platform_driver_register(&imacfb_driver);
333 ret = platform_device_register(&imacfb_device);
335 platform_driver_unregister(&imacfb_driver);
339 module_init(imacfb_init);
341 MODULE_LICENSE("GPL");