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

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

Pull i2c updates from Wolfram Sang:
"I2C has the following changes for you:

- new flag to mark DMA safe buffers in i2c_msg. Also, some
infrastructure around it. And docs.

- huge refactoring of the at24 driver led by the new maintainer
Bartosz

- update I2C bus recovery to send STOP after recovery

- conversion from gpio to gpiod for I2C bus recovery

- adding a fault-injector to the i2c-gpio driver

- lots of small driver improvements, and bigger ones to
i2c-sh_mobile"

* 'i2c/for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (99 commits)
i2c: mv64xxx: Add myself as maintainer for this driver
i2c: mv64xxx: Fix clock resource by adding an optional bus clock
i2c: mv64xxx: Remove useless test before clk_disable_unprepare
i2c: mxs: use true and false for boolean values
i2c: meson: update doc description to fix build warnings
i2c: meson: add configurable divider factors
dt-bindings: i2c: update documentation for the Meson-AXG
i2c: imx-lpi2c: add runtime pm support
i2c: rcar: fix some trivial typos in comments
i2c: davinci: fix the cpufreq transition
i2c: rk3x: add proper kerneldoc header
i2c: rk3x: account for const type of of_device_id.data
i2c: acorn: remove outdated path from file header
i2c: acorn: add MODULE_LICENSE tag
i2c: rcar: implement bus recovery
i2c: send STOP after successful bus recovery
i2c: ensure SDA is released in recovery if SDA is controllable
i2c: add 'set_sda' to bus_recovery_info
i2c: add identifier in declarations for i2c_bus_recovery
i2c: make kerneldoc about bus recovery more precise
...

