1/*
2 * Zalon 53c7xx device driver.
3 * By Richard Hirst (rhirst@linuxcare.com)
4 */
5
6#include <linux/init.h>
7#include <linux/types.h>
8#include <linux/stat.h>
9#include <linux/mm.h>
10#include <linux/blk.h>
11#include <linux/sched.h>
12#include <linux/version.h>
13#include <linux/config.h>
14#include <linux/module.h>
15
16#include <asm/page.h>
17#include <asm/pgtable.h>
18#include <asm/irq.h>
19#include <asm/hardware.h>
20#include <asm/delay.h>
21#include <asm/gsc.h>
22
23#include "scsi.h"
24#include "hosts.h"
25
26/*
27 * **      Define the BSD style u_int32 and u_int64 type.
28 * **      Are in fact u_int32_t and u_int64_t :-)
29 * */
30typedef u32 u_int32;
31typedef u64 u_int64;
32typedef u_long          vm_offset_t;
33
34#include "zalon7xx.h"
35
36
37/* hosts_* are kluges to pass info between the zalon7xx_detected()
38** and the register_parisc_driver() callbacks.
39*/
40static Scsi_Host_Template *hosts_tptr;
41static int hosts_used=0;
42static int zalon_id = 0;
43
44extern int zalon_attach(Scsi_Host_Template *tpnt,
45			unsigned long base_addr,
46			struct parisc_device *dev,
47			int irq_vector,
48			int unit
49			);
50
51
52
53static int __init
54zalon_scsi_callback(struct parisc_device *dev)
55{
56	struct gsc_irq gsc_irq;
57	u32 zalon_vers;
58	int irq;
59	unsigned long zalon = dev->hpa;
60
61	__raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
62	while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
63		;
64	__raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
65		zalon + IO_MODULE_II_CDATA);
66
67	zalon_vers = __raw_readl(dev->hpa + IO_MODULE_II_CDATA) & 0x07000000;
68	zalon_vers >>= 24;
69
70	/* Setup the interrupts first.
71	** Later on request_irq() will register the handler.
72	*/
73        irq = gsc_alloc_irq(&gsc_irq);
74
75	printk("%s: Zalon vers field is 0x%x, IRQ %d\n", __FUNCTION__,
76		zalon_vers, irq);
77
78	__raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, dev->hpa + IO_MODULE_EIM);
79
80	if ( zalon_vers == 0)
81		printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __FUNCTION__);
82
83	/*
84	**  zalon_attach: returns -1 on failure, 0 on success
85	*/
86	hosts_used = zalon_attach(hosts_tptr, dev->hpa + GSC_SCSI_ZALON_OFFSET,
87			dev, irq, zalon_id);
88
89	if (hosts_used == 0)
90		zalon_id++;
91
92	hosts_used = (hosts_used == 0);
93	return (hosts_used == 0);
94}
95
96static struct parisc_device_id zalon_tbl[] = {
97	{ HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 },
98	{ 0, }
99};
100
101MODULE_DEVICE_TABLE(parisc, zalon_tbl);
102
103static struct parisc_driver zalon_driver = {
104	name:		"GSC SCSI (Zalon)",
105	id_table:	zalon_tbl,
106	probe:		zalon_scsi_callback,
107};
108
109int zalon7xx_detect(Scsi_Host_Template *tpnt)
110{
111	/* "pass" the parameter to the callback functions */
112	hosts_tptr = tpnt;
113	hosts_used = 0;
114
115	/* claim all zalon cards. */
116	register_parisc_driver(&zalon_driver);
117
118	/* Check if any callbacks actually found/claimed anything. */
119	return (hosts_used != 0);
120}
121
122#ifdef MODULE
123extern int ncr53c8xx_release(struct Scsi_Host *host);
124
125int zalon7xx_release(struct Scsi_Host *host)
126{
127	ncr53c8xx_release(host);
128	unregister_parisc_driver(&zalon_driver);
129	return 1;
130}
131#endif
132