cciss: change the way we notify scsi midlayer of tape drives
[linux-2.6/mini2440.git] / drivers / ide / pci / jmicron.c
blobbb9d09d8f1960a564941bed0f5b87238f60a50d1
2 /*
3 * Copyright (C) 2006 Red Hat <alan@redhat.com>
5 * May be copied or modified under the terms of the GNU General Public License
6 */
8 #include <linux/types.h>
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/hdreg.h>
12 #include <linux/ide.h>
13 #include <linux/init.h>
15 #define DRV_NAME "jmicron"
17 typedef enum {
18 PORT_PATA0 = 0,
19 PORT_PATA1 = 1,
20 PORT_SATA = 2,
21 } port_type;
23 /**
24 * jmicron_cable_detect - cable detection
25 * @hwif: IDE port
27 * Returns the cable type.
30 static u8 jmicron_cable_detect(ide_hwif_t *hwif)
32 struct pci_dev *pdev = to_pci_dev(hwif->dev);
34 u32 control;
35 u32 control5;
37 int port = hwif->channel;
38 port_type port_map[2];
40 pci_read_config_dword(pdev, 0x40, &control);
42 /* There are two basic mappings. One has the two SATA ports merged
43 as master/slave and the secondary as PATA, the other has only the
44 SATA port mapped */
45 if (control & (1 << 23)) {
46 port_map[0] = PORT_SATA;
47 port_map[1] = PORT_PATA0;
48 } else {
49 port_map[0] = PORT_SATA;
50 port_map[1] = PORT_SATA;
53 /* The 365/366 may have this bit set to map the second PATA port
54 as the internal primary channel */
55 pci_read_config_dword(pdev, 0x80, &control5);
56 if (control5 & (1<<24))
57 port_map[0] = PORT_PATA1;
59 /* The two ports may then be logically swapped by the firmware */
60 if (control & (1 << 22))
61 port = port ^ 1;
64 * Now we know which physical port we are talking about we can
65 * actually do our cable checking etc. Thankfully we don't need
66 * to do the plumbing for other cases.
68 switch (port_map[port]) {
69 case PORT_PATA0:
70 if (control & (1 << 3)) /* 40/80 pin primary */
71 return ATA_CBL_PATA40;
72 return ATA_CBL_PATA80;
73 case PORT_PATA1:
74 if (control5 & (1 << 19)) /* 40/80 pin secondary */
75 return ATA_CBL_PATA40;
76 return ATA_CBL_PATA80;
77 case PORT_SATA:
78 break;
80 /* Avoid bogus "control reaches end of non-void function" */
81 return ATA_CBL_PATA80;
84 static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
88 /**
89 * jmicron_set_dma_mode - set host controller for DMA mode
90 * @drive: drive
91 * @mode: DMA mode
93 * As the JMicron snoops for timings we don't need to do anything here.
96 static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
100 static const struct ide_port_ops jmicron_port_ops = {
101 .set_pio_mode = jmicron_set_pio_mode,
102 .set_dma_mode = jmicron_set_dma_mode,
103 .cable_detect = jmicron_cable_detect,
106 static const struct ide_port_info jmicron_chipset __devinitdata = {
107 .name = DRV_NAME,
108 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
109 .port_ops = &jmicron_port_ops,
110 .pio_mask = ATA_PIO5,
111 .mwdma_mask = ATA_MWDMA2,
112 .udma_mask = ATA_UDMA6,
116 * jmicron_init_one - pci layer discovery entry
117 * @dev: PCI device
118 * @id: ident table entry
120 * Called by the PCI code when it finds a Jmicron controller.
121 * We then use the IDE PCI generic helper to do most of the work.
124 static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
126 return ide_pci_init_one(dev, &jmicron_chipset, NULL);
129 /* All JMB PATA controllers have and will continue to have the same
130 * interface. Matching vendor and device class is enough for all
131 * current and future controllers if the controller is programmed
132 * properly.
134 * If libata is configured, jmicron PCI quirk programs the controller
135 * into the correct mode. If libata isn't configured, match known
136 * device IDs too to maintain backward compatibility.
138 static struct pci_device_id jmicron_pci_tbl[] = {
139 #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
140 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
141 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
142 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
143 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
144 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
145 #endif
146 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
147 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
148 { 0, },
151 MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
153 static struct pci_driver driver = {
154 .name = "JMicron IDE",
155 .id_table = jmicron_pci_tbl,
156 .probe = jmicron_init_one,
157 .remove = ide_pci_remove,
160 static int __init jmicron_ide_init(void)
162 return ide_pci_register_driver(&driver);
165 static void __exit jmicron_ide_exit(void)
167 pci_unregister_driver(&driver);
170 module_init(jmicron_ide_init);
171 module_exit(jmicron_ide_exit);
173 MODULE_AUTHOR("Alan Cox");
174 MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
175 MODULE_LICENSE("GPL");