patch-2.3.15 linux/drivers/video/clgenfb.c

Next file: linux/drivers/video/controlfb.c
Previous file: linux/drivers/video/chipsfb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.14/linux/drivers/video/clgenfb.c linux/drivers/video/clgenfb.c
@@ -31,8 +31,9 @@
  *
  */
 
-#define CLGEN_VERSION "1.9.4.1"
+#define CLGEN_VERSION "1.9.4.3"
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -98,7 +99,6 @@
         if(!(expr)) { \
         printk( "Assertion failed! %s,%s,%s,line=%d\n",\
         #expr,__FILE__,__FUNCTION__,__LINE__); \
-        *(int*)0 = 0;\
         }
 #else
 #define assert(expr)
@@ -325,6 +325,8 @@
 #ifdef CONFIG_ZORRO
 	int keyRAM;		/* RAM, REG zorro board keys */
 	int keyREG;
+	unsigned long board_addr,
+		      board_size;
 #endif
 
 #ifdef CONFIG_PCI
@@ -339,7 +341,9 @@
 
 static struct clgenfb_info boards[MAX_NUM_BOARDS];	/* the boards */
 
-static unsigned clgen_def_mode = 0;
+static unsigned clgen_def_mode = 1;
+
+static int release_io_ports = 0;
 
 
 
@@ -635,18 +639,18 @@
 		switch (_par->var.bits_per_pixel) {
 		case 1:
 		case 8:
-			fix->smem_start = (char *) _info->fbmem_phys;
+			fix->smem_start = _info->fbmem_phys;
 			break;
 		case 16:
-			fix->smem_start = (char *) _info->fbmem_phys + 1 * MB_;
+			fix->smem_start = _info->fbmem_phys + 1 * MB_;
 			break;
 		case 24:
 		case 32:
-			fix->smem_start = (char *) _info->fbmem_phys + 2 * MB_;
+			fix->smem_start = _info->fbmem_phys + 2 * MB_;
 			break;
 		}
 	} else {
-		fix->smem_start = (char *) _info->fbmem_phys;
+		fix->smem_start = _info->fbmem_phys;
 	}
 
 	/* monochrome: only 1 memory plane */
@@ -662,7 +666,7 @@
 	fix->line_length = _par->line_length;
 
 	/* FIXME: map region at 0xB8000 if available, fill in here */
-	fix->mmio_start = (char *) NULL;
+	fix->mmio_start = 0;
 	fix->mmio_len = 0;
 	fix->accel = FB_ACCEL_NONE;
 
@@ -831,7 +835,7 @@
 	if (_par->var.yoffset > _par->var.yres_virtual - _par->var.yres)
 		_par->var.yoffset = _par->var.yres_virtual - _par->var.yres - 1;
 
-	switch (var->bits_per_pixel) {
+	switch (_par->var.bits_per_pixel) {
 	case 1:
 		_par->line_length = _par->var.xres_virtual / 8;
 		_par->visual = FB_VISUAL_MONO10;
@@ -900,7 +904,8 @@
 		break;
 
 	default:
-		assert (0);
+		DPRINTK("Unsupported bpp size: %d\n", _par->var.bits_per_pixel);
+		assert (FALSE);
 		/* should never occur */
 		break;
 	}
@@ -951,7 +956,7 @@
 
 	bestclock (freq, &_par->freq, &_par->nom, &_par->den, &_par->div,
 		   maxclock);
-	_par->mclk = clgen_get_mclk (freq, var->bits_per_pixel, &_par->divMCLK);
+	_par->mclk = clgen_get_mclk (freq, _par->var.bits_per_pixel, &_par->divMCLK);
 
 	xres = _par->var.xres;
 	hfront = _par->var.right_margin;
@@ -1787,12 +1792,16 @@
 		break;
 	}
 
+#ifdef CLGEN_USE_HARDCODED_RAM_SETTINGS
 	/* "pre-set" a RAMsize; if the test succeeds, double it */
 	if (fb_info->btype == BT_SD64 ||
 	    fb_info->btype == BT_PICASSO4)
 		fb_info->size = 0x400000;
 	else
 		fb_info->size = 0x200000;
+#else
+	assert (fb_info->size > 0); /* make sure RAM size set by this point */
+#endif
 
 	/* assume it's a "large memory" board (2/4 MB) */
 	fb_info->smallboard = FALSE;
@@ -2326,7 +2335,7 @@
 					clgen_pci_probe_list[i].device, NULL);
 	
 	if (pdev)
-		*btype = clgen_pci_probe_list[i].btype;
+		*btype = clgen_pci_probe_list[i - 1].btype;
 
 	DPRINTK ("EXIT, returning %p\n", pdev);
 	return pdev;
@@ -2362,7 +2371,7 @@
 
 #else
 
