diff options
Diffstat (limited to 'drivers/i2c/busses/i2c-viapro.c')
-rw-r--r-- | drivers/i2c/busses/i2c-viapro.c | 271 |
1 files changed, 144 insertions, 127 deletions
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 99d209e0485a..c9366b504833 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c | |||
@@ -1,9 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring | 3 | monitoring |
4 | Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, | 4 | Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, |
5 | Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>, | 5 | Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>, |
6 | Mark D. Studebaker <mdsxyz123@yahoo.com> | 6 | Mark D. Studebaker <mdsxyz123@yahoo.com> |
7 | Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> | ||
7 | 8 | ||
8 | This program is free software; you can redistribute it and/or modify | 9 | 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 | it under the terms of the GNU General Public License as published by |
@@ -21,15 +22,19 @@ | |||
21 | */ | 22 | */ |
22 | 23 | ||
23 | /* | 24 | /* |
24 | Supports Via devices: | 25 | Supports the following VIA south bridges: |
25 | 82C596A/B (0x3050) | 26 | |
26 | 82C596B (0x3051) | 27 | Chip name PCI ID REV I2C block |
27 | 82C686A/B | 28 | VT82C596A 0x3050 no |
28 | 8231 | 29 | VT82C596B 0x3051 no |
29 | 8233 | 30 | VT82C686A 0x3057 0x30 no |
30 | 8233A (0x3147 and 0x3177) | 31 | VT82C686B 0x3057 0x40 yes |
31 | 8235 | 32 | VT8231 0x8235 no? |
32 | 8237 | 33 | VT8233 0x3074 yes |
34 | VT8233A 0x3147 yes? | ||
35 | VT8235 0x3177 yes | ||
36 | VT8237R 0x3227 yes | ||
37 | |||
33 | Note: we assume there can only be one device, with one SMBus interface. | 38 | Note: we assume there can only be one device, with one SMBus interface. |
34 | */ | 39 | */ |
35 | 40 | ||
@@ -38,7 +43,6 @@ | |||
38 | #include <linux/pci.h> | 43 | #include <linux/pci.h> |
39 | #include <linux/kernel.h> | 44 | #include <linux/kernel.h> |
40 | #include <linux/stddef.h> | 45 | #include <linux/stddef.h> |
41 | #include <linux/sched.h> | ||
42 | #include <linux/ioport.h> | 46 | #include <linux/ioport.h> |
43 | #include <linux/i2c.h> | 47 | #include <linux/i2c.h> |
44 | #include <linux/init.h> | 48 | #include <linux/init.h> |
@@ -46,48 +50,37 @@ | |||
46 | 50 | ||
47 | static struct pci_dev *vt596_pdev; | 51 | static struct pci_dev *vt596_pdev; |
48 | 52 | ||
49 | #define SMBBA1 0x90 | 53 | #define SMBBA1 0x90 |
50 | #define SMBBA2 0x80 | 54 | #define SMBBA2 0x80 |
51 | #define SMBBA3 0xD0 | 55 | #define SMBBA3 0xD0 |
52 | 56 | ||
53 | /* SMBus address offsets */ | 57 | /* SMBus address offsets */ |
54 | static unsigned short vt596_smba; | 58 | static unsigned short vt596_smba; |
55 | #define SMBHSTSTS (vt596_smba + 0) | 59 | #define SMBHSTSTS (vt596_smba + 0) |
56 | #define SMBHSLVSTS (vt596_smba + 1) | ||
57 | #define SMBHSTCNT (vt596_smba + 2) | 60 | #define SMBHSTCNT (vt596_smba + 2) |
58 | #define SMBHSTCMD (vt596_smba + 3) | 61 | #define SMBHSTCMD (vt596_smba + 3) |
59 | #define SMBHSTADD (vt596_smba + 4) | 62 | #define SMBHSTADD (vt596_smba + 4) |
60 | #define SMBHSTDAT0 (vt596_smba + 5) | 63 | #define SMBHSTDAT0 (vt596_smba + 5) |
61 | #define SMBHSTDAT1 (vt596_smba + 6) | 64 | #define SMBHSTDAT1 (vt596_smba + 6) |
62 | #define SMBBLKDAT (vt596_smba + 7) | 65 | #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 | 66 | ||
68 | /* PCI Address Constants */ | 67 | /* PCI Address Constants */ |
69 | 68 | ||
70 | /* SMBus data in configuration space can be found in two places, | 69 | /* SMBus data in configuration space can be found in two places, |
71 | We try to select the better one*/ | 70 | We try to select the better one */ |
72 | |||
73 | static unsigned short smb_cf_hstcfg = 0xD2; | ||
74 | 71 | ||
75 | #define SMBHSTCFG (smb_cf_hstcfg) | 72 | static unsigned short SMBHSTCFG = 0xD2; |
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) | ||
80 | 73 | ||
81 | /* Other settings */ | 74 | /* Other settings */ |
82 | #define MAX_TIMEOUT 500 | 75 | #define MAX_TIMEOUT 500 |
83 | #define ENABLE_INT9 0 | ||
84 | 76 | ||
85 | /* VT82C596 constants */ | 77 | /* VT82C596 constants */ |
86 | #define VT596_QUICK 0x00 | 78 | #define VT596_QUICK 0x00 |
87 | #define VT596_BYTE 0x04 | 79 | #define VT596_BYTE 0x04 |
88 | #define VT596_BYTE_DATA 0x08 | 80 | #define VT596_BYTE_DATA 0x08 |
89 | #define VT596_WORD_DATA 0x0C | 81 | #define VT596_WORD_DATA 0x0C |
90 | #define VT596_BLOCK_DATA 0x14 | 82 | #define VT596_BLOCK_DATA 0x14 |
83 | #define VT596_I2C_BLOCK_DATA 0x34 | ||
91 | 84 | ||
92 | 85 | ||
93 | /* If force is set to anything different from 0, we forcibly enable the | 86 | /* If force is set to anything different from 0, we forcibly enable the |
@@ -105,40 +98,65 @@ MODULE_PARM_DESC(force_addr, | |||
105 | "EXTREMELY DANGEROUS!"); | 98 | "EXTREMELY DANGEROUS!"); |
106 | 99 | ||
107 | 100 | ||
101 | static struct pci_driver vt596_driver; | ||
108 | static struct i2c_adapter vt596_adapter; | 102 | static struct i2c_adapter vt596_adapter; |
109 | 103 | ||
110 | /* Another internally used function */ | 104 | #define FEATURE_I2CBLOCK (1<<0) |
111 | static int vt596_transaction(void) | 105 | static unsigned int vt596_features; |
106 | |||
107 | #ifdef DEBUG | ||
108 | static void vt596_dump_regs(const char *msg, u8 size) | ||
109 | { | ||
110 | dev_dbg(&vt596_adapter.dev, "%s: STS=%02x CNT=%02x CMD=%02x ADD=%02x " | ||
111 | "DAT=%02x,%02x\n", msg, inb_p(SMBHSTSTS), inb_p(SMBHSTCNT), | ||
112 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), | ||
113 | inb_p(SMBHSTDAT1)); | ||
114 | |||
115 | if (size == VT596_BLOCK_DATA | ||
116 | || size == VT596_I2C_BLOCK_DATA) { | ||
117 | int i; | ||
118 | |||
119 | dev_dbg(&vt596_adapter.dev, "BLK="); | ||
120 | for (i = 0; i < I2C_SMBUS_BLOCK_MAX / 2; i++) | ||
121 | printk("%02x,", inb_p(SMBBLKDAT)); | ||
122 | printk("\n"); | ||
123 | dev_dbg(&vt596_adapter.dev, " "); | ||
124 | for (; i < I2C_SMBUS_BLOCK_MAX - 1; i++) | ||
125 | printk("%02x,", inb_p(SMBBLKDAT)); | ||
126 | printk("%02x\n", inb_p(SMBBLKDAT)); | ||
127 | } | ||
128 | } | ||
129 | #else | ||
130 | static inline void vt596_dump_regs(const char *msg, u8 size) { } | ||
131 | #endif | ||
132 | |||
133 | /* Return -1 on error, 0 on success */ | ||
134 | static int vt596_transaction(u8 size) | ||
112 | { | 135 | { |
113 | int temp; | 136 | int temp; |
114 | int result = 0; | 137 | int result = 0; |
115 | int timeout = 0; | 138 | int timeout = 0; |
116 | 139 | ||
117 | dev_dbg(&vt596_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, " | 140 | vt596_dump_regs("Transaction (pre)", size); |
118 | "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), | ||
119 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), | ||
120 | inb_p(SMBHSTDAT1)); | ||
121 | 141 | ||
122 | /* Make sure the SMBus host is ready to start transmitting */ | 142 | /* Make sure the SMBus host is ready to start transmitting */ |
123 | if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { | 143 | if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { |
124 | dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). " | 144 | dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). " |
125 | "Resetting...\n", temp); | 145 | "Resetting... ", temp); |
126 | 146 | ||
127 | outb_p(temp, SMBHSTSTS); | 147 | outb_p(temp, SMBHSTSTS); |
128 | if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { | 148 | if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { |
129 | dev_dbg(&vt596_adapter.dev, "Failed! (0x%02x)\n", temp); | 149 | printk("Failed! (0x%02x)\n", temp); |
130 | |||
131 | return -1; | 150 | return -1; |
132 | } else { | 151 | } else { |
133 | dev_dbg(&vt596_adapter.dev, "Successfull!\n"); | 152 | printk("Successful!\n"); |
134 | } | 153 | } |
135 | } | 154 | } |
136 | 155 | ||
137 | /* start the transaction by setting bit 6 */ | 156 | /* Start the transaction by setting bit 6 */ |
138 | outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); | 157 | outb_p(0x40 | (size & 0x3C), SMBHSTCNT); |
139 | 158 | ||
140 | /* We will always wait for a fraction of a second! | 159 | /* We will always wait for a fraction of a second */ |
141 | I don't know if VIA needs this, Intel did */ | ||
142 | do { | 160 | do { |
143 | msleep(1); | 161 | msleep(1); |
144 | temp = inb_p(SMBHSTSTS); | 162 | temp = inb_p(SMBHSTSTS); |
@@ -147,77 +165,61 @@ static int vt596_transaction(void) | |||
147 | /* If the SMBus is still busy, we give up */ | 165 | /* If the SMBus is still busy, we give up */ |
148 | if (timeout >= MAX_TIMEOUT) { | 166 | if (timeout >= MAX_TIMEOUT) { |
149 | result = -1; | 167 | result = -1; |
150 | dev_dbg(&vt596_adapter.dev, "SMBus Timeout!\n"); | 168 | dev_err(&vt596_adapter.dev, "SMBus timeout!\n"); |
151 | } | 169 | } |
152 | 170 | ||
153 | if (temp & 0x10) { | 171 | if (temp & 0x10) { |
154 | result = -1; | 172 | result = -1; |
155 | dev_dbg(&vt596_adapter.dev, "Error: Failed bus transaction\n"); | 173 | dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n", |
174 | inb_p(SMBHSTCNT) & 0x3C); | ||
156 | } | 175 | } |
157 | 176 | ||
158 | if (temp & 0x08) { | 177 | if (temp & 0x08) { |
159 | result = -1; | 178 | result = -1; |
160 | dev_info(&vt596_adapter.dev, "Bus collision! SMBus may be " | 179 | dev_err(&vt596_adapter.dev, "SMBus collision!\n"); |
161 | "locked until next hard\nreset. (sorry!)\n"); | ||
162 | /* Clock stops and slave is stuck in mid-transmission */ | ||
163 | } | 180 | } |
164 | 181 | ||
165 | if (temp & 0x04) { | 182 | if (temp & 0x04) { |
166 | result = -1; | 183 | result = -1; |
167 | dev_dbg(&vt596_adapter.dev, "Error: no response!\n"); | 184 | /* Quick commands are used to probe for chips, so |
185 | errors are expected, and we don't want to frighten the | ||
186 | user. */ | ||
187 | if ((inb_p(SMBHSTCNT) & 0x3C) != VT596_QUICK) | ||
188 | dev_err(&vt596_adapter.dev, "Transaction error!\n"); | ||
168 | } | 189 | } |
169 | 190 | ||
170 | if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { | 191 | /* Resetting status register */ |
192 | if (temp & 0x1F) | ||
171 | outb_p(temp, SMBHSTSTS); | 193 | outb_p(temp, SMBHSTSTS); |
172 | if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { | ||
173 | dev_warn(&vt596_adapter.dev, "Failed reset at end " | ||
174 | "of transaction (%02x)\n", temp); | ||
175 | } | ||
176 | } | ||
177 | 194 | ||
178 | dev_dbg(&vt596_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, " | 195 | vt596_dump_regs("Transaction (post)", size); |
179 | "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), | 196 | |
180 | inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), | ||
181 | inb_p(SMBHSTDAT1)); | ||
182 | |||
183 | return result; | 197 | return result; |
184 | } | 198 | } |
185 | 199 | ||
186 | /* Return -1 on error. */ | 200 | /* Return -1 on error, 0 on success */ |
187 | static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | 201 | static s32 vt596_access(struct i2c_adapter *adap, u16 addr, |
188 | unsigned short flags, char read_write, u8 command, | 202 | unsigned short flags, char read_write, u8 command, |
189 | int size, union i2c_smbus_data *data) | 203 | int size, union i2c_smbus_data *data) |
190 | { | 204 | { |
191 | int i, len; | 205 | int i; |
192 | 206 | ||
193 | switch (size) { | 207 | switch (size) { |
194 | case I2C_SMBUS_PROC_CALL: | ||
195 | dev_info(&vt596_adapter.dev, | ||
196 | "I2C_SMBUS_PROC_CALL not supported!\n"); | ||
197 | return -1; | ||
198 | case I2C_SMBUS_QUICK: | 208 | case I2C_SMBUS_QUICK: |
199 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | ||
200 | SMBHSTADD); | ||
201 | size = VT596_QUICK; | 209 | size = VT596_QUICK; |
202 | break; | 210 | break; |
203 | case I2C_SMBUS_BYTE: | 211 | case I2C_SMBUS_BYTE: |
204 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | ||
205 | SMBHSTADD); | ||
206 | if (read_write == I2C_SMBUS_WRITE) | 212 | if (read_write == I2C_SMBUS_WRITE) |
207 | outb_p(command, SMBHSTCMD); | 213 | outb_p(command, SMBHSTCMD); |
208 | size = VT596_BYTE; | 214 | size = VT596_BYTE; |
209 | break; | 215 | break; |
210 | case I2C_SMBUS_BYTE_DATA: | 216 | case I2C_SMBUS_BYTE_DATA: |
211 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | ||
212 | SMBHSTADD); | ||
213 | outb_p(command, SMBHSTCMD); | 217 | outb_p(command, SMBHSTCMD); |
214 | if (read_write == I2C_SMBUS_WRITE) | 218 | if (read_write == I2C_SMBUS_WRITE) |
215 | outb_p(data->byte, SMBHSTDAT0); | 219 | outb_p(data->byte, SMBHSTDAT0); |
216 | size = VT596_BYTE_DATA; | 220 | size = VT596_BYTE_DATA; |
217 | break; | 221 | break; |
218 | case I2C_SMBUS_WORD_DATA: | 222 | case I2C_SMBUS_WORD_DATA: |
219 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | ||
220 | SMBHSTADD); | ||
221 | outb_p(command, SMBHSTCMD); | 223 | outb_p(command, SMBHSTCMD); |
222 | if (read_write == I2C_SMBUS_WRITE) { | 224 | if (read_write == I2C_SMBUS_WRITE) { |
223 | outb_p(data->word & 0xff, SMBHSTDAT0); | 225 | outb_p(data->word & 0xff, SMBHSTDAT0); |
@@ -225,28 +227,33 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
225 | } | 227 | } |
226 | size = VT596_WORD_DATA; | 228 | size = VT596_WORD_DATA; |
227 | break; | 229 | break; |
230 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
231 | if (!(vt596_features & FEATURE_I2CBLOCK)) | ||
232 | goto exit_unsupported; | ||
233 | if (read_write == I2C_SMBUS_READ) | ||
234 | outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0); | ||
235 | /* Fall through */ | ||
228 | case I2C_SMBUS_BLOCK_DATA: | 236 | case I2C_SMBUS_BLOCK_DATA: |
229 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | ||
230 | SMBHSTADD); | ||
231 | outb_p(command, SMBHSTCMD); | 237 | outb_p(command, SMBHSTCMD); |
232 | if (read_write == I2C_SMBUS_WRITE) { | 238 | if (read_write == I2C_SMBUS_WRITE) { |
233 | len = data->block[0]; | 239 | u8 len = data->block[0]; |
234 | if (len < 0) | ||
235 | len = 0; | ||
236 | if (len > I2C_SMBUS_BLOCK_MAX) | 240 | if (len > I2C_SMBUS_BLOCK_MAX) |
237 | len = I2C_SMBUS_BLOCK_MAX; | 241 | len = I2C_SMBUS_BLOCK_MAX; |
238 | outb_p(len, SMBHSTDAT0); | 242 | outb_p(len, SMBHSTDAT0); |
239 | i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ | 243 | inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ |
240 | for (i = 1; i <= len; i++) | 244 | for (i = 1; i <= len; i++) |
241 | outb_p(data->block[i], SMBBLKDAT); | 245 | outb_p(data->block[i], SMBBLKDAT); |
242 | } | 246 | } |
243 | size = VT596_BLOCK_DATA; | 247 | size = (size == I2C_SMBUS_I2C_BLOCK_DATA) ? |
248 | VT596_I2C_BLOCK_DATA : VT596_BLOCK_DATA; | ||
244 | break; | 249 | break; |
250 | default: | ||
251 | goto exit_unsupported; | ||
245 | } | 252 | } |
246 | 253 | ||
247 | outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); | 254 | outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD); |
248 | 255 | ||
249 | if (vt596_transaction()) /* Error in transaction */ | 256 | if (vt596_transaction(size)) /* Error in transaction */ |
250 | return -1; | 257 | return -1; |
251 | 258 | ||
252 | if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) | 259 | if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) |
@@ -254,35 +261,39 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
254 | 261 | ||
255 | switch (size) { | 262 | switch (size) { |
256 | case VT596_BYTE: | 263 | case VT596_BYTE: |
257 | /* Where is the result put? I assume here it is in | ||
258 | * SMBHSTDAT0 but it might just as well be in the | ||
259 | * SMBHSTCMD. No clue in the docs | ||
260 | */ | ||
261 | data->byte = inb_p(SMBHSTDAT0); | ||
262 | break; | ||
263 | case VT596_BYTE_DATA: | 264 | case VT596_BYTE_DATA: |
264 | data->byte = inb_p(SMBHSTDAT0); | 265 | data->byte = inb_p(SMBHSTDAT0); |
265 | break; | 266 | break; |
266 | case VT596_WORD_DATA: | 267 | case VT596_WORD_DATA: |
267 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); | 268 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); |
268 | break; | 269 | break; |
270 | case VT596_I2C_BLOCK_DATA: | ||
269 | case VT596_BLOCK_DATA: | 271 | case VT596_BLOCK_DATA: |
270 | data->block[0] = inb_p(SMBHSTDAT0); | 272 | data->block[0] = inb_p(SMBHSTDAT0); |
271 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) | 273 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) |
272 | data->block[0] = I2C_SMBUS_BLOCK_MAX; | 274 | data->block[0] = I2C_SMBUS_BLOCK_MAX; |
273 | i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ | 275 | inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ |
274 | for (i = 1; i <= data->block[0]; i++) | 276 | for (i = 1; i <= data->block[0]; i++) |
275 | data->block[i] = inb_p(SMBBLKDAT); | 277 | data->block[i] = inb_p(SMBBLKDAT); |
276 | break; | 278 | break; |
277 | } | 279 | } |
278 | return 0; | 280 | return 0; |
281 | |||
282 | exit_unsupported: | ||
283 | dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n", | ||
284 | size); | ||
285 | return -1; | ||
279 | } | 286 | } |
280 | 287 | ||
281 | static u32 vt596_func(struct i2c_adapter *adapter) | 288 | static u32 vt596_func(struct i2c_adapter *adapter) |
282 | { | 289 | { |
283 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 290 | u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
284 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | 291 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | |
285 | I2C_FUNC_SMBUS_BLOCK_DATA; | 292 | I2C_FUNC_SMBUS_BLOCK_DATA; |
293 | |||
294 | if (vt596_features & FEATURE_I2CBLOCK) | ||
295 | func |= I2C_FUNC_SMBUS_I2C_BLOCK; | ||
296 | return func; | ||
286 | } | 297 | } |
287 | 298 | ||
288 | static struct i2c_algorithm smbus_algorithm = { | 299 | static struct i2c_algorithm smbus_algorithm = { |
@@ -294,7 +305,6 @@ static struct i2c_adapter vt596_adapter = { | |||
294 | .owner = THIS_MODULE, | 305 | .owner = THIS_MODULE, |
295 | .class = I2C_CLASS_HWMON, | 306 | .class = I2C_CLASS_HWMON, |
296 | .algo = &smbus_algorithm, | 307 | .algo = &smbus_algorithm, |
297 | .name = "unset", | ||
298 | }; | 308 | }; |
299 | 309 | ||
300 | static int __devinit vt596_probe(struct pci_dev *pdev, | 310 | static int __devinit vt596_probe(struct pci_dev *pdev, |
@@ -302,7 +312,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
302 | { | 312 | { |
303 | unsigned char temp; | 313 | unsigned char temp; |
304 | int error = -ENODEV; | 314 | int error = -ENODEV; |
305 | 315 | ||
306 | /* Determine the address of the SMBus areas */ | 316 | /* Determine the address of the SMBus areas */ |
307 | if (force_addr) { | 317 | if (force_addr) { |
308 | vt596_smba = force_addr & 0xfff0; | 318 | vt596_smba = force_addr & 0xfff0; |
@@ -311,12 +321,12 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
311 | } | 321 | } |
312 | 322 | ||
313 | if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) || | 323 | if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) || |
314 | !(vt596_smba & 0x1)) { | 324 | !(vt596_smba & 0x0001)) { |
315 | /* try 2nd address and config reg. for 596 */ | 325 | /* try 2nd address and config reg. for 596 */ |
316 | if (id->device == PCI_DEVICE_ID_VIA_82C596_3 && | 326 | if (id->device == PCI_DEVICE_ID_VIA_82C596_3 && |
317 | !pci_read_config_word(pdev, SMBBA2, &vt596_smba) && | 327 | !pci_read_config_word(pdev, SMBBA2, &vt596_smba) && |
318 | (vt596_smba & 0x1)) { | 328 | (vt596_smba & 0x0001)) { |
319 | smb_cf_hstcfg = 0x84; | 329 | SMBHSTCFG = 0x84; |
320 | } else { | 330 | } else { |
321 | /* no matches at all */ | 331 | /* no matches at all */ |
322 | dev_err(&pdev->dev, "Cannot configure " | 332 | dev_err(&pdev->dev, "Cannot configure " |
@@ -333,10 +343,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
333 | return -ENODEV; | 343 | return -ENODEV; |
334 | } | 344 | } |
335 | 345 | ||
336 | found: | 346 | found: |
337 | if (!request_region(vt596_smba, 8, "viapro-smbus")) { | 347 | if (!request_region(vt596_smba, 8, vt596_driver.name)) { |
338 | dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", | 348 | dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", |
339 | vt596_smba); | 349 | vt596_smba); |
340 | return -ENODEV; | 350 | return -ENODEV; |
341 | } | 351 | } |
342 | 352 | ||
@@ -348,16 +358,16 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
348 | pci_write_config_word(pdev, id->driver_data, vt596_smba); | 358 | pci_write_config_word(pdev, id->driver_data, vt596_smba); |
349 | pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); | 359 | pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); |
350 | dev_warn(&pdev->dev, "WARNING: SMBus interface set to new " | 360 | dev_warn(&pdev->dev, "WARNING: SMBus interface set to new " |
351 | "address 0x%04x!\n", vt596_smba); | 361 | "address 0x%04x!\n", vt596_smba); |
352 | } else if ((temp & 1) == 0) { | 362 | } else if (!(temp & 0x01)) { |
353 | if (force) { | 363 | if (force) { |
354 | /* NOTE: This assumes I/O space and other allocations | 364 | /* NOTE: This assumes I/O space and other allocations |
355 | * WERE done by the Bios! Don't complain if your | 365 | * WERE done by the Bios! Don't complain if your |
356 | * hardware does weird things after enabling this. | 366 | * hardware does weird things after enabling this. |
357 | * :') Check for Bios updates before resorting to | 367 | * :') Check for Bios updates before resorting to |
358 | * this. | 368 | * this. |
359 | */ | 369 | */ |
360 | pci_write_config_byte(pdev, SMBHSTCFG, temp | 1); | 370 | pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); |
361 | dev_info(&pdev->dev, "Enabling SMBus device\n"); | 371 | dev_info(&pdev->dev, "Enabling SMBus device\n"); |
362 | } else { | 372 | } else { |
363 | dev_err(&pdev->dev, "SMBUS: Error: Host SMBus " | 373 | dev_err(&pdev->dev, "SMBUS: Error: Host SMBus " |
@@ -367,22 +377,28 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
367 | } | 377 | } |
368 | } | 378 | } |
369 | 379 | ||
370 | if ((temp & 0x0E) == 8) | ||
371 | dev_dbg(&pdev->dev, "using Interrupt 9 for SMBus.\n"); | ||
372 | else if ((temp & 0x0E) == 0) | ||
373 | dev_dbg(&pdev->dev, "using Interrupt SMI# for SMBus.\n"); | ||
374 | else | ||
375 | dev_dbg(&pdev->dev, "Illegal Interrupt configuration " | ||
376 | "(or code out of date)!\n"); | ||
377 | |||
378 | pci_read_config_byte(pdev, SMBREV, &temp); | ||
379 | dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp); | ||
380 | dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); | 380 | dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); |
381 | 381 | ||
382 | switch (pdev->device) { | ||
383 | case PCI_DEVICE_ID_VIA_8237: | ||
384 | case PCI_DEVICE_ID_VIA_8235: | ||
385 | case PCI_DEVICE_ID_VIA_8233A: | ||
386 | case PCI_DEVICE_ID_VIA_8233_0: | ||
387 | vt596_features |= FEATURE_I2CBLOCK; | ||
388 | break; | ||
389 | case PCI_DEVICE_ID_VIA_82C686_4: | ||
390 | /* The VT82C686B (rev 0x40) does support I2C block | ||
391 | transactions, but the VT82C686A (rev 0x30) doesn't */ | ||
392 | if (!pci_read_config_byte(pdev, PCI_REVISION_ID, &temp) | ||
393 | && temp >= 0x40) | ||
394 | vt596_features |= FEATURE_I2CBLOCK; | ||
395 | break; | ||
396 | } | ||
397 | |||
382 | vt596_adapter.dev.parent = &pdev->dev; | 398 | vt596_adapter.dev.parent = &pdev->dev; |
383 | snprintf(vt596_adapter.name, I2C_NAME_SIZE, | 399 | snprintf(vt596_adapter.name, I2C_NAME_SIZE, |
384 | "SMBus Via Pro adapter at %04x", vt596_smba); | 400 | "SMBus Via Pro adapter at %04x", vt596_smba); |
385 | 401 | ||
386 | vt596_pdev = pci_dev_get(pdev); | 402 | vt596_pdev = pci_dev_get(pdev); |
387 | if (i2c_add_adapter(&vt596_adapter)) { | 403 | if (i2c_add_adapter(&vt596_adapter)) { |
388 | pci_dev_put(vt596_pdev); | 404 | pci_dev_put(vt596_pdev); |
@@ -395,7 +411,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
395 | */ | 411 | */ |
396 | return -ENODEV; | 412 | return -ENODEV; |
397 | 413 | ||
398 | release_region: | 414 | release_region: |
399 | release_region(vt596_smba, 8); | 415 | release_region(vt596_smba, 8); |
400 | return error; | 416 | return error; |
401 | } | 417 | } |
@@ -420,9 +436,10 @@ static struct pci_device_id vt596_ids[] = { | |||
420 | { 0, } | 436 | { 0, } |
421 | }; | 437 | }; |
422 | 438 | ||
423 | MODULE_DEVICE_TABLE (pci, vt596_ids); | 439 | MODULE_DEVICE_TABLE(pci, vt596_ids); |
424 | 440 | ||
425 | static struct pci_driver vt596_driver = { | 441 | static struct pci_driver vt596_driver = { |
442 | .owner = THIS_MODULE, | ||
426 | .name = "vt596_smbus", | 443 | .name = "vt596_smbus", |
427 | .id_table = vt596_ids, | 444 | .id_table = vt596_ids, |
428 | .probe = vt596_probe, | 445 | .probe = vt596_probe, |