Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * pata_jmicron.c - JMicron ATA driver for non AHCI mode. This drives the |
| 3 | * PATA port of the controller. The SATA ports are |
| 4 | * driven by AHCI in the usual configuration although |
| 5 | * this driver can handle other setups if we need it. |
| 6 | * |
Alan Cox | ab77163 | 2008-10-27 15:09:10 +0000 | [diff] [blame] | 7 | * (c) 2006 Red Hat |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/pci.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/blkdev.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <scsi/scsi_host.h> |
| 18 | #include <linux/libata.h> |
| 19 | #include <linux/ata.h> |
| 20 | |
| 21 | #define DRV_NAME "pata_jmicron" |
Jeff Garzik | 8bc3fc4 | 2007-05-21 20:26:38 -0400 | [diff] [blame] | 22 | #define DRV_VERSION "0.1.5" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 23 | |
| 24 | typedef enum { |
| 25 | PORT_PATA0 = 0, |
| 26 | PORT_PATA1 = 1, |
| 27 | PORT_SATA = 2, |
| 28 | } port_type; |
| 29 | |
| 30 | /** |
| 31 | * jmicron_pre_reset - check for 40/80 pin |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 32 | * @link: ATA link |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 33 | * @deadline: deadline jiffies for the operation |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 34 | * |
| 35 | * Perform the PATA port setup we need. |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 36 | * |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 37 | * On the Jmicron 361/363 there is a single PATA port that can be mapped |
| 38 | * either as primary or secondary (or neither). We don't do any policy |
| 39 | * and setup here. We assume that has been done by init_one and the |
| 40 | * BIOS. |
| 41 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 42 | static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 43 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 44 | struct ata_port *ap = link->ap; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 45 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 46 | u32 control; |
| 47 | u32 control5; |
| 48 | int port_mask = 1<< (4 * ap->port_no); |
| 49 | int port = ap->port_no; |
| 50 | port_type port_map[2]; |
| 51 | |
| 52 | /* Check if our port is enabled */ |
| 53 | pci_read_config_dword(pdev, 0x40, &control); |
| 54 | if ((control & port_mask) == 0) |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 55 | return -ENOENT; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 56 | |
| 57 | /* There are two basic mappings. One has the two SATA ports merged |
| 58 | as master/slave and the secondary as PATA, the other has only the |
| 59 | SATA port mapped */ |
| 60 | if (control & (1 << 23)) { |
| 61 | port_map[0] = PORT_SATA; |
| 62 | port_map[1] = PORT_PATA0; |
| 63 | } else { |
| 64 | port_map[0] = PORT_SATA; |
| 65 | port_map[1] = PORT_SATA; |
| 66 | } |
| 67 | |
| 68 | /* The 365/366 may have this bit set to map the second PATA port |
| 69 | as the internal primary channel */ |
| 70 | pci_read_config_dword(pdev, 0x80, &control5); |
| 71 | if (control5 & (1<<24)) |
| 72 | port_map[0] = PORT_PATA1; |
| 73 | |
| 74 | /* The two ports may then be logically swapped by the firmware */ |
| 75 | if (control & (1 << 22)) |
| 76 | port = port ^ 1; |
| 77 | |
| 78 | /* |
| 79 | * Now we know which physical port we are talking about we can |
| 80 | * actually do our cable checking etc. Thankfully we don't need |
| 81 | * to do the plumbing for other cases. |
| 82 | */ |
Tejun Heo | 0706efd | 2007-11-19 18:06:11 +0900 | [diff] [blame] | 83 | switch (port_map[port]) { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 84 | case PORT_PATA0: |
Tejun Heo | 0706efd | 2007-11-19 18:06:11 +0900 | [diff] [blame] | 85 | if ((control & (1 << 5)) == 0) |
| 86 | return -ENOENT; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 87 | if (control & (1 << 3)) /* 40/80 pin primary */ |
| 88 | ap->cbl = ATA_CBL_PATA40; |
| 89 | else |
| 90 | ap->cbl = ATA_CBL_PATA80; |
| 91 | break; |
| 92 | case PORT_PATA1: |
| 93 | /* Bit 21 is set if the port is enabled */ |
| 94 | if ((control5 & (1 << 21)) == 0) |
Tejun Heo | 0706efd | 2007-11-19 18:06:11 +0900 | [diff] [blame] | 95 | return -ENOENT; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 96 | if (control5 & (1 << 19)) /* 40/80 pin secondary */ |
| 97 | ap->cbl = ATA_CBL_PATA40; |
| 98 | else |
| 99 | ap->cbl = ATA_CBL_PATA80; |
| 100 | break; |
| 101 | case PORT_SATA: |
| 102 | ap->cbl = ATA_CBL_SATA; |
| 103 | break; |
| 104 | } |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 105 | return ata_sff_prereset(link, deadline); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 108 | /* No PIO or DMA methods needed for this device */ |
| 109 | |
| 110 | static struct scsi_host_template jmicron_sht = { |
Tejun Heo | 68d1d07 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 111 | ATA_BMDMA_SHT(DRV_NAME), |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 112 | }; |
| 113 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 114 | static struct ata_port_operations jmicron_ops = { |
| 115 | .inherits = &ata_bmdma_port_ops, |
Tejun Heo | 887125e | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 116 | .prereset = jmicron_pre_reset, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * jmicron_init_one - Register Jmicron ATA PCI device with kernel services |
| 122 | * @pdev: PCI device to register |
| 123 | * @ent: Entry in jmicron_pci_tbl matching with @pdev |
| 124 | * |
| 125 | * Called from kernel PCI layer. |
| 126 | * |
| 127 | * LOCKING: |
| 128 | * Inherited from PCI layer (may sleep). |
| 129 | * |
| 130 | * RETURNS: |
| 131 | * Zero on success, or -ERRNO value. |
| 132 | */ |
| 133 | |
| 134 | static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id) |
| 135 | { |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 136 | static const struct ata_port_info info = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 137 | .flags = ATA_FLAG_SLAVE_POSS, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 138 | |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 139 | .pio_mask = ATA_PIO4, |
| 140 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 141 | .udma_mask = ATA_UDMA5, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 142 | |
| 143 | .port_ops = &jmicron_ops, |
| 144 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 145 | const struct ata_port_info *ppi[] = { &info, NULL }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 146 | |
Alan Cox | 16ea0fc | 2010-02-23 02:26:06 -0500 | [diff] [blame] | 147 | return ata_pci_sff_init_one(pdev, ppi, &jmicron_sht, NULL, 0); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static const struct pci_device_id jmicron_pci_tbl[] = { |
Tejun Heo | a01f48b | 2007-10-07 07:04:50 +0900 | [diff] [blame] | 151 | { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 152 | PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 }, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 153 | { } /* terminate list */ |
| 154 | }; |
| 155 | |
| 156 | static struct pci_driver jmicron_pci_driver = { |
| 157 | .name = DRV_NAME, |
| 158 | .id_table = jmicron_pci_tbl, |
| 159 | .probe = jmicron_init_one, |
| 160 | .remove = ata_pci_remove_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 161 | #ifdef CONFIG_PM |
Alan | d39ca89 | 2006-11-22 17:18:30 +0000 | [diff] [blame] | 162 | .suspend = ata_pci_device_suspend, |
Tejun Heo | 960627b | 2007-02-26 20:09:02 +0900 | [diff] [blame] | 163 | .resume = ata_pci_device_resume, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 164 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | static int __init jmicron_init(void) |
| 168 | { |
| 169 | return pci_register_driver(&jmicron_pci_driver); |
| 170 | } |
| 171 | |
| 172 | static void __exit jmicron_exit(void) |
| 173 | { |
| 174 | pci_unregister_driver(&jmicron_pci_driver); |
| 175 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 176 | |
| 177 | module_init(jmicron_init); |
| 178 | module_exit(jmicron_exit); |
| 179 | |
| 180 | MODULE_AUTHOR("Alan Cox"); |
| 181 | MODULE_DESCRIPTION("SCSI low-level driver for Jmicron PATA ports"); |
| 182 | MODULE_LICENSE("GPL"); |
| 183 | MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); |
| 184 | MODULE_VERSION(DRV_VERSION); |
| 185 | |