/drivers/ata/sata_via.c
C | 674 lines | 457 code | 101 blank | 116 comment | 49 complexity | 3d1938bce1f8d5a26910a520ff7b73bc MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
- /*
- * sata_via.c - VIA Serial ATA controllers
- *
- * Maintained by: Jeff Garzik <jgarzik@pobox.com>
- * Please ALWAYS copy linux-ide@vger.kernel.org
- * on emails.
- *
- * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
- * Copyright 2003-2004 Jeff Garzik
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- * libata documentation is available via 'make {ps|pdf}docs',
- * as Documentation/DocBook/libata.*
- *
- * Hardware documentation available under NDA.
- *
- *
- *
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/pci.h>
- #include <linux/init.h>
- #include <linux/blkdev.h>
- #include <linux/delay.h>
- #include <linux/device.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_cmnd.h>
- #include <scsi/scsi_host.h>
- #include <linux/libata.h>
- #define DRV_NAME "sata_via"
- #define DRV_VERSION "2.6"
- /*
- * vt8251 is different from other sata controllers of VIA. It has two
- * channels, each channel has both Master and Slave slot.
- */
- enum board_ids_enum {
- vt6420,
- vt6421,
- vt8251,
- };
- enum {
- SATA_CHAN_ENAB = 0x40, /* SATA channel enable */
- SATA_INT_GATE = 0x41, /* SATA interrupt gating */
- SATA_NATIVE_MODE = 0x42, /* Native mode enable */
- PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */
- PATA_PIO_TIMING = 0xAB, /* PATA timing register */
- PORT0 = (1 << 1),
- PORT1 = (1 << 0),
- ALL_PORTS = PORT0 | PORT1,
- NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4),
- SATA_EXT_PHY = (1 << 6), /* 0==use PATA, 1==ext phy */
- };
- static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
- static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
- static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
- static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val);
- static int vt8251_scr_write(struct ata_link *link, unsigned int scr, u32 val);
- static void svia_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
- static void svia_noop_freeze(struct ata_port *ap);
- static int vt6420_prereset(struct ata_link *link, unsigned long deadline);
- static void vt6420_bmdma_start(struct ata_queued_cmd *qc);
- static int vt6421_pata_cable_detect(struct ata_port *ap);
- static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
- static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
- static const struct pci_device_id svia_pci_tbl[] = {
- { PCI_VDEVICE(VIA, 0x5337), vt6420 },
- { PCI_VDEVICE(VIA, 0x0591), vt6420 }, /* 2 sata chnls (Master) */
- { PCI_VDEVICE(VIA, 0x3149), vt6420 }, /* 2 sata chnls (Master) */
- { PCI_VDEVICE(VIA, 0x3249), vt6421 }, /* 2 sata chnls, 1 pata chnl */
- { PCI_VDEVICE(VIA, 0x5372), vt6420 },
- { PCI_VDEVICE(VIA, 0x7372), vt6420 },
- { PCI_VDEVICE(VIA, 0x5287), vt8251 }, /* 2 sata chnls (Master/Slave) */
- { PCI_VDEVICE(VIA, 0x9000), vt8251 },
- { } /* terminate list */
- };
- static struct pci_driver svia_pci_driver = {
- .name = DRV_NAME,
- .id_table = svia_pci_tbl,
- .probe = svia_init_one,
- #ifdef CONFIG_PM
- .suspend = ata_pci_device_suspend,
- .resume = ata_pci_device_resume,
- #endif
- .remove = ata_pci_remove_one,
- };
- static struct scsi_host_template svia_sht = {
- ATA_BMDMA_SHT(DRV_NAME),
- };
- static struct ata_port_operations svia_base_ops = {
- .inherits = &ata_bmdma_port_ops,
- .sff_tf_load = svia_tf_load,
- };
- static struct ata_port_operations vt6420_sata_ops = {
- .inherits = &svia_base_ops,
- .freeze = svia_noop_freeze,
- .prereset = vt6420_prereset,
- .bmdma_start = vt6420_bmdma_start,
- };
- static struct ata_port_operations vt6421_pata_ops = {
- .inherits = &svia_base_ops,
- .cable_detect = vt6421_pata_cable_detect,
- .set_piomode = vt6421_set_pio_mode,
- .set_dmamode = vt6421_set_dma_mode,
- };
- static struct ata_port_operations vt6421_sata_ops = {
- .inherits = &svia_base_ops,
- .scr_read = svia_scr_read,
- .scr_write = svia_scr_write,
- };
- static struct ata_port_operations vt8251_ops = {
- .inherits = &svia_base_ops,
- .hardreset = sata_std_hardreset,
- .scr_read = vt8251_scr_read,
- .scr_write = vt8251_scr_write,
- };
- static const struct ata_port_info vt6420_port_info = {
- .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
- .pio_mask = ATA_PIO4,
- .mwdma_mask = ATA_MWDMA2,
- .udma_mask = ATA_UDMA6,
- .port_ops = &vt6420_sata_ops,
- };
- static struct ata_port_info vt6421_sport_info = {
- .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
- .pio_mask = ATA_PIO4,
- .mwdma_mask = ATA_MWDMA2,
- .udma_mask = ATA_UDMA6,
- .port_ops = &vt6421_sata_ops,
- };
- static struct ata_port_info vt6421_pport_info = {
- .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY,
- .pio_mask = ATA_PIO4,
- /* No MWDMA */
- .udma_mask = ATA_UDMA6,
- .port_ops = &vt6421_pata_ops,
- };
- static struct ata_port_info vt8251_port_info = {
- .flags = ATA_FLAG_SATA | ATA_FLAG_SLAVE_POSS |
- ATA_FLAG_NO_LEGACY,
- .pio_mask = ATA_PIO4,
- .mwdma_mask = ATA_MWDMA2,
- .udma_mask = ATA_UDMA6,
- .port_ops = &vt8251_ops,
- };
- MODULE_AUTHOR("Jeff Garzik");
- MODULE_DESCRIPTION("SCSI low-level driver for VIA SATA controllers");
- MODULE_LICENSE("GPL");
- MODULE_DEVICE_TABLE(pci, svia_pci_tbl);
- MODULE_VERSION(DRV_VERSION);
- static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
- {
- if (sc_reg > SCR_CONTROL)
- return -EINVAL;
- *val = ioread32(link->ap->ioaddr.scr_addr + (4 * sc_reg));
- return 0;
- }
- static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
- {
- if (sc_reg > SCR_CONTROL)
- return -EINVAL;
- iowrite32(val, link->ap->ioaddr.scr_addr + (4 * sc_reg));
- return 0;
- }
- static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val)
- {
- static const u8 ipm_tbl[] = { 1, 2, 6, 0 };
- struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
- int slot = 2 * link->ap->port_no + link->pmp;
- u32 v = 0;
- u8 raw;
- switch (scr) {
- case SCR_STATUS:
- pci_read_config_byte(pdev, 0xA0 + slot, &raw);
- /* read the DET field, bit0 and 1 of the config byte */
- v |= raw & 0x03;
- /* read the SPD field, bit4 of the configure byte */
- if (raw & (1 << 4))
- v |= 0x02 << 4;
- else
- v |= 0x01 << 4;
- /* read the IPM field, bit2 and 3 of the config byte */
- v |= ipm_tbl[(raw >> 2) & 0x3];
- break;
- case SCR_ERROR:
- /* devices other than 5287 uses 0xA8 as base */
- WARN_ON(pdev->device != 0x5287);
- pci_read_config_dword(pdev, 0xB0 + slot * 4, &v);
- break;
- case SCR_CONTROL:
- pci_read_config_byte(pdev, 0xA4 + slot, &raw);
- /* read the DET field, bit0 and bit1 */
- v |= ((raw & 0x02) << 1) | (raw & 0x01);
- /* read the IPM field, bit2 and bit3 */
- v |= ((raw >> 2) & 0x03) << 8;
- break;
- default:
- return -EINVAL;
-