aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-14 17:27:45 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-14 17:27:45 -0500
commitcebfa85eb86d92bf85d3b041c6b044184517a988 (patch)
treebe0a374556fe335ce96dfdb296c89537750d5868 /drivers/ata
parentd42b3a2906a10b732ea7d7f849d49be79d242ef0 (diff)
parent241738bd51cb0efe58e6c570223153e970afe3ae (diff)
Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus
Pull MIPS updates from Ralf Baechle: "The MIPS bits for 3.8. This also includes a bunch fixes that were sitting in the linux-mips.org git tree for a long time. This pull request contains updates to several OCTEON drivers and the board support code for BCM47XX, BCM63XX, XLP, XLR, XLS, lantiq, Loongson1B, updates to the SSB bus support, MIPS kexec code and adds support for kdump. When pulling this, there are two expected merge conflicts in include/linux/bcma/bcma_driver_chipcommon.h which are trivial to resolve, just remove the conflict markers and keep both alternatives." * 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus: (90 commits) MIPS: PMC-Sierra Yosemite: Remove support. VIDEO: Newport Fix console crashes MIPS: wrppmc: Fix build of PCI code. MIPS: IP22/IP28: Fix build of EISA code. MIPS: RB532: Fix build of prom code. MIPS: PowerTV: Fix build. MIPS: IP27: Correct fucked grammar in ops-bridge.c MIPS: Highmem: Fix build error if CONFIG_DEBUG_HIGHMEM is disabled MIPS: Fix potencial corruption MIPS: Fix for warning from FPU emulation code MIPS: Handle COP3 Unusable exception as COP1X for FP emulation MIPS: Fix poweroff failure when HOTPLUG_CPU configured. MIPS: MT: Fix build with CONFIG_UIDGID_STRICT_TYPE_CHECKS=y MIPS: Remove unused smvp.h MIPS/EDAC: Improve OCTEON EDAC support. MIPS: OCTEON: Add definitions for OCTEON memory contoller registers. MIPS: OCTEON: Add OCTEON family definitions to octeon-model.h ata: pata_octeon_cf: Use correct byte order for DMA in when built little-endian. MIPS/OCTEON/ata: Convert pata_octeon_cf.c to use device tree. MIPS: Remove usage of CEVT_R4K_LIB config option. ...
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/pata_octeon_cf.c423
1 files changed, 288 insertions, 135 deletions
diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
index 1d61d5d278fa..4e1194b4c271 100644
--- a/drivers/ata/pata_octeon_cf.c
+++ b/drivers/ata/pata_octeon_cf.c
@@ -5,19 +5,22 @@
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details. 6 * for more details.
7 * 7 *
8 * Copyright (C) 2005 - 2009 Cavium Networks 8 * Copyright (C) 2005 - 2012 Cavium Inc.
9 * Copyright (C) 2008 Wind River Systems 9 * Copyright (C) 2008 Wind River Systems
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/libata.h> 14#include <linux/libata.h>
15#include <linux/irq.h> 15#include <linux/hrtimer.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/irq.h>
18#include <linux/of.h>
19#include <linux/of_platform.h>
17#include <linux/platform_device.h> 20#include <linux/platform_device.h>
18#include <linux/workqueue.h>
19#include <scsi/scsi_host.h> 21#include <scsi/scsi_host.h>
20 22
23#include <asm/byteorder.h>
21#include <asm/octeon/octeon.h> 24#include <asm/octeon/octeon.h>
22 25
23/* 26/*
@@ -34,20 +37,36 @@
34 */ 37 */
35 38
36#define DRV_NAME "pata_octeon_cf" 39#define DRV_NAME "pata_octeon_cf"
37#define DRV_VERSION "2.1" 40#define DRV_VERSION "2.2"
41
42/* Poll interval in nS. */
43#define OCTEON_CF_BUSY_POLL_INTERVAL 500000
38 44
45#define DMA_CFG 0
46#define DMA_TIM 0x20
47#define DMA_INT 0x38
48#define DMA_INT_EN 0x50
39 49
40struct octeon_cf_port { 50struct octeon_cf_port {
41 struct workqueue_struct *wq; 51 struct hrtimer delayed_finish;
42 struct delayed_work delayed_finish;
43 struct ata_port *ap; 52 struct ata_port *ap;
44 int dma_finished; 53 int dma_finished;
54 void *c0;
55 unsigned int cs0;
56 unsigned int cs1;
57 bool is_true_ide;
58 u64 dma_base;
45}; 59};
46 60
47static struct scsi_host_template octeon_cf_sht = { 61static struct scsi_host_template octeon_cf_sht = {
48 ATA_PIO_SHT(DRV_NAME), 62 ATA_PIO_SHT(DRV_NAME),
49}; 63};
50 64
65static int enable_dma;
66module_param(enable_dma, int, 0444);
67MODULE_PARM_DESC(enable_dma,
68 "Enable use of DMA on interfaces that support it (0=no dma [default], 1=use dma)");
69
51/** 70/**
52 * Convert nanosecond based time to setting used in the 71 * Convert nanosecond based time to setting used in the
53 * boot bus timing register, based on timing multiple 72 * boot bus timing register, based on timing multiple
@@ -66,12 +85,29 @@ static unsigned int ns_to_tim_reg(unsigned int tim_mult, unsigned int nsecs)
66 return val; 85 return val;
67} 86}
68 87
69static void octeon_cf_set_boot_reg_cfg(int cs) 88static void octeon_cf_set_boot_reg_cfg(int cs, unsigned int multiplier)
70{ 89{
71 union cvmx_mio_boot_reg_cfgx reg_cfg; 90 union cvmx_mio_boot_reg_cfgx reg_cfg;
91 unsigned int tim_mult;
92
93 switch (multiplier) {
94 case 8:
95 tim_mult = 3;
96 break;
97 case 4:
98 tim_mult = 0;
99 break;
100 case 2:
101 tim_mult = 2;
102 break;
103 default:
104 tim_mult = 1;
105 break;
106 }
107
72 reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs)); 108 reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
73 reg_cfg.s.dmack = 0; /* Don't assert DMACK on access */ 109 reg_cfg.s.dmack = 0; /* Don't assert DMACK on access */
74 reg_cfg.s.tim_mult = 2; /* Timing mutiplier 2x */ 110 reg_cfg.s.tim_mult = tim_mult; /* Timing mutiplier */
75 reg_cfg.s.rd_dly = 0; /* Sample on falling edge of BOOT_OE */ 111 reg_cfg.s.rd_dly = 0; /* Sample on falling edge of BOOT_OE */
76 reg_cfg.s.sam = 0; /* Don't combine write and output enable */ 112 reg_cfg.s.sam = 0; /* Don't combine write and output enable */
77 reg_cfg.s.we_ext = 0; /* No write enable extension */ 113 reg_cfg.s.we_ext = 0; /* No write enable extension */
@@ -92,12 +128,12 @@ static void octeon_cf_set_boot_reg_cfg(int cs)
92 */ 128 */
93static void octeon_cf_set_piomode(struct ata_port *ap, struct ata_device *dev) 129static void octeon_cf_set_piomode(struct ata_port *ap, struct ata_device *dev)
94{ 130{
95 struct octeon_cf_data *ocd = ap->dev->platform_data; 131 struct octeon_cf_port *cf_port = ap->private_data;
96 union cvmx_mio_boot_reg_timx reg_tim; 132 union cvmx_mio_boot_reg_timx reg_tim;
97 int cs = ocd->base_region;
98 int T; 133 int T;
99 struct ata_timing timing; 134 struct ata_timing timing;
100 135
136 unsigned int div;
101 int use_iordy; 137 int use_iordy;
102 int trh; 138 int trh;
103 int pause; 139 int pause;
@@ -106,7 +142,15 @@ static void octeon_cf_set_piomode(struct ata_port *ap, struct ata_device *dev)
106 int t2; 142 int t2;
107 int t2i; 143 int t2i;
108 144
109 T = (int)(2000000000000LL / octeon_get_clock_rate()); 145 /*
146 * A divisor value of four will overflow the timing fields at
147 * clock rates greater than 800MHz
148 */
149 if (octeon_get_io_clock_rate() <= 800000000)
150 div = 4;
151 else
152 div = 8;
153 T = (int)((1000000000000LL * div) / octeon_get_io_clock_rate());
110 154
111 if (ata_timing_compute(dev, dev->pio_mode, &timing, T, T)) 155 if (ata_timing_compute(dev, dev->pio_mode, &timing, T, T))
112 BUG(); 156 BUG();
@@ -121,23 +165,26 @@ static void octeon_cf_set_piomode(struct ata_port *ap, struct ata_device *dev)
121 if (t2i) 165 if (t2i)
122 t2i--; 166 t2i--;
123 167
124 trh = ns_to_tim_reg(2, 20); 168 trh = ns_to_tim_reg(div, 20);
125 if (trh) 169 if (trh)
126 trh--; 170 trh--;
127 171
128 pause = timing.cycle - timing.active - timing.setup - trh; 172 pause = (int)timing.cycle - (int)timing.active -
173 (int)timing.setup - trh;
174 if (pause < 0)
175 pause = 0;
129 if (pause) 176 if (pause)
130 pause--; 177 pause--;
131 178
132 octeon_cf_set_boot_reg_cfg(cs); 179 octeon_cf_set_boot_reg_cfg(cf_port->cs0, div);
133 if (ocd->dma_engine >= 0) 180 if (cf_port->is_true_ide)
134 /* True IDE mode, program both chip selects. */ 181 /* True IDE mode, program both chip selects. */
135 octeon_cf_set_boot_reg_cfg(cs + 1); 182 octeon_cf_set_boot_reg_cfg(cf_port->cs1, div);
136 183
137 184
138 use_iordy = ata_pio_need_iordy(dev); 185 use_iordy = ata_pio_need_iordy(dev);
139 186
140 reg_tim.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_TIMX(cs)); 187 reg_tim.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_TIMX(cf_port->cs0));
141 /* Disable page mode */ 188 /* Disable page mode */
142 reg_tim.s.pagem = 0; 189 reg_tim.s.pagem = 0;
143 /* Enable dynamic timing */ 190 /* Enable dynamic timing */
@@ -161,20 +208,22 @@ static void octeon_cf_set_piomode(struct ata_port *ap, struct ata_device *dev)
161 /* How long read enable is asserted */ 208 /* How long read enable is asserted */
162 reg_tim.s.oe = t2; 209 reg_tim.s.oe = t2;
163 /* Time after CE that read/write starts */ 210 /* Time after CE that read/write starts */
164 reg_tim.s.ce = ns_to_tim_reg(2, 5); 211 reg_tim.s.ce = ns_to_tim_reg(div, 5);
165 /* Time before CE that address is valid */ 212 /* Time before CE that address is valid */
166 reg_tim.s.adr = 0; 213 reg_tim.s.adr = 0;
167 214
168 /* Program the bootbus region timing for the data port chip select. */ 215 /* Program the bootbus region timing for the data port chip select. */
169 cvmx_write_csr(CVMX_MIO_BOOT_REG_TIMX(cs), reg_tim.u64); 216 cvmx_write_csr(CVMX_MIO_BOOT_REG_TIMX(cf_port->cs0), reg_tim.u64);
170 if (ocd->dma_engine >= 0) 217 if (cf_port->is_true_ide)
171 /* True IDE mode, program both chip selects. */ 218 /* True IDE mode, program both chip selects. */
172 cvmx_write_csr(CVMX_MIO_BOOT_REG_TIMX(cs + 1), reg_tim.u64); 219 cvmx_write_csr(CVMX_MIO_BOOT_REG_TIMX(cf_port->cs1),
220 reg_tim.u64);
173} 221}
174 222
175static void octeon_cf_set_dmamode(struct ata_port *ap, struct ata_device *dev) 223static void octeon_cf_set_dmamode(struct ata_port *ap, struct ata_device *dev)
176{ 224{
177 struct octeon_cf_data *ocd = dev->link->ap->dev->platform_data; 225 struct octeon_cf_port *cf_port = ap->private_data;
226 union cvmx_mio_boot_pin_defs pin_defs;
178 union cvmx_mio_boot_dma_timx dma_tim; 227 union cvmx_mio_boot_dma_timx dma_tim;
179 unsigned int oe_a; 228 unsigned int oe_a;
180 unsigned int oe_n; 229 unsigned int oe_n;
@@ -183,6 +232,7 @@ static void octeon_cf_set_dmamode(struct ata_port *ap, struct ata_device *dev)
183 unsigned int pause; 232 unsigned int pause;
184 unsigned int T0, Tkr, Td; 233 unsigned int T0, Tkr, Td;
185 unsigned int tim_mult; 234 unsigned int tim_mult;
235 int c;
186 236
187 const struct ata_timing *timing; 237 const struct ata_timing *timing;
188 238
@@ -199,13 +249,19 @@ static void octeon_cf_set_dmamode(struct ata_port *ap, struct ata_device *dev)
199 /* not spec'ed, value in eclocks, not affected by tim_mult */ 249 /* not spec'ed, value in eclocks, not affected by tim_mult */
200 dma_arq = 8; 250 dma_arq = 8;
201 pause = 25 - dma_arq * 1000 / 251 pause = 25 - dma_arq * 1000 /
202 (octeon_get_clock_rate() / 1000000); /* Tz */ 252 (octeon_get_io_clock_rate() / 1000000); /* Tz */
203 253
204 oe_a = Td; 254 oe_a = Td;
205 /* Tkr from cf spec, lengthened to meet T0 */ 255 /* Tkr from cf spec, lengthened to meet T0 */
206 oe_n = max(T0 - oe_a, Tkr); 256 oe_n = max(T0 - oe_a, Tkr);
207 257
208 dma_tim.s.dmack_pi = 1; 258 pin_defs.u64 = cvmx_read_csr(CVMX_MIO_BOOT_PIN_DEFS);
259
260 /* DMA channel number. */
261 c = (cf_port->dma_base & 8) >> 3;
262
263 /* Invert the polarity if the default is 0*/
264 dma_tim.s.dmack_pi = (pin_defs.u64 & (1ull << (11 + c))) ? 0 : 1;
209 265
210 dma_tim.s.oe_n = ns_to_tim_reg(tim_mult, oe_n); 266 dma_tim.s.oe_n = ns_to_tim_reg(tim_mult, oe_n);
211 dma_tim.s.oe_a = ns_to_tim_reg(tim_mult, oe_a); 267 dma_tim.s.oe_a = ns_to_tim_reg(tim_mult, oe_a);
@@ -228,14 +284,11 @@ static void octeon_cf_set_dmamode(struct ata_port *ap, struct ata_device *dev)
228 284
229 pr_debug("ns to ticks (mult %d) of %d is: %d\n", tim_mult, 60, 285 pr_debug("ns to ticks (mult %d) of %d is: %d\n", tim_mult, 60,
230 ns_to_tim_reg(tim_mult, 60)); 286 ns_to_tim_reg(tim_mult, 60));
231 pr_debug("oe_n: %d, oe_a: %d, dmack_s: %d, dmack_h: " 287 pr_debug("oe_n: %d, oe_a: %d, dmack_s: %d, dmack_h: %d, dmarq: %d, pause: %d\n",
232 "%d, dmarq: %d, pause: %d\n",
233 dma_tim.s.oe_n, dma_tim.s.oe_a, dma_tim.s.dmack_s, 288 dma_tim.s.oe_n, dma_tim.s.oe_a, dma_tim.s.dmack_s,
234 dma_tim.s.dmack_h, dma_tim.s.dmarq, dma_tim.s.pause); 289 dma_tim.s.dmack_h, dma_tim.s.dmarq, dma_tim.s.pause);
235 290
236 cvmx_write_csr(CVMX_MIO_BOOT_DMA_TIMX(ocd->dma_engine), 291 cvmx_write_csr(cf_port->dma_base + DMA_TIM, dma_tim.u64);
237 dma_tim.u64);
238
239} 292}
240 293
241/** 294/**
@@ -489,15 +542,10 @@ static void octeon_cf_exec_command16(struct ata_port *ap,
489 ata_wait_idle(ap); 542 ata_wait_idle(ap);
490} 543}
491 544
492static void octeon_cf_irq_on(struct ata_port *ap) 545static void octeon_cf_ata_port_noaction(struct ata_port *ap)
493{ 546{
494} 547}
495 548
496static void octeon_cf_irq_clear(struct ata_port *ap)
497{
498 return;
499}
500
501static void octeon_cf_dma_setup(struct ata_queued_cmd *qc) 549static void octeon_cf_dma_setup(struct ata_queued_cmd *qc)
502{ 550{
503 struct ata_port *ap = qc->ap; 551 struct ata_port *ap = qc->ap;
@@ -519,7 +567,7 @@ static void octeon_cf_dma_setup(struct ata_queued_cmd *qc)
519 */ 567 */
520static void octeon_cf_dma_start(struct ata_queued_cmd *qc) 568static void octeon_cf_dma_start(struct ata_queued_cmd *qc)
521{ 569{
522 struct octeon_cf_data *ocd = qc->ap->dev->platform_data; 570 struct octeon_cf_port *cf_port = qc->ap->private_data;
523 union cvmx_mio_boot_dma_cfgx mio_boot_dma_cfg; 571 union cvmx_mio_boot_dma_cfgx mio_boot_dma_cfg;
524 union cvmx_mio_boot_dma_intx mio_boot_dma_int; 572 union cvmx_mio_boot_dma_intx mio_boot_dma_int;
525 struct scatterlist *sg; 573 struct scatterlist *sg;
@@ -535,15 +583,16 @@ static void octeon_cf_dma_start(struct ata_queued_cmd *qc)
535 */ 583 */
536 mio_boot_dma_int.u64 = 0; 584 mio_boot_dma_int.u64 = 0;
537 mio_boot_dma_int.s.done = 1; 585 mio_boot_dma_int.s.done = 1;
538 cvmx_write_csr(CVMX_MIO_BOOT_DMA_INTX(ocd->dma_engine), 586 cvmx_write_csr(cf_port->dma_base + DMA_INT, mio_boot_dma_int.u64);
539 mio_boot_dma_int.u64);
540 587
541 /* Enable the interrupt. */ 588 /* Enable the interrupt. */
542 cvmx_write_csr(CVMX_MIO_BOOT_DMA_INT_ENX(ocd->dma_engine), 589 cvmx_write_csr(cf_port->dma_base + DMA_INT_EN, mio_boot_dma_int.u64);
543 mio_boot_dma_int.u64);
544 590
545 /* Set the direction of the DMA */ 591 /* Set the direction of the DMA */
546 mio_boot_dma_cfg.u64 = 0; 592 mio_boot_dma_cfg.u64 = 0;
593#ifdef __LITTLE_ENDIAN
594 mio_boot_dma_cfg.s.endian = 1;
595#endif
547 mio_boot_dma_cfg.s.en = 1; 596 mio_boot_dma_cfg.s.en = 1;
548 mio_boot_dma_cfg.s.rw = ((qc->tf.flags & ATA_TFLAG_WRITE) != 0); 597 mio_boot_dma_cfg.s.rw = ((qc->tf.flags & ATA_TFLAG_WRITE) != 0);
549 598
@@ -569,8 +618,7 @@ static void octeon_cf_dma_start(struct ata_queued_cmd *qc)
569 (mio_boot_dma_cfg.s.rw) ? "write" : "read", sg->length, 618 (mio_boot_dma_cfg.s.rw) ? "write" : "read", sg->length,
570 (void *)(unsigned long)mio_boot_dma_cfg.s.adr); 619 (void *)(unsigned long)mio_boot_dma_cfg.s.adr);
571 620
572 cvmx_write_csr(CVMX_MIO_BOOT_DMA_CFGX(ocd->dma_engine), 621 cvmx_write_csr(cf_port->dma_base + DMA_CFG, mio_boot_dma_cfg.u64);
573 mio_boot_dma_cfg.u64);
574} 622}
575 623
576/** 624/**
@@ -583,10 +631,9 @@ static unsigned int octeon_cf_dma_finished(struct ata_port *ap,
583 struct ata_queued_cmd *qc) 631 struct ata_queued_cmd *qc)
584{ 632{
585 struct ata_eh_info *ehi = &ap->link.eh_info; 633 struct ata_eh_info *ehi = &ap->link.eh_info;
586 struct octeon_cf_data *ocd = ap->dev->platform_data; 634 struct octeon_cf_port *cf_port = ap->private_data;
587 union cvmx_mio_boot_dma_cfgx dma_cfg; 635 union cvmx_mio_boot_dma_cfgx dma_cfg;
588 union cvmx_mio_boot_dma_intx dma_int; 636 union cvmx_mio_boot_dma_intx dma_int;
589 struct octeon_cf_port *cf_port;
590 u8 status; 637 u8 status;
591 638
592 VPRINTK("ata%u: protocol %d task_state %d\n", 639 VPRINTK("ata%u: protocol %d task_state %d\n",
@@ -596,9 +643,7 @@ static unsigned int octeon_cf_dma_finished(struct ata_port *ap,
596 if (ap->hsm_task_state != HSM_ST_LAST) 643 if (ap->hsm_task_state != HSM_ST_LAST)
597 return 0; 644 return 0;
598 645
599 cf_port = ap->private_data; 646 dma_cfg.u64 = cvmx_read_csr(cf_port->dma_base + DMA_CFG);
600
601 dma_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_DMA_CFGX(ocd->dma_engine));
602 if (dma_cfg.s.size != 0xfffff) { 647 if (dma_cfg.s.size != 0xfffff) {
603 /* Error, the transfer was not complete. */ 648 /* Error, the transfer was not complete. */
604 qc->err_mask |= AC_ERR_HOST_BUS; 649 qc->err_mask |= AC_ERR_HOST_BUS;
@@ -608,15 +653,15 @@ static unsigned int octeon_cf_dma_finished(struct ata_port *ap,
608 /* Stop and clear the dma engine. */ 653 /* Stop and clear the dma engine. */
609 dma_cfg.u64 = 0; 654 dma_cfg.u64 = 0;
610 dma_cfg.s.size = -1; 655 dma_cfg.s.size = -1;
611 cvmx_write_csr(CVMX_MIO_BOOT_DMA_CFGX(ocd->dma_engine), dma_cfg.u64); 656 cvmx_write_csr(cf_port->dma_base + DMA_CFG, dma_cfg.u64);
612 657
613 /* Disable the interrupt. */ 658 /* Disable the interrupt. */
614 dma_int.u64 = 0; 659 dma_int.u64 = 0;
615 cvmx_write_csr(CVMX_MIO_BOOT_DMA_INT_ENX(ocd->dma_engine), dma_int.u64); 660 cvmx_write_csr(cf_port->dma_base + DMA_INT_EN, dma_int.u64);
616 661
617 /* Clear the DMA complete status */ 662 /* Clear the DMA complete status */
618 dma_int.s.done = 1; 663 dma_int.s.done = 1;
619 cvmx_write_csr(CVMX_MIO_BOOT_DMA_INTX(ocd->dma_engine), dma_int.u64); 664 cvmx_write_csr(cf_port->dma_base + DMA_INT, dma_int.u64);
620 665
621 status = ap->ops->sff_check_status(ap); 666 status = ap->ops->sff_check_status(ap);
622 667
@@ -649,69 +694,68 @@ static irqreturn_t octeon_cf_interrupt(int irq, void *dev_instance)
649 struct ata_queued_cmd *qc; 694 struct ata_queued_cmd *qc;
650 union cvmx_mio_boot_dma_intx dma_int; 695 union cvmx_mio_boot_dma_intx dma_int;
651 union cvmx_mio_boot_dma_cfgx dma_cfg; 696 union cvmx_mio_boot_dma_cfgx dma_cfg;
652 struct octeon_cf_data *ocd;
653 697
654 ap = host->ports[i]; 698 ap = host->ports[i];
655 ocd = ap->dev->platform_data;
656 cf_port = ap->private_data; 699 cf_port = ap->private_data;
657 dma_int.u64 = 700
658 cvmx_read_csr(CVMX_MIO_BOOT_DMA_INTX(ocd->dma_engine)); 701 dma_int.u64 = cvmx_read_csr(cf_port->dma_base + DMA_INT);
659 dma_cfg.u64 = 702 dma_cfg.u64 = cvmx_read_csr(cf_port->dma_base + DMA_CFG);
660 cvmx_read_csr(CVMX_MIO_BOOT_DMA_CFGX(ocd->dma_engine));
661 703
662 qc = ata_qc_from_tag(ap, ap->link.active_tag); 704 qc = ata_qc_from_tag(ap, ap->link.active_tag);
663 705
664 if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING)) { 706 if (!qc || (qc->tf.flags & ATA_TFLAG_POLLING))
665 if (dma_int.s.done && !dma_cfg.s.en) { 707 continue;
666 if (!sg_is_last(qc->cursg)) { 708
667 qc->cursg = sg_next(qc->cursg); 709 if (dma_int.s.done && !dma_cfg.s.en) {
668 handled = 1; 710 if (!sg_is_last(qc->cursg)) {
669 octeon_cf_dma_start(qc); 711 qc->cursg = sg_next(qc->cursg);
670 continue;
671 } else {
672 cf_port->dma_finished = 1;
673 }
674 }
675 if (!cf_port->dma_finished)
676 continue;
677 status = ioread8(ap->ioaddr.altstatus_addr);
678 if (status & (ATA_BUSY | ATA_DRQ)) {
679 /*
680 * We are busy, try to handle it
681 * later. This is the DMA finished
682 * interrupt, and it could take a
683 * little while for the card to be
684 * ready for more commands.
685 */
686 /* Clear DMA irq. */
687 dma_int.u64 = 0;
688 dma_int.s.done = 1;
689 cvmx_write_csr(CVMX_MIO_BOOT_DMA_INTX(ocd->dma_engine),
690 dma_int.u64);
691
692 queue_delayed_work(cf_port->wq,
693 &cf_port->delayed_finish, 1);
694 handled = 1; 712 handled = 1;
713 octeon_cf_dma_start(qc);
714 continue;
695 } else { 715 } else {
696 handled |= octeon_cf_dma_finished(ap, qc); 716 cf_port->dma_finished = 1;
697 } 717 }
698 } 718 }
719 if (!cf_port->dma_finished)
720 continue;
721 status = ioread8(ap->ioaddr.altstatus_addr);
722 if (status & (ATA_BUSY | ATA_DRQ)) {
723 /*
724 * We are busy, try to handle it later. This
725 * is the DMA finished interrupt, and it could
726 * take a little while for the card to be
727 * ready for more commands.
728 */
729 /* Clear DMA irq. */
730 dma_int.u64 = 0;
731 dma_int.s.done = 1;
732 cvmx_write_csr(cf_port->dma_base + DMA_INT,
733 dma_int.u64);
734 hrtimer_start_range_ns(&cf_port->delayed_finish,
735 ns_to_ktime(OCTEON_CF_BUSY_POLL_INTERVAL),
736 OCTEON_CF_BUSY_POLL_INTERVAL / 5,
737 HRTIMER_MODE_REL);
738 handled = 1;
739 } else {
740 handled |= octeon_cf_dma_finished(ap, qc);
741 }
699 } 742 }
700 spin_unlock_irqrestore(&host->lock, flags); 743 spin_unlock_irqrestore(&host->lock, flags);
701 DPRINTK("EXIT\n"); 744 DPRINTK("EXIT\n");
702 return IRQ_RETVAL(handled); 745 return IRQ_RETVAL(handled);
703} 746}
704 747
705static void octeon_cf_delayed_finish(struct work_struct *work) 748static enum hrtimer_restart octeon_cf_delayed_finish(struct hrtimer *hrt)
706{ 749{
707 struct octeon_cf_port *cf_port = container_of(work, 750 struct octeon_cf_port *cf_port = container_of(hrt,
708 struct octeon_cf_port, 751 struct octeon_cf_port,
709 delayed_finish.work); 752 delayed_finish);
710 struct ata_port *ap = cf_port->ap; 753 struct ata_port *ap = cf_port->ap;
711 struct ata_host *host = ap->host; 754 struct ata_host *host = ap->host;
712 struct ata_queued_cmd *qc; 755 struct ata_queued_cmd *qc;
713 unsigned long flags; 756 unsigned long flags;
714 u8 status; 757 u8 status;
758 enum hrtimer_restart rv = HRTIMER_NORESTART;
715 759
716 spin_lock_irqsave(&host->lock, flags); 760 spin_lock_irqsave(&host->lock, flags);
717 761
@@ -726,15 +770,17 @@ static void octeon_cf_delayed_finish(struct work_struct *work)
726 status = ioread8(ap->ioaddr.altstatus_addr); 770 status = ioread8(ap->ioaddr.altstatus_addr);
727 if (status & (ATA_BUSY | ATA_DRQ)) { 771 if (status & (ATA_BUSY | ATA_DRQ)) {
728 /* Still busy, try again. */ 772 /* Still busy, try again. */
729 queue_delayed_work(cf_port->wq, 773 hrtimer_forward_now(hrt,
730 &cf_port->delayed_finish, 1); 774 ns_to_ktime(OCTEON_CF_BUSY_POLL_INTERVAL));
775 rv = HRTIMER_RESTART;
731 goto out; 776 goto out;
732 } 777 }
733 qc = ata_qc_from_tag(ap, ap->link.active_tag); 778 qc = ata_qc_from_tag(ap, ap->link.active_tag);
734 if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING)) 779 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
735 octeon_cf_dma_finished(ap, qc); 780 octeon_cf_dma_finished(ap, qc);
736out: 781out:
737 spin_unlock_irqrestore(&host->lock, flags); 782 spin_unlock_irqrestore(&host->lock, flags);
783 return rv;
738} 784}
739 785
740static void octeon_cf_dev_config(struct ata_device *dev) 786static void octeon_cf_dev_config(struct ata_device *dev)
@@ -786,8 +832,8 @@ static struct ata_port_operations octeon_cf_ops = {
786 .qc_prep = ata_noop_qc_prep, 832 .qc_prep = ata_noop_qc_prep,
787 .qc_issue = octeon_cf_qc_issue, 833 .qc_issue = octeon_cf_qc_issue,
788 .sff_dev_select = octeon_cf_dev_select, 834 .sff_dev_select = octeon_cf_dev_select,
789 .sff_irq_on = octeon_cf_irq_on, 835 .sff_irq_on = octeon_cf_ata_port_noaction,
790 .sff_irq_clear = octeon_cf_irq_clear, 836 .sff_irq_clear = octeon_cf_ata_port_noaction,
791 .cable_detect = ata_cable_40wire, 837 .cable_detect = ata_cable_40wire,
792 .set_piomode = octeon_cf_set_piomode, 838 .set_piomode = octeon_cf_set_piomode,
793 .set_dmamode = octeon_cf_set_dmamode, 839 .set_dmamode = octeon_cf_set_dmamode,
@@ -798,46 +844,113 @@ static int __devinit octeon_cf_probe(struct platform_device *pdev)
798{ 844{
799 struct resource *res_cs0, *res_cs1; 845 struct resource *res_cs0, *res_cs1;
800 846
847 bool is_16bit;
848 const __be32 *cs_num;
849 struct property *reg_prop;
850 int n_addr, n_size, reg_len;
851 struct device_node *node;
852 const void *prop;
801 void __iomem *cs0; 853 void __iomem *cs0;
802 void __iomem *cs1 = NULL; 854 void __iomem *cs1 = NULL;
803 struct ata_host *host; 855 struct ata_host *host;
804 struct ata_port *ap; 856 struct ata_port *ap;
805 struct octeon_cf_data *ocd;
806 int irq = 0; 857 int irq = 0;
807 irq_handler_t irq_handler = NULL; 858 irq_handler_t irq_handler = NULL;
808 void __iomem *base; 859 void __iomem *base;
809 struct octeon_cf_port *cf_port; 860 struct octeon_cf_port *cf_port;
810 char version[32]; 861 int rv = -ENOMEM;
811 862
812 res_cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
813 863
814 if (!res_cs0) 864 node = pdev->dev.of_node;
865 if (node == NULL)
815 return -EINVAL; 866 return -EINVAL;
816 867
817 ocd = pdev->dev.platform_data; 868 cf_port = kzalloc(sizeof(*cf_port), GFP_KERNEL);
869 if (!cf_port)
870 return -ENOMEM;
818 871
819 cs0 = devm_ioremap_nocache(&pdev->dev, res_cs0->start, 872 cf_port->is_true_ide = (of_find_property(node, "cavium,true-ide", NULL) != NULL);
820 resource_size(res_cs0));
821 873
822 if (!cs0) 874 prop = of_get_property(node, "cavium,bus-width", NULL);
823 return -ENOMEM; 875 if (prop)
876 is_16bit = (be32_to_cpup(prop) == 16);
877 else
878 is_16bit = false;
824 879
825 /* Determine from availability of DMA if True IDE mode or not */ 880 n_addr = of_n_addr_cells(node);
826 if (ocd->dma_engine >= 0) { 881 n_size = of_n_size_cells(node);
827 res_cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
828 if (!res_cs1)
829 return -EINVAL;
830 882
883 reg_prop = of_find_property(node, "reg", &reg_len);
884 if (!reg_prop || reg_len < sizeof(__be32)) {
885 rv = -EINVAL;
886 goto free_cf_port;
887 }
888 cs_num = reg_prop->value;
889 cf_port->cs0 = be32_to_cpup(cs_num);
890
891 if (cf_port->is_true_ide) {
892 struct device_node *dma_node;
893 dma_node = of_parse_phandle(node,
894 "cavium,dma-engine-handle", 0);
895 if (dma_node) {
896 struct platform_device *dma_dev;
897 dma_dev = of_find_device_by_node(dma_node);
898 if (dma_dev) {
899 struct resource *res_dma;
900 int i;
901 res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
902 if (!res_dma) {
903 of_node_put(dma_node);
904 rv = -EINVAL;
905 goto free_cf_port;
906 }
907 cf_port->dma_base = (u64)devm_ioremap_nocache(&pdev->dev, res_dma->start,
908 resource_size(res_dma));
909
910 if (!cf_port->dma_base) {
911 of_node_put(dma_node);
912 rv = -EINVAL;
913 goto free_cf_port;
914 }
915
916 irq_handler = octeon_cf_interrupt;
917 i = platform_get_irq(dma_dev, 0);
918 if (i > 0)
919 irq = i;
920 }
921 of_node_put(dma_node);
922 }
923 res_cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
924 if (!res_cs1) {
925 rv = -EINVAL;
926 goto free_cf_port;
927 }
831 cs1 = devm_ioremap_nocache(&pdev->dev, res_cs1->start, 928 cs1 = devm_ioremap_nocache(&pdev->dev, res_cs1->start,
832 resource_size(res_cs1)); 929 res_cs1->end - res_cs1->start + 1);
833 930
834 if (!cs1) 931 if (!cs1)
835 return -ENOMEM; 932 goto free_cf_port;
933
934 if (reg_len < (n_addr + n_size + 1) * sizeof(__be32)) {
935 rv = -EINVAL;
936 goto free_cf_port;
937 }
938 cs_num += n_addr + n_size;
939 cf_port->cs1 = be32_to_cpup(cs_num);
836 } 940 }
837 941
838 cf_port = kzalloc(sizeof(*cf_port), GFP_KERNEL); 942 res_cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
839 if (!cf_port) 943
840 return -ENOMEM; 944 if (!res_cs0) {
945 rv = -EINVAL;
946 goto free_cf_port;
947 }
948
949 cs0 = devm_ioremap_nocache(&pdev->dev, res_cs0->start,
950 resource_size(res_cs0));
951
952 if (!cs0)
953 goto free_cf_port;
841 954
842 /* allocate host */ 955 /* allocate host */
843 host = ata_host_alloc(&pdev->dev, 1); 956 host = ata_host_alloc(&pdev->dev, 1);
@@ -846,21 +959,22 @@ static int __devinit octeon_cf_probe(struct platform_device *pdev)
846 959
847 ap = host->ports[0]; 960 ap = host->ports[0];
848 ap->private_data = cf_port; 961 ap->private_data = cf_port;
962 pdev->dev.platform_data = cf_port;
849 cf_port->ap = ap; 963 cf_port->ap = ap;
850 ap->ops = &octeon_cf_ops; 964 ap->ops = &octeon_cf_ops;
851 ap->pio_mask = ATA_PIO6; 965 ap->pio_mask = ATA_PIO6;
852 ap->flags |= ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING; 966 ap->flags |= ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING;
853 967
854 base = cs0 + ocd->base_region_bias; 968 if (!is_16bit) {
855 if (!ocd->is16bit) { 969 base = cs0 + 0x800;
856 ap->ioaddr.cmd_addr = base; 970 ap->ioaddr.cmd_addr = base;
857 ata_sff_std_ports(&ap->ioaddr); 971 ata_sff_std_ports(&ap->ioaddr);
858 972
859 ap->ioaddr.altstatus_addr = base + 0xe; 973 ap->ioaddr.altstatus_addr = base + 0xe;
860 ap->ioaddr.ctl_addr = base + 0xe; 974 ap->ioaddr.ctl_addr = base + 0xe;
861 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer8; 975 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer8;
862 } else if (cs1) { 976 } else if (cf_port->is_true_ide) {
863 /* Presence of cs1 indicates True IDE mode. */ 977 base = cs0;
864 ap->ioaddr.cmd_addr = base + (ATA_REG_CMD << 1) + 1; 978 ap->ioaddr.cmd_addr = base + (ATA_REG_CMD << 1) + 1;
865 ap->ioaddr.data_addr = base + (ATA_REG_DATA << 1); 979 ap->ioaddr.data_addr = base + (ATA_REG_DATA << 1);
866 ap->ioaddr.error_addr = base + (ATA_REG_ERR << 1) + 1; 980 ap->ioaddr.error_addr = base + (ATA_REG_ERR << 1) + 1;
@@ -876,19 +990,15 @@ static int __devinit octeon_cf_probe(struct platform_device *pdev)
876 ap->ioaddr.ctl_addr = cs1 + (6 << 1) + 1; 990 ap->ioaddr.ctl_addr = cs1 + (6 << 1) + 1;
877 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16; 991 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16;
878 992
879 ap->mwdma_mask = ATA_MWDMA4; 993 ap->mwdma_mask = enable_dma ? ATA_MWDMA4 : 0;
880 irq = platform_get_irq(pdev, 0);
881 irq_handler = octeon_cf_interrupt;
882
883 /* True IDE mode needs delayed work to poll for not-busy. */
884 cf_port->wq = create_singlethread_workqueue(DRV_NAME);
885 if (!cf_port->wq)
886 goto free_cf_port;
887 INIT_DELAYED_WORK(&cf_port->delayed_finish,
888 octeon_cf_delayed_finish);
889 994
995 /* True IDE mode needs a timer to poll for not-busy. */
996 hrtimer_init(&cf_port->delayed_finish, CLOCK_MONOTONIC,
997 HRTIMER_MODE_REL);
998 cf_port->delayed_finish.function = octeon_cf_delayed_finish;
890 } else { 999 } else {
891 /* 16 bit but not True IDE */ 1000 /* 16 bit but not True IDE */
1001 base = cs0 + 0x800;
892 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16; 1002 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16;
893 octeon_cf_ops.softreset = octeon_cf_softreset16; 1003 octeon_cf_ops.softreset = octeon_cf_softreset16;
894 octeon_cf_ops.sff_check_status = octeon_cf_check_status16; 1004 octeon_cf_ops.sff_check_status = octeon_cf_check_status16;
@@ -902,28 +1012,71 @@ static int __devinit octeon_cf_probe(struct platform_device *pdev)
902 ap->ioaddr.ctl_addr = base + 0xe; 1012 ap->ioaddr.ctl_addr = base + 0xe;
903 ap->ioaddr.altstatus_addr = base + 0xe; 1013 ap->ioaddr.altstatus_addr = base + 0xe;
904 } 1014 }
1015 cf_port->c0 = ap->ioaddr.ctl_addr;
1016
1017 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
1018 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
905 1019
906 ata_port_desc(ap, "cmd %p ctl %p", base, ap->ioaddr.ctl_addr); 1020 ata_port_desc(ap, "cmd %p ctl %p", base, ap->ioaddr.ctl_addr);
907 1021
908 1022
909 snprintf(version, sizeof(version), "%s %d bit%s", 1023 dev_info(&pdev->dev, "version " DRV_VERSION" %d bit%s.\n",
910 DRV_VERSION, 1024 is_16bit ? 16 : 8,
911 (ocd->is16bit) ? 16 : 8, 1025 cf_port->is_true_ide ? ", True IDE" : "");
912 (cs1) ? ", True IDE" : "");
913 ata_print_version_once(&pdev->dev, version);
914 1026
915 return ata_host_activate(host, irq, irq_handler, 0, &octeon_cf_sht); 1027 return ata_host_activate(host, irq, irq_handler,
1028 IRQF_SHARED, &octeon_cf_sht);
916 1029
917free_cf_port: 1030free_cf_port:
918 kfree(cf_port); 1031 kfree(cf_port);
919 return -ENOMEM; 1032 return rv;
1033}
1034
1035static void octeon_cf_shutdown(struct device *dev)
1036{
1037 union cvmx_mio_boot_dma_cfgx dma_cfg;
1038 union cvmx_mio_boot_dma_intx dma_int;
1039
1040 struct octeon_cf_port *cf_port = dev->platform_data;
1041
1042 if (cf_port->dma_base) {
1043 /* Stop and clear the dma engine. */
1044 dma_cfg.u64 = 0;
1045 dma_cfg.s.size = -1;
1046 cvmx_write_csr(cf_port->dma_base + DMA_CFG, dma_cfg.u64);
1047
1048 /* Disable the interrupt. */
1049 dma_int.u64 = 0;
1050 cvmx_write_csr(cf_port->dma_base + DMA_INT_EN, dma_int.u64);
1051
1052 /* Clear the DMA complete status */
1053 dma_int.s.done = 1;
1054 cvmx_write_csr(cf_port->dma_base + DMA_INT, dma_int.u64);
1055
1056 __raw_writeb(0, cf_port->c0);
1057 udelay(20);
1058 __raw_writeb(ATA_SRST, cf_port->c0);
1059 udelay(20);
1060 __raw_writeb(0, cf_port->c0);
1061 mdelay(100);
1062 }
920} 1063}
921 1064
1065static struct of_device_id octeon_cf_match[] = {
1066 {
1067 .compatible = "cavium,ebt3000-compact-flash",
1068 },
1069 {},
1070};
1071MODULE_DEVICE_TABLE(of, octeon_i2c_match);
1072
922static struct platform_driver octeon_cf_driver = { 1073static struct platform_driver octeon_cf_driver = {
923 .probe = octeon_cf_probe, 1074 .probe = octeon_cf_probe,
924 .driver = { 1075 .driver = {
925 .name = DRV_NAME, 1076 .name = DRV_NAME,
926 .owner = THIS_MODULE, 1077 .owner = THIS_MODULE,
1078 .of_match_table = octeon_cf_match,
1079 .shutdown = octeon_cf_shutdown
927 }, 1080 },
928}; 1081};
929 1082