Blame view
drivers/ide/it8213.c
5.54 KB
678818260 ide: it8213 IDE d... |
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 ide: add it8213 I... |
8 9 10 11 |
#include <linux/kernel.h> #include <linux/types.h> #include <linux/module.h> #include <linux/pci.h> |
9c6712c0b ide: add it8213 I... |
12 13 |
#include <linux/ide.h> #include <linux/init.h> |
ced3ec8aa ide: prefix messa... |
14 |
#define DRV_NAME "it8213" |
9c6712c0b ide: add it8213 I... |
15 |
/** |
88b2b32ba ide: move ide_con... |
16 |
* it8213_set_pio_mode - set host controller for PIO mode |
e085b3cae ide: change ->set... |
17 |
* @hwif: port |
88b2b32ba ide: move ide_con... |
18 |
* @drive: drive |
9c6712c0b ide: add it8213 I... |
19 |
* |
678818260 ide: it8213 IDE d... |
20 |
* Set the interface PIO mode. |
9c6712c0b ide: add it8213 I... |
21 |
*/ |
e085b3cae ide: change ->set... |
22 |
static void it8213_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
9c6712c0b ide: add it8213 I... |
23 |
{ |
36501650e ide: keep pointer... |
24 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
678818260 ide: it8213 IDE d... |
25 |
int is_slave = drive->dn & 1; |
9c6712c0b ide: add it8213 I... |
26 27 28 29 30 |
int master_port = 0x40; int slave_port = 0x44; unsigned long flags; u16 master_data; u8 slave_data; |
678818260 ide: it8213 IDE d... |
31 32 |
static DEFINE_SPINLOCK(tune_lock); int control = 0; |
e085b3cae ide: change ->set... |
33 |
const u8 pio = drive->pio_mode - XFER_PIO_0; |
9c6712c0b ide: add it8213 I... |
34 |
|
a2826190a IDE: Coding Style... |
35 |
static const u8 timings[][2] = { |
678818260 ide: it8213 IDE d... |
36 37 38 39 40 |
{ 0, 0 }, { 0, 0 }, { 1, 0 }, { 2, 1 }, { 2, 3 }, }; |
9c6712c0b ide: add it8213 I... |
41 |
|
9c6712c0b ide: add it8213 I... |
42 43 |
spin_lock_irqsave(&tune_lock, flags); pci_read_config_word(dev, master_port, &master_data); |
678818260 ide: it8213 IDE d... |
44 45 46 47 48 |
if (pio > 1) control |= 1; /* Programmable timing on */ if (drive->media != ide_disk) control |= 4; /* ATAPI */ |
c9ef59ff0 ide: IORDY handli... |
49 |
if (ide_pio_need_iordy(drive, pio)) |
678818260 ide: it8213 IDE d... |
50 |
control |= 2; /* IORDY */ |
9c6712c0b ide: add it8213 I... |
51 |
if (is_slave) { |
678818260 ide: it8213 IDE d... |
52 53 |
master_data |= 0x4000; master_data &= ~0x0070; |
9c6712c0b ide: add it8213 I... |
54 |
if (pio > 1) |
678818260 ide: it8213 IDE d... |
55 |
master_data = master_data | (control << 4); |
9c6712c0b ide: add it8213 I... |
56 57 |
pci_read_config_byte(dev, slave_port, &slave_data); slave_data = slave_data & 0xf0; |
678818260 ide: it8213 IDE d... |
58 |
slave_data = slave_data | (timings[pio][0] << 2) | timings[pio][1]; |
9c6712c0b ide: add it8213 I... |
59 |
} else { |
678818260 ide: it8213 IDE d... |
60 |
master_data &= ~0x3307; |
9c6712c0b ide: add it8213 I... |
61 |
if (pio > 1) |
678818260 ide: it8213 IDE d... |
62 |
master_data = master_data | control; |
9c6712c0b ide: add it8213 I... |
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 ide: add it8213 I... |
70 |
/** |
88b2b32ba ide: move ide_con... |
71 |
* it8213_set_dma_mode - set host controller for DMA mode |
8776168ca ide: change ->set... |
72 |
* @hwif: port |
88b2b32ba ide: move ide_con... |
73 |
* @drive: drive |
9c6712c0b ide: add it8213 I... |
74 |
* |
88b2b32ba ide: move ide_con... |
75 |
* Tune the ITE chipset for the DMA mode. |
9c6712c0b ide: add it8213 I... |
76 |
*/ |
8776168ca ide: change ->set... |
77 |
static void it8213_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
9c6712c0b ide: add it8213 I... |
78 |
{ |
36501650e ide: keep pointer... |
79 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
9c6712c0b ide: add it8213 I... |
80 |
u8 maslave = 0x40; |
9c6712c0b ide: add it8213 I... |
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 it8213/piix/slc90... |
87 |
u8 reg48, reg54, reg55; |
8776168ca ide: change ->set... |
88 |
const u8 speed = drive->dma_mode; |
9c6712c0b ide: add it8213 I... |
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 ide: it8213 IDE d... |
95 |
if (speed >= XFER_UDMA_0) { |
4db90a145 ide: add IDE_HFLA... |
96 97 98 |
u8 udma = speed - XFER_UDMA_0; u_speed = min_t(u8, 2 - (udma & 1), udma) << (drive->dn * 4); |
9c6712c0b ide: add it8213 I... |
99 100 |
if (!(reg48 & u_flag)) pci_write_config_byte(dev, 0x48, reg48 | u_flag); |
a2826190a IDE: Coding Style... |
101 |
if (speed >= XFER_UDMA_5) |
9c6712c0b ide: add it8213 I... |
102 |
pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag); |
a2826190a IDE: Coding Style... |
103 |
else |
9c6712c0b ide: add it8213 I... |
104 |
pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); |
9c6712c0b ide: add it8213 I... |
105 106 107 |
if ((reg4a & a_speed) != u_speed) pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed); |
678818260 ide: it8213 IDE d... |
108 |
if (speed > XFER_UDMA_2) { |
9c6712c0b ide: add it8213 I... |
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 ide: it8213 IDE d... |
113 |
} else { |
8c91abf86 it8213/piix/slc90... |
114 |
const u8 mwdma_to_pio[] = { 0, 3, 4 }; |
9c6712c0b ide: add it8213 I... |
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 it8213/piix/slc90... |
123 124 |
if (speed >= XFER_MW_DMA_0) |
e085b3cae ide: change ->set... |
125 126 |
drive->pio_mode = mwdma_to_pio[speed - XFER_MW_DMA_0] + XFER_PIO_0; |
8c91abf86 it8213/piix/slc90... |
127 |
else |
e085b3cae ide: change ->set... |
128 |
drive->pio_mode = XFER_PIO_2; /* for SWDMA2 */ |
68aaf8150 it8213: PIO fixes... |
129 |
|
e085b3cae ide: change ->set... |
130 |
it8213_set_pio_mode(hwif, drive); |
1c54a93d4 it8213/piix/slc90... |
131 |
} |
678818260 ide: it8213 IDE d... |
132 |
} |
9c6712c0b ide: add it8213 I... |
133 |
|
f454cbe8c ide: ->cable_dete... |
134 |
static u8 it8213_cable_detect(ide_hwif_t *hwif) |
bfa14b42a ide: add ->cable_... |
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 ide: add struct i... |
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 ide: add it8213 I... |
148 |
|
29f1ca920 it8213: remove DE... |
149 |
static const struct ide_port_info it8213_chipset __devinitdata = { |
ced3ec8aa ide: prefix messa... |
150 |
.name = DRV_NAME, |
29f1ca920 it8213: remove DE... |
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 ide: add it8213 I... |
158 |
}; |
9c6712c0b ide: add it8213 I... |
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 it8213: remove DE... |
171 |
return ide_pci_init_one(dev, &it8213_chipset, NULL); |
9c6712c0b ide: add it8213 I... |
172 |
} |
9cbcc5e3c ide: use PCI_VDEV... |
173 174 |
static const struct pci_device_id it8213_pci_tbl[] = { { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8213), 0 }, |
9c6712c0b ide: add it8213 I... |
175 176 177 178 |
{ 0, }, }; MODULE_DEVICE_TABLE(pci, it8213_pci_tbl); |
a9ab09e26 ide: use unique n... |
179 |
static struct pci_driver it8213_pci_driver = { |
9c6712c0b ide: add it8213 I... |
180 181 182 |
.name = "ITE8213_IDE", .id_table = it8213_pci_tbl, .probe = it8213_init_one, |
5102f7685 it8213: add ->rem... |
183 |
.remove = ide_pci_remove, |
feb22b7f8 ide: add proper P... |
184 185 |
.suspend = ide_pci_suspend, .resume = ide_pci_resume, |
9c6712c0b ide: add it8213 I... |
186 187 188 189 |
}; static int __init it8213_ide_init(void) { |
a9ab09e26 ide: use unique n... |
190 |
return ide_pci_register_driver(&it8213_pci_driver); |
678818260 ide: it8213 IDE d... |
191 |
} |
9c6712c0b ide: add it8213 I... |
192 |
|
5102f7685 it8213: add ->rem... |
193 194 |
static void __exit it8213_ide_exit(void) { |
a9ab09e26 ide: use unique n... |
195 |
pci_unregister_driver(&it8213_pci_driver); |
5102f7685 it8213: add ->rem... |
196 |
} |
9c6712c0b ide: add it8213 I... |
197 |
module_init(it8213_ide_init); |
5102f7685 it8213: add ->rem... |
198 |
module_exit(it8213_ide_exit); |
9c6712c0b ide: add it8213 I... |
199 |
|
678818260 ide: it8213 IDE d... |
200 |
MODULE_AUTHOR("Jack Lee, Alan Cox"); |
9c6712c0b ide: add it8213 I... |
201 202 |
MODULE_DESCRIPTION("PCI driver module for the ITE 8213"); MODULE_LICENSE("GPL"); |