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 | * |
| 7 | * (c) 2006 Red Hat <alan@redhat.com> |
| 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" |
Alan | d39ca89 | 2006-11-22 17:18:30 +0000 | [diff] [blame] | 22 | #define DRV_VERSION "0.1.4" |
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 |
| 32 | * @ap: Port |
| 33 | * |
| 34 | * Perform the PATA port setup we need. |
| 35 | |
| 36 | * On the Jmicron 361/363 there is a single PATA port that can be mapped |
| 37 | * either as primary or secondary (or neither). We don't do any policy |
| 38 | * and setup here. We assume that has been done by init_one and the |
| 39 | * BIOS. |
| 40 | */ |
| 41 | |
| 42 | static int jmicron_pre_reset(struct ata_port *ap) |
| 43 | { |
| 44 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 45 | u32 control; |
| 46 | u32 control5; |
| 47 | int port_mask = 1<< (4 * ap->port_no); |
| 48 | int port = ap->port_no; |
| 49 | port_type port_map[2]; |
| 50 | |
| 51 | /* Check if our port is enabled */ |
| 52 | pci_read_config_dword(pdev, 0x40, &control); |
| 53 | if ((control & port_mask) == 0) |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 54 | return -ENOENT; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 55 | |
| 56 | /* There are two basic mappings. One has the two SATA ports merged |
| 57 | as master/slave and the secondary as PATA, the other has only the |
| 58 | SATA port mapped */ |
| 59 | if (control & (1 << 23)) { |
| 60 | port_map[0] = PORT_SATA; |
| 61 | port_map[1] = PORT_PATA0; |
| 62 | } else { |
| 63 | port_map[0] = PORT_SATA; |
| 64 | port_map[1] = PORT_SATA; |
| 65 | } |
| 66 | |
| 67 | /* The 365/366 may have this bit set to map the second PATA port |
| 68 | as the internal primary channel */ |
| 69 | pci_read_config_dword(pdev, 0x80, &control5); |
| 70 | if (control5 & (1<<24)) |
| 71 | port_map[0] = PORT_PATA1; |
| 72 | |
| 73 | /* The two ports may then be logically swapped by the firmware */ |
| 74 | if (control & (1 << 22)) |
| 75 | port = port ^ 1; |
| 76 | |
| 77 | /* |
| 78 | * Now we know which physical port we are talking about we can |
| 79 | * actually do our cable checking etc. Thankfully we don't need |
| 80 | * to do the plumbing for other cases. |
| 81 | */ |
| 82 | switch (port_map[port]) |
| 83 | { |
| 84 | case PORT_PATA0: |
| 85 | if (control & (1 << 5)) |
| 86 | return 0; |
| 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) |
| 95 | return 0; |
| 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 | } |
| 105 | return ata_std_prereset(ap); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * jmicron_error_handler - Setup and error handler |
| 110 | * @ap: Port to handle |
| 111 | * |
| 112 | * LOCKING: |
| 113 | * None (inherited from caller). |
| 114 | */ |
| 115 | |
| 116 | static void jmicron_error_handler(struct ata_port *ap) |
| 117 | { |
| 118 | return ata_bmdma_drive_eh(ap, jmicron_pre_reset, ata_std_softreset, NULL, ata_std_postreset); |
| 119 | } |
| 120 | |
| 121 | /* No PIO or DMA methods needed for this device */ |
| 122 | |
| 123 | static struct scsi_host_template jmicron_sht = { |
| 124 | .module = THIS_MODULE, |
| 125 | .name = DRV_NAME, |
| 126 | .ioctl = ata_scsi_ioctl, |
| 127 | .queuecommand = ata_scsi_queuecmd, |
| 128 | .can_queue = ATA_DEF_QUEUE, |
| 129 | .this_id = ATA_SHT_THIS_ID, |
| 130 | .sg_tablesize = LIBATA_MAX_PRD, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 131 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
| 132 | .emulated = ATA_SHT_EMULATED, |
| 133 | .use_clustering = ATA_SHT_USE_CLUSTERING, |
| 134 | .proc_name = DRV_NAME, |
| 135 | .dma_boundary = ATA_DMA_BOUNDARY, |
| 136 | .slave_configure = ata_scsi_slave_config, |
Tejun Heo | afdfe89 | 2006-11-29 11:26:47 +0900 | [diff] [blame] | 137 | .slave_destroy = ata_scsi_slave_destroy, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 138 | /* Use standard CHS mapping rules */ |
| 139 | .bios_param = ata_std_bios_param, |
Tejun Heo | b23ff24 | 2007-03-02 17:30:01 +0900 | [diff] [blame] | 140 | #ifdef CONFIG_PM |
| 141 | .suspend = ata_scsi_device_suspend, |
| 142 | .resume = ata_scsi_device_resume, |
| 143 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | static const struct ata_port_operations jmicron_ops = { |
| 147 | .port_disable = ata_port_disable, |
| 148 | |
| 149 | /* Task file is PCI ATA format, use helpers */ |
| 150 | .tf_load = ata_tf_load, |
| 151 | .tf_read = ata_tf_read, |
| 152 | .check_status = ata_check_status, |
| 153 | .exec_command = ata_exec_command, |
| 154 | .dev_select = ata_std_dev_select, |
| 155 | |
| 156 | .freeze = ata_bmdma_freeze, |
| 157 | .thaw = ata_bmdma_thaw, |
| 158 | .error_handler = jmicron_error_handler, |
| 159 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
| 160 | |
| 161 | /* BMDMA handling is PCI ATA format, use helpers */ |
| 162 | .bmdma_setup = ata_bmdma_setup, |
| 163 | .bmdma_start = ata_bmdma_start, |
| 164 | .bmdma_stop = ata_bmdma_stop, |
| 165 | .bmdma_status = ata_bmdma_status, |
| 166 | .qc_prep = ata_qc_prep, |
| 167 | .qc_issue = ata_qc_issue_prot, |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 168 | .data_xfer = ata_data_xfer, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 169 | |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 170 | /* IRQ-related hooks */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 171 | .irq_handler = ata_interrupt, |
| 172 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 173 | .irq_on = ata_irq_on, |
| 174 | .irq_ack = ata_irq_ack, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 175 | |
| 176 | /* Generic PATA PCI ATA helpers */ |
| 177 | .port_start = ata_port_start, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | |
| 181 | /** |
| 182 | * jmicron_init_one - Register Jmicron ATA PCI device with kernel services |
| 183 | * @pdev: PCI device to register |
| 184 | * @ent: Entry in jmicron_pci_tbl matching with @pdev |
| 185 | * |
| 186 | * Called from kernel PCI layer. |
| 187 | * |
| 188 | * LOCKING: |
| 189 | * Inherited from PCI layer (may sleep). |
| 190 | * |
| 191 | * RETURNS: |
| 192 | * Zero on success, or -ERRNO value. |
| 193 | */ |
| 194 | |
| 195 | static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id) |
| 196 | { |
| 197 | static struct ata_port_info info = { |
| 198 | .sht = &jmicron_sht, |
| 199 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, |
| 200 | |
| 201 | .pio_mask = 0x1f, |
| 202 | .mwdma_mask = 0x07, |
| 203 | .udma_mask = 0x3f, |
| 204 | |
| 205 | .port_ops = &jmicron_ops, |
| 206 | }; |
| 207 | struct ata_port_info *port_info[2] = { &info, &info }; |
| 208 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 209 | return ata_pci_init_one(pdev, port_info, 2); |
| 210 | } |
| 211 | |
| 212 | static const struct pci_device_id jmicron_pci_tbl[] = { |
Tejun Heo | e34bb37 | 2007-02-26 20:24:03 +0900 | [diff] [blame] | 213 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, |
| 214 | PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 361 }, |
| 215 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, |
| 216 | PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 363 }, |
| 217 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, |
| 218 | PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 365 }, |
| 219 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, |
| 220 | PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 366 }, |
| 221 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, |
| 222 | PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 368 }, |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 223 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 224 | { } /* terminate list */ |
| 225 | }; |
| 226 | |
| 227 | static struct pci_driver jmicron_pci_driver = { |
| 228 | .name = DRV_NAME, |
| 229 | .id_table = jmicron_pci_tbl, |
| 230 | .probe = jmicron_init_one, |
| 231 | .remove = ata_pci_remove_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 232 | #ifdef CONFIG_PM |
Alan | d39ca89 | 2006-11-22 17:18:30 +0000 | [diff] [blame] | 233 | .suspend = ata_pci_device_suspend, |
Tejun Heo | 960627b | 2007-02-26 20:09:02 +0900 | [diff] [blame] | 234 | .resume = ata_pci_device_resume, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 235 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | static int __init jmicron_init(void) |
| 239 | { |
| 240 | return pci_register_driver(&jmicron_pci_driver); |
| 241 | } |
| 242 | |
| 243 | static void __exit jmicron_exit(void) |
| 244 | { |
| 245 | pci_unregister_driver(&jmicron_pci_driver); |
| 246 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 247 | |
| 248 | module_init(jmicron_init); |
| 249 | module_exit(jmicron_exit); |
| 250 | |
| 251 | MODULE_AUTHOR("Alan Cox"); |
| 252 | MODULE_DESCRIPTION("SCSI low-level driver for Jmicron PATA ports"); |
| 253 | MODULE_LICENSE("GPL"); |
| 254 | MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); |
| 255 | MODULE_VERSION(DRV_VERSION); |
| 256 | |