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

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

Pull i2c updates from Wolfram Sang:

- mainly feature additions to drivers (stm32f7, qup, xlp9xx, mlxcpld, ...)

- conversion to use the i2c_8bit_addr_from_msg macro consistently

- move includes to platform_data

- core updates to allow the (still in review) I3C subsystem to connect

- and the regular share of smaller driver updates

* 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (68 commits)
i2c: qup: fix building without CONFIG_ACPI
i2c: tegra: Remove suspend-resume
i2c: imx-lpi2c: Switch to SPDX identifier
i2c: mxs: Switch to SPDX identifier
i2c: busses: make use of i2c_8bit_addr_from_msg
i2c: algos: make use of i2c_8bit_addr_from_msg
i2c: rcar: document R8A77980 bindings
i2c: qup: Add command-line parameter to override SCL frequency
i2c: qup: Correct duty cycle for FM and FM+
i2c: qup: Add support for Fast Mode Plus
i2c: qup: add probe path for Centriq ACPI devices
i2c: robotfuzz-osif: drop pointless test
i2c: robotfuzz-osif: remove pointless local variable
i2c: rk3x: Don't print visible virtual mapping MMIO address
i2c: opal: don't check number of messages in the driver
i2c: ibm_iic: don't check number of messages in the driver
i2c: imx: Switch to SPDX identifier
i2c: mux: pca954x: merge calls to of_match_device and of_device_get_match_data
i2c: mux: demux-pinctrl: use proper parent device for demux adapter
i2c: mux: improve error message for failed symlink
...

