17 #include <linux/kernel.h>
18 #include <linux/module.h>
23 #include <linux/types.h>
25 #include <asm/cacheflush.h>
33 #define DRV_NAME "mpc52xx_ata"
67 static const u16 ataspec_t0[5] = {600, 383, 240, 180, 120};
68 static const u16 ataspec_t1[5] = { 70, 50, 30, 30, 25};
69 static const u16 ataspec_t2_8[5] = {290, 290, 290, 80, 70};
70 static const u16 ataspec_t2_16[5] = {165, 125, 100, 80, 70};
71 static const u16 ataspec_t2i[5] = { 0, 0, 0, 70, 25};
72 static const u16 ataspec_t4[5] = { 30, 20, 15, 10, 10};
73 static const u16 ataspec_ta[5] = { 35, 35, 35, 35, 35};
75 #define CALC_CLKCYC(c,v) ((((v)+(c)-1)/(c)))
90 static const struct mdmaspec mdmaspec66[3] = {
91 { .t0M = 32, .td = 15, .th = 2, .tj = 2, .tkw = 15, .tm = 4, .tn = 1 },
92 { .t0M = 10, .td = 6, .th = 1, .tj = 1, .tkw = 4, .tm = 2, .tn = 1 },
93 { .t0M = 8, .td = 5, .th = 1, .tj = 1, .tkw = 2, .tm = 2, .tn = 1 },
96 static const struct mdmaspec mdmaspec132[3] = {
97 { .t0M = 64, .td = 29, .th = 3, .tj = 3, .tkw = 29, .tm = 7, .tn = 2 },
98 { .t0M = 20, .td = 11, .th = 2, .tj = 1, .tkw = 7, .tm = 4, .tn = 1 },
99 { .t0M = 16, .td = 10, .th = 2, .tj = 1, .tkw = 4, .tm = 4, .tn = 1 },
123 static const struct udmaspec udmaspec66[6] = {
124 { .tcyc = 8, .t2cyc = 16, .tds = 1, .tdh = 1, .tdvs = 5, .tdvh = 1,
125 .tfs = 16, .tli = 10, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
126 .tsr = 3, .trfs = 5, .trp = 11, .tack = 2, .tss = 4,
128 { .tcyc = 5, .t2cyc = 11, .tds = 1, .tdh = 1, .tdvs = 4, .tdvh = 1,
129 .tfs = 14, .tli = 10, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
130 .tsr = 2, .trfs = 5, .trp = 9, .tack = 2, .tss = 4,
132 { .tcyc = 4, .t2cyc = 8, .tds = 1, .tdh = 1, .tdvs = 3, .tdvh = 1,
133 .tfs = 12, .tli = 10, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
134 .tsr = 2, .trfs = 4, .trp = 7, .tack = 2, .tss = 4,
136 { .tcyc = 3, .t2cyc = 6, .tds = 1, .tdh = 1, .tdvs = 2, .tdvh = 1,
137 .tfs = 9, .tli = 7, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
138 .tsr = 2, .trfs = 4, .trp = 7, .tack = 2, .tss = 4,
140 { .tcyc = 2, .t2cyc = 4, .tds = 1, .tdh = 1, .tdvs = 1, .tdvh = 1,
141 .tfs = 8, .tli = 8, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
142 .tsr = 2, .trfs = 4, .trp = 7, .tack = 2, .tss = 4,
144 { .tcyc = 2, .t2cyc = 2, .tds = 1, .tdh = 1, .tdvs = 1, .tdvh = 1,
145 .tfs = 6, .tli = 5, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
146 .tsr = 2, .trfs = 4, .trp = 6, .tack = 2, .tss = 4,
150 static const struct udmaspec udmaspec132[6] = {
151 { .tcyc = 15, .t2cyc = 31, .tds = 2, .tdh = 1, .tdvs = 10, .tdvh = 1,
152 .tfs = 30, .tli = 20, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
153 .tsr = 7, .trfs = 10, .trp = 22, .tack = 3, .tss = 7,
155 { .tcyc = 10, .t2cyc = 21, .tds = 2, .tdh = 1, .tdvs = 7, .tdvh = 1,
156 .tfs = 27, .tli = 20, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
157 .tsr = 4, .trfs = 10, .trp = 17, .tack = 3, .tss = 7,
159 { .tcyc = 6, .t2cyc = 12, .tds = 1, .tdh = 1, .tdvs = 5, .tdvh = 1,
160 .tfs = 23, .tli = 20, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
161 .tsr = 3, .trfs = 8, .trp = 14, .tack = 3, .tss = 7,
163 { .tcyc = 7, .t2cyc = 12, .tds = 1, .tdh = 1, .tdvs = 3, .tdvh = 1,
164 .tfs = 15, .tli = 13, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
165 .tsr = 3, .trfs = 8, .trp = 14, .tack = 3, .tss = 7,
167 { .tcyc = 2, .t2cyc = 5, .tds = 0, .tdh = 0, .tdvs = 1, .tdvh = 1,
168 .tfs = 16, .tli = 14, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
169 .tsr = 2, .trfs = 7, .trp = 13, .tack = 2, .tss = 6,
171 { .tcyc = 3, .t2cyc = 6, .tds = 1, .tdh = 1, .tdvs = 1, .tdvh = 1,
172 .tfs = 12, .tli = 10, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
173 .tsr = 3, .trfs = 7, .trp = 12, .tack = 3, .tss = 7,
180 #define MPC52xx_ATA_HOSTCONF_SMR 0x80000000UL
181 #define MPC52xx_ATA_HOSTCONF_FR 0x40000000UL
182 #define MPC52xx_ATA_HOSTCONF_IE 0x02000000UL
183 #define MPC52xx_ATA_HOSTCONF_IORDY 0x01000000UL
185 #define MPC52xx_ATA_HOSTSTAT_TIP 0x80000000UL
186 #define MPC52xx_ATA_HOSTSTAT_UREP 0x40000000UL
187 #define MPC52xx_ATA_HOSTSTAT_RERR 0x02000000UL
188 #define MPC52xx_ATA_HOSTSTAT_WERR 0x01000000UL
190 #define MPC52xx_ATA_FIFOSTAT_EMPTY 0x01
191 #define MPC52xx_ATA_FIFOSTAT_ERROR 0x40
193 #define MPC52xx_ATA_DMAMODE_WRITE 0x01
194 #define MPC52xx_ATA_DMAMODE_READ 0x02
195 #define MPC52xx_ATA_DMAMODE_UDMA 0x04
196 #define MPC52xx_ATA_DMAMODE_IE 0x08
197 #define MPC52xx_ATA_DMAMODE_FE 0x10
198 #define MPC52xx_ATA_DMAMODE_FR 0x20
199 #define MPC52xx_ATA_DMAMODE_HUT 0x40
201 #define MAX_DMA_BUFFERS 128
202 #define MAX_DMA_BUFFER_SIZE 0x20000u
275 if ((pio < 0) || (pio > 4))
278 t0 =
CALC_CLKCYC(ipb_period, 1000 * ataspec_t0[pio]);
279 t1 =
CALC_CLKCYC(ipb_period, 1000 * ataspec_t1[pio]);
280 t2_8 =
CALC_CLKCYC(ipb_period, 1000 * ataspec_t2_8[pio]);
281 t2_16 =
CALC_CLKCYC(ipb_period, 1000 * ataspec_t2_16[pio]);
282 t2i =
CALC_CLKCYC(ipb_period, 1000 * ataspec_t2i[pio]);
283 t4 =
CALC_CLKCYC(ipb_period, 1000 * ataspec_t4[pio]);
284 ta =
CALC_CLKCYC(ipb_period, 1000 * ataspec_ta[pio]);
286 timing->
pio1 = (t0 << 24) | (t2_8 << 16) | (t2_16 << 8) | (t2i);
287 timing->
pio2 = (t4 << 24) | (t1 << 16) | (ta << 8);
299 if (speed < 0 || speed > 2)
316 if (speed < 0 || speed > 2)
376 mpc52xx_ata_compute_pio_timings(priv, 0, 0);
377 mpc52xx_ata_compute_pio_timings(priv, 1, 0);
379 mpc52xx_ata_apply_timings(priv, 0);
397 rv = mpc52xx_ata_compute_pio_timings(priv, adev->
devno, pio);
400 dev_err(ap->
dev,
"error: invalid PIO mode: %d\n", pio);
404 mpc52xx_ata_apply_timings(priv, adev->
devno);
415 rv = mpc52xx_ata_compute_udma_timings(priv, adev->
devno, dma);
418 rv = mpc52xx_ata_compute_mdma_timings(priv, adev->
devno, dma);
423 "Trying to select invalid DMA mode %d\n",
428 mpc52xx_ata_apply_timings(priv, adev->
devno);
436 if (device != priv->
csel)
437 mpc52xx_ata_apply_timings(priv, device);
464 bcom_prepare_next_buffer(priv->
dmatsk);
485 dev_alert(ap->
dev,
"dma table"
487 goto use_pio_instead;
508 if (!mpc52xx_ata_build_dmatable(qc))
509 dev_alert(ap->
dev,
"%s: %i, return 1?\n",
514 dev_alert(ap->
dev,
"%s: FIFO error detected: 0x%02x!\n",
552 ap->
ops->sff_exec_command(ap, &qc->
tf);
561 bcom_set_task_auto_start(priv->
dmatsk->tasknum, priv->
dmatsk->tasknum);
577 dev_alert(ap->
dev,
"%s: FIFO error detected: 0x%02x!\n",
582 mpc52xx_bmdma_status(
struct ata_port *ap)
588 dev_alert(ap->
dev,
"%s: FIFO error detected: 0x%02x!\n",
597 mpc52xx_ata_task_irq(
int irq,
void *vpriv)
600 while (bcom_buffer_done(priv->
dmatsk))
613 .inherits = &ata_bmdma_port_ops,
614 .sff_dev_select = mpc52xx_ata_dev_select,
615 .set_piomode = mpc52xx_ata_set_piomode,
616 .set_dmamode = mpc52xx_ata_set_dmamode,
617 .bmdma_setup = mpc52xx_bmdma_setup,
618 .bmdma_start = mpc52xx_bmdma_start,
619 .bmdma_stop = mpc52xx_bmdma_stop,
620 .bmdma_status = mpc52xx_bmdma_status,
626 unsigned long raw_ata_regs,
int mwdma_mask,
int udma_mask)
630 struct ata_ioports *aio;
641 ap->
ops = &mpc52xx_ata_port_ops;
645 aio->cmd_addr =
NULL;
646 aio->altstatus_addr = &priv->
ata_regs->tf_control;
647 aio->ctl_addr = &priv->
ata_regs->tf_control;
648 aio->data_addr = &priv->
ata_regs->tf_data;
649 aio->error_addr = &priv->
ata_regs->tf_features;
650 aio->feature_addr = &priv->
ata_regs->tf_features;
651 aio->nsect_addr = &priv->
ata_regs->tf_sec_count;
652 aio->lbal_addr = &priv->
ata_regs->tf_sec_num;
653 aio->lbam_addr = &priv->
ata_regs->tf_cyl_low;
654 aio->lbah_addr = &priv->
ata_regs->tf_cyl_high;
655 aio->device_addr = &priv->
ata_regs->tf_dev_head;
656 aio->status_addr = &priv->
ata_regs->tf_command;
657 aio->command_addr = &priv->
ata_regs->tf_command;
667 mpc52xx_ata_remove_one(
struct device *dev)
685 unsigned int ipb_freq;
691 int mwdma_mask = 0, udma_mask = 0;
699 dev_err(&op->
dev,
"could not determine IPB bus frequency\n");
707 dev_err(&op->
dev,
"could not determine device base address\n");
713 dev_err(&op->
dev,
"error requesting register region\n");
719 dev_err(&op->
dev,
"error mapping device registers\n");
738 if ((prop) && (proplen >= 4))
739 mwdma_mask =
ATA_MWDMA2 & ((1 << (*prop + 1)) - 1);
741 if ((prop) && (proplen >= 4))
742 udma_mask =
ATA_UDMA2 & ((1 << (*prop + 1)) - 1);
753 dev_err(&op->
dev,
"error allocating private structure\n");
758 priv->
ipb_period = 1000000000 / (ipb_freq / 1000);
765 if (ipb_freq/1000000 == 66) {
776 dev_err(&op->
dev,
"bestcomm initialization failed\n");
781 task_irq = bcom_get_task_irq(dmatsk);
782 rv = devm_request_irq(&op->
dev, task_irq, &mpc52xx_ata_task_irq, 0,
785 dev_err(&op->
dev,
"error requesting DMA IRQ\n");
791 rv = mpc52xx_ata_hw_init(priv);
793 dev_err(&op->
dev,
"error initializing hardware\n");
798 rv = mpc52xx_ata_init_one(&op->
dev, priv, res_mem.start,
799 mwdma_mask, udma_mask);
801 dev_err(&op->
dev,
"error registering with ATA layer\n");
822 priv = mpc52xx_ata_remove_one(&op->
dev);
825 task_irq = bcom_get_task_irq(priv->
dmatsk);
841 return ata_host_suspend(host, state);
851 rv = mpc52xx_ata_hw_init(priv);
853 dev_err(host->
dev,
"error initializing hardware\n");
857 ata_host_resume(host);
866 { .compatible =
"fsl,mpc5200-ata", },
867 { .compatible =
"mpc5200-ata", },
873 .probe = mpc52xx_ata_probe,
874 .remove = mpc52xx_ata_remove,
876 .suspend = mpc52xx_ata_suspend,
877 .resume = mpc52xx_ata_resume,
882 .of_match_table = mpc52xx_ata_of_match,