aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sun_esp.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-08-27 03:20:58 -0400
committerDavid S. Miller <davem@davemloft.net>2008-08-29 05:14:45 -0400
commit05bb5e93f2ef3f14e0c5a7e9281d07e7a7e4233d (patch)
tree4adafe57fdb557796448ebf69e9999c638ad0284 /drivers/scsi/sun_esp.c
parent27167e0e63a9c53477a7de1c55888bd660c3f9a6 (diff)
sun_esp: Convert to pure OF driver.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/scsi/sun_esp.c')
-rw-r--r--drivers/scsi/sun_esp.c136
1 files changed, 64 insertions, 72 deletions
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c
index ea0c572c7504..97316ca28a7a 100644
--- a/drivers/scsi/sun_esp.c
+++ b/drivers/scsi/sun_esp.c
@@ -10,21 +10,21 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/of.h>
14#include <linux/of_device.h>
13 15
14#include <asm/irq.h> 16#include <asm/irq.h>
15#include <asm/io.h> 17#include <asm/io.h>
16#include <asm/dma.h> 18#include <asm/dma.h>
17 19
18#include <asm/sbus.h>
19
20#include <scsi/scsi_host.h> 20#include <scsi/scsi_host.h>
21 21
22#include "esp_scsi.h" 22#include "esp_scsi.h"
23 23
24#define DRV_MODULE_NAME "sun_esp" 24#define DRV_MODULE_NAME "sun_esp"
25#define PFX DRV_MODULE_NAME ": " 25#define PFX DRV_MODULE_NAME ": "
26#define DRV_VERSION "1.000" 26#define DRV_VERSION "1.100"
27#define DRV_MODULE_RELDATE "April 19, 2007" 27#define DRV_MODULE_RELDATE "August 27, 2008"
28 28
29#define dma_read32(REG) \ 29#define dma_read32(REG) \
30 sbus_readl(esp->dma_regs + (REG)) 30 sbus_readl(esp->dma_regs + (REG))
@@ -80,18 +80,18 @@ static int __devinit esp_sbus_setup_dma(struct esp *esp,
80 80
81static int __devinit esp_sbus_map_regs(struct esp *esp, int hme) 81static int __devinit esp_sbus_map_regs(struct esp *esp, int hme)
82{ 82{
83 struct sbus_dev *sdev = esp->dev; 83 struct of_device *op = esp->dev;
84 struct resource *res; 84 struct resource *res;
85 85
86 /* On HME, two reg sets exist, first is DVMA, 86 /* On HME, two reg sets exist, first is DVMA,
87 * second is ESP registers. 87 * second is ESP registers.
88 */ 88 */
89 if (hme) 89 if (hme)
90 res = &sdev->resource[1]; 90 res = &op->resource[1];
91 else 91 else
92 res = &sdev->resource[0]; 92 res = &op->resource[0];
93 93
94 esp->regs = sbus_ioremap(res, 0, SBUS_ESP_REG_SIZE, "ESP"); 94 esp->regs = of_ioremap(res, 0, SBUS_ESP_REG_SIZE, "ESP");
95 if (!esp->regs) 95 if (!esp->regs)
96 return -ENOMEM; 96 return -ENOMEM;
97 97
@@ -100,9 +100,9 @@ static int __devinit esp_sbus_map_regs(struct esp *esp, int hme)
100 100
101static int __devinit esp_sbus_map_command_block(struct esp *esp) 101static int __devinit esp_sbus_map_command_block(struct esp *esp)
102{ 102{
103 struct sbus_dev *sdev = esp->dev; 103 struct of_device *op = esp->dev;
104 104
105 esp->command_block = dma_alloc_coherent(&sdev->ofdev.dev, 16, 105 esp->command_block = dma_alloc_coherent(&op->dev, 16,
106 &esp->command_block_dma, 106 &esp->command_block_dma,
107 GFP_ATOMIC); 107 GFP_ATOMIC);
108 if (!esp->command_block) 108 if (!esp->command_block)
@@ -113,17 +113,18 @@ static int __devinit esp_sbus_map_command_block(struct esp *esp)
113static int __devinit esp_sbus_register_irq(struct esp *esp) 113static int __devinit esp_sbus_register_irq(struct esp *esp)
114{ 114{
115 struct Scsi_Host *host = esp->host; 115 struct Scsi_Host *host = esp->host;
116 struct sbus_dev *sdev = esp->dev; 116 struct of_device *op = esp->dev;
117 117
118 host->irq = sdev->irqs[0]; 118 host->irq = op->irqs[0];
119 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp); 119 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
120} 120}
121 121
122static void __devinit esp_get_scsi_id(struct esp *esp) 122static void __devinit esp_get_scsi_id(struct esp *esp, struct of_device *espdma)
123{ 123{
124 struct sbus_dev *sdev = esp->dev; 124 struct of_device *op = esp->dev;
125 struct device_node *dp = sdev->ofdev.node; 125 struct device_node *dp;
126 126
127 dp = op->node;
127 esp->scsi_id = of_getintprop_default(dp, "initiator-id", 0xff); 128 esp->scsi_id = of_getintprop_default(dp, "initiator-id", 0xff);
128 if (esp->scsi_id != 0xff) 129 if (esp->scsi_id != 0xff)
129 goto done; 130 goto done;
@@ -132,13 +133,7 @@ static void __devinit esp_get_scsi_id(struct esp *esp)
132 if (esp->scsi_id != 0xff) 133 if (esp->scsi_id != 0xff)
133 goto done; 134 goto done;
134 135
135 if (!sdev->bus) { 136 esp->scsi_id = of_getintprop_default(espdma->node,
136 /* SUN4 */
137 esp->scsi_id = 7;
138 goto done;
139 }
140
141 esp->scsi_id = of_getintprop_default(sdev->bus->ofdev.node,
142 "scsi-initiator-id", 7); 137 "scsi-initiator-id", 7);
143 138
144done: 139done:
@@ -148,9 +143,10 @@ done:
148 143
149static void __devinit esp_get_differential(struct esp *esp) 144static void __devinit esp_get_differential(struct esp *esp)
150{ 145{
151 struct sbus_dev *sdev = esp->dev; 146 struct of_device *op = esp->dev;
152 struct device_node *dp = sdev->ofdev.node; 147 struct device_node *dp;
153 148
149 dp = op->node;
154 if (of_find_property(dp, "differential", NULL)) 150 if (of_find_property(dp, "differential", NULL))
155 esp->flags |= ESP_FLAG_DIFFERENTIAL; 151 esp->flags |= ESP_FLAG_DIFFERENTIAL;
156 else 152 else
@@ -159,19 +155,16 @@ static void __devinit esp_get_differential(struct esp *esp)
159 155
160static void __devinit esp_get_clock_params(struct esp *esp) 156static void __devinit esp_get_clock_params(struct esp *esp)
161{ 157{
162 struct sbus_dev *sdev = esp->dev; 158 struct of_device *op = esp->dev;
163 struct device_node *dp = sdev->ofdev.node; 159 struct device_node *bus_dp, *dp;
164 struct device_node *bus_dp;
165 int fmhz; 160 int fmhz;
166 161
167 bus_dp = NULL; 162 dp = op->node;
168 if (sdev != NULL && sdev->bus != NULL) 163 bus_dp = dp->parent;
169 bus_dp = sdev->bus->ofdev.node;
170 164
171 fmhz = of_getintprop_default(dp, "clock-frequency", 0); 165 fmhz = of_getintprop_default(dp, "clock-frequency", 0);
172 if (fmhz == 0) 166 if (fmhz == 0)
173 fmhz = (!bus_dp) ? 0 : 167 fmhz = of_getintprop_default(bus_dp, "clock-frequency", 0);
174 of_getintprop_default(bus_dp, "clock-frequency", 0);
175 168
176 esp->cfreq = fmhz; 169 esp->cfreq = fmhz;
177} 170}
@@ -179,22 +172,19 @@ static void __devinit esp_get_clock_params(struct esp *esp)
179static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of) 172static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of)
180{ 173{
181 struct device_node *dma_dp = dma_of->node; 174 struct device_node *dma_dp = dma_of->node;
182 struct sbus_dev *sdev = esp->dev; 175 struct of_device *op = esp->dev;
183 struct device_node *dp; 176 struct device_node *dp;
184 u8 bursts, val; 177 u8 bursts, val;
185 178
186 dp = sdev->ofdev.node; 179 dp = op->node;
187 bursts = of_getintprop_default(dp, "burst-sizes", 0xff); 180 bursts = of_getintprop_default(dp, "burst-sizes", 0xff);
188 val = of_getintprop_default(dma_dp, "burst-sizes", 0xff); 181 val = of_getintprop_default(dma_dp, "burst-sizes", 0xff);
189 if (val != 0xff) 182 if (val != 0xff)
190 bursts &= val; 183 bursts &= val;
191 184
192 if (sdev->bus) { 185 val = of_getintprop_default(dma_dp->parent, "burst-sizes", 0xff);
193 u8 val = of_getintprop_default(sdev->bus->ofdev.node, 186 if (val != 0xff)
194 "burst-sizes", 0xff); 187 bursts &= val;
195 if (val != 0xff)
196 bursts &= val;
197 }
198 188
199 if (bursts == 0xff || 189 if (bursts == 0xff ||
200 (bursts & DMA_BURST16) == 0 || 190 (bursts & DMA_BURST16) == 0 ||
@@ -206,7 +196,7 @@ static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of)
206 196
207static void __devinit esp_sbus_get_props(struct esp *esp, struct of_device *espdma) 197static void __devinit esp_sbus_get_props(struct esp *esp, struct of_device *espdma)
208{ 198{
209 esp_get_scsi_id(esp); 199 esp_get_scsi_id(esp, espdma);
210 esp_get_differential(esp); 200 esp_get_differential(esp);
211 esp_get_clock_params(esp); 201 esp_get_clock_params(esp);
212 esp_get_bursts(esp, espdma); 202 esp_get_bursts(esp, espdma);
@@ -225,33 +215,33 @@ static u8 sbus_esp_read8(struct esp *esp, unsigned long reg)
225static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf, 215static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf,
226 size_t sz, int dir) 216 size_t sz, int dir)
227{ 217{
228 struct sbus_dev *sdev = esp->dev; 218 struct of_device *op = esp->dev;
229 219
230 return dma_map_single(&sdev->ofdev.dev, buf, sz, dir); 220 return dma_map_single(&op->dev, buf, sz, dir);
231} 221}
232 222
233static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg, 223static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg,
234 int num_sg, int dir) 224 int num_sg, int dir)
235{ 225{
236 struct sbus_dev *sdev = esp->dev; 226 struct of_device *op = esp->dev;
237 227
238 return dma_map_sg(&sdev->ofdev.dev, sg, num_sg, dir); 228 return dma_map_sg(&op->dev, sg, num_sg, dir);
239} 229}
240 230
241static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr, 231static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr,
242 size_t sz, int dir) 232 size_t sz, int dir)
243{ 233{
244 struct sbus_dev *sdev = esp->dev; 234 struct of_device *op = esp->dev;
245 235
246 dma_unmap_single(&sdev->ofdev.dev, addr, sz, dir); 236 dma_unmap_single(&op->dev, addr, sz, dir);
247} 237}
248 238
249static void sbus_esp_unmap_sg(struct esp *esp, struct scatterlist *sg, 239static void sbus_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
250 int num_sg, int dir) 240 int num_sg, int dir)
251{ 241{
252 struct sbus_dev *sdev = esp->dev; 242 struct of_device *op = esp->dev;
253 243
254 dma_unmap_sg(&sdev->ofdev.dev, sg, num_sg, dir); 244 dma_unmap_sg(&op->dev, sg, num_sg, dir);
255} 245}
256 246
257static int sbus_esp_irq_pending(struct esp *esp) 247static int sbus_esp_irq_pending(struct esp *esp)
@@ -265,14 +255,14 @@ static void sbus_esp_reset_dma(struct esp *esp)
265{ 255{
266 int can_do_burst16, can_do_burst32, can_do_burst64; 256 int can_do_burst16, can_do_burst32, can_do_burst64;
267 int can_do_sbus64, lim; 257 int can_do_sbus64, lim;
268 struct sbus_dev *sdev; 258 struct of_device *op;
269 u32 val; 259 u32 val;
270 260
271 can_do_burst16 = (esp->bursts & DMA_BURST16) != 0; 261 can_do_burst16 = (esp->bursts & DMA_BURST16) != 0;
272 can_do_burst32 = (esp->bursts & DMA_BURST32) != 0; 262 can_do_burst32 = (esp->bursts & DMA_BURST32) != 0;
273 can_do_burst64 = 0; 263 can_do_burst64 = 0;
274 can_do_sbus64 = 0; 264 can_do_sbus64 = 0;
275 sdev = esp->dev; 265 op = esp->dev;
276 if (sbus_can_dma_64bit()) 266 if (sbus_can_dma_64bit())
277 can_do_sbus64 = 1; 267 can_do_sbus64 = 1;
278 if (sbus_can_burst64()) 268 if (sbus_can_burst64())
@@ -302,7 +292,7 @@ static void sbus_esp_reset_dma(struct esp *esp)
302 292
303 if (can_do_sbus64) { 293 if (can_do_sbus64) {
304 esp->prev_hme_dmacsr |= DMA_SCSI_SBUS64; 294 esp->prev_hme_dmacsr |= DMA_SCSI_SBUS64;
305 sbus_set_sbus64(&sdev->ofdev.dev, esp->bursts); 295 sbus_set_sbus64(&op->dev, esp->bursts);
306 } 296 }
307 297
308 lim = 1000; 298 lim = 1000;
@@ -496,10 +486,8 @@ static const struct esp_driver_ops sbus_esp_ops = {
496 .dma_error = sbus_esp_dma_error, 486 .dma_error = sbus_esp_dma_error,
497}; 487};
498 488
499static int __devinit esp_sbus_probe_one(struct device *dev, 489static int __devinit esp_sbus_probe_one(struct of_device *op,
500 struct sbus_dev *esp_dev,
501 struct of_device *espdma, 490 struct of_device *espdma,
502 struct sbus_bus *sbus,
503 int hme) 491 int hme)
504{ 492{
505 struct scsi_host_template *tpnt = &scsi_esp_template; 493 struct scsi_host_template *tpnt = &scsi_esp_template;
@@ -517,7 +505,7 @@ static int __devinit esp_sbus_probe_one(struct device *dev,
517 esp = shost_priv(host); 505 esp = shost_priv(host);
518 506
519 esp->host = host; 507 esp->host = host;
520 esp->dev = esp_dev; 508 esp->dev = op;
521 esp->ops = &sbus_esp_ops; 509 esp->ops = &sbus_esp_ops;
522 510
523 if (hme) 511 if (hme)
@@ -551,9 +539,9 @@ static int __devinit esp_sbus_probe_one(struct device *dev,
551 dma_write32(val & ~DMA_RST_SCSI, DMA_CSR); 539 dma_write32(val & ~DMA_RST_SCSI, DMA_CSR);
552 } 540 }
553 541
554 dev_set_drvdata(&esp_dev->ofdev.dev, esp); 542 dev_set_drvdata(&op->dev, esp);
555 543
556 err = scsi_esp_register(esp, dev); 544 err = scsi_esp_register(esp, &op->dev);
557 if (err) 545 if (err)
558 goto fail_free_irq; 546 goto fail_free_irq;
559 547
@@ -562,22 +550,21 @@ static int __devinit esp_sbus_probe_one(struct device *dev,
562fail_free_irq: 550fail_free_irq:
563 free_irq(host->irq, esp); 551 free_irq(host->irq, esp);
564fail_unmap_command_block: 552fail_unmap_command_block:
565 dma_free_coherent(&esp_dev->ofdev.dev, 16, 553 dma_free_coherent(&op->dev, 16,
566 esp->command_block, 554 esp->command_block,
567 esp->command_block_dma); 555 esp->command_block_dma);
568fail_unmap_regs: 556fail_unmap_regs:
569 sbus_iounmap(esp->regs, SBUS_ESP_REG_SIZE); 557 of_iounmap(&op->resource[(hme ? 1 : 0)], esp->regs, SBUS_ESP_REG_SIZE);
570fail_unlink: 558fail_unlink:
571 scsi_host_put(host); 559 scsi_host_put(host);
572fail: 560fail:
573 return err; 561 return err;
574} 562}
575 563
576static int __devinit esp_sbus_probe(struct of_device *dev, const struct of_device_id *match) 564static int __devinit esp_sbus_probe(struct of_device *op, const struct of_device_id *match)
577{ 565{
578 struct sbus_dev *sdev = to_sbus_device(&dev->dev);
579 struct device_node *dma_node = NULL; 566 struct device_node *dma_node = NULL;
580 struct device_node *dp = dev->node; 567 struct device_node *dp = op->node;
581 struct of_device *dma_of = NULL; 568 struct of_device *dma_of = NULL;
582 int hme = 0; 569 int hme = 0;
583 570
@@ -586,7 +573,7 @@ static int __devinit esp_sbus_probe(struct of_device *dev, const struct of_devic
586 !strcmp(dp->parent->name, "dma"))) 573 !strcmp(dp->parent->name, "dma")))
587 dma_node = dp->parent; 574 dma_node = dp->parent;
588 else if (!strcmp(dp->name, "SUNW,fas")) { 575 else if (!strcmp(dp->name, "SUNW,fas")) {
589 dma_node = sdev->ofdev.node; 576 dma_node = op->node;
590 hme = 1; 577 hme = 1;
591 } 578 }
592 if (dma_node) 579 if (dma_node)
@@ -594,16 +581,15 @@ static int __devinit esp_sbus_probe(struct of_device *dev, const struct of_devic
594 if (!dma_of) 581 if (!dma_of)
595 return -ENODEV; 582 return -ENODEV;
596 583
597 return esp_sbus_probe_one(&dev->dev, sdev, dma_of, 584 return esp_sbus_probe_one(op, dma_of, hme);
598 sdev->bus, hme);
599} 585}
600 586
601static int __devexit esp_sbus_remove(struct of_device *dev) 587static int __devexit esp_sbus_remove(struct of_device *op)
602{ 588{
603 struct esp *esp = dev_get_drvdata(&dev->dev); 589 struct esp *esp = dev_get_drvdata(&op->dev);
604 struct sbus_dev *sdev = esp->dev;
605 struct of_device *dma_of = esp->dma; 590 struct of_device *dma_of = esp->dma;
606 unsigned int irq = esp->host->irq; 591 unsigned int irq = esp->host->irq;
592 bool is_hme;
607 u32 val; 593 u32 val;
608 594
609 scsi_esp_unregister(esp); 595 scsi_esp_unregister(esp);
@@ -613,15 +599,21 @@ static int __devexit esp_sbus_remove(struct of_device *dev)
613 dma_write32(val & ~DMA_INT_ENAB, DMA_CSR); 599 dma_write32(val & ~DMA_INT_ENAB, DMA_CSR);
614 600
615 free_irq(irq, esp); 601 free_irq(irq, esp);
616 dma_free_coherent(&sdev->ofdev.dev, 16, 602
603 is_hme = (esp->dmarev == dvmahme);
604
605 dma_free_coherent(&op->dev, 16,
617 esp->command_block, 606 esp->command_block,
618 esp->command_block_dma); 607 esp->command_block_dma);
619 sbus_iounmap(esp->regs, SBUS_ESP_REG_SIZE); 608 of_iounmap(&op->resource[(is_hme ? 1 : 0)], esp->regs,
609 SBUS_ESP_REG_SIZE);
620 of_iounmap(&dma_of->resource[0], esp->dma_regs, 610 of_iounmap(&dma_of->resource[0], esp->dma_regs,
621 resource_size(&dma_of->resource[0])); 611 resource_size(&dma_of->resource[0]));
622 612
623 scsi_host_put(esp->host); 613 scsi_host_put(esp->host);
624 614
615 dev_set_drvdata(&op->dev, NULL);
616
625 return 0; 617 return 0;
626} 618}
627 619
@@ -648,7 +640,7 @@ static struct of_platform_driver esp_sbus_driver = {
648 640
649static int __init sunesp_init(void) 641static int __init sunesp_init(void)
650{ 642{
651 return of_register_driver(&esp_sbus_driver, &sbus_bus_type); 643 return of_register_driver(&esp_sbus_driver, &of_bus_type);
652} 644}
653 645
654static void __exit sunesp_exit(void) 646static void __exit sunesp_exit(void)