i2c-i801: Handle multiple instances instead of keeping global state

It's poor form to keep driver state in global variables rather than
per-instance. It never really mattered in practice when there was only
one controller on the chipset, but the latest chipsets do have more
than one controller, so now we care.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>

authored by David Woodhouse and committed by Jean Delvare 0cd96eb0 e30d9859

+175 -144
+175 -144
drivers/i2c/busses/i2c-i801.c
··· 3 3 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker 4 4 <mdsxyz123@yahoo.com> 5 5 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> 6 + Copyright (C) 2010 Intel Corporation, 7 + David Woodhouse <dwmw2@infradead.org> 6 8 7 9 This program is free software; you can redistribute it and/or modify 8 10 it under the terms of the GNU General Public License as published by ··· 57 55 See the file Documentation/i2c/busses/i2c-i801 for details. 58 56 */ 59 57 60 - /* Note: we assume there can only be one I801, with one SMBus interface */ 61 - 62 58 #include <linux/module.h> 63 59 #include <linux/pci.h> 64 60 #include <linux/kernel.h> ··· 70 70 #include <linux/dmi.h> 71 71 72 72 /* I801 SMBus address offsets */ 73 - #define SMBHSTSTS (0 + i801_smba) 74 - #define SMBHSTCNT (2 + i801_smba) 75 - #define SMBHSTCMD (3 + i801_smba) 76 - #define SMBHSTADD (4 + i801_smba) 77 - #define SMBHSTDAT0 (5 + i801_smba) 78 - #define SMBHSTDAT1 (6 + i801_smba) 79 - #define SMBBLKDAT (7 + i801_smba) 80 - #define SMBPEC (8 + i801_smba) /* ICH3 and later */ 81 - #define SMBAUXSTS (12 + i801_smba) /* ICH4 and later */ 82 - #define SMBAUXCTL (13 + i801_smba) /* ICH4 and later */ 73 + #define SMBHSTSTS(p) (0 + (p)->smba) 74 + #define SMBHSTCNT(p) (2 + (p)->smba) 75 + #define SMBHSTCMD(p) (3 + (p)->smba) 76 + #define SMBHSTADD(p) (4 + (p)->smba) 77 + #define SMBHSTDAT0(p) (5 + (p)->smba) 78 + #define SMBHSTDAT1(p) (6 + (p)->smba) 79 + #define SMBBLKDAT(p) (7 + (p)->smba) 80 + #define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */ 81 + #define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */ 82 + #define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */ 83 83 84 84 /* PCI Address Constants */ 85 85 #define SMBBAR 4 ··· 128 128 SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \ 129 129 SMBHSTSTS_INTR) 130 130 131 - static unsigned long i801_smba; 132 - static unsigned char i801_original_hstcfg; 131 + struct i801_priv { 132 + struct i2c_adapter adapter; 133 + unsigned long smba; 134 + unsigned char original_hstcfg; 135 + struct pci_dev *pci_dev; 136 + unsigned int features; 137 + }; 138 + 133 139 static struct pci_driver i801_driver; 134 - static struct pci_dev *I801_dev; 135 140 136 141 #define FEATURE_SMBUS_PEC (1 << 0) 137 142 #define FEATURE_BLOCK_BUFFER (1 << 1) 138 143 #define FEATURE_BLOCK_PROC (1 << 2) 139 144 #define FEATURE_I2C_BLOCK_READ (1 << 3) 140 - static unsigned int i801_features; 141 145 142 146 static const char *i801_feature_names[] = { 143 147 "SMBus PEC", ··· 156 152 157 153 /* Make sure the SMBus host is ready to start transmitting. 158 154 Return 0 if it is, -EBUSY if it is not. */ 159 - static int i801_check_pre(void) 155 + static int i801_check_pre(struct i801_priv *priv) 160 156 { 161 157 int status; 162 158 163 - status = inb_p(SMBHSTSTS); 159 + status = inb_p(SMBHSTSTS(priv)); 164 160 if (status & SMBHSTSTS_HOST_BUSY) { 165 - dev_err(&I801_dev->dev, "SMBus is busy, can't use it!\n"); 161 + dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n"); 166 162 return -EBUSY; 167 163 } 168 164 169 165 status &= STATUS_FLAGS; 170 166 if (status) { 171 - dev_dbg(&I801_dev->dev, "Clearing status flags (%02x)\n", 167 + dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n", 172 168 status); 173 - outb_p(status, SMBHSTSTS); 174 - status = inb_p(SMBHSTSTS) & STATUS_FLAGS; 169 + outb_p(status, SMBHSTSTS(priv)); 170 + status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS; 175 171 if (status) { 176 - dev_err(&I801_dev->dev, 172 + dev_err(&priv->pci_dev->dev, 177 173 "Failed clearing status flags (%02x)\n", 178 174 status); 179 175 return -EBUSY; ··· 184 180 } 185 181 186 182 /* Convert the status register to an error code, and clear it. */ 187 - static int i801_check_post(int status, int timeout) 183 + static int i801_check_post(struct i801_priv *priv, int status, int timeout) 188 184 { 189 185 int result = 0; 190 186 191 187 /* If the SMBus is still busy, we give up */ 192 188 if (timeout) { 193 - dev_err(&I801_dev->dev, "Transaction timeout\n"); 189 + dev_err(&priv->pci_dev->dev, "Transaction timeout\n"); 194 190 /* try to stop the current command */ 195 - dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); 196 - outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); 191 + dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n"); 192 + outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL, 193 + SMBHSTCNT(priv)); 197 194 msleep(1); 198 - outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT); 195 + outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL), 196 + SMBHSTCNT(priv)); 199 197 200 198 /* Check if it worked */ 201 - status = inb_p(SMBHSTSTS); 199 + status = inb_p(SMBHSTSTS(priv)); 202 200 if ((status & SMBHSTSTS_HOST_BUSY) || 203 201 !(status & SMBHSTSTS_FAILED)) 204 - dev_err(&I801_dev->dev, 202 + dev_err(&priv->pci_dev->dev, 205 203 "Failed terminating the transaction\n"); 206 - outb_p(STATUS_FLAGS, SMBHSTSTS); 204 + outb_p(STATUS_FLAGS, SMBHSTSTS(priv)); 207 205 return -ETIMEDOUT; 208 206 } 209 207 210 208 if (status & SMBHSTSTS_FAILED) { 211 209 result = -EIO; 212 - dev_err(&I801_dev->dev, "Transaction failed\n"); 210 + dev_err(&priv->pci_dev->dev, "Transaction failed\n"); 213 211 } 214 212 if (status & SMBHSTSTS_DEV_ERR) { 215 213 result = -ENXIO; 216 - dev_dbg(&I801_dev->dev, "No response\n"); 214 + dev_dbg(&priv->pci_dev->dev, "No response\n"); 217 215 } 218 216 if (status & SMBHSTSTS_BUS_ERR) { 219 217 result = -EAGAIN; 220 - dev_dbg(&I801_dev->dev, "Lost arbitration\n"); 218 + dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n"); 221 219 } 222 220 223 221 if (result) { 224 222 /* Clear error flags */ 225 - outb_p(status & STATUS_FLAGS, SMBHSTSTS); 226 - status = inb_p(SMBHSTSTS) & STATUS_FLAGS; 223 + outb_p(status & STATUS_FLAGS, SMBHSTSTS(priv)); 224 + status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS; 227 225 if (status) { 228 - dev_warn(&I801_dev->dev, "Failed clearing status " 226 + dev_warn(&priv->pci_dev->dev, "Failed clearing status " 229 227 "flags at end of transaction (%02x)\n", 230 228 status); 231 229 } ··· 236 230 return result; 237 231 } 238 232 239 - static int i801_transaction(int xact) 233 + static int i801_transaction(struct i801_priv *priv, int xact) 240 234 { 241 235 int status; 242 236 int result; 243 237 int timeout = 0; 244 238 245 - result = i801_check_pre(); 239 + result = i801_check_pre(priv); 246 240 if (result < 0) 247 241 return result; 248 242 249 243 /* the current contents of SMBHSTCNT can be overwritten, since PEC, 250 244 * INTREN, SMBSCMD are passed in xact */ 251 - outb_p(xact | I801_START, SMBHSTCNT); 245 + outb_p(xact | I801_START, SMBHSTCNT(priv)); 252 246 253 247 /* We will always wait for a fraction of a second! */ 254 248 do { 255 249 msleep(1); 256 - status = inb_p(SMBHSTSTS); 250 + status = inb_p(SMBHSTSTS(priv)); 257 251 } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT)); 258 252 259 - result = i801_check_post(status, timeout > MAX_TIMEOUT); 253 + result = i801_check_post(priv, status, timeout > MAX_TIMEOUT); 260 254 if (result < 0) 261 255 return result; 262 256 263 - outb_p(SMBHSTSTS_INTR, SMBHSTSTS); 257 + outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv)); 264 258 return 0; 265 259 } 266 260 267 261 /* wait for INTR bit as advised by Intel */ 268 - static void i801_wait_hwpec(void) 262 + static void i801_wait_hwpec(struct i801_priv *priv) 269 263 { 270 264 int timeout = 0; 271 265 int status; 272 266 273 267 do { 274 268 msleep(1); 275 - status = inb_p(SMBHSTSTS); 269 + status = inb_p(SMBHSTSTS(priv)); 276 270 } while ((!(status & SMBHSTSTS_INTR)) 277 271 && (timeout++ < MAX_TIMEOUT)); 278 272 279 273 if (timeout > MAX_TIMEOUT) 280 - dev_dbg(&I801_dev->dev, "PEC Timeout!\n"); 274 + dev_dbg(&priv->pci_dev->dev, "PEC Timeout!\n"); 281 275 282 - outb_p(status, SMBHSTSTS); 276 + outb_p(status, SMBHSTSTS(priv)); 283 277 } 284 278 285 - static int i801_block_transaction_by_block(union i2c_smbus_data *data, 279 + static int i801_block_transaction_by_block(struct i801_priv *priv, 280 + union i2c_smbus_data *data, 286 281 char read_write, int hwpec) 287 282 { 288 283 int i, len; 289 284 int status; 290 285 291 - inb_p(SMBHSTCNT); /* reset the data buffer index */ 286 + inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */ 292 287 293 288 /* Use 32-byte buffer to process this transaction */ 294 289 if (read_write == I2C_SMBUS_WRITE) { 295 290 len = data->block[0]; 296 - outb_p(len, SMBHSTDAT0); 291 + outb_p(len, SMBHSTDAT0(priv)); 297 292 for (i = 0; i < len; i++) 298 - outb_p(data->block[i+1], SMBBLKDAT); 293 + outb_p(data->block[i+1], SMBBLKDAT(priv)); 299 294 } 300 295 301 - status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | 296 + status = i801_transaction(priv, I801_BLOCK_DATA | ENABLE_INT9 | 302 297 I801_PEC_EN * hwpec); 303 298 if (status) 304 299 return status; 305 300 306 301 if (read_write == I2C_SMBUS_READ) { 307 - len = inb_p(SMBHSTDAT0); 302 + len = inb_p(SMBHSTDAT0(priv)); 308 303 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 309 304 return -EPROTO; 310 305 311 306 data->block[0] = len; 312 307 for (i = 0; i < len; i++) 313 - data->block[i + 1] = inb_p(SMBBLKDAT); 308 + data->block[i + 1] = inb_p(SMBBLKDAT(priv)); 314 309 } 315 310 return 0; 316 311 } 317 312 318 - static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, 313 + static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, 314 + union i2c_smbus_data *data, 319 315 char read_write, int command, 320 316 int hwpec) 321 317 { ··· 327 319 int result; 328 320 int timeout; 329 321 330 - result = i801_check_pre(); 322 + result = i801_check_pre(priv); 331 323 if (result < 0) 332 324 return result; 333 325 334 326 len = data->block[0]; 335 327 336 328 if (read_write == I2C_SMBUS_WRITE) { 337 - outb_p(len, SMBHSTDAT0); 338 - outb_p(data->block[1], SMBBLKDAT); 329 + outb_p(len, SMBHSTDAT0(priv)); 330 + outb_p(data->block[1], SMBBLKDAT(priv)); 339 331 } 340 332 341 333 for (i = 1; i <= len; i++) { ··· 351 343 else 352 344 smbcmd = I801_BLOCK_DATA; 353 345 } 354 - outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); 346 + outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT(priv)); 355 347 356 348 if (i == 1) 357 - outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); 349 + outb_p(inb(SMBHSTCNT(priv)) | I801_START, 350 + SMBHSTCNT(priv)); 358 351 359 352 /* We will always wait for a fraction of a second! */ 360 353 timeout = 0; 361 354 do { 362 355 msleep(1); 363 - status = inb_p(SMBHSTSTS); 356 + status = inb_p(SMBHSTSTS(priv)); 364 357 } while ((!(status & SMBHSTSTS_BYTE_DONE)) 365 358 && (timeout++ < MAX_TIMEOUT)); 366 359 367 - result = i801_check_post(status, timeout > MAX_TIMEOUT); 360 + result = i801_check_post(priv, status, timeout > MAX_TIMEOUT); 368 361 if (result < 0) 369 362 return result; 370 363 371 364 if (i == 1 && read_write == I2C_SMBUS_READ 372 365 && command != I2C_SMBUS_I2C_BLOCK_DATA) { 373 - len = inb_p(SMBHSTDAT0); 366 + len = inb_p(SMBHSTDAT0(priv)); 374 367 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { 375 - dev_err(&I801_dev->dev, 368 + dev_err(&priv->pci_dev->dev, 376 369 "Illegal SMBus block read size %d\n", 377 370 len); 378 371 /* Recover */ 379 - while (inb_p(SMBHSTSTS) & SMBHSTSTS_HOST_BUSY) 380 - outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS); 381 - outb_p(SMBHSTSTS_INTR, SMBHSTSTS); 372 + while (inb_p(SMBHSTSTS(priv)) & 373 + SMBHSTSTS_HOST_BUSY) 374 + outb_p(SMBHSTSTS_BYTE_DONE, 375 + SMBHSTSTS(priv)); 376 + outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv)); 382 377 return -EPROTO; 383 378 } 384 379 data->block[0] = len; ··· 389 378 390 379 /* Retrieve/store value in SMBBLKDAT */ 391 380 if (read_write == I2C_SMBUS_READ) 392 - data->block[i] = inb_p(SMBBLKDAT); 381 + data->block[i] = inb_p(SMBBLKDAT(priv)); 393 382 if (read_write == I2C_SMBUS_WRITE && i+1 <= len) 394 - outb_p(data->block[i+1], SMBBLKDAT); 383 + outb_p(data->block[i+1], SMBBLKDAT(priv)); 395 384 396 385 /* signals SMBBLKDAT ready */ 397 - outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS); 386 + outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS(priv)); 398 387 } 399 388 400 389 return 0; 401 390 } 402 391 403 - static int i801_set_block_buffer_mode(void) 392 + static int i801_set_block_buffer_mode(struct i801_priv *priv) 404 393 { 405 - outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); 406 - if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) 394 + outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv)); 395 + if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0) 407 396 return -EIO; 408 397 return 0; 409 398 } 410 399 411 400 /* Block transaction function */ 412 - static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 401 + static int i801_block_transaction(struct i801_priv *priv, 402 + union i2c_smbus_data *data, char read_write, 413 403 int command, int hwpec) 414 404 { 415 405 int result = 0; ··· 419 407 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 420 408 if (read_write == I2C_SMBUS_WRITE) { 421 409 /* set I2C_EN bit in configuration register */ 422 - pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc); 423 - pci_write_config_byte(I801_dev, SMBHSTCFG, 410 + pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc); 411 + pci_write_config_byte(priv->pci_dev, SMBHSTCFG, 424 412 hostc | SMBHSTCFG_I2C_EN); 425 - } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { 426 - dev_err(&I801_dev->dev, 413 + } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) { 414 + dev_err(&priv->pci_dev->dev, 427 415 "I2C block read is unsupported!\n"); 428 416 return -EOPNOTSUPP; 429 417 } ··· 442 430 /* Experience has shown that the block buffer can only be used for 443 431 SMBus (not I2C) block transactions, even though the datasheet 444 432 doesn't mention this limitation. */ 445 - if ((i801_features & FEATURE_BLOCK_BUFFER) 433 + if ((priv->features & FEATURE_BLOCK_BUFFER) 446 434 && command != I2C_SMBUS_I2C_BLOCK_DATA 447 - && i801_set_block_buffer_mode() == 0) 448 - result = i801_block_transaction_by_block(data, read_write, 449 - hwpec); 435 + && i801_set_block_buffer_mode(priv) == 0) 436 + result = i801_block_transaction_by_block(priv, data, 437 + read_write, hwpec); 450 438 else 451 - result = i801_block_transaction_byte_by_byte(data, read_write, 439 + result = i801_block_transaction_byte_by_byte(priv, data, 440 + read_write, 452 441 command, hwpec); 453 442 454 443 if (result == 0 && hwpec) 455 - i801_wait_hwpec(); 444 + i801_wait_hwpec(priv); 456 445 457 446 if (command == I2C_SMBUS_I2C_BLOCK_DATA 458 447 && read_write == I2C_SMBUS_WRITE) { 459 448 /* restore saved configuration register value */ 460 - pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); 449 + pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc); 461 450 } 462 451 return result; 463 452 } ··· 471 458 int hwpec; 472 459 int block = 0; 473 460 int ret, xact = 0; 461 + struct i801_priv *priv = i2c_get_adapdata(adap); 474 462 475 - hwpec = (i801_features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) 463 + hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) 476 464 && size != I2C_SMBUS_QUICK 477 465 && size != I2C_SMBUS_I2C_BLOCK_DATA; 478 466 479 467 switch (size) { 480 468 case I2C_SMBUS_QUICK: 481 469 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 482 - SMBHSTADD); 470 + SMBHSTADD(priv)); 483 471 xact = I801_QUICK; 484 472 break; 485 473 case I2C_SMBUS_BYTE: 486 474 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 487 - SMBHSTADD); 475 + SMBHSTADD(priv)); 488 476 if (read_write == I2C_SMBUS_WRITE) 489 - outb_p(command, SMBHSTCMD); 477 + outb_p(command, SMBHSTCMD(priv)); 490 478 xact = I801_BYTE; 491 479 break; 492 480 case I2C_SMBUS_BYTE_DATA: 493 481 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 494 - SMBHSTADD); 495 - outb_p(command, SMBHSTCMD); 482 + SMBHSTADD(priv)); 483 + outb_p(command, SMBHSTCMD(priv)); 496 484 if (read_write == I2C_SMBUS_WRITE) 497 - outb_p(data->byte, SMBHSTDAT0); 485 + outb_p(data->byte, SMBHSTDAT0(priv)); 498 486 xact = I801_BYTE_DATA; 499 487 break; 500 488 case I2C_SMBUS_WORD_DATA: 501 489 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 502 - SMBHSTADD); 503 - outb_p(command, SMBHSTCMD); 490 + SMBHSTADD(priv)); 491 + outb_p(command, SMBHSTCMD(priv)); 504 492 if (read_write == I2C_SMBUS_WRITE) { 505 - outb_p(data->word & 0xff, SMBHSTDAT0); 506 - outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); 493 + outb_p(data->word & 0xff, SMBHSTDAT0(priv)); 494 + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); 507 495 } 508 496 xact = I801_WORD_DATA; 509 497 break; 510 498 case I2C_SMBUS_BLOCK_DATA: 511 499 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 512 - SMBHSTADD); 513 - outb_p(command, SMBHSTCMD); 500 + SMBHSTADD(priv)); 501 + outb_p(command, SMBHSTCMD(priv)); 514 502 block = 1; 515 503 break; 516 504 case I2C_SMBUS_I2C_BLOCK_DATA: 517 505 /* NB: page 240 of ICH5 datasheet shows that the R/#W 518 506 * bit should be cleared here, even when reading */ 519 - outb_p((addr & 0x7f) << 1, SMBHSTADD); 507 + outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); 520 508 if (read_write == I2C_SMBUS_READ) { 521 509 /* NB: page 240 of ICH5 datasheet also shows 522 510 * that DATA1 is the cmd field when reading */ 523 - outb_p(command, SMBHSTDAT1); 511 + outb_p(command, SMBHSTDAT1(priv)); 524 512 } else 525 - outb_p(command, SMBHSTCMD); 513 + outb_p(command, SMBHSTCMD(priv)); 526 514 block = 1; 527 515 break; 528 516 default: 529 - dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); 517 + dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n", 518 + size); 530 519 return -EOPNOTSUPP; 531 520 } 532 521 533 522 if (hwpec) /* enable/disable hardware PEC */ 534 - outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_CRC, SMBAUXCTL); 523 + outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv)); 535 524 else 536 - outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL); 525 + outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), 526 + SMBAUXCTL(priv)); 537 527 538 528 if (block) 539 - ret = i801_block_transaction(data, read_write, size, hwpec); 529 + ret = i801_block_transaction(priv, data, read_write, size, 530 + hwpec); 540 531 else 541 - ret = i801_transaction(xact | ENABLE_INT9); 532 + ret = i801_transaction(priv, xact | ENABLE_INT9); 542 533 543 534 /* Some BIOSes don't like it when PEC is enabled at reboot or resume 544 535 time, so we forcibly disable it after every transaction. Turn off 545 536 E32B for the same reason. */ 546 537 if (hwpec || block) 547 - outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), 548 - SMBAUXCTL); 538 + outb_p(inb_p(SMBAUXCTL(priv)) & 539 + ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); 549 540 550 541 if (block) 551 542 return ret; ··· 561 544 switch (xact & 0x7f) { 562 545 case I801_BYTE: /* Result put in SMBHSTDAT0 */ 563 546 case I801_BYTE_DATA: 564 - data->byte = inb_p(SMBHSTDAT0); 547 + data->byte = inb_p(SMBHSTDAT0(priv)); 565 548 break; 566 549 case I801_WORD_DATA: 567 - data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 550 + data->word = inb_p(SMBHSTDAT0(priv)) + 551 + (inb_p(SMBHSTDAT1(priv)) << 8); 568 552 break; 569 553 } 570 554 return 0; ··· 574 556 575 557 static u32 i801_func(struct i2c_adapter *adapter) 576 558 { 559 + struct i801_priv *priv = i2c_get_adapdata(adapter); 560 + 577 561 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 578 562 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 579 563 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK | 580 - ((i801_features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | 581 - ((i801_features & FEATURE_I2C_BLOCK_READ) ? 564 + ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | 565 + ((priv->features & FEATURE_I2C_BLOCK_READ) ? 582 566 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0); 583 567 } 584 568 585 569 static const struct i2c_algorithm smbus_algorithm = { 586 570 .smbus_xfer = i801_access, 587 571 .functionality = i801_func, 588 - }; 589 - 590 - static struct i2c_adapter i801_adapter = { 591 - .owner = THIS_MODULE, 592 - .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 593 - .algo = &smbus_algorithm, 594 572 }; 595 573 596 574 static const struct pci_device_id i801_ids[] = { ··· 720 706 { 721 707 unsigned char temp; 722 708 int err, i; 709 + struct i801_priv *priv; 723 710 724 - I801_dev = dev; 725 - i801_features = 0; 711 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 712 + if (!priv) 713 + return -ENOMEM; 714 + 715 + i2c_set_adapdata(&priv->adapter, priv); 716 + priv->adapter.owner = THIS_MODULE; 717 + priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 718 + priv->adapter.algo = &smbus_algorithm; 719 + 720 + priv->pci_dev = dev; 726 721 switch (dev->device) { 727 722 default: 728 - i801_features |= FEATURE_I2C_BLOCK_READ; 723 + priv->features |= FEATURE_I2C_BLOCK_READ; 729 724 /* fall through */ 730 725 case PCI_DEVICE_ID_INTEL_82801DB_3: 731 - i801_features |= FEATURE_SMBUS_PEC; 732 - i801_features |= FEATURE_BLOCK_BUFFER; 726 + priv->features |= FEATURE_SMBUS_PEC; 727 + priv->features |= FEATURE_BLOCK_BUFFER; 733 728 /* fall through */ 734 729 case PCI_DEVICE_ID_INTEL_82801CA_3: 735 730 case PCI_DEVICE_ID_INTEL_82801BA_2: ··· 749 726 750 727 /* Disable features on user request */ 751 728 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) { 752 - if (i801_features & disable_features & (1 << i)) 729 + if (priv->features & disable_features & (1 << i)) 753 730 dev_notice(&dev->dev, "%s disabled by user\n", 754 731 i801_feature_names[i]); 755 732 } 756 - i801_features &= ~disable_features; 733 + priv->features &= ~disable_features; 757 734 758 735 err = pci_enable_device(dev); 759 736 if (err) { ··· 763 740 } 764 741 765 742 /* Determine the address of the SMBus area */ 766 - i801_smba = pci_resource_start(dev, SMBBAR); 767 - if (!i801_smba) { 743 + priv->smba = pci_resource_start(dev, SMBBAR); 744 + if (!priv->smba) { 768 745 dev_err(&dev->dev, "SMBus base address uninitialized, " 769 746 "upgrade BIOS\n"); 770 747 err = -ENODEV; ··· 780 757 err = pci_request_region(dev, SMBBAR, i801_driver.name); 781 758 if (err) { 782 759 dev_err(&dev->dev, "Failed to request SMBus region " 783 - "0x%lx-0x%Lx\n", i801_smba, 760 + "0x%lx-0x%Lx\n", priv->smba, 784 761 (unsigned long long)pci_resource_end(dev, SMBBAR)); 785 762 goto exit; 786 763 } 787 764 788 - pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); 789 - i801_original_hstcfg = temp; 765 + pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp); 766 + priv->original_hstcfg = temp; 790 767 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ 791 768 if (!(temp & SMBHSTCFG_HST_EN)) { 792 769 dev_info(&dev->dev, "Enabling SMBus device\n"); 793 770 temp |= SMBHSTCFG_HST_EN; 794 771 } 795 - pci_write_config_byte(I801_dev, SMBHSTCFG, temp); 772 + pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp); 796 773 797 774 if (temp & SMBHSTCFG_SMB_SMI_EN) 798 775 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n"); ··· 800 777 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); 801 778 802 779 /* Clear special mode bits */ 803 - if (i801_features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) 804 - outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), 805 - SMBAUXCTL); 780 + if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) 781 + outb_p(inb_p(SMBAUXCTL(priv)) & 782 + ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); 806 783 807 784 /* set up the sysfs linkage to our parent device */ 808 - i801_adapter.dev.parent = &dev->dev; 785 + priv->adapter.dev.parent = &dev->dev; 809 786 810 787 /* Retry up to 3 times on lost arbitration */ 811 - i801_adapter.retries = 3; 788 + priv->adapter.retries = 3; 812 789 813 - snprintf(i801_adapter.name, sizeof(i801_adapter.name), 814 - "SMBus I801 adapter at %04lx", i801_smba); 815 - err = i2c_add_adapter(&i801_adapter); 790 + snprintf(priv->adapter.name, sizeof(priv->adapter.name), 791 + "SMBus I801 adapter at %04lx", priv->smba); 792 + err = i2c_add_adapter(&priv->adapter); 816 793 if (err) { 817 794 dev_err(&dev->dev, "Failed to add SMBus adapter\n"); 818 795 goto exit_release; ··· 826 803 memset(&info, 0, sizeof(struct i2c_board_info)); 827 804 info.addr = apanel_addr; 828 805 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE); 829 - i2c_new_device(&i801_adapter, &info); 806 + i2c_new_device(&priv->adapter, &info); 830 807 } 831 808 #endif 832 809 #if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE 833 810 if (dmi_name_in_vendors("FUJITSU")) 834 - dmi_walk(dmi_check_onboard_devices, &i801_adapter); 811 + dmi_walk(dmi_check_onboard_devices, &priv->adapter); 835 812 #endif 836 813 814 + pci_set_drvdata(dev, priv); 837 815 return 0; 838 816 839 817 exit_release: 840 818 pci_release_region(dev, SMBBAR); 841 819 exit: 820 + kfree(priv); 842 821 return err; 843 822 } 844 823 845 824 static void __devexit i801_remove(struct pci_dev *dev) 846 825 { 847 - i2c_del_adapter(&i801_adapter); 848 - pci_write_config_byte(I801_dev, SMBHSTCFG, i801_original_hstcfg); 826 + struct i801_priv *priv = pci_get_drvdata(dev); 827 + 828 + i2c_del_adapter(&priv->adapter); 829 + pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 849 830 pci_release_region(dev, SMBBAR); 831 + pci_set_drvdata(dev, NULL); 832 + kfree(priv); 850 833 /* 851 834 * do not call pci_disable_device(dev) since it can cause hard hangs on 852 835 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010) ··· 862 833 #ifdef CONFIG_PM 863 834 static int i801_suspend(struct pci_dev *dev, pm_message_t mesg) 864 835 { 836 + struct i801_priv *priv = pci_get_drvdata(dev); 837 + 865 838 pci_save_state(dev); 866 - pci_write_config_byte(dev, SMBHSTCFG, i801_original_hstcfg); 839 + pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 867 840 pci_set_power_state(dev, pci_choose_state(dev, mesg)); 868 841 return 0; 869 842 }