diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-14 19:53:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-14 19:53:02 -0400 |
commit | 278429cff8809958d25415ba0ed32b59866ab1a8 (patch) | |
tree | 1085100d82525ff7c0fc93fad475e4320f293548 /drivers/i2c/busses | |
parent | e413b210c541acac1a194085627db28a122f3bdf (diff) | |
parent | a05f2c5a2735ee1d68770137fbbfc334d3b9cda9 (diff) |
Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6:
i2c-viapro: Add support for SMBus Process Call transactions
i2c: Restore i2c_smbus_process_call function
i2c: Do earlier driver model init
i2c: Only build Tyan SMBus mux drivers on x86
i2c: Guard against oopses from bad init sequences
i2c: Document the implementation details of the /dev interface
i2c: Improve dev-interface documentation
i2c-parport-light: Don't register a platform device resource
hwmon: (dme1737) Convert to a new-style i2c driver
hwmon: (dme1737) Be less i2c-centric
i2c/tps65010: Vibrator hookup to gpiolib
i2c-viapro: Add VX800/VX820 support
i2c: Renesas Highlander FPGA SMBus support
i2c-pca-isa: Don't grab arbitrary resources
i2c/isp1301_omap: Convert to a new-style i2c driver, part 2
i2c/isp1301_omap: Convert to a new-style i2c driver, part 1
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r-- | drivers/i2c/busses/Kconfig | 20 | ||||
-rw-r--r-- | drivers/i2c/busses/Makefile | 1 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-highlander.c | 498 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-parport-light.c | 39 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-pca-isa.c | 20 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-viapro.c | 17 |
6 files changed, 557 insertions, 38 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 6ee997b2817c..acadbc51fc0f 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -55,7 +55,7 @@ config I2C_AMD756 | |||
55 | 55 | ||
56 | config I2C_AMD756_S4882 | 56 | config I2C_AMD756_S4882 |
57 | tristate "SMBus multiplexing on the Tyan S4882" | 57 | tristate "SMBus multiplexing on the Tyan S4882" |
58 | depends on I2C_AMD756 && EXPERIMENTAL | 58 | depends on I2C_AMD756 && X86 && EXPERIMENTAL |
59 | help | 59 | help |
60 | Enabling this option will add specific SMBus support for the Tyan | 60 | Enabling this option will add specific SMBus support for the Tyan |
61 | S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed | 61 | S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed |
@@ -148,7 +148,7 @@ config I2C_NFORCE2 | |||
148 | 148 | ||
149 | config I2C_NFORCE2_S4985 | 149 | config I2C_NFORCE2_S4985 |
150 | tristate "SMBus multiplexing on the Tyan S4985" | 150 | tristate "SMBus multiplexing on the Tyan S4985" |
151 | depends on I2C_NFORCE2 && EXPERIMENTAL | 151 | depends on I2C_NFORCE2 && X86 && EXPERIMENTAL |
152 | help | 152 | help |
153 | Enabling this option will add specific SMBus support for the Tyan | 153 | Enabling this option will add specific SMBus support for the Tyan |
154 | S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed | 154 | S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed |
@@ -209,7 +209,7 @@ config I2C_VIA | |||
209 | will be called i2c-via. | 209 | will be called i2c-via. |
210 | 210 | ||
211 | config I2C_VIAPRO | 211 | config I2C_VIAPRO |
212 | tristate "VIA VT82C596/82C686/82xx and CX700" | 212 | tristate "VIA VT82C596/82C686/82xx and CX700/VX800/VX820" |
213 | depends on PCI | 213 | depends on PCI |
214 | help | 214 | help |
215 | If you say yes to this option, support will be included for the VIA | 215 | If you say yes to this option, support will be included for the VIA |
@@ -223,6 +223,8 @@ config I2C_VIAPRO | |||
223 | VT8237R/A/S | 223 | VT8237R/A/S |
224 | VT8251 | 224 | VT8251 |
225 | CX700 | 225 | CX700 |
226 | VX800 | ||
227 | VX820 | ||
226 | 228 | ||
227 | This driver can also be built as a module. If so, the module | 229 | This driver can also be built as a module. If so, the module |
228 | will be called i2c-viapro. | 230 | will be called i2c-viapro. |
@@ -330,6 +332,18 @@ config I2C_GPIO | |||
330 | This is a very simple bitbanging I2C driver utilizing the | 332 | This is a very simple bitbanging I2C driver utilizing the |
331 | arch-neutral GPIO API to control the SCL and SDA lines. | 333 | arch-neutral GPIO API to control the SCL and SDA lines. |
332 | 334 | ||
335 | config I2C_HIGHLANDER | ||
336 | tristate "Highlander FPGA SMBus interface" | ||
337 | depends on SH_HIGHLANDER | ||
338 | help | ||
339 | If you say yes to this option, support will be included for | ||
340 | the SMBus interface located in the FPGA on various Highlander | ||
341 | boards, particularly the R0P7780LC0011RL and R0P7785LC0011RL | ||
342 | FPGAs. This is wholly unrelated to the SoC I2C. | ||
343 | |||
344 | This driver can also be built as a module. If so, the module | ||
345 | will be called i2c-highlander. | ||
346 | |||
333 | config I2C_IBM_IIC | 347 | config I2C_IBM_IIC |
334 | tristate "IBM PPC 4xx on-chip I2C interface" | 348 | tristate "IBM PPC 4xx on-chip I2C interface" |
335 | depends on 4xx | 349 | depends on 4xx |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 97dbfa2107fe..0c2c4b26cdf1 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -31,6 +31,7 @@ obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o | |||
31 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o | 31 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o |
32 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o | 32 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o |
33 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o | 33 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o |
34 | obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o | ||
34 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o | 35 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o |
35 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o | 36 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o |
36 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o | 37 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o |
diff --git a/drivers/i2c/busses/i2c-highlander.c b/drivers/i2c/busses/i2c-highlander.c new file mode 100644 index 000000000000..f4d22ae9d294 --- /dev/null +++ b/drivers/i2c/busses/i2c-highlander.c | |||
@@ -0,0 +1,498 @@ | |||
1 | /* | ||
2 | * Renesas Solutions Highlander FPGA I2C/SMBus support. | ||
3 | * | ||
4 | * Supported devices: R0P7780LC0011RL, R0P7785LC0011RL | ||
5 | * | ||
6 | * Copyright (C) 2008 Paul Mundt | ||
7 | * Copyright (C) 2008 Renesas Solutions Corp. | ||
8 | * Copyright (C) 2008 Atom Create Engineering Co., Ltd. | ||
9 | * | ||
10 | * This file is subject to the terms and conditions of the GNU General | ||
11 | * Public License version 2. See the file "COPYING" in the main directory | ||
12 | * of this archive for more details. | ||
13 | */ | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/completion.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/delay.h> | ||
22 | |||
23 | #define SMCR 0x00 | ||
24 | #define SMCR_START (1 << 0) | ||
25 | #define SMCR_IRIC (1 << 1) | ||
26 | #define SMCR_BBSY (1 << 2) | ||
27 | #define SMCR_ACKE (1 << 3) | ||
28 | #define SMCR_RST (1 << 4) | ||
29 | #define SMCR_IEIC (1 << 6) | ||
30 | |||
31 | #define SMSMADR 0x02 | ||
32 | |||
33 | #define SMMR 0x04 | ||
34 | #define SMMR_MODE0 (1 << 0) | ||
35 | #define SMMR_MODE1 (1 << 1) | ||
36 | #define SMMR_CAP (1 << 3) | ||
37 | #define SMMR_TMMD (1 << 4) | ||
38 | #define SMMR_SP (1 << 7) | ||
39 | |||
40 | #define SMSADR 0x06 | ||
41 | #define SMTRDR 0x46 | ||
42 | |||
43 | struct highlander_i2c_dev { | ||
44 | struct device *dev; | ||
45 | void __iomem *base; | ||
46 | struct i2c_adapter adapter; | ||
47 | struct completion cmd_complete; | ||
48 | unsigned long last_read_time; | ||
49 | int irq; | ||
50 | u8 *buf; | ||
51 | size_t buf_len; | ||
52 | }; | ||
53 | |||
54 | static int iic_force_poll, iic_force_normal; | ||
55 | static int iic_timeout = 1000, iic_read_delay; | ||
56 | |||
57 | static inline void highlander_i2c_irq_enable(struct highlander_i2c_dev *dev) | ||
58 | { | ||
59 | iowrite16(ioread16(dev->base + SMCR) | SMCR_IEIC, dev->base + SMCR); | ||
60 | } | ||
61 | |||
62 | static inline void highlander_i2c_irq_disable(struct highlander_i2c_dev *dev) | ||
63 | { | ||
64 | iowrite16(ioread16(dev->base + SMCR) & ~SMCR_IEIC, dev->base + SMCR); | ||
65 | } | ||
66 | |||
67 | static inline void highlander_i2c_start(struct highlander_i2c_dev *dev) | ||
68 | { | ||
69 | iowrite16(ioread16(dev->base + SMCR) | SMCR_START, dev->base + SMCR); | ||
70 | } | ||
71 | |||
72 | static inline void highlander_i2c_done(struct highlander_i2c_dev *dev) | ||
73 | { | ||
74 | iowrite16(ioread16(dev->base + SMCR) | SMCR_IRIC, dev->base + SMCR); | ||
75 | } | ||
76 | |||
77 | static void highlander_i2c_setup(struct highlander_i2c_dev *dev) | ||
78 | { | ||
79 | u16 smmr; | ||
80 | |||
81 | smmr = ioread16(dev->base + SMMR); | ||
82 | smmr |= SMMR_TMMD; | ||
83 | |||
84 | if (iic_force_normal) | ||
85 | smmr &= ~SMMR_SP; | ||
86 | else | ||
87 | smmr |= SMMR_SP; | ||
88 | |||
89 | iowrite16(smmr, dev->base + SMMR); | ||
90 | } | ||
91 | |||
92 | static void smbus_write_data(u8 *src, u16 *dst, int len) | ||
93 | { | ||
94 | for (; len > 1; len -= 2) { | ||
95 | *dst++ = be16_to_cpup((u16 *)src); | ||
96 | src += 2; | ||
97 | } | ||
98 | |||
99 | if (len) | ||
100 | *dst = *src << 8; | ||
101 | } | ||
102 | |||
103 | static void smbus_read_data(u16 *src, u8 *dst, int len) | ||
104 | { | ||
105 | for (; len > 1; len -= 2) { | ||
106 | *(u16 *)dst = cpu_to_be16p(src++); | ||
107 | dst += 2; | ||
108 | } | ||
109 | |||
110 | if (len) | ||
111 | *dst = *src >> 8; | ||
112 | } | ||
113 | |||
114 | static void highlander_i2c_command(struct highlander_i2c_dev *dev, | ||
115 | u8 command, int len) | ||
116 | { | ||
117 | unsigned int i; | ||
118 | u16 cmd = (command << 8) | command; | ||
119 | |||
120 | for (i = 0; i < len; i += 2) { | ||
121 | if (len - i == 1) | ||
122 | cmd = command << 8; | ||
123 | iowrite16(cmd, dev->base + SMSADR + i); | ||
124 | dev_dbg(dev->dev, "command data[%x] 0x%04x\n", i/2, cmd); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | static int highlander_i2c_wait_for_bbsy(struct highlander_i2c_dev *dev) | ||
129 | { | ||
130 | unsigned long timeout; | ||
131 | |||
132 | timeout = jiffies + msecs_to_jiffies(iic_timeout); | ||
133 | while (ioread16(dev->base + SMCR) & SMCR_BBSY) { | ||
134 | if (time_after(jiffies, timeout)) { | ||
135 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); | ||
136 | return -ETIMEDOUT; | ||
137 | } | ||
138 | |||
139 | msleep(1); | ||
140 | } | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static int highlander_i2c_reset(struct highlander_i2c_dev *dev) | ||
146 | { | ||
147 | iowrite16(ioread16(dev->base + SMCR) | SMCR_RST, dev->base + SMCR); | ||
148 | return highlander_i2c_wait_for_bbsy(dev); | ||
149 | } | ||
150 | |||
151 | static int highlander_i2c_wait_for_ack(struct highlander_i2c_dev *dev) | ||
152 | { | ||
153 | u16 tmp = ioread16(dev->base + SMCR); | ||
154 | |||
155 | if ((tmp & (SMCR_IRIC | SMCR_ACKE)) == SMCR_ACKE) { | ||
156 | dev_warn(dev->dev, "ack abnormality\n"); | ||
157 | return highlander_i2c_reset(dev); | ||
158 | } | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | static irqreturn_t highlander_i2c_irq(int irq, void *dev_id) | ||
164 | { | ||
165 | struct highlander_i2c_dev *dev = dev_id; | ||
166 | |||
167 | highlander_i2c_done(dev); | ||
168 | complete(&dev->cmd_complete); | ||
169 | |||
170 | return IRQ_HANDLED; | ||
171 | } | ||
172 | |||
173 | static void highlander_i2c_poll(struct highlander_i2c_dev *dev) | ||
174 | { | ||
175 | unsigned long timeout; | ||
176 | u16 smcr; | ||
177 | |||
178 | timeout = jiffies + msecs_to_jiffies(iic_timeout); | ||
179 | for (;;) { | ||
180 | smcr = ioread16(dev->base + SMCR); | ||
181 | |||
182 | /* | ||
183 | * Don't bother checking ACKE here, this and the reset | ||
184 | * are handled in highlander_i2c_wait_xfer_done() when | ||
185 | * waiting for the ACK. | ||
186 | */ | ||
187 | |||
188 | if (smcr & SMCR_IRIC) | ||
189 | return; | ||
190 | if (time_after(jiffies, timeout)) | ||
191 | break; | ||
192 | |||
193 | cpu_relax(); | ||
194 | cond_resched(); | ||
195 | } | ||
196 | |||
197 | dev_err(dev->dev, "polling timed out\n"); | ||
198 | } | ||
199 | |||
200 | static inline int highlander_i2c_wait_xfer_done(struct highlander_i2c_dev *dev) | ||
201 | { | ||
202 | if (dev->irq) | ||
203 | wait_for_completion_timeout(&dev->cmd_complete, | ||
204 | msecs_to_jiffies(iic_timeout)); | ||
205 | else | ||
206 | /* busy looping, the IRQ of champions */ | ||
207 | highlander_i2c_poll(dev); | ||
208 | |||
209 | return highlander_i2c_wait_for_ack(dev); | ||
210 | } | ||
211 | |||
212 | static int highlander_i2c_read(struct highlander_i2c_dev *dev) | ||
213 | { | ||
214 | int i, cnt; | ||
215 | u16 data[16]; | ||
216 | |||
217 | if (highlander_i2c_wait_for_bbsy(dev)) | ||
218 | return -EAGAIN; | ||
219 | |||
220 | highlander_i2c_start(dev); | ||
221 | |||
222 | if (highlander_i2c_wait_xfer_done(dev)) { | ||
223 | dev_err(dev->dev, "Arbitration loss\n"); | ||
224 | return -EAGAIN; | ||
225 | } | ||
226 | |||
227 | /* | ||
228 | * The R0P7780LC0011RL FPGA needs a significant delay between | ||
229 | * data read cycles, otherwise the transciever gets confused and | ||
230 | * garbage is returned when the read is subsequently aborted. | ||
231 | * | ||
232 | * It is not sufficient to wait for BBSY. | ||
233 | * | ||
234 | * While this generally only applies to the older SH7780-based | ||
235 | * Highlanders, the same issue can be observed on SH7785 ones, | ||
236 | * albeit less frequently. SH7780-based Highlanders may need | ||
237 | * this to be as high as 1000 ms. | ||
238 | */ | ||
239 | if (iic_read_delay && time_before(jiffies, dev->last_read_time + | ||
240 | msecs_to_jiffies(iic_read_delay))) | ||
241 | msleep(jiffies_to_msecs((dev->last_read_time + | ||
242 | msecs_to_jiffies(iic_read_delay)) - jiffies)); | ||
243 | |||
244 | cnt = (dev->buf_len + 1) >> 1; | ||
245 | for (i = 0; i < cnt; i++) { | ||
246 | data[i] = ioread16(dev->base + SMTRDR + (i * sizeof(u16))); | ||
247 | dev_dbg(dev->dev, "read data[%x] 0x%04x\n", i, data[i]); | ||
248 | } | ||
249 | |||
250 | smbus_read_data(data, dev->buf, dev->buf_len); | ||
251 | |||
252 | dev->last_read_time = jiffies; | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static int highlander_i2c_write(struct highlander_i2c_dev *dev) | ||
258 | { | ||
259 | int i, cnt; | ||
260 | u16 data[16]; | ||
261 | |||
262 | smbus_write_data(dev->buf, data, dev->buf_len); | ||
263 | |||
264 | cnt = (dev->buf_len + 1) >> 1; | ||
265 | for (i = 0; i < cnt; i++) { | ||
266 | iowrite16(data[i], dev->base + SMTRDR + (i * sizeof(u16))); | ||
267 | dev_dbg(dev->dev, "write data[%x] 0x%04x\n", i, data[i]); | ||
268 | } | ||
269 | |||
270 | if (highlander_i2c_wait_for_bbsy(dev)) | ||
271 | return -EAGAIN; | ||
272 | |||
273 | highlander_i2c_start(dev); | ||
274 | |||
275 | return highlander_i2c_wait_xfer_done(dev); | ||
276 | } | ||
277 | |||
278 | static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, | ||
279 | unsigned short flags, char read_write, | ||
280 | u8 command, int size, | ||
281 | union i2c_smbus_data *data) | ||
282 | { | ||
283 | struct highlander_i2c_dev *dev = i2c_get_adapdata(adap); | ||
284 | int read = read_write & I2C_SMBUS_READ; | ||
285 | u16 tmp; | ||
286 | |||
287 | init_completion(&dev->cmd_complete); | ||
288 | |||
289 | dev_dbg(dev->dev, "addr %04x, command %02x, read_write %d, size %d\n", | ||
290 | addr, command, read_write, size); | ||
291 | |||
292 | /* | ||
293 | * Set up the buffer and transfer size | ||
294 | */ | ||
295 | switch (size) { | ||
296 | case I2C_SMBUS_BYTE_DATA: | ||
297 | dev->buf = &data->byte; | ||
298 | dev->buf_len = 1; | ||
299 | break; | ||
300 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
301 | dev->buf = &data->block[1]; | ||
302 | dev->buf_len = data->block[0]; | ||
303 | break; | ||
304 | default: | ||
305 | dev_err(dev->dev, "unsupported command %d\n", size); | ||
306 | return -EINVAL; | ||
307 | } | ||
308 | |||
309 | /* | ||
310 | * Encode the mode setting | ||
311 | */ | ||
312 | tmp = ioread16(dev->base + SMMR); | ||
313 | tmp &= ~(SMMR_MODE0 | SMMR_MODE1); | ||
314 | |||
315 | switch (dev->buf_len) { | ||
316 | case 1: | ||
317 | /* default */ | ||
318 | break; | ||
319 | case 8: | ||
320 | tmp |= SMMR_MODE0; | ||
321 | break; | ||
322 | case 16: | ||
323 | tmp |= SMMR_MODE1; | ||
324 | break; | ||
325 | case 32: | ||
326 | tmp |= (SMMR_MODE0 | SMMR_MODE1); | ||
327 | break; | ||
328 | default: | ||
329 | dev_err(dev->dev, "unsupported xfer size %d\n", dev->buf_len); | ||
330 | return -EINVAL; | ||
331 | } | ||
332 | |||
333 | iowrite16(tmp, dev->base + SMMR); | ||
334 | |||
335 | /* Ensure we're in a sane state */ | ||
336 | highlander_i2c_done(dev); | ||
337 | |||
338 | /* Set slave address */ | ||
339 | iowrite16((addr << 1) | read, dev->base + SMSMADR); | ||
340 | |||
341 | highlander_i2c_command(dev, command, dev->buf_len); | ||
342 | |||
343 | if (read) | ||
344 | return highlander_i2c_read(dev); | ||
345 | else | ||
346 | return highlander_i2c_write(dev); | ||
347 | } | ||
348 | |||
349 | static u32 highlander_i2c_func(struct i2c_adapter *adapter) | ||
350 | { | ||
351 | return I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK; | ||
352 | } | ||
353 | |||
354 | static const struct i2c_algorithm highlander_i2c_algo = { | ||
355 | .smbus_xfer = highlander_i2c_smbus_xfer, | ||
356 | .functionality = highlander_i2c_func, | ||
357 | }; | ||
358 | |||
359 | static int __devinit highlander_i2c_probe(struct platform_device *pdev) | ||
360 | { | ||
361 | struct highlander_i2c_dev *dev; | ||
362 | struct i2c_adapter *adap; | ||
363 | struct resource *res; | ||
364 | int ret; | ||
365 | |||
366 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
367 | if (unlikely(!res)) { | ||
368 | dev_err(&pdev->dev, "no mem resource\n"); | ||
369 | return -ENODEV; | ||
370 | } | ||
371 | |||
372 | dev = kzalloc(sizeof(struct highlander_i2c_dev), GFP_KERNEL); | ||
373 | if (unlikely(!dev)) | ||
374 | return -ENOMEM; | ||
375 | |||
376 | dev->base = ioremap_nocache(res->start, res->end - res->start + 1); | ||
377 | if (unlikely(!dev->base)) { | ||
378 | ret = -ENXIO; | ||
379 | goto err; | ||
380 | } | ||
381 | |||
382 | dev->dev = &pdev->dev; | ||
383 | platform_set_drvdata(pdev, dev); | ||
384 | |||
385 | dev->irq = platform_get_irq(pdev, 0); | ||
386 | if (iic_force_poll) | ||
387 | dev->irq = 0; | ||
388 | |||
389 | if (dev->irq) { | ||
390 | ret = request_irq(dev->irq, highlander_i2c_irq, IRQF_DISABLED, | ||
391 | pdev->name, dev); | ||
392 | if (unlikely(ret)) | ||
393 | goto err_unmap; | ||
394 | |||
395 | highlander_i2c_irq_enable(dev); | ||
396 | } else { | ||
397 | dev_notice(&pdev->dev, "no IRQ, using polling mode\n"); | ||
398 | highlander_i2c_irq_disable(dev); | ||
399 | } | ||
400 | |||
401 | dev->last_read_time = jiffies; /* initial read jiffies */ | ||
402 | |||
403 | highlander_i2c_setup(dev); | ||
404 | |||
405 | adap = &dev->adapter; | ||
406 | i2c_set_adapdata(adap, dev); | ||
407 | adap->owner = THIS_MODULE; | ||
408 | adap->class = I2C_CLASS_HWMON; | ||
409 | strlcpy(adap->name, "HL FPGA I2C adapter", sizeof(adap->name)); | ||
410 | adap->algo = &highlander_i2c_algo; | ||
411 | adap->dev.parent = &pdev->dev; | ||
412 | adap->nr = pdev->id; | ||
413 | |||
414 | /* | ||
415 | * Reset the adapter | ||
416 | */ | ||
417 | ret = highlander_i2c_reset(dev); | ||
418 | if (unlikely(ret)) { | ||
419 | dev_err(&pdev->dev, "controller didn't come up\n"); | ||
420 | goto err_free_irq; | ||
421 | } | ||
422 | |||
423 | ret = i2c_add_numbered_adapter(adap); | ||
424 | if (unlikely(ret)) { | ||
425 | dev_err(&pdev->dev, "failure adding adapter\n"); | ||
426 | goto err_free_irq; | ||
427 | } | ||
428 | |||
429 | return 0; | ||
430 | |||
431 | err_free_irq: | ||
432 | if (dev->irq) | ||
433 | free_irq(dev->irq, dev); | ||
434 | err_unmap: | ||
435 | iounmap(dev->base); | ||
436 | err: | ||
437 | kfree(dev); | ||
438 | |||
439 | platform_set_drvdata(pdev, NULL); | ||
440 | |||
441 | return ret; | ||
442 | } | ||
443 | |||
444 | static int __devexit highlander_i2c_remove(struct platform_device *pdev) | ||
445 | { | ||
446 | struct highlander_i2c_dev *dev = platform_get_drvdata(pdev); | ||
447 | |||
448 | i2c_del_adapter(&dev->adapter); | ||
449 | |||
450 | if (dev->irq) | ||
451 | free_irq(dev->irq, dev); | ||
452 | |||
453 | iounmap(dev->base); | ||
454 | kfree(dev); | ||
455 | |||
456 | platform_set_drvdata(pdev, NULL); | ||
457 | |||
458 | return 0; | ||
459 | } | ||
460 | |||
461 | static struct platform_driver highlander_i2c_driver = { | ||
462 | .driver = { | ||
463 | .name = "i2c-highlander", | ||
464 | .owner = THIS_MODULE, | ||
465 | }, | ||
466 | |||
467 | .probe = highlander_i2c_probe, | ||
468 | .remove = __devexit_p(highlander_i2c_remove), | ||
469 | }; | ||
470 | |||
471 | static int __init highlander_i2c_init(void) | ||
472 | { | ||
473 | return platform_driver_register(&highlander_i2c_driver); | ||
474 | } | ||
475 | |||
476 | static void __exit highlander_i2c_exit(void) | ||
477 | { | ||
478 | platform_driver_unregister(&highlander_i2c_driver); | ||
479 | } | ||
480 | |||
481 | module_init(highlander_i2c_init); | ||
482 | module_exit(highlander_i2c_exit); | ||
483 | |||
484 | MODULE_AUTHOR("Paul Mundt"); | ||
485 | MODULE_DESCRIPTION("Renesas Highlander FPGA I2C/SMBus adapter"); | ||
486 | MODULE_LICENSE("GPL v2"); | ||
487 | |||
488 | module_param(iic_force_poll, bool, 0); | ||
489 | module_param(iic_force_normal, bool, 0); | ||
490 | module_param(iic_timeout, int, 0); | ||
491 | module_param(iic_read_delay, int, 0); | ||
492 | |||
493 | MODULE_PARM_DESC(iic_force_poll, "Force polling mode"); | ||
494 | MODULE_PARM_DESC(iic_force_normal, | ||
495 | "Force normal mode (100 kHz), default is fast mode (400 kHz)"); | ||
496 | MODULE_PARM_DESC(iic_timeout, "Set timeout value in msecs (default 1000 ms)"); | ||
497 | MODULE_PARM_DESC(iic_read_delay, | ||
498 | "Delay between data read cycles (default 0 ms)"); | ||
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c index c6faf9bdad18..b2b8380f6602 100644 --- a/drivers/i2c/busses/i2c-parport-light.c +++ b/drivers/i2c/busses/i2c-parport-light.c | |||
@@ -123,11 +123,6 @@ static struct i2c_adapter parport_adapter = { | |||
123 | static int __devinit i2c_parport_probe(struct platform_device *pdev) | 123 | static int __devinit i2c_parport_probe(struct platform_device *pdev) |
124 | { | 124 | { |
125 | int err; | 125 | int err; |
126 | struct resource *res; | ||
127 | |||
128 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
129 | if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) | ||
130 | return -EBUSY; | ||
131 | 126 | ||
132 | /* Reset hardware to a sane state (SCL and SDA high) */ | 127 | /* Reset hardware to a sane state (SCL and SDA high) */ |
133 | parport_setsda(NULL, 1); | 128 | parport_setsda(NULL, 1); |
@@ -138,29 +133,19 @@ static int __devinit i2c_parport_probe(struct platform_device *pdev) | |||
138 | 133 | ||
139 | parport_adapter.dev.parent = &pdev->dev; | 134 | parport_adapter.dev.parent = &pdev->dev; |
140 | err = i2c_bit_add_bus(&parport_adapter); | 135 | err = i2c_bit_add_bus(&parport_adapter); |
141 | if (err) { | 136 | if (err) |
142 | dev_err(&pdev->dev, "Unable to register with I2C\n"); | 137 | dev_err(&pdev->dev, "Unable to register with I2C\n"); |
143 | goto exit_region; | ||
144 | } | ||
145 | return 0; | ||
146 | |||
147 | exit_region: | ||
148 | release_region(res->start, res->end - res->start + 1); | ||
149 | return err; | 138 | return err; |
150 | } | 139 | } |
151 | 140 | ||
152 | static int __devexit i2c_parport_remove(struct platform_device *pdev) | 141 | static int __devexit i2c_parport_remove(struct platform_device *pdev) |
153 | { | 142 | { |
154 | struct resource *res; | ||
155 | |||
156 | i2c_del_adapter(&parport_adapter); | 143 | i2c_del_adapter(&parport_adapter); |
157 | 144 | ||
158 | /* Un-init if needed (power off...) */ | 145 | /* Un-init if needed (power off...) */ |
159 | if (adapter_parm[type].init.val) | 146 | if (adapter_parm[type].init.val) |
160 | line_set(0, &adapter_parm[type].init); | 147 | line_set(0, &adapter_parm[type].init); |
161 | 148 | ||
162 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
163 | release_region(res->start, res->end - res->start + 1); | ||
164 | return 0; | 149 | return 0; |
165 | } | 150 | } |
166 | 151 | ||
@@ -175,12 +160,6 @@ static struct platform_driver i2c_parport_driver = { | |||
175 | 160 | ||
176 | static int __init i2c_parport_device_add(u16 address) | 161 | static int __init i2c_parport_device_add(u16 address) |
177 | { | 162 | { |
178 | struct resource res = { | ||
179 | .start = address, | ||
180 | .end = address + 2, | ||
181 | .name = DRVNAME, | ||
182 | .flags = IORESOURCE_IO, | ||
183 | }; | ||
184 | int err; | 163 | int err; |
185 | 164 | ||
186 | pdev = platform_device_alloc(DRVNAME, -1); | 165 | pdev = platform_device_alloc(DRVNAME, -1); |
@@ -190,13 +169,6 @@ static int __init i2c_parport_device_add(u16 address) | |||
190 | goto exit; | 169 | goto exit; |
191 | } | 170 | } |
192 | 171 | ||
193 | err = platform_device_add_resources(pdev, &res, 1); | ||
194 | if (err) { | ||
195 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | ||
196 | "(%d)\n", err); | ||
197 | goto exit_device_put; | ||
198 | } | ||
199 | |||
200 | err = platform_device_add(pdev); | 172 | err = platform_device_add(pdev); |
201 | if (err) { | 173 | if (err) { |
202 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | 174 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", |
@@ -231,13 +203,16 @@ static int __init i2c_parport_init(void) | |||
231 | base = DEFAULT_BASE; | 203 | base = DEFAULT_BASE; |
232 | } | 204 | } |
233 | 205 | ||
206 | if (!request_region(base, 3, DRVNAME)) | ||
207 | return -EBUSY; | ||
208 | |||
234 | if (!adapter_parm[type].getscl.val) | 209 | if (!adapter_parm[type].getscl.val) |
235 | parport_algo_data.getscl = NULL; | 210 | parport_algo_data.getscl = NULL; |
236 | 211 | ||
237 | /* Sets global pdev as a side effect */ | 212 | /* Sets global pdev as a side effect */ |
238 | err = i2c_parport_device_add(base); | 213 | err = i2c_parport_device_add(base); |
239 | if (err) | 214 | if (err) |
240 | goto exit; | 215 | goto exit_release; |
241 | 216 | ||
242 | err = platform_driver_register(&i2c_parport_driver); | 217 | err = platform_driver_register(&i2c_parport_driver); |
243 | if (err) | 218 | if (err) |
@@ -247,7 +222,8 @@ static int __init i2c_parport_init(void) | |||
247 | 222 | ||
248 | exit_device: | 223 | exit_device: |
249 | platform_device_unregister(pdev); | 224 | platform_device_unregister(pdev); |
250 | exit: | 225 | exit_release: |
226 | release_region(base, 3); | ||
251 | return err; | 227 | return err; |
252 | } | 228 | } |
253 | 229 | ||
@@ -255,6 +231,7 @@ static void __exit i2c_parport_exit(void) | |||
255 | { | 231 | { |
256 | platform_driver_unregister(&i2c_parport_driver); | 232 | platform_driver_unregister(&i2c_parport_driver); |
257 | platform_device_unregister(pdev); | 233 | platform_device_unregister(pdev); |
234 | release_region(base, 3); | ||
258 | } | 235 | } |
259 | 236 | ||
260 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 237 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index a119784bae10..f80df9ae5054 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -36,8 +36,8 @@ | |||
36 | #define DRIVER "i2c-pca-isa" | 36 | #define DRIVER "i2c-pca-isa" |
37 | #define IO_SIZE 4 | 37 | #define IO_SIZE 4 |
38 | 38 | ||
39 | static unsigned long base = 0x330; | 39 | static unsigned long base; |
40 | static int irq = 10; | 40 | static int irq = -1; |
41 | 41 | ||
42 | /* Data sheet recommends 59kHz for 100kHz operation due to variation | 42 | /* Data sheet recommends 59kHz for 100kHz operation due to variation |
43 | * in the actual clock rate */ | 43 | * in the actual clock rate */ |
@@ -107,6 +107,19 @@ static struct i2c_adapter pca_isa_ops = { | |||
107 | .timeout = 100, | 107 | .timeout = 100, |
108 | }; | 108 | }; |
109 | 109 | ||
110 | static int __devinit pca_isa_match(struct device *dev, unsigned int id) | ||
111 | { | ||
112 | int match = base != 0; | ||
113 | |||
114 | if (match) { | ||
115 | if (irq <= -1) | ||
116 | dev_warn(dev, "Using polling mode (specify irq)\n"); | ||
117 | } else | ||
118 | dev_err(dev, "Please specify I/O base\n"); | ||
119 | |||
120 | return match; | ||
121 | } | ||
122 | |||
110 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) | 123 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) |
111 | { | 124 | { |
112 | init_waitqueue_head(&pca_wait); | 125 | init_waitqueue_head(&pca_wait); |
@@ -153,7 +166,7 @@ static int __devexit pca_isa_remove(struct device *dev, unsigned int id) | |||
153 | { | 166 | { |
154 | i2c_del_adapter(&pca_isa_ops); | 167 | i2c_del_adapter(&pca_isa_ops); |
155 | 168 | ||
156 | if (irq > 0) { | 169 | if (irq > -1) { |
157 | disable_irq(irq); | 170 | disable_irq(irq); |
158 | free_irq(irq, &pca_isa_ops); | 171 | free_irq(irq, &pca_isa_ops); |
159 | } | 172 | } |
@@ -163,6 +176,7 @@ static int __devexit pca_isa_remove(struct device *dev, unsigned int id) | |||
163 | } | 176 | } |
164 | 177 | ||
165 | static struct isa_driver pca_isa_driver = { | 178 | static struct isa_driver pca_isa_driver = { |
179 | .match = pca_isa_match, | ||
166 | .probe = pca_isa_probe, | 180 | .probe = pca_isa_probe, |
167 | .remove = __devexit_p(pca_isa_remove), | 181 | .remove = __devexit_p(pca_isa_remove), |
168 | .driver = { | 182 | .driver = { |
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 862eb352a2d9..73dc52e114eb 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c | |||
@@ -36,6 +36,7 @@ | |||
36 | VT8237S 0x3372 yes | 36 | VT8237S 0x3372 yes |
37 | VT8251 0x3287 yes | 37 | VT8251 0x3287 yes |
38 | CX700 0x8324 yes | 38 | CX700 0x8324 yes |
39 | VX800/VX820 0x8353 yes | ||
39 | 40 | ||
40 | Note: we assume there can only be one device, with one SMBus interface. | 41 | Note: we assume there can only be one device, with one SMBus interface. |
41 | */ | 42 | */ |
@@ -82,6 +83,7 @@ static unsigned short SMBHSTCFG = 0xD2; | |||
82 | #define VT596_BYTE 0x04 | 83 | #define VT596_BYTE 0x04 |
83 | #define VT596_BYTE_DATA 0x08 | 84 | #define VT596_BYTE_DATA 0x08 |
84 | #define VT596_WORD_DATA 0x0C | 85 | #define VT596_WORD_DATA 0x0C |
86 | #define VT596_PROC_CALL 0x10 | ||
85 | #define VT596_BLOCK_DATA 0x14 | 87 | #define VT596_BLOCK_DATA 0x14 |
86 | #define VT596_I2C_BLOCK_DATA 0x34 | 88 | #define VT596_I2C_BLOCK_DATA 0x34 |
87 | 89 | ||
@@ -232,6 +234,12 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
232 | } | 234 | } |
233 | size = VT596_WORD_DATA; | 235 | size = VT596_WORD_DATA; |
234 | break; | 236 | break; |
237 | case I2C_SMBUS_PROC_CALL: | ||
238 | outb_p(command, SMBHSTCMD); | ||
239 | outb_p(data->word & 0xff, SMBHSTDAT0); | ||
240 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); | ||
241 | size = VT596_PROC_CALL; | ||
242 | break; | ||
235 | case I2C_SMBUS_I2C_BLOCK_DATA: | 243 | case I2C_SMBUS_I2C_BLOCK_DATA: |
236 | if (!(vt596_features & FEATURE_I2CBLOCK)) | 244 | if (!(vt596_features & FEATURE_I2CBLOCK)) |
237 | goto exit_unsupported; | 245 | goto exit_unsupported; |
@@ -262,6 +270,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
262 | if (status) | 270 | if (status) |
263 | return status; | 271 | return status; |
264 | 272 | ||
273 | if (size == VT596_PROC_CALL) | ||
274 | read_write = I2C_SMBUS_READ; | ||
275 | |||
265 | if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) | 276 | if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) |
266 | return 0; | 277 | return 0; |
267 | 278 | ||
@@ -271,6 +282,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
271 | data->byte = inb_p(SMBHSTDAT0); | 282 | data->byte = inb_p(SMBHSTDAT0); |
272 | break; | 283 | break; |
273 | case VT596_WORD_DATA: | 284 | case VT596_WORD_DATA: |
285 | case VT596_PROC_CALL: | ||
274 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); | 286 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); |
275 | break; | 287 | break; |
276 | case VT596_I2C_BLOCK_DATA: | 288 | case VT596_I2C_BLOCK_DATA: |
@@ -295,7 +307,7 @@ static u32 vt596_func(struct i2c_adapter *adapter) | |||
295 | { | 307 | { |
296 | u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 308 | u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
297 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | 309 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | |
298 | I2C_FUNC_SMBUS_BLOCK_DATA; | 310 | I2C_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_BLOCK_DATA; |
299 | 311 | ||
300 | if (vt596_features & FEATURE_I2CBLOCK) | 312 | if (vt596_features & FEATURE_I2CBLOCK) |
301 | func |= I2C_FUNC_SMBUS_I2C_BLOCK; | 313 | func |= I2C_FUNC_SMBUS_I2C_BLOCK; |
@@ -396,6 +408,7 @@ found: | |||
396 | 408 | ||
397 | switch (pdev->device) { | 409 | switch (pdev->device) { |
398 | case PCI_DEVICE_ID_VIA_CX700: | 410 | case PCI_DEVICE_ID_VIA_CX700: |
411 | case PCI_DEVICE_ID_VIA_VX800: | ||
399 | case PCI_DEVICE_ID_VIA_8251: | 412 | case PCI_DEVICE_ID_VIA_8251: |
400 | case PCI_DEVICE_ID_VIA_8237: | 413 | case PCI_DEVICE_ID_VIA_8237: |
401 | case PCI_DEVICE_ID_VIA_8237A: | 414 | case PCI_DEVICE_ID_VIA_8237A: |
@@ -459,6 +472,8 @@ static struct pci_device_id vt596_ids[] = { | |||
459 | .driver_data = SMBBA3 }, | 472 | .driver_data = SMBBA3 }, |
460 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700), | 473 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700), |
461 | .driver_data = SMBBA3 }, | 474 | .driver_data = SMBBA3 }, |
475 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX800), | ||
476 | .driver_data = SMBBA3 }, | ||
462 | { 0, } | 477 | { 0, } |
463 | }; | 478 | }; |
464 | 479 | ||