Linux 6.10-rc3
[sfrench/cifs-2.6.git] / drivers / scsi / zalon.c
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
18 MODULE_AUTHOR("Richard Hirst");
19 MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
20 MODULE_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
40 static 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
60 static u8 iodc_data[32] __attribute__ ((aligned (64)));
61 static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
62
63 static int 
64 lasi_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
81 static struct scsi_host_template zalon7xx_template = {
82         .module         = THIS_MODULE,
83         .proc_name      = "zalon7xx",
84         .cmd_size       = sizeof(struct ncr_cmd_priv),
85 };
86
87 static int __init
88 zalon_probe(struct parisc_device *dev)
89 {
90         struct gsc_irq gsc_irq;
91         u32 zalon_vers;
92         int error = -ENODEV;
93         void __iomem *zalon = ioremap(dev->hpa.start, 4096);
94         void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
95         static int unit = 0;
96         struct Scsi_Host *host;
97         struct ncr_device device;
98
99         __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
100         while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
101                 cpu_relax();
102         __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
103                 zalon + IO_MODULE_II_CDATA);
104
105         /* XXX: Save the Zalon version for bug workarounds? */
106         zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07;
107
108         /* Setup the interrupts first.
109         ** Later on request_irq() will register the handler.
110         */
111         dev->irq = gsc_alloc_irq(&gsc_irq);
112
113         printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__,
114                 zalon_vers, dev->irq);
115
116         __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM);
117
118         if (zalon_vers == 0)
119                 printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__);
120
121         memset(&device, 0, sizeof(struct ncr_device));
122
123         /* The following three are needed before any other access. */
124         __raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG,  EA  */
125         __raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
126         __raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
127
128         /* Initialise ncr_device structure with items required by ncr_attach. */
129         device.chip             = zalon720_chip;
130         device.host_id          = 7;
131         device.dev              = &dev->dev;
132         device.slot.base        = dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
133         device.slot.base_v      = io_port;
134         device.slot.irq         = dev->irq;
135         device.differential     = 2;
136
137         host = ncr_attach(&zalon7xx_template, unit, &device);
138         if (!host)
139                 return -ENODEV;
140
141         if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
142           dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
143                      dev->irq);
144                 goto fail;
145         }
146
147         unit++;
148
149         dev_set_drvdata(&dev->dev, host);
150
151         error = scsi_add_host(host, &dev->dev);
152         if (error)
153                 goto fail_free_irq;
154
155         scsi_scan_host(host);
156         return 0;
157
158  fail_free_irq:
159         free_irq(dev->irq, host);
160  fail:
161         ncr53c8xx_release(host);
162         return error;
163 }
164
165 static const struct parisc_device_id zalon_tbl[] __initconst = {
166         { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 
167         { 0, }
168 };
169
170 MODULE_DEVICE_TABLE(parisc, zalon_tbl);
171
172 static void __exit zalon_remove(struct parisc_device *dev)
173 {
174         struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
175
176         scsi_remove_host(host);
177         ncr53c8xx_release(host);
178         free_irq(dev->irq, host);
179 }
180
181 static struct parisc_driver zalon_driver __refdata = {
182         .name =         "zalon",
183         .id_table =     zalon_tbl,
184         .probe =        zalon_probe,
185         .remove =       __exit_p(zalon_remove),
186 };
187
188 static 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
198 static void __exit zalon7xx_exit(void)
199 {
200         unregister_parisc_driver(&zalon_driver);
201         ncr53c8xx_exit();
202 }
203
204 module_init(zalon7xx_init);
205 module_exit(zalon7xx_exit);