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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/blkdev.h> |
| 10 | #include <linux/init.h> |
| 11 | |
| 12 | #include <asm/ecard.h> |
| 13 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <scsi/scsi_host.h> |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /*#define PSEUDO_DMA*/ |
Arnd Bergmann | ea065f1 | 2012-04-30 16:26:31 +0000 | [diff] [blame] | 18 | #define DONT_USE_INTR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 20 | #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata) |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 21 | |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 22 | #define NCR5380_read(reg) \ |
| 23 | readb(priv(instance)->base + ((reg) << 2)) |
| 24 | #define NCR5380_write(reg, value) \ |
| 25 | writeb(value, priv(instance)->base + ((reg) << 2)) |
| 26 | |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 27 | #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize) |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #define NCR5380_queue_command oakscsi_queue_command |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 30 | #define NCR5380_info oakscsi_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 32 | #define NCR5380_implementation_fields \ |
| 33 | void __iomem *base |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "../NCR5380.h" |
| 36 | |
| 37 | #undef START_DMA_INITIATOR_RECEIVE_REG |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 38 | #define START_DMA_INITIATOR_RECEIVE_REG (128 + 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 40 | #define STAT ((128 + 16) << 2) |
| 41 | #define DATA ((128 + 8) << 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, |
| 44 | int len) |
| 45 | { |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 46 | void __iomem *base = priv(instance)->base; |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | printk("writing %p len %d\n",addr, len); |
| 49 | if(!len) return -1; |
| 50 | |
| 51 | while(1) |
| 52 | { |
| 53 | int status; |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 54 | while (((status = readw(base + STAT)) & 0x100)==0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, |
| 59 | int len) |
| 60 | { |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 61 | void __iomem *base = priv(instance)->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | printk("reading %p len %d\n", addr, len); |
| 63 | while(len > 0) |
| 64 | { |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 65 | unsigned int status, timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | unsigned long b; |
| 67 | |
| 68 | timeout = 0x01FFFFFF; |
| 69 | |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 70 | while (((status = readw(base + STAT)) & 0x100)==0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | timeout--; |
| 73 | if(status & 0x200 || !timeout) |
| 74 | { |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 75 | printk("status = %08X\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return 1; |
| 77 | } |
| 78 | } |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if(len >= 128) |
| 81 | { |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 82 | readsw(base + DATA, addr, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | addr += 128; |
| 84 | len -= 128; |
| 85 | } |
| 86 | else |
| 87 | { |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 88 | b = (unsigned long) readw(base + DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | *addr ++ = b; |
| 90 | len -= 1; |
| 91 | if(len) |
| 92 | *addr ++ = b>>8; |
| 93 | len -= 1; |
| 94 | } |
| 95 | } |
| 96 | return 0; |
| 97 | } |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #undef STAT |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 100 | #undef DATA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | #include "../NCR5380.c" |
| 103 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 104 | static struct scsi_host_template oakscsi_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .module = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | .name = "Oak 16-bit SCSI", |
| 107 | .info = oakscsi_info, |
| 108 | .queuecommand = oakscsi_queue_command, |
| 109 | .eh_abort_handler = NCR5380_abort, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | .eh_bus_reset_handler = NCR5380_bus_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | .can_queue = 16, |
| 112 | .this_id = 7, |
| 113 | .sg_tablesize = SG_ALL, |
| 114 | .cmd_per_lun = 2, |
| 115 | .use_clustering = DISABLE_CLUSTERING, |
| 116 | .proc_name = "oakscsi", |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame^] | 117 | .cmd_size = NCR5380_CMD_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 120 | static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
| 122 | struct Scsi_Host *host; |
| 123 | int ret = -ENOMEM; |
| 124 | |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 125 | ret = ecard_request_resources(ec); |
| 126 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | goto out; |
| 128 | |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 129 | host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata)); |
| 130 | if (!host) { |
| 131 | ret = -ENOMEM; |
| 132 | goto release; |
| 133 | } |
| 134 | |
| 135 | priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), |
| 136 | ecard_resource_len(ec, ECARD_RES_MEMC)); |
| 137 | if (!priv(host)->base) { |
| 138 | ret = -ENOMEM; |
| 139 | goto unreg; |
| 140 | } |
| 141 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 142 | host->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | host->n_io_port = 255; |
| 144 | |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 145 | ret = NCR5380_init(host, 0); |
| 146 | if (ret) |
| 147 | goto out_unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 149 | NCR5380_maybe_reset_bus(host); |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | ret = scsi_add_host(host, &ec->dev); |
| 152 | if (ret) |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 153 | goto out_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | scsi_scan_host(host); |
| 156 | goto out; |
| 157 | |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 158 | out_exit: |
| 159 | NCR5380_exit(host); |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 160 | out_unmap: |
| 161 | iounmap(priv(host)->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | unreg: |
| 163 | scsi_host_put(host); |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 164 | release: |
| 165 | ecard_release_resources(ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | out: |
| 167 | return ret; |
| 168 | } |
| 169 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 170 | static void oakscsi_remove(struct expansion_card *ec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | struct Scsi_Host *host = ecard_get_drvdata(ec); |
| 173 | |
| 174 | ecard_set_drvdata(ec, NULL); |
| 175 | scsi_remove_host(host); |
| 176 | |
| 177 | NCR5380_exit(host); |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 178 | iounmap(priv(host)->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | scsi_host_put(host); |
Russell King | 8b801ea | 2007-07-20 10:38:54 +0100 | [diff] [blame] | 180 | ecard_release_resources(ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static const struct ecard_id oakscsi_cids[] = { |
| 184 | { MANU_OAK, PROD_OAK_SCSI }, |
| 185 | { 0xffff, 0xffff } |
| 186 | }; |
| 187 | |
| 188 | static struct ecard_driver oakscsi_driver = { |
| 189 | .probe = oakscsi_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 190 | .remove = oakscsi_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | .id_table = oakscsi_cids, |
| 192 | .drv = { |
| 193 | .name = "oakscsi", |
| 194 | }, |
| 195 | }; |
| 196 | |
| 197 | static int __init oakscsi_init(void) |
| 198 | { |
| 199 | return ecard_register_driver(&oakscsi_driver); |
| 200 | } |
| 201 | |
| 202 | static void __exit oakscsi_exit(void) |
| 203 | { |
| 204 | ecard_remove_driver(&oakscsi_driver); |
| 205 | } |
| 206 | |
| 207 | module_init(oakscsi_init); |
| 208 | module_exit(oakscsi_exit); |
| 209 | |
| 210 | MODULE_AUTHOR("Russell King"); |
| 211 | MODULE_DESCRIPTION("Oak SCSI driver"); |
| 212 | MODULE_LICENSE("GPL"); |
| 213 | |