aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/Kconfig14
-rw-r--r--drivers/i2c/algos/Kconfig11
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c21
-rw-r--r--drivers/i2c/busses/Kconfig21
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-acorn.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c9
-rw-r--r--drivers/i2c/busses/i2c-amd756.c5
-rw-r--r--drivers/i2c/busses/i2c-at91.c7
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c35
-rw-r--r--drivers/i2c/busses/i2c-cpm.c1
-rw-r--r--drivers/i2c/busses/i2c-davinci.c5
-rw-r--r--drivers/i2c/busses/i2c-elektor.c3
-rw-r--r--drivers/i2c/busses/i2c-gpio.c9
-rw-r--r--drivers/i2c/busses/i2c-highlander.c498
-rw-r--r--drivers/i2c/busses/i2c-hydra.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c3
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c4
-rw-r--r--drivers/i2c/busses/i2c-mpc.c1
-rw-r--r--drivers/i2c/busses/i2c-nforce2-s4985.c5
-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-pnx.c2
-rw-r--r--drivers/i2c/busses/i2c-powermac.c33
-rw-r--r--drivers/i2c/busses/i2c-pxa.c98
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c133
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c271
-rw-r--r--drivers/i2c/busses/i2c-viapro.c22
-rw-r--r--drivers/i2c/chips/Kconfig15
-rw-r--r--drivers/i2c/chips/Makefile4
-rw-r--r--drivers/i2c/chips/at24.c9
-rw-r--r--drivers/i2c/chips/ds1682.c1
-rw-r--r--drivers/i2c/chips/isp1301_omap.c147
-rw-r--r--drivers/i2c/chips/mcu_mpc8349emitx.c209
-rw-r--r--drivers/i2c/chips/menelaus.c39
-rw-r--r--drivers/i2c/chips/tps65010.c14
-rw-r--r--drivers/i2c/i2c-core.c73
-rw-r--r--drivers/i2c/i2c-dev.c10
39 files changed, 1476 insertions, 334 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 96867347bcbf..711ca08ab776 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -38,6 +38,20 @@ config I2C_CHARDEV
38 This support is also available as a module. If so, the module 38 This support is also available as a module. If so, the module
39 will be called i2c-dev. 39 will be called i2c-dev.
40 40
41config I2C_HELPER_AUTO
42 bool "Autoselect pertinent helper modules"
43 default y
44 help
45 Some I2C bus drivers require so-called "I2C algorithm" modules
46 to work. These are basically software-only abstractions of generic
47 I2C interfaces. This option will autoselect them so that you don't
48 have to care.
49
50 Unselect this only if you need to enable additional helper
51 modules, for example for use with external I2C bus drivers.
52
53 In doubt, say Y.
54
41source drivers/i2c/algos/Kconfig 55source drivers/i2c/algos/Kconfig
42source drivers/i2c/busses/Kconfig 56source drivers/i2c/busses/Kconfig
43source drivers/i2c/chips/Kconfig 57source drivers/i2c/chips/Kconfig
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index 7137a17402fe..b788579b8227 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -2,15 +2,20 @@
2# I2C algorithm drivers configuration 2# I2C algorithm drivers configuration
3# 3#
4 4
5menu "I2C Algorithms"
6 depends on !I2C_HELPER_AUTO
7
5config I2C_ALGOBIT 8config I2C_ALGOBIT
6 tristate 9 tristate "I2C bit-banging interfaces"
7 10
8config I2C_ALGOPCF 11config I2C_ALGOPCF
9 tristate 12 tristate "I2C PCF 8584 interfaces"
10 13
11config I2C_ALGOPCA 14config I2C_ALGOPCA
12 tristate 15 tristate "I2C PCA 9564 interfaces"
13 16
14config I2C_ALGO_SGI 17config I2C_ALGO_SGI
15 tristate 18 tristate
16 depends on SGI_IP22 || SGI_IP32 || X86_VISWS 19 depends on SGI_IP22 || SGI_IP32 || X86_VISWS
20
21endmenu
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 1e328d19cd6d..3e01992230b8 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -135,7 +135,7 @@ static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status) {
135 *status = get_pcf(adap, 1); 135 *status = get_pcf(adap, 1);
136#ifndef STUB_I2C 136#ifndef STUB_I2C
137 while (timeout-- && (*status & I2C_PCF_PIN)) { 137 while (timeout-- && (*status & I2C_PCF_PIN)) {
138 adap->waitforpin(); 138 adap->waitforpin(adap->data);
139 *status = get_pcf(adap, 1); 139 *status = get_pcf(adap, 1);
140 } 140 }
141 if (*status & I2C_PCF_LAB) { 141 if (*status & I2C_PCF_LAB) {
@@ -208,7 +208,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
208 return -ENXIO; 208 return -ENXIO;
209 } 209 }
210 210
211 printk(KERN_DEBUG "i2c-algo-pcf.o: deteted and initialized PCF8584.\n"); 211 printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n");
212 212
213 return 0; 213 return 0;
214} 214}
@@ -331,13 +331,16 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
331 int i; 331 int i;
332 int ret=0, timeout, status; 332 int ret=0, timeout, status;
333 333
334 if (adap->xfer_begin)
335 adap->xfer_begin(adap->data);
334 336
335 /* Check for bus busy */ 337 /* Check for bus busy */
336 timeout = wait_for_bb(adap); 338 timeout = wait_for_bb(adap);
337 if (timeout) { 339 if (timeout) {
338 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: " 340 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
339 "Timeout waiting for BB in pcf_xfer\n");) 341 "Timeout waiting for BB in pcf_xfer\n");)
340 return -EIO; 342 i = -EIO;
343 goto out;
341 } 344 }
342 345
343 for (i = 0;ret >= 0 && i < num; i++) { 346 for (i = 0;ret >= 0 && i < num; i++) {
@@ -359,12 +362,14 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
359 if (timeout) { 362 if (timeout) {
360 if (timeout == -EINTR) { 363 if (timeout == -EINTR) {
361 /* arbitration lost */ 364 /* arbitration lost */
362 return (-EINTR); 365 i = -EINTR;
366 goto out;
363 } 367 }
364 i2c_stop(adap); 368 i2c_stop(adap);
365 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting " 369 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
366 "for PIN(1) in pcf_xfer\n");) 370 "for PIN(1) in pcf_xfer\n");)
367 return (-EREMOTEIO); 371 i = -EREMOTEIO;
372 goto out;
368 } 373 }
369 374
370#ifndef STUB_I2C 375#ifndef STUB_I2C
@@ -372,7 +377,8 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
372 if (status & I2C_PCF_LRB) { 377 if (status & I2C_PCF_LRB) {
373 i2c_stop(adap); 378 i2c_stop(adap);
374 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");) 379 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
375 return (-EREMOTEIO); 380 i = -EREMOTEIO;
381 goto out;
376 } 382 }
377#endif 383#endif
378 384
@@ -404,6 +410,9 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
404 } 410 }
405 } 411 }
406 412
413out:
414 if (adap->xfer_end)
415 adap->xfer_end(adap->data);
407 return (i); 416 return (i);
408} 417}
409 418
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 6ee997b2817c..7f95905bbb9d 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
@@ -97,6 +97,7 @@ config I2C_I801
97 ICH9 97 ICH9
98 Tolapai 98 Tolapai
99 ICH10 99 ICH10
100 PCH
100 101
101 This driver can also be built as a module. If so, the module 102 This driver can also be built as a module. If so, the module
102 will be called i2c-i801. 103 will be called i2c-i801.
@@ -148,7 +149,7 @@ config I2C_NFORCE2
148 149
149config I2C_NFORCE2_S4985 150config I2C_NFORCE2_S4985
150 tristate "SMBus multiplexing on the Tyan S4985" 151 tristate "SMBus multiplexing on the Tyan S4985"
151 depends on I2C_NFORCE2 && EXPERIMENTAL 152 depends on I2C_NFORCE2 && X86 && EXPERIMENTAL
152 help 153 help
153 Enabling this option will add specific SMBus support for the Tyan 154 Enabling this option will add specific SMBus support for the Tyan
154 S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed 155 S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed
@@ -209,7 +210,7 @@ config I2C_VIA
209 will be called i2c-via. 210 will be called i2c-via.
210 211
211config I2C_VIAPRO 212config I2C_VIAPRO
212 tristate "VIA VT82C596/82C686/82xx and CX700" 213 tristate "VIA VT82C596/82C686/82xx and CX700/VX800/VX820"
213 depends on PCI 214 depends on PCI
214 help 215 help
215 If you say yes to this option, support will be included for the VIA 216 If you say yes to this option, support will be included for the VIA
@@ -223,6 +224,8 @@ config I2C_VIAPRO
223 VT8237R/A/S 224 VT8237R/A/S
224 VT8251 225 VT8251
225 CX700 226 CX700
227 VX800
228 VX820
226 229
227 This driver can also be built as a module. If so, the module 230 This driver can also be built as a module. If so, the module
228 will be called i2c-viapro. 231 will be called i2c-viapro.
@@ -330,6 +333,18 @@ config I2C_GPIO
330 This is a very simple bitbanging I2C driver utilizing the 333 This is a very simple bitbanging I2C driver utilizing the
331 arch-neutral GPIO API to control the SCL and SDA lines. 334 arch-neutral GPIO API to control the SCL and SDA lines.
332 335
336config I2C_HIGHLANDER
337 tristate "Highlander FPGA SMBus interface"
338 depends on SH_HIGHLANDER
339 help
340 If you say yes to this option, support will be included for
341 the SMBus interface located in the FPGA on various Highlander
342 boards, particularly the R0P7780LC0011RL and R0P7785LC0011RL
343 FPGAs. This is wholly unrelated to the SoC I2C.
344
345 This driver can also be built as a module. If so, the module
346 will be called i2c-highlander.
347
333config I2C_IBM_IIC 348config I2C_IBM_IIC
334 tristate "IBM PPC 4xx on-chip I2C interface" 349 tristate "IBM PPC 4xx on-chip I2C interface"
335 depends on 4xx 350 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-acorn.c b/drivers/i2c/busses/i2c-acorn.c
index 7c2be3558a24..75089febbc13 100644
--- a/drivers/i2c/busses/i2c-acorn.c
+++ b/drivers/i2c/busses/i2c-acorn.c
@@ -16,7 +16,7 @@
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/i2c-algo-bit.h> 17#include <linux/i2c-algo-bit.h>
18 18
19#include <asm/hardware.h> 19#include <mach/hardware.h>
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/hardware/ioc.h> 21#include <asm/hardware/ioc.h>
22#include <asm/system.h> 22#include <asm/system.h>
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index 72872d1e63ef..8ba2bcf727d3 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -155,6 +155,9 @@ static int __init amd756_s4882_init(void)
155 int i, error; 155 int i, error;
156 union i2c_smbus_data ioconfig; 156 union i2c_smbus_data ioconfig;
157 157
158 if (!amd756_smbus.dev.parent)
159 return -ENODEV;
160
158 /* Configure the PCA9556 multiplexer */ 161 /* Configure the PCA9556 multiplexer */
159 ioconfig.byte = 0x00; /* All I/O to output mode */ 162 ioconfig.byte = 0x00; /* All I/O to output mode */
160 error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, 163 error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
@@ -168,11 +171,7 @@ static int __init amd756_s4882_init(void)
168 /* Unregister physical bus */ 171 /* Unregister physical bus */
169 error = i2c_del_adapter(&amd756_smbus); 172 error = i2c_del_adapter(&amd756_smbus);
170 if (error) { 173 if (error) {
171 if (error == -EINVAL) 174 dev_err(&amd756_smbus.dev, "Physical bus removal failed\n");
172 error = -ENODEV;
173 else
174 dev_err(&amd756_smbus.dev, "Physical bus removal "
175 "failed\n");
176 goto ERROR0; 175 goto ERROR0;
177 } 176 }
178 177
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 1ea39254dac6..424dad6f18d8 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -332,10 +332,6 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
332 int error; 332 int error;
333 u8 temp; 333 u8 temp;
334 334
335 /* driver_data might come from user-space, so check it */
336 if (id->driver_data >= ARRAY_SIZE(chipname))
337 return -EINVAL;
338
339 if (amd756_ioport) { 335 if (amd756_ioport) {
340 dev_err(&pdev->dev, "Only one device supported " 336 dev_err(&pdev->dev, "Only one device supported "
341 "(you have a strange motherboard, btw)\n"); 337 "(you have a strange motherboard, btw)\n");
@@ -412,7 +408,6 @@ static struct pci_driver amd756_driver = {
412 .id_table = amd756_ids, 408 .id_table = amd756_ids,
413 .probe = amd756_probe, 409 .probe = amd756_probe,
414 .remove = __devexit_p(amd756_remove), 410 .remove = __devexit_p(amd756_remove),
415 .dynids.use_driver_data = 1,
416}; 411};
417 412
418static int __init amd756_init(void) 413static int __init amd756_init(void)
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 73d61946a534..9efb02137254 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -14,7 +14,6 @@
14*/ 14*/
15 15
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/version.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
19#include <linux/err.h> 18#include <linux/err.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
@@ -27,9 +26,9 @@
27 26
28#include <asm/io.h> 27#include <asm/io.h>
29 28
30#include <asm/arch/at91_twi.h> 29#include <mach/at91_twi.h>
31#include <asm/arch/board.h> 30#include <mach/board.h>
32#include <asm/arch/cpu.h> 31#include <mach/cpu.h>
33 32
34#define TWI_CLOCK 100000 /* Hz. max 400 Kbits/sec */ 33#define TWI_CLOCK 100000 /* Hz. max 400 Kbits/sec */
35 34
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 48d084bdf7c8..3c855ff2992f 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
49 struct i2c_msg *pmsg; 49 struct i2c_msg *pmsg;
50 int msg_num; 50 int msg_num;
51 int cur_msg; 51 int cur_msg;
52 u16 saved_clkdiv;
53 u16 saved_control;
52 void __iomem *regs_base; 54 void __iomem *regs_base;
53}; 55};
54 56
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct i2c_adapter *adap)
565 I2C_FUNC_I2C; 567 I2C_FUNC_I2C;
566} 568}
567 569
568
569static struct i2c_algorithm bfin_twi_algorithm = { 570static struct i2c_algorithm bfin_twi_algorithm = {
570 .master_xfer = bfin_twi_master_xfer, 571 .master_xfer = bfin_twi_master_xfer,
571 .smbus_xfer = bfin_twi_smbus_xfer, 572 .smbus_xfer = bfin_twi_smbus_xfer,
572 .functionality = bfin_twi_functionality, 573 .functionality = bfin_twi_functionality,
573}; 574};
574 575
575 576static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state)
576static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
577{ 577{
578 struct bfin_twi_iface *iface = platform_get_drvdata(dev); 578 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
579
580 iface->saved_clkdiv = read_CLKDIV(iface);
581 iface->saved_control = read_CONTROL(iface);
582
583 free_irq(iface->irq, iface);
579 584
580 /* Disable TWI */ 585 /* Disable TWI */
581 write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA); 586 write_CONTROL(iface, iface->saved_control & ~TWI_ENA);
582 SSYNC();
583 587
584 return 0; 588 return 0;
585} 589}
586 590
587static int i2c_bfin_twi_resume(struct platform_device *dev) 591static int i2c_bfin_twi_resume(struct platform_device *pdev)
588{ 592{
589 struct bfin_twi_iface *iface = platform_get_drvdata(dev); 593 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
590 594
591 /* Enable TWI */ 595 int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
592 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA); 596 IRQF_DISABLED, pdev->name, iface);
593 SSYNC(); 597 if (rc) {
598 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
599 return -ENODEV;
600 }
601
602 /* Resume TWI interface clock as specified */
603 write_CLKDIV(iface, iface->saved_clkdiv);
604
605 /* Resume TWI */
606 write_CONTROL(iface, iface->saved_control);
594 607
595 return 0; 608 return 0;
596} 609}
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 8164de1f4d72..228f75723063 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -423,7 +423,6 @@ static const struct i2c_adapter cpm_ops = {
423 .owner = THIS_MODULE, 423 .owner = THIS_MODULE,
424 .name = "i2c-cpm", 424 .name = "i2c-cpm",
425 .algo = &cpm_i2c_algo, 425 .algo = &cpm_i2c_algo,
426 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
427}; 426};
428 427
429static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) 428static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm)
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index af3846eda985..5d7789834b95 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -36,10 +36,9 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/io.h> 37#include <linux/io.h>
38 38
39#include <asm/hardware.h> 39#include <mach/hardware.h>
40#include <asm/mach-types.h>
41 40
42#include <asm/arch/i2c.h> 41#include <mach/i2c.h>
43 42
44/* ----- global defines ----------------------------------------------- */ 43/* ----- global defines ----------------------------------------------- */
45 44
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 7f38c01fb3a0..0ed3ccb81b63 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -104,7 +104,8 @@ static int pcf_isa_getclock(void *data)
104 return (clock); 104 return (clock);
105} 105}
106 106
107static void pcf_isa_waitforpin(void) { 107static void pcf_isa_waitforpin(void *data)
108{
108 DEFINE_WAIT(wait); 109 DEFINE_WAIT(wait);
109 int timeout = 2; 110 int timeout = 2;
110 unsigned long flags; 111 unsigned long flags;
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 79b455a1f090..32104eac8d3d 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -77,7 +77,7 @@ static int i2c_gpio_getscl(void *data)
77 return gpio_get_value(pdata->scl_pin); 77 return gpio_get_value(pdata->scl_pin);
78} 78}
79 79
80static int __init i2c_gpio_probe(struct platform_device *pdev) 80static int __devinit i2c_gpio_probe(struct platform_device *pdev)
81{ 81{
82 struct i2c_gpio_platform_data *pdata; 82 struct i2c_gpio_platform_data *pdata;
83 struct i2c_algo_bit_data *bit_data; 83 struct i2c_algo_bit_data *bit_data;
@@ -174,7 +174,7 @@ err_alloc_adap:
174 return ret; 174 return ret;
175} 175}
176 176
177static int __exit i2c_gpio_remove(struct platform_device *pdev) 177static int __devexit i2c_gpio_remove(struct platform_device *pdev)
178{ 178{
179 struct i2c_gpio_platform_data *pdata; 179 struct i2c_gpio_platform_data *pdata;
180 struct i2c_adapter *adap; 180 struct i2c_adapter *adap;
@@ -196,14 +196,15 @@ static struct platform_driver i2c_gpio_driver = {
196 .name = "i2c-gpio", 196 .name = "i2c-gpio",
197 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
198 }, 198 },
199 .remove = __exit_p(i2c_gpio_remove), 199 .probe = i2c_gpio_probe,
200 .remove = __devexit_p(i2c_gpio_remove),
200}; 201};
201 202
202static int __init i2c_gpio_init(void) 203static int __init i2c_gpio_init(void)
203{ 204{
204 int ret; 205 int ret;
205 206
206 ret = platform_driver_probe(&i2c_gpio_driver, i2c_gpio_probe); 207 ret = platform_driver_register(&i2c_gpio_driver);
207 if (ret) 208 if (ret)
208 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret); 209 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret);
209 210
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-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index 1098f21ace13..648aa7baff83 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -123,7 +123,7 @@ static int __devinit hydra_probe(struct pci_dev *dev,
123 hydra_adap.name)) 123 hydra_adap.name))
124 return -EBUSY; 124 return -EBUSY;
125 125
126 hydra_bit_data.data = ioremap(base, pci_resource_len(dev, 0)); 126 hydra_bit_data.data = pci_ioremap_bar(dev, 0);
127 if (hydra_bit_data.data == NULL) { 127 if (hydra_bit_data.data == NULL) {
128 release_mem_region(base+offsetof(struct Hydra, CachePD), 4); 128 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
129 return -ENODEV; 129 return -ENODEV;
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index dc7ea32b69a8..5123eb69a971 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -41,6 +41,7 @@
41 Tolapai 0x5032 32 hard yes yes yes 41 Tolapai 0x5032 32 hard yes yes yes
42 ICH10 0x3a30 32 hard yes yes yes 42 ICH10 0x3a30 32 hard yes yes yes
43 ICH10 0x3a60 32 hard yes yes yes 43 ICH10 0x3a60 32 hard yes yes yes
44 PCH 0x3b30 32 hard yes yes yes
44 45
45 Features supported by this driver: 46 Features supported by this driver:
46 Software PEC no 47 Software PEC no
@@ -576,6 +577,7 @@ static struct pci_device_id i801_ids[] = {
576 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) }, 577 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) },
577 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) }, 578 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
578 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) }, 579 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
580 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PCH_SMBUS) },
579 { 0, } 581 { 0, }
580}; 582};
581 583
@@ -599,6 +601,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
599 case PCI_DEVICE_ID_INTEL_TOLAPAI_1: 601 case PCI_DEVICE_ID_INTEL_TOLAPAI_1:
600 case PCI_DEVICE_ID_INTEL_ICH10_4: 602 case PCI_DEVICE_ID_INTEL_ICH10_4:
601 case PCI_DEVICE_ID_INTEL_ICH10_5: 603 case PCI_DEVICE_ID_INTEL_ICH10_5:
604 case PCI_DEVICE_ID_INTEL_PCH_SMBUS:
602 i801_features |= FEATURE_I2C_BLOCK_READ; 605 i801_features |= FEATURE_I2C_BLOCK_READ;
603 /* fall through */ 606 /* fall through */
604 case PCI_DEVICE_ID_INTEL_82801DB_3: 607 case PCI_DEVICE_ID_INTEL_82801DB_3:
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index 5af9e6521e6c..05d72e981353 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -33,8 +33,8 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-algo-bit.h> 34#include <linux/i2c-algo-bit.h>
35 35
36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */ 36#include <mach/hardware.h> /* Pick up IXP2000-specific bits */
37#include <asm/arch/gpio.h> 37#include <mach/gpio.h>
38 38
39static inline int ixp2000_scl_pin(void *data) 39static inline int ixp2000_scl_pin(void *data)
40{ 40{
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-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
index d1a4cbcf2aa4..29015eb9ca46 100644
--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
@@ -150,6 +150,9 @@ static int __init nforce2_s4985_init(void)
150 int i, error; 150 int i, error;
151 union i2c_smbus_data ioconfig; 151 union i2c_smbus_data ioconfig;
152 152
153 if (!nforce2_smbus)
154 return -ENODEV;
155
153 /* Configure the PCA9556 multiplexer */ 156 /* Configure the PCA9556 multiplexer */
154 ioconfig.byte = 0x00; /* All I/O to output mode */ 157 ioconfig.byte = 0x00; /* All I/O to output mode */
155 error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, 158 error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
@@ -161,8 +164,6 @@ static int __init nforce2_s4985_init(void)
161 } 164 }
162 165
163 /* Unregister physical bus */ 166 /* Unregister physical bus */
164 if (!nforce2_smbus)
165 return -ENODEV;
166 error = i2c_del_adapter(nforce2_smbus); 167 error = i2c_del_adapter(nforce2_smbus);
167 if (error) { 168 if (error) {
168 dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n"); 169 dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n");
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-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 1ca21084ffcf..ec15cff556b9 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -19,7 +19,7 @@
19#include <linux/completion.h> 19#include <linux/completion.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/i2c-pnx.h> 21#include <linux/i2c-pnx.h>
22#include <asm/hardware.h> 22#include <mach/hardware.h>
23#include <asm/irq.h> 23#include <asm/irq.h>
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25 25
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 22f6d5c00d80..60ca91745e55 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -180,7 +180,7 @@ static const struct i2c_algorithm i2c_powermac_algorithm = {
180}; 180};
181 181
182 182
183static int i2c_powermac_remove(struct platform_device *dev) 183static int __devexit i2c_powermac_remove(struct platform_device *dev)
184{ 184{
185 struct i2c_adapter *adapter = platform_get_drvdata(dev); 185 struct i2c_adapter *adapter = platform_get_drvdata(dev);
186 struct pmac_i2c_bus *bus = i2c_get_adapdata(adapter); 186 struct pmac_i2c_bus *bus = i2c_get_adapdata(adapter);
@@ -200,7 +200,7 @@ static int i2c_powermac_remove(struct platform_device *dev)
200} 200}
201 201
202 202
203static int __devexit i2c_powermac_probe(struct platform_device *dev) 203static int __devinit i2c_powermac_probe(struct platform_device *dev)
204{ 204{
205 struct pmac_i2c_bus *bus = dev->dev.platform_data; 205 struct pmac_i2c_bus *bus = dev->dev.platform_data;
206 struct device_node *parent = NULL; 206 struct device_node *parent = NULL;
@@ -259,6 +259,35 @@ static int __devexit 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 af9e6034d7fb..906f9b9d715d 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -34,11 +34,48 @@
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36 36
37#include <asm/hardware.h> 37#include <mach/hardware.h>
38#include <asm/irq.h> 38#include <asm/irq.h>
39#include <asm/io.h> 39#include <asm/io.h>
40#include <asm/arch/i2c.h> 40#include <mach/i2c.h>
41#include <asm/arch/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-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 007390ad9810..c772e02c2803 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -33,12 +33,13 @@
33#include <linux/err.h> 33#include <linux/err.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/cpufreq.h>
36 37
37#include <asm/hardware.h> 38#include <mach/hardware.h>
38#include <asm/irq.h> 39#include <asm/irq.h>
39#include <asm/io.h> 40#include <asm/io.h>
40 41
41#include <asm/arch/regs-gpio.h> 42#include <mach/regs-gpio.h>
42#include <asm/plat-s3c/regs-iic.h> 43#include <asm/plat-s3c/regs-iic.h>
43#include <asm/plat-s3c/iic.h> 44#include <asm/plat-s3c/iic.h>
44 45
@@ -64,6 +65,7 @@ struct s3c24xx_i2c {
64 unsigned int tx_setup; 65 unsigned int tx_setup;
65 66
66 enum s3c24xx_i2c_state state; 67 enum s3c24xx_i2c_state state;
68 unsigned long clkrate;
67 69
68 void __iomem *regs; 70 void __iomem *regs;
69 struct clk *clk; 71 struct clk *clk;
@@ -71,6 +73,10 @@ struct s3c24xx_i2c {
71 struct resource *irq; 73 struct resource *irq;
72 struct resource *ioarea; 74 struct resource *ioarea;
73 struct i2c_adapter adap; 75 struct i2c_adapter adap;
76
77#ifdef CONFIG_CPU_FREQ
78 struct notifier_block freq_transition;
79#endif
74}; 80};
75 81
76/* default platform data to use if not supplied in the platform_device 82/* default platform data to use if not supplied in the platform_device
@@ -501,6 +507,9 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int
501 unsigned long timeout; 507 unsigned long timeout;
502 int ret; 508 int ret;
503 509
510 if (!readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN)
511 return -EIO;
512
504 ret = s3c24xx_i2c_set_master(i2c); 513 ret = s3c24xx_i2c_set_master(i2c);
505 if (ret != 0) { 514 if (ret != 0) {
506 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); 515 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
@@ -636,27 +645,28 @@ static inline int freq_acceptable(unsigned int freq, unsigned int wanted)
636 return (diff >= -2 && diff <= 2); 645 return (diff >= -2 && diff <= 2);
637} 646}
638 647
639/* s3c24xx_i2c_getdivisor 648/* s3c24xx_i2c_clockrate
640 * 649 *
641 * work out a divisor for the user requested frequency setting, 650 * work out a divisor for the user requested frequency setting,
642 * either by the requested frequency, or scanning the acceptable 651 * either by the requested frequency, or scanning the acceptable
643 * range of frequencies until something is found 652 * range of frequencies until something is found
644*/ 653*/
645 654
646static int s3c24xx_i2c_getdivisor(struct s3c24xx_i2c *i2c, 655static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
647 struct s3c2410_platform_i2c *pdata,
648 unsigned long *iicon,
649 unsigned int *got)
650{ 656{
657 struct s3c2410_platform_i2c *pdata;
651 unsigned long clkin = clk_get_rate(i2c->clk); 658 unsigned long clkin = clk_get_rate(i2c->clk);
652
653 unsigned int divs, div1; 659 unsigned int divs, div1;
660 u32 iiccon;
654 int freq; 661 int freq;
655 int start, end; 662 int start, end;
656 663
664 i2c->clkrate = clkin;
665
666 pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent);
657 clkin /= 1000; /* clkin now in KHz */ 667 clkin /= 1000; /* clkin now in KHz */
658 668
659 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", 669 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n",
660 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); 670 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq);
661 671
662 if (pdata->bus_freq != 0) { 672 if (pdata->bus_freq != 0) {
@@ -688,11 +698,79 @@ static int s3c24xx_i2c_getdivisor(struct s3c24xx_i2c *i2c,
688 698
689 found: 699 found:
690 *got = freq; 700 *got = freq;
691 *iicon |= (divs-1); 701
692 *iicon |= (div1 == 512) ? S3C2410_IICCON_TXDIV_512 : 0; 702 iiccon = readl(i2c->regs + S3C2410_IICCON);
703 iiccon &= ~(S3C2410_IICCON_SCALEMASK | S3C2410_IICCON_TXDIV_512);
704 iiccon |= (divs-1);
705
706 if (div1 == 512)
707 iiccon |= S3C2410_IICCON_TXDIV_512;
708
709 writel(iiccon, i2c->regs + S3C2410_IICCON);
710
711 return 0;
712}
713
714#ifdef CONFIG_CPU_FREQ
715
716#define freq_to_i2c(_n) container_of(_n, struct s3c24xx_i2c, freq_transition)
717
718static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb,
719 unsigned long val, void *data)
720{
721 struct s3c24xx_i2c *i2c = freq_to_i2c(nb);
722 unsigned long flags;
723 unsigned int got;
724 int delta_f;
725 int ret;
726
727 delta_f = clk_get_rate(i2c->clk) - i2c->clkrate;
728
729 /* if we're post-change and the input clock has slowed down
730 * or at pre-change and the clock is about to speed up, then
731 * adjust our clock rate. <0 is slow, >0 speedup.
732 */
733
734 if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) ||
735 (val == CPUFREQ_PRECHANGE && delta_f > 0)) {
736 spin_lock_irqsave(&i2c->lock, flags);
737 ret = s3c24xx_i2c_clockrate(i2c, &got);
738 spin_unlock_irqrestore(&i2c->lock, flags);
739
740 if (ret < 0)
741 dev_err(i2c->dev, "cannot find frequency\n");
742 else
743 dev_info(i2c->dev, "setting freq %d\n", got);
744 }
745
746 return 0;
747}
748
749static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
750{
751 i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition;
752
753 return cpufreq_register_notifier(&i2c->freq_transition,
754 CPUFREQ_TRANSITION_NOTIFIER);
755}
756
757static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
758{
759 cpufreq_unregister_notifier(&i2c->freq_transition,
760 CPUFREQ_TRANSITION_NOTIFIER);
761}
762
763#else
764static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
765{
693 return 0; 766 return 0;
694} 767}
695 768
769static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
770{
771}
772#endif
773
696/* s3c24xx_i2c_init 774/* s3c24xx_i2c_init
697 * 775 *
698 * initialise the controller, set the IO lines and frequency 776 * initialise the controller, set the IO lines and frequency
@@ -719,9 +797,12 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
719 797
720 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); 798 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
721 799
800 writel(iicon, i2c->regs + S3C2410_IICCON);
801
722 /* we need to work out the divisors for the clock... */ 802 /* we need to work out the divisors for the clock... */
723 803
724 if (s3c24xx_i2c_getdivisor(i2c, pdata, &iicon, &freq) != 0) { 804 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
805 writel(0, i2c->regs + S3C2410_IICCON);
725 dev_err(i2c->dev, "cannot meet bus frequency required\n"); 806 dev_err(i2c->dev, "cannot meet bus frequency required\n");
726 return -EINVAL; 807 return -EINVAL;
727 } 808 }
@@ -730,8 +811,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
730 811
731 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); 812 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
732 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); 813 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon);
733
734 writel(iicon, i2c->regs + S3C2410_IICCON);
735 814
736 /* check for s3c2440 i2c controller */ 815 /* check for s3c2440 i2c controller */
737 816
@@ -752,9 +831,12 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
752static int s3c24xx_i2c_probe(struct platform_device *pdev) 831static int s3c24xx_i2c_probe(struct platform_device *pdev)
753{ 832{
754 struct s3c24xx_i2c *i2c = &s3c24xx_i2c; 833 struct s3c24xx_i2c *i2c = &s3c24xx_i2c;
834 struct s3c2410_platform_i2c *pdata;
755 struct resource *res; 835 struct resource *res;
756 int ret; 836 int ret;
757 837
838 pdata = s3c24xx_i2c_get_platformdata(&pdev->dev);
839
758 /* find the clock and enable it */ 840 /* find the clock and enable it */
759 841
760 i2c->dev = &pdev->dev; 842 i2c->dev = &pdev->dev;
@@ -832,17 +914,34 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
832 dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res, 914 dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res,
833 (unsigned long)res->start); 915 (unsigned long)res->start);
834 916
835 ret = i2c_add_adapter(&i2c->adap); 917 ret = s3c24xx_i2c_register_cpufreq(i2c);
836 if (ret < 0) { 918 if (ret < 0) {
837 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 919 dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
838 goto err_irq; 920 goto err_irq;
839 } 921 }
840 922
923 /* Note, previous versions of the driver used i2c_add_adapter()
924 * to add the bus at any number. We now pass the bus number via
925 * the platform data, so if unset it will now default to always
926 * being bus 0.
927 */
928
929 i2c->adap.nr = pdata->bus_num;
930
931 ret = i2c_add_numbered_adapter(&i2c->adap);
932 if (ret < 0) {
933 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
934 goto err_cpufreq;
935 }
936
841 platform_set_drvdata(pdev, i2c); 937 platform_set_drvdata(pdev, i2c);
842 938
843 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); 939 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
844 return 0; 940 return 0;
845 941
942 err_cpufreq:
943 s3c24xx_i2c_deregister_cpufreq(i2c);
944
846 err_irq: 945 err_irq:
847 free_irq(i2c->irq->start, i2c); 946 free_irq(i2c->irq->start, i2c);
848 947
@@ -870,6 +969,8 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev)
870{ 969{
871 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 970 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
872 971
972 s3c24xx_i2c_deregister_cpufreq(i2c);
973
873 i2c_del_adapter(&i2c->adap); 974 i2c_del_adapter(&i2c->adap);
874 free_irq(i2c->irq->start, i2c); 975 free_irq(i2c->irq->start, i2c);
875 976
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 840e634fa31f..640cbb237328 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -31,13 +31,84 @@
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/io.h> 32#include <linux/io.h>
33 33
34/* Transmit operation: */
35/* */
36/* 0 byte transmit */
37/* BUS: S A8 ACK P */
38/* IRQ: DTE WAIT */
39/* ICIC: */
40/* ICCR: 0x94 0x90 */
41/* ICDR: A8 */
42/* */
43/* 1 byte transmit */
44/* BUS: S A8 ACK D8(1) ACK P */
45/* IRQ: DTE WAIT WAIT */
46/* ICIC: -DTE */
47/* ICCR: 0x94 0x90 */
48/* ICDR: A8 D8(1) */
49/* */
50/* 2 byte transmit */
51/* BUS: S A8 ACK D8(1) ACK D8(2) ACK P */
52/* IRQ: DTE WAIT WAIT WAIT */
53/* ICIC: -DTE */
54/* ICCR: 0x94 0x90 */
55/* ICDR: A8 D8(1) D8(2) */
56/* */
57/* 3 bytes or more, +---------+ gets repeated */
58/* */
59/* */
60/* Receive operation: */
61/* */
62/* 0 byte receive - not supported since slave may hold SDA low */
63/* */
64/* 1 byte receive [TX] | [RX] */
65/* BUS: S A8 ACK | D8(1) ACK P */
66/* IRQ: DTE WAIT | WAIT DTE */
67/* ICIC: -DTE | +DTE */
68/* ICCR: 0x94 0x81 | 0xc0 */
69/* ICDR: A8 | D8(1) */
70/* */
71/* 2 byte receive [TX]| [RX] */
72/* BUS: S A8 ACK | D8(1) ACK D8(2) ACK P */
73/* IRQ: DTE WAIT | WAIT WAIT DTE */
74/* ICIC: -DTE | +DTE */
75/* ICCR: 0x94 0x81 | 0xc0 */
76/* ICDR: A8 | D8(1) D8(2) */
77/* */
78/* 3 byte receive [TX] | [RX] */
79/* BUS: S A8 ACK | D8(1) ACK D8(2) ACK D8(3) ACK P */
80/* IRQ: DTE WAIT | WAIT WAIT WAIT DTE */
81/* ICIC: -DTE | +DTE */
82/* ICCR: 0x94 0x81 | 0xc0 */
83/* ICDR: A8 | D8(1) D8(2) D8(3) */
84/* */
85/* 4 bytes or more, this part is repeated +---------+ */
86/* */
87/* */
88/* Interrupt order and BUSY flag */
89/* ___ _ */
90/* SDA ___\___XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXAAAAAAAAA___/ */
91/* SCL \_/1\_/2\_/3\_/4\_/5\_/6\_/7\_/8\___/9\_____/ */
92/* */
93/* S D7 D6 D5 D4 D3 D2 D1 D0 P */
94/* ___ */
95/* WAIT IRQ ________________________________/ \___________ */
96/* TACK IRQ ____________________________________/ \_______ */
97/* DTE IRQ __________________________________________/ \_ */
98/* AL IRQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
99/* _______________________________________________ */
100/* BUSY __/ \_ */
101/* */
102
34enum sh_mobile_i2c_op { 103enum sh_mobile_i2c_op {
35 OP_START = 0, 104 OP_START = 0,
36 OP_TX_ONLY, 105 OP_TX_FIRST,
106 OP_TX,
37 OP_TX_STOP, 107 OP_TX_STOP,
38 OP_TX_TO_RX, 108 OP_TX_TO_RX,
39 OP_RX_ONLY, 109 OP_RX,
40 OP_RX_STOP, 110 OP_RX_STOP,
111 OP_RX_STOP_DATA,
41}; 112};
42 113
43struct sh_mobile_i2c_data { 114struct sh_mobile_i2c_data {
@@ -127,25 +198,34 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
127 spin_lock_irqsave(&pd->lock, flags); 198 spin_lock_irqsave(&pd->lock, flags);
128 199
129 switch (op) { 200 switch (op) {
130 case OP_START: 201 case OP_START: /* issue start and trigger DTE interrupt */
131 iowrite8(0x94, ICCR(pd)); 202 iowrite8(0x94, ICCR(pd));
132 break; 203 break;
133 case OP_TX_ONLY: 204 case OP_TX_FIRST: /* disable DTE interrupt and write data */
205 iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE, ICIC(pd));
134 iowrite8(data, ICDR(pd)); 206 iowrite8(data, ICDR(pd));
135 break; 207 break;
136 case OP_TX_STOP: 208 case OP_TX: /* write data */
137 iowrite8(data, ICDR(pd)); 209 iowrite8(data, ICDR(pd));
138 iowrite8(0x90, ICCR(pd));
139 iowrite8(ICIC_ALE | ICIC_TACKE, ICIC(pd));
140 break; 210 break;
141 case OP_TX_TO_RX: 211 case OP_TX_STOP: /* write data and issue a stop afterwards */
142 iowrite8(data, ICDR(pd)); 212 iowrite8(data, ICDR(pd));
213 iowrite8(0x90, ICCR(pd));
214 break;
215 case OP_TX_TO_RX: /* select read mode */
143 iowrite8(0x81, ICCR(pd)); 216 iowrite8(0x81, ICCR(pd));
144 break; 217 break;
145 case OP_RX_ONLY: 218 case OP_RX: /* just read data */
146 ret = ioread8(ICDR(pd)); 219 ret = ioread8(ICDR(pd));
147 break; 220 break;
148 case OP_RX_STOP: 221 case OP_RX_STOP: /* enable DTE interrupt, issue stop */
222 iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE,
223 ICIC(pd));
224 iowrite8(0xc0, ICCR(pd));
225 break;
226 case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */
227 iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE,
228 ICIC(pd));
149 ret = ioread8(ICDR(pd)); 229 ret = ioread8(ICDR(pd));
150 iowrite8(0xc0, ICCR(pd)); 230 iowrite8(0xc0, ICCR(pd));
151 break; 231 break;
@@ -157,58 +237,120 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
157 return ret; 237 return ret;
158} 238}
159 239
240static int sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd)
241{
242 if (pd->pos == -1)
243 return 1;
244
245 return 0;
246}
247
248static int sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd)
249{
250 if (pd->pos == (pd->msg->len - 1))
251 return 1;
252
253 return 0;
254}
255
256static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd,
257 unsigned char *buf)
258{
259 switch (pd->pos) {
260 case -1:
261 *buf = (pd->msg->addr & 0x7f) << 1;
262 *buf |= (pd->msg->flags & I2C_M_RD) ? 1 : 0;
263 break;
264 default:
265 *buf = pd->msg->buf[pd->pos];
266 }
267}
268
269static int sh_mobile_i2c_isr_tx(struct sh_mobile_i2c_data *pd)
270{
271 unsigned char data;
272
273 if (pd->pos == pd->msg->len)
274 return 1;
275
276 sh_mobile_i2c_get_data(pd, &data);
277
278 if (sh_mobile_i2c_is_last_byte(pd))
279 i2c_op(pd, OP_TX_STOP, data);
280 else if (sh_mobile_i2c_is_first_byte(pd))
281 i2c_op(pd, OP_TX_FIRST, data);
282 else
283 i2c_op(pd, OP_TX, data);
284
285 pd->pos++;
286 return 0;
287}
288
289static int sh_mobile_i2c_isr_rx(struct sh_mobile_i2c_data *pd)
290{
291 unsigned char data;
292 int real_pos;
293
294 do {
295 if (pd->pos <= -1) {
296 sh_mobile_i2c_get_data(pd, &data);
297
298 if (sh_mobile_i2c_is_first_byte(pd))
299 i2c_op(pd, OP_TX_FIRST, data);
300 else
301 i2c_op(pd, OP_TX, data);
302 break;
303 }
304
305 if (pd->pos == 0) {
306 i2c_op(pd, OP_TX_TO_RX, 0);
307 break;
308 }
309
310 real_pos = pd->pos - 2;
311
312 if (pd->pos == pd->msg->len) {
313 if (real_pos < 0) {
314 i2c_op(pd, OP_RX_STOP, 0);
315 break;
316 }
317 data = i2c_op(pd, OP_RX_STOP_DATA, 0);
318 } else
319 data = i2c_op(pd, OP_RX, 0);
320
321 pd->msg->buf[real_pos] = data;
322 } while (0);
323
324 pd->pos++;
325 return pd->pos == (pd->msg->len + 2);
326}
327
160static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id) 328static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
161{ 329{
162 struct platform_device *dev = dev_id; 330 struct platform_device *dev = dev_id;
163 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); 331 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
164 struct i2c_msg *msg = pd->msg; 332 unsigned char sr;
165 unsigned char data, sr; 333 int wakeup;
166 int wakeup = 0;
167 334
168 sr = ioread8(ICSR(pd)); 335 sr = ioread8(ICSR(pd));
169 pd->sr |= sr; 336 pd->sr |= sr; /* remember state */
170 337
171 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, 338 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr,
172 (msg->flags & I2C_M_RD) ? "read" : "write", 339 (pd->msg->flags & I2C_M_RD) ? "read" : "write",
173 pd->pos, msg->len); 340 pd->pos, pd->msg->len);
174 341
175 if (sr & (ICSR_AL | ICSR_TACK)) { 342 if (sr & (ICSR_AL | ICSR_TACK)) {
176 iowrite8(0, ICIC(pd)); /* disable interrupts */ 343 /* don't interrupt transaction - continue to issue stop */
177 wakeup = 1; 344 iowrite8(sr & ~(ICSR_AL | ICSR_TACK), ICSR(pd));
178 goto do_wakeup; 345 wakeup = 0;
179 } 346 } else if (pd->msg->flags & I2C_M_RD)
347 wakeup = sh_mobile_i2c_isr_rx(pd);
348 else
349 wakeup = sh_mobile_i2c_isr_tx(pd);
180 350
181 if (pd->pos == msg->len) { 351 if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */
182 i2c_op(pd, OP_RX_ONLY, 0); 352 iowrite8(sr & ~ICSR_WAIT, ICSR(pd));
183 wakeup = 1;
184 goto do_wakeup;
185 }
186 353
187 if (pd->pos == -1) {
188 data = (msg->addr & 0x7f) << 1;
189 data |= (msg->flags & I2C_M_RD) ? 1 : 0;
190 } else
191 data = msg->buf[pd->pos];
192
193 if ((pd->pos == -1) || !(msg->flags & I2C_M_RD)) {
194 if (msg->flags & I2C_M_RD)
195 i2c_op(pd, OP_TX_TO_RX, data);
196 else if (pd->pos == (msg->len - 1)) {
197 i2c_op(pd, OP_TX_STOP, data);
198 wakeup = 1;
199 } else
200 i2c_op(pd, OP_TX_ONLY, data);
201 } else {
202 if (pd->pos == (msg->len - 1))
203 data = i2c_op(pd, OP_RX_STOP, 0);
204 else
205 data = i2c_op(pd, OP_RX_ONLY, 0);
206
207 msg->buf[pd->pos] = data;
208 }
209 pd->pos++;
210
211 do_wakeup:
212 if (wakeup) { 354 if (wakeup) {
213 pd->sr |= SW_DONE; 355 pd->sr |= SW_DONE;
214 wake_up(&pd->wait); 356 wake_up(&pd->wait);
@@ -219,6 +361,11 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
219 361
220static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg) 362static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg)
221{ 363{
364 if (usr_msg->len == 0 && (usr_msg->flags & I2C_M_RD)) {
365 dev_err(pd->dev, "Unsupported zero length i2c read\n");
366 return -EIO;
367 }
368
222 /* Initialize channel registers */ 369 /* Initialize channel registers */
223 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); 370 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd));
224 371
@@ -233,9 +380,8 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg)
233 pd->pos = -1; 380 pd->pos = -1;
234 pd->sr = 0; 381 pd->sr = 0;
235 382
236 /* Enable all interrupts except wait */ 383 /* Enable all interrupts to begin with */
237 iowrite8(ioread8(ICIC(pd)) | ICIC_ALE | ICIC_TACKE | ICIC_DTEE, 384 iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE | ICIC_DTEE, ICIC(pd));
238 ICIC(pd));
239 return 0; 385 return 0;
240} 386}
241 387
@@ -268,25 +414,18 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
268 if (!k) 414 if (!k)
269 dev_err(pd->dev, "Transfer request timed out\n"); 415 dev_err(pd->dev, "Transfer request timed out\n");
270 416
271 retry_count = 10; 417 retry_count = 1000;
272again: 418again:
273 val = ioread8(ICSR(pd)); 419 val = ioread8(ICSR(pd));
274 420
275 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); 421 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr);
276 422
277 if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) {
278 err = -EIO;
279 break;
280 }
281
282 /* the interrupt handler may wake us up before the 423 /* the interrupt handler may wake us up before the
283 * transfer is finished, so poll the hardware 424 * transfer is finished, so poll the hardware
284 * until we're done. 425 * until we're done.
285 */ 426 */
286 427 if (val & ICSR_BUSY) {
287 if (!(!(val & ICSR_BUSY) && (val & ICSR_SCLM) && 428 udelay(10);
288 (val & ICSR_SDAM))) {
289 msleep(1);
290 if (retry_count--) 429 if (retry_count--)
291 goto again; 430 goto again;
292 431
@@ -294,6 +433,12 @@ again:
294 dev_err(pd->dev, "Polling timed out\n"); 433 dev_err(pd->dev, "Polling timed out\n");
295 break; 434 break;
296 } 435 }
436
437 /* handle missing acknowledge and arbitration lost */
438 if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) {
439 err = -EIO;
440 break;
441 }
297 } 442 }
298 443
299 deactivate_ch(pd); 444 deactivate_ch(pd);
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 862eb352a2d9..9f194d9efd91 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;
@@ -320,10 +332,6 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
320 unsigned char temp; 332 unsigned char temp;
321 int error = -ENODEV; 333 int error = -ENODEV;
322 334
323 /* driver_data might come from user-space, so check it */
324 if (id->driver_data & 1 || id->driver_data > 0xff)
325 return -EINVAL;
326
327 /* Determine the address of the SMBus areas */ 335 /* Determine the address of the SMBus areas */
328 if (force_addr) { 336 if (force_addr) {
329 vt596_smba = force_addr & 0xfff0; 337 vt596_smba = force_addr & 0xfff0;
@@ -396,6 +404,7 @@ found:
396 404
397 switch (pdev->device) { 405 switch (pdev->device) {
398 case PCI_DEVICE_ID_VIA_CX700: 406 case PCI_DEVICE_ID_VIA_CX700:
407 case PCI_DEVICE_ID_VIA_VX800:
399 case PCI_DEVICE_ID_VIA_8251: 408 case PCI_DEVICE_ID_VIA_8251:
400 case PCI_DEVICE_ID_VIA_8237: 409 case PCI_DEVICE_ID_VIA_8237:
401 case PCI_DEVICE_ID_VIA_8237A: 410 case PCI_DEVICE_ID_VIA_8237A:
@@ -459,6 +468,8 @@ static struct pci_device_id vt596_ids[] = {
459 .driver_data = SMBBA3 }, 468 .driver_data = SMBBA3 },
460 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700), 469 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700),
461 .driver_data = SMBBA3 }, 470 .driver_data = SMBBA3 },
471 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX800),
472 .driver_data = SMBBA3 },
462 { 0, } 473 { 0, }
463}; 474};
464 475
@@ -468,7 +479,6 @@ static struct pci_driver vt596_driver = {
468 .name = "vt596_smbus", 479 .name = "vt596_smbus",
469 .id_table = vt596_ids, 480 .id_table = vt596_ids,
470 .probe = vt596_probe, 481 .probe = vt596_probe,
471 .dynids.use_driver_data = 1,
472}; 482};
473 483
474static int __init i2c_vt596_init(void) 484static int __init i2c_vt596_init(void)
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 50e0a4653741..4c35702830ce 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -1,6 +1,8 @@
1# 1#
2# Miscellaneous I2C chip drivers configuration 2# Miscellaneous I2C chip drivers configuration
3# 3#
4# *** DEPRECATED! Do not add new entries! See Makefile ***
5#
4 6
5menu "Miscellaneous I2C Chip support" 7menu "Miscellaneous I2C Chip support"
6 8
@@ -126,7 +128,7 @@ config ISP1301_OMAP
126 128
127config TPS65010 129config TPS65010
128 tristate "TPS6501x Power Management chips" 130 tristate "TPS6501x Power Management chips"
129 depends on HAVE_GPIO_LIB 131 depends on GPIOLIB
130 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 132 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
131 help 133 help
132 If you say yes here you get support for the TPS6501x series of 134 If you say yes here you get support for the TPS6501x series of
@@ -172,4 +174,15 @@ config MENELAUS
172 and other features that are often used in portable devices like 174 and other features that are often used in portable devices like
173 cell phones and PDAs. 175 cell phones and PDAs.
174 176
177config MCU_MPC8349EMITX
178 tristate "MPC8349E-mITX MCU driver"
179 depends on I2C && PPC_83xx
180 select GENERIC_GPIO
181 select ARCH_REQUIRE_GPIOLIB
182 help
183 Say Y here to enable soft power-off functionality on the Freescale
184 boards with the MPC8349E-mITX-compatible MCU chips. This driver will
185 also register MCU GPIOs with the generic GPIO API, so you'll able
186 to use MCU pins as GPIOs.
187
175endmenu 188endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 39e3e69ed125..23d2a31b0a64 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -1,7 +1,8 @@
1# 1#
2# Makefile for miscellaneous I2C chip drivers. 2# Makefile for miscellaneous I2C chip drivers.
3# 3#
4# Think twice before you add a new driver to this directory. 4# Do not add new drivers to this directory! It is DEPRECATED.
5#
5# Device drivers are better grouped according to the functionality they 6# Device drivers are better grouped according to the functionality they
6# implement rather than to the bus they are connected to. In particular: 7# implement rather than to the bus they are connected to. In particular:
7# * Hardware monitoring chip drivers go to drivers/hwmon 8# * Hardware monitoring chip drivers go to drivers/hwmon
@@ -21,6 +22,7 @@ obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
21obj-$(CONFIG_TPS65010) += tps65010.o 22obj-$(CONFIG_TPS65010) += tps65010.o
22obj-$(CONFIG_MENELAUS) += menelaus.o 23obj-$(CONFIG_MENELAUS) += menelaus.o
23obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o 24obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
25obj-$(CONFIG_MCU_MPC8349EMITX) += mcu_mpc8349emitx.o
24 26
25ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 27ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
26EXTRA_CFLAGS += -DDEBUG 28EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/at24.c b/drivers/i2c/chips/at24.c
index e764c94f3e3d..d4775528abc6 100644
--- a/drivers/i2c/chips/at24.c
+++ b/drivers/i2c/chips/at24.c
@@ -188,7 +188,7 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
188 count = I2C_SMBUS_BLOCK_MAX; 188 count = I2C_SMBUS_BLOCK_MAX;
189 status = i2c_smbus_read_i2c_block_data(client, offset, 189 status = i2c_smbus_read_i2c_block_data(client, offset,
190 count, buf); 190 count, buf);
191 dev_dbg(&client->dev, "smbus read %zd@%d --> %d\n", 191 dev_dbg(&client->dev, "smbus read %zu@%d --> %d\n",
192 count, offset, status); 192 count, offset, status);
193 return (status < 0) ? -EIO : status; 193 return (status < 0) ? -EIO : status;
194 } 194 }
@@ -214,7 +214,7 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
214 msg[1].len = count; 214 msg[1].len = count;
215 215
216 status = i2c_transfer(client->adapter, msg, 2); 216 status = i2c_transfer(client->adapter, msg, 2);
217 dev_dbg(&client->dev, "i2c read %zd@%d --> %d\n", 217 dev_dbg(&client->dev, "i2c read %zu@%d --> %d\n",
218 count, offset, status); 218 count, offset, status);
219 219
220 if (status == 2) 220 if (status == 2)
@@ -334,7 +334,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, char *buf,
334 if (status == 1) 334 if (status == 1)
335 status = count; 335 status = count;
336 } 336 }
337 dev_dbg(&client->dev, "write %zd@%d --> %zd (%ld)\n", 337 dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n",
338 count, offset, status, jiffies); 338 count, offset, status, jiffies);
339 339
340 if (status == count) 340 if (status == count)
@@ -460,7 +460,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
460 */ 460 */
461 at24->bin.attr.name = "eeprom"; 461 at24->bin.attr.name = "eeprom";
462 at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; 462 at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR;
463 at24->bin.attr.owner = THIS_MODULE;
464 at24->bin.read = at24_bin_read; 463 at24->bin.read = at24_bin_read;
465 at24->bin.size = chip.byte_len; 464 at24->bin.size = chip.byte_len;
466 465
@@ -512,7 +511,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
512 511
513 i2c_set_clientdata(client, at24); 512 i2c_set_clientdata(client, at24);
514 513
515 dev_info(&client->dev, "%Zd byte %s EEPROM %s\n", 514 dev_info(&client->dev, "%zu byte %s EEPROM %s\n",
516 at24->bin.size, client->name, 515 at24->bin.size, client->name,
517 writable ? "(writable)" : "(read-only)"); 516 writable ? "(writable)" : "(read-only)");
518 dev_dbg(&client->dev, 517 dev_dbg(&client->dev,
diff --git a/drivers/i2c/chips/ds1682.c b/drivers/i2c/chips/ds1682.c
index 23be4d42cb02..f3ee4a1abb77 100644
--- a/drivers/i2c/chips/ds1682.c
+++ b/drivers/i2c/chips/ds1682.c
@@ -190,7 +190,6 @@ static struct bin_attribute ds1682_eeprom_attr = {
190 .attr = { 190 .attr = {
191 .name = "eeprom", 191 .name = "eeprom",
192 .mode = S_IRUGO | S_IWUSR, 192 .mode = S_IRUGO | S_IWUSR,
193 .owner = THIS_MODULE,
194 }, 193 },
195 .size = DS1682_EEPROM_SIZE, 194 .size = DS1682_EEPROM_SIZE,
196 .read = ds1682_eeprom_read, 195 .read = ds1682_eeprom_read,
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 03a33f1b9cd3..28902ebd5539 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -33,7 +33,7 @@
33#include <linux/workqueue.h> 33#include <linux/workqueue.h>
34 34
35#include <asm/irq.h> 35#include <asm/irq.h>
36#include <asm/arch/usb.h> 36#include <mach/usb.h>
37 37
38 38
39#ifndef DEBUG 39#ifndef DEBUG
@@ -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;
@@ -94,7 +93,7 @@ struct isp1301 {
94/* board-specific PM hooks */ 93/* board-specific PM hooks */
95 94
96#include <asm/gpio.h> 95#include <asm/gpio.h>
97#include <asm/arch/mux.h> 96#include <mach/mux.h>
98#include <asm/mach-types.h> 97#include <asm/mach-types.h>
99 98
100 99
@@ -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,39 +1557,34 @@ 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
1593 if (machine_is_omap_h2()) { 1564 if (machine_is_omap_h2()) {
1594 /* full speed signaling by default */ 1565 /* full speed signaling by default */
1595 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, 1566 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1596 MC1_SPEED_REG); 1567 MC1_SPEED);
1597 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, 1568 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1598 MC2_SPD_SUSP_CTRL); 1569 MC2_SPD_SUSP_CTRL);
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/menelaus.c b/drivers/i2c/chips/menelaus.c
index b36db1797c11..4b364bae6b3e 100644
--- a/drivers/i2c/chips/menelaus.c
+++ b/drivers/i2c/chips/menelaus.c
@@ -41,11 +41,10 @@
41#include <linux/rtc.h> 41#include <linux/rtc.h>
42#include <linux/bcd.h> 42#include <linux/bcd.h>
43 43
44#include <asm/mach-types.h>
45#include <asm/mach/irq.h> 44#include <asm/mach/irq.h>
46 45
47#include <asm/arch/gpio.h> 46#include <mach/gpio.h>
48#include <asm/arch/menelaus.h> 47#include <mach/menelaus.h>
49 48
50#define DRIVER_NAME "menelaus" 49#define DRIVER_NAME "menelaus"
51 50
@@ -833,52 +832,52 @@ static irqreturn_t menelaus_irq(int irq, void *_menelaus)
833 832
834static void menelaus_to_time(char *regs, struct rtc_time *t) 833static void menelaus_to_time(char *regs, struct rtc_time *t)
835{ 834{
836 t->tm_sec = BCD2BIN(regs[0]); 835 t->tm_sec = bcd2bin(regs[0]);
837 t->tm_min = BCD2BIN(regs[1]); 836 t->tm_min = bcd2bin(regs[1]);
838 if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { 837 if (the_menelaus->rtc_control & RTC_CTRL_MODE12) {
839 t->tm_hour = BCD2BIN(regs[2] & 0x1f) - 1; 838 t->tm_hour = bcd2bin(regs[2] & 0x1f) - 1;
840 if (regs[2] & RTC_HR_PM) 839 if (regs[2] & RTC_HR_PM)
841 t->tm_hour += 12; 840 t->tm_hour += 12;
842 } else 841 } else
843 t->tm_hour = BCD2BIN(regs[2] & 0x3f); 842 t->tm_hour = bcd2bin(regs[2] & 0x3f);
844 t->tm_mday = BCD2BIN(regs[3]); 843 t->tm_mday = bcd2bin(regs[3]);
845 t->tm_mon = BCD2BIN(regs[4]) - 1; 844 t->tm_mon = bcd2bin(regs[4]) - 1;
846 t->tm_year = BCD2BIN(regs[5]) + 100; 845 t->tm_year = bcd2bin(regs[5]) + 100;
847} 846}
848 847
849static int time_to_menelaus(struct rtc_time *t, int regnum) 848static int time_to_menelaus(struct rtc_time *t, int regnum)
850{ 849{
851 int hour, status; 850 int hour, status;
852 851
853 status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_sec)); 852 status = menelaus_write_reg(regnum++, bin2bcd(t->tm_sec));
854 if (status < 0) 853 if (status < 0)
855 goto fail; 854 goto fail;
856 855
857 status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_min)); 856 status = menelaus_write_reg(regnum++, bin2bcd(t->tm_min));
858 if (status < 0) 857 if (status < 0)
859 goto fail; 858 goto fail;
860 859
861 if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { 860 if (the_menelaus->rtc_control & RTC_CTRL_MODE12) {
862 hour = t->tm_hour + 1; 861 hour = t->tm_hour + 1;
863 if (hour > 12) 862 if (hour > 12)
864 hour = RTC_HR_PM | BIN2BCD(hour - 12); 863 hour = RTC_HR_PM | bin2bcd(hour - 12);
865 else 864 else
866 hour = BIN2BCD(hour); 865 hour = bin2bcd(hour);
867 } else 866 } else
868 hour = BIN2BCD(t->tm_hour); 867 hour = bin2bcd(t->tm_hour);
869 status = menelaus_write_reg(regnum++, hour); 868 status = menelaus_write_reg(regnum++, hour);
870 if (status < 0) 869 if (status < 0)
871 goto fail; 870 goto fail;
872 871
873 status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_mday)); 872 status = menelaus_write_reg(regnum++, bin2bcd(t->tm_mday));
874 if (status < 0) 873 if (status < 0)
875 goto fail; 874 goto fail;
876 875
877 status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_mon + 1)); 876 status = menelaus_write_reg(regnum++, bin2bcd(t->tm_mon + 1));
878 if (status < 0) 877 if (status < 0)
879 goto fail; 878 goto fail;
880 879
881 status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_year - 100)); 880 status = menelaus_write_reg(regnum++, bin2bcd(t->tm_year - 100));
882 if (status < 0) 881 if (status < 0)
883 goto fail; 882 goto fail;
884 883
@@ -915,7 +914,7 @@ static int menelaus_read_time(struct device *dev, struct rtc_time *t)
915 } 914 }
916 915
917 menelaus_to_time(regs, t); 916 menelaus_to_time(regs, t);
918 t->tm_wday = BCD2BIN(regs[6]); 917 t->tm_wday = bcd2bin(regs[6]);
919 918
920 return 0; 919 return 0;
921} 920}
@@ -928,7 +927,7 @@ static int menelaus_set_time(struct device *dev, struct rtc_time *t)
928 status = time_to_menelaus(t, MENELAUS_RTC_SEC); 927 status = time_to_menelaus(t, MENELAUS_RTC_SEC);
929 if (status < 0) 928 if (status < 0)
930 return status; 929 return status;
931 status = menelaus_write_reg(MENELAUS_RTC_WKDAY, BIN2BCD(t->tm_wday)); 930 status = menelaus_write_reg(MENELAUS_RTC_WKDAY, bin2bcd(t->tm_wday));
932 if (status < 0) { 931 if (status < 0) {
933 dev_err(&the_menelaus->client->dev, "rtc write reg %02x " 932 dev_err(&the_menelaus->client->dev, "rtc write reg %02x "
934 "err %d\n", MENELAUS_RTC_WKDAY, status); 933 "err %d\n", MENELAUS_RTC_WKDAY, status);
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 85949685191b..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}
@@ -636,6 +641,8 @@ static int tps65010_probe(struct i2c_client *client,
636 tps->outmask = board->outmask; 641 tps->outmask = board->outmask;
637 642
638 tps->chip.label = client->name; 643 tps->chip.label = client->name;
644 tps->chip.dev = &client->dev;
645 tps->chip.owner = THIS_MODULE;
639 646
640 tps->chip.set = tps65010_gpio_set; 647 tps->chip.set = tps65010_gpio_set;
641 tps->chip.direction_output = tps65010_output; 648 tps->chip.direction_output = tps65010_output;
@@ -644,7 +651,7 @@ static int tps65010_probe(struct i2c_client *client,
644 tps->chip.get = tps65010_gpio_get; 651 tps->chip.get = tps65010_gpio_get;
645 652
646 tps->chip.base = board->base; 653 tps->chip.base = board->base;
647 tps->chip.ngpio = 6; 654 tps->chip.ngpio = 7;
648 tps->chip.can_sleep = 1; 655 tps->chip.can_sleep = 1;
649 656
650 status = gpiochip_add(&tps->chip); 657 status = gpiochip_add(&tps->chip);
@@ -673,6 +680,7 @@ static const struct i2c_device_id tps65010_id[] = {
673 { "tps65011", TPS65011 }, 680 { "tps65011", TPS65011 },
674 { "tps65012", TPS65012 }, 681 { "tps65012", TPS65012 },
675 { "tps65013", TPS65013 }, 682 { "tps65013", TPS65013 },
683 { "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */
676 { } 684 { }
677}; 685};
678MODULE_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 7608df83d6d1..5a485c22660a 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -108,6 +108,9 @@ static int i2c_device_probe(struct device *dev)
108 if (!driver->probe || !driver->id_table) 108 if (!driver->probe || !driver->id_table)
109 return -ENODEV; 109 return -ENODEV;
110 client->driver = driver; 110 client->driver = driver;
111 if (!device_can_wakeup(&client->dev))
112 device_init_wakeup(&client->dev,
113 client->flags & I2C_CLIENT_WAKE);
111 dev_dbg(dev, "probe\n"); 114 dev_dbg(dev, "probe\n");
112 115
113 status = driver->probe(client, i2c_match_id(driver->id_table, client)); 116 status = driver->probe(client, i2c_match_id(driver->id_table, client));
@@ -262,9 +265,11 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
262 client->adapter = adap; 265 client->adapter = adap;
263 266
264 client->dev.platform_data = info->platform_data; 267 client->dev.platform_data = info->platform_data;
265 device_init_wakeup(&client->dev, info->flags & I2C_CLIENT_WAKE);
266 268
267 client->flags = info->flags & ~I2C_CLIENT_WAKE; 269 if (info->archdata)
270 client->dev.archdata = *info->archdata;
271
272 client->flags = info->flags;
268 client->addr = info->addr; 273 client->addr = info->addr;
269 client->irq = info->irq; 274 client->irq = info->irq;
270 275
@@ -435,6 +440,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
435{ 440{
436 int res = 0, dummy; 441 int res = 0, dummy;
437 442
443 /* Can't register until after driver model init */
444 if (unlikely(WARN_ON(!i2c_bus_type.p)))
445 return -EAGAIN;
446
438 mutex_init(&adap->bus_lock); 447 mutex_init(&adap->bus_lock);
439 mutex_init(&adap->clist_lock); 448 mutex_init(&adap->clist_lock);
440 INIT_LIST_HEAD(&adap->clients); 449 INIT_LIST_HEAD(&adap->clients);
@@ -694,6 +703,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
694{ 703{
695 int res; 704 int res;
696 705
706 /* Can't register until after driver model init */
707 if (unlikely(WARN_ON(!i2c_bus_type.p)))
708 return -EAGAIN;
709
697 /* new style driver methods can't mix with legacy ones */ 710 /* new style driver methods can't mix with legacy ones */
698 if (is_newstyle_driver(driver)) { 711 if (is_newstyle_driver(driver)) {
699 if (driver->attach_adapter || driver->detach_adapter 712 if (driver->attach_adapter || driver->detach_adapter
@@ -722,7 +735,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
722 735
723 INIT_LIST_HEAD(&driver->clients); 736 INIT_LIST_HEAD(&driver->clients);
724 /* Walk the adapters that are already present */ 737 /* Walk the adapters that are already present */
725 class_for_each_device(&i2c_adapter_class, driver, __attach_adapter); 738 class_for_each_device(&i2c_adapter_class, NULL, driver,
739 __attach_adapter);
726 740
727 mutex_unlock(&core_lock); 741 mutex_unlock(&core_lock);
728 return 0; 742 return 0;
@@ -782,7 +796,8 @@ void i2c_del_driver(struct i2c_driver *driver)
782{ 796{
783 mutex_lock(&core_lock); 797 mutex_lock(&core_lock);
784 798
785 class_for_each_device(&i2c_adapter_class, driver, __detach_adapter); 799 class_for_each_device(&i2c_adapter_class, NULL, driver,
800 __detach_adapter);
786 801
787 driver_unregister(&driver->driver); 802 driver_unregister(&driver->driver);
788 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 803 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
@@ -811,7 +826,12 @@ static int i2c_check_addr(struct i2c_adapter *adapter, int addr)
811int i2c_attach_client(struct i2c_client *client) 826int i2c_attach_client(struct i2c_client *client)
812{ 827{
813 struct i2c_adapter *adapter = client->adapter; 828 struct i2c_adapter *adapter = client->adapter;
814 int res = 0; 829 int res;
830
831 /* Check for address business */
832 res = i2c_check_addr(adapter, client->addr);
833 if (res)
834 return res;
815 835
816 client->dev.parent = &client->adapter->dev; 836 client->dev.parent = &client->adapter->dev;
817 client->dev.bus = &i2c_bus_type; 837 client->dev.bus = &i2c_bus_type;
@@ -969,7 +989,10 @@ static void __exit i2c_exit(void)
969 bus_unregister(&i2c_bus_type); 989 bus_unregister(&i2c_bus_type);
970} 990}
971 991
972subsys_initcall(i2c_init); 992/* We must initialize early, because some subsystems register i2c drivers
993 * in subsys_initcall() code, but are linked (and initialized) before i2c.
994 */
995postcore_initcall(i2c_init);
973module_exit(i2c_exit); 996module_exit(i2c_exit);
974 997
975/* ---------------------------------------------------- 998/* ----------------------------------------------------
@@ -1181,8 +1204,8 @@ int i2c_probe(struct i2c_adapter *adapter,
1181 && address_data->normal_i2c[0] == I2C_CLIENT_END) 1204 && address_data->normal_i2c[0] == I2C_CLIENT_END)
1182 return 0; 1205 return 0;
1183 1206
1184 dev_warn(&adapter->dev, "SMBus Quick command not supported, " 1207 dev_dbg(&adapter->dev, "SMBus Quick command not supported, "
1185 "can't probe for chips\n"); 1208 "can't probe for chips\n");
1186 return -EOPNOTSUPP; 1209 return -EOPNOTSUPP;
1187 } 1210 }
1188 1211
@@ -1343,6 +1366,10 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1343 } 1366 }
1344 } 1367 }
1345 1368
1369 /* Stop here if the classes do not match */
1370 if (!(adapter->class & driver->class))
1371 goto exit_free;
1372
1346 /* Stop here if we can't use SMBUS_QUICK */ 1373 /* Stop here if we can't use SMBUS_QUICK */
1347 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { 1374 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
1348 if (address_data->probe[0] == I2C_CLIENT_END 1375 if (address_data->probe[0] == I2C_CLIENT_END
@@ -1355,10 +1382,6 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1355 goto exit_free; 1382 goto exit_free;
1356 } 1383 }
1357 1384
1358 /* Stop here if the classes do not match */
1359 if (!(adapter->class & driver->class))
1360 goto exit_free;
1361
1362 /* Probe entries are done second, and are not affected by ignore 1385 /* Probe entries are done second, and are not affected by ignore
1363 entries either */ 1386 entries either */
1364 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { 1387 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
@@ -1449,9 +1472,11 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1449 if ((addr_list[i] & ~0x07) == 0x30 1472 if ((addr_list[i] & ~0x07) == 0x30
1450 || (addr_list[i] & ~0x0f) == 0x50 1473 || (addr_list[i] & ~0x0f) == 0x50
1451 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) { 1474 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
1475 union i2c_smbus_data data;
1476
1452 if (i2c_smbus_xfer(adap, addr_list[i], 0, 1477 if (i2c_smbus_xfer(adap, addr_list[i], 0,
1453 I2C_SMBUS_READ, 0, 1478 I2C_SMBUS_READ, 0,
1454 I2C_SMBUS_BYTE, NULL) >= 0) 1479 I2C_SMBUS_BYTE, &data) >= 0)
1455 break; 1480 break;
1456 } else { 1481 } else {
1457 if (i2c_smbus_xfer(adap, addr_list[i], 0, 1482 if (i2c_smbus_xfer(adap, addr_list[i], 0,
@@ -1666,6 +1691,28 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1666EXPORT_SYMBOL(i2c_smbus_write_word_data); 1691EXPORT_SYMBOL(i2c_smbus_write_word_data);
1667 1692
1668/** 1693/**
1694 * i2c_smbus_process_call - SMBus "process call" protocol
1695 * @client: Handle to slave device
1696 * @command: Byte interpreted by slave
1697 * @value: 16-bit "word" being written
1698 *
1699 * This executes the SMBus "process call" protocol, returning negative errno
1700 * else a 16-bit unsigned "word" received from the device.
1701 */
1702s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value)
1703{
1704 union i2c_smbus_data data;
1705 int status;
1706 data.word = value;
1707
1708 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1709 I2C_SMBUS_WRITE, command,
1710 I2C_SMBUS_PROC_CALL, &data);
1711 return (status < 0) ? status : data.word;
1712}
1713EXPORT_SYMBOL(i2c_smbus_process_call);
1714
1715/**
1669 * i2c_smbus_read_block_data - SMBus "block read" protocol 1716 * i2c_smbus_read_block_data - SMBus "block read" protocol
1670 * @client: Handle to slave device 1717 * @client: Handle to slave device
1671 * @command: Byte interpreted by slave 1718 * @command: Byte interpreted by slave
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 86727fa8858f..c171988a9f51 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -147,7 +147,7 @@ static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,
147 if (tmp==NULL) 147 if (tmp==NULL)
148 return -ENOMEM; 148 return -ENOMEM;
149 149
150 pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n", 150 pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
151 iminor(file->f_path.dentry->d_inode), count); 151 iminor(file->f_path.dentry->d_inode), count);
152 152
153 ret = i2c_master_recv(client,tmp,count); 153 ret = i2c_master_recv(client,tmp,count);
@@ -175,7 +175,7 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
175 return -EFAULT; 175 return -EFAULT;
176 } 176 }
177 177
178 pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n", 178 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
179 iminor(file->f_path.dentry->d_inode), count); 179 iminor(file->f_path.dentry->d_inode), count);
180 180
181 ret = i2c_master_send(client,tmp,count); 181 ret = i2c_master_send(client,tmp,count);
@@ -522,7 +522,7 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
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(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 "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);
@@ -583,8 +583,10 @@ static int __init i2c_dev_init(void)
583 goto out; 583 goto out;
584 584
585 i2c_dev_class = class_create(THIS_MODULE, "i2c-dev"); 585 i2c_dev_class = class_create(THIS_MODULE, "i2c-dev");
586 if (IS_ERR(i2c_dev_class)) 586 if (IS_ERR(i2c_dev_class)) {
587 res = PTR_ERR(i2c_dev_class);
587 goto out_unreg_chrdev; 588 goto out_unreg_chrdev;
589 }
588 590
589 res = i2c_add_driver(&i2cdev_driver); 591 res = i2c_add_driver(&i2cdev_driver);
590 if (res) 592 if (res)