Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2003 ATI Inc. <hyu@ati.com> |
Bartlomiej Zolnierkiewicz | 485efc6 | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 3 | * Copyright (C) 2004,2007 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/types.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/ide.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 13 | #define DRV_NAME "atiixp" |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #define ATIIXP_IDE_PIO_TIMING 0x40 |
| 16 | #define ATIIXP_IDE_MDMA_TIMING 0x44 |
| 17 | #define ATIIXP_IDE_PIO_CONTROL 0x48 |
| 18 | #define ATIIXP_IDE_PIO_MODE 0x4a |
| 19 | #define ATIIXP_IDE_UDMA_CONTROL 0x54 |
| 20 | #define ATIIXP_IDE_UDMA_MODE 0x56 |
| 21 | |
| 22 | typedef struct { |
| 23 | u8 command_width; |
| 24 | u8 recover_width; |
| 25 | } atiixp_ide_timing; |
| 26 | |
| 27 | static atiixp_ide_timing pio_timing[] = { |
| 28 | { 0x05, 0x0d }, |
| 29 | { 0x04, 0x07 }, |
| 30 | { 0x03, 0x04 }, |
| 31 | { 0x02, 0x02 }, |
| 32 | { 0x02, 0x00 }, |
| 33 | }; |
| 34 | |
| 35 | static atiixp_ide_timing mdma_timing[] = { |
| 36 | { 0x07, 0x07 }, |
| 37 | { 0x02, 0x01 }, |
| 38 | { 0x02, 0x00 }, |
| 39 | }; |
| 40 | |
Alan | 6c5f8cc | 2007-01-05 16:36:27 -0800 | [diff] [blame] | 41 | static DEFINE_SPINLOCK(atiixp_lock); |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /** |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 44 | * atiixp_set_pio_mode - set host controller for PIO mode |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 45 | * @hwif: port |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 46 | * @drive: drive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * |
| 48 | * Set the interface PIO mode. |
| 49 | */ |
| 50 | |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 51 | static void atiixp_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 53 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | unsigned long flags; |
Roel Kluin | f76bee1 | 2009-02-25 20:28:22 +0100 | [diff] [blame] | 55 | int timing_shift = (drive->dn ^ 1) * 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | u32 pio_timing_data; |
| 57 | u16 pio_mode_data; |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 58 | const u8 pio = drive->pio_mode - XFER_PIO_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Alan | 6c5f8cc | 2007-01-05 16:36:27 -0800 | [diff] [blame] | 60 | spin_lock_irqsave(&atiixp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | pci_read_config_word(dev, ATIIXP_IDE_PIO_MODE, &pio_mode_data); |
| 63 | pio_mode_data &= ~(0x07 << (drive->dn * 4)); |
| 64 | pio_mode_data |= (pio << (drive->dn * 4)); |
| 65 | pci_write_config_word(dev, ATIIXP_IDE_PIO_MODE, pio_mode_data); |
| 66 | |
| 67 | pci_read_config_dword(dev, ATIIXP_IDE_PIO_TIMING, &pio_timing_data); |
| 68 | pio_timing_data &= ~(0xff << timing_shift); |
| 69 | pio_timing_data |= (pio_timing[pio].recover_width << timing_shift) | |
| 70 | (pio_timing[pio].command_width << (timing_shift + 4)); |
| 71 | pci_write_config_dword(dev, ATIIXP_IDE_PIO_TIMING, pio_timing_data); |
| 72 | |
Alan | 6c5f8cc | 2007-01-05 16:36:27 -0800 | [diff] [blame] | 73 | spin_unlock_irqrestore(&atiixp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 77 | * atiixp_set_dma_mode - set host controller for DMA mode |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 78 | * @hwif: port |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 79 | * @drive: drive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 81 | * Set a ATIIXP host controller to the desired DMA mode. This involves |
| 82 | * programming the right timing data into the PCI configuration space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | */ |
| 84 | |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 85 | static void atiixp_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 87 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | unsigned long flags; |
Roel Kluin | f76bee1 | 2009-02-25 20:28:22 +0100 | [diff] [blame] | 89 | int timing_shift = (drive->dn ^ 1) * 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | u32 tmp32; |
| 91 | u16 tmp16; |
Bartlomiej Zolnierkiewicz | 8ae60e3 | 2008-01-26 20:13:02 +0100 | [diff] [blame] | 92 | u16 udma_ctl = 0; |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 93 | const u8 speed = drive->dma_mode; |
Bartlomiej Zolnierkiewicz | 94c7fa0 | 2007-10-16 22:29:53 +0200 | [diff] [blame] | 94 | |
Alan | 6c5f8cc | 2007-01-05 16:36:27 -0800 | [diff] [blame] | 95 | spin_lock_irqsave(&atiixp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Bartlomiej Zolnierkiewicz | 8ae60e3 | 2008-01-26 20:13:02 +0100 | [diff] [blame] | 97 | pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &udma_ctl); |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (speed >= XFER_UDMA_0) { |
| 100 | pci_read_config_word(dev, ATIIXP_IDE_UDMA_MODE, &tmp16); |
| 101 | tmp16 &= ~(0x07 << (drive->dn * 4)); |
| 102 | tmp16 |= ((speed & 0x07) << (drive->dn * 4)); |
| 103 | pci_write_config_word(dev, ATIIXP_IDE_UDMA_MODE, tmp16); |
Bartlomiej Zolnierkiewicz | 8ae60e3 | 2008-01-26 20:13:02 +0100 | [diff] [blame] | 104 | |
| 105 | udma_ctl |= (1 << drive->dn); |
| 106 | } else if (speed >= XFER_MW_DMA_0) { |
| 107 | u8 i = speed & 0x03; |
| 108 | |
| 109 | pci_read_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, &tmp32); |
| 110 | tmp32 &= ~(0xff << timing_shift); |
| 111 | tmp32 |= (mdma_timing[i].recover_width << timing_shift) | |
| 112 | (mdma_timing[i].command_width << (timing_shift + 4)); |
| 113 | pci_write_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, tmp32); |
| 114 | |
| 115 | udma_ctl &= ~(1 << drive->dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Bartlomiej Zolnierkiewicz | 8ae60e3 | 2008-01-26 20:13:02 +0100 | [diff] [blame] | 118 | pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, udma_ctl); |
| 119 | |
Alan | 6c5f8cc | 2007-01-05 16:36:27 -0800 | [diff] [blame] | 120 | spin_unlock_irqrestore(&atiixp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Bartlomiej Zolnierkiewicz | f454cbe | 2008-08-05 18:17:04 +0200 | [diff] [blame] | 123 | static u8 atiixp_cable_detect(ide_hwif_t *hwif) |
Bartlomiej Zolnierkiewicz | b4d1c73 | 2008-02-02 19:56:29 +0100 | [diff] [blame] | 124 | { |
| 125 | struct pci_dev *pdev = to_pci_dev(hwif->dev); |
| 126 | u8 udma_mode = 0, ch = hwif->channel; |
| 127 | |
| 128 | pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode); |
| 129 | |
| 130 | if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40) |
| 131 | return ATA_CBL_PATA80; |
| 132 | else |
| 133 | return ATA_CBL_PATA40; |
| 134 | } |
| 135 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 136 | static const struct ide_port_ops atiixp_port_ops = { |
| 137 | .set_pio_mode = atiixp_set_pio_mode, |
| 138 | .set_dma_mode = atiixp_set_dma_mode, |
| 139 | .cable_detect = atiixp_cable_detect, |
| 140 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 142 | static const struct ide_port_info atiixp_pci_info[] = { |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 143 | { /* 0: IXP200/300/400/700 */ |
| 144 | .name = DRV_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 146 | .port_ops = &atiixp_port_ops, |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 147 | .pio_mask = ATA_PIO4, |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 148 | .mwdma_mask = ATA_MWDMA2, |
| 149 | .udma_mask = ATA_UDMA5, |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 150 | }, |
| 151 | { /* 1: IXP600 */ |
| 152 | .name = DRV_NAME, |
Conke Hu | b25168d | 2007-01-27 13:46:30 +0100 | [diff] [blame] | 153 | .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 154 | .port_ops = &atiixp_port_ops, |
Bartlomiej Zolnierkiewicz | 2467922 | 2009-03-24 23:22:52 +0100 | [diff] [blame] | 155 | .host_flags = IDE_HFLAG_SINGLE, |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 156 | .pio_mask = ATA_PIO4, |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 157 | .mwdma_mask = ATA_MWDMA2, |
| 158 | .udma_mask = ATA_UDMA5, |
Conke Hu | b25168d | 2007-01-27 13:46:30 +0100 | [diff] [blame] | 159 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * atiixp_init_one - called when a ATIIXP is found |
| 164 | * @dev: the atiixp device |
| 165 | * @id: the matching pci id |
| 166 | * |
| 167 | * Called when the PCI registration layer (or the IDE initialization) |
| 168 | * finds a device matching our IDE device tables. |
| 169 | */ |
| 170 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 171 | static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
Bartlomiej Zolnierkiewicz | 6cdf6eb | 2008-07-24 22:53:14 +0200 | [diff] [blame] | 173 | return ide_pci_init_one(dev, &atiixp_pci_info[id->driver_data], NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 176 | static const struct pci_device_id atiixp_pci_tbl[] = { |
| 177 | { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP200_IDE), 0 }, |
| 178 | { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP300_IDE), 0 }, |
| 179 | { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP400_IDE), 0 }, |
| 180 | { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP600_IDE), 1 }, |
| 181 | { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP700_IDE), 0 }, |
Shane Huang | 5deab53 | 2009-10-13 11:14:00 +0800 | [diff] [blame] | 182 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_HUDSON2_IDE), 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { 0, }, |
| 184 | }; |
| 185 | MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); |
| 186 | |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 187 | static struct pci_driver atiixp_pci_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | .name = "ATIIXP_IDE", |
| 189 | .id_table = atiixp_pci_tbl, |
| 190 | .probe = atiixp_init_one, |
Bartlomiej Zolnierkiewicz | f354fbc | 2008-07-24 22:53:20 +0200 | [diff] [blame] | 191 | .remove = ide_pci_remove, |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 192 | .suspend = ide_pci_suspend, |
| 193 | .resume = ide_pci_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Bartlomiej Zolnierkiewicz | 82ab1ee | 2007-01-27 13:46:56 +0100 | [diff] [blame] | 196 | static int __init atiixp_ide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 198 | return ide_pci_register_driver(&atiixp_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Bartlomiej Zolnierkiewicz | f354fbc | 2008-07-24 22:53:20 +0200 | [diff] [blame] | 201 | static void __exit atiixp_ide_exit(void) |
| 202 | { |
Bartlomiej Zolnierkiewicz | a9ab09e | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 203 | pci_unregister_driver(&atiixp_pci_driver); |
Bartlomiej Zolnierkiewicz | f354fbc | 2008-07-24 22:53:20 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | module_init(atiixp_ide_init); |
Bartlomiej Zolnierkiewicz | f354fbc | 2008-07-24 22:53:20 +0200 | [diff] [blame] | 207 | module_exit(atiixp_ide_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | MODULE_AUTHOR("HUI YU"); |
| 210 | MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE"); |
| 211 | MODULE_LICENSE("GPL"); |