diff options
author | Andrew Armenia <andrew@asquaredlabs.com> | 2012-07-24 08:13:56 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2012-07-24 08:13:56 -0400 |
commit | 14a8086d27ad9761d505489d5a239f21cd67ef0f (patch) | |
tree | 350095694b4447e35bf5d8da8c571922301bfde1 | |
parent | 56f2178898ffca84dcdfb351f0127bf5732b1610 (diff) |
i2c-piix4: Eliminate piix4_smba global variable
Some chipsets have multiple sets of piix4-compatible SMBus registers.
Eliminating the global variable will allow these chipsets to be fully
supported.
Return value from piix4_setup and piix4_sb800_setup now returns the smba
value detected. This is stored in a struct i2c_piix4_adapdata. Thus
the global variable is eliminated.
Signed-off-by: Andrew Armenia <andrew@asquaredlabs.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r-- | drivers/i2c/busses/i2c-piix4.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c index 46833fa7a3e0..822e868e2ab4 100644 --- a/drivers/i2c/busses/i2c-piix4.c +++ b/drivers/i2c/busses/i2c-piix4.c | |||
@@ -94,7 +94,6 @@ MODULE_PARM_DESC(force_addr, | |||
94 | "Forcibly enable the PIIX4 at the given address. " | 94 | "Forcibly enable the PIIX4 at the given address. " |
95 | "EXTREMELY DANGEROUS!"); | 95 | "EXTREMELY DANGEROUS!"); |
96 | 96 | ||
97 | static unsigned short piix4_smba; | ||
98 | static int srvrworks_csb5_delay; | 97 | static int srvrworks_csb5_delay; |
99 | static struct pci_driver piix4_driver; | 98 | static struct pci_driver piix4_driver; |
100 | static struct i2c_adapter piix4_adapter; | 99 | static struct i2c_adapter piix4_adapter; |
@@ -127,10 +126,15 @@ static struct dmi_system_id __devinitdata piix4_dmi_ibm[] = { | |||
127 | { }, | 126 | { }, |
128 | }; | 127 | }; |
129 | 128 | ||
129 | struct i2c_piix4_adapdata { | ||
130 | unsigned short smba; | ||
131 | }; | ||
132 | |||
130 | static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, | 133 | static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, |
131 | const struct pci_device_id *id) | 134 | const struct pci_device_id *id) |
132 | { | 135 | { |
133 | unsigned char temp; | 136 | unsigned char temp; |
137 | unsigned short piix4_smba; | ||
134 | 138 | ||
135 | if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && | 139 | if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && |
136 | (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) | 140 | (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) |
@@ -206,7 +210,6 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, | |||
206 | dev_err(&PIIX4_dev->dev, | 210 | dev_err(&PIIX4_dev->dev, |
207 | "Host SMBus controller not enabled!\n"); | 211 | "Host SMBus controller not enabled!\n"); |
208 | release_region(piix4_smba, SMBIOSIZE); | 212 | release_region(piix4_smba, SMBIOSIZE); |
209 | piix4_smba = 0; | ||
210 | return -ENODEV; | 213 | return -ENODEV; |
211 | } | 214 | } |
212 | } | 215 | } |
@@ -224,12 +227,13 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, | |||
224 | "SMBus Host Controller at 0x%x, revision %d\n", | 227 | "SMBus Host Controller at 0x%x, revision %d\n", |
225 | piix4_smba, temp); | 228 | piix4_smba, temp); |
226 | 229 | ||
227 | return 0; | 230 | return piix4_smba; |
228 | } | 231 | } |
229 | 232 | ||
230 | static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev, | 233 | static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev, |
231 | const struct pci_device_id *id) | 234 | const struct pci_device_id *id) |
232 | { | 235 | { |
236 | unsigned short piix4_smba; | ||
233 | unsigned short smba_idx = 0xcd6; | 237 | unsigned short smba_idx = 0xcd6; |
234 | u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c; | 238 | u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c; |
235 | 239 | ||
@@ -273,7 +277,6 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev, | |||
273 | dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " | 277 | dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " |
274 | "0x%x already in use!\n", piix4_smba + i2ccfg_offset); | 278 | "0x%x already in use!\n", piix4_smba + i2ccfg_offset); |
275 | release_region(piix4_smba, SMBIOSIZE); | 279 | release_region(piix4_smba, SMBIOSIZE); |
276 | piix4_smba = 0; | ||
277 | return -EBUSY; | 280 | return -EBUSY; |
278 | } | 281 | } |
279 | i2ccfg = inb_p(piix4_smba + i2ccfg_offset); | 282 | i2ccfg = inb_p(piix4_smba + i2ccfg_offset); |
@@ -288,10 +291,10 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev, | |||
288 | "SMBus Host Controller at 0x%x, revision %d\n", | 291 | "SMBus Host Controller at 0x%x, revision %d\n", |
289 | piix4_smba, i2ccfg >> 4); | 292 | piix4_smba, i2ccfg >> 4); |
290 | 293 | ||
291 | return 0; | 294 | return piix4_smba; |
292 | } | 295 | } |
293 | 296 | ||
294 | static int piix4_transaction(void) | 297 | static int piix4_transaction(unsigned short piix4_smba) |
295 | { | 298 | { |
296 | int temp; | 299 | int temp; |
297 | int result = 0; | 300 | int result = 0; |
@@ -370,6 +373,8 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr, | |||
370 | unsigned short flags, char read_write, | 373 | unsigned short flags, char read_write, |
371 | u8 command, int size, union i2c_smbus_data * data) | 374 | u8 command, int size, union i2c_smbus_data * data) |
372 | { | 375 | { |
376 | struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); | ||
377 | unsigned short piix4_smba = adapdata->smba; | ||
373 | int i, len; | 378 | int i, len; |
374 | int status; | 379 | int status; |
375 | 380 | ||
@@ -426,7 +431,7 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr, | |||
426 | 431 | ||
427 | outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); | 432 | outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); |
428 | 433 | ||
429 | status = piix4_transaction(); | 434 | status = piix4_transaction(piix4_smba); |
430 | if (status) | 435 | if (status) |
431 | return status; | 436 | return status; |
432 | 437 | ||
@@ -472,6 +477,8 @@ static struct i2c_adapter piix4_adapter = { | |||
472 | .algo = &smbus_algorithm, | 477 | .algo = &smbus_algorithm, |
473 | }; | 478 | }; |
474 | 479 | ||
480 | static struct i2c_piix4_adapdata piix4_adapter_data; | ||
481 | |||
475 | static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = { | 482 | static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = { |
476 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, | 483 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, |
477 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, | 484 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, |
@@ -510,33 +517,44 @@ static int __devinit piix4_probe(struct pci_dev *dev, | |||
510 | else | 517 | else |
511 | retval = piix4_setup(dev, id); | 518 | retval = piix4_setup(dev, id); |
512 | 519 | ||
513 | if (retval) | 520 | if (retval < 0) |
514 | return retval; | 521 | return retval; |
515 | 522 | ||
523 | piix4_adapter_data.smba = retval; | ||
524 | |||
516 | /* set up the sysfs linkage to our parent device */ | 525 | /* set up the sysfs linkage to our parent device */ |
517 | piix4_adapter.dev.parent = &dev->dev; | 526 | piix4_adapter.dev.parent = &dev->dev; |
518 | 527 | ||
519 | snprintf(piix4_adapter.name, sizeof(piix4_adapter.name), | 528 | snprintf(piix4_adapter.name, sizeof(piix4_adapter.name), |
520 | "SMBus PIIX4 adapter at %04x", piix4_smba); | 529 | "SMBus PIIX4 adapter at %04x", piix4_adapter_data.smba); |
530 | |||
531 | i2c_set_adapdata(&piix4_adapter, &piix4_adapter_data); | ||
521 | 532 | ||
522 | if ((retval = i2c_add_adapter(&piix4_adapter))) { | 533 | if ((retval = i2c_add_adapter(&piix4_adapter))) { |
523 | dev_err(&dev->dev, "Couldn't register adapter!\n"); | 534 | dev_err(&dev->dev, "Couldn't register adapter!\n"); |
524 | release_region(piix4_smba, SMBIOSIZE); | 535 | release_region(piix4_adapter_data.smba, SMBIOSIZE); |
525 | piix4_smba = 0; | 536 | piix4_adapter_data.smba = 0; |
526 | } | 537 | } |
527 | 538 | ||
528 | return retval; | 539 | return retval; |
529 | } | 540 | } |
530 | 541 | ||
531 | static void __devexit piix4_remove(struct pci_dev *dev) | 542 | static void __devexit piix4_adap_remove(struct i2c_adapter *adap) |
532 | { | 543 | { |
533 | if (piix4_smba) { | 544 | struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); |
534 | i2c_del_adapter(&piix4_adapter); | 545 | |
535 | release_region(piix4_smba, SMBIOSIZE); | 546 | if (adapdata->smba) { |
536 | piix4_smba = 0; | 547 | i2c_del_adapter(adap); |
548 | release_region(adapdata->smba, SMBIOSIZE); | ||
549 | adapdata->smba = 0; | ||
537 | } | 550 | } |
538 | } | 551 | } |
539 | 552 | ||
553 | static void __devexit piix4_remove(struct pci_dev *dev) | ||
554 | { | ||
555 | piix4_adap_remove(&piix4_adapter); | ||
556 | } | ||
557 | |||
540 | static struct pci_driver piix4_driver = { | 558 | static struct pci_driver piix4_driver = { |
541 | .name = "piix4_smbus", | 559 | .name = "piix4_smbus", |
542 | .id_table = piix4_ids, | 560 | .id_table = piix4_ids, |