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/module.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
22 #include <linux/vmalloc.h>
23 #include <linux/delay.h>
24 #include <linux/interrupt.h>
27 #include <linux/init.h>
28 #include <linux/pci.h>
29 #include <linux/console.h>
31 #ifdef CONFIG_PMAC_BACKLIGHT
32 #include <asm/backlight.h>
36 * Since we access the display with inb/outb to fixed port numbers,
37 * we can only handle one 6555x chip. -- paulus
39 #define write_ind(num, val, ap, dp) do { \
40 outb((num), (ap)); outb((val), (dp)); \
42 #define read_ind(num, var, ap, dp) do { \
43 outb((num), (ap)); var = inb((dp)); \
46 /* extension registers */
47 #define write_xr(num, val) write_ind(num, val, 0x3d6, 0x3d7)
48 #define read_xr(num, var) read_ind(num, var, 0x3d6, 0x3d7)
49 /* flat panel registers */
50 #define write_fr(num, val) write_ind(num, val, 0x3d0, 0x3d1)
51 #define read_fr(num, var) read_ind(num, var, 0x3d0, 0x3d1)
53 #define write_cr(num, val) write_ind(num, val, 0x3d4, 0x3d5)
54 #define read_cr(num, var) read_ind(num, var, 0x3d4, 0x3d5)
55 /* graphics registers */
56 #define write_gr(num, val) write_ind(num, val, 0x3ce, 0x3cf)
57 #define read_gr(num, var) read_ind(num, var, 0x3ce, 0x3cf)
58 /* sequencer registers */
59 #define write_sr(num, val) write_ind(num, val, 0x3c4, 0x3c5)
60 #define read_sr(num, var) read_ind(num, var, 0x3c4, 0x3c5)
61 /* attribute registers - slightly strange */
62 #define write_ar(num, val) do { \
63 inb(0x3da); write_ind(num, val, 0x3c0, 0x3c0); \
65 #define read_ar(num, var) do { \
66 inb(0x3da); read_ind(num, var, 0x3c0, 0x3c1); \
74 static int chipsfb_pci_init(struct pci_dev
*dp
, const struct pci_device_id
*);
75 static int chipsfb_check_var(struct fb_var_screeninfo
*var
,
76 struct fb_info
*info
);
77 static int chipsfb_set_par(struct fb_info
*info
);
78 static int chipsfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
79 u_int transp
, struct fb_info
*info
);
80 static int chipsfb_blank(int blank
, struct fb_info
*info
);
82 static const struct fb_ops chipsfb_ops
= {
84 .fb_check_var
= chipsfb_check_var
,
85 .fb_set_par
= chipsfb_set_par
,
86 .fb_setcolreg
= chipsfb_setcolreg
,
87 .fb_blank
= chipsfb_blank
,
88 .fb_fillrect
= cfb_fillrect
,
89 .fb_copyarea
= cfb_copyarea
,
90 .fb_imageblit
= cfb_imageblit
,
93 static int chipsfb_check_var(struct fb_var_screeninfo
*var
,
96 if (var
->xres
> 800 || var
->yres
> 600
97 || var
->xres_virtual
> 800 || var
->yres_virtual
> 600
98 || (var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16)
100 || (var
->vmode
& FB_VMODE_MASK
) != FB_VMODE_NONINTERLACED
)
103 var
->xres
= var
->xres_virtual
= 800;
104 var
->yres
= var
->yres_virtual
= 600;
109 static int chipsfb_set_par(struct fb_info
*info
)
111 if (info
->var
.bits_per_pixel
== 16) {
112 write_cr(0x13, 200); // Set line length (doublewords)
113 write_xr(0x81, 0x14); // 15 bit (555) color mode
114 write_xr(0x82, 0x00); // Disable palettes
115 write_xr(0x20, 0x10); // 16 bit blitter mode
117 info
->fix
.line_length
= 800*2;
118 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
120 info
->var
.red
.offset
= 10;
121 info
->var
.green
.offset
= 5;
122 info
->var
.blue
.offset
= 0;
123 info
->var
.red
.length
= info
->var
.green
.length
=
124 info
->var
.blue
.length
= 5;
127 /* p->var.bits_per_pixel == 8 */
128 write_cr(0x13, 100); // Set line length (doublewords)
129 write_xr(0x81, 0x12); // 8 bit color mode
130 write_xr(0x82, 0x08); // Graphics gamma enable
131 write_xr(0x20, 0x00); // 8 bit blitter mode
133 info
->fix
.line_length
= 800;
134 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
136 info
->var
.red
.offset
= info
->var
.green
.offset
=
137 info
->var
.blue
.offset
= 0;
138 info
->var
.red
.length
= info
->var
.green
.length
=
139 info
->var
.blue
.length
= 8;
145 static int chipsfb_blank(int blank
, struct fb_info
*info
)
147 return 1; /* get fb_blank to set the colormap to all black */
150 static int chipsfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
151 u_int transp
, struct fb_info
*info
)
167 struct chips_init_reg
{
172 static struct chips_init_reg chips_init_sr
[] = {
179 static struct chips_init_reg chips_init_gr
[] = {
185 static struct chips_init_reg chips_init_ar
[] = {
191 static struct chips_init_reg chips_init_cr
[] = {
222 static struct chips_init_reg chips_init_fr
[] = {
232 /* { 0x12, 0x40 }, -- 3400 needs 40, 2400 needs 48, no way to tell */
250 static struct chips_init_reg chips_init_xr
[] = {
251 { 0xce, 0x00 }, /* set default memory clock */
252 { 0xcc, 0x43 }, /* memory clock ratio */
275 static void chips_hw_init(void)
279 for (i
= 0; i
< ARRAY_SIZE(chips_init_xr
); ++i
)
280 write_xr(chips_init_xr
[i
].addr
, chips_init_xr
[i
].data
);
281 outb(0x29, 0x3c2); /* set misc output reg */
282 for (i
= 0; i
< ARRAY_SIZE(chips_init_sr
); ++i
)
283 write_sr(chips_init_sr
[i
].addr
, chips_init_sr
[i
].data
);
284 for (i
= 0; i
< ARRAY_SIZE(chips_init_gr
); ++i
)
285 write_gr(chips_init_gr
[i
].addr
, chips_init_gr
[i
].data
);
286 for (i
= 0; i
< ARRAY_SIZE(chips_init_ar
); ++i
)
287 write_ar(chips_init_ar
[i
].addr
, chips_init_ar
[i
].data
);
288 for (i
= 0; i
< ARRAY_SIZE(chips_init_cr
); ++i
)
289 write_cr(chips_init_cr
[i
].addr
, chips_init_cr
[i
].data
);
290 for (i
= 0; i
< ARRAY_SIZE(chips_init_fr
); ++i
)
291 write_fr(chips_init_fr
[i
].addr
, chips_init_fr
[i
].data
);
294 static const struct fb_fix_screeninfo chipsfb_fix
= {
296 .type
= FB_TYPE_PACKED_PIXELS
,
297 .visual
= FB_VISUAL_PSEUDOCOLOR
,
298 .accel
= FB_ACCEL_NONE
,
301 // FIXME: Assumes 1MB frame buffer, but 65550 supports 1MB or 2MB.
302 // * "3500" PowerBook G3 (the original PB G3) has 2MB.
303 // * 2400 has 1MB composed of 2 Mitsubishi M5M4V4265CTP DRAM chips.
304 // Motherboard actually supports 2MB -- there are two blank locations
305 // for a second pair of DRAMs. (Thanks, Apple!)
306 // * 3400 has 1MB (I think). Don't know if it's expandable.
308 .smem_len
= 0x100000, /* 1MB */
311 static const struct fb_var_screeninfo chipsfb_var
= {
317 .red
= { .length
= 8 },
318 .green
= { .length
= 8 },
319 .blue
= { .length
= 8 },
322 .vmode
= FB_VMODE_NONINTERLACED
,
332 static void init_chips(struct fb_info
*p
, unsigned long addr
)
334 memset(p
->screen_base
, 0, 0x100000);
336 p
->fix
= chipsfb_fix
;
337 p
->fix
.smem_start
= addr
;
339 p
->var
= chipsfb_var
;
341 p
->fbops
= &chipsfb_ops
;
342 p
->flags
= FBINFO_DEFAULT
;
344 fb_alloc_cmap(&p
->cmap
, 256, 0);
349 static int chipsfb_pci_init(struct pci_dev
*dp
, const struct pci_device_id
*ent
)
356 if (pci_enable_device(dp
) < 0) {
357 dev_err(&dp
->dev
, "Cannot enable PCI device\n");
361 if ((dp
->resource
[0].flags
& IORESOURCE_MEM
) == 0)
363 addr
= pci_resource_start(dp
, 0);
367 p
= framebuffer_alloc(0, &dp
->dev
);
373 if (pci_request_region(dp
, 0, "chipsfb") != 0) {
374 dev_err(&dp
->dev
, "Cannot request framebuffer\n");
380 addr
+= 0x800000; // Use big-endian aperture
383 /* we should use pci_enable_device here, but,
384 the device doesn't declare its I/O ports in its BARs
385 so pci_enable_device won't turn on I/O responses */
386 pci_read_config_word(dp
, PCI_COMMAND
, &cmd
);
387 cmd
|= 3; /* enable memory and IO space */
388 pci_write_config_word(dp
, PCI_COMMAND
, cmd
);
390 #ifdef CONFIG_PMAC_BACKLIGHT
391 /* turn on the backlight */
392 mutex_lock(&pmac_backlight_mutex
);
393 if (pmac_backlight
) {
394 pmac_backlight
->props
.power
= FB_BLANK_UNBLANK
;
395 backlight_update_status(pmac_backlight
);
397 mutex_unlock(&pmac_backlight_mutex
);
398 #endif /* CONFIG_PMAC_BACKLIGHT */
401 p
->screen_base
= ioremap_wc(addr
, 0x200000);
403 p
->screen_base
= ioremap(addr
, 0x200000);
405 if (p
->screen_base
== NULL
) {
406 dev_err(&dp
->dev
, "Cannot map framebuffer\n");
408 goto err_release_pci
;
411 pci_set_drvdata(dp
, p
);
415 if (register_framebuffer(p
) < 0) {
416 dev_err(&dp
->dev
,"C&T 65550 framebuffer failed to register\n");
420 dev_info(&dp
->dev
,"fb%d: Chips 65550 frame buffer"
421 " (%dK RAM detected)\n",
422 p
->node
, p
->fix
.smem_len
/ 1024);
427 iounmap(p
->screen_base
);
429 pci_release_region(dp
, 0);
431 framebuffer_release(p
);
437 static void chipsfb_remove(struct pci_dev
*dp
)
439 struct fb_info
*p
= pci_get_drvdata(dp
);
441 if (p
->screen_base
== NULL
)
443 unregister_framebuffer(p
);
444 iounmap(p
->screen_base
);
445 p
->screen_base
= NULL
;
446 pci_release_region(dp
, 0);
450 static int chipsfb_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
452 struct fb_info
*p
= pci_get_drvdata(pdev
);
454 if (state
.event
== pdev
->dev
.power
.power_state
.event
)
456 if (!(state
.event
& PM_EVENT_SLEEP
))
461 fb_set_suspend(p
, 1);
464 pdev
->dev
.power
.power_state
= state
;
468 static int chipsfb_pci_resume(struct pci_dev
*pdev
)
470 struct fb_info
*p
= pci_get_drvdata(pdev
);
473 fb_set_suspend(p
, 0);
477 pdev
->dev
.power
.power_state
= PMSG_ON
;
480 #endif /* CONFIG_PM */
483 static struct pci_device_id chipsfb_pci_tbl
[] = {
484 { PCI_VENDOR_ID_CT
, PCI_DEVICE_ID_CT_65550
, PCI_ANY_ID
, PCI_ANY_ID
},
488 MODULE_DEVICE_TABLE(pci
, chipsfb_pci_tbl
);
490 static struct pci_driver chipsfb_driver
= {
492 .id_table
= chipsfb_pci_tbl
,
493 .probe
= chipsfb_pci_init
,
494 .remove
= chipsfb_remove
,
496 .suspend
= chipsfb_pci_suspend
,
497 .resume
= chipsfb_pci_resume
,
501 int __init
chips_init(void)
503 if (fb_get_options("chipsfb", NULL
))
506 return pci_register_driver(&chipsfb_driver
);
509 module_init(chips_init
);
511 static void __exit
chipsfb_exit(void)
513 pci_unregister_driver(&chipsfb_driver
);
516 MODULE_LICENSE("GPL");