Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 * Zalon 53c7xx device driver.
  3 * By Richard Hirst (rhirst@linuxcare.com)
  4 */
  5
  6#include <linux/init.h>
  7#include <linux/interrupt.h>
  8#include <linux/module.h>
  9#include <linux/types.h>
 10#include <asm/hardware.h>
 11#include <asm/io.h>
 12
 13#include "../parisc/gsc.h"
 14
 15#include "ncr53c8xx.h"
 16
 17MODULE_AUTHOR("Richard Hirst");
 18MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
 19MODULE_LICENSE("GPL");
 20
 21#define GSC_SCSI_ZALON_OFFSET 0x800
 22
 23#define IO_MODULE_EIM		(1*4)
 24#define IO_MODULE_DC_ADATA	(2*4)
 25#define IO_MODULE_II_CDATA	(3*4)
 26#define IO_MODULE_IO_COMMAND	(12*4)
 27#define IO_MODULE_IO_STATUS	(13*4)
 28
 29#define IOSTATUS_RY		0x40
 30#define IOSTATUS_FE		0x80
 31#define IOIIDATA_SMINT5L	0x40000000
 32#define IOIIDATA_MINT5EN	0x20000000
 33#define IOIIDATA_PACKEN		0x10000000
 34#define IOIIDATA_PREFETCHEN	0x08000000
 35#define IOIIDATA_IOII		0x00000020
 36
 37#define CMD_RESET		5
 38
 39static struct ncr_chip zalon720_chip __initdata = {
 40	.revision_id =	0x0f,
 41	.burst_max =	3,
 42	.offset_max =	8,
 43	.nr_divisor =	4,
 44	.features =	FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
 45};
 46
 47
 48
 49#if 0
 50/* FIXME:
 51 * Is this function dead code? or is someone planning on using it in the
 52 * future.  The clock = (int) pdc_result[16] does not look correct to
 53 * me ... I think it should be iodc_data[16].  Since this cause a compile
 54 * error with the new encapsulated PDC, I'm not compiling in this function.
 55 * - RB
 56 */
 57/* poke SCSI clock out of iodc data */
 58
 59static u8 iodc_data[32] __attribute__ ((aligned (64)));
 60static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
 61
 62static int 
 63lasi_scsi_clock(void * hpa, int defaultclock)
 64{
 65	int clock, status;
 66
 67	status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
 68	if (status == PDC_RET_OK) {
 69		clock = (int) pdc_result[16];
 70	} else {
 71		printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __func__, status);
 72		clock = defaultclock; 
 73	}
 74
 75	printk(KERN_DEBUG "%s: SCSI clock %d\n", __func__, clock);
 76 	return clock;
 77}
 78#endif
 79
 80static struct scsi_host_template zalon7xx_template = {
 81	.module		= THIS_MODULE,
 82	.proc_name	= "zalon7xx",
 83};
 84
 85static int __init
 86zalon_probe(struct parisc_device *dev)
 87{
 88	struct gsc_irq gsc_irq;
 89	u32 zalon_vers;
 90	int error = -ENODEV;
 91	void __iomem *zalon = ioremap_nocache(dev->hpa.start, 4096);
 92	void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
 93	static int unit = 0;
 94	struct Scsi_Host *host;
 95	struct ncr_device device;
 96
 97	__raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
 98	while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
 99		cpu_relax();
100	__raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
101		zalon + IO_MODULE_II_CDATA);
102
103	/* XXX: Save the Zalon version for bug workarounds? */
104	zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07;
105
106	/* Setup the interrupts first.
107	** Later on request_irq() will register the handler.
108	*/
109	dev->irq = gsc_alloc_irq(&gsc_irq);
110
111	printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__,
112		zalon_vers, dev->irq);
113
114	__raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM);
115
116	if (zalon_vers == 0)
117		printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__);
118
119	memset(&device, 0, sizeof(struct ncr_device));
120
121	/* The following three are needed before any other access. */
122	__raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG,  EA  */
123	__raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
124	__raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
125
126	/* Initialise ncr_device structure with items required by ncr_attach. */
127	device.chip		= zalon720_chip;
128	device.host_id		= 7;
129	device.dev		= &dev->dev;
130	device.slot.base	= dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
131	device.slot.base_v	= io_port;
132	device.slot.irq		= dev->irq;
133	device.differential	= 2;
134
135	host = ncr_attach(&zalon7xx_template, unit, &device);
136	if (!host)
137		return -ENODEV;
138
139	if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
140	  dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
141		     dev->irq);
142		goto fail;
143	}
144
145	unit++;
146
147	dev_set_drvdata(&dev->dev, host);
148
149	error = scsi_add_host(host, &dev->dev);
150	if (error)
151		goto fail_free_irq;
152
153	scsi_scan_host(host);
154	return 0;
155
156 fail_free_irq:
157	free_irq(dev->irq, host);
158 fail:
159	ncr53c8xx_release(host);
160	return error;
161}
162
163static struct parisc_device_id zalon_tbl[] = {
164	{ HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 
165	{ 0, }
166};
167
168MODULE_DEVICE_TABLE(parisc, zalon_tbl);
169
170static int __exit zalon_remove(struct parisc_device *dev)
171{
172	struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
173
174	scsi_remove_host(host);
175	ncr53c8xx_release(host);
176	free_irq(dev->irq, host);
177
178	return 0;
179}
180
181static struct parisc_driver zalon_driver = {
182	.name =		"zalon",
183	.id_table =	zalon_tbl,
184	.probe =	zalon_probe,
185	.remove =	__devexit_p(zalon_remove),
186};
187
188static int __init zalon7xx_init(void)
189{
190	int ret = ncr53c8xx_init();
191	if (!ret)
192		ret = register_parisc_driver(&zalon_driver);
193	if (ret)
194		ncr53c8xx_exit();
195	return ret;
196}
197
198static void __exit zalon7xx_exit(void)
199{
200	unregister_parisc_driver(&zalon_driver);
201	ncr53c8xx_exit();
202}
203
204module_init(zalon7xx_init);
205module_exit(zalon7xx_exit);
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Zalon 53c7xx device driver.
  4 * By Richard Hirst (rhirst@linuxcare.com)
  5 */
  6
  7#include <linux/init.h>
  8#include <linux/interrupt.h>
  9#include <linux/module.h>
 10#include <linux/types.h>
 11#include <asm/hardware.h>
 12#include <asm/io.h>
 13
 14#include "../parisc/gsc.h"
 15
 16#include "ncr53c8xx.h"
 17
 18MODULE_AUTHOR("Richard Hirst");
 19MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
 20MODULE_LICENSE("GPL");
 21
 22#define GSC_SCSI_ZALON_OFFSET 0x800
 23
 24#define IO_MODULE_EIM		(1*4)
 25#define IO_MODULE_DC_ADATA	(2*4)
 26#define IO_MODULE_II_CDATA	(3*4)
 27#define IO_MODULE_IO_COMMAND	(12*4)
 28#define IO_MODULE_IO_STATUS	(13*4)
 29
 30#define IOSTATUS_RY		0x40
 31#define IOSTATUS_FE		0x80
 32#define IOIIDATA_SMINT5L	0x40000000
 33#define IOIIDATA_MINT5EN	0x20000000
 34#define IOIIDATA_PACKEN		0x10000000
 35#define IOIIDATA_PREFETCHEN	0x08000000
 36#define IOIIDATA_IOII		0x00000020
 37
 38#define CMD_RESET		5
 39
 40static struct ncr_chip zalon720_chip __initdata = {
 41	.revision_id =	0x0f,
 42	.burst_max =	3,
 43	.offset_max =	8,
 44	.nr_divisor =	4,
 45	.features =	FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
 46};
 47
 48
 49
 50#if 0
 51/* FIXME:
 52 * Is this function dead code? or is someone planning on using it in the
 53 * future.  The clock = (int) pdc_result[16] does not look correct to
 54 * me ... I think it should be iodc_data[16].  Since this cause a compile
 55 * error with the new encapsulated PDC, I'm not compiling in this function.
 56 * - RB
 57 */
 58/* poke SCSI clock out of iodc data */
 59
 60static u8 iodc_data[32] __attribute__ ((aligned (64)));
 61static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
 62
 63static int 
 64lasi_scsi_clock(void * hpa, int defaultclock)
 65{
 66	int clock, status;
 67
 68	status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
 69	if (status == PDC_RET_OK) {
 70		clock = (int) pdc_result[16];
 71	} else {
 72		printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __func__, status);
 73		clock = defaultclock; 
 74	}
 75
 76	printk(KERN_DEBUG "%s: SCSI clock %d\n", __func__, clock);
 77 	return clock;
 78}
 79#endif
 80
 81static struct scsi_host_template zalon7xx_template = {
 82	.module		= THIS_MODULE,
 83	.proc_name	= "zalon7xx",
 84};
 85
 86static int __init
 87zalon_probe(struct parisc_device *dev)
 88{
 89	struct gsc_irq gsc_irq;
 90	u32 zalon_vers;
 91	int error = -ENODEV;
 92	void __iomem *zalon = ioremap(dev->hpa.start, 4096);
 93	void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
 94	static int unit = 0;
 95	struct Scsi_Host *host;
 96	struct ncr_device device;
 97
 98	__raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
 99	while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
100		cpu_relax();
101	__raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
102		zalon + IO_MODULE_II_CDATA);
103
104	/* XXX: Save the Zalon version for bug workarounds? */
105	zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07;
106
107	/* Setup the interrupts first.
108	** Later on request_irq() will register the handler.
109	*/
110	dev->irq = gsc_alloc_irq(&gsc_irq);
111
112	printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__,
113		zalon_vers, dev->irq);
114
115	__raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM);
116
117	if (zalon_vers == 0)
118		printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__);
119
120	memset(&device, 0, sizeof(struct ncr_device));
121
122	/* The following three are needed before any other access. */
123	__raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG,  EA  */
124	__raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
125	__raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
126
127	/* Initialise ncr_device structure with items required by ncr_attach. */
128	device.chip		= zalon720_chip;
129	device.host_id		= 7;
130	device.dev		= &dev->dev;
131	device.slot.base	= dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
132	device.slot.base_v	= io_port;
133	device.slot.irq		= dev->irq;
134	device.differential	= 2;
135
136	host = ncr_attach(&zalon7xx_template, unit, &device);
137	if (!host)
138		return -ENODEV;
139
140	if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
141	  dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
142		     dev->irq);
143		goto fail;
144	}
145
146	unit++;
147
148	dev_set_drvdata(&dev->dev, host);
149
150	error = scsi_add_host(host, &dev->dev);
151	if (error)
152		goto fail_free_irq;
153
154	scsi_scan_host(host);
155	return 0;
156
157 fail_free_irq:
158	free_irq(dev->irq, host);
159 fail:
160	ncr53c8xx_release(host);
161	return error;
162}
163
164static const struct parisc_device_id zalon_tbl[] __initconst = {
165	{ HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 
166	{ 0, }
167};
168
169MODULE_DEVICE_TABLE(parisc, zalon_tbl);
170
171static int __exit zalon_remove(struct parisc_device *dev)
172{
173	struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
174
175	scsi_remove_host(host);
176	ncr53c8xx_release(host);
177	free_irq(dev->irq, host);
178
179	return 0;
180}
181
182static struct parisc_driver zalon_driver __refdata = {
183	.name =		"zalon",
184	.id_table =	zalon_tbl,
185	.probe =	zalon_probe,
186	.remove =	__exit_p(zalon_remove),
187};
188
189static int __init zalon7xx_init(void)
190{
191	int ret = ncr53c8xx_init();
192	if (!ret)
193		ret = register_parisc_driver(&zalon_driver);
194	if (ret)
195		ncr53c8xx_exit();
196	return ret;
197}
198
199static void __exit zalon7xx_exit(void)
200{
201	unregister_parisc_driver(&zalon_driver);
202	ncr53c8xx_exit();
203}
204
205module_init(zalon7xx_init);
206module_exit(zalon7xx_exit);