aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-14 19:53:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-14 19:53:02 -0400
commit278429cff8809958d25415ba0ed32b59866ab1a8 (patch)
tree1085100d82525ff7c0fc93fad475e4320f293548 /drivers/i2c
parente413b210c541acac1a194085627db28a122f3bdf (diff)
parenta05f2c5a2735ee1d68770137fbbfc334d3b9cda9 (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')
-rw-r--r--drivers/i2c/busses/Kconfig20
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-highlander.c498
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c39
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c20
-rw-r--r--drivers/i2c/busses/i2c-viapro.c17
-rw-r--r--drivers/i2c/chips/isp1301_omap.c141
-rw-r--r--drivers/i2c/chips/tps65010.c12
-rw-r--r--drivers/i2c/i2c-core.c35
9 files changed, 655 insertions, 128 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
56config I2C_AMD756_S4882 56config 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
149config I2C_NFORCE2_S4985 149config 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
211config I2C_VIAPRO 211config 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
335config 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
333config I2C_IBM_IIC 347config 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
31obj-$(CONFIG_I2C_CPM) += i2c-cpm.o 31obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
32obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o 32obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o
33obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 33obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
34obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o
34obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 35obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
35obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 36obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
36obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 37obj-$(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
43struct 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
54static int iic_force_poll, iic_force_normal;
55static int iic_timeout = 1000, iic_read_delay;
56
57static 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
62static 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
67static inline void highlander_i2c_start(struct highlander_i2c_dev *dev)
68{
69 iowrite16(ioread16(dev->base + SMCR) | SMCR_START, dev->base + SMCR);
70}
71
72static inline void highlander_i2c_done(struct highlander_i2c_dev *dev)
73{
74 iowrite16(ioread16(dev->base + SMCR) | SMCR_IRIC, dev->base + SMCR);
75}
76
77static 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
92static 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
103static 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
114static 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
128static 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
145static 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
151static 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
163static 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
173static 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
200static 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
212static 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
257static 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
278static 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
349static u32 highlander_i2c_func(struct i2c_adapter *adapter)
350{
351 return I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK;
352}
353
354static const struct i2c_algorithm highlander_i2c_algo = {
355 .smbus_xfer = highlander_i2c_smbus_xfer,
356 .functionality = highlander_i2c_func,
357};
358
359static 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
431err_free_irq:
432 if (dev->irq)
433 free_irq(dev->irq, dev);
434err_unmap:
435 iounmap(dev->base);
436err:
437 kfree(dev);
438
439 platform_set_drvdata(pdev, NULL);
440
441 return ret;
442}
443
444static 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
461static 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
471static int __init highlander_i2c_init(void)
472{
473 return platform_driver_register(&highlander_i2c_driver);
474}
475
476static void __exit highlander_i2c_exit(void)
477{
478 platform_driver_unregister(&highlander_i2c_driver);
479}
480
481module_init(highlander_i2c_init);
482module_exit(highlander_i2c_exit);
483
484MODULE_AUTHOR("Paul Mundt");
485MODULE_DESCRIPTION("Renesas Highlander FPGA I2C/SMBus adapter");
486MODULE_LICENSE("GPL v2");
487
488module_param(iic_force_poll, bool, 0);
489module_param(iic_force_normal, bool, 0);
490module_param(iic_timeout, int, 0);
491module_param(iic_read_delay, int, 0);
492
493MODULE_PARM_DESC(iic_force_poll, "Force polling mode");
494MODULE_PARM_DESC(iic_force_normal,
495 "Force normal mode (100 kHz), default is fast mode (400 kHz)");
496MODULE_PARM_DESC(iic_timeout, "Set timeout value in msecs (default 1000 ms)");
497MODULE_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 = {
123static int __devinit i2c_parport_probe(struct platform_device *pdev) 123static 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
147exit_region:
148 release_region(res->start, res->end - res->start + 1);
149 return err; 138 return err;
150} 139}
151 140
152static int __devexit i2c_parport_remove(struct platform_device *pdev) 141static 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
176static int __init i2c_parport_device_add(u16 address) 161static 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
248exit_device: 223exit_device:
249 platform_device_unregister(pdev); 224 platform_device_unregister(pdev);
250exit: 225exit_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
260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 237MODULE_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
39static unsigned long base = 0x330; 39static unsigned long base;
40static int irq = 10; 40static 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
110static 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
110static int __devinit pca_isa_probe(struct device *dev, unsigned int id) 123static 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
165static struct isa_driver pca_isa_driver = { 178static 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
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 4655b794ebe3..28902ebd5539 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -49,10 +49,9 @@ MODULE_LICENSE("GPL");
49 49
50struct isp1301 { 50struct isp1301 {
51 struct otg_transceiver otg; 51 struct otg_transceiver otg;
52 struct i2c_client client; 52 struct i2c_client *client;
53 void (*i2c_release)(struct device *dev); 53 void (*i2c_release)(struct device *dev);
54 54
55 int irq;
56 int irq_type; 55 int irq_type;
57 56
58 u32 last_otg_ctrl; 57 u32 last_otg_ctrl;
@@ -138,14 +137,6 @@ static inline void notresponding(struct isp1301 *isp)
138 137
139/*-------------------------------------------------------------------------*/ 138/*-------------------------------------------------------------------------*/
140 139
141/* only two addresses possible */
142#define ISP_BASE 0x2c
143static unsigned short normal_i2c[] = {
144 ISP_BASE, ISP_BASE + 1,
145 I2C_CLIENT_END };
146
147I2C_CLIENT_INSMOD;
148
149static struct i2c_driver isp1301_driver; 140static struct i2c_driver isp1301_driver;
150 141
151/* smbus apis are used for portability */ 142/* smbus apis are used for portability */
@@ -153,25 +144,25 @@ static struct i2c_driver isp1301_driver;
153static inline u8 144static inline u8
154isp1301_get_u8(struct isp1301 *isp, u8 reg) 145isp1301_get_u8(struct isp1301 *isp, u8 reg)
155{ 146{
156 return i2c_smbus_read_byte_data(&isp->client, reg + 0); 147 return i2c_smbus_read_byte_data(isp->client, reg + 0);
157} 148}
158 149
159static inline int 150static inline int
160isp1301_get_u16(struct isp1301 *isp, u8 reg) 151isp1301_get_u16(struct isp1301 *isp, u8 reg)
161{ 152{
162 return i2c_smbus_read_word_data(&isp->client, reg); 153 return i2c_smbus_read_word_data(isp->client, reg);
163} 154}
164 155
165static inline int 156static inline int
166isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) 157isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
167{ 158{
168 return i2c_smbus_write_byte_data(&isp->client, reg + 0, bits); 159 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
169} 160}
170 161
171static inline int 162static inline int
172isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) 163isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
173{ 164{
174 return i2c_smbus_write_byte_data(&isp->client, reg + 1, bits); 165 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
175} 166}
176 167
177/*-------------------------------------------------------------------------*/ 168/*-------------------------------------------------------------------------*/
@@ -349,10 +340,10 @@ isp1301_defer_work(struct isp1301 *isp, int work)
349 int status; 340 int status;
350 341
351 if (isp && !test_and_set_bit(work, &isp->todo)) { 342 if (isp && !test_and_set_bit(work, &isp->todo)) {
352 (void) get_device(&isp->client.dev); 343 (void) get_device(&isp->client->dev);
353 status = schedule_work(&isp->work); 344 status = schedule_work(&isp->work);
354 if (!status && !isp->working) 345 if (!status && !isp->working)
355 dev_vdbg(&isp->client.dev, 346 dev_vdbg(&isp->client->dev,
356 "work item %d may be lost\n", work); 347 "work item %d may be lost\n", work);
357 } 348 }
358} 349}
@@ -1135,7 +1126,7 @@ isp1301_work(struct work_struct *work)
1135 /* transfer state from otg engine to isp1301 */ 1126 /* transfer state from otg engine to isp1301 */
1136 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { 1127 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1137 otg_update_isp(isp); 1128 otg_update_isp(isp);
1138 put_device(&isp->client.dev); 1129 put_device(&isp->client->dev);
1139 } 1130 }
1140#endif 1131#endif
1141 /* transfer state from isp1301 to otg engine */ 1132 /* transfer state from isp1301 to otg engine */
@@ -1143,7 +1134,7 @@ isp1301_work(struct work_struct *work)
1143 u8 stat = isp1301_clear_latch(isp); 1134 u8 stat = isp1301_clear_latch(isp);
1144 1135
1145 isp_update_otg(isp, stat); 1136 isp_update_otg(isp, stat);
1146 put_device(&isp->client.dev); 1137 put_device(&isp->client->dev);
1147 } 1138 }
1148 1139
1149 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { 1140 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
@@ -1178,7 +1169,7 @@ isp1301_work(struct work_struct *work)
1178 } 1169 }
1179 host_resume(isp); 1170 host_resume(isp);
1180 // mdelay(10); 1171 // mdelay(10);
1181 put_device(&isp->client.dev); 1172 put_device(&isp->client->dev);
1182 } 1173 }
1183 1174
1184 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { 1175 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
@@ -1187,15 +1178,15 @@ isp1301_work(struct work_struct *work)
1187 if (!stop) 1178 if (!stop)
1188 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); 1179 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1189#endif 1180#endif
1190 put_device(&isp->client.dev); 1181 put_device(&isp->client->dev);
1191 } 1182 }
1192 1183
1193 if (isp->todo) 1184 if (isp->todo)
1194 dev_vdbg(&isp->client.dev, 1185 dev_vdbg(&isp->client->dev,
1195 "work done, todo = 0x%lx\n", 1186 "work done, todo = 0x%lx\n",
1196 isp->todo); 1187 isp->todo);
1197 if (stop) { 1188 if (stop) {
1198 dev_dbg(&isp->client.dev, "stop\n"); 1189 dev_dbg(&isp->client->dev, "stop\n");
1199 break; 1190 break;
1200 } 1191 }
1201 } while (isp->todo); 1192 } while (isp->todo);
@@ -1219,7 +1210,7 @@ static void isp1301_release(struct device *dev)
1219{ 1210{
1220 struct isp1301 *isp; 1211 struct isp1301 *isp;
1221 1212
1222 isp = container_of(dev, struct isp1301, client.dev); 1213 isp = dev_get_drvdata(dev);
1223 1214
1224 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ 1215 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1225 if (isp->i2c_release) 1216 if (isp->i2c_release)
@@ -1229,15 +1220,15 @@ static void isp1301_release(struct device *dev)
1229 1220
1230static struct isp1301 *the_transceiver; 1221static struct isp1301 *the_transceiver;
1231 1222
1232static int isp1301_detach_client(struct i2c_client *i2c) 1223static int __exit isp1301_remove(struct i2c_client *i2c)
1233{ 1224{
1234 struct isp1301 *isp; 1225 struct isp1301 *isp;
1235 1226
1236 isp = container_of(i2c, struct isp1301, client); 1227 isp = i2c_get_clientdata(i2c);
1237 1228
1238 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); 1229 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1239 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); 1230 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1240 free_irq(isp->irq, isp); 1231 free_irq(i2c->irq, isp);
1241#ifdef CONFIG_USB_OTG 1232#ifdef CONFIG_USB_OTG
1242 otg_unbind(isp); 1233 otg_unbind(isp);
1243#endif 1234#endif
@@ -1252,7 +1243,7 @@ static int isp1301_detach_client(struct i2c_client *i2c)
1252 put_device(&i2c->dev); 1243 put_device(&i2c->dev);
1253 the_transceiver = 0; 1244 the_transceiver = 0;
1254 1245
1255 return i2c_detach_client(i2c); 1246 return 0;
1256} 1247}
1257 1248
1258/*-------------------------------------------------------------------------*/ 1249/*-------------------------------------------------------------------------*/
@@ -1285,7 +1276,7 @@ static int isp1301_otg_enable(struct isp1301 *isp)
1285 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1276 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1286 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); 1277 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1287 1278
1288 dev_info(&isp->client.dev, "ready for dual-role USB ...\n"); 1279 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1289 1280
1290 return 0; 1281 return 0;
1291} 1282}
@@ -1310,7 +1301,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1310 1301
1311#ifdef CONFIG_USB_OTG 1302#ifdef CONFIG_USB_OTG
1312 isp->otg.host = host; 1303 isp->otg.host = host;
1313 dev_dbg(&isp->client.dev, "registered host\n"); 1304 dev_dbg(&isp->client->dev, "registered host\n");
1314 host_suspend(isp); 1305 host_suspend(isp);
1315 if (isp->otg.gadget) 1306 if (isp->otg.gadget)
1316 return isp1301_otg_enable(isp); 1307 return isp1301_otg_enable(isp);
@@ -1325,7 +1316,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1325 if (machine_is_omap_h2()) 1316 if (machine_is_omap_h2())
1326 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); 1317 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1327 1318
1328 dev_info(&isp->client.dev, "A-Host sessions ok\n"); 1319 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1329 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, 1320 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1330 INTR_ID_GND); 1321 INTR_ID_GND);
1331 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1322 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
@@ -1343,7 +1334,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1343 return 0; 1334 return 0;
1344 1335
1345#else 1336#else
1346 dev_dbg(&isp->client.dev, "host sessions not allowed\n"); 1337 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1347 return -EINVAL; 1338 return -EINVAL;
1348#endif 1339#endif
1349 1340
@@ -1370,7 +1361,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1370 1361
1371#ifdef CONFIG_USB_OTG 1362#ifdef CONFIG_USB_OTG
1372 isp->otg.gadget = gadget; 1363 isp->otg.gadget = gadget;
1373 dev_dbg(&isp->client.dev, "registered gadget\n"); 1364 dev_dbg(&isp->client->dev, "registered gadget\n");
1374 /* gadget driver may be suspended until vbus_connect () */ 1365 /* gadget driver may be suspended until vbus_connect () */
1375 if (isp->otg.host) 1366 if (isp->otg.host)
1376 return isp1301_otg_enable(isp); 1367 return isp1301_otg_enable(isp);
@@ -1395,7 +1386,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1395 INTR_SESS_VLD); 1386 INTR_SESS_VLD);
1396 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1387 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1397 INTR_VBUS_VLD); 1388 INTR_VBUS_VLD);
1398 dev_info(&isp->client.dev, "B-Peripheral sessions ok\n"); 1389 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1399 dump_regs(isp, __func__); 1390 dump_regs(isp, __func__);
1400 1391
1401 /* If this has a Mini-AB connector, this mode is highly 1392 /* If this has a Mini-AB connector, this mode is highly
@@ -1408,7 +1399,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1408 return 0; 1399 return 0;
1409 1400
1410#else 1401#else
1411 dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n"); 1402 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1412 return -EINVAL; 1403 return -EINVAL;
1413#endif 1404#endif
1414} 1405}
@@ -1508,12 +1499,10 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1508 1499
1509/*-------------------------------------------------------------------------*/ 1500/*-------------------------------------------------------------------------*/
1510 1501
1511/* no error returns, they'd just make bus scanning stop */ 1502static int __init isp1301_probe(struct i2c_client *i2c)
1512static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1513{ 1503{
1514 int status; 1504 int status;
1515 struct isp1301 *isp; 1505 struct isp1301 *isp;
1516 struct i2c_client *i2c;
1517 1506
1518 if (the_transceiver) 1507 if (the_transceiver)
1519 return 0; 1508 return 0;
@@ -1527,37 +1516,19 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1527 isp->timer.function = isp1301_timer; 1516 isp->timer.function = isp1301_timer;
1528 isp->timer.data = (unsigned long) isp; 1517 isp->timer.data = (unsigned long) isp;
1529 1518
1530 isp->irq = -1; 1519 i2c_set_clientdata(i2c, isp);
1531 isp->client.addr = address; 1520 isp->client = i2c;
1532 i2c_set_clientdata(&isp->client, isp);
1533 isp->client.adapter = bus;
1534 isp->client.driver = &isp1301_driver;
1535 strlcpy(isp->client.name, DRIVER_NAME, I2C_NAME_SIZE);
1536 i2c = &isp->client;
1537
1538 /* if this is a true probe, verify the chip ... */
1539 if (kind < 0) {
1540 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1541 if (status != I2C_VENDOR_ID_PHILIPS) {
1542 dev_dbg(&bus->dev, "addr %d not philips id: %d\n",
1543 address, status);
1544 goto fail1;
1545 }
1546 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1547 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1548 dev_dbg(&bus->dev, "%d not isp1301, %d\n",
1549 address, status);
1550 goto fail1;
1551 }
1552 }
1553 1521
1554 status = i2c_attach_client(i2c); 1522 /* verify the chip (shouldn't be necesary) */
1555 if (status < 0) { 1523 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1556 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n", 1524 if (status != I2C_VENDOR_ID_PHILIPS) {
1557 DRIVER_NAME, address, status); 1525 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
1558fail1: 1526 goto fail;
1559 kfree(isp); 1527 }
1560 return 0; 1528 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1529 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1530 dev_dbg(&i2c->dev, "not isp1301, %d\n", status);
1531 goto fail;
1561 } 1532 }
1562 isp->i2c_release = i2c->dev.release; 1533 isp->i2c_release = i2c->dev.release;
1563 i2c->dev.release = isp1301_release; 1534 i2c->dev.release = isp1301_release;
@@ -1586,7 +1557,7 @@ fail1:
1586 status = otg_bind(isp); 1557 status = otg_bind(isp);
1587 if (status < 0) { 1558 if (status < 0) {
1588 dev_dbg(&i2c->dev, "can't bind OTG\n"); 1559 dev_dbg(&i2c->dev, "can't bind OTG\n");
1589 goto fail2; 1560 goto fail;
1590 } 1561 }
1591#endif 1562#endif
1592 1563
@@ -1599,26 +1570,21 @@ fail1:
1599 1570
1600 /* IRQ wired at M14 */ 1571 /* IRQ wired at M14 */
1601 omap_cfg_reg(M14_1510_GPIO2); 1572 omap_cfg_reg(M14_1510_GPIO2);
1602 isp->irq = OMAP_GPIO_IRQ(2);
1603 if (gpio_request(2, "isp1301") == 0) 1573 if (gpio_request(2, "isp1301") == 0)
1604 gpio_direction_input(2); 1574 gpio_direction_input(2);
1605 isp->irq_type = IRQF_TRIGGER_FALLING; 1575 isp->irq_type = IRQF_TRIGGER_FALLING;
1606 } 1576 }
1607 1577
1608 isp->irq_type |= IRQF_SAMPLE_RANDOM; 1578 isp->irq_type |= IRQF_SAMPLE_RANDOM;
1609 status = request_irq(isp->irq, isp1301_irq, 1579 status = request_irq(i2c->irq, isp1301_irq,
1610 isp->irq_type, DRIVER_NAME, isp); 1580 isp->irq_type, DRIVER_NAME, isp);
1611 if (status < 0) { 1581 if (status < 0) {
1612 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", 1582 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1613 isp->irq, status); 1583 i2c->irq, status);
1614#ifdef CONFIG_USB_OTG 1584 goto fail;
1615fail2:
1616#endif
1617 i2c_detach_client(i2c);
1618 goto fail1;
1619 } 1585 }
1620 1586
1621 isp->otg.dev = &isp->client.dev; 1587 isp->otg.dev = &i2c->dev;
1622 isp->otg.label = DRIVER_NAME; 1588 isp->otg.label = DRIVER_NAME;
1623 1589
1624 isp->otg.set_host = isp1301_set_host, 1590 isp->otg.set_host = isp1301_set_host,
@@ -1649,22 +1615,25 @@ fail2:
1649 status); 1615 status);
1650 1616
1651 return 0; 1617 return 0;
1652}
1653 1618
1654static int isp1301_scan_bus(struct i2c_adapter *bus) 1619fail:
1655{ 1620 kfree(isp);
1656 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA 1621 return -ENODEV;
1657 | I2C_FUNC_SMBUS_READ_WORD_DATA))
1658 return -EINVAL;
1659 return i2c_probe(bus, &addr_data, isp1301_probe);
1660} 1622}
1661 1623
1624static const struct i2c_device_id isp1301_id[] = {
1625 { "isp1301_omap", 0 },
1626 { }
1627};
1628MODULE_DEVICE_TABLE(i2c, isp1301_id);
1629
1662static struct i2c_driver isp1301_driver = { 1630static struct i2c_driver isp1301_driver = {
1663 .driver = { 1631 .driver = {
1664 .name = "isp1301_omap", 1632 .name = "isp1301_omap",
1665 }, 1633 },
1666 .attach_adapter = isp1301_scan_bus, 1634 .probe = isp1301_probe,
1667 .detach_client = isp1301_detach_client, 1635 .remove = __exit_p(isp1301_remove),
1636 .id_table = isp1301_id,
1668}; 1637};
1669 1638
1670/*-------------------------------------------------------------------------*/ 1639/*-------------------------------------------------------------------------*/
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index cf02e8fceb42..acf8b9d5f575 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -456,14 +456,17 @@ static irqreturn_t tps65010_irq(int irq, void *_tps)
456 456
457/* offsets 0..3 == GPIO1..GPIO4 457/* offsets 0..3 == GPIO1..GPIO4
458 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes) 458 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
459 * offset 6 == vibrator motor driver
459 */ 460 */
460static void 461static void
461tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 462tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
462{ 463{
463 if (offset < 4) 464 if (offset < 4)
464 tps65010_set_gpio_out_value(offset + 1, value); 465 tps65010_set_gpio_out_value(offset + 1, value);
465 else 466 else if (offset < 6)
466 tps65010_set_led(offset - 3, value ? ON : OFF); 467 tps65010_set_led(offset - 3, value ? ON : OFF);
468 else
469 tps65010_set_vib(value);
467} 470}
468 471
469static int 472static int
@@ -477,8 +480,10 @@ tps65010_output(struct gpio_chip *chip, unsigned offset, int value)
477 if (!(tps->outmask & (1 << offset))) 480 if (!(tps->outmask & (1 << offset)))
478 return -EINVAL; 481 return -EINVAL;
479 tps65010_set_gpio_out_value(offset + 1, value); 482 tps65010_set_gpio_out_value(offset + 1, value);
480 } else 483 } else if (offset < 6)
481 tps65010_set_led(offset - 3, value ? ON : OFF); 484 tps65010_set_led(offset - 3, value ? ON : OFF);
485 else
486 tps65010_set_vib(value);
482 487
483 return 0; 488 return 0;
484} 489}
@@ -646,7 +651,7 @@ static int tps65010_probe(struct i2c_client *client,
646 tps->chip.get = tps65010_gpio_get; 651 tps->chip.get = tps65010_gpio_get;
647 652
648 tps->chip.base = board->base; 653 tps->chip.base = board->base;
649 tps->chip.ngpio = 6; 654 tps->chip.ngpio = 7;
650 tps->chip.can_sleep = 1; 655 tps->chip.can_sleep = 1;
651 656
652 status = gpiochip_add(&tps->chip); 657 status = gpiochip_add(&tps->chip);
@@ -675,6 +680,7 @@ static const struct i2c_device_id tps65010_id[] = {
675 { "tps65011", TPS65011 }, 680 { "tps65011", TPS65011 },
676 { "tps65012", TPS65012 }, 681 { "tps65012", TPS65012 },
677 { "tps65013", TPS65013 }, 682 { "tps65013", TPS65013 },
683 { "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */
678 { } 684 { }
679}; 685};
680MODULE_DEVICE_TABLE(i2c, tps65010_id); 686MODULE_DEVICE_TABLE(i2c, tps65010_id);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index b346a687ab59..42e852d79ffa 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -437,6 +437,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
437{ 437{
438 int res = 0, dummy; 438 int res = 0, dummy;
439 439
440 /* Can't register until after driver model init */
441 if (unlikely(WARN_ON(!i2c_bus_type.p)))
442 return -EAGAIN;
443
440 mutex_init(&adap->bus_lock); 444 mutex_init(&adap->bus_lock);
441 mutex_init(&adap->clist_lock); 445 mutex_init(&adap->clist_lock);
442 INIT_LIST_HEAD(&adap->clients); 446 INIT_LIST_HEAD(&adap->clients);
@@ -696,6 +700,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
696{ 700{
697 int res; 701 int res;
698 702
703 /* Can't register until after driver model init */
704 if (unlikely(WARN_ON(!i2c_bus_type.p)))
705 return -EAGAIN;
706
699 /* new style driver methods can't mix with legacy ones */ 707 /* new style driver methods can't mix with legacy ones */
700 if (is_newstyle_driver(driver)) { 708 if (is_newstyle_driver(driver)) {
701 if (driver->attach_adapter || driver->detach_adapter 709 if (driver->attach_adapter || driver->detach_adapter
@@ -978,7 +986,10 @@ static void __exit i2c_exit(void)
978 bus_unregister(&i2c_bus_type); 986 bus_unregister(&i2c_bus_type);
979} 987}
980 988
981subsys_initcall(i2c_init); 989/* We must initialize early, because some subsystems register i2c drivers
990 * in subsys_initcall() code, but are linked (and initialized) before i2c.
991 */
992postcore_initcall(i2c_init);
982module_exit(i2c_exit); 993module_exit(i2c_exit);
983 994
984/* ---------------------------------------------------- 995/* ----------------------------------------------------
@@ -1677,6 +1688,28 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1677EXPORT_SYMBOL(i2c_smbus_write_word_data); 1688EXPORT_SYMBOL(i2c_smbus_write_word_data);
1678 1689
1679/** 1690/**
1691 * i2c_smbus_process_call - SMBus "process call" protocol
1692 * @client: Handle to slave device
1693 * @command: Byte interpreted by slave
1694 * @value: 16-bit "word" being written
1695 *
1696 * This executes the SMBus "process call" protocol, returning negative errno
1697 * else a 16-bit unsigned "word" received from the device.
1698 */
1699s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value)
1700{
1701 union i2c_smbus_data data;
1702 int status;
1703 data.word = value;
1704
1705 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1706 I2C_SMBUS_WRITE, command,
1707 I2C_SMBUS_PROC_CALL, &data);
1708 return (status < 0) ? status : data.word;
1709}
1710EXPORT_SYMBOL(i2c_smbus_process_call);
1711
1712/**
1680 * i2c_smbus_read_block_data - SMBus "block read" protocol 1713 * i2c_smbus_read_block_data - SMBus "block read" protocol
1681 * @client: Handle to slave device 1714 * @client: Handle to slave device
1682 * @command: Byte interpreted by slave 1715 * @command: Byte interpreted by slave