35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/pci.h>
41 #include <linux/device.h>
45 #define DRV_NAME "pata_scc"
46 #define DRV_VERSION "0.3"
48 #define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
51 #define SCC_CTRL_BAR 0
52 #define SCC_BMID_BAR 1
55 #define SCC_CTL_PIOSHT 0x000
56 #define SCC_CTL_PIOCT 0x004
57 #define SCC_CTL_MDMACT 0x008
58 #define SCC_CTL_MCRCST 0x00C
59 #define SCC_CTL_SDMACT 0x010
60 #define SCC_CTL_SCRCST 0x014
61 #define SCC_CTL_UDENVT 0x018
62 #define SCC_CTL_TDVHSEL 0x020
63 #define SCC_CTL_MODEREG 0x024
64 #define SCC_CTL_ECMODE 0xF00
65 #define SCC_CTL_MAEA0 0xF50
66 #define SCC_CTL_MAEC0 0xF54
67 #define SCC_CTL_CCKCTRL 0xFF0
70 #define SCC_DMA_CMD 0x000
71 #define SCC_DMA_STATUS 0x004
72 #define SCC_DMA_TABLE_OFS 0x008
73 #define SCC_DMA_INTMASK 0x010
74 #define SCC_DMA_INTST 0x014
75 #define SCC_DMA_PTERADD 0x018
76 #define SCC_REG_CMD_ADDR 0x020
77 #define SCC_REG_DATA 0x000
78 #define SCC_REG_ERR 0x004
79 #define SCC_REG_FEATURE 0x004
80 #define SCC_REG_NSECT 0x008
81 #define SCC_REG_LBAL 0x00C
82 #define SCC_REG_LBAM 0x010
83 #define SCC_REG_LBAH 0x014
84 #define SCC_REG_DEVICE 0x018
85 #define SCC_REG_STATUS 0x01C
86 #define SCC_REG_CMD 0x01C
87 #define SCC_REG_ALTSTATUS 0x020
90 #define TDVHSEL_MASTER 0x00000001
91 #define TDVHSEL_SLAVE 0x00000004
93 #define MODE_JCUSFEN 0x00000080
95 #define ECMODE_VALUE 0x01
97 #define CCKCTRL_ATARESET 0x00040000
98 #define CCKCTRL_BUFCNT 0x00020000
99 #define CCKCTRL_CRST 0x00010000
100 #define CCKCTRL_OCLKEN 0x00000100
101 #define CCKCTRL_ATACLKOEN 0x00000002
102 #define CCKCTRL_LCLKEN 0x00000001
104 #define QCHCD_IOS_SS 0x00000001
106 #define QCHSD_STPDIAG 0x00020000
108 #define INTMASK_MSK 0xD1000012
109 #define INTSTS_SERROR 0x80000000
110 #define INTSTS_PRERR 0x40000000
111 #define INTSTS_RERR 0x10000000
112 #define INTSTS_ICERR 0x01000000
113 #define INTSTS_BMSINT 0x00000010
114 #define INTSTS_BMHE 0x00000008
115 #define INTSTS_IOIRQS 0x00000004
116 #define INTSTS_INTRQ 0x00000002
117 #define INTSTS_ACTEINT 0x00000001
122 static const unsigned long JCHSTtbl[2][7] = {
123 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00},
124 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00}
128 static const unsigned long JCHHTtbl[2][7] = {
129 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00},
130 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00}
134 static const unsigned long JCHCTtbl[2][7] = {
135 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00},
136 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00}
141 static const unsigned long JCHDCTxtbl[2][7] = {
142 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00},
143 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00}
147 static const unsigned long JCSTWTxtbl[2][7] = {
148 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00},
149 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02}
153 static const unsigned long JCTSStbl[2][7] = {
154 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00},
155 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}
159 static const unsigned long JCENVTtbl[2][7] = {
160 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00},
161 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}
165 static const unsigned long JCACTSELtbl[2][7] = {
166 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00},
167 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
222 unsigned int is_slave = (adev->
devno != 0);
245 out_be32(sdmact_port, JCHDCTxtbl[offset][idx]);
246 out_be32(scrcst_port, JCSTWTxtbl[offset][idx]);
250 out_be32(mdmact_port, JCHDCTxtbl[offset][idx]);
251 out_be32(mcrcst_port, JCSTWTxtbl[offset][idx]);
256 JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]);
280 struct ata_ioports *ioaddr = &ap->ioaddr;
283 if (tf->
ctl != ap->last_ctl) {
285 ap->last_ctl = tf->
ctl;
295 VPRINTK(
"hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
309 VPRINTK(
"feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
332 static u8 scc_check_status (
struct ata_port *ap)
334 return in_be32(ap->ioaddr.status_addr);
347 struct ata_ioports *ioaddr = &ap->ioaddr;
349 tf->
command = scc_check_status(ap);
365 ap->last_ctl = tf->
ctl;
377 static void scc_exec_command (
struct ata_port *ap,
391 static u8 scc_check_altstatus (
struct ata_port *ap)
393 return in_be32(ap->ioaddr.altstatus_addr);
404 static void scc_dev_select (
struct ata_port *ap,
unsigned int device)
413 out_be32(ap->ioaddr.device_addr, tmp);
440 void __iomem *mmio = ap->ioaddr.bmdma_addr;
453 ap->
ops->sff_exec_command(ap, &qc->
tf);
467 void __iomem *mmio = ap->ioaddr.bmdma_addr;
482 static unsigned int scc_devchk (
struct ata_port *ap,
485 struct ata_ioports *ioaddr = &ap->ioaddr;
488 ap->
ops->sff_dev_select(ap, device);
499 nsect =
in_be32(ioaddr->nsect_addr);
500 lbal =
in_be32(ioaddr->lbal_addr);
502 if ((nsect == 0x55) && (lbal == 0xaa))
514 static int scc_wait_after_reset(
struct ata_link *
link,
unsigned int devmask,
515 unsigned long deadline)
518 struct ata_ioports *ioaddr = &ap->ioaddr;
519 unsigned int dev0 = devmask & (1 << 0);
520 unsigned int dev1 = devmask & (1 << 1);
549 ap->
ops->sff_dev_select(ap, 1);
555 for (i = 0; i < 2; i++) {
558 nsect =
in_be32(ioaddr->nsect_addr);
559 lbal =
in_be32(ioaddr->lbal_addr);
560 if ((nsect == 1) && (lbal == 1))
574 ap->
ops->sff_dev_select(ap, 0);
576 ap->
ops->sff_dev_select(ap, 1);
578 ap->
ops->sff_dev_select(ap, 0);
589 static unsigned int scc_bus_softreset(
struct ata_port *ap,
unsigned int devmask,
590 unsigned long deadline)
592 struct ata_ioports *ioaddr = &ap->ioaddr;
597 out_be32(ioaddr->ctl_addr, ap->ctl);
601 out_be32(ioaddr->ctl_addr, ap->ctl);
603 scc_wait_after_reset(&ap->
link, devmask, deadline);
617 static int scc_softreset(
struct ata_link *link,
unsigned int *classes,
618 unsigned long deadline)
622 unsigned int devmask = 0, err_mask;
628 if (scc_devchk(ap, 0))
630 if (slave_possible && scc_devchk(ap, 1))
634 ap->
ops->sff_dev_select(ap, 0);
637 DPRINTK(
"about to softreset, devmask=%x\n", devmask);
638 err_mask = scc_bus_softreset(ap, devmask, deadline);
640 ata_port_err(ap,
"SRST failed (err_mask=0x%x)\n", err_mask);
646 devmask & (1 << 0), &err);
647 if (slave_possible && err != 0x81)
649 devmask & (1 << 1), &err);
651 DPRINTK(
"EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
706 unsigned int classes;
711 scc_softreset(&ap->
link, &classes, deadline);
745 static u8 scc_bmdma_status (
struct ata_port *ap)
747 void __iomem *mmio = ap->ioaddr.bmdma_addr;
751 static int retry = 0;
758 if ((scc_check_altstatus(ap) &
ATA_ERR)
769 if (!(int_status & INTSTS_ACTEINT)) {
793 static unsigned int scc_data_xfer (
struct ata_device *
dev,
unsigned char *
buf,
794 unsigned int buflen,
int rw)
797 unsigned int words = buflen >> 1;
800 void __iomem *mmio = ap->ioaddr.data_addr;
804 for (i = 0; i < words; i++)
807 for (i = 0; i < words; i++)
812 __le16 align_buf[1] = { 0 };
813 unsigned char *trailing_buf = buf + buflen - 1;
817 memcpy(trailing_buf, align_buf, 1);
819 memcpy(align_buf, trailing_buf, 1);
836 static void scc_postreset(
struct ata_link *link,
unsigned int *classes)
844 ap->
ops->sff_dev_select(ap, 1);
846 ap->
ops->sff_dev_select(ap, 0);
855 out_be32(ap->ioaddr.ctl_addr, ap->ctl);
867 static void scc_irq_clear (
struct ata_port *ap)
869 void __iomem *mmio = ap->ioaddr.bmdma_addr;
885 static int scc_port_start (
struct ata_port *ap)
887 void __iomem *mmio = ap->ioaddr.bmdma_addr;
890 rc = ata_bmdma_port_start(ap);
905 static void scc_port_stop (
struct ata_port *ap)
907 void __iomem *mmio = ap->ioaddr.bmdma_addr;
917 .inherits = &ata_bmdma_port_ops,
919 .set_piomode = scc_set_piomode,
920 .set_dmamode = scc_set_dmamode,
923 .sff_tf_load = scc_tf_load,
924 .sff_tf_read = scc_tf_read,
925 .sff_exec_command = scc_exec_command,
926 .sff_check_status = scc_check_status,
927 .sff_check_altstatus = scc_check_altstatus,
928 .sff_dev_select = scc_dev_select,
929 .sff_set_devctl = scc_set_devctl,
931 .bmdma_setup = scc_bmdma_setup,
932 .bmdma_start = scc_bmdma_start,
933 .bmdma_stop = scc_bmdma_stop,
934 .bmdma_status = scc_bmdma_status,
935 .sff_data_xfer = scc_data_xfer,
938 .softreset = scc_softreset,
939 .postreset = scc_postreset,
941 .sff_irq_clear = scc_irq_clear,
943 .port_start = scc_port_start,
944 .port_stop = scc_port_stop,
953 .port_ops = &scc_pata_ops,
1007 static void scc_setup_ports (
struct ata_ioports *ioaddr,
void __iomem *base)
1012 ioaddr->bmdma_addr = base;
1014 ioaddr->error_addr = ioaddr->cmd_addr +
SCC_REG_ERR;
1022 ioaddr->command_addr = ioaddr->cmd_addr +
SCC_REG_CMD;
1025 static int scc_host_init(
struct ata_host *host)
1030 rc = scc_reset_controller(host);
1087 rc = scc_host_init(host);
1097 .id_table = scc_pci_tbl,
1098 .probe = scc_init_one,
1099 .remove = ata_pci_remove_one,
1101 .suspend = ata_pci_device_suspend,
1102 .resume = ata_pci_device_resume,