2 * drivers/video/chipsfb.c -- frame buffer device for
3 * Chips & Technologies 65550 chip.
5 * Copyright (C) 1998-2002 Paul Mackerras
7 * This file is derived from the Powermac "chips" driver:
8 * Copyright (C) 1997 Fabio Riccardi.
9 * And from the frame buffer device for Open Firmware-initialized devices:
10 * Copyright (C) 1997 Geert Uytterhoeven.
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file COPYING in the main directory of this archive for
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/string.h>
23 #include <linux/tty.h>
24 #include <linux/slab.h>
25 #include <linux/vmalloc.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/pci.h>
31 #include <linux/console.h>
34 #ifdef CONFIG_PMAC_BACKLIGHT
35 #include <asm/backlight.h>
39 * Since we access the display with inb/outb to fixed port numbers,
40 * we can only handle one 6555x chip. -- paulus
42 #define write_ind(num, val, ap, dp) do { \
43 outb((num), (ap)); outb((val), (dp)); \
45 #define read_ind(num, var, ap, dp) do { \
46 outb((num), (ap)); var = inb((dp)); \
49 /* extension registers */
50 #define write_xr(num, val) write_ind(num, val, 0x3d6, 0x3d7)
51 #define read_xr(num, var) read_ind(num, var, 0x3d6, 0x3d7)
52 /* flat panel registers */
53 #define write_fr(num, val) write_ind(num, val, 0x3d0, 0x3d1)
54 #define read_fr(num, var) read_ind(num, var, 0x3d0, 0x3d1)
56 #define write_cr(num, val) write_ind(num, val, 0x3d4, 0x3d5)
57 #define read_cr(num, var) read_ind(num, var, 0x3d4, 0x3d5)
58 /* graphics registers */
59 #define write_gr(num, val) write_ind(num, val, 0x3ce, 0x3cf)
60 #define read_gr(num, var) read_ind(num, var, 0x3ce, 0x3cf)
61 /* sequencer registers */
62 #define write_sr(num, val) write_ind(num, val, 0x3c4, 0x3c5)
63 #define read_sr(num, var) read_ind(num, var, 0x3c4, 0x3c5)
64 /* attribute registers - slightly strange */
65 #define write_ar(num, val) do { \
66 inb(0x3da); write_ind(num, val, 0x3c0, 0x3c0); \
68 #define read_ar(num, var) do { \
69 inb(0x3da); read_ind(num, var, 0x3c0, 0x3c1); \
77 static int chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *);
78 static int chipsfb_check_var(struct fb_var_screeninfo *var,
79 struct fb_info *info);
80 static int chipsfb_set_par(struct fb_info *info);
81 static int chipsfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
82 u_int transp, struct fb_info *info);
83 static int chipsfb_blank(int blank, struct fb_info *info);
85 static struct fb_ops chipsfb_ops = {
87 .fb_check_var = chipsfb_check_var,
88 .fb_set_par = chipsfb_set_par,
89 .fb_setcolreg = chipsfb_setcolreg,
90 .fb_blank = chipsfb_blank,
91 .fb_fillrect = cfb_fillrect,
92 .fb_copyarea = cfb_copyarea,
93 .fb_imageblit = cfb_imageblit,
96 static int chipsfb_check_var(struct fb_var_screeninfo *var,
99 if (var->xres > 800 || var->yres > 600
100 || var->xres_virtual > 800 || var->yres_virtual > 600
101 || (var->bits_per_pixel != 8 && var->bits_per_pixel != 16)
103 || (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
106 var->xres = var->xres_virtual = 800;
107 var->yres = var->yres_virtual = 600;
112 static int chipsfb_set_par(struct fb_info *info)
114 if (info->var.bits_per_pixel == 16) {
115 write_cr(0x13, 200); // Set line length (doublewords)
116 write_xr(0x81, 0x14); // 15 bit (555) color mode
117 write_xr(0x82, 0x00); // Disable palettes
118 write_xr(0x20, 0x10); // 16 bit blitter mode
120 info->fix.line_length = 800*2;
121 info->fix.visual = FB_VISUAL_TRUECOLOR;
123 info->var.red.offset = 10;
124 info->var.green.offset = 5;
125 info->var.blue.offset = 0;
126 info->var.red.length = info->var.green.length =
127 info->var.blue.length = 5;
130 /* p->var.bits_per_pixel == 8 */
131 write_cr(0x13, 100); // Set line length (doublewords)
132 write_xr(0x81, 0x12); // 8 bit color mode
133 write_xr(0x82, 0x08); // Graphics gamma enable
134 write_xr(0x20, 0x00); // 8 bit blitter mode
136 info->fix.line_length = 800;
137 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
139 info->var.red.offset = info->var.green.offset =
140 info->var.blue.offset = 0;
141 info->var.red.length = info->var.green.length =
142 info->var.blue.length = 8;
148 static int chipsfb_blank(int blank, struct fb_info *info)
150 #ifdef CONFIG_PMAC_BACKLIGHT
151 // used to disable backlight only for blank > 1, but it seems
152 // useful at blank = 1 too (saves battery, extends backlight life)
153 set_backlight_enable(!blank);
154 #endif /* CONFIG_PMAC_BACKLIGHT */
156 return 1; /* get fb_blank to set the colormap to all black */
159 static int chipsfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
160 u_int transp, struct fb_info *info)
176 struct chips_init_reg {
181 #define N_ELTS(x) (sizeof(x) / sizeof(x[0]))
183 static struct chips_init_reg chips_init_sr[] = {
190 static struct chips_init_reg chips_init_gr[] = {
196 static struct chips_init_reg chips_init_ar[] = {
202 static struct chips_init_reg chips_init_cr[] = {
233 static struct chips_init_reg chips_init_fr[] = {
243 /* { 0x12, 0x40 }, -- 3400 needs 40, 2400 needs 48, no way to tell */
261 static struct chips_init_reg chips_init_xr[] = {
262 { 0xce, 0x00 }, /* set default memory clock */
263 { 0xcc, 0x43 }, /* memory clock ratio */
286 static void __init chips_hw_init(void)
290 for (i = 0; i < N_ELTS(chips_init_xr); ++i)
291 write_xr(chips_init_xr[i].addr, chips_init_xr[i].data);
292 outb(0x29, 0x3c2); /* set misc output reg */
293 for (i = 0; i < N_ELTS(chips_init_sr); ++i)
294 write_sr(chips_init_sr[i].addr, chips_init_sr[i].data);
295 for (i = 0; i < N_ELTS(chips_init_gr); ++i)
296 write_gr(chips_init_gr[i].addr, chips_init_gr[i].data);
297 for (i = 0; i < N_ELTS(chips_init_ar); ++i)
298 write_ar(chips_init_ar[i].addr, chips_init_ar[i].data);
299 for (i = 0; i < N_ELTS(chips_init_cr); ++i)
300 write_cr(chips_init_cr[i].addr, chips_init_cr[i].data);
301 for (i = 0; i < N_ELTS(chips_init_fr); ++i)
302 write_fr(chips_init_fr[i].addr, chips_init_fr[i].data);
305 static struct fb_fix_screeninfo chipsfb_fix __initdata = {
307 .type = FB_TYPE_PACKED_PIXELS,
308 .visual = FB_VISUAL_PSEUDOCOLOR,
309 .accel = FB_ACCEL_NONE,
312 // FIXME: Assumes 1MB frame buffer, but 65550 supports 1MB or 2MB.
313 // * "3500" PowerBook G3 (the original PB G3) has 2MB.
314 // * 2400 has 1MB composed of 2 Mitsubishi M5M4V4265CTP DRAM chips.
315 // Motherboard actually supports 2MB -- there are two blank locations
316 // for a second pair of DRAMs. (Thanks, Apple!)
317 // * 3400 has 1MB (I think). Don't know if it's expandable.
319 .smem_len = 0x100000, /* 1MB */
322 static struct fb_var_screeninfo chipsfb_var __initdata = {
328 .red = { .length = 8 },
329 .green = { .length = 8 },
330 .blue = { .length = 8 },
333 .vmode = FB_VMODE_NONINTERLACED,
343 static void __init init_chips(struct fb_info *p, unsigned long addr)
345 memset(p->screen_base, 0, 0x100000);
347 p->fix = chipsfb_fix;
348 p->fix.smem_start = addr;
350 p->var = chipsfb_var;
352 p->fbops = &chipsfb_ops;
353 p->flags = FBINFO_DEFAULT;
355 fb_alloc_cmap(&p->cmap, 256, 0);
361 chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
364 unsigned long addr, size;
368 if (pci_enable_device(dp) < 0) {
369 dev_err(&dp->dev, "Cannot enable PCI device\n");
373 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0)
375 addr = pci_resource_start(dp, 0);
376 size = pci_resource_len(dp, 0);
380 p = framebuffer_alloc(0, &dp->dev);
382 dev_err(&dp->dev, "Cannot allocate framebuffer structure\n");
387 if (pci_request_region(dp, 0, "chipsfb") != 0) {
388 dev_err(&dp->dev, "Cannot request framebuffer\n");
394 addr += 0x800000; // Use big-endian aperture
397 /* we should use pci_enable_device here, but,
398 the device doesn't declare its I/O ports in its BARs
399 so pci_enable_device won't turn on I/O responses */
400 pci_read_config_word(dp, PCI_COMMAND, &cmd);
401 cmd |= 3; /* enable memory and IO space */
402 pci_write_config_word(dp, PCI_COMMAND, cmd);
404 #ifdef CONFIG_PMAC_BACKLIGHT
405 /* turn on the backlight */
406 set_backlight_enable(1);
407 #endif /* CONFIG_PMAC_BACKLIGHT */
410 p->screen_base = __ioremap(addr, 0x200000, _PAGE_NO_CACHE);
412 p->screen_base = ioremap(addr, 0x200000);
414 if (p->screen_base == NULL) {
415 dev_err(&dp->dev, "Cannot map framebuffer\n");
417 goto err_release_pci;
420 pci_set_drvdata(dp, p);
421 p->device = &dp->dev;
425 if (register_framebuffer(p) < 0) {
426 dev_err(&dp->dev,"C&T 65550 framebuffer failed to register\n");
430 dev_info(&dp->dev,"fb%d: Chips 65550 frame buffer"
431 " (%dK RAM detected)\n",
432 p->node, p->fix.smem_len / 1024);
437 iounmap(p->screen_base);
439 pci_release_region(dp, 0);
441 framebuffer_release(p);
447 static void __devexit chipsfb_remove(struct pci_dev *dp)
449 struct fb_info *p = pci_get_drvdata(dp);
451 if (p->screen_base == NULL)
453 unregister_framebuffer(p);
454 iounmap(p->screen_base);
455 p->screen_base = NULL;
456 pci_release_region(dp, 0);
460 static int chipsfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
462 struct fb_info *p = pci_get_drvdata(pdev);
464 if (state.event == pdev->dev.power.power_state.event)
466 if (state.event != PM_SUSPEND_MEM)
469 acquire_console_sem();
471 fb_set_suspend(p, 1);
472 release_console_sem();
474 pdev->dev.power.power_state = state;
478 static int chipsfb_pci_resume(struct pci_dev *pdev)
480 struct fb_info *p = pci_get_drvdata(pdev);
482 acquire_console_sem();
483 fb_set_suspend(p, 0);
485 release_console_sem();
487 pdev->dev.power.power_state = PMSG_ON;
490 #endif /* CONFIG_PM */
493 static struct pci_device_id chipsfb_pci_tbl[] = {
494 { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_65550, PCI_ANY_ID, PCI_ANY_ID },
498 MODULE_DEVICE_TABLE(pci, chipsfb_pci_tbl);
500 static struct pci_driver chipsfb_driver = {
502 .id_table = chipsfb_pci_tbl,
503 .probe = chipsfb_pci_init,
504 .remove = __devexit_p(chipsfb_remove),
506 .suspend = chipsfb_pci_suspend,
507 .resume = chipsfb_pci_resume,
511 int __init chips_init(void)
513 if (fb_get_options("chipsfb", NULL))
516 return pci_register_driver(&chipsfb_driver);
519 module_init(chips_init);
521 static void __exit chipsfb_exit(void)
523 pci_unregister_driver(&chipsfb_driver);
526 MODULE_LICENSE("GPL");