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 18
#define priv(host)			((struct NCR5380_hostdata *)(host)->hostdata)

19
#define NCR5380_read(reg) \
20
	readb(priv(instance)->io + ((reg) << 2))
21
#define NCR5380_write(reg, value) \
22
	writeb(value, priv(instance)->io + ((reg) << 2))
23

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

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

32
#define NCR5380_implementation_fields	/* none */
L
Linus Torvalds 已提交
33 34 35 36

#include "../NCR5380.h"

#undef START_DMA_INITIATOR_RECEIVE_REG
37
#define START_DMA_INITIATOR_RECEIVE_REG	(128 + 7)
L
Linus Torvalds 已提交
38

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

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

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

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

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

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

#undef STAT
99
#undef DATA
L
Linus Torvalds 已提交
100 101 102

#include "../NCR5380.c"

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

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

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

129 130 131 132 133 134
	host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
	if (!host) {
		ret = -ENOMEM;
		goto release;
	}

135 136 137
	priv(host)->io = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
	                         ecard_resource_len(ec, ECARD_RES_MEMC));
	if (!priv(host)->io) {
138 139 140 141
		ret = -ENOMEM;
		goto unreg;
	}

F
Finn Thain 已提交
142
	host->irq = NO_IRQ;
L
Linus Torvalds 已提交
143

144
	ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
145 146
	if (ret)
		goto out_unmap;
L
Linus Torvalds 已提交
147

148 149
	NCR5380_maybe_reset_bus(host);

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

	scsi_scan_host(host);
	goto out;

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

169
static void oakscsi_remove(struct expansion_card *ec)
L
Linus Torvalds 已提交
170 171
{
	struct Scsi_Host *host = ecard_get_drvdata(ec);
172
	void __iomem *base = priv(host)->io;
L
Linus Torvalds 已提交
173 174 175 176 177 178

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

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

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

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