Blackfin: bf548-ezkit/bf561-ezkit: update nor flash layout
[zen-stable.git] / drivers / video / mb862xx / mb862xxfb.c
blobc76e663a6cd41a6ab43721174bf5e08b0cb0f095
1 /*
2 * drivers/mb862xx/mb862xxfb.c
4 * Fujitsu Carmine/Coral-P(A)/Lime framebuffer driver
6 * (C) 2008 Anatolij Gustschin <agust@denx.de>
7 * DENX Software Engineering
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 #undef DEBUG
17 #include <linux/fb.h>
18 #include <linux/delay.h>
19 #include <linux/init.h>
20 #include <linux/interrupt.h>
21 #include <linux/pci.h>
22 #if defined(CONFIG_OF)
23 #include <linux/of_platform.h>
24 #endif
25 #include "mb862xxfb.h"
26 #include "mb862xx_reg.h"
28 #define NR_PALETTE 256
29 #define MB862XX_MEM_SIZE 0x1000000
30 #define CORALP_MEM_SIZE 0x4000000
31 #define CARMINE_MEM_SIZE 0x8000000
32 #define DRV_NAME "mb862xxfb"
34 #if defined(CONFIG_SOCRATES)
35 static struct mb862xx_gc_mode socrates_gc_mode = {
36 /* Mode for Prime View PM070WL4 TFT LCD Panel */
37 { "800x480", 45, 800, 480, 40000, 86, 42, 33, 10, 128, 2, 0, 0, 0 },
38 /* 16 bits/pixel, 16MB, 133MHz, SDRAM memory mode value */
39 16, 0x1000000, GC_CCF_COT_133, 0x4157ba63
41 #endif
43 /* Helpers */
44 static inline int h_total(struct fb_var_screeninfo *var)
46 return var->xres + var->left_margin +
47 var->right_margin + var->hsync_len;
50 static inline int v_total(struct fb_var_screeninfo *var)
52 return var->yres + var->upper_margin +
53 var->lower_margin + var->vsync_len;
56 static inline int hsp(struct fb_var_screeninfo *var)
58 return var->xres + var->right_margin - 1;
61 static inline int vsp(struct fb_var_screeninfo *var)
63 return var->yres + var->lower_margin - 1;
66 static inline int d_pitch(struct fb_var_screeninfo *var)
68 return var->xres * var->bits_per_pixel / 8;
71 static inline unsigned int chan_to_field(unsigned int chan,
72 struct fb_bitfield *bf)
74 chan &= 0xffff;
75 chan >>= 16 - bf->length;
76 return chan << bf->offset;
79 static int mb862xxfb_setcolreg(unsigned regno,
80 unsigned red, unsigned green, unsigned blue,
81 unsigned transp, struct fb_info *info)
83 struct mb862xxfb_par *par = info->par;
84 unsigned int val;
86 switch (info->fix.visual) {
87 case FB_VISUAL_TRUECOLOR:
88 if (regno < 16) {
89 val = chan_to_field(red, &info->var.red);
90 val |= chan_to_field(green, &info->var.green);
91 val |= chan_to_field(blue, &info->var.blue);
92 par->pseudo_palette[regno] = val;
94 break;
95 case FB_VISUAL_PSEUDOCOLOR:
96 if (regno < 256) {
97 val = (red >> 8) << 16;
98 val |= (green >> 8) << 8;
99 val |= blue >> 8;
100 outreg(disp, GC_L0PAL0 + (regno * 4), val);
102 break;
103 default:
104 return 1; /* unsupported type */
106 return 0;
109 static int mb862xxfb_check_var(struct fb_var_screeninfo *var,
110 struct fb_info *fbi)
112 unsigned long tmp;
114 if (fbi->dev)
115 dev_dbg(fbi->dev, "%s\n", __func__);
117 /* check if these values fit into the registers */
118 if (var->hsync_len > 255 || var->vsync_len > 255)
119 return -EINVAL;
121 if ((var->xres + var->right_margin) >= 4096)
122 return -EINVAL;
124 if ((var->yres + var->lower_margin) > 4096)
125 return -EINVAL;
127 if (h_total(var) > 4096 || v_total(var) > 4096)
128 return -EINVAL;
130 if (var->xres_virtual > 4096 || var->yres_virtual > 4096)
131 return -EINVAL;
133 if (var->bits_per_pixel <= 8)
134 var->bits_per_pixel = 8;
135 else if (var->bits_per_pixel <= 16)
136 var->bits_per_pixel = 16;
137 else if (var->bits_per_pixel <= 32)
138 var->bits_per_pixel = 32;
141 * can cope with 8,16 or 24/32bpp if resulting
142 * pitch is divisible by 64 without remainder
144 if (d_pitch(&fbi->var) % GC_L0M_L0W_UNIT) {
145 int r;
147 var->bits_per_pixel = 0;
148 do {
149 var->bits_per_pixel += 8;
150 r = d_pitch(&fbi->var) % GC_L0M_L0W_UNIT;
151 } while (r && var->bits_per_pixel <= 32);
153 if (d_pitch(&fbi->var) % GC_L0M_L0W_UNIT)
154 return -EINVAL;
157 /* line length is going to be 128 bit aligned */
158 tmp = (var->xres * var->bits_per_pixel) / 8;
159 if ((tmp & 15) != 0)
160 return -EINVAL;
162 /* set r/g/b positions and validate bpp */
163 switch (var->bits_per_pixel) {
164 case 8:
165 var->red.length = var->bits_per_pixel;
166 var->green.length = var->bits_per_pixel;
167 var->blue.length = var->bits_per_pixel;
168 var->red.offset = 0;
169 var->green.offset = 0;
170 var->blue.offset = 0;
171 var->transp.length = 0;
172 break;
173 case 16:
174 var->red.length = 5;
175 var->green.length = 5;
176 var->blue.length = 5;
177 var->red.offset = 10;
178 var->green.offset = 5;
179 var->blue.offset = 0;
180 var->transp.length = 0;
181 break;
182 case 24:
183 case 32:
184 var->transp.length = 8;
185 var->red.length = 8;
186 var->green.length = 8;
187 var->blue.length = 8;
188 var->transp.offset = 24;
189 var->red.offset = 16;
190 var->green.offset = 8;
191 var->blue.offset = 0;
192 break;
193 default:
194 return -EINVAL;
196 return 0;
200 * set display parameters
202 static int mb862xxfb_set_par(struct fb_info *fbi)
204 struct mb862xxfb_par *par = fbi->par;
205 unsigned long reg, sc;
207 dev_dbg(par->dev, "%s\n", __func__);
208 if (par->type == BT_CORALP)
209 mb862xxfb_init_accel(fbi, fbi->var.xres);
211 if (par->pre_init)
212 return 0;
214 /* disp off */
215 reg = inreg(disp, GC_DCM1);
216 reg &= ~GC_DCM01_DEN;
217 outreg(disp, GC_DCM1, reg);
219 /* set display reference clock div. */
220 sc = par->refclk / (1000000 / fbi->var.pixclock) - 1;
221 reg = inreg(disp, GC_DCM1);
222 reg &= ~(GC_DCM01_CKS | GC_DCM01_RESV | GC_DCM01_SC);
223 reg |= sc << 8;
224 outreg(disp, GC_DCM1, reg);
225 dev_dbg(par->dev, "SC 0x%lx\n", sc);
227 /* disp dimension, format */
228 reg = pack(d_pitch(&fbi->var) / GC_L0M_L0W_UNIT,
229 (fbi->var.yres - 1));
230 if (fbi->var.bits_per_pixel == 16)
231 reg |= GC_L0M_L0C_16;
232 outreg(disp, GC_L0M, reg);
234 if (fbi->var.bits_per_pixel == 32) {
235 reg = inreg(disp, GC_L0EM);
236 outreg(disp, GC_L0EM, reg | GC_L0EM_L0EC_24);
238 outreg(disp, GC_WY_WX, 0);
239 reg = pack(fbi->var.yres - 1, fbi->var.xres);
240 outreg(disp, GC_WH_WW, reg);
241 outreg(disp, GC_L0OA0, 0);
242 outreg(disp, GC_L0DA0, 0);
243 outreg(disp, GC_L0DY_L0DX, 0);
244 outreg(disp, GC_L0WY_L0WX, 0);
245 outreg(disp, GC_L0WH_L0WW, reg);
247 /* both HW-cursors off */
248 reg = inreg(disp, GC_CPM_CUTC);
249 reg &= ~(GC_CPM_CEN0 | GC_CPM_CEN1);
250 outreg(disp, GC_CPM_CUTC, reg);
252 /* timings */
253 reg = pack(fbi->var.xres - 1, fbi->var.xres - 1);
254 outreg(disp, GC_HDB_HDP, reg);
255 reg = pack((fbi->var.yres - 1), vsp(&fbi->var));
256 outreg(disp, GC_VDP_VSP, reg);
257 reg = ((fbi->var.vsync_len - 1) << 24) |
258 pack((fbi->var.hsync_len - 1), hsp(&fbi->var));
259 outreg(disp, GC_VSW_HSW_HSP, reg);
260 outreg(disp, GC_HTP, pack(h_total(&fbi->var) - 1, 0));
261 outreg(disp, GC_VTR, pack(v_total(&fbi->var) - 1, 0));
263 /* display on */
264 reg = inreg(disp, GC_DCM1);
265 reg |= GC_DCM01_DEN | GC_DCM01_L0E;
266 reg &= ~GC_DCM01_ESY;
267 outreg(disp, GC_DCM1, reg);
268 return 0;
271 static int mb862xxfb_pan(struct fb_var_screeninfo *var,
272 struct fb_info *info)
274 struct mb862xxfb_par *par = info->par;
275 unsigned long reg;
277 reg = pack(var->yoffset, var->xoffset);
278 outreg(disp, GC_L0WY_L0WX, reg);
280 reg = pack(var->yres_virtual, var->xres_virtual);
281 outreg(disp, GC_L0WH_L0WW, reg);
282 return 0;
285 static int mb862xxfb_blank(int mode, struct fb_info *fbi)
287 struct mb862xxfb_par *par = fbi->par;
288 unsigned long reg;
290 dev_dbg(fbi->dev, "blank mode=%d\n", mode);
292 switch (mode) {
293 case FB_BLANK_POWERDOWN:
294 reg = inreg(disp, GC_DCM1);
295 reg &= ~GC_DCM01_DEN;
296 outreg(disp, GC_DCM1, reg);
297 break;
298 case FB_BLANK_UNBLANK:
299 reg = inreg(disp, GC_DCM1);
300 reg |= GC_DCM01_DEN;
301 outreg(disp, GC_DCM1, reg);
302 break;
303 case FB_BLANK_NORMAL:
304 case FB_BLANK_VSYNC_SUSPEND:
305 case FB_BLANK_HSYNC_SUSPEND:
306 default:
307 return 1;
309 return 0;
312 /* framebuffer ops */
313 static struct fb_ops mb862xxfb_ops = {
314 .owner = THIS_MODULE,
315 .fb_check_var = mb862xxfb_check_var,
316 .fb_set_par = mb862xxfb_set_par,
317 .fb_setcolreg = mb862xxfb_setcolreg,
318 .fb_blank = mb862xxfb_blank,
319 .fb_pan_display = mb862xxfb_pan,
320 .fb_fillrect = cfb_fillrect,
321 .fb_copyarea = cfb_copyarea,
322 .fb_imageblit = cfb_imageblit,
325 /* initialize fb_info data */
326 static int mb862xxfb_init_fbinfo(struct fb_info *fbi)
328 struct mb862xxfb_par *par = fbi->par;
329 struct mb862xx_gc_mode *mode = par->gc_mode;
330 unsigned long reg;
332 fbi->fbops = &mb862xxfb_ops;
333 fbi->pseudo_palette = par->pseudo_palette;
334 fbi->screen_base = par->fb_base;
335 fbi->screen_size = par->mapped_vram;
337 strcpy(fbi->fix.id, DRV_NAME);
338 fbi->fix.smem_start = (unsigned long)par->fb_base_phys;
339 fbi->fix.smem_len = par->mapped_vram;
340 fbi->fix.mmio_start = (unsigned long)par->mmio_base_phys;
341 fbi->fix.mmio_len = par->mmio_len;
342 fbi->fix.accel = FB_ACCEL_NONE;
343 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
344 fbi->fix.type_aux = 0;
345 fbi->fix.xpanstep = 1;
346 fbi->fix.ypanstep = 1;
347 fbi->fix.ywrapstep = 0;
349 reg = inreg(disp, GC_DCM1);
350 if (reg & GC_DCM01_DEN && reg & GC_DCM01_L0E) {
351 /* get the disp mode from active display cfg */
352 unsigned long sc = ((reg & GC_DCM01_SC) >> 8) + 1;
353 unsigned long hsp, vsp, ht, vt;
355 dev_dbg(par->dev, "using bootloader's disp. mode\n");
356 fbi->var.pixclock = (sc * 1000000) / par->refclk;
357 fbi->var.xres = (inreg(disp, GC_HDB_HDP) & 0x0fff) + 1;
358 reg = inreg(disp, GC_VDP_VSP);
359 fbi->var.yres = ((reg >> 16) & 0x0fff) + 1;
360 vsp = (reg & 0x0fff) + 1;
361 fbi->var.xres_virtual = fbi->var.xres;
362 fbi->var.yres_virtual = fbi->var.yres;
363 reg = inreg(disp, GC_L0EM);
364 if (reg & GC_L0EM_L0EC_24) {
365 fbi->var.bits_per_pixel = 32;
366 } else {
367 reg = inreg(disp, GC_L0M);
368 if (reg & GC_L0M_L0C_16)
369 fbi->var.bits_per_pixel = 16;
370 else
371 fbi->var.bits_per_pixel = 8;
373 reg = inreg(disp, GC_VSW_HSW_HSP);
374 fbi->var.hsync_len = ((reg & 0xff0000) >> 16) + 1;
375 fbi->var.vsync_len = ((reg & 0x3f000000) >> 24) + 1;
376 hsp = (reg & 0xffff) + 1;
377 ht = ((inreg(disp, GC_HTP) & 0xfff0000) >> 16) + 1;
378 fbi->var.right_margin = hsp - fbi->var.xres;
379 fbi->var.left_margin = ht - hsp - fbi->var.hsync_len;
380 vt = ((inreg(disp, GC_VTR) & 0xfff0000) >> 16) + 1;
381 fbi->var.lower_margin = vsp - fbi->var.yres;
382 fbi->var.upper_margin = vt - vsp - fbi->var.vsync_len;
383 } else if (mode) {
384 dev_dbg(par->dev, "using supplied mode\n");
385 fb_videomode_to_var(&fbi->var, (struct fb_videomode *)mode);
386 fbi->var.bits_per_pixel = mode->def_bpp ? mode->def_bpp : 8;
387 } else {
388 int ret;
390 ret = fb_find_mode(&fbi->var, fbi, "640x480-16@60",
391 NULL, 0, NULL, 16);
392 if (ret == 0 || ret == 4) {
393 dev_err(par->dev,
394 "failed to get initial mode\n");
395 return -EINVAL;
399 fbi->var.xoffset = 0;
400 fbi->var.yoffset = 0;
401 fbi->var.grayscale = 0;
402 fbi->var.nonstd = 0;
403 fbi->var.height = -1;
404 fbi->var.width = -1;
405 fbi->var.accel_flags = 0;
406 fbi->var.vmode = FB_VMODE_NONINTERLACED;
407 fbi->var.activate = FB_ACTIVATE_NOW;
408 fbi->flags = FBINFO_DEFAULT |
409 #ifdef __BIG_ENDIAN
410 FBINFO_FOREIGN_ENDIAN |
411 #endif
412 FBINFO_HWACCEL_XPAN |
413 FBINFO_HWACCEL_YPAN;
415 /* check and possibly fix bpp */
416 if ((fbi->fbops->fb_check_var)(&fbi->var, fbi))
417 dev_err(par->dev, "check_var() failed on initial setup?\n");
419 fbi->fix.visual = fbi->var.bits_per_pixel == 8 ?
420 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
421 fbi->fix.line_length = (fbi->var.xres_virtual *
422 fbi->var.bits_per_pixel) / 8;
423 return 0;
427 * show some display controller and cursor registers
429 static ssize_t mb862xxfb_show_dispregs(struct device *dev,
430 struct device_attribute *attr, char *buf)
432 struct fb_info *fbi = dev_get_drvdata(dev);
433 struct mb862xxfb_par *par = fbi->par;
434 char *ptr = buf;
435 unsigned int reg;
437 for (reg = GC_DCM0; reg <= GC_L0DY_L0DX; reg += 4)
438 ptr += sprintf(ptr, "%08x = %08x\n",
439 reg, inreg(disp, reg));
441 for (reg = GC_CPM_CUTC; reg <= GC_CUY1_CUX1; reg += 4)
442 ptr += sprintf(ptr, "%08x = %08x\n",
443 reg, inreg(disp, reg));
445 for (reg = GC_DCM1; reg <= GC_L0WH_L0WW; reg += 4)
446 ptr += sprintf(ptr, "%08x = %08x\n",
447 reg, inreg(disp, reg));
449 for (reg = 0x400; reg <= 0x410; reg += 4)
450 ptr += sprintf(ptr, "geo %08x = %08x\n",
451 reg, inreg(geo, reg));
453 for (reg = 0x400; reg <= 0x410; reg += 4)
454 ptr += sprintf(ptr, "draw %08x = %08x\n",
455 reg, inreg(draw, reg));
457 for (reg = 0x440; reg <= 0x450; reg += 4)
458 ptr += sprintf(ptr, "draw %08x = %08x\n",
459 reg, inreg(draw, reg));
461 return ptr - buf;
464 static DEVICE_ATTR(dispregs, 0444, mb862xxfb_show_dispregs, NULL);
466 irqreturn_t mb862xx_intr(int irq, void *dev_id)
468 struct mb862xxfb_par *par = (struct mb862xxfb_par *) dev_id;
469 unsigned long reg_ist, mask;
471 if (!par)
472 return IRQ_NONE;
474 if (par->type == BT_CARMINE) {
475 /* Get Interrupt Status */
476 reg_ist = inreg(ctrl, GC_CTRL_STATUS);
477 mask = inreg(ctrl, GC_CTRL_INT_MASK);
478 if (reg_ist == 0)
479 return IRQ_HANDLED;
481 reg_ist &= mask;
482 if (reg_ist == 0)
483 return IRQ_HANDLED;
485 /* Clear interrupt status */
486 outreg(ctrl, 0x0, reg_ist);
487 } else {
488 /* Get status */
489 reg_ist = inreg(host, GC_IST);
490 mask = inreg(host, GC_IMASK);
492 reg_ist &= mask;
493 if (reg_ist == 0)
494 return IRQ_HANDLED;
496 /* Clear status */
497 outreg(host, GC_IST, ~reg_ist);
499 return IRQ_HANDLED;
502 #if defined(CONFIG_FB_MB862XX_LIME)
504 * GDC (Lime, Coral(B/Q), Mint, ...) on host bus
506 static int mb862xx_gdc_init(struct mb862xxfb_par *par)
508 unsigned long ccf, mmr;
509 unsigned long ver, rev;
511 if (!par)
512 return -ENODEV;
514 #if defined(CONFIG_FB_PRE_INIT_FB)
515 par->pre_init = 1;
516 #endif
517 par->host = par->mmio_base;
518 par->i2c = par->mmio_base + MB862XX_I2C_BASE;
519 par->disp = par->mmio_base + MB862XX_DISP_BASE;
520 par->cap = par->mmio_base + MB862XX_CAP_BASE;
521 par->draw = par->mmio_base + MB862XX_DRAW_BASE;
522 par->geo = par->mmio_base + MB862XX_GEO_BASE;
523 par->pio = par->mmio_base + MB862XX_PIO_BASE;
525 par->refclk = GC_DISP_REFCLK_400;
527 ver = inreg(host, GC_CID);
528 rev = inreg(pio, GC_REVISION);
529 if ((ver == 0x303) && (rev & 0xffffff00) == 0x20050100) {
530 dev_info(par->dev, "Fujitsu Lime v1.%d found\n",
531 (int)rev & 0xff);
532 par->type = BT_LIME;
533 ccf = par->gc_mode ? par->gc_mode->ccf : GC_CCF_COT_100;
534 mmr = par->gc_mode ? par->gc_mode->mmr : 0x414fb7f2;
535 } else {
536 dev_info(par->dev, "? GDC, CID/Rev.: 0x%lx/0x%lx \n", ver, rev);
537 return -ENODEV;
540 if (!par->pre_init) {
541 outreg(host, GC_CCF, ccf);
542 udelay(200);
543 outreg(host, GC_MMR, mmr);
544 udelay(10);
547 /* interrupt status */
548 outreg(host, GC_IST, 0);
549 outreg(host, GC_IMASK, GC_INT_EN);
550 return 0;
553 static int __devinit of_platform_mb862xx_probe(struct platform_device *ofdev)
555 struct device_node *np = ofdev->dev.of_node;
556 struct device *dev = &ofdev->dev;
557 struct mb862xxfb_par *par;
558 struct fb_info *info;
559 struct resource res;
560 resource_size_t res_size;
561 unsigned long ret = -ENODEV;
563 if (of_address_to_resource(np, 0, &res)) {
564 dev_err(dev, "Invalid address\n");
565 return -ENXIO;
568 info = framebuffer_alloc(sizeof(struct mb862xxfb_par), dev);
569 if (info == NULL) {
570 dev_err(dev, "cannot allocate framebuffer\n");
571 return -ENOMEM;
574 par = info->par;
575 par->info = info;
576 par->dev = dev;
578 par->irq = irq_of_parse_and_map(np, 0);
579 if (par->irq == NO_IRQ) {
580 dev_err(dev, "failed to map irq\n");
581 ret = -ENODEV;
582 goto fbrel;
585 res_size = 1 + res.end - res.start;
586 par->res = request_mem_region(res.start, res_size, DRV_NAME);
587 if (par->res == NULL) {
588 dev_err(dev, "Cannot claim framebuffer/mmio\n");
589 ret = -ENXIO;
590 goto irqdisp;
593 #if defined(CONFIG_SOCRATES)
594 par->gc_mode = &socrates_gc_mode;
595 #endif
597 par->fb_base_phys = res.start;
598 par->mmio_base_phys = res.start + MB862XX_MMIO_BASE;
599 par->mmio_len = MB862XX_MMIO_SIZE;
600 if (par->gc_mode)
601 par->mapped_vram = par->gc_mode->max_vram;
602 else
603 par->mapped_vram = MB862XX_MEM_SIZE;
605 par->fb_base = ioremap(par->fb_base_phys, par->mapped_vram);
606 if (par->fb_base == NULL) {
607 dev_err(dev, "Cannot map framebuffer\n");
608 goto rel_reg;
611 par->mmio_base = ioremap(par->mmio_base_phys, par->mmio_len);
612 if (par->mmio_base == NULL) {
613 dev_err(dev, "Cannot map registers\n");
614 goto fb_unmap;
617 dev_dbg(dev, "fb phys 0x%llx 0x%lx\n",
618 (u64)par->fb_base_phys, (ulong)par->mapped_vram);
619 dev_dbg(dev, "mmio phys 0x%llx 0x%lx, (irq = %d)\n",
620 (u64)par->mmio_base_phys, (ulong)par->mmio_len, par->irq);
622 if (mb862xx_gdc_init(par))
623 goto io_unmap;
625 if (request_irq(par->irq, mb862xx_intr, IRQF_DISABLED,
626 DRV_NAME, (void *)par)) {
627 dev_err(dev, "Cannot request irq\n");
628 goto io_unmap;
631 mb862xxfb_init_fbinfo(info);
633 if (fb_alloc_cmap(&info->cmap, NR_PALETTE, 0) < 0) {
634 dev_err(dev, "Could not allocate cmap for fb_info.\n");
635 goto free_irq;
638 if ((info->fbops->fb_set_par)(info))
639 dev_err(dev, "set_var() failed on initial setup?\n");
641 if (register_framebuffer(info)) {
642 dev_err(dev, "failed to register framebuffer\n");
643 goto rel_cmap;
646 dev_set_drvdata(dev, info);
648 if (device_create_file(dev, &dev_attr_dispregs))
649 dev_err(dev, "Can't create sysfs regdump file\n");
650 return 0;
652 rel_cmap:
653 fb_dealloc_cmap(&info->cmap);
654 free_irq:
655 outreg(host, GC_IMASK, 0);
656 free_irq(par->irq, (void *)par);
657 io_unmap:
658 iounmap(par->mmio_base);
659 fb_unmap:
660 iounmap(par->fb_base);
661 rel_reg:
662 release_mem_region(res.start, res_size);
663 irqdisp:
664 irq_dispose_mapping(par->irq);
665 fbrel:
666 dev_set_drvdata(dev, NULL);
667 framebuffer_release(info);
668 return ret;
671 static int __devexit of_platform_mb862xx_remove(struct platform_device *ofdev)
673 struct fb_info *fbi = dev_get_drvdata(&ofdev->dev);
674 struct mb862xxfb_par *par = fbi->par;
675 resource_size_t res_size = 1 + par->res->end - par->res->start;
676 unsigned long reg;
678 dev_dbg(fbi->dev, "%s release\n", fbi->fix.id);
680 /* display off */
681 reg = inreg(disp, GC_DCM1);
682 reg &= ~(GC_DCM01_DEN | GC_DCM01_L0E);
683 outreg(disp, GC_DCM1, reg);
685 /* disable interrupts */
686 outreg(host, GC_IMASK, 0);
688 free_irq(par->irq, (void *)par);
689 irq_dispose_mapping(par->irq);
691 device_remove_file(&ofdev->dev, &dev_attr_dispregs);
693 unregister_framebuffer(fbi);
694 fb_dealloc_cmap(&fbi->cmap);
696 iounmap(par->mmio_base);
697 iounmap(par->fb_base);
699 dev_set_drvdata(&ofdev->dev, NULL);
700 release_mem_region(par->res->start, res_size);
701 framebuffer_release(fbi);
702 return 0;
706 * common types
708 static struct of_device_id __devinitdata of_platform_mb862xx_tbl[] = {
709 { .compatible = "fujitsu,MB86276", },
710 { .compatible = "fujitsu,lime", },
711 { .compatible = "fujitsu,MB86277", },
712 { .compatible = "fujitsu,mint", },
713 { .compatible = "fujitsu,MB86293", },
714 { .compatible = "fujitsu,MB86294", },
715 { .compatible = "fujitsu,coral", },
716 { /* end */ }
719 static struct platform_driver of_platform_mb862xxfb_driver = {
720 .driver = {
721 .name = DRV_NAME,
722 .owner = THIS_MODULE,
723 .of_match_table = of_platform_mb862xx_tbl,
725 .probe = of_platform_mb862xx_probe,
726 .remove = __devexit_p(of_platform_mb862xx_remove),
728 #endif
730 #if defined(CONFIG_FB_MB862XX_PCI_GDC)
731 static int coralp_init(struct mb862xxfb_par *par)
733 int cn, ver;
735 par->host = par->mmio_base;
736 par->i2c = par->mmio_base + MB862XX_I2C_BASE;
737 par->disp = par->mmio_base + MB862XX_DISP_BASE;
738 par->cap = par->mmio_base + MB862XX_CAP_BASE;
739 par->draw = par->mmio_base + MB862XX_DRAW_BASE;
740 par->geo = par->mmio_base + MB862XX_GEO_BASE;
741 par->pio = par->mmio_base + MB862XX_PIO_BASE;
743 par->refclk = GC_DISP_REFCLK_400;
745 ver = inreg(host, GC_CID);
746 cn = (ver & GC_CID_CNAME_MSK) >> 8;
747 ver = ver & GC_CID_VERSION_MSK;
748 if (cn == 3) {
749 dev_info(par->dev, "Fujitsu Coral-%s GDC Rev.%d found\n",\
750 (ver == 6) ? "P" : (ver == 8) ? "PA" : "?",
751 par->pdev->revision);
752 outreg(host, GC_CCF, GC_CCF_CGE_166 | GC_CCF_COT_133);
753 udelay(200);
754 outreg(host, GC_MMR, GC_MMR_CORALP_EVB_VAL);
755 udelay(10);
756 /* Clear interrupt status */
757 outreg(host, GC_IST, 0);
758 } else {
759 return -ENODEV;
761 return 0;
764 static int init_dram_ctrl(struct mb862xxfb_par *par)
766 unsigned long i = 0;
769 * Set io mode first! Spec. says IC may be destroyed
770 * if not set to SSTL2/LVCMOS before init.
772 outreg(dram_ctrl, GC_DCTL_IOCONT1_IOCONT0, GC_EVB_DCTL_IOCONT1_IOCONT0);
774 /* DRAM init */
775 outreg(dram_ctrl, GC_DCTL_MODE_ADD, GC_EVB_DCTL_MODE_ADD);
776 outreg(dram_ctrl, GC_DCTL_SETTIME1_EMODE, GC_EVB_DCTL_SETTIME1_EMODE);
777 outreg(dram_ctrl, GC_DCTL_REFRESH_SETTIME2,
778 GC_EVB_DCTL_REFRESH_SETTIME2);
779 outreg(dram_ctrl, GC_DCTL_RSV2_RSV1, GC_EVB_DCTL_RSV2_RSV1);
780 outreg(dram_ctrl, GC_DCTL_DDRIF2_DDRIF1, GC_EVB_DCTL_DDRIF2_DDRIF1);
781 outreg(dram_ctrl, GC_DCTL_RSV0_STATES, GC_EVB_DCTL_RSV0_STATES);
783 /* DLL reset done? */
784 while ((inreg(dram_ctrl, GC_DCTL_RSV0_STATES) & GC_DCTL_STATES_MSK)) {
785 udelay(GC_DCTL_INIT_WAIT_INTERVAL);
786 if (i++ > GC_DCTL_INIT_WAIT_CNT) {
787 dev_err(par->dev, "VRAM init failed.\n");
788 return -EINVAL;
791 outreg(dram_ctrl, GC_DCTL_MODE_ADD, GC_EVB_DCTL_MODE_ADD_AFT_RST);
792 outreg(dram_ctrl, GC_DCTL_RSV0_STATES, GC_EVB_DCTL_RSV0_STATES_AFT_RST);
793 return 0;
796 static int carmine_init(struct mb862xxfb_par *par)
798 unsigned long reg;
800 par->ctrl = par->mmio_base + MB86297_CTRL_BASE;
801 par->i2c = par->mmio_base + MB86297_I2C_BASE;
802 par->disp = par->mmio_base + MB86297_DISP0_BASE;
803 par->disp1 = par->mmio_base + MB86297_DISP1_BASE;
804 par->cap = par->mmio_base + MB86297_CAP0_BASE;
805 par->cap1 = par->mmio_base + MB86297_CAP1_BASE;
806 par->draw = par->mmio_base + MB86297_DRAW_BASE;
807 par->dram_ctrl = par->mmio_base + MB86297_DRAMCTRL_BASE;
808 par->wrback = par->mmio_base + MB86297_WRBACK_BASE;
810 par->refclk = GC_DISP_REFCLK_533;
812 /* warm up */
813 reg = GC_CTRL_CLK_EN_DRAM | GC_CTRL_CLK_EN_2D3D | GC_CTRL_CLK_EN_DISP0;
814 outreg(ctrl, GC_CTRL_CLK_ENABLE, reg);
816 /* check for engine module revision */
817 if (inreg(draw, GC_2D3D_REV) == GC_RE_REVISION)
818 dev_info(par->dev, "Fujitsu Carmine GDC Rev.%d found\n",
819 par->pdev->revision);
820 else
821 goto err_init;
823 reg &= ~GC_CTRL_CLK_EN_2D3D;
824 outreg(ctrl, GC_CTRL_CLK_ENABLE, reg);
826 /* set up vram */
827 if (init_dram_ctrl(par) < 0)
828 goto err_init;
830 outreg(ctrl, GC_CTRL_INT_MASK, 0);
831 return 0;
833 err_init:
834 outreg(ctrl, GC_CTRL_CLK_ENABLE, 0);
835 return -EINVAL;
838 static inline int mb862xx_pci_gdc_init(struct mb862xxfb_par *par)
840 switch (par->type) {
841 case BT_CORALP:
842 return coralp_init(par);
843 case BT_CARMINE:
844 return carmine_init(par);
845 default:
846 return -ENODEV;
850 #define CHIP_ID(id) \
851 { PCI_DEVICE(PCI_VENDOR_ID_FUJITSU_LIMITED, id) }
853 static struct pci_device_id mb862xx_pci_tbl[] __devinitdata = {
854 /* MB86295/MB86296 */
855 CHIP_ID(PCI_DEVICE_ID_FUJITSU_CORALP),
856 CHIP_ID(PCI_DEVICE_ID_FUJITSU_CORALPA),
857 /* MB86297 */
858 CHIP_ID(PCI_DEVICE_ID_FUJITSU_CARMINE),
859 { 0, }
862 MODULE_DEVICE_TABLE(pci, mb862xx_pci_tbl);
864 static int __devinit mb862xx_pci_probe(struct pci_dev *pdev,
865 const struct pci_device_id *ent)
867 struct mb862xxfb_par *par;
868 struct fb_info *info;
869 struct device *dev = &pdev->dev;
870 int ret;
872 ret = pci_enable_device(pdev);
873 if (ret < 0) {
874 dev_err(dev, "Cannot enable PCI device\n");
875 goto out;
878 info = framebuffer_alloc(sizeof(struct mb862xxfb_par), dev);
879 if (!info) {
880 dev_err(dev, "framebuffer alloc failed\n");
881 ret = -ENOMEM;
882 goto dis_dev;
885 par = info->par;
886 par->info = info;
887 par->dev = dev;
888 par->pdev = pdev;
889 par->irq = pdev->irq;
891 ret = pci_request_regions(pdev, DRV_NAME);
892 if (ret < 0) {
893 dev_err(dev, "Cannot reserve region(s) for PCI device\n");
894 goto rel_fb;
897 switch (pdev->device) {
898 case PCI_DEVICE_ID_FUJITSU_CORALP:
899 case PCI_DEVICE_ID_FUJITSU_CORALPA:
900 par->fb_base_phys = pci_resource_start(par->pdev, 0);
901 par->mapped_vram = CORALP_MEM_SIZE;
902 par->mmio_base_phys = par->fb_base_phys + MB862XX_MMIO_BASE;
903 par->mmio_len = MB862XX_MMIO_SIZE;
904 par->type = BT_CORALP;
905 break;
906 case PCI_DEVICE_ID_FUJITSU_CARMINE:
907 par->fb_base_phys = pci_resource_start(par->pdev, 2);
908 par->mmio_base_phys = pci_resource_start(par->pdev, 3);
909 par->mmio_len = pci_resource_len(par->pdev, 3);
910 par->mapped_vram = CARMINE_MEM_SIZE;
911 par->type = BT_CARMINE;
912 break;
913 default:
914 /* should never occur */
915 goto rel_reg;
918 par->fb_base = ioremap(par->fb_base_phys, par->mapped_vram);
919 if (par->fb_base == NULL) {
920 dev_err(dev, "Cannot map framebuffer\n");
921 goto rel_reg;
924 par->mmio_base = ioremap(par->mmio_base_phys, par->mmio_len);
925 if (par->mmio_base == NULL) {
926 dev_err(dev, "Cannot map registers\n");
927 ret = -EIO;
928 goto fb_unmap;
931 dev_dbg(dev, "fb phys 0x%llx 0x%lx\n",
932 (unsigned long long)par->fb_base_phys, (ulong)par->mapped_vram);
933 dev_dbg(dev, "mmio phys 0x%llx 0x%lx\n",
934 (unsigned long long)par->mmio_base_phys, (ulong)par->mmio_len);
936 if (mb862xx_pci_gdc_init(par))
937 goto io_unmap;
939 if (request_irq(par->irq, mb862xx_intr, IRQF_DISABLED | IRQF_SHARED,
940 DRV_NAME, (void *)par)) {
941 dev_err(dev, "Cannot request irq\n");
942 goto io_unmap;
945 mb862xxfb_init_fbinfo(info);
947 if (fb_alloc_cmap(&info->cmap, NR_PALETTE, 0) < 0) {
948 dev_err(dev, "Could not allocate cmap for fb_info.\n");
949 ret = -ENOMEM;
950 goto free_irq;
953 if ((info->fbops->fb_set_par)(info))
954 dev_err(dev, "set_var() failed on initial setup?\n");
956 ret = register_framebuffer(info);
957 if (ret < 0) {
958 dev_err(dev, "failed to register framebuffer\n");
959 goto rel_cmap;
962 pci_set_drvdata(pdev, info);
964 if (device_create_file(dev, &dev_attr_dispregs))
965 dev_err(dev, "Can't create sysfs regdump file\n");
967 if (par->type == BT_CARMINE)
968 outreg(ctrl, GC_CTRL_INT_MASK, GC_CARMINE_INT_EN);
969 else
970 outreg(host, GC_IMASK, GC_INT_EN);
972 return 0;
974 rel_cmap:
975 fb_dealloc_cmap(&info->cmap);
976 free_irq:
977 free_irq(par->irq, (void *)par);
978 io_unmap:
979 iounmap(par->mmio_base);
980 fb_unmap:
981 iounmap(par->fb_base);
982 rel_reg:
983 pci_release_regions(pdev);
984 rel_fb:
985 framebuffer_release(info);
986 dis_dev:
987 pci_disable_device(pdev);
988 out:
989 return ret;
992 static void __devexit mb862xx_pci_remove(struct pci_dev *pdev)
994 struct fb_info *fbi = pci_get_drvdata(pdev);
995 struct mb862xxfb_par *par = fbi->par;
996 unsigned long reg;
998 dev_dbg(fbi->dev, "%s release\n", fbi->fix.id);
1000 /* display off */
1001 reg = inreg(disp, GC_DCM1);
1002 reg &= ~(GC_DCM01_DEN | GC_DCM01_L0E);
1003 outreg(disp, GC_DCM1, reg);
1005 if (par->type == BT_CARMINE) {
1006 outreg(ctrl, GC_CTRL_INT_MASK, 0);
1007 outreg(ctrl, GC_CTRL_CLK_ENABLE, 0);
1008 } else {
1009 outreg(host, GC_IMASK, 0);
1012 device_remove_file(&pdev->dev, &dev_attr_dispregs);
1014 pci_set_drvdata(pdev, NULL);
1015 unregister_framebuffer(fbi);
1016 fb_dealloc_cmap(&fbi->cmap);
1018 free_irq(par->irq, (void *)par);
1019 iounmap(par->mmio_base);
1020 iounmap(par->fb_base);
1022 pci_release_regions(pdev);
1023 framebuffer_release(fbi);
1024 pci_disable_device(pdev);
1027 static struct pci_driver mb862xxfb_pci_driver = {
1028 .name = DRV_NAME,
1029 .id_table = mb862xx_pci_tbl,
1030 .probe = mb862xx_pci_probe,
1031 .remove = __devexit_p(mb862xx_pci_remove),
1033 #endif
1035 static int __devinit mb862xxfb_init(void)
1037 int ret = -ENODEV;
1039 #if defined(CONFIG_FB_MB862XX_LIME)
1040 ret = platform_driver_register(&of_platform_mb862xxfb_driver);
1041 #endif
1042 #if defined(CONFIG_FB_MB862XX_PCI_GDC)
1043 ret = pci_register_driver(&mb862xxfb_pci_driver);
1044 #endif
1045 return ret;
1048 static void __exit mb862xxfb_exit(void)
1050 #if defined(CONFIG_FB_MB862XX_LIME)
1051 platform_driver_unregister(&of_platform_mb862xxfb_driver);
1052 #endif
1053 #if defined(CONFIG_FB_MB862XX_PCI_GDC)
1054 pci_unregister_driver(&mb862xxfb_pci_driver);
1055 #endif
1058 module_init(mb862xxfb_init);
1059 module_exit(mb862xxfb_exit);
1061 MODULE_DESCRIPTION("Fujitsu MB862xx Framebuffer driver");
1062 MODULE_AUTHOR("Anatolij Gustschin <agust@denx.de>");
1063 MODULE_LICENSE("GPL v2");