blob: 7c7e8c2da9d911081f68d3b94d46f2effd69e496 [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>
Robert Reif738eca72008-06-10 14:13:09 -070020#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
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);
Robert Reif4dd95b62008-10-10 12:13:22 -070036static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
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,
Robert Reif4dd95b62008-10-10 12:13:22 -070046 .fb_pan_display = leo_pan_display,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .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 {
Robert Reif738eca72008-06-10 14:13:09 -070081 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;
Robert Reif738eca72008-06-10 14:13:09 -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;
Robert Reif738eca72008-06-10 14:13:09 -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
Robert Reif738eca72008-06-10 14:13:09 -0700132struct leo_ld_ss0 {
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) */
Robert Reif738eca72008-06-10 14:13:09 -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 */
Robert Reif738eca72008-06-10 14:13:09 -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;
Robert Reif738eca72008-06-10 14:13:09 -0700202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 for (i = 0;
Robert Reif738eca72008-06-10 14:13:09 -0700204 (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) &&
205 i < 300000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 i++)
Robert Reif738eca72008-06-10 14:13:09 -0700207 udelay(1); /* Busy wait at most 0.3 sec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return;
209}
210
Robert Reif4dd95b62008-10-10 12:13:22 -0700211static void leo_switch_from_graph(struct fb_info *info)
212{
213 struct leo_par *par = (struct leo_par *) info->par;
214 struct leo_ld_ss0 __iomem *ss = par->ld_ss0;
215 struct leo_cursor __iomem *cursor = par->cursor;
216 unsigned long flags;
217 u32 val;
218
219 spin_lock_irqsave(&par->lock, flags);
220
221 par->extent = ((info->var.xres - 1) |
222 ((info->var.yres - 1) << 16));
223
224 sbus_writel(0xffffffff, &ss->wid);
225 sbus_writel(0xffff, &ss->wmask);
226 sbus_writel(0, &ss->vclipmin);
227 sbus_writel(par->extent, &ss->vclipmax);
228 sbus_writel(0, &ss->fg);
229 sbus_writel(0xff000000, &ss->planemask);
230 sbus_writel(0x310850, &ss->rop);
231 sbus_writel(0, &ss->widclip);
232 sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11),
233 &par->lc_ss0_usr->extent);
234 sbus_writel(4, &par->lc_ss0_usr->addrspace);
235 sbus_writel(0x80000000, &par->lc_ss0_usr->fill);
236 sbus_writel(0, &par->lc_ss0_usr->fontt);
237 do {
238 val = sbus_readl(&par->lc_ss0_usr->csr);
239 } while (val & 0x20000000);
240
241 /* setup screen buffer for cfb_* functions */
242 sbus_writel(1, &ss->wid);
243 sbus_writel(0x00ffffff, &ss->planemask);
244 sbus_writel(0x310b90, &ss->rop);
245 sbus_writel(0, &par->lc_ss0_usr->addrspace);
246
247 /* hide cursor */
248 sbus_writel(sbus_readl(&cursor->cur_misc) & ~LEO_CUR_ENABLE, &cursor->cur_misc);
249
250 spin_unlock_irqrestore(&par->lock, flags);
251}
252
253static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
254{
255 /* We just use this to catch switches out of
256 * graphics mode.
257 */
258 leo_switch_from_graph(info);
259
260 if (var->xoffset || var->yoffset || var->vmode)
261 return -EINVAL;
262 return 0;
263}
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/**
266 * leo_setcolreg - Optional function. Sets a color register.
267 * @regno: boolean, 0 copy local, 1 get_user() function
268 * @red: frame buffer colormap structure
269 * @green: The green value which can be up to 16 bits wide
270 * @blue: The blue value which can be up to 16 bits wide.
271 * @transp: If supported the alpha value which can be up to 16 bits wide.
272 * @info: frame buffer info structure
273 */
274static int leo_setcolreg(unsigned regno,
275 unsigned red, unsigned green, unsigned blue,
276 unsigned transp, struct fb_info *info)
277{
278 struct leo_par *par = (struct leo_par *) info->par;
Robert Reif738eca72008-06-10 14:13:09 -0700279 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 unsigned long flags;
281 u32 val;
282 int i;
283
284 if (regno >= 256)
285 return 1;
286
287 red >>= 8;
288 green >>= 8;
289 blue >>= 8;
290
291 par->clut_data[regno] = red | (green << 8) | (blue << 16);
292
293 spin_lock_irqsave(&par->lock, flags);
294
295 leo_wait(lx_krn);
296
297 sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type);
298 for (i = 0; i < 256; i++)
299 sbus_writel(par->clut_data[i], &lx_krn->krn_value);
300 sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type);
301
302 val = sbus_readl(&lx_krn->krn_csr);
303 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
304 sbus_writel(val, &lx_krn->krn_csr);
305
306 spin_unlock_irqrestore(&par->lock, flags);
307
308 return 0;
309}
310
311/**
312 * leo_blank - Optional function. Blanks the display.
313 * @blank_mode: the blank mode we want.
314 * @info: frame buffer structure that represents a single frame buffer
315 */
316static int leo_blank(int blank, struct fb_info *info)
317{
318 struct leo_par *par = (struct leo_par *) info->par;
319 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
320 unsigned long flags;
321 u32 val;
322
323 spin_lock_irqsave(&par->lock, flags);
324
325 switch (blank) {
326 case FB_BLANK_UNBLANK: /* Unblanking */
327 val = sbus_readl(&lx_krn->krn_csr);
328 val |= LEO_KRN_CSR_ENABLE;
329 sbus_writel(val, &lx_krn->krn_csr);
330 par->flags &= ~LEO_FLAG_BLANKED;
331 break;
332
333 case FB_BLANK_NORMAL: /* Normal blanking */
334 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
335 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
336 case FB_BLANK_POWERDOWN: /* Poweroff */
337 val = sbus_readl(&lx_krn->krn_csr);
338 val &= ~LEO_KRN_CSR_ENABLE;
339 sbus_writel(val, &lx_krn->krn_csr);
340 par->flags |= LEO_FLAG_BLANKED;
341 break;
342 }
343
344 spin_unlock_irqrestore(&par->lock, flags);
345
346 return 0;
347}
348
349static struct sbus_mmap_map leo_mmap_map[] = {
350 {
351 .voff = LEO_SS0_MAP,
352 .poff = LEO_OFF_SS0,
353 .size = 0x800000
354 },
355 {
356 .voff = LEO_LC_SS0_USR_MAP,
357 .poff = LEO_OFF_LC_SS0_USR,
358 .size = 0x1000
359 },
360 {
361 .voff = LEO_LD_SS0_MAP,
362 .poff = LEO_OFF_LD_SS0,
363 .size = 0x1000
364 },
365 {
366 .voff = LEO_LX_CURSOR_MAP,
367 .poff = LEO_OFF_LX_CURSOR,
368 .size = 0x1000
369 },
370 {
371 .voff = LEO_SS1_MAP,
372 .poff = LEO_OFF_SS1,
373 .size = 0x800000
374 },
375 {
376 .voff = LEO_LC_SS1_USR_MAP,
377 .poff = LEO_OFF_LC_SS1_USR,
378 .size = 0x1000
379 },
380 {
381 .voff = LEO_LD_SS1_MAP,
382 .poff = LEO_OFF_LD_SS1,
383 .size = 0x1000
384 },
385 {
386 .voff = LEO_UNK_MAP,
387 .poff = LEO_OFF_UNK,
388 .size = 0x1000
389 },
390 {
391 .voff = LEO_LX_KRN_MAP,
392 .poff = LEO_OFF_LX_KRN,
393 .size = 0x1000
394 },
395 {
396 .voff = LEO_LC_SS0_KRN_MAP,
397 .poff = LEO_OFF_LC_SS0_KRN,
398 .size = 0x1000
399 },
400 {
401 .voff = LEO_LC_SS1_KRN_MAP,
402 .poff = LEO_OFF_LC_SS1_KRN,
403 .size = 0x1000
404 },
405 {
406 .voff = LEO_LD_GBL_MAP,
407 .poff = LEO_OFF_LD_GBL,
408 .size = 0x1000
409 },
410 {
411 .voff = LEO_UNK2_MAP,
412 .poff = LEO_OFF_UNK2,
413 .size = 0x100000
414 },
415 { .size = 0 }
416};
417
Christoph Hellwig216d5262006-01-14 13:21:25 -0800418static int leo_mmap(struct fb_info *info, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 struct leo_par *par = (struct leo_par *)info->par;
421
422 return sbusfb_mmap_helper(leo_mmap_map,
423 par->physbase, par->fbsize,
David S. Miller50312ce2006-06-29 14:35:52 -0700424 par->which_io, vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
Christoph Hellwig67a66802006-01-14 13:21:25 -0800427static int leo_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
429 struct leo_par *par = (struct leo_par *) info->par;
430
431 return sbusfb_ioctl_helper(cmd, arg, info,
432 FBTYPE_SUNLEO, 32, par->fbsize);
433}
434
435/*
436 * Initialisation
437 */
438
439static void
David S. Miller50312ce2006-06-29 14:35:52 -0700440leo_init_fix(struct fb_info *info, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
David S. Miller50312ce2006-06-29 14:35:52 -0700442 strlcpy(info->fix.id, dp->name, sizeof(info->fix.id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 info->fix.type = FB_TYPE_PACKED_PIXELS;
445 info->fix.visual = FB_VISUAL_TRUECOLOR;
446
447 info->fix.line_length = 8192;
448
449 info->fix.accel = FB_ACCEL_SUN_LEO;
450}
451
452static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl)
453{
454 struct leo_par *par = (struct leo_par *) info->par;
455 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
456 struct fb_wid_item *wi;
457 unsigned long flags;
458 u32 val;
459 int i, j;
460
461 spin_lock_irqsave(&par->lock, flags);
462
463 leo_wait(lx_krn);
464
465 for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
Robert Reif738eca72008-06-10 14:13:09 -0700466 switch (wi->wi_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 case FB_WID_DBL_8:
468 j = (wi->wi_index & 0xf) + 0x40;
469 break;
470
471 case FB_WID_DBL_24:
472 j = wi->wi_index & 0x3f;
473 break;
474
475 default:
476 continue;
477 };
478 sbus_writel(0x5800 + j, &lx_krn->krn_type);
479 sbus_writel(wi->wi_values[0], &lx_krn->krn_value);
480 }
481 sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type);
482
483 val = sbus_readl(&lx_krn->krn_csr);
484 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
485 sbus_writel(val, &lx_krn->krn_csr);
486
487 spin_unlock_irqrestore(&par->lock, flags);
488}
489
490static void leo_init_wids(struct fb_info *info)
491{
492 struct fb_wid_item wi;
493 struct fb_wid_list wl;
494
495 wl.wl_count = 1;
496 wl.wl_list = &wi;
497 wi.wi_type = FB_WID_DBL_8;
498 wi.wi_index = 0;
499 wi.wi_values [0] = 0x2c0;
500 leo_wid_put(info, &wl);
501 wi.wi_index = 1;
502 wi.wi_values [0] = 0x30;
503 leo_wid_put(info, &wl);
504 wi.wi_index = 2;
505 wi.wi_values [0] = 0x20;
506 leo_wid_put(info, &wl);
507 wi.wi_type = FB_WID_DBL_24;
508 wi.wi_index = 1;
509 wi.wi_values [0] = 0x30;
510 leo_wid_put(info, &wl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513static void leo_init_hw(struct fb_info *info)
514{
515 struct leo_par *par = (struct leo_par *) info->par;
516 u32 val;
517
518 val = sbus_readl(&par->ld_ss1->ss1_misc);
519 val |= LEO_SS1_MISC_ENABLE;
520 sbus_writel(val, &par->ld_ss1->ss1_misc);
521
522 leo_switch_from_graph(info);
523}
524
525static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
526{
527 var->red.offset = 0;
528 var->red.length = 8;
529 var->green.offset = 8;
530 var->green.length = 8;
531 var->blue.offset = 16;
532 var->blue.length = 8;
533 var->transp.offset = 0;
534 var->transp.length = 0;
535}
536
David S. Millerc7f439b2007-07-27 22:31:46 -0700537static void leo_unmap_regs(struct of_device *op, struct fb_info *info,
538 struct leo_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
David S. Millerc7f439b2007-07-27 22:31:46 -0700540 if (par->lc_ss0_usr)
541 of_iounmap(&op->resource[0], par->lc_ss0_usr, 0x1000);
542 if (par->ld_ss0)
543 of_iounmap(&op->resource[0], par->ld_ss0, 0x1000);
544 if (par->ld_ss1)
545 of_iounmap(&op->resource[0], par->ld_ss1, 0x1000);
546 if (par->lx_krn)
547 of_iounmap(&op->resource[0], par->lx_krn, 0x1000);
548 if (par->cursor)
David S. Millere3a411a32006-12-28 21:01:32 -0800549 of_iounmap(&op->resource[0],
David S. Millerc7f439b2007-07-27 22:31:46 -0700550 par->cursor, sizeof(struct leo_cursor));
551 if (info->screen_base)
552 of_iounmap(&op->resource[0], info->screen_base, 0x800000);
David S. Miller50312ce2006-06-29 14:35:52 -0700553}
554
Robert Reif738eca72008-06-10 14:13:09 -0700555static int __devinit leo_probe(struct of_device *op,
556 const struct of_device_id *match)
David S. Miller50312ce2006-06-29 14:35:52 -0700557{
558 struct device_node *dp = op->node;
David S. Millerc7f439b2007-07-27 22:31:46 -0700559 struct fb_info *info;
560 struct leo_par *par;
David S. Miller50312ce2006-06-29 14:35:52 -0700561 int linebytes, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
David S. Millerc7f439b2007-07-27 22:31:46 -0700563 info = framebuffer_alloc(sizeof(struct leo_par), &op->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
David S. Millerc7f439b2007-07-27 22:31:46 -0700565 err = -ENOMEM;
566 if (!info)
567 goto out_err;
568 par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
David S. Millerc7f439b2007-07-27 22:31:46 -0700570 spin_lock_init(&par->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
David S. Millerc7f439b2007-07-27 22:31:46 -0700572 par->physbase = op->resource[0].start;
573 par->which_io = op->resource[0].flags & IORESOURCE_BITS;
574
Robert Reif6cd5a862008-05-08 21:37:30 -0700575 sbusfb_fill_var(&info->var, dp, 32);
David S. Millerc7f439b2007-07-27 22:31:46 -0700576 leo_fixup_var_rgb(&info->var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
David S. Miller50312ce2006-06-29 14:35:52 -0700578 linebytes = of_getintprop_default(dp, "linebytes",
David S. Millerc7f439b2007-07-27 22:31:46 -0700579 info->var.xres);
580 par->fbsize = PAGE_ALIGN(linebytes * info->var.yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
David S. Millerc7f439b2007-07-27 22:31:46 -0700582 par->lc_ss0_usr =
David S. Miller50312ce2006-06-29 14:35:52 -0700583 of_ioremap(&op->resource[0], LEO_OFF_LC_SS0_USR,
584 0x1000, "leolc ss0usr");
David S. Millerc7f439b2007-07-27 22:31:46 -0700585 par->ld_ss0 =
David S. Miller50312ce2006-06-29 14:35:52 -0700586 of_ioremap(&op->resource[0], LEO_OFF_LD_SS0,
587 0x1000, "leold ss0");
David S. Millerc7f439b2007-07-27 22:31:46 -0700588 par->ld_ss1 =
David S. Miller50312ce2006-06-29 14:35:52 -0700589 of_ioremap(&op->resource[0], LEO_OFF_LD_SS1,
590 0x1000, "leold ss1");
David S. Millerc7f439b2007-07-27 22:31:46 -0700591 par->lx_krn =
David S. Miller50312ce2006-06-29 14:35:52 -0700592 of_ioremap(&op->resource[0], LEO_OFF_LX_KRN,
593 0x1000, "leolx krn");
David S. Millerc7f439b2007-07-27 22:31:46 -0700594 par->cursor =
David S. Miller50312ce2006-06-29 14:35:52 -0700595 of_ioremap(&op->resource[0], LEO_OFF_LX_CURSOR,
596 sizeof(struct leo_cursor), "leolx cursor");
David S. Millerc7f439b2007-07-27 22:31:46 -0700597 info->screen_base =
David S. Miller50312ce2006-06-29 14:35:52 -0700598 of_ioremap(&op->resource[0], LEO_OFF_SS0,
599 0x800000, "leo ram");
David S. Millerc7f439b2007-07-27 22:31:46 -0700600 if (!par->lc_ss0_usr ||
601 !par->ld_ss0 ||
602 !par->ld_ss1 ||
603 !par->lx_krn ||
604 !par->cursor ||
605 !info->screen_base)
606 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Robert Reif738eca72008-06-10 14:13:09 -0700608 info->flags = FBINFO_DEFAULT;
David S. Millerc7f439b2007-07-27 22:31:46 -0700609 info->fbops = &leo_ops;
Robert Reif738eca72008-06-10 14:13:09 -0700610 info->pseudo_palette = par->clut_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
David S. Millerc7f439b2007-07-27 22:31:46 -0700612 leo_init_wids(info);
613 leo_init_hw(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Robert Reif59f71372008-05-03 21:12:00 -0700615 leo_blank(FB_BLANK_UNBLANK, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
David S. Millerc7f439b2007-07-27 22:31:46 -0700617 if (fb_alloc_cmap(&info->cmap, 256, 0))
618 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
David S. Millerc7f439b2007-07-27 22:31:46 -0700620 leo_init_fix(info, dp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
David S. Millerc7f439b2007-07-27 22:31:46 -0700622 err = register_framebuffer(info);
623 if (err < 0)
624 goto out_dealloc_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
David S. Millerc7f439b2007-07-27 22:31:46 -0700626 dev_set_drvdata(&op->dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Robert Reif194f1a682008-04-27 15:18:57 -0700628 printk(KERN_INFO "%s: leo at %lx:%lx\n",
David S. Miller50312ce2006-06-29 14:35:52 -0700629 dp->full_name,
David S. Millerc7f439b2007-07-27 22:31:46 -0700630 par->which_io, par->physbase);
David S. Miller50312ce2006-06-29 14:35:52 -0700631
632 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
David S. Millerc7f439b2007-07-27 22:31:46 -0700634out_dealloc_cmap:
635 fb_dealloc_cmap(&info->cmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
David S. Millerc7f439b2007-07-27 22:31:46 -0700637out_unmap_regs:
638 leo_unmap_regs(op, info, par);
639 framebuffer_release(info);
640
641out_err:
642 return err;
David S. Miller50312ce2006-06-29 14:35:52 -0700643}
644
David S. Millere3a411a32006-12-28 21:01:32 -0800645static int __devexit leo_remove(struct of_device *op)
David S. Miller50312ce2006-06-29 14:35:52 -0700646{
David S. Millerc7f439b2007-07-27 22:31:46 -0700647 struct fb_info *info = dev_get_drvdata(&op->dev);
648 struct leo_par *par = info->par;
David S. Miller50312ce2006-06-29 14:35:52 -0700649
David S. Millerc7f439b2007-07-27 22:31:46 -0700650 unregister_framebuffer(info);
651 fb_dealloc_cmap(&info->cmap);
David S. Miller50312ce2006-06-29 14:35:52 -0700652
David S. Millerc7f439b2007-07-27 22:31:46 -0700653 leo_unmap_regs(op, info, par);
David S. Miller50312ce2006-06-29 14:35:52 -0700654
David S. Millerc7f439b2007-07-27 22:31:46 -0700655 framebuffer_release(info);
David S. Miller50312ce2006-06-29 14:35:52 -0700656
David S. Millere3a411a32006-12-28 21:01:32 -0800657 dev_set_drvdata(&op->dev, NULL);
David S. Miller50312ce2006-06-29 14:35:52 -0700658
659 return 0;
660}
661
David S. Millerfd098312008-08-31 01:23:17 -0700662static const struct of_device_id leo_match[] = {
David S. Miller50312ce2006-06-29 14:35:52 -0700663 {
Robert Reif738eca72008-06-10 14:13:09 -0700664 .name = "SUNW,leo",
David S. Miller50312ce2006-06-29 14:35:52 -0700665 },
666 {},
667};
668MODULE_DEVICE_TABLE(of, leo_match);
669
670static struct of_platform_driver leo_driver = {
671 .name = "leo",
672 .match_table = leo_match,
673 .probe = leo_probe,
674 .remove = __devexit_p(leo_remove),
675};
676
677static int __init leo_init(void)
678{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (fb_get_options("leofb", NULL))
680 return -ENODEV;
681
David S. Miller50312ce2006-06-29 14:35:52 -0700682 return of_register_driver(&leo_driver, &of_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
David S. Miller50312ce2006-06-29 14:35:52 -0700685static void __exit leo_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
David S. Miller50312ce2006-06-29 14:35:52 -0700687 of_unregister_driver(&leo_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690module_init(leo_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691module_exit(leo_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
David S. Miller50312ce2006-06-29 14:35:52 -0700694MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
695MODULE_VERSION("2.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696MODULE_LICENSE("GPL");