blob: 8bc46e9303402da0b78211d433f38949d4d687e1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* leo.c: LEO frame buffer driver
2 *
David S. Miller50312ce2006-06-29 14:35:52 -07003 * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 1996-1999 Jakub Jelinek (jj@ultra.linux.cz)
5 * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz)
6 *
7 * Driver layout based loosely on tgafb.c, see that file for credits.
8 */
9
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/errno.h>
13#include <linux/string.h>
14#include <linux/slab.h>
15#include <linux/delay.h>
16#include <linux/init.h>
17#include <linux/fb.h>
18#include <linux/mm.h>
Robert Reif6cd5a862008-05-08 21:37:30 -070019#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/fbio.h>
23
24#include "sbuslib.h"
25
26/*
27 * Local functions.
28 */
29
30static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned,
31 unsigned, struct fb_info *);
32static int leo_blank(int, struct fb_info *);
33
Christoph Hellwig216d5262006-01-14 13:21:25 -080034static int leo_mmap(struct fb_info *, struct vm_area_struct *);
Christoph Hellwig67a66802006-01-14 13:21:25 -080035static int leo_ioctl(struct fb_info *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *);
37
38/*
39 * Frame buffer operations
40 */
41
42static struct fb_ops leo_ops = {
43 .owner = THIS_MODULE,
44 .fb_setcolreg = leo_setcolreg,
45 .fb_blank = leo_blank,
46 .fb_pan_display = leo_pan_display,
47 .fb_fillrect = cfb_fillrect,
48 .fb_copyarea = cfb_copyarea,
49 .fb_imageblit = cfb_imageblit,
50 .fb_mmap = leo_mmap,
51 .fb_ioctl = leo_ioctl,
Christoph Hellwig9ffb83b2005-11-12 12:11:12 -080052#ifdef CONFIG_COMPAT
53 .fb_compat_ioctl = sbusfb_compat_ioctl,
54#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
57#define LEO_OFF_LC_SS0_KRN 0x00200000UL
58#define LEO_OFF_LC_SS0_USR 0x00201000UL
59#define LEO_OFF_LC_SS1_KRN 0x01200000UL
60#define LEO_OFF_LC_SS1_USR 0x01201000UL
61#define LEO_OFF_LD_SS0 0x00400000UL
62#define LEO_OFF_LD_SS1 0x01400000UL
63#define LEO_OFF_LD_GBL 0x00401000UL
64#define LEO_OFF_LX_KRN 0x00600000UL
65#define LEO_OFF_LX_CURSOR 0x00601000UL
66#define LEO_OFF_SS0 0x00800000UL
67#define LEO_OFF_SS1 0x01800000UL
68#define LEO_OFF_UNK 0x00602000UL
69#define LEO_OFF_UNK2 0x00000000UL
70
71#define LEO_CUR_ENABLE 0x00000080
72#define LEO_CUR_UPDATE 0x00000030
73#define LEO_CUR_PROGRESS 0x00000006
74#define LEO_CUR_UPDATECMAP 0x00000003
75
76#define LEO_CUR_TYPE_MASK 0x00000000
77#define LEO_CUR_TYPE_IMAGE 0x00000020
78#define LEO_CUR_TYPE_CMAP 0x00000050
79
80struct leo_cursor {
81 u8 xxx0[16];
David S. Miller50312ce2006-06-29 14:35:52 -070082 u32 cur_type;
83 u32 cur_misc;
84 u32 cur_cursxy;
85 u32 cur_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
88#define LEO_KRN_TYPE_CLUT0 0x00001000
89#define LEO_KRN_TYPE_CLUT1 0x00001001
90#define LEO_KRN_TYPE_CLUT2 0x00001002
91#define LEO_KRN_TYPE_WID 0x00001003
92#define LEO_KRN_TYPE_UNK 0x00001006
93#define LEO_KRN_TYPE_VIDEO 0x00002003
94#define LEO_KRN_TYPE_CLUTDATA 0x00004000
95#define LEO_KRN_CSR_ENABLE 0x00000008
96#define LEO_KRN_CSR_PROGRESS 0x00000004
97#define LEO_KRN_CSR_UNK 0x00000002
98#define LEO_KRN_CSR_UNK2 0x00000001
99
100struct leo_lx_krn {
David S. Miller50312ce2006-06-29 14:35:52 -0700101 u32 krn_type;
102 u32 krn_csr;
103 u32 krn_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106struct leo_lc_ss0_krn {
David S. Miller50312ce2006-06-29 14:35:52 -0700107 u32 misc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 u8 xxx0[0x800-4];
David S. Miller50312ce2006-06-29 14:35:52 -0700109 u32 rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
112struct leo_lc_ss0_usr {
David S. Miller50312ce2006-06-29 14:35:52 -0700113 u32 csr;
114 u32 addrspace;
115 u32 fontmsk;
116 u32 fontt;
117 u32 extent;
118 u32 src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 u32 dst;
David S. Miller50312ce2006-06-29 14:35:52 -0700120 u32 copy;
121 u32 fill;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122};
123
124struct leo_lc_ss1_krn {
125 u8 unknown;
126};
127
128struct leo_lc_ss1_usr {
129 u8 unknown;
130};
131
132struct leo_ld {
133 u8 xxx0[0xe00];
David S. Miller50312ce2006-06-29 14:35:52 -0700134 u32 csr;
135 u32 wid;
136 u32 wmask;
137 u32 widclip;
138 u32 vclipmin;
139 u32 vclipmax;
140 u32 pickmin; /* SS1 only */
141 u32 pickmax; /* SS1 only */
142 u32 fg;
143 u32 bg;
144 u32 src; /* Copy/Scroll (SS0 only) */
145 u32 dst; /* Copy/Scroll/Fill (SS0 only) */
146 u32 extent; /* Copy/Scroll/Fill size (SS0 only) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 u32 xxx1[3];
David S. Miller50312ce2006-06-29 14:35:52 -0700148 u32 setsem; /* SS1 only */
149 u32 clrsem; /* SS1 only */
150 u32 clrpick; /* SS1 only */
151 u32 clrdat; /* SS1 only */
152 u32 alpha; /* SS1 only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 u8 xxx2[0x2c];
David S. Miller50312ce2006-06-29 14:35:52 -0700154 u32 winbg;
155 u32 planemask;
156 u32 rop;
157 u32 z;
158 u32 dczf; /* SS1 only */
159 u32 dczb; /* SS1 only */
160 u32 dcs; /* SS1 only */
161 u32 dczs; /* SS1 only */
162 u32 pickfb; /* SS1 only */
163 u32 pickbb; /* SS1 only */
164 u32 dcfc; /* SS1 only */
165 u32 forcecol; /* SS1 only */
166 u32 door[8]; /* SS1 only */
167 u32 pick[5]; /* SS1 only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168};
169
170#define LEO_SS1_MISC_ENABLE 0x00000001
171#define LEO_SS1_MISC_STEREO 0x00000002
172struct leo_ld_ss1 {
David S. Miller50312ce2006-06-29 14:35:52 -0700173 u8 xxx0[0xef4];
174 u32 ss1_misc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176
177struct leo_ld_gbl {
178 u8 unknown;
179};
180
181struct leo_par {
182 spinlock_t lock;
183 struct leo_lx_krn __iomem *lx_krn;
184 struct leo_lc_ss0_usr __iomem *lc_ss0_usr;
185 struct leo_ld_ss0 __iomem *ld_ss0;
186 struct leo_ld_ss1 __iomem *ld_ss1;
187 struct leo_cursor __iomem *cursor;
188 u32 extent;
189 u32 clut_data[256];
190
191 u32 flags;
192#define LEO_FLAG_BLANKED 0x00000001
193
194 unsigned long physbase;
David S. Miller50312ce2006-06-29 14:35:52 -0700195 unsigned long which_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 unsigned long fbsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
199static void leo_wait(struct leo_lx_krn __iomem *lx_krn)
200{
201 int i;
202
203 for (i = 0;
204 (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000;
205 i++)
206 udelay (1); /* Busy wait at most 0.3 sec */
207 return;
208}
209
210/**
211 * leo_setcolreg - Optional function. Sets a color register.
212 * @regno: boolean, 0 copy local, 1 get_user() function
213 * @red: frame buffer colormap structure
214 * @green: The green value which can be up to 16 bits wide
215 * @blue: The blue value which can be up to 16 bits wide.
216 * @transp: If supported the alpha value which can be up to 16 bits wide.
217 * @info: frame buffer info structure
218 */
219static int leo_setcolreg(unsigned regno,
220 unsigned red, unsigned green, unsigned blue,
221 unsigned transp, struct fb_info *info)
222{
223 struct leo_par *par = (struct leo_par *) info->par;
224 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
225 unsigned long flags;
226 u32 val;
227 int i;
228
229 if (regno >= 256)
230 return 1;
231
232 red >>= 8;
233 green >>= 8;
234 blue >>= 8;
235
236 par->clut_data[regno] = red | (green << 8) | (blue << 16);
237
238 spin_lock_irqsave(&par->lock, flags);
239
240 leo_wait(lx_krn);
241
242 sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type);
243 for (i = 0; i < 256; i++)
244 sbus_writel(par->clut_data[i], &lx_krn->krn_value);
245 sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type);
246
247 val = sbus_readl(&lx_krn->krn_csr);
248 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
249 sbus_writel(val, &lx_krn->krn_csr);
250
251 spin_unlock_irqrestore(&par->lock, flags);
252
253 return 0;
254}
255
256/**
257 * leo_blank - Optional function. Blanks the display.
258 * @blank_mode: the blank mode we want.
259 * @info: frame buffer structure that represents a single frame buffer
260 */
261static int leo_blank(int blank, struct fb_info *info)
262{
263 struct leo_par *par = (struct leo_par *) info->par;
264 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
265 unsigned long flags;
266 u32 val;
267
268 spin_lock_irqsave(&par->lock, flags);
269
270 switch (blank) {
271 case FB_BLANK_UNBLANK: /* Unblanking */
272 val = sbus_readl(&lx_krn->krn_csr);
273 val |= LEO_KRN_CSR_ENABLE;
274 sbus_writel(val, &lx_krn->krn_csr);
275 par->flags &= ~LEO_FLAG_BLANKED;
276 break;
277
278 case FB_BLANK_NORMAL: /* Normal blanking */
279 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
280 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
281 case FB_BLANK_POWERDOWN: /* Poweroff */
282 val = sbus_readl(&lx_krn->krn_csr);
283 val &= ~LEO_KRN_CSR_ENABLE;
284 sbus_writel(val, &lx_krn->krn_csr);
285 par->flags |= LEO_FLAG_BLANKED;
286 break;
287 }
288
289 spin_unlock_irqrestore(&par->lock, flags);
290
291 return 0;
292}
293
294static struct sbus_mmap_map leo_mmap_map[] = {
295 {
296 .voff = LEO_SS0_MAP,
297 .poff = LEO_OFF_SS0,
298 .size = 0x800000
299 },
300 {
301 .voff = LEO_LC_SS0_USR_MAP,
302 .poff = LEO_OFF_LC_SS0_USR,
303 .size = 0x1000
304 },
305 {
306 .voff = LEO_LD_SS0_MAP,
307 .poff = LEO_OFF_LD_SS0,
308 .size = 0x1000
309 },
310 {
311 .voff = LEO_LX_CURSOR_MAP,
312 .poff = LEO_OFF_LX_CURSOR,
313 .size = 0x1000
314 },
315 {
316 .voff = LEO_SS1_MAP,
317 .poff = LEO_OFF_SS1,
318 .size = 0x800000
319 },
320 {
321 .voff = LEO_LC_SS1_USR_MAP,
322 .poff = LEO_OFF_LC_SS1_USR,
323 .size = 0x1000
324 },
325 {
326 .voff = LEO_LD_SS1_MAP,
327 .poff = LEO_OFF_LD_SS1,
328 .size = 0x1000
329 },
330 {
331 .voff = LEO_UNK_MAP,
332 .poff = LEO_OFF_UNK,
333 .size = 0x1000
334 },
335 {
336 .voff = LEO_LX_KRN_MAP,
337 .poff = LEO_OFF_LX_KRN,
338 .size = 0x1000
339 },
340 {
341 .voff = LEO_LC_SS0_KRN_MAP,
342 .poff = LEO_OFF_LC_SS0_KRN,
343 .size = 0x1000
344 },
345 {
346 .voff = LEO_LC_SS1_KRN_MAP,
347 .poff = LEO_OFF_LC_SS1_KRN,
348 .size = 0x1000
349 },
350 {
351 .voff = LEO_LD_GBL_MAP,
352 .poff = LEO_OFF_LD_GBL,
353 .size = 0x1000
354 },
355 {
356 .voff = LEO_UNK2_MAP,
357 .poff = LEO_OFF_UNK2,
358 .size = 0x100000
359 },
360 { .size = 0 }
361};
362
Christoph Hellwig216d5262006-01-14 13:21:25 -0800363static int leo_mmap(struct fb_info *info, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 struct leo_par *par = (struct leo_par *)info->par;
366
367 return sbusfb_mmap_helper(leo_mmap_map,
368 par->physbase, par->fbsize,
David S. Miller50312ce2006-06-29 14:35:52 -0700369 par->which_io, vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
Christoph Hellwig67a66802006-01-14 13:21:25 -0800372static int leo_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 struct leo_par *par = (struct leo_par *) info->par;
375
376 return sbusfb_ioctl_helper(cmd, arg, info,
377 FBTYPE_SUNLEO, 32, par->fbsize);
378}
379
380/*
381 * Initialisation
382 */
383
384static void
David S. Miller50312ce2006-06-29 14:35:52 -0700385leo_init_fix(struct fb_info *info, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
David S. Miller50312ce2006-06-29 14:35:52 -0700387 strlcpy(info->fix.id, dp->name, sizeof(info->fix.id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 info->fix.type = FB_TYPE_PACKED_PIXELS;
390 info->fix.visual = FB_VISUAL_TRUECOLOR;
391
392 info->fix.line_length = 8192;
393
394 info->fix.accel = FB_ACCEL_SUN_LEO;
395}
396
397static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl)
398{
399 struct leo_par *par = (struct leo_par *) info->par;
400 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
401 struct fb_wid_item *wi;
402 unsigned long flags;
403 u32 val;
404 int i, j;
405
406 spin_lock_irqsave(&par->lock, flags);
407
408 leo_wait(lx_krn);
409
410 for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
411 switch(wi->wi_type) {
412 case FB_WID_DBL_8:
413 j = (wi->wi_index & 0xf) + 0x40;
414 break;
415
416 case FB_WID_DBL_24:
417 j = wi->wi_index & 0x3f;
418 break;
419
420 default:
421 continue;
422 };
423 sbus_writel(0x5800 + j, &lx_krn->krn_type);
424 sbus_writel(wi->wi_values[0], &lx_krn->krn_value);
425 }
426 sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type);
427
428 val = sbus_readl(&lx_krn->krn_csr);
429 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
430 sbus_writel(val, &lx_krn->krn_csr);
431
432 spin_unlock_irqrestore(&par->lock, flags);
433}
434
435static void leo_init_wids(struct fb_info *info)
436{
437 struct fb_wid_item wi;
438 struct fb_wid_list wl;
439
440 wl.wl_count = 1;
441 wl.wl_list = &wi;
442 wi.wi_type = FB_WID_DBL_8;
443 wi.wi_index = 0;
444 wi.wi_values [0] = 0x2c0;
445 leo_wid_put(info, &wl);
446 wi.wi_index = 1;
447 wi.wi_values [0] = 0x30;
448 leo_wid_put(info, &wl);
449 wi.wi_index = 2;
450 wi.wi_values [0] = 0x20;
451 leo_wid_put(info, &wl);
452 wi.wi_type = FB_WID_DBL_24;
453 wi.wi_index = 1;
454 wi.wi_values [0] = 0x30;
455 leo_wid_put(info, &wl);
456
457}
458
459static void leo_switch_from_graph(struct fb_info *info)
460{
461 struct leo_par *par = (struct leo_par *) info->par;
462 struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0;
463 unsigned long flags;
464 u32 val;
465
466 spin_lock_irqsave(&par->lock, flags);
467
468 par->extent = ((info->var.xres - 1) |
469 ((info->var.yres - 1) << 16));
470
471 sbus_writel(0xffffffff, &ss->wid);
472 sbus_writel(0xffff, &ss->wmask);
473 sbus_writel(0, &ss->vclipmin);
474 sbus_writel(par->extent, &ss->vclipmax);
475 sbus_writel(0, &ss->fg);
476 sbus_writel(0xff000000, &ss->planemask);
477 sbus_writel(0x310850, &ss->rop);
478 sbus_writel(0, &ss->widclip);
479 sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11),
480 &par->lc_ss0_usr->extent);
481 sbus_writel(4, &par->lc_ss0_usr->addrspace);
482 sbus_writel(0x80000000, &par->lc_ss0_usr->fill);
483 sbus_writel(0, &par->lc_ss0_usr->fontt);
484 do {
485 val = sbus_readl(&par->lc_ss0_usr->csr);
486 } while (val & 0x20000000);
487
488 spin_unlock_irqrestore(&par->lock, flags);
489}
490
491static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
492{
493 /* We just use this to catch switches out of
494 * graphics mode.
495 */
496 leo_switch_from_graph(info);
497
498 if (var->xoffset || var->yoffset || var->vmode)
499 return -EINVAL;
500 return 0;
501}
502
503static void leo_init_hw(struct fb_info *info)
504{
505 struct leo_par *par = (struct leo_par *) info->par;
506 u32 val;
507
508 val = sbus_readl(&par->ld_ss1->ss1_misc);
509 val |= LEO_SS1_MISC_ENABLE;
510 sbus_writel(val, &par->ld_ss1->ss1_misc);
511
512 leo_switch_from_graph(info);
513}
514
515static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
516{
517 var->red.offset = 0;
518 var->red.length = 8;
519 var->green.offset = 8;
520 var->green.length = 8;
521 var->blue.offset = 16;
522 var->blue.length = 8;
523 var->transp.offset = 0;
524 var->transp.length = 0;
525}
526
David S. Millerc7f439b2007-07-27 22:31:46 -0700527static void leo_unmap_regs(struct of_device *op, struct fb_info *info,
528 struct leo_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
David S. Millerc7f439b2007-07-27 22:31:46 -0700530 if (par->lc_ss0_usr)
531 of_iounmap(&op->resource[0], par->lc_ss0_usr, 0x1000);
532 if (par->ld_ss0)
533 of_iounmap(&op->resource[0], par->ld_ss0, 0x1000);
534 if (par->ld_ss1)
535 of_iounmap(&op->resource[0], par->ld_ss1, 0x1000);
536 if (par->lx_krn)
537 of_iounmap(&op->resource[0], par->lx_krn, 0x1000);
538 if (par->cursor)
David S. Millere3a411a32006-12-28 21:01:32 -0800539 of_iounmap(&op->resource[0],
David S. Millerc7f439b2007-07-27 22:31:46 -0700540 par->cursor, sizeof(struct leo_cursor));
541 if (info->screen_base)
542 of_iounmap(&op->resource[0], info->screen_base, 0x800000);
David S. Miller50312ce2006-06-29 14:35:52 -0700543}
544
David S. Millerc7f439b2007-07-27 22:31:46 -0700545static int __devinit leo_probe(struct of_device *op, const struct of_device_id *match)
David S. Miller50312ce2006-06-29 14:35:52 -0700546{
547 struct device_node *dp = op->node;
David S. Millerc7f439b2007-07-27 22:31:46 -0700548 struct fb_info *info;
549 struct leo_par *par;
David S. Miller50312ce2006-06-29 14:35:52 -0700550 int linebytes, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
David S. Millerc7f439b2007-07-27 22:31:46 -0700552 info = framebuffer_alloc(sizeof(struct leo_par), &op->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
David S. Millerc7f439b2007-07-27 22:31:46 -0700554 err = -ENOMEM;
555 if (!info)
556 goto out_err;
557 par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
David S. Millerc7f439b2007-07-27 22:31:46 -0700559 spin_lock_init(&par->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
David S. Millerc7f439b2007-07-27 22:31:46 -0700561 par->physbase = op->resource[0].start;
562 par->which_io = op->resource[0].flags & IORESOURCE_BITS;
563
Robert Reif6cd5a862008-05-08 21:37:30 -0700564 sbusfb_fill_var(&info->var, dp, 32);
David S. Millerc7f439b2007-07-27 22:31:46 -0700565 leo_fixup_var_rgb(&info->var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
David S. Miller50312ce2006-06-29 14:35:52 -0700567 linebytes = of_getintprop_default(dp, "linebytes",
David S. Millerc7f439b2007-07-27 22:31:46 -0700568 info->var.xres);
569 par->fbsize = PAGE_ALIGN(linebytes * info->var.yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
David S. Millerc7f439b2007-07-27 22:31:46 -0700571 par->lc_ss0_usr =
David S. Miller50312ce2006-06-29 14:35:52 -0700572 of_ioremap(&op->resource[0], LEO_OFF_LC_SS0_USR,
573 0x1000, "leolc ss0usr");
David S. Millerc7f439b2007-07-27 22:31:46 -0700574 par->ld_ss0 =
David S. Miller50312ce2006-06-29 14:35:52 -0700575 of_ioremap(&op->resource[0], LEO_OFF_LD_SS0,
576 0x1000, "leold ss0");
David S. Millerc7f439b2007-07-27 22:31:46 -0700577 par->ld_ss1 =
David S. Miller50312ce2006-06-29 14:35:52 -0700578 of_ioremap(&op->resource[0], LEO_OFF_LD_SS1,
579 0x1000, "leold ss1");
David S. Millerc7f439b2007-07-27 22:31:46 -0700580 par->lx_krn =
David S. Miller50312ce2006-06-29 14:35:52 -0700581 of_ioremap(&op->resource[0], LEO_OFF_LX_KRN,
582 0x1000, "leolx krn");
David S. Millerc7f439b2007-07-27 22:31:46 -0700583 par->cursor =
David S. Miller50312ce2006-06-29 14:35:52 -0700584 of_ioremap(&op->resource[0], LEO_OFF_LX_CURSOR,
585 sizeof(struct leo_cursor), "leolx cursor");
David S. Millerc7f439b2007-07-27 22:31:46 -0700586 info->screen_base =
David S. Miller50312ce2006-06-29 14:35:52 -0700587 of_ioremap(&op->resource[0], LEO_OFF_SS0,
588 0x800000, "leo ram");
David S. Millerc7f439b2007-07-27 22:31:46 -0700589 if (!par->lc_ss0_usr ||
590 !par->ld_ss0 ||
591 !par->ld_ss1 ||
592 !par->lx_krn ||
593 !par->cursor ||
594 !info->screen_base)
595 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
David S. Millerc7f439b2007-07-27 22:31:46 -0700597 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
598 info->fbops = &leo_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
David S. Millerc7f439b2007-07-27 22:31:46 -0700600 leo_init_wids(info);
601 leo_init_hw(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Robert Reif59f71372008-05-03 21:12:00 -0700603 leo_blank(FB_BLANK_UNBLANK, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
David S. Millerc7f439b2007-07-27 22:31:46 -0700605 if (fb_alloc_cmap(&info->cmap, 256, 0))
606 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
David S. Millerc7f439b2007-07-27 22:31:46 -0700608 leo_init_fix(info, dp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
David S. Millerc7f439b2007-07-27 22:31:46 -0700610 err = register_framebuffer(info);
611 if (err < 0)
612 goto out_dealloc_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
David S. Millerc7f439b2007-07-27 22:31:46 -0700614 dev_set_drvdata(&op->dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Robert Reif194f1a682008-04-27 15:18:57 -0700616 printk(KERN_INFO "%s: leo at %lx:%lx\n",
David S. Miller50312ce2006-06-29 14:35:52 -0700617 dp->full_name,
David S. Millerc7f439b2007-07-27 22:31:46 -0700618 par->which_io, par->physbase);
David S. Miller50312ce2006-06-29 14:35:52 -0700619
620 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
David S. Millerc7f439b2007-07-27 22:31:46 -0700622out_dealloc_cmap:
623 fb_dealloc_cmap(&info->cmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
David S. Millerc7f439b2007-07-27 22:31:46 -0700625out_unmap_regs:
626 leo_unmap_regs(op, info, par);
627 framebuffer_release(info);
628
629out_err:
630 return err;
David S. Miller50312ce2006-06-29 14:35:52 -0700631}
632
David S. Millere3a411a32006-12-28 21:01:32 -0800633static int __devexit leo_remove(struct of_device *op)
David S. Miller50312ce2006-06-29 14:35:52 -0700634{
David S. Millerc7f439b2007-07-27 22:31:46 -0700635 struct fb_info *info = dev_get_drvdata(&op->dev);
636 struct leo_par *par = info->par;
David S. Miller50312ce2006-06-29 14:35:52 -0700637
David S. Millerc7f439b2007-07-27 22:31:46 -0700638 unregister_framebuffer(info);
639 fb_dealloc_cmap(&info->cmap);
David S. Miller50312ce2006-06-29 14:35:52 -0700640
David S. Millerc7f439b2007-07-27 22:31:46 -0700641 leo_unmap_regs(op, info, par);
David S. Miller50312ce2006-06-29 14:35:52 -0700642
David S. Millerc7f439b2007-07-27 22:31:46 -0700643 framebuffer_release(info);
David S. Miller50312ce2006-06-29 14:35:52 -0700644
David S. Millere3a411a32006-12-28 21:01:32 -0800645 dev_set_drvdata(&op->dev, NULL);
David S. Miller50312ce2006-06-29 14:35:52 -0700646
647 return 0;
648}
649
650static struct of_device_id leo_match[] = {
651 {
652 .name = "leo",
653 },
654 {},
655};
656MODULE_DEVICE_TABLE(of, leo_match);
657
658static struct of_platform_driver leo_driver = {
659 .name = "leo",
660 .match_table = leo_match,
661 .probe = leo_probe,
662 .remove = __devexit_p(leo_remove),
663};
664
665static int __init leo_init(void)
666{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (fb_get_options("leofb", NULL))
668 return -ENODEV;
669
David S. Miller50312ce2006-06-29 14:35:52 -0700670 return of_register_driver(&leo_driver, &of_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
David S. Miller50312ce2006-06-29 14:35:52 -0700673static void __exit leo_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
David S. Miller50312ce2006-06-29 14:35:52 -0700675 of_unregister_driver(&leo_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678module_init(leo_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679module_exit(leo_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
David S. Miller50312ce2006-06-29 14:35:52 -0700682MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
683MODULE_VERSION("2.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684MODULE_LICENSE("GPL");