0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <linux/kernel.h>
0020 #include <linux/module.h>
0021 #include <linux/pci.h>
0022 #include <linux/blkdev.h>
0023 #include <linux/delay.h>
0024 #include <scsi/scsi_host.h>
0025 #include <linux/libata.h>
0026
0027 #define DRV_NAME "pata_sc1200"
0028 #define DRV_VERSION "0.2.6"
0029
0030 #define SC1200_REV_A 0x00
0031 #define SC1200_REV_B1 0x01
0032 #define SC1200_REV_B3 0x02
0033 #define SC1200_REV_C1 0x03
0034 #define SC1200_REV_D1 0x04
0035
0036
0037
0038
0039
0040
0041
0042
0043 static int sc1200_clock(void)
0044 {
0045
0046 u8 chip_id = inb(0x903C);
0047 u8 silicon_rev = inb(0x903D);
0048 u16 pci_clock;
0049
0050 if (chip_id == 0x04 && silicon_rev < SC1200_REV_B1)
0051 return 0;
0052
0053
0054
0055
0056 pci_clock = inw(0x901E);
0057 pci_clock >>= 8;
0058 pci_clock &= 0x03;
0059 if (pci_clock == 3)
0060 pci_clock = 0;
0061 return pci_clock;
0062 }
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 static void sc1200_set_piomode(struct ata_port *ap, struct ata_device *adev)
0073 {
0074 static const u32 pio_timings[4][5] = {
0075
0076 { 0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010 },
0077
0078 { 0xd1329172, 0x71212171, 0x30200080, 0x20102010, 0x00100010 },
0079
0080 { 0xfaa3f4f3, 0xc23232b2, 0x513101c1, 0x31213121, 0x10211021 },
0081
0082 { 0xfff4fff4, 0xf35353d3, 0x814102f1, 0x42314231, 0x11311131 }
0083 };
0084
0085 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0086 u32 format;
0087 unsigned int reg = 0x40 + 0x10 * ap->port_no;
0088 int mode = adev->pio_mode - XFER_PIO_0;
0089
0090 pci_read_config_dword(pdev, reg + 4, &format);
0091 format >>= 31;
0092 format += sc1200_clock();
0093 pci_write_config_dword(pdev, reg + 8 * adev->devno,
0094 pio_timings[format][mode]);
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 static void sc1200_set_dmamode(struct ata_port *ap, struct ata_device *adev)
0107 {
0108 static const u32 udma_timing[3][3] = {
0109 { 0x00921250, 0x00911140, 0x00911030 },
0110 { 0x00932470, 0x00922260, 0x00922140 },
0111 { 0x009436A1, 0x00933481, 0x00923261 }
0112 };
0113
0114 static const u32 mwdma_timing[3][3] = {
0115 { 0x00077771, 0x00012121, 0x00002020 },
0116 { 0x000BBBB2, 0x00024241, 0x00013131 },
0117 { 0x000FFFF3, 0x00035352, 0x00015151 }
0118 };
0119
0120 int clock = sc1200_clock();
0121 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0122 unsigned int reg = 0x40 + 0x10 * ap->port_no;
0123 int mode = adev->dma_mode;
0124 u32 format;
0125
0126 if (mode >= XFER_UDMA_0)
0127 format = udma_timing[clock][mode - XFER_UDMA_0];
0128 else
0129 format = mwdma_timing[clock][mode - XFER_MW_DMA_0];
0130
0131 if (adev->devno == 0) {
0132 u32 timings;
0133
0134 pci_read_config_dword(pdev, reg + 4, &timings);
0135 timings &= 0x80000000UL;
0136 timings |= format;
0137 pci_write_config_dword(pdev, reg + 4, timings);
0138 } else
0139 pci_write_config_dword(pdev, reg + 12, format);
0140 }
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 static unsigned int sc1200_qc_issue(struct ata_queued_cmd *qc)
0153 {
0154 struct ata_port *ap = qc->ap;
0155 struct ata_device *adev = qc->dev;
0156 struct ata_device *prev = ap->private_data;
0157
0158
0159 if (ata_dma_enabled(adev) && adev != prev && prev != NULL) {
0160
0161 if ((ata_using_udma(adev) && !ata_using_udma(prev)) ||
0162 (ata_using_udma(prev) && !ata_using_udma(adev)))
0163
0164 sc1200_set_dmamode(ap, adev);
0165 }
0166
0167 return ata_bmdma_qc_issue(qc);
0168 }
0169
0170
0171
0172
0173
0174
0175
0176
0177 static int sc1200_qc_defer(struct ata_queued_cmd *qc)
0178 {
0179 struct ata_host *host = qc->ap->host;
0180 struct ata_port *alt = host->ports[1 ^ qc->ap->port_no];
0181 int rc;
0182
0183
0184 rc = ata_std_qc_defer(qc);
0185 if (rc != 0)
0186 return rc;
0187
0188
0189
0190 if (alt && alt->qc_active)
0191 return ATA_DEFER_PORT;
0192 return 0;
0193 }
0194
0195 static struct scsi_host_template sc1200_sht = {
0196 ATA_BASE_SHT(DRV_NAME),
0197 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
0198 .dma_boundary = ATA_DMA_BOUNDARY,
0199 };
0200
0201 static struct ata_port_operations sc1200_port_ops = {
0202 .inherits = &ata_bmdma_port_ops,
0203 .qc_prep = ata_bmdma_dumb_qc_prep,
0204 .qc_issue = sc1200_qc_issue,
0205 .qc_defer = sc1200_qc_defer,
0206 .cable_detect = ata_cable_40wire,
0207 .set_piomode = sc1200_set_piomode,
0208 .set_dmamode = sc1200_set_dmamode,
0209 };
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id)
0221 {
0222 static const struct ata_port_info info = {
0223 .flags = ATA_FLAG_SLAVE_POSS,
0224 .pio_mask = ATA_PIO4,
0225 .mwdma_mask = ATA_MWDMA2,
0226 .udma_mask = ATA_UDMA2,
0227 .port_ops = &sc1200_port_ops
0228 };
0229 const struct ata_port_info *ppi[] = { &info, NULL };
0230
0231 return ata_pci_bmdma_init_one(dev, ppi, &sc1200_sht, NULL, 0);
0232 }
0233
0234 static const struct pci_device_id sc1200[] = {
0235 { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_IDE), },
0236
0237 { },
0238 };
0239
0240 static struct pci_driver sc1200_pci_driver = {
0241 .name = DRV_NAME,
0242 .id_table = sc1200,
0243 .probe = sc1200_init_one,
0244 .remove = ata_pci_remove_one,
0245 #ifdef CONFIG_PM_SLEEP
0246 .suspend = ata_pci_device_suspend,
0247 .resume = ata_pci_device_resume,
0248 #endif
0249 };
0250
0251 module_pci_driver(sc1200_pci_driver);
0252
0253 MODULE_AUTHOR("Alan Cox, Mark Lord");
0254 MODULE_DESCRIPTION("low-level driver for the NS/AMD SC1200");
0255 MODULE_LICENSE("GPL");
0256 MODULE_DEVICE_TABLE(pci, sc1200);
0257 MODULE_VERSION(DRV_VERSION);