Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'i2c/for-mergewindow' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c updates from Wolfram Sang:

- big refactoring of the PASEMI driver to support the Apple M1

- huge improvements to the XIIC in terms of locking and SMP safety

- refactoring and clean ups for the i801 driver

... and the usual bunch of small driver updates

* 'i2c/for-mergewindow' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (43 commits)
i2c: amd-mp2-plat: ACPI: Use ACPI_COMPANION() directly
i2c: i801: Add support for Intel Ice Lake PCH-N
i2c: virtio: update the maintainer to Conghui
i2c: xlr: Fix a resource leak in the error handling path of 'xlr_i2c_probe()'
i2c: qup: move to use request_irq by IRQF_NO_AUTOEN flag
i2c: qup: fix a trivial typo
i2c: tegra: Ensure that device is suspended before driver is removed
i2c: i801: Fix incorrect and needless software PEC disabling
i2c: mediatek: Dump i2c/dma register when a timeout occurs
i2c: mediatek: Reset the handshake signal between i2c and dma
i2c: mlxcpld: Allow flexible polling time setting for I2C transactions
i2c: pasemi: Set enable bit for Apple variant
i2c: pasemi: Add Apple platform driver
i2c: pasemi: Refactor _probe to use devm_*
i2c: pasemi: Allow to configure bus frequency
i2c: pasemi: Move common reset code to own function
i2c: pasemi: Split pci driver to its own file
i2c: pasemi: Split off common probing code
i2c: pasemi: Remove usage of pci_dev
i2c: pasemi: Use dev_name instead of port number
...

+558 -261
+6
Documentation/devicetree/bindings/eeprom/at24.yaml
··· 98 98 - const: nxp,se97b 99 99 - const: atmel,24c02 100 100 - items: 101 + - const: onnn,cat24c04 102 + - const: atmel,24c04 103 + - items: 104 + - const: onnn,cat24c05 105 + - const: atmel,24c04 106 + - items: 101 107 - const: renesas,r1ex24002 102 108 - const: atmel,24c02 103 109 - items:
+61
Documentation/devicetree/bindings/i2c/apple,i2c.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: "http://devicetree.org/schemas/i2c/apple,i2c.yaml#" 5 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 6 + 7 + title: Apple/PASemi I2C controller 8 + 9 + maintainers: 10 + - Sven Peter <sven@svenpeter.dev> 11 + 12 + description: | 13 + Apple SoCs such as the M1 come with a I2C controller based on the one found 14 + in machines with P. A. Semi's PWRficient processors. 15 + The bus is used to communicate with e.g. USB PD chips or the speaker 16 + amp. 17 + 18 + allOf: 19 + - $ref: /schemas/i2c/i2c-controller.yaml# 20 + 21 + properties: 22 + compatible: 23 + enum: 24 + - apple,t8103-i2c 25 + - apple,i2c 26 + 27 + reg: 28 + maxItems: 1 29 + 30 + clocks: 31 + items: 32 + - description: I2C bus reference clock 33 + 34 + interrupts: 35 + maxItems: 1 36 + 37 + clock-frequency: 38 + description: | 39 + Desired I2C bus clock frequency in Hz. If not specified, 100 kHz will be 40 + used. This frequency is generated by dividing the reference clock. 41 + Allowed values are between ref_clk/(16*4) and ref_clk/(16*255). 42 + 43 + required: 44 + - compatible 45 + - reg 46 + - clocks 47 + - interrupts 48 + 49 + unevaluatedProperties: false 50 + 51 + examples: 52 + - | 53 + i2c@35010000 { 54 + compatible = "apple,t8103-i2c"; 55 + reg = <0x35010000 0x4000>; 56 + interrupt-parent = <&aic>; 57 + interrupts = <0 627 4>; 58 + clocks = <&ref_clk>; 59 + #address-cells = <1>; 60 + #size-cells = <0>; 61 + };
+1 -1
MAINTAINERS
··· 20189 20189 F: sound/virtio/* 20190 20190 20191 20191 VIRTIO I2C DRIVER 20192 - M: Jie Deng <jie.deng@intel.com> 20192 + M: Conghui Chen <conghui.chen@intel.com> 20193 20193 M: Viresh Kumar <viresh.kumar@linaro.org> 20194 20194 L: linux-i2c@vger.kernel.org 20195 20195 L: virtualization@lists.linux-foundation.org
+15 -1
drivers/i2c/busses/Kconfig
··· 615 615 depends on ARCH_EXYNOS || COMPILE_TEST 616 616 default y if ARCH_EXYNOS 617 617 help 618 - High-speed I2C controller on Exynos5 and newer Samsung SoCs. 618 + High-speed I2C controller on Samsung Exynos5 and newer Samsung SoCs: 619 + Exynos5250, Exynos5260, Exynos5410, Exynos542x, Exynos5800, 620 + Exynos5433 and Exynos7. 621 + Choose Y here only if you build for such Samsung SoC. 619 622 620 623 config I2C_GPIO 621 624 tristate "GPIO-based bitbanging I2C" ··· 858 855 depends on PPC_PASEMI && PCI 859 856 help 860 857 Supports the PA Semi PWRficient on-chip SMBus interfaces. 858 + 859 + config I2C_APPLE 860 + tristate "Apple SMBus platform driver" 861 + depends on ARCH_APPLE || COMPILE_TEST 862 + default ARCH_APPLE 863 + help 864 + Say Y here if you want to use the I2C controller present on Apple 865 + Silicon chips such as the M1. 866 + 867 + This driver can also be built as a module. If so, the module 868 + will be called i2c-apple. 861 869 862 870 config I2C_PCA_PLATFORM 863 871 tristate "PCA9564/PCA9665 as platform device"
+3
drivers/i2c/busses/Makefile
··· 84 84 obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 85 85 obj-$(CONFIG_I2C_OMAP) += i2c-omap.o 86 86 obj-$(CONFIG_I2C_OWL) += i2c-owl.o 87 + i2c-pasemi-objs := i2c-pasemi-core.o i2c-pasemi-pci.o 87 88 obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o 89 + i2c-apple-objs := i2c-pasemi-core.o i2c-pasemi-platform.o 90 + obj-$(CONFIG_I2C_APPLE) += i2c-apple.o 88 91 obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o 89 92 obj-$(CONFIG_I2C_PNX) += i2c-pnx.o 90 93 obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
+2 -2
drivers/i2c/busses/i2c-amd-mp2-pci.c
··· 307 307 308 308 pci_set_master(pci_dev); 309 309 310 - rc = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(64)); 310 + rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64)); 311 311 if (rc) { 312 - rc = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32)); 312 + rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32)); 313 313 if (rc) 314 314 goto err_dma_mask; 315 315 }
+2 -3
drivers/i2c/busses/i2c-amd-mp2-plat.c
··· 246 246 { 247 247 int ret; 248 248 struct amd_i2c_dev *i2c_dev; 249 - acpi_handle handle = ACPI_HANDLE(&pdev->dev); 250 - struct acpi_device *adev; 249 + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); 251 250 struct amd_mp2_dev *mp2_dev; 252 251 const char *uid; 253 252 254 - if (acpi_bus_get_device(handle, &adev)) 253 + if (!adev) 255 254 return -ENODEV; 256 255 257 256 /* The ACPI namespace doesn't contain information about which MP2 PCI
+1 -1
drivers/i2c/busses/i2c-bcm-kona.c
··· 763 763 /* Map hardware registers */ 764 764 dev->base = devm_platform_ioremap_resource(pdev, 0); 765 765 if (IS_ERR(dev->base)) 766 - return -ENOMEM; 766 + return PTR_ERR(dev->base); 767 767 768 768 /* Get and enable external clock */ 769 769 dev->external_clk = devm_clk_get(dev->device, NULL);
+31 -52
drivers/i2c/busses/i2c-i801.c
··· 64 64 * Cannon Lake-LP (PCH) 0x9da3 32 hard yes yes yes 65 65 * Cedar Fork (PCH) 0x18df 32 hard yes yes yes 66 66 * Ice Lake-LP (PCH) 0x34a3 32 hard yes yes yes 67 + * Ice Lake-N (PCH) 0x38a3 32 hard yes yes yes 67 68 * Comet Lake (PCH) 0x02a3 32 hard yes yes yes 68 69 * Comet Lake-H (PCH) 0x06a3 32 hard yes yes yes 69 70 * Elkhart Lake (PCH) 0x4b23 32 hard yes yes yes ··· 219 218 #define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS 0x23b0 220 219 #define PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS 0x31d4 221 220 #define PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS 0x34a3 221 + #define PCI_DEVICE_ID_INTEL_ICELAKE_N_SMBUS 0x38a3 222 222 #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30 223 223 #define PCI_DEVICE_ID_INTEL_TIGERLAKE_H_SMBUS 0x43a3 224 224 #define PCI_DEVICE_ID_INTEL_ELKHART_LAKE_SMBUS 0x4b23 ··· 1044 1042 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS) }, 1045 1043 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS) }, 1046 1044 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS) }, 1045 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICELAKE_N_SMBUS) }, 1047 1046 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS) }, 1048 1047 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COMETLAKE_H_SMBUS) }, 1049 1048 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COMETLAKE_V_SMBUS) }, ··· 1195 1192 1196 1193 kfree(info); 1197 1194 1198 - *((bool *)return_value) = true; 1195 + *return_value = NULL; 1199 1196 return AE_CTRL_TERMINATE; 1200 1197 1201 1198 smo88xx_not_found: ··· 1205 1202 1206 1203 static bool is_dell_system_with_lis3lv02d(void) 1207 1204 { 1208 - bool found; 1209 - const char *vendor; 1205 + void *err = ERR_PTR(-ENOENT); 1210 1206 1211 - vendor = dmi_get_system_info(DMI_SYS_VENDOR); 1212 - if (!vendor || strcmp(vendor, "Dell Inc.")) 1207 + if (!dmi_match(DMI_SYS_VENDOR, "Dell Inc.")) 1213 1208 return false; 1214 1209 1215 1210 /* ··· 1218 1217 * accelerometer but unfortunately ACPI does not provide any other 1219 1218 * information (like I2C address). 1220 1219 */ 1221 - found = false; 1222 - acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, 1223 - (void **)&found); 1220 + acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err); 1224 1221 1225 - return found; 1222 + return !IS_ERR(err); 1226 1223 } 1227 1224 1228 1225 /* ··· 1394 1395 }; 1395 1396 1396 1397 /* Setup multiplexing if needed */ 1397 - static int i801_add_mux(struct i801_priv *priv) 1398 + static void i801_add_mux(struct i801_priv *priv) 1398 1399 { 1399 1400 struct device *dev = &priv->adapter.dev; 1400 1401 const struct i801_mux_config *mux_config; ··· 1403 1404 int i; 1404 1405 1405 1406 if (!priv->mux_drvdata) 1406 - return 0; 1407 + return; 1407 1408 mux_config = priv->mux_drvdata; 1408 1409 1409 1410 /* Prepare the platform data */ ··· 1419 1420 struct_size(lookup, table, mux_config->n_gpios + 1), 1420 1421 GFP_KERNEL); 1421 1422 if (!lookup) 1422 - return -ENOMEM; 1423 + return; 1423 1424 lookup->dev_id = "i2c-mux-gpio"; 1424 - for (i = 0; i < mux_config->n_gpios; i++) { 1425 - lookup->table[i] = (struct gpiod_lookup) 1426 - GPIO_LOOKUP(mux_config->gpio_chip, 1427 - mux_config->gpios[i], "mux", 0); 1428 - } 1425 + for (i = 0; i < mux_config->n_gpios; i++) 1426 + lookup->table[i] = GPIO_LOOKUP(mux_config->gpio_chip, 1427 + mux_config->gpios[i], "mux", 0); 1429 1428 gpiod_add_lookup_table(lookup); 1430 1429 priv->lookup = lookup; 1431 1430 ··· 1441 1444 gpiod_remove_lookup_table(lookup); 1442 1445 dev_err(dev, "Failed to register i2c-mux-gpio device\n"); 1443 1446 } 1444 - 1445 - return PTR_ERR_OR_ZERO(priv->mux_pdev); 1446 1447 } 1447 1448 1448 1449 static void i801_del_mux(struct i801_priv *priv) ··· 1470 1475 return class; 1471 1476 } 1472 1477 #else 1473 - static inline int i801_add_mux(struct i801_priv *priv) { return 0; } 1478 + static inline void i801_add_mux(struct i801_priv *priv) { } 1474 1479 static inline void i801_del_mux(struct i801_priv *priv) { } 1475 1480 1476 1481 static inline unsigned int i801_get_adapter_class(struct i801_priv *priv) ··· 1488 1493 i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev, 1489 1494 struct resource *tco_res) 1490 1495 { 1491 - static DEFINE_MUTEX(p2sb_mutex); 1492 1496 struct resource *res; 1493 1497 unsigned int devfn; 1494 1498 u64 base64_addr; ··· 1500 1506 * enumerated by the PCI subsystem, so we need to unhide/hide it 1501 1507 * to lookup the P2SB BAR. 1502 1508 */ 1503 - mutex_lock(&p2sb_mutex); 1509 + pci_lock_rescan_remove(); 1504 1510 1505 1511 devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 1); 1506 1512 ··· 1518 1524 /* Hide the P2SB device, if it was hidden before */ 1519 1525 if (hidden) 1520 1526 pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, hidden); 1521 - mutex_unlock(&p2sb_mutex); 1527 + pci_unlock_rescan_remove(); 1522 1528 1523 1529 res = &tco_res[1]; 1524 1530 if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS) ··· 1618 1624 * BIOS is accessing the host controller so prevent it from 1619 1625 * suspending automatically from now on. 1620 1626 */ 1621 - pm_runtime_set_autosuspend_delay(&pdev->dev, -1); 1627 + pm_runtime_get_sync(&pdev->dev); 1622 1628 } 1623 1629 1624 1630 if ((function & ACPI_IO_MASK) == ACPI_READ) ··· 1633 1639 1634 1640 static int i801_acpi_probe(struct i801_priv *priv) 1635 1641 { 1636 - struct acpi_device *adev; 1642 + acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev); 1637 1643 acpi_status status; 1638 1644 1639 - adev = ACPI_COMPANION(&priv->pci_dev->dev); 1640 - if (adev) { 1641 - status = acpi_install_address_space_handler(adev->handle, 1642 - ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler, 1643 - NULL, priv); 1644 - if (ACPI_SUCCESS(status)) 1645 - return 0; 1646 - } 1645 + status = acpi_install_address_space_handler(ah, ACPI_ADR_SPACE_SYSTEM_IO, 1646 + i801_acpi_io_handler, NULL, priv); 1647 + if (ACPI_SUCCESS(status)) 1648 + return 0; 1647 1649 1648 1650 return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]); 1649 1651 } 1650 1652 1651 1653 static void i801_acpi_remove(struct i801_priv *priv) 1652 1654 { 1653 - struct acpi_device *adev; 1655 + acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev); 1654 1656 1655 - adev = ACPI_COMPANION(&priv->pci_dev->dev); 1656 - if (!adev) 1657 - return; 1658 - 1659 - acpi_remove_address_space_handler(adev->handle, 1660 - ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler); 1657 + acpi_remove_address_space_handler(ah, ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler); 1661 1658 } 1662 1659 #else 1663 1660 static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; } ··· 1660 1675 unsigned char hstcfg = priv->original_hstcfg; 1661 1676 1662 1677 hstcfg &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ 1663 - hstcfg &= ~SMBHSTCNT_PEC_EN; /* Disable software PEC */ 1664 1678 hstcfg |= SMBHSTCFG_HST_EN; 1665 1679 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hstcfg); 1666 1680 } ··· 1704 1720 case PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS: 1705 1721 case PCI_DEVICE_ID_INTEL_CDF_SMBUS: 1706 1722 case PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS: 1723 + case PCI_DEVICE_ID_INTEL_ICELAKE_N_SMBUS: 1707 1724 case PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS: 1708 1725 case PCI_DEVICE_ID_INTEL_COMETLAKE_H_SMBUS: 1709 1726 case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_SMBUS: ··· 1816 1831 priv->features &= ~FEATURE_IRQ; 1817 1832 1818 1833 if (priv->features & FEATURE_IRQ) { 1819 - u16 pcictl, pcists; 1834 + u16 pcists; 1820 1835 1821 1836 /* Complain if an interrupt is already pending */ 1822 1837 pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists); 1823 1838 if (pcists & PCI_STATUS_INTERRUPT) 1824 1839 dev_warn(&dev->dev, "An interrupt is pending!\n"); 1825 - 1826 - /* Check if interrupts have been disabled */ 1827 - pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pcictl); 1828 - if (pcictl & PCI_COMMAND_INTX_DISABLE) { 1829 - dev_info(&dev->dev, "Interrupts are disabled\n"); 1830 - priv->features &= ~FEATURE_IRQ; 1831 - } 1832 1840 } 1833 1841 1834 1842 if (priv->features & FEATURE_IRQ) { ··· 1869 1891 { 1870 1892 struct i801_priv *priv = pci_get_drvdata(dev); 1871 1893 1872 - pm_runtime_forbid(&dev->dev); 1873 - pm_runtime_get_noresume(&dev->dev); 1874 - 1875 1894 i801_disable_host_notify(priv); 1876 1895 i801_del_mux(priv); 1877 1896 i2c_del_adapter(&priv->adapter); ··· 1876 1901 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 1877 1902 1878 1903 platform_device_unregister(priv->tco_pdev); 1904 + 1905 + /* if acpi_reserved is set then usage_count is incremented already */ 1906 + if (!priv->acpi_reserved) 1907 + pm_runtime_get_noresume(&dev->dev); 1879 1908 1880 1909 /* 1881 1910 * do not call pci_disable_device(dev) since it can cause hard hangs on
+5 -7
drivers/i2c/busses/i2c-ismt.c
··· 918 918 return -ENODEV; 919 919 } 920 920 921 - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || 922 - (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { 923 - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || 924 - (pci_set_consistent_dma_mask(pdev, 925 - DMA_BIT_MASK(32)) != 0)) { 926 - dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n", 927 - pdev); 921 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 922 + if (err) { 923 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); 924 + if (err) { 925 + dev_err(&pdev->dev, "dma_set_mask fail\n"); 928 926 return -ENODEV; 929 927 } 930 928 }
+2 -1
drivers/i2c/busses/i2c-kempld.c
··· 283 283 static const struct i2c_adapter kempld_i2c_adapter = { 284 284 .owner = THIS_MODULE, 285 285 .name = "i2c-kempld", 286 - .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 286 + .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | 287 + I2C_CLASS_DEPRECATED, 287 288 .algo = &kempld_i2c_algorithm, 288 289 }; 289 290
+9 -5
drivers/i2c/busses/i2c-mlxcpld.c
··· 27 27 #define MLXCPLD_I2C_MAX_ADDR_LEN 4 28 28 #define MLXCPLD_I2C_RETR_NUM 2 29 29 #define MLXCPLD_I2C_XFER_TO 500000 /* usec */ 30 - #define MLXCPLD_I2C_POLL_TIME 400 /* usec */ 30 + #define MLXCPLD_I2C_POLL_TIME 200 /* usec */ 31 31 32 32 /* LPC I2C registers */ 33 33 #define MLXCPLD_LPCI2C_CPBLTY_REG 0x0 ··· 73 73 struct mlxcpld_i2c_curr_xfer xfer; 74 74 struct device *dev; 75 75 bool smbus_block; 76 + int polling_time; 76 77 }; 77 78 78 79 static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr) ··· 268 267 do { 269 268 if (!mlxcpld_i2c_check_busy(priv)) 270 269 break; 271 - usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME); 272 - timeout += MLXCPLD_I2C_POLL_TIME; 270 + usleep_range(priv->polling_time / 2, priv->polling_time); 271 + timeout += priv->polling_time; 273 272 } while (timeout <= MLXCPLD_I2C_XFER_TO); 274 273 275 274 if (timeout > MLXCPLD_I2C_XFER_TO) ··· 289 288 u8 datalen, val; 290 289 291 290 do { 292 - usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME); 291 + usleep_range(priv->polling_time / 2, priv->polling_time); 293 292 if (!mlxcpld_i2c_check_status(priv, &status)) 294 293 break; 295 - timeout += MLXCPLD_I2C_POLL_TIME; 294 + timeout += priv->polling_time; 296 295 } while (status == 0 && timeout < MLXCPLD_I2C_XFER_TO); 297 296 298 297 switch (status) { ··· 499 498 switch ((regval & data->mask) >> data->bit) { 500 499 case MLXCPLD_I2C_FREQ_1000KHZ: 501 500 freq = MLXCPLD_I2C_FREQ_1000KHZ_SET; 501 + priv->polling_time /= 4; 502 502 break; 503 503 case MLXCPLD_I2C_FREQ_400KHZ: 504 504 freq = MLXCPLD_I2C_FREQ_400KHZ_SET; 505 + priv->polling_time /= 4; 505 506 break; 506 507 default: 507 508 return 0; ··· 530 527 531 528 priv->dev = &pdev->dev; 532 529 priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR; 530 + priv->polling_time = MLXCPLD_I2C_POLL_TIME; 533 531 534 532 /* Set I2C bus frequency if platform data provides this info. */ 535 533 pdata = dev_get_platdata(&pdev->dev);
+81 -1
drivers/i2c/busses/i2c-mt65xx.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/interrupt.h> 17 17 #include <linux/io.h> 18 + #include <linux/iopoll.h> 18 19 #include <linux/kernel.h> 19 20 #include <linux/mm.h> 20 21 #include <linux/module.h> ··· 50 49 #define I2C_RD_TRANAC_VALUE 0x0001 51 50 #define I2C_SCL_MIS_COMP_VALUE 0x0000 52 51 #define I2C_CHN_CLR_FLAG 0x0000 52 + #define I2C_RELIABILITY 0x0010 53 + #define I2C_DMAACK_ENABLE 0x0008 53 54 54 55 #define I2C_DMA_CON_TX 0x0000 55 56 #define I2C_DMA_CON_RX 0x0001 ··· 130 127 OFFSET_HS, 131 128 OFFSET_SOFTRESET, 132 129 OFFSET_DCM_EN, 130 + OFFSET_MULTI_DMA, 133 131 OFFSET_PATH_DIR, 134 132 OFFSET_DEBUGSTAT, 135 133 OFFSET_DEBUGCTRL, ··· 198 194 [OFFSET_TRANSFER_LEN_AUX] = 0x44, 199 195 [OFFSET_CLOCK_DIV] = 0x48, 200 196 [OFFSET_SOFTRESET] = 0x50, 197 + [OFFSET_MULTI_DMA] = 0x8c, 201 198 [OFFSET_SCL_MIS_COMP_POINT] = 0x90, 202 - [OFFSET_DEBUGSTAT] = 0xe0, 199 + [OFFSET_DEBUGSTAT] = 0xe4, 203 200 [OFFSET_DEBUGCTRL] = 0xe8, 204 201 [OFFSET_FIFO_STAT] = 0xf4, 205 202 [OFFSET_FIFO_THRESH] = 0xf8, ··· 847 842 return 0; 848 843 } 849 844 845 + static void i2c_dump_register(struct mtk_i2c *i2c) 846 + { 847 + dev_dbg(i2c->dev, "SLAVE_ADDR: 0x%x, INTR_MASK: 0x%x\n", 848 + mtk_i2c_readw(i2c, OFFSET_SLAVE_ADDR), 849 + mtk_i2c_readw(i2c, OFFSET_INTR_MASK)); 850 + dev_dbg(i2c->dev, "INTR_STAT: 0x%x, CONTROL: 0x%x\n", 851 + mtk_i2c_readw(i2c, OFFSET_INTR_STAT), 852 + mtk_i2c_readw(i2c, OFFSET_CONTROL)); 853 + dev_dbg(i2c->dev, "TRANSFER_LEN: 0x%x, TRANSAC_LEN: 0x%x\n", 854 + mtk_i2c_readw(i2c, OFFSET_TRANSFER_LEN), 855 + mtk_i2c_readw(i2c, OFFSET_TRANSAC_LEN)); 856 + dev_dbg(i2c->dev, "DELAY_LEN: 0x%x, HTIMING: 0x%x\n", 857 + mtk_i2c_readw(i2c, OFFSET_DELAY_LEN), 858 + mtk_i2c_readw(i2c, OFFSET_TIMING)); 859 + dev_dbg(i2c->dev, "START: 0x%x, EXT_CONF: 0x%x\n", 860 + mtk_i2c_readw(i2c, OFFSET_START), 861 + mtk_i2c_readw(i2c, OFFSET_EXT_CONF)); 862 + dev_dbg(i2c->dev, "HS: 0x%x, IO_CONFIG: 0x%x\n", 863 + mtk_i2c_readw(i2c, OFFSET_HS), 864 + mtk_i2c_readw(i2c, OFFSET_IO_CONFIG)); 865 + dev_dbg(i2c->dev, "DCM_EN: 0x%x, TRANSFER_LEN_AUX: 0x%x\n", 866 + mtk_i2c_readw(i2c, OFFSET_DCM_EN), 867 + mtk_i2c_readw(i2c, OFFSET_TRANSFER_LEN_AUX)); 868 + dev_dbg(i2c->dev, "CLOCK_DIV: 0x%x, FIFO_STAT: 0x%x\n", 869 + mtk_i2c_readw(i2c, OFFSET_CLOCK_DIV), 870 + mtk_i2c_readw(i2c, OFFSET_FIFO_STAT)); 871 + dev_dbg(i2c->dev, "DEBUGCTRL : 0x%x, DEBUGSTAT: 0x%x\n", 872 + mtk_i2c_readw(i2c, OFFSET_DEBUGCTRL), 873 + mtk_i2c_readw(i2c, OFFSET_DEBUGSTAT)); 874 + if (i2c->dev_comp->regs == mt_i2c_regs_v2) { 875 + dev_dbg(i2c->dev, "LTIMING: 0x%x, MULTI_DMA: 0x%x\n", 876 + mtk_i2c_readw(i2c, OFFSET_LTIMING), 877 + mtk_i2c_readw(i2c, OFFSET_MULTI_DMA)); 878 + } 879 + dev_dbg(i2c->dev, "\nDMA_INT_FLAG: 0x%x, DMA_INT_EN: 0x%x\n", 880 + readl(i2c->pdmabase + OFFSET_INT_FLAG), 881 + readl(i2c->pdmabase + OFFSET_INT_EN)); 882 + dev_dbg(i2c->dev, "DMA_EN: 0x%x, DMA_CON: 0x%x\n", 883 + readl(i2c->pdmabase + OFFSET_EN), 884 + readl(i2c->pdmabase + OFFSET_CON)); 885 + dev_dbg(i2c->dev, "DMA_TX_MEM_ADDR: 0x%x, DMA_RX_MEM_ADDR: 0x%x\n", 886 + readl(i2c->pdmabase + OFFSET_TX_MEM_ADDR), 887 + readl(i2c->pdmabase + OFFSET_RX_MEM_ADDR)); 888 + dev_dbg(i2c->dev, "DMA_TX_LEN: 0x%x, DMA_RX_LEN: 0x%x\n", 889 + readl(i2c->pdmabase + OFFSET_TX_LEN), 890 + readl(i2c->pdmabase + OFFSET_RX_LEN)); 891 + dev_dbg(i2c->dev, "DMA_TX_4G_MODE: 0x%x, DMA_RX_4G_MODE: 0x%x", 892 + readl(i2c->pdmabase + OFFSET_TX_4G_MODE), 893 + readl(i2c->pdmabase + OFFSET_RX_4G_MODE)); 894 + } 895 + 850 896 static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, 851 897 int num, int left_num) 852 898 { ··· 907 851 u16 restart_flag = 0; 908 852 u16 dma_sync = 0; 909 853 u32 reg_4g_mode; 854 + u32 reg_dma_reset; 910 855 u8 *dma_rd_buf = NULL; 911 856 u8 *dma_wr_buf = NULL; 912 857 dma_addr_t rpaddr = 0; ··· 920 863 restart_flag = I2C_RS_TRANSFER; 921 864 922 865 reinit_completion(&i2c->msg_complete); 866 + 867 + if (i2c->dev_comp->apdma_sync && 868 + i2c->op != I2C_MASTER_WRRD && num > 1) { 869 + mtk_i2c_writew(i2c, 0x00, OFFSET_DEBUGCTRL); 870 + writel(I2C_DMA_HANDSHAKE_RST | I2C_DMA_WARM_RST, 871 + i2c->pdmabase + OFFSET_RST); 872 + 873 + ret = readw_poll_timeout(i2c->pdmabase + OFFSET_RST, 874 + reg_dma_reset, 875 + !(reg_dma_reset & I2C_DMA_WARM_RST), 876 + 0, 100); 877 + if (ret) { 878 + dev_err(i2c->dev, "DMA warm reset timeout\n"); 879 + return -ETIMEDOUT; 880 + } 881 + 882 + writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_RST); 883 + mtk_i2c_writew(i2c, I2C_HANDSHAKE_RST, OFFSET_SOFTRESET); 884 + mtk_i2c_writew(i2c, I2C_CHN_CLR_FLAG, OFFSET_SOFTRESET); 885 + mtk_i2c_writew(i2c, I2C_RELIABILITY | I2C_DMAACK_ENABLE, 886 + OFFSET_DEBUGCTRL); 887 + } 923 888 924 889 control_reg = mtk_i2c_readw(i2c, OFFSET_CONTROL) & 925 890 ~(I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS); ··· 1128 1049 1129 1050 if (ret == 0) { 1130 1051 dev_dbg(i2c->dev, "addr: %x, transfer timeout\n", msgs->addr); 1052 + i2c_dump_register(i2c); 1131 1053 mtk_i2c_init_hw(i2c); 1132 1054 return -ETIMEDOUT; 1133 1055 }
+21
drivers/i2c/busses/i2c-pasemi-core.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <linux/atomic.h> 3 + #include <linux/clk.h> 4 + #include <linux/delay.h> 5 + #include <linux/device.h> 6 + #include <linux/i2c.h> 7 + #include <linux/i2c-smbus.h> 8 + #include <linux/io.h> 9 + #include <linux/kernel.h> 10 + 11 + #define PASEMI_HW_REV_PCI -1 12 + 13 + struct pasemi_smbus { 14 + struct device *dev; 15 + struct i2c_adapter adapter; 16 + void __iomem *ioaddr; 17 + unsigned int clk_div; 18 + int hw_rev; 19 + }; 20 + 21 + int pasemi_i2c_common_probe(struct pasemi_smbus *smbus);
+85
drivers/i2c/busses/i2c-pasemi-pci.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2006-2007 PA Semi, Inc 4 + * 5 + * SMBus host driver for PA Semi PWRficient 6 + */ 7 + 8 + #include <linux/module.h> 9 + #include <linux/pci.h> 10 + #include <linux/kernel.h> 11 + #include <linux/stddef.h> 12 + #include <linux/sched.h> 13 + #include <linux/i2c.h> 14 + #include <linux/delay.h> 15 + #include <linux/slab.h> 16 + #include <linux/io.h> 17 + 18 + #include "i2c-pasemi-core.h" 19 + 20 + #define CLK_100K_DIV 84 21 + #define CLK_400K_DIV 21 22 + 23 + static struct pci_driver pasemi_smb_pci_driver; 24 + 25 + static int pasemi_smb_pci_probe(struct pci_dev *dev, 26 + const struct pci_device_id *id) 27 + { 28 + struct pasemi_smbus *smbus; 29 + unsigned long base; 30 + int size; 31 + int error; 32 + 33 + if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO)) 34 + return -ENODEV; 35 + 36 + smbus = devm_kzalloc(&dev->dev, sizeof(*smbus), GFP_KERNEL); 37 + if (!smbus) 38 + return -ENOMEM; 39 + 40 + smbus->dev = &dev->dev; 41 + base = pci_resource_start(dev, 0); 42 + size = pci_resource_len(dev, 0); 43 + smbus->clk_div = CLK_100K_DIV; 44 + 45 + /* 46 + * The original PASemi PCI controllers don't have a register for 47 + * their HW revision. 48 + */ 49 + smbus->hw_rev = PASEMI_HW_REV_PCI; 50 + 51 + if (!devm_request_region(&dev->dev, base, size, 52 + pasemi_smb_pci_driver.name)) 53 + return -EBUSY; 54 + 55 + smbus->ioaddr = pcim_iomap(dev, 0, 0); 56 + if (!smbus->ioaddr) 57 + return -EBUSY; 58 + 59 + error = pasemi_i2c_common_probe(smbus); 60 + if (error) 61 + return error; 62 + 63 + pci_set_drvdata(dev, smbus); 64 + 65 + return 0; 66 + } 67 + 68 + static const struct pci_device_id pasemi_smb_pci_ids[] = { 69 + { PCI_DEVICE(0x1959, 0xa003) }, 70 + { 0, } 71 + }; 72 + 73 + MODULE_DEVICE_TABLE(pci, pasemi_smb_pci_ids); 74 + 75 + static struct pci_driver pasemi_smb_pci_driver = { 76 + .name = "i2c-pasemi", 77 + .id_table = pasemi_smb_pci_ids, 78 + .probe = pasemi_smb_pci_probe, 79 + }; 80 + 81 + module_pci_driver(pasemi_smb_pci_driver); 82 + 83 + MODULE_LICENSE("GPL"); 84 + MODULE_AUTHOR("Olof Johansson <olof@lixom.net>"); 85 + MODULE_DESCRIPTION("PA Semi PWRficient SMBus driver");
+122
drivers/i2c/busses/i2c-pasemi-platform.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2021 The Asahi Linux Contributors 4 + * 5 + * PA Semi PWRficient SMBus host driver for Apple SoCs 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/i2c.h> 10 + #include <linux/io.h> 11 + #include <linux/kernel.h> 12 + #include <linux/module.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/types.h> 15 + 16 + #include "i2c-pasemi-core.h" 17 + 18 + struct pasemi_platform_i2c_data { 19 + struct pasemi_smbus smbus; 20 + struct clk *clk_ref; 21 + }; 22 + 23 + static int 24 + pasemi_platform_i2c_calc_clk_div(struct pasemi_platform_i2c_data *data, 25 + u32 frequency) 26 + { 27 + unsigned long clk_rate = clk_get_rate(data->clk_ref); 28 + 29 + if (!clk_rate) 30 + return -EINVAL; 31 + 32 + data->smbus.clk_div = DIV_ROUND_UP(clk_rate, 16 * frequency); 33 + if (data->smbus.clk_div < 4) 34 + return dev_err_probe(data->smbus.dev, -EINVAL, 35 + "Bus frequency %d is too fast.\n", 36 + frequency); 37 + if (data->smbus.clk_div > 0xff) 38 + return dev_err_probe(data->smbus.dev, -EINVAL, 39 + "Bus frequency %d is too slow.\n", 40 + frequency); 41 + 42 + return 0; 43 + } 44 + 45 + static int pasemi_platform_i2c_probe(struct platform_device *pdev) 46 + { 47 + struct device *dev = &pdev->dev; 48 + struct pasemi_platform_i2c_data *data; 49 + struct pasemi_smbus *smbus; 50 + u32 frequency; 51 + int error; 52 + 53 + data = devm_kzalloc(dev, sizeof(struct pasemi_platform_i2c_data), 54 + GFP_KERNEL); 55 + if (!data) 56 + return -ENOMEM; 57 + 58 + smbus = &data->smbus; 59 + smbus->dev = dev; 60 + 61 + smbus->ioaddr = devm_platform_ioremap_resource(pdev, 0); 62 + if (IS_ERR(smbus->ioaddr)) 63 + return PTR_ERR(smbus->ioaddr); 64 + 65 + if (of_property_read_u32(dev->of_node, "clock-frequency", &frequency)) 66 + frequency = I2C_MAX_STANDARD_MODE_FREQ; 67 + 68 + data->clk_ref = devm_clk_get(dev, NULL); 69 + if (IS_ERR(data->clk_ref)) 70 + return PTR_ERR(data->clk_ref); 71 + 72 + error = clk_prepare_enable(data->clk_ref); 73 + if (error) 74 + return error; 75 + 76 + error = pasemi_platform_i2c_calc_clk_div(data, frequency); 77 + if (error) 78 + goto out_clk_disable; 79 + 80 + smbus->adapter.dev.of_node = pdev->dev.of_node; 81 + error = pasemi_i2c_common_probe(smbus); 82 + if (error) 83 + goto out_clk_disable; 84 + 85 + platform_set_drvdata(pdev, data); 86 + 87 + return 0; 88 + 89 + out_clk_disable: 90 + clk_disable_unprepare(data->clk_ref); 91 + 92 + return error; 93 + } 94 + 95 + static int pasemi_platform_i2c_remove(struct platform_device *pdev) 96 + { 97 + struct pasemi_platform_i2c_data *data = platform_get_drvdata(pdev); 98 + 99 + clk_disable_unprepare(data->clk_ref); 100 + return 0; 101 + } 102 + 103 + static const struct of_device_id pasemi_platform_i2c_of_match[] = { 104 + { .compatible = "apple,t8103-i2c" }, 105 + { .compatible = "apple,i2c" }, 106 + {}, 107 + }; 108 + MODULE_DEVICE_TABLE(of, pasemi_platform_i2c_of_match); 109 + 110 + static struct platform_driver pasemi_platform_i2c_driver = { 111 + .driver = { 112 + .name = "i2c-apple", 113 + .of_match_table = pasemi_platform_i2c_of_match, 114 + }, 115 + .probe = pasemi_platform_i2c_probe, 116 + .remove = pasemi_platform_i2c_remove, 117 + }; 118 + module_platform_driver(pasemi_platform_i2c_driver); 119 + 120 + MODULE_LICENSE("GPL"); 121 + MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>"); 122 + MODULE_DESCRIPTION("Apple/PASemi SMBus platform driver");
+29 -85
drivers/i2c/busses/i2c-pasemi.c drivers/i2c/busses/i2c-pasemi-core.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/io.h> 17 17 18 - static struct pci_driver pasemi_smb_driver; 19 - 20 - struct pasemi_smbus { 21 - struct pci_dev *dev; 22 - struct i2c_adapter adapter; 23 - unsigned long base; 24 - int size; 25 - }; 18 + #include "i2c-pasemi-core.h" 26 19 27 20 /* Register offsets */ 28 21 #define REG_MTXFIFO 0x00 29 22 #define REG_MRXFIFO 0x04 30 23 #define REG_SMSTA 0x14 31 24 #define REG_CTL 0x1c 25 + #define REG_REV 0x28 32 26 33 27 /* Register defs */ 34 28 #define MTXFIFO_READ 0x00000400 ··· 38 44 39 45 #define CTL_MRR 0x00000400 40 46 #define CTL_MTR 0x00000200 47 + #define CTL_EN 0x00000800 41 48 #define CTL_CLK_M 0x000000ff 42 - 43 - #define CLK_100K_DIV 84 44 - #define CLK_400K_DIV 21 45 49 46 50 static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) 47 51 { 48 - dev_dbg(&smbus->dev->dev, "smbus write reg %lx val %08x\n", 49 - smbus->base + reg, val); 50 - outl(val, smbus->base + reg); 52 + dev_dbg(smbus->dev, "smbus write reg %x val %08x\n", reg, val); 53 + iowrite32(val, smbus->ioaddr + reg); 51 54 } 52 55 53 56 static inline int reg_read(struct pasemi_smbus *smbus, int reg) 54 57 { 55 58 int ret; 56 - ret = inl(smbus->base + reg); 57 - dev_dbg(&smbus->dev->dev, "smbus read reg %lx val %08x\n", 58 - smbus->base + reg, ret); 59 + ret = ioread32(smbus->ioaddr + reg); 60 + dev_dbg(smbus->dev, "smbus read reg %x val %08x\n", reg, ret); 59 61 return ret; 60 62 } 61 63 62 64 #define TXFIFO_WR(smbus, reg) reg_write((smbus), REG_MTXFIFO, (reg)) 63 65 #define RXFIFO_RD(smbus) reg_read((smbus), REG_MRXFIFO) 66 + 67 + static void pasemi_reset(struct pasemi_smbus *smbus) 68 + { 69 + u32 val = (CTL_MTR | CTL_MRR | (smbus->clk_div & CTL_CLK_M)); 70 + 71 + if (smbus->hw_rev >= 6) 72 + val |= CTL_EN; 73 + 74 + reg_write(smbus, REG_CTL, val); 75 + } 64 76 65 77 static void pasemi_smb_clear(struct pasemi_smbus *smbus) 66 78 { ··· 93 93 return -ENXIO; 94 94 95 95 if (timeout < 0) { 96 - dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status); 96 + dev_warn(smbus->dev, "Timeout, status 0x%08x\n", status); 97 97 reg_write(smbus, REG_SMSTA, status); 98 98 return -ETIME; 99 99 } ··· 142 142 return 0; 143 143 144 144 reset_out: 145 - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | 146 - (CLK_100K_DIV & CTL_CLK_M))); 145 + pasemi_reset(smbus); 147 146 return err; 148 147 } 149 148 ··· 308 309 return 0; 309 310 310 311 reset_out: 311 - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | 312 - (CLK_100K_DIV & CTL_CLK_M))); 312 + pasemi_reset(smbus); 313 313 return err; 314 314 } 315 315 ··· 326 328 .functionality = pasemi_smb_func, 327 329 }; 328 330 329 - static int pasemi_smb_probe(struct pci_dev *dev, 330 - const struct pci_device_id *id) 331 + int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) 331 332 { 332 - struct pasemi_smbus *smbus; 333 333 int error; 334 - 335 - if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO)) 336 - return -ENODEV; 337 - 338 - smbus = kzalloc(sizeof(struct pasemi_smbus), GFP_KERNEL); 339 - if (!smbus) 340 - return -ENOMEM; 341 - 342 - smbus->dev = dev; 343 - smbus->base = pci_resource_start(dev, 0); 344 - smbus->size = pci_resource_len(dev, 0); 345 - 346 - if (!request_region(smbus->base, smbus->size, 347 - pasemi_smb_driver.name)) { 348 - error = -EBUSY; 349 - goto out_kfree; 350 - } 351 334 352 335 smbus->adapter.owner = THIS_MODULE; 353 336 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), 354 - "PA Semi SMBus adapter at 0x%lx", smbus->base); 337 + "PA Semi SMBus adapter (%s)", dev_name(smbus->dev)); 355 338 smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 356 339 smbus->adapter.algo = &smbus_algorithm; 357 340 smbus->adapter.algo_data = smbus; 358 341 359 342 /* set up the sysfs linkage to our parent device */ 360 - smbus->adapter.dev.parent = &dev->dev; 343 + smbus->adapter.dev.parent = smbus->dev; 361 344 362 - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | 363 - (CLK_100K_DIV & CTL_CLK_M))); 345 + if (smbus->hw_rev != PASEMI_HW_REV_PCI) 346 + smbus->hw_rev = reg_read(smbus, REG_REV); 364 347 365 - error = i2c_add_adapter(&smbus->adapter); 348 + pasemi_reset(smbus); 349 + 350 + error = devm_i2c_add_adapter(smbus->dev, &smbus->adapter); 366 351 if (error) 367 - goto out_release_region; 368 - 369 - pci_set_drvdata(dev, smbus); 352 + return error; 370 353 371 354 return 0; 372 - 373 - out_release_region: 374 - release_region(smbus->base, smbus->size); 375 - out_kfree: 376 - kfree(smbus); 377 - return error; 378 355 } 379 - 380 - static void pasemi_smb_remove(struct pci_dev *dev) 381 - { 382 - struct pasemi_smbus *smbus = pci_get_drvdata(dev); 383 - 384 - i2c_del_adapter(&smbus->adapter); 385 - release_region(smbus->base, smbus->size); 386 - kfree(smbus); 387 - } 388 - 389 - static const struct pci_device_id pasemi_smb_ids[] = { 390 - { PCI_DEVICE(0x1959, 0xa003) }, 391 - { 0, } 392 - }; 393 - 394 - MODULE_DEVICE_TABLE(pci, pasemi_smb_ids); 395 - 396 - static struct pci_driver pasemi_smb_driver = { 397 - .name = "i2c-pasemi", 398 - .id_table = pasemi_smb_ids, 399 - .probe = pasemi_smb_probe, 400 - .remove = pasemi_smb_remove, 401 - }; 402 - 403 - module_pci_driver(pasemi_smb_driver); 404 - 405 - MODULE_LICENSE("GPL"); 406 - MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>"); 407 - MODULE_DESCRIPTION("PA Semi PWRficient SMBus driver");
-1
drivers/i2c/busses/i2c-pxa.c
··· 1547 1547 } 1548 1548 1549 1549 MODULE_LICENSE("GPL"); 1550 - MODULE_ALIAS("platform:pxa2xx-i2c"); 1551 1550 1552 1551 subsys_initcall(i2c_adap_pxa_init); 1553 1552 module_exit(i2c_adap_pxa_exit);
+3 -3
drivers/i2c/busses/i2c-qup.c
··· 1290 1290 * 1. Check if tx_tags_sent is false i.e. the start of QUP block so write the 1291 1291 * tags to TX FIFO and set tx_tags_sent to true. 1292 1292 * 2. Check if send_last_word is true. It will be set when last few data bytes 1293 - * (less than 4 bytes) are reamining to be written in FIFO because of no FIFO 1293 + * (less than 4 bytes) are remaining to be written in FIFO because of no FIFO 1294 1294 * space. All this data bytes are available in tx_fifo_data so write this 1295 1295 * in FIFO. 1296 1296 * 3. Write the data to TX FIFO and check for cur_blk_len. If it is non zero ··· 1797 1797 goto fail; 1798 1798 1799 1799 ret = devm_request_irq(qup->dev, qup->irq, qup_i2c_interrupt, 1800 - IRQF_TRIGGER_HIGH, "i2c_qup", qup); 1800 + IRQF_TRIGGER_HIGH | IRQF_NO_AUTOEN, 1801 + "i2c_qup", qup); 1801 1802 if (ret) { 1802 1803 dev_err(qup->dev, "Request %d IRQ failed\n", qup->irq); 1803 1804 goto fail; 1804 1805 } 1805 - disable_irq(qup->irq); 1806 1806 1807 1807 hw_ver = readl(qup->base + QUP_HW_VERSION); 1808 1808 dev_dbg(qup->dev, "Revision %x\n", hw_ver);
+3 -3
drivers/i2c/busses/i2c-rcar.c
··· 339 339 priv->flags |= ID_LAST_MSG; 340 340 341 341 rcar_i2c_write(priv, ICMAR, i2c_8bit_addr_from_msg(priv->msg)); 342 + if (!priv->atomic_xfer) 343 + rcar_i2c_write(priv, ICMIER, read ? RCAR_IRQ_RECV : RCAR_IRQ_SEND); 344 + 342 345 /* 343 346 * We don't have a test case but the HW engineers say that the write order 344 347 * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since ··· 357 354 rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); 358 355 rcar_i2c_write(priv, ICMSR, 0); 359 356 } 360 - 361 - if (!priv->atomic_xfer) 362 - rcar_i2c_write(priv, ICMIER, read ? RCAR_IRQ_RECV : RCAR_IRQ_SEND); 363 357 } 364 358 365 359 static void rcar_i2c_next_msg(struct rcar_i2c_priv *priv)
+2 -2
drivers/i2c/busses/i2c-tegra.c
··· 1700 1700 else 1701 1701 ret = tegra_i2c_init(i2c_dev); 1702 1702 1703 - pm_runtime_put(i2c_dev->dev); 1703 + pm_runtime_put_sync(i2c_dev->dev); 1704 1704 1705 1705 return ret; 1706 1706 } ··· 1819 1819 struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 1820 1820 1821 1821 i2c_del_adapter(&i2c_dev->adapter); 1822 - pm_runtime_disable(i2c_dev->dev); 1822 + pm_runtime_force_suspend(i2c_dev->dev); 1823 1823 1824 1824 tegra_i2c_release_dma(i2c_dev); 1825 1825 tegra_i2c_release_clocks(i2c_dev);
+69 -92
drivers/i2c/busses/i2c-xiic.c
··· 23 23 #include <linux/platform_device.h> 24 24 #include <linux/i2c.h> 25 25 #include <linux/interrupt.h> 26 - #include <linux/wait.h> 26 + #include <linux/completion.h> 27 27 #include <linux/platform_data/i2c-xiic.h> 28 28 #include <linux/io.h> 29 29 #include <linux/slab.h> ··· 48 48 * struct xiic_i2c - Internal representation of the XIIC I2C bus 49 49 * @dev: Pointer to device structure 50 50 * @base: Memory base of the HW registers 51 - * @wait: Wait queue for callers 51 + * @completion: Completion for callers 52 52 * @adap: Kernel adapter representation 53 53 * @tx_msg: Messages from above to be sent 54 54 * @lock: Mutual exclusion ··· 64 64 struct xiic_i2c { 65 65 struct device *dev; 66 66 void __iomem *base; 67 - wait_queue_head_t wait; 67 + struct completion completion; 68 68 struct i2c_adapter adap; 69 69 struct i2c_msg *tx_msg; 70 70 struct mutex lock; ··· 160 160 #define XIIC_PM_TIMEOUT 1000 /* ms */ 161 161 /* timeout waiting for the controller to respond */ 162 162 #define XIIC_I2C_TIMEOUT (msecs_to_jiffies(1000)) 163 + /* timeout waiting for the controller finish transfers */ 164 + #define XIIC_XFER_TIMEOUT (msecs_to_jiffies(10000)) 165 + 163 166 /* 164 167 * The following constant is used for the device global interrupt enable 165 168 * register, to enable all interrupts for the device, this is the only bit ··· 173 170 #define xiic_tx_space(i2c) ((i2c)->tx_msg->len - (i2c)->tx_pos) 174 171 #define xiic_rx_space(i2c) ((i2c)->rx_msg->len - (i2c)->rx_pos) 175 172 176 - static int xiic_start_xfer(struct xiic_i2c *i2c); 173 + static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num); 177 174 static void __xiic_start_xfer(struct xiic_i2c *i2c); 178 175 179 176 /* ··· 370 367 i2c->rx_msg = NULL; 371 368 i2c->nmsgs = 0; 372 369 i2c->state = code; 373 - wake_up(&i2c->wait); 370 + complete(&i2c->completion); 374 371 } 375 372 376 373 static irqreturn_t xiic_process(int irq, void *dev_id) ··· 378 375 struct xiic_i2c *i2c = dev_id; 379 376 u32 pend, isr, ier; 380 377 u32 clr = 0; 378 + int xfer_more = 0; 379 + int wakeup_req = 0; 380 + int wakeup_code = 0; 381 381 382 382 /* Get the interrupt Status from the IPIF. There is no clearing of 383 383 * interrupts in the IPIF. Interrupts must be cleared at the source. ··· 417 411 */ 418 412 xiic_reinit(i2c); 419 413 420 - if (i2c->rx_msg) 421 - xiic_wakeup(i2c, STATE_ERROR); 422 - if (i2c->tx_msg) 423 - xiic_wakeup(i2c, STATE_ERROR); 414 + if (i2c->rx_msg) { 415 + wakeup_req = 1; 416 + wakeup_code = STATE_ERROR; 417 + } 418 + if (i2c->tx_msg) { 419 + wakeup_req = 1; 420 + wakeup_code = STATE_ERROR; 421 + } 424 422 } 425 423 if (pend & XIIC_INTR_RX_FULL_MASK) { 426 424 /* Receive register/FIFO is full */ ··· 458 448 i2c->tx_msg++; 459 449 dev_dbg(i2c->adap.dev.parent, 460 450 "%s will start next...\n", __func__); 461 - 462 - __xiic_start_xfer(i2c); 451 + xfer_more = 1; 463 452 } 464 453 } 465 454 } ··· 472 463 if (!i2c->tx_msg) 473 464 goto out; 474 465 475 - if ((i2c->nmsgs == 1) && !i2c->rx_msg && 476 - xiic_tx_space(i2c) == 0) 477 - xiic_wakeup(i2c, STATE_DONE); 466 + wakeup_req = 1; 467 + 468 + if (i2c->nmsgs == 1 && !i2c->rx_msg && 469 + xiic_tx_space(i2c) == 0) 470 + wakeup_code = STATE_DONE; 478 471 else 479 - xiic_wakeup(i2c, STATE_ERROR); 472 + wakeup_code = STATE_ERROR; 480 473 } 481 474 if (pend & (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK)) { 482 475 /* Transmit register/FIFO is empty or ½ empty */ ··· 502 491 if (i2c->nmsgs > 1) { 503 492 i2c->nmsgs--; 504 493 i2c->tx_msg++; 505 - __xiic_start_xfer(i2c); 494 + xfer_more = 1; 506 495 } else { 507 496 xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK); 508 497 ··· 520 509 dev_dbg(i2c->adap.dev.parent, "%s clr: 0x%x\n", __func__, clr); 521 510 522 511 xiic_setreg32(i2c, XIIC_IISR_OFFSET, clr); 512 + if (xfer_more) 513 + __xiic_start_xfer(i2c); 514 + if (wakeup_req) 515 + xiic_wakeup(i2c, wakeup_code); 516 + 517 + WARN_ON(xfer_more && wakeup_req); 518 + 523 519 mutex_unlock(&i2c->lock); 524 520 return IRQ_HANDLED; 525 521 } ··· 543 525 int tries = 3; 544 526 int err; 545 527 546 - if (i2c->tx_msg) 528 + if (i2c->tx_msg || i2c->rx_msg) 547 529 return -EBUSY; 548 530 549 531 /* In single master mode bus can only be busy, when in use by this ··· 572 554 { 573 555 u8 rx_watermark; 574 556 struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg; 575 - unsigned long flags; 576 557 577 558 /* Clear and enable Rx full interrupt. */ 578 559 xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | XIIC_INTR_TX_ERROR_MASK); ··· 587 570 rx_watermark = IIC_RX_FIFO_DEPTH; 588 571 xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rx_watermark - 1); 589 572 590 - local_irq_save(flags); 591 573 if (!(msg->flags & I2C_M_NOSTART)) 592 574 /* write the address */ 593 575 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, ··· 596 580 597 581 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 598 582 msg->len | ((i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0)); 599 - local_irq_restore(flags); 600 583 601 584 if (i2c->nmsgs == 1) 602 585 /* very last, enable bus not busy as well */ ··· 608 593 static void xiic_start_send(struct xiic_i2c *i2c) 609 594 { 610 595 struct i2c_msg *msg = i2c->tx_msg; 611 - 612 - xiic_irq_clr(i2c, XIIC_INTR_TX_ERROR_MASK); 613 596 614 597 dev_dbg(i2c->adap.dev.parent, "%s entry, msg: %p, len: %d", 615 598 __func__, msg, msg->len); ··· 626 613 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); 627 614 } 628 615 629 - xiic_fill_tx_fifo(i2c); 630 - 631 616 /* Clear any pending Tx empty, Tx Error and then enable them. */ 632 617 xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_ERROR_MASK | 633 - XIIC_INTR_BNB_MASK); 634 - } 618 + XIIC_INTR_BNB_MASK | 619 + ((i2c->nmsgs > 1 || xiic_tx_space(i2c)) ? 620 + XIIC_INTR_TX_HALF_MASK : 0)); 635 621 636 - static irqreturn_t xiic_isr(int irq, void *dev_id) 637 - { 638 - struct xiic_i2c *i2c = dev_id; 639 - u32 pend, isr, ier; 640 - irqreturn_t ret = IRQ_NONE; 641 - /* Do not processes a devices interrupts if the device has no 642 - * interrupts pending 643 - */ 644 - 645 - dev_dbg(i2c->adap.dev.parent, "%s entry\n", __func__); 646 - 647 - isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); 648 - ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); 649 - pend = isr & ier; 650 - if (pend) 651 - ret = IRQ_WAKE_THREAD; 652 - 653 - return ret; 622 + xiic_fill_tx_fifo(i2c); 654 623 } 655 624 656 625 static void __xiic_start_xfer(struct xiic_i2c *i2c) 657 626 { 658 - int first = 1; 659 627 int fifo_space = xiic_tx_fifo_space(i2c); 660 628 dev_dbg(i2c->adap.dev.parent, "%s entry, msg: %p, fifos space: %d\n", 661 629 __func__, i2c->tx_msg, fifo_space); ··· 647 653 i2c->rx_pos = 0; 648 654 i2c->tx_pos = 0; 649 655 i2c->state = STATE_START; 650 - while ((fifo_space >= 2) && (first || (i2c->nmsgs > 1))) { 651 - if (!first) { 652 - i2c->nmsgs--; 653 - i2c->tx_msg++; 654 - i2c->tx_pos = 0; 655 - } else 656 - first = 0; 657 - 658 - if (i2c->tx_msg->flags & I2C_M_RD) { 659 - /* we dont date putting several reads in the FIFO */ 660 - xiic_start_recv(i2c); 661 - return; 662 - } else { 663 - xiic_start_send(i2c); 664 - if (xiic_tx_space(i2c) != 0) { 665 - /* the message could not be completely sent */ 666 - break; 667 - } 668 - } 669 - 670 - fifo_space = xiic_tx_fifo_space(i2c); 656 + if (i2c->tx_msg->flags & I2C_M_RD) { 657 + /* we dont date putting several reads in the FIFO */ 658 + xiic_start_recv(i2c); 659 + } else { 660 + xiic_start_send(i2c); 671 661 } 672 - 673 - /* there are more messages or the current one could not be completely 674 - * put into the FIFO, also enable the half empty interrupt 675 - */ 676 - if (i2c->nmsgs > 1 || xiic_tx_space(i2c)) 677 - xiic_irq_clr_en(i2c, XIIC_INTR_TX_HALF_MASK); 678 - 679 662 } 680 663 681 - static int xiic_start_xfer(struct xiic_i2c *i2c) 664 + static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num) 682 665 { 683 666 int ret; 667 + 684 668 mutex_lock(&i2c->lock); 669 + 670 + ret = xiic_busy(i2c); 671 + if (ret) 672 + goto out; 673 + 674 + i2c->tx_msg = msgs; 675 + i2c->rx_msg = NULL; 676 + i2c->nmsgs = num; 677 + init_completion(&i2c->completion); 685 678 686 679 ret = xiic_reinit(i2c); 687 680 if (!ret) 688 681 __xiic_start_xfer(i2c); 689 682 683 + out: 690 684 mutex_unlock(&i2c->lock); 691 685 692 686 return ret; ··· 692 710 if (err < 0) 693 711 return err; 694 712 695 - err = xiic_busy(i2c); 696 - if (err) 697 - goto out; 698 - 699 - i2c->tx_msg = msgs; 700 - i2c->nmsgs = num; 701 - 702 - err = xiic_start_xfer(i2c); 713 + err = xiic_start_xfer(i2c, msgs, num); 703 714 if (err < 0) { 704 715 dev_err(adap->dev.parent, "Error xiic_start_xfer\n"); 705 - goto out; 716 + return err; 706 717 } 707 718 708 - if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) || 709 - (i2c->state == STATE_DONE), HZ)) { 710 - err = (i2c->state == STATE_DONE) ? num : -EIO; 711 - goto out; 712 - } else { 719 + err = wait_for_completion_timeout(&i2c->completion, XIIC_XFER_TIMEOUT); 720 + mutex_lock(&i2c->lock); 721 + if (err == 0) { /* Timeout */ 713 722 i2c->tx_msg = NULL; 714 723 i2c->rx_msg = NULL; 715 724 i2c->nmsgs = 0; 716 725 err = -ETIMEDOUT; 717 - goto out; 726 + } else if (err < 0) { /* Completion error */ 727 + i2c->tx_msg = NULL; 728 + i2c->rx_msg = NULL; 729 + i2c->nmsgs = 0; 730 + } else { 731 + err = (i2c->state == STATE_DONE) ? num : -EIO; 718 732 } 719 - out: 733 + mutex_unlock(&i2c->lock); 720 734 pm_runtime_mark_last_busy(i2c->dev); 721 735 pm_runtime_put_autosuspend(i2c->dev); 722 736 return err; ··· 773 795 i2c->adap.dev.of_node = pdev->dev.of_node; 774 796 775 797 mutex_init(&i2c->lock); 776 - init_waitqueue_head(&i2c->wait); 777 798 778 799 i2c->clk = devm_clk_get(&pdev->dev, NULL); 779 800 if (IS_ERR(i2c->clk)) ··· 789 812 pm_runtime_use_autosuspend(i2c->dev); 790 813 pm_runtime_set_active(i2c->dev); 791 814 pm_runtime_enable(i2c->dev); 792 - ret = devm_request_threaded_irq(&pdev->dev, irq, xiic_isr, 815 + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 793 816 xiic_process, IRQF_ONESHOT, 794 817 pdev->name, i2c); 795 818
+5 -1
drivers/i2c/busses/i2c-xlr.c
··· 431 431 i2c_set_adapdata(&priv->adap, priv); 432 432 ret = i2c_add_numbered_adapter(&priv->adap); 433 433 if (ret < 0) 434 - return ret; 434 + goto err_unprepare_clk; 435 435 436 436 platform_set_drvdata(pdev, priv); 437 437 dev_info(&priv->adap.dev, "Added I2C Bus.\n"); 438 438 return 0; 439 + 440 + err_unprepare_clk: 441 + clk_unprepare(clk); 442 + return ret; 439 443 } 440 444 441 445 static int xlr_i2c_remove(struct platform_device *pdev)