-	if (pdev->resource[0].flags & IORESOURCE_IOPORT) {
+	if (pdev->resource[0].flags & IORESOURCE_IO) {
 		*display = pdev->resource[1].start;
 		*registers = pdev->resource[0].start;
 	} else {
@@ -2380,6 +2389,21 @@
 
 
 
+/* clgen_pci_unmap only used in modules */
+#ifdef MODULE
+static void clgen_pci_unmap (struct clgenfb_info *info)
+{
+	iounmap (info->fbmem);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,13)
+	__release_region (&iomem_resource, info->fbmem_phys, info->size);
+	__release_region (&iomem_resource, 0xA0000, 65535);
+	if (release_io_ports)
+		__release_region (&ioport_resource, 0x3C0, 32);
+#endif
+}
+#endif /* MODULE */
+
+
 static int __init clgen_pci_setup (struct clgenfb_info *info,
 				   clgen_board_t *btype)
 {
@@ -2411,8 +2435,8 @@
 
 	pci_read_config_word (pdev, PCI_COMMAND, &tmp16);
 	if (!(tmp16 & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO))) {
-		tmp16 |= PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
-		pci_write_config_word (pdev, PCI_COMMAND, tmp16);
+		u16 tmp16_o = tmp16 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
+		pci_write_config_word (pdev, PCI_COMMAND, tmp16_o);
 	}
 
 #ifdef CONFIG_FB_OF
@@ -2453,10 +2477,33 @@
 	} else {
 		board_size = clgen_get_memsize (info->regs);
 	}
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,13)
+
+	if (!__request_region (&iomem_resource, board_addr,
+			       board_size, "clgenfb")) {
+		pci_write_config_word (pdev, PCI_COMMAND, tmp16);
+		printk(KERN_ERR "clgen: cannot reserve region 0x%lu, abort\n",
+		       board_addr);
+		return -1;
+	}
+	if (!__request_region (&iomem_resource, 0xA0000, 65535, "clgenfb")) {
+		pci_write_config_word (pdev, PCI_COMMAND, tmp16);
+		printk(KERN_ERR "clgen: cannot reserve region 0x%lu, abort\n",
+		       0xA0000L);
+		__release_region(&iomem_resource, board_addr, board_size);
+		return -1;
+	}
+	if (__request_region(&ioport_resource, 0x3C0, 32, "clgenfb"))
+		release_io_ports = 1;
+
+#endif /* kernel > 2.3.13 */
+
 	info->fbmem = ioremap (board_addr, board_size);
 	info->fbmem_phys = board_addr;
+	info->size = board_size;
 
-	printk (" RAM (%lu MB) at $%lx, ", board_size / 0x100000, board_addr);
+	printk (" RAM (%lu MB) at 0x%lx, ", info->size / MB_, board_addr);
 
 	printk (KERN_INFO "Cirrus Logic chipset on PCI bus\n");
 
@@ -2485,7 +2532,7 @@
 			*key2_o = zorro_find (clgen_zorro_probe_list[i].key2, 0, 0);
 		else
 			*key2_o = 0;
-		*btype = clgen_zorro_probe_list[i].btype;
+		*btype = clgen_zorro_probe_list[i - 1].btype;
 		
 		printk (KERN_INFO "clgen: %s board detected; ",
 			clgen_board_info[*btype].name);
@@ -2499,6 +2546,25 @@
 
 
 
+/* clgen_zorro_unmap only used in modules */
+#ifdef MODULE
+static void clgen_zorro_unmap (struct clgenfb_info *info)
+{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,13)
+	__release_region(&iomem_resource, info->board_addr, info->board_size);
+#endif
+	if (info->btype == BT_PICASSO4) {
+		iounmap (info->board_addr);
+		iounmap (info->fbmem_phys);
+	} else {
+		if (info->board_addr > 0x01000000)
+			iounmap (info->board_addr);
+	}
+}
+#endif /* MODULE */
+
+
+
 static int __init clgen_zorro_setup (struct clgenfb_info *info,
 				     clgen_board_t *btype)
 {
@@ -2520,9 +2586,17 @@
 	info->keyRAM = key;
 	info->keyREG = key2;
 	cd = zorro_get_board (key);
-	board_addr = (unsigned long) cd->cd_BoardAddr;
-	board_size = (unsigned long) cd->cd_BoardSize;
-	printk (" RAM (%lu MB) at $%lx, ", board_size / 0x100000, board_addr);
+	info->board_addr = board_addr = (unsigned long) cd->cd_BoardAddr;
+	info->board_size = board_size = (unsigned long) cd->cd_BoardSize;
+
+	if (!__request_region(&iomem_resource, board_addr,
+			      board_size, "clgenfb")) {
+		printk(KERN_ERR "clgen: cannot reserve region 0x%lu, abort\n",
+		       board_addr);
+		return -1;
+	}
+
+	printk (" RAM (%lu MB) at $%lx, ", board_size / MB_, board_addr);
 
 	if (*btype == BT_PICASSO4) {
 		printk (" REG at $%lx\n", board_addr + 0x600000);
@@ -2683,9 +2757,13 @@
 #ifdef CONFIG_ZORRO
 	switch_monitor (info, 0);
 
+	clgen_zorro_unmap (info);
+
 	zorro_unconfig_board (info->keyRAM, 0);
 	if (info->btype != BT_PICASSO4)
 		zorro_unconfig_board (info->keyREG, 0);
+#else
+	clgen_pci_unmap (info);
 #endif				/* CONFIG_ZORRO */
 
 	unregister_framebuffer ((struct fb_info *) info);
@@ -3277,7 +3355,7 @@
 			break;
 		default:
 			/* should never occur */
-			assert (0);
+			assert (FALSE);
 			break;
 		}
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)