diff options
42 files changed, 960 insertions, 497 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-arb-gpio-challenge.txt b/Documentation/devicetree/bindings/i2c/i2c-arb-gpio-challenge.txt new file mode 100644 index 000000000000..1ac8ea8ade1d --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/i2c-arb-gpio-challenge.txt | |||
@@ -0,0 +1,80 @@ | |||
1 | GPIO-based I2C Arbitration Using a Challenge & Response Mechanism | ||
2 | ================================================================= | ||
3 | This uses GPIO lines and a challenge & response mechanism to arbitrate who is | ||
4 | the master of an I2C bus in a multimaster situation. | ||
5 | |||
6 | In many cases using GPIOs to arbitrate is not needed and a design can use | ||
7 | the standard I2C multi-master rules. Using GPIOs is generally useful in | ||
8 | the case where there is a device on the bus that has errata and/or bugs | ||
9 | that makes standard multimaster mode not feasible. | ||
10 | |||
11 | |||
12 | Algorithm: | ||
13 | |||
14 | All masters on the bus have a 'bus claim' line which is an output that the | ||
15 | others can see. These are all active low with pull-ups enabled. We'll | ||
16 | describe these lines as: | ||
17 | |||
18 | - OUR_CLAIM: output from us signaling to other hosts that we want the bus | ||
19 | - THEIR_CLAIMS: output from others signaling that they want the bus | ||
20 | |||
21 | The basic algorithm is to assert your line when you want the bus, then make | ||
22 | sure that the other side doesn't want it also. A detailed explanation is best | ||
23 | done with an example. | ||
24 | |||
25 | Let's say we want to claim the bus. We: | ||
26 | 1. Assert OUR_CLAIM. | ||
27 | 2. Waits a little bit for the other sides to notice (slew time, say 10 | ||
28 | microseconds). | ||
29 | 3. Check THEIR_CLAIMS. If none are asserted then the we have the bus and we are | ||
30 | done. | ||
31 | 4. Otherwise, wait for a few milliseconds and see if THEIR_CLAIMS are released. | ||
32 | 5. If not, back off, release the claim and wait for a few more milliseconds. | ||
33 | 6. Go back to 1 (until retry time has expired). | ||
34 | |||
35 | |||
36 | Required properties: | ||
37 | - compatible: i2c-arb-gpio-challenge | ||
38 | - our-claim-gpio: The GPIO that we use to claim the bus. | ||
39 | - their-claim-gpios: The GPIOs that the other sides use to claim the bus. | ||
40 | Note that some implementations may only support a single other master. | ||
41 | - Standard I2C mux properties. See mux.txt in this directory. | ||
42 | - Single I2C child bus node at reg 0. See mux.txt in this directory. | ||
43 | |||
44 | Optional properties: | ||
45 | - slew-delay-us: microseconds to wait for a GPIO to go high. Default is 10 us. | ||
46 | - wait-retry-us: we'll attempt another claim after this many microseconds. | ||
47 | Default is 3000 us. | ||
48 | - wait-free-us: we'll give up after this many microseconds. Default is 50000 us. | ||
49 | |||
50 | |||
51 | Example: | ||
52 | i2c@12CA0000 { | ||
53 | compatible = "acme,some-i2c-device"; | ||
54 | #address-cells = <1>; | ||
55 | #size-cells = <0>; | ||
56 | }; | ||
57 | |||
58 | i2c-arbitrator { | ||
59 | compatible = "i2c-arb-gpio-challenge"; | ||
60 | #address-cells = <1>; | ||
61 | #size-cells = <0>; | ||
62 | |||
63 | i2c-parent = <&{/i2c@12CA0000}>; | ||
64 | |||
65 | our-claim-gpio = <&gpf0 3 1>; | ||
66 | their-claim-gpios = <&gpe0 4 1>; | ||
67 | slew-delay-us = <10>; | ||
68 | wait-retry-us = <3000>; | ||
69 | wait-free-us = <50000>; | ||
70 | |||
71 | i2c@0 { | ||
72 | reg = <0>; | ||
73 | #address-cells = <1>; | ||
74 | #size-cells = <0>; | ||
75 | |||
76 | i2c@52 { | ||
77 | // Normal I2C device | ||
78 | }; | ||
79 | }; | ||
80 | }; | ||
diff --git a/MAINTAINERS b/MAINTAINERS index b57e2765a342..59d708f29249 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -3919,7 +3919,6 @@ F: drivers/i2c/i2c-stub.c | |||
3919 | 3919 | ||
3920 | I2C SUBSYSTEM | 3920 | I2C SUBSYSTEM |
3921 | M: Wolfram Sang <wsa@the-dreams.de> | 3921 | M: Wolfram Sang <wsa@the-dreams.de> |
3922 | M: "Ben Dooks (embedded platforms)" <ben-linux@fluff.org> | ||
3923 | L: linux-i2c@vger.kernel.org | 3922 | L: linux-i2c@vger.kernel.org |
3924 | W: http://i2c.wiki.kernel.org/ | 3923 | W: http://i2c.wiki.kernel.org/ |
3925 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git | 3924 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git |
diff --git a/arch/arm/mach-s3c24xx/mach-rx1950.c b/arch/arm/mach-s3c24xx/mach-rx1950.c index 1f9ba2ae5288..43f3ac5a1c7a 100644 --- a/arch/arm/mach-s3c24xx/mach-rx1950.c +++ b/arch/arm/mach-s3c24xx/mach-rx1950.c | |||
@@ -56,7 +56,6 @@ | |||
56 | #include <plat/cpu.h> | 56 | #include <plat/cpu.h> |
57 | #include <plat/devs.h> | 57 | #include <plat/devs.h> |
58 | #include <plat/pm.h> | 58 | #include <plat/pm.h> |
59 | #include <plat/regs-iic.h> | ||
60 | #include <plat/regs-serial.h> | 59 | #include <plat/regs-serial.h> |
61 | 60 | ||
62 | #include "common.h" | 61 | #include "common.h" |
diff --git a/arch/arm/mach-tegra/tegra.c b/arch/arm/mach-tegra/tegra.c index 84deeab23ee7..9cf1ab17afeb 100644 --- a/arch/arm/mach-tegra/tegra.c +++ b/arch/arm/mach-tegra/tegra.c | |||
@@ -31,8 +31,6 @@ | |||
31 | #include <linux/pda_power.h> | 31 | #include <linux/pda_power.h> |
32 | #include <linux/platform_data/tegra_usb.h> | 32 | #include <linux/platform_data/tegra_usb.h> |
33 | #include <linux/io.h> | 33 | #include <linux/io.h> |
34 | #include <linux/i2c.h> | ||
35 | #include <linux/i2c-tegra.h> | ||
36 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
37 | #include <linux/sys_soc.h> | 35 | #include <linux/sys_soc.h> |
38 | #include <linux/usb/tegra_usb_phy.h> | 36 | #include <linux/usb/tegra_usb_phy.h> |
diff --git a/arch/arm/plat-samsung/devs.c b/arch/arm/plat-samsung/devs.c index f55d3f9b508d..8f456bed4fa0 100644 --- a/arch/arm/plat-samsung/devs.c +++ b/arch/arm/plat-samsung/devs.c | |||
@@ -63,7 +63,6 @@ | |||
63 | #include <linux/platform_data/usb-s3c2410_udc.h> | 63 | #include <linux/platform_data/usb-s3c2410_udc.h> |
64 | #include <linux/platform_data/usb-ohci-s3c2410.h> | 64 | #include <linux/platform_data/usb-ohci-s3c2410.h> |
65 | #include <plat/usb-phy.h> | 65 | #include <plat/usb-phy.h> |
66 | #include <plat/regs-iic.h> | ||
67 | #include <plat/regs-serial.h> | 66 | #include <plat/regs-serial.h> |
68 | #include <plat/regs-spi.h> | 67 | #include <plat/regs-spi.h> |
69 | #include <linux/platform_data/spi-s3c64xx.h> | 68 | #include <linux/platform_data/spi-s3c64xx.h> |
diff --git a/arch/arm/plat-samsung/include/plat/regs-iic.h b/arch/arm/plat-samsung/include/plat/regs-iic.h deleted file mode 100644 index 2f7c17de8ac8..000000000000 --- a/arch/arm/plat-samsung/include/plat/regs-iic.h +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | /* arch/arm/mach-s3c2410/include/mach/regs-iic.h | ||
2 | * | ||
3 | * Copyright (c) 2004 Simtec Electronics <linux@simtec.co.uk> | ||
4 | * http://www.simtec.co.uk/products/SWLINUX/ | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * S3C2410 I2C Controller | ||
11 | */ | ||
12 | |||
13 | #ifndef __ASM_ARCH_REGS_IIC_H | ||
14 | #define __ASM_ARCH_REGS_IIC_H __FILE__ | ||
15 | |||
16 | /* see s3c2410x user guide, v1.1, section 9 (p447) for more info */ | ||
17 | |||
18 | #define S3C2410_IICREG(x) (x) | ||
19 | |||
20 | #define S3C2410_IICCON S3C2410_IICREG(0x00) | ||
21 | #define S3C2410_IICSTAT S3C2410_IICREG(0x04) | ||
22 | #define S3C2410_IICADD S3C2410_IICREG(0x08) | ||
23 | #define S3C2410_IICDS S3C2410_IICREG(0x0C) | ||
24 | #define S3C2440_IICLC S3C2410_IICREG(0x10) | ||
25 | |||
26 | #define S3C2410_IICCON_ACKEN (1<<7) | ||
27 | #define S3C2410_IICCON_TXDIV_16 (0<<6) | ||
28 | #define S3C2410_IICCON_TXDIV_512 (1<<6) | ||
29 | #define S3C2410_IICCON_IRQEN (1<<5) | ||
30 | #define S3C2410_IICCON_IRQPEND (1<<4) | ||
31 | #define S3C2410_IICCON_SCALE(x) ((x)&15) | ||
32 | #define S3C2410_IICCON_SCALEMASK (0xf) | ||
33 | |||
34 | #define S3C2410_IICSTAT_MASTER_RX (2<<6) | ||
35 | #define S3C2410_IICSTAT_MASTER_TX (3<<6) | ||
36 | #define S3C2410_IICSTAT_SLAVE_RX (0<<6) | ||
37 | #define S3C2410_IICSTAT_SLAVE_TX (1<<6) | ||
38 | #define S3C2410_IICSTAT_MODEMASK (3<<6) | ||
39 | |||
40 | #define S3C2410_IICSTAT_START (1<<5) | ||
41 | #define S3C2410_IICSTAT_BUSBUSY (1<<5) | ||
42 | #define S3C2410_IICSTAT_TXRXEN (1<<4) | ||
43 | #define S3C2410_IICSTAT_ARBITR (1<<3) | ||
44 | #define S3C2410_IICSTAT_ASSLAVE (1<<2) | ||
45 | #define S3C2410_IICSTAT_ADDR0 (1<<1) | ||
46 | #define S3C2410_IICSTAT_LASTBIT (1<<0) | ||
47 | |||
48 | #define S3C2410_IICLC_SDA_DELAY0 (0 << 0) | ||
49 | #define S3C2410_IICLC_SDA_DELAY5 (1 << 0) | ||
50 | #define S3C2410_IICLC_SDA_DELAY10 (2 << 0) | ||
51 | #define S3C2410_IICLC_SDA_DELAY15 (3 << 0) | ||
52 | #define S3C2410_IICLC_SDA_DELAY_MASK (3 << 0) | ||
53 | |||
54 | #define S3C2410_IICLC_FILTER_ON (1<<2) | ||
55 | |||
56 | #endif /* __ASM_ARCH_REGS_IIC_H */ | ||
diff --git a/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c b/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c index 88627e3ba1e3..1eb86c79523e 100644 --- a/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c +++ b/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c | |||
@@ -319,8 +319,7 @@ void oaktrail_hdmi_i2c_exit(struct pci_dev *dev) | |||
319 | struct hdmi_i2c_dev *i2c_dev; | 319 | struct hdmi_i2c_dev *i2c_dev; |
320 | 320 | ||
321 | hdmi_dev = pci_get_drvdata(dev); | 321 | hdmi_dev = pci_get_drvdata(dev); |
322 | if (i2c_del_adapter(&oaktrail_hdmi_i2c_adapter)) | 322 | i2c_del_adapter(&oaktrail_hdmi_i2c_adapter); |
323 | DRM_DEBUG_DRIVER("Failed to delete hdmi-i2c adapter\n"); | ||
324 | 323 | ||
325 | i2c_dev = hdmi_dev->i2c_dev; | 324 | i2c_dev = hdmi_dev->i2c_dev; |
326 | kfree(i2c_dev); | 325 | kfree(i2c_dev); |
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c index 378fcb5d5783..07f01ac853ff 100644 --- a/drivers/i2c/busses/i2c-amd756-s4882.c +++ b/drivers/i2c/busses/i2c-amd756-s4882.c | |||
@@ -169,11 +169,7 @@ static int __init amd756_s4882_init(void) | |||
169 | } | 169 | } |
170 | 170 | ||
171 | /* Unregister physical bus */ | 171 | /* Unregister physical bus */ |
172 | error = i2c_del_adapter(&amd756_smbus); | 172 | i2c_del_adapter(&amd756_smbus); |
173 | if (error) { | ||
174 | dev_err(&amd756_smbus.dev, "Physical bus removal failed\n"); | ||
175 | goto ERROR0; | ||
176 | } | ||
177 | 173 | ||
178 | printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4882\n"); | 174 | printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4882\n"); |
179 | /* Define the 5 virtual adapters and algorithms structures */ | 175 | /* Define the 5 virtual adapters and algorithms structures */ |
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 75195e3f5ddb..6bb839b688be 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c | |||
@@ -603,15 +603,18 @@ static const struct of_device_id atmel_twi_dt_ids[] = { | |||
603 | } | 603 | } |
604 | }; | 604 | }; |
605 | MODULE_DEVICE_TABLE(of, atmel_twi_dt_ids); | 605 | MODULE_DEVICE_TABLE(of, atmel_twi_dt_ids); |
606 | #else | ||
607 | #define atmel_twi_dt_ids NULL | ||
608 | #endif | 606 | #endif |
609 | 607 | ||
610 | static bool filter(struct dma_chan *chan, void *slave) | 608 | static bool filter(struct dma_chan *chan, void *pdata) |
611 | { | 609 | { |
612 | struct at_dma_slave *sl = slave; | 610 | struct at91_twi_pdata *sl_pdata = pdata; |
611 | struct at_dma_slave *sl; | ||
612 | |||
613 | if (!sl_pdata) | ||
614 | return false; | ||
613 | 615 | ||
614 | if (sl->dma_dev == chan->device->dev) { | 616 | sl = &sl_pdata->dma_slave; |
617 | if (sl && (sl->dma_dev == chan->device->dev)) { | ||
615 | chan->private = sl; | 618 | chan->private = sl; |
616 | return true; | 619 | return true; |
617 | } else { | 620 | } else { |
@@ -622,11 +625,10 @@ static bool filter(struct dma_chan *chan, void *slave) | |||
622 | static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr) | 625 | static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr) |
623 | { | 626 | { |
624 | int ret = 0; | 627 | int ret = 0; |
625 | struct at_dma_slave *sdata; | 628 | struct at91_twi_pdata *pdata = dev->pdata; |
626 | struct dma_slave_config slave_config; | 629 | struct dma_slave_config slave_config; |
627 | struct at91_twi_dma *dma = &dev->dma; | 630 | struct at91_twi_dma *dma = &dev->dma; |
628 | 631 | dma_cap_mask_t mask; | |
629 | sdata = &dev->pdata->dma_slave; | ||
630 | 632 | ||
631 | memset(&slave_config, 0, sizeof(slave_config)); | 633 | memset(&slave_config, 0, sizeof(slave_config)); |
632 | slave_config.src_addr = (dma_addr_t)phy_addr + AT91_TWI_RHR; | 634 | slave_config.src_addr = (dma_addr_t)phy_addr + AT91_TWI_RHR; |
@@ -637,25 +639,22 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr) | |||
637 | slave_config.dst_maxburst = 1; | 639 | slave_config.dst_maxburst = 1; |
638 | slave_config.device_fc = false; | 640 | slave_config.device_fc = false; |
639 | 641 | ||
640 | if (sdata && sdata->dma_dev) { | 642 | dma_cap_zero(mask); |
641 | dma_cap_mask_t mask; | 643 | dma_cap_set(DMA_SLAVE, mask); |
642 | 644 | ||
643 | dma_cap_zero(mask); | 645 | dma->chan_tx = dma_request_slave_channel_compat(mask, filter, pdata, |
644 | dma_cap_set(DMA_SLAVE, mask); | 646 | dev->dev, "tx"); |
645 | dma->chan_tx = dma_request_channel(mask, filter, sdata); | 647 | if (!dma->chan_tx) { |
646 | if (!dma->chan_tx) { | 648 | dev_err(dev->dev, "can't get a DMA channel for tx\n"); |
647 | dev_err(dev->dev, "no DMA channel available for tx\n"); | 649 | ret = -EBUSY; |
648 | ret = -EBUSY; | 650 | goto error; |
649 | goto error; | 651 | } |
650 | } | 652 | |
651 | dma->chan_rx = dma_request_channel(mask, filter, sdata); | 653 | dma->chan_rx = dma_request_slave_channel_compat(mask, filter, pdata, |
652 | if (!dma->chan_rx) { | 654 | dev->dev, "rx"); |
653 | dev_err(dev->dev, "no DMA channel available for rx\n"); | 655 | if (!dma->chan_rx) { |
654 | ret = -EBUSY; | 656 | dev_err(dev->dev, "can't get a DMA channel for rx\n"); |
655 | goto error; | 657 | ret = -EBUSY; |
656 | } | ||
657 | } else { | ||
658 | ret = -EINVAL; | ||
659 | goto error; | 658 | goto error; |
660 | } | 659 | } |
661 | 660 | ||
@@ -785,12 +784,11 @@ static int at91_twi_probe(struct platform_device *pdev) | |||
785 | static int at91_twi_remove(struct platform_device *pdev) | 784 | static int at91_twi_remove(struct platform_device *pdev) |
786 | { | 785 | { |
787 | struct at91_twi_dev *dev = platform_get_drvdata(pdev); | 786 | struct at91_twi_dev *dev = platform_get_drvdata(pdev); |
788 | int rc; | ||
789 | 787 | ||
790 | rc = i2c_del_adapter(&dev->adapter); | 788 | i2c_del_adapter(&dev->adapter); |
791 | clk_disable_unprepare(dev->clk); | 789 | clk_disable_unprepare(dev->clk); |
792 | 790 | ||
793 | return rc; | 791 | return 0; |
794 | } | 792 | } |
795 | 793 | ||
796 | #ifdef CONFIG_PM | 794 | #ifdef CONFIG_PM |
@@ -828,7 +826,7 @@ static struct platform_driver at91_twi_driver = { | |||
828 | .driver = { | 826 | .driver = { |
829 | .name = "at91_i2c", | 827 | .name = "at91_i2c", |
830 | .owner = THIS_MODULE, | 828 | .owner = THIS_MODULE, |
831 | .of_match_table = atmel_twi_dt_ids, | 829 | .of_match_table = of_match_ptr(atmel_twi_dt_ids), |
832 | .pm = at91_twi_pm_ops, | 830 | .pm = at91_twi_pm_ops, |
833 | }, | 831 | }, |
834 | }; | 832 | }; |
diff --git a/drivers/i2c/busses/i2c-cbus-gpio.c b/drivers/i2c/busses/i2c-cbus-gpio.c index 98386d659318..1be13ac11dc5 100644 --- a/drivers/i2c/busses/i2c-cbus-gpio.c +++ b/drivers/i2c/busses/i2c-cbus-gpio.c | |||
@@ -206,7 +206,9 @@ static int cbus_i2c_remove(struct platform_device *pdev) | |||
206 | { | 206 | { |
207 | struct i2c_adapter *adapter = platform_get_drvdata(pdev); | 207 | struct i2c_adapter *adapter = platform_get_drvdata(pdev); |
208 | 208 | ||
209 | return i2c_del_adapter(adapter); | 209 | i2c_del_adapter(adapter); |
210 | |||
211 | return 0; | ||
210 | } | 212 | } |
211 | 213 | ||
212 | static int cbus_i2c_probe(struct platform_device *pdev) | 214 | static int cbus_i2c_probe(struct platform_device *pdev) |
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 7d1e590a7bb6..cf20e06a88e1 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c | |||
@@ -137,7 +137,7 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) | |||
137 | } | 137 | } |
138 | 138 | ||
139 | /* Generate a pulse on the i2c clock pin. */ | 139 | /* Generate a pulse on the i2c clock pin. */ |
140 | static void generic_i2c_clock_pulse(unsigned int scl_pin) | 140 | static void davinci_i2c_clock_pulse(unsigned int scl_pin) |
141 | { | 141 | { |
142 | u16 i; | 142 | u16 i; |
143 | 143 | ||
@@ -155,7 +155,7 @@ static void generic_i2c_clock_pulse(unsigned int scl_pin) | |||
155 | /* This routine does i2c bus recovery as specified in the | 155 | /* This routine does i2c bus recovery as specified in the |
156 | * i2c protocol Rev. 03 section 3.16 titled "Bus clear" | 156 | * i2c protocol Rev. 03 section 3.16 titled "Bus clear" |
157 | */ | 157 | */ |
158 | static void i2c_recover_bus(struct davinci_i2c_dev *dev) | 158 | static void davinci_i2c_recover_bus(struct davinci_i2c_dev *dev) |
159 | { | 159 | { |
160 | u32 flag = 0; | 160 | u32 flag = 0; |
161 | struct davinci_i2c_platform_data *pdata = dev->pdata; | 161 | struct davinci_i2c_platform_data *pdata = dev->pdata; |
@@ -166,7 +166,7 @@ static void i2c_recover_bus(struct davinci_i2c_dev *dev) | |||
166 | flag |= DAVINCI_I2C_MDR_NACK; | 166 | flag |= DAVINCI_I2C_MDR_NACK; |
167 | /* write the data into mode register */ | 167 | /* write the data into mode register */ |
168 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); | 168 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); |
169 | generic_i2c_clock_pulse(pdata->scl_pin); | 169 | davinci_i2c_clock_pulse(pdata->scl_pin); |
170 | /* Send STOP */ | 170 | /* Send STOP */ |
171 | flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | 171 | flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); |
172 | flag |= DAVINCI_I2C_MDR_STP; | 172 | flag |= DAVINCI_I2C_MDR_STP; |
@@ -289,7 +289,7 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, | |||
289 | return -ETIMEDOUT; | 289 | return -ETIMEDOUT; |
290 | } else { | 290 | } else { |
291 | to_cnt = 0; | 291 | to_cnt = 0; |
292 | i2c_recover_bus(dev); | 292 | davinci_i2c_recover_bus(dev); |
293 | i2c_davinci_init(dev); | 293 | i2c_davinci_init(dev); |
294 | } | 294 | } |
295 | } | 295 | } |
@@ -379,7 +379,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) | |||
379 | dev->adapter.timeout); | 379 | dev->adapter.timeout); |
380 | if (r == 0) { | 380 | if (r == 0) { |
381 | dev_err(dev->dev, "controller timed out\n"); | 381 | dev_err(dev->dev, "controller timed out\n"); |
382 | i2c_recover_bus(dev); | 382 | davinci_i2c_recover_bus(dev); |
383 | i2c_davinci_init(dev); | 383 | i2c_davinci_init(dev); |
384 | dev->buf_len = 0; | 384 | dev->buf_len = 0; |
385 | return -ETIMEDOUT; | 385 | return -ETIMEDOUT; |
@@ -643,7 +643,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
643 | { | 643 | { |
644 | struct davinci_i2c_dev *dev; | 644 | struct davinci_i2c_dev *dev; |
645 | struct i2c_adapter *adap; | 645 | struct i2c_adapter *adap; |
646 | struct resource *mem, *irq, *ioarea; | 646 | struct resource *mem, *irq; |
647 | int r; | 647 | int r; |
648 | 648 | ||
649 | /* NOTE: driver uses the static register mapping */ | 649 | /* NOTE: driver uses the static register mapping */ |
@@ -659,24 +659,18 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
659 | return -ENODEV; | 659 | return -ENODEV; |
660 | } | 660 | } |
661 | 661 | ||
662 | ioarea = request_mem_region(mem->start, resource_size(mem), | 662 | dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_i2c_dev), |
663 | pdev->name); | 663 | GFP_KERNEL); |
664 | if (!ioarea) { | ||
665 | dev_err(&pdev->dev, "I2C region already claimed\n"); | ||
666 | return -EBUSY; | ||
667 | } | ||
668 | |||
669 | dev = kzalloc(sizeof(struct davinci_i2c_dev), GFP_KERNEL); | ||
670 | if (!dev) { | 664 | if (!dev) { |
671 | r = -ENOMEM; | 665 | dev_err(&pdev->dev, "Memory allocation failed\n"); |
672 | goto err_release_region; | 666 | return -ENOMEM; |
673 | } | 667 | } |
674 | 668 | ||
675 | init_completion(&dev->cmd_complete); | 669 | init_completion(&dev->cmd_complete); |
676 | #ifdef CONFIG_CPU_FREQ | 670 | #ifdef CONFIG_CPU_FREQ |
677 | init_completion(&dev->xfr_complete); | 671 | init_completion(&dev->xfr_complete); |
678 | #endif | 672 | #endif |
679 | dev->dev = get_device(&pdev->dev); | 673 | dev->dev = &pdev->dev; |
680 | dev->irq = irq->start; | 674 | dev->irq = irq->start; |
681 | dev->pdata = dev->dev->platform_data; | 675 | dev->pdata = dev->dev->platform_data; |
682 | platform_set_drvdata(pdev, dev); | 676 | platform_set_drvdata(pdev, dev); |
@@ -686,10 +680,9 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
686 | 680 | ||
687 | dev->pdata = devm_kzalloc(&pdev->dev, | 681 | dev->pdata = devm_kzalloc(&pdev->dev, |
688 | sizeof(struct davinci_i2c_platform_data), GFP_KERNEL); | 682 | sizeof(struct davinci_i2c_platform_data), GFP_KERNEL); |
689 | if (!dev->pdata) { | 683 | if (!dev->pdata) |
690 | r = -ENOMEM; | 684 | return -ENOMEM; |
691 | goto err_free_mem; | 685 | |
692 | } | ||
693 | memcpy(dev->pdata, &davinci_i2c_platform_data_default, | 686 | memcpy(dev->pdata, &davinci_i2c_platform_data_default, |
694 | sizeof(struct davinci_i2c_platform_data)); | 687 | sizeof(struct davinci_i2c_platform_data)); |
695 | if (!of_property_read_u32(pdev->dev.of_node, "clock-frequency", | 688 | if (!of_property_read_u32(pdev->dev.of_node, "clock-frequency", |
@@ -699,22 +692,21 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
699 | dev->pdata = &davinci_i2c_platform_data_default; | 692 | dev->pdata = &davinci_i2c_platform_data_default; |
700 | } | 693 | } |
701 | 694 | ||
702 | dev->clk = clk_get(&pdev->dev, NULL); | 695 | dev->clk = devm_clk_get(&pdev->dev, NULL); |
703 | if (IS_ERR(dev->clk)) { | 696 | if (IS_ERR(dev->clk)) |
704 | r = -ENODEV; | 697 | return -ENODEV; |
705 | goto err_free_mem; | ||
706 | } | ||
707 | clk_prepare_enable(dev->clk); | 698 | clk_prepare_enable(dev->clk); |
708 | 699 | ||
709 | dev->base = ioremap(mem->start, resource_size(mem)); | 700 | dev->base = devm_ioremap_resource(&pdev->dev, mem); |
710 | if (!dev->base) { | 701 | if (IS_ERR(dev->base)) { |
711 | r = -EBUSY; | 702 | r = PTR_ERR(dev->base); |
712 | goto err_mem_ioremap; | 703 | goto err_unuse_clocks; |
713 | } | 704 | } |
714 | 705 | ||
715 | i2c_davinci_init(dev); | 706 | i2c_davinci_init(dev); |
716 | 707 | ||
717 | r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev); | 708 | r = devm_request_irq(&pdev->dev, dev->irq, i2c_davinci_isr, 0, |
709 | pdev->name, dev); | ||
718 | if (r) { | 710 | if (r) { |
719 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | 711 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); |
720 | goto err_unuse_clocks; | 712 | goto err_unuse_clocks; |
@@ -723,7 +715,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
723 | r = i2c_davinci_cpufreq_register(dev); | 715 | r = i2c_davinci_cpufreq_register(dev); |
724 | if (r) { | 716 | if (r) { |
725 | dev_err(&pdev->dev, "failed to register cpufreq\n"); | 717 | dev_err(&pdev->dev, "failed to register cpufreq\n"); |
726 | goto err_free_irq; | 718 | goto err_unuse_clocks; |
727 | } | 719 | } |
728 | 720 | ||
729 | adap = &dev->adapter; | 721 | adap = &dev->adapter; |
@@ -740,50 +732,31 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
740 | r = i2c_add_numbered_adapter(adap); | 732 | r = i2c_add_numbered_adapter(adap); |
741 | if (r) { | 733 | if (r) { |
742 | dev_err(&pdev->dev, "failure adding adapter\n"); | 734 | dev_err(&pdev->dev, "failure adding adapter\n"); |
743 | goto err_free_irq; | 735 | goto err_unuse_clocks; |
744 | } | 736 | } |
745 | of_i2c_register_devices(adap); | 737 | of_i2c_register_devices(adap); |
746 | 738 | ||
747 | return 0; | 739 | return 0; |
748 | 740 | ||
749 | err_free_irq: | ||
750 | free_irq(dev->irq, dev); | ||
751 | err_unuse_clocks: | 741 | err_unuse_clocks: |
752 | iounmap(dev->base); | ||
753 | err_mem_ioremap: | ||
754 | clk_disable_unprepare(dev->clk); | 742 | clk_disable_unprepare(dev->clk); |
755 | clk_put(dev->clk); | ||
756 | dev->clk = NULL; | 743 | dev->clk = NULL; |
757 | err_free_mem: | ||
758 | put_device(&pdev->dev); | ||
759 | kfree(dev); | ||
760 | err_release_region: | ||
761 | release_mem_region(mem->start, resource_size(mem)); | ||
762 | |||
763 | return r; | 744 | return r; |
764 | } | 745 | } |
765 | 746 | ||
766 | static int davinci_i2c_remove(struct platform_device *pdev) | 747 | static int davinci_i2c_remove(struct platform_device *pdev) |
767 | { | 748 | { |
768 | struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); | 749 | struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); |
769 | struct resource *mem; | ||
770 | 750 | ||
771 | i2c_davinci_cpufreq_deregister(dev); | 751 | i2c_davinci_cpufreq_deregister(dev); |
772 | 752 | ||
773 | i2c_del_adapter(&dev->adapter); | 753 | i2c_del_adapter(&dev->adapter); |
774 | put_device(&pdev->dev); | ||
775 | 754 | ||
776 | clk_disable_unprepare(dev->clk); | 755 | clk_disable_unprepare(dev->clk); |
777 | clk_put(dev->clk); | ||
778 | dev->clk = NULL; | 756 | dev->clk = NULL; |
779 | 757 | ||
780 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); | 758 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); |
781 | free_irq(dev->irq, dev); | ||
782 | iounmap(dev->base); | ||
783 | kfree(dev); | ||
784 | 759 | ||
785 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
786 | release_mem_region(mem->start, resource_size(mem)); | ||
787 | return 0; | 760 | return 0; |
788 | } | 761 | } |
789 | 762 | ||
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c index 94fd81875409..21fbb340ad66 100644 --- a/drivers/i2c/busses/i2c-designware-core.c +++ b/drivers/i2c/busses/i2c-designware-core.c | |||
@@ -68,6 +68,7 @@ | |||
68 | #define DW_IC_TXFLR 0x74 | 68 | #define DW_IC_TXFLR 0x74 |
69 | #define DW_IC_RXFLR 0x78 | 69 | #define DW_IC_RXFLR 0x78 |
70 | #define DW_IC_TX_ABRT_SOURCE 0x80 | 70 | #define DW_IC_TX_ABRT_SOURCE 0x80 |
71 | #define DW_IC_ENABLE_STATUS 0x9c | ||
71 | #define DW_IC_COMP_PARAM_1 0xf4 | 72 | #define DW_IC_COMP_PARAM_1 0xf4 |
72 | #define DW_IC_COMP_TYPE 0xfc | 73 | #define DW_IC_COMP_TYPE 0xfc |
73 | #define DW_IC_COMP_TYPE_VALUE 0x44570140 | 74 | #define DW_IC_COMP_TYPE_VALUE 0x44570140 |
@@ -248,6 +249,27 @@ static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) | |||
248 | return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; | 249 | return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; |
249 | } | 250 | } |
250 | 251 | ||
252 | static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) | ||
253 | { | ||
254 | int timeout = 100; | ||
255 | |||
256 | do { | ||
257 | dw_writel(dev, enable, DW_IC_ENABLE); | ||
258 | if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable) | ||
259 | return; | ||
260 | |||
261 | /* | ||
262 | * Wait 10 times the signaling period of the highest I2C | ||
263 | * transfer supported by the driver (for 400KHz this is | ||
264 | * 25us) as described in the DesignWare I2C databook. | ||
265 | */ | ||
266 | usleep_range(25, 250); | ||
267 | } while (timeout--); | ||
268 | |||
269 | dev_warn(dev->dev, "timeout in %sabling adapter\n", | ||
270 | enable ? "en" : "dis"); | ||
271 | } | ||
272 | |||
251 | /** | 273 | /** |
252 | * i2c_dw_init() - initialize the designware i2c master hardware | 274 | * i2c_dw_init() - initialize the designware i2c master hardware |
253 | * @dev: device private data | 275 | * @dev: device private data |
@@ -278,7 +300,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev) | |||
278 | } | 300 | } |
279 | 301 | ||
280 | /* Disable the adapter */ | 302 | /* Disable the adapter */ |
281 | dw_writel(dev, 0, DW_IC_ENABLE); | 303 | __i2c_dw_enable(dev, false); |
282 | 304 | ||
283 | /* set standard and fast speed deviders for high/low periods */ | 305 | /* set standard and fast speed deviders for high/low periods */ |
284 | 306 | ||
@@ -333,7 +355,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) | |||
333 | return -ETIMEDOUT; | 355 | return -ETIMEDOUT; |
334 | } | 356 | } |
335 | timeout--; | 357 | timeout--; |
336 | mdelay(1); | 358 | usleep_range(1000, 1100); |
337 | } | 359 | } |
338 | 360 | ||
339 | return 0; | 361 | return 0; |
@@ -345,7 +367,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) | |||
345 | u32 ic_con; | 367 | u32 ic_con; |
346 | 368 | ||
347 | /* Disable the adapter */ | 369 | /* Disable the adapter */ |
348 | dw_writel(dev, 0, DW_IC_ENABLE); | 370 | __i2c_dw_enable(dev, false); |
349 | 371 | ||
350 | /* set the slave (target) address */ | 372 | /* set the slave (target) address */ |
351 | dw_writel(dev, msgs[dev->msg_write_idx].addr, DW_IC_TAR); | 373 | dw_writel(dev, msgs[dev->msg_write_idx].addr, DW_IC_TAR); |
@@ -359,7 +381,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) | |||
359 | dw_writel(dev, ic_con, DW_IC_CON); | 381 | dw_writel(dev, ic_con, DW_IC_CON); |
360 | 382 | ||
361 | /* Enable the adapter */ | 383 | /* Enable the adapter */ |
362 | dw_writel(dev, 1, DW_IC_ENABLE); | 384 | __i2c_dw_enable(dev, true); |
363 | 385 | ||
364 | /* Enable interrupts */ | 386 | /* Enable interrupts */ |
365 | dw_writel(dev, DW_IC_INTR_DEFAULT_MASK, DW_IC_INTR_MASK); | 387 | dw_writel(dev, DW_IC_INTR_DEFAULT_MASK, DW_IC_INTR_MASK); |
@@ -565,7 +587,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
565 | /* no error */ | 587 | /* no error */ |
566 | if (likely(!dev->cmd_err)) { | 588 | if (likely(!dev->cmd_err)) { |
567 | /* Disable the adapter */ | 589 | /* Disable the adapter */ |
568 | dw_writel(dev, 0, DW_IC_ENABLE); | 590 | __i2c_dw_enable(dev, false); |
569 | ret = num; | 591 | ret = num; |
570 | goto done; | 592 | goto done; |
571 | } | 593 | } |
@@ -578,7 +600,8 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
578 | ret = -EIO; | 600 | ret = -EIO; |
579 | 601 | ||
580 | done: | 602 | done: |
581 | pm_runtime_put(dev->dev); | 603 | pm_runtime_mark_last_busy(dev->dev); |
604 | pm_runtime_put_autosuspend(dev->dev); | ||
582 | mutex_unlock(&dev->lock); | 605 | mutex_unlock(&dev->lock); |
583 | 606 | ||
584 | return ret; | 607 | return ret; |
@@ -700,7 +723,7 @@ EXPORT_SYMBOL_GPL(i2c_dw_isr); | |||
700 | void i2c_dw_enable(struct dw_i2c_dev *dev) | 723 | void i2c_dw_enable(struct dw_i2c_dev *dev) |
701 | { | 724 | { |
702 | /* Enable the adapter */ | 725 | /* Enable the adapter */ |
703 | dw_writel(dev, 1, DW_IC_ENABLE); | 726 | __i2c_dw_enable(dev, true); |
704 | } | 727 | } |
705 | EXPORT_SYMBOL_GPL(i2c_dw_enable); | 728 | EXPORT_SYMBOL_GPL(i2c_dw_enable); |
706 | 729 | ||
@@ -713,7 +736,7 @@ EXPORT_SYMBOL_GPL(i2c_dw_is_enabled); | |||
713 | void i2c_dw_disable(struct dw_i2c_dev *dev) | 736 | void i2c_dw_disable(struct dw_i2c_dev *dev) |
714 | { | 737 | { |
715 | /* Disable controller */ | 738 | /* Disable controller */ |
716 | dw_writel(dev, 0, DW_IC_ENABLE); | 739 | __i2c_dw_enable(dev, false); |
717 | 740 | ||
718 | /* Disable all interupts */ | 741 | /* Disable all interupts */ |
719 | dw_writel(dev, 0, DW_IC_INTR_MASK); | 742 | dw_writel(dev, 0, DW_IC_INTR_MASK); |
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c index 7c5e383c350d..f6ed06c966ee 100644 --- a/drivers/i2c/busses/i2c-designware-pcidrv.c +++ b/drivers/i2c/busses/i2c-designware-pcidrv.c | |||
@@ -208,68 +208,45 @@ static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) | |||
208 | } | 208 | } |
209 | 209 | ||
210 | static int i2c_dw_pci_probe(struct pci_dev *pdev, | 210 | static int i2c_dw_pci_probe(struct pci_dev *pdev, |
211 | const struct pci_device_id *id) | 211 | const struct pci_device_id *id) |
212 | { | 212 | { |
213 | struct dw_i2c_dev *dev; | 213 | struct dw_i2c_dev *dev; |
214 | struct i2c_adapter *adap; | 214 | struct i2c_adapter *adap; |
215 | unsigned long start, len; | ||
216 | void __iomem *base; | ||
217 | int r; | 215 | int r; |
218 | struct dw_pci_controller *controller; | 216 | struct dw_pci_controller *controller; |
219 | 217 | ||
220 | if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) { | 218 | if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) { |
221 | printk(KERN_ERR "dw_i2c_pci_probe: invalid driver data %ld\n", | 219 | dev_err(&pdev->dev, "%s: invalid driver data %ld\n", __func__, |
222 | id->driver_data); | 220 | id->driver_data); |
223 | return -EINVAL; | 221 | return -EINVAL; |
224 | } | 222 | } |
225 | 223 | ||
226 | controller = &dw_pci_controllers[id->driver_data]; | 224 | controller = &dw_pci_controllers[id->driver_data]; |
227 | 225 | ||
228 | r = pci_enable_device(pdev); | 226 | r = pcim_enable_device(pdev); |
229 | if (r) { | 227 | if (r) { |
230 | dev_err(&pdev->dev, "Failed to enable I2C PCI device (%d)\n", | 228 | dev_err(&pdev->dev, "Failed to enable I2C PCI device (%d)\n", |
231 | r); | 229 | r); |
232 | goto exit; | 230 | return r; |
233 | } | 231 | } |
234 | 232 | ||
235 | /* Determine the address of the I2C area */ | 233 | r = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev)); |
236 | start = pci_resource_start(pdev, 0); | ||
237 | len = pci_resource_len(pdev, 0); | ||
238 | if (!start || len == 0) { | ||
239 | dev_err(&pdev->dev, "base address not set\n"); | ||
240 | r = -ENODEV; | ||
241 | goto exit; | ||
242 | } | ||
243 | |||
244 | r = pci_request_region(pdev, 0, DRIVER_NAME); | ||
245 | if (r) { | 234 | if (r) { |
246 | dev_err(&pdev->dev, "failed to request I2C region " | ||
247 | "0x%lx-0x%lx\n", start, | ||
248 | (unsigned long)pci_resource_end(pdev, 0)); | ||
249 | goto exit; | ||
250 | } | ||
251 | |||
252 | base = ioremap_nocache(start, len); | ||
253 | if (!base) { | ||
254 | dev_err(&pdev->dev, "I/O memory remapping failed\n"); | 235 | dev_err(&pdev->dev, "I/O memory remapping failed\n"); |
255 | r = -ENOMEM; | 236 | return r; |
256 | goto err_release_region; | ||
257 | } | 237 | } |
258 | 238 | ||
259 | 239 | dev = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL); | |
260 | dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); | 240 | if (!dev) |
261 | if (!dev) { | 241 | return -ENOMEM; |
262 | r = -ENOMEM; | ||
263 | goto err_release_region; | ||
264 | } | ||
265 | 242 | ||
266 | init_completion(&dev->cmd_complete); | 243 | init_completion(&dev->cmd_complete); |
267 | mutex_init(&dev->lock); | 244 | mutex_init(&dev->lock); |
268 | dev->clk = NULL; | 245 | dev->clk = NULL; |
269 | dev->controller = controller; | 246 | dev->controller = controller; |
270 | dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; | 247 | dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; |
271 | dev->base = base; | 248 | dev->base = pcim_iomap_table(pdev)[0]; |
272 | dev->dev = get_device(&pdev->dev); | 249 | dev->dev = &pdev->dev; |
273 | dev->functionality = | 250 | dev->functionality = |
274 | I2C_FUNC_I2C | | 251 | I2C_FUNC_I2C | |
275 | I2C_FUNC_SMBUS_BYTE | | 252 | I2C_FUNC_SMBUS_BYTE | |
@@ -284,7 +261,7 @@ const struct pci_device_id *id) | |||
284 | dev->rx_fifo_depth = controller->rx_fifo_depth; | 261 | dev->rx_fifo_depth = controller->rx_fifo_depth; |
285 | r = i2c_dw_init(dev); | 262 | r = i2c_dw_init(dev); |
286 | if (r) | 263 | if (r) |
287 | goto err_iounmap; | 264 | return r; |
288 | 265 | ||
289 | adap = &dev->adapter; | 266 | adap = &dev->adapter; |
290 | i2c_set_adapdata(adap, dev); | 267 | i2c_set_adapdata(adap, dev); |
@@ -296,10 +273,11 @@ const struct pci_device_id *id) | |||
296 | snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d", | 273 | snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d", |
297 | adap->nr); | 274 | adap->nr); |
298 | 275 | ||
299 | r = request_irq(pdev->irq, i2c_dw_isr, IRQF_SHARED, adap->name, dev); | 276 | r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, IRQF_SHARED, |
277 | adap->name, dev); | ||
300 | if (r) { | 278 | if (r) { |
301 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | 279 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); |
302 | goto err_iounmap; | 280 | return r; |
303 | } | 281 | } |
304 | 282 | ||
305 | i2c_dw_disable_int(dev); | 283 | i2c_dw_disable_int(dev); |
@@ -307,24 +285,14 @@ const struct pci_device_id *id) | |||
307 | r = i2c_add_numbered_adapter(adap); | 285 | r = i2c_add_numbered_adapter(adap); |
308 | if (r) { | 286 | if (r) { |
309 | dev_err(&pdev->dev, "failure adding adapter\n"); | 287 | dev_err(&pdev->dev, "failure adding adapter\n"); |
310 | goto err_free_irq; | 288 | return r; |
311 | } | 289 | } |
312 | 290 | ||
313 | pm_runtime_put_noidle(&pdev->dev); | 291 | pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); |
292 | pm_runtime_use_autosuspend(&pdev->dev); | ||
314 | pm_runtime_allow(&pdev->dev); | 293 | pm_runtime_allow(&pdev->dev); |
315 | 294 | ||
316 | return 0; | 295 | return 0; |
317 | |||
318 | err_free_irq: | ||
319 | free_irq(pdev->irq, dev); | ||
320 | err_iounmap: | ||
321 | iounmap(dev->base); | ||
322 | put_device(&pdev->dev); | ||
323 | kfree(dev); | ||
324 | err_release_region: | ||
325 | pci_release_region(pdev, 0); | ||
326 | exit: | ||
327 | return r; | ||
328 | } | 296 | } |
329 | 297 | ||
330 | static void i2c_dw_pci_remove(struct pci_dev *pdev) | 298 | static void i2c_dw_pci_remove(struct pci_dev *pdev) |
@@ -336,11 +304,6 @@ static void i2c_dw_pci_remove(struct pci_dev *pdev) | |||
336 | pm_runtime_get_noresume(&pdev->dev); | 304 | pm_runtime_get_noresume(&pdev->dev); |
337 | 305 | ||
338 | i2c_del_adapter(&dev->adapter); | 306 | i2c_del_adapter(&dev->adapter); |
339 | put_device(&pdev->dev); | ||
340 | |||
341 | free_irq(dev->irq, dev); | ||
342 | kfree(dev); | ||
343 | pci_release_region(pdev, 0); | ||
344 | } | 307 | } |
345 | 308 | ||
346 | /* work with hotplug and coldplug */ | 309 | /* work with hotplug and coldplug */ |
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index e3085c487ace..8ec91335d95a 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c | |||
@@ -56,20 +56,11 @@ static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) | |||
56 | static int dw_i2c_acpi_configure(struct platform_device *pdev) | 56 | static int dw_i2c_acpi_configure(struct platform_device *pdev) |
57 | { | 57 | { |
58 | struct dw_i2c_dev *dev = platform_get_drvdata(pdev); | 58 | struct dw_i2c_dev *dev = platform_get_drvdata(pdev); |
59 | struct acpi_device *adev; | ||
60 | int busno, ret; | ||
61 | 59 | ||
62 | if (!ACPI_HANDLE(&pdev->dev)) | 60 | if (!ACPI_HANDLE(&pdev->dev)) |
63 | return -ENODEV; | 61 | return -ENODEV; |
64 | 62 | ||
65 | ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); | ||
66 | if (ret) | ||
67 | return -ENODEV; | ||
68 | |||
69 | dev->adapter.nr = -1; | 63 | dev->adapter.nr = -1; |
70 | if (adev->pnp.unique_id && !kstrtoint(adev->pnp.unique_id, 0, &busno)) | ||
71 | dev->adapter.nr = busno; | ||
72 | |||
73 | dev->tx_fifo_depth = 32; | 64 | dev->tx_fifo_depth = 32; |
74 | dev->rx_fifo_depth = 32; | 65 | dev->rx_fifo_depth = 32; |
75 | return 0; | 66 | return 0; |
@@ -92,7 +83,7 @@ static int dw_i2c_probe(struct platform_device *pdev) | |||
92 | { | 83 | { |
93 | struct dw_i2c_dev *dev; | 84 | struct dw_i2c_dev *dev; |
94 | struct i2c_adapter *adap; | 85 | struct i2c_adapter *adap; |
95 | struct resource *mem, *ioarea; | 86 | struct resource *mem; |
96 | int irq, r; | 87 | int irq, r; |
97 | 88 | ||
98 | /* NOTE: driver uses the static register mapping */ | 89 | /* NOTE: driver uses the static register mapping */ |
@@ -108,32 +99,25 @@ static int dw_i2c_probe(struct platform_device *pdev) | |||
108 | return irq; /* -ENXIO */ | 99 | return irq; /* -ENXIO */ |
109 | } | 100 | } |
110 | 101 | ||
111 | ioarea = request_mem_region(mem->start, resource_size(mem), | 102 | dev = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL); |
112 | pdev->name); | 103 | if (!dev) |
113 | if (!ioarea) { | 104 | return -ENOMEM; |
114 | dev_err(&pdev->dev, "I2C region already claimed\n"); | ||
115 | return -EBUSY; | ||
116 | } | ||
117 | 105 | ||
118 | dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); | 106 | dev->base = devm_ioremap_resource(&pdev->dev, mem); |
119 | if (!dev) { | 107 | if (IS_ERR(dev->base)) |
120 | r = -ENOMEM; | 108 | return PTR_ERR(dev->base); |
121 | goto err_release_region; | ||
122 | } | ||
123 | 109 | ||
124 | init_completion(&dev->cmd_complete); | 110 | init_completion(&dev->cmd_complete); |
125 | mutex_init(&dev->lock); | 111 | mutex_init(&dev->lock); |
126 | dev->dev = get_device(&pdev->dev); | 112 | dev->dev = &pdev->dev; |
127 | dev->irq = irq; | 113 | dev->irq = irq; |
128 | platform_set_drvdata(pdev, dev); | 114 | platform_set_drvdata(pdev, dev); |
129 | 115 | ||
130 | dev->clk = clk_get(&pdev->dev, NULL); | 116 | dev->clk = devm_clk_get(&pdev->dev, NULL); |
131 | dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; | 117 | dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; |
132 | 118 | ||
133 | if (IS_ERR(dev->clk)) { | 119 | if (IS_ERR(dev->clk)) |
134 | r = -ENODEV; | 120 | return PTR_ERR(dev->clk); |
135 | goto err_free_mem; | ||
136 | } | ||
137 | clk_prepare_enable(dev->clk); | 121 | clk_prepare_enable(dev->clk); |
138 | 122 | ||
139 | dev->functionality = | 123 | dev->functionality = |
@@ -146,13 +130,6 @@ static int dw_i2c_probe(struct platform_device *pdev) | |||
146 | dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | | 130 | dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | |
147 | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; | 131 | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; |
148 | 132 | ||
149 | dev->base = ioremap(mem->start, resource_size(mem)); | ||
150 | if (dev->base == NULL) { | ||
151 | dev_err(&pdev->dev, "failure mapping io resources\n"); | ||
152 | r = -EBUSY; | ||
153 | goto err_unuse_clocks; | ||
154 | } | ||
155 | |||
156 | /* Try first if we can configure the device from ACPI */ | 133 | /* Try first if we can configure the device from ACPI */ |
157 | r = dw_i2c_acpi_configure(pdev); | 134 | r = dw_i2c_acpi_configure(pdev); |
158 | if (r) { | 135 | if (r) { |
@@ -164,13 +141,14 @@ static int dw_i2c_probe(struct platform_device *pdev) | |||
164 | } | 141 | } |
165 | r = i2c_dw_init(dev); | 142 | r = i2c_dw_init(dev); |
166 | if (r) | 143 | if (r) |
167 | goto err_iounmap; | 144 | return r; |
168 | 145 | ||
169 | i2c_dw_disable_int(dev); | 146 | i2c_dw_disable_int(dev); |
170 | r = request_irq(dev->irq, i2c_dw_isr, IRQF_SHARED, pdev->name, dev); | 147 | r = devm_request_irq(&pdev->dev, dev->irq, i2c_dw_isr, IRQF_SHARED, |
148 | pdev->name, dev); | ||
171 | if (r) { | 149 | if (r) { |
172 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | 150 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); |
173 | goto err_iounmap; | 151 | return r; |
174 | } | 152 | } |
175 | 153 | ||
176 | adap = &dev->adapter; | 154 | adap = &dev->adapter; |
@@ -186,57 +164,32 @@ static int dw_i2c_probe(struct platform_device *pdev) | |||
186 | r = i2c_add_numbered_adapter(adap); | 164 | r = i2c_add_numbered_adapter(adap); |
187 | if (r) { | 165 | if (r) { |
188 | dev_err(&pdev->dev, "failure adding adapter\n"); | 166 | dev_err(&pdev->dev, "failure adding adapter\n"); |
189 | goto err_free_irq; | 167 | return r; |
190 | } | 168 | } |
191 | of_i2c_register_devices(adap); | 169 | of_i2c_register_devices(adap); |
192 | acpi_i2c_register_devices(adap); | 170 | acpi_i2c_register_devices(adap); |
193 | 171 | ||
172 | pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); | ||
173 | pm_runtime_use_autosuspend(&pdev->dev); | ||
194 | pm_runtime_set_active(&pdev->dev); | 174 | pm_runtime_set_active(&pdev->dev); |
195 | pm_runtime_enable(&pdev->dev); | 175 | pm_runtime_enable(&pdev->dev); |
196 | pm_runtime_put(&pdev->dev); | ||
197 | 176 | ||
198 | return 0; | 177 | return 0; |
199 | |||
200 | err_free_irq: | ||
201 | free_irq(dev->irq, dev); | ||
202 | err_iounmap: | ||
203 | iounmap(dev->base); | ||
204 | err_unuse_clocks: | ||
205 | clk_disable_unprepare(dev->clk); | ||
206 | clk_put(dev->clk); | ||
207 | dev->clk = NULL; | ||
208 | err_free_mem: | ||
209 | put_device(&pdev->dev); | ||
210 | kfree(dev); | ||
211 | err_release_region: | ||
212 | release_mem_region(mem->start, resource_size(mem)); | ||
213 | |||
214 | return r; | ||
215 | } | 178 | } |
216 | 179 | ||
217 | static int dw_i2c_remove(struct platform_device *pdev) | 180 | static int dw_i2c_remove(struct platform_device *pdev) |
218 | { | 181 | { |
219 | struct dw_i2c_dev *dev = platform_get_drvdata(pdev); | 182 | struct dw_i2c_dev *dev = platform_get_drvdata(pdev); |
220 | struct resource *mem; | ||
221 | 183 | ||
222 | pm_runtime_get_sync(&pdev->dev); | 184 | pm_runtime_get_sync(&pdev->dev); |
223 | 185 | ||
224 | i2c_del_adapter(&dev->adapter); | 186 | i2c_del_adapter(&dev->adapter); |
225 | put_device(&pdev->dev); | ||
226 | |||
227 | clk_disable_unprepare(dev->clk); | ||
228 | clk_put(dev->clk); | ||
229 | dev->clk = NULL; | ||
230 | 187 | ||
231 | i2c_dw_disable(dev); | 188 | i2c_dw_disable(dev); |
232 | free_irq(dev->irq, dev); | ||
233 | kfree(dev); | ||
234 | 189 | ||
235 | pm_runtime_put(&pdev->dev); | 190 | pm_runtime_put(&pdev->dev); |
236 | pm_runtime_disable(&pdev->dev); | 191 | pm_runtime_disable(&pdev->dev); |
237 | 192 | ||
238 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
239 | release_mem_region(mem->start, resource_size(mem)); | ||
240 | return 0; | 193 | return 0; |
241 | } | 194 | } |
242 | 195 | ||
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index f3fa4332bbdf..bc6e139c6e7f 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c | |||
@@ -85,23 +85,29 @@ static int i2c_gpio_getscl(void *data) | |||
85 | return gpio_get_value(pdata->scl_pin); | 85 | return gpio_get_value(pdata->scl_pin); |
86 | } | 86 | } |
87 | 87 | ||
88 | static int of_i2c_gpio_probe(struct device_node *np, | 88 | static int of_i2c_gpio_get_pins(struct device_node *np, |
89 | struct i2c_gpio_platform_data *pdata) | 89 | unsigned int *sda_pin, unsigned int *scl_pin) |
90 | { | 90 | { |
91 | u32 reg; | ||
92 | |||
93 | if (of_gpio_count(np) < 2) | 91 | if (of_gpio_count(np) < 2) |
94 | return -ENODEV; | 92 | return -ENODEV; |
95 | 93 | ||
96 | pdata->sda_pin = of_get_gpio(np, 0); | 94 | *sda_pin = of_get_gpio(np, 0); |
97 | pdata->scl_pin = of_get_gpio(np, 1); | 95 | *scl_pin = of_get_gpio(np, 1); |
98 | 96 | ||
99 | if (!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin)) { | 97 | if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { |
100 | pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n", | 98 | pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n", |
101 | np->full_name, pdata->sda_pin, pdata->scl_pin); | 99 | np->full_name, *sda_pin, *scl_pin); |
102 | return -ENODEV; | 100 | return -ENODEV; |
103 | } | 101 | } |
104 | 102 | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static void of_i2c_gpio_get_props(struct device_node *np, | ||
107 | struct i2c_gpio_platform_data *pdata) | ||
108 | { | ||
109 | u32 reg; | ||
110 | |||
105 | of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay); | 111 | of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay); |
106 | 112 | ||
107 | if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", ®)) | 113 | if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", ®)) |
@@ -113,8 +119,6 @@ static int of_i2c_gpio_probe(struct device_node *np, | |||
113 | of_property_read_bool(np, "i2c-gpio,scl-open-drain"); | 119 | of_property_read_bool(np, "i2c-gpio,scl-open-drain"); |
114 | pdata->scl_is_output_only = | 120 | pdata->scl_is_output_only = |
115 | of_property_read_bool(np, "i2c-gpio,scl-output-only"); | 121 | of_property_read_bool(np, "i2c-gpio,scl-output-only"); |
116 | |||
117 | return 0; | ||
118 | } | 122 | } |
119 | 123 | ||
120 | static int i2c_gpio_probe(struct platform_device *pdev) | 124 | static int i2c_gpio_probe(struct platform_device *pdev) |
@@ -123,31 +127,52 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
123 | struct i2c_gpio_platform_data *pdata; | 127 | struct i2c_gpio_platform_data *pdata; |
124 | struct i2c_algo_bit_data *bit_data; | 128 | struct i2c_algo_bit_data *bit_data; |
125 | struct i2c_adapter *adap; | 129 | struct i2c_adapter *adap; |
130 | unsigned int sda_pin, scl_pin; | ||
126 | int ret; | 131 | int ret; |
127 | 132 | ||
128 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | 133 | /* First get the GPIO pins; if it fails, we'll defer the probe. */ |
129 | if (!priv) | ||
130 | return -ENOMEM; | ||
131 | adap = &priv->adap; | ||
132 | bit_data = &priv->bit_data; | ||
133 | pdata = &priv->pdata; | ||
134 | |||
135 | if (pdev->dev.of_node) { | 134 | if (pdev->dev.of_node) { |
136 | ret = of_i2c_gpio_probe(pdev->dev.of_node, pdata); | 135 | ret = of_i2c_gpio_get_pins(pdev->dev.of_node, |
136 | &sda_pin, &scl_pin); | ||
137 | if (ret) | 137 | if (ret) |
138 | return ret; | 138 | return ret; |
139 | } else { | 139 | } else { |
140 | if (!pdev->dev.platform_data) | 140 | if (!pdev->dev.platform_data) |
141 | return -ENXIO; | 141 | return -ENXIO; |
142 | memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); | 142 | pdata = pdev->dev.platform_data; |
143 | sda_pin = pdata->sda_pin; | ||
144 | scl_pin = pdata->scl_pin; | ||
143 | } | 145 | } |
144 | 146 | ||
145 | ret = gpio_request(pdata->sda_pin, "sda"); | 147 | ret = gpio_request(sda_pin, "sda"); |
146 | if (ret) | 148 | if (ret) { |
149 | if (ret == -EINVAL) | ||
150 | ret = -EPROBE_DEFER; /* Try again later */ | ||
147 | goto err_request_sda; | 151 | goto err_request_sda; |
148 | ret = gpio_request(pdata->scl_pin, "scl"); | 152 | } |
149 | if (ret) | 153 | ret = gpio_request(scl_pin, "scl"); |
154 | if (ret) { | ||
155 | if (ret == -EINVAL) | ||
156 | ret = -EPROBE_DEFER; /* Try again later */ | ||
150 | goto err_request_scl; | 157 | goto err_request_scl; |
158 | } | ||
159 | |||
160 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
161 | if (!priv) { | ||
162 | ret = -ENOMEM; | ||
163 | goto err_add_bus; | ||
164 | } | ||
165 | adap = &priv->adap; | ||
166 | bit_data = &priv->bit_data; | ||
167 | pdata = &priv->pdata; | ||
168 | |||
169 | if (pdev->dev.of_node) { | ||
170 | pdata->sda_pin = sda_pin; | ||
171 | pdata->scl_pin = scl_pin; | ||
172 | of_i2c_gpio_get_props(pdev->dev.of_node, pdata); | ||
173 | } else { | ||
174 | memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); | ||
175 | } | ||
151 | 176 | ||
152 | if (pdata->sda_is_open_drain) { | 177 | if (pdata->sda_is_open_drain) { |
153 | gpio_direction_output(pdata->sda_pin, 1); | 178 | gpio_direction_output(pdata->sda_pin, 1); |
@@ -211,9 +236,9 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
211 | return 0; | 236 | return 0; |
212 | 237 | ||
213 | err_add_bus: | 238 | err_add_bus: |
214 | gpio_free(pdata->scl_pin); | 239 | gpio_free(scl_pin); |
215 | err_request_scl: | 240 | err_request_scl: |
216 | gpio_free(pdata->sda_pin); | 241 | gpio_free(sda_pin); |
217 | err_request_sda: | 242 | err_request_sda: |
218 | return ret; | 243 | return ret; |
219 | } | 244 | } |
diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c index 323fa018ffd5..0fb659726ffc 100644 --- a/drivers/i2c/busses/i2c-intel-mid.c +++ b/drivers/i2c/busses/i2c-intel-mid.c | |||
@@ -1082,8 +1082,7 @@ static void intel_mid_i2c_remove(struct pci_dev *dev) | |||
1082 | { | 1082 | { |
1083 | struct intel_mid_i2c_private *mrst = pci_get_drvdata(dev); | 1083 | struct intel_mid_i2c_private *mrst = pci_get_drvdata(dev); |
1084 | intel_mid_i2c_disable(&mrst->adap); | 1084 | intel_mid_i2c_disable(&mrst->adap); |
1085 | if (i2c_del_adapter(&mrst->adap)) | 1085 | i2c_del_adapter(&mrst->adap); |
1086 | dev_err(&dev->dev, "Failed to delete i2c adapter"); | ||
1087 | 1086 | ||
1088 | free_irq(dev->irq, mrst); | 1087 | free_irq(dev->irq, mrst); |
1089 | iounmap(mrst->base); | 1088 | iounmap(mrst->base); |
diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index 130f02cc9d94..cd82eb44e4c4 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c | |||
@@ -183,7 +183,7 @@ struct ismt_priv { | |||
183 | /** | 183 | /** |
184 | * ismt_ids - PCI device IDs supported by this driver | 184 | * ismt_ids - PCI device IDs supported by this driver |
185 | */ | 185 | */ |
186 | static const DEFINE_PCI_DEVICE_TABLE(ismt_ids) = { | 186 | static DEFINE_PCI_DEVICE_TABLE(ismt_ids) = { |
187 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) }, | 187 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) }, |
188 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) }, | 188 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) }, |
189 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) }, | 189 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) }, |
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index 8b20ef8524ac..3bbd65d35a5e 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
@@ -701,9 +701,8 @@ static int | |||
701 | mv64xxx_i2c_remove(struct platform_device *dev) | 701 | mv64xxx_i2c_remove(struct platform_device *dev) |
702 | { | 702 | { |
703 | struct mv64xxx_i2c_data *drv_data = platform_get_drvdata(dev); | 703 | struct mv64xxx_i2c_data *drv_data = platform_get_drvdata(dev); |
704 | int rc; | ||
705 | 704 | ||
706 | rc = i2c_del_adapter(&drv_data->adapter); | 705 | i2c_del_adapter(&drv_data->adapter); |
707 | free_irq(drv_data->irq, drv_data); | 706 | free_irq(drv_data->irq, drv_data); |
708 | mv64xxx_i2c_unmap_regs(drv_data); | 707 | mv64xxx_i2c_unmap_regs(drv_data); |
709 | #if defined(CONFIG_HAVE_CLK) | 708 | #if defined(CONFIG_HAVE_CLK) |
@@ -715,7 +714,7 @@ mv64xxx_i2c_remove(struct platform_device *dev) | |||
715 | #endif | 714 | #endif |
716 | kfree(drv_data); | 715 | kfree(drv_data); |
717 | 716 | ||
718 | return rc; | 717 | return 0; |
719 | } | 718 | } |
720 | 719 | ||
721 | static const struct of_device_id mv64xxx_i2c_of_match_table[] = { | 720 | static const struct of_device_id mv64xxx_i2c_of_match_table[] = { |
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c index 120f24646696..c67d89fc6254 100644 --- a/drivers/i2c/busses/i2c-mxs.c +++ b/drivers/i2c/busses/i2c-mxs.c | |||
@@ -56,6 +56,7 @@ | |||
56 | #define MXS_I2C_CTRL1_SET (0x44) | 56 | #define MXS_I2C_CTRL1_SET (0x44) |
57 | #define MXS_I2C_CTRL1_CLR (0x48) | 57 | #define MXS_I2C_CTRL1_CLR (0x48) |
58 | 58 | ||
59 | #define MXS_I2C_CTRL1_CLR_GOT_A_NAK 0x10000000 | ||
59 | #define MXS_I2C_CTRL1_BUS_FREE_IRQ 0x80 | 60 | #define MXS_I2C_CTRL1_BUS_FREE_IRQ 0x80 |
60 | #define MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ 0x40 | 61 | #define MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ 0x40 |
61 | #define MXS_I2C_CTRL1_NO_SLAVE_ACK_IRQ 0x20 | 62 | #define MXS_I2C_CTRL1_NO_SLAVE_ACK_IRQ 0x20 |
@@ -65,6 +66,10 @@ | |||
65 | #define MXS_I2C_CTRL1_SLAVE_STOP_IRQ 0x02 | 66 | #define MXS_I2C_CTRL1_SLAVE_STOP_IRQ 0x02 |
66 | #define MXS_I2C_CTRL1_SLAVE_IRQ 0x01 | 67 | #define MXS_I2C_CTRL1_SLAVE_IRQ 0x01 |
67 | 68 | ||
69 | #define MXS_I2C_STAT (0x50) | ||
70 | #define MXS_I2C_STAT_BUS_BUSY 0x00000800 | ||
71 | #define MXS_I2C_STAT_CLK_GEN_BUSY 0x00000400 | ||
72 | |||
68 | #define MXS_I2C_DATA (0xa0) | 73 | #define MXS_I2C_DATA (0xa0) |
69 | 74 | ||
70 | #define MXS_I2C_DEBUG0 (0xb0) | 75 | #define MXS_I2C_DEBUG0 (0xb0) |
@@ -297,12 +302,10 @@ static int mxs_i2c_pio_wait_dmareq(struct mxs_i2c_dev *i2c) | |||
297 | cond_resched(); | 302 | cond_resched(); |
298 | } | 303 | } |
299 | 304 | ||
300 | writel(MXS_I2C_DEBUG0_DMAREQ, i2c->regs + MXS_I2C_DEBUG0_CLR); | ||
301 | |||
302 | return 0; | 305 | return 0; |
303 | } | 306 | } |
304 | 307 | ||
305 | static int mxs_i2c_pio_wait_cplt(struct mxs_i2c_dev *i2c) | 308 | static int mxs_i2c_pio_wait_cplt(struct mxs_i2c_dev *i2c, int last) |
306 | { | 309 | { |
307 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | 310 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
308 | 311 | ||
@@ -323,9 +326,50 @@ static int mxs_i2c_pio_wait_cplt(struct mxs_i2c_dev *i2c) | |||
323 | writel(MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ, | 326 | writel(MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ, |
324 | i2c->regs + MXS_I2C_CTRL1_CLR); | 327 | i2c->regs + MXS_I2C_CTRL1_CLR); |
325 | 328 | ||
329 | /* | ||
330 | * When ending a transfer with a stop, we have to wait for the bus to | ||
331 | * go idle before we report the transfer as completed. Otherwise the | ||
332 | * start of the next transfer may race with the end of the current one. | ||
333 | */ | ||
334 | while (last && (readl(i2c->regs + MXS_I2C_STAT) & | ||
335 | (MXS_I2C_STAT_BUS_BUSY | MXS_I2C_STAT_CLK_GEN_BUSY))) { | ||
336 | if (time_after(jiffies, timeout)) | ||
337 | return -ETIMEDOUT; | ||
338 | cond_resched(); | ||
339 | } | ||
340 | |||
326 | return 0; | 341 | return 0; |
327 | } | 342 | } |
328 | 343 | ||
344 | static int mxs_i2c_pio_check_error_state(struct mxs_i2c_dev *i2c) | ||
345 | { | ||
346 | u32 state; | ||
347 | |||
348 | state = readl(i2c->regs + MXS_I2C_CTRL1_CLR) & MXS_I2C_IRQ_MASK; | ||
349 | |||
350 | if (state & MXS_I2C_CTRL1_NO_SLAVE_ACK_IRQ) | ||
351 | i2c->cmd_err = -ENXIO; | ||
352 | else if (state & (MXS_I2C_CTRL1_EARLY_TERM_IRQ | | ||
353 | MXS_I2C_CTRL1_MASTER_LOSS_IRQ | | ||
354 | MXS_I2C_CTRL1_SLAVE_STOP_IRQ | | ||
355 | MXS_I2C_CTRL1_SLAVE_IRQ)) | ||
356 | i2c->cmd_err = -EIO; | ||
357 | |||
358 | return i2c->cmd_err; | ||
359 | } | ||
360 | |||
361 | static void mxs_i2c_pio_trigger_cmd(struct mxs_i2c_dev *i2c, u32 cmd) | ||
362 | { | ||
363 | u32 reg; | ||
364 | |||
365 | writel(cmd, i2c->regs + MXS_I2C_CTRL0); | ||
366 | |||
367 | /* readback makes sure the write is latched into hardware */ | ||
368 | reg = readl(i2c->regs + MXS_I2C_CTRL0); | ||
369 | reg |= MXS_I2C_CTRL0_RUN; | ||
370 | writel(reg, i2c->regs + MXS_I2C_CTRL0); | ||
371 | } | ||
372 | |||
329 | static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, | 373 | static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, |
330 | struct i2c_msg *msg, uint32_t flags) | 374 | struct i2c_msg *msg, uint32_t flags) |
331 | { | 375 | { |
@@ -341,23 +385,26 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, | |||
341 | addr_data |= I2C_SMBUS_READ; | 385 | addr_data |= I2C_SMBUS_READ; |
342 | 386 | ||
343 | /* SELECT command. */ | 387 | /* SELECT command. */ |
344 | writel(MXS_I2C_CTRL0_RUN | MXS_CMD_I2C_SELECT, | 388 | mxs_i2c_pio_trigger_cmd(i2c, MXS_CMD_I2C_SELECT); |
345 | i2c->regs + MXS_I2C_CTRL0); | ||
346 | 389 | ||
347 | ret = mxs_i2c_pio_wait_dmareq(i2c); | 390 | ret = mxs_i2c_pio_wait_dmareq(i2c); |
348 | if (ret) | 391 | if (ret) |
349 | return ret; | 392 | return ret; |
350 | 393 | ||
351 | writel(addr_data, i2c->regs + MXS_I2C_DATA); | 394 | writel(addr_data, i2c->regs + MXS_I2C_DATA); |
395 | writel(MXS_I2C_DEBUG0_DMAREQ, i2c->regs + MXS_I2C_DEBUG0_CLR); | ||
352 | 396 | ||
353 | ret = mxs_i2c_pio_wait_cplt(i2c); | 397 | ret = mxs_i2c_pio_wait_cplt(i2c, 0); |
354 | if (ret) | 398 | if (ret) |
355 | return ret; | 399 | return ret; |
356 | 400 | ||
401 | if (mxs_i2c_pio_check_error_state(i2c)) | ||
402 | goto cleanup; | ||
403 | |||
357 | /* READ command. */ | 404 | /* READ command. */ |
358 | writel(MXS_I2C_CTRL0_RUN | MXS_CMD_I2C_READ | flags | | 405 | mxs_i2c_pio_trigger_cmd(i2c, |
359 | MXS_I2C_CTRL0_XFER_COUNT(msg->len), | 406 | MXS_CMD_I2C_READ | flags | |
360 | i2c->regs + MXS_I2C_CTRL0); | 407 | MXS_I2C_CTRL0_XFER_COUNT(msg->len)); |
361 | 408 | ||
362 | for (i = 0; i < msg->len; i++) { | 409 | for (i = 0; i < msg->len; i++) { |
363 | if ((i & 3) == 0) { | 410 | if ((i & 3) == 0) { |
@@ -365,6 +412,8 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, | |||
365 | if (ret) | 412 | if (ret) |
366 | return ret; | 413 | return ret; |
367 | data = readl(i2c->regs + MXS_I2C_DATA); | 414 | data = readl(i2c->regs + MXS_I2C_DATA); |
415 | writel(MXS_I2C_DEBUG0_DMAREQ, | ||
416 | i2c->regs + MXS_I2C_DEBUG0_CLR); | ||
368 | } | 417 | } |
369 | msg->buf[i] = data & 0xff; | 418 | msg->buf[i] = data & 0xff; |
370 | data >>= 8; | 419 | data >>= 8; |
@@ -373,9 +422,9 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, | |||
373 | addr_data |= I2C_SMBUS_WRITE; | 422 | addr_data |= I2C_SMBUS_WRITE; |
374 | 423 | ||
375 | /* WRITE command. */ | 424 | /* WRITE command. */ |
376 | writel(MXS_I2C_CTRL0_RUN | MXS_CMD_I2C_WRITE | flags | | 425 | mxs_i2c_pio_trigger_cmd(i2c, |
377 | MXS_I2C_CTRL0_XFER_COUNT(msg->len + 1), | 426 | MXS_CMD_I2C_WRITE | flags | |
378 | i2c->regs + MXS_I2C_CTRL0); | 427 | MXS_I2C_CTRL0_XFER_COUNT(msg->len + 1)); |
379 | 428 | ||
380 | /* | 429 | /* |
381 | * The LSB of data buffer is the first byte blasted across | 430 | * The LSB of data buffer is the first byte blasted across |
@@ -391,6 +440,8 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, | |||
391 | if (ret) | 440 | if (ret) |
392 | return ret; | 441 | return ret; |
393 | writel(data, i2c->regs + MXS_I2C_DATA); | 442 | writel(data, i2c->regs + MXS_I2C_DATA); |
443 | writel(MXS_I2C_DEBUG0_DMAREQ, | ||
444 | i2c->regs + MXS_I2C_DEBUG0_CLR); | ||
394 | } | 445 | } |
395 | } | 446 | } |
396 | 447 | ||
@@ -401,13 +452,19 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, | |||
401 | if (ret) | 452 | if (ret) |
402 | return ret; | 453 | return ret; |
403 | writel(data, i2c->regs + MXS_I2C_DATA); | 454 | writel(data, i2c->regs + MXS_I2C_DATA); |
455 | writel(MXS_I2C_DEBUG0_DMAREQ, | ||
456 | i2c->regs + MXS_I2C_DEBUG0_CLR); | ||
404 | } | 457 | } |
405 | } | 458 | } |
406 | 459 | ||
407 | ret = mxs_i2c_pio_wait_cplt(i2c); | 460 | ret = mxs_i2c_pio_wait_cplt(i2c, flags & MXS_I2C_CTRL0_POST_SEND_STOP); |
408 | if (ret) | 461 | if (ret) |
409 | return ret; | 462 | return ret; |
410 | 463 | ||
464 | /* make sure we capture any occurred error into cmd_err */ | ||
465 | mxs_i2c_pio_check_error_state(i2c); | ||
466 | |||
467 | cleanup: | ||
411 | /* Clear any dangling IRQs and re-enable interrupts. */ | 468 | /* Clear any dangling IRQs and re-enable interrupts. */ |
412 | writel(MXS_I2C_IRQ_MASK, i2c->regs + MXS_I2C_CTRL1_CLR); | 469 | writel(MXS_I2C_IRQ_MASK, i2c->regs + MXS_I2C_CTRL1_CLR); |
413 | writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); | 470 | writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); |
@@ -439,12 +496,12 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, | |||
439 | * using PIO mode while longer transfers use DMA. The 8 byte border is | 496 | * using PIO mode while longer transfers use DMA. The 8 byte border is |
440 | * based on this empirical measurement and a lot of previous frobbing. | 497 | * based on this empirical measurement and a lot of previous frobbing. |
441 | */ | 498 | */ |
499 | i2c->cmd_err = 0; | ||
442 | if (msg->len < 8) { | 500 | if (msg->len < 8) { |
443 | ret = mxs_i2c_pio_setup_xfer(adap, msg, flags); | 501 | ret = mxs_i2c_pio_setup_xfer(adap, msg, flags); |
444 | if (ret) | 502 | if (ret) |
445 | mxs_i2c_reset(i2c); | 503 | mxs_i2c_reset(i2c); |
446 | } else { | 504 | } else { |
447 | i2c->cmd_err = 0; | ||
448 | INIT_COMPLETION(i2c->cmd_complete); | 505 | INIT_COMPLETION(i2c->cmd_complete); |
449 | ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); | 506 | ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); |
450 | if (ret) | 507 | if (ret) |
@@ -454,13 +511,19 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, | |||
454 | msecs_to_jiffies(1000)); | 511 | msecs_to_jiffies(1000)); |
455 | if (ret == 0) | 512 | if (ret == 0) |
456 | goto timeout; | 513 | goto timeout; |
514 | } | ||
457 | 515 | ||
458 | if (i2c->cmd_err == -ENXIO) | 516 | if (i2c->cmd_err == -ENXIO) { |
459 | mxs_i2c_reset(i2c); | 517 | /* |
460 | 518 | * If the transfer fails with a NAK from the slave the | |
461 | ret = i2c->cmd_err; | 519 | * controller halts until it gets told to return to idle state. |
520 | */ | ||
521 | writel(MXS_I2C_CTRL1_CLR_GOT_A_NAK, | ||
522 | i2c->regs + MXS_I2C_CTRL1_SET); | ||
462 | } | 523 | } |
463 | 524 | ||
525 | ret = i2c->cmd_err; | ||
526 | |||
464 | dev_dbg(i2c->dev, "Done with err=%d\n", ret); | 527 | dev_dbg(i2c->dev, "Done with err=%d\n", ret); |
465 | 528 | ||
466 | return ret; | 529 | return ret; |
@@ -686,11 +749,8 @@ static int mxs_i2c_probe(struct platform_device *pdev) | |||
686 | static int mxs_i2c_remove(struct platform_device *pdev) | 749 | static int mxs_i2c_remove(struct platform_device *pdev) |
687 | { | 750 | { |
688 | struct mxs_i2c_dev *i2c = platform_get_drvdata(pdev); | 751 | struct mxs_i2c_dev *i2c = platform_get_drvdata(pdev); |
689 | int ret; | ||
690 | 752 | ||
691 | ret = i2c_del_adapter(&i2c->adapter); | 753 | i2c_del_adapter(&i2c->adapter); |
692 | if (ret) | ||
693 | return -EBUSY; | ||
694 | 754 | ||
695 | if (i2c->dmach) | 755 | if (i2c->dmach) |
696 | dma_release_channel(i2c->dmach); | 756 | dma_release_channel(i2c->dmach); |
diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c index 29015eb9ca46..2ca268d6140b 100644 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c | |||
@@ -164,11 +164,7 @@ static int __init nforce2_s4985_init(void) | |||
164 | } | 164 | } |
165 | 165 | ||
166 | /* Unregister physical bus */ | 166 | /* Unregister physical bus */ |
167 | error = i2c_del_adapter(nforce2_smbus); | 167 | i2c_del_adapter(nforce2_smbus); |
168 | if (error) { | ||
169 | dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n"); | ||
170 | goto ERROR0; | ||
171 | } | ||
172 | 168 | ||
173 | printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4985\n"); | 169 | printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4985\n"); |
174 | /* Define the 5 virtual adapters and algorithms structures */ | 170 | /* Define the 5 virtual adapters and algorithms structures */ |
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c index 935585ef4d39..956fe320f313 100644 --- a/drivers/i2c/busses/i2c-octeon.c +++ b/drivers/i2c/busses/i2c-octeon.c | |||
@@ -183,7 +183,7 @@ static irqreturn_t octeon_i2c_isr(int irq, void *dev_id) | |||
183 | struct octeon_i2c *i2c = dev_id; | 183 | struct octeon_i2c *i2c = dev_id; |
184 | 184 | ||
185 | octeon_i2c_int_disable(i2c); | 185 | octeon_i2c_int_disable(i2c); |
186 | wake_up_interruptible(&i2c->queue); | 186 | wake_up(&i2c->queue); |
187 | 187 | ||
188 | return IRQ_HANDLED; | 188 | return IRQ_HANDLED; |
189 | } | 189 | } |
@@ -206,9 +206,9 @@ static int octeon_i2c_wait(struct octeon_i2c *i2c) | |||
206 | 206 | ||
207 | octeon_i2c_int_enable(i2c); | 207 | octeon_i2c_int_enable(i2c); |
208 | 208 | ||
209 | result = wait_event_interruptible_timeout(i2c->queue, | 209 | result = wait_event_timeout(i2c->queue, |
210 | octeon_i2c_test_iflg(i2c), | 210 | octeon_i2c_test_iflg(i2c), |
211 | i2c->adap.timeout); | 211 | i2c->adap.timeout); |
212 | 212 | ||
213 | octeon_i2c_int_disable(i2c); | 213 | octeon_i2c_int_disable(i2c); |
214 | 214 | ||
@@ -440,7 +440,7 @@ static struct i2c_adapter octeon_i2c_ops = { | |||
440 | .owner = THIS_MODULE, | 440 | .owner = THIS_MODULE, |
441 | .name = "OCTEON adapter", | 441 | .name = "OCTEON adapter", |
442 | .algo = &octeon_i2c_algo, | 442 | .algo = &octeon_i2c_algo, |
443 | .timeout = 2, | 443 | .timeout = HZ / 50, |
444 | }; | 444 | }; |
445 | 445 | ||
446 | /** | 446 | /** |
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index da54e673449d..8dc90da1e6e6 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c | |||
@@ -213,14 +213,8 @@ static const struct i2c_algorithm i2c_powermac_algorithm = { | |||
213 | static int i2c_powermac_remove(struct platform_device *dev) | 213 | static int i2c_powermac_remove(struct platform_device *dev) |
214 | { | 214 | { |
215 | struct i2c_adapter *adapter = platform_get_drvdata(dev); | 215 | struct i2c_adapter *adapter = platform_get_drvdata(dev); |
216 | int rc; | 216 | |
217 | 217 | i2c_del_adapter(adapter); | |
218 | rc = i2c_del_adapter(adapter); | ||
219 | /* We aren't that prepared to deal with this... */ | ||
220 | if (rc) | ||
221 | printk(KERN_WARNING | ||
222 | "i2c-powermac.c: Failed to remove bus %s !\n", | ||
223 | adapter->name); | ||
224 | memset(adapter, 0, sizeof(*adapter)); | 218 | memset(adapter, 0, sizeof(*adapter)); |
225 | 219 | ||
226 | return 0; | 220 | return 0; |
diff --git a/drivers/i2c/busses/i2c-puv3.c b/drivers/i2c/busses/i2c-puv3.c index 8acef657abf3..37a84c87c5fd 100644 --- a/drivers/i2c/busses/i2c-puv3.c +++ b/drivers/i2c/busses/i2c-puv3.c | |||
@@ -234,21 +234,15 @@ static int puv3_i2c_remove(struct platform_device *pdev) | |||
234 | { | 234 | { |
235 | struct i2c_adapter *adapter = platform_get_drvdata(pdev); | 235 | struct i2c_adapter *adapter = platform_get_drvdata(pdev); |
236 | struct resource *mem; | 236 | struct resource *mem; |
237 | int rc; | ||
238 | 237 | ||
239 | rc = i2c_del_adapter(adapter); | 238 | i2c_del_adapter(adapter); |
240 | if (rc) { | ||
241 | dev_err(&pdev->dev, "Adapter '%s' delete fail\n", | ||
242 | adapter->name); | ||
243 | return rc; | ||
244 | } | ||
245 | 239 | ||
246 | put_device(&pdev->dev); | 240 | put_device(&pdev->dev); |
247 | 241 | ||
248 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 242 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
249 | release_mem_region(mem->start, resource_size(mem)); | 243 | release_mem_region(mem->start, resource_size(mem)); |
250 | 244 | ||
251 | return rc; | 245 | return 0; |
252 | } | 246 | } |
253 | 247 | ||
254 | #ifdef CONFIG_PM | 248 | #ifdef CONFIG_PM |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 1e88e8d66c55..ea6d45d1dcd6 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -1053,16 +1053,13 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, | |||
1053 | struct device_node *np = pdev->dev.of_node; | 1053 | struct device_node *np = pdev->dev.of_node; |
1054 | const struct of_device_id *of_id = | 1054 | const struct of_device_id *of_id = |
1055 | of_match_device(i2c_pxa_dt_ids, &pdev->dev); | 1055 | of_match_device(i2c_pxa_dt_ids, &pdev->dev); |
1056 | int ret; | ||
1057 | 1056 | ||
1058 | if (!of_id) | 1057 | if (!of_id) |
1059 | return 1; | 1058 | return 1; |
1060 | ret = of_alias_get_id(np, "i2c"); | 1059 | |
1061 | if (ret < 0) { | 1060 | /* For device tree we always use the dynamic or alias-assigned ID */ |
1062 | dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); | 1061 | i2c->adap.nr = -1; |
1063 | return ret; | 1062 | |
1064 | } | ||
1065 | pdev->id = ret; | ||
1066 | if (of_get_property(np, "mrvl,i2c-polling", NULL)) | 1063 | if (of_get_property(np, "mrvl,i2c-polling", NULL)) |
1067 | i2c->use_pio = 1; | 1064 | i2c->use_pio = 1; |
1068 | if (of_get_property(np, "mrvl,i2c-fast-mode", NULL)) | 1065 | if (of_get_property(np, "mrvl,i2c-fast-mode", NULL)) |
@@ -1100,6 +1097,9 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
1100 | goto emalloc; | 1097 | goto emalloc; |
1101 | } | 1098 | } |
1102 | 1099 | ||
1100 | /* Default adapter num to device id; i2c_pxa_probe_dt can override. */ | ||
1101 | i2c->adap.nr = dev->id; | ||
1102 | |||
1103 | ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type); | 1103 | ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type); |
1104 | if (ret > 0) | 1104 | if (ret > 0) |
1105 | ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); | 1105 | ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); |
@@ -1124,9 +1124,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
1124 | spin_lock_init(&i2c->lock); | 1124 | spin_lock_init(&i2c->lock); |
1125 | init_waitqueue_head(&i2c->wait); | 1125 | init_waitqueue_head(&i2c->wait); |
1126 | 1126 | ||
1127 | i2c->adap.nr = dev->id; | 1127 | strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); |
1128 | snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u", | ||
1129 | i2c->adap.nr); | ||
1130 | 1128 | ||
1131 | i2c->clk = clk_get(&dev->dev, NULL); | 1129 | i2c->clk = clk_get(&dev->dev, NULL); |
1132 | if (IS_ERR(i2c->clk)) { | 1130 | if (IS_ERR(i2c->clk)) { |
@@ -1169,7 +1167,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
1169 | } else { | 1167 | } else { |
1170 | i2c->adap.algo = &i2c_pxa_algorithm; | 1168 | i2c->adap.algo = &i2c_pxa_algorithm; |
1171 | ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED, | 1169 | ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED, |
1172 | i2c->adap.name, i2c); | 1170 | dev_name(&dev->dev), i2c); |
1173 | if (ret) | 1171 | if (ret) |
1174 | goto ereqirq; | 1172 | goto ereqirq; |
1175 | } | 1173 | } |
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index f6b880ba1932..6e8ee92ab553 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c | |||
@@ -42,9 +42,46 @@ | |||
42 | 42 | ||
43 | #include <asm/irq.h> | 43 | #include <asm/irq.h> |
44 | 44 | ||
45 | #include <plat/regs-iic.h> | ||
46 | #include <linux/platform_data/i2c-s3c2410.h> | 45 | #include <linux/platform_data/i2c-s3c2410.h> |
47 | 46 | ||
47 | /* see s3c2410x user guide, v1.1, section 9 (p447) for more info */ | ||
48 | |||
49 | #define S3C2410_IICCON 0x00 | ||
50 | #define S3C2410_IICSTAT 0x04 | ||
51 | #define S3C2410_IICADD 0x08 | ||
52 | #define S3C2410_IICDS 0x0C | ||
53 | #define S3C2440_IICLC 0x10 | ||
54 | |||
55 | #define S3C2410_IICCON_ACKEN (1 << 7) | ||
56 | #define S3C2410_IICCON_TXDIV_16 (0 << 6) | ||
57 | #define S3C2410_IICCON_TXDIV_512 (1 << 6) | ||
58 | #define S3C2410_IICCON_IRQEN (1 << 5) | ||
59 | #define S3C2410_IICCON_IRQPEND (1 << 4) | ||
60 | #define S3C2410_IICCON_SCALE(x) ((x) & 0xf) | ||
61 | #define S3C2410_IICCON_SCALEMASK (0xf) | ||
62 | |||
63 | #define S3C2410_IICSTAT_MASTER_RX (2 << 6) | ||
64 | #define S3C2410_IICSTAT_MASTER_TX (3 << 6) | ||
65 | #define S3C2410_IICSTAT_SLAVE_RX (0 << 6) | ||
66 | #define S3C2410_IICSTAT_SLAVE_TX (1 << 6) | ||
67 | #define S3C2410_IICSTAT_MODEMASK (3 << 6) | ||
68 | |||
69 | #define S3C2410_IICSTAT_START (1 << 5) | ||
70 | #define S3C2410_IICSTAT_BUSBUSY (1 << 5) | ||
71 | #define S3C2410_IICSTAT_TXRXEN (1 << 4) | ||
72 | #define S3C2410_IICSTAT_ARBITR (1 << 3) | ||
73 | #define S3C2410_IICSTAT_ASSLAVE (1 << 2) | ||
74 | #define S3C2410_IICSTAT_ADDR0 (1 << 1) | ||
75 | #define S3C2410_IICSTAT_LASTBIT (1 << 0) | ||
76 | |||
77 | #define S3C2410_IICLC_SDA_DELAY0 (0 << 0) | ||
78 | #define S3C2410_IICLC_SDA_DELAY5 (1 << 0) | ||
79 | #define S3C2410_IICLC_SDA_DELAY10 (2 << 0) | ||
80 | #define S3C2410_IICLC_SDA_DELAY15 (3 << 0) | ||
81 | #define S3C2410_IICLC_SDA_DELAY_MASK (3 << 0) | ||
82 | |||
83 | #define S3C2410_IICLC_FILTER_ON (1 << 2) | ||
84 | |||
48 | /* Treat S3C2410 as baseline hardware, anything else is supported via quirks */ | 85 | /* Treat S3C2410 as baseline hardware, anything else is supported via quirks */ |
49 | #define QUIRK_S3C2440 (1 << 0) | 86 | #define QUIRK_S3C2440 (1 << 0) |
50 | #define QUIRK_HDMIPHY (1 << 1) | 87 | #define QUIRK_HDMIPHY (1 << 1) |
@@ -309,6 +346,12 @@ static inline int is_lastmsg(struct s3c24xx_i2c *i2c) | |||
309 | 346 | ||
310 | static inline int is_msglast(struct s3c24xx_i2c *i2c) | 347 | static inline int is_msglast(struct s3c24xx_i2c *i2c) |
311 | { | 348 | { |
349 | /* msg->len is always 1 for the first byte of smbus block read. | ||
350 | * Actual length will be read from slave. More bytes will be | ||
351 | * read according to the length then. */ | ||
352 | if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1) | ||
353 | return 0; | ||
354 | |||
312 | return i2c->msg_ptr == i2c->msg->len-1; | 355 | return i2c->msg_ptr == i2c->msg->len-1; |
313 | } | 356 | } |
314 | 357 | ||
@@ -448,6 +491,9 @@ static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
448 | byte = readb(i2c->regs + S3C2410_IICDS); | 491 | byte = readb(i2c->regs + S3C2410_IICDS); |
449 | i2c->msg->buf[i2c->msg_ptr++] = byte; | 492 | i2c->msg->buf[i2c->msg_ptr++] = byte; |
450 | 493 | ||
494 | /* Add actual length to read for smbus block read */ | ||
495 | if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1) | ||
496 | i2c->msg->len += byte; | ||
451 | prepare_read: | 497 | prepare_read: |
452 | if (is_msglast(i2c)) { | 498 | if (is_msglast(i2c)) { |
453 | /* last byte of buffer */ | 499 | /* last byte of buffer */ |
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index b714776b6ddd..b60ff90adc39 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/i2c-tegra.h> | ||
29 | #include <linux/of_i2c.h> | 28 | #include <linux/of_i2c.h> |
30 | #include <linux/of_device.h> | 29 | #include <linux/of_device.h> |
31 | #include <linux/module.h> | 30 | #include <linux/module.h> |
@@ -172,7 +171,7 @@ struct tegra_i2c_dev { | |||
172 | u8 *msg_buf; | 171 | u8 *msg_buf; |
173 | size_t msg_buf_remaining; | 172 | size_t msg_buf_remaining; |
174 | int msg_read; | 173 | int msg_read; |
175 | unsigned long bus_clk_rate; | 174 | u32 bus_clk_rate; |
176 | bool is_suspended; | 175 | bool is_suspended; |
177 | }; | 176 | }; |
178 | 177 | ||
@@ -694,7 +693,6 @@ static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { | |||
694 | .clk_divisor_std_fast_mode = 0x19, | 693 | .clk_divisor_std_fast_mode = 0x19, |
695 | }; | 694 | }; |
696 | 695 | ||
697 | #if defined(CONFIG_OF) | ||
698 | /* Match table for of_platform binding */ | 696 | /* Match table for of_platform binding */ |
699 | static const struct of_device_id tegra_i2c_of_match[] = { | 697 | static const struct of_device_id tegra_i2c_of_match[] = { |
700 | { .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, }, | 698 | { .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, }, |
@@ -704,16 +702,13 @@ static const struct of_device_id tegra_i2c_of_match[] = { | |||
704 | {}, | 702 | {}, |
705 | }; | 703 | }; |
706 | MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); | 704 | MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); |
707 | #endif | ||
708 | 705 | ||
709 | static int tegra_i2c_probe(struct platform_device *pdev) | 706 | static int tegra_i2c_probe(struct platform_device *pdev) |
710 | { | 707 | { |
711 | struct tegra_i2c_dev *i2c_dev; | 708 | struct tegra_i2c_dev *i2c_dev; |
712 | struct tegra_i2c_platform_data *pdata = pdev->dev.platform_data; | ||
713 | struct resource *res; | 709 | struct resource *res; |
714 | struct clk *div_clk; | 710 | struct clk *div_clk; |
715 | struct clk *fast_clk; | 711 | struct clk *fast_clk; |
716 | const unsigned int *prop; | ||
717 | void __iomem *base; | 712 | void __iomem *base; |
718 | int irq; | 713 | int irq; |
719 | int ret = 0; | 714 | int ret = 0; |
@@ -754,23 +749,16 @@ static int tegra_i2c_probe(struct platform_device *pdev) | |||
754 | i2c_dev->cont_id = pdev->id; | 749 | i2c_dev->cont_id = pdev->id; |
755 | i2c_dev->dev = &pdev->dev; | 750 | i2c_dev->dev = &pdev->dev; |
756 | 751 | ||
757 | i2c_dev->bus_clk_rate = 100000; /* default clock rate */ | 752 | ret = of_property_read_u32(i2c_dev->dev->of_node, "clock-frequency", |
758 | if (pdata) { | 753 | &i2c_dev->bus_clk_rate); |
759 | i2c_dev->bus_clk_rate = pdata->bus_clk_rate; | 754 | if (ret) |
760 | 755 | i2c_dev->bus_clk_rate = 100000; /* default clock rate */ | |
761 | } else if (i2c_dev->dev->of_node) { /* if there is a device tree node ... */ | ||
762 | prop = of_get_property(i2c_dev->dev->of_node, | ||
763 | "clock-frequency", NULL); | ||
764 | if (prop) | ||
765 | i2c_dev->bus_clk_rate = be32_to_cpup(prop); | ||
766 | } | ||
767 | 756 | ||
768 | i2c_dev->hw = &tegra20_i2c_hw; | 757 | i2c_dev->hw = &tegra20_i2c_hw; |
769 | 758 | ||
770 | if (pdev->dev.of_node) { | 759 | if (pdev->dev.of_node) { |
771 | const struct of_device_id *match; | 760 | const struct of_device_id *match; |
772 | match = of_match_device(of_match_ptr(tegra_i2c_of_match), | 761 | match = of_match_device(tegra_i2c_of_match, &pdev->dev); |
773 | &pdev->dev); | ||
774 | i2c_dev->hw = match->data; | 762 | i2c_dev->hw = match->data; |
775 | i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, | 763 | i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, |
776 | "nvidia,tegra20-i2c-dvc"); | 764 | "nvidia,tegra20-i2c-dvc"); |
@@ -876,7 +864,7 @@ static struct platform_driver tegra_i2c_driver = { | |||
876 | .driver = { | 864 | .driver = { |
877 | .name = "tegra-i2c", | 865 | .name = "tegra-i2c", |
878 | .owner = THIS_MODULE, | 866 | .owner = THIS_MODULE, |
879 | .of_match_table = of_match_ptr(tegra_i2c_of_match), | 867 | .of_match_table = tegra_i2c_of_match, |
880 | .pm = TEGRA_I2C_PM, | 868 | .pm = TEGRA_I2C_PM, |
881 | }, | 869 | }, |
882 | }; | 870 | }; |
diff --git a/drivers/i2c/busses/i2c-viperboard.c b/drivers/i2c/busses/i2c-viperboard.c index f45c32c1ace6..c68450cd8d5f 100644 --- a/drivers/i2c/busses/i2c-viperboard.c +++ b/drivers/i2c/busses/i2c-viperboard.c | |||
@@ -421,11 +421,10 @@ error: | |||
421 | static int vprbrd_i2c_remove(struct platform_device *pdev) | 421 | static int vprbrd_i2c_remove(struct platform_device *pdev) |
422 | { | 422 | { |
423 | struct vprbrd_i2c *vb_i2c = platform_get_drvdata(pdev); | 423 | struct vprbrd_i2c *vb_i2c = platform_get_drvdata(pdev); |
424 | int ret; | ||
425 | 424 | ||
426 | ret = i2c_del_adapter(&vb_i2c->i2c); | 425 | i2c_del_adapter(&vb_i2c->i2c); |
427 | 426 | ||
428 | return ret; | 427 | return 0; |
429 | } | 428 | } |
430 | 429 | ||
431 | static struct platform_driver vprbrd_i2c_driver = { | 430 | static struct platform_driver vprbrd_i2c_driver = { |
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 332c720fb3fe..3d0f0520c1b4 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c | |||
@@ -312,10 +312,8 @@ static void xiic_fill_tx_fifo(struct xiic_i2c *i2c) | |||
312 | /* last message in transfer -> STOP */ | 312 | /* last message in transfer -> STOP */ |
313 | data |= XIIC_TX_DYN_STOP_MASK; | 313 | data |= XIIC_TX_DYN_STOP_MASK; |
314 | dev_dbg(i2c->adap.dev.parent, "%s TX STOP\n", __func__); | 314 | dev_dbg(i2c->adap.dev.parent, "%s TX STOP\n", __func__); |
315 | 315 | } | |
316 | xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); | 316 | xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); |
317 | } else | ||
318 | xiic_setreg8(i2c, XIIC_DTR_REG_OFFSET, data); | ||
319 | } | 317 | } |
320 | } | 318 | } |
321 | 319 | ||
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 991d38daa87d..6b63cc7eb71e 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -27,7 +27,9 @@ | |||
27 | 27 | ||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
30 | #include <linux/delay.h> | ||
30 | #include <linux/errno.h> | 31 | #include <linux/errno.h> |
32 | #include <linux/gpio.h> | ||
31 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
32 | #include <linux/i2c.h> | 34 | #include <linux/i2c.h> |
33 | #include <linux/init.h> | 35 | #include <linux/init.h> |
@@ -47,7 +49,7 @@ | |||
47 | 49 | ||
48 | /* core_lock protects i2c_adapter_idr, and guarantees | 50 | /* core_lock protects i2c_adapter_idr, and guarantees |
49 | that device detection, deletion of detected devices, and attach_adapter | 51 | that device detection, deletion of detected devices, and attach_adapter |
50 | and detach_adapter calls are serialized */ | 52 | calls are serialized */ |
51 | static DEFINE_MUTEX(core_lock); | 53 | static DEFINE_MUTEX(core_lock); |
52 | static DEFINE_IDR(i2c_adapter_idr); | 54 | static DEFINE_IDR(i2c_adapter_idr); |
53 | 55 | ||
@@ -91,7 +93,6 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv) | |||
91 | return 0; | 93 | return 0; |
92 | } | 94 | } |
93 | 95 | ||
94 | #ifdef CONFIG_HOTPLUG | ||
95 | 96 | ||
96 | /* uevent helps with hotplug: modprobe -q $(MODALIAS) */ | 97 | /* uevent helps with hotplug: modprobe -q $(MODALIAS) */ |
97 | static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) | 98 | static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
@@ -105,9 +106,129 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
105 | return 0; | 106 | return 0; |
106 | } | 107 | } |
107 | 108 | ||
108 | #else | 109 | /* i2c bus recovery routines */ |
109 | #define i2c_device_uevent NULL | 110 | static int get_scl_gpio_value(struct i2c_adapter *adap) |
110 | #endif /* CONFIG_HOTPLUG */ | 111 | { |
112 | return gpio_get_value(adap->bus_recovery_info->scl_gpio); | ||
113 | } | ||
114 | |||
115 | static void set_scl_gpio_value(struct i2c_adapter *adap, int val) | ||
116 | { | ||
117 | gpio_set_value(adap->bus_recovery_info->scl_gpio, val); | ||
118 | } | ||
119 | |||
120 | static int get_sda_gpio_value(struct i2c_adapter *adap) | ||
121 | { | ||
122 | return gpio_get_value(adap->bus_recovery_info->sda_gpio); | ||
123 | } | ||
124 | |||
125 | static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap) | ||
126 | { | ||
127 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | ||
128 | struct device *dev = &adap->dev; | ||
129 | int ret = 0; | ||
130 | |||
131 | ret = gpio_request_one(bri->scl_gpio, GPIOF_OPEN_DRAIN | | ||
132 | GPIOF_OUT_INIT_HIGH, "i2c-scl"); | ||
133 | if (ret) { | ||
134 | dev_warn(dev, "Can't get SCL gpio: %d\n", bri->scl_gpio); | ||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | if (bri->get_sda) { | ||
139 | if (gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda")) { | ||
140 | /* work without SDA polling */ | ||
141 | dev_warn(dev, "Can't get SDA gpio: %d. Not using SDA polling\n", | ||
142 | bri->sda_gpio); | ||
143 | bri->get_sda = NULL; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | return ret; | ||
148 | } | ||
149 | |||
150 | static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap) | ||
151 | { | ||
152 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | ||
153 | |||
154 | if (bri->get_sda) | ||
155 | gpio_free(bri->sda_gpio); | ||
156 | |||
157 | gpio_free(bri->scl_gpio); | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * We are generating clock pulses. ndelay() determines durating of clk pulses. | ||
162 | * We will generate clock with rate 100 KHz and so duration of both clock levels | ||
163 | * is: delay in ns = (10^6 / 100) / 2 | ||
164 | */ | ||
165 | #define RECOVERY_NDELAY 5000 | ||
166 | #define RECOVERY_CLK_CNT 9 | ||
167 | |||
168 | static int i2c_generic_recovery(struct i2c_adapter *adap) | ||
169 | { | ||
170 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | ||
171 | int i = 0, val = 1, ret = 0; | ||
172 | |||
173 | if (bri->prepare_recovery) | ||
174 | bri->prepare_recovery(bri); | ||
175 | |||
176 | /* | ||
177 | * By this time SCL is high, as we need to give 9 falling-rising edges | ||
178 | */ | ||
179 | while (i++ < RECOVERY_CLK_CNT * 2) { | ||
180 | if (val) { | ||
181 | /* Break if SDA is high */ | ||
182 | if (bri->get_sda && bri->get_sda(adap)) | ||
183 | break; | ||
184 | /* SCL shouldn't be low here */ | ||
185 | if (!bri->get_scl(adap)) { | ||
186 | dev_err(&adap->dev, | ||
187 | "SCL is stuck low, exit recovery\n"); | ||
188 | ret = -EBUSY; | ||
189 | break; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | val = !val; | ||
194 | bri->set_scl(adap, val); | ||
195 | ndelay(RECOVERY_NDELAY); | ||
196 | } | ||
197 | |||
198 | if (bri->unprepare_recovery) | ||
199 | bri->unprepare_recovery(bri); | ||
200 | |||
201 | return ret; | ||
202 | } | ||
203 | |||
204 | int i2c_generic_scl_recovery(struct i2c_adapter *adap) | ||
205 | { | ||
206 | adap->bus_recovery_info->set_scl(adap, 1); | ||
207 | return i2c_generic_recovery(adap); | ||
208 | } | ||
209 | |||
210 | int i2c_generic_gpio_recovery(struct i2c_adapter *adap) | ||
211 | { | ||
212 | int ret; | ||
213 | |||
214 | ret = i2c_get_gpios_for_recovery(adap); | ||
215 | if (ret) | ||
216 | return ret; | ||
217 | |||
218 | ret = i2c_generic_recovery(adap); | ||
219 | i2c_put_gpios_for_recovery(adap); | ||
220 | |||
221 | return ret; | ||
222 | } | ||
223 | |||
224 | int i2c_recover_bus(struct i2c_adapter *adap) | ||
225 | { | ||
226 | if (!adap->bus_recovery_info) | ||
227 | return -EOPNOTSUPP; | ||
228 | |||
229 | dev_dbg(&adap->dev, "Trying i2c bus recovery\n"); | ||
230 | return adap->bus_recovery_info->recover_bus(adap); | ||
231 | } | ||
111 | 232 | ||
112 | static int i2c_device_probe(struct device *dev) | 233 | static int i2c_device_probe(struct device *dev) |
113 | { | 234 | { |
@@ -902,6 +1023,39 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
902 | "Failed to create compatibility class link\n"); | 1023 | "Failed to create compatibility class link\n"); |
903 | #endif | 1024 | #endif |
904 | 1025 | ||
1026 | /* bus recovery specific initialization */ | ||
1027 | if (adap->bus_recovery_info) { | ||
1028 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | ||
1029 | |||
1030 | if (!bri->recover_bus) { | ||
1031 | dev_err(&adap->dev, "No recover_bus() found, not using recovery\n"); | ||
1032 | adap->bus_recovery_info = NULL; | ||
1033 | goto exit_recovery; | ||
1034 | } | ||
1035 | |||
1036 | /* Generic GPIO recovery */ | ||
1037 | if (bri->recover_bus == i2c_generic_gpio_recovery) { | ||
1038 | if (!gpio_is_valid(bri->scl_gpio)) { | ||
1039 | dev_err(&adap->dev, "Invalid SCL gpio, not using recovery\n"); | ||
1040 | adap->bus_recovery_info = NULL; | ||
1041 | goto exit_recovery; | ||
1042 | } | ||
1043 | |||
1044 | if (gpio_is_valid(bri->sda_gpio)) | ||
1045 | bri->get_sda = get_sda_gpio_value; | ||
1046 | else | ||
1047 | bri->get_sda = NULL; | ||
1048 | |||
1049 | bri->get_scl = get_scl_gpio_value; | ||
1050 | bri->set_scl = set_scl_gpio_value; | ||
1051 | } else if (!bri->set_scl || !bri->get_scl) { | ||
1052 | /* Generic SCL recovery */ | ||
1053 | dev_err(&adap->dev, "No {get|set}_gpio() found, not using recovery\n"); | ||
1054 | adap->bus_recovery_info = NULL; | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | exit_recovery: | ||
905 | /* create pre-declared device nodes */ | 1059 | /* create pre-declared device nodes */ |
906 | if (adap->nr < __i2c_first_dynamic_bus_num) | 1060 | if (adap->nr < __i2c_first_dynamic_bus_num) |
907 | i2c_scan_static_board_info(adap); | 1061 | i2c_scan_static_board_info(adap); |
@@ -921,13 +1075,35 @@ out_list: | |||
921 | } | 1075 | } |
922 | 1076 | ||
923 | /** | 1077 | /** |
1078 | * __i2c_add_numbered_adapter - i2c_add_numbered_adapter where nr is never -1 | ||
1079 | * @adap: the adapter to register (with adap->nr initialized) | ||
1080 | * Context: can sleep | ||
1081 | * | ||
1082 | * See i2c_add_numbered_adapter() for details. | ||
1083 | */ | ||
1084 | static int __i2c_add_numbered_adapter(struct i2c_adapter *adap) | ||
1085 | { | ||
1086 | int id; | ||
1087 | |||
1088 | mutex_lock(&core_lock); | ||
1089 | id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1, | ||
1090 | GFP_KERNEL); | ||
1091 | mutex_unlock(&core_lock); | ||
1092 | if (id < 0) | ||
1093 | return id == -ENOSPC ? -EBUSY : id; | ||
1094 | |||
1095 | return i2c_register_adapter(adap); | ||
1096 | } | ||
1097 | |||
1098 | /** | ||
924 | * i2c_add_adapter - declare i2c adapter, use dynamic bus number | 1099 | * i2c_add_adapter - declare i2c adapter, use dynamic bus number |
925 | * @adapter: the adapter to add | 1100 | * @adapter: the adapter to add |
926 | * Context: can sleep | 1101 | * Context: can sleep |
927 | * | 1102 | * |
928 | * This routine is used to declare an I2C adapter when its bus number | 1103 | * This routine is used to declare an I2C adapter when its bus number |
929 | * doesn't matter. Examples: for I2C adapters dynamically added by | 1104 | * doesn't matter or when its bus number is specified by an dt alias. |
930 | * USB links or PCI plugin cards. | 1105 | * Examples of bases when the bus number doesn't matter: I2C adapters |
1106 | * dynamically added by USB links or PCI plugin cards. | ||
931 | * | 1107 | * |
932 | * When this returns zero, a new bus number was allocated and stored | 1108 | * When this returns zero, a new bus number was allocated and stored |
933 | * in adap->nr, and the specified adapter became available for clients. | 1109 | * in adap->nr, and the specified adapter became available for clients. |
@@ -935,8 +1111,17 @@ out_list: | |||
935 | */ | 1111 | */ |
936 | int i2c_add_adapter(struct i2c_adapter *adapter) | 1112 | int i2c_add_adapter(struct i2c_adapter *adapter) |
937 | { | 1113 | { |
1114 | struct device *dev = &adapter->dev; | ||
938 | int id; | 1115 | int id; |
939 | 1116 | ||
1117 | if (dev->of_node) { | ||
1118 | id = of_alias_get_id(dev->of_node, "i2c"); | ||
1119 | if (id >= 0) { | ||
1120 | adapter->nr = id; | ||
1121 | return __i2c_add_numbered_adapter(adapter); | ||
1122 | } | ||
1123 | } | ||
1124 | |||
940 | mutex_lock(&core_lock); | 1125 | mutex_lock(&core_lock); |
941 | id = idr_alloc(&i2c_adapter_idr, adapter, | 1126 | id = idr_alloc(&i2c_adapter_idr, adapter, |
942 | __i2c_first_dynamic_bus_num, 0, GFP_KERNEL); | 1127 | __i2c_first_dynamic_bus_num, 0, GFP_KERNEL); |
@@ -975,26 +1160,17 @@ EXPORT_SYMBOL(i2c_add_adapter); | |||
975 | */ | 1160 | */ |
976 | int i2c_add_numbered_adapter(struct i2c_adapter *adap) | 1161 | int i2c_add_numbered_adapter(struct i2c_adapter *adap) |
977 | { | 1162 | { |
978 | int id; | ||
979 | |||
980 | if (adap->nr == -1) /* -1 means dynamically assign bus id */ | 1163 | if (adap->nr == -1) /* -1 means dynamically assign bus id */ |
981 | return i2c_add_adapter(adap); | 1164 | return i2c_add_adapter(adap); |
982 | 1165 | ||
983 | mutex_lock(&core_lock); | 1166 | return __i2c_add_numbered_adapter(adap); |
984 | id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1, | ||
985 | GFP_KERNEL); | ||
986 | mutex_unlock(&core_lock); | ||
987 | if (id < 0) | ||
988 | return id == -ENOSPC ? -EBUSY : id; | ||
989 | return i2c_register_adapter(adap); | ||
990 | } | 1167 | } |
991 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); | 1168 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); |
992 | 1169 | ||
993 | static int i2c_do_del_adapter(struct i2c_driver *driver, | 1170 | static void i2c_do_del_adapter(struct i2c_driver *driver, |
994 | struct i2c_adapter *adapter) | 1171 | struct i2c_adapter *adapter) |
995 | { | 1172 | { |
996 | struct i2c_client *client, *_n; | 1173 | struct i2c_client *client, *_n; |
997 | int res; | ||
998 | 1174 | ||
999 | /* Remove the devices we created ourselves as the result of hardware | 1175 | /* Remove the devices we created ourselves as the result of hardware |
1000 | * probing (using a driver's detect method) */ | 1176 | * probing (using a driver's detect method) */ |
@@ -1006,16 +1182,6 @@ static int i2c_do_del_adapter(struct i2c_driver *driver, | |||
1006 | i2c_unregister_device(client); | 1182 | i2c_unregister_device(client); |
1007 | } | 1183 | } |
1008 | } | 1184 | } |
1009 | |||
1010 | if (!driver->detach_adapter) | ||
1011 | return 0; | ||
1012 | dev_warn(&adapter->dev, "%s: detach_adapter method is deprecated\n", | ||
1013 | driver->driver.name); | ||
1014 | res = driver->detach_adapter(adapter); | ||
1015 | if (res) | ||
1016 | dev_err(&adapter->dev, "detach_adapter failed (%d) " | ||
1017 | "for driver [%s]\n", res, driver->driver.name); | ||
1018 | return res; | ||
1019 | } | 1185 | } |
1020 | 1186 | ||
1021 | static int __unregister_client(struct device *dev, void *dummy) | 1187 | static int __unregister_client(struct device *dev, void *dummy) |
@@ -1036,7 +1202,8 @@ static int __unregister_dummy(struct device *dev, void *dummy) | |||
1036 | 1202 | ||
1037 | static int __process_removed_adapter(struct device_driver *d, void *data) | 1203 | static int __process_removed_adapter(struct device_driver *d, void *data) |
1038 | { | 1204 | { |
1039 | return i2c_do_del_adapter(to_i2c_driver(d), data); | 1205 | i2c_do_del_adapter(to_i2c_driver(d), data); |
1206 | return 0; | ||
1040 | } | 1207 | } |
1041 | 1208 | ||
1042 | /** | 1209 | /** |
@@ -1047,9 +1214,8 @@ static int __process_removed_adapter(struct device_driver *d, void *data) | |||
1047 | * This unregisters an I2C adapter which was previously registered | 1214 | * This unregisters an I2C adapter which was previously registered |
1048 | * by @i2c_add_adapter or @i2c_add_numbered_adapter. | 1215 | * by @i2c_add_adapter or @i2c_add_numbered_adapter. |
1049 | */ | 1216 | */ |
1050 | int i2c_del_adapter(struct i2c_adapter *adap) | 1217 | void i2c_del_adapter(struct i2c_adapter *adap) |
1051 | { | 1218 | { |
1052 | int res = 0; | ||
1053 | struct i2c_adapter *found; | 1219 | struct i2c_adapter *found; |
1054 | struct i2c_client *client, *next; | 1220 | struct i2c_client *client, *next; |
1055 | 1221 | ||
@@ -1060,16 +1226,14 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
1060 | if (found != adap) { | 1226 | if (found != adap) { |
1061 | pr_debug("i2c-core: attempting to delete unregistered " | 1227 | pr_debug("i2c-core: attempting to delete unregistered " |
1062 | "adapter [%s]\n", adap->name); | 1228 | "adapter [%s]\n", adap->name); |
1063 | return -EINVAL; | 1229 | return; |
1064 | } | 1230 | } |
1065 | 1231 | ||
1066 | /* Tell drivers about this removal */ | 1232 | /* Tell drivers about this removal */ |
1067 | mutex_lock(&core_lock); | 1233 | mutex_lock(&core_lock); |
1068 | res = bus_for_each_drv(&i2c_bus_type, NULL, adap, | 1234 | bus_for_each_drv(&i2c_bus_type, NULL, adap, |
1069 | __process_removed_adapter); | 1235 | __process_removed_adapter); |
1070 | mutex_unlock(&core_lock); | 1236 | mutex_unlock(&core_lock); |
1071 | if (res) | ||
1072 | return res; | ||
1073 | 1237 | ||
1074 | /* Remove devices instantiated from sysfs */ | 1238 | /* Remove devices instantiated from sysfs */ |
1075 | mutex_lock_nested(&adap->userspace_clients_lock, | 1239 | mutex_lock_nested(&adap->userspace_clients_lock, |
@@ -1088,8 +1252,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
1088 | * we can't remove the dummy devices during the first pass: they | 1252 | * we can't remove the dummy devices during the first pass: they |
1089 | * could have been instantiated by real devices wishing to clean | 1253 | * could have been instantiated by real devices wishing to clean |
1090 | * them up properly, so we give them a chance to do that first. */ | 1254 | * them up properly, so we give them a chance to do that first. */ |
1091 | res = device_for_each_child(&adap->dev, NULL, __unregister_client); | 1255 | device_for_each_child(&adap->dev, NULL, __unregister_client); |
1092 | res = device_for_each_child(&adap->dev, NULL, __unregister_dummy); | 1256 | device_for_each_child(&adap->dev, NULL, __unregister_dummy); |
1093 | 1257 | ||
1094 | #ifdef CONFIG_I2C_COMPAT | 1258 | #ifdef CONFIG_I2C_COMPAT |
1095 | class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, | 1259 | class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, |
@@ -1114,8 +1278,6 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
1114 | /* Clear the device structure in case this adapter is ever going to be | 1278 | /* Clear the device structure in case this adapter is ever going to be |
1115 | added again */ | 1279 | added again */ |
1116 | memset(&adap->dev, 0, sizeof(adap->dev)); | 1280 | memset(&adap->dev, 0, sizeof(adap->dev)); |
1117 | |||
1118 | return 0; | ||
1119 | } | 1281 | } |
1120 | EXPORT_SYMBOL(i2c_del_adapter); | 1282 | EXPORT_SYMBOL(i2c_del_adapter); |
1121 | 1283 | ||
@@ -1185,9 +1347,9 @@ EXPORT_SYMBOL(i2c_register_driver); | |||
1185 | 1347 | ||
1186 | static int __process_removed_driver(struct device *dev, void *data) | 1348 | static int __process_removed_driver(struct device *dev, void *data) |
1187 | { | 1349 | { |
1188 | if (dev->type != &i2c_adapter_type) | 1350 | if (dev->type == &i2c_adapter_type) |
1189 | return 0; | 1351 | i2c_do_del_adapter(data, to_i2c_adapter(dev)); |
1190 | return i2c_do_del_adapter(data, to_i2c_adapter(dev)); | 1352 | return 0; |
1191 | } | 1353 | } |
1192 | 1354 | ||
1193 | /** | 1355 | /** |
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index d94e0ce78277..7409ebb33c47 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c | |||
@@ -191,17 +191,12 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, | |||
191 | } | 191 | } |
192 | EXPORT_SYMBOL_GPL(i2c_add_mux_adapter); | 192 | EXPORT_SYMBOL_GPL(i2c_add_mux_adapter); |
193 | 193 | ||
194 | int i2c_del_mux_adapter(struct i2c_adapter *adap) | 194 | void i2c_del_mux_adapter(struct i2c_adapter *adap) |
195 | { | 195 | { |
196 | struct i2c_mux_priv *priv = adap->algo_data; | 196 | struct i2c_mux_priv *priv = adap->algo_data; |
197 | int ret; | ||
198 | 197 | ||
199 | ret = i2c_del_adapter(adap); | 198 | i2c_del_adapter(adap); |
200 | if (ret < 0) | ||
201 | return ret; | ||
202 | kfree(priv); | 199 | kfree(priv); |
203 | |||
204 | return 0; | ||
205 | } | 200 | } |
206 | EXPORT_SYMBOL_GPL(i2c_del_mux_adapter); | 201 | EXPORT_SYMBOL_GPL(i2c_del_mux_adapter); |
207 | 202 | ||
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index 0be5b83c08fa..5faf244d2476 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig | |||
@@ -5,6 +5,18 @@ | |||
5 | menu "Multiplexer I2C Chip support" | 5 | menu "Multiplexer I2C Chip support" |
6 | depends on I2C_MUX | 6 | depends on I2C_MUX |
7 | 7 | ||
8 | config I2C_ARB_GPIO_CHALLENGE | ||
9 | tristate "GPIO-based I2C arbitration" | ||
10 | depends on GENERIC_GPIO && OF | ||
11 | help | ||
12 | If you say yes to this option, support will be included for an | ||
13 | I2C multimaster arbitration scheme using GPIOs and a challenge & | ||
14 | response mechanism where masters have to claim the bus by asserting | ||
15 | a GPIO. | ||
16 | |||
17 | This driver can also be built as a module. If so, the module | ||
18 | will be called i2c-arb-gpio-challenge. | ||
19 | |||
8 | config I2C_MUX_GPIO | 20 | config I2C_MUX_GPIO |
9 | tristate "GPIO-based I2C multiplexer" | 21 | tristate "GPIO-based I2C multiplexer" |
10 | depends on GENERIC_GPIO | 22 | depends on GENERIC_GPIO |
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile index 76da8692afff..465778b5d5dc 100644 --- a/drivers/i2c/muxes/Makefile +++ b/drivers/i2c/muxes/Makefile | |||
@@ -1,6 +1,8 @@ | |||
1 | # | 1 | # |
2 | # Makefile for multiplexer I2C chip drivers. | 2 | # Makefile for multiplexer I2C chip drivers. |
3 | 3 | ||
4 | obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o | ||
5 | |||
4 | obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o | 6 | obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o |
5 | obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o | 7 | obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o |
6 | obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o | 8 | obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o |
diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c new file mode 100644 index 000000000000..210b6f7b9028 --- /dev/null +++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | * GPIO-based I2C Arbitration Using a Challenge & Response Mechanism | ||
3 | * | ||
4 | * Copyright (C) 2012 Google, Inc | ||
5 | * | ||
6 | * This software is licensed under the terms of the GNU General Public | ||
7 | * License version 2, as published by the Free Software Foundation, and | ||
8 | * may be copied, distributed, and modified under those terms. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/delay.h> | ||
18 | #include <linux/gpio.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/i2c-mux.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/of_i2c.h> | ||
25 | #include <linux/of_gpio.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/slab.h> | ||
28 | |||
29 | |||
30 | /** | ||
31 | * struct i2c_arbitrator_data - Driver data for I2C arbitrator | ||
32 | * | ||
33 | * @parent: Parent adapter | ||
34 | * @child: Child bus | ||
35 | * @our_gpio: GPIO we'll use to claim. | ||
36 | * @our_gpio_release: 0 if active high; 1 if active low; AKA if the GPIO == | ||
37 | * this then consider it released. | ||
38 | * @their_gpio: GPIO that the other side will use to claim. | ||
39 | * @their_gpio_release: 0 if active high; 1 if active low; AKA if the GPIO == | ||
40 | * this then consider it released. | ||
41 | * @slew_delay_us: microseconds to wait for a GPIO to go high. | ||
42 | * @wait_retry_us: we'll attempt another claim after this many microseconds. | ||
43 | * @wait_free_us: we'll give up after this many microseconds. | ||
44 | */ | ||
45 | |||
46 | struct i2c_arbitrator_data { | ||
47 | struct i2c_adapter *parent; | ||
48 | struct i2c_adapter *child; | ||
49 | int our_gpio; | ||
50 | int our_gpio_release; | ||
51 | int their_gpio; | ||
52 | int their_gpio_release; | ||
53 | unsigned int slew_delay_us; | ||
54 | unsigned int wait_retry_us; | ||
55 | unsigned int wait_free_us; | ||
56 | }; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * i2c_arbitrator_select - claim the I2C bus | ||
61 | * | ||
62 | * Use the GPIO-based signalling protocol; return -EBUSY if we fail. | ||
63 | */ | ||
64 | static int i2c_arbitrator_select(struct i2c_adapter *adap, void *data, u32 chan) | ||
65 | { | ||
66 | const struct i2c_arbitrator_data *arb = data; | ||
67 | unsigned long stop_retry, stop_time; | ||
68 | |||
69 | /* Start a round of trying to claim the bus */ | ||
70 | stop_time = jiffies + usecs_to_jiffies(arb->wait_free_us) + 1; | ||
71 | do { | ||
72 | /* Indicate that we want to claim the bus */ | ||
73 | gpio_set_value(arb->our_gpio, !arb->our_gpio_release); | ||
74 | udelay(arb->slew_delay_us); | ||
75 | |||
76 | /* Wait for the other master to release it */ | ||
77 | stop_retry = jiffies + usecs_to_jiffies(arb->wait_retry_us) + 1; | ||
78 | while (time_before(jiffies, stop_retry)) { | ||
79 | int gpio_val = !!gpio_get_value(arb->their_gpio); | ||
80 | |||
81 | if (gpio_val == arb->their_gpio_release) { | ||
82 | /* We got it, so return */ | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | usleep_range(50, 200); | ||
87 | } | ||
88 | |||
89 | /* It didn't release, so give up, wait, and try again */ | ||
90 | gpio_set_value(arb->our_gpio, arb->our_gpio_release); | ||
91 | |||
92 | usleep_range(arb->wait_retry_us, arb->wait_retry_us * 2); | ||
93 | } while (time_before(jiffies, stop_time)); | ||
94 | |||
95 | /* Give up, release our claim */ | ||
96 | gpio_set_value(arb->our_gpio, arb->our_gpio_release); | ||
97 | udelay(arb->slew_delay_us); | ||
98 | dev_err(&adap->dev, "Could not claim bus, timeout\n"); | ||
99 | return -EBUSY; | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * i2c_arbitrator_deselect - release the I2C bus | ||
104 | * | ||
105 | * Release the I2C bus using the GPIO-based signalling protocol. | ||
106 | */ | ||
107 | static int i2c_arbitrator_deselect(struct i2c_adapter *adap, void *data, | ||
108 | u32 chan) | ||
109 | { | ||
110 | const struct i2c_arbitrator_data *arb = data; | ||
111 | |||
112 | /* Release the bus and wait for the other master to notice */ | ||
113 | gpio_set_value(arb->our_gpio, arb->our_gpio_release); | ||
114 | udelay(arb->slew_delay_us); | ||
115 | |||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static int i2c_arbitrator_probe(struct platform_device *pdev) | ||
120 | { | ||
121 | struct device *dev = &pdev->dev; | ||
122 | struct device_node *np = dev->of_node; | ||
123 | struct device_node *parent_np; | ||
124 | struct i2c_arbitrator_data *arb; | ||
125 | enum of_gpio_flags gpio_flags; | ||
126 | unsigned long out_init; | ||
127 | int ret; | ||
128 | |||
129 | /* We only support probing from device tree; no platform_data */ | ||
130 | if (!np) { | ||
131 | dev_err(dev, "Cannot find device tree node\n"); | ||
132 | return -ENODEV; | ||
133 | } | ||
134 | if (dev->platform_data) { | ||
135 | dev_err(dev, "Platform data is not supported\n"); | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | |||
139 | arb = devm_kzalloc(dev, sizeof(*arb), GFP_KERNEL); | ||
140 | if (!arb) { | ||
141 | dev_err(dev, "Cannot allocate i2c_arbitrator_data\n"); | ||
142 | return -ENOMEM; | ||
143 | } | ||
144 | platform_set_drvdata(pdev, arb); | ||
145 | |||
146 | /* Request GPIOs */ | ||
147 | ret = of_get_named_gpio_flags(np, "our-claim-gpio", 0, &gpio_flags); | ||
148 | if (!gpio_is_valid(ret)) { | ||
149 | if (ret != -EPROBE_DEFER) | ||
150 | dev_err(dev, "Error getting our-claim-gpio\n"); | ||
151 | return ret; | ||
152 | } | ||
153 | arb->our_gpio = ret; | ||
154 | arb->our_gpio_release = !!(gpio_flags & OF_GPIO_ACTIVE_LOW); | ||
155 | out_init = (gpio_flags & OF_GPIO_ACTIVE_LOW) ? | ||
156 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
157 | ret = devm_gpio_request_one(dev, arb->our_gpio, out_init, | ||
158 | "our-claim-gpio"); | ||
159 | if (ret) { | ||
160 | if (ret != -EPROBE_DEFER) | ||
161 | dev_err(dev, "Error requesting our-claim-gpio\n"); | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | ret = of_get_named_gpio_flags(np, "their-claim-gpios", 0, &gpio_flags); | ||
166 | if (!gpio_is_valid(ret)) { | ||
167 | if (ret != -EPROBE_DEFER) | ||
168 | dev_err(dev, "Error getting their-claim-gpio\n"); | ||
169 | return ret; | ||
170 | } | ||
171 | arb->their_gpio = ret; | ||
172 | arb->their_gpio_release = !!(gpio_flags & OF_GPIO_ACTIVE_LOW); | ||
173 | ret = devm_gpio_request_one(dev, arb->their_gpio, GPIOF_IN, | ||
174 | "their-claim-gpio"); | ||
175 | if (ret) { | ||
176 | if (ret != -EPROBE_DEFER) | ||
177 | dev_err(dev, "Error requesting their-claim-gpio\n"); | ||
178 | return ret; | ||
179 | } | ||
180 | |||
181 | /* At the moment we only support a single two master (us + 1 other) */ | ||
182 | if (gpio_is_valid(of_get_named_gpio(np, "their-claim-gpios", 1))) { | ||
183 | dev_err(dev, "Only one other master is supported\n"); | ||
184 | return -EINVAL; | ||
185 | } | ||
186 | |||
187 | /* Arbitration parameters */ | ||
188 | if (of_property_read_u32(np, "slew-delay-us", &arb->slew_delay_us)) | ||
189 | arb->slew_delay_us = 10; | ||
190 | if (of_property_read_u32(np, "wait-retry-us", &arb->wait_retry_us)) | ||
191 | arb->wait_retry_us = 3000; | ||
192 | if (of_property_read_u32(np, "wait-free-us", &arb->wait_free_us)) | ||
193 | arb->wait_free_us = 50000; | ||
194 | |||
195 | /* Find our parent */ | ||
196 | parent_np = of_parse_phandle(np, "i2c-parent", 0); | ||
197 | if (!parent_np) { | ||
198 | dev_err(dev, "Cannot parse i2c-parent\n"); | ||
199 | return -EINVAL; | ||
200 | } | ||
201 | arb->parent = of_find_i2c_adapter_by_node(parent_np); | ||
202 | if (!arb->parent) { | ||
203 | dev_err(dev, "Cannot find parent bus\n"); | ||
204 | return -EINVAL; | ||
205 | } | ||
206 | |||
207 | /* Actually add the mux adapter */ | ||
208 | arb->child = i2c_add_mux_adapter(arb->parent, dev, arb, 0, 0, 0, | ||
209 | i2c_arbitrator_select, | ||
210 | i2c_arbitrator_deselect); | ||
211 | if (!arb->child) { | ||
212 | dev_err(dev, "Failed to add adapter\n"); | ||
213 | ret = -ENODEV; | ||
214 | i2c_put_adapter(arb->parent); | ||
215 | } | ||
216 | |||
217 | return ret; | ||
218 | } | ||
219 | |||
220 | static int i2c_arbitrator_remove(struct platform_device *pdev) | ||
221 | { | ||
222 | struct i2c_arbitrator_data *arb = platform_get_drvdata(pdev); | ||
223 | |||
224 | i2c_del_mux_adapter(arb->child); | ||
225 | i2c_put_adapter(arb->parent); | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | static const struct of_device_id i2c_arbitrator_of_match[] = { | ||
231 | { .compatible = "i2c-arb-gpio-challenge", }, | ||
232 | {}, | ||
233 | }; | ||
234 | MODULE_DEVICE_TABLE(of, i2c_arbitrator_of_match); | ||
235 | |||
236 | static struct platform_driver i2c_arbitrator_driver = { | ||
237 | .probe = i2c_arbitrator_probe, | ||
238 | .remove = i2c_arbitrator_remove, | ||
239 | .driver = { | ||
240 | .owner = THIS_MODULE, | ||
241 | .name = "i2c-arb-gpio-challenge", | ||
242 | .of_match_table = of_match_ptr(i2c_arbitrator_of_match), | ||
243 | }, | ||
244 | }; | ||
245 | |||
246 | module_platform_driver(i2c_arbitrator_driver); | ||
247 | |||
248 | MODULE_DESCRIPTION("GPIO-based I2C Arbitration"); | ||
249 | MODULE_AUTHOR("Doug Anderson <dianders@chromium.org>"); | ||
250 | MODULE_LICENSE("GPL v2"); | ||
251 | MODULE_ALIAS("platform:i2c-arb-gpio-challenge"); | ||
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index abc2e55aa243..5a0ce0081dce 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c | |||
@@ -201,10 +201,21 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) | |||
201 | 201 | ||
202 | for (i = 0; i < mux->data.n_gpios; i++) { | 202 | for (i = 0; i < mux->data.n_gpios; i++) { |
203 | ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); | 203 | ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); |
204 | if (ret) | 204 | if (ret) { |
205 | dev_err(&pdev->dev, "Failed to request GPIO %d\n", | ||
206 | mux->data.gpios[i]); | ||
205 | goto err_request_gpio; | 207 | goto err_request_gpio; |
206 | gpio_direction_output(gpio_base + mux->data.gpios[i], | 208 | } |
207 | initial_state & (1 << i)); | 209 | |
210 | ret = gpio_direction_output(gpio_base + mux->data.gpios[i], | ||
211 | initial_state & (1 << i)); | ||
212 | if (ret) { | ||
213 | dev_err(&pdev->dev, | ||
214 | "Failed to set direction of GPIO %d to output\n", | ||
215 | mux->data.gpios[i]); | ||
216 | i++; /* gpio_request above succeeded, so must free */ | ||
217 | goto err_request_gpio; | ||
218 | } | ||
208 | } | 219 | } |
209 | 220 | ||
210 | for (i = 0; i < mux->data.n_values; i++) { | 221 | for (i = 0; i < mux->data.n_values; i++) { |
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 8e4387235b69..a531d801dbe4 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c | |||
@@ -262,13 +262,11 @@ static int pca954x_remove(struct i2c_client *client) | |||
262 | { | 262 | { |
263 | struct pca954x *data = i2c_get_clientdata(client); | 263 | struct pca954x *data = i2c_get_clientdata(client); |
264 | const struct chip_desc *chip = &chips[data->type]; | 264 | const struct chip_desc *chip = &chips[data->type]; |
265 | int i, err; | 265 | int i; |
266 | 266 | ||
267 | for (i = 0; i < chip->nchans; ++i) | 267 | for (i = 0; i < chip->nchans; ++i) |
268 | if (data->virt_adaps[i]) { | 268 | if (data->virt_adaps[i]) { |
269 | err = i2c_del_mux_adapter(data->virt_adaps[i]); | 269 | i2c_del_mux_adapter(data->virt_adaps[i]); |
270 | if (err) | ||
271 | return err; | ||
272 | data->virt_adaps[i] = NULL; | 270 | data->virt_adaps[i] = NULL; |
273 | } | 271 | } |
274 | 272 | ||
diff --git a/drivers/media/pci/bt8xx/bttv-i2c.c b/drivers/media/pci/bt8xx/bttv-i2c.c index b7c52dc8999c..d43911deb617 100644 --- a/drivers/media/pci/bt8xx/bttv-i2c.c +++ b/drivers/media/pci/bt8xx/bttv-i2c.c | |||
@@ -397,8 +397,8 @@ int init_bttv_i2c(struct bttv *btv) | |||
397 | 397 | ||
398 | int fini_bttv_i2c(struct bttv *btv) | 398 | int fini_bttv_i2c(struct bttv *btv) |
399 | { | 399 | { |
400 | if (0 != btv->i2c_rc) | 400 | if (btv->i2c_rc == 0) |
401 | return 0; | 401 | i2c_del_adapter(&btv->c.i2c_adap); |
402 | 402 | ||
403 | return i2c_del_adapter(&btv->c.i2c_adap); | 403 | return 0; |
404 | } | 404 | } |
diff --git a/drivers/media/pci/mantis/mantis_i2c.c b/drivers/media/pci/mantis/mantis_i2c.c index 937fb9d50213..895ddba3c0fb 100644 --- a/drivers/media/pci/mantis/mantis_i2c.c +++ b/drivers/media/pci/mantis/mantis_i2c.c | |||
@@ -261,6 +261,8 @@ int mantis_i2c_exit(struct mantis_pci *mantis) | |||
261 | mmwrite((intmask & ~MANTIS_INT_I2CDONE), MANTIS_INT_MASK); | 261 | mmwrite((intmask & ~MANTIS_INT_I2CDONE), MANTIS_INT_MASK); |
262 | 262 | ||
263 | dprintk(MANTIS_DEBUG, 1, "Removing I2C adapter"); | 263 | dprintk(MANTIS_DEBUG, 1, "Removing I2C adapter"); |
264 | return i2c_del_adapter(&mantis->adapter); | 264 | i2c_del_adapter(&mantis->adapter); |
265 | |||
266 | return 0; | ||
265 | } | 267 | } |
266 | EXPORT_SYMBOL_GPL(mantis_i2c_exit); | 268 | EXPORT_SYMBOL_GPL(mantis_i2c_exit); |
diff --git a/drivers/net/ethernet/sfc/falcon.c b/drivers/net/ethernet/sfc/falcon.c index 4486102fa9b3..71998e7995d9 100644 --- a/drivers/net/ethernet/sfc/falcon.c +++ b/drivers/net/ethernet/sfc/falcon.c | |||
@@ -1528,7 +1528,7 @@ static int falcon_probe_nic(struct efx_nic *efx) | |||
1528 | return 0; | 1528 | return 0; |
1529 | 1529 | ||
1530 | fail6: | 1530 | fail6: |
1531 | BUG_ON(i2c_del_adapter(&board->i2c_adap)); | 1531 | i2c_del_adapter(&board->i2c_adap); |
1532 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); | 1532 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
1533 | fail5: | 1533 | fail5: |
1534 | efx_nic_free_buffer(efx, &efx->irq_status); | 1534 | efx_nic_free_buffer(efx, &efx->irq_status); |
@@ -1666,13 +1666,11 @@ static void falcon_remove_nic(struct efx_nic *efx) | |||
1666 | { | 1666 | { |
1667 | struct falcon_nic_data *nic_data = efx->nic_data; | 1667 | struct falcon_nic_data *nic_data = efx->nic_data; |
1668 | struct falcon_board *board = falcon_board(efx); | 1668 | struct falcon_board *board = falcon_board(efx); |
1669 | int rc; | ||
1670 | 1669 | ||
1671 | board->type->fini(efx); | 1670 | board->type->fini(efx); |
1672 | 1671 | ||
1673 | /* Remove I2C adapter and clear it in preparation for a retry */ | 1672 | /* Remove I2C adapter and clear it in preparation for a retry */ |
1674 | rc = i2c_del_adapter(&board->i2c_adap); | 1673 | i2c_del_adapter(&board->i2c_adap); |
1675 | BUG_ON(rc); | ||
1676 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); | 1674 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
1677 | 1675 | ||
1678 | efx_nic_free_buffer(efx, &efx->irq_status); | 1676 | efx_nic_free_buffer(efx, &efx->irq_status); |
diff --git a/drivers/staging/media/go7007/go7007-driver.c b/drivers/staging/media/go7007/go7007-driver.c index a5ca99d7c0b2..3640df0aa0c1 100644 --- a/drivers/staging/media/go7007/go7007-driver.c +++ b/drivers/staging/media/go7007/go7007-driver.c | |||
@@ -242,11 +242,8 @@ static void go7007_remove(struct v4l2_device *v4l2_dev) | |||
242 | if (go->hpi_ops->release) | 242 | if (go->hpi_ops->release) |
243 | go->hpi_ops->release(go); | 243 | go->hpi_ops->release(go); |
244 | if (go->i2c_adapter_online) { | 244 | if (go->i2c_adapter_online) { |
245 | if (i2c_del_adapter(&go->i2c_adapter) == 0) | 245 | i2c_del_adapter(&go->i2c_adapter); |
246 | go->i2c_adapter_online = 0; | 246 | go->i2c_adapter_online = 0; |
247 | else | ||
248 | v4l2_err(&go->v4l2_dev, | ||
249 | "error removing I2C adapter!\n"); | ||
250 | } | 247 | } |
251 | 248 | ||
252 | kfree(go->boot_fw); | 249 | kfree(go->boot_fw); |
diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h index 40cb05a97b46..b5f9a007a3ab 100644 --- a/include/linux/i2c-mux.h +++ b/include/linux/i2c-mux.h | |||
@@ -42,7 +42,7 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, | |||
42 | int (*deselect) (struct i2c_adapter *, | 42 | int (*deselect) (struct i2c_adapter *, |
43 | void *mux_dev, u32 chan_id)); | 43 | void *mux_dev, u32 chan_id)); |
44 | 44 | ||
45 | int i2c_del_mux_adapter(struct i2c_adapter *adap); | 45 | void i2c_del_mux_adapter(struct i2c_adapter *adap); |
46 | 46 | ||
47 | #endif /* __KERNEL__ */ | 47 | #endif /* __KERNEL__ */ |
48 | 48 | ||
diff --git a/include/linux/i2c-tegra.h b/include/linux/i2c-tegra.h deleted file mode 100644 index 9c85da49857a..000000000000 --- a/include/linux/i2c-tegra.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | * drivers/i2c/busses/i2c-tegra.c | ||
3 | * | ||
4 | * Copyright (C) 2010 Google, Inc. | ||
5 | * Author: Colin Cross <ccross@android.com> | ||
6 | * | ||
7 | * This software is licensed under the terms of the GNU General Public | ||
8 | * License version 2, as published by the Free Software Foundation, and | ||
9 | * may be copied, distributed, and modified under those terms. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #ifndef _LINUX_I2C_TEGRA_H | ||
19 | #define _LINUX_I2C_TEGRA_H | ||
20 | |||
21 | struct tegra_i2c_platform_data { | ||
22 | unsigned long bus_clk_rate; | ||
23 | }; | ||
24 | |||
25 | #endif /* _LINUX_I2C_TEGRA_H */ | ||
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index d0c4db7b4872..e988fa935b3c 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
@@ -125,7 +125,6 @@ extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, | |||
125 | * struct i2c_driver - represent an I2C device driver | 125 | * struct i2c_driver - represent an I2C device driver |
126 | * @class: What kind of i2c device we instantiate (for detect) | 126 | * @class: What kind of i2c device we instantiate (for detect) |
127 | * @attach_adapter: Callback for bus addition (deprecated) | 127 | * @attach_adapter: Callback for bus addition (deprecated) |
128 | * @detach_adapter: Callback for bus removal (deprecated) | ||
129 | * @probe: Callback for device binding | 128 | * @probe: Callback for device binding |
130 | * @remove: Callback for device unbinding | 129 | * @remove: Callback for device unbinding |
131 | * @shutdown: Callback for device shutdown | 130 | * @shutdown: Callback for device shutdown |
@@ -162,12 +161,10 @@ extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, | |||
162 | struct i2c_driver { | 161 | struct i2c_driver { |
163 | unsigned int class; | 162 | unsigned int class; |
164 | 163 | ||
165 | /* Notifies the driver that a new bus has appeared or is about to be | 164 | /* Notifies the driver that a new bus has appeared. You should avoid |
166 | * removed. You should avoid using this, it will be removed in a | 165 | * using this, it will be removed in a near future. |
167 | * near future. | ||
168 | */ | 166 | */ |
169 | int (*attach_adapter)(struct i2c_adapter *) __deprecated; | 167 | int (*attach_adapter)(struct i2c_adapter *) __deprecated; |
170 | int (*detach_adapter)(struct i2c_adapter *) __deprecated; | ||
171 | 168 | ||
172 | /* Standard driver model interfaces */ | 169 | /* Standard driver model interfaces */ |
173 | int (*probe)(struct i2c_client *, const struct i2c_device_id *); | 170 | int (*probe)(struct i2c_client *, const struct i2c_device_id *); |
@@ -370,6 +367,45 @@ struct i2c_algorithm { | |||
370 | u32 (*functionality) (struct i2c_adapter *); | 367 | u32 (*functionality) (struct i2c_adapter *); |
371 | }; | 368 | }; |
372 | 369 | ||
370 | /** | ||
371 | * struct i2c_bus_recovery_info - I2C bus recovery information | ||
372 | * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or | ||
373 | * i2c_generic_scl_recovery() or i2c_generic_gpio_recovery(). | ||
374 | * @get_scl: This gets current value of SCL line. Mandatory for generic SCL | ||
375 | * recovery. Used internally for generic GPIO recovery. | ||
376 | * @set_scl: This sets/clears SCL line. Mandatory for generic SCL recovery. Used | ||
377 | * internally for generic GPIO recovery. | ||
378 | * @get_sda: This gets current value of SDA line. Optional for generic SCL | ||
379 | * recovery. Used internally, if sda_gpio is a valid GPIO, for generic GPIO | ||
380 | * recovery. | ||
381 | * @prepare_recovery: This will be called before starting recovery. Platform may | ||
382 | * configure padmux here for SDA/SCL line or something else they want. | ||
383 | * @unprepare_recovery: This will be called after completing recovery. Platform | ||
384 | * may configure padmux here for SDA/SCL line or something else they want. | ||
385 | * @scl_gpio: gpio number of the SCL line. Only required for GPIO recovery. | ||
386 | * @sda_gpio: gpio number of the SDA line. Only required for GPIO recovery. | ||
387 | */ | ||
388 | struct i2c_bus_recovery_info { | ||
389 | int (*recover_bus)(struct i2c_adapter *); | ||
390 | |||
391 | int (*get_scl)(struct i2c_adapter *); | ||
392 | void (*set_scl)(struct i2c_adapter *, int val); | ||
393 | int (*get_sda)(struct i2c_adapter *); | ||
394 | |||
395 | void (*prepare_recovery)(struct i2c_bus_recovery_info *bri); | ||
396 | void (*unprepare_recovery)(struct i2c_bus_recovery_info *bri); | ||
397 | |||
398 | /* gpio recovery */ | ||
399 | int scl_gpio; | ||
400 | int sda_gpio; | ||
401 | }; | ||
402 | |||
403 | int i2c_recover_bus(struct i2c_adapter *adap); | ||
404 | |||
405 | /* Generic recovery routines */ | ||
406 | int i2c_generic_gpio_recovery(struct i2c_adapter *adap); | ||
407 | int i2c_generic_scl_recovery(struct i2c_adapter *adap); | ||
408 | |||
373 | /* | 409 | /* |
374 | * i2c_adapter is the structure used to identify a physical i2c bus along | 410 | * i2c_adapter is the structure used to identify a physical i2c bus along |
375 | * with the access algorithms necessary to access it. | 411 | * with the access algorithms necessary to access it. |
@@ -393,6 +429,8 @@ struct i2c_adapter { | |||
393 | 429 | ||
394 | struct mutex userspace_clients_lock; | 430 | struct mutex userspace_clients_lock; |
395 | struct list_head userspace_clients; | 431 | struct list_head userspace_clients; |
432 | |||
433 | struct i2c_bus_recovery_info *bus_recovery_info; | ||
396 | }; | 434 | }; |
397 | #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) | 435 | #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) |
398 | 436 | ||
@@ -450,7 +488,7 @@ void i2c_unlock_adapter(struct i2c_adapter *); | |||
450 | */ | 488 | */ |
451 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 489 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
452 | extern int i2c_add_adapter(struct i2c_adapter *); | 490 | extern int i2c_add_adapter(struct i2c_adapter *); |
453 | extern int i2c_del_adapter(struct i2c_adapter *); | 491 | extern void i2c_del_adapter(struct i2c_adapter *); |
454 | extern int i2c_add_numbered_adapter(struct i2c_adapter *); | 492 | extern int i2c_add_numbered_adapter(struct i2c_adapter *); |
455 | 493 | ||
456 | extern int i2c_register_driver(struct module *, struct i2c_driver *); | 494 | extern int i2c_register_driver(struct module *, struct i2c_driver *); |