1 /* 2 * Oak Generic NCR5380 driver 3 * 4 * Copyright 1995-2002, Russell King 5 */ 6 7 #include <linux/module.h> 8 #include <linux/signal.h> 9 #include <linux/ioport.h> 10 #include <linux/delay.h> 11 #include <linux/blkdev.h> 12 #include <linux/init.h> 13 14 #include <asm/ecard.h> 15 #include <asm/io.h> 16 17 #include "../scsi.h" 18 #include <scsi/scsi_host.h> 19 20 #define AUTOSENSE 21 /*#define PSEUDO_DMA*/ 22 23 #define OAKSCSI_PUBLIC_RELEASE 1 24 #define DONT_USE_INTR 25 26 #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata) 27 #define NCR5380_local_declare() void __iomem *_base 28 #define NCR5380_setup(host) _base = priv(host)->base 29 30 #define NCR5380_read(reg) readb(_base + ((reg) << 2)) 31 #define NCR5380_write(reg, value) writeb(value, _base + ((reg) << 2)) 32 #define NCR5380_intr oakscsi_intr 33 #define NCR5380_queue_command oakscsi_queue_command 34 #define NCR5380_show_info oakscsi_show_info 35 #define NCR5380_write_info oakscsi_write_info 36 37 #define NCR5380_implementation_fields \ 38 void __iomem *base 39 40 #include "../NCR5380.h" 41 42 #undef START_DMA_INITIATOR_RECEIVE_REG 43 #define START_DMA_INITIATOR_RECEIVE_REG (128 + 7) 44 45 const char * oakscsi_info (struct Scsi_Host *spnt) 46 { 47 return ""; 48 } 49 50 #define STAT ((128 + 16) << 2) 51 #define DATA ((128 + 8) << 2) 52 53 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, 54 int len) 55 { 56 void __iomem *base = priv(instance)->base; 57 58 printk("writing %p len %d\n",addr, len); 59 if(!len) return -1; 60 61 while(1) 62 { 63 int status; 64 while (((status = readw(base + STAT)) & 0x100)==0); 65 } 66 } 67 68 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, 69 int len) 70 { 71 void __iomem *base = priv(instance)->base; 72 printk("reading %p len %d\n", addr, len); 73 while(len > 0) 74 { 75 unsigned int status, timeout; 76 unsigned long b; 77 78 timeout = 0x01FFFFFF; 79 80 while (((status = readw(base + STAT)) & 0x100)==0) 81 { 82 timeout--; 83 if(status & 0x200 || !timeout) 84 { 85 printk("status = %08X\n", status); 86 return 1; 87 } 88 } 89 90 if(len >= 128) 91 { 92 readsw(base + DATA, addr, 128); 93 addr += 128; 94 len -= 128; 95 } 96 else 97 { 98 b = (unsigned long) readw(base + DATA); 99 *addr ++ = b; 100 len -= 1; 101 if(len) 102 *addr ++ = b>>8; 103 len -= 1; 104 } 105 } 106 return 0; 107 } 108 109 #undef STAT 110 #undef DATA 111 112 #include "../NCR5380.c" 113 114 static struct scsi_host_template oakscsi_template = { 115 .module = THIS_MODULE, 116 .show_info = oakscsi_show_info, 117 .write_info = oakscsi_write_info, 118 .name = "Oak 16-bit SCSI", 119 .info = oakscsi_info, 120 .queuecommand = oakscsi_queue_command, 121 .eh_abort_handler = NCR5380_abort, 122 .eh_bus_reset_handler = NCR5380_bus_reset, 123 .can_queue = 16, 124 .this_id = 7, 125 .sg_tablesize = SG_ALL, 126 .cmd_per_lun = 2, 127 .use_clustering = DISABLE_CLUSTERING, 128 .proc_name = "oakscsi", 129 }; 130 131 static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id) 132 { 133 struct Scsi_Host *host; 134 int ret = -ENOMEM; 135 136 ret = ecard_request_resources(ec); 137 if (ret) 138 goto out; 139 140 host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata)); 141 if (!host) { 142 ret = -ENOMEM; 143 goto release; 144 } 145 146 priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 147 ecard_resource_len(ec, ECARD_RES_MEMC)); 148 if (!priv(host)->base) { 149 ret = -ENOMEM; 150 goto unreg; 151 } 152 153 host->irq = IRQ_NONE; 154 host->n_io_port = 255; 155 156 NCR5380_init(host, 0); 157 158 printk("scsi%d: at port 0x%08lx irqs disabled", 159 host->host_no, host->io_port); 160 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", 161 host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE); 162 printk("\nscsi%d:", host->host_no); 163 NCR5380_print_options(host); 164 printk("\n"); 165 166 ret = scsi_add_host(host, &ec->dev); 167 if (ret) 168 goto out_unmap; 169 170 scsi_scan_host(host); 171 goto out; 172 173 out_unmap: 174 iounmap(priv(host)->base); 175 unreg: 176 scsi_host_put(host); 177 release: 178 ecard_release_resources(ec); 179 out: 180 return ret; 181 } 182 183 static void oakscsi_remove(struct expansion_card *ec) 184 { 185 struct Scsi_Host *host = ecard_get_drvdata(ec); 186 187 ecard_set_drvdata(ec, NULL); 188 scsi_remove_host(host); 189 190 NCR5380_exit(host); 191 iounmap(priv(host)->base); 192 scsi_host_put(host); 193 ecard_release_resources(ec); 194 } 195 196 static const struct ecard_id oakscsi_cids[] = { 197 { MANU_OAK, PROD_OAK_SCSI }, 198 { 0xffff, 0xffff } 199 }; 200 201 static struct ecard_driver oakscsi_driver = { 202 .probe = oakscsi_probe, 203 .remove = oakscsi_remove, 204 .id_table = oakscsi_cids, 205 .drv = { 206 .name = "oakscsi", 207 }, 208 }; 209 210 static int __init oakscsi_init(void) 211 { 212 return ecard_register_driver(&oakscsi_driver); 213 } 214 215 static void __exit oakscsi_exit(void) 216 { 217 ecard_remove_driver(&oakscsi_driver); 218 } 219 220 module_init(oakscsi_init); 221 module_exit(oakscsi_exit); 222 223 MODULE_AUTHOR("Russell King"); 224 MODULE_DESCRIPTION("Oak SCSI driver"); 225 MODULE_LICENSE("GPL"); 226 227