aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/pata_at32.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/pata_at32.c')
-rw-r--r--drivers/ata/pata_at32.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
index bb250a48e27c..67e574de31e8 100644
--- a/drivers/ata/pata_at32.c
+++ b/drivers/ata/pata_at32.c
@@ -28,7 +28,7 @@
28#include <asm/arch/smc.h> 28#include <asm/arch/smc.h>
29 29
30#define DRV_NAME "pata_at32" 30#define DRV_NAME "pata_at32"
31#define DRV_VERSION "0.0.2" 31#define DRV_VERSION "0.0.3"
32 32
33/* 33/*
34 * CompactFlash controller memory layout relative to the base address: 34 * CompactFlash controller memory layout relative to the base address:
@@ -64,6 +64,8 @@
64 * Mode 2 | 8.3 | 240 ns | 0x07 64 * Mode 2 | 8.3 | 240 ns | 0x07
65 * Mode 3 | 11.1 | 180 ns | 0x0f 65 * Mode 3 | 11.1 | 180 ns | 0x0f
66 * Mode 4 | 16.7 | 120 ns | 0x1f 66 * Mode 4 | 16.7 | 120 ns | 0x1f
67 *
68 * Alter PIO_MASK below according to table to set maximal PIO mode.
67 */ 69 */
68#define PIO_MASK (0x1f) 70#define PIO_MASK (0x1f)
69 71
@@ -85,36 +87,40 @@ struct at32_ide_info {
85 */ 87 */
86static int pata_at32_setup_timing(struct device *dev, 88static int pata_at32_setup_timing(struct device *dev,
87 struct at32_ide_info *info, 89 struct at32_ide_info *info,
88 const struct ata_timing *timing) 90 const struct ata_timing *ata)
89{ 91{
90 /* These two values are found through testing */
91 const int min_recover = 25;
92 const int ncs_hold = 15;
93
94 struct smc_config *smc = &info->smc; 92 struct smc_config *smc = &info->smc;
93 struct smc_timing timing;
95 94
96 int active; 95 int active;
97 int recover; 96 int recover;
98 97
98 memset(&timing, 0, sizeof(struct smc_timing));
99
99 /* Total cycle time */ 100 /* Total cycle time */
100 smc->read_cycle = timing->cyc8b; 101 timing.read_cycle = ata->cyc8b;
101 102
102 /* DIOR <= CFIOR timings */ 103 /* DIOR <= CFIOR timings */
103 smc->nrd_setup = timing->setup; 104 timing.nrd_setup = ata->setup;
104 smc->nrd_pulse = timing->act8b; 105 timing.nrd_pulse = ata->act8b;
106 timing.nrd_recover = ata->rec8b;
107
108 /* Convert nanosecond timing to clock cycles */
109 smc_set_timing(smc, &timing);
105 110
106 /* Compute recover, extend total cycle if needed */ 111 /* Add one extra cycle setup due to signal ring */
107 active = smc->nrd_setup + smc->nrd_pulse; 112 smc->nrd_setup = smc->nrd_setup + 1;
113
114 active = smc->nrd_setup + smc->nrd_pulse;
108 recover = smc->read_cycle - active; 115 recover = smc->read_cycle - active;
109 116
110 if (recover < min_recover) { 117 /* Need at least two cycles recovery */
111 smc->read_cycle = active + min_recover; 118 if (recover < 2)
112 recover = min_recover; 119 smc->read_cycle = active + 2;
113 }
114 120
115 /* (CS0, CS1, DIR, OE) <= (CFCE1, CFCE2, CFRNW, NCSX) timings */ 121 /* (CS0, CS1, DIR, OE) <= (CFCE1, CFCE2, CFRNW, NCSX) timings */
116 smc->ncs_read_setup = 0; 122 smc->ncs_read_setup = 1;
117 smc->ncs_read_pulse = active + ncs_hold; 123 smc->ncs_read_pulse = smc->read_cycle - 2;
118 124
119 /* Write timings same as read timings */ 125 /* Write timings same as read timings */
120 smc->write_cycle = smc->read_cycle; 126 smc->write_cycle = smc->read_cycle;
@@ -123,11 +129,13 @@ static int pata_at32_setup_timing(struct device *dev,
123 smc->ncs_write_setup = smc->ncs_read_setup; 129 smc->ncs_write_setup = smc->ncs_read_setup;
124 smc->ncs_write_pulse = smc->ncs_read_pulse; 130 smc->ncs_write_pulse = smc->ncs_read_pulse;
125 131
126 /* Do some debugging output */ 132 /* Do some debugging output of ATA and SMC timings */
127 dev_dbg(dev, "SMC: C=%d S=%d P=%d R=%d NCSS=%d NCSP=%d NCSR=%d\n", 133 dev_dbg(dev, "ATA: C=%d S=%d P=%d R=%d\n",
134 ata->cyc8b, ata->setup, ata->act8b, ata->rec8b);
135
136 dev_dbg(dev, "SMC: C=%d S=%d P=%d NS=%d NP=%d\n",
128 smc->read_cycle, smc->nrd_setup, smc->nrd_pulse, 137 smc->read_cycle, smc->nrd_setup, smc->nrd_pulse,
129 recover, smc->ncs_read_setup, smc->ncs_read_pulse, 138 smc->ncs_read_setup, smc->ncs_read_pulse);
130 smc->read_cycle - smc->ncs_read_pulse);
131 139
132 /* Finally, configure the SMC */ 140 /* Finally, configure the SMC */
133 return smc_set_configuration(info->cs, smc); 141 return smc_set_configuration(info->cs, smc);
@@ -182,7 +190,6 @@ static struct scsi_host_template at32_sht = {
182}; 190};
183 191
184static struct ata_port_operations at32_port_ops = { 192static struct ata_port_operations at32_port_ops = {
185 .port_disable = ata_port_disable,
186 .set_piomode = pata_at32_set_piomode, 193 .set_piomode = pata_at32_set_piomode,
187 .tf_load = ata_tf_load, 194 .tf_load = ata_tf_load,
188 .tf_read = ata_tf_read, 195 .tf_read = ata_tf_read,
@@ -203,7 +210,6 @@ static struct ata_port_operations at32_port_ops = {
203 210
204 .irq_clear = pata_at32_irq_clear, 211 .irq_clear = pata_at32_irq_clear,
205 .irq_on = ata_irq_on, 212 .irq_on = ata_irq_on,
206 .irq_ack = ata_irq_ack,
207 213
208 .port_start = ata_sff_port_start, 214 .port_start = ata_sff_port_start,
209}; 215};
@@ -223,8 +229,7 @@ static int __init pata_at32_init_one(struct device *dev,
223 /* Setup ATA bindings */ 229 /* Setup ATA bindings */
224 ap->ops = &at32_port_ops; 230 ap->ops = &at32_port_ops;
225 ap->pio_mask = PIO_MASK; 231 ap->pio_mask = PIO_MASK;
226 ap->flags = ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS 232 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS;
227 | ATA_FLAG_PIO_POLLING;
228 233
229 /* 234 /*
230 * Since all 8-bit taskfile transfers has to go on the lower 235 * Since all 8-bit taskfile transfers has to go on the lower
@@ -357,12 +362,12 @@ static int __init pata_at32_probe(struct platform_device *pdev)
357 info->smc.tdf_mode = 0; /* TDF optimization disabled */ 362 info->smc.tdf_mode = 0; /* TDF optimization disabled */
358 info->smc.tdf_cycles = 0; /* No TDF wait cycles */ 363 info->smc.tdf_cycles = 0; /* No TDF wait cycles */
359 364
360 /* Setup ATA timing */ 365 /* Setup SMC to ATA timing */
361 ret = pata_at32_setup_timing(dev, info, &initial_timing); 366 ret = pata_at32_setup_timing(dev, info, &initial_timing);
362 if (ret) 367 if (ret)
363 goto err_setup_timing; 368 goto err_setup_timing;
364 369
365 /* Setup ATA addresses */ 370 /* Map ATA address space */
366 ret = -ENOMEM; 371 ret = -ENOMEM;
367 info->ide_addr = devm_ioremap(dev, info->res_ide.start, 16); 372 info->ide_addr = devm_ioremap(dev, info->res_ide.start, 16);
368 info->alt_addr = devm_ioremap(dev, info->res_alt.start, 16); 373 info->alt_addr = devm_ioremap(dev, info->res_alt.start, 16);
@@ -373,7 +378,7 @@ static int __init pata_at32_probe(struct platform_device *pdev)
373 pata_at32_debug_bus(dev, info); 378 pata_at32_debug_bus(dev, info);
374#endif 379#endif
375 380
376 /* Register ATA device */ 381 /* Setup and register ATA device */
377 ret = pata_at32_init_one(dev, info); 382 ret = pata_at32_init_one(dev, info);
378 if (ret) 383 if (ret)
379 goto err_ata_device; 384 goto err_ata_device;