--- awe_ram.c.0 Mon Feb 26 18:59:19 2001 +++ awe_ram.c Mon Feb 26 20:27:01 2001 @@ -13,25 +13,15 @@ /* Currently /dev/aweram should have major 242 and minor 0 */ #define MAJOR_NR 242 /* 240--254 local/experimental range */ -#include - -#ifdef MODULE #include -#include -#else -#define MOD_INC_USE_COUNT -#define MOD_DEC_USE_COUNT -#endif - -#include #include +#include +#include #include -#include #include #include -/* Should awe_hw.h be moved to include/linux? */ -#include "../sound/lowlevel/awe_hw.h" +#include "../linux/drivers/sound/awe_hw.h" #define DEVICE_NAME "AWE RAM block device" #define DEVICE_REQUEST do_aweram_request @@ -41,9 +31,6 @@ #include -#define FALSE 0 -#define TRUE (!FALSE) - #define INLINE inline #define AWERAM_MINOR 0 @@ -70,7 +57,7 @@ int memsize = AWE_DEFAULT_MEM_SIZE; /* memory size in Kbytes */ #endif -static int awe_present = FALSE; /* awe device present? */ +static int awe_present; /* awe device present? */ @@ -80,7 +67,7 @@ /* select a given AWE32 pointer */ static int awe_ports[5]; -static int port_setuped = FALSE; +static int port_setuped; static int awe_cur_cmd = -1; #define awe_set_cmd(cmd) \ if (awe_cur_cmd != cmd) { outw(cmd, awe_ports[Pointer]); awe_cur_cmd = cmd; } @@ -98,7 +85,7 @@ awe_ports[3] = port3; awe_ports[4] = port3 + 2; - port_setuped = TRUE; + port_setuped = 1; } @@ -389,9 +376,33 @@ static int awe_detect(void) { int base; + struct pci_dev *idev = NULL; - if (port_setuped) /* already initialized by PnP */ - return 1; + /* first try ISA-PNP */ + idev = isapnp_find_dev(NULL, + ISAPNP_VENDOR('C', 'T', 'L'), + ISAPNP_FUNCTION(0x0045), idev); + if (idev) { /* found something, maybe */ + int err; + + err = idev->prepare(idev); + if (err & err != -EBUSY) { + printk (KERN_ERR DEVICE_NAME ": ISA-PNP AWE32 found but cannot autoconfigure\n"); + return 0; + } + if (!idev->active) { + err = idev->activate(idev); + if (err < 0) { + printk (KERN_ERR DEVICE_NAME ": ISA-PNP AWE32 autoconfigured but cannot activate\n"); + idev->deactivate(idev); + return 0; + } + } + if (awe_detect_base(idev->resource[0].start)) + return 1; + printk (KERN_ERR DEVICE_NAME ": ISA-PNP AWE32 not found\n"); + return 0; + } if (awe_port) /* use default i/o port value */ setup_ports(awe_port, 0, 0); @@ -399,7 +410,7 @@ for (base = 0x620; base <= 0x680; base += 0x20) if (awe_detect_base(base)) return 1; - printk (KERN_INFO DEVICE_NAME ": AWE32 not found\n"); + printk (KERN_ERR DEVICE_NAME ": AWE32 not found\n"); return 0; } @@ -511,7 +522,7 @@ /* awe_poke(AWE_HWCF3, 0x0004); */ /* set default values */ - /* awe_init_ctrl_parms(TRUE); */ + /* awe_init_ctrl_parms(1); */ /* set equalizer */ /* awe_update_equalizer(); */ @@ -526,7 +537,7 @@ { u_long start, len; - while (TRUE) { + while (1) { INIT_REQUEST; start = CURRENT->sector << 9; @@ -536,14 +547,14 @@ printk (KERN_ERR DEVICE_NAME ": bad access: block=%ld, count=%ld\n", CURRENT->sector, CURRENT->current_nr_sectors); - end_request (FALSE); + end_request (0); continue; } if ((CURRENT->cmd != READ) && (CURRENT->cmd != WRITE)) { printk (KERN_ERR DEVICE_NAME ": bad command: %d\n", CURRENT->cmd); - end_request (FALSE); + end_request (0); continue; } @@ -552,7 +563,7 @@ else awe_write_dram_buffer (start, CURRENT->buffer, len); - end_request (TRUE); + end_request (1); } } @@ -588,9 +599,7 @@ } MOD_INC_USE_COUNT; - awe_open_dram_for_write (); - return 0; } @@ -599,91 +608,44 @@ { if (current_device == -1) return 0; - sync_dev (inode->i_rdev); - awe_close_dram (); - MOD_DEC_USE_COUNT; - return 0; } -static struct file_operations aweram_fops = +static struct block_device_operations aweram_fops = { - NULL, /* lseek - default */ - block_read, /* read - general block-dev read */ - block_write, /* write - general block-dev write */ - NULL, /* readdir - bad */ - NULL, /* poll */ - NULL, /* ioctl */ - NULL, /* mmap */ - aweram_open, /* open */ - NULL, /* flush */ - aweram_release, /* release */ - block_fsync, /* fsync */ - NULL, /* fasync */ - NULL, /* check_media_change */ - NULL, /* revalidate */ + open: aweram_open, + release: aweram_release, }; -int __init aweram_init (void) +static int __init aweram_init (void) { - if (!awe_detect()) { - printk (KERN_WARNING DEVICE_NAME ": card not detected\n"); + if (!awe_detect()) return -ENXIO; - } - if (register_blkdev (MAJOR_NR, DEVICE_NAME, &aweram_fops)) { - printk (KERN_ERR DEVICE_NAME ": Unable to get major %d\n", - MAJOR_NR); + printk (KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR); return -EBUSY; } - - - /* intialize AWE32 hardware */ awe_initialize(); - aweram_blocksize[0] = 1 << 10; aweram_size[0] = awe_mem_size >> 10; printk (KERN_INFO DEVICE_NAME ": size = %d\n", aweram_size[0]); - blk_init_queue (BLK_DEFAULT_QUEUE(MAJOR_NR), DEVICE_REQUEST); blksize_size[MAJOR_NR] = aweram_blocksize; blk_size[MAJOR_NR] = aweram_size; - - awe_present = TRUE; - + awe_present = 1; return 0; } - -#if defined(MODULE) - -int init_module (void) -{ - int error; - - error = aweram_init(); - if (!error) - printk (KERN_INFO DEVICE_NAME ": loaded as module\n"); - else - printk (KERN_ERR DEVICE_NAME ": module not loaded\n"); - - return error; -} - - -void cleanup_module (void) +static void __exit aweram_exit (void) { if (unregister_blkdev (MAJOR_NR, DEVICE_NAME)) printk (KERN_ERR DEVICE_NAME ": unregister of device failed\n"); - - printk (KERN_INFO DEVICE_NAME ": module unloaded\n"); - - return; } -#endif +module_init(aweram_init) +module_exit(aweram_exit)