18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/slab.h>
29 static unsigned int intr_coalescing_count;
32 "INT coalescing count threshold (1..31)");
34 static unsigned int intr_coalescing_ticks;
37 "INT coalescing timer threshold in AHB ticks");
290 static void fsl_sata_set_irq_coalescing(
struct ata_host *
host,
307 spin_lock(&host->
lock);
310 intr_coalescing_count =
count;
311 intr_coalescing_ticks =
ticks;
312 spin_unlock(&host->
lock);
314 DPRINTK(
"intrrupt coalescing, count = 0x%x, ticks = %x\n",
315 intr_coalescing_count, intr_coalescing_ticks);
316 DPRINTK(
"ICC register status: (hcr base: 0x%x) = 0x%x\n",
324 intr_coalescing_count, intr_coalescing_ticks);
329 const char *
buf,
size_t count)
331 unsigned int coalescing_count, coalescing_ticks;
335 &coalescing_ticks) != 2) {
341 coalescing_count, coalescing_ticks);
346 static inline unsigned int sata_fsl_tag(
unsigned int tag,
352 if (ata_tag_internal(tag)) {
353 DPRINTK(
"mapping internal cmds to tag#0\n");
358 DPRINTK(
"tag %d invalid : out of range\n", tag);
363 DPRINTK(
"tag %d invalid : in use!!\n", tag);
371 unsigned int tag,
u32 desc_info,
388 VPRINTK(
"cda=0x%x, prde_fis_len=0x%x, ttl=0x%x, di=0x%x\n",
400 unsigned int num_prde = 0;
409 struct prde *prd_ptr_to_indirect_ext =
NULL;
410 unsigned indirect_ext_segment_sz = 0;
414 VPRINTK(
"SATA FSL : cd = 0x%p, prd = 0x%p\n", cmd_desc, prd);
416 indirect_ext_segment_paddr = cmd_desc_paddr +
423 VPRINTK(
"SATA FSL : fill_sg, sg_addr = 0x%llx, sg_len = %d\n",
424 (
unsigned long long)sg_addr, sg_len);
429 (
unsigned long long)sg_addr);
434 if (num_prde == (SATA_FSL_MAX_PRD_DIRECT - 1) &&
436 VPRINTK(
"setting indirect prde\n");
437 prd_ptr_to_indirect_ext = prd;
439 indirect_ext_segment_sz = 0;
444 ttl_dwords += sg_len;
448 VPRINTK(
"sg_fill, ttl=%d, dba=0x%x, ddc=0x%x\n",
453 if (prd_ptr_to_indirect_ext)
454 indirect_ext_segment_sz += sg_len;
457 if (prd_ptr_to_indirect_ext) {
462 (indirect_ext_segment_sz & ~0x03)));
475 unsigned int tag = sata_fsl_tag(qc->
tag, hcr_base);
487 VPRINTK(
"Dumping cfis : 0x%x, 0x%x, 0x%x\n",
491 VPRINTK(
"FPDMA xfer,Sctor cnt[0:7],[8:15] = %d,%d\n",
496 if (ata_is_atapi(qc->
tf.protocol)) {
503 num_prde = sata_fsl_fill_sg(qc, (
void *)cd,
504 &ttl_dwords, cd_paddr,
510 sata_fsl_setup_cmd_hdr_entry(pp, tag, desc_info, ttl_dwords,
513 VPRINTK(
"SATA FSL : xx_qc_prep, di = 0x%x, ttl = %d, num_prde = %d\n",
514 desc_info, ttl_dwords, num_prde);
522 unsigned int tag = sata_fsl_tag(qc->
tag, hcr_base);
524 VPRINTK(
"xx_qc_issue called,CQ=0x%x,CA=0x%x,CE=0x%x,CC=0x%x\n",
534 VPRINTK(
"xx_qc_issue called, tag=%d, CQ=0x%x, CA=0x%x\n",
537 VPRINTK(
"CE=0x%x, DE=0x%x, CC=0x%x, CmdStat = 0x%x\n",
551 unsigned int tag = sata_fsl_tag(qc->
tag, hcr_base);
561 unsigned int sc_reg_in,
u32 val)
578 VPRINTK(
"xx_scr_write, reg_in = %d\n", sc_reg);
584 static int sata_fsl_scr_read(
struct ata_link *link,
585 unsigned int sc_reg_in,
u32 *val)
602 VPRINTK(
"xx_scr_read, reg_in = %d\n", sc_reg);
604 *val =
ioread32(ssr_base + (sc_reg * 4));
608 static void sata_fsl_freeze(
struct ata_port *ap)
614 VPRINTK(
"xx_freeze, CQ=0x%x, CA=0x%x, CE=0x%x, DE=0x%x\n",
625 VPRINTK(
"in xx_freeze : HControl = 0x%x, HStatus = 0x%x\n",
629 static void sata_fsl_thaw(
struct ata_port *ap)
638 VPRINTK(
"xx_thaw, pending IRQs = 0x%x\n", (temp & 0x3F));
647 VPRINTK(
"xx_thaw : HControl = 0x%x, HStatus = 0x%x\n",
651 static void sata_fsl_pmp_attach(
struct ata_port *ap)
661 static void sata_fsl_pmp_detach(
struct ata_port *ap)
677 static int sata_fsl_port_start(
struct ata_port *ap)
710 VPRINTK(
"CHBA = 0x%x, cmdentry_phys = 0x%x\n",
731 #ifdef CONFIG_MPC8315_DS
742 dev_warn(dev,
"scr_control, speed limited to %x\n", temp);
748 static void sata_fsl_port_stop(
struct ata_port *ap)
774 static unsigned int sata_fsl_dev_classify(
struct ata_port *ap)
783 VPRINTK(
"raw sig = 0x%x\n", temp);
787 tf.lbah = (temp >> 24) & 0xff;
788 tf.lbam = (temp >> 16) & 0xff;
789 tf.lbal = (temp >> 8) & 0xff;
790 tf.nsect = temp & 0xff;
795 static int sata_fsl_hardreset(
struct ata_link *link,
unsigned int *
class,
796 unsigned long deadline)
803 unsigned long start_jiffies;
820 ata_port_err(ap,
"Hardreset failed, not off-lined %d\n", i);
829 goto try_offline_again;
832 DPRINTK(
"hardreset, controller off-lined\n");
855 if (!(temp & ONLINE)) {
860 DPRINTK(
"hardreset, controller off-lined & on-lined\n");
872 ata_port_warn(ap,
"No Device OR PHYRDY change,Hstatus = 0x%x\n",
885 if ((temp & 0xFF) != 0x18) {
888 goto do_followup_srst;
892 *
class = sata_fsl_dev_classify(ap);
906 static int sata_fsl_softreset(
struct ata_link *link,
unsigned int *
class,
907 unsigned long deadline)
913 int pmp = sata_srst_pmp(link);
922 DPRINTK(
"PHY reports no device\n");
935 DPRINTK(
"Sending SRST/device reset\n");
941 sata_fsl_setup_cmd_hdr_entry(pp, 0,
947 DPRINTK(
"Dumping cfis : 0x%x, 0x%x, 0x%x, 0x%x\n",
948 cfis[0], cfis[1], cfis[2], cfis[3]);
955 DPRINTK(
"@Softreset, CQ = 0x%x, CA = 0x%x, CC = 0x%x\n",
968 DPRINTK(
"Softreset@5000,CQ=0x%x,CA=0x%x,CC=0x%x\n",
976 DPRINTK(
"Serror = 0x%x\n", Serror);
1008 DPRINTK(
"SATA FSL : Now checking device signature\n");
1021 *
class = sata_fsl_dev_classify(ap);
1023 DPRINTK(
"class = %d\n", *
class);
1034 static void sata_fsl_error_handler(
struct ata_port *ap)
1037 DPRINTK(
"in xx_error_handler\n");
1042 static void sata_fsl_post_internal_cmd(
struct ata_queued_cmd *qc)
1053 static void sata_fsl_error_intr(
struct ata_port *ap)
1057 u32 hstatus, dereg=0, cereg = 0, SError = 0;
1058 unsigned int err_mask = 0,
action = 0;
1059 int freeze = 0,
abort=0;
1080 DPRINTK(
"error_intr,hStat=0x%x,CE=0x%x,DE =0x%x,SErr=0x%x\n",
1081 hstatus, cereg,
ioread32(hcr_base +
DE), SError);
1097 DPRINTK(
"SATA FSL: PHYRDY change indication\n");
1100 ata_ehi_hotplugged(ehi);
1118 DPRINTK(
"single device error, CE=0x%x, DE=0x%x\n",
1123 unsigned int dev_num;
1129 dev_num =
ffs(dereg) - 1;
1130 if (dev_num < ap->nr_pmp_links && dereg != 0) {
1179 static void sata_fsl_host_intr(
struct ata_port *ap)
1183 u32 hstatus, done_mask = 0;
1199 qc = ata_qc_from_tag(ap, tag);
1200 if (qc && ata_is_atapi(qc->
tf.protocol)) {
1223 if (
unlikely(SError & 0xFFFF0000)) {
1224 DPRINTK(
"serror @host_intr : 0x%x\n", SError);
1225 sata_fsl_error_intr(ap);
1228 if (
unlikely(hstatus & status_mask)) {
1229 DPRINTK(
"error interrupt!!\n");
1230 sata_fsl_error_intr(ap);
1234 VPRINTK(
"Status of all queues :\n");
1235 VPRINTK(
"done_mask/CC = 0x%x, CA = 0x%x, CE=0x%x,CQ=0x%x,apqa=0x%x\n",
1247 DPRINTK(
"Status of all queues :\n");
1248 DPRINTK(
"done_mask/CC = 0x%x, CA = 0x%x, CE=0x%x\n",
1253 if (done_mask & (1 << i))
1255 (
"completing ncq cmd,tag=%d,CC=0x%x,CA=0x%x\n",
1266 DPRINTK(
"completing non-ncq cmd, CC=0x%x\n",
1274 DPRINTK(
"spurious interrupt!!, CC = 0x%x\n",
1281 static irqreturn_t sata_fsl_interrupt(
int irq,
void *dev_instance)
1283 struct ata_host *host = dev_instance;
1286 u32 interrupt_enables;
1287 unsigned handled = 0;
1292 interrupt_enables &= 0x3F;
1294 DPRINTK(
"interrupt status 0x%x\n", interrupt_enables);
1296 if (!interrupt_enables)
1299 spin_lock(&host->
lock);
1303 ap = host->
ports[0];
1305 sata_fsl_host_intr(ap);
1307 dev_warn(host->
dev,
"interrupt on disabled port 0\n");
1313 spin_unlock(&host->
lock);
1322 static int sata_fsl_init_controller(
struct ata_host *host)
1359 fsl_sata_set_irq_coalescing(host, intr_coalescing_count,
1360 intr_coalescing_ticks);
1387 .qc_prep = sata_fsl_qc_prep,
1388 .qc_issue = sata_fsl_qc_issue,
1389 .qc_fill_rtf = sata_fsl_qc_fill_rtf,
1391 .scr_read = sata_fsl_scr_read,
1392 .scr_write = sata_fsl_scr_write,
1394 .freeze = sata_fsl_freeze,
1395 .thaw = sata_fsl_thaw,
1396 .softreset = sata_fsl_softreset,
1397 .hardreset = sata_fsl_hardreset,
1398 .pmp_softreset = sata_fsl_softreset,
1399 .error_handler = sata_fsl_error_handler,
1400 .post_internal_cmd = sata_fsl_post_internal_cmd,
1402 .port_start = sata_fsl_port_start,
1403 .port_stop = sata_fsl_port_stop,
1405 .pmp_attach = sata_fsl_pmp_attach,
1406 .pmp_detach = sata_fsl_pmp_detach,
1414 .port_ops = &sata_fsl_ops,
1432 dev_info(&ofdev->
dev,
"Sata FSL Platform/CSB Driver init\n");
1436 goto error_exit_with_cleanup;
1438 ssr_base = hcr_base + 0x100;
1439 csr_base = hcr_base + 0x140;
1443 temp = temp & 0xffffffe0;
1449 DPRINTK(
"sizeof(#define cmd_desc) = %d\n", SATA_FSL_CMD_DESC_SIZE);
1453 goto error_exit_with_cleanup;
1461 dev_err(&ofdev->
dev,
"invalid irq from platform\n");
1462 goto error_exit_with_cleanup;
1464 host_priv->
irq = irq;
1475 goto error_exit_with_cleanup;
1482 sata_fsl_init_controller(host);
1501 goto error_exit_with_cleanup;
1505 error_exit_with_cleanup:
1542 return ata_host_suspend(host, state);
1554 ret = sata_fsl_init_controller(host);
1556 dev_err(&op->
dev,
"Error initializing hardware\n");
1569 ata_host_resume(host);
1576 .compatible =
"fsl,pq-sata",
1579 .compatible =
"fsl,pq-sata-v2",
1590 .of_match_table = fsl_sata_match,
1592 .probe = sata_fsl_probe,
1593 .remove = sata_fsl_remove,
1595 .suspend = sata_fsl_suspend,
1596 .resume = sata_fsl_resume,