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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull i2c updates from Wolfram Sang:
"This contains two bigger than usual tree-wide changes this time. They
all have proper acks, caused no merge conflicts in linux-next where
they have been for a while. They are namely:

- to-gpiod conversion of the i2c-gpio driver and its users (touching
arch/* and drivers/mfd/*)

- adding a sbs-manager based on I2C core updates to SMBus alerts
(touching drivers/power/*)

Other notable changes:

- i2c_boardinfo can now carry a dev_name to be used when the device
is created. This is because some devices in ACPI world need fixed
names to find the regulators.

- the designware driver got a long discussed overhaul of its PM
handling. img-scb and davinci got PM support, too.

- at24 driver has way better OF support. And it has a new maintainer.
Thanks Bartosz for stepping up!

The rest is regular driver updates and fixes"

* 'i2c/for-4.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (55 commits)
ARM: sa1100: simpad: Correct I2C GPIO offsets
i2c: aspeed: Deassert reset in probe
eeprom: at24: Add OF device ID table
MAINTAINERS: new maintainer for AT24 driver
i2c: nuc900: remove platform_data, too
i2c: thunderx: Remove duplicate NULL check
i2c: taos-evm: Remove duplicate NULL check
i2c: Make i2c_unregister_device() NULL-aware
i2c: xgene-slimpro: Support v2
i2c: mpc: remove useless variable initialization
i2c: omap: Trigger bus recovery in lockup case
i2c: gpio: Add support for named gpios in DT
dt-bindings: i2c: i2c-gpio: Add support for named gpios
i2c: gpio: Local vars in probe
i2c: gpio: Augment all boardfiles to use open drain
i2c: gpio: Enforce open drain through gpiolib
gpio: Make it possible for consumers to enforce open drain
i2c: gpio: Convert to use descriptors
power: supply: sbs-message: fix some code style issues
power: supply: sbs-battery: remove unchecked return var
...

+1687 -602
+2
Documentation/devicetree/bindings/eeprom/eeprom.txt
··· 36 36 37 37 - read-only: this parameterless property disables writes to the eeprom 38 38 39 + - size: total eeprom size in bytes 40 + 39 41 Example: 40 42 41 43 eeprom@52 {
+5 -2
Documentation/devicetree/bindings/i2c/i2c-aspeed.txt
··· 7 7 - compatible : should be "aspeed,ast2400-i2c-bus" 8 8 or "aspeed,ast2500-i2c-bus" 9 9 - clocks : root clock of bus, should reference the APB 10 - clock 10 + clock in the second cell 11 + - resets : phandle to reset controller with the reset number in 12 + the second cell 11 13 - interrupts : interrupt number 12 14 - interrupt-parent : interrupt controller for bus, should reference a 13 15 aspeed,ast2400-i2c-ic or aspeed,ast2500-i2c-ic ··· 42 40 #interrupt-cells = <1>; 43 41 reg = <0x40 0x40>; 44 42 compatible = "aspeed,ast2400-i2c-bus"; 45 - clocks = <&clk_apb>; 43 + clocks = <&syscon ASPEED_CLK_APB>; 44 + resets = <&syscon ASPEED_RESET_I2C>; 46 45 bus-frequency = <100000>; 47 46 interrupts = <0>; 48 47 interrupt-parent = <&i2c_ic>;
+12
Documentation/devicetree/bindings/i2c/i2c-davinci.txt
··· 6 6 Required properties: 7 7 - compatible: "ti,davinci-i2c" or "ti,keystone-i2c"; 8 8 - reg : Offset and length of the register set for the device 9 + - clocks: I2C functional clock phandle. 10 + For 66AK2G this property should be set per binding, 11 + Documentation/devicetree/bindings/clock/ti,sci-clk.txt 12 + 13 + SoC-specific Required Properties: 14 + 15 + The following are mandatory properties for Keystone 2 66AK2G SoCs only: 16 + 17 + - power-domains: Should contain a phandle to a PM domain provider node 18 + and an args specifier containing the I2C device id 19 + value. This property is as per the binding, 20 + Documentation/devicetree/bindings/soc/ti/sci-pm-domain.txt 9 21 10 22 Recommended properties : 11 23 - interrupts : standard interrupt property.
+23 -9
Documentation/devicetree/bindings/i2c/i2c-gpio.txt
··· 2 2 3 3 Required properties: 4 4 - compatible = "i2c-gpio"; 5 - - gpios: sda and scl gpio 6 - 5 + - sda-gpios: gpio used for the sda signal, this should be flagged as 6 + active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN) 7 + from <dt-bindings/gpio/gpio.h> since the signal is by definition 8 + open drain. 9 + - scl-gpios: gpio used for the scl signal, this should be flagged as 10 + active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN) 11 + from <dt-bindings/gpio/gpio.h> since the signal is by definition 12 + open drain. 7 13 8 14 Optional properties: 9 - - i2c-gpio,sda-open-drain: sda as open drain 10 - - i2c-gpio,scl-open-drain: scl as open drain 11 15 - i2c-gpio,scl-output-only: scl as output only 12 16 - i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform) 13 17 - i2c-gpio,timeout-ms: timeout to get data 14 18 19 + Deprecated properties, do not use in new device tree sources: 20 + - gpios: sda and scl gpio, alternative for {sda,scl}-gpios 21 + - i2c-gpio,sda-open-drain: this means that something outside of our 22 + control has put the GPIO line used for SDA into open drain mode, and 23 + that something is not the GPIO chip. It is essentially an 24 + inconsistency flag. 25 + - i2c-gpio,scl-open-drain: this means that something outside of our 26 + control has put the GPIO line used for SCL into open drain mode, and 27 + that something is not the GPIO chip. It is essentially an 28 + inconsistency flag. 29 + 15 30 Example nodes: 31 + 32 + #include <dt-bindings/gpio/gpio.h> 16 33 17 34 i2c@0 { 18 35 compatible = "i2c-gpio"; 19 - gpios = <&pioA 23 0 /* sda */ 20 - &pioA 24 0 /* scl */ 21 - >; 22 - i2c-gpio,sda-open-drain; 23 - i2c-gpio,scl-open-drain; 36 + sda-gpios = <&pioA 23 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; 37 + scl-gpios = <&pioA 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; 24 38 i2c-gpio,delay-us = <2>; /* ~100 kHz */ 25 39 #address-cells = <1>; 26 40 #size-cells = <0>;
+2 -2
Documentation/devicetree/bindings/i2c/i2c-mux.txt
··· 6 6 7 7 Optional properties: 8 8 - #address-cells = <1>; 9 - This property is required is the i2c-mux child node does not exist. 9 + This property is required if the i2c-mux child node does not exist. 10 10 11 11 - #size-cells = <0>; 12 - This property is required is the i2c-mux child node does not exist. 12 + This property is required if the i2c-mux child node does not exist. 13 13 14 14 - i2c-mux 15 15 For i2c multiplexers/switches that have child nodes that are a mixture
+1
Documentation/devicetree/bindings/i2c/i2c-rcar.txt
··· 13 13 "renesas,i2c-r8a7794" if the device is a part of a R8A7794 SoC. 14 14 "renesas,i2c-r8a7795" if the device is a part of a R8A7795 SoC. 15 15 "renesas,i2c-r8a7796" if the device is a part of a R8A7796 SoC. 16 + "renesas,i2c-r8a77970" if the device is a part of a R8A77970 SoC. 16 17 "renesas,rcar-gen1-i2c" for a generic R-Car Gen1 compatible device. 17 18 "renesas,rcar-gen2-i2c" for a generic R-Car Gen2 or RZ/G1 compatible 18 19 device.
+2 -2
Documentation/devicetree/bindings/i2c/i2c.txt
··· 59 59 interrupts used by the device. 60 60 61 61 - interrupt-names 62 - "irq" and "wakeup" names are recognized by I2C core, other names are 63 - left to individual drivers. 62 + "irq", "wakeup" and "smbus_alert" names are recognized by I2C core, 63 + other names are left to individual drivers. 64 64 65 65 - host-notify 66 66 device uses SMBus host notify protocol instead of interrupt line.
+66
Documentation/devicetree/bindings/power/supply/sbs,sbs-manager.txt
··· 1 + Binding for sbs-manager 2 + 3 + Required properties: 4 + - compatible: "<vendor>,<part-number>", "sbs,sbs-charger" as fallback. The part 5 + number compatible string might be used in order to take care of vendor 6 + specific registers. 7 + - reg: integer, i2c address of the device. Should be <0xa>. 8 + Optional properties: 9 + - gpio-controller: Marks the port as GPIO controller. 10 + See "gpio-specifier" in .../devicetree/bindings/gpio/gpio.txt. 11 + - #gpio-cells: Should be <2>. The first cell is the pin number, the second cell 12 + is used to specify optional parameters: 13 + See "gpio-specifier" in .../devicetree/bindings/gpio/gpio.txt. 14 + 15 + From OS view the device is basically an i2c-mux used to communicate with up to 16 + four smart battery devices at address 0xb. The driver actually implements this 17 + behaviour. So standard i2c-mux nodes can be used to register up to four slave 18 + batteries. Channels will be numerated starting from 1 to 4. 19 + 20 + Example: 21 + 22 + batman@a { 23 + compatible = "lltc,ltc1760", "sbs,sbs-manager"; 24 + reg = <0x0a>; 25 + #address-cells = <1>; 26 + #size-cells = <0>; 27 + 28 + gpio-controller; 29 + #gpio-cells = <2>; 30 + 31 + i2c@1 { 32 + #address-cells = <1>; 33 + #size-cells = <0>; 34 + reg = <1>; 35 + 36 + battery@b { 37 + compatible = "ti,bq2060", "sbs,sbs-battery"; 38 + reg = <0x0b>; 39 + sbs,battery-detect-gpios = <&batman 1 1>; 40 + }; 41 + }; 42 + 43 + i2c@2 { 44 + #address-cells = <1>; 45 + #size-cells = <0>; 46 + reg = <2>; 47 + 48 + battery@b { 49 + compatible = "ti,bq2060", "sbs,sbs-battery"; 50 + reg = <0x0b>; 51 + sbs,battery-detect-gpios = <&batman 2 1>; 52 + }; 53 + }; 54 + 55 + i2c@3 { 56 + #address-cells = <1>; 57 + #size-cells = <0>; 58 + reg = <3>; 59 + 60 + battery@b { 61 + compatible = "ti,bq2060", "sbs,sbs-battery"; 62 + reg = <0x0b>; 63 + sbs,battery-detect-gpios = <&batman 3 1>; 64 + }; 65 + }; 66 + };
+1 -1
MAINTAINERS
··· 2249 2249 F: include/linux/async_tx.h 2250 2250 2251 2251 AT24 EEPROM DRIVER 2252 - M: Wolfram Sang <wsa@the-dreams.de> 2252 + M: Bartosz Golaszewski <brgl@bgdev.pl> 2253 2253 L: linux-i2c@vger.kernel.org 2254 2254 S: Maintained 2255 2255 F: drivers/misc/eeprom/at24.c
+23 -18
arch/arm/mach-ep93xx/core.c
··· 31 31 #include <linux/amba/serial.h> 32 32 #include <linux/mtd/physmap.h> 33 33 #include <linux/i2c.h> 34 - #include <linux/i2c-gpio.h> 34 + #include <linux/gpio/machine.h> 35 35 #include <linux/spi/spi.h> 36 36 #include <linux/export.h> 37 37 #include <linux/irqchip/arm-vic.h> ··· 320 320 /************************************************************************* 321 321 * EP93xx i2c peripheral handling 322 322 *************************************************************************/ 323 - static struct i2c_gpio_platform_data ep93xx_i2c_data; 323 + 324 + /* All EP93xx devices use the same two GPIO pins for I2C bit-banging */ 325 + static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = { 326 + .dev_id = "i2c-gpio", 327 + .table = { 328 + /* Use local offsets on gpiochip/port "G" */ 329 + GPIO_LOOKUP_IDX("G", 1, NULL, 0, 330 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 331 + GPIO_LOOKUP_IDX("G", 0, NULL, 1, 332 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 333 + }, 334 + }; 324 335 325 336 static struct platform_device ep93xx_i2c_device = { 326 337 .name = "i2c-gpio", 327 338 .id = 0, 328 339 .dev = { 329 - .platform_data = &ep93xx_i2c_data, 340 + .platform_data = NULL, 330 341 }, 331 342 }; 332 343 333 344 /** 334 345 * ep93xx_register_i2c - Register the i2c platform device. 335 - * @data: platform specific i2c-gpio configuration (__initdata) 336 346 * @devices: platform specific i2c bus device information (__initdata) 337 347 * @num: the number of devices on the i2c bus 338 348 */ 339 - void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 340 - struct i2c_board_info *devices, int num) 349 + void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num) 341 350 { 342 351 /* 343 - * Set the EEPROM interface pin drive type control. 344 - * Defines the driver type for the EECLK and EEDAT pins as either 345 - * open drain, which will require an external pull-up, or a normal 346 - * CMOS driver. 352 + * FIXME: this just sets the two pins as non-opendrain, as no 353 + * platforms tries to do that anyway. Flag the applicable lines 354 + * as open drain in the GPIO_LOOKUP above and the driver or 355 + * gpiolib will handle open drain/open drain emulation as need 356 + * be. Right now i2c-gpio emulates open drain which is not 357 + * optimal. 347 358 */ 348 - if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT) 349 - pr_warning("sda != EEDAT, open drain has no effect\n"); 350 - if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK) 351 - pr_warning("scl != EECLK, open drain has no effect\n"); 352 - 353 - __raw_writel((data->sda_is_open_drain << 1) | 354 - (data->scl_is_open_drain << 0), 359 + __raw_writel((0 << 1) | (0 << 0), 355 360 EP93XX_GPIO_EEDRIVE); 356 361 357 - ep93xx_i2c_data = *data; 358 362 i2c_register_board_info(0, devices, num); 363 + gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table); 359 364 platform_device_register(&ep93xx_i2c_device); 360 365 } 361 366
+2 -13
arch/arm/mach-ep93xx/edb93xx.c
··· 28 28 #include <linux/init.h> 29 29 #include <linux/platform_device.h> 30 30 #include <linux/i2c.h> 31 - #include <linux/i2c-gpio.h> 32 31 #include <linux/spi/spi.h> 33 32 34 33 #include <sound/cs4271.h> ··· 60 61 /************************************************************************* 61 62 * EDB93xx i2c peripheral handling 62 63 *************************************************************************/ 63 - static struct i2c_gpio_platform_data __initdata edb93xx_i2c_gpio_data = { 64 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 65 - .sda_is_open_drain = 0, 66 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 67 - .scl_is_open_drain = 0, 68 - .udelay = 0, /* default to 100 kHz */ 69 - .timeout = 0, /* default to 100 ms */ 70 - }; 71 64 72 65 static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = { 73 66 { ··· 77 86 { 78 87 if (machine_is_edb9302a() || machine_is_edb9307a() || 79 88 machine_is_edb9315a()) { 80 - ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 81 - edb93xxa_i2c_board_info, 89 + ep93xx_register_i2c(edb93xxa_i2c_board_info, 82 90 ARRAY_SIZE(edb93xxa_i2c_board_info)); 83 91 } else if (machine_is_edb9302() || machine_is_edb9307() 84 92 || machine_is_edb9312() || machine_is_edb9315()) { 85 - ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 86 - edb93xx_i2c_board_info, 93 + ep93xx_register_i2c(edb93xx_i2c_board_info, 87 94 ARRAY_SIZE(edb93xx_i2c_board_info)); 88 95 } 89 96 }
+1 -3
arch/arm/mach-ep93xx/include/mach/platform.h
··· 8 8 #include <linux/reboot.h> 9 9 10 10 struct device; 11 - struct i2c_gpio_platform_data; 12 11 struct i2c_board_info; 13 12 struct spi_board_info; 14 13 struct platform_device; ··· 36 37 resource_size_t start, resource_size_t size); 37 38 38 39 void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr); 39 - void ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 40 - struct i2c_board_info *devices, int num); 40 + void ep93xx_register_i2c(struct i2c_board_info *devices, int num); 41 41 void ep93xx_register_spi(struct ep93xx_spi_info *info, 42 42 struct spi_board_info *devices, int num); 43 43 void ep93xx_register_fb(struct ep93xxfb_mach_info *data);
+1 -11
arch/arm/mach-ep93xx/simone.c
··· 19 19 #include <linux/init.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/i2c.h> 22 - #include <linux/i2c-gpio.h> 23 22 #include <linux/mmc/host.h> 24 23 #include <linux/spi/spi.h> 25 24 #include <linux/spi/mmc_spi.h> ··· 128 129 .use_dma = 1, 129 130 }; 130 131 131 - static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = { 132 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 133 - .sda_is_open_drain = 0, 134 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 135 - .scl_is_open_drain = 0, 136 - .udelay = 0, 137 - .timeout = 0, 138 - }; 139 - 140 132 static struct i2c_board_info __initdata simone_i2c_board_info[] = { 141 133 { 142 134 I2C_BOARD_INFO("ds1337", 0x68), ··· 151 161 ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M); 152 162 ep93xx_register_eth(&simone_eth_data, 1); 153 163 ep93xx_register_fb(&simone_fb_info); 154 - ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, 164 + ep93xx_register_i2c(simone_i2c_board_info, 155 165 ARRAY_SIZE(simone_i2c_board_info)); 156 166 ep93xx_register_spi(&simone_spi_info, simone_spi_devices, 157 167 ARRAY_SIZE(simone_spi_devices));
+1 -11
arch/arm/mach-ep93xx/snappercl15.c
··· 21 21 #include <linux/init.h> 22 22 #include <linux/io.h> 23 23 #include <linux/i2c.h> 24 - #include <linux/i2c-gpio.h> 25 24 #include <linux/fb.h> 26 25 27 26 #include <linux/mtd/partitions.h> ··· 126 127 .phy_id = 1, 127 128 }; 128 129 129 - static struct i2c_gpio_platform_data __initdata snappercl15_i2c_gpio_data = { 130 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 131 - .sda_is_open_drain = 0, 132 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 133 - .scl_is_open_drain = 0, 134 - .udelay = 0, 135 - .timeout = 0, 136 - }; 137 - 138 130 static struct i2c_board_info __initdata snappercl15_i2c_data[] = { 139 131 { 140 132 /* Audio codec */ ··· 151 161 { 152 162 ep93xx_init_devices(); 153 163 ep93xx_register_eth(&snappercl15_eth_data, 1); 154 - ep93xx_register_i2c(&snappercl15_i2c_gpio_data, snappercl15_i2c_data, 164 + ep93xx_register_i2c(snappercl15_i2c_data, 155 165 ARRAY_SIZE(snappercl15_i2c_data)); 156 166 ep93xx_register_fb(&snappercl15_fb_info); 157 167 snappercl15_register_audio();
+1 -6
arch/arm/mach-ep93xx/vision_ep9307.c
··· 22 22 #include <linux/io.h> 23 23 #include <linux/mtd/partitions.h> 24 24 #include <linux/i2c.h> 25 - #include <linux/i2c-gpio.h> 26 25 #include <linux/platform_data/pca953x.h> 27 26 #include <linux/spi/spi.h> 28 27 #include <linux/spi/flash.h> ··· 143 144 /************************************************************************* 144 145 * I2C Bus 145 146 *************************************************************************/ 146 - static struct i2c_gpio_platform_data vision_i2c_gpio_data __initdata = { 147 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 148 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 149 - }; 150 147 151 148 static struct i2c_board_info vision_i2c_info[] __initdata = { 152 149 { ··· 284 289 285 290 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7)); 286 291 287 - ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info, 292 + ep93xx_register_i2c(vision_i2c_info, 288 293 ARRAY_SIZE(vision_i2c_info)); 289 294 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, 290 295 ARRAY_SIZE(vision_spi_board_info));
+12 -5
arch/arm/mach-ixp4xx/avila-setup.c
··· 18 18 #include <linux/serial.h> 19 19 #include <linux/tty.h> 20 20 #include <linux/serial_8250.h> 21 - #include <linux/i2c-gpio.h> 21 + #include <linux/gpio/machine.h> 22 22 #include <asm/types.h> 23 23 #include <asm/setup.h> 24 24 #include <asm/memory.h> ··· 50 50 .resource = &avila_flash_resource, 51 51 }; 52 52 53 - static struct i2c_gpio_platform_data avila_i2c_gpio_data = { 54 - .sda_pin = AVILA_SDA_PIN, 55 - .scl_pin = AVILA_SCL_PIN, 53 + static struct gpiod_lookup_table avila_i2c_gpiod_table = { 54 + .dev_id = "i2c-gpio", 55 + .table = { 56 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SDA_PIN, 57 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 58 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SCL_PIN, 59 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 60 + }, 56 61 }; 57 62 58 63 static struct platform_device avila_i2c_gpio = { 59 64 .name = "i2c-gpio", 60 65 .id = 0, 61 66 .dev = { 62 - .platform_data = &avila_i2c_gpio_data, 67 + .platform_data = NULL, 63 68 }, 64 69 }; 65 70 ··· 152 147 avila_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); 153 148 avila_flash_resource.end = 154 149 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 150 + 151 + gpiod_add_lookup_table(&avila_i2c_gpiod_table); 155 152 156 153 platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices)); 157 154
+11 -5
arch/arm/mach-ixp4xx/dsmg600-setup.c
··· 26 26 #include <linux/leds.h> 27 27 #include <linux/reboot.h> 28 28 #include <linux/i2c.h> 29 - #include <linux/i2c-gpio.h> 29 + #include <linux/gpio/machine.h> 30 30 31 31 #include <mach/hardware.h> 32 32 ··· 69 69 .resource = &dsmg600_flash_resource, 70 70 }; 71 71 72 - static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { 73 - .sda_pin = DSMG600_SDA_PIN, 74 - .scl_pin = DSMG600_SCL_PIN, 72 + static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = { 73 + .dev_id = "i2c-gpio", 74 + .table = { 75 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN, 76 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 77 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN, 78 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 79 + }, 75 80 }; 76 81 77 82 static struct platform_device dsmg600_i2c_gpio = { 78 83 .name = "i2c-gpio", 79 84 .id = 0, 80 85 .dev = { 81 - .platform_data = &dsmg600_i2c_gpio_data, 86 + .platform_data = NULL, 82 87 }, 83 88 }; 84 89 ··· 275 270 dsmg600_flash_resource.end = 276 271 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 277 272 273 + gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table); 278 274 i2c_register_board_info(0, dsmg600_i2c_board_info, 279 275 ARRAY_SIZE(dsmg600_i2c_board_info)); 280 276
+11 -5
arch/arm/mach-ixp4xx/fsg-setup.c
··· 23 23 #include <linux/leds.h> 24 24 #include <linux/reboot.h> 25 25 #include <linux/i2c.h> 26 - #include <linux/i2c-gpio.h> 26 + #include <linux/gpio/machine.h> 27 27 #include <linux/io.h> 28 28 #include <asm/mach-types.h> 29 29 #include <asm/mach/arch.h> ··· 55 55 .resource = &fsg_flash_resource, 56 56 }; 57 57 58 - static struct i2c_gpio_platform_data fsg_i2c_gpio_data = { 59 - .sda_pin = FSG_SDA_PIN, 60 - .scl_pin = FSG_SCL_PIN, 58 + static struct gpiod_lookup_table fsg_i2c_gpiod_table = { 59 + .dev_id = "i2c-gpio", 60 + .table = { 61 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN, 62 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 63 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN, 64 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 65 + }, 61 66 }; 62 67 63 68 static struct platform_device fsg_i2c_gpio = { 64 69 .name = "i2c-gpio", 65 70 .id = 0, 66 71 .dev = { 67 - .platform_data = &fsg_i2c_gpio_data, 72 + .platform_data = NULL, 68 73 }, 69 74 }; 70 75 ··· 202 197 /* Configure CS2 for operation, 8bit and writable */ 203 198 *IXP4XX_EXP_CS2 = 0xbfff0002; 204 199 200 + gpiod_add_lookup_table(&fsg_i2c_gpiod_table); 205 201 i2c_register_board_info(0, fsg_i2c_board_info, 206 202 ARRAY_SIZE(fsg_i2c_board_info)); 207 203
+6 -18
arch/arm/mach-ixp4xx/goramo_mlr.c
··· 7 7 #include <linux/delay.h> 8 8 #include <linux/gpio.h> 9 9 #include <linux/hdlc.h> 10 - #include <linux/i2c-gpio.h> 11 10 #include <linux/io.h> 12 11 #include <linux/irq.h> 13 12 #include <linux/kernel.h> ··· 78 79 static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */; 79 80 static u8 control_value; 80 81 82 + /* 83 + * FIXME: this is reimplementing I2C bit-bangining. Move this 84 + * over to using driver/i2c/busses/i2c-gpio.c like all other boards 85 + * and register proper I2C device(s) on the bus for this. (See 86 + * other IXP4xx boards for examples.) 87 + */ 81 88 static void set_scl(u8 value) 82 89 { 83 90 gpio_set_value(GPIO_SCL, !!value); ··· 221 216 .num_resources = 1, 222 217 .resource = &flash_resource, 223 218 }; 224 - 225 - 226 - /* I^2C interface */ 227 - static struct i2c_gpio_platform_data i2c_data = { 228 - .sda_pin = GPIO_SDA, 229 - .scl_pin = GPIO_SCL, 230 - }; 231 - 232 - static struct platform_device device_i2c = { 233 - .name = "i2c-gpio", 234 - .id = 0, 235 - .dev = { .platform_data = &i2c_data }, 236 - }; 237 - 238 219 239 220 /* IXP425 2 UART ports */ 240 221 static struct resource uart_resources[] = { ··· 402 411 device_tab[devices++] = &device_hss_tab[0]; /* max index 4 */ 403 412 if (hw_bits & CFG_HW_HAS_HSS1) 404 413 device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */ 405 - 406 - if (hw_bits & CFG_HW_HAS_EEPROM) 407 - device_tab[devices++] = &device_i2c; /* max index 6 */ 408 414 409 415 gpio_request(GPIO_SCL, "SCL/clock"); 410 416 gpio_request(GPIO_SDA, "SDA/data");
+11 -5
arch/arm/mach-ixp4xx/ixdp425-setup.c
··· 15 15 #include <linux/serial.h> 16 16 #include <linux/tty.h> 17 17 #include <linux/serial_8250.h> 18 - #include <linux/i2c-gpio.h> 18 + #include <linux/gpio/machine.h> 19 19 #include <linux/io.h> 20 20 #include <linux/mtd/mtd.h> 21 21 #include <linux/mtd/rawnand.h> ··· 123 123 }; 124 124 #endif /* CONFIG_MTD_NAND_PLATFORM */ 125 125 126 - static struct i2c_gpio_platform_data ixdp425_i2c_gpio_data = { 127 - .sda_pin = IXDP425_SDA_PIN, 128 - .scl_pin = IXDP425_SCL_PIN, 126 + static struct gpiod_lookup_table ixdp425_i2c_gpiod_table = { 127 + .dev_id = "i2c-gpio", 128 + .table = { 129 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SDA_PIN, 130 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 131 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SCL_PIN, 132 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 133 + }, 129 134 }; 130 135 131 136 static struct platform_device ixdp425_i2c_gpio = { 132 137 .name = "i2c-gpio", 133 138 .id = 0, 134 139 .dev = { 135 - .platform_data = &ixdp425_i2c_gpio_data, 140 + .platform_data = NULL, 136 141 }, 137 142 }; 138 143 ··· 251 246 ixdp425_uart_data[1].flags = 0; 252 247 } 253 248 249 + gpiod_add_lookup_table(&ixdp425_i2c_gpiod_table); 254 250 platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices)); 255 251 } 256 252
+11 -5
arch/arm/mach-ixp4xx/nas100d-setup.c
··· 28 28 #include <linux/leds.h> 29 29 #include <linux/reboot.h> 30 30 #include <linux/i2c.h> 31 - #include <linux/i2c-gpio.h> 31 + #include <linux/gpio/machine.h> 32 32 #include <linux/io.h> 33 33 #include <asm/mach-types.h> 34 34 #include <asm/mach/arch.h> ··· 101 101 .dev.platform_data = &nas100d_led_data, 102 102 }; 103 103 104 - static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = { 105 - .sda_pin = NAS100D_SDA_PIN, 106 - .scl_pin = NAS100D_SCL_PIN, 104 + static struct gpiod_lookup_table nas100d_i2c_gpiod_table = { 105 + .dev_id = "i2c-gpio", 106 + .table = { 107 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN, 108 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 109 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN, 110 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 111 + }, 107 112 }; 108 113 109 114 static struct platform_device nas100d_i2c_gpio = { 110 115 .name = "i2c-gpio", 111 116 .id = 0, 112 117 .dev = { 113 - .platform_data = &nas100d_i2c_gpio_data, 118 + .platform_data = NULL, 114 119 }, 115 120 }; 116 121 ··· 286 281 nas100d_flash_resource.end = 287 282 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 288 283 284 + gpiod_add_lookup_table(&nas100d_i2c_gpiod_table); 289 285 i2c_register_board_info(0, nas100d_i2c_board_info, 290 286 ARRAY_SIZE(nas100d_i2c_board_info)); 291 287
+11 -5
arch/arm/mach-ixp4xx/nslu2-setup.c
··· 25 25 #include <linux/leds.h> 26 26 #include <linux/reboot.h> 27 27 #include <linux/i2c.h> 28 - #include <linux/i2c-gpio.h> 28 + #include <linux/gpio/machine.h> 29 29 #include <linux/io.h> 30 30 #include <asm/mach-types.h> 31 31 #include <asm/mach/arch.h> ··· 69 69 .resource = &nslu2_flash_resource, 70 70 }; 71 71 72 - static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { 73 - .sda_pin = NSLU2_SDA_PIN, 74 - .scl_pin = NSLU2_SCL_PIN, 72 + static struct gpiod_lookup_table nslu2_i2c_gpiod_table = { 73 + .dev_id = "i2c-gpio", 74 + .table = { 75 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN, 76 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 77 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN, 78 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 79 + }, 75 80 }; 76 81 77 82 static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { ··· 121 116 .name = "i2c-gpio", 122 117 .id = 0, 123 118 .dev = { 124 - .platform_data = &nslu2_i2c_gpio_data, 119 + .platform_data = NULL, 125 120 }, 126 121 }; 127 122 ··· 256 251 nslu2_flash_resource.end = 257 252 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 258 253 254 + gpiod_add_lookup_table(&nslu2_i2c_gpiod_table); 259 255 i2c_register_board_info(0, nslu2_i2c_board_info, 260 256 ARRAY_SIZE(nslu2_i2c_board_info)); 261 257
+12 -3
arch/arm/mach-ks8695/board-acs5k.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/init.h> 18 18 #include <linux/platform_device.h> 19 - 19 + #include <linux/gpio/machine.h> 20 20 #include <linux/i2c.h> 21 21 #include <linux/i2c-algo-bit.h> 22 22 #include <linux/i2c-gpio.h> ··· 38 38 39 39 #include "generic.h" 40 40 41 + static struct gpiod_lookup_table acs5k_i2c_gpiod_table = { 42 + .dev_id = "i2c-gpio", 43 + .table = { 44 + GPIO_LOOKUP_IDX("KS8695", 4, NULL, 0, 45 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 46 + GPIO_LOOKUP_IDX("KS8695", 5, NULL, 1, 47 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 48 + }, 49 + }; 50 + 41 51 static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { 42 - .sda_pin = 4, 43 - .scl_pin = 5, 44 52 .udelay = 10, 45 53 }; 46 54 ··· 103 95 static void acs5k_i2c_init(void) 104 96 { 105 97 /* The gpio interface */ 98 + gpiod_add_lookup_table(&acs5k_i2c_gpiod_table); 106 99 platform_device_register(&acs5k_i2c_device); 107 100 /* I2C devices */ 108 101 i2c_register_board_info(0, acs5k_i2c_devs,
+12 -2
arch/arm/mach-pxa/palmz72.c
··· 31 31 #include <linux/power_supply.h> 32 32 #include <linux/usb/gpio_vbus.h> 33 33 #include <linux/i2c-gpio.h> 34 + #include <linux/gpio/machine.h> 34 35 35 36 #include <asm/mach-types.h> 36 37 #include <asm/suspend.h> ··· 321 320 .flags = SOCAM_DATAWIDTH_8, 322 321 }; 323 322 323 + static struct gpiod_lookup_table palmz72_i2c_gpiod_table = { 324 + .dev_id = "i2c-gpio", 325 + .table = { 326 + GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0, 327 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 328 + GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1, 329 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 330 + }, 331 + }; 332 + 324 333 static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { 325 - .sda_pin = 118, 326 - .scl_pin = 117, 327 334 .udelay = 10, 328 335 .timeout = 100, 329 336 }; ··· 378 369 { 379 370 palmz72_cam_gpio_init(); 380 371 pxa_set_camera_info(&palmz72_pxacamera_platform_data); 372 + gpiod_add_lookup_table(&palmz72_i2c_gpiod_table); 381 373 platform_device_register(&palmz72_i2c_bus_device); 382 374 platform_device_register(&palmz72_camera); 383 375 }
+23 -4
arch/arm/mach-pxa/viper.c
··· 36 36 #include <linux/gpio.h> 37 37 #include <linux/jiffies.h> 38 38 #include <linux/i2c-gpio.h> 39 + #include <linux/gpio/machine.h> 39 40 #include <linux/i2c/pxa-i2c.h> 40 41 #include <linux/serial_8250.h> 41 42 #include <linux/smc91x.h> ··· 459 458 }; 460 459 461 460 /* i2c */ 461 + static struct gpiod_lookup_table viper_i2c_gpiod_table = { 462 + .dev_id = "i2c-gpio", 463 + .table = { 464 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO, 465 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 466 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO, 467 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 468 + }, 469 + }; 470 + 462 471 static struct i2c_gpio_platform_data i2c_bus_data = { 463 - .sda_pin = VIPER_RTC_I2C_SDA_GPIO, 464 - .scl_pin = VIPER_RTC_I2C_SCL_GPIO, 465 472 .udelay = 10, 466 473 .timeout = HZ, 467 474 }; ··· 788 779 789 780 __setup("tpm=", viper_tpm_setup); 790 781 782 + struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = { 783 + .dev_id = "i2c-gpio", 784 + .table = { 785 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO, 786 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 787 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO, 788 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 789 + }, 790 + }; 791 + 791 792 static void __init viper_tpm_init(void) 792 793 { 793 794 struct platform_device *tpm_device; 794 795 struct i2c_gpio_platform_data i2c_tpm_data = { 795 - .sda_pin = VIPER_TPM_I2C_SDA_GPIO, 796 - .scl_pin = VIPER_TPM_I2C_SCL_GPIO, 797 796 .udelay = 10, 798 797 .timeout = HZ, 799 798 }; ··· 811 794 if (!viper_tpm) 812 795 return; 813 796 797 + gpiod_add_lookup_table(&viper_tpm_i2c_gpiod_table); 814 798 tpm_device = platform_device_alloc("i2c-gpio", 2); 815 799 if (tpm_device) { 816 800 if (!platform_device_add_data(tpm_device, ··· 961 943 smc91x_device.num_resources--; 962 944 963 945 pxa_set_i2c_info(NULL); 946 + gpiod_add_lookup_table(&viper_i2c_gpiod_table); 964 947 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup)); 965 948 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs)); 966 949
+12 -2
arch/arm/mach-sa1100/simpad.c
··· 17 17 #include <linux/mtd/partitions.h> 18 18 #include <linux/io.h> 19 19 #include <linux/gpio/driver.h> 20 + #include <linux/gpio/machine.h> 20 21 21 22 #include <mach/hardware.h> 22 23 #include <asm/setup.h> ··· 325 324 /* 326 325 * i2c 327 326 */ 327 + static struct gpiod_lookup_table simpad_i2c_gpiod_table = { 328 + .dev_id = "i2c-gpio", 329 + .table = { 330 + GPIO_LOOKUP_IDX("gpio", 21, NULL, 0, 331 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 332 + GPIO_LOOKUP_IDX("gpio", 25, NULL, 1, 333 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 334 + }, 335 + }; 336 + 328 337 static struct i2c_gpio_platform_data simpad_i2c_data = { 329 - .sda_pin = GPIO_GPIO21, 330 - .scl_pin = GPIO_GPIO25, 331 338 .udelay = 10, 332 339 .timeout = HZ, 333 340 }; ··· 390 381 ARRAY_SIZE(simpad_flash_resources)); 391 382 sa11x0_register_mcp(&simpad_mcp_data); 392 383 384 + gpiod_add_lookup_table(&simpad_i2c_gpiod_table); 393 385 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 394 386 if(ret) 395 387 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
+14 -5
arch/blackfin/mach-bf533/boards/blackstamp.c
··· 22 22 #include <linux/irq.h> 23 23 #include <linux/gpio.h> 24 24 #include <linux/i2c.h> 25 + #include <linux/gpio/machine.h> 25 26 #include <asm/dma.h> 26 27 #include <asm/bfin5xx_spi.h> 27 28 #include <asm/portmux.h> ··· 363 362 #if IS_ENABLED(CONFIG_I2C_GPIO) 364 363 #include <linux/i2c-gpio.h> 365 364 365 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 366 + .dev_id = "i2c-gpio", 367 + .table = { 368 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF8, NULL, 0, 369 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 370 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF9, NULL, 1, 371 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 372 + }, 373 + }; 374 + 366 375 static struct i2c_gpio_platform_data i2c_gpio_data = { 367 - .sda_pin = GPIO_PF8, 368 - .scl_pin = GPIO_PF9, 369 - .sda_is_open_drain = 0, 370 - .scl_is_open_drain = 0, 371 376 .udelay = 40, 372 377 }; /* This hasn't actually been used these pins 373 378 * are (currently) free pins on the expansion connector */ ··· 469 462 int ret; 470 463 471 464 printk(KERN_INFO "%s(): registering device resources\n", __func__); 472 - 465 + #if IS_ENABLED(CONFIG_I2C_GPIO) 466 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 467 + #endif 473 468 i2c_register_board_info(0, bfin_i2c_board_info, 474 469 ARRAY_SIZE(bfin_i2c_board_info)); 475 470
+14 -4
arch/blackfin/mach-bf533/boards/ezkit.c
··· 19 19 #endif 20 20 #include <linux/irq.h> 21 21 #include <linux/i2c.h> 22 + #include <linux/gpio/machine.h> 22 23 #include <asm/dma.h> 23 24 #include <asm/bfin5xx_spi.h> 24 25 #include <asm/portmux.h> ··· 391 390 #if IS_ENABLED(CONFIG_I2C_GPIO) 392 391 #include <linux/i2c-gpio.h> 393 392 393 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 394 + .dev_id = "i2c-gpio", 395 + .table = { 396 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0, 397 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 398 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, 399 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 400 + }, 401 + }; 402 + 394 403 static struct i2c_gpio_platform_data i2c_gpio_data = { 395 - .sda_pin = GPIO_PF1, 396 - .scl_pin = GPIO_PF0, 397 - .sda_is_open_drain = 0, 398 - .scl_is_open_drain = 0, 399 404 .udelay = 40, 400 405 }; 401 406 ··· 523 516 static int __init ezkit_init(void) 524 517 { 525 518 printk(KERN_INFO "%s(): registering device resources\n", __func__); 519 + #if IS_ENABLED(CONFIG_I2C_GPIO) 520 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 521 + #endif 526 522 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 527 523 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 528 524 i2c_register_board_info(0, bfin_i2c_board_info,
+14 -4
arch/blackfin/mach-bf533/boards/stamp.c
··· 21 21 #include <linux/gpio.h> 22 22 #include <linux/irq.h> 23 23 #include <linux/i2c.h> 24 + #include <linux/gpio/machine.h> 24 25 #include <asm/dma.h> 25 26 #include <asm/bfin5xx_spi.h> 26 27 #include <asm/reboot.h> ··· 513 512 #if IS_ENABLED(CONFIG_I2C_GPIO) 514 513 #include <linux/i2c-gpio.h> 515 514 515 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 516 + .dev_id = "i2c-gpio", 517 + .table = { 518 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF2, NULL, 0, 519 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 520 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1, 521 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 522 + }, 523 + }; 524 + 516 525 static struct i2c_gpio_platform_data i2c_gpio_data = { 517 - .sda_pin = GPIO_PF2, 518 - .scl_pin = GPIO_PF3, 519 - .sda_is_open_drain = 0, 520 - .scl_is_open_drain = 0, 521 526 .udelay = 10, 522 527 }; 523 528 ··· 855 848 856 849 printk(KERN_INFO "%s(): registering device resources\n", __func__); 857 850 851 + #if IS_ENABLED(CONFIG_I2C_GPIO) 852 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 853 + #endif 858 854 i2c_register_board_info(0, bfin_i2c_board_info, 859 855 ARRAY_SIZE(bfin_i2c_board_info)); 860 856
+14 -4
arch/blackfin/mach-bf561/boards/ezkit.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/gpio.h> 18 18 #include <linux/delay.h> 19 + #include <linux/gpio/machine.h> 19 20 #include <asm/dma.h> 20 21 #include <asm/bfin5xx_spi.h> 21 22 #include <asm/portmux.h> ··· 380 379 #if IS_ENABLED(CONFIG_I2C_GPIO) 381 380 #include <linux/i2c-gpio.h> 382 381 382 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 383 + .dev_id = "i2c-gpio", 384 + .table = { 385 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0, 386 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 387 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, 388 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 389 + }, 390 + }; 391 + 383 392 static struct i2c_gpio_platform_data i2c_gpio_data = { 384 - .sda_pin = GPIO_PF1, 385 - .scl_pin = GPIO_PF0, 386 - .sda_is_open_drain = 0, 387 - .scl_is_open_drain = 0, 388 393 .udelay = 10, 389 394 }; 390 395 ··· 640 633 641 634 printk(KERN_INFO "%s(): registering device resources\n", __func__); 642 635 636 + #if IS_ENABLED(CONFIG_I2C_GPIO) 637 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 638 + #endif 643 639 ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 644 640 if (ret < 0) 645 641 return ret;
+21 -2
arch/mips/alchemy/board-gpr.c
··· 30 30 #include <linux/gpio.h> 31 31 #include <linux/i2c.h> 32 32 #include <linux/i2c-gpio.h> 33 + #include <linux/gpio/machine.h> 33 34 #include <asm/bootinfo.h> 34 35 #include <asm/idle.h> 35 36 #include <asm/reboot.h> ··· 219 218 /* 220 219 * I2C 221 220 */ 221 + static struct gpiod_lookup_table gpr_i2c_gpiod_table = { 222 + .dev_id = "i2c-gpio", 223 + .table = { 224 + /* 225 + * This should be on "GPIO2" which has base at 200 so 226 + * the global numbers 209 and 210 should correspond to 227 + * local offsets 9 and 10. 228 + */ 229 + GPIO_LOOKUP_IDX("alchemy-gpio2", 9, NULL, 0, 230 + GPIO_ACTIVE_HIGH), 231 + GPIO_LOOKUP_IDX("alchemy-gpio2", 10, NULL, 1, 232 + GPIO_ACTIVE_HIGH), 233 + }, 234 + }; 235 + 222 236 static struct i2c_gpio_platform_data gpr_i2c_data = { 223 - .sda_pin = 209, 237 + /* 238 + * The open drain mode is hardwired somewhere or an electrical 239 + * property of the alchemy GPIO controller. 240 + */ 224 241 .sda_is_open_drain = 1, 225 - .scl_pin = 210, 226 242 .scl_is_open_drain = 1, 227 243 .udelay = 2, /* ~100 kHz */ 228 244 .timeout = HZ, ··· 313 295 314 296 static int __init gpr_dev_init(void) 315 297 { 298 + gpiod_add_lookup_table(&gpr_i2c_gpiod_table); 316 299 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); 317 300 318 301 return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
+11 -5
arch/mips/ath79/mach-pb44.c
··· 11 11 #include <linux/init.h> 12 12 #include <linux/platform_device.h> 13 13 #include <linux/i2c.h> 14 - #include <linux/i2c-gpio.h> 14 + #include <linux/gpio/machine.h> 15 15 #include <linux/platform_data/pcf857x.h> 16 16 17 17 #include "machtypes.h" ··· 33 33 #define PB44_KEYS_POLL_INTERVAL 20 /* msecs */ 34 34 #define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL) 35 35 36 - static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 37 - .sda_pin = PB44_GPIO_I2C_SDA, 38 - .scl_pin = PB44_GPIO_I2C_SCL, 36 + static struct gpiod_lookup_table pb44_i2c_gpiod_table = { 37 + .dev_id = "i2c-gpio", 38 + .table = { 39 + GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SDA, 40 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 41 + GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SCL, 42 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 43 + }, 39 44 }; 40 45 41 46 static struct platform_device pb44_i2c_gpio_device = { 42 47 .name = "i2c-gpio", 43 48 .id = 0, 44 49 .dev = { 45 - .platform_data = &pb44_i2c_gpio_data, 50 + .platform_data = NULL, 46 51 } 47 52 }; 48 53 ··· 108 103 109 104 static void __init pb44_init(void) 110 105 { 106 + gpiod_add_lookup_table(&pb44_i2c_gpiod_table); 111 107 i2c_register_board_info(0, pb44_i2c_board_info, 112 108 ARRAY_SIZE(pb44_i2c_board_info)); 113 109 platform_device_register(&pb44_i2c_gpio_device);
+5
drivers/acpi/acpi_apd.c
··· 116 116 .setup = acpi_apd_setup, 117 117 .fixed_clk_rate = 250000000, 118 118 }; 119 + static const struct apd_device_desc thunderx2_i2c_desc = { 120 + .setup = acpi_apd_setup, 121 + .fixed_clk_rate = 125000000, 122 + }; 119 123 #endif 120 124 121 125 #else ··· 184 180 { "APMC0D0F", APD_ADDR(xgene_i2c_desc) }, 185 181 { "BRCM900D", APD_ADDR(vulcan_spi_desc) }, 186 182 { "CAV900D", APD_ADDR(vulcan_spi_desc) }, 183 + { "CAV9007", APD_ADDR(thunderx2_i2c_desc) }, 187 184 { "HISI02A1", APD_ADDR(hip07_i2c_desc) }, 188 185 { "HISI02A2", APD_ADDR(hip08_i2c_desc) }, 189 186 #endif
+13
drivers/gpio/gpiolib.c
··· 3528 3528 3529 3529 if (lflags & GPIO_ACTIVE_LOW) 3530 3530 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 3531 + 3531 3532 if (lflags & GPIO_OPEN_DRAIN) 3532 3533 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 3534 + else if (dflags & GPIOD_FLAGS_BIT_OPEN_DRAIN) { 3535 + /* 3536 + * This enforces open drain mode from the consumer side. 3537 + * This is necessary for some busses like I2C, but the lookup 3538 + * should *REALLY* have specified them as open drain in the 3539 + * first place, so print a little warning here. 3540 + */ 3541 + set_bit(FLAG_OPEN_DRAIN, &desc->flags); 3542 + gpiod_warn(desc, 3543 + "enforced open drain please flag it properly in DT/ACPI DSDT/board file\n"); 3544 + } 3545 + 3533 3546 if (lflags & GPIO_OPEN_SOURCE) 3534 3547 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 3535 3548 if (lflags & GPIO_SLEEP_MAY_LOSE_VALUE)
+5
drivers/i2c/busses/Kconfig
··· 198 198 SMBus controller found in the Intel Cherry Trail Whiskey Cove PMIC 199 199 found on some Intel Cherry Trail systems. 200 200 201 + Note this controller is hooked up to a TI bq24292i charger-IC, 202 + combined with a FUSB302 Type-C port-controller as such it is advised 203 + to also select CONFIG_CHARGER_BQ24190=m and CONFIG_TYPEC_FUSB302=m 204 + (the fusb302 driver currently is in drivers/staging). 205 + 201 206 config I2C_NFORCE2 202 207 tristate "Nvidia nForce2, nForce3 and nForce4" 203 208 depends on PCI
+12
drivers/i2c/busses/i2c-aspeed.c
··· 27 27 #include <linux/of_irq.h> 28 28 #include <linux/of_platform.h> 29 29 #include <linux/platform_device.h> 30 + #include <linux/reset.h> 30 31 #include <linux/slab.h> 31 32 32 33 /* I2C Register */ ··· 133 132 struct i2c_adapter adap; 134 133 struct device *dev; 135 134 void __iomem *base; 135 + struct reset_control *rst; 136 136 /* Synchronizes I/O mem access to base. */ 137 137 spinlock_t lock; 138 138 struct completion cmd_complete; ··· 849 847 /* We just need the clock rate, we don't actually use the clk object. */ 850 848 devm_clk_put(&pdev->dev, parent_clk); 851 849 850 + bus->rst = devm_reset_control_get_shared(&pdev->dev, NULL); 851 + if (IS_ERR(bus->rst)) { 852 + dev_err(&pdev->dev, 853 + "missing or invalid reset controller device tree entry"); 854 + return PTR_ERR(bus->rst); 855 + } 856 + reset_control_deassert(bus->rst); 857 + 852 858 ret = of_property_read_u32(pdev->dev.of_node, 853 859 "bus-frequency", &bus->bus_frequency); 854 860 if (ret < 0) { ··· 926 916 writel(0, bus->base + ASPEED_I2C_INTR_CTRL_REG); 927 917 928 918 spin_unlock_irqrestore(&bus->lock, flags); 919 + 920 + reset_control_assert(bus->rst); 929 921 930 922 i2c_del_adapter(&bus->adap); 931 923
+44 -7
drivers/i2c/busses/i2c-cht-wc.c
··· 16 16 * GNU General Public License for more details. 17 17 */ 18 18 19 + #include <linux/acpi.h> 19 20 #include <linux/completion.h> 20 21 #include <linux/delay.h> 21 22 #include <linux/i2c.h> ··· 26 25 #include <linux/mfd/intel_soc_pmic.h> 27 26 #include <linux/module.h> 28 27 #include <linux/platform_device.h> 28 + #include <linux/power/bq24190_charger.h> 29 29 #include <linux/slab.h> 30 30 31 31 #define CHT_WC_I2C_CTRL 0x5e24 ··· 234 232 .name = "cht_wc_ext_chrg_irq_chip", 235 233 }; 236 234 235 + static const char * const bq24190_suppliers[] = { "fusb302-typec-source" }; 236 + 237 237 static const struct property_entry bq24190_props[] = { 238 - PROPERTY_ENTRY_STRING("extcon-name", "cht_wcove_pwrsrc"), 238 + PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_suppliers), 239 239 PROPERTY_ENTRY_BOOL("omit-battery-class"), 240 240 PROPERTY_ENTRY_BOOL("disable-reset"), 241 241 { } 242 + }; 243 + 244 + static struct regulator_consumer_supply fusb302_consumer = { 245 + .supply = "vbus", 246 + /* Must match fusb302 dev_name in intel_cht_int33fe.c */ 247 + .dev_name = "i2c-fusb302", 248 + }; 249 + 250 + static const struct regulator_init_data bq24190_vbus_init_data = { 251 + .constraints = { 252 + /* The name is used in intel_cht_int33fe.c do not change. */ 253 + .name = "cht_wc_usb_typec_vbus", 254 + .valid_ops_mask = REGULATOR_CHANGE_STATUS, 255 + }, 256 + .consumer_supplies = &fusb302_consumer, 257 + .num_consumer_supplies = 1, 258 + }; 259 + 260 + static struct bq24190_platform_data bq24190_pdata = { 261 + .regulator_init_data = &bq24190_vbus_init_data, 242 262 }; 243 263 244 264 static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) ··· 270 246 struct i2c_board_info board_info = { 271 247 .type = "bq24190", 272 248 .addr = 0x6b, 249 + .dev_name = "bq24190", 273 250 .properties = bq24190_props, 251 + .platform_data = &bq24190_pdata, 274 252 }; 275 253 int ret, reg, irq; 276 254 ··· 340 314 if (ret) 341 315 goto remove_irq_domain; 342 316 343 - board_info.irq = adap->client_irq; 344 - adap->client = i2c_new_device(&adap->adapter, &board_info); 345 - if (!adap->client) { 346 - ret = -ENOMEM; 347 - goto del_adapter; 317 + /* 318 + * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger, 319 + * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302 320 + * USB Type-C controller connected to another i2c bus. In this setup 321 + * the max17047 and fusb302 devices are enumerated through an INT33FE 322 + * ACPI device. If this device is present register an i2c-client for 323 + * the TI bq24292i charger. 324 + */ 325 + if (acpi_dev_present("INT33FE", NULL, -1)) { 326 + board_info.irq = adap->client_irq; 327 + adap->client = i2c_new_device(&adap->adapter, &board_info); 328 + if (!adap->client) { 329 + ret = -ENOMEM; 330 + goto del_adapter; 331 + } 348 332 } 349 333 350 334 platform_set_drvdata(pdev, adap); ··· 371 335 { 372 336 struct cht_wc_i2c_adap *adap = platform_get_drvdata(pdev); 373 337 374 - i2c_unregister_device(adap->client); 338 + if (adap->client) 339 + i2c_unregister_device(adap->client); 375 340 i2c_del_adapter(&adap->adapter); 376 341 irq_domain_remove(adap->irq_domain); 377 342
+56 -13
drivers/i2c/busses/i2c-davinci.c
··· 36 36 #include <linux/gpio.h> 37 37 #include <linux/of_device.h> 38 38 #include <linux/platform_data/i2c-davinci.h> 39 + #include <linux/pm_runtime.h> 39 40 40 41 /* ----- global defines ----------------------------------------------- */ 41 42 ··· 122 121 #define DAVINCI_I2C_DCLR_PDCLR0 BIT(0) 123 122 /* set the SDA GPIO low */ 124 123 #define DAVINCI_I2C_DCLR_PDCLR1 BIT(1) 124 + 125 + /* timeout for pm runtime autosuspend */ 126 + #define DAVINCI_I2C_PM_TIMEOUT 1000 /* ms */ 125 127 126 128 struct davinci_i2c_dev { 127 129 struct device *dev; ··· 504 500 /* This should be 0 if all bytes were transferred 505 501 * or dev->cmd_err denotes an error. 506 502 */ 507 - dev_err(dev->dev, "abnormal termination buf_len=%i\n", 503 + dev_err(dev->dev, "abnormal termination buf_len=%zu\n", 508 504 dev->buf_len); 509 505 dev->terminate = 1; 510 506 wmb(); ··· 545 541 546 542 dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); 547 543 544 + ret = pm_runtime_get_sync(dev->dev); 545 + if (ret < 0) { 546 + dev_err(dev->dev, "Failed to runtime_get device: %d\n", ret); 547 + pm_runtime_put_noidle(dev->dev); 548 + return ret; 549 + } 550 + 548 551 ret = i2c_davinci_wait_bus_not_busy(dev); 549 552 if (ret < 0) { 550 553 dev_warn(dev->dev, "timeout waiting for bus ready\n"); 551 - return ret; 554 + goto out; 552 555 } 553 556 554 557 for (i = 0; i < num; i++) { ··· 563 552 dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num, 564 553 ret); 565 554 if (ret < 0) 566 - return ret; 555 + goto out; 567 556 } 568 557 558 + ret = num; 569 559 #ifdef CONFIG_CPU_FREQ 570 560 complete(&dev->xfr_complete); 571 561 #endif 572 562 573 - return num; 563 + out: 564 + pm_runtime_mark_last_busy(dev->dev); 565 + pm_runtime_put_autosuspend(dev->dev); 566 + 567 + return ret; 574 568 } 575 569 576 570 static u32 i2c_davinci_func(struct i2c_adapter *adap) ··· 614 598 u32 stat; 615 599 int count = 0; 616 600 u16 w; 601 + 602 + if (pm_runtime_suspended(dev->dev)) 603 + return IRQ_NONE; 617 604 618 605 while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) { 619 606 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); ··· 821 802 dev->clk = devm_clk_get(&pdev->dev, NULL); 822 803 if (IS_ERR(dev->clk)) 823 804 return PTR_ERR(dev->clk); 824 - clk_prepare_enable(dev->clk); 825 805 826 806 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 827 807 dev->base = devm_ioremap_resource(&pdev->dev, mem); 828 808 if (IS_ERR(dev->base)) { 829 - r = PTR_ERR(dev->base); 830 - goto err_unuse_clocks; 809 + return PTR_ERR(dev->base); 810 + } 811 + 812 + pm_runtime_set_autosuspend_delay(dev->dev, 813 + DAVINCI_I2C_PM_TIMEOUT); 814 + pm_runtime_use_autosuspend(dev->dev); 815 + 816 + pm_runtime_enable(dev->dev); 817 + 818 + r = pm_runtime_get_sync(dev->dev); 819 + if (r < 0) { 820 + dev_err(dev->dev, "failed to runtime_get device: %d\n", r); 821 + pm_runtime_put_noidle(dev->dev); 822 + return r; 831 823 } 832 824 833 825 i2c_davinci_init(dev); ··· 879 849 if (r) 880 850 goto err_unuse_clocks; 881 851 852 + pm_runtime_mark_last_busy(dev->dev); 853 + pm_runtime_put_autosuspend(dev->dev); 854 + 882 855 return 0; 883 856 884 857 err_unuse_clocks: 885 - clk_disable_unprepare(dev->clk); 886 - dev->clk = NULL; 858 + pm_runtime_dont_use_autosuspend(dev->dev); 859 + pm_runtime_put_sync(dev->dev); 860 + pm_runtime_disable(dev->dev); 861 + 887 862 return r; 888 863 } 889 864 890 865 static int davinci_i2c_remove(struct platform_device *pdev) 891 866 { 892 867 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); 868 + int ret; 893 869 894 870 i2c_davinci_cpufreq_deregister(dev); 895 871 896 872 i2c_del_adapter(&dev->adapter); 897 873 898 - clk_disable_unprepare(dev->clk); 899 - dev->clk = NULL; 874 + ret = pm_runtime_get_sync(&pdev->dev); 875 + if (ret < 0) { 876 + pm_runtime_put_noidle(&pdev->dev); 877 + return ret; 878 + } 900 879 901 880 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); 881 + 882 + pm_runtime_dont_use_autosuspend(dev->dev); 883 + pm_runtime_put_sync(dev->dev); 884 + pm_runtime_disable(dev->dev); 902 885 903 886 return 0; 904 887 } ··· 923 880 924 881 /* put I2C into reset */ 925 882 davinci_i2c_reset_ctrl(i2c_dev, 0); 926 - clk_disable_unprepare(i2c_dev->clk); 927 883 928 884 return 0; 929 885 } ··· 931 889 { 932 890 struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev); 933 891 934 - clk_prepare_enable(i2c_dev->clk); 935 892 /* take I2C out of reset */ 936 893 davinci_i2c_reset_ctrl(i2c_dev, 1); 937 894 ··· 940 899 static const struct dev_pm_ops davinci_i2c_pm = { 941 900 .suspend = davinci_i2c_suspend, 942 901 .resume = davinci_i2c_resume, 902 + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 903 + pm_runtime_force_resume) 943 904 }; 944 905 945 906 #define davinci_i2c_pm_ops (&davinci_i2c_pm)
+2
drivers/i2c/busses/i2c-designware-core.h
··· 280 280 int (*acquire_lock)(struct dw_i2c_dev *dev); 281 281 void (*release_lock)(struct dw_i2c_dev *dev); 282 282 bool pm_disabled; 283 + bool suspended; 284 + bool skip_resume; 283 285 void (*disable)(struct dw_i2c_dev *dev); 284 286 void (*disable_int)(struct dw_i2c_dev *dev); 285 287 int (*init)(struct dw_i2c_dev *dev);
+45 -26
drivers/i2c/busses/i2c-designware-platdrv.c
··· 249 249 } 250 250 } 251 251 252 + static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) 253 + { 254 + pm_runtime_disable(dev->dev); 255 + 256 + if (dev->pm_disabled) 257 + pm_runtime_put_noidle(dev->dev); 258 + } 259 + 252 260 static int dw_i2c_plat_probe(struct platform_device *pdev) 253 261 { 254 262 struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); ··· 265 257 u32 acpi_speed, ht = 0; 266 258 struct resource *mem; 267 259 int i, irq, ret; 268 - const int supported_speeds[] = { 0, 100000, 400000, 1000000, 3400000 }; 260 + static const int supported_speeds[] = { 261 + 0, 100000, 400000, 1000000, 3400000 262 + }; 269 263 270 264 irq = platform_get_irq(pdev, 0); 271 265 if (irq < 0) ··· 372 362 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 373 363 adap->dev.of_node = pdev->dev.of_node; 374 364 375 - if (dev->pm_disabled) { 376 - pm_runtime_forbid(&pdev->dev); 377 - } else { 378 - pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 379 - pm_runtime_use_autosuspend(&pdev->dev); 380 - pm_runtime_set_active(&pdev->dev); 381 - pm_runtime_enable(&pdev->dev); 382 - } 365 + /* The code below assumes runtime PM to be disabled. */ 366 + WARN_ON(pm_runtime_enabled(&pdev->dev)); 367 + 368 + pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 369 + pm_runtime_use_autosuspend(&pdev->dev); 370 + pm_runtime_set_active(&pdev->dev); 371 + 372 + if (dev->pm_disabled) 373 + pm_runtime_get_noresume(&pdev->dev); 374 + 375 + pm_runtime_enable(&pdev->dev); 383 376 384 377 if (dev->mode == DW_IC_SLAVE) 385 378 ret = i2c_dw_probe_slave(dev); ··· 395 382 return ret; 396 383 397 384 exit_probe: 398 - if (!dev->pm_disabled) 399 - pm_runtime_disable(&pdev->dev); 385 + dw_i2c_plat_pm_cleanup(dev); 400 386 exit_reset: 401 387 if (!IS_ERR_OR_NULL(dev->rst)) 402 388 reset_control_assert(dev->rst); ··· 414 402 415 403 pm_runtime_dont_use_autosuspend(&pdev->dev); 416 404 pm_runtime_put_sync(&pdev->dev); 417 - if (!dev->pm_disabled) 418 - pm_runtime_disable(&pdev->dev); 405 + dw_i2c_plat_pm_cleanup(dev); 406 + 419 407 if (!IS_ERR_OR_NULL(dev->rst)) 420 408 reset_control_assert(dev->rst); 421 409 ··· 449 437 #endif 450 438 451 439 #ifdef CONFIG_PM 452 - static int dw_i2c_plat_runtime_suspend(struct device *dev) 440 + static int dw_i2c_plat_suspend(struct device *dev) 453 441 { 454 442 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 455 443 444 + if (i_dev->suspended) { 445 + i_dev->skip_resume = true; 446 + return 0; 447 + } 448 + 456 449 i_dev->disable(i_dev); 457 450 i2c_dw_plat_prepare_clk(i_dev, false); 451 + 452 + i_dev->suspended = true; 458 453 459 454 return 0; 460 455 } ··· 470 451 { 471 452 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 472 453 454 + if (!i_dev->suspended) 455 + return 0; 456 + 457 + if (i_dev->skip_resume) { 458 + i_dev->skip_resume = false; 459 + return 0; 460 + } 461 + 473 462 i2c_dw_plat_prepare_clk(i_dev, true); 474 463 i_dev->init(i_dev); 464 + 465 + i_dev->suspended = false; 475 466 476 467 return 0; 477 468 } 478 469 479 - #ifdef CONFIG_PM_SLEEP 480 - static int dw_i2c_plat_suspend(struct device *dev) 481 - { 482 - pm_runtime_resume(dev); 483 - return dw_i2c_plat_runtime_suspend(dev); 484 - } 485 - #endif 486 - 487 470 static const struct dev_pm_ops dw_i2c_dev_pm_ops = { 488 471 .prepare = dw_i2c_plat_prepare, 489 472 .complete = dw_i2c_plat_complete, 490 - SET_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) 491 - SET_RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, 492 - dw_i2c_plat_resume, 493 - NULL) 473 + SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) 474 + SET_RUNTIME_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume, NULL) 494 475 }; 495 476 496 477 #define DW_I2C_DEV_PMOPS (&dw_i2c_dev_pm_ops)
+104 -108
drivers/i2c/busses/i2c-gpio.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/platform_device.h> 17 - #include <linux/gpio.h> 17 + #include <linux/gpio/consumer.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_gpio.h> 20 19 21 20 struct i2c_gpio_private_data { 21 + struct gpio_desc *sda; 22 + struct gpio_desc *scl; 22 23 struct i2c_adapter adap; 23 24 struct i2c_algo_bit_data bit_data; 24 25 struct i2c_gpio_platform_data pdata; 25 26 }; 26 - 27 - /* Toggle SDA by changing the direction of the pin */ 28 - static void i2c_gpio_setsda_dir(void *data, int state) 29 - { 30 - struct i2c_gpio_platform_data *pdata = data; 31 - 32 - if (state) 33 - gpio_direction_input(pdata->sda_pin); 34 - else 35 - gpio_direction_output(pdata->sda_pin, 0); 36 - } 37 27 38 28 /* 39 29 * Toggle SDA by changing the output value of the pin. This is only ··· 32 42 */ 33 43 static void i2c_gpio_setsda_val(void *data, int state) 34 44 { 35 - struct i2c_gpio_platform_data *pdata = data; 45 + struct i2c_gpio_private_data *priv = data; 36 46 37 - gpio_set_value(pdata->sda_pin, state); 38 - } 39 - 40 - /* Toggle SCL by changing the direction of the pin. */ 41 - static void i2c_gpio_setscl_dir(void *data, int state) 42 - { 43 - struct i2c_gpio_platform_data *pdata = data; 44 - 45 - if (state) 46 - gpio_direction_input(pdata->scl_pin); 47 - else 48 - gpio_direction_output(pdata->scl_pin, 0); 47 + gpiod_set_value(priv->sda, state); 49 48 } 50 49 51 50 /* ··· 45 66 */ 46 67 static void i2c_gpio_setscl_val(void *data, int state) 47 68 { 48 - struct i2c_gpio_platform_data *pdata = data; 69 + struct i2c_gpio_private_data *priv = data; 49 70 50 - gpio_set_value(pdata->scl_pin, state); 71 + gpiod_set_value(priv->scl, state); 51 72 } 52 73 53 74 static int i2c_gpio_getsda(void *data) 54 75 { 55 - struct i2c_gpio_platform_data *pdata = data; 76 + struct i2c_gpio_private_data *priv = data; 56 77 57 - return gpio_get_value(pdata->sda_pin); 78 + return gpiod_get_value(priv->sda); 58 79 } 59 80 60 81 static int i2c_gpio_getscl(void *data) 61 82 { 62 - struct i2c_gpio_platform_data *pdata = data; 83 + struct i2c_gpio_private_data *priv = data; 63 84 64 - return gpio_get_value(pdata->scl_pin); 65 - } 66 - 67 - static int of_i2c_gpio_get_pins(struct device_node *np, 68 - unsigned int *sda_pin, unsigned int *scl_pin) 69 - { 70 - if (of_gpio_count(np) < 2) 71 - return -ENODEV; 72 - 73 - *sda_pin = of_get_gpio(np, 0); 74 - *scl_pin = of_get_gpio(np, 1); 75 - 76 - if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER) 77 - return -EPROBE_DEFER; 78 - 79 - if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { 80 - pr_err("%pOF: invalid GPIO pins, sda=%d/scl=%d\n", 81 - np, *sda_pin, *scl_pin); 82 - return -ENODEV; 83 - } 84 - 85 - return 0; 85 + return gpiod_get_value(priv->scl); 86 86 } 87 87 88 88 static void of_i2c_gpio_get_props(struct device_node *np, ··· 82 124 of_property_read_bool(np, "i2c-gpio,scl-output-only"); 83 125 } 84 126 127 + static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, 128 + const char *con_id, 129 + unsigned int index, 130 + enum gpiod_flags gflags) 131 + { 132 + struct gpio_desc *retdesc; 133 + int ret; 134 + 135 + retdesc = devm_gpiod_get(dev, con_id, gflags); 136 + if (!IS_ERR(retdesc)) { 137 + dev_dbg(dev, "got GPIO from name %s\n", con_id); 138 + return retdesc; 139 + } 140 + 141 + retdesc = devm_gpiod_get_index(dev, NULL, index, gflags); 142 + if (!IS_ERR(retdesc)) { 143 + dev_dbg(dev, "got GPIO from index %u\n", index); 144 + return retdesc; 145 + } 146 + 147 + ret = PTR_ERR(retdesc); 148 + 149 + /* FIXME: hack in the old code, is this really necessary? */ 150 + if (ret == -EINVAL) 151 + retdesc = ERR_PTR(-EPROBE_DEFER); 152 + 153 + /* This happens if the GPIO driver is not yet probed, let's defer */ 154 + if (ret == -ENOENT) 155 + retdesc = ERR_PTR(-EPROBE_DEFER); 156 + 157 + if (ret != -EPROBE_DEFER) 158 + dev_err(dev, "error trying to get descriptor: %d\n", ret); 159 + 160 + return retdesc; 161 + } 162 + 85 163 static int i2c_gpio_probe(struct platform_device *pdev) 86 164 { 87 165 struct i2c_gpio_private_data *priv; 88 166 struct i2c_gpio_platform_data *pdata; 89 167 struct i2c_algo_bit_data *bit_data; 90 168 struct i2c_adapter *adap; 91 - unsigned int sda_pin, scl_pin; 169 + struct device *dev = &pdev->dev; 170 + struct device_node *np = dev->of_node; 171 + enum gpiod_flags gflags; 92 172 int ret; 93 173 94 - /* First get the GPIO pins; if it fails, we'll defer the probe. */ 95 - if (pdev->dev.of_node) { 96 - ret = of_i2c_gpio_get_pins(pdev->dev.of_node, 97 - &sda_pin, &scl_pin); 98 - if (ret) 99 - return ret; 100 - } else { 101 - if (!dev_get_platdata(&pdev->dev)) 102 - return -ENXIO; 103 - pdata = dev_get_platdata(&pdev->dev); 104 - sda_pin = pdata->sda_pin; 105 - scl_pin = pdata->scl_pin; 106 - } 107 - 108 - ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); 109 - if (ret) { 110 - if (ret == -EINVAL) 111 - ret = -EPROBE_DEFER; /* Try again later */ 112 - return ret; 113 - } 114 - ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); 115 - if (ret) { 116 - if (ret == -EINVAL) 117 - ret = -EPROBE_DEFER; /* Try again later */ 118 - return ret; 119 - } 120 - 121 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 174 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 122 175 if (!priv) 123 176 return -ENOMEM; 177 + 124 178 adap = &priv->adap; 125 179 bit_data = &priv->bit_data; 126 180 pdata = &priv->pdata; 127 181 128 - if (pdev->dev.of_node) { 129 - pdata->sda_pin = sda_pin; 130 - pdata->scl_pin = scl_pin; 131 - of_i2c_gpio_get_props(pdev->dev.of_node, pdata); 182 + if (np) { 183 + of_i2c_gpio_get_props(np, pdata); 132 184 } else { 133 - memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); 185 + /* 186 + * If all platform data settings are zero it is OK 187 + * to not provide any platform data from the board. 188 + */ 189 + if (dev_get_platdata(dev)) 190 + memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata)); 134 191 } 135 192 136 - if (pdata->sda_is_open_drain) { 137 - gpio_direction_output(pdata->sda_pin, 1); 138 - bit_data->setsda = i2c_gpio_setsda_val; 139 - } else { 140 - gpio_direction_input(pdata->sda_pin); 141 - bit_data->setsda = i2c_gpio_setsda_dir; 142 - } 193 + /* 194 + * First get the GPIO pins; if it fails, we'll defer the probe. 195 + * If the SDA line is marked from platform data or device tree as 196 + * "open drain" it means something outside of our control is making 197 + * this line being handled as open drain, and we should just handle 198 + * it as any other output. Else we enforce open drain as this is 199 + * required for an I2C bus. 200 + */ 201 + if (pdata->sda_is_open_drain) 202 + gflags = GPIOD_OUT_HIGH; 203 + else 204 + gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; 205 + priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags); 206 + if (IS_ERR(priv->sda)) 207 + return PTR_ERR(priv->sda); 143 208 144 - if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { 145 - gpio_direction_output(pdata->scl_pin, 1); 146 - bit_data->setscl = i2c_gpio_setscl_val; 147 - } else { 148 - gpio_direction_input(pdata->scl_pin); 149 - bit_data->setscl = i2c_gpio_setscl_dir; 150 - } 209 + /* 210 + * If the SCL line is marked from platform data or device tree as 211 + * "open drain" it means something outside of our control is making 212 + * this line being handled as open drain, and we should just handle 213 + * it as any other output. Else we enforce open drain as this is 214 + * required for an I2C bus. 215 + */ 216 + if (pdata->scl_is_open_drain) 217 + gflags = GPIOD_OUT_LOW; 218 + else 219 + gflags = GPIOD_OUT_LOW_OPEN_DRAIN; 220 + priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags); 221 + if (IS_ERR(priv->scl)) 222 + return PTR_ERR(priv->scl); 223 + 224 + bit_data->setsda = i2c_gpio_setsda_val; 225 + bit_data->setscl = i2c_gpio_setscl_val; 151 226 152 227 if (!pdata->scl_is_output_only) 153 228 bit_data->getscl = i2c_gpio_getscl; ··· 198 207 else 199 208 bit_data->timeout = HZ / 10; /* 100 ms */ 200 209 201 - bit_data->data = pdata; 210 + bit_data->data = priv; 202 211 203 212 adap->owner = THIS_MODULE; 204 - if (pdev->dev.of_node) 205 - strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); 213 + if (np) 214 + strlcpy(adap->name, dev_name(dev), sizeof(adap->name)); 206 215 else 207 216 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 208 217 209 218 adap->algo_data = bit_data; 210 219 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 211 - adap->dev.parent = &pdev->dev; 212 - adap->dev.of_node = pdev->dev.of_node; 220 + adap->dev.parent = dev; 221 + adap->dev.of_node = np; 213 222 214 223 adap->nr = pdev->id; 215 224 ret = i2c_bit_add_numbered_bus(adap); ··· 218 227 219 228 platform_set_drvdata(pdev, priv); 220 229 221 - dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", 222 - pdata->sda_pin, pdata->scl_pin, 230 + /* 231 + * FIXME: using global GPIO numbers is not helpful. If/when we 232 + * get accessors to get the actual name of the GPIO line, 233 + * from the descriptor, then provide that instead. 234 + */ 235 + dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", 236 + desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), 223 237 pdata->scl_is_output_only 224 238 ? ", no clock stretching" : ""); 225 239
+81 -23
drivers/i2c/busses/i2c-img-scb.c
··· 82 82 #include <linux/module.h> 83 83 #include <linux/of_platform.h> 84 84 #include <linux/platform_device.h> 85 + #include <linux/pm_runtime.h> 85 86 #include <linux/slab.h> 86 87 #include <linux/timer.h> 87 88 ··· 281 280 #define ISR_COMPLETE(err) (ISR_COMPLETE_M | (ISR_STATUS_M & (err))) 282 281 #define ISR_FATAL(err) (ISR_COMPLETE(err) | ISR_FATAL_M) 283 282 283 + #define IMG_I2C_PM_TIMEOUT 1000 /* ms */ 284 + 284 285 enum img_i2c_mode { 285 286 MODE_INACTIVE, 286 287 MODE_RAW, ··· 410 407 /* raw mode */ 411 408 unsigned int raw_timeout; 412 409 }; 410 + 411 + static int img_i2c_runtime_suspend(struct device *dev); 412 + static int img_i2c_runtime_resume(struct device *dev); 413 413 414 414 static void img_i2c_writel(struct img_i2c *i2c, u32 offset, u32 value) 415 415 { ··· 832 826 * Timer function to check if something has gone wrong in automatic mode (so we 833 827 * don't have to handle so many interrupts just to catch an exception). 834 828 */ 835 - static void img_i2c_check_timer(unsigned long arg) 829 + static void img_i2c_check_timer(struct timer_list *t) 836 830 { 837 - struct img_i2c *i2c = (struct img_i2c *)arg; 831 + struct img_i2c *i2c = from_timer(i2c, t, check_timer); 838 832 unsigned long flags; 839 833 unsigned int line_status; 840 834 ··· 1060 1054 atomic = true; 1061 1055 } 1062 1056 1063 - ret = clk_prepare_enable(i2c->scb_clk); 1064 - if (ret) 1057 + ret = pm_runtime_get_sync(adap->dev.parent); 1058 + if (ret < 0) 1065 1059 return ret; 1066 1060 1067 1061 for (i = 0; i < num; i++) { ··· 1137 1131 break; 1138 1132 } 1139 1133 1140 - clk_disable_unprepare(i2c->scb_clk); 1134 + pm_runtime_mark_last_busy(adap->dev.parent); 1135 + pm_runtime_put_autosuspend(adap->dev.parent); 1141 1136 1142 1137 return i2c->msg_status ? i2c->msg_status : num; 1143 1138 } ··· 1156 1149 static int img_i2c_init(struct img_i2c *i2c) 1157 1150 { 1158 1151 unsigned int clk_khz, bitrate_khz, clk_period, tckh, tckl, tsdh; 1159 - unsigned int i, ret, data, prescale, inc, int_bitrate, filt; 1152 + unsigned int i, data, prescale, inc, int_bitrate, filt; 1160 1153 struct img_i2c_timings timing; 1161 1154 u32 rev; 1155 + int ret; 1162 1156 1163 - ret = clk_prepare_enable(i2c->scb_clk); 1164 - if (ret) 1157 + ret = pm_runtime_get_sync(i2c->adap.dev.parent); 1158 + if (ret < 0) 1165 1159 return ret; 1166 1160 1167 1161 rev = img_i2c_readl(i2c, SCB_CORE_REV_REG); ··· 1171 1163 "Unknown hardware revision (%d.%d.%d.%d)\n", 1172 1164 (rev >> 24) & 0xff, (rev >> 16) & 0xff, 1173 1165 (rev >> 8) & 0xff, rev & 0xff); 1174 - clk_disable_unprepare(i2c->scb_clk); 1166 + pm_runtime_mark_last_busy(i2c->adap.dev.parent); 1167 + pm_runtime_put_autosuspend(i2c->adap.dev.parent); 1175 1168 return -EINVAL; 1176 1169 } 1177 1170 ··· 1323 1314 /* Perform a synchronous sequence to reset the bus */ 1324 1315 ret = img_i2c_reset_bus(i2c); 1325 1316 1326 - clk_disable_unprepare(i2c->scb_clk); 1317 + pm_runtime_mark_last_busy(i2c->adap.dev.parent); 1318 + pm_runtime_put_autosuspend(i2c->adap.dev.parent); 1327 1319 1328 1320 return ret; 1329 1321 } ··· 1372 1362 } 1373 1363 1374 1364 /* Set up the exception check timer */ 1375 - setup_timer(&i2c->check_timer, img_i2c_check_timer, 1376 - (unsigned long)i2c); 1365 + timer_setup(&i2c->check_timer, img_i2c_check_timer, 0); 1377 1366 1378 1367 i2c->bitrate = timings[0].max_bitrate; 1379 1368 if (!of_property_read_u32(node, "clock-frequency", &val)) ··· 1393 1384 1394 1385 platform_set_drvdata(pdev, i2c); 1395 1386 1396 - ret = clk_prepare_enable(i2c->sys_clk); 1397 - if (ret) 1398 - return ret; 1387 + pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_I2C_PM_TIMEOUT); 1388 + pm_runtime_use_autosuspend(&pdev->dev); 1389 + pm_runtime_enable(&pdev->dev); 1390 + if (!pm_runtime_enabled(&pdev->dev)) { 1391 + ret = img_i2c_runtime_resume(&pdev->dev); 1392 + if (ret) 1393 + return ret; 1394 + } 1399 1395 1400 1396 ret = img_i2c_init(i2c); 1401 1397 if (ret) 1402 - goto disable_clk; 1398 + goto rpm_disable; 1403 1399 1404 1400 ret = i2c_add_numbered_adapter(&i2c->adap); 1405 1401 if (ret < 0) 1406 - goto disable_clk; 1402 + goto rpm_disable; 1407 1403 1408 1404 return 0; 1409 1405 1410 - disable_clk: 1411 - clk_disable_unprepare(i2c->sys_clk); 1406 + rpm_disable: 1407 + if (!pm_runtime_enabled(&pdev->dev)) 1408 + img_i2c_runtime_suspend(&pdev->dev); 1409 + pm_runtime_disable(&pdev->dev); 1410 + pm_runtime_dont_use_autosuspend(&pdev->dev); 1412 1411 return ret; 1413 1412 } 1414 1413 ··· 1425 1408 struct img_i2c *i2c = platform_get_drvdata(dev); 1426 1409 1427 1410 i2c_del_adapter(&i2c->adap); 1411 + pm_runtime_disable(&dev->dev); 1412 + if (!pm_runtime_status_suspended(&dev->dev)) 1413 + img_i2c_runtime_suspend(&dev->dev); 1414 + 1415 + return 0; 1416 + } 1417 + 1418 + static int img_i2c_runtime_suspend(struct device *dev) 1419 + { 1420 + struct img_i2c *i2c = dev_get_drvdata(dev); 1421 + 1422 + clk_disable_unprepare(i2c->scb_clk); 1428 1423 clk_disable_unprepare(i2c->sys_clk); 1424 + 1425 + return 0; 1426 + } 1427 + 1428 + static int img_i2c_runtime_resume(struct device *dev) 1429 + { 1430 + struct img_i2c *i2c = dev_get_drvdata(dev); 1431 + int ret; 1432 + 1433 + ret = clk_prepare_enable(i2c->sys_clk); 1434 + if (ret) { 1435 + dev_err(dev, "Unable to enable sys clock\n"); 1436 + return ret; 1437 + } 1438 + 1439 + ret = clk_prepare_enable(i2c->scb_clk); 1440 + if (ret) { 1441 + dev_err(dev, "Unable to enable scb clock\n"); 1442 + clk_disable_unprepare(i2c->sys_clk); 1443 + return ret; 1444 + } 1429 1445 1430 1446 return 0; 1431 1447 } ··· 1467 1417 static int img_i2c_suspend(struct device *dev) 1468 1418 { 1469 1419 struct img_i2c *i2c = dev_get_drvdata(dev); 1420 + int ret; 1421 + 1422 + ret = pm_runtime_force_suspend(dev); 1423 + if (ret) 1424 + return ret; 1470 1425 1471 1426 img_i2c_switch_mode(i2c, MODE_SUSPEND); 1472 - 1473 - clk_disable_unprepare(i2c->sys_clk); 1474 1427 1475 1428 return 0; 1476 1429 } ··· 1483 1430 struct img_i2c *i2c = dev_get_drvdata(dev); 1484 1431 int ret; 1485 1432 1486 - ret = clk_prepare_enable(i2c->sys_clk); 1433 + ret = pm_runtime_force_resume(dev); 1487 1434 if (ret) 1488 1435 return ret; 1489 1436 ··· 1493 1440 } 1494 1441 #endif /* CONFIG_PM_SLEEP */ 1495 1442 1496 - static SIMPLE_DEV_PM_OPS(img_i2c_pm, img_i2c_suspend, img_i2c_resume); 1443 + static const struct dev_pm_ops img_i2c_pm = { 1444 + SET_RUNTIME_PM_OPS(img_i2c_runtime_suspend, 1445 + img_i2c_runtime_resume, 1446 + NULL) 1447 + SET_SYSTEM_SLEEP_PM_OPS(img_i2c_suspend, img_i2c_resume) 1448 + }; 1497 1449 1498 1450 static const struct of_device_id img_scb_i2c_match[] = { 1499 1451 { .compatible = "img,scb-i2c" },
+2 -2
drivers/i2c/busses/i2c-mpc.c
··· 322 322 323 323 static u32 mpc_i2c_get_sec_cfg_8xxx(void) 324 324 { 325 - struct device_node *node = NULL; 325 + struct device_node *node; 326 326 u32 __iomem *reg; 327 327 u32 val = 0; 328 328 ··· 700 700 } 701 701 } 702 702 703 - if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) { 703 + if (of_property_read_bool(op->dev.of_node, "fsl,preserve-clocking")) { 704 704 clock = MPC_I2C_CLOCK_PRESERVE; 705 705 } else { 706 706 prop = of_get_property(op->dev.of_node, "clock-frequency",
+23 -2
drivers/i2c/busses/i2c-omap.c
··· 487 487 } 488 488 489 489 /* 490 + * Try bus recovery, but only if SDA is actually low. 491 + */ 492 + static int omap_i2c_recover_bus(struct omap_i2c_dev *omap) 493 + { 494 + u16 systest; 495 + 496 + systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG); 497 + if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) && 498 + (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC)) 499 + return 0; /* bus seems to already be fine */ 500 + if (!(systest & OMAP_I2C_SYSTEST_SCL_I_FUNC)) 501 + return -EBUSY; /* recovery would not fix SCL */ 502 + return i2c_recover_bus(&omap->adapter); 503 + } 504 + 505 + /* 490 506 * Waiting on Bus Busy 491 507 */ 492 508 static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap) ··· 512 496 timeout = jiffies + OMAP_I2C_TIMEOUT; 513 497 while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { 514 498 if (time_after(jiffies, timeout)) 515 - return i2c_recover_bus(&omap->adapter); 499 + return omap_i2c_recover_bus(omap); 516 500 msleep(1); 517 501 } 518 502 ··· 593 577 } 594 578 595 579 if (time_after(jiffies, timeout)) { 580 + /* 581 + * SDA or SCL were low for the entire timeout without 582 + * any activity detected. Most likely, a slave is 583 + * locking up the bus with no master driving the clock. 584 + */ 596 585 dev_warn(omap->dev, "timeout waiting for bus ready\n"); 597 - return -ETIMEDOUT; 586 + return omap_i2c_recover_bus(omap); 598 587 } 599 588 600 589 msleep(1);
-1
drivers/i2c/busses/i2c-parport-light.c
··· 123 123 124 124 /* SMBus alert support */ 125 125 static struct i2c_smbus_alert_setup alert_data = { 126 - .alert_edge_triggered = 1, 127 126 }; 128 127 static struct i2c_client *ara; 129 128 static struct lineop parport_ctrl_irq = {
-1
drivers/i2c/busses/i2c-parport.c
··· 237 237 238 238 /* Setup SMBus alert if supported */ 239 239 if (adapter_parm[type].smbus_alert) { 240 - adapter->alert_data.alert_edge_triggered = 1; 241 240 adapter->ara = i2c_setup_smbus_alert(&adapter->adapter, 242 241 &adapter->alert_data); 243 242 if (adapter->ara)
+3 -5
drivers/i2c/busses/i2c-pnx.c
··· 112 112 jiffies, expires); 113 113 114 114 timer->expires = jiffies + expires; 115 - timer->data = (unsigned long)alg_data; 116 115 117 116 add_timer(timer); 118 117 } ··· 434 435 return IRQ_HANDLED; 435 436 } 436 437 437 - static void i2c_pnx_timeout(unsigned long data) 438 + static void i2c_pnx_timeout(struct timer_list *t) 438 439 { 439 - struct i2c_pnx_algo_data *alg_data = (struct i2c_pnx_algo_data *)data; 440 + struct i2c_pnx_algo_data *alg_data = from_timer(alg_data, t, mif.timer); 440 441 u32 ctl; 441 442 442 443 dev_err(&alg_data->adapter.dev, ··· 658 659 if (IS_ERR(alg_data->clk)) 659 660 return PTR_ERR(alg_data->clk); 660 661 661 - setup_timer(&alg_data->mif.timer, i2c_pnx_timeout, 662 - (unsigned long)alg_data); 662 + timer_setup(&alg_data->mif.timer, i2c_pnx_timeout, 0); 663 663 664 664 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name), 665 665 "%s", pdev->name);
+82 -35
drivers/i2c/busses/i2c-riic.c
··· 84 84 85 85 #define ICSR2_NACKF 0x10 86 86 87 - /* ICBRx (@ PCLK 33MHz) */ 88 87 #define ICBR_RESERVED 0xe0 /* Should be 1 on writes */ 89 - #define ICBRL_SP100K (19 | ICBR_RESERVED) 90 - #define ICBRH_SP100K (16 | ICBR_RESERVED) 91 - #define ICBRL_SP400K (21 | ICBR_RESERVED) 92 - #define ICBRH_SP400K (9 | ICBR_RESERVED) 93 88 94 89 #define RIIC_INIT_MSG -1 95 90 ··· 283 288 .functionality = riic_func, 284 289 }; 285 290 286 - static int riic_init_hw(struct riic_dev *riic, u32 spd) 291 + static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) 287 292 { 288 293 int ret; 289 294 unsigned long rate; 295 + int total_ticks, cks, brl, brh; 290 296 291 297 ret = clk_prepare_enable(riic->clk); 292 298 if (ret) 293 299 return ret; 294 300 295 - /* 296 - * TODO: Implement formula to calculate the timing values depending on 297 - * variable parent clock rate and arbitrary bus speed 298 - */ 299 - rate = clk_get_rate(riic->clk); 300 - if (rate != 33325000) { 301 + if (t->bus_freq_hz > 400000) { 301 302 dev_err(&riic->adapter.dev, 302 - "invalid parent clk (%lu). Must be 33325000Hz\n", rate); 303 + "unsupported bus speed (%dHz). 400000 max\n", 304 + t->bus_freq_hz); 303 305 clk_disable_unprepare(riic->clk); 304 306 return -EINVAL; 305 307 } 308 + 309 + rate = clk_get_rate(riic->clk); 310 + 311 + /* 312 + * Assume the default register settings: 313 + * FER.SCLE = 1 (SCL sync circuit enabled, adds 2 or 3 cycles) 314 + * FER.NFE = 1 (noise circuit enabled) 315 + * MR3.NF = 0 (1 cycle of noise filtered out) 316 + * 317 + * Freq (CKS=000) = (I2CCLK + tr + tf)/ (BRH + 3 + 1) + (BRL + 3 + 1) 318 + * Freq (CKS!=000) = (I2CCLK + tr + tf)/ (BRH + 2 + 1) + (BRL + 2 + 1) 319 + */ 320 + 321 + /* 322 + * Determine reference clock rate. We must be able to get the desired 323 + * frequency with only 62 clock ticks max (31 high, 31 low). 324 + * Aim for a duty of 60% LOW, 40% HIGH. 325 + */ 326 + total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz); 327 + 328 + for (cks = 0; cks < 7; cks++) { 329 + /* 330 + * 60% low time must be less than BRL + 2 + 1 331 + * BRL max register value is 0x1F. 332 + */ 333 + brl = ((total_ticks * 6) / 10); 334 + if (brl <= (0x1F + 3)) 335 + break; 336 + 337 + total_ticks /= 2; 338 + rate /= 2; 339 + } 340 + 341 + if (brl > (0x1F + 3)) { 342 + dev_err(&riic->adapter.dev, "invalid speed (%lu). Too slow.\n", 343 + (unsigned long)t->bus_freq_hz); 344 + clk_disable_unprepare(riic->clk); 345 + return -EINVAL; 346 + } 347 + 348 + brh = total_ticks - brl; 349 + 350 + /* Remove automatic clock ticks for sync circuit and NF */ 351 + if (cks == 0) { 352 + brl -= 4; 353 + brh -= 4; 354 + } else { 355 + brl -= 3; 356 + brh -= 3; 357 + } 358 + 359 + /* 360 + * Remove clock ticks for rise and fall times. Convert ns to clock 361 + * ticks. 362 + */ 363 + brl -= t->scl_fall_ns / (1000000000 / rate); 364 + brh -= t->scl_rise_ns / (1000000000 / rate); 365 + 366 + /* Adjust for min register values for when SCLE=1 and NFE=1 */ 367 + if (brl < 1) 368 + brl = 1; 369 + if (brh < 1) 370 + brh = 1; 371 + 372 + pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n", 373 + rate / total_ticks, ((brl + 3) * 100) / (brl + brh + 6), 374 + t->scl_fall_ns / (1000000000 / rate), 375 + t->scl_rise_ns / (1000000000 / rate), cks, brl, brh); 306 376 307 377 /* Changing the order of accessing IICRST and ICE may break things! */ 308 378 writeb(ICCR1_IICRST | ICCR1_SOWP, riic->base + RIIC_ICCR1); 309 379 riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1); 310 380 311 - switch (spd) { 312 - case 100000: 313 - writeb(ICMR1_CKS(3), riic->base + RIIC_ICMR1); 314 - writeb(ICBRH_SP100K, riic->base + RIIC_ICBRH); 315 - writeb(ICBRL_SP100K, riic->base + RIIC_ICBRL); 316 - break; 317 - case 400000: 318 - writeb(ICMR1_CKS(1), riic->base + RIIC_ICMR1); 319 - writeb(ICBRH_SP400K, riic->base + RIIC_ICBRH); 320 - writeb(ICBRL_SP400K, riic->base + RIIC_ICBRL); 321 - break; 322 - default: 323 - dev_err(&riic->adapter.dev, 324 - "unsupported bus speed (%dHz). Use 100000 or 400000\n", spd); 325 - clk_disable_unprepare(riic->clk); 326 - return -EINVAL; 327 - } 381 + writeb(ICMR1_CKS(cks), riic->base + RIIC_ICMR1); 382 + writeb(brh | ICBR_RESERVED, riic->base + RIIC_ICBRH); 383 + writeb(brl | ICBR_RESERVED, riic->base + RIIC_ICBRL); 328 384 329 385 writeb(0, riic->base + RIIC_ICSER); 330 386 writeb(ICMR3_ACKWP | ICMR3_RDRFS, riic->base + RIIC_ICMR3); ··· 397 351 398 352 static int riic_i2c_probe(struct platform_device *pdev) 399 353 { 400 - struct device_node *np = pdev->dev.of_node; 401 354 struct riic_dev *riic; 402 355 struct i2c_adapter *adap; 403 356 struct resource *res; 404 - u32 bus_rate = 0; 357 + struct i2c_timings i2c_t; 405 358 int i, ret; 406 359 407 360 riic = devm_kzalloc(&pdev->dev, sizeof(*riic), GFP_KERNEL); ··· 441 396 442 397 init_completion(&riic->msg_done); 443 398 444 - of_property_read_u32(np, "clock-frequency", &bus_rate); 445 - ret = riic_init_hw(riic, bus_rate); 399 + i2c_parse_fw_timings(&pdev->dev, &i2c_t, true); 400 + 401 + ret = riic_init_hw(riic, &i2c_t); 446 402 if (ret) 447 403 return ret; 448 404 ··· 454 408 455 409 platform_set_drvdata(pdev, riic); 456 410 457 - dev_info(&pdev->dev, "registered with %dHz bus speed\n", bus_rate); 411 + dev_info(&pdev->dev, "registered with %dHz bus speed\n", 412 + i2c_t.bus_freq_hz); 458 413 return 0; 459 414 } 460 415
+3 -5
drivers/i2c/busses/i2c-sh_mobile.c
··· 881 881 struct sh_mobile_i2c_data *pd; 882 882 struct i2c_adapter *adap; 883 883 struct resource *res; 884 - const struct of_device_id *match; 884 + const struct sh_mobile_dt_config *config; 885 885 int ret; 886 886 u32 bus_speed; 887 887 ··· 913 913 pd->bus_speed = ret ? STANDARD_MODE : bus_speed; 914 914 pd->clks_per_count = 1; 915 915 916 - match = of_match_device(sh_mobile_i2c_dt_ids, &dev->dev); 917 - if (match) { 918 - const struct sh_mobile_dt_config *config = match->data; 919 - 916 + config = of_device_get_match_data(&dev->dev); 917 + if (config) { 920 918 pd->clks_per_count = config->clks_per_count; 921 919 922 920 if (config->setup)
+1 -2
drivers/i2c/busses/i2c-taos-evm.c
··· 282 282 { 283 283 struct taos_data *taos = serio_get_drvdata(serio); 284 284 285 - if (taos->client) 286 - i2c_unregister_device(taos->client); 285 + i2c_unregister_device(taos->client); 287 286 i2c_del_adapter(&taos->adapter); 288 287 serio_close(serio); 289 288 kfree(taos);
+1 -8
drivers/i2c/busses/i2c-thunderx-pcidrv.c
··· 118 118 static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c, 119 119 struct device_node *node) 120 120 { 121 - u32 type; 122 - 123 121 if (!node) 124 122 return -EINVAL; 125 123 126 124 i2c->alert_data.irq = irq_of_parse_and_map(node, 0); 127 125 if (!i2c->alert_data.irq) 128 126 return -EINVAL; 129 - 130 - type = irqd_get_trigger_type(irq_get_irq_data(i2c->alert_data.irq)); 131 - i2c->alert_data.alert_edge_triggered = 132 - (type & IRQ_TYPE_LEVEL_MASK) ? 1 : 0; 133 127 134 128 i2c->ara = i2c_setup_smbus_alert(&i2c->adap, &i2c->alert_data); 135 129 if (!i2c->ara) ··· 143 149 144 150 static void thunder_i2c_smbus_remove(struct octeon_i2c *i2c) 145 151 { 146 - if (i2c->ara) 147 - i2c_unregister_device(i2c->ara); 152 + i2c_unregister_device(i2c->ara); 148 153 } 149 154 150 155 static int thunder_i2c_probe_pci(struct pci_dev *pdev,
+26 -4
drivers/i2c/busses/i2c-xgene-slimpro.c
··· 129 129 #define to_slimpro_i2c_dev(cl) \ 130 130 container_of(cl, struct slimpro_i2c_dev, mbox_client) 131 131 132 + enum slimpro_i2c_version { 133 + XGENE_SLIMPRO_I2C_V1 = 0, 134 + XGENE_SLIMPRO_I2C_V2 = 1, 135 + }; 136 + 132 137 /* 133 138 * This function tests and clears a bitmask then returns its old value 134 139 */ ··· 481 476 } 482 477 } else { 483 478 struct acpi_pcct_hw_reduced *cppc_ss; 479 + const struct acpi_device_id *acpi_id; 480 + int version = XGENE_SLIMPRO_I2C_V1; 481 + 482 + acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table, 483 + &pdev->dev); 484 + if (!acpi_id) 485 + return -EINVAL; 486 + 487 + version = (int)acpi_id->driver_data; 484 488 485 489 if (device_property_read_u32(&pdev->dev, "pcc-channel", 486 490 &ctx->mbox_idx)) ··· 528 514 */ 529 515 ctx->comm_base_addr = cppc_ss->base_address; 530 516 if (ctx->comm_base_addr) { 531 - ctx->pcc_comm_addr = memremap(ctx->comm_base_addr, 532 - cppc_ss->length, 533 - MEMREMAP_WB); 517 + if (version == XGENE_SLIMPRO_I2C_V2) 518 + ctx->pcc_comm_addr = memremap( 519 + ctx->comm_base_addr, 520 + cppc_ss->length, 521 + MEMREMAP_WT); 522 + else 523 + ctx->pcc_comm_addr = memremap( 524 + ctx->comm_base_addr, 525 + cppc_ss->length, 526 + MEMREMAP_WB); 534 527 } else { 535 528 dev_err(&pdev->dev, "Failed to get PCC comm region\n"); 536 529 rc = -ENOENT; ··· 602 581 603 582 #ifdef CONFIG_ACPI 604 583 static const struct acpi_device_id xgene_slimpro_i2c_acpi_ids[] = { 605 - {"APMC0D40", 0}, 584 + {"APMC0D40", XGENE_SLIMPRO_I2C_V1}, 585 + {"APMC0D8B", XGENE_SLIMPRO_I2C_V2}, 606 586 {} 607 587 }; 608 588 MODULE_DEVICE_TABLE(acpi, xgene_slimpro_i2c_acpi_ids);
+40 -4
drivers/i2c/busses/i2c-xlp9xx.c
··· 7 7 */ 8 8 9 9 #include <linux/acpi.h> 10 + #include <linux/clk.h> 10 11 #include <linux/completion.h> 11 12 #include <linux/i2c.h> 12 13 #include <linux/init.h> ··· 82 81 struct completion msg_complete; 83 82 int irq; 84 83 bool msg_read; 84 + bool len_recv; 85 + bool client_pec; 85 86 u32 __iomem *base; 86 87 u32 msg_buf_remaining; 87 88 u32 msg_len; 89 + u32 ip_clk_hz; 88 90 u32 clk_hz; 89 91 u32 msg_err; 90 92 u8 *msg_buf; ··· 145 141 static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) 146 142 { 147 143 u32 len, i; 148 - u8 *buf = priv->msg_buf; 144 + u8 rlen, *buf = priv->msg_buf; 149 145 150 146 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & 151 147 XLP9XX_I2C_FIFO_WCNT_MASK; 148 + if (!len) 149 + return; 150 + if (priv->len_recv) { 151 + /* read length byte */ 152 + rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); 153 + *buf++ = rlen; 154 + len--; 155 + if (priv->client_pec) 156 + ++rlen; 157 + /* update remaining bytes and message length */ 158 + priv->msg_buf_remaining = rlen; 159 + priv->msg_len = rlen + 1; 160 + priv->len_recv = false; 161 + } 162 + 152 163 len = min(priv->msg_buf_remaining, len); 153 164 for (i = 0; i < len; i++, buf++) 154 165 *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); ··· 232 213 * The controller uses 5 * SCL clock internally. 233 214 * So prescale value should be divided by 5. 234 215 */ 235 - prescale = DIV_ROUND_UP(XLP9XX_I2C_IP_CLK_FREQ, priv->clk_hz); 216 + prescale = DIV_ROUND_UP(priv->ip_clk_hz, priv->clk_hz); 236 217 prescale = ((prescale - 8) / 5) - 1; 237 218 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST); 238 219 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN | ··· 247 228 int last_msg) 248 229 { 249 230 unsigned long timeleft; 250 - u32 intr_mask, cmd, val; 231 + u32 intr_mask, cmd, val, len; 251 232 252 233 priv->msg_buf = msg->buf; 253 234 priv->msg_buf_remaining = priv->msg_len = msg->len; ··· 280 261 else 281 262 val &= ~XLP9XX_I2C_CTRL_ADDMODE; 282 263 264 + priv->len_recv = msg->flags & I2C_M_RECV_LEN; 265 + len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len; 266 + priv->client_pec = msg->flags & I2C_CLIENT_PEC; 267 + 283 268 /* set data length to be transferred */ 284 269 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | 285 - (msg->len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); 270 + (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); 286 271 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); 287 272 288 273 /* fill fifo during tx */ ··· 333 310 return -ETIMEDOUT; 334 311 } 335 312 313 + /* update msg->len with actual received length */ 314 + if (msg->flags & I2C_M_RECV_LEN) 315 + msg->len = priv->msg_len; 336 316 return 0; 337 317 } 338 318 ··· 368 342 static int xlp9xx_i2c_get_frequency(struct platform_device *pdev, 369 343 struct xlp9xx_i2c_dev *priv) 370 344 { 345 + struct clk *clk; 371 346 u32 freq; 372 347 int err; 348 + 349 + clk = devm_clk_get(&pdev->dev, NULL); 350 + if (IS_ERR(clk)) { 351 + priv->ip_clk_hz = XLP9XX_I2C_IP_CLK_FREQ; 352 + dev_dbg(&pdev->dev, "using default input frequency %u\n", 353 + priv->ip_clk_hz); 354 + } else { 355 + priv->ip_clk_hz = clk_get_rate(clk); 356 + } 373 357 374 358 err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq); 375 359 if (err) {
+27 -7
drivers/i2c/i2c-core-base.c
··· 29 29 #include <linux/errno.h> 30 30 #include <linux/gpio.h> 31 31 #include <linux/i2c.h> 32 + #include <linux/i2c-smbus.h> 32 33 #include <linux/idr.h> 33 34 #include <linux/init.h> 34 35 #include <linux/irqflags.h> ··· 206 205 */ 207 206 while (i++ < RECOVERY_CLK_CNT * 2) { 208 207 if (val) { 209 - /* Break if SDA is high */ 210 - if (bri->get_sda && bri->get_sda(adap)) 211 - break; 212 208 /* SCL shouldn't be low here */ 213 209 if (!bri->get_scl(adap)) { 214 210 dev_err(&adap->dev, ··· 213 215 ret = -EBUSY; 214 216 break; 215 217 } 218 + /* Break if SDA is high */ 219 + if (bri->get_sda && bri->get_sda(adap)) 220 + break; 216 221 } 217 222 218 223 val = !val; 219 224 bri->set_scl(adap, val); 220 225 ndelay(RECOVERY_NDELAY); 221 226 } 227 + 228 + /* check if recovery actually succeeded */ 229 + if (bri->get_sda && !bri->get_sda(adap)) 230 + ret = -EBUSY; 222 231 223 232 if (bri->unprepare_recovery) 224 233 bri->unprepare_recovery(adap); ··· 671 666 } 672 667 673 668 static void i2c_dev_set_name(struct i2c_adapter *adap, 674 - struct i2c_client *client) 669 + struct i2c_client *client, 670 + struct i2c_board_info const *info) 675 671 { 676 672 struct acpi_device *adev = ACPI_COMPANION(&client->dev); 673 + 674 + if (info && info->dev_name) { 675 + dev_set_name(&client->dev, "i2c-%s", info->dev_name); 676 + return; 677 + } 677 678 678 679 if (adev) { 679 680 dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev)); ··· 777 766 client->dev.of_node = info->of_node; 778 767 client->dev.fwnode = info->fwnode; 779 768 780 - i2c_dev_set_name(adap, client); 769 + i2c_dev_set_name(adap, client, info); 781 770 782 771 if (info->properties) { 783 772 status = device_add_properties(&client->dev, info->properties); ··· 819 808 */ 820 809 void i2c_unregister_device(struct i2c_client *client) 821 810 { 811 + if (!client) 812 + return; 822 813 if (client->dev.of_node) 823 814 of_node_clear_flag(client->dev.of_node, OF_POPULATED); 824 815 if (ACPI_COMPANION(&client->dev)) ··· 1272 1259 goto out_list; 1273 1260 } 1274 1261 1262 + res = of_i2c_setup_smbus_alert(adap); 1263 + if (res) 1264 + goto out_reg; 1265 + 1275 1266 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 1276 1267 1277 1268 pm_runtime_no_callbacks(&adap->dev); ··· 1307 1290 1308 1291 return 0; 1309 1292 1293 + out_reg: 1294 + init_completion(&adap->dev_released); 1295 + device_unregister(&adap->dev); 1296 + wait_for_completion(&adap->dev_released); 1310 1297 out_list: 1311 1298 mutex_lock(&core_lock); 1312 1299 idr_remove(&i2c_adapter_idr, adap->nr); ··· 1438 1417 static int __unregister_dummy(struct device *dev, void *dummy) 1439 1418 { 1440 1419 struct i2c_client *client = i2c_verify_client(dev); 1441 - if (client) 1442 - i2c_unregister_device(client); 1420 + i2c_unregister_device(client); 1443 1421 return 0; 1444 1422 } 1445 1423
+55
drivers/i2c/i2c-core-smbus.c
··· 17 17 #include <linux/device.h> 18 18 #include <linux/err.h> 19 19 #include <linux/i2c.h> 20 + #include <linux/i2c-smbus.h> 20 21 21 22 #define CREATE_TRACE_POINTS 22 23 #include <trace/events/smbus.h> ··· 593 592 return i; 594 593 } 595 594 EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated); 595 + 596 + /** 597 + * i2c_setup_smbus_alert - Setup SMBus alert support 598 + * @adapter: the target adapter 599 + * @setup: setup data for the SMBus alert handler 600 + * Context: can sleep 601 + * 602 + * Setup handling of the SMBus alert protocol on a given I2C bus segment. 603 + * 604 + * Handling can be done either through our IRQ handler, or by the 605 + * adapter (from its handler, periodic polling, or whatever). 606 + * 607 + * NOTE that if we manage the IRQ, we *MUST* know if it's level or 608 + * edge triggered in order to hand it to the workqueue correctly. 609 + * If triggering the alert seems to wedge the system, you probably 610 + * should have said it's level triggered. 611 + * 612 + * This returns the ara client, which should be saved for later use with 613 + * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL 614 + * to indicate an error. 615 + */ 616 + struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, 617 + struct i2c_smbus_alert_setup *setup) 618 + { 619 + struct i2c_board_info ara_board_info = { 620 + I2C_BOARD_INFO("smbus_alert", 0x0c), 621 + .platform_data = setup, 622 + }; 623 + 624 + return i2c_new_device(adapter, &ara_board_info); 625 + } 626 + EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); 627 + 628 + #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) 629 + int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter) 630 + { 631 + struct i2c_client *client; 632 + int irq; 633 + 634 + irq = of_property_match_string(adapter->dev.of_node, "interrupt-names", 635 + "smbus_alert"); 636 + if (irq == -EINVAL || irq == -ENODATA) 637 + return 0; 638 + else if (irq < 0) 639 + return irq; 640 + 641 + client = i2c_setup_smbus_alert(adapter, NULL); 642 + if (!client) 643 + return -ENODEV; 644 + 645 + return 0; 646 + } 647 + EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert); 648 + #endif
+25 -56
drivers/i2c/i2c-smbus.c
··· 21 21 #include <linux/interrupt.h> 22 22 #include <linux/kernel.h> 23 23 #include <linux/module.h> 24 + #include <linux/of_irq.h> 24 25 #include <linux/slab.h> 25 26 #include <linux/workqueue.h> 26 27 27 28 struct i2c_smbus_alert { 28 - unsigned int alert_edge_triggered:1; 29 - int irq; 30 29 struct work_struct alert; 31 30 struct i2c_client *ara; /* Alert response address */ 32 31 }; ··· 71 72 * The alert IRQ handler needs to hand work off to a task which can issue 72 73 * SMBus calls, because those sleeping calls can't be made in IRQ context. 73 74 */ 74 - static void smbus_alert(struct work_struct *work) 75 + static irqreturn_t smbus_alert(int irq, void *d) 75 76 { 76 - struct i2c_smbus_alert *alert; 77 + struct i2c_smbus_alert *alert = d; 77 78 struct i2c_client *ara; 78 79 unsigned short prev_addr = 0; /* Not a valid address */ 79 80 80 - alert = container_of(work, struct i2c_smbus_alert, alert); 81 81 ara = alert->ara; 82 82 83 83 for (;;) { ··· 113 115 prev_addr = data.addr; 114 116 } 115 117 116 - /* We handled all alerts; re-enable level-triggered IRQs */ 117 - if (!alert->alert_edge_triggered) 118 - enable_irq(alert->irq); 118 + return IRQ_HANDLED; 119 119 } 120 120 121 - static irqreturn_t smbalert_irq(int irq, void *d) 121 + static void smbalert_work(struct work_struct *work) 122 122 { 123 - struct i2c_smbus_alert *alert = d; 123 + struct i2c_smbus_alert *alert; 124 124 125 - /* Disable level-triggered IRQs until we handle them */ 126 - if (!alert->alert_edge_triggered) 127 - disable_irq_nosync(irq); 125 + alert = container_of(work, struct i2c_smbus_alert, alert); 128 126 129 - schedule_work(&alert->alert); 130 - return IRQ_HANDLED; 127 + smbus_alert(0, alert); 128 + 131 129 } 132 130 133 131 /* Setup SMBALERT# infrastructure */ ··· 133 139 struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev); 134 140 struct i2c_smbus_alert *alert; 135 141 struct i2c_adapter *adapter = ara->adapter; 136 - int res; 142 + int res, irq; 137 143 138 144 alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert), 139 145 GFP_KERNEL); 140 146 if (!alert) 141 147 return -ENOMEM; 142 148 143 - alert->alert_edge_triggered = setup->alert_edge_triggered; 144 - alert->irq = setup->irq; 145 - INIT_WORK(&alert->alert, smbus_alert); 149 + if (setup) { 150 + irq = setup->irq; 151 + } else { 152 + irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); 153 + if (irq <= 0) 154 + return irq; 155 + } 156 + 157 + INIT_WORK(&alert->alert, smbalert_work); 146 158 alert->ara = ara; 147 159 148 - if (setup->irq > 0) { 149 - res = devm_request_irq(&ara->dev, setup->irq, smbalert_irq, 150 - 0, "smbus_alert", alert); 160 + if (irq > 0) { 161 + res = devm_request_threaded_irq(&ara->dev, irq, 162 + NULL, smbus_alert, 163 + IRQF_SHARED | IRQF_ONESHOT, 164 + "smbus_alert", alert); 151 165 if (res) 152 166 return res; 153 167 } 154 168 155 169 i2c_set_clientdata(ara, alert); 156 - dev_info(&adapter->dev, "supports SMBALERT#, %s trigger\n", 157 - setup->alert_edge_triggered ? "edge" : "level"); 170 + dev_info(&adapter->dev, "supports SMBALERT#\n"); 158 171 159 172 return 0; 160 173 } ··· 189 188 .remove = smbalert_remove, 190 189 .id_table = smbalert_ids, 191 190 }; 192 - 193 - /** 194 - * i2c_setup_smbus_alert - Setup SMBus alert support 195 - * @adapter: the target adapter 196 - * @setup: setup data for the SMBus alert handler 197 - * Context: can sleep 198 - * 199 - * Setup handling of the SMBus alert protocol on a given I2C bus segment. 200 - * 201 - * Handling can be done either through our IRQ handler, or by the 202 - * adapter (from its handler, periodic polling, or whatever). 203 - * 204 - * NOTE that if we manage the IRQ, we *MUST* know if it's level or 205 - * edge triggered in order to hand it to the workqueue correctly. 206 - * If triggering the alert seems to wedge the system, you probably 207 - * should have said it's level triggered. 208 - * 209 - * This returns the ara client, which should be saved for later use with 210 - * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL 211 - * to indicate an error. 212 - */ 213 - struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, 214 - struct i2c_smbus_alert_setup *setup) 215 - { 216 - struct i2c_board_info ara_board_info = { 217 - I2C_BOARD_INFO("smbus_alert", 0x0c), 218 - .platform_data = setup, 219 - }; 220 - 221 - return i2c_new_device(adapter, &ara_board_info); 222 - } 223 - EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); 224 191 225 192 /** 226 193 * i2c_handle_smbus_alert - Handle an SMBus alert
+33 -64
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 246 246 return handled ? IRQ_HANDLED : IRQ_NONE; 247 247 } 248 248 249 - static void pca954x_irq_mask(struct irq_data *idata) 250 - { 251 - struct pca954x *data = irq_data_get_irq_chip_data(idata); 252 - unsigned int pos = idata->hwirq; 253 - unsigned long flags; 254 - 255 - raw_spin_lock_irqsave(&data->lock, flags); 256 - 257 - data->irq_mask &= ~BIT(pos); 258 - if (!data->irq_mask) 259 - disable_irq(data->client->irq); 260 - 261 - raw_spin_unlock_irqrestore(&data->lock, flags); 262 - } 263 - 264 - static void pca954x_irq_unmask(struct irq_data *idata) 265 - { 266 - struct pca954x *data = irq_data_get_irq_chip_data(idata); 267 - unsigned int pos = idata->hwirq; 268 - unsigned long flags; 269 - 270 - raw_spin_lock_irqsave(&data->lock, flags); 271 - 272 - if (!data->irq_mask) 273 - enable_irq(data->client->irq); 274 - data->irq_mask |= BIT(pos); 275 - 276 - raw_spin_unlock_irqrestore(&data->lock, flags); 277 - } 278 - 279 249 static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type) 280 250 { 281 251 if ((type & IRQ_TYPE_SENSE_MASK) != IRQ_TYPE_LEVEL_LOW) ··· 255 285 256 286 static struct irq_chip pca954x_irq_chip = { 257 287 .name = "i2c-mux-pca954x", 258 - .irq_mask = pca954x_irq_mask, 259 - .irq_unmask = pca954x_irq_unmask, 260 288 .irq_set_type = pca954x_irq_set_type, 261 289 }; 262 290 ··· 262 294 { 263 295 struct pca954x *data = i2c_mux_priv(muxc); 264 296 struct i2c_client *client = data->client; 265 - int c, err, irq; 297 + int c, irq; 266 298 267 299 if (!data->chip->has_irq || client->irq <= 0) 268 300 return 0; ··· 277 309 278 310 for (c = 0; c < data->chip->nchans; c++) { 279 311 irq = irq_create_mapping(data->irq, c); 312 + if (!irq) { 313 + dev_err(&client->dev, "failed irq create map\n"); 314 + return -EINVAL; 315 + } 280 316 irq_set_chip_data(irq, data); 281 317 irq_set_chip_and_handler(irq, &pca954x_irq_chip, 282 318 handle_simple_irq); 283 319 } 284 320 285 - err = devm_request_threaded_irq(&client->dev, data->client->irq, NULL, 286 - pca954x_irq_handler, 287 - IRQF_ONESHOT | IRQF_SHARED, 288 - "pca954x", data); 289 - if (err) 290 - goto err_req_irq; 291 - 292 - disable_irq(data->client->irq); 293 - 294 321 return 0; 295 - err_req_irq: 296 - for (c = 0; c < data->chip->nchans; c++) { 297 - irq = irq_find_mapping(data->irq, c); 298 - irq_dispose_mapping(irq); 299 - } 300 - irq_domain_remove(data->irq); 322 + } 301 323 302 - return err; 324 + static void pca954x_cleanup(struct i2c_mux_core *muxc) 325 + { 326 + struct pca954x *data = i2c_mux_priv(muxc); 327 + int c, irq; 328 + 329 + if (data->irq) { 330 + for (c = 0; c < data->chip->nchans; c++) { 331 + irq = irq_find_mapping(data->irq, c); 332 + irq_dispose_mapping(irq); 333 + } 334 + irq_domain_remove(data->irq); 335 + } 336 + i2c_mux_del_adapters(muxc); 303 337 } 304 338 305 339 /* ··· 361 391 362 392 ret = pca954x_irq_setup(muxc); 363 393 if (ret) 364 - goto fail_del_adapters; 394 + goto fail_cleanup; 365 395 366 396 /* Now create an adapter for each channel */ 367 397 for (num = 0; num < data->chip->nchans; num++) { ··· 384 414 385 415 ret = i2c_mux_add_adapter(muxc, force, num, class); 386 416 if (ret) 387 - goto fail_del_adapters; 417 + goto fail_cleanup; 418 + } 419 + 420 + if (data->irq) { 421 + ret = devm_request_threaded_irq(&client->dev, data->client->irq, 422 + NULL, pca954x_irq_handler, 423 + IRQF_ONESHOT | IRQF_SHARED, 424 + "pca954x", data); 425 + if (ret) 426 + goto fail_cleanup; 388 427 } 389 428 390 429 dev_info(&client->dev, ··· 403 424 404 425 return 0; 405 426 406 - fail_del_adapters: 407 - i2c_mux_del_adapters(muxc); 427 + fail_cleanup: 428 + pca954x_cleanup(muxc); 408 429 return ret; 409 430 } 410 431 411 432 static int pca954x_remove(struct i2c_client *client) 412 433 { 413 434 struct i2c_mux_core *muxc = i2c_get_clientdata(client); 414 - struct pca954x *data = i2c_mux_priv(muxc); 415 - int c, irq; 416 435 417 - if (data->irq) { 418 - for (c = 0; c < data->chip->nchans; c++) { 419 - irq = irq_find_mapping(data->irq, c); 420 - irq_dispose_mapping(irq); 421 - } 422 - irq_domain_remove(data->irq); 423 - } 424 - 425 - i2c_mux_del_adapters(muxc); 436 + pca954x_cleanup(muxc); 426 437 return 0; 427 438 } 428 439
+3 -6
drivers/i2c/muxes/i2c-mux-reg.c
··· 107 107 put_device(&adapter->dev); 108 108 109 109 mux->data.n_values = of_get_child_count(np); 110 - if (of_find_property(np, "little-endian", NULL)) { 110 + if (of_property_read_bool(np, "little-endian")) { 111 111 mux->data.little_endian = true; 112 - } else if (of_find_property(np, "big-endian", NULL)) { 112 + } else if (of_property_read_bool(np, "big-endian")) { 113 113 mux->data.little_endian = false; 114 114 } else { 115 115 #if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : \ ··· 122 122 #error Endianness not defined? 123 123 #endif 124 124 } 125 - if (of_find_property(np, "write-only", NULL)) 126 - mux->data.write_only = true; 127 - else 128 - mux->data.write_only = false; 125 + mux->data.write_only = of_property_read_bool(np, "write-only"); 129 126 130 127 values = devm_kzalloc(&pdev->dev, 131 128 sizeof(*mux->data.values) * mux->data.n_values,
+1 -6
drivers/mfd/intel-lpss.h
··· 38 38 #ifdef CONFIG_PM_SLEEP 39 39 #define INTEL_LPSS_SLEEP_PM_OPS \ 40 40 .prepare = intel_lpss_prepare, \ 41 - .suspend = intel_lpss_suspend, \ 42 - .resume = intel_lpss_resume, \ 43 - .freeze = intel_lpss_suspend, \ 44 - .thaw = intel_lpss_resume, \ 45 - .poweroff = intel_lpss_suspend, \ 46 - .restore = intel_lpss_resume, 41 + SET_LATE_SYSTEM_SLEEP_PM_OPS(intel_lpss_suspend, intel_lpss_resume) 47 42 #else 48 43 #define INTEL_LPSS_SLEEP_PM_OPS 49 44 #endif
+27 -22
drivers/mfd/sm501.c
··· 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pci.h> 22 22 #include <linux/i2c-gpio.h> 23 + #include <linux/gpio/machine.h> 23 24 #include <linux/slab.h> 24 25 25 26 #include <linux/sm501.h> ··· 1108 1107 kfree(gpio->regs_res); 1109 1108 } 1110 1109 1111 - static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) 1112 - { 1113 - struct sm501_gpio *gpio = &sm->gpio; 1114 - int base = (pin < 32) ? gpio->low.gpio.base : gpio->high.gpio.base; 1115 - 1116 - return (pin % 32) + base; 1117 - } 1118 - 1119 1110 static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1120 1111 { 1121 1112 return sm->gpio.registered; ··· 1122 1129 { 1123 1130 } 1124 1131 1125 - static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) 1126 - { 1127 - return -1; 1128 - } 1129 - 1130 1132 static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1131 1133 { 1132 1134 return 0; ··· 1133 1145 { 1134 1146 struct i2c_gpio_platform_data *icd; 1135 1147 struct platform_device *pdev; 1148 + struct gpiod_lookup_table *lookup; 1136 1149 1137 1150 pdev = sm501_create_subdev(sm, "i2c-gpio", 0, 1138 1151 sizeof(struct i2c_gpio_platform_data)); 1139 1152 if (!pdev) 1140 1153 return -ENOMEM; 1141 1154 1155 + /* Create a gpiod lookup using gpiochip-local offsets */ 1156 + lookup = devm_kzalloc(&pdev->dev, 1157 + sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup), 1158 + GFP_KERNEL); 1159 + lookup->dev_id = "i2c-gpio"; 1160 + if (iic->pin_sda < 32) 1161 + lookup->table[0].chip_label = "SM501-LOW"; 1162 + else 1163 + lookup->table[0].chip_label = "SM501-HIGH"; 1164 + lookup->table[0].chip_hwnum = iic->pin_sda % 32; 1165 + lookup->table[0].con_id = NULL; 1166 + lookup->table[0].idx = 0; 1167 + lookup->table[0].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; 1168 + if (iic->pin_scl < 32) 1169 + lookup->table[1].chip_label = "SM501-LOW"; 1170 + else 1171 + lookup->table[1].chip_label = "SM501-HIGH"; 1172 + lookup->table[1].chip_hwnum = iic->pin_scl % 32; 1173 + lookup->table[1].con_id = NULL; 1174 + lookup->table[1].idx = 1; 1175 + lookup->table[1].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; 1176 + gpiod_add_lookup_table(lookup); 1177 + 1142 1178 icd = dev_get_platdata(&pdev->dev); 1143 - 1144 - /* We keep the pin_sda and pin_scl fields relative in case the 1145 - * same platform data is passed to >1 SM501. 1146 - */ 1147 - 1148 - icd->sda_pin = sm501_gpio_pin2nr(sm, iic->pin_sda); 1149 - icd->scl_pin = sm501_gpio_pin2nr(sm, iic->pin_scl); 1150 1179 icd->timeout = iic->timeout; 1151 1180 icd->udelay = iic->udelay; 1152 1181 ··· 1175 1170 1176 1171 pdev->id = iic->bus_num; 1177 1172 1178 - dev_info(sm->dev, "registering i2c-%d: sda=%d (%d), scl=%d (%d)\n", 1173 + dev_info(sm->dev, "registering i2c-%d: sda=%d, scl=%d\n", 1179 1174 iic->bus_num, 1180 - icd->sda_pin, iic->pin_sda, icd->scl_pin, iic->pin_scl); 1175 + iic->pin_sda, iic->pin_scl); 1181 1176 1182 1177 return sm501_register_device(sm, pdev); 1183 1178 }
+111 -1
drivers/misc/eeprom/at24.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/init.h> 14 14 #include <linux/module.h> 15 + #include <linux/of_device.h> 15 16 #include <linux/slab.h> 16 17 #include <linux/delay.h> 17 18 #include <linux/mutex.h> ··· 25 24 #include <linux/i2c.h> 26 25 #include <linux/nvmem-provider.h> 27 26 #include <linux/platform_data/at24.h> 27 + #include <linux/pm_runtime.h> 28 28 29 29 /* 30 30 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. ··· 176 174 { /* END OF LIST */ } 177 175 }; 178 176 MODULE_DEVICE_TABLE(i2c, at24_ids); 177 + 178 + static const struct of_device_id at24_of_match[] = { 179 + { 180 + .compatible = "atmel,24c00", 181 + .data = (void *)AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) 182 + }, 183 + { 184 + .compatible = "atmel,24c01", 185 + .data = (void *)AT24_DEVICE_MAGIC(1024 / 8, 0) 186 + }, 187 + { 188 + .compatible = "atmel,24c02", 189 + .data = (void *)AT24_DEVICE_MAGIC(2048 / 8, 0) 190 + }, 191 + { 192 + .compatible = "atmel,spd", 193 + .data = (void *)AT24_DEVICE_MAGIC(2048 / 8, 194 + AT24_FLAG_READONLY | AT24_FLAG_IRUGO) 195 + }, 196 + { 197 + .compatible = "atmel,24c04", 198 + .data = (void *)AT24_DEVICE_MAGIC(4096 / 8, 0) 199 + }, 200 + { 201 + .compatible = "atmel,24c08", 202 + .data = (void *)AT24_DEVICE_MAGIC(8192 / 8, 0) 203 + }, 204 + { 205 + .compatible = "atmel,24c16", 206 + .data = (void *)AT24_DEVICE_MAGIC(16384 / 8, 0) 207 + }, 208 + { 209 + .compatible = "atmel,24c32", 210 + .data = (void *)AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) 211 + }, 212 + { 213 + .compatible = "atmel,24c64", 214 + .data = (void *)AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) 215 + }, 216 + { 217 + .compatible = "atmel,24c128", 218 + .data = (void *)AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) 219 + }, 220 + { 221 + .compatible = "atmel,24c256", 222 + .data = (void *)AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) 223 + }, 224 + { 225 + .compatible = "atmel,24c512", 226 + .data = (void *)AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) 227 + }, 228 + { 229 + .compatible = "atmel,24c1024", 230 + .data = (void *)AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16) 231 + }, 232 + { }, 233 + }; 234 + MODULE_DEVICE_TABLE(of, at24_of_match); 179 235 180 236 static const struct acpi_device_id at24_acpi_ids[] = { 181 237 { "INT3499", AT24_DEVICE_MAGIC(8192 / 8, 0) }, ··· 561 501 static int at24_read(void *priv, unsigned int off, void *val, size_t count) 562 502 { 563 503 struct at24_data *at24 = priv; 504 + struct i2c_client *client; 564 505 char *buf = val; 506 + int ret; 565 507 566 508 if (unlikely(!count)) 567 509 return count; 510 + 511 + client = at24_translate_offset(at24, &off); 512 + 513 + ret = pm_runtime_get_sync(&client->dev); 514 + if (ret < 0) { 515 + pm_runtime_put_noidle(&client->dev); 516 + return ret; 517 + } 568 518 569 519 /* 570 520 * Read data from chip, protecting against concurrent updates ··· 588 518 status = at24->read_func(at24, buf, off, count); 589 519 if (status < 0) { 590 520 mutex_unlock(&at24->lock); 521 + pm_runtime_put(&client->dev); 591 522 return status; 592 523 } 593 524 buf += status; ··· 598 527 599 528 mutex_unlock(&at24->lock); 600 529 530 + pm_runtime_put(&client->dev); 531 + 601 532 return 0; 602 533 } 603 534 604 535 static int at24_write(void *priv, unsigned int off, void *val, size_t count) 605 536 { 606 537 struct at24_data *at24 = priv; 538 + struct i2c_client *client; 607 539 char *buf = val; 540 + int ret; 608 541 609 542 if (unlikely(!count)) 610 543 return -EINVAL; 544 + 545 + client = at24_translate_offset(at24, &off); 546 + 547 + ret = pm_runtime_get_sync(&client->dev); 548 + if (ret < 0) { 549 + pm_runtime_put_noidle(&client->dev); 550 + return ret; 551 + } 611 552 612 553 /* 613 554 * Write data to chip, protecting against concurrent updates ··· 633 550 status = at24->write_func(at24, buf, off, count); 634 551 if (status < 0) { 635 552 mutex_unlock(&at24->lock); 553 + pm_runtime_put(&client->dev); 636 554 return status; 637 555 } 638 556 buf += status; ··· 642 558 } 643 559 644 560 mutex_unlock(&at24->lock); 561 + 562 + pm_runtime_put(&client->dev); 645 563 646 564 return 0; 647 565 } ··· 655 569 656 570 if (device_property_present(dev, "read-only")) 657 571 chip->flags |= AT24_FLAG_READONLY; 572 + 573 + err = device_property_read_u32(dev, "size", &val); 574 + if (!err) 575 + chip->byte_len = val; 658 576 659 577 err = device_property_read_u32(dev, "pagesize", &val); 660 578 if (!err) { ··· 688 598 if (client->dev.platform_data) { 689 599 chip = *(struct at24_platform_data *)client->dev.platform_data; 690 600 } else { 691 - if (id) { 601 + /* 602 + * The I2C core allows OF nodes compatibles to match against the 603 + * I2C device ID table as a fallback, so check not only if an OF 604 + * node is present but also if it matches an OF device ID entry. 605 + */ 606 + if (client->dev.of_node && 607 + of_match_device(at24_of_match, &client->dev)) { 608 + magic = (kernel_ulong_t) 609 + of_device_get_match_data(&client->dev); 610 + } else if (id) { 692 611 magic = id->driver_data; 693 612 } else { 694 613 const struct acpi_device_id *aid; ··· 838 739 839 740 i2c_set_clientdata(client, at24); 840 741 742 + /* enable runtime pm */ 743 + pm_runtime_set_active(&client->dev); 744 + pm_runtime_enable(&client->dev); 745 + 841 746 /* 842 747 * Perform a one-byte test read to verify that the 843 748 * chip is functional. 844 749 */ 845 750 err = at24_read(at24, 0, &test_byte, 1); 751 + pm_runtime_idle(&client->dev); 846 752 if (err) { 847 753 err = -ENODEV; 848 754 goto err_clients; ··· 895 791 if (at24->client[i]) 896 792 i2c_unregister_device(at24->client[i]); 897 793 794 + pm_runtime_disable(&client->dev); 795 + 898 796 return err; 899 797 } 900 798 ··· 912 806 for (i = 1; i < at24->num_addresses; i++) 913 807 i2c_unregister_device(at24->client[i]); 914 808 809 + pm_runtime_disable(&client->dev); 810 + pm_runtime_set_suspended(&client->dev); 811 + 915 812 return 0; 916 813 } 917 814 ··· 923 814 static struct i2c_driver at24_driver = { 924 815 .driver = { 925 816 .name = "at24", 817 + .of_match_table = at24_of_match, 926 818 .acpi_match_table = ACPI_PTR(at24_acpi_ids), 927 819 }, 928 820 .probe = at24_probe,
+14
drivers/power/supply/Kconfig
··· 184 184 help 185 185 Say Y to include support for SBS compilant battery chargers. 186 186 187 + config MANAGER_SBS 188 + tristate "Smart Battery System Manager" 189 + depends on I2C && I2C_MUX && GPIOLIB 190 + select I2C_SMBUS 191 + help 192 + Say Y here to include support for Smart Battery System Manager 193 + ICs. The driver reports online and charging status via sysfs. 194 + It presents itself also as I2C mux which allows to bind 195 + smart battery driver to its ports. 196 + Supported is for example LTC1760. 197 + 198 + This driver can also be built as a module. If so, the module will be 199 + called sbs-manager. 200 + 187 201 config BATTERY_BQ27XXX 188 202 tristate "BQ27xxx battery driver" 189 203 help
+1
drivers/power/supply/Makefile
··· 37 37 obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o 38 38 obj-$(CONFIG_BATTERY_SBS) += sbs-battery.o 39 39 obj-$(CONFIG_CHARGER_SBS) += sbs-charger.o 40 + obj-$(CONFIG_MANAGER_SBS) += sbs-manager.o 40 41 obj-$(CONFIG_BATTERY_BQ27XXX) += bq27xxx_battery.o 41 42 obj-$(CONFIG_BATTERY_BQ27XXX_I2C) += bq27xxx_battery_i2c.o 42 43 obj-$(CONFIG_BATTERY_BQ27XXX_HDQ) += bq27xxx_battery_hdq.o
+17 -18
drivers/power/supply/sbs-battery.c
··· 177 177 static int sbs_read_word_data(struct i2c_client *client, u8 address) 178 178 { 179 179 struct sbs_info *chip = i2c_get_clientdata(client); 180 + int retries = chip->i2c_retry_count; 180 181 s32 ret = 0; 181 - int retries = 1; 182 - 183 - retries = chip->i2c_retry_count; 184 182 185 183 while (retries > 0) { 186 184 ret = i2c_smbus_read_word_data(client, address); ··· 202 204 { 203 205 struct sbs_info *chip = i2c_get_clientdata(client); 204 206 s32 ret = 0, block_length = 0; 205 - int retries_length = 1, retries_block = 1; 207 + int retries_length, retries_block; 206 208 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; 207 209 208 210 retries_length = chip->i2c_retry_count; ··· 267 269 u16 value) 268 270 { 269 271 struct sbs_info *chip = i2c_get_clientdata(client); 272 + int retries = chip->i2c_retry_count; 270 273 s32 ret = 0; 271 - int retries = 1; 272 - 273 - retries = chip->i2c_retry_count; 274 274 275 275 while (retries > 0) { 276 276 ret = i2c_smbus_write_word_data(client, address, value); ··· 317 321 union power_supply_propval *val) 318 322 { 319 323 s32 ret; 320 - struct sbs_info *chip = i2c_get_clientdata(client); 321 - 322 - if (psp == POWER_SUPPLY_PROP_PRESENT && chip->gpio_detect) { 323 - ret = gpiod_get_value_cansleep(chip->gpio_detect); 324 - if (ret < 0) 325 - return ret; 326 - val->intval = ret; 327 - chip->is_present = val->intval; 328 - return ret; 329 - } 330 324 331 325 /* 332 326 * Write to ManufacturerAccess with ManufacturerAccess command ··· 556 570 if (ret < 0) 557 571 return ret; 558 572 559 - ret = sprintf(sbs_serial, "%04x", ret); 573 + sprintf(sbs_serial, "%04x", ret); 560 574 val->strval = sbs_serial; 561 575 562 576 return 0; ··· 583 597 int ret = 0; 584 598 struct sbs_info *chip = power_supply_get_drvdata(psy); 585 599 struct i2c_client *client = chip->client; 600 + 601 + if (chip->gpio_detect) { 602 + ret = gpiod_get_value_cansleep(chip->gpio_detect); 603 + if (ret < 0) 604 + return ret; 605 + if (psp == POWER_SUPPLY_PROP_PRESENT) { 606 + val->intval = ret; 607 + chip->is_present = val->intval; 608 + return 0; 609 + } 610 + if (ret == 0) 611 + return -ENODATA; 612 + } 586 613 587 614 switch (psp) { 588 615 case POWER_SUPPLY_PROP_PRESENT:
+445
drivers/power/supply/sbs-manager.c
··· 1 + /* 2 + * Driver for SBS compliant Smart Battery System Managers 3 + * 4 + * The device communicates via i2c at address 0x0a and multiplexes access to up 5 + * to four smart batteries at address 0x0b. 6 + * 7 + * Via sysfs interface the online state and charge type are presented. 8 + * 9 + * Datasheet SBSM: http://sbs-forum.org/specs/sbsm100b.pdf 10 + * Datasheet LTC1760: http://cds.linear.com/docs/en/datasheet/1760fb.pdf 11 + * 12 + * Karl-Heinz Schneider <karl-heinz@schneider-inet.de> 13 + * 14 + * This program is free software; you can redistribute it and/or modify 15 + * it under the terms of the GNU General Public License version 2 as 16 + * published by the Free Software Foundation. 17 + */ 18 + 19 + #include <linux/gpio.h> 20 + #include <linux/module.h> 21 + #include <linux/i2c.h> 22 + #include <linux/i2c-mux.h> 23 + #include <linux/power_supply.h> 24 + #include <linux/property.h> 25 + 26 + #define SBSM_MAX_BATS 4 27 + #define SBSM_RETRY_CNT 3 28 + 29 + /* registers addresses */ 30 + #define SBSM_CMD_BATSYSSTATE 0x01 31 + #define SBSM_CMD_BATSYSSTATECONT 0x02 32 + #define SBSM_CMD_BATSYSINFO 0x04 33 + #define SBSM_CMD_LTC 0x3c 34 + 35 + #define SBSM_MASK_BAT_SUPPORTED GENMASK(3, 0) 36 + #define SBSM_MASK_CHARGE_BAT GENMASK(7, 4) 37 + #define SBSM_BIT_AC_PRESENT BIT(0) 38 + #define SBSM_BIT_TURBO BIT(7) 39 + 40 + #define SBSM_SMB_BAT_OFFSET 11 41 + struct sbsm_data { 42 + struct i2c_client *client; 43 + struct i2c_mux_core *muxc; 44 + 45 + struct power_supply *psy; 46 + 47 + u8 cur_chan; /* currently selected channel */ 48 + struct gpio_chip chip; 49 + bool is_ltc1760; /* special capabilities */ 50 + 51 + unsigned int supported_bats; 52 + unsigned int last_state; 53 + unsigned int last_state_cont; 54 + }; 55 + 56 + static enum power_supply_property sbsm_props[] = { 57 + POWER_SUPPLY_PROP_ONLINE, 58 + POWER_SUPPLY_PROP_CHARGE_TYPE, 59 + }; 60 + 61 + static int sbsm_read_word(struct i2c_client *client, u8 address) 62 + { 63 + int reg, retries; 64 + 65 + for (retries = SBSM_RETRY_CNT; retries > 0; retries--) { 66 + reg = i2c_smbus_read_word_data(client, address); 67 + if (reg >= 0) 68 + break; 69 + } 70 + 71 + if (reg < 0) { 72 + dev_err(&client->dev, "failed to read register 0x%02x\n", 73 + address); 74 + } 75 + 76 + return reg; 77 + } 78 + 79 + static int sbsm_write_word(struct i2c_client *client, u8 address, u16 word) 80 + { 81 + int ret, retries; 82 + 83 + for (retries = SBSM_RETRY_CNT; retries > 0; retries--) { 84 + ret = i2c_smbus_write_word_data(client, address, word); 85 + if (ret >= 0) 86 + break; 87 + } 88 + if (ret < 0) 89 + dev_err(&client->dev, "failed to write to register 0x%02x\n", 90 + address); 91 + 92 + return ret; 93 + } 94 + 95 + static int sbsm_get_property(struct power_supply *psy, 96 + enum power_supply_property psp, 97 + union power_supply_propval *val) 98 + { 99 + struct sbsm_data *data = power_supply_get_drvdata(psy); 100 + int regval = 0; 101 + 102 + switch (psp) { 103 + case POWER_SUPPLY_PROP_ONLINE: 104 + regval = sbsm_read_word(data->client, SBSM_CMD_BATSYSSTATECONT); 105 + if (regval < 0) 106 + return regval; 107 + val->intval = !!(regval & SBSM_BIT_AC_PRESENT); 108 + break; 109 + 110 + case POWER_SUPPLY_PROP_CHARGE_TYPE: 111 + regval = sbsm_read_word(data->client, SBSM_CMD_BATSYSSTATE); 112 + if (regval < 0) 113 + return regval; 114 + 115 + if ((regval & SBSM_MASK_CHARGE_BAT) == 0) { 116 + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; 117 + return 0; 118 + } 119 + val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; 120 + 121 + if (data->is_ltc1760) { 122 + /* charge mode fast if turbo is active */ 123 + regval = sbsm_read_word(data->client, SBSM_CMD_LTC); 124 + if (regval < 0) 125 + return regval; 126 + else if (regval & SBSM_BIT_TURBO) 127 + val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; 128 + } 129 + break; 130 + 131 + default: 132 + return -EINVAL; 133 + } 134 + 135 + return 0; 136 + } 137 + 138 + static int sbsm_prop_is_writeable(struct power_supply *psy, 139 + enum power_supply_property psp) 140 + { 141 + struct sbsm_data *data = power_supply_get_drvdata(psy); 142 + 143 + return (psp == POWER_SUPPLY_PROP_CHARGE_TYPE) && data->is_ltc1760; 144 + } 145 + 146 + static int sbsm_set_property(struct power_supply *psy, 147 + enum power_supply_property psp, 148 + const union power_supply_propval *val) 149 + { 150 + struct sbsm_data *data = power_supply_get_drvdata(psy); 151 + int ret = -EINVAL; 152 + u16 regval; 153 + 154 + switch (psp) { 155 + case POWER_SUPPLY_PROP_CHARGE_TYPE: 156 + /* write 1 to TURBO if type fast is given */ 157 + if (!data->is_ltc1760) 158 + break; 159 + regval = val->intval == 160 + POWER_SUPPLY_CHARGE_TYPE_FAST ? SBSM_BIT_TURBO : 0; 161 + ret = sbsm_write_word(data->client, SBSM_CMD_LTC, regval); 162 + break; 163 + 164 + default: 165 + break; 166 + } 167 + 168 + return ret; 169 + } 170 + 171 + /* 172 + * Switch to battery 173 + * Parameter chan is directly the content of SMB_BAT* nibble 174 + */ 175 + static int sbsm_select(struct i2c_mux_core *muxc, u32 chan) 176 + { 177 + struct sbsm_data *data = i2c_mux_priv(muxc); 178 + struct device *dev = &data->client->dev; 179 + int ret = 0; 180 + u16 reg; 181 + 182 + if (data->cur_chan == chan) 183 + return ret; 184 + 185 + /* chan goes from 1 ... 4 */ 186 + reg = 1 << BIT(SBSM_SMB_BAT_OFFSET + chan); 187 + ret = sbsm_write_word(data->client, SBSM_CMD_BATSYSSTATE, reg); 188 + if (ret) 189 + dev_err(dev, "Failed to select channel %i\n", chan); 190 + else 191 + data->cur_chan = chan; 192 + 193 + return ret; 194 + } 195 + 196 + static int sbsm_gpio_get_value(struct gpio_chip *gc, unsigned int off) 197 + { 198 + struct sbsm_data *data = gpiochip_get_data(gc); 199 + int ret; 200 + 201 + ret = sbsm_read_word(data->client, SBSM_CMD_BATSYSSTATE); 202 + if (ret < 0) 203 + return ret; 204 + 205 + return ret & BIT(off); 206 + } 207 + 208 + /* 209 + * This needs to be defined or the GPIO lib fails to register the pin. 210 + * But the 'gpio' is always an input. 211 + */ 212 + static int sbsm_gpio_direction_input(struct gpio_chip *gc, unsigned int off) 213 + { 214 + return 0; 215 + } 216 + 217 + static int sbsm_do_alert(struct device *dev, void *d) 218 + { 219 + struct i2c_client *client = i2c_verify_client(dev); 220 + struct i2c_driver *driver; 221 + 222 + if (!client || client->addr != 0x0b) 223 + return 0; 224 + 225 + device_lock(dev); 226 + if (client->dev.driver) { 227 + driver = to_i2c_driver(client->dev.driver); 228 + if (driver->alert) 229 + driver->alert(client, I2C_PROTOCOL_SMBUS_ALERT, 0); 230 + else 231 + dev_warn(&client->dev, "no driver alert()!\n"); 232 + } else { 233 + dev_dbg(&client->dev, "alert with no driver\n"); 234 + } 235 + device_unlock(dev); 236 + 237 + return -EBUSY; 238 + } 239 + 240 + static void sbsm_alert(struct i2c_client *client, enum i2c_alert_protocol prot, 241 + unsigned int d) 242 + { 243 + struct sbsm_data *sbsm = i2c_get_clientdata(client); 244 + 245 + int ret, i, irq_bat = 0, state = 0; 246 + 247 + ret = sbsm_read_word(sbsm->client, SBSM_CMD_BATSYSSTATE); 248 + if (ret >= 0) { 249 + irq_bat = ret ^ sbsm->last_state; 250 + sbsm->last_state = ret; 251 + state = ret; 252 + } 253 + 254 + ret = sbsm_read_word(sbsm->client, SBSM_CMD_BATSYSSTATECONT); 255 + if ((ret >= 0) && 256 + ((ret ^ sbsm->last_state_cont) & SBSM_BIT_AC_PRESENT)) { 257 + irq_bat |= sbsm->supported_bats & state; 258 + power_supply_changed(sbsm->psy); 259 + } 260 + sbsm->last_state_cont = ret; 261 + 262 + for (i = 0; i < SBSM_MAX_BATS; i++) { 263 + if (irq_bat & BIT(i)) { 264 + device_for_each_child(&sbsm->muxc->adapter[i]->dev, 265 + NULL, sbsm_do_alert); 266 + } 267 + } 268 + } 269 + 270 + static int sbsm_gpio_setup(struct sbsm_data *data) 271 + { 272 + struct gpio_chip *gc = &data->chip; 273 + struct i2c_client *client = data->client; 274 + struct device *dev = &client->dev; 275 + int ret; 276 + 277 + if (!device_property_present(dev, "gpio-controller")) 278 + return 0; 279 + 280 + ret = sbsm_read_word(client, SBSM_CMD_BATSYSSTATE); 281 + if (ret < 0) 282 + return ret; 283 + data->last_state = ret; 284 + 285 + ret = sbsm_read_word(client, SBSM_CMD_BATSYSSTATECONT); 286 + if (ret < 0) 287 + return ret; 288 + data->last_state_cont = ret; 289 + 290 + gc->get = sbsm_gpio_get_value; 291 + gc->direction_input = sbsm_gpio_direction_input; 292 + gc->can_sleep = true; 293 + gc->base = -1; 294 + gc->ngpio = SBSM_MAX_BATS; 295 + gc->label = client->name; 296 + gc->parent = dev; 297 + gc->owner = THIS_MODULE; 298 + 299 + ret = devm_gpiochip_add_data(dev, gc, data); 300 + if (ret) { 301 + dev_err(dev, "devm_gpiochip_add_data failed: %d\n", ret); 302 + return ret; 303 + } 304 + 305 + return ret; 306 + } 307 + 308 + static const struct power_supply_desc sbsm_default_psy_desc = { 309 + .type = POWER_SUPPLY_TYPE_MAINS, 310 + .properties = sbsm_props, 311 + .num_properties = ARRAY_SIZE(sbsm_props), 312 + .get_property = &sbsm_get_property, 313 + .set_property = &sbsm_set_property, 314 + .property_is_writeable = &sbsm_prop_is_writeable, 315 + }; 316 + 317 + static int sbsm_probe(struct i2c_client *client, 318 + const struct i2c_device_id *id) 319 + { 320 + struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 321 + struct sbsm_data *data; 322 + struct device *dev = &client->dev; 323 + struct power_supply_desc *psy_desc; 324 + struct power_supply_config psy_cfg = {}; 325 + int ret = 0, i; 326 + 327 + /* Device listens only at address 0x0a */ 328 + if (client->addr != 0x0a) 329 + return -EINVAL; 330 + 331 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 332 + return -EPFNOSUPPORT; 333 + 334 + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 335 + if (!data) 336 + return -ENOMEM; 337 + 338 + i2c_set_clientdata(client, data); 339 + 340 + data->client = client; 341 + data->is_ltc1760 = !!strstr(id->name, "ltc1760"); 342 + 343 + ret = sbsm_read_word(client, SBSM_CMD_BATSYSINFO); 344 + if (ret < 0) 345 + return ret; 346 + data->supported_bats = ret & SBSM_MASK_BAT_SUPPORTED; 347 + data->muxc = i2c_mux_alloc(adapter, dev, SBSM_MAX_BATS, 0, 348 + I2C_MUX_LOCKED, &sbsm_select, NULL); 349 + if (!data->muxc) { 350 + dev_err(dev, "failed to alloc i2c mux\n"); 351 + ret = -ENOMEM; 352 + goto err_mux_alloc; 353 + } 354 + data->muxc->priv = data; 355 + 356 + /* register muxed i2c channels. One for each supported battery */ 357 + for (i = 0; i < SBSM_MAX_BATS; ++i) { 358 + if (data->supported_bats & BIT(i)) { 359 + ret = i2c_mux_add_adapter(data->muxc, 0, i + 1, 0); 360 + if (ret) 361 + break; 362 + } 363 + } 364 + if (ret) { 365 + dev_err(dev, "failed to register i2c mux channel %d\n", i + 1); 366 + goto err_mux_register; 367 + } 368 + 369 + psy_desc = devm_kmemdup(dev, &sbsm_default_psy_desc, 370 + sizeof(struct power_supply_desc), 371 + GFP_KERNEL); 372 + if (!psy_desc) { 373 + ret = -ENOMEM; 374 + goto err_psy; 375 + } 376 + 377 + psy_desc->name = devm_kasprintf(dev, GFP_KERNEL, "sbsm-%s", 378 + dev_name(&client->dev)); 379 + if (!psy_desc->name) { 380 + ret = -ENOMEM; 381 + goto err_psy; 382 + } 383 + ret = sbsm_gpio_setup(data); 384 + if (ret < 0) 385 + goto err_psy; 386 + 387 + psy_cfg.drv_data = data; 388 + psy_cfg.of_node = dev->of_node; 389 + data->psy = devm_power_supply_register(dev, psy_desc, &psy_cfg); 390 + if (IS_ERR(data->psy)) { 391 + ret = PTR_ERR(data->psy); 392 + dev_err(dev, "failed to register power supply %s\n", 393 + psy_desc->name); 394 + goto err_psy; 395 + } 396 + 397 + return 0; 398 + 399 + err_psy: 400 + err_mux_register: 401 + i2c_mux_del_adapters(data->muxc); 402 + 403 + err_mux_alloc: 404 + return ret; 405 + } 406 + 407 + static int sbsm_remove(struct i2c_client *client) 408 + { 409 + struct sbsm_data *data = i2c_get_clientdata(client); 410 + 411 + i2c_mux_del_adapters(data->muxc); 412 + return 0; 413 + } 414 + 415 + static const struct i2c_device_id sbsm_ids[] = { 416 + { "sbs-manager", 0 }, 417 + { "ltc1760", 0 }, 418 + { } 419 + }; 420 + MODULE_DEVICE_TABLE(i2c, sbsm_ids); 421 + 422 + #ifdef CONFIG_OF 423 + static const struct of_device_id sbsm_dt_ids[] = { 424 + { .compatible = "sbs,sbs-manager" }, 425 + { .compatible = "lltc,ltc1760" }, 426 + { } 427 + }; 428 + MODULE_DEVICE_TABLE(of, sbsm_dt_ids); 429 + #endif 430 + 431 + static struct i2c_driver sbsm_driver = { 432 + .driver = { 433 + .name = "sbsm", 434 + .of_match_table = of_match_ptr(sbsm_dt_ids), 435 + }, 436 + .probe = sbsm_probe, 437 + .remove = sbsm_remove, 438 + .alert = sbsm_alert, 439 + .id_table = sbsm_ids 440 + }; 441 + module_i2c_driver(sbsm_driver); 442 + 443 + MODULE_LICENSE("GPL"); 444 + MODULE_AUTHOR("Karl-Heinz Schneider <karl-heinz@schneider-inet.de>"); 445 + MODULE_DESCRIPTION("SBSM Smart Battery System Manager");
+6
include/linux/gpio/consumer.h
··· 29 29 #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) 30 30 #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) 31 31 #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) 32 + #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) 32 33 33 34 /** 34 35 * Optional flags that can be passed to one of gpiod_* to configure direction ··· 41 40 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, 42 41 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | 43 42 GPIOD_FLAGS_BIT_DIR_VAL, 43 + GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | 44 + GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_OPEN_DRAIN, 45 + GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | 46 + GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL | 47 + GPIOD_FLAGS_BIT_OPEN_DRAIN, 44 48 }; 45 49 46 50 #ifdef CONFIG_GPIOLIB
-4
include/linux/i2c-gpio.h
··· 12 12 13 13 /** 14 14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio 15 - * @sda_pin: GPIO pin ID to use for SDA 16 - * @scl_pin: GPIO pin ID to use for SCL 17 15 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz 18 16 * @timeout: clock stretching timeout in jiffies. If the slave keeps 19 17 * SCL low for longer than this, the transfer will time out. ··· 24 26 * @scl_is_output_only: SCL output drivers cannot be turned off. 25 27 */ 26 28 struct i2c_gpio_platform_data { 27 - unsigned int sda_pin; 28 - unsigned int scl_pin; 29 29 int udelay; 30 30 int timeout; 31 31 unsigned int sda_is_open_drain:1;
+9 -1
include/linux/i2c-smbus.h
··· 42 42 * properly set. 43 43 */ 44 44 struct i2c_smbus_alert_setup { 45 - unsigned int alert_edge_triggered:1; 46 45 int irq; 47 46 }; 48 47 49 48 struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, 50 49 struct i2c_smbus_alert_setup *setup); 51 50 int i2c_handle_smbus_alert(struct i2c_client *ara); 51 + 52 + #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) 53 + int of_i2c_setup_smbus_alert(struct i2c_adapter *adap); 54 + #else 55 + static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap) 56 + { 57 + return 0; 58 + } 59 + #endif 52 60 53 61 #endif /* _LINUX_I2C_SMBUS_H */
+2
include/linux/i2c.h
··· 304 304 * @type: chip type, to initialize i2c_client.name 305 305 * @flags: to initialize i2c_client.flags 306 306 * @addr: stored in i2c_client.addr 307 + * @dev_name: Overrides the default <busnr>-<addr> dev_name if set 307 308 * @platform_data: stored in i2c_client.dev.platform_data 308 309 * @archdata: copied into i2c_client.dev.archdata 309 310 * @of_node: pointer to OpenFirmware device node ··· 329 328 char type[I2C_NAME_SIZE]; 330 329 unsigned short flags; 331 330 unsigned short addr; 331 + const char *dev_name; 332 332 void *platform_data; 333 333 struct dev_archdata *archdata; 334 334 struct device_node *of_node;
-10
include/linux/platform_data/i2c-nuc900.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef __ASM_ARCH_NUC900_I2C_H 3 - #define __ASM_ARCH_NUC900_I2C_H 4 - 5 - struct nuc900_platform_i2c { 6 - int bus_num; 7 - unsigned long bus_freq; 8 - }; 9 - 10 - #endif /* __ASM_ARCH_NUC900_I2C_H */