oak.c 4.6 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
/*
 * Oak 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>

/*#define PSEUDO_DMA*/

#define OAKSCSI_PUBLIC_RELEASE 1
23
#define DONT_USE_INTR
L
Linus Torvalds 已提交
24

25 26 27 28 29 30
#define priv(host)			((struct NCR5380_hostdata *)(host)->hostdata)
#define NCR5380_local_declare()		void __iomem *_base
#define NCR5380_setup(host)		_base = priv(host)->base

#define NCR5380_read(reg)		readb(_base + ((reg) << 2))
#define NCR5380_write(reg, value)	writeb(value, _base + ((reg) << 2))
L
Linus Torvalds 已提交
31
#define NCR5380_queue_command		oakscsi_queue_command
A
Al Viro 已提交
32 33
#define NCR5380_show_info		oakscsi_show_info
#define NCR5380_write_info		oakscsi_write_info
L
Linus Torvalds 已提交
34

35 36
#define NCR5380_implementation_fields	\
	void __iomem *base
L
Linus Torvalds 已提交
37 38 39 40

#include "../NCR5380.h"

#undef START_DMA_INITIATOR_RECEIVE_REG
41
#define START_DMA_INITIATOR_RECEIVE_REG	(128 + 7)
L
Linus Torvalds 已提交
42 43 44 45 46 47

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

48 49
#define STAT	((128 + 16) << 2)
#define DATA	((128 + 8) << 2)
L
Linus Torvalds 已提交
50 51 52 53

static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
              int len)
{
54 55
  void __iomem *base = priv(instance)->base;

L
Linus Torvalds 已提交
56 57 58 59 60 61
printk("writing %p len %d\n",addr, len);
  if(!len) return -1;

  while(1)
  {
    int status;
62
    while (((status = readw(base + STAT)) & 0x100)==0);
L
Linus Torvalds 已提交
63 64 65 66 67 68
  }
}

static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
              int len)
{
69
  void __iomem *base = priv(instance)->base;
L
Linus Torvalds 已提交
70 71 72
printk("reading %p len %d\n", addr, len);
  while(len > 0)
  {
73
    unsigned int status, timeout;
L
Linus Torvalds 已提交
74 75 76 77
    unsigned long b;
    
    timeout = 0x01FFFFFF;
    
78
    while (((status = readw(base + STAT)) & 0x100)==0)
L
Linus Torvalds 已提交
79 80 81 82
    {
      timeout--;
      if(status & 0x200 || !timeout)
      {
83
        printk("status = %08X\n", status);
L
Linus Torvalds 已提交
84 85 86
        return 1;
      }
    }
87

L
Linus Torvalds 已提交
88 89
    if(len >= 128)
    {
90
      readsw(base + DATA, addr, 128);
L
Linus Torvalds 已提交
91 92 93 94 95
      addr += 128;
      len -= 128;
    }
    else
    {
96
      b = (unsigned long) readw(base + DATA);
L
Linus Torvalds 已提交
97 98 99 100 101 102 103 104 105 106 107
      *addr ++ = b;
      len -= 1;
      if(len)
        *addr ++ = b>>8;
      len -= 1;
    }
  }
  return 0;
}

#undef STAT
108
#undef DATA
L
Linus Torvalds 已提交
109 110 111

#include "../NCR5380.c"

112
static struct scsi_host_template oakscsi_template = {
L
Linus Torvalds 已提交
113
	.module			= THIS_MODULE,
A
Al Viro 已提交
114 115
	.show_info		= oakscsi_show_info,
	.write_info		= oakscsi_write_info,
L
Linus Torvalds 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128
	.name			= "Oak 16-bit SCSI",
	.info			= oakscsi_info,
	.queuecommand		= oakscsi_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		= "oakscsi",
};

129
static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
L
Linus Torvalds 已提交
130 131 132 133
{
	struct Scsi_Host *host;
	int ret = -ENOMEM;

134 135
	ret = ecard_request_resources(ec);
	if (ret)
L
Linus Torvalds 已提交
136 137
		goto out;

138 139 140 141 142 143 144 145 146 147 148 149 150
	host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
	if (!host) {
		ret = -ENOMEM;
		goto release;
	}

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

F
Finn Thain 已提交
151
	host->irq = NO_IRQ;
L
Linus Torvalds 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165
	host->n_io_port = 255;

	NCR5380_init(host, 0);

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

	ret = scsi_add_host(host, &ec->dev);
	if (ret)
166
		goto out_unmap;
L
Linus Torvalds 已提交
167 168 169 170

	scsi_scan_host(host);
	goto out;

171 172
 out_unmap:
	iounmap(priv(host)->base);
L
Linus Torvalds 已提交
173 174
 unreg:
	scsi_host_put(host);
175 176
 release:
	ecard_release_resources(ec);
L
Linus Torvalds 已提交
177 178 179 180
 out:
	return ret;
}

181
static void oakscsi_remove(struct expansion_card *ec)
L
Linus Torvalds 已提交
182 183 184 185 186 187 188
{
	struct Scsi_Host *host = ecard_get_drvdata(ec);

	ecard_set_drvdata(ec, NULL);
	scsi_remove_host(host);

	NCR5380_exit(host);
189
	iounmap(priv(host)->base);
L
Linus Torvalds 已提交
190
	scsi_host_put(host);
191
	ecard_release_resources(ec);
L
Linus Torvalds 已提交
192 193 194 195 196 197 198 199 200
}

static const struct ecard_id oakscsi_cids[] = {
	{ MANU_OAK, PROD_OAK_SCSI },
	{ 0xffff, 0xffff }
};

static struct ecard_driver oakscsi_driver = {
	.probe		= oakscsi_probe,
201
	.remove		= oakscsi_remove,
L
Linus Torvalds 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	.id_table	= oakscsi_cids,
	.drv = {
		.name		= "oakscsi",
	},
};

static int __init oakscsi_init(void)
{
	return ecard_register_driver(&oakscsi_driver);
}

static void __exit oakscsi_exit(void)
{
	ecard_remove_driver(&oakscsi_driver);
}

module_init(oakscsi_init);
module_exit(oakscsi_exit);

MODULE_AUTHOR("Russell King");
MODULE_DESCRIPTION("Oak SCSI driver");
MODULE_LICENSE("GPL");