47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/errno.h>
50 #include <linux/string.h>
52 #include <linux/slab.h>
57 #include <linux/pci.h>
59 #ifdef CONFIG_SH_DREAMCAST
60 #include <asm/machvec.h>
64 #ifdef CONFIG_PVR2_DMA
70 #ifdef CONFIG_SH_STORE_QUEUES
75 #ifndef PCI_DEVICE_ID_NEC_NEON250
76 # define PCI_DEVICE_ID_NEC_NEON250 0x0067
80 #define DISP_BASE par->mmio_base
81 #define DISP_BRDRCOLR (DISP_BASE + 0x40)
82 #define DISP_DIWMODE (DISP_BASE + 0x44)
83 #define DISP_DIWADDRL (DISP_BASE + 0x50)
84 #define DISP_DIWADDRS (DISP_BASE + 0x54)
85 #define DISP_DIWSIZE (DISP_BASE + 0x5c)
86 #define DISP_SYNCCONF (DISP_BASE + 0xd0)
87 #define DISP_BRDRHORZ (DISP_BASE + 0xd4)
88 #define DISP_SYNCSIZE (DISP_BASE + 0xd8)
89 #define DISP_BRDRVERT (DISP_BASE + 0xdc)
90 #define DISP_DIWCONF (DISP_BASE + 0xe8)
91 #define DISP_DIWHSTRT (DISP_BASE + 0xec)
92 #define DISP_DIWVSTRT (DISP_BASE + 0xf0)
93 #define DISP_PIXDEPTH (DISP_BASE + 0x108)
100 #define PAL_HTOTAL 863
101 #define PAL_VTOTAL 312
102 #define NTSC_HTOTAL 857
103 #define NTSC_VTOTAL 262
119 static struct pvr2_params outputs[] __devinitdata = {
127 static struct pvr2fb_par {
128 unsigned int hsync_total;
129 unsigned int vsync_total;
130 unsigned int borderstart_h;
131 unsigned int borderstop_h;
132 unsigned int borderstart_v;
133 unsigned int borderstop_v;
134 unsigned int diwstart_h;
135 unsigned int diwstart_v;
137 unsigned long disp_start;
138 unsigned char is_interlaced;
139 unsigned char is_doublescan;
140 unsigned char is_lowres;
149 .id =
"NEC PowerVR2",
164 .green = { 5, 6, 0 },
172 static int cable_type =
CT_VGA;
173 static int video_output =
VO_VGA;
175 static int nopan = 0;
176 static int nowrap = 1;
181 static unsigned int do_vmode_full = 0;
182 static unsigned int do_vmode_pan = 0;
183 static short do_blank = 0;
185 static unsigned int is_blanked = 0;
187 #ifdef CONFIG_SH_STORE_QUEUES
188 static unsigned long pvr2fb_map;
191 #ifdef CONFIG_PVR2_DMA
193 static unsigned int pvr2dma = ONCHIP_NR_DMA_CHANNELS;
196 static int pvr2fb_setcolreg(
unsigned int regno,
unsigned int red,
unsigned int green,
unsigned int blue,
198 static int pvr2fb_blank(
int blank,
struct fb_info *
info);
202 static int pvr2fb_set_par(
struct fb_info *
info);
203 static void pvr2_update_display(
struct fb_info *
info);
204 static void pvr2_init_display(
struct fb_info *
info);
205 static void pvr2_do_blank(
void);
207 static int pvr2_init_cable(
void);
208 static int pvr2_get_param(
const struct pvr2_params *
p,
const char *
s,
210 #ifdef CONFIG_PVR2_DMA
211 static ssize_t pvr2fb_write(
struct fb_info *
info,
const char *
buf,
212 size_t count, loff_t *ppos);
215 static struct fb_ops pvr2fb_ops = {
217 .fb_setcolreg = pvr2fb_setcolreg,
218 .fb_blank = pvr2fb_blank,
219 .fb_check_var = pvr2fb_check_var,
220 .fb_set_par = pvr2fb_set_par,
221 #ifdef CONFIG_PVR2_DMA
222 .fb_write = pvr2fb_write,
229 static struct fb_videomode pvr2_modedb[] __devinitdata = {
238 "ntsc_640x480i", 60, 640, 480,
TV_CLK, 38, 33, 0, 18, 146, 26,
243 "ntsc_640x240", 60, 640, 240,
TV_CLK, 38, 33, 0, 0, 146, 22,
247 "vga_640x480", 60, 640, 480,
VGA_CLK, 38, 33, 0, 18, 146, 26,
252 #define NUM_TOTAL_MODES ARRAY_SIZE(pvr2_modedb)
254 #define DEFMODE_NTSC 0
255 #define DEFMODE_PAL 0
256 #define DEFMODE_VGA 2
259 static char *mode_option __devinitdata =
NULL;
261 static inline void pvr2fb_set_pal_type(
unsigned int type)
263 struct pvr2fb_par *par = (
struct pvr2fb_par *)fb_info->
par;
268 static inline void pvr2fb_set_pal_entry(
struct pvr2fb_par *par,
272 fb_writel(val, par->mmio_base + 0x1000 + (4 * regno));
275 static int pvr2fb_blank(
int blank,
struct fb_info *
info)
277 do_blank = blank ? blank : -1;
281 static inline unsigned long get_line_length(
int xres_virtual,
int bpp)
283 return (
unsigned long)((((xres_virtual*
bpp)+31)&~31) >> 3);
291 var->
red.offset = 11; var->
red.length = 5;
293 var->
blue.offset = 0; var->
blue.length = 5;
297 var->
red.offset = 16; var->
red.length = 8;
299 var->
blue.offset = 0; var->
blue.length = 8;
304 var->
red.offset = 16; var->
red.length = 8;
306 var->
blue.offset = 0; var->
blue.length = 8;
312 static int pvr2fb_setcolreg(
unsigned int regno,
unsigned int red,
316 struct pvr2fb_par *par = (
struct pvr2fb_par *)info->
par;
319 if (regno > info->
cmap.len)
327 switch (info->
var.bits_per_pixel) {
329 tmp = (red & 0xf800) |
330 ((green & 0xfc00) >> 5) |
331 ((blue & 0xf800) >> 11);
333 pvr2fb_set_pal_entry(par, regno,
tmp);
336 red >>= 8; green >>= 8; blue >>= 8;
337 tmp = (red << 16) | (green << 8) |
blue;
340 red >>= 8; green >>= 8; blue >>= 8;
341 tmp = (transp << 24) | (red << 16) | (green << 8) | blue;
343 pvr2fb_set_pal_entry(par, regno,
tmp);
346 pr_debug(
"Invalid bit depth %d?!?\n", info->
var.bits_per_pixel);
356 static int pvr2fb_set_par(
struct fb_info *info)
358 struct pvr2fb_par *par = (
struct pvr2fb_par *)info->
par;
360 unsigned long line_length;
370 cable_type = pvr2_init_cable();
376 par->is_interlaced = 1;
382 par->is_doublescan = 1;
390 vtotal = par->vsync_total;
391 if (par->is_interlaced)
396 par->borderstart_h = 116;
397 par->borderstart_v = 44;
400 par->borderstart_h = 126;
401 par->borderstart_v = 18;
410 par->borderstart_h = 126;
411 par->borderstart_v = 40;
415 par->diwstart_h = par->borderstart_h + var->
left_margin;
416 par->diwstart_v = par->borderstart_v + var->
upper_margin;
417 par->borderstop_h = par->diwstart_h + var->
xres +
419 par->borderstop_v = par->diwstart_v + var->
yres +
422 if (!par->is_interlaced)
423 par->borderstop_v /= 2;
424 if (info->
var.xres < 640)
428 par->disp_start = info->
fix.smem_start + (line_length * var->
yoffset) * line_length;
429 info->
fix.line_length = line_length;
435 struct pvr2fb_par *par = (
struct pvr2fb_par *)info->
par;
436 unsigned int vtotal, hsync_total;
437 unsigned long line_length;
460 set_color_bitfields(var);
480 if (var->
yres < 480 && video_output ==
VO_VGA)
483 if (video_output !=
VO_VGA) {
494 (par->diwstart_h + var->
xres);
495 var->
left_margin = par->diwstart_h - par->borderstart_h;
497 (par->hsync_total - par->borderstop_h);
499 var->
upper_margin = par->diwstart_v - par->borderstart_v;
501 (par->diwstart_v + var->
yres);
503 (par->vsync_total - par->borderstop_v);
518 pr_debug(
"invalid hsync total for PAL\n");
524 pr_debug(
"invalid hsync total for NTSC\n");
538 static void pvr2_update_display(
struct fb_info *info)
540 struct pvr2fb_par *par = (
struct pvr2fb_par *) info->
par;
556 static void pvr2_init_display(
struct fb_info *info)
558 struct pvr2fb_par *par = (
struct pvr2fb_par *) info->
par;
560 unsigned int diw_height, diw_width, diw_modulo = 1;
569 if (video_output !=
VO_VGA && par->is_interlaced)
570 diw_modulo += info->
fix.line_length / 4;
571 diw_height = (par->is_interlaced ? var->
yres / 2 : var->
yres);
573 fb_writel((diw_modulo << 20) | (--diw_height << 10) | --diw_width,
609 #define BLANK_BIT (1<<3)
611 static void pvr2_do_blank(
void)
613 struct pvr2fb_par *par = currentpar;
614 unsigned long diwconf;
622 is_blanked = do_blank > 0 ? do_blank : 0;
627 struct fb_info *info =
dev_id;
629 if (do_vmode_pan || do_vmode_full)
630 pvr2_update_display(info);
632 pvr2_init_display(info);
649 #define PCTRA 0xff80002c
650 #define PDTRA 0xff800030
651 #define VOUTC 0xa0702c00
653 static int pvr2_init_cable(
void)
655 if (cable_type < 0) {
666 else if (cable_type ==
CT_RGB)
674 #ifdef CONFIG_PVR2_DMA
675 static ssize_t pvr2fb_write(
struct fb_info *info,
const char *
buf,
676 size_t count, loff_t *ppos)
679 unsigned int nr_pages;
694 if (ret < nr_pages) {
708 if (start + len == end) {
710 if ((*ppos + len) > fb_info->
fix.smem_len) {
715 dma_write(shdma, start, 0, len);
716 dma_write(pvr2dma, 0, dst, len);
723 for (i = 0; i < nr_pages; i++, dst +=
PAGE_SIZE) {
724 if ((*ppos + (i << PAGE_SHIFT)) > fb_info->
fix.smem_len) {
729 dma_write_page(shdma, (
unsigned long)
page_address(pages[i]), 0);
730 dma_write_page(pvr2dma, 0, dst);
739 for (i = 0; i < nr_pages; i++)
766 static int __devinit pvr2fb_common_init(
void)
768 struct pvr2fb_par *par = currentpar;
769 unsigned long modememused,
rev;
781 if (!par->mmio_base) {
788 pvr2_fix.ypanstep = nopan ? 0 : 1;
789 pvr2_fix.ywrapstep = nowrap ? 0 : 1;
791 fb_info->
fbops = &pvr2fb_ops;
792 fb_info->
fix = pvr2_fix;
793 fb_info->
par = currentpar;
797 if (video_output ==
VO_VGA)
801 mode_option =
"640x480@60";
805 fb_info->
var = pvr2_var;
812 pvr2_init_display(fb_info);
814 modememused = get_line_length(fb_info->
var.xres_virtual,
815 fb_info->
var.bits_per_pixel);
816 modememused *= fb_info->
var.yres_virtual;
818 rev =
fb_readl(par->mmio_base + 0x04);
820 printk(
"fb%d: %s (rev %ld.%ld) frame buffer device, using %ldk/%ldk of video memory\n",
821 fb_info->
node, fb_info->
fix.id, (rev >> 4) & 0x0f, rev & 0x0f,
822 modememused >> 10, (
unsigned long)(fb_info->
fix.smem_len >> 10));
823 printk(
"fb%d: Mode %dx%d-%d pitch = %ld cable: %s video output: %s\n",
824 fb_info->
node, fb_info->
var.xres, fb_info->
var.yres,
825 fb_info->
var.bits_per_pixel,
826 get_line_length(fb_info->
var.xres, fb_info->
var.bits_per_pixel),
827 (
char *)pvr2_get_param(cables,
NULL, cable_type, 3),
828 (
char *)pvr2_get_param(outputs,
NULL, video_output, 3));
830 #ifdef CONFIG_SH_STORE_QUEUES
833 pvr2fb_map =
sq_remap(fb_info->
fix.smem_start, fb_info->
fix.smem_len,
834 fb_info->
fix.id, PAGE_SHARED);
837 fb_info->
node, pvr2fb_map);
846 iounmap((
void *)par->mmio_base);
851 #ifdef CONFIG_SH_DREAMCAST
852 static int __init pvr2fb_dc_init(
void)
854 if (!mach_is_dreamcast())
858 if (pvr2_init_cable() ==
CT_VGA) {
874 if (video_output < 0) {
875 if (cable_type ==
CT_VGA) {
885 pvr2_fix.smem_start = 0xa5000000;
886 pvr2_fix.smem_len = 8 << 20;
888 pvr2_fix.mmio_start = 0xa05f8000;
889 pvr2_fix.mmio_len = 0x2000;
892 "pvr2 VBL handler", fb_info)) {
896 #ifdef CONFIG_PVR2_DMA
903 return pvr2fb_common_init();
906 static void __exit pvr2fb_dc_exit(
void)
912 if (currentpar->mmio_base) {
913 iounmap((
void *)currentpar->mmio_base);
914 currentpar->mmio_base = 0;
918 #ifdef CONFIG_PVR2_DMA
953 return pvr2fb_common_init();
962 if (currentpar->mmio_base) {
963 iounmap((
void *)currentpar->mmio_base);
964 currentpar->mmio_base = 0;
970 static struct pci_device_id pvr2fb_pci_tbl[] __devinitdata = {
978 static struct pci_driver pvr2fb_pci_driver = {
980 .id_table = pvr2fb_pci_tbl,
981 .probe = pvr2fb_pci_probe,
985 static int __init pvr2fb_pci_init(
void)
987 return pci_register_driver(&pvr2fb_pci_driver);
990 static void __exit pvr2fb_pci_exit(
void)
1001 for (i = 0 ; i <
size ; i++ ) {
1006 if (p[i].val == val)
1007 return (
int)p[
i].
name;
1028 char output_arg[80];
1030 if (!options || !*options)
1033 while ((this_opt =
strsep(&options,
","))) {
1036 if (!
strcmp(this_opt,
"inverse")) {
1038 }
else if (!
strncmp(this_opt,
"cable:", 6)) {
1039 strcpy(cable_arg, this_opt + 6);
1040 }
else if (!
strncmp(this_opt,
"output:", 7)) {
1041 strcpy(output_arg, this_opt + 7);
1042 }
else if (!
strncmp(this_opt,
"nopan", 5)) {
1044 }
else if (!
strncmp(this_opt,
"nowrap", 6)) {
1047 mode_option = this_opt;
1052 cable_type = pvr2_get_param(cables, cable_arg, 0, 3);
1054 video_output = pvr2_get_param(outputs, output_arg, 0, 3);
1060 static struct pvr2_board {
1065 #ifdef CONFIG_SH_DREAMCAST
1066 { pvr2fb_dc_init, pvr2fb_dc_exit,
"Sega DC PVR2" },
1069 { pvr2fb_pci_init, pvr2fb_pci_exit,
"PCI PVR2" },
1074 static int __init pvr2fb_init(
void)
1084 pvr2fb_setup(option);
1086 size =
sizeof(
struct fb_info) +
sizeof(
struct pvr2fb_par) + 16 *
sizeof(
u32);
1096 currentpar = fb_info->
par;
1098 for (i = 0; i <
ARRAY_SIZE(board_driver); i++) {
1099 struct pvr2_board *pvr_board = board_driver +
i;
1101 if (!pvr_board->init)
1104 ret = pvr_board->init();
1117 static void __exit pvr2fb_exit(
void)
1121 for (i = 0; i <
ARRAY_SIZE(board_driver); i++) {
1122 struct pvr2_board *pvr_board = board_driver +
i;
1124 if (pvr_board->exit)
1128 #ifdef CONFIG_SH_STORE_QUEUES