oak.c 4.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Oak Generic NCR5380 driver
 *
 * Copyright 1995-2002, Russell King
 */

#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/blkdev.h>
#include <linux/init.h>

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

#include <scsi/scsi_host.h>

17
#define DONT_USE_INTR
L
Linus Torvalds 已提交
18

19 20
#define priv(host)			((struct NCR5380_hostdata *)(host)->hostdata)

21 22 23 24 25
#define NCR5380_read(reg) \
	readb(priv(instance)->base + ((reg) << 2))
#define NCR5380_write(reg, value) \
	writeb(value, priv(instance)->base + ((reg) << 2))

F
Finn Thain 已提交
26
#define NCR5380_dma_xfer_len(instance, cmd, phase)	(0)
F
Finn Thain 已提交
27 28
#define NCR5380_dma_recv_setup		oakscsi_pread
#define NCR5380_dma_send_setup		oakscsi_pwrite
29

L
Linus Torvalds 已提交
30
#define NCR5380_queue_command		oakscsi_queue_command
F
Finn Thain 已提交
31
#define NCR5380_info			oakscsi_info
L
Linus Torvalds 已提交
32

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

#include "../NCR5380.h"

#undef START_DMA_INITIATOR_RECEIVE_REG
39
#define START_DMA_INITIATOR_RECEIVE_REG	(128 + 7)
L
Linus Torvalds 已提交
40

41 42
#define STAT	((128 + 16) << 2)
#define DATA	((128 + 8) << 2)
L
Linus Torvalds 已提交
43

F
Finn Thain 已提交
44 45
static inline int oakscsi_pwrite(struct Scsi_Host *instance,
                                 unsigned char *addr, int len)
L
Linus Torvalds 已提交
46
{
47 48
  void __iomem *base = priv(instance)->base;

L
Linus Torvalds 已提交
49 50 51 52 53
printk("writing %p len %d\n",addr, len);

  while(1)
  {
    int status;
54
    while (((status = readw(base + STAT)) & 0x100)==0);
L
Linus Torvalds 已提交
55
  }
56
  return 0;
L
Linus Torvalds 已提交
57 58
}

F
Finn Thain 已提交
59 60
static inline int oakscsi_pread(struct Scsi_Host *instance,
                                unsigned char *addr, int len)
L
Linus Torvalds 已提交
61
{
62
  void __iomem *base = priv(instance)->base;
L
Linus Torvalds 已提交
63 64 65
printk("reading %p len %d\n", addr, len);
  while(len > 0)
  {
66
    unsigned int status, timeout;
L
Linus Torvalds 已提交
67 68 69 70
    unsigned long b;
    
    timeout = 0x01FFFFFF;
    
71
    while (((status = readw(base + STAT)) & 0x100)==0)
L
Linus Torvalds 已提交
72 73 74 75
    {
      timeout--;
      if(status & 0x200 || !timeout)
      {
76
        printk("status = %08X\n", status);
77
        return -1;
L
Linus Torvalds 已提交
78 79
      }
    }
80

L
Linus Torvalds 已提交
81 82
    if(len >= 128)
    {
83
      readsw(base + DATA, addr, 128);
L
Linus Torvalds 已提交
84 85 86 87 88
      addr += 128;
      len -= 128;
    }
    else
    {
89
      b = (unsigned long) readw(base + DATA);
L
Linus Torvalds 已提交
90 91 92 93 94 95 96 97 98 99 100
      *addr ++ = b;
      len -= 1;
      if(len)
        *addr ++ = b>>8;
      len -= 1;
    }
  }
  return 0;
}

#undef STAT
101
#undef DATA
L
Linus Torvalds 已提交
102 103 104

#include "../NCR5380.c"

105
static struct scsi_host_template oakscsi_template = {
L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113 114 115 116 117
	.module			= THIS_MODULE,
	.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",
118
	.cmd_size		= NCR5380_CMD_SIZE,
F
Finn Thain 已提交
119
	.max_sectors		= 128,
L
Linus Torvalds 已提交
120 121
};

122
static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
L
Linus Torvalds 已提交
123 124 125 126
{
	struct Scsi_Host *host;
	int ret = -ENOMEM;

127 128
	ret = ecard_request_resources(ec);
	if (ret)
L
Linus Torvalds 已提交
129 130
		goto out;

131 132 133 134 135 136 137 138 139 140 141 142 143
	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 已提交
144
	host->irq = NO_IRQ;
L
Linus Torvalds 已提交
145 146
	host->n_io_port = 255;

147
	ret = NCR5380_init(host, FLAG_DMA_FIXUP);
148 149
	if (ret)
		goto out_unmap;
L
Linus Torvalds 已提交
150

151 152
	NCR5380_maybe_reset_bus(host);

L
Linus Torvalds 已提交
153 154
	ret = scsi_add_host(host, &ec->dev);
	if (ret)
155
		goto out_exit;
L
Linus Torvalds 已提交
156 157 158 159

	scsi_scan_host(host);
	goto out;

160 161
 out_exit:
	NCR5380_exit(host);
162 163
 out_unmap:
	iounmap(priv(host)->base);
L
Linus Torvalds 已提交
164 165
 unreg:
	scsi_host_put(host);
166 167
 release:
	ecard_release_resources(ec);
L
Linus Torvalds 已提交
168 169 170 171
 out:
	return ret;
}

172
static void oakscsi_remove(struct expansion_card *ec)
L
Linus Torvalds 已提交
173 174 175 176 177 178 179
{
	struct Scsi_Host *host = ecard_get_drvdata(ec);

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

	NCR5380_exit(host);
180
	iounmap(priv(host)->base);
L
Linus Torvalds 已提交
181
	scsi_host_put(host);
182
	ecard_release_resources(ec);
L
Linus Torvalds 已提交
183 184 185 186 187 188 189 190 191
}

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

static struct ecard_driver oakscsi_driver = {
	.probe		= oakscsi_probe,
192
	.remove		= oakscsi_remove,
L
Linus Torvalds 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
	.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");