25 #include <linux/types.h>
26 #include <linux/module.h>
27 #include <linux/pci.h>
32 #define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
34 #define SCC_PATA_NAME "scc IDE"
36 #define TDVHSEL_MASTER 0x00000001
37 #define TDVHSEL_SLAVE 0x00000004
39 #define MODE_JCUSFEN 0x00000080
41 #define CCKCTRL_ATARESET 0x00040000
42 #define CCKCTRL_BUFCNT 0x00020000
43 #define CCKCTRL_CRST 0x00010000
44 #define CCKCTRL_OCLKEN 0x00000100
45 #define CCKCTRL_ATACLKOEN 0x00000002
46 #define CCKCTRL_LCLKEN 0x00000001
48 #define QCHCD_IOS_SS 0x00000001
50 #define QCHSD_STPDIAG 0x00020000
52 #define INTMASK_MSK 0xD1000012
53 #define INTSTS_SERROR 0x80000000
54 #define INTSTS_PRERR 0x40000000
55 #define INTSTS_RERR 0x10000000
56 #define INTSTS_ICERR 0x01000000
57 #define INTSTS_BMSINT 0x00000010
58 #define INTSTS_BMHE 0x00000008
59 #define INTSTS_IOIRQS 0x00000004
60 #define INTSTS_INTRQ 0x00000002
61 #define INTSTS_ACTEINT 0x00000001
63 #define ECMODE_VALUE 0x01
65 static struct scc_ports {
72 static unsigned long JCHSTtbl[2][7] = {
73 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00},
74 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00}
78 static unsigned long JCHHTtbl[2][7] = {
79 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00},
80 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00}
84 static unsigned long JCHCTtbl[2][7] = {
85 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00},
86 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00}
92 static unsigned long JCHDCTxtbl[2][7] = {
93 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00},
94 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00}
98 static unsigned long JCSTWTxtbl[2][7] = {
99 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00},
100 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02}
104 static unsigned long JCTSStbl[2][7] = {
105 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00},
106 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}
110 static unsigned long JCENVTtbl[2][7] = {
111 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00},
112 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}
116 static unsigned long JCACTSELtbl[2][7] = {
117 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00},
118 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
122 static u8 scc_ide_inb(
unsigned long port)
159 static void scc_ide_insw(
unsigned long port,
void *
addr,
u32 count)
167 static void scc_ide_insl(
unsigned long port,
void *addr,
u32 count)
176 static void scc_ide_outb(
u8 addr,
unsigned long port)
182 scc_ide_outsw(
unsigned long port,
void *addr,
u32 count)
191 scc_ide_outsl(
unsigned long port,
void *addr,
u32 count)
211 struct scc_ports *
ports = ide_get_hwifdata(hwif);
212 unsigned long ctl_base = ports->ctl;
213 unsigned long cckctrl_port = ctl_base + 0xff0;
214 unsigned long piosht_port = ctl_base + 0x000;
215 unsigned long pioct_port = ctl_base + 0x004;
243 struct scc_ports *ports = ide_get_hwifdata(hwif);
244 unsigned long ctl_base = ports->ctl;
245 unsigned long cckctrl_port = ctl_base + 0xff0;
246 unsigned long mdmact_port = ctl_base + 0x008;
247 unsigned long mcrcst_port = ctl_base + 0x00c;
248 unsigned long sdmact_port = ctl_base + 0x010;
249 unsigned long scrcst_port = ctl_base + 0x014;
250 unsigned long udenvt_port = ctl_base + 0x018;
251 unsigned long tdvhsel_port = ctl_base + 0x020;
252 int is_slave = drive->
dn & 1;
255 unsigned long jcactsel;
259 if (reg & CCKCTRL_ATACLKOEN) {
271 jcactsel = jcactsel << 2;
282 static void scc_dma_host_set(
ide_drive_t *drive,
int on)
286 u8 dma_stat = scc_dma_sff_read_status(hwif);
289 dma_stat |= (1 << (5 +
unit));
291 dma_stat &= ~(1 << (5 +
unit));
293 scc_ide_outb(dma_stat, hwif->
dma_base + 4);
325 dma_stat = scc_dma_sff_read_status(hwif);
339 scc_ide_outb(dma_cmd | 1, hwif->
dma_base);
345 u8 dma_stat, dma_cmd;
348 dma_cmd = scc_ide_inb(hwif->
dma_base);
350 scc_ide_outb(dma_cmd & ~1, hwif->
dma_base);
352 dma_stat = scc_dma_sff_read_status(hwif);
354 scc_ide_outb(dma_stat | 6, hwif->
dma_base + 4);
356 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
371 unsigned long intsts_port = hwif->
dma_base + 0x014;
373 int dma_stat, data_loss = 0;
374 static int retry = 0;
458 if (reg & INTSTS_ACTEINT) {
470 dma_stat = __scc_dma_end(drive);
489 if (int_stat & INTSTS_IOIRQS)
524 if (scc_ports[i].ctl == 0)
545 scc_ports[
i].ctl = (
unsigned long)ctl_addr;
546 scc_ports[
i].dma = (
unsigned long)dma_addr;
547 pci_set_drvdata(dev, (
void *) &scc_ports[i]);
557 static int scc_ide_setup_pci_device(
struct pci_dev *dev,
560 struct scc_ports *ports = pci_get_drvdata(dev);
566 for (i = 0; i <= 8; i++)
567 hw.io_ports_array[i] = ports->dma + 0x20 + i * 4;
591 unsigned long ctl_base;
592 unsigned long dma_base;
593 unsigned long cckctrl_port;
594 unsigned long intmask_port;
595 unsigned long mode_port;
596 unsigned long ecmode_port;
598 struct scc_ports *ports;
605 rc = setup_mmio_scc(dev, d->
name);
609 ports = pci_get_drvdata(dev);
610 ctl_base = ports->ctl;
611 dma_base = ports->dma;
612 cckctrl_port = ctl_base + 0xff0;
613 intmask_port = dma_base + 0x010;
614 mode_port = ctl_base + 0x024;
615 ecmode_port = ctl_base + 0xf00;
628 reg =
in_be32((
void*)cckctrl_port);
641 rc = scc_ide_setup_pci_device(dev, d);
671 if (valid & IDE_VALID_NSECT)
673 if (valid & IDE_VALID_LBAL)
675 if (valid & IDE_VALID_LBAM)
677 if (valid & IDE_VALID_LBAH)
684 void *
buf,
unsigned int len)
691 scc_ide_insl(data_addr, buf, len / 4);
694 scc_ide_insw(data_addr, (
u8 *)buf + (len & ~3), 1);
696 scc_ide_insw(data_addr, buf, len / 2);
700 void *buf,
unsigned int len)
702 unsigned long data_addr = drive->
hwif->io_ports.data_addr;
707 scc_ide_outsl(data_addr, buf, len / 4);
710 scc_ide_outsw(data_addr, (
u8 *)buf + (len & ~3), 1);
712 scc_ide_outsw(data_addr, buf, len / 2);
724 struct scc_ports *ports = pci_get_drvdata(dev);
725 unsigned long dma_base = ports->dma;
727 ide_set_hwifdata(hwif, ports);
746 if (pci_get_drvdata(dev) ==
NULL)
748 init_mmio_iops_scc(hwif);
783 .exec_command = scc_exec_command,
784 .read_status = scc_read_status,
785 .read_altstatus = scc_read_altstatus,
786 .write_devctl = scc_write_devctl,
789 .tf_load = scc_tf_load,
790 .tf_read = scc_tf_read,
792 .input_data = scc_input_data,
793 .output_data = scc_output_data,
797 .set_pio_mode = scc_set_pio_mode,
798 .set_dma_mode = scc_set_dma_mode,
799 .udma_filter = scc_udma_filter,
800 .cable_detect = scc_cable_detect,
804 .dma_host_set = scc_dma_host_set,
805 .dma_setup = scc_dma_setup,
806 .dma_start = scc_dma_start,
807 .dma_end = scc_dma_end,
808 .dma_test_irq = scc_dma_test_irq,
811 .dma_sff_read_status = scc_dma_sff_read_status,
816 .init_iops = init_iops_scc,
817 .init_dma = scc_init_dma,
818 .init_hwif = init_hwif_scc,
819 .tp_ops = &scc_tp_ops,
820 .port_ops = &scc_port_ops,
821 .dma_ops = &scc_dma_ops,
839 return init_setup_scc(dev, &scc_chipset);
851 struct scc_ports *ports = pci_get_drvdata(dev);
852 struct ide_host *host = ports->host;
859 memset(ports, 0,
sizeof(*ports));
870 .id_table = scc_pci_tbl,
871 .probe = scc_init_one,
875 static int __init scc_ide_init(
void)
880 static void __exit scc_ide_exit(
void)