15 #include <linux/errno.h>
20 #include <linux/kernel.h>
22 #include <linux/module.h>
29 #include <asm/addrspace.h>
31 #include <asm/byteorder.h>
32 #include <asm/tlbflush.h>
44 #ifdef CONFIG_SGI_IP32
45 #define GBE_BASE 0x16000000
48 #ifdef CONFIG_X86_VISWS
49 #define GBE_BASE 0xd0000000
54 #ifdef CONFIG_CPU_R10000
55 #define pgprot_fb(_prot) (((_prot) & (~_CACHE_MASK)) | _CACHE_UNCACHED_ACCELERATED)
57 #define pgprot_fb(_prot) (((_prot) & (~_CACHE_MASK)) | _CACHE_CACHABLE_NO_WA)
61 #define pgprot_fb(_prot) ((_prot) | _PAGE_PCD)
68 #if CONFIG_FB_GBE_MEM > 8
69 #error GBE Framebuffer cannot use more than 8MB of memory
73 #define TILE_SIZE (1 << TILE_SHIFT)
74 #define TILE_MASK (TILE_SIZE - 1)
76 static unsigned int gbe_mem_size = CONFIG_FB_GBE_MEM * 1024*1024;
79 static unsigned long gbe_mem_phys;
86 static int gbe_revision;
88 static int ypan, ywrap;
92 static int gbe_turned_on;
108 .green = { 0, 8, 0 },
110 .transp = { 0, 0, 0 },
132 .xres_virtual = 1600,
133 .yres_virtual = 1024,
139 .green = { 0, 8, 0 },
141 .transp = { 0, 0, 0 },
160 static struct fb_videomode default_mode_CRT __devinitdata = {
175 static struct fb_videomode default_mode_LCD __devinitdata = {
189 static struct fb_videomode *default_mode __devinitdata = &default_mode_CRT;
192 static int flat_panel_enabled = 0;
194 static void gbe_reset(
void)
209 static void gbe_turn_off(
void)
212 unsigned int val,
x,
y, vpixen_off;
237 for (i = 0; i < 10000; i++) {
261 for (i = 0; i < 100000; i++) {
271 "gbefb: wait for vpixen_off timed out\n");
272 for (i = 0; i < 10000; i++) {
288 for (i = 0; i < 10000; i++) {
303 for (i = 0; i < 10000; i++) {
321 static void gbe_turn_on(
void)
329 if (gbe_revision < 2) {
340 for (i = 0; i < 10000; i++) {
355 for (i = 0; i < 10000; i++) {
370 for (i = 0; i < 10000; i++) {
383 static void gbe_loadcmap(
void)
387 for (i = 0; i < 256; i++) {
388 for (j = 0; j < 1000 && gbe->
cm_fifo >= 63; j++)
393 gbe->
cmap[
i] = gbe_cmap[
i];
400 static int gbefb_blank(
int blank,
struct fb_info *
info)
425 int fp_wid, fp_hgt, fp_vbs, fp_vbe;
446 gbe->
fp_de = outputVal;
470 int pll_m, pll_n, pll_p,
error, best_m, best_n, best_p, best_error;
474 if (gbe_revision < 2)
475 gbe_pll = &gbe_pll_table[0];
477 gbe_pll = &gbe_pll_table[1];
484 best_error = 1000000000;
485 best_n = best_m = best_p = 0;
486 for (pll_p = 0; pll_p < 4; pll_p++)
487 for (pll_m = 1; pll_m < 256; pll_m++)
488 for (pll_n = 1; pll_n < 64; pll_n++) {
490 (pll_n << pll_p) / pll_m;
497 if (error < best_error &&
509 if (!best_n || !best_m)
513 (best_n << best_p) / best_m;
519 timing->
pll_m = best_m;
520 timing->
pll_n = best_n;
521 timing->
pll_p = best_p;
598 if (flat_panel_enabled)
599 gbefb_setup_flatpanel(timing);
633 ((temp + timing->
width -
652 static int gbefb_set_par(
struct fb_info *info)
656 int wholeTilesX, partTilesX, maxPixelsPerTileX;
662 compute_gbe_timing(&info->
var, &par->
timing);
664 bytesPerPixel = info->
var.bits_per_pixel / 8;
665 info->
fix.line_length = info->
var.xres_virtual * bytesPerPixel;
666 xpmax = par->
timing.width;
667 ypmax = par->
timing.height;
673 gbe_set_timing_info(&par->
timing);
677 switch (bytesPerPixel) {
693 for (i = 0; i < 32; i++)
768 SET_GBE_FIELD(FRM_CONTROL, FRM_TILE_PTR, val, gbe_tiles.dma >> 9);
773 maxPixelsPerTileX = 512 / bytesPerPixel;
779 SET_GBE_FIELD(FRM_SIZE_TILE, FRM_WIDTH_TILE, val, wholeTilesX);
782 switch (bytesPerPixel) {
799 height_pix = xpmax * ypmax / maxPixelsPerTileX;
802 SET_GBE_FIELD(FRM_SIZE_PIXEL, FB_HEIGHT_PIX, val, height_pix);
817 for (i = 0; i < 256; i++)
818 gbe->
gmap[i] = (i << 24) | (i << 16) | (i << 8);
821 for (i = 0; i < 256; i++)
822 gbe_cmap[i] = (i << 8) | (i << 16) | (i << 24);
861 static int gbefb_setcolreg(
unsigned regno,
unsigned red,
unsigned green,
873 if (info->
var.bits_per_pixel <= 8) {
874 gbe_cmap[regno] = (red << 24) | (green << 16) | (blue << 8);
877 for (i = 0; i < 1000 && gbe->
cm_fifo >= 63; i++)
883 gbe->
cmap[regno] = gbe_cmap[regno];
885 }
else if (regno < 16) {
886 switch (info->
var.bits_per_pixel) {
892 pseudo_palette[regno] =
893 (red << info->
var.red.offset) |
894 (green << info->
var.green.offset) |
895 (blue << info->
var.blue.offset);
898 pseudo_palette[regno] =
899 (red << info->
var.red.offset) |
900 (green << info->
var.green.offset) |
901 (blue << info->
var.blue.offset);
914 unsigned int line_length;
935 ret = compute_gbe_timing(var, &timing);
964 var->
green.offset = 0;
965 var->
green.length = 8;
966 var->
blue.offset = 0;
967 var->
blue.length = 8;
972 var->
red.offset = 10;
974 var->
green.offset = 5;
975 var->
green.length = 5;
976 var->
blue.offset = 0;
977 var->
blue.length = 5;
982 var->
red.offset = 24;
984 var->
green.offset = 16;
985 var->
green.length = 8;
986 var->
blue.offset = 8;
987 var->
blue.length = 8;
992 var->
red.msb_right = 0;
993 var->
green.msb_right = 0;
994 var->
blue.msb_right = 0;
995 var->
transp.msb_right = 0;
1007 static int gbefb_mmap(
struct fb_info *info,
1019 if (offset + size > gbe_mem_size)
1055 static struct fb_ops gbefb_ops = {
1057 .fb_check_var = gbefb_check_var,
1058 .fb_set_par = gbefb_set_par,
1059 .fb_setcolreg = gbefb_setcolreg,
1060 .fb_mmap = gbefb_mmap,
1061 .fb_blank = gbefb_blank,
1091 static void gbefb_create_sysfs(
struct device *
dev)
1105 if (!options || !*options)
1108 while ((this_opt =
strsep(&options,
",")) !=
NULL) {
1109 if (!
strncmp(this_opt,
"monitor:", 8)) {
1110 if (!
strncmp(this_opt + 8,
"crt", 3)) {
1111 flat_panel_enabled = 0;
1113 default_mode = &default_mode_CRT;
1114 }
else if (!
strncmp(this_opt + 8,
"1600sw", 6) ||
1115 !
strncmp(this_opt + 8,
"lcd", 3)) {
1116 flat_panel_enabled = 1;
1118 default_mode = &default_mode_LCD;
1120 }
else if (!
strncmp(this_opt,
"mem:", 4)) {
1121 gbe_mem_size =
memparse(this_opt + 4, &this_opt);
1122 if (gbe_mem_size > CONFIG_FB_GBE_MEM * 1024 * 1024)
1123 gbe_mem_size = CONFIG_FB_GBE_MEM * 1024 * 1024;
1127 mode_option = this_opt;
1138 char *options =
NULL;
1148 goto out_release_framebuffer;
1150 gbefb_setup(options);
1156 goto out_release_framebuffer;
1164 goto out_release_mem_region;
1171 if (!gbe_tiles.cpu) {
1174 goto out_release_mem_region;
1184 goto out_tiles_free;
1194 printk(
KERN_ERR "gbefb: couldn't allocate framebuffer memory\n");
1196 goto out_tiles_free;
1199 gbe_mem_phys = (
unsigned long) gbe_dma_addr;
1207 for (i = 0; i < (gbe_mem_size >>
TILE_SHIFT); i++)
1208 gbe_tiles.cpu[i] = (gbe_mem_phys >>
TILE_SHIFT) +
i;
1210 info->
fbops = &gbefb_ops;
1222 default_mode, 8) == 0)
1225 gbefb_check_var(&par->
var, info);
1226 gbefb_encode_fix(&info->
fix, &info->
var);
1234 platform_set_drvdata(p_dev, info);
1235 gbefb_create_sysfs(&p_dev->
dev);
1238 info->
node, info->
fix.id, gbe_revision, (
unsigned) GBE_BASE,
1239 gbe_mem_size >> 10);
1248 (
void *)gbe_tiles.cpu, gbe_tiles.dma);
1249 out_release_mem_region:
1251 out_release_framebuffer:
1259 struct fb_info *info = platform_get_drvdata(p_dev);
1266 (
void *)gbe_tiles.cpu, gbe_tiles.dma);
1268 gbefb_remove_sysfs(&p_dev->
dev);
1275 .probe = gbefb_probe,
1284 static int __init gbefb_init(
void)
1302 static void __exit gbefb_exit(
void)