Changeset 3140
- Timestamp:
- 10/29/05 23:04:11 (8 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/kernel/busses/i2c-viapro.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/busses/i2c-viapro.c
r3139 r3140 39 39 #include <linux/kernel.h> 40 40 #include <linux/stddef.h> 41 #include <linux/sched.h>42 41 #include <linux/ioport.h> 43 42 #include <linux/i2c.h> … … 54 53 static unsigned short vt596_smba; 55 54 #define SMBHSTSTS (vt596_smba + 0) 56 #define SMBHSLVSTS (vt596_smba + 1)57 55 #define SMBHSTCNT (vt596_smba + 2) 58 56 #define SMBHSTCMD (vt596_smba + 3) … … 61 59 #define SMBHSTDAT1 (vt596_smba + 6) 62 60 #define SMBBLKDAT (vt596_smba + 7) 63 #define SMBSLVCNT (vt596_smba + 8)64 #define SMBSHDWCMD (vt596_smba + 9)65 #define SMBSLVEVT (vt596_smba + 0xA)66 #define SMBSLVDAT (vt596_smba + 0xC)67 61 68 62 /* PCI Address Constants */ … … 71 65 We try to select the better one */ 72 66 73 static unsigned short smb_cf_hstcfg = 0xD2; 74 75 #define SMBHSTCFG (smb_cf_hstcfg) 76 #define SMBSLVC (smb_cf_hstcfg + 1) 77 #define SMBSHDW1 (smb_cf_hstcfg + 2) 78 #define SMBSHDW2 (smb_cf_hstcfg + 3) 79 #define SMBREV (smb_cf_hstcfg + 4) 67 static unsigned short SMBHSTCFG = 0xD2; 80 68 81 69 /* Other settings */ 82 70 #define MAX_TIMEOUT 500 83 #define ENABLE_INT9 084 71 85 72 /* VT82C596 constants */ … … 107 94 108 95 96 static struct pci_driver vt596_driver; 109 97 static struct i2c_adapter vt596_adapter; 110 98 … … 112 100 static unsigned int vt596_features; 113 101 114 /* Another internally used function*/102 /* Return -1 on error, 0 on success */ 115 103 static int vt596_transaction(void) 116 104 { … … 132 120 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 133 121 dev_dbg(&vt596_adapter, "Failed! (0x%02x)\n", temp); 134 135 122 return -1; 136 123 } else { 137 dev_dbg(&vt596_adapter, "Successful l!\n");124 dev_dbg(&vt596_adapter, "Successful!\n"); 138 125 } 139 126 } 140 127 141 /* start the transaction by setting bit 6 */ 142 outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 143 144 /* We will always wait for a fraction of a second! 145 I don't know if VIA needs this, Intel did */ 128 /* Start the transaction by setting bit 6 */ 129 outb_p(inb(SMBHSTCNT) | 0x40, SMBHSTCNT); 130 131 /* We will always wait for a fraction of a second */ 146 132 do { 147 133 i2c_delay(1); … … 152 138 if (timeout >= MAX_TIMEOUT) { 153 139 result = -1; 154 dev_ dbg(&vt596_adapter, "SMBus Timeout!\n");140 dev_err(&vt596_adapter, "SMBus Timeout!\n"); 155 141 } 156 142 157 143 if (temp & 0x10) { 158 144 result = -1; 159 dev_dbg(&vt596_adapter, "Error: Failed bus transaction\n"); 145 dev_err(&vt596_adapter, "Transaction failed (0x%02x)\n", 146 inb_p(SMBHSTCNT) & 0x3C); 160 147 } 161 148 162 149 if (temp & 0x08) { 163 150 result = -1; 164 dev_info(&vt596_adapter, "Bus collision! SMBus may be " 165 "locked until next hard\nreset. (sorry!)\n"); 166 /* Clock stops and slave is stuck in mid-transmission */ 151 dev_err(&vt596_adapter, "SMBus collision!\n"); 167 152 } 168 153 169 154 if (temp & 0x04) { 155 int size = inb_p(SMBHSTCNT) & 0x3C; 156 int read = inb_p(SMBHSTADD) & 0x01; 170 157 result = -1; 171 dev_dbg(&vt596_adapter, "Error: no response!\n"); 172 } 173 174 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 158 /* The quick and receive byte command are used to probe 159 for chips, so errors are expected, and we don't 160 want to frighten the user. */ 161 if (!((size == VT596_QUICK && !read) || 162 (size == VT596_BYTE && read))) 163 dev_err(&vt596_adapter, "Transaction error!\n"); 164 } 165 166 /* Resetting status register */ 167 if (temp & 0x1F) 175 168 outb_p(temp, SMBHSTSTS); 176 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {177 dev_warn(&vt596_adapter, "Failed reset at end "178 "of transaction (%02x)\n", temp);179 }180 }181 169 182 170 dev_dbg(&vt596_adapter, "Transaction (post): CNT=%02x, CMD=%02x, " … … 188 176 } 189 177 190 /* Return -1 on error .*/178 /* Return -1 on error, 0 on success */ 191 179 static s32 vt596_access(struct i2c_adapter *adap, u16 addr, 192 180 unsigned short flags, char read_write, u8 command, 193 181 int size, union i2c_smbus_data *data) 194 182 { 195 int i , len;183 int i; 196 184 197 185 switch (size) { 198 186 case I2C_SMBUS_QUICK: 199 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),200 SMBHSTADD);201 187 size = VT596_QUICK; 202 188 break; 203 189 case I2C_SMBUS_BYTE: 204 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),205 SMBHSTADD);206 190 if (read_write == I2C_SMBUS_WRITE) 207 191 outb_p(command, SMBHSTCMD); … … 209 193 break; 210 194 case I2C_SMBUS_BYTE_DATA: 211 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),212 SMBHSTADD);213 195 outb_p(command, SMBHSTCMD); 214 196 if (read_write == I2C_SMBUS_WRITE) … … 217 199 break; 218 200 case I2C_SMBUS_WORD_DATA: 219 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),220 SMBHSTADD);221 201 outb_p(command, SMBHSTCMD); 222 202 if (read_write == I2C_SMBUS_WRITE) { … … 228 208 case I2C_SMBUS_I2C_BLOCK_DATA: 229 209 if (!(vt596_features & FEATURE_I2CBLOCK)) 230 return -1;210 goto exit_unsupported; 231 211 if (read_write == I2C_SMBUS_READ) 232 212 outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0); 233 213 /* Fall through */ 234 214 case I2C_SMBUS_BLOCK_DATA: 235 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),236 SMBHSTADD);237 215 outb_p(command, SMBHSTCMD); 238 216 if (read_write == I2C_SMBUS_WRITE) { 239 len = data->block[0]; 240 if (len < 0) 241 len = 0; 217 u8 len = data->block[0]; 242 218 if (len > I2C_SMBUS_BLOCK_MAX) 243 219 len = I2C_SMBUS_BLOCK_MAX; 244 220 outb_p(len, SMBHSTDAT0); 245 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */221 inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 246 222 for (i = 1; i <= len; i++) 247 223 outb_p(data->block[i], SMBBLKDAT); … … 251 227 break; 252 228 default: 253 dev_warn(&vt596_adapter, "Unsupported transaction %d\n", size);254 return -1;255 } 256 257 outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);229 goto exit_unsupported; 230 } 231 232 outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD); 233 outb_p((size & 0x3C), SMBHSTCNT); 258 234 259 235 if (vt596_transaction()) /* Error in transaction */ … … 265 241 switch (size) { 266 242 case VT596_BYTE: 267 /* Where is the result put? I assume here it is in268 * SMBHSTDAT0 but it might just as well be in the269 * SMBHSTCMD. No clue in the docs270 */271 data->byte = inb_p(SMBHSTDAT0);272 break;273 243 case VT596_BYTE_DATA: 274 244 data->byte = inb_p(SMBHSTDAT0); … … 282 252 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) 283 253 data->block[0] = I2C_SMBUS_BLOCK_MAX; 284 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */254 inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 285 255 for (i = 1; i <= data->block[0]; i++) 286 256 data->block[i] = inb_p(SMBBLKDAT); … … 288 258 } 289 259 return 0; 260 261 exit_unsupported: 262 dev_warn(&vt596_adapter, "Unsupported command invoked! (0x%02x)\n", 263 size); 264 return -1; 290 265 } 291 266 … … 325 300 .id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_VIA2, 326 301 .algo = &smbus_algorithm, 327 .name = "unset",328 302 .inc_use = vt596_inc, 329 303 .dec_use = vt596_dec, … … 344 318 345 319 if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) || 346 !(vt596_smba & 0x 1)) {320 !(vt596_smba & 0x0001)) { 347 321 /* try 2nd address and config reg. for 596 */ 348 322 if (id->device == PCI_DEVICE_ID_VIA_82C596_3 && 349 323 !pci_read_config_word(pdev, SMBBA2, &vt596_smba) && 350 (vt596_smba & 0x 1)) {351 smb_cf_hstcfg= 0x84;324 (vt596_smba & 0x0001)) { 325 SMBHSTCFG = 0x84; 352 326 } else { 353 327 /* no matches at all */ … … 367 341 368 342 found: 369 if (!request_region(vt596_smba, 8, "viapro-smbus")) {343 if (!request_region(vt596_smba, 8, vt596_driver.name)) { 370 344 dev_err(pdev, "SMBus region 0x%x already in use!\n", 371 345 vt596_smba); … … 382 356 dev_warn(pdev, "WARNING: SMBus interface set to new " 383 357 "address 0x%04x!\n", vt596_smba); 384 } else if ( (temp & 1) == 0) {358 } else if (!(temp & 0x01)) { 385 359 if (force) { 386 360 /* NOTE: This assumes I/O space and other allocations … … 390 364 * this. 391 365 */ 392 pci_write_config_byte(pdev, SMBHSTCFG, temp | 1);366 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); 393 367 dev_info(pdev, "Enabling SMBus device\n"); 394 368 } else { … … 400 374 } 401 375 402 if ((temp & 0x0E) == 8)403 dev_dbg(pdev, "using Interrupt 9 for SMBus.\n");404 else if ((temp & 0x0E) == 0)405 dev_dbg(pdev, "using Interrupt SMI# for SMBus.\n");406 else407 dev_dbg(pdev, "Illegal Interrupt configuration "408 "(or code out of date)!\n");409 410 pci_read_config_byte(pdev, SMBREV, &temp);411 dev_dbg(pdev, "SMBREV = 0x%X\n", temp);412 376 dev_dbg(pdev, "VT596_smba = 0x%X\n", vt596_smba); 413 377
