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) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and |
| 3 | Philip Edelbrock <phil@netroedge.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | Supports: |
| 18 | Intel PIIX4, 440MX |
Flavio Leitner | 506a8b6 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 19 | Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 20 | ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800 |
Shane Huang | 032f708 | 2014-01-22 14:05:46 -0800 | [diff] [blame] | 21 | AMD Hudson-2, ML, CZ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | SMSC Victory66 |
| 23 | |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 24 | Note: we assume there can only be one device, with one or more |
| 25 | SMBus interfaces. |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 26 | The device can register multiple i2c_adapters (up to PIIX4_MAX_ADAPTERS). |
| 27 | For devices supporting multiple ports the i2c_adapter should provide |
| 28 | an i2c_algorithm to access them. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/moduleparam.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/stddef.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/ioport.h> |
| 38 | #include <linux/i2c.h> |
Daniel J Blueman | c415b30 | 2012-10-05 22:23:55 +0200 | [diff] [blame] | 39 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/dmi.h> |
Jean Delvare | 54fb4a05 | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 41 | #include <linux/acpi.h> |
H Hartley Sweeten | 2178218 | 2010-05-21 18:41:01 +0200 | [diff] [blame] | 42 | #include <linux/io.h> |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 43 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* PIIX4 SMBus address offsets */ |
| 47 | #define SMBHSTSTS (0 + piix4_smba) |
| 48 | #define SMBHSLVSTS (1 + piix4_smba) |
| 49 | #define SMBHSTCNT (2 + piix4_smba) |
| 50 | #define SMBHSTCMD (3 + piix4_smba) |
| 51 | #define SMBHSTADD (4 + piix4_smba) |
| 52 | #define SMBHSTDAT0 (5 + piix4_smba) |
| 53 | #define SMBHSTDAT1 (6 + piix4_smba) |
| 54 | #define SMBBLKDAT (7 + piix4_smba) |
| 55 | #define SMBSLVCNT (8 + piix4_smba) |
| 56 | #define SMBSHDWCMD (9 + piix4_smba) |
| 57 | #define SMBSLVEVT (0xA + piix4_smba) |
| 58 | #define SMBSLVDAT (0xC + piix4_smba) |
| 59 | |
| 60 | /* count for request_region */ |
Ricardo Ribalda | 47a5aab | 2017-05-23 21:53:45 -0400 | [diff] [blame] | 61 | #define SMBIOSIZE 9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | /* PCI Address Constants */ |
| 64 | #define SMBBA 0x090 |
| 65 | #define SMBHSTCFG 0x0D2 |
| 66 | #define SMBSLVC 0x0D3 |
| 67 | #define SMBSHDW1 0x0D4 |
| 68 | #define SMBSHDW2 0x0D5 |
| 69 | #define SMBREV 0x0D6 |
| 70 | |
| 71 | /* Other settings */ |
| 72 | #define MAX_TIMEOUT 500 |
| 73 | #define ENABLE_INT9 0 |
| 74 | |
| 75 | /* PIIX4 constants */ |
| 76 | #define PIIX4_QUICK 0x00 |
| 77 | #define PIIX4_BYTE 0x04 |
| 78 | #define PIIX4_BYTE_DATA 0x08 |
| 79 | #define PIIX4_WORD_DATA 0x0C |
| 80 | #define PIIX4_BLOCK_DATA 0x14 |
| 81 | |
Christian Fetzer | ca2061e | 2015-11-19 20:13:47 +0100 | [diff] [blame] | 82 | /* Multi-port constants */ |
| 83 | #define PIIX4_MAX_ADAPTERS 4 |
| 84 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 85 | /* SB800 constants */ |
| 86 | #define SB800_PIIX4_SMB_IDX 0xcd6 |
| 87 | |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 88 | /* |
| 89 | * SB800 port is selected by bits 2:1 of the smb_en register (0x2c) |
| 90 | * or the smb_sel register (0x2e), depending on bit 0 of register 0x2f. |
| 91 | * Hudson-2/Bolton port is always selected by bits 2:1 of register 0x2f. |
| 92 | */ |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 93 | #define SB800_PIIX4_PORT_IDX 0x2c |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 94 | #define SB800_PIIX4_PORT_IDX_ALT 0x2e |
| 95 | #define SB800_PIIX4_PORT_IDX_SEL 0x2f |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 96 | #define SB800_PIIX4_PORT_IDX_MASK 0x06 |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 97 | #define SB800_PIIX4_PORT_IDX_SHIFT 1 |
| 98 | |
Andrew Cooks | 625ee1a | 2019-08-02 14:52:46 +0200 | [diff] [blame^] | 99 | /* On kerncz and Hudson2, SmBus0Sel is at bit 20:19 of PMx00 DecodeEn */ |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 100 | #define SB800_PIIX4_PORT_IDX_KERNCZ 0x02 |
| 101 | #define SB800_PIIX4_PORT_IDX_MASK_KERNCZ 0x18 |
| 102 | #define SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ 3 |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* insmod parameters */ |
| 105 | |
| 106 | /* If force is set to anything different from 0, we forcibly enable the |
| 107 | PIIX4. DANGEROUS! */ |
Jean Delvare | 6050709 | 2005-09-25 16:23:07 +0200 | [diff] [blame] | 108 | static int force; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | module_param (force, int, 0); |
| 110 | MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); |
| 111 | |
| 112 | /* If force_addr is set to anything different from 0, we forcibly enable |
| 113 | the PIIX4 at the given address. VERY DANGEROUS! */ |
Jean Delvare | 6050709 | 2005-09-25 16:23:07 +0200 | [diff] [blame] | 114 | static int force_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | module_param (force_addr, int, 0); |
| 116 | MODULE_PARM_DESC(force_addr, |
| 117 | "Forcibly enable the PIIX4 at the given address. " |
| 118 | "EXTREMELY DANGEROUS!"); |
| 119 | |
David Milburn | b1c1759 | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 120 | static int srvrworks_csb5_delay; |
Jean Delvare | d6072f8 | 2005-09-25 16:37:04 +0200 | [diff] [blame] | 121 | static struct pci_driver piix4_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 123 | static const struct dmi_system_id piix4_dmi_blacklist[] = { |
Jean Delvare | c2fc54f | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 124 | { |
| 125 | .ident = "Sapphire AM2RD790", |
| 126 | .matches = { |
| 127 | DMI_MATCH(DMI_BOARD_VENDOR, "SAPPHIRE Inc."), |
| 128 | DMI_MATCH(DMI_BOARD_NAME, "PC-AM2RD790"), |
| 129 | }, |
| 130 | }, |
| 131 | { |
| 132 | .ident = "DFI Lanparty UT 790FX", |
| 133 | .matches = { |
| 134 | DMI_MATCH(DMI_BOARD_VENDOR, "DFI Inc."), |
| 135 | DMI_MATCH(DMI_BOARD_NAME, "LP UT 790FX"), |
| 136 | }, |
| 137 | }, |
| 138 | { } |
| 139 | }; |
| 140 | |
| 141 | /* The IBM entry is in a separate table because we only check it |
| 142 | on Intel-based systems */ |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 143 | static const struct dmi_system_id piix4_dmi_ibm[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
| 145 | .ident = "IBM", |
| 146 | .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, |
| 147 | }, |
| 148 | { }, |
| 149 | }; |
| 150 | |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 151 | /* |
| 152 | * SB800 globals |
| 153 | * piix4_mutex_sb800 protects piix4_port_sel_sb800 and the pair |
| 154 | * of I/O ports at SB800_PIIX4_SMB_IDX. |
| 155 | */ |
Jean Delvare | a28e351 | 2016-01-22 14:12:02 +0100 | [diff] [blame] | 156 | static DEFINE_MUTEX(piix4_mutex_sb800); |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 157 | static u8 piix4_port_sel_sb800; |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 158 | static u8 piix4_port_mask_sb800; |
| 159 | static u8 piix4_port_shift_sb800; |
Christian Fetzer | 725d2e3 | 2015-11-19 20:13:49 +0100 | [diff] [blame] | 160 | static const char *piix4_main_port_names_sb800[PIIX4_MAX_ADAPTERS] = { |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 161 | " port 0", " port 2", " port 3", " port 4" |
Christian Fetzer | 725d2e3 | 2015-11-19 20:13:49 +0100 | [diff] [blame] | 162 | }; |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 163 | static const char *piix4_aux_port_name_sb800 = " port 1"; |
Christian Fetzer | 725d2e3 | 2015-11-19 20:13:49 +0100 | [diff] [blame] | 164 | |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 165 | struct i2c_piix4_adapdata { |
| 166 | unsigned short smba; |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 167 | |
| 168 | /* SB800 */ |
| 169 | bool sb800_main; |
Jean Delvare | 33f5ccc | 2016-01-29 10:46:37 +0100 | [diff] [blame] | 170 | u8 port; /* Port number, shifted */ |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 171 | }; |
| 172 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 173 | static int piix4_setup(struct pci_dev *PIIX4_dev, |
| 174 | const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | unsigned char temp; |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 177 | unsigned short piix4_smba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
David Milburn | b1c1759 | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 179 | if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && |
| 180 | (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) |
| 181 | srvrworks_csb5_delay = 1; |
| 182 | |
Jean Delvare | c2fc54f | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 183 | /* On some motherboards, it was reported that accessing the SMBus |
| 184 | caused severe hardware problems */ |
| 185 | if (dmi_check_system(piix4_dmi_blacklist)) { |
| 186 | dev_err(&PIIX4_dev->dev, |
| 187 | "Accessing the SMBus on this system is unsafe!\n"); |
| 188 | return -EPERM; |
| 189 | } |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* Don't access SMBus on IBM systems which get corrupted eeproms */ |
Jean Delvare | c2fc54f | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 192 | if (dmi_check_system(piix4_dmi_ibm) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { |
Jean Delvare | f9ba6c0 | 2006-04-25 13:37:25 +0200 | [diff] [blame] | 194 | dev_err(&PIIX4_dev->dev, "IBM system detected; this module " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | "may corrupt your serial eeprom! Refusing to load " |
| 196 | "module!\n"); |
| 197 | return -EPERM; |
| 198 | } |
| 199 | |
| 200 | /* Determine the address of the SMBus areas */ |
| 201 | if (force_addr) { |
| 202 | piix4_smba = force_addr & 0xfff0; |
| 203 | force = 0; |
| 204 | } else { |
| 205 | pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); |
| 206 | piix4_smba &= 0xfff0; |
| 207 | if(piix4_smba == 0) { |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 208 | dev_err(&PIIX4_dev->dev, "SMBus base address " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | "uninitialized - upgrade BIOS or use " |
| 210 | "force_addr=0xaddr\n"); |
| 211 | return -ENODEV; |
| 212 | } |
| 213 | } |
| 214 | |
Jean Delvare | 54fb4a05 | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 215 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) |
Jean Delvare | 18669ea | 2009-10-04 22:53:45 +0200 | [diff] [blame] | 216 | return -ENODEV; |
Jean Delvare | 54fb4a05 | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 217 | |
Jean Delvare | d6072f8 | 2005-09-25 16:37:04 +0200 | [diff] [blame] | 218 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 219 | dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | piix4_smba); |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 221 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | /* If force_addr is set, we program the new address here. Just to make |
| 227 | sure, we disable the PIIX4 first. */ |
| 228 | if (force_addr) { |
| 229 | pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe); |
| 230 | pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba); |
| 231 | pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01); |
| 232 | dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to " |
| 233 | "new address %04x!\n", piix4_smba); |
| 234 | } else if ((temp & 1) == 0) { |
| 235 | if (force) { |
| 236 | /* This should never need to be done, but has been |
| 237 | * noted that many Dell machines have the SMBus |
| 238 | * interface on the PIIX4 disabled!? NOTE: This assumes |
| 239 | * I/O space and other allocations WERE done by the |
| 240 | * Bios! Don't complain if your hardware does weird |
| 241 | * things after enabling this. :') Check for Bios |
| 242 | * updates before resorting to this. |
| 243 | */ |
| 244 | pci_write_config_byte(PIIX4_dev, SMBHSTCFG, |
| 245 | temp | 1); |
Joe Perches | 8117e41 | 2012-12-16 21:11:55 +0100 | [diff] [blame] | 246 | dev_notice(&PIIX4_dev->dev, |
| 247 | "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } else { |
| 249 | dev_err(&PIIX4_dev->dev, |
Jean Delvare | 66f8a8f | 2014-01-23 16:59:38 +0100 | [diff] [blame] | 250 | "SMBus Host Controller not enabled!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | release_region(piix4_smba, SMBIOSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return -ENODEV; |
| 253 | } |
| 254 | } |
| 255 | |
Rudolf Marek | 54aaa1c | 2006-04-25 13:06:41 +0200 | [diff] [blame] | 256 | if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2)) |
Jean Delvare | 66f8a8f | 2014-01-23 16:59:38 +0100 | [diff] [blame] | 257 | dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | else if ((temp & 0x0E) == 0) |
Jean Delvare | 66f8a8f | 2014-01-23 16:59:38 +0100 | [diff] [blame] | 259 | dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | else |
| 261 | dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration " |
| 262 | "(or code out of date)!\n"); |
| 263 | |
| 264 | pci_read_config_byte(PIIX4_dev, SMBREV, &temp); |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 265 | dev_info(&PIIX4_dev->dev, |
| 266 | "SMBus Host Controller at 0x%x, revision %d\n", |
| 267 | piix4_smba, temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 269 | return piix4_smba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 272 | static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 273 | const struct pci_device_id *id, u8 aux) |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 274 | { |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 275 | unsigned short piix4_smba; |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 276 | u8 smba_en_lo, smba_en_hi, smb_en, smb_en_status, port_sel; |
Shane Huang | 032f708 | 2014-01-22 14:05:46 -0800 | [diff] [blame] | 277 | u8 i2ccfg, i2ccfg_offset = 0x10; |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 278 | |
Crane Cai | 3806e94b | 2009-11-07 13:10:46 +0100 | [diff] [blame] | 279 | /* SB800 and later SMBus does not support forcing address */ |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 280 | if (force || force_addr) { |
Crane Cai | 3806e94b | 2009-11-07 13:10:46 +0100 | [diff] [blame] | 281 | dev_err(&PIIX4_dev->dev, "SMBus does not support " |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 282 | "forcing address!\n"); |
| 283 | return -EINVAL; |
| 284 | } |
| 285 | |
| 286 | /* Determine the address of the SMBus areas */ |
Shane Huang | 032f708 | 2014-01-22 14:05:46 -0800 | [diff] [blame] | 287 | if ((PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && |
| 288 | PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && |
| 289 | PIIX4_dev->revision >= 0x41) || |
| 290 | (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && |
Vincent Wan | bcb2999 | 2015-06-11 20:11:46 +0800 | [diff] [blame] | 291 | PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && |
Shane Huang | 032f708 | 2014-01-22 14:05:46 -0800 | [diff] [blame] | 292 | PIIX4_dev->revision >= 0x49)) |
| 293 | smb_en = 0x00; |
| 294 | else |
| 295 | smb_en = (aux) ? 0x28 : 0x2c; |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 296 | |
Jean Delvare | a28e351 | 2016-01-22 14:12:02 +0100 | [diff] [blame] | 297 | mutex_lock(&piix4_mutex_sb800); |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 298 | outb_p(smb_en, SB800_PIIX4_SMB_IDX); |
| 299 | smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); |
| 300 | outb_p(smb_en + 1, SB800_PIIX4_SMB_IDX); |
| 301 | smba_en_hi = inb_p(SB800_PIIX4_SMB_IDX + 1); |
Jean Delvare | a28e351 | 2016-01-22 14:12:02 +0100 | [diff] [blame] | 302 | mutex_unlock(&piix4_mutex_sb800); |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 303 | |
Shane Huang | 032f708 | 2014-01-22 14:05:46 -0800 | [diff] [blame] | 304 | if (!smb_en) { |
| 305 | smb_en_status = smba_en_lo & 0x10; |
| 306 | piix4_smba = smba_en_hi << 8; |
| 307 | if (aux) |
| 308 | piix4_smba |= 0x20; |
| 309 | } else { |
| 310 | smb_en_status = smba_en_lo & 0x01; |
| 311 | piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0; |
| 312 | } |
| 313 | |
| 314 | if (!smb_en_status) { |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 315 | dev_err(&PIIX4_dev->dev, |
Jean Delvare | 66f8a8f | 2014-01-23 16:59:38 +0100 | [diff] [blame] | 316 | "SMBus Host Controller not enabled!\n"); |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 317 | return -ENODEV; |
| 318 | } |
| 319 | |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 320 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) |
Jean Delvare | 18669ea | 2009-10-04 22:53:45 +0200 | [diff] [blame] | 321 | return -ENODEV; |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 322 | |
| 323 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { |
| 324 | dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", |
| 325 | piix4_smba); |
| 326 | return -EBUSY; |
| 327 | } |
| 328 | |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 329 | /* Aux SMBus does not support IRQ information */ |
| 330 | if (aux) { |
| 331 | dev_info(&PIIX4_dev->dev, |
Shane Huang | 85fd0fe | 2014-01-22 14:06:52 -0800 | [diff] [blame] | 332 | "Auxiliary SMBus Host Controller at 0x%x\n", |
| 333 | piix4_smba); |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 334 | return piix4_smba; |
| 335 | } |
| 336 | |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 337 | /* Request the SMBus I2C bus config region */ |
| 338 | if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) { |
| 339 | dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " |
| 340 | "0x%x already in use!\n", piix4_smba + i2ccfg_offset); |
| 341 | release_region(piix4_smba, SMBIOSIZE); |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 342 | return -EBUSY; |
| 343 | } |
| 344 | i2ccfg = inb_p(piix4_smba + i2ccfg_offset); |
| 345 | release_region(piix4_smba + i2ccfg_offset, 1); |
| 346 | |
| 347 | if (i2ccfg & 1) |
Jean Delvare | 66f8a8f | 2014-01-23 16:59:38 +0100 | [diff] [blame] | 348 | dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 349 | else |
Jean Delvare | 66f8a8f | 2014-01-23 16:59:38 +0100 | [diff] [blame] | 350 | dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 351 | |
| 352 | dev_info(&PIIX4_dev->dev, |
| 353 | "SMBus Host Controller at 0x%x, revision %d\n", |
| 354 | piix4_smba, i2ccfg >> 4); |
| 355 | |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 356 | /* Find which register is used for port selection */ |
| 357 | if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD) { |
Andrew Cooks | 625ee1a | 2019-08-02 14:52:46 +0200 | [diff] [blame^] | 358 | if (PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS || |
| 359 | (PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && |
| 360 | PIIX4_dev->revision >= 0x1F)) { |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 361 | piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_KERNCZ; |
| 362 | piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK_KERNCZ; |
| 363 | piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ; |
Andrew Cooks | 625ee1a | 2019-08-02 14:52:46 +0200 | [diff] [blame^] | 364 | } else { |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 365 | piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_ALT; |
| 366 | piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; |
| 367 | piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 368 | } |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 369 | } else { |
| 370 | mutex_lock(&piix4_mutex_sb800); |
| 371 | outb_p(SB800_PIIX4_PORT_IDX_SEL, SB800_PIIX4_SMB_IDX); |
| 372 | port_sel = inb_p(SB800_PIIX4_SMB_IDX + 1); |
| 373 | piix4_port_sel_sb800 = (port_sel & 0x01) ? |
| 374 | SB800_PIIX4_PORT_IDX_ALT : |
| 375 | SB800_PIIX4_PORT_IDX; |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 376 | piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; |
| 377 | piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 378 | mutex_unlock(&piix4_mutex_sb800); |
| 379 | } |
| 380 | |
| 381 | dev_info(&PIIX4_dev->dev, |
| 382 | "Using register 0x%02x for SMBus port selection\n", |
| 383 | (unsigned int)piix4_port_sel_sb800); |
| 384 | |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 385 | return piix4_smba; |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 388 | static int piix4_setup_aux(struct pci_dev *PIIX4_dev, |
| 389 | const struct pci_device_id *id, |
| 390 | unsigned short base_reg_addr) |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 391 | { |
| 392 | /* Set up auxiliary SMBus controllers found on some |
| 393 | * AMD chipsets e.g. SP5100 (SB700 derivative) */ |
| 394 | |
| 395 | unsigned short piix4_smba; |
| 396 | |
| 397 | /* Read address of auxiliary SMBus controller */ |
| 398 | pci_read_config_word(PIIX4_dev, base_reg_addr, &piix4_smba); |
| 399 | if ((piix4_smba & 1) == 0) { |
| 400 | dev_dbg(&PIIX4_dev->dev, |
| 401 | "Auxiliary SMBus controller not enabled\n"); |
| 402 | return -ENODEV; |
| 403 | } |
| 404 | |
| 405 | piix4_smba &= 0xfff0; |
| 406 | if (piix4_smba == 0) { |
| 407 | dev_dbg(&PIIX4_dev->dev, |
| 408 | "Auxiliary SMBus base address uninitialized\n"); |
| 409 | return -ENODEV; |
| 410 | } |
| 411 | |
| 412 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) |
| 413 | return -ENODEV; |
| 414 | |
| 415 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { |
| 416 | dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x " |
| 417 | "already in use!\n", piix4_smba); |
| 418 | return -EBUSY; |
| 419 | } |
| 420 | |
| 421 | dev_info(&PIIX4_dev->dev, |
| 422 | "Auxiliary SMBus Host Controller at 0x%x\n", |
| 423 | piix4_smba); |
| 424 | |
| 425 | return piix4_smba; |
| 426 | } |
| 427 | |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 428 | static int piix4_transaction(struct i2c_adapter *piix4_adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 430 | struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter); |
| 431 | unsigned short piix4_smba = adapdata->smba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | int temp; |
| 433 | int result = 0; |
| 434 | int timeout = 0; |
| 435 | |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 436 | dev_dbg(&piix4_adapter->dev, "Transaction (pre): CNT=%02x, CMD=%02x, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), |
| 438 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), |
| 439 | inb_p(SMBHSTDAT1)); |
| 440 | |
| 441 | /* Make sure the SMBus host is ready to start transmitting */ |
| 442 | if ((temp = inb_p(SMBHSTSTS)) != 0x00) { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 443 | dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). " |
Jean Delvare | 541e6a0 | 2005-06-23 22:18:08 +0200 | [diff] [blame] | 444 | "Resetting...\n", temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | outb_p(temp, SMBHSTSTS); |
| 446 | if ((temp = inb_p(SMBHSTSTS)) != 0x00) { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 447 | dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp); |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 448 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } else { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 450 | dev_dbg(&piix4_adapter->dev, "Successful!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | /* start the transaction by setting bit 6 */ |
| 455 | outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); |
| 456 | |
| 457 | /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ |
David Milburn | b1c1759 | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 458 | if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */ |
| 459 | msleep(2); |
| 460 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | msleep(1); |
David Milburn | b1c1759 | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 462 | |
Roel Kluin | b6a3195 | 2010-01-16 20:43:12 +0100 | [diff] [blame] | 463 | while ((++timeout < MAX_TIMEOUT) && |
David Milburn | b1c1759 | 2008-05-11 20:37:05 +0200 | [diff] [blame] | 464 | ((temp = inb_p(SMBHSTSTS)) & 0x01)) |
| 465 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | /* If the SMBus is still busy, we give up */ |
Roel Kluin | b6a3195 | 2010-01-16 20:43:12 +0100 | [diff] [blame] | 468 | if (timeout == MAX_TIMEOUT) { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 469 | dev_err(&piix4_adapter->dev, "SMBus Timeout!\n"); |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 470 | result = -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | if (temp & 0x10) { |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 474 | result = -EIO; |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 475 | dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | if (temp & 0x08) { |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 479 | result = -EIO; |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 480 | dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | "locked until next hard reset. (sorry!)\n"); |
| 482 | /* Clock stops and slave is stuck in mid-transmission */ |
| 483 | } |
| 484 | |
| 485 | if (temp & 0x04) { |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 486 | result = -ENXIO; |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 487 | dev_dbg(&piix4_adapter->dev, "Error: no response!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | if (inb_p(SMBHSTSTS) != 0x00) |
| 491 | outb_p(inb(SMBHSTSTS), SMBHSTSTS); |
| 492 | |
| 493 | if ((temp = inb_p(SMBHSTSTS)) != 0x00) { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 494 | dev_err(&piix4_adapter->dev, "Failed reset at end of " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | "transaction (%02x)\n", temp); |
| 496 | } |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 497 | dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), |
| 499 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), |
| 500 | inb_p(SMBHSTDAT1)); |
| 501 | return result; |
| 502 | } |
| 503 | |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 504 | /* Return negative errno on error. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | static s32 piix4_access(struct i2c_adapter * adap, u16 addr, |
| 506 | unsigned short flags, char read_write, |
| 507 | u8 command, int size, union i2c_smbus_data * data) |
| 508 | { |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 509 | struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); |
| 510 | unsigned short piix4_smba = adapdata->smba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | int i, len; |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 512 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | switch (size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | case I2C_SMBUS_QUICK: |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 516 | outb_p((addr << 1) | read_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | SMBHSTADD); |
| 518 | size = PIIX4_QUICK; |
| 519 | break; |
| 520 | case I2C_SMBUS_BYTE: |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 521 | outb_p((addr << 1) | read_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | SMBHSTADD); |
| 523 | if (read_write == I2C_SMBUS_WRITE) |
| 524 | outb_p(command, SMBHSTCMD); |
| 525 | size = PIIX4_BYTE; |
| 526 | break; |
| 527 | case I2C_SMBUS_BYTE_DATA: |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 528 | outb_p((addr << 1) | read_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | SMBHSTADD); |
| 530 | outb_p(command, SMBHSTCMD); |
| 531 | if (read_write == I2C_SMBUS_WRITE) |
| 532 | outb_p(data->byte, SMBHSTDAT0); |
| 533 | size = PIIX4_BYTE_DATA; |
| 534 | break; |
| 535 | case I2C_SMBUS_WORD_DATA: |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 536 | outb_p((addr << 1) | read_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | SMBHSTADD); |
| 538 | outb_p(command, SMBHSTCMD); |
| 539 | if (read_write == I2C_SMBUS_WRITE) { |
| 540 | outb_p(data->word & 0xff, SMBHSTDAT0); |
| 541 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); |
| 542 | } |
| 543 | size = PIIX4_WORD_DATA; |
| 544 | break; |
| 545 | case I2C_SMBUS_BLOCK_DATA: |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 546 | outb_p((addr << 1) | read_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | SMBHSTADD); |
| 548 | outb_p(command, SMBHSTCMD); |
| 549 | if (read_write == I2C_SMBUS_WRITE) { |
| 550 | len = data->block[0]; |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 551 | if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) |
| 552 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | outb_p(len, SMBHSTDAT0); |
Wolfram Sang | d7a4c76 | 2015-11-30 14:43:09 +0100 | [diff] [blame] | 554 | inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | for (i = 1; i <= len; i++) |
| 556 | outb_p(data->block[i], SMBBLKDAT); |
| 557 | } |
| 558 | size = PIIX4_BLOCK_DATA; |
| 559 | break; |
Jean Delvare | ac7fc4f | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 560 | default: |
| 561 | dev_warn(&adap->dev, "Unsupported transaction %d\n", size); |
| 562 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); |
| 566 | |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 567 | status = piix4_transaction(adap); |
David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 568 | if (status) |
| 569 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) |
| 572 | return 0; |
| 573 | |
| 574 | |
| 575 | switch (size) { |
Jean Delvare | 3578a07 | 2008-04-29 23:11:37 +0200 | [diff] [blame] | 576 | case PIIX4_BYTE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | case PIIX4_BYTE_DATA: |
| 578 | data->byte = inb_p(SMBHSTDAT0); |
| 579 | break; |
| 580 | case PIIX4_WORD_DATA: |
| 581 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); |
| 582 | break; |
| 583 | case PIIX4_BLOCK_DATA: |
| 584 | data->block[0] = inb_p(SMBHSTDAT0); |
Jean Delvare | fa63cd5 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 585 | if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX) |
| 586 | return -EPROTO; |
Wolfram Sang | d7a4c76 | 2015-11-30 14:43:09 +0100 | [diff] [blame] | 587 | inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | for (i = 1; i <= data->block[0]; i++) |
| 589 | data->block[i] = inb_p(SMBBLKDAT); |
| 590 | break; |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 595 | /* |
| 596 | * Handles access to multiple SMBus ports on the SB800. |
| 597 | * The port is selected by bits 2:1 of the smb_en register (0x2c). |
| 598 | * Returns negative errno on error. |
| 599 | * |
| 600 | * Note: The selected port must be returned to the initial selection to avoid |
| 601 | * problems on certain systems. |
| 602 | */ |
| 603 | static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, |
| 604 | unsigned short flags, char read_write, |
| 605 | u8 command, int size, union i2c_smbus_data *data) |
| 606 | { |
| 607 | struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); |
Ricardo Ribalda Delgado | 64e2368 | 2017-01-11 10:11:44 +0100 | [diff] [blame] | 608 | unsigned short piix4_smba = adapdata->smba; |
| 609 | int retries = MAX_TIMEOUT; |
| 610 | int smbslvcnt; |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 611 | u8 smba_en_lo; |
| 612 | u8 port; |
| 613 | int retval; |
| 614 | |
Ricardo Ribalda | c1a4306 | 2017-05-23 21:53:44 -0400 | [diff] [blame] | 615 | mutex_lock(&piix4_mutex_sb800); |
| 616 | |
Ricardo Ribalda Delgado | 64e2368 | 2017-01-11 10:11:44 +0100 | [diff] [blame] | 617 | /* Request the SMBUS semaphore, avoid conflicts with the IMC */ |
| 618 | smbslvcnt = inb_p(SMBSLVCNT); |
| 619 | do { |
| 620 | outb_p(smbslvcnt | 0x10, SMBSLVCNT); |
| 621 | |
| 622 | /* Check the semaphore status */ |
| 623 | smbslvcnt = inb_p(SMBSLVCNT); |
| 624 | if (smbslvcnt & 0x10) |
| 625 | break; |
| 626 | |
| 627 | usleep_range(1000, 2000); |
| 628 | } while (--retries); |
| 629 | /* SMBus is still owned by the IMC, we give up */ |
Ricardo Ribalda | c1a4306 | 2017-05-23 21:53:44 -0400 | [diff] [blame] | 630 | if (!retries) { |
| 631 | mutex_unlock(&piix4_mutex_sb800); |
Ricardo Ribalda Delgado | 64e2368 | 2017-01-11 10:11:44 +0100 | [diff] [blame] | 632 | return -EBUSY; |
Ricardo Ribalda | c1a4306 | 2017-05-23 21:53:44 -0400 | [diff] [blame] | 633 | } |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 634 | |
Jean Delvare | 6befa3f | 2016-02-17 10:26:35 +0100 | [diff] [blame] | 635 | outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX); |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 636 | smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); |
| 637 | |
| 638 | port = adapdata->port; |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 639 | if ((smba_en_lo & piix4_port_mask_sb800) != port) |
| 640 | outb_p((smba_en_lo & ~piix4_port_mask_sb800) | port, |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 641 | SB800_PIIX4_SMB_IDX + 1); |
| 642 | |
| 643 | retval = piix4_access(adap, addr, flags, read_write, |
| 644 | command, size, data); |
| 645 | |
| 646 | outb_p(smba_en_lo, SB800_PIIX4_SMB_IDX + 1); |
| 647 | |
Ricardo Ribalda Delgado | 64e2368 | 2017-01-11 10:11:44 +0100 | [diff] [blame] | 648 | /* Release the semaphore */ |
| 649 | outb_p(smbslvcnt | 0x20, SMBSLVCNT); |
| 650 | |
Ricardo Ribalda | c1a4306 | 2017-05-23 21:53:44 -0400 | [diff] [blame] | 651 | mutex_unlock(&piix4_mutex_sb800); |
| 652 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 653 | return retval; |
| 654 | } |
| 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | static u32 piix4_func(struct i2c_adapter *adapter) |
| 657 | { |
| 658 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
| 659 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | |
| 660 | I2C_FUNC_SMBUS_BLOCK_DATA; |
| 661 | } |
| 662 | |
Jean Delvare | 8f9082c | 2006-09-03 22:39:46 +0200 | [diff] [blame] | 663 | static const struct i2c_algorithm smbus_algorithm = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | .smbus_xfer = piix4_access, |
| 665 | .functionality = piix4_func, |
| 666 | }; |
| 667 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 668 | static const struct i2c_algorithm piix4_smbus_algorithm_sb800 = { |
| 669 | .smbus_xfer = piix4_access_sb800, |
| 670 | .functionality = piix4_func, |
| 671 | }; |
| 672 | |
Jingoo Han | 392debf | 2013-12-03 08:11:20 +0900 | [diff] [blame] | 673 | static const struct pci_device_id piix4_ids[] = { |
Jean Delvare | 9b7389c | 2008-01-27 18:14:51 +0100 | [diff] [blame] | 674 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, |
| 675 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, |
| 676 | { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, |
| 677 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) }, |
| 678 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, |
| 679 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, |
| 680 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, |
Crane Cai | 3806e94b | 2009-11-07 13:10:46 +0100 | [diff] [blame] | 681 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) }, |
Vincent Wan | bcb2999 | 2015-06-11 20:11:46 +0800 | [diff] [blame] | 682 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) }, |
Jean Delvare | 9b7389c | 2008-01-27 18:14:51 +0100 | [diff] [blame] | 683 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
| 684 | PCI_DEVICE_ID_SERVERWORKS_OSB4) }, |
| 685 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
| 686 | PCI_DEVICE_ID_SERVERWORKS_CSB5) }, |
| 687 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
| 688 | PCI_DEVICE_ID_SERVERWORKS_CSB6) }, |
| 689 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
| 690 | PCI_DEVICE_ID_SERVERWORKS_HT1000SB) }, |
Flavio Leitner | 506a8b6 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 691 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
| 692 | PCI_DEVICE_ID_SERVERWORKS_HT1100LD) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | { 0, } |
| 694 | }; |
| 695 | |
| 696 | MODULE_DEVICE_TABLE (pci, piix4_ids); |
| 697 | |
Christian Fetzer | ca2061e | 2015-11-19 20:13:47 +0100 | [diff] [blame] | 698 | static struct i2c_adapter *piix4_main_adapters[PIIX4_MAX_ADAPTERS]; |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 699 | static struct i2c_adapter *piix4_aux_adapter; |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 700 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 701 | static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba, |
Jean Delvare | 62194e8 | 2016-01-29 10:45:30 +0100 | [diff] [blame] | 702 | bool sb800_main, u8 port, |
Christian Fetzer | 725d2e3 | 2015-11-19 20:13:49 +0100 | [diff] [blame] | 703 | const char *name, struct i2c_adapter **padap) |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 704 | { |
| 705 | struct i2c_adapter *adap; |
| 706 | struct i2c_piix4_adapdata *adapdata; |
| 707 | int retval; |
| 708 | |
| 709 | adap = kzalloc(sizeof(*adap), GFP_KERNEL); |
| 710 | if (adap == NULL) { |
| 711 | release_region(smba, SMBIOSIZE); |
| 712 | return -ENOMEM; |
| 713 | } |
| 714 | |
| 715 | adap->owner = THIS_MODULE; |
| 716 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
Jean Delvare | 83c6015 | 2016-01-25 12:17:07 +0100 | [diff] [blame] | 717 | adap->algo = sb800_main ? &piix4_smbus_algorithm_sb800 |
| 718 | : &smbus_algorithm; |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 719 | |
| 720 | adapdata = kzalloc(sizeof(*adapdata), GFP_KERNEL); |
| 721 | if (adapdata == NULL) { |
| 722 | kfree(adap); |
| 723 | release_region(smba, SMBIOSIZE); |
| 724 | return -ENOMEM; |
| 725 | } |
| 726 | |
| 727 | adapdata->smba = smba; |
Jean Delvare | 83c6015 | 2016-01-25 12:17:07 +0100 | [diff] [blame] | 728 | adapdata->sb800_main = sb800_main; |
Guenter Roeck | 717ef37d | 2017-07-15 16:51:26 -0700 | [diff] [blame] | 729 | adapdata->port = port << piix4_port_shift_sb800; |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 730 | |
| 731 | /* set up the sysfs linkage to our parent device */ |
| 732 | adap->dev.parent = &dev->dev; |
| 733 | |
| 734 | snprintf(adap->name, sizeof(adap->name), |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 735 | "SMBus PIIX4 adapter%s at %04x", name, smba); |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 736 | |
| 737 | i2c_set_adapdata(adap, adapdata); |
| 738 | |
| 739 | retval = i2c_add_adapter(adap); |
| 740 | if (retval) { |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 741 | kfree(adapdata); |
| 742 | kfree(adap); |
| 743 | release_region(smba, SMBIOSIZE); |
| 744 | return retval; |
| 745 | } |
| 746 | |
| 747 | *padap = adap; |
| 748 | return 0; |
| 749 | } |
| 750 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 751 | static int piix4_add_adapters_sb800(struct pci_dev *dev, unsigned short smba) |
| 752 | { |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 753 | struct i2c_piix4_adapdata *adapdata; |
| 754 | int port; |
| 755 | int retval; |
| 756 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 757 | for (port = 0; port < PIIX4_MAX_ADAPTERS; port++) { |
Jean Delvare | 83c6015 | 2016-01-25 12:17:07 +0100 | [diff] [blame] | 758 | retval = piix4_add_adapter(dev, smba, true, port, |
Christian Fetzer | 725d2e3 | 2015-11-19 20:13:49 +0100 | [diff] [blame] | 759 | piix4_main_port_names_sb800[port], |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 760 | &piix4_main_adapters[port]); |
| 761 | if (retval < 0) |
| 762 | goto error; |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | return retval; |
| 766 | |
| 767 | error: |
| 768 | dev_err(&dev->dev, |
| 769 | "Error setting up SB800 adapters. Unregistering!\n"); |
| 770 | while (--port >= 0) { |
| 771 | adapdata = i2c_get_adapdata(piix4_main_adapters[port]); |
| 772 | if (adapdata->smba) { |
| 773 | i2c_del_adapter(piix4_main_adapters[port]); |
| 774 | kfree(adapdata); |
| 775 | kfree(piix4_main_adapters[port]); |
| 776 | piix4_main_adapters[port] = NULL; |
| 777 | } |
| 778 | } |
| 779 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 780 | return retval; |
| 781 | } |
| 782 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 783 | static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
| 785 | int retval; |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 786 | bool is_sb800 = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Crane Cai | 76b3e28 | 2009-09-18 22:45:50 +0200 | [diff] [blame] | 788 | if ((dev->vendor == PCI_VENDOR_ID_ATI && |
| 789 | dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && |
| 790 | dev->revision >= 0x40) || |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 791 | dev->vendor == PCI_VENDOR_ID_AMD) { |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 792 | is_sb800 = true; |
| 793 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 794 | if (!request_region(SB800_PIIX4_SMB_IDX, 2, "smba_idx")) { |
| 795 | dev_err(&dev->dev, |
| 796 | "SMBus base address index region 0x%x already in use!\n", |
| 797 | SB800_PIIX4_SMB_IDX); |
| 798 | return -EBUSY; |
| 799 | } |
| 800 | |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 801 | /* base address location etc changed in SB800 */ |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 802 | retval = piix4_setup_sb800(dev, id, 0); |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 803 | if (retval < 0) { |
| 804 | release_region(SB800_PIIX4_SMB_IDX, 2); |
| 805 | return retval; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * Try to register multiplexed main SMBus adapter, |
| 810 | * give up if we can't |
| 811 | */ |
| 812 | retval = piix4_add_adapters_sb800(dev, retval); |
| 813 | if (retval < 0) { |
| 814 | release_region(SB800_PIIX4_SMB_IDX, 2); |
| 815 | return retval; |
| 816 | } |
| 817 | } else { |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 818 | retval = piix4_setup(dev, id); |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 819 | if (retval < 0) |
| 820 | return retval; |
Shane Huang | 87e1960 | 2009-03-28 21:34:46 +0100 | [diff] [blame] | 821 | |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 822 | /* Try to register main SMBus adapter, give up if we can't */ |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 823 | retval = piix4_add_adapter(dev, retval, false, 0, "", |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 824 | &piix4_main_adapters[0]); |
| 825 | if (retval < 0) |
| 826 | return retval; |
| 827 | } |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 828 | |
| 829 | /* Check for auxiliary SMBus on some AMD chipsets */ |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 830 | retval = -ENODEV; |
| 831 | |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 832 | if (dev->vendor == PCI_VENDOR_ID_ATI && |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 833 | dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) { |
| 834 | if (dev->revision < 0x40) { |
| 835 | retval = piix4_setup_aux(dev, id, 0x58); |
| 836 | } else { |
| 837 | /* SB800 added aux bus too */ |
| 838 | retval = piix4_setup_sb800(dev, id, 1); |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 842 | if (dev->vendor == PCI_VENDOR_ID_AMD && |
| 843 | dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) { |
| 844 | retval = piix4_setup_sb800(dev, id, 1); |
| 845 | } |
| 846 | |
| 847 | if (retval > 0) { |
| 848 | /* Try to add the aux adapter if it exists, |
| 849 | * piix4_add_adapter will clean up if this fails */ |
Jean Delvare | 83c6015 | 2016-01-25 12:17:07 +0100 | [diff] [blame] | 850 | piix4_add_adapter(dev, retval, false, 0, |
Jean Delvare | 52795f6 | 2016-01-27 14:40:33 +0100 | [diff] [blame] | 851 | is_sb800 ? piix4_aux_port_name_sb800 : "", |
Christian Fetzer | 725d2e3 | 2015-11-19 20:13:49 +0100 | [diff] [blame] | 852 | &piix4_aux_adapter); |
Rudolf Marek | a94dd00 | 2013-07-14 23:17:26 +0200 | [diff] [blame] | 853 | } |
| 854 | |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 855 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 858 | static void piix4_adap_remove(struct i2c_adapter *adap) |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 859 | { |
| 860 | struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); |
| 861 | |
| 862 | if (adapdata->smba) { |
| 863 | i2c_del_adapter(adap); |
Jean Delvare | 33f5ccc | 2016-01-29 10:46:37 +0100 | [diff] [blame] | 864 | if (adapdata->port == (0 << 1)) { |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 865 | release_region(adapdata->smba, SMBIOSIZE); |
Jean Delvare | a28e351 | 2016-01-22 14:12:02 +0100 | [diff] [blame] | 866 | if (adapdata->sb800_main) |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 867 | release_region(SB800_PIIX4_SMB_IDX, 2); |
Christian Fetzer | 2fee61d | 2015-11-19 20:13:48 +0100 | [diff] [blame] | 868 | } |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 869 | kfree(adapdata); |
| 870 | kfree(adap); |
Andrew Armenia | 14a8086 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 874 | static void piix4_remove(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
Christian Fetzer | ca2061e | 2015-11-19 20:13:47 +0100 | [diff] [blame] | 876 | int port = PIIX4_MAX_ADAPTERS; |
| 877 | |
| 878 | while (--port >= 0) { |
| 879 | if (piix4_main_adapters[port]) { |
| 880 | piix4_adap_remove(piix4_main_adapters[port]); |
| 881 | piix4_main_adapters[port] = NULL; |
| 882 | } |
Andrew Armenia | e154bf6 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 883 | } |
Andrew Armenia | 2a2f740 | 2012-07-24 14:13:57 +0200 | [diff] [blame] | 884 | |
| 885 | if (piix4_aux_adapter) { |
| 886 | piix4_adap_remove(piix4_aux_adapter); |
| 887 | piix4_aux_adapter = NULL; |
| 888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | static struct pci_driver piix4_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | .name = "piix4_smbus", |
| 893 | .id_table = piix4_ids, |
| 894 | .probe = piix4_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 895 | .remove = piix4_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | }; |
| 897 | |
Axel Lin | 56f2178 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 898 | module_pci_driver(piix4_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " |
| 901 | "Philip Edelbrock <phil@netroedge.com>"); |
| 902 | MODULE_DESCRIPTION("PIIX4 SMBus driver"); |
| 903 | MODULE_LICENSE("GPL"); |