+1685 -485
+1 -1
Documentation/devicetree/bindings/i2c/i2c-davinci.txt
··· 24 24 - clock-frequency : desired I2C bus clock frequency in Hz. 25 25 - ti,has-pfunc: boolean; if defined, it indicates that SoC supports PFUNC 26 26 registers. PFUNC registers allow to switch I2C pins to function as 27 - GPIOs, so they can by toggled manually. 27 + GPIOs, so they can be toggled manually. 28 28 29 29 Example (enbw_cmc board): 30 30 i2c@1c22000 {
+1
Documentation/devicetree/bindings/i2c/i2c-rcar.txt
··· 15 15 "renesas,i2c-r8a7796" if the device is a part of a R8A7796 SoC. 16 16 "renesas,i2c-r8a77965" if the device is a part of a R8A77965 SoC. 17 17 "renesas,i2c-r8a77970" if the device is a part of a R8A77970 SoC. 18 + "renesas,i2c-r8a77980" if the device is a part of a R8A77980 SoC. 18 19 "renesas,i2c-r8a77995" if the device is a part of a R8A77995 SoC. 19 20 "renesas,rcar-gen1-i2c" for a generic R-Car Gen1 compatible device. 20 21 "renesas,rcar-gen2-i2c" for a generic R-Car Gen2 or RZ/G1 compatible
+1 -3
Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt
··· 8 8 (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c. 9 9 (c) "samsung, s3c2440-hdmiphy-i2c", for s3c2440-like i2c used 10 10 inside HDMIPHY block found on several samsung SoCs 11 - (d) "samsung, exynos5440-i2c", for s3c2440-like i2c used 12 - on EXYNOS5440 which does not need GPIO configuration. 13 - (e) "samsung, exynos5-sata-phy-i2c", for s3c2440-like i2c used as 11 + (d) "samsung, exynos5-sata-phy-i2c", for s3c2440-like i2c used as 14 12 a host to SATA PHY controller on an internal bus. 15 13 - reg: physical base address of the controller and length of memory mapped 16 14 region.
+4
Documentation/i2c/busses/i2c-mlxcpld
··· 20 20 - Write Byte/Block. 21 21 22 22 Registers: 23 + CPBLTY 0x0 - capability reg. 24 + Bits [6:5] - transaction length. b01 - 72B is supported, 25 + 36B in other case. 26 + Bit 7 - SMBus block read support. 23 27 CTRL 0x1 - control reg. 24 28 Resets all the registers. 25 29 HALF_CYC 0x4 - cycle reg.
+1 -1
Documentation/i2c/busses/i2c-ocores
··· 18 18 i2c-ocores uses the platform bus, so you need to provide a struct 19 19 platform_device with the base address and interrupt number. The 20 20 dev.platform_data of the device should also point to a struct 21 - ocores_i2c_platform_data (see linux/i2c-ocores.h) describing the 21 + ocores_i2c_platform_data (see linux/platform_data/i2c-ocores.h) describing the 22 22 distance between registers and the input clock speed. 23 23 There is also a possibility to attach a list of i2c_board_info which 24 24 the i2c-ocores driver will add to the bus upon creation.
+2 -2
Documentation/i2c/muxes/i2c-mux-gpio
··· 30 30 platform_device with the platform_data pointing to a struct 31 31 i2c_mux_gpio_platform_data with the I2C adapter number of the master 32 32 bus, the number of bus segments to create and the GPIO pins used 33 - to control it. See include/linux/i2c-mux-gpio.h for details. 33 + to control it. See include/linux/platform_data/i2c-mux-gpio.h for details. 34 34 35 35 E.G. something like this for a MUX providing 4 bus segments 36 36 controlled through 3 GPIO pins: 37 37 38 - #include <linux/i2c-mux-gpio.h> 38 + #include <linux/platform_data/i2c-mux-gpio.h> 39 39 #include <linux/platform_device.h> 40 40 41 41 static const unsigned myboard_gpiomux_gpios[] = {
+4 -4
MAINTAINERS
··· 5953 5953 M: Haavard Skinnemoen <hskinnemoen@gmail.com> 5954 5954 S: Supported 5955 5955 F: drivers/i2c/busses/i2c-gpio.c 5956 - F: include/linux/i2c-gpio.h 5956 + F: include/linux/platform_data/i2c-gpio.h 5957 5957 5958 5958 GENERIC GPIO I2C MULTIPLEXER DRIVER 5959 5959 M: Peter Korsgaard <peter.korsgaard@barco.com> 5960 5960 L: linux-i2c@vger.kernel.org 5961 5961 S: Supported 5962 5962 F: drivers/i2c/muxes/i2c-mux-gpio.c 5963 - F: include/linux/i2c-mux-gpio.h 5963 + F: include/linux/platform_data/i2c-mux-gpio.h 5964 5964 F: Documentation/i2c/muxes/i2c-mux-gpio 5965 5965 5966 5966 GENERIC HDLC (WAN) DRIVERS ··· 10392 10392 F: arch/arm/plat-omap/ 10393 10393 F: arch/arm/configs/omap1_defconfig 10394 10394 F: drivers/i2c/busses/i2c-omap.c 10395 - F: include/linux/i2c-omap.h 10395 + F: include/linux/platform_data/i2c-omap.h 10396 10396 10397 10397 OMAP2+ SUPPORT 10398 10398 M: Tony Lindgren <tony@atomide.com> ··· 10424 10424 F: drivers/regulator/tps65910-regulator.c 10425 10425 F: drivers/regulator/twl-regulator.c 10426 10426 F: drivers/regulator/twl6030-regulator.c 10427 - F: include/linux/i2c-omap.h 10427 + F: include/linux/platform_data/i2c-omap.h 10428 10428 10429 10429 ONION OMEGA2+ BOARD 10430 10430 M: Harvey Hunt <harveyhuntnexus@gmail.com>
+1 -1
arch/arm/mach-ks8695/board-acs5k.c
··· 19 19 #include <linux/gpio/machine.h> 20 20 #include <linux/i2c.h> 21 21 #include <linux/i2c-algo-bit.h> 22 - #include <linux/i2c-gpio.h> 22 + #include <linux/platform_data/i2c-gpio.h> 23 23 #include <linux/platform_data/pca953x.h> 24 24 25 25 #include <linux/mtd/mtd.h>
+1 -1
arch/arm/mach-omap1/board-htcherald.c
··· 31 31 #include <linux/gpio.h> 32 32 #include <linux/gpio_keys.h> 33 33 #include <linux/i2c.h> 34 - #include <linux/i2c-gpio.h> 34 + #include <linux/platform_data/i2c-gpio.h> 35 35 #include <linux/htcpld.h> 36 36 #include <linux/leds.h> 37 37 #include <linux/spi/spi.h>
+1 -1
arch/arm/mach-omap1/common.h
··· 27 27 #define __ARCH_ARM_MACH_OMAP1_COMMON_H 28 28 29 29 #include <linux/mtd/mtd.h> 30 - #include <linux/i2c-omap.h> 30 + #include <linux/platform_data/i2c-omap.h> 31 31 #include <linux/reboot.h> 32 32 33 33 #include <asm/exception.h>
+1 -1
arch/arm/mach-omap1/i2c.c
··· 20 20 */ 21 21 22 22 #include <linux/i2c.h> 23 - #include <linux/i2c-omap.h> 23 + #include <linux/platform_data/i2c-omap.h> 24 24 #include <mach/mux.h> 25 25 #include "soc.h" 26 26
+1 -1
arch/arm/mach-omap2/common.h
··· 30 30 #include <linux/delay.h> 31 31 #include <linux/i2c.h> 32 32 #include <linux/mfd/twl.h> 33 - #include <linux/i2c-omap.h> 33 + #include <linux/platform_data/i2c-omap.h> 34 34 #include <linux/reboot.h> 35 35 #include <linux/irqchip/irq-omap-intc.h> 36 36
+1 -1
arch/arm/mach-omap2/omap_hwmod_2420_data.c
··· 13 13 * XXX these should be marked initdata for multi-OMAP kernels 14 14 */ 15 15 16 - #include <linux/i2c-omap.h> 16 + #include <linux/platform_data/i2c-omap.h> 17 17 #include <linux/omap-dma.h> 18 18 19 19 #include "omap_hwmod.h"
+1 -1
arch/arm/mach-omap2/omap_hwmod_2430_data.c
··· 13 13 * XXX these should be marked initdata for multi-OMAP kernels 14 14 */ 15 15 16 - #include <linux/i2c-omap.h> 16 + #include <linux/platform_data/i2c-omap.h> 17 17 #include <linux/platform_data/hsmmc-omap.h> 18 18 #include <linux/omap-dma.h> 19 19
+1 -1
arch/arm/mach-omap2/omap_hwmod_33xx_data.c
··· 14 14 * GNU General Public License for more details. 15 15 */ 16 16 17 - #include <linux/i2c-omap.h> 17 + #include <linux/platform_data/i2c-omap.h> 18 18 19 19 #include "omap_hwmod.h" 20 20 #include "omap_hwmod_common_data.h"
+1 -1
arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
··· 15 15 * XXX these should be marked initdata for multi-OMAP kernels 16 16 */ 17 17 18 - #include <linux/i2c-omap.h> 18 + #include <linux/platform_data/i2c-omap.h> 19 19 #include <linux/power/smartreflex.h> 20 20 #include <linux/platform_data/hsmmc-omap.h> 21 21
+1 -1
arch/arm/mach-omap2/omap_hwmod_44xx_data.c
··· 23 23 #include <linux/io.h> 24 24 #include <linux/platform_data/hsmmc-omap.h> 25 25 #include <linux/power/smartreflex.h> 26 - #include <linux/i2c-omap.h> 26 + #include <linux/platform_data/i2c-omap.h> 27 27 28 28 #include <linux/omap-dma.h> 29 29
+1 -1
arch/arm/mach-omap2/omap_hwmod_54xx_data.c
··· 20 20 #include <linux/io.h> 21 21 #include <linux/platform_data/hsmmc-omap.h> 22 22 #include <linux/power/smartreflex.h> 23 - #include <linux/i2c-omap.h> 23 + #include <linux/platform_data/i2c-omap.h> 24 24 25 25 #include <linux/omap-dma.h> 26 26
+1 -1
arch/arm/mach-omap2/omap_hwmod_7xx_data.c
··· 20 20 #include <linux/io.h> 21 21 #include <linux/platform_data/hsmmc-omap.h> 22 22 #include <linux/power/smartreflex.h> 23 - #include <linux/i2c-omap.h> 23 + #include <linux/platform_data/i2c-omap.h> 24 24 25 25 #include <linux/omap-dma.h> 26 26
+1 -1
arch/arm/mach-pxa/palmz72.c
··· 30 30 #include <linux/wm97xx.h> 31 31 #include <linux/power_supply.h> 32 32 #include <linux/usb/gpio_vbus.h> 33 - #include <linux/i2c-gpio.h> 33 + #include <linux/platform_data/i2c-gpio.h> 34 34 #include <linux/gpio/machine.h> 35 35 36 36 #include <asm/mach-types.h>
+1 -1
arch/arm/mach-pxa/viper.c
··· 35 35 #include <linux/sched.h> 36 36 #include <linux/gpio.h> 37 37 #include <linux/jiffies.h> 38 - #include <linux/i2c-gpio.h> 38 + #include <linux/platform_data/i2c-gpio.h> 39 39 #include <linux/gpio/machine.h> 40 40 #include <linux/platform_data/i2c-pxa.h> 41 41 #include <linux/serial_8250.h>
+1 -1
arch/arm/mach-sa1100/simpad.c
··· 37 37 #include <linux/input.h> 38 38 #include <linux/gpio_keys.h> 39 39 #include <linux/leds.h> 40 - #include <linux/i2c-gpio.h> 40 + #include <linux/platform_data/i2c-gpio.h> 41 41 42 42 #include "generic.h" 43 43
+1 -1
arch/mips/alchemy/board-gpr.c
··· 29 29 #include <linux/leds.h> 30 30 #include <linux/gpio.h> 31 31 #include <linux/i2c.h> 32 - #include <linux/i2c-gpio.h> 32 + #include <linux/platform_data/i2c-gpio.h> 33 33 #include <linux/gpio/machine.h> 34 34 #include <asm/bootinfo.h> 35 35 #include <asm/idle.h>
+1 -1
arch/sh/boards/board-sh7785lcr.c
··· 17 17 #include <linux/delay.h> 18 18 #include <linux/interrupt.h> 19 19 #include <linux/i2c.h> 20 - #include <linux/i2c-pca-platform.h> 20 + #include <linux/platform_data/i2c-pca-platform.h> 21 21 #include <linux/i2c-algo-pca.h> 22 22 #include <linux/usb/r8a66597.h> 23 23 #include <linux/sh_intc.h>
+1 -3
drivers/i2c/algos/i2c-algo-bit.c
··· 519 519 } 520 520 } 521 521 } else { /* normal 7bit address */ 522 - addr = msg->addr << 1; 523 - if (flags & I2C_M_RD) 524 - addr |= 1; 522 + addr = i2c_8bit_addr_from_msg(msg); 525 523 if (flags & I2C_M_REV_DIR_ADDR) 526 524 addr ^= 1; 527 525 ret = try_address(i2c_adap, addr, retries);
+1 -4
drivers/i2c/algos/i2c-algo-pca.c
··· 112 112 struct i2c_msg *msg) 113 113 { 114 114 int sta = pca_get_con(adap); 115 - int addr; 115 + int addr = i2c_8bit_addr_from_msg(msg); 116 116 117 - addr = ((0x7f & msg->addr) << 1); 118 - if (msg->flags & I2C_M_RD) 119 - addr |= 1; 120 117 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", 121 118 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); 122 119
+2 -6
drivers/i2c/algos/i2c-algo-pcf.c
··· 291 291 static int pcf_doAddress(struct i2c_algo_pcf_data *adap, 292 292 struct i2c_msg *msg) 293 293 { 294 - unsigned short flags = msg->flags; 295 - unsigned char addr; 294 + unsigned char addr = i2c_8bit_addr_from_msg(msg); 296 295 297 - addr = msg->addr << 1; 298 - if (flags & I2C_M_RD) 299 - addr |= 1; 300 - if (flags & I2C_M_REV_DIR_ADDR) 296 + if (msg->flags & I2C_M_REV_DIR_ADDR) 301 297 addr ^= 1; 302 298 i2c_outb(adap, addr); 303 299
+1
drivers/i2c/busses/Kconfig
··· 943 943 config I2C_STM32F7 944 944 tristate "STMicroelectronics STM32F7 I2C support" 945 945 depends on ARCH_STM32 || COMPILE_TEST 946 + select I2C_SLAVE 946 947 help 947 948 Enable this option to add support for STM32 I2C controller embedded 948 949 in STM32F7 SoCs.
+2 -1
drivers/i2c/busses/Makefile
··· 94 94 obj-$(CONFIG_I2C_SPRD) += i2c-sprd.o 95 95 obj-$(CONFIG_I2C_ST) += i2c-st.o 96 96 obj-$(CONFIG_I2C_STM32F4) += i2c-stm32f4.o 97 - obj-$(CONFIG_I2C_STM32F7) += i2c-stm32f7.o 97 + i2c-stm32f7-drv-objs := i2c-stm32f7.o i2c-stm32.o 98 + obj-$(CONFIG_I2C_STM32F7) += i2c-stm32f7-drv.o 98 99 obj-$(CONFIG_I2C_STU300) += i2c-stu300.o 99 100 obj-$(CONFIG_I2C_SUN6I_P2WI) += i2c-sun6i-p2wi.o 100 101 obj-$(CONFIG_I2C_SYNQUACER) += i2c-synquacer.o
+1 -2
drivers/i2c/busses/i2c-aspeed.c
··· 335 335 { 336 336 u32 command = ASPEED_I2CD_M_START_CMD | ASPEED_I2CD_M_TX_CMD; 337 337 struct i2c_msg *msg = &bus->msgs[bus->msgs_index]; 338 - u8 slave_addr = msg->addr << 1; 338 + u8 slave_addr = i2c_8bit_addr_from_msg(msg); 339 339 340 340 bus->master_state = ASPEED_I2C_MASTER_START; 341 341 bus->buf_index = 0; 342 342 343 343 if (msg->flags & I2C_M_RD) { 344 - slave_addr |= 1; 345 344 command |= ASPEED_I2CD_M_RX_CMD; 346 345 /* Need to let the hardware know to NACK after RX. */ 347 346 if (msg->len == 1 && !(msg->flags & I2C_M_RECV_LEN))
+10 -2
drivers/i2c/busses/i2c-at91.c
··· 518 518 * the RXRDY interrupt first in order to not keep garbage data in the 519 519 * Receive Holding Register for the next transfer. 520 520 */ 521 - if (irqstatus & AT91_TWI_RXRDY) 522 - at91_twi_read_next_byte(dev); 521 + if (irqstatus & AT91_TWI_RXRDY) { 522 + /* 523 + * Read all available bytes at once by polling RXRDY usable w/ 524 + * and w/o FIFO. With FIFO enabled we could also read RXFL and 525 + * avoid polling RXRDY. 526 + */ 527 + do { 528 + at91_twi_read_next_byte(dev); 529 + } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY); 530 + } 523 531 524 532 /* 525 533 * When a NACK condition is detected, the I2C controller sets the NACK,
+17 -14
drivers/i2c/busses/i2c-axxia.c
··· 351 351 * addr_2: addr[7:0] 352 352 */ 353 353 addr_1 = 0xF0 | ((msg->addr >> 7) & 0x06); 354 + if (i2c_m_rd(msg)) 355 + addr_1 |= 1; /* Set the R/nW bit of the address */ 354 356 addr_2 = msg->addr & 0xFF; 355 357 } else { 356 358 /* 7-bit address 357 359 * addr_1: addr[6:0] | (R/nW) 358 360 * addr_2: dont care 359 361 */ 360 - addr_1 = (msg->addr << 1) & 0xFF; 362 + addr_1 = i2c_8bit_addr_from_msg(msg); 361 363 addr_2 = 0; 362 364 } 363 365 ··· 367 365 /* I2C read transfer */ 368 366 rx_xfer = i2c_m_recv_len(msg) ? I2C_SMBUS_BLOCK_MAX : msg->len; 369 367 tx_xfer = 0; 370 - addr_1 |= 1; /* Set the R/nW bit of the address */ 371 368 } else { 372 369 /* I2C write transfer */ 373 370 rx_xfer = 0; ··· 533 532 if (idev->bus_clk_rate == 0) 534 533 idev->bus_clk_rate = 100000; /* default clock rate */ 535 534 535 + ret = clk_prepare_enable(idev->i2c_clk); 536 + if (ret) { 537 + dev_err(&pdev->dev, "failed to enable clock\n"); 538 + return ret; 539 + } 540 + 536 541 ret = axxia_i2c_init(idev); 537 542 if (ret) { 538 543 dev_err(&pdev->dev, "failed to initialize\n"); 539 - return ret; 544 + goto error_disable_clk; 540 545 } 541 546 542 547 ret = devm_request_irq(&pdev->dev, irq, axxia_i2c_isr, 0, 543 548 pdev->name, idev); 544 549 if (ret) { 545 550 dev_err(&pdev->dev, "failed to claim IRQ%d\n", irq); 546 - return ret; 547 - } 548 - 549 - ret = clk_prepare_enable(idev->i2c_clk); 550 - if (ret) { 551 - dev_err(&pdev->dev, "failed to enable clock\n"); 552 - return ret; 551 + goto error_disable_clk; 553 552 } 554 553 555 554 i2c_set_adapdata(&idev->adapter, idev); ··· 564 563 platform_set_drvdata(pdev, idev); 565 564 566 565 ret = i2c_add_adapter(&idev->adapter); 567 - if (ret) { 568 - clk_disable_unprepare(idev->i2c_clk); 569 - return ret; 570 - } 566 + if (ret) 567 + goto error_disable_clk; 571 568 572 569 return 0; 570 + 571 + error_disable_clk: 572 + clk_disable_unprepare(idev->i2c_clk); 573 + return ret; 573 574 } 574 575 575 576 static int axxia_i2c_remove(struct platform_device *pdev)
+9 -11
drivers/i2c/busses/i2c-designware-common.c
··· 149 149 return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset; 150 150 } 151 151 152 - void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) 153 - { 154 - dw_writel(dev, enable, DW_IC_ENABLE); 155 - } 156 - 157 - void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable) 152 + void __i2c_dw_disable(struct dw_i2c_dev *dev) 158 153 { 159 154 int timeout = 100; 160 155 161 156 do { 162 - __i2c_dw_enable(dev, enable); 163 - if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable) 157 + __i2c_dw_disable_nowait(dev); 158 + /* 159 + * The enable status register may be unimplemented, but 160 + * in that case this test reads zero and exits the loop. 161 + */ 162 + if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == 0) 164 163 return; 165 164 166 165 /* ··· 170 171 usleep_range(25, 250); 171 172 } while (timeout--); 172 173 173 - dev_warn(dev->dev, "timeout in %sabling adapter\n", 174 - enable ? "en" : "dis"); 174 + dev_warn(dev->dev, "timeout in disabling adapter\n"); 175 175 } 176 176 177 177 unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev) ··· 275 277 void i2c_dw_disable(struct dw_i2c_dev *dev) 276 278 { 277 279 /* Disable controller */ 278 - __i2c_dw_enable_and_wait(dev, false); 280 + __i2c_dw_disable(dev); 279 281 280 282 /* Disable all interupts */ 281 283 dw_writel(dev, 0, DW_IC_INTR_MASK);
+12 -2
drivers/i2c/busses/i2c-designware-core.h
··· 297 297 void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset); 298 298 u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset); 299 299 u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset); 300 - void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable); 301 - void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable); 302 300 unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev); 303 301 int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare); 304 302 int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); ··· 306 308 u32 i2c_dw_func(struct i2c_adapter *adap); 307 309 void i2c_dw_disable(struct dw_i2c_dev *dev); 308 310 void i2c_dw_disable_int(struct dw_i2c_dev *dev); 311 + 312 + static inline void __i2c_dw_enable(struct dw_i2c_dev *dev) 313 + { 314 + dw_writel(dev, 1, DW_IC_ENABLE); 315 + } 316 + 317 + static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) 318 + { 319 + dw_writel(dev, 0, DW_IC_ENABLE); 320 + } 321 + 322 + void __i2c_dw_disable(struct dw_i2c_dev *dev); 309 323 310 324 extern u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev); 311 325 extern int i2c_dw_probe(struct dw_i2c_dev *dev);
+4 -4
drivers/i2c/busses/i2c-designware-master.c
··· 81 81 comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1); 82 82 83 83 /* Disable the adapter */ 84 - __i2c_dw_enable_and_wait(dev, false); 84 + __i2c_dw_disable(dev); 85 85 86 86 /* Set standard and fast speed deviders for high/low periods */ 87 87 ··· 180 180 u32 ic_con, ic_tar = 0; 181 181 182 182 /* Disable the adapter */ 183 - __i2c_dw_enable_and_wait(dev, false); 183 + __i2c_dw_disable(dev); 184 184 185 185 /* If the slave address is ten bit address, enable 10BITADDR */ 186 186 ic_con = dw_readl(dev, DW_IC_CON); ··· 209 209 i2c_dw_disable_int(dev); 210 210 211 211 /* Enable the adapter */ 212 - __i2c_dw_enable(dev, true); 212 + __i2c_dw_enable(dev); 213 213 214 214 /* Dummy read to avoid the register getting stuck on Bay Trail */ 215 215 dw_readl(dev, DW_IC_ENABLE_STATUS); ··· 462 462 * additional interrupts are a hardware bug or this driver doesn't 463 463 * handle them correctly yet. 464 464 */ 465 - __i2c_dw_enable(dev, false); 465 + __i2c_dw_disable_nowait(dev); 466 466 467 467 if (dev->msg_err) { 468 468 ret = dev->msg_err;
+3 -3
drivers/i2c/busses/i2c-designware-slave.c
··· 75 75 comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1); 76 76 77 77 /* Disable the adapter. */ 78 - __i2c_dw_enable_and_wait(dev, false); 78 + __i2c_dw_disable(dev); 79 79 80 80 /* Configure SDA Hold Time if required. */ 81 81 reg = dw_readl(dev, DW_IC_COMP_VERSION); ··· 119 119 * Set slave address in the IC_SAR register, 120 120 * the address to which the DW_apb_i2c responds. 121 121 */ 122 - __i2c_dw_enable(dev, false); 122 + __i2c_dw_disable_nowait(dev); 123 123 dw_writel(dev, slave->addr, DW_IC_SAR); 124 124 dev->slave = slave; 125 125 126 - __i2c_dw_enable(dev, true); 126 + __i2c_dw_enable(dev); 127 127 128 128 dev->cmd_err = 0; 129 129 dev->msg_write_idx = 0;
+4 -7
drivers/i2c/busses/i2c-diolan-u2c.c
··· 360 360 if (ret < 0) 361 361 goto abort; 362 362 } 363 + ret = diolan_i2c_put_byte_ack(dev, 364 + i2c_8bit_addr_from_msg(pmsg)); 365 + if (ret < 0) 366 + goto abort; 363 367 if (pmsg->flags & I2C_M_RD) { 364 - ret = 365 - diolan_i2c_put_byte_ack(dev, (pmsg->addr << 1) | 1); 366 - if (ret < 0) 367 - goto abort; 368 368 for (j = 0; j < pmsg->len; j++) { 369 369 u8 byte; 370 370 bool ack = j < pmsg->len - 1; ··· 393 393 pmsg->buf[j] = byte; 394 394 } 395 395 } else { 396 - ret = diolan_i2c_put_byte_ack(dev, pmsg->addr << 1); 397 - if (ret < 0) 398 - goto abort; 399 396 for (j = 0; j < pmsg->len; j++) { 400 397 ret = diolan_i2c_put_byte_ack(dev, 401 398 pmsg->buf[j]);
+1 -2
drivers/i2c/busses/i2c-efm32.c
··· 144 144 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg]; 145 145 146 146 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_START); 147 - efm32_i2c_write32(ddata, REG_TXDATA, cur_msg->addr << 1 | 148 - (cur_msg->flags & I2C_M_RD ? 1 : 0)); 147 + efm32_i2c_write32(ddata, REG_TXDATA, i2c_8bit_addr_from_msg(cur_msg)); 149 148 } 150 149 151 150 static void efm32_i2c_send_next_byte(struct efm32_i2c_ddata *ddata)
+2 -3
drivers/i2c/busses/i2c-eg20t.c
··· 414 414 iowrite32(addr_8_lsb, p + PCH_I2CDR); 415 415 } else { 416 416 /* set 7 bit slave address and R/W bit as 0 */ 417 - iowrite32(addr << 1, p + PCH_I2CDR); 417 + iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR); 418 418 if (first) 419 419 pch_i2c_start(adap); 420 420 } ··· 538 538 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); 539 539 } else { 540 540 /* 7 address bits + R/W bit */ 541 - addr = (((addr) << 1) | (I2C_RD)); 542 - iowrite32(addr, p + PCH_I2CDR); 541 + iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR); 543 542 } 544 543 545 544 /* check if it is the first message */
+1 -1
drivers/i2c/busses/i2c-emev2.c
··· 149 149 em_clear_set_bit(priv, 0, I2C_BIT_STT0, I2C_OFS_IICC0); 150 150 151 151 /* Send slave address and R/W type */ 152 - writeb((msg->addr << 1) | read, priv->base + I2C_OFS_IIC0); 152 + writeb(i2c_8bit_addr_from_msg(msg), priv->base + I2C_OFS_IIC0); 153 153 154 154 /* Wait for transaction */ 155 155 status = em_i2c_wait_for_event(priv);
+7 -22
drivers/i2c/busses/i2c-exynos5.c
··· 707 707 struct i2c_msg *msgs, int num) 708 708 { 709 709 struct exynos5_i2c *i2c = adap->algo_data; 710 - int i = 0, ret = 0, stop = 0; 710 + int i, ret; 711 711 712 712 if (i2c->suspended) { 713 713 dev_err(i2c->dev, "HS-I2C is not initialized.\n"); ··· 718 718 if (ret) 719 719 return ret; 720 720 721 - for (i = 0; i < num; i++, msgs++) { 722 - stop = (i == num - 1); 723 - 724 - ret = exynos5_i2c_xfer_msg(i2c, msgs, stop); 725 - 726 - if (ret < 0) 727 - goto out; 721 + for (i = 0; i < num; ++i) { 722 + ret = exynos5_i2c_xfer_msg(i2c, msgs + i, i + 1 == num); 723 + if (ret) 724 + break; 728 725 } 729 726 730 - if (i == num) { 731 - ret = num; 732 - } else { 733 - /* Only one message, cannot access the device */ 734 - if (i == 1) 735 - ret = -EREMOTEIO; 736 - else 737 - ret = i; 738 - 739 - dev_warn(i2c->dev, "xfer message failed\n"); 740 - } 741 - 742 - out: 743 727 clk_disable(i2c->clk); 744 - return ret; 728 + 729 + return ret ?: num; 745 730 } 746 731 747 732 static u32 exynos5_i2c_func(struct i2c_adapter *adap)
+1 -1
drivers/i2c/busses/i2c-gpio.c
··· 11 11 #include <linux/delay.h> 12 12 #include <linux/i2c.h> 13 13 #include <linux/i2c-algo-bit.h> 14 - #include <linux/i2c-gpio.h> 14 + #include <linux/platform_data/i2c-gpio.h> 15 15 #include <linux/init.h> 16 16 #include <linux/module.h> 17 17 #include <linux/slab.h>
+3 -19
drivers/i2c/busses/i2c-hix5hd2.c
··· 73 73 #define I2C_OVER_INTR BIT(0) 74 74 75 75 #define HIX5I2C_MAX_FREQ 400000 /* 400k */ 76 - #define HIX5I2C_READ_OPERATION 0x01 77 76 78 77 enum hix5hd2_i2c_state { 79 78 HIX5I2C_STAT_RW_ERR = -1, ··· 310 311 hix5hd2_i2c_clr_all_irq(priv); 311 312 hix5hd2_i2c_enable_irq(priv); 312 313 313 - if (priv->msg->flags & I2C_M_RD) 314 - writel_relaxed((priv->msg->addr << 1) | HIX5I2C_READ_OPERATION, 315 - priv->regs + HIX5I2C_TXR); 316 - else 317 - writel_relaxed(priv->msg->addr << 1, 318 - priv->regs + HIX5I2C_TXR); 314 + writel_relaxed(i2c_8bit_addr_from_msg(priv->msg), 315 + priv->regs + HIX5I2C_TXR); 319 316 320 317 writel_relaxed(I2C_WRITE | I2C_START, priv->regs + HIX5I2C_COM); 321 318 spin_unlock_irqrestore(&priv->lock, flags); ··· 372 377 goto out; 373 378 } 374 379 375 - if (i == num) { 376 - ret = num; 377 - } else { 378 - /* Only one message, cannot access the device */ 379 - if (i == 1) 380 - ret = -EREMOTEIO; 381 - else 382 - ret = i; 383 - 384 - dev_warn(priv->dev, "xfer message failed\n"); 385 - } 380 + ret = num; 386 381 387 382 out: 388 383 pm_runtime_mark_last_busy(priv->dev); ··· 456 471 goto err_clk; 457 472 } 458 473 459 - pm_suspend_ignore_children(&pdev->dev, true); 460 474 pm_runtime_set_autosuspend_delay(priv->dev, MSEC_PER_SEC); 461 475 pm_runtime_use_autosuspend(priv->dev); 462 476 pm_runtime_set_active(priv->dev);
+3 -4
drivers/i2c/busses/i2c-i801.c
··· 106 106 107 107 #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 108 108 #include <linux/gpio.h> 109 - #include <linux/i2c-mux-gpio.h> 109 + #include <linux/platform_data/i2c-mux-gpio.h> 110 110 #endif 111 111 112 112 /* I801 SMBus address offsets */ ··· 1710 1710 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 1711 1711 } 1712 1712 1713 - #ifdef CONFIG_PM 1713 + #ifdef CONFIG_PM_SLEEP 1714 1714 static int i801_suspend(struct device *dev) 1715 1715 { 1716 1716 struct pci_dev *pci_dev = to_pci_dev(dev); ··· 1731 1731 } 1732 1732 #endif 1733 1733 1734 - static UNIVERSAL_DEV_PM_OPS(i801_pm_ops, i801_suspend, 1735 - i801_resume, NULL); 1734 + static SIMPLE_DEV_PM_OPS(i801_pm_ops, i801_suspend, i801_resume); 1736 1735 1737 1736 static struct pci_driver i801_driver = { 1738 1737 .name = "i801_smbus",
-3
drivers/i2c/busses/i2c-ibm_iic.c
··· 561 561 562 562 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num); 563 563 564 - if (!num) 565 - return 0; 566 - 567 564 /* Check the sanity of the passed messages. 568 565 * Uhh, generic i2c layer is more suitable place for such code... 569 566 */
+2 -14
drivers/i2c/busses/i2c-imx-lpi2c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 1 2 /* 2 3 * This is i.MX low power i2c controller driver. 3 4 * 4 5 * Copyright 2016 Freescale Semiconductor, Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * as published by the Free Software Foundation; either version 2 9 - * of the License, or (at your option) any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - * 16 6 */ 17 7 18 8 #include <linux/clk.h> ··· 170 180 struct i2c_msg *msgs) 171 181 { 172 182 unsigned int temp; 173 - u8 read; 174 183 175 184 temp = readl(lpi2c_imx->base + LPI2C_MCR); 176 185 temp |= MCR_RRF | MCR_RTF; 177 186 writel(temp, lpi2c_imx->base + LPI2C_MCR); 178 187 writel(0x7f00, lpi2c_imx->base + LPI2C_MSR); 179 188 180 - read = msgs->flags & I2C_M_RD; 181 - temp = (msgs->addr << 1 | read) | (GEN_START << 8); 189 + temp = i2c_8bit_addr_from_msg(msgs) | (GEN_START << 8); 182 190 writel(temp, lpi2c_imx->base + LPI2C_MTDR); 183 191 184 192 return lpi2c_imx_bus_busy(lpi2c_imx);
+6 -15
drivers/i2c/busses/i2c-imx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 1 2 /* 2 3 * Copyright (C) 2002 Motorola GSG-China 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public License 6 - * as published by the Free Software Foundation; either version 2 7 - * of the License, or (at your option) any later version. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 4 * 14 5 * Author: 15 6 * Darius Augulis, Teltonika Inc. ··· 621 630 * Write slave address. 622 631 * The first byte must be transmitted by the CPU. 623 632 */ 624 - imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR); 633 + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 625 634 reinit_completion(&i2c_imx->dma->cmd_complete); 626 635 time_left = wait_for_completion_timeout( 627 636 &i2c_imx->dma->cmd_complete, ··· 751 760 int i, result; 752 761 753 762 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", 754 - __func__, msgs->addr << 1); 763 + __func__, i2c_8bit_addr_from_msg(msgs)); 755 764 756 765 /* write slave address */ 757 - imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR); 766 + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 758 767 result = i2c_imx_trx_complete(i2c_imx); 759 768 if (result) 760 769 return result; ··· 787 796 788 797 dev_dbg(&i2c_imx->adapter.dev, 789 798 "<%s> write slave address: addr=0x%x\n", 790 - __func__, (msgs->addr << 1) | 0x01); 799 + __func__, i2c_8bit_addr_from_msg(msgs)); 791 800 792 801 /* write slave address */ 793 - imx_i2c_write_reg((msgs->addr << 1) | 0x01, i2c_imx, IMX_I2C_I2DR); 802 + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 794 803 result = i2c_imx_trx_complete(i2c_imx); 795 804 if (result) 796 805 return result;
+3 -4
drivers/i2c/busses/i2c-kempld.c
··· 124 124 /* 10 bit address? */ 125 125 if (i2c->msg->flags & I2C_M_TEN) { 126 126 addr = 0xf0 | ((i2c->msg->addr >> 7) & 0x6); 127 + /* Set read bit if necessary */ 128 + addr |= (i2c->msg->flags & I2C_M_RD) ? 1 : 0; 127 129 i2c->state = STATE_ADDR10; 128 130 } else { 129 - addr = (i2c->msg->addr << 1); 131 + addr = i2c_8bit_addr_from_msg(i2c->msg); 130 132 i2c->state = STATE_START; 131 133 } 132 - 133 - /* Set read bit if necessary */ 134 - addr |= (i2c->msg->flags & I2C_M_RD) ? 1 : 0; 135 134 136 135 kempld_write8(pld, KEMPLD_I2C_DATA, addr); 137 136 kempld_write8(pld, KEMPLD_I2C_CMD, I2C_CMD_START);
+59 -9
drivers/i2c/busses/i2c-mlxcpld.c
··· 45 45 #define MLXCPLD_I2C_VALID_FLAG (I2C_M_RECV_LEN | I2C_M_RD) 46 46 #define MLXCPLD_I2C_BUS_NUM 1 47 47 #define MLXCPLD_I2C_DATA_REG_SZ 36 48 + #define MLXCPLD_I2C_DATA_SZ_BIT BIT(5) 49 + #define MLXCPLD_I2C_DATA_SZ_MASK GENMASK(6, 5) 50 + #define MLXCPLD_I2C_SMBUS_BLK_BIT BIT(7) 48 51 #define MLXCPLD_I2C_MAX_ADDR_LEN 4 49 52 #define MLXCPLD_I2C_RETR_NUM 2 50 53 #define MLXCPLD_I2C_XFER_TO 500000 /* usec */ 51 54 #define MLXCPLD_I2C_POLL_TIME 2000 /* usec */ 52 55 53 56 /* LPC I2C registers */ 54 - #define MLXCPLD_LPCI2C_LPF_REG 0x0 57 + #define MLXCPLD_LPCI2C_CPBLTY_REG 0x0 55 58 #define MLXCPLD_LPCI2C_CTRL_REG 0x1 56 59 #define MLXCPLD_LPCI2C_HALF_CYC_REG 0x4 57 60 #define MLXCPLD_LPCI2C_I2C_HOLD_REG 0x5 ··· 86 83 struct mutex lock; 87 84 struct mlxcpld_i2c_curr_xfer xfer; 88 85 struct device *dev; 86 + bool smbus_block; 89 87 }; 90 88 91 89 static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr) ··· 234 230 * All upper layers currently are never use transfer with more than 235 231 * 2 messages. Actually, it's also not so relevant in Mellanox systems 236 232 * because of HW limitation. Max size of transfer is not more than 32 237 - * bytes in the current x86 LPCI2C bridge. 233 + * or 68 bytes in the current x86 LPCI2C bridge. 238 234 */ 239 235 priv->xfer.cmd = msgs[num - 1].flags & I2C_M_RD; 240 236 ··· 299 295 static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv) 300 296 { 301 297 int status, i, timeout = 0; 302 - u8 datalen; 298 + u8 datalen, val; 303 299 304 300 do { 305 301 usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME); ··· 328 324 * Actual read data len will be always the same as 329 325 * requested len. 0xff (line pull-up) will be returned 330 326 * if slave has no data to return. Thus don't read 331 - * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. 327 + * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. Only in case of 328 + * SMBus block read transaction data len can be different, 329 + * check this case. 332 330 */ 333 - datalen = priv->xfer.data_len; 331 + mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val, 332 + 1); 333 + if (priv->smbus_block && (val & MLXCPLD_I2C_SMBUS_BLK_BIT)) { 334 + mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG, 335 + &datalen, 1); 336 + if (unlikely(datalen > (I2C_SMBUS_BLOCK_MAX + 1))) { 337 + dev_err(priv->dev, "Incorrect smbus block read message len\n"); 338 + return -E2BIG; 339 + } 340 + } else { 341 + datalen = priv->xfer.data_len; 342 + } 334 343 335 344 mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_DATA_REG, 336 345 priv->xfer.msg[i].buf, datalen); ··· 361 344 static void mlxcpld_i2c_xfer_msg(struct mlxcpld_i2c_priv *priv) 362 345 { 363 346 int i, len = 0; 364 - u8 cmd; 347 + u8 cmd, val; 365 348 366 349 mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG, 367 350 &priv->xfer.data_len, 1); 368 - mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, 369 - &priv->xfer.addr_width, 1); 351 + 352 + val = priv->xfer.addr_width; 353 + /* Notify HW about SMBus block read transaction */ 354 + if (priv->smbus_block && priv->xfer.msg_num >= 2 && 355 + priv->xfer.msg[1].len == 1 && 356 + (priv->xfer.msg[1].flags & I2C_M_RECV_LEN) && 357 + (priv->xfer.msg[1].flags & I2C_M_RD)) 358 + val |= MLXCPLD_I2C_SMBUS_BLK_BIT; 359 + 360 + mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val, 1); 370 361 371 362 for (i = 0; i < priv->xfer.msg_num; i++) { 372 363 if ((priv->xfer.msg[i].flags & I2C_M_RD) != I2C_M_RD) { ··· 450 425 451 426 static u32 mlxcpld_i2c_func(struct i2c_adapter *adap) 452 427 { 453 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; 428 + struct mlxcpld_i2c_priv *priv = i2c_get_adapdata(adap); 429 + 430 + if (priv->smbus_block) 431 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 432 + I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_BLOCK_DATA; 433 + else 434 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 435 + I2C_FUNC_SMBUS_I2C_BLOCK; 454 436 } 455 437 456 438 static const struct i2c_algorithm mlxcpld_i2c_algo = { ··· 469 437 .flags = I2C_AQ_COMB_WRITE_THEN_READ, 470 438 .max_read_len = MLXCPLD_I2C_DATA_REG_SZ - MLXCPLD_I2C_MAX_ADDR_LEN, 471 439 .max_write_len = MLXCPLD_I2C_DATA_REG_SZ, 440 + .max_comb_1st_msg_len = 4, 441 + }; 442 + 443 + static const struct i2c_adapter_quirks mlxcpld_i2c_quirks_ext = { 444 + .flags = I2C_AQ_COMB_WRITE_THEN_READ, 445 + .max_read_len = MLXCPLD_I2C_DATA_REG_SZ * 2 - MLXCPLD_I2C_MAX_ADDR_LEN, 446 + .max_write_len = MLXCPLD_I2C_DATA_REG_SZ * 2, 472 447 .max_comb_1st_msg_len = 4, 473 448 }; 474 449 ··· 493 454 { 494 455 struct mlxcpld_i2c_priv *priv; 495 456 int err; 457 + u8 val; 496 458 497 459 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 498 460 if (!priv) ··· 506 466 507 467 /* Register with i2c layer */ 508 468 mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO); 469 + /* Read capability register */ 470 + mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_CPBLTY_REG, &val, 1); 471 + /* Check support for extended transaction length */ 472 + if ((val & MLXCPLD_I2C_DATA_SZ_MASK) == MLXCPLD_I2C_DATA_SZ_BIT) 473 + mlxcpld_i2c_adapter.quirks = &mlxcpld_i2c_quirks_ext; 474 + /* Check support for smbus block transaction */ 475 + if (val & MLXCPLD_I2C_SMBUS_BLK_BIT) 476 + priv->smbus_block = true; 477 + if (pdev->id >= -1) 478 + mlxcpld_i2c_adapter.nr = pdev->id; 509 479 priv->adap = mlxcpld_i2c_adapter; 510 480 priv->adap.dev.parent = &pdev->dev; 511 481 priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
+2 -6
drivers/i2c/busses/i2c-mt65xx.c
··· 27 27 #include <linux/mm.h> 28 28 #include <linux/module.h> 29 29 #include <linux/of_address.h> 30 + #include <linux/of_device.h> 30 31 #include <linux/of_irq.h> 31 32 #include <linux/platform_device.h> 32 33 #include <linux/scatterlist.h> ··· 735 734 736 735 static int mtk_i2c_probe(struct platform_device *pdev) 737 736 { 738 - const struct of_device_id *of_id; 739 737 int ret = 0; 740 738 struct mtk_i2c *i2c; 741 739 struct clk *clk; ··· 761 761 762 762 init_completion(&i2c->msg_complete); 763 763 764 - of_id = of_match_node(mtk_i2c_of_match, pdev->dev.of_node); 765 - if (!of_id) 766 - return -EINVAL; 767 - 768 - i2c->dev_comp = of_id->data; 764 + i2c->dev_comp = of_device_get_match_data(&pdev->dev); 769 765 i2c->adap.dev.of_node = pdev->dev.of_node; 770 766 i2c->dev = &pdev->dev; 771 767 i2c->adap.dev.parent = &pdev->dev;
+4 -12
drivers/i2c/busses/i2c-mxs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 1 2 /* 2 3 * Freescale MXS I2C bus driver 3 4 * ··· 8 7 * based on a (non-working) driver which was: 9 8 * 10 9 * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved. 11 - * 12 - * This program is free software; you can redistribute it and/or modify 13 - * it under the terms of the GNU General Public License as published by 14 - * the Free Software Foundation; either version 2 of the License, or 15 - * (at your option) any later version. 16 - * 17 10 */ 18 11 19 12 #include <linux/slab.h> ··· 175 180 struct dma_async_tx_descriptor *desc; 176 181 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 177 182 183 + i2c->addr_data = i2c_8bit_addr_from_msg(msg); 184 + 178 185 if (msg->flags & I2C_M_RD) { 179 186 i2c->dma_read = true; 180 - i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_READ; 181 187 182 188 /* 183 189 * SELECT command. ··· 236 240 } 237 241 } else { 238 242 i2c->dma_read = false; 239 - i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_WRITE; 240 243 241 244 /* 242 245 * WRITE command. ··· 366 371 struct i2c_msg *msg, uint32_t flags) 367 372 { 368 373 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 369 - uint32_t addr_data = msg->addr << 1; 374 + uint32_t addr_data = i2c_8bit_addr_from_msg(msg); 370 375 uint32_t data = 0; 371 376 int i, ret, xlen = 0, xmit = 0; 372 377 uint32_t start; ··· 406 411 */ 407 412 BUG_ON(msg->len > 4); 408 413 409 - addr_data |= I2C_SMBUS_READ; 410 - 411 414 /* SELECT command. */ 412 415 mxs_i2c_pio_trigger_write_cmd(i2c, MXS_CMD_I2C_SELECT, 413 416 addr_data); ··· 443 450 * fast enough. It is possible to transfer arbitrary amount 444 451 * of data using PIO write. 445 452 */ 446 - addr_data |= I2C_SMBUS_WRITE; 447 453 448 454 /* 449 455 * The LSB of data buffer is the first byte blasted across
-2
drivers/i2c/busses/i2c-nomadik.c
··· 1012 1012 goto err_no_mem; 1013 1013 } 1014 1014 1015 - pm_suspend_ignore_children(&adev->dev, true); 1016 - 1017 1015 dev->clk = devm_clk_get(&adev->dev, NULL); 1018 1016 if (IS_ERR(dev->clk)) { 1019 1017 dev_err(&adev->dev, "could not get i2c clock\n");
+2 -5
drivers/i2c/busses/i2c-ocores.c
··· 21 21 #include <linux/i2c.h> 22 22 #include <linux/interrupt.h> 23 23 #include <linux/wait.h> 24 - #include <linux/i2c-ocores.h> 24 + #include <linux/platform_data/i2c-ocores.h> 25 25 #include <linux/slab.h> 26 26 #include <linux/io.h> 27 27 #include <linux/log2.h> ··· 222 222 i2c->nmsgs = num; 223 223 i2c->state = STATE_START; 224 224 225 - oc_setreg(i2c, OCI2C_DATA, 226 - (i2c->msg->addr << 1) | 227 - ((i2c->msg->flags & I2C_M_RD) ? 1:0)); 228 - 225 + oc_setreg(i2c, OCI2C_DATA, i2c_8bit_addr_from_msg(i2c->msg)); 229 226 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 230 227 231 228 if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) ||
+1 -1
drivers/i2c/busses/i2c-omap.c
··· 36 36 #include <linux/of.h> 37 37 #include <linux/of_device.h> 38 38 #include <linux/slab.h> 39 - #include <linux/i2c-omap.h> 39 + #include <linux/platform_data/i2c-omap.h> 40 40 #include <linux/pm_runtime.h> 41 41 #include <linux/pinctrl/consumer.h> 42 42
-4
drivers/i2c/busses/i2c-opal.c
··· 94 94 */ 95 95 memset(&req, 0, sizeof(req)); 96 96 switch(num) { 97 - case 0: 98 - return 0; 99 97 case 1: 100 98 req.type = (msgs[0].flags & I2C_M_RD) ? 101 99 OPAL_I2C_RAW_READ : OPAL_I2C_RAW_WRITE; ··· 112 114 req.size = cpu_to_be32(msgs[1].len); 113 115 req.buffer_ra = cpu_to_be64(__pa(msgs[1].buf)); 114 116 break; 115 - default: 116 - return -EOPNOTSUPP; 117 117 } 118 118 119 119 rc = i2c_opal_send_request(opal_id, &req);
+1 -1
drivers/i2c/busses/i2c-pasemi.c
··· 121 121 122 122 read = msg->flags & I2C_M_RD ? 1 : 0; 123 123 124 - TXFIFO_WR(smbus, MTXFIFO_START | (msg->addr << 1) | read); 124 + TXFIFO_WR(smbus, MTXFIFO_START | i2c_8bit_addr_from_msg(msg)); 125 125 126 126 if (read) { 127 127 TXFIFO_WR(smbus, msg->len | MTXFIFO_READ |
+1 -1
drivers/i2c/busses/i2c-pca-platform.c
··· 20 20 #include <linux/interrupt.h> 21 21 #include <linux/platform_device.h> 22 22 #include <linux/i2c-algo-pca.h> 23 - #include <linux/i2c-pca-platform.h> 23 + #include <linux/platform_data/i2c-pca-platform.h> 24 24 #include <linux/gpio.h> 25 25 #include <linux/gpio/consumer.h> 26 26 #include <linux/io.h>
+20 -1
drivers/i2c/busses/i2c-pnx.c
··· 18 18 #include <linux/timer.h> 19 19 #include <linux/completion.h> 20 20 #include <linux/platform_device.h> 21 - #include <linux/i2c-pnx.h> 22 21 #include <linux/io.h> 23 22 #include <linux/err.h> 24 23 #include <linux/clk.h> ··· 27 28 #define I2C_PNX_TIMEOUT_DEFAULT 10 /* msec */ 28 29 #define I2C_PNX_SPEED_KHZ_DEFAULT 100 29 30 #define I2C_PNX_REGION_SIZE 0x100 31 + 32 + struct i2c_pnx_mif { 33 + int ret; /* Return value */ 34 + int mode; /* Interface mode */ 35 + struct completion complete; /* I/O completion */ 36 + struct timer_list timer; /* Timeout */ 37 + u8 * buf; /* Data buffer */ 38 + int len; /* Length of data buffer */ 39 + int order; /* RX Bytes to order via TX */ 40 + }; 41 + 42 + struct i2c_pnx_algo_data { 43 + void __iomem *ioaddr; 44 + struct i2c_pnx_mif mif; 45 + int last; 46 + struct clk *clk; 47 + struct i2c_adapter adapter; 48 + int irq; 49 + u32 timeout; 50 + }; 30 51 31 52 enum { 32 53 mstatus_tdi = 0x00000001,
+40 -19
drivers/i2c/busses/i2c-qup.c
··· 136 136 */ 137 137 #define TOUT_MIN 2 138 138 139 + /* I2C Frequency Modes */ 140 + #define I2C_STANDARD_FREQ 100000 141 + #define I2C_FAST_MODE_FREQ 400000 142 + #define I2C_FAST_MODE_PLUS_FREQ 1000000 143 + 139 144 /* Default values. Use these if FW query fails */ 140 - #define DEFAULT_CLK_FREQ 100000 145 + #define DEFAULT_CLK_FREQ I2C_STANDARD_FREQ 141 146 #define DEFAULT_SRC_CLK 20000000 142 147 143 148 /* ··· 154 149 #define RECV_MAX_DATA_LEN 254 155 150 /* TAG length for DATA READ in RX FIFO */ 156 151 #define READ_RX_TAGS_LEN 2 152 + 153 + static unsigned int scl_freq; 154 + module_param_named(scl_freq, scl_freq, uint, 0444); 155 + MODULE_PARM_DESC(scl_freq, "SCL frequency override"); 157 156 158 157 /* 159 158 * count: no of blocks ··· 462 453 { 463 454 struct qup_i2c_block *blk = &qup->blk; 464 455 struct i2c_msg *msg = qup->msg; 465 - u32 addr = msg->addr << 1; 456 + u32 addr = i2c_8bit_addr_from_msg(msg); 466 457 u32 qup_tag; 467 458 int idx; 468 459 u32 val; ··· 1657 1648 clk_disable_unprepare(qup->pclk); 1658 1649 } 1659 1650 1651 + static const struct acpi_device_id qup_i2c_acpi_match[] = { 1652 + { "QCOM8010"}, 1653 + { }, 1654 + }; 1655 + MODULE_DEVICE_TABLE(acpi, qup_i2c_acpi_match); 1656 + 1660 1657 static int qup_i2c_probe(struct platform_device *pdev) 1661 1658 { 1662 1659 static const int blk_sizes[] = {4, 16, 32}; ··· 1684 1669 init_completion(&qup->xfer); 1685 1670 platform_set_drvdata(pdev, qup); 1686 1671 1687 - ret = device_property_read_u32(qup->dev, "clock-frequency", &clk_freq); 1688 - if (ret) { 1689 - dev_notice(qup->dev, "using default clock-frequency %d", 1690 - DEFAULT_CLK_FREQ); 1672 + if (scl_freq) { 1673 + dev_notice(qup->dev, "Using override frequency of %u\n", scl_freq); 1674 + clk_freq = scl_freq; 1675 + } else { 1676 + ret = device_property_read_u32(qup->dev, "clock-frequency", &clk_freq); 1677 + if (ret) { 1678 + dev_notice(qup->dev, "using default clock-frequency %d", 1679 + DEFAULT_CLK_FREQ); 1680 + } 1691 1681 } 1692 1682 1693 1683 if (of_device_is_compatible(pdev->dev.of_node, "qcom,i2c-qup-v1.1.1")) { ··· 1702 1682 } else { 1703 1683 qup->adap.algo = &qup_i2c_algo_v2; 1704 1684 is_qup_v1 = false; 1705 - ret = qup_i2c_req_dma(qup); 1685 + if (acpi_match_device(qup_i2c_acpi_match, qup->dev)) 1686 + goto nodma; 1687 + else 1688 + ret = qup_i2c_req_dma(qup); 1706 1689 1707 1690 if (ret == -EPROBE_DEFER) 1708 1691 goto fail_dma; ··· 1757 1734 } 1758 1735 1759 1736 nodma: 1760 - /* We support frequencies up to FAST Mode (400KHz) */ 1761 - if (!clk_freq || clk_freq > 400000) { 1737 + /* We support frequencies up to FAST Mode Plus (1MHz) */ 1738 + if (!clk_freq || clk_freq > I2C_FAST_MODE_PLUS_FREQ) { 1762 1739 dev_err(qup->dev, "clock frequency not supported %d\n", 1763 1740 clk_freq); 1764 1741 return -EINVAL; ··· 1862 1839 size = QUP_INPUT_FIFO_SIZE(io_mode); 1863 1840 qup->in_fifo_sz = qup->in_blk_sz * (2 << size); 1864 1841 1865 - fs_div = ((src_clk_freq / clk_freq) / 2) - 3; 1866 1842 hs_div = 3; 1867 - qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff); 1843 + if (clk_freq <= I2C_STANDARD_FREQ) { 1844 + fs_div = ((src_clk_freq / clk_freq) / 2) - 3; 1845 + qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff); 1846 + } else { 1847 + /* 33%/66% duty cycle */ 1848 + fs_div = ((src_clk_freq / clk_freq) - 6) * 2 / 3; 1849 + qup->clk_ctl = ((fs_div / 2) << 16) | (hs_div << 8) | (fs_div & 0xff); 1850 + } 1868 1851 1869 1852 /* 1870 1853 * Time it takes for a byte to be clocked out on the bus. ··· 1987 1958 {} 1988 1959 }; 1989 1960 MODULE_DEVICE_TABLE(of, qup_i2c_dt_match); 1990 - 1991 - #if IS_ENABLED(CONFIG_ACPI) 1992 - static const struct acpi_device_id qup_i2c_acpi_match[] = { 1993 - { "QCOM8010"}, 1994 - { }, 1995 - }; 1996 - MODULE_DEVICE_TABLE(acpi, qup_i2c_acpi_match); 1997 - #endif 1998 1961 1999 1962 static struct platform_driver qup_i2c_driver = { 2000 1963 .probe = qup_i2c_probe,
+3 -1
drivers/i2c/busses/i2c-rcar.c
··· 329 329 if (priv->msgs_left == 1) 330 330 priv->flags |= ID_LAST_MSG; 331 331 332 - rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); 332 + rcar_i2c_write(priv, ICMAR, i2c_8bit_addr_from_msg(priv->msg)); 333 333 /* 334 334 * We don't have a test case but the HW engineers say that the write order 335 335 * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since ··· 542 542 * If next received data is the _LAST_, go to STOP phase. Might be 543 543 * overwritten by REP START when setting up a new msg. Not elegant 544 544 * but the only stable sequence for REP START I have found so far. 545 + * If you want to change this code, make sure sending one transfer with 546 + * four messages (WR-RD-WR-RD) works! 545 547 */ 546 548 if (priv->pos + 1 >= msg->len) 547 549 rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP);
+2 -3
drivers/i2c/busses/i2c-riic.c
··· 167 167 return IRQ_NONE; 168 168 169 169 if (riic->bytes_left == RIIC_INIT_MSG) { 170 - val = !!(riic->msg->flags & I2C_M_RD); 171 - if (val) 170 + if (riic->msg->flags & I2C_M_RD) 172 171 /* On read, switch over to receive interrupt */ 173 172 riic_clear_set_bit(riic, ICIER_TIE, ICIER_RIE, RIIC_ICIER); 174 173 else 175 174 /* On write, initialize length */ 176 175 riic->bytes_left = riic->msg->len; 177 176 178 - val |= (riic->msg->addr << 1); 177 + val = i2c_8bit_addr_from_msg(riic->msg); 179 178 } else { 180 179 val = *riic->buf; 181 180 riic->buf++;
-2
drivers/i2c/busses/i2c-rk3x.c
··· 1326 1326 if (ret < 0) 1327 1327 goto err_clk_notifier; 1328 1328 1329 - dev_info(&pdev->dev, "Initialized RK3xxx I2C bus at %p\n", i2c->regs); 1330 - 1331 1329 return 0; 1332 1330 1333 1331 err_clk_notifier:
+9 -12
drivers/i2c/busses/i2c-robotfuzz-osif.c
··· 62 62 { 63 63 struct osif_priv *priv = adapter->algo_data; 64 64 struct i2c_msg *pmsg; 65 - int ret = 0; 66 - int i, cmd; 65 + int ret; 66 + int i; 67 67 68 - for (i = 0; ret >= 0 && i < num; i++) { 68 + for (i = 0; i < num; i++) { 69 69 pmsg = &msgs[i]; 70 70 71 71 if (pmsg->flags & I2C_M_RD) { 72 - cmd = OSIFI2C_READ; 73 - 74 - ret = osif_usb_read(adapter, cmd, pmsg->flags, 75 - pmsg->addr, pmsg->buf, 76 - pmsg->len); 72 + ret = osif_usb_read(adapter, OSIFI2C_READ, 73 + pmsg->flags, pmsg->addr, 74 + pmsg->buf, pmsg->len); 77 75 if (ret != pmsg->len) { 78 76 dev_err(&adapter->dev, "failure reading data\n"); 79 77 return -EREMOTEIO; 80 78 } 81 79 } else { 82 - cmd = OSIFI2C_WRITE; 83 - 84 - ret = osif_usb_write(adapter, cmd, pmsg->flags, 85 - pmsg->addr, pmsg->buf, pmsg->len); 80 + ret = osif_usb_write(adapter, OSIFI2C_WRITE, 81 + pmsg->flags, pmsg->addr, 82 + pmsg->buf, pmsg->len); 86 83 if (ret != pmsg->len) { 87 84 dev_err(&adapter->dev, "failure writing data\n"); 88 85 return -EREMOTEIO;
-2
drivers/i2c/busses/i2c-s3c2410.c
··· 154 154 { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 }, 155 155 { .compatible = "samsung,s3c2440-hdmiphy-i2c", 156 156 .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) }, 157 - { .compatible = "samsung,exynos5440-i2c", 158 - .data = (void *)(QUIRK_S3C2440 | QUIRK_NO_GPIO) }, 159 157 { .compatible = "samsung,exynos5-sata-phy-i2c", 160 158 .data = (void *)(QUIRK_S3C2440 | QUIRK_POLL | QUIRK_NO_GPIO) }, 161 159 {},
-11
drivers/i2c/busses/i2c-sh_mobile.c
··· 899 899 if (resource_size(res) > 0x17) 900 900 pd->flags |= IIC_FLAG_HAS_ICIC67; 901 901 902 - /* Enable Runtime PM for this device. 903 - * 904 - * Also tell the Runtime PM core to ignore children 905 - * for this device since it is valid for us to suspend 906 - * this I2C master driver even though the slave devices 907 - * on the I2C bus may not be suspended. 908 - * 909 - * The state of the I2C hardware bus is unaffected by 910 - * the Runtime PM state. 911 - */ 912 - pm_suspend_ignore_children(&dev->dev, true); 913 902 pm_runtime_enable(&dev->dev); 914 903 pm_runtime_get_sync(&dev->dev); 915 904
+153
drivers/i2c/busses/i2c-stm32.c
··· 1 + /* 2 + * i2c-stm32.c 3 + * 4 + * Copyright (C) M'boumba Cedric Madianga 2017 5 + * Author: M'boumba Cedric Madianga <cedric.madianga@gmail.com> 6 + * 7 + * License terms: GNU General Public License (GPL), version 2 8 + */ 9 + 10 + #include "i2c-stm32.h" 11 + 12 + /* Functions for DMA support */ 13 + struct stm32_i2c_dma *stm32_i2c_dma_request(struct device *dev, 14 + dma_addr_t phy_addr, 15 + u32 txdr_offset, 16 + u32 rxdr_offset) 17 + { 18 + struct stm32_i2c_dma *dma; 19 + struct dma_slave_config dma_sconfig; 20 + int ret; 21 + 22 + dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); 23 + if (!dma) 24 + return NULL; 25 + 26 + /* Request and configure I2C TX dma channel */ 27 + dma->chan_tx = dma_request_slave_channel(dev, "tx"); 28 + if (!dma->chan_tx) { 29 + dev_dbg(dev, "can't request DMA tx channel\n"); 30 + ret = -EINVAL; 31 + goto fail_al; 32 + } 33 + 34 + memset(&dma_sconfig, 0, sizeof(dma_sconfig)); 35 + dma_sconfig.dst_addr = phy_addr + txdr_offset; 36 + dma_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 37 + dma_sconfig.dst_maxburst = 1; 38 + dma_sconfig.direction = DMA_MEM_TO_DEV; 39 + ret = dmaengine_slave_config(dma->chan_tx, &dma_sconfig); 40 + if (ret < 0) { 41 + dev_err(dev, "can't configure tx channel\n"); 42 + goto fail_tx; 43 + } 44 + 45 + /* Request and configure I2C RX dma channel */ 46 + dma->chan_rx = dma_request_slave_channel(dev, "rx"); 47 + if (!dma->chan_rx) { 48 + dev_err(dev, "can't request DMA rx channel\n"); 49 + ret = -EINVAL; 50 + goto fail_tx; 51 + } 52 + 53 + memset(&dma_sconfig, 0, sizeof(dma_sconfig)); 54 + dma_sconfig.src_addr = phy_addr + rxdr_offset; 55 + dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 56 + dma_sconfig.src_maxburst = 1; 57 + dma_sconfig.direction = DMA_DEV_TO_MEM; 58 + ret = dmaengine_slave_config(dma->chan_rx, &dma_sconfig); 59 + if (ret < 0) { 60 + dev_err(dev, "can't configure rx channel\n"); 61 + goto fail_rx; 62 + } 63 + 64 + init_completion(&dma->dma_complete); 65 + 66 + dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", 67 + dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); 68 + 69 + return dma; 70 + 71 + fail_rx: 72 + dma_release_channel(dma->chan_rx); 73 + fail_tx: 74 + dma_release_channel(dma->chan_tx); 75 + fail_al: 76 + devm_kfree(dev, dma); 77 + dev_info(dev, "can't use DMA\n"); 78 + 79 + return NULL; 80 + } 81 + 82 + void stm32_i2c_dma_free(struct stm32_i2c_dma *dma) 83 + { 84 + dma->dma_buf = 0; 85 + dma->dma_len = 0; 86 + 87 + dma_release_channel(dma->chan_tx); 88 + dma->chan_tx = NULL; 89 + 90 + dma_release_channel(dma->chan_rx); 91 + dma->chan_rx = NULL; 92 + 93 + dma->chan_using = NULL; 94 + } 95 + 96 + int stm32_i2c_prep_dma_xfer(struct device *dev, struct stm32_i2c_dma *dma, 97 + bool rd_wr, u32 len, u8 *buf, 98 + dma_async_tx_callback callback, 99 + void *dma_async_param) 100 + { 101 + struct dma_async_tx_descriptor *txdesc; 102 + struct device *chan_dev; 103 + int ret; 104 + 105 + if (rd_wr) { 106 + dma->chan_using = dma->chan_rx; 107 + dma->dma_transfer_dir = DMA_DEV_TO_MEM; 108 + dma->dma_data_dir = DMA_FROM_DEVICE; 109 + } else { 110 + dma->chan_using = dma->chan_tx; 111 + dma->dma_transfer_dir = DMA_MEM_TO_DEV; 112 + dma->dma_data_dir = DMA_TO_DEVICE; 113 + } 114 + 115 + dma->dma_len = len; 116 + chan_dev = dma->chan_using->device->dev; 117 + 118 + dma->dma_buf = dma_map_single(chan_dev, buf, dma->dma_len, 119 + dma->dma_data_dir); 120 + if (dma_mapping_error(chan_dev, dma->dma_buf)) { 121 + dev_err(dev, "DMA mapping failed\n"); 122 + return -EINVAL; 123 + } 124 + 125 + txdesc = dmaengine_prep_slave_single(dma->chan_using, dma->dma_buf, 126 + dma->dma_len, 127 + dma->dma_transfer_dir, 128 + DMA_PREP_INTERRUPT); 129 + if (!txdesc) { 130 + dev_err(dev, "Not able to get desc for DMA xfer\n"); 131 + ret = -EINVAL; 132 + goto err; 133 + } 134 + 135 + reinit_completion(&dma->dma_complete); 136 + 137 + txdesc->callback = callback; 138 + txdesc->callback_param = dma_async_param; 139 + ret = dma_submit_error(dmaengine_submit(txdesc)); 140 + if (ret < 0) { 141 + dev_err(dev, "DMA submit failed\n"); 142 + goto err; 143 + } 144 + 145 + dma_async_issue_pending(dma->chan_using); 146 + 147 + return 0; 148 + 149 + err: 150 + dma_unmap_single(chan_dev, dma->dma_buf, dma->dma_len, 151 + dma->dma_data_dir); 152 + return ret; 153 + }
+37
drivers/i2c/busses/i2c-stm32.h
··· 11 11 #ifndef _I2C_STM32_H 12 12 #define _I2C_STM32_H 13 13 14 + #include <linux/dma-direction.h> 15 + #include <linux/dmaengine.h> 16 + #include <linux/dma-mapping.h> 17 + 14 18 enum stm32_i2c_speed { 15 19 STM32_I2C_SPEED_STANDARD, /* 100 kHz */ 16 20 STM32_I2C_SPEED_FAST, /* 400 kHz */ 17 21 STM32_I2C_SPEED_FAST_PLUS, /* 1 MHz */ 18 22 STM32_I2C_SPEED_END, 19 23 }; 24 + 25 + /** 26 + * struct stm32_i2c_dma - DMA specific data 27 + * @chan_tx: dma channel for TX transfer 28 + * @chan_rx: dma channel for RX transfer 29 + * @chan_using: dma channel used for the current transfer (TX or RX) 30 + * @dma_buf: dma buffer 31 + * @dma_len: dma buffer len 32 + * @dma_transfer_dir: dma transfer direction indicator 33 + * @dma_data_dir: dma transfer mode indicator 34 + * @dma_complete: dma transfer completion 35 + */ 36 + struct stm32_i2c_dma { 37 + struct dma_chan *chan_tx; 38 + struct dma_chan *chan_rx; 39 + struct dma_chan *chan_using; 40 + dma_addr_t dma_buf; 41 + unsigned int dma_len; 42 + enum dma_transfer_direction dma_transfer_dir; 43 + enum dma_data_direction dma_data_dir; 44 + struct completion dma_complete; 45 + }; 46 + 47 + struct stm32_i2c_dma *stm32_i2c_dma_request(struct device *dev, 48 + dma_addr_t phy_addr, 49 + u32 txdr_offset, u32 rxdr_offset); 50 + 51 + void stm32_i2c_dma_free(struct stm32_i2c_dma *dma); 52 + 53 + int stm32_i2c_prep_dma_xfer(struct device *dev, struct stm32_i2c_dma *dma, 54 + bool rd_wr, u32 len, u8 *buf, 55 + dma_async_tx_callback callback, 56 + void *dma_async_param); 20 57 21 58 #endif /* _I2C_STM32_H */
+1019 -30
drivers/i2c/busses/i2c-stm32f7.c
··· 35 35 /* STM32F7 I2C registers */ 36 36 #define STM32F7_I2C_CR1 0x00 37 37 #define STM32F7_I2C_CR2 0x04 38 + #define STM32F7_I2C_OAR1 0x08 39 + #define STM32F7_I2C_OAR2 0x0C 40 + #define STM32F7_I2C_PECR 0x20 38 41 #define STM32F7_I2C_TIMINGR 0x10 39 42 #define STM32F7_I2C_ISR 0x18 40 43 #define STM32F7_I2C_ICR 0x1C ··· 45 42 #define STM32F7_I2C_TXDR 0x28 46 43 47 44 /* STM32F7 I2C control 1 */ 45 + #define STM32F7_I2C_CR1_PECEN BIT(23) 46 + #define STM32F7_I2C_CR1_SBC BIT(16) 47 + #define STM32F7_I2C_CR1_RXDMAEN BIT(15) 48 + #define STM32F7_I2C_CR1_TXDMAEN BIT(14) 48 49 #define STM32F7_I2C_CR1_ANFOFF BIT(12) 49 50 #define STM32F7_I2C_CR1_ERRIE BIT(7) 50 51 #define STM32F7_I2C_CR1_TCIE BIT(6) ··· 64 57 | STM32F7_I2C_CR1_NACKIE \ 65 58 | STM32F7_I2C_CR1_RXIE \ 66 59 | STM32F7_I2C_CR1_TXIE) 60 + #define STM32F7_I2C_XFER_IRQ_MASK (STM32F7_I2C_CR1_TCIE \ 61 + | STM32F7_I2C_CR1_STOPIE \ 62 + | STM32F7_I2C_CR1_NACKIE \ 63 + | STM32F7_I2C_CR1_RXIE \ 64 + | STM32F7_I2C_CR1_TXIE) 67 65 68 66 /* STM32F7 I2C control 2 */ 67 + #define STM32F7_I2C_CR2_PECBYTE BIT(26) 69 68 #define STM32F7_I2C_CR2_RELOAD BIT(24) 70 69 #define STM32F7_I2C_CR2_NBYTES_MASK GENMASK(23, 16) 71 70 #define STM32F7_I2C_CR2_NBYTES(n) (((n) & 0xff) << 16) 72 71 #define STM32F7_I2C_CR2_NACK BIT(15) 73 72 #define STM32F7_I2C_CR2_STOP BIT(14) 74 73 #define STM32F7_I2C_CR2_START BIT(13) 74 + #define STM32F7_I2C_CR2_HEAD10R BIT(12) 75 + #define STM32F7_I2C_CR2_ADD10 BIT(11) 75 76 #define STM32F7_I2C_CR2_RD_WRN BIT(10) 77 + #define STM32F7_I2C_CR2_SADD10_MASK GENMASK(9, 0) 78 + #define STM32F7_I2C_CR2_SADD10(n) (((n) & \ 79 + STM32F7_I2C_CR2_SADD10_MASK)) 76 80 #define STM32F7_I2C_CR2_SADD7_MASK GENMASK(7, 1) 77 81 #define STM32F7_I2C_CR2_SADD7(n) (((n) & 0x7f) << 1) 78 82 83 + /* STM32F7 I2C Own Address 1 */ 84 + #define STM32F7_I2C_OAR1_OA1EN BIT(15) 85 + #define STM32F7_I2C_OAR1_OA1MODE BIT(10) 86 + #define STM32F7_I2C_OAR1_OA1_10_MASK GENMASK(9, 0) 87 + #define STM32F7_I2C_OAR1_OA1_10(n) (((n) & \ 88 + STM32F7_I2C_OAR1_OA1_10_MASK)) 89 + #define STM32F7_I2C_OAR1_OA1_7_MASK GENMASK(7, 1) 90 + #define STM32F7_I2C_OAR1_OA1_7(n) (((n) & 0x7f) << 1) 91 + #define STM32F7_I2C_OAR1_MASK (STM32F7_I2C_OAR1_OA1_7_MASK \ 92 + | STM32F7_I2C_OAR1_OA1_10_MASK \ 93 + | STM32F7_I2C_OAR1_OA1EN \ 94 + | STM32F7_I2C_OAR1_OA1MODE) 95 + 96 + /* STM32F7 I2C Own Address 2 */ 97 + #define STM32F7_I2C_OAR2_OA2EN BIT(15) 98 + #define STM32F7_I2C_OAR2_OA2MSK_MASK GENMASK(10, 8) 99 + #define STM32F7_I2C_OAR2_OA2MSK(n) (((n) & 0x7) << 8) 100 + #define STM32F7_I2C_OAR2_OA2_7_MASK GENMASK(7, 1) 101 + #define STM32F7_I2C_OAR2_OA2_7(n) (((n) & 0x7f) << 1) 102 + #define STM32F7_I2C_OAR2_MASK (STM32F7_I2C_OAR2_OA2MSK_MASK \ 103 + | STM32F7_I2C_OAR2_OA2_7_MASK \ 104 + | STM32F7_I2C_OAR2_OA2EN) 105 + 79 106 /* STM32F7 I2C Interrupt Status */ 107 + #define STM32F7_I2C_ISR_ADDCODE_MASK GENMASK(23, 17) 108 + #define STM32F7_I2C_ISR_ADDCODE_GET(n) \ 109 + (((n) & STM32F7_I2C_ISR_ADDCODE_MASK) >> 17) 110 + #define STM32F7_I2C_ISR_DIR BIT(16) 80 111 #define STM32F7_I2C_ISR_BUSY BIT(15) 112 + #define STM32F7_I2C_ISR_PECERR BIT(11) 81 113 #define STM32F7_I2C_ISR_ARLO BIT(9) 82 114 #define STM32F7_I2C_ISR_BERR BIT(8) 83 115 #define STM32F7_I2C_ISR_TCR BIT(7) 84 116 #define STM32F7_I2C_ISR_TC BIT(6) 85 117 #define STM32F7_I2C_ISR_STOPF BIT(5) 86 118 #define STM32F7_I2C_ISR_NACKF BIT(4) 119 + #define STM32F7_I2C_ISR_ADDR BIT(3) 87 120 #define STM32F7_I2C_ISR_RXNE BIT(2) 88 121 #define STM32F7_I2C_ISR_TXIS BIT(1) 122 + #define STM32F7_I2C_ISR_TXE BIT(0) 89 123 90 124 /* STM32F7 I2C Interrupt Clear */ 125 + #define STM32F7_I2C_ICR_PECCF BIT(11) 91 126 #define STM32F7_I2C_ICR_ARLOCF BIT(9) 92 127 #define STM32F7_I2C_ICR_BERRCF BIT(8) 93 128 #define STM32F7_I2C_ICR_STOPCF BIT(5) 94 129 #define STM32F7_I2C_ICR_NACKCF BIT(4) 130 + #define STM32F7_I2C_ICR_ADDRCF BIT(3) 95 131 96 132 /* STM32F7 I2C Timing */ 97 133 #define STM32F7_I2C_TIMINGR_PRESC(n) (((n) & 0xf) << 28) ··· 144 94 #define STM32F7_I2C_TIMINGR_SCLL(n) ((n) & 0xff) 145 95 146 96 #define STM32F7_I2C_MAX_LEN 0xff 97 + #define STM32F7_I2C_DMA_LEN_MIN 0x16 98 + #define STM32F7_I2C_MAX_SLAVE 0x2 147 99 148 100 #define STM32F7_I2C_DNF_DEFAULT 0 149 101 #define STM32F7_I2C_DNF_MAX 16 ··· 211 159 212 160 /** 213 161 * struct stm32f7_i2c_timings - private I2C output parameters 214 - * @prec: Prescaler value 162 + * @node: List entry 163 + * @presc: Prescaler value 215 164 * @scldel: Data setup time 216 165 * @sdadel: Data hold time 217 166 * @sclh: SCL high period (master mode) 218 - * @sclh: SCL low period (master mode) 167 + * @scll: SCL low period (master mode) 219 168 */ 220 169 struct stm32f7_i2c_timings { 221 170 struct list_head node; ··· 229 176 230 177 /** 231 178 * struct stm32f7_i2c_msg - client specific data 232 - * @addr: 8-bit slave addr, including r/w bit 179 + * @addr: 8-bit or 10-bit slave addr, including r/w bit 233 180 * @count: number of bytes to be transferred 234 181 * @buf: data buffer 235 182 * @result: result of the transfer 236 183 * @stop: last I2C msg to be sent, i.e. STOP to be generated 184 + * @smbus: boolean to know if the I2C IP is used in SMBus mode 185 + * @size: type of SMBus protocol 186 + * @read_write: direction of SMBus protocol 187 + * SMBus block read and SMBus block write - block read process call protocols 188 + * @smbus_buf: buffer to be used for SMBus protocol transfer. It will 189 + * contain a maximum of 32 bytes of data + byte command + byte count + PEC 190 + * This buffer has to be 32-bit aligned to be compliant with memory address 191 + * register in DMA mode. 237 192 */ 238 193 struct stm32f7_i2c_msg { 239 - u8 addr; 194 + u16 addr; 240 195 u32 count; 241 196 u8 *buf; 242 197 int result; 243 198 bool stop; 199 + bool smbus; 200 + int size; 201 + char read_write; 202 + u8 smbus_buf[I2C_SMBUS_BLOCK_MAX + 3] __aligned(4); 244 203 }; 245 204 246 205 /** ··· 269 204 * @f7_msg: customized i2c msg for driver usage 270 205 * @setup: I2C timing input setup 271 206 * @timing: I2C computed timings 207 + * @slave: list of slave devices registered on the I2C bus 208 + * @slave_running: slave device currently used 209 + * @slave_dir: transfer direction for the current slave device 210 + * @master_mode: boolean to know in which mode the I2C is running (master or 211 + * slave) 212 + * @dma: dma data 213 + * @use_dma: boolean to know if dma is used in the current transfer 272 214 */ 273 215 struct stm32f7_i2c_dev { 274 216 struct i2c_adapter adap; ··· 290 218 struct stm32f7_i2c_msg f7_msg; 291 219 struct stm32f7_i2c_setup setup; 292 220 struct stm32f7_i2c_timings timing; 221 + struct i2c_client *slave[STM32F7_I2C_MAX_SLAVE]; 222 + struct i2c_client *slave_running; 223 + u32 slave_dir; 224 + bool master_mode; 225 + struct stm32_i2c_dma *dma; 226 + bool use_dma; 293 227 }; 294 228 295 229 /** ··· 359 281 static inline void stm32f7_i2c_clr_bits(void __iomem *reg, u32 mask) 360 282 { 361 283 writel_relaxed(readl_relaxed(reg) & ~mask, reg); 284 + } 285 + 286 + static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask) 287 + { 288 + stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); 362 289 } 363 290 364 291 static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev, ··· 607 524 return 0; 608 525 } 609 526 527 + static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev) 528 + { 529 + void __iomem *base = i2c_dev->base; 530 + u32 mask = STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN; 531 + 532 + stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR1, mask); 533 + } 534 + 535 + static void stm32f7_i2c_dma_callback(void *arg) 536 + { 537 + struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg; 538 + struct stm32_i2c_dma *dma = i2c_dev->dma; 539 + struct device *dev = dma->chan_using->device->dev; 540 + 541 + stm32f7_i2c_disable_dma_req(i2c_dev); 542 + dma_unmap_single(dev, dma->dma_buf, dma->dma_len, dma->dma_data_dir); 543 + complete(&dma->dma_complete); 544 + } 545 + 610 546 static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev) 611 547 { 612 548 struct stm32f7_i2c_timings *t = &i2c_dev->timing; ··· 669 567 if (f7_msg->count) { 670 568 *f7_msg->buf++ = readb_relaxed(base + STM32F7_I2C_RXDR); 671 569 f7_msg->count--; 570 + } else { 571 + /* Flush RX buffer has no data is expected */ 572 + readb_relaxed(base + STM32F7_I2C_RXDR); 672 573 } 673 574 } 674 575 ··· 679 574 { 680 575 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 681 576 u32 cr2; 577 + 578 + if (i2c_dev->use_dma) 579 + f7_msg->count -= STM32F7_I2C_MAX_LEN; 682 580 683 581 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); 684 582 ··· 696 588 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); 697 589 } 698 590 591 + static void stm32f7_i2c_smbus_reload(struct stm32f7_i2c_dev *i2c_dev) 592 + { 593 + struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 594 + u32 cr2; 595 + u8 *val; 596 + 597 + /* 598 + * For I2C_SMBUS_BLOCK_DATA && I2C_SMBUS_BLOCK_PROC_CALL, the first 599 + * data received inform us how many data will follow. 600 + */ 601 + stm32f7_i2c_read_rx_data(i2c_dev); 602 + 603 + /* 604 + * Update NBYTES with the value read to continue the transfer 605 + */ 606 + val = f7_msg->buf - sizeof(u8); 607 + f7_msg->count = *val; 608 + cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); 609 + cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD); 610 + cr2 |= STM32F7_I2C_CR2_NBYTES(f7_msg->count); 611 + writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); 612 + } 613 + 614 + static int stm32f7_i2c_release_bus(struct i2c_adapter *i2c_adap) 615 + { 616 + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); 617 + 618 + dev_info(i2c_dev->dev, "Trying to recover bus\n"); 619 + 620 + stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, 621 + STM32F7_I2C_CR1_PE); 622 + 623 + stm32f7_i2c_hw_config(i2c_dev); 624 + 625 + return 0; 626 + } 627 + 699 628 static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev) 700 629 { 701 630 u32 status; ··· 742 597 status, 743 598 !(status & STM32F7_I2C_ISR_BUSY), 744 599 10, 1000); 600 + if (!ret) 601 + return 0; 602 + 603 + dev_info(i2c_dev->dev, "bus busy\n"); 604 + 605 + ret = stm32f7_i2c_release_bus(&i2c_dev->adap); 745 606 if (ret) { 746 - dev_dbg(i2c_dev->dev, "bus busy\n"); 747 - ret = -EBUSY; 607 + dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret); 608 + return ret; 748 609 } 749 610 750 - return ret; 611 + return -EBUSY; 751 612 } 752 613 753 614 static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, ··· 762 611 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 763 612 void __iomem *base = i2c_dev->base; 764 613 u32 cr1, cr2; 614 + int ret; 765 615 766 616 f7_msg->addr = msg->addr; 767 617 f7_msg->buf = msg->buf; ··· 781 629 cr2 |= STM32F7_I2C_CR2_RD_WRN; 782 630 783 631 /* Set slave address */ 784 - cr2 &= ~STM32F7_I2C_CR2_SADD7_MASK; 785 - cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr); 632 + cr2 &= ~(STM32F7_I2C_CR2_HEAD10R | STM32F7_I2C_CR2_ADD10); 633 + if (msg->flags & I2C_M_TEN) { 634 + cr2 &= ~STM32F7_I2C_CR2_SADD10_MASK; 635 + cr2 |= STM32F7_I2C_CR2_SADD10(f7_msg->addr); 636 + cr2 |= STM32F7_I2C_CR2_ADD10; 637 + } else { 638 + cr2 &= ~STM32F7_I2C_CR2_SADD7_MASK; 639 + cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr); 640 + } 786 641 787 642 /* Set nb bytes to transfer and reload if needed */ 788 643 cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD); ··· 804 645 cr1 |= STM32F7_I2C_CR1_ERRIE | STM32F7_I2C_CR1_TCIE | 805 646 STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE; 806 647 807 - /* Clear TX/RX interrupt */ 808 - cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE); 648 + /* Clear DMA req and TX/RX interrupt */ 649 + cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE | 650 + STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN); 809 651 810 - /* Enable RX/TX interrupt according to msg direction */ 811 - if (msg->flags & I2C_M_RD) 812 - cr1 |= STM32F7_I2C_CR1_RXIE; 813 - else 814 - cr1 |= STM32F7_I2C_CR1_TXIE; 652 + /* Configure DMA or enable RX/TX interrupt */ 653 + i2c_dev->use_dma = false; 654 + if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { 655 + ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, 656 + msg->flags & I2C_M_RD, 657 + f7_msg->count, f7_msg->buf, 658 + stm32f7_i2c_dma_callback, 659 + i2c_dev); 660 + if (!ret) 661 + i2c_dev->use_dma = true; 662 + else 663 + dev_warn(i2c_dev->dev, "can't use DMA\n"); 664 + } 665 + 666 + if (!i2c_dev->use_dma) { 667 + if (msg->flags & I2C_M_RD) 668 + cr1 |= STM32F7_I2C_CR1_RXIE; 669 + else 670 + cr1 |= STM32F7_I2C_CR1_TXIE; 671 + } else { 672 + if (msg->flags & I2C_M_RD) 673 + cr1 |= STM32F7_I2C_CR1_RXDMAEN; 674 + else 675 + cr1 |= STM32F7_I2C_CR1_TXDMAEN; 676 + } 815 677 816 678 /* Configure Start/Repeated Start */ 679 + cr2 |= STM32F7_I2C_CR2_START; 680 + 681 + i2c_dev->master_mode = true; 682 + 683 + /* Write configurations registers */ 684 + writel_relaxed(cr1, base + STM32F7_I2C_CR1); 685 + writel_relaxed(cr2, base + STM32F7_I2C_CR2); 686 + } 687 + 688 + static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, 689 + unsigned short flags, u8 command, 690 + union i2c_smbus_data *data) 691 + { 692 + struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 693 + struct device *dev = i2c_dev->dev; 694 + void __iomem *base = i2c_dev->base; 695 + u32 cr1, cr2; 696 + int i, ret; 697 + 698 + f7_msg->result = 0; 699 + reinit_completion(&i2c_dev->complete); 700 + 701 + cr2 = readl_relaxed(base + STM32F7_I2C_CR2); 702 + cr1 = readl_relaxed(base + STM32F7_I2C_CR1); 703 + 704 + /* Set transfer direction */ 705 + cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 706 + if (f7_msg->read_write) 707 + cr2 |= STM32F7_I2C_CR2_RD_WRN; 708 + 709 + /* Set slave address */ 710 + cr2 &= ~(STM32F7_I2C_CR2_ADD10 | STM32F7_I2C_CR2_SADD7_MASK); 711 + cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr); 712 + 713 + f7_msg->smbus_buf[0] = command; 714 + switch (f7_msg->size) { 715 + case I2C_SMBUS_QUICK: 716 + f7_msg->stop = true; 717 + f7_msg->count = 0; 718 + break; 719 + case I2C_SMBUS_BYTE: 720 + f7_msg->stop = true; 721 + f7_msg->count = 1; 722 + break; 723 + case I2C_SMBUS_BYTE_DATA: 724 + if (f7_msg->read_write) { 725 + f7_msg->stop = false; 726 + f7_msg->count = 1; 727 + cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 728 + } else { 729 + f7_msg->stop = true; 730 + f7_msg->count = 2; 731 + f7_msg->smbus_buf[1] = data->byte; 732 + } 733 + break; 734 + case I2C_SMBUS_WORD_DATA: 735 + if (f7_msg->read_write) { 736 + f7_msg->stop = false; 737 + f7_msg->count = 1; 738 + cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 739 + } else { 740 + f7_msg->stop = true; 741 + f7_msg->count = 3; 742 + f7_msg->smbus_buf[1] = data->word & 0xff; 743 + f7_msg->smbus_buf[2] = data->word >> 8; 744 + } 745 + break; 746 + case I2C_SMBUS_BLOCK_DATA: 747 + if (f7_msg->read_write) { 748 + f7_msg->stop = false; 749 + f7_msg->count = 1; 750 + cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 751 + } else { 752 + f7_msg->stop = true; 753 + if (data->block[0] > I2C_SMBUS_BLOCK_MAX || 754 + !data->block[0]) { 755 + dev_err(dev, "Invalid block write size %d\n", 756 + data->block[0]); 757 + return -EINVAL; 758 + } 759 + f7_msg->count = data->block[0] + 2; 760 + for (i = 1; i < f7_msg->count; i++) 761 + f7_msg->smbus_buf[i] = data->block[i - 1]; 762 + } 763 + break; 764 + case I2C_SMBUS_PROC_CALL: 765 + f7_msg->stop = false; 766 + f7_msg->count = 3; 767 + f7_msg->smbus_buf[1] = data->word & 0xff; 768 + f7_msg->smbus_buf[2] = data->word >> 8; 769 + cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 770 + f7_msg->read_write = I2C_SMBUS_READ; 771 + break; 772 + case I2C_SMBUS_BLOCK_PROC_CALL: 773 + f7_msg->stop = false; 774 + if (data->block[0] > I2C_SMBUS_BLOCK_MAX - 1) { 775 + dev_err(dev, "Invalid block write size %d\n", 776 + data->block[0]); 777 + return -EINVAL; 778 + } 779 + f7_msg->count = data->block[0] + 2; 780 + for (i = 1; i < f7_msg->count; i++) 781 + f7_msg->smbus_buf[i] = data->block[i - 1]; 782 + cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 783 + f7_msg->read_write = I2C_SMBUS_READ; 784 + break; 785 + default: 786 + dev_err(dev, "Unsupported smbus protocol %d\n", f7_msg->size); 787 + return -EOPNOTSUPP; 788 + } 789 + 790 + f7_msg->buf = f7_msg->smbus_buf; 791 + 792 + /* Configure PEC */ 793 + if ((flags & I2C_CLIENT_PEC) && f7_msg->size != I2C_SMBUS_QUICK) { 794 + cr1 |= STM32F7_I2C_CR1_PECEN; 795 + cr2 |= STM32F7_I2C_CR2_PECBYTE; 796 + if (!f7_msg->read_write) 797 + f7_msg->count++; 798 + } else { 799 + cr1 &= ~STM32F7_I2C_CR1_PECEN; 800 + cr2 &= ~STM32F7_I2C_CR2_PECBYTE; 801 + } 802 + 803 + /* Set number of bytes to be transferred */ 804 + cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD); 805 + cr2 |= STM32F7_I2C_CR2_NBYTES(f7_msg->count); 806 + 807 + /* Enable NACK, STOP, error and transfer complete interrupts */ 808 + cr1 |= STM32F7_I2C_CR1_ERRIE | STM32F7_I2C_CR1_TCIE | 809 + STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE; 810 + 811 + /* Clear DMA req and TX/RX interrupt */ 812 + cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE | 813 + STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN); 814 + 815 + /* Configure DMA or enable RX/TX interrupt */ 816 + i2c_dev->use_dma = false; 817 + if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { 818 + ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, 819 + cr2 & STM32F7_I2C_CR2_RD_WRN, 820 + f7_msg->count, f7_msg->buf, 821 + stm32f7_i2c_dma_callback, 822 + i2c_dev); 823 + if (!ret) 824 + i2c_dev->use_dma = true; 825 + else 826 + dev_warn(i2c_dev->dev, "can't use DMA\n"); 827 + } 828 + 829 + if (!i2c_dev->use_dma) { 830 + if (cr2 & STM32F7_I2C_CR2_RD_WRN) 831 + cr1 |= STM32F7_I2C_CR1_RXIE; 832 + else 833 + cr1 |= STM32F7_I2C_CR1_TXIE; 834 + } else { 835 + if (cr2 & STM32F7_I2C_CR2_RD_WRN) 836 + cr1 |= STM32F7_I2C_CR1_RXDMAEN; 837 + else 838 + cr1 |= STM32F7_I2C_CR1_TXDMAEN; 839 + } 840 + 841 + /* Set Start bit */ 842 + cr2 |= STM32F7_I2C_CR2_START; 843 + 844 + i2c_dev->master_mode = true; 845 + 846 + /* Write configurations registers */ 847 + writel_relaxed(cr1, base + STM32F7_I2C_CR1); 848 + writel_relaxed(cr2, base + STM32F7_I2C_CR2); 849 + 850 + return 0; 851 + } 852 + 853 + static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev) 854 + { 855 + struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 856 + void __iomem *base = i2c_dev->base; 857 + u32 cr1, cr2; 858 + int ret; 859 + 860 + cr2 = readl_relaxed(base + STM32F7_I2C_CR2); 861 + cr1 = readl_relaxed(base + STM32F7_I2C_CR1); 862 + 863 + /* Set transfer direction */ 864 + cr2 |= STM32F7_I2C_CR2_RD_WRN; 865 + 866 + switch (f7_msg->size) { 867 + case I2C_SMBUS_BYTE_DATA: 868 + f7_msg->count = 1; 869 + break; 870 + case I2C_SMBUS_WORD_DATA: 871 + case I2C_SMBUS_PROC_CALL: 872 + f7_msg->count = 2; 873 + break; 874 + case I2C_SMBUS_BLOCK_DATA: 875 + case I2C_SMBUS_BLOCK_PROC_CALL: 876 + f7_msg->count = 1; 877 + cr2 |= STM32F7_I2C_CR2_RELOAD; 878 + break; 879 + } 880 + 881 + f7_msg->buf = f7_msg->smbus_buf; 882 + f7_msg->stop = true; 883 + 884 + /* Add one byte for PEC if needed */ 885 + if (cr1 & STM32F7_I2C_CR1_PECEN) 886 + f7_msg->count++; 887 + 888 + /* Set number of bytes to be transferred */ 889 + cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK); 890 + cr2 |= STM32F7_I2C_CR2_NBYTES(f7_msg->count); 891 + 892 + /* 893 + * Configure RX/TX interrupt: 894 + */ 895 + cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE); 896 + cr1 |= STM32F7_I2C_CR1_RXIE; 897 + 898 + /* 899 + * Configure DMA or enable RX/TX interrupt: 900 + * For I2C_SMBUS_BLOCK_DATA and I2C_SMBUS_BLOCK_PROC_CALL we don't use 901 + * dma as we don't know in advance how many data will be received 902 + */ 903 + cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE | 904 + STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN); 905 + 906 + i2c_dev->use_dma = false; 907 + if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN && 908 + f7_msg->size != I2C_SMBUS_BLOCK_DATA && 909 + f7_msg->size != I2C_SMBUS_BLOCK_PROC_CALL) { 910 + ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, 911 + cr2 & STM32F7_I2C_CR2_RD_WRN, 912 + f7_msg->count, f7_msg->buf, 913 + stm32f7_i2c_dma_callback, 914 + i2c_dev); 915 + 916 + if (!ret) 917 + i2c_dev->use_dma = true; 918 + else 919 + dev_warn(i2c_dev->dev, "can't use DMA\n"); 920 + } 921 + 922 + if (!i2c_dev->use_dma) 923 + cr1 |= STM32F7_I2C_CR1_RXIE; 924 + else 925 + cr1 |= STM32F7_I2C_CR1_RXDMAEN; 926 + 927 + /* Configure Repeated Start */ 817 928 cr2 |= STM32F7_I2C_CR2_START; 818 929 819 930 /* Write configurations registers */ ··· 1091 662 writel_relaxed(cr2, base + STM32F7_I2C_CR2); 1092 663 } 1093 664 1094 - static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask) 665 + static int stm32f7_i2c_smbus_check_pec(struct stm32f7_i2c_dev *i2c_dev) 1095 666 { 1096 - stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); 667 + struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 668 + u8 count, internal_pec, received_pec; 669 + 670 + internal_pec = readl_relaxed(i2c_dev->base + STM32F7_I2C_PECR); 671 + 672 + switch (f7_msg->size) { 673 + case I2C_SMBUS_BYTE: 674 + case I2C_SMBUS_BYTE_DATA: 675 + received_pec = f7_msg->smbus_buf[1]; 676 + break; 677 + case I2C_SMBUS_WORD_DATA: 678 + case I2C_SMBUS_PROC_CALL: 679 + received_pec = f7_msg->smbus_buf[2]; 680 + break; 681 + case I2C_SMBUS_BLOCK_DATA: 682 + case I2C_SMBUS_BLOCK_PROC_CALL: 683 + count = f7_msg->smbus_buf[0]; 684 + received_pec = f7_msg->smbus_buf[count]; 685 + break; 686 + default: 687 + dev_err(i2c_dev->dev, "Unsupported smbus protocol for PEC\n"); 688 + return -EINVAL; 689 + } 690 + 691 + if (internal_pec != received_pec) { 692 + dev_err(i2c_dev->dev, "Bad PEC 0x%02x vs. 0x%02x\n", 693 + internal_pec, received_pec); 694 + return -EBADMSG; 695 + } 696 + 697 + return 0; 698 + } 699 + 700 + static bool stm32f7_i2c_is_addr_match(struct i2c_client *slave, u32 addcode) 701 + { 702 + u32 addr; 703 + 704 + if (!slave) 705 + return false; 706 + 707 + if (slave->flags & I2C_CLIENT_TEN) { 708 + /* 709 + * For 10-bit addr, addcode = 11110XY with 710 + * X = Bit 9 of slave address 711 + * Y = Bit 8 of slave address 712 + */ 713 + addr = slave->addr >> 8; 714 + addr |= 0x78; 715 + if (addr == addcode) 716 + return true; 717 + } else { 718 + addr = slave->addr & 0x7f; 719 + if (addr == addcode) 720 + return true; 721 + } 722 + 723 + return false; 724 + } 725 + 726 + static void stm32f7_i2c_slave_start(struct stm32f7_i2c_dev *i2c_dev) 727 + { 728 + struct i2c_client *slave = i2c_dev->slave_running; 729 + void __iomem *base = i2c_dev->base; 730 + u32 mask; 731 + u8 value = 0; 732 + 733 + if (i2c_dev->slave_dir) { 734 + /* Notify i2c slave that new read transfer is starting */ 735 + i2c_slave_event(slave, I2C_SLAVE_READ_REQUESTED, &value); 736 + 737 + /* 738 + * Disable slave TX config in case of I2C combined message 739 + * (I2C Write followed by I2C Read) 740 + */ 741 + mask = STM32F7_I2C_CR2_RELOAD; 742 + stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR2, mask); 743 + mask = STM32F7_I2C_CR1_SBC | STM32F7_I2C_CR1_RXIE | 744 + STM32F7_I2C_CR1_TCIE; 745 + stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR1, mask); 746 + 747 + /* Enable TX empty, STOP, NACK interrupts */ 748 + mask = STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE | 749 + STM32F7_I2C_CR1_TXIE; 750 + stm32f7_i2c_set_bits(base + STM32F7_I2C_CR1, mask); 751 + 752 + } else { 753 + /* Notify i2c slave that new write transfer is starting */ 754 + i2c_slave_event(slave, I2C_SLAVE_WRITE_REQUESTED, &value); 755 + 756 + /* Set reload mode to be able to ACK/NACK each received byte */ 757 + mask = STM32F7_I2C_CR2_RELOAD; 758 + stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask); 759 + 760 + /* 761 + * Set STOP, NACK, RX empty and transfer complete interrupts.* 762 + * Set Slave Byte Control to be able to ACK/NACK each data 763 + * byte received 764 + */ 765 + mask = STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE | 766 + STM32F7_I2C_CR1_SBC | STM32F7_I2C_CR1_RXIE | 767 + STM32F7_I2C_CR1_TCIE; 768 + stm32f7_i2c_set_bits(base + STM32F7_I2C_CR1, mask); 769 + } 770 + } 771 + 772 + static void stm32f7_i2c_slave_addr(struct stm32f7_i2c_dev *i2c_dev) 773 + { 774 + void __iomem *base = i2c_dev->base; 775 + u32 isr, addcode, dir, mask; 776 + int i; 777 + 778 + isr = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 779 + addcode = STM32F7_I2C_ISR_ADDCODE_GET(isr); 780 + dir = isr & STM32F7_I2C_ISR_DIR; 781 + 782 + for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) { 783 + if (stm32f7_i2c_is_addr_match(i2c_dev->slave[i], addcode)) { 784 + i2c_dev->slave_running = i2c_dev->slave[i]; 785 + i2c_dev->slave_dir = dir; 786 + 787 + /* Start I2C slave processing */ 788 + stm32f7_i2c_slave_start(i2c_dev); 789 + 790 + /* Clear ADDR flag */ 791 + mask = STM32F7_I2C_ICR_ADDRCF; 792 + writel_relaxed(mask, base + STM32F7_I2C_ICR); 793 + break; 794 + } 795 + } 796 + } 797 + 798 + static int stm32f7_i2c_get_slave_id(struct stm32f7_i2c_dev *i2c_dev, 799 + struct i2c_client *slave, int *id) 800 + { 801 + int i; 802 + 803 + for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) { 804 + if (i2c_dev->slave[i] == slave) { 805 + *id = i; 806 + return 0; 807 + } 808 + } 809 + 810 + dev_err(i2c_dev->dev, "Slave 0x%x not registered\n", slave->addr); 811 + 812 + return -ENODEV; 813 + } 814 + 815 + static int stm32f7_i2c_get_free_slave_id(struct stm32f7_i2c_dev *i2c_dev, 816 + struct i2c_client *slave, int *id) 817 + { 818 + struct device *dev = i2c_dev->dev; 819 + int i; 820 + 821 + /* 822 + * slave[0] supports 7-bit and 10-bit slave address 823 + * slave[1] supports 7-bit slave address only 824 + */ 825 + for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) { 826 + if (i == 1 && (slave->flags & I2C_CLIENT_PEC)) 827 + continue; 828 + if (!i2c_dev->slave[i]) { 829 + *id = i; 830 + return 0; 831 + } 832 + } 833 + 834 + dev_err(dev, "Slave 0x%x could not be registered\n", slave->addr); 835 + 836 + return -EINVAL; 837 + } 838 + 839 + static bool stm32f7_i2c_is_slave_registered(struct stm32f7_i2c_dev *i2c_dev) 840 + { 841 + int i; 842 + 843 + for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) { 844 + if (i2c_dev->slave[i]) 845 + return true; 846 + } 847 + 848 + return false; 849 + } 850 + 851 + static bool stm32f7_i2c_is_slave_busy(struct stm32f7_i2c_dev *i2c_dev) 852 + { 853 + int i, busy; 854 + 855 + busy = 0; 856 + for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) { 857 + if (i2c_dev->slave[i]) 858 + busy++; 859 + } 860 + 861 + return i == busy; 862 + } 863 + 864 + static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev) 865 + { 866 + void __iomem *base = i2c_dev->base; 867 + u32 cr2, status, mask; 868 + u8 val; 869 + int ret; 870 + 871 + status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 872 + 873 + /* Slave transmitter mode */ 874 + if (status & STM32F7_I2C_ISR_TXIS) { 875 + i2c_slave_event(i2c_dev->slave_running, 876 + I2C_SLAVE_READ_PROCESSED, 877 + &val); 878 + 879 + /* Write data byte */ 880 + writel_relaxed(val, base + STM32F7_I2C_TXDR); 881 + } 882 + 883 + /* Transfer Complete Reload for Slave receiver mode */ 884 + if (status & STM32F7_I2C_ISR_TCR || status & STM32F7_I2C_ISR_RXNE) { 885 + /* 886 + * Read data byte then set NBYTES to receive next byte or NACK 887 + * the current received byte 888 + */ 889 + val = readb_relaxed(i2c_dev->base + STM32F7_I2C_RXDR); 890 + ret = i2c_slave_event(i2c_dev->slave_running, 891 + I2C_SLAVE_WRITE_RECEIVED, 892 + &val); 893 + if (!ret) { 894 + cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); 895 + cr2 |= STM32F7_I2C_CR2_NBYTES(1); 896 + writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); 897 + } else { 898 + mask = STM32F7_I2C_CR2_NACK; 899 + stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask); 900 + } 901 + } 902 + 903 + /* NACK received */ 904 + if (status & STM32F7_I2C_ISR_NACKF) { 905 + dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); 906 + writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR); 907 + } 908 + 909 + /* STOP received */ 910 + if (status & STM32F7_I2C_ISR_STOPF) { 911 + /* Disable interrupts */ 912 + stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_XFER_IRQ_MASK); 913 + 914 + if (i2c_dev->slave_dir) { 915 + /* 916 + * Flush TX buffer in order to not used the byte in 917 + * TXDR for the next transfer 918 + */ 919 + mask = STM32F7_I2C_ISR_TXE; 920 + stm32f7_i2c_set_bits(base + STM32F7_I2C_ISR, mask); 921 + } 922 + 923 + /* Clear STOP flag */ 924 + writel_relaxed(STM32F7_I2C_ICR_STOPCF, base + STM32F7_I2C_ICR); 925 + 926 + /* Notify i2c slave that a STOP flag has been detected */ 927 + i2c_slave_event(i2c_dev->slave_running, I2C_SLAVE_STOP, &val); 928 + 929 + i2c_dev->slave_running = NULL; 930 + } 931 + 932 + /* Address match received */ 933 + if (status & STM32F7_I2C_ISR_ADDR) 934 + stm32f7_i2c_slave_addr(i2c_dev); 935 + 936 + return IRQ_HANDLED; 1097 937 } 1098 938 1099 939 static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data) ··· 1371 673 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1372 674 void __iomem *base = i2c_dev->base; 1373 675 u32 status, mask; 676 + int ret = IRQ_HANDLED; 677 + 678 + /* Check if the interrupt if for a slave device */ 679 + if (!i2c_dev->master_mode) { 680 + ret = stm32f7_i2c_slave_isr_event(i2c_dev); 681 + return ret; 682 + } 1374 683 1375 684 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 1376 685 ··· 1399 694 /* STOP detection flag */ 1400 695 if (status & STM32F7_I2C_ISR_STOPF) { 1401 696 /* Disable interrupts */ 1402 - stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); 697 + if (stm32f7_i2c_is_slave_registered(i2c_dev)) 698 + mask = STM32F7_I2C_XFER_IRQ_MASK; 699 + else 700 + mask = STM32F7_I2C_ALL_IRQ_MASK; 701 + stm32f7_i2c_disable_irq(i2c_dev, mask); 1403 702 1404 703 /* Clear STOP flag */ 1405 704 writel_relaxed(STM32F7_I2C_ICR_STOPCF, base + STM32F7_I2C_ICR); 1406 705 1407 - complete(&i2c_dev->complete); 706 + if (i2c_dev->use_dma) { 707 + ret = IRQ_WAKE_THREAD; 708 + } else { 709 + i2c_dev->master_mode = false; 710 + complete(&i2c_dev->complete); 711 + } 1408 712 } 1409 713 1410 714 /* Transfer complete */ ··· 1421 707 if (f7_msg->stop) { 1422 708 mask = STM32F7_I2C_CR2_STOP; 1423 709 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask); 710 + } else if (i2c_dev->use_dma) { 711 + ret = IRQ_WAKE_THREAD; 712 + } else if (f7_msg->smbus) { 713 + stm32f7_i2c_smbus_rep_start(i2c_dev); 1424 714 } else { 1425 715 i2c_dev->msg_id++; 1426 716 i2c_dev->msg++; ··· 1432 714 } 1433 715 } 1434 716 717 + if (status & STM32F7_I2C_ISR_TCR) { 718 + if (f7_msg->smbus) 719 + stm32f7_i2c_smbus_reload(i2c_dev); 720 + else 721 + stm32f7_i2c_reload(i2c_dev); 722 + } 723 + 724 + return ret; 725 + } 726 + 727 + static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data) 728 + { 729 + struct stm32f7_i2c_dev *i2c_dev = data; 730 + struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 731 + struct stm32_i2c_dma *dma = i2c_dev->dma; 732 + u32 status; 733 + int ret; 734 + 1435 735 /* 1436 - * Transfer Complete Reload: 255 data bytes have been transferred 1437 - * We have to prepare the I2C controller to transfer the remaining 1438 - * data. 736 + * Wait for dma transfer completion before sending next message or 737 + * notity the end of xfer to the client 1439 738 */ 1440 - if (status & STM32F7_I2C_ISR_TCR) 1441 - stm32f7_i2c_reload(i2c_dev); 739 + ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ); 740 + if (!ret) { 741 + dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__); 742 + stm32f7_i2c_disable_dma_req(i2c_dev); 743 + dmaengine_terminate_all(dma->chan_using); 744 + f7_msg->result = -ETIMEDOUT; 745 + } 746 + 747 + status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 748 + 749 + if (status & STM32F7_I2C_ISR_TC) { 750 + if (f7_msg->smbus) { 751 + stm32f7_i2c_smbus_rep_start(i2c_dev); 752 + } else { 753 + i2c_dev->msg_id++; 754 + i2c_dev->msg++; 755 + stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg); 756 + } 757 + } else { 758 + i2c_dev->master_mode = false; 759 + complete(&i2c_dev->complete); 760 + } 1442 761 1443 762 return IRQ_HANDLED; 1444 763 } ··· 1486 731 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1487 732 void __iomem *base = i2c_dev->base; 1488 733 struct device *dev = i2c_dev->dev; 1489 - u32 status; 734 + struct stm32_i2c_dma *dma = i2c_dev->dma; 735 + u32 mask, status; 1490 736 1491 737 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 1492 738 ··· 1495 739 if (status & STM32F7_I2C_ISR_BERR) { 1496 740 dev_err(dev, "<%s>: Bus error\n", __func__); 1497 741 writel_relaxed(STM32F7_I2C_ICR_BERRCF, base + STM32F7_I2C_ICR); 742 + stm32f7_i2c_release_bus(&i2c_dev->adap); 1498 743 f7_msg->result = -EIO; 1499 744 } 1500 745 ··· 1506 749 f7_msg->result = -EAGAIN; 1507 750 } 1508 751 1509 - stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); 752 + if (status & STM32F7_I2C_ISR_PECERR) { 753 + dev_err(dev, "<%s>: PEC error in reception\n", __func__); 754 + writel_relaxed(STM32F7_I2C_ICR_PECCF, base + STM32F7_I2C_ICR); 755 + f7_msg->result = -EINVAL; 756 + } 1510 757 758 + /* Disable interrupts */ 759 + if (stm32f7_i2c_is_slave_registered(i2c_dev)) 760 + mask = STM32F7_I2C_XFER_IRQ_MASK; 761 + else 762 + mask = STM32F7_I2C_ALL_IRQ_MASK; 763 + stm32f7_i2c_disable_irq(i2c_dev, mask); 764 + 765 + /* Disable dma */ 766 + if (i2c_dev->use_dma) { 767 + stm32f7_i2c_disable_dma_req(i2c_dev); 768 + dmaengine_terminate_all(dma->chan_using); 769 + } 770 + 771 + i2c_dev->master_mode = false; 1511 772 complete(&i2c_dev->complete); 1512 773 1513 774 return IRQ_HANDLED; ··· 1536 761 { 1537 762 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); 1538 763 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 764 + struct stm32_i2c_dma *dma = i2c_dev->dma; 1539 765 unsigned long time_left; 1540 766 int ret; 1541 767 1542 768 i2c_dev->msg = msgs; 1543 769 i2c_dev->msg_num = num; 1544 770 i2c_dev->msg_id = 0; 771 + f7_msg->smbus = false; 1545 772 1546 773 ret = clk_enable(i2c_dev->clk); 1547 774 if (ret) { ··· 1564 787 if (!time_left) { 1565 788 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n", 1566 789 i2c_dev->msg->addr); 790 + if (i2c_dev->use_dma) 791 + dmaengine_terminate_all(dma->chan_using); 1567 792 ret = -ETIMEDOUT; 1568 793 } 1569 794 ··· 1575 796 return (ret < 0) ? ret : num; 1576 797 } 1577 798 799 + static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, 800 + unsigned short flags, char read_write, 801 + u8 command, int size, 802 + union i2c_smbus_data *data) 803 + { 804 + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adapter); 805 + struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 806 + struct stm32_i2c_dma *dma = i2c_dev->dma; 807 + struct device *dev = i2c_dev->dev; 808 + unsigned long timeout; 809 + int i, ret; 810 + 811 + f7_msg->addr = addr; 812 + f7_msg->size = size; 813 + f7_msg->read_write = read_write; 814 + f7_msg->smbus = true; 815 + 816 + ret = clk_enable(i2c_dev->clk); 817 + if (ret) { 818 + dev_err(i2c_dev->dev, "Failed to enable clock\n"); 819 + return ret; 820 + } 821 + 822 + ret = stm32f7_i2c_wait_free_bus(i2c_dev); 823 + if (ret) 824 + goto clk_free; 825 + 826 + ret = stm32f7_i2c_smbus_xfer_msg(i2c_dev, flags, command, data); 827 + if (ret) 828 + goto clk_free; 829 + 830 + timeout = wait_for_completion_timeout(&i2c_dev->complete, 831 + i2c_dev->adap.timeout); 832 + ret = f7_msg->result; 833 + if (ret) 834 + goto clk_free; 835 + 836 + if (!timeout) { 837 + dev_dbg(dev, "Access to slave 0x%x timed out\n", f7_msg->addr); 838 + if (i2c_dev->use_dma) 839 + dmaengine_terminate_all(dma->chan_using); 840 + ret = -ETIMEDOUT; 841 + goto clk_free; 842 + } 843 + 844 + /* Check PEC */ 845 + if ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK && read_write) { 846 + ret = stm32f7_i2c_smbus_check_pec(i2c_dev); 847 + if (ret) 848 + goto clk_free; 849 + } 850 + 851 + if (read_write && size != I2C_SMBUS_QUICK) { 852 + switch (size) { 853 + case I2C_SMBUS_BYTE: 854 + case I2C_SMBUS_BYTE_DATA: 855 + data->byte = f7_msg->smbus_buf[0]; 856 + break; 857 + case I2C_SMBUS_WORD_DATA: 858 + case I2C_SMBUS_PROC_CALL: 859 + data->word = f7_msg->smbus_buf[0] | 860 + (f7_msg->smbus_buf[1] << 8); 861 + break; 862 + case I2C_SMBUS_BLOCK_DATA: 863 + case I2C_SMBUS_BLOCK_PROC_CALL: 864 + for (i = 0; i <= f7_msg->smbus_buf[0]; i++) 865 + data->block[i] = f7_msg->smbus_buf[i]; 866 + break; 867 + default: 868 + dev_err(dev, "Unsupported smbus transaction\n"); 869 + ret = -EINVAL; 870 + } 871 + } 872 + 873 + clk_free: 874 + clk_disable(i2c_dev->clk); 875 + return ret; 876 + } 877 + 878 + static int stm32f7_i2c_reg_slave(struct i2c_client *slave) 879 + { 880 + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); 881 + void __iomem *base = i2c_dev->base; 882 + struct device *dev = i2c_dev->dev; 883 + u32 oar1, oar2, mask; 884 + int id, ret; 885 + 886 + if (slave->flags & I2C_CLIENT_PEC) { 887 + dev_err(dev, "SMBus PEC not supported in slave mode\n"); 888 + return -EINVAL; 889 + } 890 + 891 + if (stm32f7_i2c_is_slave_busy(i2c_dev)) { 892 + dev_err(dev, "Too much slave registered\n"); 893 + return -EBUSY; 894 + } 895 + 896 + ret = stm32f7_i2c_get_free_slave_id(i2c_dev, slave, &id); 897 + if (ret) 898 + return ret; 899 + 900 + if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) { 901 + ret = clk_enable(i2c_dev->clk); 902 + if (ret) { 903 + dev_err(dev, "Failed to enable clock\n"); 904 + return ret; 905 + } 906 + } 907 + 908 + if (id == 0) { 909 + /* Configure Own Address 1 */ 910 + oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1); 911 + oar1 &= ~STM32F7_I2C_OAR1_MASK; 912 + if (slave->flags & I2C_CLIENT_TEN) { 913 + oar1 |= STM32F7_I2C_OAR1_OA1_10(slave->addr); 914 + oar1 |= STM32F7_I2C_OAR1_OA1MODE; 915 + } else { 916 + oar1 |= STM32F7_I2C_OAR1_OA1_7(slave->addr); 917 + } 918 + oar1 |= STM32F7_I2C_OAR1_OA1EN; 919 + i2c_dev->slave[id] = slave; 920 + writel_relaxed(oar1, i2c_dev->base + STM32F7_I2C_OAR1); 921 + } else if (id == 1) { 922 + /* Configure Own Address 2 */ 923 + oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2); 924 + oar2 &= ~STM32F7_I2C_OAR2_MASK; 925 + if (slave->flags & I2C_CLIENT_TEN) { 926 + ret = -EOPNOTSUPP; 927 + goto exit; 928 + } 929 + 930 + oar2 |= STM32F7_I2C_OAR2_OA2_7(slave->addr); 931 + oar2 |= STM32F7_I2C_OAR2_OA2EN; 932 + i2c_dev->slave[id] = slave; 933 + writel_relaxed(oar2, i2c_dev->base + STM32F7_I2C_OAR2); 934 + } else { 935 + ret = -ENODEV; 936 + goto exit; 937 + } 938 + 939 + /* Enable ACK */ 940 + stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR2, STM32F7_I2C_CR2_NACK); 941 + 942 + /* Enable Address match interrupt, error interrupt and enable I2C */ 943 + mask = STM32F7_I2C_CR1_ADDRIE | STM32F7_I2C_CR1_ERRIE | 944 + STM32F7_I2C_CR1_PE; 945 + stm32f7_i2c_set_bits(base + STM32F7_I2C_CR1, mask); 946 + 947 + return 0; 948 + 949 + exit: 950 + if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) 951 + clk_disable(i2c_dev->clk); 952 + 953 + return ret; 954 + } 955 + 956 + static int stm32f7_i2c_unreg_slave(struct i2c_client *slave) 957 + { 958 + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter); 959 + void __iomem *base = i2c_dev->base; 960 + u32 mask; 961 + int id, ret; 962 + 963 + ret = stm32f7_i2c_get_slave_id(i2c_dev, slave, &id); 964 + if (ret) 965 + return ret; 966 + 967 + WARN_ON(!i2c_dev->slave[id]); 968 + 969 + if (id == 0) { 970 + mask = STM32F7_I2C_OAR1_OA1EN; 971 + stm32f7_i2c_clr_bits(base + STM32F7_I2C_OAR1, mask); 972 + } else { 973 + mask = STM32F7_I2C_OAR2_OA2EN; 974 + stm32f7_i2c_clr_bits(base + STM32F7_I2C_OAR2, mask); 975 + } 976 + 977 + i2c_dev->slave[id] = NULL; 978 + 979 + if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) { 980 + stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); 981 + clk_disable(i2c_dev->clk); 982 + } 983 + 984 + return 0; 985 + } 986 + 1578 987 static u32 stm32f7_i2c_func(struct i2c_adapter *adap) 1579 988 { 1580 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 989 + return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SLAVE | 990 + I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 991 + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 992 + I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | 993 + I2C_FUNC_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_PEC; 1581 994 } 1582 995 1583 996 static struct i2c_algorithm stm32f7_i2c_algo = { 1584 997 .master_xfer = stm32f7_i2c_xfer, 998 + .smbus_xfer = stm32f7_i2c_smbus_xfer, 1585 999 .functionality = stm32f7_i2c_func, 1000 + .reg_slave = stm32f7_i2c_reg_slave, 1001 + .unreg_slave = stm32f7_i2c_unreg_slave, 1586 1002 }; 1587 1003 1588 1004 static int stm32f7_i2c_probe(struct platform_device *pdev) ··· 1789 815 u32 irq_error, irq_event, clk_rate, rise_time, fall_time; 1790 816 struct i2c_adapter *adap; 1791 817 struct reset_control *rst; 818 + dma_addr_t phy_addr; 1792 819 int ret; 1793 820 1794 821 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); ··· 1800 825 i2c_dev->base = devm_ioremap_resource(&pdev->dev, res); 1801 826 if (IS_ERR(i2c_dev->base)) 1802 827 return PTR_ERR(i2c_dev->base); 828 + phy_addr = (dma_addr_t)res->start; 1803 829 1804 830 irq_event = irq_of_parse_and_map(np, 0); 1805 831 if (!irq_event) { ··· 1847 871 1848 872 i2c_dev->dev = &pdev->dev; 1849 873 1850 - ret = devm_request_irq(&pdev->dev, irq_event, stm32f7_i2c_isr_event, 0, 1851 - pdev->name, i2c_dev); 874 + ret = devm_request_threaded_irq(&pdev->dev, irq_event, 875 + stm32f7_i2c_isr_event, 876 + stm32f7_i2c_isr_event_thread, 877 + IRQF_ONESHOT, 878 + pdev->name, i2c_dev); 1852 879 if (ret) { 1853 880 dev_err(&pdev->dev, "Failed to request irq event %i\n", 1854 881 irq_event); ··· 1903 924 1904 925 init_completion(&i2c_dev->complete); 1905 926 927 + /* Init DMA config if supported */ 928 + i2c_dev->dma = stm32_i2c_dma_request(i2c_dev->dev, phy_addr, 929 + STM32F7_I2C_TXDR, 930 + STM32F7_I2C_RXDR); 931 + 1906 932 ret = i2c_add_adapter(adap); 1907 933 if (ret) 1908 934 goto clk_free; ··· 1929 945 static int stm32f7_i2c_remove(struct platform_device *pdev) 1930 946 { 1931 947 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 948 + 949 + if (i2c_dev->dma) { 950 + stm32_i2c_dma_free(i2c_dev->dma); 951 + i2c_dev->dma = NULL; 952 + } 1932 953 1933 954 i2c_del_adapter(&i2c_dev->adap); 1934 955
+13 -9
drivers/i2c/busses/i2c-stu300.c
··· 602 602 u32 val; 603 603 int ret; 604 604 605 - if (msg->flags & I2C_M_TEN) 605 + if (msg->flags & I2C_M_TEN) { 606 606 /* This is probably how 10 bit addresses look */ 607 607 val = (0xf0 | (((u32) msg->addr & 0x300) >> 7)) & 608 608 I2C_DR_D_MASK; 609 - else 610 - val = ((msg->addr << 1) & I2C_DR_D_MASK); 609 + if (msg->flags & I2C_M_RD) 610 + /* This is the direction bit */ 611 + val |= 0x01; 612 + } else { 613 + val = i2c_8bit_addr_from_msg(msg); 614 + } 611 615 612 - if (msg->flags & I2C_M_RD) { 613 - /* This is the direction bit */ 614 - val |= 0x01; 615 - if (resend) 616 + if (resend) { 617 + if (msg->flags & I2C_M_RD) 616 618 dev_dbg(&dev->pdev->dev, "read resend\n"); 617 - } else if (resend) 618 - dev_dbg(&dev->pdev->dev, "write resend\n"); 619 + else 620 + dev_dbg(&dev->pdev->dev, "write resend\n"); 621 + } 622 + 619 623 stu300_wr8(val, dev->virtbase + I2C_DR); 620 624 621 625 /* For 10bit addressing, await 10bit request (EVENT 9) */
+1 -1
drivers/i2c/busses/i2c-synquacer.c
··· 509 509 510 510 dev_dbg(i2c->dev, "calculated timeout %d ms\n", i2c->timeout_ms); 511 511 512 - for (retry = 0; retry < adap->retries; retry++) { 512 + for (retry = 0; retry <= adap->retries; retry++) { 513 513 ret = synquacer_i2c_doxfer(i2c, msgs, num); 514 514 if (ret != -EAGAIN) 515 515 return ret;
-33
drivers/i2c/busses/i2c-tegra.c
··· 173 173 * @msg_buf_remaining: size of unsent data in the message buffer 174 174 * @msg_read: identifies read transfers 175 175 * @bus_clk_rate: current i2c bus clock rate 176 - * @is_suspended: prevents i2c controller accesses after suspend is called 177 176 */ 178 177 struct tegra_i2c_dev { 179 178 struct device *dev; ··· 193 194 int msg_read; 194 195 u32 bus_clk_rate; 195 196 u16 clk_divisor_non_hs_mode; 196 - bool is_suspended; 197 197 bool is_multimaster_mode; 198 198 spinlock_t xfer_lock; 199 199 }; ··· 732 734 int i; 733 735 int ret = 0; 734 736 735 - if (i2c_dev->is_suspended) 736 - return -EBUSY; 737 - 738 737 ret = pm_runtime_get_sync(i2c_dev->dev); 739 738 if (ret < 0) { 740 739 dev_err(i2c_dev->dev, "runtime resume failed %d\n", ret); ··· 1046 1051 } 1047 1052 1048 1053 #ifdef CONFIG_PM_SLEEP 1049 - static int tegra_i2c_suspend(struct device *dev) 1050 - { 1051 - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); 1052 - 1053 - i2c_lock_adapter(&i2c_dev->adapter); 1054 - i2c_dev->is_suspended = true; 1055 - i2c_unlock_adapter(&i2c_dev->adapter); 1056 - 1057 - return 0; 1058 - } 1059 - 1060 - static int tegra_i2c_resume(struct device *dev) 1061 - { 1062 - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); 1063 - int ret; 1064 - 1065 - i2c_lock_adapter(&i2c_dev->adapter); 1066 - 1067 - ret = tegra_i2c_init(i2c_dev); 1068 - if (!ret) 1069 - i2c_dev->is_suspended = false; 1070 - 1071 - i2c_unlock_adapter(&i2c_dev->adapter); 1072 - 1073 - return ret; 1074 - } 1075 - 1076 1054 static const struct dev_pm_ops tegra_i2c_pm = { 1077 1055 SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume, 1078 1056 NULL) 1079 - SET_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume) 1080 1057 }; 1081 1058 #define TEGRA_I2C_PM (&tegra_i2c_pm) 1082 1059 #else
+5 -12
drivers/i2c/busses/i2c-xiic.c
··· 33 33 #include <linux/i2c.h> 34 34 #include <linux/interrupt.h> 35 35 #include <linux/wait.h> 36 - #include <linux/i2c-xiic.h> 36 + #include <linux/platform_data/i2c-xiic.h> 37 37 #include <linux/io.h> 38 38 #include <linux/slab.h> 39 39 #include <linux/of.h> ··· 142 142 (XIIC_INTR_TX_ERROR_MASK | XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK) 143 143 144 144 #define XIIC_TX_RX_INTERRUPTS (XIIC_INTR_RX_FULL_MASK | XIIC_TX_INTERRUPTS) 145 - 146 - /* The following constants are used with the following macros to specify the 147 - * operation, a read or write operation. 148 - */ 149 - #define XIIC_READ_OPERATION 1 150 - #define XIIC_WRITE_OPERATION 0 151 145 152 146 /* 153 147 * Tx Fifo upper bit masks. ··· 409 415 clr |= XIIC_INTR_RX_FULL_MASK; 410 416 if (!i2c->rx_msg) { 411 417 dev_dbg(i2c->adap.dev.parent, 412 - "%s unexpexted RX IRQ\n", __func__); 418 + "%s unexpected RX IRQ\n", __func__); 413 419 xiic_clear_rx_fifo(i2c); 414 420 goto out; 415 421 } ··· 464 470 465 471 if (!i2c->tx_msg) { 466 472 dev_dbg(i2c->adap.dev.parent, 467 - "%s unexpexted TX IRQ\n", __func__); 473 + "%s unexpected TX IRQ\n", __func__); 468 474 goto out; 469 475 } 470 476 ··· 550 556 if (!(msg->flags & I2C_M_NOSTART)) 551 557 /* write the address */ 552 558 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 553 - (msg->addr << 1) | XIIC_READ_OPERATION | 554 - XIIC_TX_DYN_START_MASK); 559 + i2c_8bit_addr_from_msg(msg) | XIIC_TX_DYN_START_MASK); 555 560 556 561 xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); 557 562 ··· 578 585 579 586 if (!(msg->flags & I2C_M_NOSTART)) { 580 587 /* write the address */ 581 - u16 data = ((msg->addr << 1) & 0xfe) | XIIC_WRITE_OPERATION | 588 + u16 data = i2c_8bit_addr_from_msg(msg) | 582 589 XIIC_TX_DYN_START_MASK; 583 590 if ((i2c->nmsgs == 1) && msg->len == 0) 584 591 /* no data and last message -> add STOP */
+68 -21
drivers/i2c/busses/i2c-xlp9xx.c
··· 10 10 #include <linux/clk.h> 11 11 #include <linux/completion.h> 12 12 #include <linux/i2c.h> 13 + #include <linux/i2c-smbus.h> 13 14 #include <linux/init.h> 14 15 #include <linux/interrupt.h> 15 16 #include <linux/io.h> ··· 85 84 struct device *dev; 86 85 struct i2c_adapter adapter; 87 86 struct completion msg_complete; 87 + struct i2c_smbus_alert_setup alert_data; 88 + struct i2c_client *ara; 88 89 int irq; 89 90 bool msg_read; 90 91 bool len_recv; ··· 158 155 priv->msg_buf += len; 159 156 } 160 157 158 + static void xlp9xx_i2c_update_rlen(struct xlp9xx_i2c_dev *priv) 159 + { 160 + u32 val, len; 161 + 162 + /* 163 + * Update receive length. Re-read len to get the latest value, 164 + * and then add 4 to have a minimum value that can be safely 165 + * written. This is to account for the byte read above, the 166 + * transfer in progress and any delays in the register I/O 167 + */ 168 + val = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_CTRL); 169 + len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & 170 + XLP9XX_I2C_FIFO_WCNT_MASK; 171 + len = max_t(u32, priv->msg_len, len + 4); 172 + if (len >= I2C_SMBUS_BLOCK_MAX + 2) 173 + return; 174 + val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | 175 + (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); 176 + xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); 177 + } 178 + 161 179 static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) 162 180 { 163 - u32 len, i, val; 181 + u32 len, i; 164 182 u8 rlen, *buf = priv->msg_buf; 165 183 166 184 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & ··· 191 167 if (priv->len_recv) { 192 168 /* read length byte */ 193 169 rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); 194 - *buf++ = rlen; 195 - len--; 196 - 197 - if (priv->client_pec) 198 - ++rlen; 199 - /* update remaining bytes and message length */ 200 - priv->msg_buf_remaining = rlen; 201 - priv->msg_len = rlen + 1; 170 + if (rlen > I2C_SMBUS_BLOCK_MAX || rlen == 0) { 171 + rlen = 0; /*abort transfer */ 172 + priv->msg_buf_remaining = 0; 173 + priv->msg_len = 0; 174 + } else { 175 + *buf++ = rlen; 176 + if (priv->client_pec) 177 + ++rlen; /* account for error check byte */ 178 + /* update remaining bytes and message length */ 179 + priv->msg_buf_remaining = rlen; 180 + priv->msg_len = rlen + 1; 181 + } 182 + xlp9xx_i2c_update_rlen(priv); 202 183 priv->len_recv = false; 203 - 204 - /* Update transfer length to read only actual data */ 205 - val = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_CTRL); 206 - val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | 207 - ((rlen + 1) << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); 208 - xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); 209 184 } else { 210 185 len = min(priv->msg_buf_remaining, len); 211 186 for (i = 0; i < len; i++, buf++) ··· 323 300 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MFIFOCTRL, 324 301 XLP9XX_I2C_MFIFOCTRL_RST); 325 302 326 - /* set FIFO threshold if reading */ 327 - if (priv->msg_read) 328 - xlp9xx_i2c_update_rx_fifo_thres(priv); 329 - 330 303 /* set slave addr */ 331 304 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_SLAVEADDR, 332 305 (msg->addr << XLP9XX_I2C_SLAVEADDR_ADDR_SHIFT) | ··· 341 322 val &= ~XLP9XX_I2C_CTRL_ADDMODE; 342 323 343 324 priv->len_recv = msg->flags & I2C_M_RECV_LEN; 344 - len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len; 325 + len = priv->len_recv ? I2C_SMBUS_BLOCK_MAX + 2 : msg->len; 345 326 priv->client_pec = msg->flags & I2C_CLIENT_PEC; 327 + 328 + /* set FIFO threshold if reading */ 329 + if (priv->msg_read) 330 + xlp9xx_i2c_update_rx_fifo_thres(priv); 346 331 347 332 /* set data length to be transferred */ 348 333 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | ··· 401 378 } 402 379 403 380 /* update msg->len with actual received length */ 404 - if (msg->flags & I2C_M_RECV_LEN) 381 + if (msg->flags & I2C_M_RECV_LEN) { 382 + if (!priv->msg_len) 383 + return -EPROTO; 405 384 msg->len = priv->msg_len; 385 + } 406 386 return 0; 407 387 } 408 388 ··· 473 447 return 0; 474 448 } 475 449 450 + static int xlp9xx_i2c_smbus_setup(struct xlp9xx_i2c_dev *priv, 451 + struct platform_device *pdev) 452 + { 453 + if (!priv->alert_data.irq) 454 + return -EINVAL; 455 + 456 + priv->ara = i2c_setup_smbus_alert(&priv->adapter, &priv->alert_data); 457 + if (!priv->ara) 458 + return -ENODEV; 459 + 460 + return 0; 461 + } 462 + 476 463 static int xlp9xx_i2c_probe(struct platform_device *pdev) 477 464 { 478 465 struct xlp9xx_i2c_dev *priv; ··· 506 467 dev_err(&pdev->dev, "invalid irq!\n"); 507 468 return priv->irq; 508 469 } 470 + /* SMBAlert irq */ 471 + priv->alert_data.irq = platform_get_irq(pdev, 1); 472 + if (priv->alert_data.irq <= 0) 473 + priv->alert_data.irq = 0; 509 474 510 475 xlp9xx_i2c_get_frequency(pdev, priv); 511 476 xlp9xx_i2c_init(priv); ··· 535 492 err = i2c_add_adapter(&priv->adapter); 536 493 if (err) 537 494 return err; 495 + 496 + err = xlp9xx_i2c_smbus_setup(priv, pdev); 497 + if (err) 498 + dev_dbg(&pdev->dev, "No active SMBus alert %d\n", err); 538 499 539 500 platform_set_drvdata(pdev, priv); 540 501 dev_dbg(&pdev->dev, "I2C bus:%d added\n", priv->adapter.nr);
+4 -6
drivers/i2c/i2c-core-base.c
··· 717 717 client->adapter = adap; 718 718 719 719 client->dev.platform_data = info->platform_data; 720 - 721 - if (info->archdata) 722 - client->dev.archdata = *info->archdata; 723 - 724 720 client->flags = info->flags; 725 721 client->addr = info->addr; 726 722 ··· 742 746 client->dev.parent = &client->adapter->dev; 743 747 client->dev.bus = &i2c_bus_type; 744 748 client->dev.type = &i2c_client_type; 745 - client->dev.of_node = info->of_node; 749 + client->dev.of_node = of_node_get(info->of_node); 746 750 client->dev.fwnode = info->fwnode; 747 751 748 752 i2c_dev_set_name(adap, client, info); ··· 753 757 dev_err(&adap->dev, 754 758 "Failed to add properties to client %s: %d\n", 755 759 client->name, status); 756 - goto out_err; 760 + goto out_err_put_of_node; 757 761 } 758 762 } 759 763 ··· 769 773 out_free_props: 770 774 if (info->properties) 771 775 device_remove_properties(&client->dev); 776 + out_err_put_of_node: 777 + of_node_put(info->of_node); 772 778 out_err: 773 779 dev_err(&adap->dev, 774 780 "Failed to register i2c client %s at 0x%02x (%d)\n",
+31 -20
drivers/i2c/i2c-core-of.c
··· 22 22 23 23 #include "i2c-core.h" 24 24 25 - static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap, 26 - struct device_node *node) 25 + int of_i2c_get_board_info(struct device *dev, struct device_node *node, 26 + struct i2c_board_info *info) 27 27 { 28 - struct i2c_client *client; 29 - struct i2c_board_info info = {}; 30 - struct dev_archdata dev_ad = {}; 31 28 u32 addr; 32 29 int ret; 33 30 34 - dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node); 31 + memset(info, 0, sizeof(*info)); 35 32 36 - if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { 37 - dev_err(&adap->dev, "of_i2c: modalias failure on %pOF\n", 38 - node); 39 - return ERR_PTR(-EINVAL); 33 + if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) { 34 + dev_err(dev, "of_i2c: modalias failure on %pOF\n", node); 35 + return -EINVAL; 40 36 } 41 37 42 38 ret = of_property_read_u32(node, "reg", &addr); 43 39 if (ret) { 44 - dev_err(&adap->dev, "of_i2c: invalid reg on %pOF\n", node); 45 - return ERR_PTR(ret); 40 + dev_err(dev, "of_i2c: invalid reg on %pOF\n", node); 41 + return ret; 46 42 } 47 43 48 44 if (addr & I2C_TEN_BIT_ADDRESS) { 49 45 addr &= ~I2C_TEN_BIT_ADDRESS; 50 - info.flags |= I2C_CLIENT_TEN; 46 + info->flags |= I2C_CLIENT_TEN; 51 47 } 52 48 53 49 if (addr & I2C_OWN_SLAVE_ADDRESS) { 54 50 addr &= ~I2C_OWN_SLAVE_ADDRESS; 55 - info.flags |= I2C_CLIENT_SLAVE; 51 + info->flags |= I2C_CLIENT_SLAVE; 56 52 } 57 53 58 - info.addr = addr; 59 - info.archdata = &dev_ad; 60 - info.of_node = of_node_get(node); 54 + info->addr = addr; 55 + info->of_node = node; 61 56 62 57 if (of_property_read_bool(node, "host-notify")) 63 - info.flags |= I2C_CLIENT_HOST_NOTIFY; 58 + info->flags |= I2C_CLIENT_HOST_NOTIFY; 64 59 65 60 if (of_get_property(node, "wakeup-source", NULL)) 66 - info.flags |= I2C_CLIENT_WAKE; 61 + info->flags |= I2C_CLIENT_WAKE; 62 + 63 + return 0; 64 + } 65 + EXPORT_SYMBOL_GPL(of_i2c_get_board_info); 66 + 67 + static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap, 68 + struct device_node *node) 69 + { 70 + struct i2c_client *client; 71 + struct i2c_board_info info; 72 + int ret; 73 + 74 + dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node); 75 + 76 + ret = of_i2c_get_board_info(&adap->dev, node, &info); 77 + if (ret) 78 + return ERR_PTR(ret); 67 79 68 80 client = i2c_new_device(adap, &info); 69 81 if (!client) { 70 82 dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", node); 71 - of_node_put(node); 72 83 return ERR_PTR(-EINVAL); 73 84 } 74 85 return client;
+2
drivers/i2c/i2c-core-smbus.c
··· 466 466 status = i2c_transfer(adapter, msg, num); 467 467 if (status < 0) 468 468 return status; 469 + if (status != num) 470 + return -EIO; 469 471 470 472 /* Check PEC if last message is a read */ 471 473 if (i && (msg[num-1].flags & I2C_M_RD)) {
+1 -1
drivers/i2c/i2c-mux.c
··· 418 418 snprintf(symlink_name, sizeof(symlink_name), "channel-%u", chan_id); 419 419 WARN(sysfs_create_link(&muxc->dev->kobj, &priv->adap.dev.kobj, 420 420 symlink_name), 421 - "can't create symlink for channel %u\n", chan_id); 421 + "can't create symlink to channel %u\n", chan_id); 422 422 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", 423 423 i2c_adapter_id(&priv->adap)); 424 424
+4 -1
drivers/i2c/muxes/i2c-demux-pinctrl.c
··· 18 18 #include <linux/of.h> 19 19 #include <linux/pinctrl/consumer.h> 20 20 #include <linux/platform_device.h> 21 + #include <linux/pm_runtime.h> 21 22 #include <linux/slab.h> 22 23 #include <linux/sysfs.h> 23 24 ··· 106 105 priv->cur_adap.owner = THIS_MODULE; 107 106 priv->cur_adap.algo = &priv->algo; 108 107 priv->cur_adap.algo_data = priv; 109 - priv->cur_adap.dev.parent = priv->dev; 108 + priv->cur_adap.dev.parent = &adap->dev; 110 109 priv->cur_adap.class = adap->class; 111 110 priv->cur_adap.retries = adap->retries; 112 111 priv->cur_adap.timeout = adap->timeout; ··· 254 253 priv->dev = &pdev->dev; 255 254 256 255 platform_set_drvdata(pdev, priv); 256 + 257 + pm_runtime_no_callbacks(&pdev->dev); 257 258 258 259 /* switch to first parent as active master */ 259 260 i2c_demux_activate_master(priv, 0);
+1 -1
drivers/i2c/muxes/i2c-mux-gpio.c
··· 10 10 11 11 #include <linux/i2c.h> 12 12 #include <linux/i2c-mux.h> 13 - #include <linux/i2c-mux-gpio.h> 13 + #include <linux/platform_data/i2c-mux-gpio.h> 14 14 #include <linux/platform_device.h> 15 15 #include <linux/module.h> 16 16 #include <linux/slab.h>
+3 -4
drivers/i2c/muxes/i2c-mux-ltc4306.c
··· 206 206 }; 207 207 MODULE_DEVICE_TABLE(of, ltc4306_of_match); 208 208 209 - static int ltc4306_probe(struct i2c_client *client, 210 - const struct i2c_device_id *id) 209 + static int ltc4306_probe(struct i2c_client *client) 211 210 { 212 211 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); 213 212 const struct chip_desc *chip; ··· 220 221 chip = of_device_get_match_data(&client->dev); 221 222 222 223 if (!chip) 223 - chip = &chips[id->driver_data]; 224 + chip = &chips[i2c_match_id(ltc4306_id, client)->driver_data]; 224 225 225 226 idle_disc = device_property_read_bool(&client->dev, 226 227 "i2c-mux-idle-disconnect"); ··· 309 310 .name = "ltc4306", 310 311 .of_match_table = of_match_ptr(ltc4306_of_match), 311 312 }, 312 - .probe = ltc4306_probe, 313 + .probe_new = ltc4306_probe, 313 314 .remove = ltc4306_remove, 314 315 .id_table = ltc4306_id, 315 316 };
+11 -7
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 36 36 */ 37 37 38 38 #include <linux/device.h> 39 + #include <linux/delay.h> 39 40 #include <linux/gpio/consumer.h> 40 41 #include <linux/i2c.h> 41 42 #include <linux/i2c-mux.h> ··· 374 373 int num, force, class; 375 374 struct i2c_mux_core *muxc; 376 375 struct pca954x *data; 377 - const struct of_device_id *match; 378 376 int ret; 379 377 380 378 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) ··· 389 389 i2c_set_clientdata(client, muxc); 390 390 data->client = client; 391 391 392 - /* Get the mux out of reset if a reset GPIO is specified. */ 393 - gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW); 392 + /* Reset the mux if a reset GPIO is specified. */ 393 + gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); 394 394 if (IS_ERR(gpio)) 395 395 return PTR_ERR(gpio); 396 + if (gpio) { 397 + udelay(1); 398 + gpiod_set_value_cansleep(gpio, 0); 399 + /* Give the chip some time to recover. */ 400 + udelay(1); 401 + } 396 402 397 - match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev); 398 - if (match) 399 - data->chip = of_device_get_match_data(&client->dev); 400 - else 403 + data->chip = of_device_get_match_data(&client->dev); 404 + if (!data->chip) 401 405 data->chip = &chips[id->driver_data]; 402 406 403 407 if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) {
+1 -3
drivers/i2c/muxes/i2c-mux-reg.c
··· 127 127 values = devm_kcalloc(&pdev->dev, 128 128 mux->data.n_values, sizeof(*mux->data.values), 129 129 GFP_KERNEL); 130 - if (!values) { 131 - dev_err(&pdev->dev, "Cannot allocate values array"); 130 + if (!values) 132 131 return -ENOMEM; 133 - } 134 132 135 133 for_each_child_of_node(np, child) { 136 134 of_property_read_u32(child, "reg", values + i);
+1 -1
drivers/media/platform/marvell-ccic/mmp-driver.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 14 #include <linux/i2c.h> 15 - #include <linux/i2c-gpio.h> 15 + #include <linux/platform_data/i2c-gpio.h> 16 16 #include <linux/interrupt.h> 17 17 #include <linux/spinlock.h> 18 18 #include <linux/slab.h>
+1 -1
drivers/mfd/sm501.c
··· 19 19 #include <linux/device.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pci.h> 22 - #include <linux/i2c-gpio.h> 22 + #include <linux/platform_data/i2c-gpio.h> 23 23 #include <linux/gpio/machine.h> 24 24 #include <linux/slab.h> 25 25
+2 -2
drivers/mfd/timberdale.c
··· 30 30 #include <linux/timb_gpio.h> 31 31 32 32 #include <linux/i2c.h> 33 - #include <linux/i2c-ocores.h> 34 - #include <linux/i2c-xiic.h> 33 + #include <linux/platform_data/i2c-ocores.h> 34 + #include <linux/platform_data/i2c-xiic.h> 35 35 36 36 #include <linux/spi/spi.h> 37 37 #include <linux/spi/xilinx_spi.h>
+46 -25
drivers/misc/eeprom/at24.c
··· 532 532 return 0; 533 533 } 534 534 535 + static void at24_remove_dummy_clients(struct at24_data *at24) 536 + { 537 + int i; 538 + 539 + for (i = 1; i < at24->num_addresses; i++) 540 + i2c_unregister_device(at24->client[i].client); 541 + } 542 + 543 + static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, 544 + struct regmap_config *regmap_config) 545 + { 546 + struct i2c_client *base_client, *dummy_client; 547 + unsigned short int addr; 548 + struct regmap *regmap; 549 + struct device *dev; 550 + 551 + base_client = at24->client[0].client; 552 + dev = &base_client->dev; 553 + addr = base_client->addr + index; 554 + 555 + dummy_client = i2c_new_dummy(base_client->adapter, 556 + base_client->addr + index); 557 + if (!dummy_client) { 558 + dev_err(dev, "address 0x%02x unavailable\n", addr); 559 + return -EADDRINUSE; 560 + } 561 + 562 + regmap = devm_regmap_init_i2c(dummy_client, regmap_config); 563 + if (IS_ERR(regmap)) { 564 + i2c_unregister_device(dummy_client); 565 + return PTR_ERR(regmap); 566 + } 567 + 568 + at24->client[index].client = dummy_client; 569 + at24->client[index].regmap = regmap; 570 + 571 + return 0; 572 + } 573 + 535 574 static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len) 536 575 { 537 576 if (flags & AT24_FLAG_MAC) { ··· 676 637 677 638 /* use dummy devices for multiple-address chips */ 678 639 for (i = 1; i < num_addresses; i++) { 679 - at24->client[i].client = i2c_new_dummy(client->adapter, 680 - client->addr + i); 681 - if (!at24->client[i].client) { 682 - dev_err(dev, "address 0x%02x unavailable\n", 683 - client->addr + i); 684 - err = -EADDRINUSE; 685 - goto err_clients; 686 - } 687 - at24->client[i].regmap = devm_regmap_init_i2c( 688 - at24->client[i].client, 689 - &regmap_config); 690 - if (IS_ERR(at24->client[i].regmap)) { 691 - err = PTR_ERR(at24->client[i].regmap); 692 - goto err_clients; 640 + err = at24_make_dummy_client(at24, i, &regmap_config); 641 + if (err) { 642 + at24_remove_dummy_clients(at24); 643 + return err; 693 644 } 694 645 } 695 646 ··· 714 685 nvmem_config.word_size = 1; 715 686 nvmem_config.size = pdata.byte_len; 716 687 717 - at24->nvmem = nvmem_register(&nvmem_config); 688 + at24->nvmem = devm_nvmem_register(dev, &nvmem_config); 718 689 if (IS_ERR(at24->nvmem)) { 719 690 err = PTR_ERR(at24->nvmem); 720 691 goto err_clients; ··· 731 702 return 0; 732 703 733 704 err_clients: 734 - for (i = 1; i < num_addresses; i++) 735 - if (at24->client[i].client) 736 - i2c_unregister_device(at24->client[i].client); 737 - 705 + at24_remove_dummy_clients(at24); 738 706 pm_runtime_disable(dev); 739 707 740 708 return err; ··· 740 714 static int at24_remove(struct i2c_client *client) 741 715 { 742 716 struct at24_data *at24; 743 - int i; 744 717 745 718 at24 = i2c_get_clientdata(client); 746 719 747 - nvmem_unregister(at24->nvmem); 748 - 749 - for (i = 1; i < at24->num_addresses; i++) 750 - i2c_unregister_device(at24->client[i].client); 751 - 720 + at24_remove_dummy_clients(at24); 752 721 pm_runtime_disable(&client->dev); 753 722 pm_runtime_set_suspended(&client->dev); 754 723
include/linux/i2c-gpio.h include/linux/platform_data/i2c-gpio.h
include/linux/i2c-mux-gpio.h include/linux/platform_data/i2c-mux-gpio.h
include/linux/i2c-ocores.h include/linux/platform_data/i2c-ocores.h
include/linux/i2c-omap.h include/linux/platform_data/i2c-omap.h
include/linux/i2c-pca-platform.h include/linux/platform_data/i2c-pca-platform.h
-38
include/linux/i2c-pnx.h
··· 1 - /* 2 - * Header file for I2C support on PNX010x/4008. 3 - * 4 - * Author: Dennis Kovalev <dkovalev@ru.mvista.com> 5 - * 6 - * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under 7 - * the terms of the GNU General Public License version 2. This program 8 - * is licensed "as is" without any warranty of any kind, whether express 9 - * or implied. 10 - */ 11 - 12 - #ifndef __I2C_PNX_H__ 13 - #define __I2C_PNX_H__ 14 - 15 - struct platform_device; 16 - struct clk; 17 - 18 - struct i2c_pnx_mif { 19 - int ret; /* Return value */ 20 - int mode; /* Interface mode */ 21 - struct completion complete; /* I/O completion */ 22 - struct timer_list timer; /* Timeout */ 23 - u8 * buf; /* Data buffer */ 24 - int len; /* Length of data buffer */ 25 - int order; /* RX Bytes to order via TX */ 26 - }; 27 - 28 - struct i2c_pnx_algo_data { 29 - void __iomem *ioaddr; 30 - struct i2c_pnx_mif mif; 31 - int last; 32 - struct clk *clk; 33 - struct i2c_adapter adapter; 34 - int irq; 35 - u32 timeout; 36 - }; 37 - 38 - #endif /* __I2C_PNX_H__ */
include/linux/i2c-xiic.h include/linux/platform_data/i2c-xiic.h
+10 -2
include/linux/i2c.h
··· 394 394 * @addr: stored in i2c_client.addr 395 395 * @dev_name: Overrides the default <busnr>-<addr> dev_name if set 396 396 * @platform_data: stored in i2c_client.dev.platform_data 397 - * @archdata: copied into i2c_client.dev.archdata 398 397 * @of_node: pointer to OpenFirmware device node 399 398 * @fwnode: device node supplied by the platform firmware 400 399 * @properties: additional device properties for the device ··· 418 419 unsigned short addr; 419 420 const char *dev_name; 420 421 void *platform_data; 421 - struct dev_archdata *archdata; 422 422 struct device_node *of_node; 423 423 struct fwnode_handle *fwnode; 424 424 const struct property_entry *properties; ··· 901 903 *i2c_of_match_device(const struct of_device_id *matches, 902 904 struct i2c_client *client); 903 905 906 + int of_i2c_get_board_info(struct device *dev, struct device_node *node, 907 + struct i2c_board_info *info); 908 + 904 909 #else 905 910 906 911 static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) ··· 926 925 struct i2c_client *client) 927 926 { 928 927 return NULL; 928 + } 929 + 930 + static inline int of_i2c_get_board_info(struct device *dev, 931 + struct device_node *node, 932 + struct i2c_board_info *info) 933 + { 934 + return -ENOTSUPP; 929 935 } 930 936 931 937 #endif /* CONFIG_OF */