Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
Alan Cox | ccd32e2 | 2008-11-02 21:40:08 +0100 | [diff] [blame] | 3 | * Copyright (C) 2006 Red Hat |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * May be copied or modified under the terms of the GNU General Public License |
| 6 | */ |
| 7 | |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 8 | #include <linux/types.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/pci.h> |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 11 | #include <linux/ide.h> |
| 12 | #include <linux/init.h> |
| 13 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 14 | #define DRV_NAME "jmicron" |
| 15 | |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 16 | typedef enum { |
| 17 | PORT_PATA0 = 0, |
| 18 | PORT_PATA1 = 1, |
| 19 | PORT_SATA = 2, |
| 20 | } port_type; |
| 21 | |
| 22 | /** |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 23 | * jmicron_cable_detect - cable detection |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 24 | * @hwif: IDE port |
| 25 | * |
Bartlomiej Zolnierkiewicz | 49521f9 | 2007-07-09 23:17:58 +0200 | [diff] [blame] | 26 | * Returns the cable type. |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
Bartlomiej Zolnierkiewicz | f454cbe | 2008-08-05 18:17:04 +0200 | [diff] [blame] | 29 | static u8 jmicron_cable_detect(ide_hwif_t *hwif) |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 30 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 31 | struct pci_dev *pdev = to_pci_dev(hwif->dev); |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 32 | |
| 33 | u32 control; |
| 34 | u32 control5; |
| 35 | |
| 36 | int port = hwif->channel; |
| 37 | port_type port_map[2]; |
| 38 | |
| 39 | pci_read_config_dword(pdev, 0x40, &control); |
| 40 | |
| 41 | /* There are two basic mappings. One has the two SATA ports merged |
| 42 | as master/slave and the secondary as PATA, the other has only the |
| 43 | SATA port mapped */ |
| 44 | if (control & (1 << 23)) { |
| 45 | port_map[0] = PORT_SATA; |
| 46 | port_map[1] = PORT_PATA0; |
| 47 | } else { |
| 48 | port_map[0] = PORT_SATA; |
| 49 | port_map[1] = PORT_SATA; |
| 50 | } |
| 51 | |
| 52 | /* The 365/366 may have this bit set to map the second PATA port |
| 53 | as the internal primary channel */ |
| 54 | pci_read_config_dword(pdev, 0x80, &control5); |
| 55 | if (control5 & (1<<24)) |
| 56 | port_map[0] = PORT_PATA1; |
| 57 | |
| 58 | /* The two ports may then be logically swapped by the firmware */ |
| 59 | if (control & (1 << 22)) |
| 60 | port = port ^ 1; |
| 61 | |
| 62 | /* |
| 63 | * Now we know which physical port we are talking about we can |
| 64 | * actually do our cable checking etc. Thankfully we don't need |
| 65 | * to do the plumbing for other cases. |
| 66 | */ |
Paolo Ciarrocchi | 740694f | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 67 | switch (port_map[port]) { |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 68 | case PORT_PATA0: |
| 69 | if (control & (1 << 3)) /* 40/80 pin primary */ |
Bartlomiej Zolnierkiewicz | 49521f9 | 2007-07-09 23:17:58 +0200 | [diff] [blame] | 70 | return ATA_CBL_PATA40; |
| 71 | return ATA_CBL_PATA80; |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 72 | case PORT_PATA1: |
| 73 | if (control5 & (1 << 19)) /* 40/80 pin secondary */ |
Bartlomiej Zolnierkiewicz | 49521f9 | 2007-07-09 23:17:58 +0200 | [diff] [blame] | 74 | return ATA_CBL_PATA40; |
| 75 | return ATA_CBL_PATA80; |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 76 | case PORT_SATA: |
Andrew Morton | a51545a | 2007-01-27 13:46:21 +0100 | [diff] [blame] | 77 | break; |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 78 | } |
Bartlomiej Zolnierkiewicz | 49521f9 | 2007-07-09 23:17:58 +0200 | [diff] [blame] | 79 | /* Avoid bogus "control reaches end of non-void function" */ |
| 80 | return ATA_CBL_PATA80; |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 83 | static void jmicron_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 84 | { |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /** |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 88 | * jmicron_set_dma_mode - set host controller for DMA mode |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 89 | * @hwif: port |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 90 | * @drive: drive |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 91 | * |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 92 | * As the JMicron snoops for timings we don't need to do anything here. |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 93 | */ |
| 94 | |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 95 | static void jmicron_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 96 | { |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 99 | static const struct ide_port_ops jmicron_port_ops = { |
| 100 | .set_pio_mode = jmicron_set_pio_mode, |
| 101 | .set_dma_mode = jmicron_set_dma_mode, |
| 102 | .cable_detect = jmicron_cable_detect, |
| 103 | }; |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 104 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 105 | static const struct ide_port_info jmicron_chipset = { |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 106 | .name = DRV_NAME, |
Tejun Heo | bda7970 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 107 | .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } }, |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 108 | .port_ops = &jmicron_port_ops, |
Tejun Heo | bda7970 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 109 | .pio_mask = ATA_PIO5, |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 110 | .mwdma_mask = ATA_MWDMA2, |
| 111 | .udma_mask = ATA_UDMA6, |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /** |
| 115 | * jmicron_init_one - pci layer discovery entry |
| 116 | * @dev: PCI device |
| 117 | * @id: ident table entry |
| 118 | * |
| 119 | * Called by the PCI code when it finds a Jmicron controller. |
| 120 | * We then use the IDE PCI generic helper to do most of the work. |
| 121 | */ |
| 122 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 123 | static int jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 124 | { |
Bartlomiej Zolnierkiewicz | 6cdf6eb | 2008-07-24 22:53:14 +0200 | [diff] [blame] | 125 | return ide_pci_init_one(dev, &jmicron_chipset, NULL); |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Tejun Heo | bda7970 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 128 | /* All JMB PATA controllers have and will continue to have the same |
| 129 | * interface. Matching vendor and device class is enough for all |
| 130 | * current and future controllers if the controller is programmed |
| 131 | * properly. |
| 132 | * |
| 133 | * If libata is configured, jmicron PCI quirk programs the controller |
| 134 | * into the correct mode. If libata isn't configured, match known |
| 135 | * device IDs too to maintain backward compatibility. |
Tejun Heo | ebbc203 | 2007-03-17 21:57:25 +0100 | [diff] [blame] | 136 | */ |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 137 | static struct pci_device_id jmicron_pci_tbl[] = { |
Tejun Heo | bda7970 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 138 | #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE) |
| 139 | { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) }, |
| 140 | { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) }, |
| 141 | { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) }, |
| 142 | { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) }, |
| 143 | { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) }, |
| 144 | #endif |
| 145 | { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 146 | PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 }, |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 147 | { 0, }, |
| 148 | }; |
| 149 | |
| 150 | MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); |
| 151 | |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 152 | static struct pci_driver jmicron_pci_driver = { |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 153 | .name = "JMicron IDE", |
| 154 | .id_table = jmicron_pci_tbl, |
| 155 | .probe = jmicron_init_one, |
Bartlomiej Zolnierkiewicz | 1bcaaba | 2008-07-24 22:53:22 +0200 | [diff] [blame] | 156 | .remove = ide_pci_remove, |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 157 | .suspend = ide_pci_suspend, |
| 158 | .resume = ide_pci_resume, |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | static int __init jmicron_ide_init(void) |
| 162 | { |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 163 | return ide_pci_register_driver(&jmicron_pci_driver); |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Bartlomiej Zolnierkiewicz | 1bcaaba | 2008-07-24 22:53:22 +0200 | [diff] [blame] | 166 | static void __exit jmicron_ide_exit(void) |
| 167 | { |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 168 | pci_unregister_driver(&jmicron_pci_driver); |
Bartlomiej Zolnierkiewicz | 1bcaaba | 2008-07-24 22:53:22 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 171 | module_init(jmicron_ide_init); |
Bartlomiej Zolnierkiewicz | 1bcaaba | 2008-07-24 22:53:22 +0200 | [diff] [blame] | 172 | module_exit(jmicron_ide_exit); |
Alan Cox | bbb3bbd | 2006-10-03 01:14:12 -0700 | [diff] [blame] | 173 | |
| 174 | MODULE_AUTHOR("Alan Cox"); |
| 175 | MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes"); |
| 176 | MODULE_LICENSE("GPL"); |