Blame view
drivers/ide/it8213.c
5.54 KB
678818260
|
1 2 3 4 5 6 7 |
/* * ITE 8213 IDE driver * * Copyright (C) 2006 Jack Lee * Copyright (C) 2006 Alan Cox * Copyright (C) 2007 Bartlomiej Zolnierkiewicz */ |
9c6712c0b
|
8 9 10 11 |
#include <linux/kernel.h> #include <linux/types.h> #include <linux/module.h> #include <linux/pci.h> |
9c6712c0b
|
12 13 |
#include <linux/ide.h> #include <linux/init.h> |
ced3ec8aa
|
14 |
#define DRV_NAME "it8213" |
9c6712c0b
|
15 |
/** |
88b2b32ba
|
16 |
* it8213_set_pio_mode - set host controller for PIO mode |
e085b3cae
|
17 |
* @hwif: port |
88b2b32ba
|
18 |
* @drive: drive |
9c6712c0b
|
19 |
* |
678818260
|
20 |
* Set the interface PIO mode. |
9c6712c0b
|
21 |
*/ |
e085b3cae
|
22 |
static void it8213_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
9c6712c0b
|
23 |
{ |
36501650e
|
24 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
678818260
|
25 |
int is_slave = drive->dn & 1; |
9c6712c0b
|
26 27 28 29 30 |
int master_port = 0x40; int slave_port = 0x44; unsigned long flags; u16 master_data; u8 slave_data; |
678818260
|
31 32 |
static DEFINE_SPINLOCK(tune_lock); int control = 0; |
e085b3cae
|
33 |
const u8 pio = drive->pio_mode - XFER_PIO_0; |
9c6712c0b
|
34 |
|
a2826190a
|
35 |
static const u8 timings[][2] = { |
678818260
|
36 37 38 39 40 |
{ 0, 0 }, { 0, 0 }, { 1, 0 }, { 2, 1 }, { 2, 3 }, }; |
9c6712c0b
|
41 |
|
9c6712c0b
|
42 43 |
spin_lock_irqsave(&tune_lock, flags); pci_read_config_word(dev, master_port, &master_data); |
678818260
|
44 45 46 47 48 |
if (pio > 1) control |= 1; /* Programmable timing on */ if (drive->media != ide_disk) control |= 4; /* ATAPI */ |
c9ef59ff0
|
49 |
if (ide_pio_need_iordy(drive, pio)) |
678818260
|
50 |
control |= 2; /* IORDY */ |
9c6712c0b
|
51 |
if (is_slave) { |
678818260
|
52 53 |
master_data |= 0x4000; master_data &= ~0x0070; |
9c6712c0b
|
54 |
if (pio > 1) |
678818260
|
55 |
master_data = master_data | (control << 4); |
9c6712c0b
|
56 57 |
pci_read_config_byte(dev, slave_port, &slave_data); slave_data = slave_data & 0xf0; |
678818260
|
58 |
slave_data = slave_data | (timings[pio][0] << 2) | timings[pio][1]; |
9c6712c0b
|
59 |
} else { |
678818260
|
60 |
master_data &= ~0x3307; |
9c6712c0b
|
61 |
if (pio > 1) |
678818260
|
62 |
master_data = master_data | control; |
9c6712c0b
|
63 64 65 66 67 68 69 |
master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); } pci_write_config_word(dev, master_port, master_data); if (is_slave) pci_write_config_byte(dev, slave_port, slave_data); spin_unlock_irqrestore(&tune_lock, flags); } |
9c6712c0b
|
70 |
/** |
88b2b32ba
|
71 |
* it8213_set_dma_mode - set host controller for DMA mode |
8776168ca
|
72 |
* @hwif: port |
88b2b32ba
|
73 |
* @drive: drive |
9c6712c0b
|
74 |
* |
88b2b32ba
|
75 |
* Tune the ITE chipset for the DMA mode. |
9c6712c0b
|
76 |
*/ |
8776168ca
|
77 |
static void it8213_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
9c6712c0b
|
78 |
{ |
36501650e
|
79 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
9c6712c0b
|
80 |
u8 maslave = 0x40; |
9c6712c0b
|
81 82 83 84 85 86 |
int a_speed = 3 << (drive->dn * 4); int u_flag = 1 << drive->dn; int v_flag = 0x01 << drive->dn; int w_flag = 0x10 << drive->dn; int u_speed = 0; u16 reg4042, reg4a; |
1c54a93d4
|
87 |
u8 reg48, reg54, reg55; |
8776168ca
|
88 |
const u8 speed = drive->dma_mode; |
9c6712c0b
|
89 90 91 92 93 94 |
pci_read_config_word(dev, maslave, ®4042); pci_read_config_byte(dev, 0x48, ®48); pci_read_config_word(dev, 0x4a, ®4a); pci_read_config_byte(dev, 0x54, ®54); pci_read_config_byte(dev, 0x55, ®55); |
678818260
|
95 |
if (speed >= XFER_UDMA_0) { |
4db90a145
|
96 97 98 |
u8 udma = speed - XFER_UDMA_0; u_speed = min_t(u8, 2 - (udma & 1), udma) << (drive->dn * 4); |
9c6712c0b
|
99 100 |
if (!(reg48 & u_flag)) pci_write_config_byte(dev, 0x48, reg48 | u_flag); |
a2826190a
|
101 |
if (speed >= XFER_UDMA_5) |
9c6712c0b
|
102 |
pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag); |
a2826190a
|
103 |
else |
9c6712c0b
|
104 |
pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); |
9c6712c0b
|
105 106 107 |
if ((reg4a & a_speed) != u_speed) pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed); |
678818260
|
108 |
if (speed > XFER_UDMA_2) { |
9c6712c0b
|
109 110 111 112 |
if (!(reg54 & v_flag)) pci_write_config_byte(dev, 0x54, reg54 | v_flag); } else pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); |
678818260
|
113 |
} else { |
8c91abf86
|
114 |
const u8 mwdma_to_pio[] = { 0, 3, 4 }; |
9c6712c0b
|
115 116 117 118 119 120 121 122 |
if (reg48 & u_flag) pci_write_config_byte(dev, 0x48, reg48 & ~u_flag); if (reg4a & a_speed) pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); if (reg54 & v_flag) pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); if (reg55 & w_flag) pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); |
8c91abf86
|
123 124 |
if (speed >= XFER_MW_DMA_0) |
e085b3cae
|
125 126 |
drive->pio_mode = mwdma_to_pio[speed - XFER_MW_DMA_0] + XFER_PIO_0; |
8c91abf86
|
127 |
else |
e085b3cae
|
128 |
drive->pio_mode = XFER_PIO_2; /* for SWDMA2 */ |
68aaf8150
|
129 |
|
e085b3cae
|
130 |
it8213_set_pio_mode(hwif, drive); |
1c54a93d4
|
131 |
} |
678818260
|
132 |
} |
9c6712c0b
|
133 |
|
f454cbe8c
|
134 |
static u8 it8213_cable_detect(ide_hwif_t *hwif) |
bfa14b42a
|
135 136 137 138 139 140 141 142 |
{ struct pci_dev *dev = to_pci_dev(hwif->dev); u8 reg42h = 0; pci_read_config_byte(dev, 0x42, ®42h); return (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80; } |
ac95beedf
|
143 144 145 146 147 |
static const struct ide_port_ops it8213_port_ops = { .set_pio_mode = it8213_set_pio_mode, .set_dma_mode = it8213_set_dma_mode, .cable_detect = it8213_cable_detect, }; |
9c6712c0b
|
148 |
|
29f1ca920
|
149 |
static const struct ide_port_info it8213_chipset __devinitdata = { |
ced3ec8aa
|
150 |
.name = DRV_NAME, |
29f1ca920
|
151 152 153 154 155 156 157 |
.enablebits = { {0x41, 0x80, 0x80} }, .port_ops = &it8213_port_ops, .host_flags = IDE_HFLAG_SINGLE, .pio_mask = ATA_PIO4, .swdma_mask = ATA_SWDMA2_ONLY, .mwdma_mask = ATA_MWDMA12_ONLY, .udma_mask = ATA_UDMA6, |
9c6712c0b
|
158 |
}; |
9c6712c0b
|
159 160 161 162 163 164 165 166 167 168 169 170 |
/** * it8213_init_one - pci layer discovery entry * @dev: PCI device * @id: ident table entry * * Called by the PCI code when it finds an ITE8213 controller. As * this device follows the standard interfaces we can use the * standard helper functions to do almost all the work for us. */ static int __devinit it8213_init_one(struct pci_dev *dev, const struct pci_device_id *id) { |
29f1ca920
|
171 |
return ide_pci_init_one(dev, &it8213_chipset, NULL); |
9c6712c0b
|
172 |
} |
9cbcc5e3c
|
173 174 |
static const struct pci_device_id it8213_pci_tbl[] = { { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8213), 0 }, |
9c6712c0b
|
175 176 177 178 |
{ 0, }, }; MODULE_DEVICE_TABLE(pci, it8213_pci_tbl); |
a9ab09e26
|
179 |
static struct pci_driver it8213_pci_driver = { |
9c6712c0b
|
180 181 182 |
.name = "ITE8213_IDE", .id_table = it8213_pci_tbl, .probe = it8213_init_one, |
5102f7685
|
183 |
.remove = ide_pci_remove, |
feb22b7f8
|
184 185 |
.suspend = ide_pci_suspend, .resume = ide_pci_resume, |
9c6712c0b
|
186 187 188 189 |
}; static int __init it8213_ide_init(void) { |
a9ab09e26
|
190 |
return ide_pci_register_driver(&it8213_pci_driver); |
678818260
|
191 |
} |
9c6712c0b
|
192 |
|
5102f7685
|
193 194 |
static void __exit it8213_ide_exit(void) { |
a9ab09e26
|
195 |
pci_unregister_driver(&it8213_pci_driver); |
5102f7685
|
196 |
} |
9c6712c0b
|
197 |
module_init(it8213_ide_init); |
5102f7685
|
198 |
module_exit(it8213_ide_exit); |
9c6712c0b
|
199 |
|
678818260
|
200 |
MODULE_AUTHOR("Jack Lee, Alan Cox"); |
9c6712c0b
|
201 202 |
MODULE_DESCRIPTION("PCI driver module for the ITE 8213"); MODULE_LICENSE("GPL"); |