| 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>, | 
|  | 3 | Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker | 
|  | 4 | <mdsxyz123@yahoo.com> | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 5 | Copyright (C) 2007, 2008   Jean Delvare <khali@linux-fr.org> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 |  | 
|  | 7 | This program is free software; you can redistribute it and/or modify | 
|  | 8 | it under the terms of the GNU General Public License as published by | 
|  | 9 | the Free Software Foundation; either version 2 of the License, or | 
|  | 10 | (at your option) any later version. | 
|  | 11 |  | 
|  | 12 | This program is distributed in the hope that it will be useful, | 
|  | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 15 | GNU General Public License for more details. | 
|  | 16 |  | 
|  | 17 | You should have received a copy of the GNU General Public License | 
|  | 18 | along with this program; if not, write to the Free Software | 
|  | 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
|  | 20 | */ | 
|  | 21 |  | 
|  | 22 | /* | 
| Jean Delvare | ae7b049 | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 23 | Supports the following Intel I/O Controller Hubs (ICH): | 
|  | 24 |  | 
|  | 25 | I/O                     Block   I2C | 
|  | 26 | region  SMBus   Block   proc.   block | 
|  | 27 | Chip name             PCI ID    size    PEC     buffer  call    read | 
|  | 28 | ---------------------------------------------------------------------- | 
|  | 29 | 82801AA  (ICH)        0x2413     16      no      no      no      no | 
|  | 30 | 82801AB  (ICH0)       0x2423     16      no      no      no      no | 
|  | 31 | 82801BA  (ICH2)       0x2443     16      no      no      no      no | 
|  | 32 | 82801CA  (ICH3)       0x2483     32     soft     no      no      no | 
|  | 33 | 82801DB  (ICH4)       0x24c3     32     hard     yes     no      no | 
|  | 34 | 82801E   (ICH5)       0x24d3     32     hard     yes     yes     yes | 
|  | 35 | 6300ESB               0x25a4     32     hard     yes     yes     yes | 
|  | 36 | 82801F   (ICH6)       0x266a     32     hard     yes     yes     yes | 
|  | 37 | 6310ESB/6320ESB       0x269b     32     hard     yes     yes     yes | 
|  | 38 | 82801G   (ICH7)       0x27da     32     hard     yes     yes     yes | 
|  | 39 | 82801H   (ICH8)       0x283e     32     hard     yes     yes     yes | 
|  | 40 | 82801I   (ICH9)       0x2930     32     hard     yes     yes     yes | 
| Gaston, Jason D | d28dc71 | 2008-02-24 20:03:42 +0100 | [diff] [blame] | 41 | Tolapai               0x5032     32     hard     yes     yes     yes | 
|  | 42 | ICH10                 0x3a30     32     hard     yes     yes     yes | 
|  | 43 | ICH10                 0x3a60     32     hard     yes     yes     yes | 
| Jean Delvare | ae7b049 | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 44 |  | 
|  | 45 | Features supported by this driver: | 
|  | 46 | Software PEC                     no | 
|  | 47 | Hardware PEC                     yes | 
|  | 48 | Block buffer                     yes | 
|  | 49 | Block process call transaction   no | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 50 | I2C block read transaction       yes  (doesn't use the block buffer) | 
| Jean Delvare | ae7b049 | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 51 |  | 
|  | 52 | See the file Documentation/i2c/busses/i2c-i801 for details. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | */ | 
|  | 54 |  | 
|  | 55 | /* Note: we assume there can only be one I801, with one SMBus interface */ | 
|  | 56 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <linux/module.h> | 
|  | 58 | #include <linux/pci.h> | 
|  | 59 | #include <linux/kernel.h> | 
|  | 60 | #include <linux/stddef.h> | 
|  | 61 | #include <linux/delay.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <linux/ioport.h> | 
|  | 63 | #include <linux/init.h> | 
|  | 64 | #include <linux/i2c.h> | 
| Jean Delvare | 54fb4a05 | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 65 | #include <linux/acpi.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include <asm/io.h> | 
|  | 67 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* I801 SMBus address offsets */ | 
|  | 69 | #define SMBHSTSTS	(0 + i801_smba) | 
|  | 70 | #define SMBHSTCNT	(2 + i801_smba) | 
|  | 71 | #define SMBHSTCMD	(3 + i801_smba) | 
|  | 72 | #define SMBHSTADD	(4 + i801_smba) | 
|  | 73 | #define SMBHSTDAT0	(5 + i801_smba) | 
|  | 74 | #define SMBHSTDAT1	(6 + i801_smba) | 
|  | 75 | #define SMBBLKDAT	(7 + i801_smba) | 
| Jean Delvare | ae7b049 | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 76 | #define SMBPEC		(8 + i801_smba)		/* ICH3 and later */ | 
|  | 77 | #define SMBAUXSTS	(12 + i801_smba)	/* ICH4 and later */ | 
|  | 78 | #define SMBAUXCTL	(13 + i801_smba)	/* ICH4 and later */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 |  | 
|  | 80 | /* PCI Address Constants */ | 
| Jean Delvare | 6dcc19d | 2006-06-12 21:53:02 +0200 | [diff] [blame] | 81 | #define SMBBAR		4 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #define SMBHSTCFG	0x040 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 |  | 
|  | 84 | /* Host configuration bits for SMBHSTCFG */ | 
|  | 85 | #define SMBHSTCFG_HST_EN	1 | 
|  | 86 | #define SMBHSTCFG_SMB_SMI_EN	2 | 
|  | 87 | #define SMBHSTCFG_I2C_EN	4 | 
|  | 88 |  | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 89 | /* Auxillary control register bits, ICH4+ only */ | 
|  | 90 | #define SMBAUXCTL_CRC		1 | 
|  | 91 | #define SMBAUXCTL_E32B		2 | 
|  | 92 |  | 
|  | 93 | /* kill bit for SMBHSTCNT */ | 
|  | 94 | #define SMBHSTCNT_KILL		2 | 
|  | 95 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* Other settings */ | 
|  | 97 | #define MAX_TIMEOUT		100 | 
|  | 98 | #define ENABLE_INT9		0	/* set to 0x01 to enable - untested */ | 
|  | 99 |  | 
|  | 100 | /* I801 command constants */ | 
|  | 101 | #define I801_QUICK		0x00 | 
|  | 102 | #define I801_BYTE		0x04 | 
|  | 103 | #define I801_BYTE_DATA		0x08 | 
|  | 104 | #define I801_WORD_DATA		0x0C | 
| Jean Delvare | ae7b049 | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 105 | #define I801_PROC_CALL		0x10	/* unimplemented */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #define I801_BLOCK_DATA		0x14 | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 107 | #define I801_I2C_BLOCK_DATA	0x18	/* ICH5 and later */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define I801_BLOCK_LAST		0x34 | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 109 | #define I801_I2C_BLOCK_LAST	0x38	/* ICH5 and later */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #define I801_START		0x40 | 
| Jean Delvare | ae7b049 | 2008-01-27 18:14:49 +0100 | [diff] [blame] | 111 | #define I801_PEC_EN		0x80	/* ICH3 and later */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 113 | /* I801 Hosts Status register bits */ | 
|  | 114 | #define SMBHSTSTS_BYTE_DONE	0x80 | 
|  | 115 | #define SMBHSTSTS_INUSE_STS	0x40 | 
|  | 116 | #define SMBHSTSTS_SMBALERT_STS	0x20 | 
|  | 117 | #define SMBHSTSTS_FAILED	0x10 | 
|  | 118 | #define SMBHSTSTS_BUS_ERR	0x08 | 
|  | 119 | #define SMBHSTSTS_DEV_ERR	0x04 | 
|  | 120 | #define SMBHSTSTS_INTR		0x02 | 
|  | 121 | #define SMBHSTSTS_HOST_BUSY	0x01 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 123 | #define STATUS_FLAGS		(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | \ | 
|  | 124 | SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \ | 
|  | 125 | SMBHSTSTS_INTR) | 
|  | 126 |  | 
| Jean Delvare | 6dcc19d | 2006-06-12 21:53:02 +0200 | [diff] [blame] | 127 | static unsigned long i801_smba; | 
| Jean Delvare | a5aaea3 | 2007-03-22 19:49:01 +0100 | [diff] [blame] | 128 | static unsigned char i801_original_hstcfg; | 
| Jean Delvare | d6072f8 | 2005-09-25 16:37:04 +0200 | [diff] [blame] | 129 | static struct pci_driver i801_driver; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | static struct pci_dev *I801_dev; | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 131 |  | 
|  | 132 | #define FEATURE_SMBUS_PEC	(1 << 0) | 
|  | 133 | #define FEATURE_BLOCK_BUFFER	(1 << 1) | 
|  | 134 | #define FEATURE_BLOCK_PROC	(1 << 2) | 
|  | 135 | #define FEATURE_I2C_BLOCK_READ	(1 << 3) | 
|  | 136 | static unsigned int i801_features; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 138 | /* Make sure the SMBus host is ready to start transmitting. | 
|  | 139 | Return 0 if it is, -EBUSY if it is not. */ | 
|  | 140 | static int i801_check_pre(void) | 
|  | 141 | { | 
|  | 142 | int status; | 
|  | 143 |  | 
|  | 144 | status = inb_p(SMBHSTSTS); | 
|  | 145 | if (status & SMBHSTSTS_HOST_BUSY) { | 
|  | 146 | dev_err(&I801_dev->dev, "SMBus is busy, can't use it!\n"); | 
|  | 147 | return -EBUSY; | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | status &= STATUS_FLAGS; | 
|  | 151 | if (status) { | 
|  | 152 | dev_dbg(&I801_dev->dev, "Clearing status flags (%02x)\n", | 
|  | 153 | status); | 
|  | 154 | outb_p(status, SMBHSTSTS); | 
|  | 155 | status = inb_p(SMBHSTSTS) & STATUS_FLAGS; | 
|  | 156 | if (status) { | 
|  | 157 | dev_err(&I801_dev->dev, | 
|  | 158 | "Failed clearing status flags (%02x)\n", | 
|  | 159 | status); | 
|  | 160 | return -EBUSY; | 
|  | 161 | } | 
|  | 162 | } | 
|  | 163 |  | 
|  | 164 | return 0; | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | /* Convert the status register to an error code, and clear it. */ | 
|  | 168 | static int i801_check_post(int status, int timeout) | 
|  | 169 | { | 
|  | 170 | int result = 0; | 
|  | 171 |  | 
|  | 172 | /* If the SMBus is still busy, we give up */ | 
|  | 173 | if (timeout) { | 
|  | 174 | dev_err(&I801_dev->dev, "Transaction timeout\n"); | 
|  | 175 | /* try to stop the current command */ | 
|  | 176 | dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); | 
|  | 177 | outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); | 
|  | 178 | msleep(1); | 
|  | 179 | outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT); | 
|  | 180 |  | 
|  | 181 | /* Check if it worked */ | 
|  | 182 | status = inb_p(SMBHSTSTS); | 
|  | 183 | if ((status & SMBHSTSTS_HOST_BUSY) || | 
|  | 184 | !(status & SMBHSTSTS_FAILED)) | 
|  | 185 | dev_err(&I801_dev->dev, | 
|  | 186 | "Failed terminating the transaction\n"); | 
|  | 187 | outb_p(STATUS_FLAGS, SMBHSTSTS); | 
|  | 188 | return -ETIMEDOUT; | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | if (status & SMBHSTSTS_FAILED) { | 
|  | 192 | result = -EIO; | 
|  | 193 | dev_err(&I801_dev->dev, "Transaction failed\n"); | 
|  | 194 | } | 
|  | 195 | if (status & SMBHSTSTS_DEV_ERR) { | 
|  | 196 | result = -ENXIO; | 
|  | 197 | dev_dbg(&I801_dev->dev, "No response\n"); | 
|  | 198 | } | 
|  | 199 | if (status & SMBHSTSTS_BUS_ERR) { | 
|  | 200 | result = -EAGAIN; | 
|  | 201 | dev_dbg(&I801_dev->dev, "Lost arbitration\n"); | 
|  | 202 | } | 
|  | 203 |  | 
|  | 204 | if (result) { | 
|  | 205 | /* Clear error flags */ | 
|  | 206 | outb_p(status & STATUS_FLAGS, SMBHSTSTS); | 
|  | 207 | status = inb_p(SMBHSTSTS) & STATUS_FLAGS; | 
|  | 208 | if (status) { | 
|  | 209 | dev_warn(&I801_dev->dev, "Failed clearing status " | 
|  | 210 | "flags at end of transaction (%02x)\n", | 
|  | 211 | status); | 
|  | 212 | } | 
|  | 213 | } | 
|  | 214 |  | 
|  | 215 | return result; | 
|  | 216 | } | 
|  | 217 |  | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 218 | static int i801_transaction(int xact) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 220 | int status; | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 221 | int result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | int timeout = 0; | 
|  | 223 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 224 | result = i801_check_pre(); | 
|  | 225 | if (result < 0) | 
|  | 226 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 |  | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 228 | /* the current contents of SMBHSTCNT can be overwritten, since PEC, | 
|  | 229 | * INTREN, SMBSCMD are passed in xact */ | 
|  | 230 | outb_p(xact | I801_START, SMBHSTCNT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 |  | 
|  | 232 | /* We will always wait for a fraction of a second! */ | 
|  | 233 | do { | 
|  | 234 | msleep(1); | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 235 | status = inb_p(SMBHSTSTS); | 
|  | 236 | } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 238 | result = i801_check_post(status, timeout >= MAX_TIMEOUT); | 
|  | 239 | if (result < 0) | 
|  | 240 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 242 | outb_p(SMBHSTSTS_INTR, SMBHSTSTS); | 
|  | 243 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } | 
|  | 245 |  | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 246 | /* wait for INTR bit as advised by Intel */ | 
|  | 247 | static void i801_wait_hwpec(void) | 
|  | 248 | { | 
|  | 249 | int timeout = 0; | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 250 | int status; | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 251 |  | 
|  | 252 | do { | 
|  | 253 | msleep(1); | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 254 | status = inb_p(SMBHSTSTS); | 
|  | 255 | } while ((!(status & SMBHSTSTS_INTR)) | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 256 | && (timeout++ < MAX_TIMEOUT)); | 
|  | 257 |  | 
|  | 258 | if (timeout >= MAX_TIMEOUT) { | 
|  | 259 | dev_dbg(&I801_dev->dev, "PEC Timeout!\n"); | 
|  | 260 | } | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 261 | outb_p(status, SMBHSTSTS); | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 262 | } | 
|  | 263 |  | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 264 | static int i801_block_transaction_by_block(union i2c_smbus_data *data, | 
|  | 265 | char read_write, int hwpec) | 
|  | 266 | { | 
|  | 267 | int i, len; | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 268 | int status; | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 269 |  | 
|  | 270 | inb_p(SMBHSTCNT); /* reset the data buffer index */ | 
|  | 271 |  | 
|  | 272 | /* Use 32-byte buffer to process this transaction */ | 
|  | 273 | if (read_write == I2C_SMBUS_WRITE) { | 
|  | 274 | len = data->block[0]; | 
|  | 275 | outb_p(len, SMBHSTDAT0); | 
|  | 276 | for (i = 0; i < len; i++) | 
|  | 277 | outb_p(data->block[i+1], SMBBLKDAT); | 
|  | 278 | } | 
|  | 279 |  | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 280 | status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | | 
|  | 281 | I801_PEC_EN * hwpec); | 
|  | 282 | if (status) | 
|  | 283 | return status; | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 284 |  | 
|  | 285 | if (read_write == I2C_SMBUS_READ) { | 
|  | 286 | len = inb_p(SMBHSTDAT0); | 
|  | 287 | if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 288 | return -EPROTO; | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 289 |  | 
|  | 290 | data->block[0] = len; | 
|  | 291 | for (i = 0; i < len; i++) | 
|  | 292 | data->block[i + 1] = inb_p(SMBBLKDAT); | 
|  | 293 | } | 
|  | 294 | return 0; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 298 | char read_write, int command, | 
|  | 299 | int hwpec) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { | 
|  | 301 | int i, len; | 
|  | 302 | int smbcmd; | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 303 | int status; | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 304 | int result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | int timeout; | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 306 |  | 
|  | 307 | result = i801_check_pre(); | 
|  | 308 | if (result < 0) | 
|  | 309 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 |  | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 311 | len = data->block[0]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 |  | 
|  | 313 | if (read_write == I2C_SMBUS_WRITE) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | outb_p(len, SMBHSTDAT0); | 
|  | 315 | outb_p(data->block[1], SMBBLKDAT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } | 
|  | 317 |  | 
|  | 318 | for (i = 1; i <= len; i++) { | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 319 | if (i == len && read_write == I2C_SMBUS_READ) { | 
|  | 320 | if (command == I2C_SMBUS_I2C_BLOCK_DATA) | 
|  | 321 | smbcmd = I801_I2C_BLOCK_LAST; | 
|  | 322 | else | 
|  | 323 | smbcmd = I801_BLOCK_LAST; | 
|  | 324 | } else { | 
|  | 325 | if (command == I2C_SMBUS_I2C_BLOCK_DATA | 
|  | 326 | && read_write == I2C_SMBUS_READ) | 
|  | 327 | smbcmd = I801_I2C_BLOCK_DATA; | 
|  | 328 | else | 
|  | 329 | smbcmd = I801_BLOCK_DATA; | 
|  | 330 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); | 
|  | 332 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (i == 1) | 
|  | 334 | outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); | 
|  | 335 |  | 
|  | 336 | /* We will always wait for a fraction of a second! */ | 
|  | 337 | timeout = 0; | 
|  | 338 | do { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | msleep(1); | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 340 | status = inb_p(SMBHSTSTS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } | 
| Jean Delvare | 2b73809 | 2008-07-14 22:38:32 +0200 | [diff] [blame] | 342 | while ((!(status & SMBHSTSTS_BYTE_DONE)) | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 343 | && (timeout++ < MAX_TIMEOUT)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 345 | result = i801_check_post(status, timeout >= MAX_TIMEOUT); | 
|  | 346 | if (result < 0) | 
|  | 347 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 |  | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 349 | if (i == 1 && read_write == I2C_SMBUS_READ | 
|  | 350 | && command != I2C_SMBUS_I2C_BLOCK_DATA) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | len = inb_p(SMBHSTDAT0); | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 352 | if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { | 
|  | 353 | dev_err(&I801_dev->dev, | 
|  | 354 | "Illegal SMBus block read size %d\n", | 
|  | 355 | len); | 
|  | 356 | /* Recover */ | 
|  | 357 | while (inb_p(SMBHSTSTS) & SMBHSTSTS_HOST_BUSY) | 
|  | 358 | outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS); | 
|  | 359 | outb_p(SMBHSTSTS_INTR, SMBHSTSTS); | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 360 | return -EPROTO; | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 361 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | data->block[0] = len; | 
|  | 363 | } | 
|  | 364 |  | 
|  | 365 | /* Retrieve/store value in SMBBLKDAT */ | 
|  | 366 | if (read_write == I2C_SMBUS_READ) | 
|  | 367 | data->block[i] = inb_p(SMBBLKDAT); | 
|  | 368 | if (read_write == I2C_SMBUS_WRITE && i+1 <= len) | 
|  | 369 | outb_p(data->block[i+1], SMBBLKDAT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 |  | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 371 | /* signals SMBBLKDAT ready */ | 
|  | 372 | outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS); | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 373 | } | 
| Jean Delvare | cf898dc | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 374 |  | 
|  | 375 | return 0; | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 376 | } | 
|  | 377 |  | 
|  | 378 | static int i801_set_block_buffer_mode(void) | 
|  | 379 | { | 
|  | 380 | outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); | 
|  | 381 | if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 382 | return -EIO; | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 383 | return 0; | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | /* Block transaction function */ | 
|  | 387 | static int i801_block_transaction(union i2c_smbus_data *data, char read_write, | 
|  | 388 | int command, int hwpec) | 
|  | 389 | { | 
|  | 390 | int result = 0; | 
|  | 391 | unsigned char hostc; | 
|  | 392 |  | 
|  | 393 | if (command == I2C_SMBUS_I2C_BLOCK_DATA) { | 
|  | 394 | if (read_write == I2C_SMBUS_WRITE) { | 
|  | 395 | /* set I2C_EN bit in configuration register */ | 
|  | 396 | pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc); | 
|  | 397 | pci_write_config_byte(I801_dev, SMBHSTCFG, | 
|  | 398 | hostc | SMBHSTCFG_I2C_EN); | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 399 | } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 400 | dev_err(&I801_dev->dev, | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 401 | "I2C block read is unsupported!\n"); | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 402 | return -EOPNOTSUPP; | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 403 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } | 
|  | 405 |  | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 406 | if (read_write == I2C_SMBUS_WRITE | 
|  | 407 | || command == I2C_SMBUS_I2C_BLOCK_DATA) { | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 408 | if (data->block[0] < 1) | 
|  | 409 | data->block[0] = 1; | 
|  | 410 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) | 
|  | 411 | data->block[0] = I2C_SMBUS_BLOCK_MAX; | 
|  | 412 | } else { | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 413 | data->block[0] = 32;	/* max for SMBus block reads */ | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 414 | } | 
|  | 415 |  | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 416 | if ((i801_features & FEATURE_BLOCK_BUFFER) | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 417 | && !(command == I2C_SMBUS_I2C_BLOCK_DATA | 
|  | 418 | && read_write == I2C_SMBUS_READ) | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 419 | && i801_set_block_buffer_mode() == 0) | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 420 | result = i801_block_transaction_by_block(data, read_write, | 
|  | 421 | hwpec); | 
|  | 422 | else | 
|  | 423 | result = i801_block_transaction_byte_by_byte(data, read_write, | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 424 | command, hwpec); | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 425 |  | 
|  | 426 | if (result == 0 && hwpec) | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 427 | i801_wait_hwpec(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 |  | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 429 | if (command == I2C_SMBUS_I2C_BLOCK_DATA | 
|  | 430 | && read_write == I2C_SMBUS_WRITE) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* restore saved configuration register value */ | 
|  | 432 | pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); | 
|  | 433 | } | 
|  | 434 | return result; | 
|  | 435 | } | 
|  | 436 |  | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 437 | /* Return negative errno on error. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | static s32 i801_access(struct i2c_adapter * adap, u16 addr, | 
|  | 439 | unsigned short flags, char read_write, u8 command, | 
|  | 440 | int size, union i2c_smbus_data * data) | 
|  | 441 | { | 
| Jean Delvare | e8aac4a | 2005-10-26 21:34:42 +0200 | [diff] [blame] | 442 | int hwpec; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | int block = 0; | 
|  | 444 | int ret, xact = 0; | 
|  | 445 |  | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 446 | hwpec = (i801_features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) | 
| Jean Delvare | e8aac4a | 2005-10-26 21:34:42 +0200 | [diff] [blame] | 447 | && size != I2C_SMBUS_QUICK | 
|  | 448 | && size != I2C_SMBUS_I2C_BLOCK_DATA; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 |  | 
|  | 450 | switch (size) { | 
|  | 451 | case I2C_SMBUS_QUICK: | 
|  | 452 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 
|  | 453 | SMBHSTADD); | 
|  | 454 | xact = I801_QUICK; | 
|  | 455 | break; | 
|  | 456 | case I2C_SMBUS_BYTE: | 
|  | 457 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 
|  | 458 | SMBHSTADD); | 
|  | 459 | if (read_write == I2C_SMBUS_WRITE) | 
|  | 460 | outb_p(command, SMBHSTCMD); | 
|  | 461 | xact = I801_BYTE; | 
|  | 462 | break; | 
|  | 463 | case I2C_SMBUS_BYTE_DATA: | 
|  | 464 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 
|  | 465 | SMBHSTADD); | 
|  | 466 | outb_p(command, SMBHSTCMD); | 
|  | 467 | if (read_write == I2C_SMBUS_WRITE) | 
|  | 468 | outb_p(data->byte, SMBHSTDAT0); | 
|  | 469 | xact = I801_BYTE_DATA; | 
|  | 470 | break; | 
|  | 471 | case I2C_SMBUS_WORD_DATA: | 
|  | 472 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 
|  | 473 | SMBHSTADD); | 
|  | 474 | outb_p(command, SMBHSTCMD); | 
|  | 475 | if (read_write == I2C_SMBUS_WRITE) { | 
|  | 476 | outb_p(data->word & 0xff, SMBHSTDAT0); | 
|  | 477 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); | 
|  | 478 | } | 
|  | 479 | xact = I801_WORD_DATA; | 
|  | 480 | break; | 
|  | 481 | case I2C_SMBUS_BLOCK_DATA: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 
|  | 483 | SMBHSTADD); | 
|  | 484 | outb_p(command, SMBHSTCMD); | 
|  | 485 | block = 1; | 
|  | 486 | break; | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 487 | case I2C_SMBUS_I2C_BLOCK_DATA: | 
|  | 488 | /* NB: page 240 of ICH5 datasheet shows that the R/#W | 
|  | 489 | * bit should be cleared here, even when reading */ | 
|  | 490 | outb_p((addr & 0x7f) << 1, SMBHSTADD); | 
|  | 491 | if (read_write == I2C_SMBUS_READ) { | 
|  | 492 | /* NB: page 240 of ICH5 datasheet also shows | 
|  | 493 | * that DATA1 is the cmd field when reading */ | 
|  | 494 | outb_p(command, SMBHSTDAT1); | 
|  | 495 | } else | 
|  | 496 | outb_p(command, SMBHSTCMD); | 
|  | 497 | block = 1; | 
|  | 498 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | default: | 
|  | 500 | dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 501 | return -EOPNOTSUPP; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } | 
|  | 503 |  | 
| Oleg Ryjkov | ca8b9e3 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 504 | if (hwpec)	/* enable/disable hardware PEC */ | 
|  | 505 | outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_CRC, SMBAUXCTL); | 
|  | 506 | else | 
|  | 507 | outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL); | 
| Jean Delvare | e8aac4a | 2005-10-26 21:34:42 +0200 | [diff] [blame] | 508 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | if(block) | 
| Jean Delvare | 585b316 | 2005-10-26 21:31:15 +0200 | [diff] [blame] | 510 | ret = i801_block_transaction(data, read_write, size, hwpec); | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 511 | else | 
|  | 512 | ret = i801_transaction(xact | ENABLE_INT9); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 |  | 
| Jean Delvare | c79cfba | 2006-04-20 02:43:18 -0700 | [diff] [blame] | 514 | /* Some BIOSes don't like it when PEC is enabled at reboot or resume | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 515 | time, so we forcibly disable it after every transaction. Turn off | 
|  | 516 | E32B for the same reason. */ | 
| Jean Delvare | a0921b6 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 517 | if (hwpec || block) | 
| Oleg Ryjkov | 7edcb9a | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 518 | outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), | 
|  | 519 | SMBAUXCTL); | 
| Jean Delvare | c79cfba | 2006-04-20 02:43:18 -0700 | [diff] [blame] | 520 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | if(block) | 
|  | 522 | return ret; | 
|  | 523 | if(ret) | 
| David Brownell | 9714034 | 2008-07-14 22:38:25 +0200 | [diff] [blame] | 524 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) | 
|  | 526 | return 0; | 
|  | 527 |  | 
|  | 528 | switch (xact & 0x7f) { | 
|  | 529 | case I801_BYTE:	/* Result put in SMBHSTDAT0 */ | 
|  | 530 | case I801_BYTE_DATA: | 
|  | 531 | data->byte = inb_p(SMBHSTDAT0); | 
|  | 532 | break; | 
|  | 533 | case I801_WORD_DATA: | 
|  | 534 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); | 
|  | 535 | break; | 
|  | 536 | } | 
|  | 537 | return 0; | 
|  | 538 | } | 
|  | 539 |  | 
|  | 540 |  | 
|  | 541 | static u32 i801_func(struct i2c_adapter *adapter) | 
|  | 542 | { | 
|  | 543 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 544 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | 
|  | 545 | I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK | | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 546 | ((i801_features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | | 
|  | 547 | ((i801_features & FEATURE_I2C_BLOCK_READ) ? | 
|  | 548 | I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } | 
|  | 550 |  | 
| Jean Delvare | 8f9082c | 2006-09-03 22:39:46 +0200 | [diff] [blame] | 551 | static const struct i2c_algorithm smbus_algorithm = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | .smbus_xfer	= i801_access, | 
|  | 553 | .functionality	= i801_func, | 
|  | 554 | }; | 
|  | 555 |  | 
|  | 556 | static struct i2c_adapter i801_adapter = { | 
|  | 557 | .owner		= THIS_MODULE, | 
| Stephen Hemminger | 9ace555 | 2007-02-13 22:09:01 +0100 | [diff] [blame] | 558 | .id		= I2C_HW_SMBUS_I801, | 
| Jean Delvare | 3401b2f | 2008-07-14 22:38:29 +0200 | [diff] [blame] | 559 | .class		= I2C_CLASS_HWMON | I2C_CLASS_SPD, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | .algo		= &smbus_algorithm, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | }; | 
|  | 562 |  | 
|  | 563 | static struct pci_device_id i801_ids[] = { | 
|  | 564 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, | 
|  | 565 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, | 
|  | 566 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) }, | 
|  | 567 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) }, | 
|  | 568 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) }, | 
|  | 569 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) }, | 
|  | 570 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) }, | 
|  | 571 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) }, | 
|  | 572 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) }, | 
| Jason Gaston | b0a70b5 | 2005-04-16 15:24:45 -0700 | [diff] [blame] | 573 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) }, | 
| Jason Gaston | 8254fc4 | 2006-01-09 10:58:08 -0800 | [diff] [blame] | 574 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) }, | 
| Jason Gaston | adbc2a1 | 2006-11-22 15:19:12 -0800 | [diff] [blame] | 575 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) }, | 
| Jason Gaston | e07bc67 | 2007-10-13 23:56:31 +0200 | [diff] [blame] | 576 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) }, | 
| Gaston, Jason D | d28dc71 | 2008-02-24 20:03:42 +0100 | [diff] [blame] | 577 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) }, | 
|  | 578 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | { 0, } | 
|  | 580 | }; | 
|  | 581 |  | 
|  | 582 | MODULE_DEVICE_TABLE (pci, i801_ids); | 
|  | 583 |  | 
|  | 584 | static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id) | 
|  | 585 | { | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 586 | unsigned char temp; | 
| Jean Delvare | 455f332 | 2006-06-12 21:52:02 +0200 | [diff] [blame] | 587 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 |  | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 589 | I801_dev = dev; | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 590 | i801_features = 0; | 
| Jean Delvare | 250d1bd | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 591 | switch (dev->device) { | 
| Jean Delvare | 250d1bd | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 592 | case PCI_DEVICE_ID_INTEL_82801EB_3: | 
|  | 593 | case PCI_DEVICE_ID_INTEL_ESB_4: | 
|  | 594 | case PCI_DEVICE_ID_INTEL_ICH6_16: | 
|  | 595 | case PCI_DEVICE_ID_INTEL_ICH7_17: | 
|  | 596 | case PCI_DEVICE_ID_INTEL_ESB2_17: | 
|  | 597 | case PCI_DEVICE_ID_INTEL_ICH8_5: | 
|  | 598 | case PCI_DEVICE_ID_INTEL_ICH9_6: | 
| Gaston, Jason D | d28dc71 | 2008-02-24 20:03:42 +0100 | [diff] [blame] | 599 | case PCI_DEVICE_ID_INTEL_TOLAPAI_1: | 
|  | 600 | case PCI_DEVICE_ID_INTEL_ICH10_4: | 
|  | 601 | case PCI_DEVICE_ID_INTEL_ICH10_5: | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 602 | i801_features |= FEATURE_I2C_BLOCK_READ; | 
|  | 603 | /* fall through */ | 
|  | 604 | case PCI_DEVICE_ID_INTEL_82801DB_3: | 
| Jean Delvare | 369f6f4 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 605 | i801_features |= FEATURE_SMBUS_PEC; | 
|  | 606 | i801_features |= FEATURE_BLOCK_BUFFER; | 
| Jean Delvare | 250d1bd | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 607 | break; | 
| Jean Delvare | 250d1bd | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 608 | } | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 609 |  | 
|  | 610 | err = pci_enable_device(dev); | 
|  | 611 | if (err) { | 
|  | 612 | dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", | 
|  | 613 | err); | 
|  | 614 | goto exit; | 
|  | 615 | } | 
|  | 616 |  | 
|  | 617 | /* Determine the address of the SMBus area */ | 
|  | 618 | i801_smba = pci_resource_start(dev, SMBBAR); | 
|  | 619 | if (!i801_smba) { | 
|  | 620 | dev_err(&dev->dev, "SMBus base address uninitialized, " | 
|  | 621 | "upgrade BIOS\n"); | 
|  | 622 | err = -ENODEV; | 
| Daniel Ritz | d6fcb3b | 2006-06-27 18:40:54 +0200 | [diff] [blame] | 623 | goto exit; | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 624 | } | 
|  | 625 |  | 
| Jean Delvare | 54fb4a05 | 2008-07-14 22:38:33 +0200 | [diff] [blame] | 626 | err = acpi_check_resource_conflict(&dev->resource[SMBBAR]); | 
|  | 627 | if (err) | 
|  | 628 | goto exit; | 
|  | 629 |  | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 630 | err = pci_request_region(dev, SMBBAR, i801_driver.name); | 
|  | 631 | if (err) { | 
|  | 632 | dev_err(&dev->dev, "Failed to request SMBus region " | 
| Andrew Morton | 598736c | 2006-06-30 01:56:20 -0700 | [diff] [blame] | 633 | "0x%lx-0x%Lx\n", i801_smba, | 
|  | 634 | (unsigned long long)pci_resource_end(dev, SMBBAR)); | 
| Daniel Ritz | d6fcb3b | 2006-06-27 18:40:54 +0200 | [diff] [blame] | 635 | goto exit; | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 636 | } | 
|  | 637 |  | 
|  | 638 | pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); | 
| Jean Delvare | a5aaea3 | 2007-03-22 19:49:01 +0100 | [diff] [blame] | 639 | i801_original_hstcfg = temp; | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 640 | temp &= ~SMBHSTCFG_I2C_EN;	/* SMBus timing */ | 
|  | 641 | if (!(temp & SMBHSTCFG_HST_EN)) { | 
|  | 642 | dev_info(&dev->dev, "Enabling SMBus device\n"); | 
|  | 643 | temp |= SMBHSTCFG_HST_EN; | 
|  | 644 | } | 
|  | 645 | pci_write_config_byte(I801_dev, SMBHSTCFG, temp); | 
|  | 646 |  | 
|  | 647 | if (temp & SMBHSTCFG_SMB_SMI_EN) | 
|  | 648 | dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n"); | 
|  | 649 | else | 
|  | 650 | dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 |  | 
| Jean Delvare | a0921b6 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 652 | /* Clear special mode bits */ | 
|  | 653 | if (i801_features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) | 
|  | 654 | outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), | 
|  | 655 | SMBAUXCTL); | 
|  | 656 |  | 
| Robert P. J. Day | 405ae7d | 2007-02-17 19:13:42 +0100 | [diff] [blame] | 657 | /* set up the sysfs linkage to our parent device */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | i801_adapter.dev.parent = &dev->dev; | 
|  | 659 |  | 
| David Brownell | 2096b95 | 2007-05-01 23:26:28 +0200 | [diff] [blame] | 660 | snprintf(i801_adapter.name, sizeof(i801_adapter.name), | 
| Jean Delvare | 6dcc19d | 2006-06-12 21:53:02 +0200 | [diff] [blame] | 661 | "SMBus I801 adapter at %04lx", i801_smba); | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 662 | err = i2c_add_adapter(&i801_adapter); | 
|  | 663 | if (err) { | 
|  | 664 | dev_err(&dev->dev, "Failed to add SMBus adapter\n"); | 
| Daniel Ritz | d6fcb3b | 2006-06-27 18:40:54 +0200 | [diff] [blame] | 665 | goto exit_release; | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 666 | } | 
| Daniel Ritz | d6fcb3b | 2006-06-27 18:40:54 +0200 | [diff] [blame] | 667 | return 0; | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 668 |  | 
| Daniel Ritz | d6fcb3b | 2006-06-27 18:40:54 +0200 | [diff] [blame] | 669 | exit_release: | 
|  | 670 | pci_release_region(dev, SMBBAR); | 
| Jean Delvare | 02dd7ae | 2006-06-12 21:53:41 +0200 | [diff] [blame] | 671 | exit: | 
|  | 672 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } | 
|  | 674 |  | 
|  | 675 | static void __devexit i801_remove(struct pci_dev *dev) | 
|  | 676 | { | 
|  | 677 | i2c_del_adapter(&i801_adapter); | 
| Jean Delvare | a5aaea3 | 2007-03-22 19:49:01 +0100 | [diff] [blame] | 678 | pci_write_config_byte(I801_dev, SMBHSTCFG, i801_original_hstcfg); | 
| Jean Delvare | 6dcc19d | 2006-06-12 21:53:02 +0200 | [diff] [blame] | 679 | pci_release_region(dev, SMBBAR); | 
| Daniel Ritz | d6fcb3b | 2006-06-27 18:40:54 +0200 | [diff] [blame] | 680 | /* | 
|  | 681 | * do not call pci_disable_device(dev) since it can cause hard hangs on | 
|  | 682 | * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010) | 
|  | 683 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } | 
|  | 685 |  | 
| Jean Delvare | a5aaea3 | 2007-03-22 19:49:01 +0100 | [diff] [blame] | 686 | #ifdef CONFIG_PM | 
|  | 687 | static int i801_suspend(struct pci_dev *dev, pm_message_t mesg) | 
|  | 688 | { | 
|  | 689 | pci_save_state(dev); | 
|  | 690 | pci_write_config_byte(dev, SMBHSTCFG, i801_original_hstcfg); | 
|  | 691 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); | 
|  | 692 | return 0; | 
|  | 693 | } | 
|  | 694 |  | 
|  | 695 | static int i801_resume(struct pci_dev *dev) | 
|  | 696 | { | 
|  | 697 | pci_set_power_state(dev, PCI_D0); | 
|  | 698 | pci_restore_state(dev); | 
|  | 699 | return pci_enable_device(dev); | 
|  | 700 | } | 
|  | 701 | #else | 
|  | 702 | #define i801_suspend NULL | 
|  | 703 | #define i801_resume NULL | 
|  | 704 | #endif | 
|  | 705 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | static struct pci_driver i801_driver = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | .name		= "i801_smbus", | 
|  | 708 | .id_table	= i801_ids, | 
|  | 709 | .probe		= i801_probe, | 
|  | 710 | .remove		= __devexit_p(i801_remove), | 
| Jean Delvare | a5aaea3 | 2007-03-22 19:49:01 +0100 | [diff] [blame] | 711 | .suspend	= i801_suspend, | 
|  | 712 | .resume		= i801_resume, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | }; | 
|  | 714 |  | 
|  | 715 | static int __init i2c_i801_init(void) | 
|  | 716 | { | 
|  | 717 | return pci_register_driver(&i801_driver); | 
|  | 718 | } | 
|  | 719 |  | 
|  | 720 | static void __exit i2c_i801_exit(void) | 
|  | 721 | { | 
|  | 722 | pci_unregister_driver(&i801_driver); | 
|  | 723 | } | 
|  | 724 |  | 
| Jean Delvare | 6342064 | 2008-01-27 18:14:50 +0100 | [diff] [blame] | 725 | MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, " | 
|  | 726 | "Jean Delvare <khali@linux-fr.org>"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | MODULE_DESCRIPTION("I801 SMBus driver"); | 
|  | 728 | MODULE_LICENSE("GPL"); | 
|  | 729 |  | 
|  | 730 | module_init(i2c_i801_init); | 
|  | 731 | module_exit(i2c_i801_exit); |