+1387 -1018
+78
Documentation/devicetree/bindings/eeprom/at24.txt
··· 1 + EEPROMs (I2C) 2 + 3 + Required properties: 4 + 5 + - compatible: Must be a "<manufacturer>,<model>" pair. The following <model> 6 + values are supported (assuming "atmel" as manufacturer): 7 + 8 + "atmel,24c00", 9 + "atmel,24c01", 10 + "atmel,24cs01", 11 + "atmel,24c02", 12 + "atmel,24cs02", 13 + "atmel,24mac402", 14 + "atmel,24mac602", 15 + "atmel,spd", 16 + "atmel,24c04", 17 + "atmel,24cs04", 18 + "atmel,24c08", 19 + "atmel,24cs08", 20 + "atmel,24c16", 21 + "atmel,24cs16", 22 + "atmel,24c32", 23 + "atmel,24cs32", 24 + "atmel,24c64", 25 + "atmel,24cs64", 26 + "atmel,24c128", 27 + "atmel,24c256", 28 + "atmel,24c512", 29 + "atmel,24c1024", 30 + 31 + If <manufacturer> is not "atmel", then a fallback must be used 32 + with the same <model> and "atmel" as manufacturer. 33 + 34 + Example: 35 + compatible = "microchip,24c128", "atmel,24c128"; 36 + 37 + Supported manufacturers are: 38 + 39 + "catalyst", 40 + "microchip", 41 + "ramtron", 42 + "renesas", 43 + "nxp", 44 + "st", 45 + 46 + Some vendors use different model names for chips which are just 47 + variants of the above. Known such exceptions are listed below: 48 + 49 + "renesas,r1ex24002" - the fallback is "atmel,24c02" 50 + 51 + - reg: The I2C address of the EEPROM. 52 + 53 + Optional properties: 54 + 55 + - pagesize: The length of the pagesize for writing. Please consult the 56 + manual of your device, that value varies a lot. A wrong value 57 + may result in data loss! If not specified, a safety value of 58 + '1' is used which will be very slow. 59 + 60 + - read-only: This parameterless property disables writes to the eeprom. 61 + 62 + - size: Total eeprom size in bytes. 63 + 64 + - no-read-rollover: This parameterless property indicates that the 65 + multi-address eeprom does not automatically roll over 66 + reads to the next slave address. Please consult the 67 + manual of your device. 68 + 69 + - wp-gpios: GPIO to which the write-protect pin of the chip is connected. 70 + 71 + Example: 72 + 73 + eeprom@52 { 74 + compatible = "atmel,24c32"; 75 + reg = <0x52>; 76 + pagesize = <32>; 77 + wp-gpios = <&gpio1 3 0>; 78 + };
-47
Documentation/devicetree/bindings/eeprom/eeprom.txt
··· 1 - EEPROMs (I2C) 2 - 3 - Required properties: 4 - 5 - - compatible : should be "<manufacturer>,<type>", like these: 6 - 7 - "atmel,24c00", "atmel,24c01", "atmel,24c02", "atmel,24c04", 8 - "atmel,24c08", "atmel,24c16", "atmel,24c32", "atmel,24c64", 9 - "atmel,24c128", "atmel,24c256", "atmel,24c512", "atmel,24c1024" 10 - 11 - "catalyst,24c32" 12 - 13 - "microchip,24c128" 14 - 15 - "ramtron,24c64" 16 - 17 - "renesas,r1ex24002" 18 - 19 - The following manufacturers values have been deprecated: 20 - "at", "at24" 21 - 22 - If there is no specific driver for <manufacturer>, a generic 23 - device with <type> and manufacturer "atmel" should be used. 24 - Possible types are: 25 - "24c00", "24c01", "24c02", "24c04", "24c08", "24c16", "24c32", "24c64", 26 - "24c128", "24c256", "24c512", "24c1024", "spd" 27 - 28 - - reg : the I2C address of the EEPROM 29 - 30 - Optional properties: 31 - 32 - - pagesize : the length of the pagesize for writing. Please consult the 33 - manual of your device, that value varies a lot. A wrong value 34 - may result in data loss! If not specified, a safety value of 35 - '1' is used which will be very slow. 36 - 37 - - read-only: this parameterless property disables writes to the eeprom 38 - 39 - - size: total eeprom size in bytes 40 - 41 - Example: 42 - 43 - eeprom@52 { 44 - compatible = "atmel,24c32"; 45 - reg = <0x52>; 46 - pagesize = <32>; 47 - };
+5 -1
Documentation/devicetree/bindings/i2c/i2c-meson.txt
··· 1 1 Amlogic Meson I2C controller 2 2 3 3 Required properties: 4 - - compatible: must be "amlogic,meson6-i2c" or "amlogic,meson-gxbb-i2c" 4 + - compatible: must be: 5 + "amlogic,meson6-i2c" for Meson8 and compatible SoCs 6 + "amlogic,meson-gxbb-i2c" for GXBB and compatible SoCs 7 + "amlogic,meson-axg-i2c"for AXG and compatible SoCs 8 + 5 9 - reg: physical address and length of the device registers 6 10 - interrupts: a single interrupt specifier 7 11 - clocks: clock for the device
+1
Documentation/devicetree/bindings/i2c/i2c-mtk.txt
··· 5 5 Required properties: 6 6 - compatible: value should be either of the following. 7 7 "mediatek,mt2701-i2c", "mediatek,mt6577-i2c": for MediaTek MT2701 8 + "mediatek,mt2712-i2c": for MediaTek MT2712 8 9 "mediatek,mt6577-i2c": for MediaTek MT6577 9 10 "mediatek,mt6589-i2c": for MediaTek MT6589 10 11 "mediatek,mt7622-i2c": for MediaTek MT7622
+11 -2
Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
··· 1 1 * NXP PCA954x I2C bus switch 2 2 3 + The driver supports NXP PCA954x and PCA984x I2C mux/switch devices. 4 + 3 5 Required Properties: 4 6 5 7 - compatible: Must contain one of the following. 6 - "nxp,pca9540", "nxp,pca9542", "nxp,pca9543", "nxp,pca9544", 7 - "nxp,pca9545", "nxp,pca9546", "nxp,pca9547", "nxp,pca9548" 8 + "nxp,pca9540", 9 + "nxp,pca9542", 10 + "nxp,pca9543", 11 + "nxp,pca9544", 12 + "nxp,pca9545", 13 + "nxp,pca9546", "nxp,pca9846", 14 + "nxp,pca9547", "nxp,pca9847", 15 + "nxp,pca9548", "nxp,pca9848", 16 + "nxp,pca9849" 8 17 9 18 - reg: The I2C address of the device. 10 19
+20
Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
··· 25 25 whenever you're using the "allwinner,sun6i-a31-i2c" 26 26 compatible. 27 27 28 + - clocks: : pointers to the reference clocks for this device, the 29 + first one is the one used for the clock on the i2c bus, 30 + the second one is the clock used to acces the registers 31 + of the controller 32 + 33 + - clock-names : names of used clocks, mandatory if the second clock is 34 + used, the name must be "core", and "reg" (the latter is 35 + only for Armada 7K/8K). 36 + 28 37 Examples: 29 38 30 39 i2c@11000 { ··· 50 41 reg = <0x11000 0x100>; 51 42 interrupts = <29>; 52 43 clock-frequency = <100000>; 44 + }; 45 + 46 + For the Armada 7040: 47 + 48 + i2c@701000 { 49 + compatible = "marvell,mv78230-i2c"; 50 + reg = <0x701000 0x20>; 51 + interrupts = <29>; 52 + clock-frequency = <100000>; 53 + clock-names = "core", "reg"; 54 + clocks = <&core_clock>, <&reg_clock>; 53 55 };
+67
Documentation/i2c/DMA-considerations
··· 1 + ================= 2 + Linux I2C and DMA 3 + ================= 4 + 5 + Given that i2c is a low-speed bus, over which the majority of messages 6 + transferred are small, it is not considered a prime user of DMA access. At this 7 + time of writing, only 10% of I2C bus master drivers have DMA support 8 + implemented. And the vast majority of transactions are so small that setting up 9 + DMA for it will likely add more overhead than a plain PIO transfer. 10 + 11 + Therefore, it is *not* mandatory that the buffer of an I2C message is DMA safe. 12 + It does not seem reasonable to apply additional burdens when the feature is so 13 + rarely used. However, it is recommended to use a DMA-safe buffer if your 14 + message size is likely applicable for DMA. Most drivers have this threshold 15 + around 8 bytes (as of today, this is mostly an educated guess, however). For 16 + any message of 16 byte or larger, it is probably a really good idea. Please 17 + note that other subsystems you use might add requirements. E.g., if your 18 + I2C bus master driver is using USB as a bridge, then you need to have DMA 19 + safe buffers always, because USB requires it. 20 + 21 + Clients 22 + ------- 23 + 24 + For clients, if you use a DMA safe buffer in i2c_msg, set the I2C_M_DMA_SAFE 25 + flag with it. Then, the I2C core and drivers know they can safely operate DMA 26 + on it. Note that using this flag is optional. I2C host drivers which are not 27 + updated to use this flag will work like before. And like before, they risk 28 + using an unsafe DMA buffer. To improve this situation, using I2C_M_DMA_SAFE in 29 + more and more clients and host drivers is the planned way forward. Note also 30 + that setting this flag makes only sense in kernel space. User space data is 31 + copied into kernel space anyhow. The I2C core makes sure the destination 32 + buffers in kernel space are always DMA capable. Also, when the core emulates 33 + SMBus transactions via I2C, the buffers for block transfers are DMA safe. Users 34 + of i2c_master_send() and i2c_master_recv() functions can now use DMA safe 35 + variants (i2c_master_send_dmasafe() and i2c_master_recv_dmasafe()) once they 36 + know their buffers are DMA safe. Users of i2c_transfer() must set the 37 + I2C_M_DMA_SAFE flag manually. 38 + 39 + Masters 40 + ------- 41 + 42 + Bus master drivers wishing to implement safe DMA can use helper functions from 43 + the I2C core. One gives you a DMA-safe buffer for a given i2c_msg as long as a 44 + certain threshold is met:: 45 + 46 + dma_buf = i2c_get_dma_safe_msg_buf(msg, threshold_in_byte); 47 + 48 + If a buffer is returned, it is either msg->buf for the I2C_M_DMA_SAFE case or a 49 + bounce buffer. But you don't need to care about that detail, just use the 50 + returned buffer. If NULL is returned, the threshold was not met or a bounce 51 + buffer could not be allocated. Fall back to PIO in that case. 52 + 53 + In any case, a buffer obtained from above needs to be released. It ensures data 54 + is copied back to the message and a potentially used bounce buffer is freed:: 55 + 56 + i2c_release_dma_safe_msg_buf(msg, dma_buf); 57 + 58 + The bounce buffer handling from the core is generic and simple. It will always 59 + allocate a new bounce buffer. If you want a more sophisticated handling (e.g. 60 + reusing pre-allocated buffers), you are free to implement your own. 61 + 62 + Please also check the in-kernel documentation for details. The i2c-sh_mobile 63 + driver can be used as a reference example how to use the above helpers. 64 + 65 + Final note: If you plan to use DMA with I2C (or with anything else, actually) 66 + make sure you have CONFIG_DMA_API_DEBUG enabled during development. It can help 67 + you find various issues which can be complex to debug otherwise.
+54
Documentation/i2c/gpio-fault-injection
··· 1 + Linux I2C fault injection 2 + ========================= 3 + 4 + The GPIO based I2C bus master driver can be configured to provide fault 5 + injection capabilities. It is then meant to be connected to another I2C bus 6 + which is driven by the I2C bus master driver under test. The GPIO fault 7 + injection driver can create special states on the bus which the other I2C bus 8 + master driver should handle gracefully. 9 + 10 + Once the Kconfig option I2C_GPIO_FAULT_INJECTOR is enabled, there will be an 11 + 'i2c-fault-injector' subdirectory in the Kernel debugfs filesystem, usually 12 + mounted at /sys/kernel/debug. There will be a separate subdirectory per GPIO 13 + driven I2C bus. Each subdirectory will contain files to trigger the fault 14 + injection. They will be described now along with their intended use-cases. 15 + 16 + "scl" 17 + ----- 18 + 19 + By reading this file, you get the current state of SCL. By writing, you can 20 + change its state to either force it low or to release it again. So, by using 21 + "echo 0 > scl" you force SCL low and thus, no communication will be possible 22 + because the bus master under test will not be able to clock. It should detect 23 + the condition of SCL being unresponsive and report an error to the upper 24 + layers. 25 + 26 + "sda" 27 + ----- 28 + 29 + By reading this file, you get the current state of SDA. By writing, you can 30 + change its state to either force it low or to release it again. So, by using 31 + "echo 0 > sda" you force SDA low and thus, data cannot be transmitted. The bus 32 + master under test should detect this condition and trigger a bus recovery (see 33 + I2C specification version 4, section 3.1.16) using the helpers of the Linux I2C 34 + core (see 'struct bus_recovery_info'). However, the bus recovery will not 35 + succeed because SDA is still pinned low until you manually release it again 36 + with "echo 1 > sda". A test with an automatic release can be done with the 37 + 'incomplete_transfer' file. 38 + 39 + "incomplete_transfer" 40 + --------------------- 41 + 42 + This file is write only and you need to write the address of an existing I2C 43 + client device to it. Then, a transfer to this device will be started, but it 44 + will stop at the ACK phase after the address of the client has been 45 + transmitted. Because the device will ACK its presence, this results in SDA 46 + being pulled low by the device while SCL is high. So, similar to the "sda" file 47 + above, the bus master under test should detect this condition and try a bus 48 + recovery. This time, however, it should succeed and the device should release 49 + SDA after toggling SCL. Please note: there are I2C client devices which detect 50 + a stuck SDA on their side and release it on their own after a few milliseconds. 51 + Also, there are external devices deglitching and monitoring the I2C bus. They 52 + can also detect a stuck SDA and will init a bus recovery on their own. If you 53 + want to implement bus recovery in a bus master driver, make sure you checked 54 + your hardware setup carefully before.
+8
MAINTAINERS
··· 2288 2288 AT24 EEPROM DRIVER 2289 2289 M: Bartosz Golaszewski <brgl@bgdev.pl> 2290 2290 L: linux-i2c@vger.kernel.org 2291 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git 2291 2292 S: Maintained 2293 + F: Documentation/devicetree/bindings/eeprom/at24.txt 2292 2294 F: drivers/misc/eeprom/at24.c 2293 2295 F: include/linux/platform_data/at24.h 2294 2296 ··· 6581 6579 F: drivers/i2c/i2c-mux.c 6582 6580 F: drivers/i2c/muxes/ 6583 6581 F: include/linux/i2c-mux.h 6582 + 6583 + I2C MV64XXX MARVELL AND ALLWINNER DRIVER 6584 + M: Gregory CLEMENT <gregory.clement@free-electrons.com> 6585 + L: linux-i2c@vger.kernel.org 6586 + S: Maintained 6587 + F: drivers/i2c/busses/i2c-mv64xxx.c 6584 6588 6585 6589 I2C OVER PARALLEL PORT 6586 6590 M: Jean Delvare <jdelvare@suse.com>
+13 -2
arch/arm/mach-davinci/board-dm355-evm.c
··· 17 17 #include <linux/mtd/rawnand.h> 18 18 #include <linux/i2c.h> 19 19 #include <linux/gpio.h> 20 + #include <linux/gpio/machine.h> 20 21 #include <linux/clk.h> 21 22 #include <linux/videodev2.h> 22 23 #include <media/i2c/tvp514x.h> ··· 109 108 }, 110 109 }; 111 110 111 + static struct gpiod_lookup_table i2c_recovery_gpiod_table = { 112 + .dev_id = "i2c_davinci", 113 + .table = { 114 + GPIO_LOOKUP("davinci_gpio", 15, "sda", 115 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 116 + GPIO_LOOKUP("davinci_gpio", 14, "scl", 117 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 118 + }, 119 + }; 120 + 112 121 static struct davinci_i2c_platform_data i2c_pdata = { 113 122 .bus_freq = 400 /* kHz */, 114 123 .bus_delay = 0 /* usec */, 115 - .sda_pin = 15, 116 - .scl_pin = 14, 124 + .gpio_recovery = true, 117 125 }; 118 126 119 127 static int dm355evm_mmc_gpios = -EINVAL; ··· 151 141 152 142 static void __init evm_init_i2c(void) 153 143 { 144 + gpiod_add_lookup_table(&i2c_recovery_gpiod_table); 154 145 davinci_init_i2c(&i2c_pdata); 155 146 156 147 gpio_request(5, "dm355evm_msp");
+13 -2
arch/arm/mach-davinci/board-dm644x-evm.c
··· 13 13 #include <linux/dma-mapping.h> 14 14 #include <linux/platform_device.h> 15 15 #include <linux/gpio.h> 16 + #include <linux/gpio/machine.h> 16 17 #include <linux/i2c.h> 17 18 #include <linux/platform_data/pcf857x.h> 18 19 #include <linux/platform_data/at24.h> ··· 596 595 }, 597 596 }; 598 597 598 + static struct gpiod_lookup_table i2c_recovery_gpiod_table = { 599 + .dev_id = "i2c_davinci", 600 + .table = { 601 + GPIO_LOOKUP("davinci_gpio", 44, "sda", 602 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 603 + GPIO_LOOKUP("davinci_gpio", 43, "scl", 604 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 605 + }, 606 + }; 607 + 599 608 /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz), 600 609 * which requires 100 usec of idle bus after i2c writes sent to it. 601 610 */ 602 611 static struct davinci_i2c_platform_data i2c_pdata = { 603 612 .bus_freq = 20 /* kHz */, 604 613 .bus_delay = 100 /* usec */, 605 - .sda_pin = 44, 606 - .scl_pin = 43, 614 + .gpio_recovery = true, 607 615 }; 608 616 609 617 static void __init evm_init_i2c(void) 610 618 { 619 + gpiod_add_lookup_table(&i2c_recovery_gpiod_table); 611 620 davinci_init_i2c(&i2c_pdata); 612 621 i2c_add_driver(&dm6446evm_msp_driver); 613 622 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
+5
drivers/i2c/algos/i2c-algo-bit.c
··· 649 649 if (bit_adap->getscl == NULL) 650 650 adap->quirks = &i2c_bit_quirk_no_clk_stretch; 651 651 652 + /* Bring bus to a known state. Looks like STOP if bus is not free yet */ 653 + setscl(bit_adap, 1); 654 + udelay(bit_adap->udelay); 655 + setsda(bit_adap, 1); 656 + 652 657 ret = add_adapter(adap); 653 658 if (ret < 0) 654 659 return ret;
+8
drivers/i2c/busses/Kconfig
··· 603 603 This is a very simple bitbanging I2C driver utilizing the 604 604 arch-neutral GPIO API to control the SCL and SDA lines. 605 605 606 + config I2C_GPIO_FAULT_INJECTOR 607 + bool "GPIO-based fault injector" 608 + depends on I2C_GPIO 609 + help 610 + This adds some functionality to the i2c-gpio driver which can inject 611 + faults to an I2C bus, so another bus master can be stress-tested. 612 + This is for debugging. If unsure, say 'no'. 613 + 606 614 config I2C_HIGHLANDER 607 615 tristate "Highlander FPGA SMBus interface" 608 616 depends on SH_HIGHLANDER
+5 -3
drivers/i2c/busses/i2c-acorn.c
··· 1 1 /* 2 - * linux/drivers/acorn/char/i2c.c 2 + * ARM IOC/IOMD i2c driver. 3 3 * 4 4 * Copyright (C) 2000 Russell King 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 - * 10 - * ARM IOC/IOMD i2c driver. 11 9 * 12 10 * On Acorn machines, the following i2c devices are on the bus: 13 11 * - PCF8583 real time clock & static RAM ··· 92 94 } 93 95 94 96 module_init(i2c_ioc_init); 97 + 98 + MODULE_AUTHOR("Russell King <linux@armlinux.org.uk>"); 99 + MODULE_DESCRIPTION("ARM IOC/IOMD i2c driver"); 100 + MODULE_LICENSE("GPL v2");
+22 -15
drivers/i2c/busses/i2c-davinci.c
··· 33 33 #include <linux/io.h> 34 34 #include <linux/slab.h> 35 35 #include <linux/cpufreq.h> 36 - #include <linux/gpio.h> 36 + #include <linux/gpio/consumer.h> 37 37 #include <linux/of_device.h> 38 38 #include <linux/platform_data/i2c-davinci.h> 39 39 #include <linux/pm_runtime.h> ··· 139 139 u8 terminate; 140 140 struct i2c_adapter adapter; 141 141 #ifdef CONFIG_CPU_FREQ 142 - struct completion xfr_complete; 143 142 struct notifier_block freq_transition; 144 143 #endif 145 144 struct davinci_i2c_platform_data *pdata; ··· 293 294 } 294 295 295 296 /* 296 - * This routine does i2c bus recovery by using i2c_generic_gpio_recovery 297 + * This routine does i2c bus recovery by using i2c_generic_scl_recovery 297 298 * which is provided by I2C Bus recovery infrastructure. 298 299 */ 299 300 static void davinci_i2c_prepare_recovery(struct i2c_adapter *adap) ··· 315 316 } 316 317 317 318 static struct i2c_bus_recovery_info davinci_i2c_gpio_recovery_info = { 318 - .recover_bus = i2c_generic_gpio_recovery, 319 + .recover_bus = i2c_generic_scl_recovery, 319 320 .prepare_recovery = davinci_i2c_prepare_recovery, 320 321 .unprepare_recovery = davinci_i2c_unprepare_recovery, 321 322 }; ··· 566 567 } 567 568 568 569 ret = num; 569 - #ifdef CONFIG_CPU_FREQ 570 - complete(&dev->xfr_complete); 571 - #endif 572 570 573 571 out: 574 572 pm_runtime_mark_last_busy(dev->dev); ··· 713 717 struct davinci_i2c_dev *dev; 714 718 715 719 dev = container_of(nb, struct davinci_i2c_dev, freq_transition); 720 + 721 + i2c_lock_adapter(&dev->adapter); 716 722 if (val == CPUFREQ_PRECHANGE) { 717 - wait_for_completion(&dev->xfr_complete); 718 723 davinci_i2c_reset_ctrl(dev, 0); 719 724 } else if (val == CPUFREQ_POSTCHANGE) { 720 725 i2c_davinci_calc_clk_dividers(dev); 721 726 davinci_i2c_reset_ctrl(dev, 1); 722 727 } 728 + i2c_unlock_adapter(&dev->adapter); 723 729 724 730 return 0; 725 731 } ··· 767 769 struct davinci_i2c_dev *dev; 768 770 struct i2c_adapter *adap; 769 771 struct resource *mem; 772 + struct i2c_bus_recovery_info *rinfo; 770 773 int r, irq; 771 774 772 775 irq = platform_get_irq(pdev, 0); ··· 788 789 } 789 790 790 791 init_completion(&dev->cmd_complete); 791 - #ifdef CONFIG_CPU_FREQ 792 - init_completion(&dev->xfr_complete); 793 - #endif 792 + 794 793 dev->dev = &pdev->dev; 795 794 dev->irq = irq; 796 795 dev->pdata = dev_get_platdata(&pdev->dev); ··· 865 868 866 869 if (dev->pdata->has_pfunc) 867 870 adap->bus_recovery_info = &davinci_i2c_scl_recovery_info; 868 - else if (dev->pdata->scl_pin) { 869 - adap->bus_recovery_info = &davinci_i2c_gpio_recovery_info; 870 - adap->bus_recovery_info->scl_gpio = dev->pdata->scl_pin; 871 - adap->bus_recovery_info->sda_gpio = dev->pdata->sda_pin; 871 + else if (dev->pdata->gpio_recovery) { 872 + rinfo = &davinci_i2c_gpio_recovery_info; 873 + adap->bus_recovery_info = rinfo; 874 + rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", 875 + GPIOD_OUT_HIGH_OPEN_DRAIN); 876 + if (IS_ERR(rinfo->scl_gpiod)) { 877 + r = PTR_ERR(rinfo->scl_gpiod); 878 + goto err_unuse_clocks; 879 + } 880 + rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); 881 + if (IS_ERR(rinfo->sda_gpiod)) { 882 + r = PTR_ERR(rinfo->sda_gpiod); 883 + goto err_unuse_clocks; 884 + } 872 885 } 873 886 874 887 adap->nr = pdev->id;
+19 -1
drivers/i2c/busses/i2c-designware-common.c
··· 21 21 * ---------------------------------------------------------------------------- 22 22 * 23 23 */ 24 + #include <linux/clk.h> 24 25 #include <linux/delay.h> 25 26 #include <linux/export.h> 26 27 #include <linux/errno.h> ··· 186 185 return dev->get_clk_rate_khz(dev); 187 186 } 188 187 188 + int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare) 189 + { 190 + if (IS_ERR(dev->clk)) 191 + return PTR_ERR(dev->clk); 192 + 193 + if (prepare) 194 + return clk_prepare_enable(dev->clk); 195 + 196 + clk_disable_unprepare(dev->clk); 197 + return 0; 198 + } 199 + EXPORT_SYMBOL_GPL(i2c_dw_prepare_clk); 200 + 189 201 int i2c_dw_acquire_lock(struct dw_i2c_dev *dev) 190 202 { 191 203 int ret; ··· 231 217 while (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { 232 218 if (timeout <= 0) { 233 219 dev_warn(dev->dev, "timeout waiting for bus ready\n"); 234 - return -ETIMEDOUT; 220 + i2c_recover_bus(&dev->adapter); 221 + 222 + if (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) 223 + return -ETIMEDOUT; 224 + return 0; 235 225 } 236 226 timeout--; 237 227 usleep_range(1000, 1100);
+2
drivers/i2c/busses/i2c-designware-core.h
··· 284 284 void (*disable_int)(struct dw_i2c_dev *dev); 285 285 int (*init)(struct dw_i2c_dev *dev); 286 286 int mode; 287 + struct i2c_bus_recovery_info rinfo; 287 288 }; 288 289 289 290 #define ACCESS_SWAP 0x00000001 ··· 300 299 void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable); 301 300 void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable); 302 301 unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev); 302 + int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare); 303 303 int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); 304 304 void i2c_dw_release_lock(struct dw_i2c_dev *dev); 305 305 int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev);
+57
drivers/i2c/busses/i2c-designware-master.c
··· 25 25 #include <linux/err.h> 26 26 #include <linux/errno.h> 27 27 #include <linux/export.h> 28 + #include <linux/gpio/consumer.h> 28 29 #include <linux/i2c.h> 29 30 #include <linux/interrupt.h> 30 31 #include <linux/io.h> 31 32 #include <linux/module.h> 32 33 #include <linux/pm_runtime.h> 34 + #include <linux/reset.h> 33 35 34 36 #include "i2c-designware-core.h" 35 37 ··· 445 443 if (!wait_for_completion_timeout(&dev->cmd_complete, adap->timeout)) { 446 444 dev_err(dev->dev, "controller timed out\n"); 447 445 /* i2c_dw_init implicitly disables the adapter */ 446 + i2c_recover_bus(&dev->adapter); 448 447 i2c_dw_init_master(dev); 449 448 ret = -ETIMEDOUT; 450 449 goto done; ··· 616 613 return IRQ_HANDLED; 617 614 } 618 615 616 + static void i2c_dw_prepare_recovery(struct i2c_adapter *adap) 617 + { 618 + struct dw_i2c_dev *dev = i2c_get_adapdata(adap); 619 + 620 + i2c_dw_disable(dev); 621 + reset_control_assert(dev->rst); 622 + i2c_dw_prepare_clk(dev, false); 623 + } 624 + 625 + static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap) 626 + { 627 + struct dw_i2c_dev *dev = i2c_get_adapdata(adap); 628 + 629 + i2c_dw_prepare_clk(dev, true); 630 + reset_control_deassert(dev->rst); 631 + i2c_dw_init_master(dev); 632 + } 633 + 634 + static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) 635 + { 636 + struct i2c_bus_recovery_info *rinfo = &dev->rinfo; 637 + struct i2c_adapter *adap = &dev->adapter; 638 + struct gpio_desc *gpio; 639 + int r; 640 + 641 + gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH); 642 + if (IS_ERR(gpio)) { 643 + r = PTR_ERR(gpio); 644 + if (r == -ENOENT) 645 + return 0; 646 + return r; 647 + } 648 + rinfo->scl_gpiod = gpio; 649 + 650 + gpio = devm_gpiod_get_optional(dev->dev, "sda", GPIOD_IN); 651 + if (IS_ERR(gpio)) 652 + return PTR_ERR(gpio); 653 + rinfo->sda_gpiod = gpio; 654 + 655 + rinfo->recover_bus = i2c_generic_scl_recovery; 656 + rinfo->prepare_recovery = i2c_dw_prepare_recovery; 657 + rinfo->unprepare_recovery = i2c_dw_unprepare_recovery; 658 + adap->bus_recovery_info = rinfo; 659 + 660 + dev_info(dev->dev, "running with gpio recovery mode! scl%s", 661 + rinfo->sda_gpiod ? ",sda" : ""); 662 + 663 + return 0; 664 + } 665 + 619 666 int i2c_dw_probe(struct dw_i2c_dev *dev) 620 667 { 621 668 struct i2c_adapter *adap = &dev->adapter; ··· 704 651 dev->irq, ret); 705 652 return ret; 706 653 } 654 + 655 + ret = i2c_dw_init_recovery_info(dev); 656 + if (ret) 657 + return ret; 707 658 708 659 /* 709 660 * Increment PM usage count during adapter registration in order to
+3 -26
drivers/i2c/busses/i2c-designware-platdrv.c
··· 202 202 DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED; 203 203 204 204 dev->mode = DW_IC_SLAVE; 205 - 206 - switch (dev->clk_freq) { 207 - case 100000: 208 - dev->slave_cfg |= DW_IC_CON_SPEED_STD; 209 - break; 210 - case 3400000: 211 - dev->slave_cfg |= DW_IC_CON_SPEED_HIGH; 212 - break; 213 - default: 214 - dev->slave_cfg |= DW_IC_CON_SPEED_FAST; 215 - } 216 - } 217 - 218 - static int i2c_dw_plat_prepare_clk(struct dw_i2c_dev *i_dev, bool prepare) 219 - { 220 - if (IS_ERR(i_dev->clk)) 221 - return PTR_ERR(i_dev->clk); 222 - 223 - if (prepare) 224 - return clk_prepare_enable(i_dev->clk); 225 - 226 - clk_disable_unprepare(i_dev->clk); 227 - return 0; 228 205 } 229 206 230 207 static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id) ··· 333 356 i2c_dw_configure_master(dev); 334 357 335 358 dev->clk = devm_clk_get(&pdev->dev, NULL); 336 - if (!i2c_dw_plat_prepare_clk(dev, true)) { 359 + if (!i2c_dw_prepare_clk(dev, true)) { 337 360 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; 338 361 339 362 if (!dev->sda_hold_time && ht) ··· 449 472 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 450 473 451 474 i_dev->disable(i_dev); 452 - i2c_dw_plat_prepare_clk(i_dev, false); 475 + i2c_dw_prepare_clk(i_dev, false); 453 476 454 477 return 0; 455 478 } ··· 458 481 { 459 482 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 460 483 461 - i2c_dw_plat_prepare_clk(i_dev, true); 484 + i2c_dw_prepare_clk(i_dev, true); 462 485 i_dev->init(i_dev); 463 486 464 487 return 0;
-64
drivers/i2c/busses/i2c-designware-slave.c
··· 51 51 */ 52 52 static int i2c_dw_init_slave(struct dw_i2c_dev *dev) 53 53 { 54 - u32 sda_falling_time, scl_falling_time; 55 54 u32 reg, comp_param1; 56 - u32 hcnt, lcnt; 57 55 int ret; 58 56 59 57 ret = i2c_dw_acquire_lock(dev); ··· 76 78 77 79 /* Disable the adapter. */ 78 80 __i2c_dw_enable_and_wait(dev, false); 79 - 80 - /* Set standard and fast speed deviders for high/low periods. */ 81 - sda_falling_time = dev->sda_falling_time ?: 300; /* ns */ 82 - scl_falling_time = dev->scl_falling_time ?: 300; /* ns */ 83 - 84 - /* Set SCL timing parameters for standard-mode. */ 85 - if (dev->ss_hcnt && dev->ss_lcnt) { 86 - hcnt = dev->ss_hcnt; 87 - lcnt = dev->ss_lcnt; 88 - } else { 89 - hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), 90 - 4000, /* tHD;STA = tHIGH = 4.0 us */ 91 - sda_falling_time, 92 - 0, /* 0: DW default, 1: Ideal */ 93 - 0); /* No offset */ 94 - lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), 95 - 4700, /* tLOW = 4.7 us */ 96 - scl_falling_time, 97 - 0); /* No offset */ 98 - } 99 - dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT); 100 - dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT); 101 - dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); 102 - 103 - /* Set SCL timing parameters for fast-mode or fast-mode plus. */ 104 - if ((dev->clk_freq == 1000000) && dev->fp_hcnt && dev->fp_lcnt) { 105 - hcnt = dev->fp_hcnt; 106 - lcnt = dev->fp_lcnt; 107 - } else if (dev->fs_hcnt && dev->fs_lcnt) { 108 - hcnt = dev->fs_hcnt; 109 - lcnt = dev->fs_lcnt; 110 - } else { 111 - hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), 112 - 600, /* tHD;STA = tHIGH = 0.6 us */ 113 - sda_falling_time, 114 - 0, /* 0: DW default, 1: Ideal */ 115 - 0); /* No offset */ 116 - lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), 117 - 1300, /* tLOW = 1.3 us */ 118 - scl_falling_time, 119 - 0); /* No offset */ 120 - } 121 - dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT); 122 - dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT); 123 - dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); 124 - 125 - if ((dev->slave_cfg & DW_IC_CON_SPEED_MASK) == 126 - DW_IC_CON_SPEED_HIGH) { 127 - if ((comp_param1 & DW_IC_COMP_PARAM_1_SPEED_MODE_MASK) 128 - != DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH) { 129 - dev_err(dev->dev, "High Speed not supported!\n"); 130 - dev->slave_cfg &= ~DW_IC_CON_SPEED_MASK; 131 - dev->slave_cfg |= DW_IC_CON_SPEED_FAST; 132 - } else if (dev->hs_hcnt && dev->hs_lcnt) { 133 - hcnt = dev->hs_hcnt; 134 - lcnt = dev->hs_lcnt; 135 - dw_writel(dev, hcnt, DW_IC_HS_SCL_HCNT); 136 - dw_writel(dev, lcnt, DW_IC_HS_SCL_LCNT); 137 - dev_dbg(dev->dev, "HighSpeed-mode HCNT:LCNT = %d:%d\n", 138 - hcnt, lcnt); 139 - } 140 - } 141 81 142 82 /* Configure SDA Hold Time if required. */ 143 83 reg = dw_readl(dev, DW_IC_COMP_VERSION);
+1 -1
drivers/i2c/busses/i2c-exynos5.c
··· 170 170 #define HSI2C_HS_TX_CLOCK 1000000 171 171 #define HSI2C_FS_TX_CLOCK 100000 172 172 173 - #define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000)) 173 + #define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(100)) 174 174 175 175 #define HSI2C_EXYNOS7 BIT(0) 176 176
+118 -4
drivers/i2c/busses/i2c-gpio.c
··· 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 9 */ 10 + #include <linux/debugfs.h> 11 + #include <linux/delay.h> 10 12 #include <linux/i2c.h> 11 13 #include <linux/i2c-algo-bit.h> 12 14 #include <linux/i2c-gpio.h> ··· 25 23 struct i2c_adapter adap; 26 24 struct i2c_algo_bit_data bit_data; 27 25 struct i2c_gpio_platform_data pdata; 26 + #ifdef CONFIG_I2C_GPIO_FAULT_INJECTOR 27 + struct dentry *debug_dir; 28 + #endif 28 29 }; 29 30 30 31 /* ··· 39 34 { 40 35 struct i2c_gpio_private_data *priv = data; 41 36 42 - gpiod_set_value(priv->sda, state); 37 + gpiod_set_value_cansleep(priv->sda, state); 43 38 } 44 39 45 40 /* ··· 52 47 { 53 48 struct i2c_gpio_private_data *priv = data; 54 49 55 - gpiod_set_value(priv->scl, state); 50 + gpiod_set_value_cansleep(priv->scl, state); 56 51 } 57 52 58 53 static int i2c_gpio_getsda(void *data) 59 54 { 60 55 struct i2c_gpio_private_data *priv = data; 61 56 62 - return gpiod_get_value(priv->sda); 57 + return gpiod_get_value_cansleep(priv->sda); 63 58 } 64 59 65 60 static int i2c_gpio_getscl(void *data) 66 61 { 67 62 struct i2c_gpio_private_data *priv = data; 68 63 69 - return gpiod_get_value(priv->scl); 64 + return gpiod_get_value_cansleep(priv->scl); 70 65 } 66 + 67 + #ifdef CONFIG_I2C_GPIO_FAULT_INJECTOR 68 + static struct dentry *i2c_gpio_debug_dir; 69 + 70 + #define setsda(bd, val) ((bd)->setsda((bd)->data, val)) 71 + #define setscl(bd, val) ((bd)->setscl((bd)->data, val)) 72 + #define getsda(bd) ((bd)->getsda((bd)->data)) 73 + #define getscl(bd) ((bd)->getscl((bd)->data)) 74 + 75 + #define WIRE_ATTRIBUTE(wire) \ 76 + static int fops_##wire##_get(void *data, u64 *val) \ 77 + { \ 78 + struct i2c_gpio_private_data *priv = data; \ 79 + \ 80 + i2c_lock_adapter(&priv->adap); \ 81 + *val = get##wire(&priv->bit_data); \ 82 + i2c_unlock_adapter(&priv->adap); \ 83 + return 0; \ 84 + } \ 85 + static int fops_##wire##_set(void *data, u64 val) \ 86 + { \ 87 + struct i2c_gpio_private_data *priv = data; \ 88 + \ 89 + i2c_lock_adapter(&priv->adap); \ 90 + set##wire(&priv->bit_data, val); \ 91 + i2c_unlock_adapter(&priv->adap); \ 92 + return 0; \ 93 + } \ 94 + DEFINE_DEBUGFS_ATTRIBUTE(fops_##wire, fops_##wire##_get, fops_##wire##_set, "%llu\n") 95 + 96 + WIRE_ATTRIBUTE(scl); 97 + WIRE_ATTRIBUTE(sda); 98 + 99 + static int fops_incomplete_transfer_set(void *data, u64 addr) 100 + { 101 + struct i2c_gpio_private_data *priv = data; 102 + struct i2c_algo_bit_data *bit_data = &priv->bit_data; 103 + int i, pattern; 104 + 105 + if (addr > 0x7f) 106 + return -EINVAL; 107 + 108 + /* ADDR (7 bit) + RD (1 bit) + SDA hi (1 bit) */ 109 + pattern = (addr << 2) | 3; 110 + 111 + i2c_lock_adapter(&priv->adap); 112 + 113 + /* START condition */ 114 + setsda(bit_data, 0); 115 + udelay(bit_data->udelay); 116 + 117 + /* Send ADDR+RD, request ACK, don't send STOP */ 118 + for (i = 8; i >= 0; i--) { 119 + setscl(bit_data, 0); 120 + udelay(bit_data->udelay / 2); 121 + setsda(bit_data, (pattern >> i) & 1); 122 + udelay((bit_data->udelay + 1) / 2); 123 + setscl(bit_data, 1); 124 + udelay(bit_data->udelay); 125 + } 126 + 127 + i2c_unlock_adapter(&priv->adap); 128 + 129 + return 0; 130 + } 131 + DEFINE_DEBUGFS_ATTRIBUTE(fops_incomplete_transfer, NULL, fops_incomplete_transfer_set, "%llu\n"); 132 + 133 + static void i2c_gpio_fault_injector_init(struct platform_device *pdev) 134 + { 135 + struct i2c_gpio_private_data *priv = platform_get_drvdata(pdev); 136 + 137 + /* 138 + * If there will be a debugfs-dir per i2c adapter somewhen, put the 139 + * 'fault-injector' dir there. Until then, we have a global dir with 140 + * all adapters as subdirs. 141 + */ 142 + if (!i2c_gpio_debug_dir) { 143 + i2c_gpio_debug_dir = debugfs_create_dir("i2c-fault-injector", NULL); 144 + if (!i2c_gpio_debug_dir) 145 + return; 146 + } 147 + 148 + priv->debug_dir = debugfs_create_dir(pdev->name, i2c_gpio_debug_dir); 149 + if (!priv->debug_dir) 150 + return; 151 + 152 + debugfs_create_file_unsafe("scl", 0600, priv->debug_dir, priv, &fops_scl); 153 + debugfs_create_file_unsafe("sda", 0600, priv->debug_dir, priv, &fops_sda); 154 + debugfs_create_file_unsafe("incomplete_transfer", 0200, priv->debug_dir, 155 + priv, &fops_incomplete_transfer); 156 + } 157 + 158 + static void i2c_gpio_fault_injector_exit(struct platform_device *pdev) 159 + { 160 + struct i2c_gpio_private_data *priv = platform_get_drvdata(pdev); 161 + 162 + debugfs_remove_recursive(priv->debug_dir); 163 + } 164 + #else 165 + static inline void i2c_gpio_fault_injector_init(struct platform_device *pdev) {} 166 + static inline void i2c_gpio_fault_injector_exit(struct platform_device *pdev) {} 167 + #endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/ 71 168 72 169 static void of_i2c_gpio_get_props(struct device_node *np, 73 170 struct i2c_gpio_platform_data *pdata) ··· 286 179 if (IS_ERR(priv->scl)) 287 180 return PTR_ERR(priv->scl); 288 181 182 + if (gpiod_cansleep(priv->sda) || gpiod_cansleep(priv->scl)) 183 + dev_warn(dev, "Slow GPIO pins might wreak havoc into I2C/SMBus bus timing"); 184 + 289 185 bit_data->setsda = i2c_gpio_setsda_val; 290 186 bit_data->setscl = i2c_gpio_setscl_val; 291 187 ··· 338 228 pdata->scl_is_output_only 339 229 ? ", no clock stretching" : ""); 340 230 231 + i2c_gpio_fault_injector_init(pdev); 232 + 341 233 return 0; 342 234 } 343 235 ··· 347 235 { 348 236 struct i2c_gpio_private_data *priv; 349 237 struct i2c_adapter *adap; 238 + 239 + i2c_gpio_fault_injector_exit(pdev); 350 240 351 241 priv = platform_get_drvdata(pdev); 352 242 adap = &priv->adap;
+51 -17
drivers/i2c/busses/i2c-imx-lpi2c.c
··· 30 30 #include <linux/of_device.h> 31 31 #include <linux/pinctrl/consumer.h> 32 32 #include <linux/platform_device.h> 33 + #include <linux/pm_runtime.h> 33 34 #include <linux/sched.h> 34 35 #include <linux/slab.h> 35 36 ··· 90 89 #define FAST_MAX_BITRATE 1000000 91 90 #define FAST_PLUS_MAX_BITRATE 3400000 92 91 #define HIGHSPEED_MAX_BITRATE 5000000 92 + 93 + #define I2C_PM_TIMEOUT 10 /* ms */ 93 94 94 95 enum lpi2c_imx_mode { 95 96 STANDARD, /* 100+Kbps */ ··· 277 274 unsigned int temp; 278 275 int ret; 279 276 280 - ret = clk_enable(lpi2c_imx->clk); 281 - if (ret) 277 + ret = pm_runtime_get_sync(lpi2c_imx->adapter.dev.parent); 278 + if (ret < 0) 282 279 return ret; 283 280 284 281 temp = MCR_RST; ··· 287 284 288 285 ret = lpi2c_imx_config(lpi2c_imx); 289 286 if (ret) 290 - goto clk_disable; 287 + goto rpm_put; 291 288 292 289 temp = readl(lpi2c_imx->base + LPI2C_MCR); 293 290 temp |= MCR_MEN; ··· 295 292 296 293 return 0; 297 294 298 - clk_disable: 299 - clk_disable(lpi2c_imx->clk); 295 + rpm_put: 296 + pm_runtime_mark_last_busy(lpi2c_imx->adapter.dev.parent); 297 + pm_runtime_put_autosuspend(lpi2c_imx->adapter.dev.parent); 300 298 301 299 return ret; 302 300 } ··· 310 306 temp &= ~MCR_MEN; 311 307 writel(temp, lpi2c_imx->base + LPI2C_MCR); 312 308 313 - clk_disable(lpi2c_imx->clk); 309 + pm_runtime_mark_last_busy(lpi2c_imx->adapter.dev.parent); 310 + pm_runtime_put_autosuspend(lpi2c_imx->adapter.dev.parent); 314 311 315 312 return 0; 316 313 } ··· 611 606 return ret; 612 607 } 613 608 609 + pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); 610 + pm_runtime_use_autosuspend(&pdev->dev); 611 + pm_runtime_get_noresume(&pdev->dev); 612 + pm_runtime_set_active(&pdev->dev); 613 + pm_runtime_enable(&pdev->dev); 614 + 614 615 temp = readl(lpi2c_imx->base + LPI2C_PARAM); 615 616 lpi2c_imx->txfifosize = 1 << (temp & 0x0f); 616 617 lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f); 617 618 618 - clk_disable(lpi2c_imx->clk); 619 - 620 619 ret = i2c_add_adapter(&lpi2c_imx->adapter); 621 620 if (ret) 622 - goto clk_unprepare; 621 + goto rpm_disable; 622 + 623 + pm_runtime_mark_last_busy(&pdev->dev); 624 + pm_runtime_put_autosuspend(&pdev->dev); 623 625 624 626 dev_info(&lpi2c_imx->adapter.dev, "LPI2C adapter registered\n"); 625 627 626 628 return 0; 627 629 628 - clk_unprepare: 629 - clk_unprepare(lpi2c_imx->clk); 630 + rpm_disable: 631 + pm_runtime_put(&pdev->dev); 632 + pm_runtime_disable(&pdev->dev); 633 + pm_runtime_dont_use_autosuspend(&pdev->dev); 630 634 631 635 return ret; 632 636 } ··· 646 632 647 633 i2c_del_adapter(&lpi2c_imx->adapter); 648 634 649 - clk_unprepare(lpi2c_imx->clk); 635 + pm_runtime_disable(&pdev->dev); 636 + pm_runtime_dont_use_autosuspend(&pdev->dev); 650 637 651 638 return 0; 652 639 } 653 640 654 641 #ifdef CONFIG_PM_SLEEP 655 - static int lpi2c_imx_suspend(struct device *dev) 642 + static int lpi2c_runtime_suspend(struct device *dev) 656 643 { 644 + struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev); 645 + 646 + clk_disable_unprepare(lpi2c_imx->clk); 657 647 pinctrl_pm_select_sleep_state(dev); 658 648 659 649 return 0; 660 650 } 661 651 662 - static int lpi2c_imx_resume(struct device *dev) 652 + static int lpi2c_runtime_resume(struct device *dev) 663 653 { 654 + struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev); 655 + int ret; 656 + 664 657 pinctrl_pm_select_default_state(dev); 658 + ret = clk_prepare_enable(lpi2c_imx->clk); 659 + if (ret) { 660 + dev_err(dev, "failed to enable I2C clock, ret=%d\n", ret); 661 + return ret; 662 + } 665 663 666 664 return 0; 667 665 } 668 - #endif 669 666 670 - static SIMPLE_DEV_PM_OPS(imx_lpi2c_pm, lpi2c_imx_suspend, lpi2c_imx_resume); 667 + static const struct dev_pm_ops lpi2c_pm_ops = { 668 + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 669 + pm_runtime_force_resume) 670 + SET_RUNTIME_PM_OPS(lpi2c_runtime_suspend, 671 + lpi2c_runtime_resume, NULL) 672 + }; 673 + #define IMX_LPI2C_PM (&lpi2c_pm_ops) 674 + #else 675 + #define IMX_LPI2C_PM NULL 676 + #endif 671 677 672 678 static struct platform_driver lpi2c_imx_driver = { 673 679 .probe = lpi2c_imx_probe, ··· 695 661 .driver = { 696 662 .name = DRIVER_NAME, 697 663 .of_match_table = lpi2c_imx_of_match, 698 - .pm = &imx_lpi2c_pm, 664 + .pm = IMX_LPI2C_PM, 699 665 }, 700 666 }; 701 667
+10 -10
drivers/i2c/busses/i2c-imx.c
··· 37 37 #include <linux/dmapool.h> 38 38 #include <linux/err.h> 39 39 #include <linux/errno.h> 40 + #include <linux/gpio/consumer.h> 40 41 #include <linux/i2c.h> 41 42 #include <linux/init.h> 42 43 #include <linux/interrupt.h> ··· 47 46 #include <linux/of.h> 48 47 #include <linux/of_device.h> 49 48 #include <linux/of_dma.h> 50 - #include <linux/of_gpio.h> 51 49 #include <linux/pinctrl/consumer.h> 52 50 #include <linux/platform_data/i2c-imx.h> 53 51 #include <linux/platform_device.h> ··· 1006 1006 PINCTRL_STATE_DEFAULT); 1007 1007 i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, 1008 1008 "gpio"); 1009 - rinfo->sda_gpio = of_get_named_gpio(pdev->dev.of_node, "sda-gpios", 0); 1010 - rinfo->scl_gpio = of_get_named_gpio(pdev->dev.of_node, "scl-gpios", 0); 1009 + rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); 1010 + rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH); 1011 1011 1012 - if (rinfo->sda_gpio == -EPROBE_DEFER || 1013 - rinfo->scl_gpio == -EPROBE_DEFER) { 1012 + if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || 1013 + PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) { 1014 1014 return -EPROBE_DEFER; 1015 - } else if (!gpio_is_valid(rinfo->sda_gpio) || 1016 - !gpio_is_valid(rinfo->scl_gpio) || 1015 + } else if (IS_ERR(rinfo->sda_gpiod) || 1016 + IS_ERR(rinfo->scl_gpiod) || 1017 1017 IS_ERR(i2c_imx->pinctrl_pins_default) || 1018 1018 IS_ERR(i2c_imx->pinctrl_pins_gpio)) { 1019 1019 dev_dbg(&pdev->dev, "recovery information incomplete\n"); 1020 1020 return 0; 1021 1021 } 1022 1022 1023 - dev_dbg(&pdev->dev, "using scl-gpio %d and sda-gpio %d for recovery\n", 1024 - rinfo->scl_gpio, rinfo->sda_gpio); 1023 + dev_dbg(&pdev->dev, "using scl%s for recovery\n", 1024 + rinfo->sda_gpiod ? ",sda" : ""); 1025 1025 1026 1026 rinfo->prepare_recovery = i2c_imx_prepare_recovery; 1027 1027 rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; 1028 - rinfo->recover_bus = i2c_generic_gpio_recovery; 1028 + rinfo->recover_bus = i2c_generic_scl_recovery; 1029 1029 i2c_imx->adapter.bus_recovery_info = rinfo; 1030 1030 1031 1031 return 0;
+22 -20
drivers/i2c/busses/i2c-ismt.c
··· 172 172 dma_addr_t io_rng_dma; /* descriptor HW base addr */ 173 173 u8 head; /* ring buffer head pointer */ 174 174 struct completion cmp; /* interrupt completion */ 175 - u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* temp R/W data buffer */ 175 + u8 buffer[I2C_SMBUS_BLOCK_MAX + 16]; /* temp R/W data buffer */ 176 176 }; 177 177 178 178 /** ··· 320 320 struct ismt_priv *priv, int size, 321 321 char read_write) 322 322 { 323 - u8 *dma_buffer = priv->dma_buffer; 323 + u8 *dma_buffer = PTR_ALIGN(&priv->buffer[0], 16); 324 324 325 325 dev_dbg(&priv->pci_dev->dev, "Processing completed descriptor\n"); 326 326 __ismt_desc_dump(&priv->pci_dev->dev, desc); 327 + ismt_gen_reg_dump(priv); 328 + ismt_mstr_reg_dump(priv); 327 329 328 330 if (desc->status & ISMT_DESC_SCS) { 329 331 if (read_write == I2C_SMBUS_WRITE && ··· 395 393 struct ismt_desc *desc; 396 394 struct ismt_priv *priv = i2c_get_adapdata(adap); 397 395 struct device *dev = &priv->pci_dev->dev; 396 + u8 *dma_buffer = PTR_ALIGN(&priv->buffer[0], 16); 398 397 399 398 desc = &priv->hw[priv->head]; 400 399 401 400 /* Initialize the DMA buffer */ 402 - memset(priv->dma_buffer, 0, sizeof(priv->dma_buffer)); 401 + memset(priv->buffer, 0, sizeof(priv->buffer)); 403 402 404 403 /* Initialize the descriptor */ 405 404 memset(desc, 0, sizeof(struct ismt_desc)); ··· 449 446 desc->wr_len_cmd = 2; 450 447 dma_size = 2; 451 448 dma_direction = DMA_TO_DEVICE; 452 - priv->dma_buffer[0] = command; 453 - priv->dma_buffer[1] = data->byte; 449 + dma_buffer[0] = command; 450 + dma_buffer[1] = data->byte; 454 451 } else { 455 452 /* Read Byte */ 456 453 dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: READ\n"); ··· 469 466 desc->wr_len_cmd = 3; 470 467 dma_size = 3; 471 468 dma_direction = DMA_TO_DEVICE; 472 - priv->dma_buffer[0] = command; 473 - priv->dma_buffer[1] = data->word & 0xff; 474 - priv->dma_buffer[2] = data->word >> 8; 469 + dma_buffer[0] = command; 470 + dma_buffer[1] = data->word & 0xff; 471 + dma_buffer[2] = data->word >> 8; 475 472 } else { 476 473 /* Read Word */ 477 474 dev_dbg(dev, "I2C_SMBUS_WORD_DATA: READ\n"); ··· 489 486 desc->rd_len = 2; 490 487 dma_size = 3; 491 488 dma_direction = DMA_BIDIRECTIONAL; 492 - priv->dma_buffer[0] = command; 493 - priv->dma_buffer[1] = data->word & 0xff; 494 - priv->dma_buffer[2] = data->word >> 8; 489 + dma_buffer[0] = command; 490 + dma_buffer[1] = data->word & 0xff; 491 + dma_buffer[2] = data->word >> 8; 495 492 break; 496 493 497 494 case I2C_SMBUS_BLOCK_DATA: ··· 502 499 dma_direction = DMA_TO_DEVICE; 503 500 desc->wr_len_cmd = dma_size; 504 501 desc->control |= ISMT_DESC_BLK; 505 - priv->dma_buffer[0] = command; 506 - memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1); 502 + dma_buffer[0] = command; 503 + memcpy(&dma_buffer[1], &data->block[1], dma_size - 1); 507 504 } else { 508 505 /* Block Read */ 509 506 dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: READ\n"); ··· 530 527 dma_direction = DMA_TO_DEVICE; 531 528 desc->wr_len_cmd = dma_size; 532 529 desc->control |= ISMT_DESC_I2C; 533 - priv->dma_buffer[0] = command; 534 - memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1); 530 + dma_buffer[0] = command; 531 + memcpy(&dma_buffer[1], &data->block[1], dma_size - 1); 535 532 } else { 536 533 /* i2c Block Read */ 537 534 dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA: READ\n"); ··· 560 557 if (dma_size != 0) { 561 558 dev_dbg(dev, " dev=%p\n", dev); 562 559 dev_dbg(dev, " data=%p\n", data); 563 - dev_dbg(dev, " dma_buffer=%p\n", priv->dma_buffer); 560 + dev_dbg(dev, " dma_buffer=%p\n", dma_buffer); 564 561 dev_dbg(dev, " dma_size=%d\n", dma_size); 565 562 dev_dbg(dev, " dma_direction=%d\n", dma_direction); 566 563 567 564 dma_addr = dma_map_single(dev, 568 - priv->dma_buffer, 565 + dma_buffer, 569 566 dma_size, 570 567 dma_direction); 571 568 572 569 if (dma_mapping_error(dev, dma_addr)) { 573 570 dev_err(dev, "Error in mapping dma buffer %p\n", 574 - priv->dma_buffer); 571 + dma_buffer); 575 572 return -EIO; 576 573 } 577 574 578 - dev_dbg(dev, " dma_addr = 0x%016llX\n", 579 - (unsigned long long)dma_addr); 575 + dev_dbg(dev, " dma_addr = %pad\n", &dma_addr); 580 576 581 577 desc->dptr_low = lower_32_bits(dma_addr); 582 578 desc->dptr_high = upper_32_bits(dma_addr);
+30 -6
drivers/i2c/busses/i2c-meson.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 18 #include <linux/of.h> 19 + #include <linux/of_device.h> 19 20 #include <linux/platform_device.h> 20 21 #include <linux/types.h> 21 22 ··· 58 57 STATE_WRITE, 59 58 }; 60 59 60 + struct meson_i2c_data { 61 + unsigned char div_factor; 62 + }; 63 + 61 64 /** 62 65 * struct meson_i2c - Meson I2C device private data 63 66 * ··· 69 64 * @dev: Pointer to device structure 70 65 * @regs: Base address of the device memory mapped registers 71 66 * @clk: Pointer to clock structure 72 - * @irq: IRQ number 73 67 * @msg: Pointer to the current I2C message 74 68 * @state: Current state in the driver state machine 75 69 * @last: Flag set for the last message in the transfer ··· 79 75 * @done: Completion used to wait for transfer termination 80 76 * @tokens: Sequence of tokens to be written to the device 81 77 * @num_tokens: Number of tokens 78 + * @data: Pointer to the controlller's platform data 82 79 */ 83 80 struct meson_i2c { 84 81 struct i2c_adapter adap; ··· 98 93 struct completion done; 99 94 u32 tokens[2]; 100 95 int num_tokens; 96 + 97 + const struct meson_i2c_data *data; 101 98 }; 102 99 103 100 static void meson_i2c_set_mask(struct meson_i2c *i2c, int reg, u32 mask, ··· 135 128 unsigned long clk_rate = clk_get_rate(i2c->clk); 136 129 unsigned int div; 137 130 138 - div = DIV_ROUND_UP(clk_rate, freq * 4); 131 + div = DIV_ROUND_UP(clk_rate, freq * i2c->data->div_factor); 139 132 140 133 /* clock divider has 12 bits */ 141 134 if (div >= (1 << 12)) { ··· 383 376 spin_lock_init(&i2c->lock); 384 377 init_completion(&i2c->done); 385 378 379 + i2c->data = (const struct meson_i2c_data *) 380 + of_device_get_match_data(&pdev->dev); 381 + 386 382 i2c->clk = devm_clk_get(&pdev->dev, NULL); 387 383 if (IS_ERR(i2c->clk)) { 388 384 dev_err(&pdev->dev, "can't get device clock\n"); ··· 450 440 return 0; 451 441 } 452 442 453 - static const struct of_device_id meson_i2c_match[] = { 454 - { .compatible = "amlogic,meson6-i2c" }, 455 - { .compatible = "amlogic,meson-gxbb-i2c" }, 456 - { }, 443 + static const struct meson_i2c_data i2c_meson6_data = { 444 + .div_factor = 4, 457 445 }; 446 + 447 + static const struct meson_i2c_data i2c_gxbb_data = { 448 + .div_factor = 4, 449 + }; 450 + 451 + static const struct meson_i2c_data i2c_axg_data = { 452 + .div_factor = 3, 453 + }; 454 + 455 + static const struct of_device_id meson_i2c_match[] = { 456 + { .compatible = "amlogic,meson6-i2c", .data = &i2c_meson6_data }, 457 + { .compatible = "amlogic,meson-gxbb-i2c", .data = &i2c_gxbb_data }, 458 + { .compatible = "amlogic,meson-axg-i2c", .data = &i2c_axg_data }, 459 + {}, 460 + }; 461 + 458 462 MODULE_DEVICE_TABLE(of, meson_i2c_match); 459 463 460 464 static struct platform_driver meson_i2c_driver = {
+30 -27
drivers/i2c/busses/i2c-mpc.c
··· 78 78 }; 79 79 80 80 struct mpc_i2c_data { 81 - void (*setup)(struct device_node *node, struct mpc_i2c *i2c, 82 - u32 clock, u32 prescaler); 83 - u32 prescaler; 81 + void (*setup)(struct device_node *node, struct mpc_i2c *i2c, u32 clock); 84 82 }; 85 83 86 84 static inline void writeccr(struct mpc_i2c *i2c, u32 x) ··· 199 201 }; 200 202 201 203 static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, 202 - int prescaler, u32 *real_clk) 204 + u32 *real_clk) 203 205 { 204 206 const struct mpc_i2c_divider *div = NULL; 205 207 unsigned int pvr = mfspr(SPRN_PVR); ··· 234 236 235 237 static void mpc_i2c_setup_52xx(struct device_node *node, 236 238 struct mpc_i2c *i2c, 237 - u32 clock, u32 prescaler) 239 + u32 clock) 238 240 { 239 241 int ret, fdr; 240 242 ··· 244 246 return; 245 247 } 246 248 247 - ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler, &i2c->real_clk); 249 + ret = mpc_i2c_get_fdr_52xx(node, clock, &i2c->real_clk); 248 250 fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ 249 251 250 252 writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); ··· 256 258 #else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ 257 259 static void mpc_i2c_setup_52xx(struct device_node *node, 258 260 struct mpc_i2c *i2c, 259 - u32 clock, u32 prescaler) 261 + u32 clock) 260 262 { 261 263 } 262 264 #endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ ··· 264 266 #ifdef CONFIG_PPC_MPC512x 265 267 static void mpc_i2c_setup_512x(struct device_node *node, 266 268 struct mpc_i2c *i2c, 267 - u32 clock, u32 prescaler) 269 + u32 clock) 268 270 { 269 271 struct device_node *node_ctrl; 270 272 void __iomem *ctrl; ··· 287 289 } 288 290 289 291 /* The clock setup for the 52xx works also fine for the 512x */ 290 - mpc_i2c_setup_52xx(node, i2c, clock, prescaler); 292 + mpc_i2c_setup_52xx(node, i2c, clock); 291 293 } 292 294 #else /* CONFIG_PPC_MPC512x */ 293 295 static void mpc_i2c_setup_512x(struct device_node *node, 294 296 struct mpc_i2c *i2c, 295 - u32 clock, u32 prescaler) 297 + u32 clock) 296 298 { 297 299 } 298 300 #endif /* CONFIG_PPC_MPC512x */ ··· 330 332 if (prop) { 331 333 /* 332 334 * Map and check POR Device Status Register 2 333 - * (PORDEVSR2) at 0xE0014 335 + * (PORDEVSR2) at 0xE0014. Note than while MPC8533 336 + * and MPC8544 indicate SEC frequency ratio 337 + * configuration as bit 26 in PORDEVSR2, other MPC8xxx 338 + * parts may store it differently or may not have it 339 + * at all. 334 340 */ 335 341 reg = ioremap(get_immrbase() + *prop + 0x14, 0x4); 336 342 if (!reg) 337 343 printk(KERN_ERR 338 344 "Error: couldn't map PORDEVSR2\n"); 339 345 else 340 - val = in_be32(reg) & 0x00000080; /* sec-cfg */ 346 + val = in_be32(reg) & 0x00000020; /* sec-cfg */ 341 347 iounmap(reg); 342 348 } 343 349 } ··· 352 350 353 351 static u32 mpc_i2c_get_prescaler_8xxx(void) 354 352 { 355 - /* mpc83xx and mpc82xx all have prescaler 1 */ 353 + /* 354 + * According to the AN2919 all MPC824x have prescaler 1, while MPC83xx 355 + * may have prescaler 1, 2, or 3, depending on the power-on 356 + * configuration. 357 + */ 356 358 u32 prescaler = 1; 357 359 358 360 /* mpc85xx */ ··· 373 367 || (SVR_SOC_VER(svr) == SVR_8610)) 374 368 /* the above 85xx SoCs have prescaler 1 */ 375 369 prescaler = 1; 370 + else if ((SVR_SOC_VER(svr) == SVR_8533) 371 + || (SVR_SOC_VER(svr) == SVR_8544)) 372 + /* the above 85xx SoCs have prescaler 3 or 2 */ 373 + prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2; 376 374 else 377 375 /* all the other 85xx have prescaler 2 */ 378 376 prescaler = 2; ··· 386 376 } 387 377 388 378 static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, 389 - u32 prescaler, u32 *real_clk) 379 + u32 *real_clk) 390 380 { 391 381 const struct mpc_i2c_divider *div = NULL; 382 + u32 prescaler = mpc_i2c_get_prescaler_8xxx(); 392 383 u32 divider; 393 384 int i; 394 385 ··· 398 387 *real_clk = fsl_get_sys_freq() / prescaler / (16 * 3072); 399 388 return -EINVAL; 400 389 } 401 - 402 - /* Determine proper divider value */ 403 - if (of_device_is_compatible(node, "fsl,mpc8544-i2c")) 404 - prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2; 405 - if (!prescaler) 406 - prescaler = mpc_i2c_get_prescaler_8xxx(); 407 390 408 391 divider = fsl_get_sys_freq() / clock / prescaler; 409 392 ··· 420 415 421 416 static void mpc_i2c_setup_8xxx(struct device_node *node, 422 417 struct mpc_i2c *i2c, 423 - u32 clock, u32 prescaler) 418 + u32 clock) 424 419 { 425 420 int ret, fdr; 426 421 ··· 431 426 return; 432 427 } 433 428 434 - ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler, &i2c->real_clk); 429 + ret = mpc_i2c_get_fdr_8xxx(node, clock, &i2c->real_clk); 435 430 fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ 436 431 437 432 writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); ··· 445 440 #else /* !CONFIG_FSL_SOC */ 446 441 static void mpc_i2c_setup_8xxx(struct device_node *node, 447 442 struct mpc_i2c *i2c, 448 - u32 clock, u32 prescaler) 443 + u32 clock) 449 444 { 450 445 } 451 446 #endif /* CONFIG_FSL_SOC */ ··· 716 711 717 712 if (match->data) { 718 713 const struct mpc_i2c_data *data = match->data; 719 - data->setup(op->dev.of_node, i2c, clock, data->prescaler); 714 + data->setup(op->dev.of_node, i2c, clock); 720 715 } else { 721 716 /* Backwards compatibility */ 722 717 if (of_get_property(op->dev.of_node, "dfsrr", NULL)) 723 - mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock, 0); 718 + mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock); 724 719 } 725 720 726 721 prop = of_get_property(op->dev.of_node, "fsl,timeout", &plen); ··· 818 813 819 814 static const struct mpc_i2c_data mpc_i2c_data_8543 = { 820 815 .setup = mpc_i2c_setup_8xxx, 821 - .prescaler = 2, 822 816 }; 823 817 824 818 static const struct mpc_i2c_data mpc_i2c_data_8544 = { 825 819 .setup = mpc_i2c_setup_8xxx, 826 - .prescaler = 3, 827 820 }; 828 821 829 822 static const struct of_device_id mpc_i2c_of_match[] = {
+36 -4
drivers/i2c/busses/i2c-mt65xx.c
··· 61 61 #define I2C_DMA_HARD_RST 0x0002 62 62 #define I2C_DMA_4G_MODE 0x0001 63 63 64 + #define I2C_DEFAULT_CLK_DIV 5 64 65 #define I2C_DEFAULT_SPEED 100000 /* hz */ 65 66 #define MAX_FS_MODE_SPEED 400000 66 67 #define MAX_HS_MODE_SPEED 3400000 ··· 128 127 OFFSET_DEBUGSTAT = 0x64, 129 128 OFFSET_DEBUGCTRL = 0x68, 130 129 OFFSET_TRANSFER_LEN_AUX = 0x6c, 130 + OFFSET_CLOCK_DIV = 0x70, 131 131 }; 132 132 133 133 struct mtk_i2c_compatible { ··· 138 136 unsigned char auto_restart: 1; 139 137 unsigned char aux_len_reg: 1; 140 138 unsigned char support_33bits: 1; 139 + unsigned char timing_adjust: 1; 141 140 }; 142 141 143 142 struct mtk_i2c { ··· 179 176 .max_num_msgs = 255, 180 177 }; 181 178 179 + static const struct mtk_i2c_compatible mt2712_compat = { 180 + .pmic_i2c = 0, 181 + .dcm = 1, 182 + .auto_restart = 1, 183 + .aux_len_reg = 1, 184 + .support_33bits = 1, 185 + .timing_adjust = 1, 186 + }; 187 + 182 188 static const struct mtk_i2c_compatible mt6577_compat = { 183 189 .quirks = &mt6577_i2c_quirks, 184 190 .pmic_i2c = 0, ··· 195 183 .auto_restart = 0, 196 184 .aux_len_reg = 0, 197 185 .support_33bits = 0, 186 + .timing_adjust = 0, 198 187 }; 199 188 200 189 static const struct mtk_i2c_compatible mt6589_compat = { ··· 205 192 .auto_restart = 0, 206 193 .aux_len_reg = 0, 207 194 .support_33bits = 0, 195 + .timing_adjust = 0, 208 196 }; 209 197 210 198 static const struct mtk_i2c_compatible mt7622_compat = { ··· 215 201 .auto_restart = 1, 216 202 .aux_len_reg = 1, 217 203 .support_33bits = 0, 204 + .timing_adjust = 0, 218 205 }; 219 206 220 207 static const struct mtk_i2c_compatible mt8173_compat = { ··· 224 209 .auto_restart = 1, 225 210 .aux_len_reg = 1, 226 211 .support_33bits = 1, 212 + .timing_adjust = 0, 227 213 }; 228 214 229 215 static const struct of_device_id mtk_i2c_of_match[] = { 216 + { .compatible = "mediatek,mt2712-i2c", .data = &mt2712_compat }, 230 217 { .compatible = "mediatek,mt6577-i2c", .data = &mt6577_compat }, 231 218 { .compatible = "mediatek,mt6589-i2c", .data = &mt6589_compat }, 232 219 { .compatible = "mediatek,mt7622-i2c", .data = &mt7622_compat }, ··· 287 270 288 271 if (i2c->dev_comp->dcm) 289 272 writew(I2C_DCM_DISABLE, i2c->base + OFFSET_DCM_EN); 273 + 274 + if (i2c->dev_comp->timing_adjust) 275 + writew(I2C_DEFAULT_CLK_DIV - 1, i2c->base + OFFSET_CLOCK_DIV); 290 276 291 277 writew(i2c->timing_reg, i2c->base + OFFSET_TIMING); 292 278 writew(i2c->high_speed_reg, i2c->base + OFFSET_HS); ··· 745 725 if (!i2c) 746 726 return -ENOMEM; 747 727 748 - ret = mtk_i2c_parse_dt(pdev->dev.of_node, i2c); 749 - if (ret) 750 - return -EINVAL; 751 - 752 728 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 753 729 i2c->base = devm_ioremap_resource(&pdev->dev, res); 754 730 if (IS_ERR(i2c->base)) ··· 774 758 i2c->adap.quirks = i2c->dev_comp->quirks; 775 759 i2c->adap.timeout = 2 * HZ; 776 760 i2c->adap.retries = 1; 761 + 762 + ret = mtk_i2c_parse_dt(pdev->dev.of_node, i2c); 763 + if (ret) 764 + return -EINVAL; 765 + 766 + if (i2c->dev_comp->timing_adjust) 767 + i2c->clk_src_div *= I2C_DEFAULT_CLK_DIV; 777 768 778 769 if (i2c->have_pmic && !i2c->dev_comp->pmic_i2c) 779 770 return -EINVAL; ··· 861 838 #ifdef CONFIG_PM_SLEEP 862 839 static int mtk_i2c_resume(struct device *dev) 863 840 { 841 + int ret; 864 842 struct mtk_i2c *i2c = dev_get_drvdata(dev); 865 843 844 + ret = mtk_i2c_clock_enable(i2c); 845 + if (ret) { 846 + dev_err(dev, "clock enable failed!\n"); 847 + return ret; 848 + } 849 + 866 850 mtk_i2c_init_hw(i2c); 851 + 852 + mtk_i2c_clock_disable(i2c); 867 853 868 854 return 0; 869 855 }
+13 -7
drivers/i2c/busses/i2c-mv64xxx.c
··· 135 135 u32 freq_m; 136 136 u32 freq_n; 137 137 struct clk *clk; 138 + struct clk *reg_clk; 138 139 wait_queue_head_t waitq; 139 140 spinlock_t lock; 140 141 struct i2c_msg *msg; ··· 895 894 init_waitqueue_head(&drv_data->waitq); 896 895 spin_lock_init(&drv_data->lock); 897 896 898 - /* Not all platforms have a clk */ 897 + /* Not all platforms have clocks */ 899 898 drv_data->clk = devm_clk_get(&pd->dev, NULL); 900 899 if (IS_ERR(drv_data->clk) && PTR_ERR(drv_data->clk) == -EPROBE_DEFER) 901 900 return -EPROBE_DEFER; 902 901 if (!IS_ERR(drv_data->clk)) 903 902 clk_prepare_enable(drv_data->clk); 903 + 904 + drv_data->reg_clk = devm_clk_get(&pd->dev, "reg"); 905 + if (IS_ERR(drv_data->reg_clk) && 906 + PTR_ERR(drv_data->reg_clk) == -EPROBE_DEFER) 907 + return -EPROBE_DEFER; 908 + if (!IS_ERR(drv_data->reg_clk)) 909 + clk_prepare_enable(drv_data->reg_clk); 904 910 905 911 drv_data->irq = platform_get_irq(pd, 0); 906 912 ··· 958 950 exit_reset: 959 951 reset_control_assert(drv_data->rstc); 960 952 exit_clk: 961 - /* Not all platforms have a clk */ 962 - if (!IS_ERR(drv_data->clk)) 963 - clk_disable_unprepare(drv_data->clk); 953 + clk_disable_unprepare(drv_data->reg_clk); 954 + clk_disable_unprepare(drv_data->clk); 964 955 965 956 return rc; 966 957 } ··· 972 965 i2c_del_adapter(&drv_data->adapter); 973 966 free_irq(drv_data->irq, drv_data); 974 967 reset_control_assert(drv_data->rstc); 975 - /* Not all platforms have a clk */ 976 - if (!IS_ERR(drv_data->clk)) 977 - clk_disable_unprepare(drv_data->clk); 968 + clk_disable_unprepare(drv_data->reg_clk); 969 + clk_disable_unprepare(drv_data->clk); 978 970 979 971 return 0; 980 972 }
+2 -2
drivers/i2c/busses/i2c-mxs.c
··· 181 181 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 182 182 183 183 if (msg->flags & I2C_M_RD) { 184 - i2c->dma_read = 1; 184 + i2c->dma_read = true; 185 185 i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_READ; 186 186 187 187 /* ··· 239 239 goto read_init_dma_fail; 240 240 } 241 241 } else { 242 - i2c->dma_read = 0; 242 + i2c->dma_read = false; 243 243 i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_WRITE; 244 244 245 245 /*
+56 -6
drivers/i2c/busses/i2c-rcar.c
··· 62 62 #define MIE (1 << 3) /* master if enable */ 63 63 #define TSBE (1 << 2) 64 64 #define FSB (1 << 1) /* force stop bit */ 65 - #define ESG (1 << 0) /* en startbit gen */ 65 + #define ESG (1 << 0) /* enable start bit gen */ 66 66 67 67 /* ICSSR (also for ICSIER) */ 68 68 #define GCAR (1 << 6) /* general call received */ ··· 132 132 int pos; 133 133 u32 icccr; 134 134 u32 flags; 135 + u8 recovery_icmcr; /* protected by adapter lock */ 135 136 enum rcar_i2c_type devtype; 136 137 struct i2c_client *slave; 137 138 ··· 159 158 return readl(priv->io + reg); 160 159 } 161 160 161 + static int rcar_i2c_get_scl(struct i2c_adapter *adap) 162 + { 163 + struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); 164 + 165 + return !!(rcar_i2c_read(priv, ICMCR) & FSCL); 166 + 167 + }; 168 + 169 + static void rcar_i2c_set_scl(struct i2c_adapter *adap, int val) 170 + { 171 + struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); 172 + 173 + if (val) 174 + priv->recovery_icmcr |= FSCL; 175 + else 176 + priv->recovery_icmcr &= ~FSCL; 177 + 178 + rcar_i2c_write(priv, ICMCR, priv->recovery_icmcr); 179 + }; 180 + 181 + /* No get_sda, because the HW only reports its bus free logic, not SDA itself */ 182 + 183 + static void rcar_i2c_set_sda(struct i2c_adapter *adap, int val) 184 + { 185 + struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); 186 + 187 + if (val) 188 + priv->recovery_icmcr |= FSDA; 189 + else 190 + priv->recovery_icmcr &= ~FSDA; 191 + 192 + rcar_i2c_write(priv, ICMCR, priv->recovery_icmcr); 193 + }; 194 + 195 + static struct i2c_bus_recovery_info rcar_i2c_bri = { 196 + .get_scl = rcar_i2c_get_scl, 197 + .set_scl = rcar_i2c_set_scl, 198 + .set_sda = rcar_i2c_set_sda, 199 + .recover_bus = i2c_generic_scl_recovery, 200 + }; 162 201 static void rcar_i2c_init(struct rcar_i2c_priv *priv) 163 202 { 164 203 /* reset master mode */ ··· 211 170 212 171 static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) 213 172 { 214 - int i; 173 + int i, ret; 215 174 216 175 for (i = 0; i < LOOP_TIMEOUT; i++) { 217 176 /* make sure that bus is not busy */ ··· 220 179 udelay(1); 221 180 } 222 181 223 - return -EBUSY; 182 + /* Waiting did not help, try to recover */ 183 + priv->recovery_icmcr = MDBS | OBPC | FSDA | FSCL; 184 + ret = i2c_recover_bus(&priv->adap); 185 + 186 + /* No failure when recovering, so check bus busy bit again */ 187 + if (ret == 0) 188 + ret = (rcar_i2c_read(priv, ICMCR) & FSDA) ? -EBUSY : 0; 189 + 190 + return ret; 224 191 } 225 192 226 193 static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timings *t) ··· 331 282 332 283 rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); 333 284 /* 334 - * We don't have a testcase but the HW engineers say that the write order 285 + * We don't have a test case but the HW engineers say that the write order 335 286 * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since 336 287 * it didn't cause a drawback for me, let's rather be safe than sorry. 337 288 */ ··· 408 359 int len; 409 360 410 361 /* Do not use DMA if it's not available or for messages < 8 bytes */ 411 - if (IS_ERR(chan) || msg->len < 8) 362 + if (IS_ERR(chan) || msg->len < 8 || !(msg->flags & I2C_M_DMA_SAFE)) 412 363 return; 413 364 414 365 if (read) { ··· 489 440 490 441 /* 491 442 * Try to use DMA to transmit the rest of the data if 492 - * address transfer pashe just finished. 443 + * address transfer phase just finished. 493 444 */ 494 445 if (msr & MAT) 495 446 rcar_i2c_dma(priv); ··· 900 851 adap->retries = 3; 901 852 adap->dev.parent = dev; 902 853 adap->dev.of_node = dev->of_node; 854 + adap->bus_recovery_info = &rcar_i2c_bri; 903 855 i2c_set_adapdata(adap, priv); 904 856 strlcpy(adap->name, pdev->name, sizeof(adap->name)); 905 857
+9 -8
drivers/i2c/busses/i2c-rk3x.c
··· 161 161 }; 162 162 163 163 /** 164 + * struct rk3x_i2c_soc_data: 164 165 * @grf_offset: offset inside the grf regmap for setting the i2c type 165 166 * @calc_timings: Callback function for i2c timing information calculated 166 167 */ ··· 195 194 struct rk3x_i2c { 196 195 struct i2c_adapter adap; 197 196 struct device *dev; 198 - struct rk3x_i2c_soc_data *soc_data; 197 + const struct rk3x_i2c_soc_data *soc_data; 199 198 200 199 /* Hardware resources */ 201 200 void __iomem *regs; ··· 1165 1164 static const struct of_device_id rk3x_i2c_match[] = { 1166 1165 { 1167 1166 .compatible = "rockchip,rv1108-i2c", 1168 - .data = (void *)&rv1108_soc_data 1167 + .data = &rv1108_soc_data 1169 1168 }, 1170 1169 { 1171 1170 .compatible = "rockchip,rk3066-i2c", 1172 - .data = (void *)&rk3066_soc_data 1171 + .data = &rk3066_soc_data 1173 1172 }, 1174 1173 { 1175 1174 .compatible = "rockchip,rk3188-i2c", 1176 - .data = (void *)&rk3188_soc_data 1175 + .data = &rk3188_soc_data 1177 1176 }, 1178 1177 { 1179 1178 .compatible = "rockchip,rk3228-i2c", 1180 - .data = (void *)&rk3228_soc_data 1179 + .data = &rk3228_soc_data 1181 1180 }, 1182 1181 { 1183 1182 .compatible = "rockchip,rk3288-i2c", 1184 - .data = (void *)&rk3288_soc_data 1183 + .data = &rk3288_soc_data 1185 1184 }, 1186 1185 { 1187 1186 .compatible = "rockchip,rk3399-i2c", 1188 - .data = (void *)&rk3399_soc_data 1187 + .data = &rk3399_soc_data 1189 1188 }, 1190 1189 {}, 1191 1190 }; ··· 1208 1207 return -ENOMEM; 1209 1208 1210 1209 match = of_match_node(rk3x_i2c_match, np); 1211 - i2c->soc_data = (struct rk3x_i2c_soc_data *)match->data; 1210 + i2c->soc_data = match->data; 1212 1211 1213 1212 /* use common interface to get I2C timing properties */ 1214 1213 i2c_parse_fw_timings(&pdev->dev, &i2c->t, true);
+86 -105
drivers/i2c/busses/i2c-sh_mobile.c
··· 40 40 /* BUS: S A8 ACK P(*) */ 41 41 /* IRQ: DTE WAIT */ 42 42 /* ICIC: */ 43 - /* ICCR: 0x94 0x90 */ 43 + /* ICCR: 0x94 0x90 */ 44 44 /* ICDR: A8 */ 45 45 /* */ 46 46 /* 1 byte transmit */ 47 47 /* BUS: S A8 ACK D8(1) ACK P(*) */ 48 48 /* IRQ: DTE WAIT WAIT */ 49 49 /* ICIC: -DTE */ 50 - /* ICCR: 0x94 0x90 */ 50 + /* ICCR: 0x94 0x90 */ 51 51 /* ICDR: A8 D8(1) */ 52 52 /* */ 53 53 /* 2 byte transmit */ 54 54 /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P(*) */ 55 55 /* IRQ: DTE WAIT WAIT WAIT */ 56 56 /* ICIC: -DTE */ 57 - /* ICCR: 0x94 0x90 */ 57 + /* ICCR: 0x94 0x90 */ 58 58 /* ICDR: A8 D8(1) D8(2) */ 59 59 /* */ 60 60 /* 3 bytes or more, +---------+ gets repeated */ ··· 113 113 OP_TX_FIRST, 114 114 OP_TX, 115 115 OP_TX_STOP, 116 - OP_TX_STOP_DATA, 117 116 OP_TX_TO_RX, 118 117 OP_RX, 119 118 OP_RX_STOP, ··· 144 145 struct dma_chan *dma_rx; 145 146 struct scatterlist sg; 146 147 enum dma_data_direction dma_direction; 148 + u8 *dma_buf; 147 149 }; 148 150 149 151 struct sh_mobile_dt_config { 150 152 int clks_per_count; 151 - void (*setup)(struct sh_mobile_i2c_data *pd); 153 + int (*setup)(struct sh_mobile_i2c_data *pd); 152 154 }; 153 155 154 156 #define IIC_FLAG_HAS_ICIC67 (1 << 0) ··· 246 246 return (((count_khz * (tHIGH + tf)) + 5000) / 10000); 247 247 } 248 248 249 - static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) 249 + static int sh_mobile_i2c_check_timing(struct sh_mobile_i2c_data *pd) 250 250 { 251 - unsigned long i2c_clk_khz; 252 - u32 tHIGH, tLOW, tf; 253 - uint16_t max_val; 251 + u16 max_val = pd->flags & IIC_FLAG_HAS_ICIC67 ? 0x1ff : 0xff; 254 252 255 - /* Get clock rate after clock is enabled */ 256 - clk_prepare_enable(pd->clk); 257 - i2c_clk_khz = clk_get_rate(pd->clk) / 1000; 258 - clk_disable_unprepare(pd->clk); 259 - i2c_clk_khz /= pd->clks_per_count; 260 - 261 - if (pd->bus_speed == STANDARD_MODE) { 262 - tLOW = 47; /* tLOW = 4.7 us */ 263 - tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ 264 - tf = 3; /* tf = 0.3 us */ 265 - } else if (pd->bus_speed == FAST_MODE) { 266 - tLOW = 13; /* tLOW = 1.3 us */ 267 - tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ 268 - tf = 3; /* tf = 0.3 us */ 269 - } else { 270 - dev_err(pd->dev, "unrecognized bus speed %lu Hz\n", 271 - pd->bus_speed); 272 - return -EINVAL; 273 - } 274 - 275 - pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf); 276 - pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf); 277 - 278 - max_val = pd->flags & IIC_FLAG_HAS_ICIC67 ? 0x1ff : 0xff; 279 253 if (pd->iccl > max_val || pd->icch > max_val) { 280 254 dev_err(pd->dev, "timing values out of range: L/H=0x%x/0x%x\n", 281 255 pd->iccl, pd->icch); ··· 272 298 return 0; 273 299 } 274 300 275 - static void activate_ch(struct sh_mobile_i2c_data *pd) 301 + static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) 276 302 { 277 - /* Wake up device and enable clock */ 278 - pm_runtime_get_sync(pd->dev); 279 - clk_prepare_enable(pd->clk); 303 + unsigned long i2c_clk_khz; 304 + u32 tHIGH, tLOW, tf; 280 305 281 - /* Enable channel and configure rx ack */ 282 - iic_set_clr(pd, ICCR, ICCR_ICE, 0); 306 + i2c_clk_khz = clk_get_rate(pd->clk) / 1000 / pd->clks_per_count; 283 307 284 - /* Mask all interrupts */ 285 - iic_wr(pd, ICIC, 0); 308 + if (pd->bus_speed == STANDARD_MODE) { 309 + tLOW = 47; /* tLOW = 4.7 us */ 310 + tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ 311 + tf = 3; /* tf = 0.3 us */ 312 + } else if (pd->bus_speed == FAST_MODE) { 313 + tLOW = 13; /* tLOW = 1.3 us */ 314 + tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ 315 + tf = 3; /* tf = 0.3 us */ 316 + } else { 317 + dev_err(pd->dev, "unrecognized bus speed %lu Hz\n", 318 + pd->bus_speed); 319 + return -EINVAL; 320 + } 286 321 287 - /* Set the clock */ 288 - iic_wr(pd, ICCL, pd->iccl & 0xff); 289 - iic_wr(pd, ICCH, pd->icch & 0xff); 322 + pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf); 323 + pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf); 324 + 325 + return sh_mobile_i2c_check_timing(pd); 290 326 } 291 327 292 - static void deactivate_ch(struct sh_mobile_i2c_data *pd) 328 + static int sh_mobile_i2c_v2_init(struct sh_mobile_i2c_data *pd) 293 329 { 294 - /* Clear/disable interrupts */ 295 - iic_wr(pd, ICSR, 0); 296 - iic_wr(pd, ICIC, 0); 330 + unsigned long clks_per_cycle; 297 331 298 - /* Disable channel */ 299 - iic_set_clr(pd, ICCR, 0, ICCR_ICE); 332 + /* L = 5, H = 4, L + H = 9 */ 333 + clks_per_cycle = clk_get_rate(pd->clk) / pd->bus_speed; 334 + pd->iccl = DIV_ROUND_UP(clks_per_cycle * 5 / 9 - 1, pd->clks_per_count); 335 + pd->icch = DIV_ROUND_UP(clks_per_cycle * 4 / 9 - 5, pd->clks_per_count); 300 336 301 - /* Disable clock and mark device as idle */ 302 - clk_disable_unprepare(pd->clk); 303 - pm_runtime_put_sync(pd->dev); 337 + return sh_mobile_i2c_check_timing(pd); 304 338 } 305 339 306 340 static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, ··· 332 350 case OP_TX: /* write data */ 333 351 iic_wr(pd, ICDR, data); 334 352 break; 335 - case OP_TX_STOP_DATA: /* write data and issue a stop afterwards */ 336 - iic_wr(pd, ICDR, data); 337 - /* fallthrough */ 338 - case OP_TX_STOP: /* issue a stop */ 353 + case OP_TX_STOP: /* issue a stop (or rep_start) */ 339 354 iic_wr(pd, ICCR, pd->send_stop ? ICCR_ICE | ICCR_TRS 340 355 : ICCR_ICE | ICCR_TRS | ICCR_BBSY); 341 356 break; ··· 366 387 return pd->pos == -1; 367 388 } 368 389 369 - static bool sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd) 370 - { 371 - return pd->pos == pd->msg->len - 1; 372 - } 373 - 374 390 static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd, 375 391 unsigned char *buf) 376 392 { ··· 383 409 unsigned char data; 384 410 385 411 if (pd->pos == pd->msg->len) { 386 - /* Send stop if we haven't yet (DMA case) */ 387 - if (pd->send_stop && pd->stop_after_dma) 388 - i2c_op(pd, OP_TX_STOP, 0); 412 + i2c_op(pd, OP_TX_STOP, 0); 389 413 return 1; 390 414 } 391 415 392 416 sh_mobile_i2c_get_data(pd, &data); 393 - 394 - if (sh_mobile_i2c_is_last_byte(pd)) 395 - i2c_op(pd, OP_TX_STOP_DATA, data); 396 - else if (sh_mobile_i2c_is_first_byte(pd)) 397 - i2c_op(pd, OP_TX_FIRST, data); 398 - else 399 - i2c_op(pd, OP_TX, data); 417 + i2c_op(pd, sh_mobile_i2c_is_first_byte(pd) ? OP_TX_FIRST : OP_TX, data); 400 418 401 419 pd->pos++; 402 420 return 0; ··· 430 464 break; 431 465 } 432 466 data = i2c_op(pd, OP_RX_STOP_DATA, 0); 433 - } else 467 + } else if (real_pos >= 0) { 434 468 data = i2c_op(pd, OP_RX, 0); 469 + } 435 470 436 471 if (real_pos >= 0) 437 472 pd->msg->buf[real_pos] = data; ··· 515 548 pd->pos = pd->msg->len; 516 549 pd->stop_after_dma = true; 517 550 551 + i2c_release_dma_safe_msg_buf(pd->msg, pd->dma_buf); 552 + 518 553 iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE); 519 554 } 520 555 ··· 577 608 if (IS_ERR(chan)) 578 609 return; 579 610 580 - dma_addr = dma_map_single(chan->device->dev, pd->msg->buf, pd->msg->len, dir); 611 + dma_addr = dma_map_single(chan->device->dev, pd->dma_buf, pd->msg->len, dir); 581 612 if (dma_mapping_error(chan->device->dev, dma_addr)) { 582 613 dev_dbg(pd->dev, "dma map failed, using PIO\n"); 583 614 return; ··· 620 651 621 652 if (do_init) { 622 653 /* Initialize channel registers */ 623 - iic_set_clr(pd, ICCR, 0, ICCR_ICE); 654 + iic_wr(pd, ICCR, ICCR_SCP); 624 655 625 656 /* Enable channel and configure rx ack */ 626 - iic_set_clr(pd, ICCR, ICCR_ICE, 0); 657 + iic_wr(pd, ICCR, ICCR_ICE | ICCR_SCP); 627 658 628 659 /* Set the clock */ 629 660 iic_wr(pd, ICCL, pd->iccl & 0xff); ··· 634 665 pd->pos = -1; 635 666 pd->sr = 0; 636 667 637 - if (pd->msg->len > 8) 668 + pd->dma_buf = i2c_get_dma_safe_msg_buf(pd->msg, 8); 669 + if (pd->dma_buf) 638 670 sh_mobile_i2c_xfer_dma(pd); 639 671 640 672 /* Enable all interrupts to begin with */ ··· 701 731 int i; 702 732 long timeout; 703 733 704 - activate_ch(pd); 734 + /* Wake up device and enable clock */ 735 + pm_runtime_get_sync(pd->dev); 705 736 706 737 /* Process all messages */ 707 738 for (i = 0; i < num; i++) { ··· 739 768 break; 740 769 } 741 770 742 - deactivate_ch(pd); 771 + /* Disable channel */ 772 + iic_wr(pd, ICCR, ICCR_SCP); 743 773 744 - if (!err) 745 - err = num; 746 - return err; 774 + /* Disable clock and mark device as idle */ 775 + pm_runtime_put_sync(pd->dev); 776 + 777 + return err ?: num; 747 778 } 748 779 749 780 static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter) ··· 762 789 * r8a7740 chip has lasting errata on I2C I/O pad reset. 763 790 * this is work-around for it. 764 791 */ 765 - static void sh_mobile_i2c_r8a7740_workaround(struct sh_mobile_i2c_data *pd) 792 + static int sh_mobile_i2c_r8a7740_workaround(struct sh_mobile_i2c_data *pd) 766 793 { 767 794 iic_set_clr(pd, ICCR, ICCR_ICE, 0); 768 795 iic_rd(pd, ICCR); /* dummy read */ ··· 783 810 udelay(10); 784 811 iic_wr(pd, ICCR, ICCR_TRS); 785 812 udelay(10); 813 + 814 + return sh_mobile_i2c_init(pd); 786 815 } 787 816 788 817 static const struct sh_mobile_dt_config default_dt_config = { 789 818 .clks_per_count = 1, 819 + .setup = sh_mobile_i2c_init, 790 820 }; 791 821 792 822 static const struct sh_mobile_dt_config fast_clock_dt_config = { 793 823 .clks_per_count = 2, 824 + .setup = sh_mobile_i2c_init, 825 + }; 826 + 827 + static const struct sh_mobile_dt_config v2_freq_calc_dt_config = { 828 + .clks_per_count = 2, 829 + .setup = sh_mobile_i2c_v2_init, 794 830 }; 795 831 796 832 static const struct sh_mobile_dt_config r8a7740_dt_config = { ··· 810 828 static const struct of_device_id sh_mobile_i2c_dt_ids[] = { 811 829 { .compatible = "renesas,iic-r8a73a4", .data = &fast_clock_dt_config }, 812 830 { .compatible = "renesas,iic-r8a7740", .data = &r8a7740_dt_config }, 813 - { .compatible = "renesas,iic-r8a7790", .data = &fast_clock_dt_config }, 831 + { .compatible = "renesas,iic-r8a7790", .data = &v2_freq_calc_dt_config }, 814 832 { .compatible = "renesas,iic-r8a7791", .data = &fast_clock_dt_config }, 815 833 { .compatible = "renesas,iic-r8a7792", .data = &fast_clock_dt_config }, 816 834 { .compatible = "renesas,iic-r8a7793", .data = &fast_clock_dt_config }, ··· 892 910 return PTR_ERR(pd->reg); 893 911 894 912 ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); 895 - pd->bus_speed = ret ? STANDARD_MODE : bus_speed; 913 + pd->bus_speed = (ret || !bus_speed) ? STANDARD_MODE : bus_speed; 896 914 pd->clks_per_count = 1; 897 915 898 - config = of_device_get_match_data(&dev->dev); 899 - if (config) { 900 - pd->clks_per_count = config->clks_per_count; 901 - 902 - if (config->setup) 903 - config->setup(pd); 904 - } 905 - 906 - /* The IIC blocks on SH-Mobile ARM processors 907 - * come with two new bits in ICIC. 908 - */ 916 + /* Newer variants come with two new bits in ICIC */ 909 917 if (resource_size(res) > 0x17) 910 918 pd->flags |= IIC_FLAG_HAS_ICIC67; 911 - 912 - ret = sh_mobile_i2c_init(pd); 913 - if (ret) 914 - return ret; 915 - 916 - /* Init DMA */ 917 - sg_init_table(&pd->sg, 1); 918 - pd->dma_direction = DMA_NONE; 919 - pd->dma_rx = pd->dma_tx = ERR_PTR(-EPROBE_DEFER); 920 919 921 920 /* Enable Runtime PM for this device. 922 921 * ··· 911 948 */ 912 949 pm_suspend_ignore_children(&dev->dev, true); 913 950 pm_runtime_enable(&dev->dev); 951 + pm_runtime_get_sync(&dev->dev); 952 + 953 + config = of_device_get_match_data(&dev->dev); 954 + if (config) { 955 + pd->clks_per_count = config->clks_per_count; 956 + ret = config->setup(pd); 957 + } else { 958 + ret = sh_mobile_i2c_init(pd); 959 + } 960 + 961 + pm_runtime_put_sync(&dev->dev); 962 + if (ret) 963 + return ret; 964 + 965 + /* Init DMA */ 966 + sg_init_table(&pd->sg, 1); 967 + pd->dma_direction = DMA_NONE; 968 + pd->dma_rx = pd->dma_tx = ERR_PTR(-EPROBE_DEFER); 914 969 915 970 /* setup the private data */ 916 971 adap = &pd->adap;
+96 -116
drivers/i2c/i2c-core-base.c
··· 27 27 #include <linux/delay.h> 28 28 #include <linux/err.h> 29 29 #include <linux/errno.h> 30 - #include <linux/gpio.h> 30 + #include <linux/gpio/consumer.h> 31 31 #include <linux/i2c.h> 32 32 #include <linux/i2c-smbus.h> 33 33 #include <linux/idr.h> ··· 134 134 /* i2c bus recovery routines */ 135 135 static int get_scl_gpio_value(struct i2c_adapter *adap) 136 136 { 137 - return gpio_get_value(adap->bus_recovery_info->scl_gpio); 137 + return gpiod_get_value_cansleep(adap->bus_recovery_info->scl_gpiod); 138 138 } 139 139 140 140 static void set_scl_gpio_value(struct i2c_adapter *adap, int val) 141 141 { 142 - gpio_set_value(adap->bus_recovery_info->scl_gpio, val); 142 + gpiod_set_value_cansleep(adap->bus_recovery_info->scl_gpiod, val); 143 143 } 144 144 145 145 static int get_sda_gpio_value(struct i2c_adapter *adap) 146 146 { 147 - return gpio_get_value(adap->bus_recovery_info->sda_gpio); 147 + return gpiod_get_value_cansleep(adap->bus_recovery_info->sda_gpiod); 148 148 } 149 149 150 - static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap) 150 + static void set_sda_gpio_value(struct i2c_adapter *adap, int val) 151 151 { 152 - struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; 153 - struct device *dev = &adap->dev; 154 - int ret = 0; 155 - 156 - ret = gpio_request_one(bri->scl_gpio, GPIOF_OPEN_DRAIN | 157 - GPIOF_OUT_INIT_HIGH, "i2c-scl"); 158 - if (ret) { 159 - dev_warn(dev, "Can't get SCL gpio: %d\n", bri->scl_gpio); 160 - return ret; 161 - } 162 - 163 - if (bri->get_sda) { 164 - if (gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda")) { 165 - /* work without SDA polling */ 166 - dev_warn(dev, "Can't get SDA gpio: %d. Not using SDA polling\n", 167 - bri->sda_gpio); 168 - bri->get_sda = NULL; 169 - } 170 - } 171 - 172 - return ret; 173 - } 174 - 175 - static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap) 176 - { 177 - struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; 178 - 179 - if (bri->get_sda) 180 - gpio_free(bri->sda_gpio); 181 - 182 - gpio_free(bri->scl_gpio); 152 + gpiod_set_value_cansleep(adap->bus_recovery_info->sda_gpiod, val); 183 153 } 184 154 185 155 /* ··· 160 190 #define RECOVERY_NDELAY 5000 161 191 #define RECOVERY_CLK_CNT 9 162 192 163 - static int i2c_generic_recovery(struct i2c_adapter *adap) 193 + int i2c_generic_scl_recovery(struct i2c_adapter *adap) 164 194 { 165 195 struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; 166 196 int i = 0, val = 1, ret = 0; ··· 169 199 bri->prepare_recovery(adap); 170 200 171 201 bri->set_scl(adap, val); 202 + if (bri->set_sda) 203 + bri->set_sda(adap, 1); 172 204 ndelay(RECOVERY_NDELAY); 173 205 174 206 /* ··· 199 227 if (bri->get_sda && !bri->get_sda(adap)) 200 228 ret = -EBUSY; 201 229 230 + /* If all went well, send STOP for a sane bus state. */ 231 + if (ret == 0 && bri->set_sda) { 232 + bri->set_scl(adap, 0); 233 + ndelay(RECOVERY_NDELAY / 2); 234 + bri->set_sda(adap, 0); 235 + ndelay(RECOVERY_NDELAY / 2); 236 + bri->set_scl(adap, 1); 237 + ndelay(RECOVERY_NDELAY / 2); 238 + bri->set_sda(adap, 1); 239 + ndelay(RECOVERY_NDELAY / 2); 240 + } 241 + 202 242 if (bri->unprepare_recovery) 203 243 bri->unprepare_recovery(adap); 204 244 205 245 return ret; 206 246 } 207 - 208 - int i2c_generic_scl_recovery(struct i2c_adapter *adap) 209 - { 210 - return i2c_generic_recovery(adap); 211 - } 212 247 EXPORT_SYMBOL_GPL(i2c_generic_scl_recovery); 213 - 214 - int i2c_generic_gpio_recovery(struct i2c_adapter *adap) 215 - { 216 - int ret; 217 - 218 - ret = i2c_get_gpios_for_recovery(adap); 219 - if (ret) 220 - return ret; 221 - 222 - ret = i2c_generic_recovery(adap); 223 - i2c_put_gpios_for_recovery(adap); 224 - 225 - return ret; 226 - } 227 - EXPORT_SYMBOL_GPL(i2c_generic_gpio_recovery); 228 248 229 249 int i2c_recover_bus(struct i2c_adapter *adap) 230 250 { ··· 241 277 goto err; 242 278 } 243 279 244 - /* Generic GPIO recovery */ 245 - if (bri->recover_bus == i2c_generic_gpio_recovery) { 246 - if (!gpio_is_valid(bri->scl_gpio)) { 247 - err_str = "invalid SCL gpio"; 248 - goto err; 249 - } 250 - 251 - if (gpio_is_valid(bri->sda_gpio)) 252 - bri->get_sda = get_sda_gpio_value; 253 - else 254 - bri->get_sda = NULL; 255 - 280 + if (bri->scl_gpiod && bri->recover_bus == i2c_generic_scl_recovery) { 256 281 bri->get_scl = get_scl_gpio_value; 257 282 bri->set_scl = set_scl_gpio_value; 258 - } else if (bri->recover_bus == i2c_generic_scl_recovery) { 283 + if (bri->sda_gpiod) { 284 + bri->get_sda = get_sda_gpio_value; 285 + /* FIXME: add proper flag instead of '0' once available */ 286 + if (gpiod_get_direction(bri->sda_gpiod) == 0) 287 + bri->set_sda = set_sda_gpio_value; 288 + } 289 + return; 290 + } 291 + 292 + if (bri->recover_bus == i2c_generic_scl_recovery) { 259 293 /* Generic SCL recovery */ 260 294 if (!bri->set_scl || !bri->get_scl) { 261 295 err_str = "no {get|set}_scl() found"; ··· 1938 1976 EXPORT_SYMBOL(i2c_transfer); 1939 1977 1940 1978 /** 1941 - * i2c_master_send - issue a single I2C message in master transmit mode 1979 + * i2c_transfer_buffer_flags - issue a single I2C message transferring data 1980 + * to/from a buffer 1942 1981 * @client: Handle to slave device 1943 - * @buf: Data that will be written to the slave 1944 - * @count: How many bytes to write, must be less than 64k since msg.len is u16 1982 + * @buf: Where the data is stored 1983 + * @count: How many bytes to transfer, must be less than 64k since msg.len is u16 1984 + * @flags: The flags to be used for the message, e.g. I2C_M_RD for reads 1945 1985 * 1946 - * Returns negative errno, or else the number of bytes written. 1986 + * Returns negative errno, or else the number of bytes transferred. 1947 1987 */ 1948 - int i2c_master_send(const struct i2c_client *client, const char *buf, int count) 1988 + int i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf, 1989 + int count, u16 flags) 1949 1990 { 1950 1991 int ret; 1951 - struct i2c_adapter *adap = client->adapter; 1952 - struct i2c_msg msg; 1992 + struct i2c_msg msg = { 1993 + .addr = client->addr, 1994 + .flags = flags | (client->flags & I2C_M_TEN), 1995 + .len = count, 1996 + .buf = buf, 1997 + }; 1953 1998 1954 - msg.addr = client->addr; 1955 - msg.flags = client->flags & I2C_M_TEN; 1956 - msg.len = count; 1957 - msg.buf = (char *)buf; 1958 - 1959 - ret = i2c_transfer(adap, &msg, 1); 1999 + ret = i2c_transfer(client->adapter, &msg, 1); 1960 2000 1961 2001 /* 1962 - * If everything went ok (i.e. 1 msg transmitted), return #bytes 1963 - * transmitted, else error code. 2002 + * If everything went ok (i.e. 1 msg transferred), return #bytes 2003 + * transferred, else error code. 1964 2004 */ 1965 2005 return (ret == 1) ? count : ret; 1966 2006 } 1967 - EXPORT_SYMBOL(i2c_master_send); 1968 - 1969 - /** 1970 - * i2c_master_recv - issue a single I2C message in master receive mode 1971 - * @client: Handle to slave device 1972 - * @buf: Where to store data read from slave 1973 - * @count: How many bytes to read, must be less than 64k since msg.len is u16 1974 - * 1975 - * Returns negative errno, or else the number of bytes read. 1976 - */ 1977 - int i2c_master_recv(const struct i2c_client *client, char *buf, int count) 1978 - { 1979 - struct i2c_adapter *adap = client->adapter; 1980 - struct i2c_msg msg; 1981 - int ret; 1982 - 1983 - msg.addr = client->addr; 1984 - msg.flags = client->flags & I2C_M_TEN; 1985 - msg.flags |= I2C_M_RD; 1986 - msg.len = count; 1987 - msg.buf = buf; 1988 - 1989 - ret = i2c_transfer(adap, &msg, 1); 1990 - 1991 - /* 1992 - * If everything went ok (i.e. 1 msg received), return #bytes received, 1993 - * else error code. 1994 - */ 1995 - return (ret == 1) ? count : ret; 1996 - } 1997 - EXPORT_SYMBOL(i2c_master_recv); 2007 + EXPORT_SYMBOL(i2c_transfer_buffer_flags); 1998 2008 1999 2009 /* ---------------------------------------------------- 2000 2010 * the i2c address scanning function ··· 2198 2264 module_put(adap->owner); 2199 2265 } 2200 2266 EXPORT_SYMBOL(i2c_put_adapter); 2267 + 2268 + /** 2269 + * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg 2270 + * @msg: the message to be checked 2271 + * @threshold: the minimum number of bytes for which using DMA makes sense 2272 + * 2273 + * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO. 2274 + * Or a valid pointer to be used with DMA. After use, release it by 2275 + * calling i2c_release_dma_safe_msg_buf(). 2276 + * 2277 + * This function must only be called from process context! 2278 + */ 2279 + u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold) 2280 + { 2281 + if (msg->len < threshold) 2282 + return NULL; 2283 + 2284 + if (msg->flags & I2C_M_DMA_SAFE) 2285 + return msg->buf; 2286 + 2287 + pr_debug("using bounce buffer for addr=0x%02x, len=%d\n", 2288 + msg->addr, msg->len); 2289 + 2290 + if (msg->flags & I2C_M_RD) 2291 + return kzalloc(msg->len, GFP_KERNEL); 2292 + else 2293 + return kmemdup(msg->buf, msg->len, GFP_KERNEL); 2294 + } 2295 + EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf); 2296 + 2297 + /** 2298 + * i2c_release_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg 2299 + * @msg: the message to be synced with 2300 + * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL. 2301 + */ 2302 + void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) 2303 + { 2304 + if (!buf || buf == msg->buf) 2305 + return; 2306 + 2307 + if (msg->flags & I2C_M_RD) 2308 + memcpy(msg->buf, buf, msg->len); 2309 + 2310 + kfree(buf); 2311 + } 2312 + EXPORT_SYMBOL_GPL(i2c_release_dma_safe_msg_buf); 2201 2313 2202 2314 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 2203 2315 MODULE_DESCRIPTION("I2C-Bus main module");
+39 -6
drivers/i2c/i2c-core-smbus.c
··· 18 18 #include <linux/err.h> 19 19 #include <linux/i2c.h> 20 20 #include <linux/i2c-smbus.h> 21 + #include <linux/slab.h> 21 22 22 23 #define CREATE_TRACE_POINTS 23 24 #include <trace/events/smbus.h> ··· 292 291 } 293 292 EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); 294 293 294 + static void i2c_smbus_try_get_dmabuf(struct i2c_msg *msg, u8 init_val) 295 + { 296 + bool is_read = msg->flags & I2C_M_RD; 297 + unsigned char *dma_buf; 298 + 299 + dma_buf = kzalloc(I2C_SMBUS_BLOCK_MAX + (is_read ? 2 : 3), GFP_KERNEL); 300 + if (!dma_buf) 301 + return; 302 + 303 + msg->buf = dma_buf; 304 + msg->flags |= I2C_M_DMA_SAFE; 305 + 306 + if (init_val) 307 + msg->buf[0] = init_val; 308 + } 309 + 295 310 /* Simulate a SMBus command using the i2c protocol 296 311 No checking of parameters is done! */ 297 312 static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, ··· 385 368 msg[1].flags |= I2C_M_RECV_LEN; 386 369 msg[1].len = 1; /* block length will be added by 387 370 the underlying bus driver */ 371 + i2c_smbus_try_get_dmabuf(&msg[1], 0); 388 372 } else { 389 373 msg[0].len = data->block[0] + 2; 390 374 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { ··· 394 376 data->block[0]); 395 377 return -EINVAL; 396 378 } 379 + 380 + i2c_smbus_try_get_dmabuf(&msg[0], command); 397 381 for (i = 1; i < msg[0].len; i++) 398 - msgbuf0[i] = data->block[i-1]; 382 + msg[0].buf[i] = data->block[i - 1]; 399 383 } 400 384 break; 401 385 case I2C_SMBUS_BLOCK_PROC_CALL: ··· 409 389 data->block[0]); 410 390 return -EINVAL; 411 391 } 392 + 412 393 msg[0].len = data->block[0] + 2; 394 + i2c_smbus_try_get_dmabuf(&msg[0], command); 413 395 for (i = 1; i < msg[0].len; i++) 414 - msgbuf0[i] = data->block[i-1]; 396 + msg[0].buf[i] = data->block[i - 1]; 397 + 415 398 msg[1].flags |= I2C_M_RECV_LEN; 416 399 msg[1].len = 1; /* block length will be added by 417 400 the underlying bus driver */ 401 + i2c_smbus_try_get_dmabuf(&msg[1], 0); 418 402 break; 419 403 case I2C_SMBUS_I2C_BLOCK_DATA: 420 404 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { ··· 430 406 431 407 if (read_write == I2C_SMBUS_READ) { 432 408 msg[1].len = data->block[0]; 409 + i2c_smbus_try_get_dmabuf(&msg[1], 0); 433 410 } else { 434 411 msg[0].len = data->block[0] + 1; 412 + 413 + i2c_smbus_try_get_dmabuf(&msg[0], command); 435 414 for (i = 1; i <= data->block[0]; i++) 436 - msgbuf0[i] = data->block[i]; 415 + msg[0].buf[i] = data->block[i]; 437 416 } 438 417 break; 439 418 default: ··· 484 457 break; 485 458 case I2C_SMBUS_I2C_BLOCK_DATA: 486 459 for (i = 0; i < data->block[0]; i++) 487 - data->block[i+1] = msgbuf1[i]; 460 + data->block[i + 1] = msg[1].buf[i]; 488 461 break; 489 462 case I2C_SMBUS_BLOCK_DATA: 490 463 case I2C_SMBUS_BLOCK_PROC_CALL: 491 - for (i = 0; i < msgbuf1[0] + 1; i++) 492 - data->block[i] = msgbuf1[i]; 464 + for (i = 0; i < msg[1].buf[0] + 1; i++) 465 + data->block[i] = msg[1].buf[i]; 493 466 break; 494 467 } 468 + 469 + if (msg[0].flags & I2C_M_DMA_SAFE) 470 + kfree(msg[0].buf); 471 + if (msg[1].flags & I2C_M_DMA_SAFE) 472 + kfree(msg[1].buf); 473 + 495 474 return 0; 496 475 } 497 476
+2
drivers/i2c/i2c-dev.c
··· 264 264 res = PTR_ERR(msgs[i].buf); 265 265 break; 266 266 } 267 + /* memdup_user allocates with GFP_KERNEL, so DMA is ok */ 268 + msgs[i].flags |= I2C_M_DMA_SAFE; 267 269 268 270 /* 269 271 * If the message length is received from the slave (similar
+3 -3
drivers/i2c/muxes/Kconfig
··· 64 64 will be called i2c-mux-pca9541. 65 65 66 66 config I2C_MUX_PCA954x 67 - tristate "Philips PCA954x I2C Mux/switches" 67 + tristate "NXP PCA954x and PCA984x I2C Mux/switches" 68 68 depends on GPIOLIB || COMPILE_TEST 69 69 help 70 - If you say yes here you get support for the Philips PCA954x 71 - I2C mux/switch devices. 70 + If you say yes here you get support for the NXP PCA954x 71 + and PCA984x I2C mux/switch devices. 72 72 73 73 This driver can also be built as a module. If so, the module 74 74 will be called i2c-mux-pca954x.
+34 -4
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 4 4 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> 5 5 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> 6 6 * 7 - * This module supports the PCA954x series of I2C multiplexer/switch chips 8 - * made by Philips Semiconductors. 7 + * This module supports the PCA954x and PCA954x series of I2C multiplexer/switch 8 + * chips made by NXP Semiconductors. 9 9 * This includes the: 10 - * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547 11 - * and PCA9548. 10 + * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547, 11 + * PCA9548, PCA9846, PCA9847, PCA9848 and PCA9849. 12 12 * 13 13 * These chips are all controlled via the I2C bus itself, and all have a 14 14 * single 8-bit register. The upstream "parent" bus fans out to two, ··· 63 63 pca_9546, 64 64 pca_9547, 65 65 pca_9548, 66 + pca_9846, 67 + pca_9847, 68 + pca_9848, 69 + pca_9849, 66 70 }; 67 71 68 72 struct chip_desc { ··· 133 129 .nchans = 8, 134 130 .muxtype = pca954x_isswi, 135 131 }, 132 + [pca_9846] = { 133 + .nchans = 4, 134 + .muxtype = pca954x_isswi, 135 + }, 136 + [pca_9847] = { 137 + .nchans = 8, 138 + .enable = 0x8, 139 + .muxtype = pca954x_ismux, 140 + }, 141 + [pca_9848] = { 142 + .nchans = 8, 143 + .muxtype = pca954x_isswi, 144 + }, 145 + [pca_9849] = { 146 + .nchans = 4, 147 + .enable = 0x4, 148 + .muxtype = pca954x_ismux, 149 + }, 136 150 }; 137 151 138 152 static const struct i2c_device_id pca954x_id[] = { ··· 162 140 { "pca9546", pca_9546 }, 163 141 { "pca9547", pca_9547 }, 164 142 { "pca9548", pca_9548 }, 143 + { "pca9846", pca_9846 }, 144 + { "pca9847", pca_9847 }, 145 + { "pca9848", pca_9848 }, 146 + { "pca9849", pca_9849 }, 165 147 { } 166 148 }; 167 149 MODULE_DEVICE_TABLE(i2c, pca954x_id); ··· 180 154 { .compatible = "nxp,pca9546", .data = &chips[pca_9546] }, 181 155 { .compatible = "nxp,pca9547", .data = &chips[pca_9547] }, 182 156 { .compatible = "nxp,pca9548", .data = &chips[pca_9548] }, 157 + { .compatible = "nxp,pca9846", .data = &chips[pca_9846] }, 158 + { .compatible = "nxp,pca9847", .data = &chips[pca_9847] }, 159 + { .compatible = "nxp,pca9848", .data = &chips[pca_9848] }, 160 + { .compatible = "nxp,pca9849", .data = &chips[pca_9849] }, 183 161 {} 184 162 }; 185 163 MODULE_DEVICE_TABLE(of, pca954x_of_match);
+3
drivers/i2c/muxes/i2c-mux-reg.c
··· 177 177 sizeof(mux->data)); 178 178 } else { 179 179 ret = i2c_mux_reg_probe_dt(mux, pdev); 180 + if (ret == -EPROBE_DEFER) 181 + return ret; 182 + 180 183 if (ret < 0) { 181 184 dev_err(&pdev->dev, "Error parsing device tree"); 182 185 return ret;
+1
drivers/misc/eeprom/Kconfig
··· 4 4 tristate "I2C EEPROMs / RAMs / ROMs from most vendors" 5 5 depends on I2C && SYSFS 6 6 select NVMEM 7 + select REGMAP_I2C 7 8 help 8 9 Enable this driver to get read/write support to most I2C EEPROMs 9 10 and compatible devices like FRAMs, SRAMs, ROMs etc. After you
+259 -482
drivers/misc/eeprom/at24.c
··· 24 24 #include <linux/acpi.h> 25 25 #include <linux/i2c.h> 26 26 #include <linux/nvmem-provider.h> 27 + #include <linux/regmap.h> 27 28 #include <linux/platform_data/at24.h> 28 29 #include <linux/pm_runtime.h> 30 + #include <linux/gpio/consumer.h> 29 31 30 32 /* 31 33 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. ··· 57 55 * which won't work on pure SMBus systems. 58 56 */ 59 57 58 + struct at24_client { 59 + struct i2c_client *client; 60 + struct regmap *regmap; 61 + }; 62 + 60 63 struct at24_data { 61 64 struct at24_platform_data chip; 62 - int use_smbus; 63 - int use_smbus_write; 64 - 65 - ssize_t (*read_func)(struct at24_data *, char *, unsigned int, size_t); 66 - ssize_t (*write_func)(struct at24_data *, 67 - const char *, unsigned int, size_t); 68 65 69 66 /* 70 67 * Lock protects against activities from other Linux tasks, ··· 71 70 */ 72 71 struct mutex lock; 73 72 74 - u8 *writebuf; 75 - unsigned write_max; 76 - unsigned num_addresses; 73 + unsigned int write_max; 74 + unsigned int num_addresses; 75 + unsigned int offset_adj; 77 76 78 77 struct nvmem_config nvmem_config; 79 78 struct nvmem_device *nvmem; 79 + 80 + struct gpio_desc *wp_gpio; 80 81 81 82 /* 82 83 * Some chips tie up multiple I2C addresses; dummy devices reserve 83 84 * them for us, and we'll use them with SMBus calls. 84 85 */ 85 - struct i2c_client *client[]; 86 + struct at24_client client[]; 86 87 }; 87 88 88 89 /* ··· 96 93 * 97 94 * This value is forced to be a power of two so that writes align on pages. 98 95 */ 99 - static unsigned io_limit = 128; 100 - module_param(io_limit, uint, 0); 101 - MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)"); 96 + static unsigned int at24_io_limit = 128; 97 + module_param_named(io_limit, at24_io_limit, uint, 0); 98 + MODULE_PARM_DESC(at24_io_limit, "Maximum bytes per I/O (default 128)"); 102 99 103 100 /* 104 101 * Specs often allow 5 msec for a page write, sometimes 20 msec; 105 102 * it's important to recover from write timeouts. 106 103 */ 107 - static unsigned write_timeout = 25; 108 - module_param(write_timeout, uint, 0); 109 - MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); 110 - 111 - #define AT24_SIZE_BYTELEN 5 112 - #define AT24_SIZE_FLAGS 8 113 - 114 - #define AT24_BITMASK(x) (BIT(x) - 1) 115 - 116 - /* create non-zero magic value for given eeprom parameters */ 117 - #define AT24_DEVICE_MAGIC(_len, _flags) \ 118 - ((1 << AT24_SIZE_FLAGS | (_flags)) \ 119 - << AT24_SIZE_BYTELEN | ilog2(_len)) 104 + static unsigned int at24_write_timeout = 25; 105 + module_param_named(write_timeout, at24_write_timeout, uint, 0); 106 + MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)"); 120 107 121 108 /* 122 109 * Both reads and writes fail if the previous write didn't complete yet. This ··· 119 126 * iteration of processing the request. Both should be unsigned integers 120 127 * holding at least 32 bits. 121 128 */ 122 - #define loop_until_timeout(tout, op_time) \ 123 - for (tout = jiffies + msecs_to_jiffies(write_timeout), op_time = 0; \ 129 + #define at24_loop_until_timeout(tout, op_time) \ 130 + for (tout = jiffies + msecs_to_jiffies(at24_write_timeout), \ 131 + op_time = 0; \ 124 132 op_time ? time_before(op_time, tout) : true; \ 125 133 usleep_range(1000, 1500), op_time = jiffies) 126 134 135 + struct at24_chip_data { 136 + /* 137 + * these fields mirror their equivalents in 138 + * struct at24_platform_data 139 + */ 140 + u32 byte_len; 141 + u8 flags; 142 + }; 143 + 144 + #define AT24_CHIP_DATA(_name, _len, _flags) \ 145 + static const struct at24_chip_data _name = { \ 146 + .byte_len = _len, .flags = _flags, \ 147 + } 148 + 149 + /* needs 8 addresses as A0-A2 are ignored */ 150 + AT24_CHIP_DATA(at24_data_24c00, 128 / 8, AT24_FLAG_TAKE8ADDR); 151 + /* old variants can't be handled with this generic entry! */ 152 + AT24_CHIP_DATA(at24_data_24c01, 1024 / 8, 0); 153 + AT24_CHIP_DATA(at24_data_24cs01, 16, 154 + AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 155 + AT24_CHIP_DATA(at24_data_24c02, 2048 / 8, 0); 156 + AT24_CHIP_DATA(at24_data_24cs02, 16, 157 + AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 158 + AT24_CHIP_DATA(at24_data_24mac402, 48 / 8, 159 + AT24_FLAG_MAC | AT24_FLAG_READONLY); 160 + AT24_CHIP_DATA(at24_data_24mac602, 64 / 8, 161 + AT24_FLAG_MAC | AT24_FLAG_READONLY); 162 + /* spd is a 24c02 in memory DIMMs */ 163 + AT24_CHIP_DATA(at24_data_spd, 2048 / 8, 164 + AT24_FLAG_READONLY | AT24_FLAG_IRUGO); 165 + AT24_CHIP_DATA(at24_data_24c04, 4096 / 8, 0); 166 + AT24_CHIP_DATA(at24_data_24cs04, 16, 167 + AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 168 + /* 24rf08 quirk is handled at i2c-core */ 169 + AT24_CHIP_DATA(at24_data_24c08, 8192 / 8, 0); 170 + AT24_CHIP_DATA(at24_data_24cs08, 16, 171 + AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 172 + AT24_CHIP_DATA(at24_data_24c16, 16384 / 8, 0); 173 + AT24_CHIP_DATA(at24_data_24cs16, 16, 174 + AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 175 + AT24_CHIP_DATA(at24_data_24c32, 32768 / 8, AT24_FLAG_ADDR16); 176 + AT24_CHIP_DATA(at24_data_24cs32, 16, 177 + AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 178 + AT24_CHIP_DATA(at24_data_24c64, 65536 / 8, AT24_FLAG_ADDR16); 179 + AT24_CHIP_DATA(at24_data_24cs64, 16, 180 + AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 181 + AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16); 182 + AT24_CHIP_DATA(at24_data_24c256, 262144 / 8, AT24_FLAG_ADDR16); 183 + AT24_CHIP_DATA(at24_data_24c512, 524288 / 8, AT24_FLAG_ADDR16); 184 + AT24_CHIP_DATA(at24_data_24c1024, 1048576 / 8, AT24_FLAG_ADDR16); 185 + /* identical to 24c08 ? */ 186 + AT24_CHIP_DATA(at24_data_INT3499, 8192 / 8, 0); 187 + 127 188 static const struct i2c_device_id at24_ids[] = { 128 - /* needs 8 addresses as A0-A2 are ignored */ 129 - { "24c00", AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) }, 130 - /* old variants can't be handled with this generic entry! */ 131 - { "24c01", AT24_DEVICE_MAGIC(1024 / 8, 0) }, 132 - { "24cs01", AT24_DEVICE_MAGIC(16, 133 - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, 134 - { "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) }, 135 - { "24cs02", AT24_DEVICE_MAGIC(16, 136 - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, 137 - { "24mac402", AT24_DEVICE_MAGIC(48 / 8, 138 - AT24_FLAG_MAC | AT24_FLAG_READONLY) }, 139 - { "24mac602", AT24_DEVICE_MAGIC(64 / 8, 140 - AT24_FLAG_MAC | AT24_FLAG_READONLY) }, 141 - /* spd is a 24c02 in memory DIMMs */ 142 - { "spd", AT24_DEVICE_MAGIC(2048 / 8, 143 - AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, 144 - { "24c04", AT24_DEVICE_MAGIC(4096 / 8, 0) }, 145 - { "24cs04", AT24_DEVICE_MAGIC(16, 146 - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, 147 - /* 24rf08 quirk is handled at i2c-core */ 148 - { "24c08", AT24_DEVICE_MAGIC(8192 / 8, 0) }, 149 - { "24cs08", AT24_DEVICE_MAGIC(16, 150 - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, 151 - { "24c16", AT24_DEVICE_MAGIC(16384 / 8, 0) }, 152 - { "24cs16", AT24_DEVICE_MAGIC(16, 153 - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, 154 - { "24c32", AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) }, 155 - { "24cs32", AT24_DEVICE_MAGIC(16, 156 - AT24_FLAG_ADDR16 | 157 - AT24_FLAG_SERIAL | 158 - AT24_FLAG_READONLY) }, 159 - { "24c64", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) }, 160 - { "24cs64", AT24_DEVICE_MAGIC(16, 161 - AT24_FLAG_ADDR16 | 162 - AT24_FLAG_SERIAL | 163 - AT24_FLAG_READONLY) }, 164 - { "24c128", AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) }, 165 - { "24c256", AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) }, 166 - { "24c512", AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) }, 167 - { "24c1024", AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16) }, 168 - { "at24", 0 }, 189 + { "24c00", (kernel_ulong_t)&at24_data_24c00 }, 190 + { "24c01", (kernel_ulong_t)&at24_data_24c01 }, 191 + { "24cs01", (kernel_ulong_t)&at24_data_24cs01 }, 192 + { "24c02", (kernel_ulong_t)&at24_data_24c02 }, 193 + { "24cs02", (kernel_ulong_t)&at24_data_24cs02 }, 194 + { "24mac402", (kernel_ulong_t)&at24_data_24mac402 }, 195 + { "24mac602", (kernel_ulong_t)&at24_data_24mac602 }, 196 + { "spd", (kernel_ulong_t)&at24_data_spd }, 197 + { "24c04", (kernel_ulong_t)&at24_data_24c04 }, 198 + { "24cs04", (kernel_ulong_t)&at24_data_24cs04 }, 199 + { "24c08", (kernel_ulong_t)&at24_data_24c08 }, 200 + { "24cs08", (kernel_ulong_t)&at24_data_24cs08 }, 201 + { "24c16", (kernel_ulong_t)&at24_data_24c16 }, 202 + { "24cs16", (kernel_ulong_t)&at24_data_24cs16 }, 203 + { "24c32", (kernel_ulong_t)&at24_data_24c32 }, 204 + { "24cs32", (kernel_ulong_t)&at24_data_24cs32 }, 205 + { "24c64", (kernel_ulong_t)&at24_data_24c64 }, 206 + { "24cs64", (kernel_ulong_t)&at24_data_24cs64 }, 207 + { "24c128", (kernel_ulong_t)&at24_data_24c128 }, 208 + { "24c256", (kernel_ulong_t)&at24_data_24c256 }, 209 + { "24c512", (kernel_ulong_t)&at24_data_24c512 }, 210 + { "24c1024", (kernel_ulong_t)&at24_data_24c1024 }, 211 + { "at24", 0 }, 169 212 { /* END OF LIST */ } 170 213 }; 171 214 MODULE_DEVICE_TABLE(i2c, at24_ids); 172 215 173 216 static const struct of_device_id at24_of_match[] = { 174 - { 175 - .compatible = "atmel,24c00", 176 - .data = (void *)AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) 177 - }, 178 - { 179 - .compatible = "atmel,24c01", 180 - .data = (void *)AT24_DEVICE_MAGIC(1024 / 8, 0) 181 - }, 182 - { 183 - .compatible = "atmel,24c02", 184 - .data = (void *)AT24_DEVICE_MAGIC(2048 / 8, 0) 185 - }, 186 - { 187 - .compatible = "atmel,spd", 188 - .data = (void *)AT24_DEVICE_MAGIC(2048 / 8, 189 - AT24_FLAG_READONLY | AT24_FLAG_IRUGO) 190 - }, 191 - { 192 - .compatible = "atmel,24c04", 193 - .data = (void *)AT24_DEVICE_MAGIC(4096 / 8, 0) 194 - }, 195 - { 196 - .compatible = "atmel,24c08", 197 - .data = (void *)AT24_DEVICE_MAGIC(8192 / 8, 0) 198 - }, 199 - { 200 - .compatible = "atmel,24c16", 201 - .data = (void *)AT24_DEVICE_MAGIC(16384 / 8, 0) 202 - }, 203 - { 204 - .compatible = "atmel,24c32", 205 - .data = (void *)AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) 206 - }, 207 - { 208 - .compatible = "atmel,24c64", 209 - .data = (void *)AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) 210 - }, 211 - { 212 - .compatible = "atmel,24c128", 213 - .data = (void *)AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) 214 - }, 215 - { 216 - .compatible = "atmel,24c256", 217 - .data = (void *)AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) 218 - }, 219 - { 220 - .compatible = "atmel,24c512", 221 - .data = (void *)AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) 222 - }, 223 - { 224 - .compatible = "atmel,24c1024", 225 - .data = (void *)AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16) 226 - }, 227 - { }, 217 + { .compatible = "atmel,24c00", .data = &at24_data_24c00 }, 218 + { .compatible = "atmel,24c01", .data = &at24_data_24c01 }, 219 + { .compatible = "atmel,24cs01", .data = &at24_data_24cs01 }, 220 + { .compatible = "atmel,24c02", .data = &at24_data_24c02 }, 221 + { .compatible = "atmel,24cs02", .data = &at24_data_24cs02 }, 222 + { .compatible = "atmel,24mac402", .data = &at24_data_24mac402 }, 223 + { .compatible = "atmel,24mac602", .data = &at24_data_24mac602 }, 224 + { .compatible = "atmel,spd", .data = &at24_data_spd }, 225 + { .compatible = "atmel,24c04", .data = &at24_data_24c04 }, 226 + { .compatible = "atmel,24cs04", .data = &at24_data_24cs04 }, 227 + { .compatible = "atmel,24c08", .data = &at24_data_24c08 }, 228 + { .compatible = "atmel,24cs08", .data = &at24_data_24cs08 }, 229 + { .compatible = "atmel,24c16", .data = &at24_data_24c16 }, 230 + { .compatible = "atmel,24cs16", .data = &at24_data_24cs16 }, 231 + { .compatible = "atmel,24c32", .data = &at24_data_24c32 }, 232 + { .compatible = "atmel,24cs32", .data = &at24_data_24cs32 }, 233 + { .compatible = "atmel,24c64", .data = &at24_data_24c64 }, 234 + { .compatible = "atmel,24cs64", .data = &at24_data_24cs64 }, 235 + { .compatible = "atmel,24c128", .data = &at24_data_24c128 }, 236 + { .compatible = "atmel,24c256", .data = &at24_data_24c256 }, 237 + { .compatible = "atmel,24c512", .data = &at24_data_24c512 }, 238 + { .compatible = "atmel,24c1024", .data = &at24_data_24c1024 }, 239 + { /* END OF LIST */ }, 228 240 }; 229 241 MODULE_DEVICE_TABLE(of, at24_of_match); 230 242 231 243 static const struct acpi_device_id at24_acpi_ids[] = { 232 - { "INT3499", AT24_DEVICE_MAGIC(8192 / 8, 0) }, 233 - { } 244 + { "INT3499", (kernel_ulong_t)&at24_data_INT3499 }, 245 + { /* END OF LIST */ } 234 246 }; 235 247 MODULE_DEVICE_TABLE(acpi, at24_acpi_ids); 236 248 ··· 249 251 * Slave address and byte offset derive from the offset. Always 250 252 * set the byte address; on a multi-master board, another master 251 253 * may have changed the chip's "current" address pointer. 252 - * 253 - * REVISIT some multi-address chips don't rollover page reads to 254 - * the next slave address, so we may need to truncate the count. 255 - * Those chips might need another quirk flag. 256 - * 257 - * If the real hardware used four adjacent 24c02 chips and that 258 - * were misconfigured as one 24c08, that would be a similar effect: 259 - * one "eeprom" file not four, but larger reads would fail when 260 - * they crossed certain pages. 261 254 */ 262 - static struct i2c_client *at24_translate_offset(struct at24_data *at24, 263 - unsigned int *offset) 255 + static struct at24_client *at24_translate_offset(struct at24_data *at24, 256 + unsigned int *offset) 264 257 { 265 - unsigned i; 258 + unsigned int i; 266 259 267 260 if (at24->chip.flags & AT24_FLAG_ADDR16) { 268 261 i = *offset >> 16; ··· 263 274 *offset &= 0xff; 264 275 } 265 276 266 - return at24->client[i]; 277 + return &at24->client[i]; 267 278 } 268 279 269 - static ssize_t at24_eeprom_read_smbus(struct at24_data *at24, char *buf, 280 + static size_t at24_adjust_read_count(struct at24_data *at24, 270 281 unsigned int offset, size_t count) 271 282 { 272 - unsigned long timeout, read_time; 273 - struct i2c_client *client; 274 - int status; 275 - 276 - client = at24_translate_offset(at24, &offset); 277 - 278 - if (count > io_limit) 279 - count = io_limit; 280 - 281 - /* Smaller eeproms can work given some SMBus extension calls */ 282 - if (count > I2C_SMBUS_BLOCK_MAX) 283 - count = I2C_SMBUS_BLOCK_MAX; 284 - 285 - loop_until_timeout(timeout, read_time) { 286 - status = i2c_smbus_read_i2c_block_data_or_emulated(client, 287 - offset, 288 - count, buf); 289 - 290 - dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", 291 - count, offset, status, jiffies); 292 - 293 - if (status == count) 294 - return count; 295 - } 296 - 297 - return -ETIMEDOUT; 298 - } 299 - 300 - static ssize_t at24_eeprom_read_i2c(struct at24_data *at24, char *buf, 301 - unsigned int offset, size_t count) 302 - { 303 - unsigned long timeout, read_time; 304 - struct i2c_client *client; 305 - struct i2c_msg msg[2]; 306 - int status, i; 307 - u8 msgbuf[2]; 308 - 309 - memset(msg, 0, sizeof(msg)); 310 - client = at24_translate_offset(at24, &offset); 311 - 312 - if (count > io_limit) 313 - count = io_limit; 283 + unsigned int bits; 284 + size_t remainder; 314 285 315 286 /* 316 - * When we have a better choice than SMBus calls, use a combined I2C 317 - * message. Write address; then read up to io_limit data bytes. Note 318 - * that read page rollover helps us here (unlike writes). msgbuf is 319 - * u8 and will cast to our needs. 287 + * In case of multi-address chips that don't rollover reads to 288 + * the next slave address: truncate the count to the slave boundary, 289 + * so that the read never straddles slaves. 320 290 */ 321 - i = 0; 322 - if (at24->chip.flags & AT24_FLAG_ADDR16) 323 - msgbuf[i++] = offset >> 8; 324 - msgbuf[i++] = offset; 291 + if (at24->chip.flags & AT24_FLAG_NO_RDROL) { 292 + bits = (at24->chip.flags & AT24_FLAG_ADDR16) ? 16 : 8; 293 + remainder = BIT(bits) - offset; 294 + if (count > remainder) 295 + count = remainder; 296 + } 325 297 326 - msg[0].addr = client->addr; 327 - msg[0].buf = msgbuf; 328 - msg[0].len = i; 298 + if (count > at24_io_limit) 299 + count = at24_io_limit; 329 300 330 - msg[1].addr = client->addr; 331 - msg[1].flags = I2C_M_RD; 332 - msg[1].buf = buf; 333 - msg[1].len = count; 301 + return count; 302 + } 334 303 335 - loop_until_timeout(timeout, read_time) { 336 - status = i2c_transfer(client->adapter, msg, 2); 337 - if (status == 2) 338 - status = count; 304 + static ssize_t at24_regmap_read(struct at24_data *at24, char *buf, 305 + unsigned int offset, size_t count) 306 + { 307 + unsigned long timeout, read_time; 308 + struct at24_client *at24_client; 309 + struct i2c_client *client; 310 + struct regmap *regmap; 311 + int ret; 339 312 313 + at24_client = at24_translate_offset(at24, &offset); 314 + regmap = at24_client->regmap; 315 + client = at24_client->client; 316 + count = at24_adjust_read_count(at24, offset, count); 317 + 318 + /* adjust offset for mac and serial read ops */ 319 + offset += at24->offset_adj; 320 + 321 + at24_loop_until_timeout(timeout, read_time) { 322 + ret = regmap_bulk_read(regmap, offset, buf, count); 340 323 dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", 341 - count, offset, status, jiffies); 342 - 343 - if (status == count) 344 - return count; 345 - } 346 - 347 - return -ETIMEDOUT; 348 - } 349 - 350 - static ssize_t at24_eeprom_read_serial(struct at24_data *at24, char *buf, 351 - unsigned int offset, size_t count) 352 - { 353 - unsigned long timeout, read_time; 354 - struct i2c_client *client; 355 - struct i2c_msg msg[2]; 356 - u8 addrbuf[2]; 357 - int status; 358 - 359 - client = at24_translate_offset(at24, &offset); 360 - 361 - memset(msg, 0, sizeof(msg)); 362 - msg[0].addr = client->addr; 363 - msg[0].buf = addrbuf; 364 - 365 - /* 366 - * The address pointer of the device is shared between the regular 367 - * EEPROM array and the serial number block. The dummy write (part of 368 - * the sequential read protocol) ensures the address pointer is reset 369 - * to the desired position. 370 - */ 371 - if (at24->chip.flags & AT24_FLAG_ADDR16) { 372 - /* 373 - * For 16 bit address pointers, the word address must contain 374 - * a '10' sequence in bits 11 and 10 regardless of the 375 - * intended position of the address pointer. 376 - */ 377 - addrbuf[0] = 0x08; 378 - addrbuf[1] = offset; 379 - msg[0].len = 2; 380 - } else { 381 - /* 382 - * Otherwise the word address must begin with a '10' sequence, 383 - * regardless of the intended address. 384 - */ 385 - addrbuf[0] = 0x80 + offset; 386 - msg[0].len = 1; 387 - } 388 - 389 - msg[1].addr = client->addr; 390 - msg[1].flags = I2C_M_RD; 391 - msg[1].buf = buf; 392 - msg[1].len = count; 393 - 394 - loop_until_timeout(timeout, read_time) { 395 - status = i2c_transfer(client->adapter, msg, 2); 396 - if (status == 2) 397 - return count; 398 - } 399 - 400 - return -ETIMEDOUT; 401 - } 402 - 403 - static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf, 404 - unsigned int offset, size_t count) 405 - { 406 - unsigned long timeout, read_time; 407 - struct i2c_client *client; 408 - struct i2c_msg msg[2]; 409 - u8 addrbuf[2]; 410 - int status; 411 - 412 - client = at24_translate_offset(at24, &offset); 413 - 414 - memset(msg, 0, sizeof(msg)); 415 - msg[0].addr = client->addr; 416 - msg[0].buf = addrbuf; 417 - /* EUI-48 starts from 0x9a, EUI-64 from 0x98 */ 418 - addrbuf[0] = 0xa0 - at24->chip.byte_len + offset; 419 - msg[0].len = 1; 420 - msg[1].addr = client->addr; 421 - msg[1].flags = I2C_M_RD; 422 - msg[1].buf = buf; 423 - msg[1].len = count; 424 - 425 - loop_until_timeout(timeout, read_time) { 426 - status = i2c_transfer(client->adapter, msg, 2); 427 - if (status == 2) 324 + count, offset, ret, jiffies); 325 + if (!ret) 428 326 return count; 429 327 } 430 328 ··· 330 454 static size_t at24_adjust_write_count(struct at24_data *at24, 331 455 unsigned int offset, size_t count) 332 456 { 333 - unsigned next_page; 457 + unsigned int next_page; 334 458 335 459 /* write_max is at most a page */ 336 460 if (count > at24->write_max) ··· 344 468 return count; 345 469 } 346 470 347 - static ssize_t at24_eeprom_write_smbus_block(struct at24_data *at24, 348 - const char *buf, 349 - unsigned int offset, size_t count) 471 + static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf, 472 + unsigned int offset, size_t count) 350 473 { 351 474 unsigned long timeout, write_time; 475 + struct at24_client *at24_client; 352 476 struct i2c_client *client; 353 - ssize_t status = 0; 477 + struct regmap *regmap; 478 + int ret; 354 479 355 - client = at24_translate_offset(at24, &offset); 480 + at24_client = at24_translate_offset(at24, &offset); 481 + regmap = at24_client->regmap; 482 + client = at24_client->client; 356 483 count = at24_adjust_write_count(at24, offset, count); 357 484 358 - loop_until_timeout(timeout, write_time) { 359 - status = i2c_smbus_write_i2c_block_data(client, 360 - offset, count, buf); 361 - if (status == 0) 362 - status = count; 363 - 364 - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", 365 - count, offset, status, jiffies); 366 - 367 - if (status == count) 368 - return count; 369 - } 370 - 371 - return -ETIMEDOUT; 372 - } 373 - 374 - static ssize_t at24_eeprom_write_smbus_byte(struct at24_data *at24, 375 - const char *buf, 376 - unsigned int offset, size_t count) 377 - { 378 - unsigned long timeout, write_time; 379 - struct i2c_client *client; 380 - ssize_t status = 0; 381 - 382 - client = at24_translate_offset(at24, &offset); 383 - 384 - loop_until_timeout(timeout, write_time) { 385 - status = i2c_smbus_write_byte_data(client, offset, buf[0]); 386 - if (status == 0) 387 - status = count; 388 - 389 - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", 390 - count, offset, status, jiffies); 391 - 392 - if (status == count) 393 - return count; 394 - } 395 - 396 - return -ETIMEDOUT; 397 - } 398 - 399 - static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf, 400 - unsigned int offset, size_t count) 401 - { 402 - unsigned long timeout, write_time; 403 - struct i2c_client *client; 404 - struct i2c_msg msg; 405 - ssize_t status = 0; 406 - int i = 0; 407 - 408 - client = at24_translate_offset(at24, &offset); 409 - count = at24_adjust_write_count(at24, offset, count); 410 - 411 - msg.addr = client->addr; 412 - msg.flags = 0; 413 - 414 - /* msg.buf is u8 and casts will mask the values */ 415 - msg.buf = at24->writebuf; 416 - if (at24->chip.flags & AT24_FLAG_ADDR16) 417 - msg.buf[i++] = offset >> 8; 418 - 419 - msg.buf[i++] = offset; 420 - memcpy(&msg.buf[i], buf, count); 421 - msg.len = i + count; 422 - 423 - loop_until_timeout(timeout, write_time) { 424 - status = i2c_transfer(client->adapter, &msg, 1); 425 - if (status == 1) 426 - status = count; 427 - 428 - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", 429 - count, offset, status, jiffies); 430 - 431 - if (status == count) 485 + at24_loop_until_timeout(timeout, write_time) { 486 + ret = regmap_bulk_write(regmap, offset, buf, count); 487 + dev_dbg(&client->dev, "write %zu@%d --> %d (%ld)\n", 488 + count, offset, ret, jiffies); 489 + if (!ret) 432 490 return count; 433 491 } 434 492 ··· 372 562 static int at24_read(void *priv, unsigned int off, void *val, size_t count) 373 563 { 374 564 struct at24_data *at24 = priv; 375 - struct device *dev = &at24->client[0]->dev; 565 + struct device *dev = &at24->client[0].client->dev; 376 566 char *buf = val; 377 567 int ret; 378 568 ··· 397 587 while (count) { 398 588 int status; 399 589 400 - status = at24->read_func(at24, buf, off, count); 590 + status = at24_regmap_read(at24, buf, off, count); 401 591 if (status < 0) { 402 592 mutex_unlock(&at24->lock); 403 593 pm_runtime_put(dev); ··· 418 608 static int at24_write(void *priv, unsigned int off, void *val, size_t count) 419 609 { 420 610 struct at24_data *at24 = priv; 421 - struct device *dev = &at24->client[0]->dev; 611 + struct device *dev = &at24->client[0].client->dev; 422 612 char *buf = val; 423 613 int ret; 424 614 ··· 439 629 * from this host, but not from other I2C masters. 440 630 */ 441 631 mutex_lock(&at24->lock); 632 + gpiod_set_value_cansleep(at24->wp_gpio, 0); 442 633 443 634 while (count) { 444 635 int status; 445 636 446 - status = at24->write_func(at24, buf, off, count); 637 + status = at24_regmap_write(at24, buf, off, count); 447 638 if (status < 0) { 639 + gpiod_set_value_cansleep(at24->wp_gpio, 1); 448 640 mutex_unlock(&at24->lock); 449 641 pm_runtime_put(dev); 450 642 return status; ··· 456 644 count -= status; 457 645 } 458 646 647 + gpiod_set_value_cansleep(at24->wp_gpio, 1); 459 648 mutex_unlock(&at24->lock); 460 649 461 650 pm_runtime_put(dev); ··· 471 658 472 659 if (device_property_present(dev, "read-only")) 473 660 chip->flags |= AT24_FLAG_READONLY; 661 + if (device_property_present(dev, "no-read-rollover")) 662 + chip->flags |= AT24_FLAG_NO_RDROL; 474 663 475 664 err = device_property_read_u32(dev, "size", &val); 476 665 if (!err) ··· 491 676 } 492 677 } 493 678 679 + static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len) 680 + { 681 + if (flags & AT24_FLAG_MAC) { 682 + /* EUI-48 starts from 0x9a, EUI-64 from 0x98 */ 683 + return 0xa0 - byte_len; 684 + } else if (flags & AT24_FLAG_SERIAL && flags & AT24_FLAG_ADDR16) { 685 + /* 686 + * For 16 bit address pointers, the word address must contain 687 + * a '10' sequence in bits 11 and 10 regardless of the 688 + * intended position of the address pointer. 689 + */ 690 + return 0x0800; 691 + } else if (flags & AT24_FLAG_SERIAL) { 692 + /* 693 + * Otherwise the word address must begin with a '10' sequence, 694 + * regardless of the intended address. 695 + */ 696 + return 0x0080; 697 + } else { 698 + return 0; 699 + } 700 + } 701 + 494 702 static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) 495 703 { 496 - struct at24_platform_data chip; 497 - kernel_ulong_t magic = 0; 704 + struct at24_platform_data chip = { 0 }; 705 + const struct at24_chip_data *cd = NULL; 498 706 bool writable; 499 - int use_smbus = 0; 500 - int use_smbus_write = 0; 501 707 struct at24_data *at24; 502 708 int err; 503 - unsigned i, num_addresses; 709 + unsigned int i, num_addresses; 710 + struct regmap_config regmap_config = { }; 504 711 u8 test_byte; 505 712 506 713 if (client->dev.platform_data) { ··· 535 698 */ 536 699 if (client->dev.of_node && 537 700 of_match_device(at24_of_match, &client->dev)) { 538 - magic = (kernel_ulong_t) 539 - of_device_get_match_data(&client->dev); 701 + cd = of_device_get_match_data(&client->dev); 540 702 } else if (id) { 541 - magic = id->driver_data; 703 + cd = (void *)id->driver_data; 542 704 } else { 543 705 const struct acpi_device_id *aid; 544 706 545 707 aid = acpi_match_device(at24_acpi_ids, &client->dev); 546 708 if (aid) 547 - magic = aid->driver_data; 709 + cd = (void *)aid->driver_data; 548 710 } 549 - if (!magic) 711 + if (!cd) 550 712 return -ENODEV; 551 713 552 - chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); 553 - magic >>= AT24_SIZE_BYTELEN; 554 - chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); 555 - 714 + chip.byte_len = cd->byte_len; 715 + chip.flags = cd->flags; 556 716 at24_get_pdata(&client->dev, &chip); 557 - 558 - chip.setup = NULL; 559 - chip.context = NULL; 560 717 } 561 718 562 719 if (!is_power_of_2(chip.byte_len)) ··· 564 733 dev_warn(&client->dev, 565 734 "page_size looks suspicious (no power of 2)!\n"); 566 735 567 - /* 568 - * REVISIT: the size of the EUI-48 byte array is 6 in at24mac402, while 569 - * the call to ilog2() in AT24_DEVICE_MAGIC() rounds it down to 4. 570 - * 571 - * Eventually we'll get rid of the magic values altoghether in favor of 572 - * real structs, but for now just manually set the right size. 573 - */ 574 - if (chip.flags & AT24_FLAG_MAC && chip.byte_len == 4) 575 - chip.byte_len = 6; 576 - 577 - /* Use I2C operations unless we're stuck with SMBus extensions. */ 578 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 579 - if (chip.flags & AT24_FLAG_ADDR16) 580 - return -EPFNOSUPPORT; 581 - 582 - if (i2c_check_functionality(client->adapter, 583 - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 584 - use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; 585 - } else if (i2c_check_functionality(client->adapter, 586 - I2C_FUNC_SMBUS_READ_WORD_DATA)) { 587 - use_smbus = I2C_SMBUS_WORD_DATA; 588 - } else if (i2c_check_functionality(client->adapter, 589 - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { 590 - use_smbus = I2C_SMBUS_BYTE_DATA; 591 - } else { 592 - return -EPFNOSUPPORT; 593 - } 594 - 595 - if (i2c_check_functionality(client->adapter, 596 - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { 597 - use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA; 598 - } else if (i2c_check_functionality(client->adapter, 599 - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { 600 - use_smbus_write = I2C_SMBUS_BYTE_DATA; 601 - chip.page_size = 1; 602 - } 603 - } 736 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && 737 + !i2c_check_functionality(client->adapter, 738 + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) 739 + chip.page_size = 1; 604 740 605 741 if (chip.flags & AT24_FLAG_TAKE8ADDR) 606 742 num_addresses = 8; ··· 575 777 num_addresses = DIV_ROUND_UP(chip.byte_len, 576 778 (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); 577 779 780 + regmap_config.val_bits = 8; 781 + regmap_config.reg_bits = (chip.flags & AT24_FLAG_ADDR16) ? 16 : 8; 782 + 578 783 at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + 579 - num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); 784 + num_addresses * sizeof(struct at24_client), GFP_KERNEL); 580 785 if (!at24) 581 786 return -ENOMEM; 582 787 583 788 mutex_init(&at24->lock); 584 - at24->use_smbus = use_smbus; 585 - at24->use_smbus_write = use_smbus_write; 586 789 at24->chip = chip; 587 790 at24->num_addresses = num_addresses; 791 + at24->offset_adj = at24_get_offset_adj(chip.flags, chip.byte_len); 792 + 793 + at24->wp_gpio = devm_gpiod_get_optional(&client->dev, 794 + "wp", GPIOD_OUT_HIGH); 795 + if (IS_ERR(at24->wp_gpio)) 796 + return PTR_ERR(at24->wp_gpio); 797 + 798 + at24->client[0].client = client; 799 + at24->client[0].regmap = devm_regmap_init_i2c(client, &regmap_config); 800 + if (IS_ERR(at24->client[0].regmap)) 801 + return PTR_ERR(at24->client[0].regmap); 588 802 589 803 if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { 590 804 dev_err(&client->dev, ··· 604 794 return -EINVAL; 605 795 } 606 796 607 - if (chip.flags & AT24_FLAG_SERIAL) { 608 - at24->read_func = at24_eeprom_read_serial; 609 - } else if (chip.flags & AT24_FLAG_MAC) { 610 - at24->read_func = at24_eeprom_read_mac; 611 - } else { 612 - at24->read_func = at24->use_smbus ? at24_eeprom_read_smbus 613 - : at24_eeprom_read_i2c; 614 - } 615 - 616 - if (at24->use_smbus) { 617 - if (at24->use_smbus_write == I2C_SMBUS_I2C_BLOCK_DATA) 618 - at24->write_func = at24_eeprom_write_smbus_block; 619 - else 620 - at24->write_func = at24_eeprom_write_smbus_byte; 621 - } else { 622 - at24->write_func = at24_eeprom_write_i2c; 623 - } 624 - 625 797 writable = !(chip.flags & AT24_FLAG_READONLY); 626 798 if (writable) { 627 - if (!use_smbus || use_smbus_write) { 628 - 629 - unsigned write_max = chip.page_size; 630 - 631 - if (write_max > io_limit) 632 - write_max = io_limit; 633 - if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) 634 - write_max = I2C_SMBUS_BLOCK_MAX; 635 - at24->write_max = write_max; 636 - 637 - /* buffer (data + address at the beginning) */ 638 - at24->writebuf = devm_kzalloc(&client->dev, 639 - write_max + 2, GFP_KERNEL); 640 - if (!at24->writebuf) 641 - return -ENOMEM; 642 - } else { 643 - dev_warn(&client->dev, 644 - "cannot write due to controller restrictions."); 645 - } 799 + at24->write_max = min_t(unsigned int, 800 + chip.page_size, at24_io_limit); 801 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && 802 + at24->write_max > I2C_SMBUS_BLOCK_MAX) 803 + at24->write_max = I2C_SMBUS_BLOCK_MAX; 646 804 } 647 - 648 - at24->client[0] = client; 649 805 650 806 /* use dummy devices for multiple-address chips */ 651 807 for (i = 1; i < num_addresses; i++) { 652 - at24->client[i] = i2c_new_dummy(client->adapter, 653 - client->addr + i); 654 - if (!at24->client[i]) { 808 + at24->client[i].client = i2c_new_dummy(client->adapter, 809 + client->addr + i); 810 + if (!at24->client[i].client) { 655 811 dev_err(&client->dev, "address 0x%02x unavailable\n", 656 812 client->addr + i); 657 813 err = -EADDRINUSE; 814 + goto err_clients; 815 + } 816 + at24->client[i].regmap = devm_regmap_init_i2c( 817 + at24->client[i].client, 818 + &regmap_config); 819 + if (IS_ERR(at24->client[i].regmap)) { 820 + err = PTR_ERR(at24->client[i].regmap); 658 821 goto err_clients; 659 822 } 660 823 } ··· 673 890 dev_info(&client->dev, "%u byte %s EEPROM, %s, %u bytes/write\n", 674 891 chip.byte_len, client->name, 675 892 writable ? "writable" : "read-only", at24->write_max); 676 - if (use_smbus == I2C_SMBUS_WORD_DATA || 677 - use_smbus == I2C_SMBUS_BYTE_DATA) { 678 - dev_notice(&client->dev, "Falling back to %s reads, " 679 - "performance will suffer\n", use_smbus == 680 - I2C_SMBUS_WORD_DATA ? "word" : "byte"); 681 - } 682 893 683 894 /* export data to kernel code */ 684 895 if (chip.setup) ··· 682 905 683 906 err_clients: 684 907 for (i = 1; i < num_addresses; i++) 685 - if (at24->client[i]) 686 - i2c_unregister_device(at24->client[i]); 908 + if (at24->client[i].client) 909 + i2c_unregister_device(at24->client[i].client); 687 910 688 911 pm_runtime_disable(&client->dev); 689 912 ··· 700 923 nvmem_unregister(at24->nvmem); 701 924 702 925 for (i = 1; i < at24->num_addresses; i++) 703 - i2c_unregister_device(at24->client[i]); 926 + i2c_unregister_device(at24->client[i].client); 704 927 705 928 pm_runtime_disable(&client->dev); 706 929 pm_runtime_set_suspended(&client->dev); ··· 723 946 724 947 static int __init at24_init(void) 725 948 { 726 - if (!io_limit) { 727 - pr_err("at24: io_limit must not be 0!\n"); 949 + if (!at24_io_limit) { 950 + pr_err("at24: at24_io_limit must not be 0!\n"); 728 951 return -EINVAL; 729 952 } 730 953 731 - io_limit = rounddown_pow_of_two(io_limit); 954 + at24_io_limit = rounddown_pow_of_two(at24_io_limit); 732 955 return i2c_add_driver(&at24_driver); 733 956 } 734 957 module_init(at24_init);
+88 -24
include/linux/i2c.h
··· 55 55 struct module; 56 56 struct property_entry; 57 57 58 - #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 58 + #if IS_ENABLED(CONFIG_I2C) 59 59 /* 60 60 * The master routines are the ones normally used to transmit data to devices 61 61 * on a bus (or read from them). Apart from two basic transfer functions to ··· 63 63 * transmit an arbitrary number of messages without interruption. 64 64 * @count must be be less than 64k since msg.len is u16. 65 65 */ 66 - extern int i2c_master_send(const struct i2c_client *client, const char *buf, 67 - int count); 68 - extern int i2c_master_recv(const struct i2c_client *client, char *buf, 69 - int count); 66 + extern int i2c_transfer_buffer_flags(const struct i2c_client *client, 67 + char *buf, int count, u16 flags); 68 + 69 + /** 70 + * i2c_master_recv - issue a single I2C message in master receive mode 71 + * @client: Handle to slave device 72 + * @buf: Where to store data read from slave 73 + * @count: How many bytes to read, must be less than 64k since msg.len is u16 74 + * 75 + * Returns negative errno, or else the number of bytes read. 76 + */ 77 + static inline int i2c_master_recv(const struct i2c_client *client, 78 + char *buf, int count) 79 + { 80 + return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD); 81 + }; 82 + 83 + /** 84 + * i2c_master_recv_dmasafe - issue a single I2C message in master receive mode 85 + * using a DMA safe buffer 86 + * @client: Handle to slave device 87 + * @buf: Where to store data read from slave, must be safe to use with DMA 88 + * @count: How many bytes to read, must be less than 64k since msg.len is u16 89 + * 90 + * Returns negative errno, or else the number of bytes read. 91 + */ 92 + static inline int i2c_master_recv_dmasafe(const struct i2c_client *client, 93 + char *buf, int count) 94 + { 95 + return i2c_transfer_buffer_flags(client, buf, count, 96 + I2C_M_RD | I2C_M_DMA_SAFE); 97 + }; 98 + 99 + /** 100 + * i2c_master_send - issue a single I2C message in master transmit mode 101 + * @client: Handle to slave device 102 + * @buf: Data that will be written to the slave 103 + * @count: How many bytes to write, must be less than 64k since msg.len is u16 104 + * 105 + * Returns negative errno, or else the number of bytes written. 106 + */ 107 + static inline int i2c_master_send(const struct i2c_client *client, 108 + const char *buf, int count) 109 + { 110 + return i2c_transfer_buffer_flags(client, (char *)buf, count, 0); 111 + }; 112 + 113 + /** 114 + * i2c_master_send_dmasafe - issue a single I2C message in master transmit mode 115 + * using a DMA safe buffer 116 + * @client: Handle to slave device 117 + * @buf: Data that will be written to the slave, must be safe to use with DMA 118 + * @count: How many bytes to write, must be less than 64k since msg.len is u16 119 + * 120 + * Returns negative errno, or else the number of bytes written. 121 + */ 122 + static inline int i2c_master_send_dmasafe(const struct i2c_client *client, 123 + const char *buf, int count) 124 + { 125 + return i2c_transfer_buffer_flags(client, (char *)buf, count, 126 + I2C_M_DMA_SAFE); 127 + }; 70 128 71 129 /* Transfer num messages. 72 130 */ ··· 412 354 .type = dev_type, .addr = (dev_addr) 413 355 414 356 415 - #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 357 + #if IS_ENABLED(CONFIG_I2C) 416 358 /* Add-on boards should register/unregister their devices; e.g. a board 417 359 * with integrated I2C, a config eeprom, sensors, and a codec that's 418 360 * used in conjunction with the primary hardware. ··· 543 485 /** 544 486 * struct i2c_bus_recovery_info - I2C bus recovery information 545 487 * @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or 546 - * i2c_generic_scl_recovery() or i2c_generic_gpio_recovery(). 488 + * i2c_generic_scl_recovery(). 547 489 * @get_scl: This gets current value of SCL line. Mandatory for generic SCL 548 - * recovery. Used internally for generic GPIO recovery. 549 - * @set_scl: This sets/clears SCL line. Mandatory for generic SCL recovery. Used 550 - * internally for generic GPIO recovery. 490 + * recovery. Populated internally for generic GPIO recovery. 491 + * @set_scl: This sets/clears the SCL line. Mandatory for generic SCL recovery. 492 + * Populated internally for generic GPIO recovery. 551 493 * @get_sda: This gets current value of SDA line. Optional for generic SCL 552 - * recovery. Used internally, if sda_gpio is a valid GPIO, for generic GPIO 553 - * recovery. 494 + * recovery. Populated internally, if sda_gpio is a valid GPIO, for generic 495 + * GPIO recovery. 496 + * @set_sda: This sets/clears the SDA line. Optional for generic SCL recovery. 497 + * Populated internally, if sda_gpio is a valid GPIO, for generic GPIO 498 + * recovery. 554 499 * @prepare_recovery: This will be called before starting recovery. Platform may 555 500 * configure padmux here for SDA/SCL line or something else they want. 556 501 * @unprepare_recovery: This will be called after completing recovery. Platform 557 502 * may configure padmux here for SDA/SCL line or something else they want. 558 - * @scl_gpio: gpio number of the SCL line. Only required for GPIO recovery. 559 - * @sda_gpio: gpio number of the SDA line. Only required for GPIO recovery. 503 + * @scl_gpiod: gpiod of the SCL line. Only required for GPIO recovery. 504 + * @sda_gpiod: gpiod of the SDA line. Only required for GPIO recovery. 560 505 */ 561 506 struct i2c_bus_recovery_info { 562 - int (*recover_bus)(struct i2c_adapter *); 507 + int (*recover_bus)(struct i2c_adapter *adap); 563 508 564 - int (*get_scl)(struct i2c_adapter *); 565 - void (*set_scl)(struct i2c_adapter *, int val); 566 - int (*get_sda)(struct i2c_adapter *); 509 + int (*get_scl)(struct i2c_adapter *adap); 510 + void (*set_scl)(struct i2c_adapter *adap, int val); 511 + int (*get_sda)(struct i2c_adapter *adap); 512 + void (*set_sda)(struct i2c_adapter *adap, int val); 567 513 568 - void (*prepare_recovery)(struct i2c_adapter *); 569 - void (*unprepare_recovery)(struct i2c_adapter *); 514 + void (*prepare_recovery)(struct i2c_adapter *adap); 515 + void (*unprepare_recovery)(struct i2c_adapter *adap); 570 516 571 517 /* gpio recovery */ 572 - int scl_gpio; 573 - int sda_gpio; 518 + struct gpio_desc *scl_gpiod; 519 + struct gpio_desc *sda_gpiod; 574 520 }; 575 521 576 522 int i2c_recover_bus(struct i2c_adapter *adap); 577 523 578 524 /* Generic recovery routines */ 579 - int i2c_generic_gpio_recovery(struct i2c_adapter *adap); 580 525 int i2c_generic_scl_recovery(struct i2c_adapter *adap); 581 526 582 527 /** ··· 767 706 768 707 /* administration... 769 708 */ 770 - #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 709 + #if IS_ENABLED(CONFIG_I2C) 771 710 extern int i2c_add_adapter(struct i2c_adapter *); 772 711 extern void i2c_del_adapter(struct i2c_adapter *); 773 712 extern int i2c_add_numbered_adapter(struct i2c_adapter *); ··· 829 768 { 830 769 return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0); 831 770 } 771 + 772 + u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold); 773 + void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf); 832 774 833 775 int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr); 834 776 /**
+2
include/linux/platform_data/at24.h
··· 50 50 #define AT24_FLAG_TAKE8ADDR BIT(4) /* take always 8 addresses (24c00) */ 51 51 #define AT24_FLAG_SERIAL BIT(3) /* factory-programmed serial number */ 52 52 #define AT24_FLAG_MAC BIT(2) /* factory-programmed mac address */ 53 + #define AT24_FLAG_NO_RDROL BIT(1) /* does not auto-rollover reads to */ 54 + /* the next slave address */ 53 55 54 56 void (*setup)(struct nvmem_device *nvmem, void *context); 55 57 void *context;
+2 -3
include/linux/platform_data/i2c-davinci.h
··· 16 16 struct davinci_i2c_platform_data { 17 17 unsigned int bus_freq; /* standard bus frequency (kHz) */ 18 18 unsigned int bus_delay; /* post-transaction delay (usec) */ 19 - unsigned int sda_pin; /* GPIO pin ID to use for SDA */ 20 - unsigned int scl_pin; /* GPIO pin ID to use for SCL */ 21 - bool has_pfunc; /*chip has a ICPFUNC register */ 19 + bool gpio_recovery; /* Use GPIO recovery method */ 20 + bool has_pfunc; /* Chip has a ICPFUNC register */ 22 21 }; 23 22 24 23 /* for board setup code */
+3
include/uapi/linux/i2c.h
··· 72 72 #define I2C_M_RD 0x0001 /* read data, from slave to master */ 73 73 /* I2C_M_RD is guaranteed to be 0x0001! */ 74 74 #define I2C_M_TEN 0x0010 /* this is a ten bit chip address */ 75 + #define I2C_M_DMA_SAFE 0x0200 /* the buffer of this message is DMA safe */ 76 + /* makes only sense in kernelspace */ 77 + /* userspace buffers are copied anyway */ 75 78 #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */ 76 79 #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */ 77 80 #define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */