aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/Kconfig18
-rw-r--r--drivers/i2c/Makefile5
-rw-r--r--drivers/i2c/busses/Kconfig46
-rw-r--r--drivers/i2c/busses/Makefile2
-rw-r--r--drivers/i2c/busses/i2c-at91.c6
-rw-r--r--drivers/i2c/busses/i2c-bcm2835.c2
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c2
-rw-r--r--drivers/i2c/busses/i2c-davinci.c2
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c9
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c3
-rw-r--r--drivers/i2c/busses/i2c-efm32.c8
-rw-r--r--drivers/i2c/busses/i2c-exynos5.c16
-rw-r--r--drivers/i2c/busses/i2c-gpio.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c139
-rw-r--r--drivers/i2c/busses/i2c-imx.c5
-rw-r--r--drivers/i2c/busses/i2c-mpc.c3
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c8
-rw-r--r--drivers/i2c/busses/i2c-ocores.c12
-rw-r--r--drivers/i2c/busses/i2c-omap.c2
-rw-r--r--drivers/i2c/busses/i2c-qup.c12
-rw-r--r--drivers/i2c/busses/i2c-rcar.c14
-rw-r--r--drivers/i2c/busses/i2c-rk3x.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c16
-rw-r--r--drivers/i2c/busses/i2c-s6000.c404
-rw-r--r--drivers/i2c/busses/i2c-s6000.h79
-rw-r--r--drivers/i2c/busses/i2c-sirf.c2
-rw-r--r--drivers/i2c/busses/i2c-st.c34
-rw-r--r--drivers/i2c/busses/i2c-stu300.c2
-rw-r--r--drivers/i2c/busses/i2c-taos-evm.c13
-rw-r--r--drivers/i2c/busses/i2c-tegra.c2
-rw-r--r--drivers/i2c/busses/i2c-xiic.c12
-rw-r--r--drivers/i2c/busses/scx200_i2c.c129
-rw-r--r--drivers/i2c/i2c-acpi.c362
-rw-r--r--drivers/i2c/i2c-core.c107
-rw-r--r--drivers/i2c/i2c-stub.c237
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c15
37 files changed, 810 insertions, 924 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 7b7ea320a258..3e3b680dc007 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -2,7 +2,9 @@
2# I2C subsystem configuration 2# I2C subsystem configuration
3# 3#
4 4
5menuconfig I2C 5menu "I2C support"
6
7config I2C
6 tristate "I2C support" 8 tristate "I2C support"
7 select RT_MUTEXES 9 select RT_MUTEXES
8 ---help--- 10 ---help---
@@ -21,6 +23,18 @@ menuconfig I2C
21 This I2C support can also be built as a module. If so, the module 23 This I2C support can also be built as a module. If so, the module
22 will be called i2c-core. 24 will be called i2c-core.
23 25
26config I2C_ACPI
27 bool "I2C ACPI support"
28 select I2C
29 depends on ACPI
30 default y
31 help
32 Say Y here if you want to enable ACPI I2C support. This includes support
33 for automatic enumeration of I2C slave devices and support for ACPI I2C
34 Operation Regions. Operation Regions allow firmware (BIOS) code to
35 access I2C slave devices, such as smart batteries through an I2C host
36 controller driver.
37
24if I2C 38if I2C
25 39
26config I2C_BOARDINFO 40config I2C_BOARDINFO
@@ -124,3 +138,5 @@ config I2C_DEBUG_BUS
124 on. 138 on.
125 139
126endif # I2C 140endif # I2C
141
142endmenu
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 1722f50f2473..a1f590cbb435 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -2,8 +2,11 @@
2# Makefile for the i2c core. 2# Makefile for the i2c core.
3# 3#
4 4
5i2ccore-y := i2c-core.o
6i2ccore-$(CONFIG_I2C_ACPI) += i2c-acpi.o
7
5obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o 8obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
6obj-$(CONFIG_I2C) += i2c-core.o 9obj-$(CONFIG_I2C) += i2ccore.o
7obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o 10obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o
8obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 11obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
9obj-$(CONFIG_I2C_MUX) += i2c-mux.o 12obj-$(CONFIG_I2C_MUX) += i2c-mux.o
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 9f7d5859cf65..2ac87fa3058d 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -109,6 +109,7 @@ config I2C_I801
109 Avoton (SOC) 109 Avoton (SOC)
110 Wellsburg (PCH) 110 Wellsburg (PCH)
111 Coleto Creek (PCH) 111 Coleto Creek (PCH)
112 Wildcat Point (PCH)
112 Wildcat Point-LP (PCH) 113 Wildcat Point-LP (PCH)
113 BayTrail (SOC) 114 BayTrail (SOC)
114 115
@@ -465,9 +466,9 @@ config I2C_EG20T
465config I2C_EXYNOS5 466config I2C_EXYNOS5
466 tristate "Exynos5 high-speed I2C driver" 467 tristate "Exynos5 high-speed I2C driver"
467 depends on ARCH_EXYNOS5 && OF 468 depends on ARCH_EXYNOS5 && OF
469 default y
468 help 470 help
469 Say Y here to include support for high-speed I2C controller in the 471 High-speed I2C controller on Exynos5 based Samsung SoCs.
470 Exynos5 based Samsung SoCs.
471 472
472config I2C_GPIO 473config I2C_GPIO
473 tristate "GPIO-based bitbanging I2C" 474 tristate "GPIO-based bitbanging I2C"
@@ -700,16 +701,6 @@ config I2C_S3C2410
700 Say Y here to include support for I2C controller in the 701 Say Y here to include support for I2C controller in the
701 Samsung SoCs. 702 Samsung SoCs.
702 703
703config I2C_S6000
704 tristate "S6000 I2C support"
705 depends on XTENSA_VARIANT_S6000
706 help
707 This driver supports the on chip I2C device on the
708 S6000 xtensa processor family.
709
710 To compile this driver as a module, choose M here. The module
711 will be called i2c-s6000.
712
713config I2C_SH7760 704config I2C_SH7760
714 tristate "Renesas SH7760 I2C Controller" 705 tristate "Renesas SH7760 I2C Controller"
715 depends on CPU_SUBTYPE_SH7760 706 depends on CPU_SUBTYPE_SH7760
@@ -1018,37 +1009,6 @@ config I2C_CROS_EC_TUNNEL
1018 connected there. This will work whatever the interface used to 1009 connected there. This will work whatever the interface used to
1019 talk to the EC (SPI, I2C or LPC). 1010 talk to the EC (SPI, I2C or LPC).
1020 1011
1021config SCx200_I2C
1022 tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)"
1023 depends on SCx200_GPIO
1024 select I2C_ALGOBIT
1025 help
1026 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus.
1027
1028 If you don't know what to do here, say N.
1029
1030 This support is also available as a module. If so, the module
1031 will be called scx200_i2c.
1032
1033 This driver is deprecated and will be dropped soon. Use i2c-gpio
1034 (or scx200_acb) instead.
1035
1036config SCx200_I2C_SCL
1037 int "GPIO pin used for SCL"
1038 depends on SCx200_I2C
1039 default "12"
1040 help
1041 Enter the GPIO pin number used for the SCL signal. This value can
1042 also be specified with a module parameter.
1043
1044config SCx200_I2C_SDA
1045 int "GPIO pin used for SDA"
1046 depends on SCx200_I2C
1047 default "13"
1048 help
1049 Enter the GPIO pin number used for the SSA signal. This value can
1050 also be specified with a module parameter.
1051
1052config SCx200_ACB 1012config SCx200_ACB
1053 tristate "Geode ACCESS.bus support" 1013 tristate "Geode ACCESS.bus support"
1054 depends on X86_32 && PCI 1014 depends on X86_32 && PCI
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index dd9a7f8e873f..49bf07e5ef4d 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -68,7 +68,6 @@ obj-$(CONFIG_I2C_QUP) += i2c-qup.o
68obj-$(CONFIG_I2C_RIIC) += i2c-riic.o 68obj-$(CONFIG_I2C_RIIC) += i2c-riic.o
69obj-$(CONFIG_I2C_RK3X) += i2c-rk3x.o 69obj-$(CONFIG_I2C_RK3X) += i2c-rk3x.o
70obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 70obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
71obj-$(CONFIG_I2C_S6000) += i2c-s6000.o
72obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o 71obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o
73obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o 72obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o
74obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o 73obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
@@ -101,6 +100,5 @@ obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
101obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 100obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
102obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 101obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
103obj-$(CONFIG_SCx200_ACB) += scx200_acb.o 102obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
104obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
105 103
106ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG 104ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index e95f9ba96790..79a68999a696 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -210,7 +210,7 @@ static void at91_twi_write_data_dma_callback(void *data)
210 struct at91_twi_dev *dev = (struct at91_twi_dev *)data; 210 struct at91_twi_dev *dev = (struct at91_twi_dev *)data;
211 211
212 dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg), 212 dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg),
213 dev->buf_len, DMA_MEM_TO_DEV); 213 dev->buf_len, DMA_TO_DEVICE);
214 214
215 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); 215 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
216} 216}
@@ -289,7 +289,7 @@ static void at91_twi_read_data_dma_callback(void *data)
289 struct at91_twi_dev *dev = (struct at91_twi_dev *)data; 289 struct at91_twi_dev *dev = (struct at91_twi_dev *)data;
290 290
291 dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg), 291 dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg),
292 dev->buf_len, DMA_DEV_TO_MEM); 292 dev->buf_len, DMA_FROM_DEVICE);
293 293
294 /* The last two bytes have to be read without using dma */ 294 /* The last two bytes have to be read without using dma */
295 dev->buf += dev->buf_len - 2; 295 dev->buf += dev->buf_len - 2;
@@ -768,7 +768,7 @@ static int at91_twi_probe(struct platform_device *pdev)
768 snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91"); 768 snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");
769 i2c_set_adapdata(&dev->adapter, dev); 769 i2c_set_adapdata(&dev->adapter, dev);
770 dev->adapter.owner = THIS_MODULE; 770 dev->adapter.owner = THIS_MODULE;
771 dev->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 771 dev->adapter.class = I2C_CLASS_DEPRECATED;
772 dev->adapter.algo = &at91_twi_algorithm; 772 dev->adapter.algo = &at91_twi_algorithm;
773 dev->adapter.dev.parent = dev->dev; 773 dev->adapter.dev.parent = dev->dev;
774 dev->adapter.nr = pdev->id; 774 dev->adapter.nr = pdev->id;
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
index 214ff9700efe..4b8ecd0b3661 100644
--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -277,7 +277,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
277 adap = &i2c_dev->adapter; 277 adap = &i2c_dev->adapter;
278 i2c_set_adapdata(adap, i2c_dev); 278 i2c_set_adapdata(adap, i2c_dev);
279 adap->owner = THIS_MODULE; 279 adap->owner = THIS_MODULE;
280 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 280 adap->class = I2C_CLASS_DEPRECATED;
281 strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name)); 281 strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name));
282 adap->algo = &bcm2835_i2c_algo; 282 adap->algo = &bcm2835_i2c_algo;
283 adap->dev.parent = &pdev->dev; 283 adap->dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 3e271e7558d3..067c1615e968 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -648,7 +648,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
648 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name)); 648 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
649 p_adap->algo = &bfin_twi_algorithm; 649 p_adap->algo = &bfin_twi_algorithm;
650 p_adap->algo_data = iface; 650 p_adap->algo_data = iface;
651 p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 651 p_adap->class = I2C_CLASS_DEPRECATED;
652 p_adap->dev.parent = &pdev->dev; 652 p_adap->dev.parent = &pdev->dev;
653 p_adap->timeout = 5 * HZ; 653 p_adap->timeout = 5 * HZ;
654 p_adap->retries = 3; 654 p_adap->retries = 3;
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 389bc68c55ad..4d9614719128 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -712,7 +712,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
712 adap = &dev->adapter; 712 adap = &dev->adapter;
713 i2c_set_adapdata(adap, dev); 713 i2c_set_adapdata(adap, dev);
714 adap->owner = THIS_MODULE; 714 adap->owner = THIS_MODULE;
715 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 715 adap->class = I2C_CLASS_DEPRECATED;
716 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name)); 716 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name));
717 adap->algo = &i2c_davinci_algo; 717 adap->algo = &i2c_davinci_algo;
718 adap->dev.parent = &pdev->dev; 718 adap->dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 3356f7ab9f79..d31d313ab4f7 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -188,6 +188,7 @@ static struct dw_pci_controller dw_pci_controllers[] = {
188 .scl_sda_cfg = &hsw_config, 188 .scl_sda_cfg = &hsw_config,
189 }, 189 },
190}; 190};
191
191static struct i2c_algorithm i2c_dw_algo = { 192static struct i2c_algorithm i2c_dw_algo = {
192 .master_xfer = i2c_dw_xfer, 193 .master_xfer = i2c_dw_xfer,
193 .functionality = i2c_dw_func, 194 .functionality = i2c_dw_func,
@@ -350,6 +351,14 @@ static const struct pci_device_id i2_designware_pci_ids[] = {
350 /* Haswell */ 351 /* Haswell */
351 { PCI_VDEVICE(INTEL, 0x9c61), haswell }, 352 { PCI_VDEVICE(INTEL, 0x9c61), haswell },
352 { PCI_VDEVICE(INTEL, 0x9c62), haswell }, 353 { PCI_VDEVICE(INTEL, 0x9c62), haswell },
354 /* Braswell / Cherrytrail */
355 { PCI_VDEVICE(INTEL, 0x22C1), baytrail,},
356 { PCI_VDEVICE(INTEL, 0x22C2), baytrail },
357 { PCI_VDEVICE(INTEL, 0x22C3), baytrail },
358 { PCI_VDEVICE(INTEL, 0x22C4), baytrail },
359 { PCI_VDEVICE(INTEL, 0x22C5), baytrail },
360 { PCI_VDEVICE(INTEL, 0x22C6), baytrail },
361 { PCI_VDEVICE(INTEL, 0x22C7), baytrail },
353 { 0,} 362 { 0,}
354}; 363};
355MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids); 364MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 402ec3970fed..bc8773333155 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -106,6 +106,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = {
106 { "INT3432", 0 }, 106 { "INT3432", 0 },
107 { "INT3433", 0 }, 107 { "INT3433", 0 },
108 { "80860F41", 0 }, 108 { "80860F41", 0 },
109 { "808622C1", 0 },
109 { } 110 { }
110}; 111};
111MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match); 112MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match);
@@ -202,7 +203,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
202 adap = &dev->adapter; 203 adap = &dev->adapter;
203 i2c_set_adapdata(adap, dev); 204 i2c_set_adapdata(adap, dev);
204 adap->owner = THIS_MODULE; 205 adap->owner = THIS_MODULE;
205 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 206 adap->class = I2C_CLASS_DEPRECATED;
206 strlcpy(adap->name, "Synopsys DesignWare I2C adapter", 207 strlcpy(adap->name, "Synopsys DesignWare I2C adapter",
207 sizeof(adap->name)); 208 sizeof(adap->name));
208 adap->algo = &i2c_dw_algo; 209 adap->algo = &i2c_dw_algo;
diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
index f7eccd682de9..10b8323b08d4 100644
--- a/drivers/i2c/busses/i2c-efm32.c
+++ b/drivers/i2c/busses/i2c-efm32.c
@@ -370,7 +370,13 @@ static int efm32_i2c_probe(struct platform_device *pdev)
370 return ret; 370 return ret;
371 } 371 }
372 372
373 ret = of_property_read_u32(np, "efm32,location", &location); 373
374 ret = of_property_read_u32(np, "energymicro,location", &location);
375
376 if (ret)
377 /* fall back to wrongly namespaced property */
378 ret = of_property_read_u32(np, "efm32,location", &location);
379
374 if (!ret) { 380 if (!ret) {
375 dev_dbg(&pdev->dev, "using location %u\n", location); 381 dev_dbg(&pdev->dev, "using location %u\n", location);
376 } else { 382 } else {
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 63d229202854..28073f1d6d47 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -405,7 +405,6 @@ static irqreturn_t exynos5_i2c_irq(int irqno, void *dev_id)
405 405
406 int_status = readl(i2c->regs + HSI2C_INT_STATUS); 406 int_status = readl(i2c->regs + HSI2C_INT_STATUS);
407 writel(int_status, i2c->regs + HSI2C_INT_STATUS); 407 writel(int_status, i2c->regs + HSI2C_INT_STATUS);
408 fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
409 408
410 /* handle interrupt related to the transfer status */ 409 /* handle interrupt related to the transfer status */
411 if (int_status & HSI2C_INT_I2C) { 410 if (int_status & HSI2C_INT_I2C) {
@@ -526,7 +525,7 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
526 if (i2c->msg->flags & I2C_M_RD) { 525 if (i2c->msg->flags & I2C_M_RD) {
527 i2c_ctl |= HSI2C_RXCHON; 526 i2c_ctl |= HSI2C_RXCHON;
528 527
529 i2c_auto_conf = HSI2C_READ_WRITE; 528 i2c_auto_conf |= HSI2C_READ_WRITE;
530 529
531 trig_lvl = (i2c->msg->len > i2c->variant->fifo_depth) ? 530 trig_lvl = (i2c->msg->len > i2c->variant->fifo_depth) ?
532 (i2c->variant->fifo_depth * 3 / 4) : i2c->msg->len; 531 (i2c->variant->fifo_depth * 3 / 4) : i2c->msg->len;
@@ -549,7 +548,6 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
549 writel(fifo_ctl, i2c->regs + HSI2C_FIFO_CTL); 548 writel(fifo_ctl, i2c->regs + HSI2C_FIFO_CTL);
550 writel(i2c_ctl, i2c->regs + HSI2C_CTL); 549 writel(i2c_ctl, i2c->regs + HSI2C_CTL);
551 550
552
553 /* 551 /*
554 * Enable interrupts before starting the transfer so that we don't 552 * Enable interrupts before starting the transfer so that we don't
555 * miss any INT_I2C interrupts. 553 * miss any INT_I2C interrupts.
@@ -789,8 +787,16 @@ static int exynos5_i2c_resume_noirq(struct device *dev)
789} 787}
790#endif 788#endif
791 789
792static SIMPLE_DEV_PM_OPS(exynos5_i2c_dev_pm_ops, exynos5_i2c_suspend_noirq, 790static const struct dev_pm_ops exynos5_i2c_dev_pm_ops = {
793 exynos5_i2c_resume_noirq); 791#ifdef CONFIG_PM_SLEEP
792 .suspend_noirq = exynos5_i2c_suspend_noirq,
793 .resume_noirq = exynos5_i2c_resume_noirq,
794 .freeze_noirq = exynos5_i2c_suspend_noirq,
795 .thaw_noirq = exynos5_i2c_resume_noirq,
796 .poweroff_noirq = exynos5_i2c_suspend_noirq,
797 .restore_noirq = exynos5_i2c_resume_noirq,
798#endif
799};
794 800
795static struct platform_driver exynos5_i2c_driver = { 801static struct platform_driver exynos5_i2c_driver = {
796 .probe = exynos5_i2c_probe, 802 .probe = exynos5_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 71a45b210a24..933f1e453e41 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -238,12 +238,10 @@ static int i2c_gpio_probe(struct platform_device *pdev)
238static int i2c_gpio_remove(struct platform_device *pdev) 238static int i2c_gpio_remove(struct platform_device *pdev)
239{ 239{
240 struct i2c_gpio_private_data *priv; 240 struct i2c_gpio_private_data *priv;
241 struct i2c_gpio_platform_data *pdata;
242 struct i2c_adapter *adap; 241 struct i2c_adapter *adap;
243 242
244 priv = platform_get_drvdata(pdev); 243 priv = platform_get_drvdata(pdev);
245 adap = &priv->adap; 244 adap = &priv->adap;
246 pdata = &priv->pdata;
247 245
248 i2c_del_adapter(adap); 246 i2c_del_adapter(adap);
249 247
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 6777cd6f8776..2994690b26e9 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -22,57 +22,58 @@
22*/ 22*/
23 23
24/* 24/*
25 Supports the following Intel I/O Controller Hubs (ICH): 25 * Supports the following Intel I/O Controller Hubs (ICH):
26 26 *
27 I/O Block I2C 27 * I/O Block I2C
28 region SMBus Block proc. block 28 * region SMBus Block proc. block
29 Chip name PCI ID size PEC buffer call read 29 * Chip name PCI ID size PEC buffer call read
30 ---------------------------------------------------------------------- 30 * ---------------------------------------------------------------------------
31 82801AA (ICH) 0x2413 16 no no no no 31 * 82801AA (ICH) 0x2413 16 no no no no
32 82801AB (ICH0) 0x2423 16 no no no no 32 * 82801AB (ICH0) 0x2423 16 no no no no
33 82801BA (ICH2) 0x2443 16 no no no no 33 * 82801BA (ICH2) 0x2443 16 no no no no
34 82801CA (ICH3) 0x2483 32 soft no no no 34 * 82801CA (ICH3) 0x2483 32 soft no no no
35 82801DB (ICH4) 0x24c3 32 hard yes no no 35 * 82801DB (ICH4) 0x24c3 32 hard yes no no
36 82801E (ICH5) 0x24d3 32 hard yes yes yes 36 * 82801E (ICH5) 0x24d3 32 hard yes yes yes
37 6300ESB 0x25a4 32 hard yes yes yes 37 * 6300ESB 0x25a4 32 hard yes yes yes
38 82801F (ICH6) 0x266a 32 hard yes yes yes 38 * 82801F (ICH6) 0x266a 32 hard yes yes yes
39 6310ESB/6320ESB 0x269b 32 hard yes yes yes 39 * 6310ESB/6320ESB 0x269b 32 hard yes yes yes
40 82801G (ICH7) 0x27da 32 hard yes yes yes 40 * 82801G (ICH7) 0x27da 32 hard yes yes yes
41 82801H (ICH8) 0x283e 32 hard yes yes yes 41 * 82801H (ICH8) 0x283e 32 hard yes yes yes
42 82801I (ICH9) 0x2930 32 hard yes yes yes 42 * 82801I (ICH9) 0x2930 32 hard yes yes yes
43 EP80579 (Tolapai) 0x5032 32 hard yes yes yes 43 * EP80579 (Tolapai) 0x5032 32 hard yes yes yes
44 ICH10 0x3a30 32 hard yes yes yes 44 * ICH10 0x3a30 32 hard yes yes yes
45 ICH10 0x3a60 32 hard yes yes yes 45 * ICH10 0x3a60 32 hard yes yes yes
46 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes 46 * 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
47 6 Series (PCH) 0x1c22 32 hard yes yes yes 47 * 6 Series (PCH) 0x1c22 32 hard yes yes yes
48 Patsburg (PCH) 0x1d22 32 hard yes yes yes 48 * Patsburg (PCH) 0x1d22 32 hard yes yes yes
49 Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes 49 * Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
50 Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes 50 * Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
51 Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes 51 * Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
52 DH89xxCC (PCH) 0x2330 32 hard yes yes yes 52 * DH89xxCC (PCH) 0x2330 32 hard yes yes yes
53 Panther Point (PCH) 0x1e22 32 hard yes yes yes 53 * Panther Point (PCH) 0x1e22 32 hard yes yes yes
54 Lynx Point (PCH) 0x8c22 32 hard yes yes yes 54 * Lynx Point (PCH) 0x8c22 32 hard yes yes yes
55 Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes 55 * Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
56 Avoton (SOC) 0x1f3c 32 hard yes yes yes 56 * Avoton (SOC) 0x1f3c 32 hard yes yes yes
57 Wellsburg (PCH) 0x8d22 32 hard yes yes yes 57 * Wellsburg (PCH) 0x8d22 32 hard yes yes yes
58 Wellsburg (PCH) MS 0x8d7d 32 hard yes yes yes 58 * Wellsburg (PCH) MS 0x8d7d 32 hard yes yes yes
59 Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes 59 * Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes
60 Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes 60 * Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes
61 Coleto Creek (PCH) 0x23b0 32 hard yes yes yes 61 * Coleto Creek (PCH) 0x23b0 32 hard yes yes yes
62 Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes 62 * Wildcat Point (PCH) 0x8ca2 32 hard yes yes yes
63 BayTrail (SOC) 0x0f12 32 hard yes yes yes 63 * Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
64 64 * BayTrail (SOC) 0x0f12 32 hard yes yes yes
65 Features supported by this driver: 65 *
66 Software PEC no 66 * Features supported by this driver:
67 Hardware PEC yes 67 * Software PEC no
68 Block buffer yes 68 * Hardware PEC yes
69 Block process call transaction no 69 * Block buffer yes
70 I2C block read transaction yes (doesn't use the block buffer) 70 * Block process call transaction no
71 Slave mode no 71 * I2C block read transaction yes (doesn't use the block buffer)
72 Interrupt processing yes 72 * Slave mode no
73 73 * Interrupt processing yes
74 See the file Documentation/i2c/busses/i2c-i801 for details. 74 *
75*/ 75 * See the file Documentation/i2c/busses/i2c-i801 for details.
76 */
76 77
77#include <linux/interrupt.h> 78#include <linux/interrupt.h>
78#include <linux/module.h> 79#include <linux/module.h>
@@ -162,24 +163,25 @@
162 STATUS_ERROR_FLAGS) 163 STATUS_ERROR_FLAGS)
163 164
164/* Older devices have their ID defined in <linux/pci_ids.h> */ 165/* Older devices have their ID defined in <linux/pci_ids.h> */
165#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12 166#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12
166#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22 167#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
167#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22 168#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
168/* Patsburg also has three 'Integrated Device Function' SMBus controllers */ 169/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
169#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70 170#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
170#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71 171#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
171#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72 172#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
172#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22 173#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
173#define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c 174#define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c
174#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330 175#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
175#define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS 0x23b0 176#define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS 0x23b0
176#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30 177#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
177#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22 178#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
178#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22 179#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS 0x8ca2
179#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d 180#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22
180#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e 181#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d
181#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f 182#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e
182#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22 183#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f
184#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
183#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2 185#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2
184 186
185struct i801_mux_config { 187struct i801_mux_config {
@@ -823,6 +825,7 @@ static const struct pci_device_id i801_ids[] = {
823 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) }, 825 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
824 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) }, 826 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
825 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) }, 827 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
828 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS) },
826 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) }, 829 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
827 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) }, 830 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
828 { 0, } 831 { 0, }
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index aa8bc146718b..613069bc561a 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -735,10 +735,7 @@ static int i2c_imx_probe(struct platform_device *pdev)
735 clk_disable_unprepare(i2c_imx->clk); 735 clk_disable_unprepare(i2c_imx->clk);
736 736
737 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq); 737 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq);
738 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n", 738 dev_dbg(&i2c_imx->adapter.dev, "device resources: %pR\n", res);
739 res->start, res->end);
740 dev_dbg(&i2c_imx->adapter.dev, "allocated %d bytes at 0x%x\n",
741 resource_size(res), res->start);
742 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", 739 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
743 i2c_imx->adapter.name); 740 i2c_imx->adapter.name);
744 dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); 741 dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 6a32aa095f83..0edf630b099a 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -341,8 +341,7 @@ static u32 mpc_i2c_get_sec_cfg_8xxx(void)
341 iounmap(reg); 341 iounmap(reg);
342 } 342 }
343 } 343 }
344 if (node) 344 of_node_put(node);
345 of_node_put(node);
346 345
347 return val; 346 return val;
348} 347}
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 9f4b775e2e39..6dc5ded86f62 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -863,7 +863,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
863 drv_data->adapter.dev.parent = &pd->dev; 863 drv_data->adapter.dev.parent = &pd->dev;
864 drv_data->adapter.algo = &mv64xxx_i2c_algo; 864 drv_data->adapter.algo = &mv64xxx_i2c_algo;
865 drv_data->adapter.owner = THIS_MODULE; 865 drv_data->adapter.owner = THIS_MODULE;
866 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 866 drv_data->adapter.class = I2C_CLASS_DEPRECATED;
867 drv_data->adapter.nr = pd->id; 867 drv_data->adapter.nr = pd->id;
868 drv_data->adapter.dev.of_node = pd->dev.of_node; 868 drv_data->adapter.dev.of_node = pd->dev.of_node;
869 platform_set_drvdata(pd, drv_data); 869 platform_set_drvdata(pd, drv_data);
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 0e55d85fd4ed..9ad038d223c4 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -1032,10 +1032,10 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1032 adap = &dev->adap; 1032 adap = &dev->adap;
1033 adap->dev.of_node = np; 1033 adap->dev.of_node = np;
1034 adap->dev.parent = &adev->dev; 1034 adap->dev.parent = &adev->dev;
1035 adap->owner = THIS_MODULE; 1035 adap->owner = THIS_MODULE;
1036 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 1036 adap->class = I2C_CLASS_DEPRECATED;
1037 adap->algo = &nmk_i2c_algo; 1037 adap->algo = &nmk_i2c_algo;
1038 adap->timeout = msecs_to_jiffies(dev->timeout); 1038 adap->timeout = msecs_to_jiffies(dev->timeout);
1039 snprintf(adap->name, sizeof(adap->name), 1039 snprintf(adap->name, sizeof(adap->name),
1040 "Nomadik I2C at %pR", &adev->res); 1040 "Nomadik I2C at %pR", &adev->res);
1041 1041
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 0e10cc6182f0..2a4fe0b7cfb7 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -239,15 +239,15 @@ static u32 ocores_func(struct i2c_adapter *adap)
239} 239}
240 240
241static const struct i2c_algorithm ocores_algorithm = { 241static const struct i2c_algorithm ocores_algorithm = {
242 .master_xfer = ocores_xfer, 242 .master_xfer = ocores_xfer,
243 .functionality = ocores_func, 243 .functionality = ocores_func,
244}; 244};
245 245
246static struct i2c_adapter ocores_adapter = { 246static struct i2c_adapter ocores_adapter = {
247 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
248 .name = "i2c-ocores", 248 .name = "i2c-ocores",
249 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED, 249 .class = I2C_CLASS_DEPRECATED,
250 .algo = &ocores_algorithm, 250 .algo = &ocores_algorithm,
251}; 251};
252 252
253static const struct of_device_id ocores_i2c_match[] = { 253static const struct of_device_id ocores_i2c_match[] = {
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index b182793a4051..0dffb0e62c3b 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -1236,7 +1236,7 @@ omap_i2c_probe(struct platform_device *pdev)
1236 adap = &dev->adapter; 1236 adap = &dev->adapter;
1237 i2c_set_adapdata(adap, dev); 1237 i2c_set_adapdata(adap, dev);
1238 adap->owner = THIS_MODULE; 1238 adap->owner = THIS_MODULE;
1239 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 1239 adap->class = I2C_CLASS_DEPRECATED;
1240 strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); 1240 strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name));
1241 adap->algo = &omap_i2c_algo; 1241 adap->algo = &omap_i2c_algo;
1242 adap->dev.parent = &pdev->dev; 1242 adap->dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c
index 2a5efb5b487c..3a4d64e1dfb1 100644
--- a/drivers/i2c/busses/i2c-qup.c
+++ b/drivers/i2c/busses/i2c-qup.c
@@ -633,13 +633,17 @@ static int qup_i2c_probe(struct platform_device *pdev)
633 * associated with each byte written/received 633 * associated with each byte written/received
634 */ 634 */
635 size = QUP_OUTPUT_BLOCK_SIZE(io_mode); 635 size = QUP_OUTPUT_BLOCK_SIZE(io_mode);
636 if (size >= ARRAY_SIZE(blk_sizes)) 636 if (size >= ARRAY_SIZE(blk_sizes)) {
637 return -EIO; 637 ret = -EIO;
638 goto fail;
639 }
638 qup->out_blk_sz = blk_sizes[size] / 2; 640 qup->out_blk_sz = blk_sizes[size] / 2;
639 641
640 size = QUP_INPUT_BLOCK_SIZE(io_mode); 642 size = QUP_INPUT_BLOCK_SIZE(io_mode);
641 if (size >= ARRAY_SIZE(blk_sizes)) 643 if (size >= ARRAY_SIZE(blk_sizes)) {
642 return -EIO; 644 ret = -EIO;
645 goto fail;
646 }
643 qup->in_blk_sz = blk_sizes[size] / 2; 647 qup->in_blk_sz = blk_sizes[size] / 2;
644 648
645 size = QUP_OUTPUT_FIFO_SIZE(io_mode); 649 size = QUP_OUTPUT_FIFO_SIZE(io_mode);
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 899405923678..f3c7139dfa25 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -541,13 +541,13 @@ static int rcar_i2c_probe(struct platform_device *pdev)
541 irq = platform_get_irq(pdev, 0); 541 irq = platform_get_irq(pdev, 0);
542 init_waitqueue_head(&priv->wait); 542 init_waitqueue_head(&priv->wait);
543 543
544 adap = &priv->adap; 544 adap = &priv->adap;
545 adap->nr = pdev->id; 545 adap->nr = pdev->id;
546 adap->algo = &rcar_i2c_algo; 546 adap->algo = &rcar_i2c_algo;
547 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 547 adap->class = I2C_CLASS_DEPRECATED;
548 adap->retries = 3; 548 adap->retries = 3;
549 adap->dev.parent = dev; 549 adap->dev.parent = dev;
550 adap->dev.of_node = dev->of_node; 550 adap->dev.of_node = dev->of_node;
551 i2c_set_adapdata(adap, priv); 551 i2c_set_adapdata(adap, priv);
552 strlcpy(adap->name, pdev->name, sizeof(adap->name)); 552 strlcpy(adap->name, pdev->name, sizeof(adap->name));
553 553
diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index a9791509966a..69e11853e8bf 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -399,7 +399,7 @@ static irqreturn_t rk3x_i2c_irq(int irqno, void *dev_id)
399 } 399 }
400 400
401 /* is there anything left to handle? */ 401 /* is there anything left to handle? */
402 if (unlikely(ipd == 0)) 402 if (unlikely((ipd & REG_INT_ALL) == 0))
403 goto out; 403 goto out;
404 404
405 switch (i2c->state) { 405 switch (i2c->state) {
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index e828a1dba0e5..e086fb075f2b 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -1128,11 +1128,11 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1128 s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c); 1128 s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c);
1129 1129
1130 strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name)); 1130 strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
1131 i2c->adap.owner = THIS_MODULE; 1131 i2c->adap.owner = THIS_MODULE;
1132 i2c->adap.algo = &s3c24xx_i2c_algorithm; 1132 i2c->adap.algo = &s3c24xx_i2c_algorithm;
1133 i2c->adap.retries = 2; 1133 i2c->adap.retries = 2;
1134 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 1134 i2c->adap.class = I2C_CLASS_DEPRECATED;
1135 i2c->tx_setup = 50; 1135 i2c->tx_setup = 50;
1136 1136
1137 init_waitqueue_head(&i2c->wait); 1137 init_waitqueue_head(&i2c->wait);
1138 1138
@@ -1267,7 +1267,7 @@ static int s3c24xx_i2c_suspend_noirq(struct device *dev)
1267 return 0; 1267 return 0;
1268} 1268}
1269 1269
1270static int s3c24xx_i2c_resume(struct device *dev) 1270static int s3c24xx_i2c_resume_noirq(struct device *dev)
1271{ 1271{
1272 struct platform_device *pdev = to_platform_device(dev); 1272 struct platform_device *pdev = to_platform_device(dev);
1273 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 1273 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
@@ -1285,7 +1285,11 @@ static int s3c24xx_i2c_resume(struct device *dev)
1285static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { 1285static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = {
1286#ifdef CONFIG_PM_SLEEP 1286#ifdef CONFIG_PM_SLEEP
1287 .suspend_noirq = s3c24xx_i2c_suspend_noirq, 1287 .suspend_noirq = s3c24xx_i2c_suspend_noirq,
1288 .resume = s3c24xx_i2c_resume, 1288 .resume_noirq = s3c24xx_i2c_resume_noirq,
1289 .freeze_noirq = s3c24xx_i2c_suspend_noirq,
1290 .thaw_noirq = s3c24xx_i2c_resume_noirq,
1291 .poweroff_noirq = s3c24xx_i2c_suspend_noirq,
1292 .restore_noirq = s3c24xx_i2c_resume_noirq,
1289#endif 1293#endif
1290}; 1294};
1291 1295
diff --git a/drivers/i2c/busses/i2c-s6000.c b/drivers/i2c/busses/i2c-s6000.c
deleted file mode 100644
index dd186a037684..000000000000
--- a/drivers/i2c/busses/i2c-s6000.c
+++ /dev/null
@@ -1,404 +0,0 @@
1/*
2 * drivers/i2c/busses/i2c-s6000.c
3 *
4 * Description: Driver for S6000 Family I2C Interface
5 * Copyright (c) 2008 emlix GmbH
6 * Author: Oskar Schirmer <oskar@scara.com>
7 *
8 * Partially based on i2c-bfin-twi.c driver by <sonic.zhang@analog.com>
9 * Copyright (c) 2005-2007 Analog Devices, Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <linux/clk.h>
27#include <linux/err.h>
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/i2c.h>
33#include <linux/i2c/s6000.h>
34#include <linux/timer.h>
35#include <linux/spinlock.h>
36#include <linux/completion.h>
37#include <linux/interrupt.h>
38#include <linux/platform_device.h>
39#include <linux/io.h>
40
41#include "i2c-s6000.h"
42
43#define DRV_NAME "i2c-s6000"
44
45#define POLL_TIMEOUT (2 * HZ)
46
47struct s6i2c_if {
48 u8 __iomem *reg; /* memory mapped registers */
49 int irq;
50 spinlock_t lock;
51 struct i2c_msg *msgs; /* messages currently handled */
52 int msgs_num; /* nb of msgs to do */
53 int msgs_push; /* nb of msgs read/written */
54 int msgs_done; /* nb of msgs finally handled */
55 unsigned push; /* nb of bytes read/written in msg */
56 unsigned done; /* nb of bytes finally handled */
57 int timeout_count; /* timeout retries left */
58 struct timer_list timeout_timer;
59 struct i2c_adapter adap;
60 struct completion complete;
61 struct clk *clk;
62 struct resource *res;
63};
64
65static inline u16 i2c_rd16(struct s6i2c_if *iface, unsigned n)
66{
67 return readw(iface->reg + (n));
68}
69
70static inline void i2c_wr16(struct s6i2c_if *iface, unsigned n, u16 v)
71{
72 writew(v, iface->reg + (n));
73}
74
75static inline u32 i2c_rd32(struct s6i2c_if *iface, unsigned n)
76{
77 return readl(iface->reg + (n));
78}
79
80static inline void i2c_wr32(struct s6i2c_if *iface, unsigned n, u32 v)
81{
82 writel(v, iface->reg + (n));
83}
84
85static struct s6i2c_if s6i2c_if;
86
87static void s6i2c_handle_interrupt(struct s6i2c_if *iface)
88{
89 if (i2c_rd16(iface, S6_I2C_INTRSTAT) & (1 << S6_I2C_INTR_TXABRT)) {
90 i2c_rd16(iface, S6_I2C_CLRTXABRT);
91 i2c_wr16(iface, S6_I2C_INTRMASK, 0);
92 complete(&iface->complete);
93 return;
94 }
95 if (iface->msgs_done >= iface->msgs_num) {
96 dev_err(&iface->adap.dev, "s6i2c: spurious I2C irq: %04x\n",
97 i2c_rd16(iface, S6_I2C_INTRSTAT));
98 i2c_wr16(iface, S6_I2C_INTRMASK, 0);
99 return;
100 }
101 while ((iface->msgs_push < iface->msgs_num)
102 && (i2c_rd16(iface, S6_I2C_STATUS) & (1 << S6_I2C_STATUS_TFNF))) {
103 struct i2c_msg *m = &iface->msgs[iface->msgs_push];
104 if (!(m->flags & I2C_M_RD))
105 i2c_wr16(iface, S6_I2C_DATACMD, m->buf[iface->push]);
106 else
107 i2c_wr16(iface, S6_I2C_DATACMD,
108 1 << S6_I2C_DATACMD_READ);
109 if (++iface->push >= m->len) {
110 iface->push = 0;
111 iface->msgs_push += 1;
112 }
113 }
114 do {
115 struct i2c_msg *m = &iface->msgs[iface->msgs_done];
116 if (!(m->flags & I2C_M_RD)) {
117 if (iface->msgs_done < iface->msgs_push)
118 iface->msgs_done += 1;
119 else
120 break;
121 } else if (i2c_rd16(iface, S6_I2C_STATUS)
122 & (1 << S6_I2C_STATUS_RFNE)) {
123 m->buf[iface->done] = i2c_rd16(iface, S6_I2C_DATACMD);
124 if (++iface->done >= m->len) {
125 iface->done = 0;
126 iface->msgs_done += 1;
127 }
128 } else{
129 break;
130 }
131 } while (iface->msgs_done < iface->msgs_num);
132 if (iface->msgs_done >= iface->msgs_num) {
133 i2c_wr16(iface, S6_I2C_INTRMASK, 1 << S6_I2C_INTR_TXABRT);
134 complete(&iface->complete);
135 } else if (iface->msgs_push >= iface->msgs_num) {
136 i2c_wr16(iface, S6_I2C_INTRMASK, (1 << S6_I2C_INTR_TXABRT) |
137 (1 << S6_I2C_INTR_RXFULL));
138 } else {
139 i2c_wr16(iface, S6_I2C_INTRMASK, (1 << S6_I2C_INTR_TXABRT) |
140 (1 << S6_I2C_INTR_TXEMPTY) |
141 (1 << S6_I2C_INTR_RXFULL));
142 }
143}
144
145static irqreturn_t s6i2c_interrupt_entry(int irq, void *dev_id)
146{
147 struct s6i2c_if *iface = dev_id;
148 if (!(i2c_rd16(iface, S6_I2C_STATUS) & ((1 << S6_I2C_INTR_RXUNDER)
149 | (1 << S6_I2C_INTR_RXOVER)
150 | (1 << S6_I2C_INTR_RXFULL)
151 | (1 << S6_I2C_INTR_TXOVER)
152 | (1 << S6_I2C_INTR_TXEMPTY)
153 | (1 << S6_I2C_INTR_RDREQ)
154 | (1 << S6_I2C_INTR_TXABRT)
155 | (1 << S6_I2C_INTR_RXDONE)
156 | (1 << S6_I2C_INTR_ACTIVITY)
157 | (1 << S6_I2C_INTR_STOPDET)
158 | (1 << S6_I2C_INTR_STARTDET)
159 | (1 << S6_I2C_INTR_GENCALL))))
160 return IRQ_NONE;
161
162 spin_lock(&iface->lock);
163 del_timer(&iface->timeout_timer);
164 s6i2c_handle_interrupt(iface);
165 spin_unlock(&iface->lock);
166 return IRQ_HANDLED;
167}
168
169static void s6i2c_timeout(unsigned long data)
170{
171 struct s6i2c_if *iface = (struct s6i2c_if *)data;
172 unsigned long flags;
173
174 spin_lock_irqsave(&iface->lock, flags);
175 s6i2c_handle_interrupt(iface);
176 if (--iface->timeout_count > 0) {
177 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
178 add_timer(&iface->timeout_timer);
179 } else {
180 complete(&iface->complete);
181 i2c_wr16(iface, S6_I2C_INTRMASK, 0);
182 }
183 spin_unlock_irqrestore(&iface->lock, flags);
184}
185
186static int s6i2c_master_xfer(struct i2c_adapter *adap,
187 struct i2c_msg *msgs, int num)
188{
189 struct s6i2c_if *iface = adap->algo_data;
190 int i;
191 if (num == 0)
192 return 0;
193 if (i2c_rd16(iface, S6_I2C_STATUS) & (1 << S6_I2C_STATUS_ACTIVITY))
194 yield();
195 i2c_wr16(iface, S6_I2C_INTRMASK, 0);
196 i2c_rd16(iface, S6_I2C_CLRINTR);
197 for (i = 0; i < num; i++) {
198 if (msgs[i].flags & I2C_M_TEN) {
199 dev_err(&adap->dev,
200 "s6i2c: 10 bits addr not supported\n");
201 return -EINVAL;
202 }
203 if (msgs[i].len == 0) {
204 dev_err(&adap->dev,
205 "s6i2c: zero length message not supported\n");
206 return -EINVAL;
207 }
208 if (msgs[i].addr != msgs[0].addr) {
209 dev_err(&adap->dev,
210 "s6i2c: multiple xfer cannot change target\n");
211 return -EINVAL;
212 }
213 }
214
215 iface->msgs = msgs;
216 iface->msgs_num = num;
217 iface->msgs_push = 0;
218 iface->msgs_done = 0;
219 iface->push = 0;
220 iface->done = 0;
221 iface->timeout_count = 10;
222 i2c_wr16(iface, S6_I2C_TAR, msgs[0].addr);
223 i2c_wr16(iface, S6_I2C_ENABLE, 1);
224 i2c_wr16(iface, S6_I2C_INTRMASK, (1 << S6_I2C_INTR_TXEMPTY) |
225 (1 << S6_I2C_INTR_TXABRT));
226
227 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
228 add_timer(&iface->timeout_timer);
229 wait_for_completion(&iface->complete);
230 del_timer_sync(&iface->timeout_timer);
231 while (i2c_rd32(iface, S6_I2C_TXFLR) > 0)
232 schedule();
233 while (i2c_rd16(iface, S6_I2C_STATUS) & (1 << S6_I2C_STATUS_ACTIVITY))
234 schedule();
235
236 i2c_wr16(iface, S6_I2C_INTRMASK, 0);
237 i2c_wr16(iface, S6_I2C_ENABLE, 0);
238 return iface->msgs_done;
239}
240
241static u32 s6i2c_functionality(struct i2c_adapter *adap)
242{
243 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
244}
245
246static struct i2c_algorithm s6i2c_algorithm = {
247 .master_xfer = s6i2c_master_xfer,
248 .functionality = s6i2c_functionality,
249};
250
251static u16 nanoseconds_on_clk(struct s6i2c_if *iface, u32 ns)
252{
253 u32 dividend = ((clk_get_rate(iface->clk) / 1000) * ns) / 1000000;
254 if (dividend > 0xffff)
255 return 0xffff;
256 return dividend;
257}
258
259static int s6i2c_probe(struct platform_device *dev)
260{
261 struct s6i2c_if *iface = &s6i2c_if;
262 struct i2c_adapter *p_adap;
263 const char *clock;
264 int bus_num, rc;
265 spin_lock_init(&iface->lock);
266 init_completion(&iface->complete);
267 iface->irq = platform_get_irq(dev, 0);
268 if (iface->irq < 0) {
269 rc = iface->irq;
270 goto err_out;
271 }
272 iface->res = platform_get_resource(dev, IORESOURCE_MEM, 0);
273 if (!iface->res) {
274 rc = -ENXIO;
275 goto err_out;
276 }
277 iface->res = request_mem_region(iface->res->start,
278 resource_size(iface->res),
279 dev->dev.bus_id);
280 if (!iface->res) {
281 rc = -EBUSY;
282 goto err_out;
283 }
284 iface->reg = ioremap_nocache(iface->res->start,
285 resource_size(iface->res));
286 if (!iface->reg) {
287 rc = -ENOMEM;
288 goto err_reg;
289 }
290
291 clock = 0;
292 bus_num = -1;
293 if (dev_get_platdata(&dev->dev)) {
294 struct s6_i2c_platform_data *pdata =
295 dev_get_platdata(&dev->dev);
296 bus_num = pdata->bus_num;
297 clock = pdata->clock;
298 }
299 iface->clk = clk_get(&dev->dev, clock);
300 if (IS_ERR(iface->clk)) {
301 rc = PTR_ERR(iface->clk);
302 goto err_map;
303 }
304 rc = clk_enable(iface->clk);
305 if (rc < 0)
306 goto err_clk_put;
307 init_timer(&iface->timeout_timer);
308 iface->timeout_timer.function = s6i2c_timeout;
309 iface->timeout_timer.data = (unsigned long)iface;
310
311 p_adap = &iface->adap;
312 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name));
313 p_adap->algo = &s6i2c_algorithm;
314 p_adap->algo_data = iface;
315 p_adap->nr = bus_num;
316 p_adap->class = 0;
317 p_adap->dev.parent = &dev->dev;
318 i2c_wr16(iface, S6_I2C_INTRMASK, 0);
319 rc = request_irq(iface->irq, s6i2c_interrupt_entry,
320 IRQF_SHARED, dev->name, iface);
321 if (rc) {
322 dev_err(&p_adap->dev, "s6i2c: can't get IRQ %d\n", iface->irq);
323 goto err_clk_dis;
324 }
325
326 i2c_wr16(iface, S6_I2C_ENABLE, 0);
327 udelay(1);
328 i2c_wr32(iface, S6_I2C_SRESET, 1 << S6_I2C_SRESET_IC_SRST);
329 i2c_wr16(iface, S6_I2C_CLRTXABRT, 1);
330 i2c_wr16(iface, S6_I2C_CON,
331 (1 << S6_I2C_CON_MASTER) |
332 (S6_I2C_CON_SPEED_NORMAL << S6_I2C_CON_SPEED) |
333 (0 << S6_I2C_CON_10BITSLAVE) |
334 (0 << S6_I2C_CON_10BITMASTER) |
335 (1 << S6_I2C_CON_RESTARTENA) |
336 (1 << S6_I2C_CON_SLAVEDISABLE));
337 i2c_wr16(iface, S6_I2C_SSHCNT, nanoseconds_on_clk(iface, 4000));
338 i2c_wr16(iface, S6_I2C_SSLCNT, nanoseconds_on_clk(iface, 4700));
339 i2c_wr16(iface, S6_I2C_FSHCNT, nanoseconds_on_clk(iface, 600));
340 i2c_wr16(iface, S6_I2C_FSLCNT, nanoseconds_on_clk(iface, 1300));
341 i2c_wr16(iface, S6_I2C_RXTL, 0);
342 i2c_wr16(iface, S6_I2C_TXTL, 0);
343
344 platform_set_drvdata(dev, iface);
345 rc = i2c_add_numbered_adapter(p_adap);
346 if (rc)
347 goto err_irq_free;
348 return 0;
349
350err_irq_free:
351 free_irq(iface->irq, iface);
352err_clk_dis:
353 clk_disable(iface->clk);
354err_clk_put:
355 clk_put(iface->clk);
356err_map:
357 iounmap(iface->reg);
358err_reg:
359 release_mem_region(iface->res->start,
360 resource_size(iface->res));
361err_out:
362 return rc;
363}
364
365static int s6i2c_remove(struct platform_device *pdev)
366{
367 struct s6i2c_if *iface = platform_get_drvdata(pdev);
368 i2c_wr16(iface, S6_I2C_ENABLE, 0);
369 i2c_del_adapter(&iface->adap);
370 free_irq(iface->irq, iface);
371 clk_disable(iface->clk);
372 clk_put(iface->clk);
373 iounmap(iface->reg);
374 release_mem_region(iface->res->start,
375 resource_size(iface->res));
376 return 0;
377}
378
379static struct platform_driver s6i2c_driver = {
380 .probe = s6i2c_probe,
381 .remove = s6i2c_remove,
382 .driver = {
383 .name = DRV_NAME,
384 .owner = THIS_MODULE,
385 },
386};
387
388static int __init s6i2c_init(void)
389{
390 pr_info("I2C: S6000 I2C driver\n");
391 return platform_driver_register(&s6i2c_driver);
392}
393
394static void __exit s6i2c_exit(void)
395{
396 platform_driver_unregister(&s6i2c_driver);
397}
398
399MODULE_DESCRIPTION("I2C-Bus adapter routines for S6000 I2C");
400MODULE_LICENSE("GPL");
401MODULE_ALIAS("platform:" DRV_NAME);
402
403subsys_initcall(s6i2c_init);
404module_exit(s6i2c_exit);
diff --git a/drivers/i2c/busses/i2c-s6000.h b/drivers/i2c/busses/i2c-s6000.h
deleted file mode 100644
index 4936f9f2256f..000000000000
--- a/drivers/i2c/busses/i2c-s6000.h
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 * drivers/i2c/busses/i2c-s6000.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2008 Emlix GmbH <info@emlix.com>
9 * Author: Oskar Schirmer <oskar@scara.com>
10 */
11
12#ifndef __DRIVERS_I2C_BUSSES_I2C_S6000_H
13#define __DRIVERS_I2C_BUSSES_I2C_S6000_H
14
15#define S6_I2C_CON 0x000
16#define S6_I2C_CON_MASTER 0
17#define S6_I2C_CON_SPEED 1
18#define S6_I2C_CON_SPEED_NORMAL 1
19#define S6_I2C_CON_SPEED_FAST 2
20#define S6_I2C_CON_SPEED_MASK 3
21#define S6_I2C_CON_10BITSLAVE 3
22#define S6_I2C_CON_10BITMASTER 4
23#define S6_I2C_CON_RESTARTENA 5
24#define S6_I2C_CON_SLAVEDISABLE 6
25#define S6_I2C_TAR 0x004
26#define S6_I2C_TAR_GCORSTART 10
27#define S6_I2C_TAR_SPECIAL 11
28#define S6_I2C_SAR 0x008
29#define S6_I2C_HSMADDR 0x00C
30#define S6_I2C_DATACMD 0x010
31#define S6_I2C_DATACMD_READ 8
32#define S6_I2C_SSHCNT 0x014
33#define S6_I2C_SSLCNT 0x018
34#define S6_I2C_FSHCNT 0x01C
35#define S6_I2C_FSLCNT 0x020
36#define S6_I2C_INTRSTAT 0x02C
37#define S6_I2C_INTRMASK 0x030
38#define S6_I2C_RAWINTR 0x034
39#define S6_I2C_INTR_RXUNDER 0
40#define S6_I2C_INTR_RXOVER 1
41#define S6_I2C_INTR_RXFULL 2
42#define S6_I2C_INTR_TXOVER 3
43#define S6_I2C_INTR_TXEMPTY 4
44#define S6_I2C_INTR_RDREQ 5
45#define S6_I2C_INTR_TXABRT 6
46#define S6_I2C_INTR_RXDONE 7
47#define S6_I2C_INTR_ACTIVITY 8
48#define S6_I2C_INTR_STOPDET 9
49#define S6_I2C_INTR_STARTDET 10
50#define S6_I2C_INTR_GENCALL 11
51#define S6_I2C_RXTL 0x038
52#define S6_I2C_TXTL 0x03C
53#define S6_I2C_CLRINTR 0x040
54#define S6_I2C_CLRRXUNDER 0x044
55#define S6_I2C_CLRRXOVER 0x048
56#define S6_I2C_CLRTXOVER 0x04C
57#define S6_I2C_CLRRDREQ 0x050
58#define S6_I2C_CLRTXABRT 0x054
59#define S6_I2C_CLRRXDONE 0x058
60#define S6_I2C_CLRACTIVITY 0x05C
61#define S6_I2C_CLRSTOPDET 0x060
62#define S6_I2C_CLRSTARTDET 0x064
63#define S6_I2C_CLRGENCALL 0x068
64#define S6_I2C_ENABLE 0x06C
65#define S6_I2C_STATUS 0x070
66#define S6_I2C_STATUS_ACTIVITY 0
67#define S6_I2C_STATUS_TFNF 1
68#define S6_I2C_STATUS_TFE 2
69#define S6_I2C_STATUS_RFNE 3
70#define S6_I2C_STATUS_RFF 4
71#define S6_I2C_TXFLR 0x074
72#define S6_I2C_RXFLR 0x078
73#define S6_I2C_SRESET 0x07C
74#define S6_I2C_SRESET_IC_SRST 0
75#define S6_I2C_SRESET_IC_MASTER_SRST 1
76#define S6_I2C_SRESET_IC_SLAVE_SRST 2
77#define S6_I2C_TXABRTSOURCE 0x080
78
79#endif
diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index a3216defc1d3..b1336d5f0531 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -311,7 +311,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
311 goto out; 311 goto out;
312 } 312 }
313 adap = &siic->adapter; 313 adap = &siic->adapter;
314 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 314 adap->class = I2C_CLASS_DEPRECATED;
315 315
316 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 316 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
317 siic->base = devm_ioremap_resource(&pdev->dev, mem_res); 317 siic->base = devm_ioremap_resource(&pdev->dev, mem_res);
diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
index 95b947670386..2e4eccd6599a 100644
--- a/drivers/i2c/busses/i2c-st.c
+++ b/drivers/i2c/busses/i2c-st.c
@@ -206,25 +206,31 @@ static inline void st_i2c_clr_bits(void __iomem *reg, u32 mask)
206 writel_relaxed(readl_relaxed(reg) & ~mask, reg); 206 writel_relaxed(readl_relaxed(reg) & ~mask, reg);
207} 207}
208 208
209/* From I2C Specifications v0.5 */ 209/*
210 * From I2C Specifications v0.5.
211 *
212 * All the values below have +10% margin added to be
213 * compatible with some out-of-spec devices,
214 * like HDMI link of the Toshiba 19AV600 TV.
215 */
210static struct st_i2c_timings i2c_timings[] = { 216static struct st_i2c_timings i2c_timings[] = {
211 [I2C_MODE_STANDARD] = { 217 [I2C_MODE_STANDARD] = {
212 .rate = 100000, 218 .rate = 100000,
213 .rep_start_hold = 4000, 219 .rep_start_hold = 4400,
214 .rep_start_setup = 4700, 220 .rep_start_setup = 5170,
215 .start_hold = 4000, 221 .start_hold = 4400,
216 .data_setup_time = 250, 222 .data_setup_time = 275,
217 .stop_setup_time = 4000, 223 .stop_setup_time = 4400,
218 .bus_free_time = 4700, 224 .bus_free_time = 5170,
219 }, 225 },
220 [I2C_MODE_FAST] = { 226 [I2C_MODE_FAST] = {
221 .rate = 400000, 227 .rate = 400000,
222 .rep_start_hold = 600, 228 .rep_start_hold = 660,
223 .rep_start_setup = 600, 229 .rep_start_setup = 660,
224 .start_hold = 600, 230 .start_hold = 660,
225 .data_setup_time = 100, 231 .data_setup_time = 110,
226 .stop_setup_time = 600, 232 .stop_setup_time = 660,
227 .bus_free_time = 1300, 233 .bus_free_time = 1430,
228 }, 234 },
229}; 235};
230 236
@@ -815,7 +821,7 @@ static int st_i2c_probe(struct platform_device *pdev)
815 821
816 adap = &i2c_dev->adap; 822 adap = &i2c_dev->adap;
817 i2c_set_adapdata(adap, i2c_dev); 823 i2c_set_adapdata(adap, i2c_dev);
818 snprintf(adap->name, sizeof(adap->name), "ST I2C(0x%x)", res->start); 824 snprintf(adap->name, sizeof(adap->name), "ST I2C(0x%pa)", &res->start);
819 adap->owner = THIS_MODULE; 825 adap->owner = THIS_MODULE;
820 adap->timeout = 2 * HZ; 826 adap->timeout = 2 * HZ;
821 adap->retries = 0; 827 adap->retries = 0;
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index fefb1c19ec1d..6a44f37798c8 100644
--- a/drivers/i2c/busses/i2c-stu300.c
+++ b/drivers/i2c/busses/i2c-stu300.c
@@ -909,7 +909,7 @@ static int stu300_probe(struct platform_device *pdev)
909 adap = &dev->adapter; 909 adap = &dev->adapter;
910 adap->owner = THIS_MODULE; 910 adap->owner = THIS_MODULE;
911 /* DDC class but actually often used for more generic I2C */ 911 /* DDC class but actually often used for more generic I2C */
912 adap->class = I2C_CLASS_DDC | I2C_CLASS_DEPRECATED; 912 adap->class = I2C_CLASS_DEPRECATED;
913 strlcpy(adap->name, "ST Microelectronics DDC I2C adapter", 913 strlcpy(adap->name, "ST Microelectronics DDC I2C adapter",
914 sizeof(adap->name)); 914 sizeof(adap->name));
915 adap->nr = bus_nr; 915 adap->nr = bus_nr;
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index 057602683553..10855a0b7e7f 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -311,19 +311,8 @@ static struct serio_driver taos_drv = {
311 .interrupt = taos_interrupt, 311 .interrupt = taos_interrupt,
312}; 312};
313 313
314static int __init taos_init(void) 314module_serio_driver(taos_drv);
315{
316 return serio_register_driver(&taos_drv);
317}
318
319static void __exit taos_exit(void)
320{
321 serio_unregister_driver(&taos_drv);
322}
323 315
324MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); 316MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
325MODULE_DESCRIPTION("TAOS evaluation module driver"); 317MODULE_DESCRIPTION("TAOS evaluation module driver");
326MODULE_LICENSE("GPL"); 318MODULE_LICENSE("GPL");
327
328module_init(taos_init);
329module_exit(taos_exit);
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index f1bb2fc06791..87d0371cebb7 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -792,7 +792,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
792 792
793 i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); 793 i2c_set_adapdata(&i2c_dev->adapter, i2c_dev);
794 i2c_dev->adapter.owner = THIS_MODULE; 794 i2c_dev->adapter.owner = THIS_MODULE;
795 i2c_dev->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 795 i2c_dev->adapter.class = I2C_CLASS_DEPRECATED;
796 strlcpy(i2c_dev->adapter.name, "Tegra I2C adapter", 796 strlcpy(i2c_dev->adapter.name, "Tegra I2C adapter",
797 sizeof(i2c_dev->adapter.name)); 797 sizeof(i2c_dev->adapter.name));
798 i2c_dev->adapter.algo = &tegra_i2c_algo; 798 i2c_dev->adapter.algo = &tegra_i2c_algo;
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 7731f1795869..ade9223912d3 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -677,15 +677,15 @@ static u32 xiic_func(struct i2c_adapter *adap)
677} 677}
678 678
679static const struct i2c_algorithm xiic_algorithm = { 679static const struct i2c_algorithm xiic_algorithm = {
680 .master_xfer = xiic_xfer, 680 .master_xfer = xiic_xfer,
681 .functionality = xiic_func, 681 .functionality = xiic_func,
682}; 682};
683 683
684static struct i2c_adapter xiic_adapter = { 684static struct i2c_adapter xiic_adapter = {
685 .owner = THIS_MODULE, 685 .owner = THIS_MODULE,
686 .name = DRIVER_NAME, 686 .name = DRIVER_NAME,
687 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED, 687 .class = I2C_CLASS_DEPRECATED,
688 .algo = &xiic_algorithm, 688 .algo = &xiic_algorithm,
689}; 689};
690 690
691 691
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c
deleted file mode 100644
index 8eadf0f47ad7..000000000000
--- a/drivers/i2c/busses/scx200_i2c.c
+++ /dev/null
@@ -1,129 +0,0 @@
1/* linux/drivers/i2c/busses/scx200_i2c.c
2
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4
5 National Semiconductor SCx200 I2C bus on GPIO pins
6
7 Based on i2c-velleman.c Copyright (C) 1995-96, 2000 Simon G. Vogl
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/
23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
26#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/kernel.h>
29#include <linux/i2c.h>
30#include <linux/i2c-algo-bit.h>
31#include <linux/io.h>
32
33#include <linux/scx200_gpio.h>
34
35MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
36MODULE_DESCRIPTION("NatSemi SCx200 I2C Driver");
37MODULE_LICENSE("GPL");
38
39static int scl = CONFIG_SCx200_I2C_SCL;
40static int sda = CONFIG_SCx200_I2C_SDA;
41
42module_param(scl, int, 0);
43MODULE_PARM_DESC(scl, "GPIO line for SCL");
44module_param(sda, int, 0);
45MODULE_PARM_DESC(sda, "GPIO line for SDA");
46
47static void scx200_i2c_setscl(void *data, int state)
48{
49 scx200_gpio_set(scl, state);
50}
51
52static void scx200_i2c_setsda(void *data, int state)
53{
54 scx200_gpio_set(sda, state);
55}
56
57static int scx200_i2c_getscl(void *data)
58{
59 return scx200_gpio_get(scl);
60}
61
62static int scx200_i2c_getsda(void *data)
63{
64 return scx200_gpio_get(sda);
65}
66
67/* ------------------------------------------------------------------------
68 * Encapsulate the above functions in the correct operations structure.
69 * This is only done when more than one hardware adapter is supported.
70 */
71
72static struct i2c_algo_bit_data scx200_i2c_data = {
73 .setsda = scx200_i2c_setsda,
74 .setscl = scx200_i2c_setscl,
75 .getsda = scx200_i2c_getsda,
76 .getscl = scx200_i2c_getscl,
77 .udelay = 10,
78 .timeout = HZ,
79};
80
81static struct i2c_adapter scx200_i2c_ops = {
82 .owner = THIS_MODULE,
83 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
84 .algo_data = &scx200_i2c_data,
85 .name = "NatSemi SCx200 I2C",
86};
87
88static int scx200_i2c_init(void)
89{
90 pr_debug("NatSemi SCx200 I2C Driver\n");
91
92 if (!scx200_gpio_present()) {
93 pr_err("no SCx200 gpio pins available\n");
94 return -ENODEV;
95 }
96
97 pr_debug("SCL=GPIO%02u, SDA=GPIO%02u\n", scl, sda);
98
99 if (scl == -1 || sda == -1 || scl == sda) {
100 pr_err("scl and sda must be specified\n");
101 return -EINVAL;
102 }
103
104 /* Configure GPIOs as open collector outputs */
105 scx200_gpio_configure(scl, ~2, 5);
106 scx200_gpio_configure(sda, ~2, 5);
107
108 if (i2c_bit_add_bus(&scx200_i2c_ops) < 0) {
109 pr_err("adapter %s registration failed\n", scx200_i2c_ops.name);
110 return -ENODEV;
111 }
112
113 return 0;
114}
115
116static void scx200_i2c_cleanup(void)
117{
118 i2c_del_adapter(&scx200_i2c_ops);
119}
120
121module_init(scx200_i2c_init);
122module_exit(scx200_i2c_cleanup);
123
124/*
125 Local variables:
126 compile-command: "make -k -C ../.. SUBDIRS=drivers/i2c modules"
127 c-basic-offset: 8
128 End:
129*/
diff --git a/drivers/i2c/i2c-acpi.c b/drivers/i2c/i2c-acpi.c
new file mode 100644
index 000000000000..e8b61967334b
--- /dev/null
+++ b/drivers/i2c/i2c-acpi.c
@@ -0,0 +1,362 @@
1/*
2 * I2C ACPI code
3 *
4 * Copyright (C) 2014 Intel Corp
5 *
6 * Author: Lan Tianyu <tianyu.lan@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17#define pr_fmt(fmt) "I2C/ACPI : " fmt
18
19#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/err.h>
22#include <linux/i2c.h>
23#include <linux/acpi.h>
24
25struct acpi_i2c_handler_data {
26 struct acpi_connection_info info;
27 struct i2c_adapter *adapter;
28};
29
30struct gsb_buffer {
31 u8 status;
32 u8 len;
33 union {
34 u16 wdata;
35 u8 bdata;
36 u8 data[0];
37 };
38} __packed;
39
40static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
41{
42 struct i2c_board_info *info = data;
43
44 if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
45 struct acpi_resource_i2c_serialbus *sb;
46
47 sb = &ares->data.i2c_serial_bus;
48 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
49 info->addr = sb->slave_address;
50 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
51 info->flags |= I2C_CLIENT_TEN;
52 }
53 } else if (info->irq < 0) {
54 struct resource r;
55
56 if (acpi_dev_resource_interrupt(ares, 0, &r))
57 info->irq = r.start;
58 }
59
60 /* Tell the ACPI core to skip this resource */
61 return 1;
62}
63
64static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
65 void *data, void **return_value)
66{
67 struct i2c_adapter *adapter = data;
68 struct list_head resource_list;
69 struct i2c_board_info info;
70 struct acpi_device *adev;
71 int ret;
72
73 if (acpi_bus_get_device(handle, &adev))
74 return AE_OK;
75 if (acpi_bus_get_status(adev) || !adev->status.present)
76 return AE_OK;
77
78 memset(&info, 0, sizeof(info));
79 info.acpi_node.companion = adev;
80 info.irq = -1;
81
82 INIT_LIST_HEAD(&resource_list);
83 ret = acpi_dev_get_resources(adev, &resource_list,
84 acpi_i2c_add_resource, &info);
85 acpi_dev_free_resource_list(&resource_list);
86
87 if (ret < 0 || !info.addr)
88 return AE_OK;
89
90 adev->power.flags.ignore_parent = true;
91 strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
92 if (!i2c_new_device(adapter, &info)) {
93 adev->power.flags.ignore_parent = false;
94 dev_err(&adapter->dev,
95 "failed to add I2C device %s from ACPI\n",
96 dev_name(&adev->dev));
97 }
98
99 return AE_OK;
100}
101
102/**
103 * acpi_i2c_register_devices - enumerate I2C slave devices behind adapter
104 * @adap: pointer to adapter
105 *
106 * Enumerate all I2C slave devices behind this adapter by walking the ACPI
107 * namespace. When a device is found it will be added to the Linux device
108 * model and bound to the corresponding ACPI handle.
109 */
110void acpi_i2c_register_devices(struct i2c_adapter *adap)
111{
112 acpi_handle handle;
113 acpi_status status;
114
115 if (!adap->dev.parent)
116 return;
117
118 handle = ACPI_HANDLE(adap->dev.parent);
119 if (!handle)
120 return;
121
122 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
123 acpi_i2c_add_device, NULL,
124 adap, NULL);
125 if (ACPI_FAILURE(status))
126 dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
127}
128
129static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
130 u8 cmd, u8 *data, u8 data_len)
131{
132
133 struct i2c_msg msgs[2];
134 int ret;
135 u8 *buffer;
136
137 buffer = kzalloc(data_len, GFP_KERNEL);
138 if (!buffer)
139 return AE_NO_MEMORY;
140
141 msgs[0].addr = client->addr;
142 msgs[0].flags = client->flags;
143 msgs[0].len = 1;
144 msgs[0].buf = &cmd;
145
146 msgs[1].addr = client->addr;
147 msgs[1].flags = client->flags | I2C_M_RD;
148 msgs[1].len = data_len;
149 msgs[1].buf = buffer;
150
151 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
152 if (ret < 0)
153 dev_err(&client->adapter->dev, "i2c read failed\n");
154 else
155 memcpy(data, buffer, data_len);
156
157 kfree(buffer);
158 return ret;
159}
160
161static int acpi_gsb_i2c_write_bytes(struct i2c_client *client,
162 u8 cmd, u8 *data, u8 data_len)
163{
164
165 struct i2c_msg msgs[1];
166 u8 *buffer;
167 int ret = AE_OK;
168
169 buffer = kzalloc(data_len + 1, GFP_KERNEL);
170 if (!buffer)
171 return AE_NO_MEMORY;
172
173 buffer[0] = cmd;
174 memcpy(buffer + 1, data, data_len);
175
176 msgs[0].addr = client->addr;
177 msgs[0].flags = client->flags;
178 msgs[0].len = data_len + 1;
179 msgs[0].buf = buffer;
180
181 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
182 if (ret < 0)
183 dev_err(&client->adapter->dev, "i2c write failed\n");
184
185 kfree(buffer);
186 return ret;
187}
188
189static acpi_status
190acpi_i2c_space_handler(u32 function, acpi_physical_address command,
191 u32 bits, u64 *value64,
192 void *handler_context, void *region_context)
193{
194 struct gsb_buffer *gsb = (struct gsb_buffer *)value64;
195 struct acpi_i2c_handler_data *data = handler_context;
196 struct acpi_connection_info *info = &data->info;
197 struct acpi_resource_i2c_serialbus *sb;
198 struct i2c_adapter *adapter = data->adapter;
199 struct i2c_client client;
200 struct acpi_resource *ares;
201 u32 accessor_type = function >> 16;
202 u8 action = function & ACPI_IO_MASK;
203 acpi_status ret = AE_OK;
204 int status;
205
206 ret = acpi_buffer_to_resource(info->connection, info->length, &ares);
207 if (ACPI_FAILURE(ret))
208 return ret;
209
210 if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) {
211 ret = AE_BAD_PARAMETER;
212 goto err;
213 }
214
215 sb = &ares->data.i2c_serial_bus;
216 if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) {
217 ret = AE_BAD_PARAMETER;
218 goto err;
219 }
220
221 memset(&client, 0, sizeof(client));
222 client.adapter = adapter;
223 client.addr = sb->slave_address;
224 client.flags = 0;
225
226 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
227 client.flags |= I2C_CLIENT_TEN;
228
229 switch (accessor_type) {
230 case ACPI_GSB_ACCESS_ATTRIB_SEND_RCV:
231 if (action == ACPI_READ) {
232 status = i2c_smbus_read_byte(&client);
233 if (status >= 0) {
234 gsb->bdata = status;
235 status = 0;
236 }
237 } else {
238 status = i2c_smbus_write_byte(&client, gsb->bdata);
239 }
240 break;
241
242 case ACPI_GSB_ACCESS_ATTRIB_BYTE:
243 if (action == ACPI_READ) {
244 status = i2c_smbus_read_byte_data(&client, command);
245 if (status >= 0) {
246 gsb->bdata = status;
247 status = 0;
248 }
249 } else {
250 status = i2c_smbus_write_byte_data(&client, command,
251 gsb->bdata);
252 }
253 break;
254
255 case ACPI_GSB_ACCESS_ATTRIB_WORD:
256 if (action == ACPI_READ) {
257 status = i2c_smbus_read_word_data(&client, command);
258 if (status >= 0) {
259 gsb->wdata = status;
260 status = 0;
261 }
262 } else {
263 status = i2c_smbus_write_word_data(&client, command,
264 gsb->wdata);
265 }
266 break;
267
268 case ACPI_GSB_ACCESS_ATTRIB_BLOCK:
269 if (action == ACPI_READ) {
270 status = i2c_smbus_read_block_data(&client, command,
271 gsb->data);
272 if (status >= 0) {
273 gsb->len = status;
274 status = 0;
275 }
276 } else {
277 status = i2c_smbus_write_block_data(&client, command,
278 gsb->len, gsb->data);
279 }
280 break;
281
282 case ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE:
283 if (action == ACPI_READ) {
284 status = acpi_gsb_i2c_read_bytes(&client, command,
285 gsb->data, info->access_length);
286 if (status > 0)
287 status = 0;
288 } else {
289 status = acpi_gsb_i2c_write_bytes(&client, command,
290 gsb->data, info->access_length);
291 }
292 break;
293
294 default:
295 pr_info("protocol(0x%02x) is not supported.\n", accessor_type);
296 ret = AE_BAD_PARAMETER;
297 goto err;
298 }
299
300 gsb->status = status;
301
302 err:
303 ACPI_FREE(ares);
304 return ret;
305}
306
307
308int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
309{
310 acpi_handle handle = ACPI_HANDLE(adapter->dev.parent);
311 struct acpi_i2c_handler_data *data;
312 acpi_status status;
313
314 if (!handle)
315 return -ENODEV;
316
317 data = kzalloc(sizeof(struct acpi_i2c_handler_data),
318 GFP_KERNEL);
319 if (!data)
320 return -ENOMEM;
321
322 data->adapter = adapter;
323 status = acpi_bus_attach_private_data(handle, (void *)data);
324 if (ACPI_FAILURE(status)) {
325 kfree(data);
326 return -ENOMEM;
327 }
328
329 status = acpi_install_address_space_handler(handle,
330 ACPI_ADR_SPACE_GSBUS,
331 &acpi_i2c_space_handler,
332 NULL,
333 data);
334 if (ACPI_FAILURE(status)) {
335 dev_err(&adapter->dev, "Error installing i2c space handler\n");
336 acpi_bus_detach_private_data(handle);
337 kfree(data);
338 return -ENOMEM;
339 }
340
341 return 0;
342}
343
344void acpi_i2c_remove_space_handler(struct i2c_adapter *adapter)
345{
346 acpi_handle handle = ACPI_HANDLE(adapter->dev.parent);
347 struct acpi_i2c_handler_data *data;
348 acpi_status status;
349
350 if (!handle)
351 return;
352
353 acpi_remove_address_space_handler(handle,
354 ACPI_ADR_SPACE_GSBUS,
355 &acpi_i2c_space_handler);
356
357 status = acpi_bus_get_private_data(handle, (void **)&data);
358 if (ACPI_SUCCESS(status))
359 kfree(data);
360
361 acpi_bus_detach_private_data(handle);
362}
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 66aa83b99383..632057a44615 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1097,101 +1097,6 @@ EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
1097static void of_i2c_register_devices(struct i2c_adapter *adap) { } 1097static void of_i2c_register_devices(struct i2c_adapter *adap) { }
1098#endif /* CONFIG_OF */ 1098#endif /* CONFIG_OF */
1099 1099
1100/* ACPI support code */
1101
1102#if IS_ENABLED(CONFIG_ACPI)
1103static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
1104{
1105 struct i2c_board_info *info = data;
1106
1107 if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
1108 struct acpi_resource_i2c_serialbus *sb;
1109
1110 sb = &ares->data.i2c_serial_bus;
1111 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
1112 info->addr = sb->slave_address;
1113 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
1114 info->flags |= I2C_CLIENT_TEN;
1115 }
1116 } else if (info->irq < 0) {
1117 struct resource r;
1118
1119 if (acpi_dev_resource_interrupt(ares, 0, &r))
1120 info->irq = r.start;
1121 }
1122
1123 /* Tell the ACPI core to skip this resource */
1124 return 1;
1125}
1126
1127static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
1128 void *data, void **return_value)
1129{
1130 struct i2c_adapter *adapter = data;
1131 struct list_head resource_list;
1132 struct i2c_board_info info;
1133 struct acpi_device *adev;
1134 int ret;
1135
1136 if (acpi_bus_get_device(handle, &adev))
1137 return AE_OK;
1138 if (acpi_bus_get_status(adev) || !adev->status.present)
1139 return AE_OK;
1140
1141 memset(&info, 0, sizeof(info));
1142 info.acpi_node.companion = adev;
1143 info.irq = -1;
1144
1145 INIT_LIST_HEAD(&resource_list);
1146 ret = acpi_dev_get_resources(adev, &resource_list,
1147 acpi_i2c_add_resource, &info);
1148 acpi_dev_free_resource_list(&resource_list);
1149
1150 if (ret < 0 || !info.addr)
1151 return AE_OK;
1152
1153 adev->power.flags.ignore_parent = true;
1154 strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
1155 if (!i2c_new_device(adapter, &info)) {
1156 adev->power.flags.ignore_parent = false;
1157 dev_err(&adapter->dev,
1158 "failed to add I2C device %s from ACPI\n",
1159 dev_name(&adev->dev));
1160 }
1161
1162 return AE_OK;
1163}
1164
1165/**
1166 * acpi_i2c_register_devices - enumerate I2C slave devices behind adapter
1167 * @adap: pointer to adapter
1168 *
1169 * Enumerate all I2C slave devices behind this adapter by walking the ACPI
1170 * namespace. When a device is found it will be added to the Linux device
1171 * model and bound to the corresponding ACPI handle.
1172 */
1173static void acpi_i2c_register_devices(struct i2c_adapter *adap)
1174{
1175 acpi_handle handle;
1176 acpi_status status;
1177
1178 if (!adap->dev.parent)
1179 return;
1180
1181 handle = ACPI_HANDLE(adap->dev.parent);
1182 if (!handle)
1183 return;
1184
1185 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
1186 acpi_i2c_add_device, NULL,
1187 adap, NULL);
1188 if (ACPI_FAILURE(status))
1189 dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
1190}
1191#else
1192static inline void acpi_i2c_register_devices(struct i2c_adapter *adap) {}
1193#endif /* CONFIG_ACPI */
1194
1195static int i2c_do_add_adapter(struct i2c_driver *driver, 1100static int i2c_do_add_adapter(struct i2c_driver *driver,
1196 struct i2c_adapter *adap) 1101 struct i2c_adapter *adap)
1197{ 1102{
@@ -1298,6 +1203,7 @@ exit_recovery:
1298 /* create pre-declared device nodes */ 1203 /* create pre-declared device nodes */
1299 of_i2c_register_devices(adap); 1204 of_i2c_register_devices(adap);
1300 acpi_i2c_register_devices(adap); 1205 acpi_i2c_register_devices(adap);
1206 acpi_i2c_install_space_handler(adap);
1301 1207
1302 if (adap->nr < __i2c_first_dynamic_bus_num) 1208 if (adap->nr < __i2c_first_dynamic_bus_num)
1303 i2c_scan_static_board_info(adap); 1209 i2c_scan_static_board_info(adap);
@@ -1471,6 +1377,7 @@ void i2c_del_adapter(struct i2c_adapter *adap)
1471 return; 1377 return;
1472 } 1378 }
1473 1379
1380 acpi_i2c_remove_space_handler(adap);
1474 /* Tell drivers about this removal */ 1381 /* Tell drivers about this removal */
1475 mutex_lock(&core_lock); 1382 mutex_lock(&core_lock);
1476 bus_for_each_drv(&i2c_bus_type, NULL, adap, 1383 bus_for_each_drv(&i2c_bus_type, NULL, adap,
@@ -2013,6 +1920,16 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
2013 if (!driver->detect || !address_list) 1920 if (!driver->detect || !address_list)
2014 return 0; 1921 return 0;
2015 1922
1923 /* Warn that the adapter lost class based instantiation */
1924 if (adapter->class == I2C_CLASS_DEPRECATED) {
1925 dev_dbg(&adapter->dev,
1926 "This adapter dropped support for I2C classes and "
1927 "won't auto-detect %s devices anymore. If you need it, check "
1928 "'Documentation/i2c/instantiating-devices' for alternatives.\n",
1929 driver->driver.name);
1930 return 0;
1931 }
1932
2016 /* Stop here if the classes do not match */ 1933 /* Stop here if the classes do not match */
2017 if (!(adapter->class & driver->class)) 1934 if (!(adapter->class & driver->class))
2018 return 0; 1935 return 0;
diff --git a/drivers/i2c/i2c-stub.c b/drivers/i2c/i2c-stub.c
index 77e4849d2f2a..d241aa295d96 100644
--- a/drivers/i2c/i2c-stub.c
+++ b/drivers/i2c/i2c-stub.c
@@ -2,7 +2,7 @@
2 i2c-stub.c - I2C/SMBus chip emulator 2 i2c-stub.c - I2C/SMBus chip emulator
3 3
4 Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com> 4 Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
5 Copyright (C) 2007, 2012 Jean Delvare <jdelvare@suse.de> 5 Copyright (C) 2007-2014 Jean Delvare <jdelvare@suse.de>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -27,28 +27,109 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/list.h>
30 31
31#define MAX_CHIPS 10 32#define MAX_CHIPS 10
32#define STUB_FUNC (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | \ 33
33 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | \ 34/*
34 I2C_FUNC_SMBUS_I2C_BLOCK) 35 * Support for I2C_FUNC_SMBUS_BLOCK_DATA is disabled by default and must
36 * be enabled explicitly by setting the I2C_FUNC_SMBUS_BLOCK_DATA bits
37 * in the 'functionality' module parameter.
38 */
39#define STUB_FUNC_DEFAULT \
40 (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | \
41 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | \
42 I2C_FUNC_SMBUS_I2C_BLOCK)
43
44#define STUB_FUNC_ALL \
45 (STUB_FUNC_DEFAULT | I2C_FUNC_SMBUS_BLOCK_DATA)
35 46
36static unsigned short chip_addr[MAX_CHIPS]; 47static unsigned short chip_addr[MAX_CHIPS];
37module_param_array(chip_addr, ushort, NULL, S_IRUGO); 48module_param_array(chip_addr, ushort, NULL, S_IRUGO);
38MODULE_PARM_DESC(chip_addr, 49MODULE_PARM_DESC(chip_addr,
39 "Chip addresses (up to 10, between 0x03 and 0x77)"); 50 "Chip addresses (up to 10, between 0x03 and 0x77)");
40 51
41static unsigned long functionality = STUB_FUNC; 52static unsigned long functionality = STUB_FUNC_DEFAULT;
42module_param(functionality, ulong, S_IRUGO | S_IWUSR); 53module_param(functionality, ulong, S_IRUGO | S_IWUSR);
43MODULE_PARM_DESC(functionality, "Override functionality bitfield"); 54MODULE_PARM_DESC(functionality, "Override functionality bitfield");
44 55
56/* Some chips have banked register ranges */
57
58static u8 bank_reg[MAX_CHIPS];
59module_param_array(bank_reg, byte, NULL, S_IRUGO);
60MODULE_PARM_DESC(bank_reg, "Bank register");
61
62static u8 bank_mask[MAX_CHIPS];
63module_param_array(bank_mask, byte, NULL, S_IRUGO);
64MODULE_PARM_DESC(bank_mask, "Bank value mask");
65
66static u8 bank_start[MAX_CHIPS];
67module_param_array(bank_start, byte, NULL, S_IRUGO);
68MODULE_PARM_DESC(bank_start, "First banked register");
69
70static u8 bank_end[MAX_CHIPS];
71module_param_array(bank_end, byte, NULL, S_IRUGO);
72MODULE_PARM_DESC(bank_end, "Last banked register");
73
74struct smbus_block_data {
75 struct list_head node;
76 u8 command;
77 u8 len;
78 u8 block[I2C_SMBUS_BLOCK_MAX];
79};
80
45struct stub_chip { 81struct stub_chip {
46 u8 pointer; 82 u8 pointer;
47 u16 words[256]; /* Byte operations use the LSB as per SMBus 83 u16 words[256]; /* Byte operations use the LSB as per SMBus
48 specification */ 84 specification */
85 struct list_head smbus_blocks;
86
87 /* For chips with banks, extra registers are allocated dynamically */
88 u8 bank_reg;
89 u8 bank_shift;
90 u8 bank_mask;
91 u8 bank_sel; /* Currently selected bank */
92 u8 bank_start;
93 u8 bank_end;
94 u16 bank_size;
95 u16 *bank_words; /* Room for bank_mask * bank_size registers */
49}; 96};
50 97
51static struct stub_chip *stub_chips; 98static struct stub_chip *stub_chips;
99static int stub_chips_nr;
100
101static struct smbus_block_data *stub_find_block(struct device *dev,
102 struct stub_chip *chip,
103 u8 command, bool create)
104{
105 struct smbus_block_data *b, *rb = NULL;
106
107 list_for_each_entry(b, &chip->smbus_blocks, node) {
108 if (b->command == command) {
109 rb = b;
110 break;
111 }
112 }
113 if (rb == NULL && create) {
114 rb = devm_kzalloc(dev, sizeof(*rb), GFP_KERNEL);
115 if (rb == NULL)
116 return rb;
117 rb->command = command;
118 list_add(&rb->node, &chip->smbus_blocks);
119 }
120 return rb;
121}
122
123static u16 *stub_get_wordp(struct stub_chip *chip, u8 offset)
124{
125 if (chip->bank_sel &&
126 offset >= chip->bank_start && offset <= chip->bank_end)
127 return chip->bank_words +
128 (chip->bank_sel - 1) * chip->bank_size +
129 offset - chip->bank_start;
130 else
131 return chip->words + offset;
132}
52 133
53/* Return negative errno on error. */ 134/* Return negative errno on error. */
54static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, 135static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
@@ -57,9 +138,11 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
57 s32 ret; 138 s32 ret;
58 int i, len; 139 int i, len;
59 struct stub_chip *chip = NULL; 140 struct stub_chip *chip = NULL;
141 struct smbus_block_data *b;
142 u16 *wordp;
60 143
61 /* Search for the right chip */ 144 /* Search for the right chip */
62 for (i = 0; i < MAX_CHIPS && chip_addr[i]; i++) { 145 for (i = 0; i < stub_chips_nr; i++) {
63 if (addr == chip_addr[i]) { 146 if (addr == chip_addr[i]) {
64 chip = stub_chips + i; 147 chip = stub_chips + i;
65 break; 148 break;
@@ -82,7 +165,8 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
82 "smbus byte - addr 0x%02x, wrote 0x%02x.\n", 165 "smbus byte - addr 0x%02x, wrote 0x%02x.\n",
83 addr, command); 166 addr, command);
84 } else { 167 } else {
85 data->byte = chip->words[chip->pointer++] & 0xff; 168 wordp = stub_get_wordp(chip, chip->pointer++);
169 data->byte = *wordp & 0xff;
86 dev_dbg(&adap->dev, 170 dev_dbg(&adap->dev,
87 "smbus byte - addr 0x%02x, read 0x%02x.\n", 171 "smbus byte - addr 0x%02x, read 0x%02x.\n",
88 addr, data->byte); 172 addr, data->byte);
@@ -92,14 +176,25 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
92 break; 176 break;
93 177
94 case I2C_SMBUS_BYTE_DATA: 178 case I2C_SMBUS_BYTE_DATA:
179 wordp = stub_get_wordp(chip, command);
95 if (read_write == I2C_SMBUS_WRITE) { 180 if (read_write == I2C_SMBUS_WRITE) {
96 chip->words[command] &= 0xff00; 181 *wordp &= 0xff00;
97 chip->words[command] |= data->byte; 182 *wordp |= data->byte;
98 dev_dbg(&adap->dev, 183 dev_dbg(&adap->dev,
99 "smbus byte data - addr 0x%02x, wrote 0x%02x at 0x%02x.\n", 184 "smbus byte data - addr 0x%02x, wrote 0x%02x at 0x%02x.\n",
100 addr, data->byte, command); 185 addr, data->byte, command);
186
187 /* Set the bank as needed */
188 if (chip->bank_words && command == chip->bank_reg) {
189 chip->bank_sel =
190 (data->byte >> chip->bank_shift)
191 & chip->bank_mask;
192 dev_dbg(&adap->dev,
193 "switching to bank %u.\n",
194 chip->bank_sel);
195 }
101 } else { 196 } else {
102 data->byte = chip->words[command] & 0xff; 197 data->byte = *wordp & 0xff;
103 dev_dbg(&adap->dev, 198 dev_dbg(&adap->dev,
104 "smbus byte data - addr 0x%02x, read 0x%02x at 0x%02x.\n", 199 "smbus byte data - addr 0x%02x, read 0x%02x at 0x%02x.\n",
105 addr, data->byte, command); 200 addr, data->byte, command);
@@ -110,13 +205,14 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
110 break; 205 break;
111 206
112 case I2C_SMBUS_WORD_DATA: 207 case I2C_SMBUS_WORD_DATA:
208 wordp = stub_get_wordp(chip, command);
113 if (read_write == I2C_SMBUS_WRITE) { 209 if (read_write == I2C_SMBUS_WRITE) {
114 chip->words[command] = data->word; 210 *wordp = data->word;
115 dev_dbg(&adap->dev, 211 dev_dbg(&adap->dev,
116 "smbus word data - addr 0x%02x, wrote 0x%04x at 0x%02x.\n", 212 "smbus word data - addr 0x%02x, wrote 0x%04x at 0x%02x.\n",
117 addr, data->word, command); 213 addr, data->word, command);
118 } else { 214 } else {
119 data->word = chip->words[command]; 215 data->word = *wordp;
120 dev_dbg(&adap->dev, 216 dev_dbg(&adap->dev,
121 "smbus word data - addr 0x%02x, read 0x%04x at 0x%02x.\n", 217 "smbus word data - addr 0x%02x, read 0x%04x at 0x%02x.\n",
122 addr, data->word, command); 218 addr, data->word, command);
@@ -126,6 +222,12 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
126 break; 222 break;
127 223
128 case I2C_SMBUS_I2C_BLOCK_DATA: 224 case I2C_SMBUS_I2C_BLOCK_DATA:
225 /*
226 * We ignore banks here, because banked chips don't use I2C
227 * block transfers
228 */
229 if (data->block[0] > 256 - command) /* Avoid overrun */
230 data->block[0] = 256 - command;
129 len = data->block[0]; 231 len = data->block[0];
130 if (read_write == I2C_SMBUS_WRITE) { 232 if (read_write == I2C_SMBUS_WRITE) {
131 for (i = 0; i < len; i++) { 233 for (i = 0; i < len; i++) {
@@ -148,6 +250,55 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
148 ret = 0; 250 ret = 0;
149 break; 251 break;
150 252
253 case I2C_SMBUS_BLOCK_DATA:
254 /*
255 * We ignore banks here, because chips typically don't use both
256 * banks and SMBus block transfers
257 */
258 b = stub_find_block(&adap->dev, chip, command, false);
259 if (read_write == I2C_SMBUS_WRITE) {
260 len = data->block[0];
261 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) {
262 ret = -EINVAL;
263 break;
264 }
265 if (b == NULL) {
266 b = stub_find_block(&adap->dev, chip, command,
267 true);
268 if (b == NULL) {
269 ret = -ENOMEM;
270 break;
271 }
272 }
273 /* Largest write sets read block length */
274 if (len > b->len)
275 b->len = len;
276 for (i = 0; i < len; i++)
277 b->block[i] = data->block[i + 1];
278 /* update for byte and word commands */
279 chip->words[command] = (b->block[0] << 8) | b->len;
280 dev_dbg(&adap->dev,
281 "smbus block data - addr 0x%02x, wrote %d bytes at 0x%02x.\n",
282 addr, len, command);
283 } else {
284 if (b == NULL) {
285 dev_dbg(&adap->dev,
286 "SMBus block read command without prior block write not supported\n");
287 ret = -EOPNOTSUPP;
288 break;
289 }
290 len = b->len;
291 data->block[0] = len;
292 for (i = 0; i < len; i++)
293 data->block[i + 1] = b->block[i];
294 dev_dbg(&adap->dev,
295 "smbus block data - addr 0x%02x, read %d bytes at 0x%02x.\n",
296 addr, len, command);
297 }
298
299 ret = 0;
300 break;
301
151 default: 302 default:
152 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); 303 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
153 ret = -EOPNOTSUPP; 304 ret = -EOPNOTSUPP;
@@ -159,7 +310,7 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
159 310
160static u32 stub_func(struct i2c_adapter *adapter) 311static u32 stub_func(struct i2c_adapter *adapter)
161{ 312{
162 return STUB_FUNC & functionality; 313 return STUB_FUNC_ALL & functionality;
163} 314}
164 315
165static const struct i2c_algorithm smbus_algorithm = { 316static const struct i2c_algorithm smbus_algorithm = {
@@ -174,6 +325,43 @@ static struct i2c_adapter stub_adapter = {
174 .name = "SMBus stub driver", 325 .name = "SMBus stub driver",
175}; 326};
176 327
328static int __init i2c_stub_allocate_banks(int i)
329{
330 struct stub_chip *chip = stub_chips + i;
331
332 chip->bank_reg = bank_reg[i];
333 chip->bank_start = bank_start[i];
334 chip->bank_end = bank_end[i];
335 chip->bank_size = bank_end[i] - bank_start[i] + 1;
336
337 /* We assume that all bits in the mask are contiguous */
338 chip->bank_mask = bank_mask[i];
339 while (!(chip->bank_mask & 1)) {
340 chip->bank_shift++;
341 chip->bank_mask >>= 1;
342 }
343
344 chip->bank_words = kzalloc(chip->bank_mask * chip->bank_size *
345 sizeof(u16), GFP_KERNEL);
346 if (!chip->bank_words)
347 return -ENOMEM;
348
349 pr_debug("i2c-stub: Allocated %u banks of %u words each (registers 0x%02x to 0x%02x)\n",
350 chip->bank_mask, chip->bank_size, chip->bank_start,
351 chip->bank_end);
352
353 return 0;
354}
355
356static void i2c_stub_free(void)
357{
358 int i;
359
360 for (i = 0; i < stub_chips_nr; i++)
361 kfree(stub_chips[i].bank_words);
362 kfree(stub_chips);
363}
364
177static int __init i2c_stub_init(void) 365static int __init i2c_stub_init(void)
178{ 366{
179 int i, ret; 367 int i, ret;
@@ -194,22 +382,39 @@ static int __init i2c_stub_init(void)
194 } 382 }
195 383
196 /* Allocate memory for all chips at once */ 384 /* Allocate memory for all chips at once */
197 stub_chips = kzalloc(i * sizeof(struct stub_chip), GFP_KERNEL); 385 stub_chips_nr = i;
386 stub_chips = kcalloc(stub_chips_nr, sizeof(struct stub_chip),
387 GFP_KERNEL);
198 if (!stub_chips) { 388 if (!stub_chips) {
199 pr_err("i2c-stub: Out of memory\n"); 389 pr_err("i2c-stub: Out of memory\n");
200 return -ENOMEM; 390 return -ENOMEM;
201 } 391 }
392 for (i = 0; i < stub_chips_nr; i++) {
393 INIT_LIST_HEAD(&stub_chips[i].smbus_blocks);
394
395 /* Allocate extra memory for banked register ranges */
396 if (bank_mask[i]) {
397 ret = i2c_stub_allocate_banks(i);
398 if (ret)
399 goto fail_free;
400 }
401 }
202 402
203 ret = i2c_add_adapter(&stub_adapter); 403 ret = i2c_add_adapter(&stub_adapter);
204 if (ret) 404 if (ret)
205 kfree(stub_chips); 405 goto fail_free;
406
407 return 0;
408
409 fail_free:
410 i2c_stub_free();
206 return ret; 411 return ret;
207} 412}
208 413
209static void __exit i2c_stub_exit(void) 414static void __exit i2c_stub_exit(void)
210{ 415{
211 i2c_del_adapter(&stub_adapter); 416 i2c_del_adapter(&stub_adapter);
212 kfree(stub_chips); 417 i2c_stub_free();
213} 418}
214 419
215MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 420MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 9bd4212782ab..ec11b404b433 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -41,6 +41,7 @@
41#include <linux/i2c-mux.h> 41#include <linux/i2c-mux.h>
42#include <linux/i2c/pca954x.h> 42#include <linux/i2c/pca954x.h>
43#include <linux/module.h> 43#include <linux/module.h>
44#include <linux/pm.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45 46
46#define PCA954X_MAX_NCHANS 8 47#define PCA954X_MAX_NCHANS 8
@@ -273,9 +274,23 @@ static int pca954x_remove(struct i2c_client *client)
273 return 0; 274 return 0;
274} 275}
275 276
277#ifdef CONFIG_PM_SLEEP
278static int pca954x_resume(struct device *dev)
279{
280 struct i2c_client *client = to_i2c_client(dev);
281 struct pca954x *data = i2c_get_clientdata(client);
282
283 data->last_chan = 0;
284 return i2c_smbus_write_byte(client, 0);
285}
286#endif
287
288static SIMPLE_DEV_PM_OPS(pca954x_pm, NULL, pca954x_resume);
289
276static struct i2c_driver pca954x_driver = { 290static struct i2c_driver pca954x_driver = {
277 .driver = { 291 .driver = {
278 .name = "pca954x", 292 .name = "pca954x",
293 .pm = &pca954x_pm,
279 .owner = THIS_MODULE, 294 .owner = THIS_MODULE,
280 }, 295 },
281 .probe = pca954x_probe, 296 .probe = pca954x_probe,