]>
Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
352e921f | 2 | /* jazz_esp.c: ESP front-end for MIPS JAZZ systems. |
1da177e4 | 3 | * |
d36b6910 | 4 | * Copyright (C) 2007 Thomas Bogendörfer ([email protected]) |
1da177e4 LT |
5 | */ |
6 | ||
1da177e4 | 7 | #include <linux/kernel.h> |
5a0e3ad6 | 8 | #include <linux/gfp.h> |
1da177e4 | 9 | #include <linux/types.h> |
352e921f TB |
10 | #include <linux/module.h> |
11 | #include <linux/init.h> | |
12 | #include <linux/interrupt.h> | |
13 | #include <linux/platform_device.h> | |
14 | #include <linux/dma-mapping.h> | |
1da177e4 LT |
15 | |
16 | #include <asm/irq.h> | |
352e921f TB |
17 | #include <asm/io.h> |
18 | #include <asm/dma.h> | |
19 | ||
1da177e4 LT |
20 | #include <asm/jazz.h> |
21 | #include <asm/jazzdma.h> | |
1da177e4 | 22 | |
352e921f | 23 | #include <scsi/scsi_host.h> |
1da177e4 | 24 | |
352e921f | 25 | #include "esp_scsi.h" |
1da177e4 | 26 | |
352e921f TB |
27 | #define DRV_MODULE_NAME "jazz_esp" |
28 | #define PFX DRV_MODULE_NAME ": " | |
29 | #define DRV_VERSION "1.000" | |
30 | #define DRV_MODULE_RELDATE "May 19, 2007" | |
1da177e4 | 31 | |
352e921f | 32 | static void jazz_esp_write8(struct esp *esp, u8 val, unsigned long reg) |
1da177e4 | 33 | { |
352e921f | 34 | *(volatile u8 *)(esp->regs + reg) = val; |
1da177e4 LT |
35 | } |
36 | ||
352e921f | 37 | static u8 jazz_esp_read8(struct esp *esp, unsigned long reg) |
1da177e4 | 38 | { |
352e921f | 39 | return *(volatile u8 *)(esp->regs + reg); |
1da177e4 LT |
40 | } |
41 | ||
352e921f | 42 | static int jazz_esp_irq_pending(struct esp *esp) |
1da177e4 | 43 | { |
352e921f TB |
44 | if (jazz_esp_read8(esp, ESP_STATUS) & ESP_STAT_INTR) |
45 | return 1; | |
46 | return 0; | |
1da177e4 LT |
47 | } |
48 | ||
352e921f | 49 | static void jazz_esp_reset_dma(struct esp *esp) |
1da177e4 | 50 | { |
352e921f | 51 | vdma_disable ((int)esp->dma_regs); |
1da177e4 LT |
52 | } |
53 | ||
352e921f | 54 | static void jazz_esp_dma_drain(struct esp *esp) |
1da177e4 | 55 | { |
352e921f | 56 | /* nothing to do */ |
1da177e4 LT |
57 | } |
58 | ||
352e921f | 59 | static void jazz_esp_dma_invalidate(struct esp *esp) |
1da177e4 | 60 | { |
352e921f | 61 | vdma_disable ((int)esp->dma_regs); |
1da177e4 LT |
62 | } |
63 | ||
352e921f TB |
64 | static void jazz_esp_send_dma_cmd(struct esp *esp, u32 addr, u32 esp_count, |
65 | u32 dma_count, int write, u8 cmd) | |
1da177e4 | 66 | { |
352e921f TB |
67 | BUG_ON(!(cmd & ESP_CMD_DMA)); |
68 | ||
69 | jazz_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW); | |
70 | jazz_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED); | |
71 | vdma_disable ((int)esp->dma_regs); | |
72 | if (write) | |
73 | vdma_set_mode ((int)esp->dma_regs, DMA_MODE_READ); | |
74 | else | |
75 | vdma_set_mode ((int)esp->dma_regs, DMA_MODE_WRITE); | |
76 | ||
77 | vdma_set_addr ((int)esp->dma_regs, addr); | |
78 | vdma_set_count ((int)esp->dma_regs, dma_count); | |
79 | vdma_enable ((int)esp->dma_regs); | |
80 | ||
81 | scsi_esp_cmd(esp, cmd); | |
1da177e4 LT |
82 | } |
83 | ||
352e921f | 84 | static int jazz_esp_dma_error(struct esp *esp) |
1da177e4 | 85 | { |
352e921f TB |
86 | u32 enable = vdma_get_enable((int)esp->dma_regs); |
87 | ||
88 | if (enable & (R4030_MEM_INTR|R4030_ADDR_INTR)) | |
89 | return 1; | |
90 | ||
91 | return 0; | |
1da177e4 LT |
92 | } |
93 | ||
352e921f TB |
94 | static const struct esp_driver_ops jazz_esp_ops = { |
95 | .esp_write8 = jazz_esp_write8, | |
96 | .esp_read8 = jazz_esp_read8, | |
352e921f TB |
97 | .irq_pending = jazz_esp_irq_pending, |
98 | .reset_dma = jazz_esp_reset_dma, | |
99 | .dma_drain = jazz_esp_dma_drain, | |
100 | .dma_invalidate = jazz_esp_dma_invalidate, | |
101 | .send_dma_cmd = jazz_esp_send_dma_cmd, | |
102 | .dma_error = jazz_esp_dma_error, | |
103 | }; | |
104 | ||
6f039790 | 105 | static int esp_jazz_probe(struct platform_device *dev) |
1da177e4 | 106 | { |
3b465a14 | 107 | const struct scsi_host_template *tpnt = &scsi_esp_template; |
352e921f TB |
108 | struct Scsi_Host *host; |
109 | struct esp *esp; | |
110 | struct resource *res; | |
111 | int err; | |
112 | ||
113 | host = scsi_host_alloc(tpnt, sizeof(struct esp)); | |
114 | ||
115 | err = -ENOMEM; | |
116 | if (!host) | |
117 | goto fail; | |
118 | ||
119 | host->max_id = 8; | |
2b14ec78 | 120 | esp = shost_priv(host); |
352e921f TB |
121 | |
122 | esp->host = host; | |
e32ec657 | 123 | esp->dev = &dev->dev; |
352e921f TB |
124 | esp->ops = &jazz_esp_ops; |
125 | ||
126 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | |
127 | if (!res) | |
128 | goto fail_unlink; | |
129 | ||
130 | esp->regs = (void __iomem *)res->start; | |
131 | if (!esp->regs) | |
132 | goto fail_unlink; | |
133 | ||
134 | res = platform_get_resource(dev, IORESOURCE_MEM, 1); | |
135 | if (!res) | |
136 | goto fail_unlink; | |
137 | ||
138 | esp->dma_regs = (void __iomem *)res->start; | |
139 | ||
140 | esp->command_block = dma_alloc_coherent(esp->dev, 16, | |
141 | &esp->command_block_dma, | |
142 | GFP_KERNEL); | |
143 | if (!esp->command_block) | |
144 | goto fail_unmap_regs; | |
145 | ||
38fca15c SS |
146 | host->irq = err = platform_get_irq(dev, 0); |
147 | if (err < 0) | |
148 | goto fail_unmap_command_block; | |
352e921f TB |
149 | err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp); |
150 | if (err < 0) | |
151 | goto fail_unmap_command_block; | |
152 | ||
153 | esp->scsi_id = 7; | |
154 | esp->host->this_id = esp->scsi_id; | |
155 | esp->scsi_id_mask = (1 << esp->scsi_id); | |
156 | esp->cfreq = 40000000; | |
157 | ||
158 | dev_set_drvdata(&dev->dev, esp); | |
159 | ||
44b1b4d2 | 160 | err = scsi_esp_register(esp); |
352e921f TB |
161 | if (err) |
162 | goto fail_free_irq; | |
163 | ||
164 | return 0; | |
165 | ||
166 | fail_free_irq: | |
167 | free_irq(host->irq, esp); | |
168 | fail_unmap_command_block: | |
169 | dma_free_coherent(esp->dev, 16, | |
170 | esp->command_block, | |
171 | esp->command_block_dma); | |
172 | fail_unmap_regs: | |
173 | fail_unlink: | |
174 | scsi_host_put(host); | |
175 | fail: | |
176 | return err; | |
1da177e4 LT |
177 | } |
178 | ||
c71ef3d1 | 179 | static void esp_jazz_remove(struct platform_device *dev) |
1da177e4 | 180 | { |
352e921f TB |
181 | struct esp *esp = dev_get_drvdata(&dev->dev); |
182 | unsigned int irq = esp->host->irq; | |
183 | ||
184 | scsi_esp_unregister(esp); | |
185 | ||
186 | free_irq(irq, esp); | |
187 | dma_free_coherent(esp->dev, 16, | |
188 | esp->command_block, | |
189 | esp->command_block_dma); | |
190 | ||
191 | scsi_host_put(esp->host); | |
1da177e4 LT |
192 | } |
193 | ||
ecc1241e KS |
194 | /* work with hotplug and coldplug */ |
195 | MODULE_ALIAS("platform:jazz_esp"); | |
196 | ||
352e921f TB |
197 | static struct platform_driver esp_jazz_driver = { |
198 | .probe = esp_jazz_probe, | |
c71ef3d1 | 199 | .remove_new = esp_jazz_remove, |
352e921f TB |
200 | .driver = { |
201 | .name = "jazz_esp", | |
202 | }, | |
203 | }; | |
7fc83de5 | 204 | module_platform_driver(esp_jazz_driver); |
1da177e4 | 205 | |
352e921f | 206 | MODULE_DESCRIPTION("JAZZ ESP SCSI driver"); |
6a57a219 | 207 | MODULE_AUTHOR("Thomas Bogendoerfer <[email protected]>"); |
352e921f TB |
208 | MODULE_LICENSE("GPL"); |
209 | MODULE_VERSION(DRV_VERSION); |