cumana_1.c 7.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Generic Generic NCR5380 driver
 *
 * Copyright 1995-2002, Russell King
 */
#include <linux/module.h>
#include <linux/signal.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <linux/blkdev.h>
#include <linux/init.h>

#include <asm/ecard.h>
#include <asm/io.h>

#include "../scsi.h"
#include <scsi/scsi_host.h>

#include <scsi/scsicam.h>

#define AUTOSENSE
#define PSEUDO_DMA

#define CUMANASCSI_PUBLIC_RELEASE 1

26
#define priv(host)			((struct NCR5380_hostdata *)(host)->hostdata)
L
Linus Torvalds 已提交
27 28 29 30 31 32 33
#define NCR5380_local_declare()		struct Scsi_Host *_instance
#define NCR5380_setup(instance)		_instance = instance
#define NCR5380_read(reg)		cumanascsi_read(_instance, reg)
#define NCR5380_write(reg, value)	cumanascsi_write(_instance, reg, value)
#define NCR5380_intr			cumanascsi_intr
#define NCR5380_queue_command		cumanascsi_queue_command

34 35 36 37 38
#define NCR5380_implementation_fields	\
	unsigned ctrl;			\
	void __iomem *base;		\
	void __iomem *dma

L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52
#define BOARD_NORMAL	0
#define BOARD_NCR53C400	1

#include "../NCR5380.h"

void cumanascsi_setup(char *str, int *ints)
{
}

const char *cumanascsi_info(struct Scsi_Host *spnt)
{
	return "";
}

53 54 55 56
#define CTRL	0x16fc
#define STAT	0x2004
#define L(v)	(((v)<<16)|((v) & 0x0000ffff))
#define H(v)	(((v)>>16)|((v) & 0xffff0000))
L
Linus Torvalds 已提交
57 58

static inline int
59
NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
L
Linus Torvalds 已提交
60 61
{
  unsigned long *laddr;
62
  void __iomem *dma = priv(host)->dma + 0x2000;
L
Linus Torvalds 已提交
63 64 65

  if(!len) return 0;

66
  writeb(0x02, priv(host)->base + CTRL);
L
Linus Torvalds 已提交
67 68 69
  laddr = (unsigned long *)addr;
  while(len >= 32)
  {
70
    unsigned int status;
L
Linus Torvalds 已提交
71
    unsigned long v;
72
    status = readb(priv(host)->base + STAT);
L
Linus Torvalds 已提交
73 74 75 76
    if(status & 0x80)
      goto end;
    if(!(status & 0x40))
      continue;
77 78 79 80 81 82 83 84
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
    v=*laddr++; writew(L(v), dma); writew(H(v), dma);
L
Linus Torvalds 已提交
85 86 87 88 89 90
    len -= 32;
    if(len == 0)
      break;
  }

  addr = (unsigned char *)laddr;
91 92
  writeb(0x12, priv(host)->base + CTRL);

L
Linus Torvalds 已提交
93 94
  while(len > 0)
  {
95 96
    unsigned int status;
    status = readb(priv(host)->base + STAT);
L
Linus Torvalds 已提交
97 98 99 100
    if(status & 0x80)
      goto end;
    if(status & 0x40)
    {
101
      writeb(*addr++, dma);
L
Linus Torvalds 已提交
102 103 104 105
      if(--len == 0)
        break;
    }

106
    status = readb(priv(host)->base + STAT);
L
Linus Torvalds 已提交
107 108 109 110
    if(status & 0x80)
      goto end;
    if(status & 0x40)
    {
111
      writeb(*addr++, dma);
L
Linus Torvalds 已提交
112 113 114 115 116
      if(--len == 0)
        break;
    }
  }
end:
117
  writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
L
Linus Torvalds 已提交
118 119 120 121
  return len;
}

static inline int
122
NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
L
Linus Torvalds 已提交
123 124
{
  unsigned long *laddr;
125
  void __iomem *dma = priv(host)->dma + 0x2000;
L
Linus Torvalds 已提交
126 127 128

  if(!len) return 0;

129
  writeb(0x00, priv(host)->base + CTRL);
L
Linus Torvalds 已提交
130 131 132
  laddr = (unsigned long *)addr;
  while(len >= 32)
  {
133 134
    unsigned int status;
    status = readb(priv(host)->base + STAT);
L
Linus Torvalds 已提交
135 136 137 138
    if(status & 0x80)
      goto end;
    if(!(status & 0x40))
      continue;
139 140 141 142 143 144 145 146
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
    *laddr++ = readw(dma) | (readw(dma) << 16);
L
Linus Torvalds 已提交
147 148 149 150 151 152
    len -= 32;
    if(len == 0)
      break;
  }

  addr = (unsigned char *)laddr;
153 154
  writeb(0x10, priv(host)->base + CTRL);

L
Linus Torvalds 已提交
155 156
  while(len > 0)
  {
157 158
    unsigned int status;
    status = readb(priv(host)->base + STAT);
L
Linus Torvalds 已提交
159 160 161 162
    if(status & 0x80)
      goto end;
    if(status & 0x40)
    {
163
      *addr++ = readb(dma);
L
Linus Torvalds 已提交
164 165 166 167
      if(--len == 0)
        break;
    }

168
    status = readb(priv(host)->base + STAT);
L
Linus Torvalds 已提交
169 170 171 172
    if(status & 0x80)
      goto end;
    if(status & 0x40)
    {
173
      *addr++ = readb(dma);
L
Linus Torvalds 已提交
174 175 176 177 178
      if(--len == 0)
        break;
    }
  }
end:
179
  writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
L
Linus Torvalds 已提交
180 181 182
  return len;
}

