| 1 | /* |
|---|
| 2 | i801.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, |
|---|
| 5 | Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker |
|---|
| 6 | <mdsxyz123@yahoo.com> |
|---|
| 7 | |
|---|
| 8 | This program is free software; you can redistribute it and/or modify |
|---|
| 9 | it under the terms of the GNU General Public License as published by |
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | (at your option) any later version. |
|---|
| 12 | |
|---|
| 13 | This program is distributed in the hope that it will be useful, |
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | GNU General Public License for more details. |
|---|
| 17 | |
|---|
| 18 | You should have received a copy of the GNU General Public License |
|---|
| 19 | along with this program; if not, write to the Free Software |
|---|
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | /* |
|---|
| 24 | SUPPORTED DEVICES PCI ID |
|---|
| 25 | 82801AA 2413 |
|---|
| 26 | 82801AB 2423 |
|---|
| 27 | 82801BA 2443 |
|---|
| 28 | 82801CA/CAM 2483 |
|---|
| 29 | 82801DB 24C3 (HW PEC supported, 32 byte buffer not supported) |
|---|
| 30 | 82801EB 24D3 (HW PEC supported, 32 byte buffer not supported) |
|---|
| 31 | 6300ESB 25A4 ("") |
|---|
| 32 | ICH6 266A ("") |
|---|
| 33 | ICH7 27DA ("") |
|---|
| 34 | ESB2 269B ("") |
|---|
| 35 | This driver supports several versions of Intel's I/O Controller Hubs (ICH). |
|---|
| 36 | For SMBus support, they are similar to the PIIX4 and are part |
|---|
| 37 | of Intel's '810' and other chipsets. |
|---|
| 38 | See the doc/busses/i2c-i801 file for details. |
|---|
| 39 | I2C Block Read supported for ICH5 and higher. |
|---|
| 40 | Block Process Call are not supported. |
|---|
| 41 | */ |
|---|
| 42 | |
|---|
| 43 | /* Note: we assume there can only be one I801, with one SMBus interface */ |
|---|
| 44 | |
|---|
| 45 | /* #define DEBUG 1 */ |
|---|
| 46 | |
|---|
| 47 | #include <linux/module.h> |
|---|
| 48 | #include <linux/pci.h> |
|---|
| 49 | #include <linux/kernel.h> |
|---|
| 50 | #include <linux/stddef.h> |
|---|
| 51 | #include <linux/sched.h> |
|---|
| 52 | #include <linux/ioport.h> |
|---|
| 53 | #include <linux/init.h> |
|---|
| 54 | #include <linux/i2c.h> |
|---|
| 55 | #include <asm/io.h> |
|---|
| 56 | #include "version.h" |
|---|
| 57 | #include "sensors_compat.h" |
|---|
| 58 | |
|---|
| 59 | /* 82801CA is undefined before kernel 2.4.13 */ |
|---|
| 60 | #ifndef PCI_DEVICE_ID_INTEL_82801CA_3 |
|---|
| 61 | #define PCI_DEVICE_ID_INTEL_82801CA_3 0x2483 |
|---|
| 62 | #endif |
|---|
| 63 | |
|---|
| 64 | /* 82801DB is undefined before kernel 2.4.19 */ |
|---|
| 65 | #ifndef PCI_DEVICE_ID_INTEL_82801DB_3 |
|---|
| 66 | #define PCI_DEVICE_ID_INTEL_82801DB_3 0x24c3 |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | /* 82801EB is undefined before kernel 2.4.21 */ |
|---|
| 70 | #ifndef PCI_DEVICE_ID_INTEL_82801EB_3 |
|---|
| 71 | #define PCI_DEVICE_ID_INTEL_82801EB_3 0x24d3 |
|---|
| 72 | #endif |
|---|
| 73 | |
|---|
| 74 | /* ESB is undefined before kernel 2.4.22 */ |
|---|
| 75 | #ifndef PCI_DEVICE_ID_INTEL_ESB_4 |
|---|
| 76 | #define PCI_DEVICE_ID_INTEL_ESB_4 0x25a4 |
|---|
| 77 | #endif |
|---|
| 78 | |
|---|
| 79 | /* ESB2 - Enterprise Southbridge is undefined */ |
|---|
| 80 | #ifndef PCI_DEVICE_ID_INTEL_ESB2_17 |
|---|
| 81 | #define PCI_DEVICE_ID_INTEL_ESB2_17 0x269b |
|---|
| 82 | #endif |
|---|
| 83 | |
|---|
| 84 | /* ICH6 is undefined */ |
|---|
| 85 | #ifndef PCI_DEVICE_ID_INTEL_ICH6_16 |
|---|
| 86 | #define PCI_DEVICE_ID_INTEL_ICH6_16 0x266a |
|---|
| 87 | #endif |
|---|
| 88 | |
|---|
| 89 | /* ICH7 is undefined */ |
|---|
| 90 | #ifndef PCI_DEVICE_ID_INTEL_ICH7_17 |
|---|
| 91 | #define PCI_DEVICE_ID_INTEL_ICH7_17 0x27da |
|---|
| 92 | #endif |
|---|
| 93 | |
|---|
| 94 | #ifdef I2C_CLIENT_PEC |
|---|
| 95 | #define HAVE_PEC |
|---|
| 96 | #endif |
|---|
| 97 | |
|---|
| 98 | /* I801 SMBus address offsets */ |
|---|
| 99 | #define SMBHSTSTS (0 + i801_smba) |
|---|
| 100 | #define SMBHSTCNT (2 + i801_smba) |
|---|
| 101 | #define SMBHSTCMD (3 + i801_smba) |
|---|
| 102 | #define SMBHSTADD (4 + i801_smba) |
|---|
| 103 | #define SMBHSTDAT0 (5 + i801_smba) |
|---|
| 104 | #define SMBHSTDAT1 (6 + i801_smba) |
|---|
| 105 | #define SMBBLKDAT (7 + i801_smba) |
|---|
| 106 | #define SMBPEC (8 + i801_smba) /* ICH4 only */ |
|---|
| 107 | #define SMBAUXSTS (12 + i801_smba) /* ICH4 only */ |
|---|
| 108 | #define SMBAUXCTL (13 + i801_smba) /* ICH4 only */ |
|---|
| 109 | |
|---|
| 110 | /* PCI Address Constants */ |
|---|
| 111 | #define SMBBA 0x020 |
|---|
| 112 | #define SMBHSTCFG 0x040 |
|---|
| 113 | #define SMBREV 0x008 |
|---|
| 114 | |
|---|
| 115 | /* Host configuration bits for SMBHSTCFG */ |
|---|
| 116 | #define SMBHSTCFG_HST_EN 1 |
|---|
| 117 | #define SMBHSTCFG_SMB_SMI_EN 2 |
|---|
| 118 | #define SMBHSTCFG_I2C_EN 4 |
|---|
| 119 | |
|---|
| 120 | /* Other settings */ |
|---|
| 121 | #define MAX_TIMEOUT 100 |
|---|
| 122 | #define ENABLE_INT9 0 /* set to 0x01 to enable - untested */ |
|---|
| 123 | |
|---|
| 124 | /* I801 command constants */ |
|---|
| 125 | #define I801_QUICK 0x00 |
|---|
| 126 | #define I801_BYTE 0x04 |
|---|
| 127 | #define I801_BYTE_DATA 0x08 |
|---|
| 128 | #define I801_WORD_DATA 0x0C |
|---|
| 129 | #define I801_PROC_CALL 0x10 /* later chips only, unimplemented */ |
|---|
| 130 | #define I801_BLOCK_DATA 0x14 |
|---|
| 131 | #define I801_I2C_BLOCK_DATA 0x18 /* ich4 and later */ |
|---|
| 132 | #define I801_BLOCK_LAST 0x34 |
|---|
| 133 | #define I801_I2C_BLOCK_LAST 0x38 /* unimplemented */ |
|---|
| 134 | #define I801_START 0x40 |
|---|
| 135 | #define I801_PEC_EN 0x80 /* ich4 and later */ |
|---|
| 136 | |
|---|
| 137 | /* insmod parameters */ |
|---|
| 138 | |
|---|
| 139 | /* If force_addr is set to anything different from 0, we forcibly enable |
|---|
| 140 | the I801 at the given address. VERY DANGEROUS! */ |
|---|
| 141 | static int force_addr = 0; |
|---|
| 142 | MODULE_PARM(force_addr, "i"); |
|---|
| 143 | MODULE_PARM_DESC(force_addr, |
|---|
| 144 | "Forcibly enable the I801 at the given address. " |
|---|
| 145 | "EXTREMELY DANGEROUS!"); |
|---|
| 146 | |
|---|
| 147 | static int i801_transaction(void); |
|---|
| 148 | static int i801_block_transaction(union i2c_smbus_data *data, char read_write, |
|---|
| 149 | int command, int hwpec); |
|---|
| 150 | |
|---|
| 151 | static unsigned short i801_smba; |
|---|
| 152 | static struct pci_driver i801_driver; |
|---|
| 153 | static struct pci_dev *I801_dev; |
|---|
| 154 | static int isich4; /* is PEC supported? */ |
|---|
| 155 | static int isich5; /* is i2c block read supported? */ |
|---|
| 156 | |
|---|
| 157 | static int i801_setup(struct pci_dev *dev) |
|---|
| 158 | { |
|---|
| 159 | int error_return = 0; |
|---|
| 160 | unsigned char temp; |
|---|
| 161 | |
|---|
| 162 | /* Note: we keep on searching until we have found 'function 3' */ |
|---|
| 163 | if(PCI_FUNC(dev->devfn) != 3) |
|---|
| 164 | return -ENODEV; |
|---|
| 165 | |
|---|
| 166 | I801_dev = dev; |
|---|
| 167 | if (dev->device == PCI_DEVICE_ID_INTEL_82801DB_3 || |
|---|
| 168 | dev->device == PCI_DEVICE_ID_INTEL_82801EB_3 || |
|---|
| 169 | dev->device == PCI_DEVICE_ID_INTEL_ESB_4 || |
|---|
| 170 | dev->device == PCI_DEVICE_ID_INTEL_ESB2_17 || |
|---|
| 171 | dev->device == PCI_DEVICE_ID_INTEL_ICH6_16 || |
|---|
| 172 | dev->device == PCI_DEVICE_ID_INTEL_ICH7_17) |
|---|
| 173 | isich4 = 1; |
|---|
| 174 | else |
|---|
| 175 | isich4 = 0; |
|---|
| 176 | isich5 = isich4 && dev->device != PCI_DEVICE_ID_INTEL_82801DB_3; |
|---|
| 177 | |
|---|
| 178 | /* Determine the address of the SMBus areas */ |
|---|
| 179 | if (force_addr) { |
|---|
| 180 | i801_smba = force_addr & 0xfff0; |
|---|
| 181 | } else { |
|---|
| 182 | pci_read_config_word(I801_dev, SMBBA, &i801_smba); |
|---|
| 183 | i801_smba &= 0xfff0; |
|---|
| 184 | if(i801_smba == 0) { |
|---|
| 185 | dev_err(dev, "SMB base address uninitialized " |
|---|
| 186 | "- upgrade BIOS or use force_addr=0xaddr\n"); |
|---|
| 187 | return -ENODEV; |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | if (!request_region(i801_smba, (isich4 ? 16 : 8), i801_driver.name)) { |
|---|
| 192 | dev_err(dev, "I801_smb region 0x%x already in use!\n", |
|---|
| 193 | i801_smba); |
|---|
| 194 | error_return = -EBUSY; |
|---|
| 195 | goto END; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); |
|---|
| 199 | temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ |
|---|
| 200 | pci_write_config_byte(I801_dev, SMBHSTCFG, temp); |
|---|
| 201 | |
|---|
| 202 | /* If force_addr is set, we program the new address here. Just to make |
|---|
| 203 | sure, we disable the device first. */ |
|---|
| 204 | if (force_addr) { |
|---|
| 205 | pci_write_config_byte(I801_dev, SMBHSTCFG, temp & 0xfe); |
|---|
| 206 | pci_write_config_word(I801_dev, SMBBA, i801_smba); |
|---|
| 207 | pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 0x01); |
|---|
| 208 | dev_warn(dev, "WARNING: I801 SMBus interface set to " |
|---|
| 209 | "new address %04x!\n", i801_smba); |
|---|
| 210 | } else if ((temp & 1) == 0) { |
|---|
| 211 | pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 1); |
|---|
| 212 | dev_warn(dev, "enabling SMBus device\n"); |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | if (temp & 0x02) |
|---|
| 216 | dev_dbg(dev, "I801 using Interrupt SMI# for SMBus.\n"); |
|---|
| 217 | else |
|---|
| 218 | dev_dbg(dev, "I801 using PCI Interrupt for SMBus.\n"); |
|---|
| 219 | |
|---|
| 220 | pci_read_config_byte(I801_dev, SMBREV, &temp); |
|---|
| 221 | dev_dbg(dev, "SMBREV = 0x%X\n", temp); |
|---|
| 222 | dev_dbg(dev, "I801_smba = 0x%X\n", i801_smba); |
|---|
| 223 | |
|---|
| 224 | END: |
|---|
| 225 | return error_return; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | static int i801_transaction(void) |
|---|
| 230 | { |
|---|
| 231 | int temp; |
|---|
| 232 | int result = 0; |
|---|
| 233 | int timeout = 0; |
|---|
| 234 | |
|---|
| 235 | dev_dbg(I801_dev, "Transaction (pre): CNT=%02x, CMD=%02x, " |
|---|
| 236 | "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), |
|---|
| 237 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), |
|---|
| 238 | inb_p(SMBHSTDAT1)); |
|---|
| 239 | |
|---|
| 240 | /* Make sure the SMBus host is ready to start transmitting */ |
|---|
| 241 | /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ |
|---|
| 242 | if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { |
|---|
| 243 | dev_dbg(I801_dev, "SMBus busy (%02x). Resetting...\n", |
|---|
| 244 | temp); |
|---|
| 245 | outb_p(temp, SMBHSTSTS); |
|---|
| 246 | if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { |
|---|
| 247 | dev_dbg(I801_dev, "Failed! (%02x)\n", temp); |
|---|
| 248 | return -1; |
|---|
| 249 | } else { |
|---|
| 250 | dev_dbg(I801_dev, "Successfull!\n"); |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); |
|---|
| 255 | |
|---|
| 256 | /* We will always wait for a fraction of a second! */ |
|---|
| 257 | do { |
|---|
| 258 | i2c_delay(1); |
|---|
| 259 | temp = inb_p(SMBHSTSTS); |
|---|
| 260 | } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); |
|---|
| 261 | |
|---|
| 262 | /* If the SMBus is still busy, we give up */ |
|---|
| 263 | if (timeout >= MAX_TIMEOUT) { |
|---|
| 264 | dev_dbg(I801_dev, "SMBus Timeout!\n"); |
|---|
| 265 | result = -1; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | if (temp & 0x10) { |
|---|
| 269 | result = -1; |
|---|
| 270 | dev_dbg(I801_dev, "Error: Failed bus transaction\n"); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if (temp & 0x08) { |
|---|
| 274 | result = -1; |
|---|
| 275 | dev_err(I801_dev, "Bus collision! SMBus may be locked " |
|---|
| 276 | "until next hard reset. (sorry!)\n"); |
|---|
| 277 | /* Clock stops and slave is stuck in mid-transmission */ |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | if (temp & 0x04) { |
|---|
| 281 | result = -1; |
|---|
| 282 | dev_dbg(I801_dev, "Error: no response!\n"); |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00) |
|---|
| 286 | outb_p(inb(SMBHSTSTS), SMBHSTSTS); |
|---|
| 287 | |
|---|
| 288 | if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { |
|---|
| 289 | dev_dbg(I801_dev, "Failed reset at end of transaction " |
|---|
| 290 | "(%02x)\n", temp); |
|---|
| 291 | } |
|---|
| 292 | dev_dbg(I801_dev, "Transaction (post): CNT=%02x, CMD=%02x, " |
|---|
| 293 | "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), |
|---|
| 294 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), |
|---|
| 295 | inb_p(SMBHSTDAT1)); |
|---|
| 296 | return result; |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | /* All-inclusive block transaction function */ |
|---|
| 300 | static int i801_block_transaction(union i2c_smbus_data *data, char read_write, |
|---|
| 301 | int command, int hwpec) |
|---|
| 302 | { |
|---|
| 303 | int i, len; |
|---|
| 304 | int smbcmd; |
|---|
| 305 | int temp; |
|---|
| 306 | int result = 0; |
|---|
| 307 | int timeout; |
|---|
| 308 | unsigned char hostc, errmask; |
|---|
| 309 | |
|---|
| 310 | if (command == I2C_SMBUS_I2C_BLOCK_DATA) { |
|---|
| 311 | if (read_write == I2C_SMBUS_WRITE) { |
|---|
| 312 | /* set I2C_EN bit in configuration register */ |
|---|
| 313 | pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc); |
|---|
| 314 | pci_write_config_byte(I801_dev, SMBHSTCFG, |
|---|
| 315 | hostc | SMBHSTCFG_I2C_EN); |
|---|
| 316 | } else if (!isich5) { |
|---|
| 317 | dev_err(I801_dev, |
|---|
| 318 | "I2C_SMBUS_I2C_BLOCK_READ unsupported!\n"); |
|---|
| 319 | return -1; |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | if (read_write == I2C_SMBUS_WRITE) { |
|---|
| 324 | len = data->block[0]; |
|---|
| 325 | if (len < 1) |
|---|
| 326 | len = 1; |
|---|
| 327 | if (len > 32) |
|---|
| 328 | len = 32; |
|---|
| 329 | outb_p(len, SMBHSTDAT0); |
|---|
| 330 | outb_p(data->block[1], SMBBLKDAT); |
|---|
| 331 | } else { |
|---|
| 332 | len = 32; /* max for reads */ |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | if(isich4 && command != I2C_SMBUS_I2C_BLOCK_DATA) { |
|---|
| 336 | /* set 32 byte buffer */ |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | for (i = 1; i <= len; i++) { |
|---|
| 340 | if (i == len && read_write == I2C_SMBUS_READ) |
|---|
| 341 | smbcmd = I801_BLOCK_LAST; |
|---|
| 342 | else if (command == I2C_SMBUS_I2C_BLOCK_DATA && |
|---|
| 343 | read_write == I2C_SMBUS_READ) |
|---|
| 344 | smbcmd = I801_I2C_BLOCK_DATA; |
|---|
| 345 | else |
|---|
| 346 | smbcmd = I801_BLOCK_DATA; |
|---|
| 347 | outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); |
|---|
| 348 | |
|---|
| 349 | dev_dbg(I801_dev, "Block (pre %d): CNT=%02x, CMD=%02x, " |
|---|
| 350 | "ADD=%02x, DAT0=%02x, BLKDAT=%02x\n", i, |
|---|
| 351 | inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD), |
|---|
| 352 | inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT)); |
|---|
| 353 | |
|---|
| 354 | /* Make sure the SMBus host is ready to start transmitting */ |
|---|
| 355 | temp = inb_p(SMBHSTSTS); |
|---|
| 356 | if (i == 1) { |
|---|
| 357 | /* Erronenous conditions before transaction: |
|---|
| 358 | * Byte_Done, Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ |
|---|
| 359 | errmask=0x9f; |
|---|
| 360 | } else { |
|---|
| 361 | /* Erronenous conditions during transaction: |
|---|
| 362 | * Failed, Bus_Err, Dev_Err, Intr */ |
|---|
| 363 | errmask=0x1e; |
|---|
| 364 | } |
|---|
| 365 | if (temp & errmask) { |
|---|
| 366 | dev_dbg(I801_dev, "SMBus busy (%02x). " |
|---|
| 367 | "Resetting...\n", temp); |
|---|
| 368 | outb_p(temp, SMBHSTSTS); |
|---|
| 369 | if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { |
|---|
| 370 | dev_err(I801_dev, |
|---|
| 371 | "Reset failed! (%02x)\n", temp); |
|---|
| 372 | result = -1; |
|---|
| 373 | goto END; |
|---|
| 374 | } |
|---|
| 375 | if (i != 1) { |
|---|
| 376 | /* if die in middle of block transaction, fail */ |
|---|
| 377 | result = -1; |
|---|
| 378 | goto END; |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | if (i == 1) |
|---|
| 383 | outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); |
|---|
| 384 | |
|---|
| 385 | /* We will always wait for a fraction of a second! */ |
|---|
| 386 | timeout = 0; |
|---|
| 387 | do { |
|---|
| 388 | temp = inb_p(SMBHSTSTS); |
|---|
| 389 | i2c_delay(1); |
|---|
| 390 | } |
|---|
| 391 | while ((!(temp & 0x80)) |
|---|
| 392 | && (timeout++ < MAX_TIMEOUT)); |
|---|
| 393 | |
|---|
| 394 | /* If the SMBus is still busy, we give up */ |
|---|
| 395 | if (timeout >= MAX_TIMEOUT) { |
|---|
| 396 | result = -1; |
|---|
| 397 | dev_dbg(I801_dev, "SMBus Timeout!\n"); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | if (temp & 0x10) { |
|---|
| 401 | result = -1; |
|---|
| 402 | dev_dbg(I801_dev, |
|---|
| 403 | "Error: Failed bus transaction\n"); |
|---|
| 404 | } else if (temp & 0x08) { |
|---|
| 405 | result = -1; |
|---|
| 406 | dev_err(I801_dev, "Bus collision!\n"); |
|---|
| 407 | } else if (temp & 0x04) { |
|---|
| 408 | result = -1; |
|---|
| 409 | dev_dbg(I801_dev, "Error: no response!\n"); |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | if (i == 1 && read_write == I2C_SMBUS_READ) { |
|---|
| 413 | if (command != I2C_SMBUS_I2C_BLOCK_DATA) { |
|---|
| 414 | len = inb_p(SMBHSTDAT0); |
|---|
| 415 | if (len < 1) |
|---|
| 416 | len = 1; |
|---|
| 417 | if (len > 32) |
|---|
| 418 | len = 32; |
|---|
| 419 | data->block[0] = len; |
|---|
| 420 | } else { |
|---|
| 421 | /* if slave returns < 32 bytes transaction will fail */ |
|---|
| 422 | data->block[0] = 32; |
|---|
| 423 | } |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | /* Retrieve/store value in SMBBLKDAT */ |
|---|
| 427 | if (read_write == I2C_SMBUS_READ) |
|---|
| 428 | data->block[i] = inb_p(SMBBLKDAT); |
|---|
| 429 | if (read_write == I2C_SMBUS_WRITE && i+1 <= len) |
|---|
| 430 | outb_p(data->block[i+1], SMBBLKDAT); |
|---|
| 431 | if ((temp & 0x9e) != 0x00) |
|---|
| 432 | outb_p(temp, SMBHSTSTS); /* signals SMBBLKDAT ready */ |
|---|
| 433 | |
|---|
| 434 | if ((temp = (0x1e & inb_p(SMBHSTSTS))) != 0x00) { |
|---|
| 435 | dev_dbg(I801_dev, |
|---|
| 436 | "Bad status (%02x) at end of transaction\n", |
|---|
| 437 | temp); |
|---|
| 438 | } |
|---|
| 439 | dev_dbg(I801_dev, "Block (post %d): CNT=%02x, CMD=%02x, " |
|---|
| 440 | "ADD=%02x, DAT0=%02x, BLKDAT=%02x\n", i, |
|---|
| 441 | inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD), |
|---|
| 442 | inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT)); |
|---|
| 443 | |
|---|
| 444 | if (result < 0) |
|---|
| 445 | goto END; |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | if (hwpec) { |
|---|
| 449 | /* wait for INTR bit as advised by Intel */ |
|---|
| 450 | timeout = 0; |
|---|
| 451 | do { |
|---|
| 452 | temp = inb_p(SMBHSTSTS); |
|---|
| 453 | i2c_delay(1); |
|---|
| 454 | } while ((!(temp & 0x02)) |
|---|
| 455 | && (timeout++ < MAX_TIMEOUT)); |
|---|
| 456 | |
|---|
| 457 | if (timeout >= MAX_TIMEOUT) { |
|---|
| 458 | dev_dbg(I801_dev, "PEC Timeout!\n"); |
|---|
| 459 | } |
|---|
| 460 | outb_p(temp, SMBHSTSTS); |
|---|
| 461 | } |
|---|
| 462 | result = 0; |
|---|
| 463 | END: |
|---|
| 464 | if (command == I2C_SMBUS_I2C_BLOCK_DATA && |
|---|
| 465 | read_write == I2C_SMBUS_WRITE) { |
|---|
| 466 | /* restore saved configuration register value */ |
|---|
| 467 | pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); |
|---|
| 468 | } |
|---|
| 469 | return result; |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | /* Return -1 on error. */ |
|---|
| 473 | static s32 i801_access(struct i2c_adapter * adap, u16 addr, |
|---|
| 474 | unsigned short flags, char read_write, u8 command, |
|---|
| 475 | int size, union i2c_smbus_data * data) |
|---|
| 476 | { |
|---|
| 477 | int hwpec = 0; |
|---|
| 478 | int block = 0; |
|---|
| 479 | int ret, xact = 0; |
|---|
| 480 | |
|---|
| 481 | #ifdef HAVE_PEC |
|---|
| 482 | hwpec = isich4 && (flags & I2C_CLIENT_PEC) |
|---|
| 483 | && size != I2C_SMBUS_QUICK |
|---|
| 484 | && size != I2C_SMBUS_I2C_BLOCK_DATA; |
|---|
| 485 | #endif |
|---|
| 486 | |
|---|
| 487 | switch (size) { |
|---|
| 488 | case I2C_SMBUS_QUICK: |
|---|
| 489 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
|---|
| 490 | SMBHSTADD); |
|---|
| 491 | xact = I801_QUICK; |
|---|
| 492 | break; |
|---|
| 493 | case I2C_SMBUS_BYTE: |
|---|
| 494 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
|---|
| 495 | SMBHSTADD); |
|---|
| 496 | if (read_write == I2C_SMBUS_WRITE) |
|---|
| 497 | outb_p(command, SMBHSTCMD); |
|---|
| 498 | xact = I801_BYTE; |
|---|
| 499 | break; |
|---|
| 500 | case I2C_SMBUS_BYTE_DATA: |
|---|
| 501 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
|---|
| 502 | SMBHSTADD); |
|---|
| 503 | outb_p(command, SMBHSTCMD); |
|---|
| 504 | if (read_write == I2C_SMBUS_WRITE) |
|---|
| 505 | outb_p(data->byte, SMBHSTDAT0); |
|---|
| 506 | xact = I801_BYTE_DATA; |
|---|
| 507 | break; |
|---|
| 508 | case I2C_SMBUS_WORD_DATA: |
|---|
| 509 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
|---|
| 510 | SMBHSTADD); |
|---|
| 511 | outb_p(command, SMBHSTCMD); |
|---|
| 512 | if (read_write == I2C_SMBUS_WRITE) { |
|---|
| 513 | outb_p(data->word & 0xff, SMBHSTDAT0); |
|---|
| 514 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); |
|---|
| 515 | } |
|---|
| 516 | xact = I801_WORD_DATA; |
|---|
| 517 | break; |
|---|
| 518 | case I2C_SMBUS_BLOCK_DATA: |
|---|
| 519 | case I2C_SMBUS_I2C_BLOCK_DATA: |
|---|
| 520 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
|---|
| 521 | SMBHSTADD); |
|---|
| 522 | outb_p(command, SMBHSTCMD); |
|---|
| 523 | block = 1; |
|---|
| 524 | break; |
|---|
| 525 | case I2C_SMBUS_PROC_CALL: |
|---|
| 526 | default: |
|---|
| 527 | dev_err(I801_dev, "Unsupported transaction %d\n", size); |
|---|
| 528 | return -1; |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | outb_p(hwpec, SMBAUXCTL); /* enable/disable hardware PEC */ |
|---|
| 532 | |
|---|
| 533 | if(block) |
|---|
| 534 | ret = i801_block_transaction(data, read_write, size, hwpec); |
|---|
| 535 | else { |
|---|
| 536 | outb_p(xact | ENABLE_INT9, SMBHSTCNT); |
|---|
| 537 | ret = i801_transaction(); |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | /* Some BIOSes don't like it when PEC is enabled at reboot or resume |
|---|
| 541 | time, so we forcibly disable it after every transaction. */ |
|---|
| 542 | if (hwpec) |
|---|
| 543 | outb_p(0, SMBAUXCTL); |
|---|
| 544 | |
|---|
| 545 | if(block) |
|---|
| 546 | return ret; |
|---|
| 547 | if(ret) |
|---|
| 548 | return -1; |
|---|
| 549 | if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) |
|---|
| 550 | return 0; |
|---|
| 551 | |
|---|
| 552 | switch (xact & 0x7f) { |
|---|
| 553 | case I801_BYTE: /* Result put in SMBHSTDAT0 */ |
|---|
| 554 | case I801_BYTE_DATA: |
|---|
| 555 | data->byte = inb_p(SMBHSTDAT0); |
|---|
| 556 | break; |
|---|
| 557 | case I801_WORD_DATA: |
|---|
| 558 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); |
|---|
| 559 | break; |
|---|
| 560 | } |
|---|
| 561 | return 0; |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | static void i801_inc(struct i2c_adapter *adapter) |
|---|
| 565 | { |
|---|
| 566 | #ifdef MODULE |
|---|
| 567 | MOD_INC_USE_COUNT; |
|---|
| 568 | #endif |
|---|
| 569 | } |
|---|
| 570 | |
|---|
| 571 | static void i801_dec(struct i2c_adapter *adapter) |
|---|
| 572 | { |
|---|
| 573 | #ifdef MODULE |
|---|
| 574 | MOD_DEC_USE_COUNT; |
|---|
| 575 | #endif |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | static u32 i801_func(struct i2c_adapter *adapter) |
|---|
| 579 | { |
|---|
| 580 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
|---|
| 581 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | |
|---|
| 582 | I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
|---|
| 583 | #ifdef HAVE_PEC |
|---|
| 584 | | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0) |
|---|
| 585 | #endif |
|---|
| 586 | #if 0 |
|---|
| 587 | | (isich5 ? I2C_FUNC_SMBUS_READ_I2C_BLOCK |
|---|
| 588 | : 0) |
|---|
| 589 | #endif |
|---|
| 590 | ; |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | static struct i2c_algorithm smbus_algorithm = { |
|---|
| 594 | .name = "Non-I2C SMBus adapter", |
|---|
| 595 | .id = I2C_ALGO_SMBUS, |
|---|
| 596 | .smbus_xfer = i801_access, |
|---|
| 597 | .functionality = i801_func, |
|---|
| 598 | }; |
|---|
| 599 | |
|---|
| 600 | static struct i2c_adapter i801_adapter = { |
|---|
| 601 | .id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801, |
|---|
| 602 | .algo = &smbus_algorithm, |
|---|
| 603 | .inc_use = i801_inc, |
|---|
| 604 | .dec_use = i801_dec, |
|---|
| 605 | }; |
|---|
| 606 | |
|---|
| 607 | static struct pci_device_id i801_ids[] __devinitdata = { |
|---|
| 608 | { |
|---|
| 609 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 610 | .device = PCI_DEVICE_ID_INTEL_82801AA_3, |
|---|
| 611 | .subvendor = PCI_ANY_ID, |
|---|
| 612 | .subdevice = PCI_ANY_ID, |
|---|
| 613 | }, |
|---|
| 614 | { |
|---|
| 615 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 616 | .device = PCI_DEVICE_ID_INTEL_82801AB_3, |
|---|
| 617 | .subvendor = PCI_ANY_ID, |
|---|
| 618 | .subdevice = PCI_ANY_ID, |
|---|
| 619 | }, |
|---|
| 620 | { |
|---|
| 621 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 622 | .device = PCI_DEVICE_ID_INTEL_82801BA_2, |
|---|
| 623 | .subvendor = PCI_ANY_ID, |
|---|
| 624 | .subdevice = PCI_ANY_ID, |
|---|
| 625 | }, |
|---|
| 626 | { |
|---|
| 627 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 628 | .device = PCI_DEVICE_ID_INTEL_82801CA_3, |
|---|
| 629 | .subvendor = PCI_ANY_ID, |
|---|
| 630 | .subdevice = PCI_ANY_ID, |
|---|
| 631 | }, |
|---|
| 632 | { |
|---|
| 633 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 634 | .device = PCI_DEVICE_ID_INTEL_82801DB_3, |
|---|
| 635 | .subvendor = PCI_ANY_ID, |
|---|
| 636 | .subdevice = PCI_ANY_ID, |
|---|
| 637 | }, |
|---|
| 638 | { |
|---|
| 639 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 640 | .device = PCI_DEVICE_ID_INTEL_82801EB_3, |
|---|
| 641 | .subvendor = PCI_ANY_ID, |
|---|
| 642 | .subdevice = PCI_ANY_ID, |
|---|
| 643 | }, |
|---|
| 644 | { |
|---|
| 645 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 646 | .device = PCI_DEVICE_ID_INTEL_ESB_4, |
|---|
| 647 | .subvendor = PCI_ANY_ID, |
|---|
| 648 | .subdevice = PCI_ANY_ID, |
|---|
| 649 | }, |
|---|
| 650 | { |
|---|
| 651 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 652 | .device = PCI_DEVICE_ID_INTEL_ESB2_17, |
|---|
| 653 | .subvendor = PCI_ANY_ID, |
|---|
| 654 | .subdevice = PCI_ANY_ID, |
|---|
| 655 | }, |
|---|
| 656 | { |
|---|
| 657 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 658 | .device = PCI_DEVICE_ID_INTEL_ICH6_16, |
|---|
| 659 | .subvendor = PCI_ANY_ID, |
|---|
| 660 | .subdevice = PCI_ANY_ID, |
|---|
| 661 | }, |
|---|
| 662 | { |
|---|
| 663 | .vendor = PCI_VENDOR_ID_INTEL, |
|---|
| 664 | .device = PCI_DEVICE_ID_INTEL_ICH7_17, |
|---|
| 665 | .subvendor = PCI_ANY_ID, |
|---|
| 666 | .subdevice = PCI_ANY_ID, |
|---|
| 667 | }, |
|---|
| 668 | { 0, } |
|---|
| 669 | }; |
|---|
| 670 | |
|---|
| 671 | static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id) |
|---|
| 672 | { |
|---|
| 673 | |
|---|
| 674 | if (i801_setup(dev)) { |
|---|
| 675 | dev_warn(dev, |
|---|
| 676 | "I801 not detected, module not inserted.\n"); |
|---|
| 677 | return -ENODEV; |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | snprintf(i801_adapter.name, 32, |
|---|
| 681 | "SMBus I801 adapter at %04x", i801_smba); |
|---|
| 682 | return i2c_add_adapter(&i801_adapter); |
|---|
| 683 | } |
|---|
| 684 | |
|---|
| 685 | static void __devexit i801_remove(struct pci_dev *dev) |
|---|
| 686 | { |
|---|
| 687 | i2c_del_adapter(&i801_adapter); |
|---|
| 688 | release_region(i801_smba, (isich4 ? 16 : 8)); |
|---|
| 689 | } |
|---|
| 690 | |
|---|
| 691 | static struct pci_driver i801_driver = { |
|---|
| 692 | .name = "i801 smbus", |
|---|
| 693 | .id_table = i801_ids, |
|---|
| 694 | .probe = i801_probe, |
|---|
| 695 | .remove = __devexit_p(i801_remove), |
|---|
| 696 | }; |
|---|
| 697 | |
|---|
| 698 | static int __init i2c_i801_init(void) |
|---|
| 699 | { |
|---|
| 700 | printk(KERN_INFO "i2c-i801 version %s (%s)\n", LM_VERSION, LM_DATE); |
|---|
| 701 | return pci_module_init(&i801_driver); |
|---|
| 702 | } |
|---|
| 703 | |
|---|
| 704 | static void __exit i2c_i801_exit(void) |
|---|
| 705 | { |
|---|
| 706 | pci_unregister_driver(&i801_driver); |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl>, " |
|---|
| 710 | "Philip Edelbrock <phil@netroedge.com>, " |
|---|
| 711 | "and Mark D. Studebaker <mdsxyz123@yahoo.com>"); |
|---|
| 712 | MODULE_DESCRIPTION("I801 SMBus driver"); |
|---|
| 713 | MODULE_LICENSE("GPL"); |
|---|
| 714 | |
|---|
| 715 | module_init(i2c_i801_init); |
|---|
| 716 | module_exit(i2c_i801_exit); |
|---|