Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  Marvell PATA driver.
0004  *
0005  *  For the moment we drive the PATA port in legacy mode. That
0006  *  isn't making full use of the device functionality but it is
0007  *  easy to get working.
0008  *
0009  *  (c) 2006 Red Hat
0010  */
0011 
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/pci.h>
0015 #include <linux/blkdev.h>
0016 #include <linux/delay.h>
0017 #include <linux/device.h>
0018 #include <scsi/scsi_host.h>
0019 #include <linux/libata.h>
0020 #include <linux/ata.h>
0021 
0022 #define DRV_NAME    "pata_marvell"
0023 #define DRV_VERSION "0.1.6"
0024 
0025 /**
0026  *  marvell_pata_active -   check if PATA is active
0027  *  @pdev: PCI device
0028  *
0029  *  Returns 1 if the PATA port may be active. We know how to check this
0030  *  for the 6145 but not the other devices
0031  */
0032 
0033 static int marvell_pata_active(struct pci_dev *pdev)
0034 {
0035     u32 devices;
0036     void __iomem *barp;
0037 
0038     /* We don't yet know how to do this for other devices */
0039     if (pdev->device != 0x6145)
0040         return 1;
0041 
0042     barp = pci_iomap(pdev, 5, 0x10);
0043     if (barp == NULL)
0044         return -ENOMEM;
0045 
0046     devices = ioread32(barp + 0x0C);
0047     pci_iounmap(pdev, barp);
0048 
0049     if (devices & 0x10)
0050         return 1;
0051     return 0;
0052 }
0053 
0054 /**
0055  *  marvell_pre_reset   -   probe begin
0056  *  @link: link
0057  *  @deadline: deadline jiffies for the operation
0058  *
0059  *  Perform the PATA port setup we need.
0060  */
0061 
0062 static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
0063 {
0064     struct ata_port *ap = link->ap;
0065     struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0066 
0067     if (pdev->device == 0x6145 && ap->port_no == 0 &&
0068         !marvell_pata_active(pdev)) /* PATA enable ? */
0069             return -ENOENT;
0070 
0071     return ata_sff_prereset(link, deadline);
0072 }
0073 
0074 static int marvell_cable_detect(struct ata_port *ap)
0075 {
0076     /* Cable type */
0077     switch(ap->port_no)
0078     {
0079     case 0:
0080         if (!ap->ioaddr.bmdma_addr)
0081             return ATA_CBL_PATA_UNK;
0082         if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
0083             return ATA_CBL_PATA40;
0084         return ATA_CBL_PATA80;
0085     case 1: /* Legacy SATA port */
0086         return ATA_CBL_SATA;
0087     }
0088 
0089     BUG();
0090     return 0;   /* Our BUG macro needs the right markup */
0091 }
0092 
0093 /* No PIO or DMA methods needed for this device */
0094 
0095 static struct scsi_host_template marvell_sht = {
0096     ATA_BMDMA_SHT(DRV_NAME),
0097 };
0098 
0099 static struct ata_port_operations marvell_ops = {
0100     .inherits       = &ata_bmdma_port_ops,
0101     .cable_detect       = marvell_cable_detect,
0102     .prereset       = marvell_pre_reset,
0103 };
0104 
0105 
0106 /**
0107  *  marvell_init_one - Register Marvell ATA PCI device with kernel services
0108  *  @pdev: PCI device to register
0109  *  @id: PCI device ID
0110  *
0111  *  Called from kernel PCI layer.
0112  *
0113  *  LOCKING:
0114  *  Inherited from PCI layer (may sleep).
0115  *
0116  *  RETURNS:
0117  *  Zero on success, or -ERRNO value.
0118  */
0119 
0120 static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
0121 {
0122     static const struct ata_port_info info = {
0123         .flags      = ATA_FLAG_SLAVE_POSS,
0124 
0125         .pio_mask   = ATA_PIO4,
0126         .mwdma_mask = ATA_MWDMA2,
0127         .udma_mask  = ATA_UDMA5,
0128 
0129         .port_ops   = &marvell_ops,
0130     };
0131     static const struct ata_port_info info_sata = {
0132         /* Slave possible as its magically mapped not real */
0133         .flags      = ATA_FLAG_SLAVE_POSS,
0134 
0135         .pio_mask   = ATA_PIO4,
0136         .mwdma_mask = ATA_MWDMA2,
0137         .udma_mask  = ATA_UDMA6,
0138 
0139         .port_ops   = &marvell_ops,
0140     };
0141     const struct ata_port_info *ppi[] = { &info, &info_sata };
0142 
0143     if (pdev->device == 0x6101)
0144         ppi[1] = &ata_dummy_port_info;
0145 
0146 #if IS_ENABLED(CONFIG_SATA_AHCI)
0147     if (!marvell_pata_active(pdev)) {
0148         dev_info(&pdev->dev,
0149              "PATA port not active, deferring to AHCI driver.\n");
0150         return -ENODEV;
0151     }
0152 #endif
0153     return ata_pci_bmdma_init_one(pdev, ppi, &marvell_sht, NULL, 0);
0154 }
0155 
0156 static const struct pci_device_id marvell_pci_tbl[] = {
0157     { PCI_DEVICE(0x11AB, 0x6101), },
0158     { PCI_DEVICE(0x11AB, 0x6121), },
0159     { PCI_DEVICE(0x11AB, 0x6123), },
0160     { PCI_DEVICE(0x11AB, 0x6145), },
0161     { PCI_DEVICE(0x1B4B, 0x91A0), },
0162     { PCI_DEVICE(0x1B4B, 0x91A4), },
0163 
0164     { } /* terminate list */
0165 };
0166 
0167 static struct pci_driver marvell_pci_driver = {
0168     .name           = DRV_NAME,
0169     .id_table       = marvell_pci_tbl,
0170     .probe          = marvell_init_one,
0171     .remove         = ata_pci_remove_one,
0172 #ifdef CONFIG_PM_SLEEP
0173     .suspend        = ata_pci_device_suspend,
0174     .resume         = ata_pci_device_resume,
0175 #endif
0176 };
0177 
0178 module_pci_driver(marvell_pci_driver);
0179 
0180 MODULE_AUTHOR("Alan Cox");
0181 MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
0182 MODULE_LICENSE("GPL");
0183 MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
0184 MODULE_VERSION(DRV_VERSION);