183 184 185 186
static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
{
	void __iomem *base = priv(host)->base;
	unsigned char val;
L
Linus Torvalds 已提交
187

188
	writeb(0, base + CTRL);
L
Linus Torvalds 已提交
189

190
	val = readb(base + 0x2100 + (reg << 2));
L
Linus Torvalds 已提交
191

192 193
	priv(host)->ctrl = 0x40;
	writeb(0x40, base + CTRL);
L
Linus Torvalds 已提交
194

195
	return val;
L
Linus Torvalds 已提交
196 197
}

198
static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
L
Linus Torvalds 已提交
199
{
200
	void __iomem *base = priv(host)->base;
L
Linus Torvalds 已提交
201

202
	writeb(0, base + CTRL);
L
Linus Torvalds 已提交
203

204 205 206 207 208
	writeb(value, base + 0x2100 + (reg << 2));

	priv(host)->ctrl = 0x40;
	writeb(0x40, base + CTRL);
}
L
Linus Torvalds 已提交
209 210 211

#include "../NCR5380.c"

212
static struct scsi_host_template cumanascsi_template = {
L
Linus Torvalds 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226
	.module			= THIS_MODULE,
	.name			= "Cumana 16-bit SCSI",
	.info			= cumanascsi_info,
	.queuecommand		= cumanascsi_queue_command,
	.eh_abort_handler	= NCR5380_abort,
	.eh_bus_reset_handler	= NCR5380_bus_reset,
	.can_queue		= 16,
	.this_id		= 7,
	.sg_tablesize		= SG_ALL,
	.cmd_per_lun		= 2,
	.use_clustering		= DISABLE_CLUSTERING,
	.proc_name		= "CumanaSCSI-1",
};

227 228
static int cumanascsi1_probe(struct expansion_card *ec,
			     const struct ecard_id *id)
L
Linus Torvalds 已提交
229 230
{
	struct Scsi_Host *host;
231
	int ret;
L
Linus Torvalds 已提交
232

233 234
	ret = ecard_request_resources(ec);
	if (ret)
L
Linus Torvalds 已提交
235 236
		goto out;

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
	host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
	if (!host) {
		ret = -ENOMEM;
		goto out_release;
	}

	priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
				   ecard_resource_len(ec, ECARD_RES_IOCSLOW));
	priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
				  ecard_resource_len(ec, ECARD_RES_MEMC));
	if (!priv(host)->base || !priv(host)->dma) {
		ret = -ENOMEM;
		goto out_unmap;
	}

L
Linus Torvalds 已提交
252 253 254 255
	host->irq = ec->irq;

	NCR5380_init(host, 0);

256 257 258
        priv(host)->ctrl = 0;
        writeb(0, priv(host)->base + CTRL);

L
Linus Torvalds 已提交
259 260 261
	host->n_io_port = 255;
	if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
		ret = -EBUSY;
262
		goto out_unmap;
L
Linus Torvalds 已提交
263 264
	}

265
	ret = request_irq(host->irq, cumanascsi_intr, IRQF_DISABLED,
L
Linus Torvalds 已提交
266 267 268 269
			  "CumanaSCSI-1", host);
	if (ret) {
		printk("scsi%d: IRQ%d not free: %d\n",
		    host->host_no, host->irq, ret);
270
		goto out_unmap;
L
Linus Torvalds 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
	}

	printk("scsi%d: at port 0x%08lx irq %d",
		host->host_no, host->io_port, host->irq);
	printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
		host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
	printk("\nscsi%d:", host->host_no);
	NCR5380_print_options(host);
	printk("\n");

	ret = scsi_add_host(host, &ec->dev);
	if (ret)
		goto out_free_irq;

	scsi_scan_host(host);
	goto out;

 out_free_irq:
	free_irq(host->irq, host);
290 291 292
 out_unmap:
	iounmap(priv(host)->base);
	iounmap(priv(host)->dma);
L
Linus Torvalds 已提交
293
	scsi_host_put(host);
294 295
 out_release:
	ecard_release_resources(ec);
L
Linus Torvalds 已提交
296 297 298 299
 out:
	return ret;
}

300
static void cumanascsi1_remove(struct expansion_card *ec)
L
Linus Torvalds 已提交
301 302 303 304 305 306 307 308
{
	struct Scsi_Host *host = ecard_get_drvdata(ec);

	ecard_set_drvdata(ec, NULL);

	scsi_remove_host(host);
	free_irq(host->irq, host);
	NCR5380_exit(host);
309 310
	iounmap(priv(host)->base);
	iounmap(priv(host)->dma);
L
Linus Torvalds 已提交
311
	scsi_host_put(host);
312
	ecard_release_resources(ec);
L
Linus Torvalds 已提交
313 314 315 316 317 318 319 320 321
}

static const struct ecard_id cumanascsi1_cids[] = {
	{ MANU_CUMANA, PROD_CUMANA_SCSI_1 },
	{ 0xffff, 0xffff }
};

static struct ecard_driver cumanascsi1_driver = {
	.probe		= cumanascsi1_probe,
322
	.remove		= cumanascsi1_remove,
L
Linus Torvalds 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	.id_table	= cumanascsi1_cids,
	.drv = {
		.name		= "cumanascsi1",
	},
};

static int __init cumanascsi_init(void)
{
	return ecard_register_driver(&cumanascsi1_driver);
}

static void __exit cumanascsi_exit(void)
{
	ecard_remove_driver(&cumanascsi1_driver);
}

module_init(cumanascsi_init);
module_exit(cumanascsi_exit);

MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
MODULE_LICENSE("GPL");