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