aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@csr.com>2008-10-20 11:07:19 -0400
committerDavid Vrabel <david.vrabel@csr.com>2008-10-20 11:07:19 -0400
commit61e0e79ee3c609eb34edf2fe023708cba6a79b1f (patch)
tree663deacffd4071120dc9badb70428fe5f124c7b9 /drivers/i2c
parentc15895ef30c2c03e99802951787183039a349d32 (diff)
parent0cfd81031a26717fe14380d18275f8e217571615 (diff)
Merge branch 'master' into for-upstream
Conflicts: Documentation/ABI/testing/sysfs-bus-usb drivers/Makefile
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-mpc.c1
-rw-r--r--drivers/i2c/busses/i2c-omap.c12
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c39
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c22
-rw-r--r--drivers/i2c/busses/i2c-powermac.c29
-rw-r--r--drivers/i2c/busses/i2c-pxa.c94
-rw-r--r--drivers/i2c/busses/i2c-viapro.c17
-rw-r--r--drivers/i2c/chips/Kconfig11
-rw-r--r--drivers/i2c/chips/Makefile1
-rw-r--r--drivers/i2c/chips/isp1301_omap.c141
-rw-r--r--drivers/i2c/chips/mcu_mpc8349emitx.c209
-rw-r--r--drivers/i2c/chips/tps65010.c12
-rw-r--r--drivers/i2c/i2c-core.c35
-rw-r--r--drivers/i2c/i2c-dev.c6
17 files changed, 996 insertions, 152 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-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 27443f073bc9..a9a45fcc8544 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -312,7 +312,6 @@ static struct i2c_adapter mpc_ops = {
312 .name = "MPC adapter", 312 .name = "MPC adapter",
313 .id = I2C_HW_MPC107, 313 .id = I2C_HW_MPC107,
314 .algo = &mpc_algo, 314 .algo = &mpc_algo,
315 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
316 .timeout = 1, 315 .timeout = 1,
317}; 316};
318 317
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index e7eb7bf9ddec..608038d64f81 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -589,11 +589,16 @@ omap_i2c_probe(struct platform_device *pdev)
589 589
590 dev->dev = &pdev->dev; 590 dev->dev = &pdev->dev;
591 dev->irq = irq->start; 591 dev->irq = irq->start;
592 dev->base = (void __iomem *) IO_ADDRESS(mem->start); 592 dev->base = ioremap(mem->start, mem->end - mem->start + 1);
593 if (!dev->base) {
594 r = -ENOMEM;
595 goto err_free_mem;
596 }
597
593 platform_set_drvdata(pdev, dev); 598 platform_set_drvdata(pdev, dev);
594 599
595 if ((r = omap_i2c_get_clocks(dev)) != 0) 600 if ((r = omap_i2c_get_clocks(dev)) != 0)
596 goto err_free_mem; 601 goto err_iounmap;
597 602
598 omap_i2c_unidle(dev); 603 omap_i2c_unidle(dev);
599 604
@@ -640,6 +645,8 @@ err_unuse_clocks:
640 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 645 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
641 omap_i2c_idle(dev); 646 omap_i2c_idle(dev);
642 omap_i2c_put_clocks(dev); 647 omap_i2c_put_clocks(dev);
648err_iounmap:
649 iounmap(dev->base);
643err_free_mem: 650err_free_mem:
644 platform_set_drvdata(pdev, NULL); 651 platform_set_drvdata(pdev, NULL);
645 kfree(dev); 652 kfree(dev);
@@ -661,6 +668,7 @@ omap_i2c_remove(struct platform_device *pdev)
661 i2c_del_adapter(&dev->adapter); 668 i2c_del_adapter(&dev->adapter);
662 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 669 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
663 omap_i2c_put_clocks(dev); 670 omap_i2c_put_clocks(dev);
671 iounmap(dev->base);
664 kfree(dev); 672 kfree(dev);
665 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 673 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
666 release_mem_region(mem->start, (mem->end - mem->start) + 1); 674 release_mem_region(mem->start, (mem->end - mem->start) + 1);
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..9eb76268ec78 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,13 +107,26 @@ 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);
113 126
114 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq); 127 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
115 128
116#ifdef CONFIG_PPC_MERGE 129#ifdef CONFIG_PPC
117 if (check_legacy_ioport(base)) { 130 if (check_legacy_ioport(base)) {
118 dev_err(dev, "I/O address %#08lx is not available\n", base); 131 dev_err(dev, "I/O address %#08lx is not available\n", base);
119 goto out; 132 goto out;
@@ -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-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 0e7b1c6724aa..60ca91745e55 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -259,6 +259,35 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
259 } 259 }
260 260
261 printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); 261 printk(KERN_INFO "PowerMac i2c bus %s registered\n", name);
262
263 if (!strncmp(basename, "uni-n", 5)) {
264 struct device_node *np;
265 const u32 *prop;
266 struct i2c_board_info info;
267
268 /* Instantiate I2C motion sensor if present */
269 np = of_find_node_by_name(NULL, "accelerometer");
270 if (np && of_device_is_compatible(np, "AAPL,accelerometer_1") &&
271 (prop = of_get_property(np, "reg", NULL))) {
272 int i2c_bus;
273 const char *tmp_bus;
274
275 /* look for bus either using "reg" or by path */
276 tmp_bus = strstr(np->full_name, "/i2c-bus@");
277 if (tmp_bus)
278 i2c_bus = *(tmp_bus + 9) - '0';
279 else
280 i2c_bus = ((*prop) >> 8) & 0x0f;
281
282 if (pmac_i2c_get_channel(bus) == i2c_bus) {
283 memset(&info, 0, sizeof(struct i2c_board_info));
284 info.addr = ((*prop) & 0xff) >> 1;
285 strlcpy(info.type, "ams", I2C_NAME_SIZE);
286 i2c_new_device(adapter, &info);
287 }
288 }
289 }
290
262 return rc; 291 return rc;
263} 292}
264 293
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 44d838410f15..906f9b9d715d 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -38,7 +38,44 @@
38#include <asm/irq.h> 38#include <asm/irq.h>
39#include <asm/io.h> 39#include <asm/io.h>
40#include <mach/i2c.h> 40#include <mach/i2c.h>
41#include <mach/pxa-regs.h> 41
42/*
43 * I2C registers and bit definitions
44 */
45#define IBMR (0x00)
46#define IDBR (0x08)
47#define ICR (0x10)
48#define ISR (0x18)
49#define ISAR (0x20)
50
51#define ICR_START (1 << 0) /* start bit */
52#define ICR_STOP (1 << 1) /* stop bit */
53#define ICR_ACKNAK (1 << 2) /* send ACK(0) or NAK(1) */
54#define ICR_TB (1 << 3) /* transfer byte bit */
55#define ICR_MA (1 << 4) /* master abort */
56#define ICR_SCLE (1 << 5) /* master clock enable */
57#define ICR_IUE (1 << 6) /* unit enable */
58#define ICR_GCD (1 << 7) /* general call disable */
59#define ICR_ITEIE (1 << 8) /* enable tx interrupts */
60#define ICR_IRFIE (1 << 9) /* enable rx interrupts */
61#define ICR_BEIE (1 << 10) /* enable bus error ints */
62#define ICR_SSDIE (1 << 11) /* slave STOP detected int enable */
63#define ICR_ALDIE (1 << 12) /* enable arbitration interrupt */
64#define ICR_SADIE (1 << 13) /* slave address detected int enable */
65#define ICR_UR (1 << 14) /* unit reset */
66#define ICR_FM (1 << 15) /* fast mode */
67
68#define ISR_RWM (1 << 0) /* read/write mode */
69#define ISR_ACKNAK (1 << 1) /* ack/nak status */
70#define ISR_UB (1 << 2) /* unit busy */
71#define ISR_IBB (1 << 3) /* bus busy */
72#define ISR_SSD (1 << 4) /* slave stop detected */
73#define ISR_ALD (1 << 5) /* arbitration loss detected */
74#define ISR_ITE (1 << 6) /* tx buffer empty */
75#define ISR_IRF (1 << 7) /* rx buffer full */
76#define ISR_GCAD (1 << 8) /* general call address detected */
77#define ISR_SAD (1 << 9) /* slave address detected */
78#define ISR_BED (1 << 10) /* bus error no ACK/NAK */
42 79
43struct pxa_i2c { 80struct pxa_i2c {
44 spinlock_t lock; 81 spinlock_t lock;
@@ -60,19 +97,21 @@ struct pxa_i2c {
60 u32 icrlog[32]; 97 u32 icrlog[32];
61 98
62 void __iomem *reg_base; 99 void __iomem *reg_base;
100 unsigned int reg_shift;
63 101
64 unsigned long iobase; 102 unsigned long iobase;
65 unsigned long iosize; 103 unsigned long iosize;
66 104
67 int irq; 105 int irq;
68 int use_pio; 106 unsigned int use_pio :1;
107 unsigned int fast_mode :1;
69}; 108};
70 109
71#define _IBMR(i2c) ((i2c)->reg_base + 0) 110#define _IBMR(i2c) ((i2c)->reg_base + (0x0 << (i2c)->reg_shift))
72#define _IDBR(i2c) ((i2c)->reg_base + 8) 111#define _IDBR(i2c) ((i2c)->reg_base + (0x4 << (i2c)->reg_shift))
73#define _ICR(i2c) ((i2c)->reg_base + 0x10) 112#define _ICR(i2c) ((i2c)->reg_base + (0x8 << (i2c)->reg_shift))
74#define _ISR(i2c) ((i2c)->reg_base + 0x18) 113#define _ISR(i2c) ((i2c)->reg_base + (0xc << (i2c)->reg_shift))
75#define _ISAR(i2c) ((i2c)->reg_base + 0x20) 114#define _ISAR(i2c) ((i2c)->reg_base + (0x10 << (i2c)->reg_shift))
76 115
77/* 116/*
78 * I2C Slave mode address 117 * I2C Slave mode address
@@ -188,14 +227,14 @@ static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
188 227
189static void i2c_pxa_abort(struct pxa_i2c *i2c) 228static void i2c_pxa_abort(struct pxa_i2c *i2c)
190{ 229{
191 unsigned long timeout = jiffies + HZ/4; 230 int i = 250;
192 231
193 if (i2c_pxa_is_slavemode(i2c)) { 232 if (i2c_pxa_is_slavemode(i2c)) {
194 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__); 233 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__);
195 return; 234 return;
196 } 235 }
197 236
198 while (time_before(jiffies, timeout) && (readl(_IBMR(i2c)) & 0x1) == 0) { 237 while ((i > 0) && (readl(_IBMR(i2c)) & 0x1) == 0) {
199 unsigned long icr = readl(_ICR(i2c)); 238 unsigned long icr = readl(_ICR(i2c));
200 239
201 icr &= ~ICR_START; 240 icr &= ~ICR_START;
@@ -205,7 +244,8 @@ static void i2c_pxa_abort(struct pxa_i2c *i2c)
205 244
206 show_state(i2c); 245 show_state(i2c);
207 246
208 msleep(1); 247 mdelay(1);
248 i --;
209 } 249 }
210 250
211 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP), 251 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
@@ -364,7 +404,7 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c)
364 writel(i2c->slave_addr, _ISAR(i2c)); 404 writel(i2c->slave_addr, _ISAR(i2c));
365 405
366 /* set control register values */ 406 /* set control register values */
367 writel(I2C_ICR_INIT, _ICR(i2c)); 407 writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c));
368 408
369#ifdef CONFIG_I2C_PXA_SLAVE 409#ifdef CONFIG_I2C_PXA_SLAVE
370 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); 410 dev_info(&i2c->adap.dev, "Enabling slave mode\n");
@@ -907,12 +947,6 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
907 struct pxa_i2c *i2c = adap->algo_data; 947 struct pxa_i2c *i2c = adap->algo_data;
908 int ret, i; 948 int ret, i;
909 949
910 /* If the I2C controller is disabled we need to reset it (probably due
911 to a suspend/resume destroying state). We do this here as we can then
912 avoid worrying about resuming the controller before its users. */
913 if (!(readl(_ICR(i2c)) & ICR_IUE))
914 i2c_pxa_reset(i2c);
915
916 for (i = adap->retries; i >= 0; i--) { 950 for (i = adap->retries; i >= 0; i--) {
917 ret = i2c_pxa_do_xfer(i2c, msgs, num); 951 ret = i2c_pxa_do_xfer(i2c, msgs, num);
918 if (ret != I2C_RETRY) 952 if (ret != I2C_RETRY)
@@ -993,6 +1027,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
993 ret = -EIO; 1027 ret = -EIO;
994 goto eremap; 1028 goto eremap;
995 } 1029 }
1030 i2c->reg_shift = (cpu_is_pxa3xx() && (dev->id == 1)) ? 0 : 1;
996 1031
997 i2c->iobase = res->start; 1032 i2c->iobase = res->start;
998 i2c->iosize = res_len(res); 1033 i2c->iosize = res_len(res);
@@ -1013,6 +1048,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
1013 if (plat) { 1048 if (plat) {
1014 i2c->adap.class = plat->class; 1049 i2c->adap.class = plat->class;
1015 i2c->use_pio = plat->use_pio; 1050 i2c->use_pio = plat->use_pio;
1051 i2c->fast_mode = plat->fast_mode;
1016 } 1052 }
1017 1053
1018 if (i2c->use_pio) { 1054 if (i2c->use_pio) {
@@ -1082,9 +1118,33 @@ static int __exit i2c_pxa_remove(struct platform_device *dev)
1082 return 0; 1118 return 0;
1083} 1119}
1084 1120
1121#ifdef CONFIG_PM
1122static int i2c_pxa_suspend_late(struct platform_device *dev, pm_message_t state)
1123{
1124 struct pxa_i2c *i2c = platform_get_drvdata(dev);
1125 clk_disable(i2c->clk);
1126 return 0;
1127}
1128
1129static int i2c_pxa_resume_early(struct platform_device *dev)
1130{
1131 struct pxa_i2c *i2c = platform_get_drvdata(dev);
1132
1133 clk_enable(i2c->clk);
1134 i2c_pxa_reset(i2c);
1135
1136 return 0;
1137}
1138#else
1139#define i2c_pxa_suspend_late NULL
1140#define i2c_pxa_resume_early NULL
1141#endif
1142
1085static struct platform_driver i2c_pxa_driver = { 1143static struct platform_driver i2c_pxa_driver = {
1086 .probe = i2c_pxa_probe, 1144 .probe = i2c_pxa_probe,
1087 .remove = __exit_p(i2c_pxa_remove), 1145 .remove = __exit_p(i2c_pxa_remove),
1146 .suspend_late = i2c_pxa_suspend_late,
1147 .resume_early = i2c_pxa_resume_early,
1088 .driver = { 1148 .driver = {
1089 .name = "pxa2xx-i2c", 1149 .name = "pxa2xx-i2c",
1090 .owner = THIS_MODULE, 1150 .owner = THIS_MODULE,
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/Kconfig b/drivers/i2c/chips/Kconfig
index a95cb9465d65..17356827b93d 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -172,4 +172,15 @@ config MENELAUS
172 and other features that are often used in portable devices like 172 and other features that are often used in portable devices like
173 cell phones and PDAs. 173 cell phones and PDAs.
174 174
175config MCU_MPC8349EMITX
176 tristate "MPC8349E-mITX MCU driver"
177 depends on I2C && PPC_83xx
178 select GENERIC_GPIO
179 select ARCH_REQUIRE_GPIOLIB
180 help
181 Say Y here to enable soft power-off functionality on the Freescale
182 boards with the MPC8349E-mITX-compatible MCU chips. This driver will
183 also register MCU GPIOs with the generic GPIO API, so you'll able
184 to use MCU pins as GPIOs.
185
175endmenu 186endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 39e3e69ed125..ca520fa143d6 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
21obj-$(CONFIG_TPS65010) += tps65010.o 21obj-$(CONFIG_TPS65010) += tps65010.o
22obj-$(CONFIG_MENELAUS) += menelaus.o 22obj-$(CONFIG_MENELAUS) += menelaus.o
23obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o 23obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
24obj-$(CONFIG_MCU_MPC8349EMITX) += mcu_mpc8349emitx.o
24 25
25ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 26ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
26EXTRA_CFLAGS += -DDEBUG 27EXTRA_CFLAGS += -DDEBUG
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/mcu_mpc8349emitx.c b/drivers/i2c/chips/mcu_mpc8349emitx.c
new file mode 100644
index 000000000000..82a9bcb858b6
--- /dev/null
+++ b/drivers/i2c/chips/mcu_mpc8349emitx.c
@@ -0,0 +1,209 @@
1/*
2 * Power Management and GPIO expander driver for MPC8349E-mITX-compatible MCU
3 *
4 * Copyright (c) 2008 MontaVista Software, Inc.
5 *
6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
7 *
8 * 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 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/device.h>
18#include <linux/mutex.h>
19#include <linux/i2c.h>
20#include <linux/gpio.h>
21#include <linux/of.h>
22#include <linux/of_gpio.h>
23#include <asm/prom.h>
24#include <asm/machdep.h>
25
26/*
27 * I don't have specifications for the MCU firmware, I found this register
28 * and bits positions by the trial&error method.
29 */
30#define MCU_REG_CTRL 0x20
31#define MCU_CTRL_POFF 0x40
32
33#define MCU_NUM_GPIO 2
34
35struct mcu {
36 struct mutex lock;
37 struct device_node *np;
38 struct i2c_client *client;
39 struct of_gpio_chip of_gc;
40 u8 reg_ctrl;
41};
42
43static struct mcu *glob_mcu;
44
45static void mcu_power_off(void)
46{
47 struct mcu *mcu = glob_mcu;
48
49 pr_info("Sending power-off request to the MCU...\n");
50 mutex_lock(&mcu->lock);
51 i2c_smbus_write_byte_data(glob_mcu->client, MCU_REG_CTRL,
52 mcu->reg_ctrl | MCU_CTRL_POFF);
53 mutex_unlock(&mcu->lock);
54}
55
56static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
57{
58 struct of_gpio_chip *of_gc = to_of_gpio_chip(gc);
59 struct mcu *mcu = container_of(of_gc, struct mcu, of_gc);
60 u8 bit = 1 << (4 + gpio);
61
62 mutex_lock(&mcu->lock);
63 if (val)
64 mcu->reg_ctrl &= ~bit;
65 else
66 mcu->reg_ctrl |= bit;
67
68 i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL, mcu->reg_ctrl);
69 mutex_unlock(&mcu->lock);
70}
71
72static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
73{
74 mcu_gpio_set(gc, gpio, val);
75 return 0;
76}
77
78static int mcu_gpiochip_add(struct mcu *mcu)
79{
80 struct device_node *np;
81 struct of_gpio_chip *of_gc = &mcu->of_gc;
82 struct gpio_chip *gc = &of_gc->gc;
83 int ret;
84
85 np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
86 if (!np)
87 return -ENODEV;
88
89 gc->owner = THIS_MODULE;
90 gc->label = np->full_name;
91 gc->can_sleep = 1;
92 gc->ngpio = MCU_NUM_GPIO;
93 gc->base = -1;
94 gc->set = mcu_gpio_set;
95 gc->direction_output = mcu_gpio_dir_out;
96 of_gc->gpio_cells = 2;
97 of_gc->xlate = of_gpio_simple_xlate;
98
99 np->data = of_gc;
100 mcu->np = np;
101
102 /*
103 * We don't want to lose the node, its ->data and ->full_name...
104 * So, if succeeded, we don't put the node here.
105 */
106 ret = gpiochip_add(gc);
107 if (ret)
108 of_node_put(np);
109 return ret;
110}
111
112static int mcu_gpiochip_remove(struct mcu *mcu)
113{
114 int ret;
115
116 ret = gpiochip_remove(&mcu->of_gc.gc);
117 if (ret)
118 return ret;
119 of_node_put(mcu->np);
120
121 return 0;
122}
123
124static int __devinit mcu_probe(struct i2c_client *client,
125 const struct i2c_device_id *id)
126{
127 struct mcu *mcu;
128 int ret;
129
130 mcu = kzalloc(sizeof(*mcu), GFP_KERNEL);
131 if (!mcu)
132 return -ENOMEM;
133
134 mutex_init(&mcu->lock);
135 mcu->client = client;
136 i2c_set_clientdata(client, mcu);
137
138 ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
139 if (ret < 0)
140 goto err;
141 mcu->reg_ctrl = ret;
142
143 ret = mcu_gpiochip_add(mcu);
144 if (ret)
145 goto err;
146
147 /* XXX: this is potentially racy, but there is no lock for ppc_md */
148 if (!ppc_md.power_off) {
149 glob_mcu = mcu;
150 ppc_md.power_off = mcu_power_off;
151 dev_info(&client->dev, "will provide power-off service\n");
152 }
153
154 return 0;
155err:
156 kfree(mcu);
157 return ret;
158}
159
160static int __devexit mcu_remove(struct i2c_client *client)
161{
162 struct mcu *mcu = i2c_get_clientdata(client);
163 int ret;
164
165 if (glob_mcu == mcu) {
166 ppc_md.power_off = NULL;
167 glob_mcu = NULL;
168 }
169
170 ret = mcu_gpiochip_remove(mcu);
171 if (ret)
172 return ret;
173 i2c_set_clientdata(client, NULL);
174 kfree(mcu);
175 return 0;
176}
177
178static const struct i2c_device_id mcu_ids[] = {
179 { "mcu-mpc8349emitx", },
180 {},
181};
182MODULE_DEVICE_TABLE(i2c, mcu_ids);
183
184static struct i2c_driver mcu_driver = {
185 .driver = {
186 .name = "mcu-mpc8349emitx",
187 .owner = THIS_MODULE,
188 },
189 .probe = mcu_probe,
190 .remove = __devexit_p(mcu_remove),
191 .id_table = mcu_ids,
192};
193
194static int __init mcu_init(void)
195{
196 return i2c_add_driver(&mcu_driver);
197}
198module_init(mcu_init);
199
200static void __exit mcu_exit(void)
201{
202 i2c_del_driver(&mcu_driver);
203}
204module_exit(mcu_exit);
205
206MODULE_DESCRIPTION("Power Management and GPIO expander driver for "
207 "MPC8349E-mITX-compatible MCU");
208MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
209MODULE_LICENSE("GPL");
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
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 307d976c9b69..c171988a9f51 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -521,9 +521,9 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
521 return PTR_ERR(i2c_dev); 521 return PTR_ERR(i2c_dev);
522 522
523 /* register this i2c device with the driver core */ 523 /* register this i2c device with the driver core */
524 i2c_dev->dev = device_create_drvdata(i2c_dev_class, &adap->dev, 524 i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
525 MKDEV(I2C_MAJOR, adap->nr), 525 MKDEV(I2C_MAJOR, adap->nr), NULL,
526 NULL, "i2c-%d", adap->nr); 526 "i2c-%d", adap->nr);
527 if (IS_ERR(i2c_dev->dev)) { 527 if (IS_ERR(i2c_dev->dev)) {
528 res = PTR_ERR(i2c_dev->dev); 528 res = PTR_ERR(i2c_dev->dev);
529 goto error; 529 goto error;