blob: fe45a3b8d0e060141e8a7cef3d7702fff15a44fa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* cg14.c: CGFOURTEEN 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,1998 Jakub Jelinek (jj@ultra.linux.cz)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
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 Reif631a9dc2008-02-12 18:23:31 -080019#include <linux/uaccess.h>
Robert Reif6cd5a862008-05-08 21:37:30 -070020#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/fbio.h>
24
25#include "sbuslib.h"
26
27/*
28 * Local functions.
29 */
30
31static int cg14_setcolreg(unsigned, unsigned, unsigned, unsigned,
32 unsigned, struct fb_info *);
33
Christoph Hellwig216d5262006-01-14 13:21:25 -080034static int cg14_mmap(struct fb_info *, struct vm_area_struct *);
Christoph Hellwig67a66802006-01-14 13:21:25 -080035static int cg14_ioctl(struct fb_info *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static int cg14_pan_display(struct fb_var_screeninfo *, struct fb_info *);
37
38/*
39 * Frame buffer operations
40 */
41
42static struct fb_ops cg14_ops = {
43 .owner = THIS_MODULE,
44 .fb_setcolreg = cg14_setcolreg,
45 .fb_pan_display = cg14_pan_display,
46 .fb_fillrect = cfb_fillrect,
47 .fb_copyarea = cfb_copyarea,
48 .fb_imageblit = cfb_imageblit,
49 .fb_mmap = cg14_mmap,
50 .fb_ioctl = cg14_ioctl,
Christoph Hellwig9ffb83b2005-11-12 12:11:12 -080051#ifdef CONFIG_COMPAT
52 .fb_compat_ioctl = sbusfb_compat_ioctl,
53#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
56#define CG14_MCR_INTENABLE_SHIFT 7
57#define CG14_MCR_INTENABLE_MASK 0x80
58#define CG14_MCR_VIDENABLE_SHIFT 6
59#define CG14_MCR_VIDENABLE_MASK 0x40
60#define CG14_MCR_PIXMODE_SHIFT 4
61#define CG14_MCR_PIXMODE_MASK 0x30
62#define CG14_MCR_TMR_SHIFT 2
63#define CG14_MCR_TMR_MASK 0x0c
64#define CG14_MCR_TMENABLE_SHIFT 1
65#define CG14_MCR_TMENABLE_MASK 0x02
66#define CG14_MCR_RESET_SHIFT 0
67#define CG14_MCR_RESET_MASK 0x01
68#define CG14_REV_REVISION_SHIFT 4
69#define CG14_REV_REVISION_MASK 0xf0
70#define CG14_REV_IMPL_SHIFT 0
71#define CG14_REV_IMPL_MASK 0x0f
72#define CG14_VBR_FRAMEBASE_SHIFT 12
73#define CG14_VBR_FRAMEBASE_MASK 0x00fff000
74#define CG14_VMCR1_SETUP_SHIFT 0
75#define CG14_VMCR1_SETUP_MASK 0x000001ff
76#define CG14_VMCR1_VCONFIG_SHIFT 9
77#define CG14_VMCR1_VCONFIG_MASK 0x00000e00
78#define CG14_VMCR2_REFRESH_SHIFT 0
79#define CG14_VMCR2_REFRESH_MASK 0x00000001
80#define CG14_VMCR2_TESTROWCNT_SHIFT 1
81#define CG14_VMCR2_TESTROWCNT_MASK 0x00000002
82#define CG14_VMCR2_FBCONFIG_SHIFT 2
83#define CG14_VMCR2_FBCONFIG_MASK 0x0000000c
84#define CG14_VCR_REFRESHREQ_SHIFT 0
85#define CG14_VCR_REFRESHREQ_MASK 0x000003ff
86#define CG14_VCR1_REFRESHENA_SHIFT 10
87#define CG14_VCR1_REFRESHENA_MASK 0x00000400
88#define CG14_VCA_CAD_SHIFT 0
89#define CG14_VCA_CAD_MASK 0x000003ff
90#define CG14_VCA_VERS_SHIFT 10
91#define CG14_VCA_VERS_MASK 0x00000c00
92#define CG14_VCA_RAMSPEED_SHIFT 12
93#define CG14_VCA_RAMSPEED_MASK 0x00001000
94#define CG14_VCA_8MB_SHIFT 13
95#define CG14_VCA_8MB_MASK 0x00002000
96
97#define CG14_MCR_PIXMODE_8 0
98#define CG14_MCR_PIXMODE_16 2
99#define CG14_MCR_PIXMODE_32 3
100
101struct cg14_regs{
David S. Miller50312ce2006-06-29 14:35:52 -0700102 u8 mcr; /* Master Control Reg */
103 u8 ppr; /* Packed Pixel Reg */
104 u8 tms[2]; /* Test Mode Status Regs */
105 u8 msr; /* Master Status Reg */
106 u8 fsr; /* Fault Status Reg */
107 u8 rev; /* Revision & Impl */
108 u8 ccr; /* Clock Control Reg */
109 u32 tmr; /* Test Mode Read Back */
110 u8 mod; /* Monitor Operation Data Reg */
111 u8 acr; /* Aux Control */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 u8 xxx0[6];
David S. Miller50312ce2006-06-29 14:35:52 -0700113 u16 hct; /* Hor Counter */
114 u16 vct; /* Vert Counter */
115 u16 hbs; /* Hor Blank Start */
116 u16 hbc; /* Hor Blank Clear */
117 u16 hss; /* Hor Sync Start */
118 u16 hsc; /* Hor Sync Clear */
119 u16 csc; /* Composite Sync Clear */
120 u16 vbs; /* Vert Blank Start */
121 u16 vbc; /* Vert Blank Clear */
122 u16 vss; /* Vert Sync Start */
123 u16 vsc; /* Vert Sync Clear */
124 u16 xcs;
125 u16 xcc;
126 u16 fsa; /* Fault Status Address */
127 u16 adr; /* Address Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 u8 xxx1[0xce];
David S. Miller50312ce2006-06-29 14:35:52 -0700129 u8 pcg[0x100]; /* Pixel Clock Generator */
130 u32 vbr; /* Frame Base Row */
131 u32 vmcr; /* VBC Master Control */
132 u32 vcr; /* VBC refresh */
133 u32 vca; /* VBC Config */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134};
135
136#define CG14_CCR_ENABLE 0x04
137#define CG14_CCR_SELECT 0x02 /* HW/Full screen */
138
139struct cg14_cursor {
David S. Miller50312ce2006-06-29 14:35:52 -0700140 u32 cpl0[32]; /* Enable plane 0 */
141 u32 cpl1[32]; /* Color selection plane */
142 u8 ccr; /* Cursor Control Reg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 u8 xxx0[3];
David S. Miller50312ce2006-06-29 14:35:52 -0700144 u16 cursx; /* Cursor x,y position */
145 u16 cursy; /* Cursor x,y position */
146 u32 color0;
147 u32 color1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 u32 xxx1[0x1bc];
David S. Miller50312ce2006-06-29 14:35:52 -0700149 u32 cpl0i[32]; /* Enable plane 0 autoinc */
150 u32 cpl1i[32]; /* Color selection autoinc */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
153struct cg14_dac {
David S. Miller50312ce2006-06-29 14:35:52 -0700154 u8 addr; /* Address Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 u8 xxx0[255];
David S. Miller50312ce2006-06-29 14:35:52 -0700156 u8 glut; /* Gamma table */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 u8 xxx1[255];
David S. Miller50312ce2006-06-29 14:35:52 -0700158 u8 select; /* Register Select */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 u8 xxx2[255];
David S. Miller50312ce2006-06-29 14:35:52 -0700160 u8 mode; /* Mode Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161};
162
163struct cg14_xlut{
David S. Miller50312ce2006-06-29 14:35:52 -0700164 u8 x_xlut [256];
165 u8 x_xlutd [256];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 u8 xxx0[0x600];
David S. Miller50312ce2006-06-29 14:35:52 -0700167 u8 x_xlut_inc [256];
168 u8 x_xlutd_inc [256];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169};
170
171/* Color look up table (clut) */
172/* Each one of these arrays hold the color lookup table (for 256
173 * colors) for each MDI page (I assume then there should be 4 MDI
174 * pages, I still wonder what they are. I have seen NeXTStep split
175 * the screen in four parts, while operating in 24 bits mode. Each
176 * integer holds 4 values: alpha value (transparency channel, thanks
177 * go to John Stone (johns@umr.edu) from OpenBSD), red, green and blue
178 *
179 * I currently use the clut instead of the Xlut
180 */
181struct cg14_clut {
182 u32 c_clut [256];
183 u32 c_clutd [256]; /* i wonder what the 'd' is for */
184 u32 c_clut_inc [256];
185 u32 c_clutd_inc [256];
186};
187
188#define CG14_MMAP_ENTRIES 16
189
190struct cg14_par {
191 spinlock_t lock;
192 struct cg14_regs __iomem *regs;
193 struct cg14_clut __iomem *clut;
194 struct cg14_cursor __iomem *cursor;
195
196 u32 flags;
197#define CG14_FLAG_BLANKED 0x00000001
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 unsigned long iospace;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 struct sbus_mmap_map mmap_map[CG14_MMAP_ENTRIES];
202
203 int mode;
204 int ramsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
207static void __cg14_reset(struct cg14_par *par)
208{
209 struct cg14_regs __iomem *regs = par->regs;
210 u8 val;
211
212 val = sbus_readb(&regs->mcr);
213 val &= ~(CG14_MCR_PIXMODE_MASK);
214 sbus_writeb(val, &regs->mcr);
215}
216
217static int cg14_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
218{
219 struct cg14_par *par = (struct cg14_par *) info->par;
220 unsigned long flags;
221
222 /* We just use this to catch switches out of
223 * graphics mode.
224 */
225 spin_lock_irqsave(&par->lock, flags);
226 __cg14_reset(par);
227 spin_unlock_irqrestore(&par->lock, flags);
228
229 if (var->xoffset || var->yoffset || var->vmode)
230 return -EINVAL;
231 return 0;
232}
233
234/**
235 * cg14_setcolreg - Optional function. Sets a color register.
236 * @regno: boolean, 0 copy local, 1 get_user() function
237 * @red: frame buffer colormap structure
238 * @green: The green value which can be up to 16 bits wide
239 * @blue: The blue value which can be up to 16 bits wide.
240 * @transp: If supported the alpha value which can be up to 16 bits wide.
241 * @info: frame buffer info structure
242 */
243static int cg14_setcolreg(unsigned regno,
244 unsigned red, unsigned green, unsigned blue,
245 unsigned transp, struct fb_info *info)
246{
247 struct cg14_par *par = (struct cg14_par *) info->par;
248 struct cg14_clut __iomem *clut = par->clut;
249 unsigned long flags;
250 u32 val;
251
252 if (regno >= 256)
253 return 1;
254
255 red >>= 8;
256 green >>= 8;
257 blue >>= 8;
258 val = (red | (green << 8) | (blue << 16));
259
260 spin_lock_irqsave(&par->lock, flags);
261 sbus_writel(val, &clut->c_clut[regno]);
262 spin_unlock_irqrestore(&par->lock, flags);
263
264 return 0;
265}
266
Christoph Hellwig216d5262006-01-14 13:21:25 -0800267static int cg14_mmap(struct fb_info *info, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 struct cg14_par *par = (struct cg14_par *) info->par;
270
271 return sbusfb_mmap_helper(par->mmap_map,
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000272 info->fix.smem_start, info->fix.smem_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 par->iospace, vma);
274}
275
Christoph Hellwig67a66802006-01-14 13:21:25 -0800276static int cg14_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 struct cg14_par *par = (struct cg14_par *) info->par;
279 struct cg14_regs __iomem *regs = par->regs;
280 struct mdi_cfginfo kmdi, __user *mdii;
281 unsigned long flags;
282 int cur_mode, mode, ret = 0;
283
284 switch (cmd) {
285 case MDI_RESET:
286 spin_lock_irqsave(&par->lock, flags);
287 __cg14_reset(par);
288 spin_unlock_irqrestore(&par->lock, flags);
289 break;
290
291 case MDI_GET_CFGINFO:
292 memset(&kmdi, 0, sizeof(kmdi));
293
294 spin_lock_irqsave(&par->lock, flags);
295 kmdi.mdi_type = FBTYPE_MDICOLOR;
296 kmdi.mdi_height = info->var.yres;
297 kmdi.mdi_width = info->var.xres;
298 kmdi.mdi_mode = par->mode;
299 kmdi.mdi_pixfreq = 72; /* FIXME */
300 kmdi.mdi_size = par->ramsize;
301 spin_unlock_irqrestore(&par->lock, flags);
302
303 mdii = (struct mdi_cfginfo __user *) arg;
304 if (copy_to_user(mdii, &kmdi, sizeof(kmdi)))
305 ret = -EFAULT;
306 break;
307
308 case MDI_SET_PIXELMODE:
309 if (get_user(mode, (int __user *) arg)) {
310 ret = -EFAULT;
311 break;
312 }
313
314 spin_lock_irqsave(&par->lock, flags);
315 cur_mode = sbus_readb(&regs->mcr);
316 cur_mode &= ~CG14_MCR_PIXMODE_MASK;
317 switch(mode) {
318 case MDI_32_PIX:
319 cur_mode |= (CG14_MCR_PIXMODE_32 <<
320 CG14_MCR_PIXMODE_SHIFT);
321 break;
322
323 case MDI_16_PIX:
324 cur_mode |= (CG14_MCR_PIXMODE_16 <<
325 CG14_MCR_PIXMODE_SHIFT);
326 break;
327
328 case MDI_8_PIX:
329 break;
330
331 default:
332 ret = -ENOSYS;
333 break;
334 };
335 if (!ret) {
336 sbus_writeb(cur_mode, &regs->mcr);
337 par->mode = mode;
338 }
339 spin_unlock_irqrestore(&par->lock, flags);
340 break;
341
342 default:
343 ret = sbusfb_ioctl_helper(cmd, arg, info,
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000344 FBTYPE_MDICOLOR, 8,
345 info->fix.smem_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347 };
348
349 return ret;
350}
351
352/*
353 * Initialisation
354 */
355
Robert Reif8fdab472007-03-08 21:22:03 -0800356static void __devinit cg14_init_fix(struct fb_info *info, int linebytes,
357 struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
David S. Miller50312ce2006-06-29 14:35:52 -0700359 const char *name = dp->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 strlcpy(info->fix.id, name, sizeof(info->fix.id));
362
363 info->fix.type = FB_TYPE_PACKED_PIXELS;
364 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
365
366 info->fix.line_length = linebytes;
367
368 info->fix.accel = FB_ACCEL_SUN_CG14;
369}
370
Robert Reif8fdab472007-03-08 21:22:03 -0800371static struct sbus_mmap_map __cg14_mmap_map[CG14_MMAP_ENTRIES] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 {
373 .voff = CG14_REGS,
374 .poff = 0x80000000,
375 .size = 0x1000
376 },
377 {
378 .voff = CG14_XLUT,
379 .poff = 0x80003000,
380 .size = 0x1000
381 },
382 {
383 .voff = CG14_CLUT1,
384 .poff = 0x80004000,
385 .size = 0x1000
386 },
387 {
388 .voff = CG14_CLUT2,
389 .poff = 0x80005000,
390 .size = 0x1000
391 },
392 {
393 .voff = CG14_CLUT3,
394 .poff = 0x80006000,
395 .size = 0x1000
396 },
397 {
398 .voff = CG3_MMAP_OFFSET - 0x7000,
399 .poff = 0x80000000,
400 .size = 0x7000
401 },
402 {
403 .voff = CG3_MMAP_OFFSET,
404 .poff = 0x00000000,
405 .size = SBUS_MMAP_FBSIZE(1)
406 },
407 {
408 .voff = MDI_CURSOR_MAP,
409 .poff = 0x80001000,
410 .size = 0x1000
411 },
412 {
413 .voff = MDI_CHUNKY_BGR_MAP,
414 .poff = 0x01000000,
415 .size = 0x400000
416 },
417 {
418 .voff = MDI_PLANAR_X16_MAP,
419 .poff = 0x02000000,
420 .size = 0x200000
421 },
422 {
423 .voff = MDI_PLANAR_C16_MAP,
424 .poff = 0x02800000,
425 .size = 0x200000
426 },
427 {
428 .voff = MDI_PLANAR_X32_MAP,
429 .poff = 0x03000000,
430 .size = 0x100000
431 },
432 {
433 .voff = MDI_PLANAR_B32_MAP,
434 .poff = 0x03400000,
435 .size = 0x100000
436 },
437 {
438 .voff = MDI_PLANAR_G32_MAP,
439 .poff = 0x03800000,
440 .size = 0x100000
441 },
442 {
443 .voff = MDI_PLANAR_R32_MAP,
444 .poff = 0x03c00000,
445 .size = 0x100000
446 },
447 { .size = 0 }
448};
449
David S. Millerc7f439b2007-07-27 22:31:46 -0700450static void cg14_unmap_regs(struct of_device *op, struct fb_info *info,
451 struct cg14_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
David S. Millerc7f439b2007-07-27 22:31:46 -0700453 if (par->regs)
David S. Millere3a411a2006-12-28 21:01:32 -0800454 of_iounmap(&op->resource[0],
David S. Millerc7f439b2007-07-27 22:31:46 -0700455 par->regs, sizeof(struct cg14_regs));
456 if (par->clut)
David S. Millere3a411a2006-12-28 21:01:32 -0800457 of_iounmap(&op->resource[0],
David S. Millerc7f439b2007-07-27 22:31:46 -0700458 par->clut, sizeof(struct cg14_clut));
459 if (par->cursor)
David S. Millere3a411a2006-12-28 21:01:32 -0800460 of_iounmap(&op->resource[0],
David S. Millerc7f439b2007-07-27 22:31:46 -0700461 par->cursor, sizeof(struct cg14_cursor));
462 if (info->screen_base)
David S. Millere3a411a2006-12-28 21:01:32 -0800463 of_iounmap(&op->resource[1],
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000464 info->screen_base, info->fix.smem_len);
David S. Miller50312ce2006-06-29 14:35:52 -0700465}
466
David S. Millerc7f439b2007-07-27 22:31:46 -0700467static int __devinit cg14_probe(struct of_device *op, const struct of_device_id *match)
David S. Miller50312ce2006-06-29 14:35:52 -0700468{
469 struct device_node *dp = op->node;
David S. Millerc7f439b2007-07-27 22:31:46 -0700470 struct fb_info *info;
471 struct cg14_par *par;
David S. Miller50312ce2006-06-29 14:35:52 -0700472 int is_8mb, linebytes, i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
David S. Millerc7f439b2007-07-27 22:31:46 -0700474 info = framebuffer_alloc(sizeof(struct cg14_par), &op->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
David S. Millerc7f439b2007-07-27 22:31:46 -0700476 err = -ENOMEM;
477 if (!info)
478 goto out_err;
479 par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
David S. Millerc7f439b2007-07-27 22:31:46 -0700481 spin_lock_init(&par->lock);
482
Robert Reif6cd5a862008-05-08 21:37:30 -0700483 sbusfb_fill_var(&info->var, dp, 8);
David S. Millerc7f439b2007-07-27 22:31:46 -0700484 info->var.red.length = 8;
485 info->var.green.length = 8;
486 info->var.blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
David S. Miller50312ce2006-06-29 14:35:52 -0700488 linebytes = of_getintprop_default(dp, "linebytes",
David S. Millerc7f439b2007-07-27 22:31:46 -0700489 info->var.xres);
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000490 info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
David S. Miller50312ce2006-06-29 14:35:52 -0700492 if (!strcmp(dp->parent->name, "sbus") ||
493 !strcmp(dp->parent->name, "sbi")) {
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000494 info->fix.smem_start = op->resource[0].start;
David S. Millerc7f439b2007-07-27 22:31:46 -0700495 par->iospace = op->resource[0].flags & IORESOURCE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 } else {
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000497 info->fix.smem_start = op->resource[1].start;
David S. Millerc7f439b2007-07-27 22:31:46 -0700498 par->iospace = op->resource[0].flags & IORESOURCE_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500
David S. Millerc7f439b2007-07-27 22:31:46 -0700501 par->regs = of_ioremap(&op->resource[0], 0,
502 sizeof(struct cg14_regs), "cg14 regs");
503 par->clut = of_ioremap(&op->resource[0], CG14_CLUT1,
504 sizeof(struct cg14_clut), "cg14 clut");
505 par->cursor = of_ioremap(&op->resource[0], CG14_CURSORREGS,
506 sizeof(struct cg14_cursor), "cg14 cursor");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
David S. Millerc7f439b2007-07-27 22:31:46 -0700508 info->screen_base = of_ioremap(&op->resource[1], 0,
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000509 info->fix.smem_len, "cg14 ram");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
David S. Millerc7f439b2007-07-27 22:31:46 -0700511 if (!par->regs || !par->clut || !par->cursor || !info->screen_base)
512 goto out_unmap_regs;
David S. Miller50312ce2006-06-29 14:35:52 -0700513
514 is_8mb = (((op->resource[1].end - op->resource[1].start) + 1) ==
515 (8 * 1024 * 1024));
516
David S. Millerc7f439b2007-07-27 22:31:46 -0700517 BUILD_BUG_ON(sizeof(par->mmap_map) != sizeof(__cg14_mmap_map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
David S. Millerc7f439b2007-07-27 22:31:46 -0700519 memcpy(&par->mmap_map, &__cg14_mmap_map, sizeof(par->mmap_map));
David S. Miller50312ce2006-06-29 14:35:52 -0700520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 for (i = 0; i < CG14_MMAP_ENTRIES; i++) {
David S. Millerc7f439b2007-07-27 22:31:46 -0700522 struct sbus_mmap_map *map = &par->mmap_map[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 if (!map->size)
525 break;
526 if (map->poff & 0x80000000)
David S. Miller50312ce2006-06-29 14:35:52 -0700527 map->poff = (map->poff & 0x7fffffff) +
528 (op->resource[0].start -
529 op->resource[1].start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (is_8mb &&
531 map->size >= 0x100000 &&
532 map->size <= 0x400000)
533 map->size *= 2;
534 }
535
David S. Millerc7f439b2007-07-27 22:31:46 -0700536 par->mode = MDI_8_PIX;
537 par->ramsize = (is_8mb ? 0x800000 : 0x400000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
David S. Millerc7f439b2007-07-27 22:31:46 -0700539 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
540 info->fbops = &cg14_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
David S. Millerc7f439b2007-07-27 22:31:46 -0700542 __cg14_reset(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
David S. Millerc7f439b2007-07-27 22:31:46 -0700544 if (fb_alloc_cmap(&info->cmap, 256, 0))
545 goto out_unmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
David S. Millerc7f439b2007-07-27 22:31:46 -0700547 fb_set_cmap(&info->cmap, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
David S. Millerc7f439b2007-07-27 22:31:46 -0700549 cg14_init_fix(info, linebytes, dp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
David S. Millerc7f439b2007-07-27 22:31:46 -0700551 err = register_framebuffer(info);
552 if (err < 0)
553 goto out_dealloc_cmap;
554
555 dev_set_drvdata(&op->dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Robert Reif194f1a62008-04-27 15:18:57 -0700557 printk(KERN_INFO "%s: cgfourteen at %lx:%lx, %dMB\n",
David S. Miller50312ce2006-06-29 14:35:52 -0700558 dp->full_name,
Krzysztof Heltde4dc482009-05-04 10:36:50 +0000559 par->iospace, info->fix.smem_start,
David S. Millerc7f439b2007-07-27 22:31:46 -0700560 par->ramsize >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
David S. Miller50312ce2006-06-29 14:35:52 -0700562 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
David S. Millerc7f439b2007-07-27 22:31:46 -0700564out_dealloc_cmap:
565 fb_dealloc_cmap(&info->cmap);
David S. Miller50312ce2006-06-29 14:35:52 -0700566
David S. Millerc7f439b2007-07-27 22:31:46 -0700567out_unmap_regs:
568 cg14_unmap_regs(op, info, par);
569
570out_err:
571 return err;
David S. Miller50312ce2006-06-29 14:35:52 -0700572}
573
David S. Millere3a411a2006-12-28 21:01:32 -0800574static int __devexit cg14_remove(struct of_device *op)
David S. Miller50312ce2006-06-29 14:35:52 -0700575{
David S. Millerc7f439b2007-07-27 22:31:46 -0700576 struct fb_info *info = dev_get_drvdata(&op->dev);
577 struct cg14_par *par = info->par;
David S. Miller50312ce2006-06-29 14:35:52 -0700578
David S. Millerc7f439b2007-07-27 22:31:46 -0700579 unregister_framebuffer(info);
580 fb_dealloc_cmap(&info->cmap);
David S. Miller50312ce2006-06-29 14:35:52 -0700581
David S. Millerc7f439b2007-07-27 22:31:46 -0700582 cg14_unmap_regs(op, info, par);
David S. Miller50312ce2006-06-29 14:35:52 -0700583
David S. Millerc7f439b2007-07-27 22:31:46 -0700584 framebuffer_release(info);
David S. Miller50312ce2006-06-29 14:35:52 -0700585
David S. Millere3a411a2006-12-28 21:01:32 -0800586 dev_set_drvdata(&op->dev, NULL);
David S. Miller50312ce2006-06-29 14:35:52 -0700587
588 return 0;
589}
590
David S. Millerfd098312008-08-31 01:23:17 -0700591static const struct of_device_id cg14_match[] = {
David S. Miller50312ce2006-06-29 14:35:52 -0700592 {
593 .name = "cgfourteen",
594 },
595 {},
596};
597MODULE_DEVICE_TABLE(of, cg14_match);
598
599static struct of_platform_driver cg14_driver = {
600 .name = "cg14",
601 .match_table = cg14_match,
602 .probe = cg14_probe,
603 .remove = __devexit_p(cg14_remove),
604};
605
Robert Reif54433002008-04-27 15:17:23 -0700606static int __init cg14_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 if (fb_get_options("cg14fb", NULL))
609 return -ENODEV;
610
David S. Miller50312ce2006-06-29 14:35:52 -0700611 return of_register_driver(&cg14_driver, &of_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Robert Reif54433002008-04-27 15:17:23 -0700614static void __exit cg14_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
David S. Miller50312ce2006-06-29 14:35:52 -0700616 of_unregister_driver(&cg14_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
619module_init(cg14_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620module_exit(cg14_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622MODULE_DESCRIPTION("framebuffer driver for CGfourteen chipsets");
David S. Miller50312ce2006-06-29 14:35:52 -0700623MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
624MODULE_VERSION("2.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625MODULE_LICENSE("GPL");