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

Merge tag 'i2c-for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c updates from Wolfram Sang:
"I2C has largely driver updates for 6.7, i.e. feature additions (like
adding transfers while in atomic mode), using new helpers (like
devm_clk_get_enabled), new IDs, documentation fixes and additions...
you name it.

The core got a memleak fix and better support for nested muxes"

* tag 'i2c-for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (53 commits)
i2c: s3c2410: make i2c_s3c_irq_nextbyte() void
i2c: qcom-geni: add ACPI device id for sc8180x
Documentation: i2c: add fault code for not supporting 10 bit addresses
i2c: sun6i-p2wi: Prevent potential division by zero
i2c: mux: demux-pinctrl: Convert to use sysfs_emit_at() API
i2c: i801: Use new helper acpi_use_parent_companion
ACPI: Add helper acpi_use_parent_companion
MAINTAINERS: add YAML file for i2c-demux-pinctrl
i2c: core: fix lockdep warning for sparsely nested adapter chain
i2c: axxia: eliminate kernel-doc warnings
dt-bindings: i2c: i2c-demux-pinctrl: Convert to json-schema
i2c: stm32f7: Use devm_clk_get_enabled()
i2c: stm32f4: Use devm_clk_get_enabled()
i2c: stm32f7: add description of atomic in struct stm32f7_i2c_dev
i2c: fix memleak in i2c_new_client_device()
i2c: exynos5: Calculate t_scl_l, t_scl_h according to i2c spec
i2c: i801: Simplify class-based client device instantiation
i2c: exynos5: add support for atomic transfers
i2c: at91-core: Use devm_clk_get_enabled()
eeprom: at24: add ST M24C64-D Additional Write lockable page support
...

+596 -427
+4
Documentation/devicetree/bindings/eeprom/at24.yaml
··· 69 69 - items: 70 70 pattern: c32$ 71 71 - items: 72 + pattern: c32d-wl$ 73 + - items: 72 74 pattern: cs32$ 73 75 - items: 74 76 pattern: c64$ 77 + - items: 78 + pattern: c64d-wl$ 75 79 - items: 76 80 pattern: cs64$ 77 81 - items:
-135
Documentation/devicetree/bindings/i2c/i2c-demux-pinctrl.txt
··· 1 - Pinctrl-based I2C Bus DeMux 2 - 3 - This binding describes an I2C bus demultiplexer that uses pin multiplexing to 4 - route the I2C signals, and represents the pin multiplexing configuration using 5 - the pinctrl device tree bindings. This may be used to select one I2C IP core at 6 - runtime which may have a better feature set for a given task than another I2C 7 - IP core on the SoC. The most simple example is to fall back to GPIO bitbanging 8 - if your current runtime configuration hits an errata of the internal IP core. 9 - 10 - +-------------------------------+ 11 - | SoC | 12 - | | +-----+ +-----+ 13 - | +------------+ | | dev | | dev | 14 - | |I2C IP Core1|--\ | +-----+ +-----+ 15 - | +------------+ \-------+ | | | 16 - | |Pinctrl|--|------+--------+ 17 - | +------------+ +-------+ | 18 - | |I2C IP Core2|--/ | 19 - | +------------+ | 20 - | | 21 - +-------------------------------+ 22 - 23 - Required properties: 24 - - compatible: "i2c-demux-pinctrl" 25 - - i2c-parent: List of phandles of I2C masters available for selection. The first 26 - one will be used as default. 27 - - i2c-bus-name: The name of this bus. Also needed as pinctrl-name for the I2C 28 - parents. 29 - 30 - Furthermore, I2C mux properties and child nodes. See i2c-mux.yaml in this 31 - directory. 32 - 33 - Example: 34 - 35 - Here is a snipplet for a bus to be demuxed. It contains various i2c clients for 36 - HDMI, so the bus is named "i2c-hdmi": 37 - 38 - i2chdmi: i2c@8 { 39 - 40 - compatible = "i2c-demux-pinctrl"; 41 - i2c-parent = <&gpioi2c>, <&iic2>, <&i2c2>; 42 - i2c-bus-name = "i2c-hdmi"; 43 - #address-cells = <1>; 44 - #size-cells = <0>; 45 - 46 - ak4643: sound-codec@12 { 47 - compatible = "asahi-kasei,ak4643"; 48 - 49 - #sound-dai-cells = <0>; 50 - reg = <0x12>; 51 - }; 52 - 53 - composite-in@20 { 54 - compatible = "adi,adv7180"; 55 - reg = <0x20>; 56 - remote = <&vin1>; 57 - 58 - port { 59 - adv7180: endpoint { 60 - bus-width = <8>; 61 - remote-endpoint = <&vin1ep0>; 62 - }; 63 - }; 64 - }; 65 - 66 - hdmi@39 { 67 - compatible = "adi,adv7511w"; 68 - reg = <0x39>; 69 - interrupt-parent = <&gpio1>; 70 - interrupts = <15 IRQ_TYPE_LEVEL_LOW>; 71 - 72 - adi,input-depth = <8>; 73 - adi,input-colorspace = "rgb"; 74 - adi,input-clock = "1x"; 75 - adi,input-style = <1>; 76 - adi,input-justification = "evenly"; 77 - 78 - ports { 79 - #address-cells = <1>; 80 - #size-cells = <0>; 81 - 82 - port@0 { 83 - reg = <0>; 84 - adv7511_in: endpoint { 85 - remote-endpoint = <&du_out_lvds0>; 86 - }; 87 - }; 88 - 89 - port@1 { 90 - reg = <1>; 91 - adv7511_out: endpoint { 92 - remote-endpoint = <&hdmi_con>; 93 - }; 94 - }; 95 - }; 96 - }; 97 - }; 98 - 99 - And for clarification, here are the snipplets for the i2c-parents: 100 - 101 - gpioi2c: i2c@9 { 102 - #address-cells = <1>; 103 - #size-cells = <0>; 104 - compatible = "i2c-gpio"; 105 - gpios = <&gpio5 6 GPIO_ACTIVE_HIGH /* sda */ 106 - &gpio5 5 GPIO_ACTIVE_HIGH /* scl */ 107 - >; 108 - i2c-gpio,delay-us = <5>; 109 - }; 110 - 111 - ... 112 - 113 - &i2c2 { 114 - pinctrl-0 = <&i2c2_pins>; 115 - pinctrl-names = "i2c-hdmi"; 116 - 117 - clock-frequency = <100000>; 118 - }; 119 - 120 - ... 121 - 122 - &iic2 { 123 - pinctrl-0 = <&iic2_pins>; 124 - pinctrl-names = "i2c-hdmi"; 125 - 126 - clock-frequency = <100000>; 127 - }; 128 - 129 - Please note: 130 - 131 - - pinctrl properties for the parent I2C controllers need a pinctrl state 132 - with the same name as i2c-bus-name, not "default"! 133 - 134 - - the i2c masters must have their status "disabled". This driver will 135 - enable them at runtime when needed.
+172
Documentation/devicetree/bindings/i2c/i2c-demux-pinctrl.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/i2c/i2c-demux-pinctrl.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Pinctrl-based I2C Bus Demultiplexer 8 + 9 + maintainers: 10 + - Wolfram Sang <wsa+renesas@sang-engineering.com> 11 + 12 + description: | 13 + This binding describes an I2C bus demultiplexer that uses pin multiplexing to 14 + route the I2C signals, and represents the pin multiplexing configuration 15 + using the pinctrl device tree bindings. This may be used to select one I2C 16 + IP core at runtime which may have a better feature set for a given task than 17 + another I2C IP core on the SoC. The most simple example is to fall back to 18 + GPIO bitbanging if your current runtime configuration hits an errata of the 19 + internal IP core. 20 + 21 + +-------------------------------+ 22 + | SoC | 23 + | | +-----+ +-----+ 24 + | +------------+ | | dev | | dev | 25 + | |I2C IP Core1|--\ | +-----+ +-----+ 26 + | +------------+ \-------+ | | | 27 + | |Pinctrl|--|------+--------+ 28 + | +------------+ +-------+ | 29 + | |I2C IP Core2|--/ | 30 + | +------------+ | 31 + | | 32 + +-------------------------------+ 33 + 34 + allOf: 35 + - $ref: i2c-mux.yaml 36 + - $ref: /schemas/i2c/i2c-controller.yaml# 37 + 38 + properties: 39 + compatible: 40 + const: i2c-demux-pinctrl 41 + 42 + i2c-parent: 43 + $ref: /schemas/types.yaml#/definitions/phandle-array 44 + description: 45 + List of phandles of I2C masters available for selection. The first one 46 + will be used as default. 47 + 48 + i2c-bus-name: 49 + $ref: /schemas/types.yaml#/definitions/string 50 + description: 51 + The name of this bus. Also needed as pinctrl-name for the I2C parents. 52 + 53 + required: 54 + - compatible 55 + - i2c-parent 56 + - i2c-bus-name 57 + 58 + unevaluatedProperties: false 59 + 60 + examples: 61 + - | 62 + #include <dt-bindings/gpio/gpio.h> 63 + #include <dt-bindings/interrupt-controller/irq.h> 64 + 65 + gpioi2c2: i2c-9 { 66 + #address-cells = <1>; 67 + #size-cells = <0>; 68 + compatible = "i2c-gpio"; 69 + scl-gpios = <&gpio5 5 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; 70 + sda-gpios = <&gpio5 6 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; 71 + i2c-gpio,delay-us = <5>; 72 + 73 + // The I2C controller must have its status "disabled". The I2C bus 74 + // demultiplexer will enable it at runtime when needed. 75 + status = "disabled"; 76 + }; 77 + 78 + iic2: i2c@e6520000 { 79 + reg = <0xe6520000 0x425>; 80 + pinctrl-0 = <&iic2_pins>; 81 + // The pinctrl property for the parent I2C controller needs a pinctrl 82 + // state with the same name as i2c-bus-name in the I2C bus demultiplexer 83 + // node, not "default"! 84 + pinctrl-names = "i2c-hdmi"; 85 + 86 + clock-frequency = <100000>; 87 + 88 + // The I2C controller must have its status "disabled". The I2C bus 89 + // demultiplexer will enable it at runtime when needed. 90 + status = "disabled"; 91 + }; 92 + 93 + i2c2: i2c@e6530000 { 94 + reg = <0 0xe6530000 0 0x40>; 95 + pinctrl-0 = <&i2c2_pins>; 96 + // The pinctrl property for the parent I2C controller needs a pinctrl 97 + // state with the same name as i2c-bus-name in the I2C bus demultiplexer 98 + // node, not "default"! 99 + pinctrl-names = "i2c-hdmi"; 100 + 101 + clock-frequency = <100000>; 102 + 103 + // The I2C controller must have its status "disabled". The I2C bus 104 + // demultiplexer will enable it at runtime when needed. 105 + status = "disabled"; 106 + }; 107 + 108 + // Example for a bus to be demuxed. It contains various I2C clients for 109 + // HDMI, so the bus is named "i2c-hdmi": 110 + i2chdmi: i2c-mux3 { 111 + compatible = "i2c-demux-pinctrl"; 112 + i2c-parent = <&iic2>, <&i2c2>, <&gpioi2c2>; 113 + i2c-bus-name = "i2c-hdmi"; 114 + #address-cells = <1>; 115 + #size-cells = <0>; 116 + 117 + ak4643: codec@12 { 118 + compatible = "asahi-kasei,ak4643"; 119 + #sound-dai-cells = <0>; 120 + reg = <0x12>; 121 + }; 122 + 123 + composite-in@20 { 124 + compatible = "adi,adv7180"; 125 + reg = <0x20>; 126 + 127 + port { 128 + adv7180: endpoint { 129 + bus-width = <8>; 130 + remote-endpoint = <&vin1ep0>; 131 + }; 132 + }; 133 + }; 134 + 135 + hdmi@39 { 136 + compatible = "adi,adv7511w"; 137 + reg = <0x39>; 138 + interrupt-parent = <&gpio1>; 139 + interrupts = <15 IRQ_TYPE_LEVEL_LOW>; 140 + clocks = <&cec_clock>; 141 + clock-names = "cec"; 142 + 143 + avdd-supply = <&fixedregulator1v8>; 144 + dvdd-supply = <&fixedregulator1v8>; 145 + pvdd-supply = <&fixedregulator1v8>; 146 + dvdd-3v-supply = <&fixedregulator3v3>; 147 + bgvdd-supply = <&fixedregulator1v8>; 148 + 149 + adi,input-depth = <8>; 150 + adi,input-colorspace = "rgb"; 151 + adi,input-clock = "1x"; 152 + 153 + ports { 154 + #address-cells = <1>; 155 + #size-cells = <0>; 156 + 157 + port@0 { 158 + reg = <0>; 159 + adv7511_in: endpoint { 160 + remote-endpoint = <&lvds0_out>; 161 + }; 162 + }; 163 + 164 + port@1 { 165 + reg = <1>; 166 + adv7511_out: endpoint { 167 + remote-endpoint = <&hdmi_con_out>; 168 + }; 169 + }; 170 + }; 171 + }; 172 + };
+2
Documentation/devicetree/bindings/i2c/qcom,i2c-cci.yaml
··· 25 25 26 26 - items: 27 27 - enum: 28 + - qcom,sc7280-cci 28 29 - qcom,sdm845-cci 29 30 - qcom,sm6350-cci 30 31 - qcom,sm8250-cci ··· 160 159 compatible: 161 160 contains: 162 161 enum: 162 + - qcom,sc7280-cci 163 163 - qcom,sm8250-cci 164 164 - qcom,sm8450-cci 165 165 then:
+1
Documentation/i2c/busses/i2c-i801.rst
··· 47 47 * Intel Alder Lake (PCH) 48 48 * Intel Raptor Lake (PCH) 49 49 * Intel Meteor Lake (SOC and PCH) 50 + * Intel Birch Stream (SOC) 50 51 51 52 Datasheets: Publicly available at the Intel website 52 53
+4
Documentation/i2c/fault-codes.rst
··· 39 39 specific to their host bus (such as PCI, or the platform bus). 40 40 41 41 42 + EAFNOSUPPORT 43 + Returned by I2C adapters not supporting 10 bit addresses when 44 + they are requested to use such an address. 45 + 42 46 EAGAIN 43 47 Returned by I2C adapters when they lose arbitration in master 44 48 transmit mode: some other master was transmitting different
+1
MAINTAINERS
··· 8825 8825 GENERIC PINCTRL I2C DEMULTIPLEXER DRIVER 8826 8826 M: Wolfram Sang <wsa+renesas@sang-engineering.com> 8827 8827 S: Supported 8828 + F: Documentation/devicetree/bindings/i2c/i2c-demux-pinctrl.yaml 8828 8829 F: drivers/i2c/muxes/i2c-demux-pinctrl.c 8829 8830 8830 8831 GENERIC PM DOMAINS
+1
drivers/i2c/busses/Kconfig
··· 158 158 Alder Lake (PCH) 159 159 Raptor Lake (PCH) 160 160 Meteor Lake (SOC and PCH) 161 + Birch Stream (SOC) 161 162 162 163 This driver can also be built as a module. If so, the module 163 164 will be called i2c-i801.
+3 -7
drivers/i2c/busses/i2c-at91-core.c
··· 221 221 222 222 platform_set_drvdata(pdev, dev); 223 223 224 - dev->clk = devm_clk_get(dev->dev, NULL); 224 + dev->clk = devm_clk_get_enabled(dev->dev, NULL); 225 225 if (IS_ERR(dev->clk)) 226 - return dev_err_probe(dev->dev, PTR_ERR(dev->clk), "no clock defined\n"); 227 - 228 - clk_prepare_enable(dev->clk); 226 + return dev_err_probe(dev->dev, PTR_ERR(dev->clk), 227 + "failed to enable clock\n"); 229 228 230 229 snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91"); 231 230 i2c_set_adapdata(&dev->adapter, dev); ··· 253 254 254 255 rc = i2c_add_numbered_adapter(&dev->adapter); 255 256 if (rc) { 256 - clk_disable_unprepare(dev->clk); 257 - 258 257 pm_runtime_disable(dev->dev); 259 258 pm_runtime_set_suspended(dev->dev); 260 259 ··· 269 272 struct at91_twi_dev *dev = platform_get_drvdata(pdev); 270 273 271 274 i2c_del_adapter(&dev->adapter); 272 - clk_disable_unprepare(dev->clk); 273 275 274 276 pm_runtime_disable(dev->dev); 275 277 pm_runtime_set_suspended(dev->dev);
+5 -3
drivers/i2c/busses/i2c-axxia.c
··· 131 131 * @i2c_clk: clock reference for i2c input clock 132 132 * @bus_clk_rate: current i2c bus clock rate 133 133 * @last: a flag indicating is this is last message in transfer 134 + * @slave: associated &i2c_client 135 + * @irq: platform device IRQ number 134 136 */ 135 137 struct axxia_i2c_dev { 136 138 void __iomem *base; ··· 167 165 writel(int_en | mask, idev->base + MST_INT_ENABLE); 168 166 } 169 167 170 - /** 168 + /* 171 169 * ns_to_clk - Convert time (ns) to clock cycles for the given clock frequency. 172 170 */ 173 171 static u32 ns_to_clk(u64 ns, u32 clk_mhz) ··· 265 263 return (msg->flags & I2C_M_RECV_LEN) != 0; 266 264 } 267 265 268 - /** 266 + /* 269 267 * axxia_i2c_empty_rx_fifo - Fetch data from RX FIFO and update SMBus block 270 268 * transfer length if this is the first byte of such a transfer. 271 269 */ ··· 297 295 return 0; 298 296 } 299 297 300 - /** 298 + /* 301 299 * axxia_i2c_fill_tx_fifo - Fill TX FIFO from current message buffer. 302 300 * @return: Number of bytes left to transfer. 303 301 */
+21 -2
drivers/i2c/busses/i2c-brcmstb.c
··· 160 160 struct completion done; 161 161 u32 clk_freq_hz; 162 162 int data_regsz; 163 + bool atomic; 163 164 }; 164 165 165 166 /* register accessors for both be and le cpu arch */ ··· 241 240 int ret = 0; 242 241 unsigned long timeout = msecs_to_jiffies(I2C_TIMEOUT); 243 242 244 - if (dev->irq >= 0) { 243 + if (dev->irq >= 0 && !dev->atomic) { 245 244 if (!wait_for_completion_timeout(&dev->done, timeout)) 246 245 ret = -ETIMEDOUT; 247 246 } else { ··· 288 287 return rc; 289 288 290 289 /* only if we are in interrupt mode */ 291 - if (dev->irq >= 0) 290 + if (dev->irq >= 0 && !dev->atomic) 292 291 reinit_completion(&dev->done); 293 292 294 293 /* enable BSC CTL interrupt line */ ··· 521 520 522 521 } 523 522 523 + static int brcmstb_i2c_xfer_atomic(struct i2c_adapter *adapter, 524 + struct i2c_msg msgs[], int num) 525 + { 526 + struct brcmstb_i2c_dev *dev = i2c_get_adapdata(adapter); 527 + int ret; 528 + 529 + if (dev->irq >= 0) 530 + disable_irq(dev->irq); 531 + dev->atomic = true; 532 + ret = brcmstb_i2c_xfer(adapter, msgs, num); 533 + dev->atomic = false; 534 + if (dev->irq >= 0) 535 + enable_irq(dev->irq); 536 + 537 + return ret; 538 + } 539 + 524 540 static u32 brcmstb_i2c_functionality(struct i2c_adapter *adap) 525 541 { 526 542 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR ··· 546 528 547 529 static const struct i2c_algorithm brcmstb_i2c_algo = { 548 530 .master_xfer = brcmstb_i2c_xfer, 531 + .master_xfer_atomic = brcmstb_i2c_xfer_atomic, 549 532 .functionality = brcmstb_i2c_functionality, 550 533 }; 551 534
+1 -1
drivers/i2c/busses/i2c-cp2615.c
··· 298 298 if (!adap) 299 299 return -ENOMEM; 300 300 301 - strncpy(adap->name, usbdev->serial, sizeof(adap->name) - 1); 301 + strscpy(adap->name, usbdev->serial, sizeof(adap->name)); 302 302 adap->owner = THIS_MODULE; 303 303 adap->dev.parent = &usbif->dev; 304 304 adap->dev.of_node = usbif->dev.of_node;
+75 -5
drivers/i2c/busses/i2c-exynos5.c
··· 194 194 */ 195 195 int trans_done; 196 196 197 + /* 198 + * Called from atomic context, don't use interrupts. 199 + */ 200 + unsigned int atomic; 201 + 197 202 /* Controller operating frequency */ 198 203 unsigned int op_clock; 199 204 ··· 270 265 * exynos5_i2c_set_timing: updates the registers with appropriate 271 266 * timing values calculated 272 267 * 273 - * Timing values for operation are calculated against either 100kHz 268 + * Timing values for operation are calculated against 100kHz, 400kHz 274 269 * or 1MHz controller operating frequency. 275 270 * 276 271 * Returns 0 on success, -EINVAL if the cycle length cannot ··· 333 328 * 334 329 * Constraints: 4 <= temp, 0 <= CLK_DIV < 256, 2 <= clk_cycle <= 510 335 330 * 331 + * To split SCL clock into low, high periods appropriately, one 332 + * proportion factor for each I2C mode is used, which is calculated 333 + * using this formula. 334 + * ``` 335 + * ((t_low_min + (scl_clock - t_low_min - t_high_min) / 2) / scl_clock) 336 + * ``` 337 + * where: 338 + * t_low_min is the minimal value of low period of the SCL clock in us; 339 + * t_high_min is the minimal value of high period of the SCL clock in us; 340 + * scl_clock is converted from SCL clock frequency into us. 341 + * 342 + * Below are the proportion factors for these I2C modes: 343 + * t_low_min, t_high_min, scl_clock, proportion 344 + * Standard Mode: 4.7us, 4.0us, 10us, 0.535 345 + * Fast Mode: 1.3us, 0.6us, 2.5us, 0.64 346 + * Fast-Plus Mode: 0.5us, 0.26us, 1us, 0.62 347 + * 336 348 */ 337 349 t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7; 338 350 temp = clkin / op_clk - 8 - t_ftl_cycle; ··· 363 341 return -EINVAL; 364 342 } 365 343 366 - t_scl_l = clk_cycle / 2; 367 - t_scl_h = clk_cycle / 2; 344 + /* 345 + * Scale clk_cycle to get t_scl_l using the proption factors for individual I2C modes. 346 + */ 347 + if (op_clk <= I2C_MAX_STANDARD_MODE_FREQ) 348 + t_scl_l = clk_cycle * 535 / 1000; 349 + else if (op_clk <= I2C_MAX_FAST_MODE_FREQ) 350 + t_scl_l = clk_cycle * 64 / 100; 351 + else 352 + t_scl_l = clk_cycle * 62 / 100; 353 + 354 + if (t_scl_l > 0xFF) 355 + t_scl_l = 0xFF; 356 + t_scl_h = clk_cycle - t_scl_l; 368 357 t_start_su = t_scl_l; 369 358 t_start_hd = t_scl_l; 370 359 t_stop_su = t_scl_l; ··· 744 711 spin_unlock_irqrestore(&i2c->lock, flags); 745 712 } 746 713 714 + static bool exynos5_i2c_poll_irqs_timeout(struct exynos5_i2c *i2c, 715 + unsigned long timeout) 716 + { 717 + unsigned long time_left = jiffies + timeout; 718 + 719 + while (time_before(jiffies, time_left) && 720 + !((i2c->trans_done && (i2c->msg->len == i2c->msg_ptr)) || 721 + (i2c->state < 0))) { 722 + while (readl(i2c->regs + HSI2C_INT_ENABLE) & 723 + readl(i2c->regs + HSI2C_INT_STATUS)) 724 + exynos5_i2c_irq(i2c->irq, i2c); 725 + usleep_range(100, 200); 726 + } 727 + return time_before(jiffies, time_left); 728 + } 729 + 747 730 static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, 748 731 struct i2c_msg *msgs, int stop) 749 732 { ··· 774 725 775 726 exynos5_i2c_message_start(i2c, stop); 776 727 777 - timeout = wait_for_completion_timeout(&i2c->msg_complete, 778 - EXYNOS5_I2C_TIMEOUT); 728 + if (!i2c->atomic) 729 + timeout = wait_for_completion_timeout(&i2c->msg_complete, 730 + EXYNOS5_I2C_TIMEOUT); 731 + else 732 + timeout = exynos5_i2c_poll_irqs_timeout(i2c, 733 + EXYNOS5_I2C_TIMEOUT); 734 + 779 735 if (timeout == 0) 780 736 ret = -ETIMEDOUT; 781 737 else ··· 831 777 return ret ?: num; 832 778 } 833 779 780 + static int exynos5_i2c_xfer_atomic(struct i2c_adapter *adap, 781 + struct i2c_msg *msgs, int num) 782 + { 783 + struct exynos5_i2c *i2c = adap->algo_data; 784 + int ret; 785 + 786 + disable_irq(i2c->irq); 787 + i2c->atomic = true; 788 + ret = exynos5_i2c_xfer(adap, msgs, num); 789 + i2c->atomic = false; 790 + enable_irq(i2c->irq); 791 + 792 + return ret; 793 + } 794 + 834 795 static u32 exynos5_i2c_func(struct i2c_adapter *adap) 835 796 { 836 797 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); ··· 853 784 854 785 static const struct i2c_algorithm exynos5_i2c_algorithm = { 855 786 .master_xfer = exynos5_i2c_xfer, 787 + .master_xfer_atomic = exynos5_i2c_xfer_atomic, 856 788 .functionality = exynos5_i2c_func, 857 789 }; 858 790
+1 -6
drivers/i2c/busses/i2c-gpio.c
··· 263 263 * 'fault-injector' dir there. Until then, we have a global dir with 264 264 * all adapters as subdirs. 265 265 */ 266 - if (!i2c_gpio_debug_dir) { 266 + if (!i2c_gpio_debug_dir) 267 267 i2c_gpio_debug_dir = debugfs_create_dir("i2c-fault-injector", NULL); 268 - if (!i2c_gpio_debug_dir) 269 - return; 270 - } 271 268 272 269 priv->debug_dir = debugfs_create_dir(pdev->name, i2c_gpio_debug_dir); 273 - if (!priv->debug_dir) 274 - return; 275 270 276 271 init_completion(&priv->scl_irq_completion); 277 272
+42 -68
drivers/i2c/busses/i2c-i801.c
··· 79 79 * Meteor Lake-P (SOC) 0x7e22 32 hard yes yes yes 80 80 * Meteor Lake SoC-S (SOC) 0xae22 32 hard yes yes yes 81 81 * Meteor Lake PCH-S (PCH) 0x7f23 32 hard yes yes yes 82 + * Birch Stream (SOC) 0x5796 32 hard yes yes yes 82 83 * 83 84 * Features supported by this driver: 84 85 * Software PEC no ··· 232 231 #define PCI_DEVICE_ID_INTEL_JASPER_LAKE_SMBUS 0x4da3 233 232 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_P_SMBUS 0x51a3 234 233 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_M_SMBUS 0x54a3 234 + #define PCI_DEVICE_ID_INTEL_BIRCH_STREAM_SMBUS 0x5796 235 235 #define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4 236 236 #define PCI_DEVICE_ID_INTEL_RAPTOR_LAKE_S_SMBUS 0x7a23 237 237 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_S_SMBUS 0x7aa3 ··· 287 285 u8 *data; 288 286 289 287 #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 290 - const struct i801_mux_config *mux_drvdata; 291 288 struct platform_device *mux_pdev; 292 289 struct gpiod_lookup_table *lookup; 293 290 #endif ··· 294 293 295 294 /* 296 295 * If set to true the host controller registers are reserved for 297 - * ACPI AML use. Protected by acpi_lock. 296 + * ACPI AML use. 298 297 */ 299 298 bool acpi_reserved; 300 - struct mutex acpi_lock; 301 299 }; 302 300 303 301 #define FEATURE_SMBUS_PEC BIT(0) ··· 679 679 return result ? priv->status : -ETIMEDOUT; 680 680 } 681 681 682 + if (len == 1 && read_write == I2C_SMBUS_READ) 683 + smbcmd |= SMBHSTCNT_LAST_BYTE; 684 + outb_p(smbcmd | SMBHSTCNT_START, SMBHSTCNT(priv)); 685 + 682 686 for (i = 1; i <= len; i++) { 683 - if (i == len && read_write == I2C_SMBUS_READ) 684 - smbcmd |= SMBHSTCNT_LAST_BYTE; 685 - outb_p(smbcmd, SMBHSTCNT(priv)); 686 - 687 - if (i == 1) 688 - outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START, 689 - SMBHSTCNT(priv)); 690 - 691 687 status = i801_wait_byte_done(priv); 692 688 if (status) 693 689 return status; ··· 706 710 data->block[0] = len; 707 711 } 708 712 709 - /* Retrieve/store value in SMBBLKDAT */ 710 - if (read_write == I2C_SMBUS_READ) 713 + if (read_write == I2C_SMBUS_READ) { 711 714 data->block[i] = inb_p(SMBBLKDAT(priv)); 715 + if (i == len - 1) 716 + outb_p(smbcmd | SMBHSTCNT_LAST_BYTE, SMBHSTCNT(priv)); 717 + } 718 + 712 719 if (read_write == I2C_SMBUS_WRITE && i+1 <= len) 713 720 outb_p(data->block[i+1], SMBBLKDAT(priv)); 714 721 ··· 874 875 int hwpec, ret; 875 876 struct i801_priv *priv = i2c_get_adapdata(adap); 876 877 877 - mutex_lock(&priv->acpi_lock); 878 - if (priv->acpi_reserved) { 879 - mutex_unlock(&priv->acpi_lock); 878 + if (priv->acpi_reserved) 880 879 return -EBUSY; 881 - } 882 880 883 881 pm_runtime_get_sync(&priv->pci_dev->dev); 884 882 ··· 916 920 917 921 pm_runtime_mark_last_busy(&priv->pci_dev->dev); 918 922 pm_runtime_put_autosuspend(&priv->pci_dev->dev); 919 - mutex_unlock(&priv->acpi_lock); 920 923 return ret; 921 924 } 922 925 ··· 1039 1044 { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_P_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1040 1045 { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_SOC_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1041 1046 { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_PCH_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1047 + { PCI_DEVICE_DATA(INTEL, BIRCH_STREAM_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1042 1048 { 0, } 1043 1049 }; 1044 1050 ··· 1284 1288 1285 1289 /* Instantiate SPD EEPROMs unless the SMBus is multiplexed */ 1286 1290 #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) 1287 - if (!priv->mux_drvdata) 1291 + if (!priv->mux_pdev) 1288 1292 #endif 1289 1293 i2c_register_spd(&priv->adapter); 1290 1294 } ··· 1386 1390 const struct i801_mux_config *mux_config; 1387 1391 struct i2c_mux_gpio_platform_data gpio_data; 1388 1392 struct gpiod_lookup_table *lookup; 1393 + const struct dmi_system_id *id; 1389 1394 int i; 1390 1395 1391 - if (!priv->mux_drvdata) 1396 + id = dmi_first_match(mux_dmi_table); 1397 + if (!id) 1392 1398 return; 1393 - mux_config = priv->mux_drvdata; 1399 + 1400 + mux_config = id->driver_data; 1394 1401 1395 1402 /* Prepare the platform data */ 1396 1403 memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data)); ··· 1437 1438 platform_device_unregister(priv->mux_pdev); 1438 1439 gpiod_remove_lookup_table(priv->lookup); 1439 1440 } 1440 - 1441 - static unsigned int i801_get_adapter_class(struct i801_priv *priv) 1442 - { 1443 - const struct dmi_system_id *id; 1444 - const struct i801_mux_config *mux_config; 1445 - unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1446 - int i; 1447 - 1448 - id = dmi_first_match(mux_dmi_table); 1449 - if (id) { 1450 - /* Remove branch classes from trunk */ 1451 - mux_config = id->driver_data; 1452 - for (i = 0; i < mux_config->n_values; i++) 1453 - class &= ~mux_config->classes[i]; 1454 - 1455 - /* Remember for later */ 1456 - priv->mux_drvdata = mux_config; 1457 - } 1458 - 1459 - return class; 1460 - } 1461 1441 #else 1462 1442 static inline void i801_add_mux(struct i801_priv *priv) { } 1463 1443 static inline void i801_del_mux(struct i801_priv *priv) { } 1464 - 1465 - static inline unsigned int i801_get_adapter_class(struct i801_priv *priv) 1466 - { 1467 - return I2C_CLASS_HWMON | I2C_CLASS_SPD; 1468 - } 1469 1444 #endif 1470 1445 1471 1446 static struct platform_device * ··· 1545 1572 * further access from the driver itself. This device is now owned 1546 1573 * by the system firmware. 1547 1574 */ 1548 - mutex_lock(&priv->acpi_lock); 1575 + i2c_lock_bus(&priv->adapter, I2C_LOCK_SEGMENT); 1549 1576 1550 1577 if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) { 1551 1578 priv->acpi_reserved = true; ··· 1565 1592 else 1566 1593 status = acpi_os_write_port(address, (u32)*value, bits); 1567 1594 1568 - mutex_unlock(&priv->acpi_lock); 1595 + i2c_unlock_bus(&priv->adapter, I2C_LOCK_SEGMENT); 1569 1596 1570 1597 return status; 1571 1598 } ··· 1603 1630 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hstcfg); 1604 1631 } 1605 1632 1633 + static void i801_restore_regs(struct i801_priv *priv) 1634 + { 1635 + outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); 1636 + pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg); 1637 + } 1638 + 1606 1639 static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) 1607 1640 { 1608 1641 int err, i; ··· 1620 1641 1621 1642 i2c_set_adapdata(&priv->adapter, priv); 1622 1643 priv->adapter.owner = THIS_MODULE; 1623 - priv->adapter.class = i801_get_adapter_class(priv); 1644 + priv->adapter.class = I2C_CLASS_HWMON; 1624 1645 priv->adapter.algo = &smbus_algorithm; 1625 1646 priv->adapter.dev.parent = &dev->dev; 1626 - ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev)); 1647 + acpi_use_parent_companion(&priv->adapter.dev); 1627 1648 priv->adapter.retries = 3; 1628 - mutex_init(&priv->acpi_lock); 1629 1649 1630 1650 priv->pci_dev = dev; 1631 1651 priv->features = id->driver_data; ··· 1734 1756 if (err) { 1735 1757 platform_device_unregister(priv->tco_pdev); 1736 1758 i801_acpi_remove(priv); 1759 + i801_restore_regs(priv); 1737 1760 return err; 1738 1761 } 1739 1762 ··· 1759 1780 { 1760 1781 struct i801_priv *priv = pci_get_drvdata(dev); 1761 1782 1762 - outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); 1763 1783 i801_disable_host_notify(priv); 1764 1784 i801_del_mux(priv); 1765 1785 i2c_del_adapter(&priv->adapter); 1766 1786 i801_acpi_remove(priv); 1767 - pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 1768 1787 1769 1788 platform_device_unregister(priv->tco_pdev); 1770 1789 1771 1790 /* if acpi_reserved is set then usage_count is incremented already */ 1772 1791 if (!priv->acpi_reserved) 1773 1792 pm_runtime_get_noresume(&dev->dev); 1793 + 1794 + i801_restore_regs(priv); 1774 1795 1775 1796 /* 1776 1797 * do not call pci_disable_device(dev) since it can cause hard hangs on ··· 1782 1803 { 1783 1804 struct i801_priv *priv = pci_get_drvdata(dev); 1784 1805 1785 - /* Restore config registers to avoid hard hang on some systems */ 1786 - outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); 1787 1806 i801_disable_host_notify(priv); 1788 - pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 1807 + /* Restore config registers to avoid hard hang on some systems */ 1808 + i801_restore_regs(priv); 1789 1809 } 1790 1810 1791 1811 static int i801_suspend(struct device *dev) 1792 1812 { 1793 1813 struct i801_priv *priv = dev_get_drvdata(dev); 1794 1814 1795 - outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); 1796 - pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg); 1815 + i2c_mark_adapter_suspended(&priv->adapter); 1816 + i801_restore_regs(priv); 1817 + 1797 1818 return 0; 1798 1819 } 1799 1820 ··· 1803 1824 1804 1825 i801_setup_hstcfg(priv); 1805 1826 i801_enable_host_notify(&priv->adapter); 1827 + i2c_mark_adapter_resumed(&priv->adapter); 1806 1828 1807 1829 return 0; 1808 1830 } ··· 1822 1842 }, 1823 1843 }; 1824 1844 1825 - static int __init i2c_i801_init(void) 1845 + static int __init i2c_i801_init(struct pci_driver *drv) 1826 1846 { 1827 1847 if (dmi_name_in_vendors("FUJITSU")) 1828 1848 input_apanel_init(); 1829 - return pci_register_driver(&i801_driver); 1830 - } 1831 - 1832 - static void __exit i2c_i801_exit(void) 1833 - { 1834 - pci_unregister_driver(&i801_driver); 1849 + return pci_register_driver(drv); 1835 1850 } 1836 1851 1837 1852 MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>"); ··· 1834 1859 MODULE_DESCRIPTION("I801 SMBus driver"); 1835 1860 MODULE_LICENSE("GPL"); 1836 1861 1837 - module_init(i2c_i801_init); 1838 - module_exit(i2c_i801_exit); 1862 + module_driver(i801_driver, i2c_i801_init, pci_unregister_driver);
+8 -4
drivers/i2c/busses/i2c-mt65xx.c
··· 1442 1442 if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk)) 1443 1443 return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_ARB].clk); 1444 1444 1445 + i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get_optional(&pdev->dev, "pmic"); 1446 + if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) { 1447 + dev_err(&pdev->dev, "cannot get pmic clock\n"); 1448 + return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk); 1449 + } 1450 + 1445 1451 if (i2c->have_pmic) { 1446 - i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = devm_clk_get(&pdev->dev, "pmic"); 1447 - if (IS_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk)) { 1452 + if (!i2c->clocks[I2C_MT65XX_CLK_PMIC].clk) { 1448 1453 dev_err(&pdev->dev, "cannot get pmic clock\n"); 1449 - return PTR_ERR(i2c->clocks[I2C_MT65XX_CLK_PMIC].clk); 1454 + return -ENODEV; 1450 1455 } 1451 1456 speed_clk = I2C_MT65XX_CLK_PMIC; 1452 1457 } else { 1453 - i2c->clocks[I2C_MT65XX_CLK_PMIC].clk = NULL; 1454 1458 speed_clk = I2C_MT65XX_CLK_MAIN; 1455 1459 } 1456 1460
+5 -6
drivers/i2c/busses/i2c-mv64xxx.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/pinctrl/consumer.h> 21 21 #include <linux/pm_runtime.h> 22 + #include <linux/property.h> 22 23 #include <linux/reset.h> 23 24 #include <linux/io.h> 24 25 #include <linux/of.h> 25 - #include <linux/of_device.h> 26 - #include <linux/of_irq.h> 27 26 #include <linux/clk.h> 28 27 #include <linux/err.h> 29 28 #include <linux/delay.h> ··· 858 859 mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, 859 860 struct device *dev) 860 861 { 861 - const struct of_device_id *device; 862 + const struct mv64xxx_i2c_regs *data; 862 863 struct device_node *np = dev->of_node; 863 864 u32 bus_freq, tclk; 864 865 int rc = 0; ··· 896 897 */ 897 898 drv_data->adapter.timeout = HZ; 898 899 899 - device = of_match_device(mv64xxx_i2c_of_match_table, dev); 900 - if (!device) 900 + data = device_get_match_data(dev); 901 + if (!data) 901 902 return -ENODEV; 902 903 903 - memcpy(&drv_data->reg_offsets, device->data, sizeof(drv_data->reg_offsets)); 904 + memcpy(&drv_data->reg_offsets, data, sizeof(drv_data->reg_offsets)); 904 905 905 906 /* 906 907 * For controllers embedded in new SoCs activate the
+3 -5
drivers/i2c/busses/i2c-omap.c
··· 25 25 #include <linux/clk.h> 26 26 #include <linux/io.h> 27 27 #include <linux/of.h> 28 - #include <linux/of_device.h> 29 28 #include <linux/slab.h> 30 29 #include <linux/platform_data/i2c-omap.h> 31 30 #include <linux/pm_runtime.h> 32 31 #include <linux/pinctrl/consumer.h> 32 + #include <linux/property.h> 33 33 34 34 /* I2C controller revisions */ 35 35 #define OMAP_I2C_OMAP1_REV_2 0x20 ··· 1358 1358 const struct omap_i2c_bus_platform_data *pdata = 1359 1359 dev_get_platdata(&pdev->dev); 1360 1360 struct device_node *node = pdev->dev.of_node; 1361 - const struct of_device_id *match; 1362 1361 int irq; 1363 1362 int r; 1364 1363 u32 rev; ··· 1375 1376 if (IS_ERR(omap->base)) 1376 1377 return PTR_ERR(omap->base); 1377 1378 1378 - match = of_match_device(of_match_ptr(omap_i2c_of_match), &pdev->dev); 1379 - if (match) { 1379 + if (pdev->dev.of_node) { 1380 1380 u32 freq = I2C_MAX_STANDARD_MODE_FREQ; 1381 1381 1382 - pdata = match->data; 1382 + pdata = device_get_match_data(&pdev->dev); 1383 1383 omap->flags = pdata->flags; 1384 1384 1385 1385 of_property_read_u32(node, "clock-frequency", &freq);
+1 -1
drivers/i2c/busses/i2c-powermac.c
··· 231 231 struct i2c_board_info info = {}; 232 232 struct i2c_client *newdev; 233 233 234 - strncpy(info.type, type, sizeof(info.type)); 234 + strscpy(info.type, type, sizeof(info.type)); 235 235 info.addr = addr; 236 236 newdev = i2c_new_client_device(adap, &info); 237 237 if (IS_ERR(newdev))
+3 -4
drivers/i2c/busses/i2c-pxa.c
··· 32 32 #include <linux/pinctrl/consumer.h> 33 33 #include <linux/platform_device.h> 34 34 #include <linux/platform_data/i2c-pxa.h> 35 + #include <linux/property.h> 35 36 #include <linux/slab.h> 36 37 37 38 /* I2C register field definitions */ ··· 1253 1252 enum pxa_i2c_types *i2c_types) 1254 1253 { 1255 1254 struct device_node *np = pdev->dev.of_node; 1256 - const struct of_device_id *of_id = 1257 - of_match_device(i2c_pxa_dt_ids, &pdev->dev); 1258 1255 1259 - if (!of_id) 1256 + if (!pdev->dev.of_node) 1260 1257 return 1; 1261 1258 1262 1259 /* For device tree we always use the dynamic or alias-assigned ID */ ··· 1263 1264 i2c->use_pio = of_property_read_bool(np, "mrvl,i2c-polling"); 1264 1265 i2c->fast_mode = of_property_read_bool(np, "mrvl,i2c-fast-mode"); 1265 1266 1266 - *i2c_types = (enum pxa_i2c_types)(of_id->data); 1267 + *i2c_types = (enum pxa_i2c_types)device_get_match_data(&pdev->dev); 1267 1268 1268 1269 return 0; 1269 1270 }
+1
drivers/i2c/busses/i2c-qcom-geni.c
··· 722 722 #ifdef CONFIG_ACPI 723 723 static const struct acpi_device_id geni_i2c_acpi_match[] = { 724 724 { "QCOM0220"}, 725 + { "QCOM0411" }, 725 726 { }, 726 727 }; 727 728 MODULE_DEVICE_TABLE(acpi, geni_i2c_acpi_match);
+114 -68
drivers/i2c/busses/i2c-rcar.c
··· 41 41 #define ICSAR 0x1C /* slave address */ 42 42 #define ICMAR 0x20 /* master address */ 43 43 #define ICRXTX 0x24 /* data port */ 44 + #define ICCCR2 0x28 /* Clock control 2 */ 45 + #define ICMPR 0x2C /* SCL mask control */ 46 + #define ICHPR 0x30 /* SCL HIGH control */ 47 + #define ICLPR 0x34 /* SCL LOW control */ 44 48 #define ICFBSCR 0x38 /* first bit setup cycle (Gen3) */ 45 49 #define ICDMAER 0x3c /* DMA enable (Gen3) */ 46 50 ··· 88 84 #define RMDMAE BIT(1) /* DMA Master Received Enable */ 89 85 #define TMDMAE BIT(0) /* DMA Master Transmitted Enable */ 90 86 87 + /* ICCCR2 */ 88 + #define CDFD BIT(2) /* CDF Disable */ 89 + #define HLSE BIT(1) /* HIGH/LOW Separate Control Enable */ 90 + #define SME BIT(0) /* SCL Mask Enable */ 91 + 91 92 /* ICFBSCR */ 92 93 #define TCYC17 0x0f /* 17*Tcyc delay 1st bit between SDA and SCL */ 93 94 94 95 #define RCAR_MIN_DMA_LEN 8 96 + 97 + /* SCL low/high ratio 5:4 to meet all I2C timing specs (incl safety margin) */ 98 + #define RCAR_SCLD_RATIO 5 99 + #define RCAR_SCHD_RATIO 4 100 + /* 101 + * SMD should be smaller than SCLD/SCHD and is always around 20 in the docs. 102 + * Thus, we simply use 20 which works for low and high speeds. 103 + */ 104 + #define RCAR_DEFAULT_SMD 20 95 105 96 106 #define RCAR_BUS_PHASE_START (MDBS | MIE | ESG) 97 107 #define RCAR_BUS_PHASE_DATA (MDBS | MIE) ··· 146 128 147 129 int pos; 148 130 u32 icccr; 131 + u16 schd; 132 + u16 scld; 149 133 u8 recovery_icmcr; /* protected by adapter lock */ 150 134 enum rcar_i2c_type devtype; 151 135 struct i2c_client *slave; ··· 236 216 rcar_i2c_write(priv, ICMCR, MDBS); 237 217 rcar_i2c_write(priv, ICMSR, 0); 238 218 /* start clock */ 239 - rcar_i2c_write(priv, ICCCR, priv->icccr); 240 - 241 - if (priv->devtype == I2C_RCAR_GEN3) 219 + if (priv->devtype < I2C_RCAR_GEN3) { 220 + rcar_i2c_write(priv, ICCCR, priv->icccr); 221 + } else { 222 + rcar_i2c_write(priv, ICCCR2, CDFD | HLSE | SME); 223 + rcar_i2c_write(priv, ICCCR, priv->icccr); 224 + rcar_i2c_write(priv, ICMPR, RCAR_DEFAULT_SMD); 225 + rcar_i2c_write(priv, ICHPR, priv->schd); 226 + rcar_i2c_write(priv, ICLPR, priv->scld); 242 227 rcar_i2c_write(priv, ICFBSCR, TCYC17); 243 - 228 + } 244 229 } 245 230 246 231 static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) ··· 266 241 267 242 static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) 268 243 { 269 - u32 scgd, cdf, round, ick, sum, scl, cdf_width; 244 + u32 cdf, round, ick, sum, scl, cdf_width; 270 245 unsigned long rate; 271 246 struct device *dev = rcar_i2c_priv_to_dev(priv); 272 247 struct i2c_timings t = { ··· 279 254 /* Fall back to previously used values if not supplied */ 280 255 i2c_parse_fw_timings(dev, &t, false); 281 256 282 - switch (priv->devtype) { 283 - case I2C_RCAR_GEN1: 284 - cdf_width = 2; 285 - break; 286 - case I2C_RCAR_GEN2: 287 - case I2C_RCAR_GEN3: 288 - cdf_width = 3; 289 - break; 290 - default: 291 - dev_err(dev, "device type error\n"); 292 - return -EIO; 293 - } 294 - 295 257 /* 296 258 * calculate SCL clock 297 259 * see 298 - * ICCCR 260 + * ICCCR (and ICCCR2 for Gen3+) 299 261 * 300 262 * ick = clkp / (1 + CDF) 301 263 * SCL = ick / (20 + SCGD * 8 + F[(ticf + tr + intd) * ick]) 264 + * 265 + * for Gen3+: 266 + * SCL = clkp / (8 + SMD * 2 + SCLD + SCHD +F[(ticf + tr + intd) * clkp]) 302 267 * 303 268 * ick : I2C internal clock < 20 MHz 304 269 * ticf : I2C SCL falling time ··· 299 284 */ 300 285 rate = clk_get_rate(priv->clk); 301 286 cdf = rate / 20000000; 302 - if (cdf >= 1U << cdf_width) { 303 - dev_err(dev, "Input clock %lu too high\n", rate); 304 - return -EIO; 305 - } 306 - ick = rate / (cdf + 1); 287 + cdf_width = (priv->devtype == I2C_RCAR_GEN1) ? 2 : 3; 288 + if (cdf >= 1U << cdf_width) 289 + goto err_no_val; 290 + 291 + /* On Gen3+, we use cdf only for the filters, not as a SCL divider */ 292 + ick = rate / (priv->devtype < I2C_RCAR_GEN3 ? (cdf + 1) : 1); 307 293 308 294 /* 309 - * it is impossible to calculate large scale 310 - * number on u32. separate it 295 + * It is impossible to calculate a large scale number on u32. Separate it. 311 296 * 312 297 * F[(ticf + tr + intd) * ick] with sum = (ticf + tr + intd) 313 298 * = F[sum * ick / 1000000000] 314 299 * = F[(ick / 1000000) * sum / 1000] 315 300 */ 316 301 sum = t.scl_fall_ns + t.scl_rise_ns + t.scl_int_delay_ns; 317 - round = (ick + 500000) / 1000000 * sum; 318 - round = (round + 500) / 1000; 302 + round = DIV_ROUND_CLOSEST(ick, 1000000); 303 + round = DIV_ROUND_CLOSEST(round * sum, 1000); 319 304 320 - /* 321 - * SCL = ick / (20 + SCGD * 8 + F[(ticf + tr + intd) * ick]) 322 - * 323 - * Calculation result (= SCL) should be less than 324 - * bus_speed for hardware safety 325 - * 326 - * We could use something along the lines of 327 - * div = ick / (bus_speed + 1) + 1; 328 - * scgd = (div - 20 - round + 7) / 8; 329 - * scl = ick / (20 + (scgd * 8) + round); 330 - * (not fully verified) but that would get pretty involved 331 - */ 332 - for (scgd = 0; scgd < 0x40; scgd++) { 333 - scl = ick / (20 + (scgd * 8) + round); 334 - if (scl <= t.bus_freq_hz) 335 - goto scgd_find; 305 + if (priv->devtype < I2C_RCAR_GEN3) { 306 + u32 scgd; 307 + /* 308 + * SCL = ick / (20 + 8 * SCGD + F[(ticf + tr + intd) * ick]) 309 + * 20 + 8 * SCGD + F[...] = ick / SCL 310 + * SCGD = ((ick / SCL) - 20 - F[...]) / 8 311 + * Result (= SCL) should be less than bus_speed for hardware safety 312 + */ 313 + scgd = DIV_ROUND_UP(ick, t.bus_freq_hz ?: 1); 314 + scgd = DIV_ROUND_UP(scgd - 20 - round, 8); 315 + scl = ick / (20 + 8 * scgd + round); 316 + 317 + if (scgd > 0x3f) 318 + goto err_no_val; 319 + 320 + dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u, SCGD: %u\n", 321 + scl, t.bus_freq_hz, rate, round, cdf, scgd); 322 + 323 + priv->icccr = scgd << cdf_width | cdf; 324 + } else { 325 + u32 x, sum_ratio = RCAR_SCHD_RATIO + RCAR_SCLD_RATIO; 326 + /* 327 + * SCLD/SCHD ratio and SMD default value are explained above 328 + * where they are defined. With these definitions, we can compute 329 + * x as a base value for the SCLD/SCHD ratio: 330 + * 331 + * SCL = clkp / (8 + 2 * SMD + SCLD + SCHD + F[(ticf + tr + intd) * clkp]) 332 + * SCL = clkp / (8 + 2 * RCAR_DEFAULT_SMD + RCAR_SCLD_RATIO * x 333 + * + RCAR_SCHD_RATIO * x + F[...]) 334 + * 335 + * with: sum_ratio = RCAR_SCLD_RATIO + RCAR_SCHD_RATIO 336 + * and: smd = RCAR_DEFAULT_SMD 337 + * 338 + * SCL = clkp / (8 + 2 * smd + sum_ratio * x + F[...]) 339 + * 8 + 2 * smd + sum_ratio * x + F[...] = clkp / SCL 340 + * x = ((clkp / SCL) - 8 - 2 * smd - F[...]) / sum_ratio 341 + */ 342 + x = DIV_ROUND_UP(rate, t.bus_freq_hz ?: 1); 343 + x = DIV_ROUND_UP(x - 8 - 2 * RCAR_DEFAULT_SMD - round, sum_ratio); 344 + scl = rate / (8 + 2 * RCAR_DEFAULT_SMD + sum_ratio * x + round); 345 + 346 + /* Bail out if values don't fit into 16 bit or SMD became too large */ 347 + if (x * RCAR_SCLD_RATIO > 0xffff || RCAR_DEFAULT_SMD > x * RCAR_SCHD_RATIO) 348 + goto err_no_val; 349 + 350 + priv->icccr = cdf; 351 + priv->schd = RCAR_SCHD_RATIO * x; 352 + priv->scld = RCAR_SCLD_RATIO * x; 353 + 354 + dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCHD %u SCLD %u\n", 355 + scl, t.bus_freq_hz, rate, round, cdf, priv->schd, priv->scld); 336 356 } 337 - dev_err(dev, "it is impossible to calculate best SCL\n"); 338 - return -EIO; 339 - 340 - scgd_find: 341 - dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n", 342 - scl, t.bus_freq_hz, rate, round, cdf, scgd); 343 - 344 - /* keep icccr value */ 345 - priv->icccr = scgd << cdf_width | cdf; 346 357 347 358 return 0; 359 + 360 + err_no_val: 361 + dev_err(dev, "it is impossible to calculate best SCL\n"); 362 + return -EINVAL; 348 363 } 349 364 350 365 /* ··· 888 843 889 844 /* Gen3 needs a reset before allowing RXDMA once */ 890 845 if (priv->devtype == I2C_RCAR_GEN3) { 891 - priv->flags |= ID_P_NO_RXDMA; 892 - if (!IS_ERR(priv->rstc)) { 893 - ret = rcar_i2c_do_reset(priv); 894 - if (ret == 0) 895 - priv->flags &= ~ID_P_NO_RXDMA; 896 - } 846 + priv->flags &= ~ID_P_NO_RXDMA; 847 + ret = rcar_i2c_do_reset(priv); 848 + if (ret) 849 + goto out; 897 850 } 898 851 899 852 rcar_i2c_init(priv); ··· 1142 1099 irqhandler = rcar_i2c_gen2_irq; 1143 1100 } 1144 1101 1145 - if (priv->devtype == I2C_RCAR_GEN3) { 1146 - priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); 1147 - if (!IS_ERR(priv->rstc)) { 1148 - ret = reset_control_status(priv->rstc); 1149 - if (ret < 0) 1150 - priv->rstc = ERR_PTR(-ENOTSUPP); 1151 - } 1152 - } 1153 - 1154 1102 /* Stay always active when multi-master to keep arbitration working */ 1155 1103 if (of_property_read_bool(dev->of_node, "multi-master")) 1156 1104 priv->flags |= ID_P_PM_BLOCKED; ··· 1150 1116 1151 1117 if (of_property_read_bool(dev->of_node, "smbus")) 1152 1118 priv->flags |= ID_P_HOST_NOTIFY; 1119 + 1120 + if (priv->devtype == I2C_RCAR_GEN3) { 1121 + priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); 1122 + if (IS_ERR(priv->rstc)) { 1123 + ret = PTR_ERR(priv->rstc); 1124 + goto out_pm_put; 1125 + } 1126 + 1127 + ret = reset_control_status(priv->rstc); 1128 + if (ret < 0) 1129 + goto out_pm_put; 1130 + } 1153 1131 1154 1132 ret = platform_get_irq(pdev, 0); 1155 1133 if (ret < 0)
+1 -1
drivers/i2c/busses/i2c-riic.c
··· 313 313 * frequency with only 62 clock ticks max (31 high, 31 low). 314 314 * Aim for a duty of 60% LOW, 40% HIGH. 315 315 */ 316 - total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz); 316 + total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz ?: 1); 317 317 318 318 for (cks = 0; cks < 7; cks++) { 319 319 /*
+3 -4
drivers/i2c/busses/i2c-s3c2410.c
··· 133 133 }; 134 134 MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); 135 135 136 - static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat); 136 + static void i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat); 137 137 138 138 #ifdef CONFIG_OF 139 139 static const struct of_device_id s3c24xx_i2c_match[] = { ··· 377 377 /* 378 378 * process an interrupt and work out what to do 379 379 */ 380 - static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) 380 + static void i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) 381 381 { 382 382 unsigned long tmp; 383 383 unsigned char byte; 384 - int ret = 0; 385 384 386 385 switch (i2c->state) { 387 386 ··· 543 544 tmp &= ~S3C2410_IICCON_IRQPEND; 544 545 writel(tmp, i2c->regs + S3C2410_IICCON); 545 546 out: 546 - return ret; 547 + return; 547 548 } 548 549 549 550 /*
+10 -22
drivers/i2c/busses/i2c-stm32f4.c
··· 783 783 return -EINVAL; 784 784 } 785 785 786 - i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 786 + i2c_dev->clk = devm_clk_get_enabled(&pdev->dev, NULL); 787 787 if (IS_ERR(i2c_dev->clk)) { 788 - dev_err(&pdev->dev, "Error: Missing controller clock\n"); 788 + dev_err(&pdev->dev, "Failed to enable clock\n"); 789 789 return PTR_ERR(i2c_dev->clk); 790 - } 791 - ret = clk_prepare_enable(i2c_dev->clk); 792 - if (ret) { 793 - dev_err(i2c_dev->dev, "Failed to prepare_enable clock\n"); 794 - return ret; 795 790 } 796 791 797 792 rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); 798 - if (IS_ERR(rst)) { 799 - ret = dev_err_probe(&pdev->dev, PTR_ERR(rst), 800 - "Error: Missing reset ctrl\n"); 801 - goto clk_free; 802 - } 793 + if (IS_ERR(rst)) 794 + return dev_err_probe(&pdev->dev, PTR_ERR(rst), 795 + "Error: Missing reset ctrl\n"); 796 + 803 797 reset_control_assert(rst); 804 798 udelay(2); 805 799 reset_control_deassert(rst); ··· 810 816 if (ret) { 811 817 dev_err(&pdev->dev, "Failed to request irq event %i\n", 812 818 irq_event); 813 - goto clk_free; 819 + return ret; 814 820 } 815 821 816 822 ret = devm_request_irq(&pdev->dev, irq_error, stm32f4_i2c_isr_error, 0, ··· 818 824 if (ret) { 819 825 dev_err(&pdev->dev, "Failed to request irq error %i\n", 820 826 irq_error); 821 - goto clk_free; 827 + return ret; 822 828 } 823 829 824 830 ret = stm32f4_i2c_hw_config(i2c_dev); 825 831 if (ret) 826 - goto clk_free; 832 + return ret; 827 833 828 834 adap = &i2c_dev->adap; 829 835 i2c_set_adapdata(adap, i2c_dev); ··· 839 845 840 846 ret = i2c_add_adapter(adap); 841 847 if (ret) 842 - goto clk_free; 848 + return ret; 843 849 844 850 platform_set_drvdata(pdev, i2c_dev); 845 851 ··· 848 854 dev_info(i2c_dev->dev, "STM32F4 I2C driver registered\n"); 849 855 850 856 return 0; 851 - 852 - clk_free: 853 - clk_disable_unprepare(i2c_dev->clk); 854 - return ret; 855 857 } 856 858 857 859 static void stm32f4_i2c_remove(struct platform_device *pdev) ··· 855 865 struct stm32f4_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 856 866 857 867 i2c_del_adapter(&i2c_dev->adap); 858 - 859 - clk_unprepare(i2c_dev->clk); 860 868 } 861 869 862 870 static const struct of_device_id stm32f4_i2c_match[] = {
+60 -29
drivers/i2c/busses/i2c-stm32f7.c
··· 325 325 * @dnf_dt: value of digital filter requested via dt 326 326 * @dnf: value of digital filter to apply 327 327 * @alert: SMBus alert specific data 328 + * @atomic: boolean indicating that current transfer is atomic 328 329 */ 329 330 struct stm32f7_i2c_dev { 330 331 struct i2c_adapter adap; ··· 358 357 u32 dnf_dt; 359 358 u32 dnf; 360 359 struct stm32f7_i2c_alert *alert; 360 + bool atomic; 361 361 }; 362 362 363 363 /* ··· 917 915 918 916 /* Configure DMA or enable RX/TX interrupt */ 919 917 i2c_dev->use_dma = false; 920 - if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { 918 + if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN 919 + && !i2c_dev->atomic) { 921 920 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, 922 921 msg->flags & I2C_M_RD, 923 922 f7_msg->count, f7_msg->buf, ··· 941 938 else 942 939 cr1 |= STM32F7_I2C_CR1_TXDMAEN; 943 940 } 941 + 942 + if (i2c_dev->atomic) 943 + cr1 &= ~STM32F7_I2C_ALL_IRQ_MASK; /* Disable all interrupts */ 944 944 945 945 /* Configure Start/Repeated Start */ 946 946 cr2 |= STM32F7_I2C_CR2_START; ··· 1679 1673 return IRQ_HANDLED; 1680 1674 } 1681 1675 1682 - static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap, 1676 + static int stm32f7_i2c_wait_polling(struct stm32f7_i2c_dev *i2c_dev) 1677 + { 1678 + ktime_t timeout = ktime_add_ms(ktime_get(), i2c_dev->adap.timeout); 1679 + 1680 + while (ktime_compare(ktime_get(), timeout) < 0) { 1681 + udelay(5); 1682 + stm32f7_i2c_isr_event(0, i2c_dev); 1683 + 1684 + if (completion_done(&i2c_dev->complete)) 1685 + return 1; 1686 + } 1687 + 1688 + return 0; 1689 + } 1690 + 1691 + static int stm32f7_i2c_xfer_core(struct i2c_adapter *i2c_adap, 1683 1692 struct i2c_msg msgs[], int num) 1684 1693 { 1685 1694 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); ··· 1718 1697 1719 1698 stm32f7_i2c_xfer_msg(i2c_dev, msgs); 1720 1699 1721 - time_left = wait_for_completion_timeout(&i2c_dev->complete, 1722 - i2c_dev->adap.timeout); 1700 + if (!i2c_dev->atomic) 1701 + time_left = wait_for_completion_timeout(&i2c_dev->complete, 1702 + i2c_dev->adap.timeout); 1703 + else 1704 + time_left = stm32f7_i2c_wait_polling(i2c_dev); 1705 + 1723 1706 ret = f7_msg->result; 1724 1707 if (ret) { 1725 1708 if (i2c_dev->use_dma) ··· 1753 1728 pm_runtime_put_autosuspend(i2c_dev->dev); 1754 1729 1755 1730 return (ret < 0) ? ret : num; 1731 + } 1732 + 1733 + static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap, 1734 + struct i2c_msg msgs[], int num) 1735 + { 1736 + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); 1737 + 1738 + i2c_dev->atomic = false; 1739 + return stm32f7_i2c_xfer_core(i2c_adap, msgs, num); 1740 + } 1741 + 1742 + static int stm32f7_i2c_xfer_atomic(struct i2c_adapter *i2c_adap, 1743 + struct i2c_msg msgs[], int num) 1744 + { 1745 + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); 1746 + 1747 + i2c_dev->atomic = true; 1748 + return stm32f7_i2c_xfer_core(i2c_adap, msgs, num); 1756 1749 } 1757 1750 1758 1751 static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, ··· 2141 2098 2142 2099 static const struct i2c_algorithm stm32f7_i2c_algo = { 2143 2100 .master_xfer = stm32f7_i2c_xfer, 2101 + .master_xfer_atomic = stm32f7_i2c_xfer_atomic, 2144 2102 .smbus_xfer = stm32f7_i2c_smbus_xfer, 2145 2103 .functionality = stm32f7_i2c_func, 2146 2104 .reg_slave = stm32f7_i2c_reg_slave, ··· 2178 2134 i2c_dev->wakeup_src = of_property_read_bool(pdev->dev.of_node, 2179 2135 "wakeup-source"); 2180 2136 2181 - i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 2137 + i2c_dev->clk = devm_clk_get_enabled(&pdev->dev, NULL); 2182 2138 if (IS_ERR(i2c_dev->clk)) 2183 2139 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->clk), 2184 - "Failed to get controller clock\n"); 2185 - 2186 - ret = clk_prepare_enable(i2c_dev->clk); 2187 - if (ret) { 2188 - dev_err(&pdev->dev, "Failed to prepare_enable clock\n"); 2189 - return ret; 2190 - } 2140 + "Failed to enable controller clock\n"); 2191 2141 2192 2142 rst = devm_reset_control_get(&pdev->dev, NULL); 2193 - if (IS_ERR(rst)) { 2194 - ret = dev_err_probe(&pdev->dev, PTR_ERR(rst), 2195 - "Error: Missing reset ctrl\n"); 2196 - goto clk_free; 2197 - } 2143 + if (IS_ERR(rst)) 2144 + return dev_err_probe(&pdev->dev, PTR_ERR(rst), 2145 + "Error: Missing reset ctrl\n"); 2146 + 2198 2147 reset_control_assert(rst); 2199 2148 udelay(2); 2200 2149 reset_control_deassert(rst); ··· 2202 2165 if (ret) { 2203 2166 dev_err(&pdev->dev, "Failed to request irq event %i\n", 2204 2167 irq_event); 2205 - goto clk_free; 2168 + return ret; 2206 2169 } 2207 2170 2208 2171 ret = devm_request_irq(&pdev->dev, irq_error, stm32f7_i2c_isr_error, 0, ··· 2210 2173 if (ret) { 2211 2174 dev_err(&pdev->dev, "Failed to request irq error %i\n", 2212 2175 irq_error); 2213 - goto clk_free; 2176 + return ret; 2214 2177 } 2215 2178 2216 2179 setup = of_device_get_match_data(&pdev->dev); 2217 2180 if (!setup) { 2218 2181 dev_err(&pdev->dev, "Can't get device data\n"); 2219 - ret = -ENODEV; 2220 - goto clk_free; 2182 + return -ENODEV; 2221 2183 } 2222 2184 i2c_dev->setup = *setup; 2223 2185 2224 2186 ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup); 2225 2187 if (ret) 2226 - goto clk_free; 2188 + return ret; 2227 2189 2228 2190 /* Setup Fast mode plus if necessary */ 2229 2191 if (i2c_dev->bus_rate > I2C_MAX_FAST_MODE_FREQ) { 2230 2192 ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev); 2231 2193 if (ret) 2232 - goto clk_free; 2194 + return ret; 2233 2195 ret = stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); 2234 2196 if (ret) 2235 - goto clk_free; 2197 + return ret; 2236 2198 } 2237 2199 2238 2200 adap = &i2c_dev->adap; ··· 2342 2306 fmp_clear: 2343 2307 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); 2344 2308 2345 - clk_free: 2346 - clk_disable_unprepare(i2c_dev->clk); 2347 - 2348 2309 return ret; 2349 2310 } 2350 2311 ··· 2375 2342 } 2376 2343 2377 2344 stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); 2378 - 2379 - clk_disable_unprepare(i2c_dev->clk); 2380 2345 } 2381 2346 2382 2347 static int __maybe_unused stm32f7_i2c_runtime_suspend(struct device *dev)
+5
drivers/i2c/busses/i2c-sun6i-p2wi.c
··· 201 201 return -EINVAL; 202 202 } 203 203 204 + if (clk_freq == 0) { 205 + dev_err(dev, "clock-frequency is set to 0 in DT\n"); 206 + return -EINVAL; 207 + } 208 + 204 209 if (of_get_child_count(np) > 1) { 205 210 dev_err(dev, "P2WI only supports one slave device\n"); 206 211 return -EINVAL;
+1 -1
drivers/i2c/i2c-atr.c
··· 94 94 95 95 struct notifier_block i2c_nb; 96 96 97 - struct i2c_adapter *adapter[]; 97 + struct i2c_adapter *adapter[] __counted_by(max_adapters); 98 98 }; 99 99 100 100 static struct i2c_atr_alias_pair *
+13 -6
drivers/i2c/i2c-core-base.c
··· 931 931 struct i2c_client * 932 932 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 933 933 { 934 - struct i2c_client *client; 935 - int status; 934 + struct i2c_client *client; 935 + bool need_put = false; 936 + int status; 936 937 937 938 client = kzalloc(sizeof *client, GFP_KERNEL); 938 939 if (!client) ··· 971 970 client->dev.fwnode = info->fwnode; 972 971 973 972 device_enable_async_suspend(&client->dev); 974 - i2c_dev_set_name(adap, client, info); 975 973 976 974 if (info->swnode) { 977 975 status = device_add_software_node(&client->dev, info->swnode); ··· 982 982 } 983 983 } 984 984 985 + i2c_dev_set_name(adap, client, info); 985 986 status = device_register(&client->dev); 986 987 if (status) 987 988 goto out_remove_swnode; ··· 994 993 995 994 out_remove_swnode: 996 995 device_remove_software_node(&client->dev); 996 + need_put = true; 997 997 out_err_put_of_node: 998 998 of_node_put(info->of_node); 999 999 out_err: ··· 1002 1000 "Failed to register i2c client %s at 0x%02x (%d)\n", 1003 1001 client->name, client->addr, status); 1004 1002 out_err_silent: 1005 - kfree(client); 1003 + if (need_put) 1004 + put_device(&client->dev); 1005 + else 1006 + kfree(client); 1006 1007 return ERR_PTR(status); 1007 1008 } 1008 1009 EXPORT_SYMBOL_GPL(i2c_new_client_device); ··· 1194 1189 unsigned int i2c_adapter_depth(struct i2c_adapter *adapter) 1195 1190 { 1196 1191 unsigned int depth = 0; 1192 + struct device *parent; 1197 1193 1198 - while ((adapter = i2c_parent_is_i2c_adapter(adapter))) 1199 - depth++; 1194 + for (parent = adapter->dev.parent; parent; parent = parent->parent) 1195 + if (parent->type == &i2c_adapter_type) 1196 + depth++; 1200 1197 1201 1198 WARN_ONCE(depth >= MAX_LOCKDEP_SUBCLASSES, 1202 1199 "adapter depth exceeds lockdep subclass limit\n");
+9 -9
drivers/i2c/i2c-dev.c
··· 636 636 637 637 /* ------------------------------------------------------------------------- */ 638 638 639 - static struct class *i2c_dev_class; 639 + static const struct class i2c_dev_class = { 640 + .name = "i2c-dev", 641 + .dev_groups = i2c_groups, 642 + }; 640 643 641 644 static void i2cdev_dev_release(struct device *dev) 642 645 { ··· 668 665 669 666 device_initialize(&i2c_dev->dev); 670 667 i2c_dev->dev.devt = MKDEV(I2C_MAJOR, adap->nr); 671 - i2c_dev->dev.class = i2c_dev_class; 668 + i2c_dev->dev.class = &i2c_dev_class; 672 669 i2c_dev->dev.parent = &adap->dev; 673 670 i2c_dev->dev.release = i2cdev_dev_release; 674 671 ··· 754 751 if (res) 755 752 goto out; 756 753 757 - i2c_dev_class = class_create("i2c-dev"); 758 - if (IS_ERR(i2c_dev_class)) { 759 - res = PTR_ERR(i2c_dev_class); 754 + res = class_register(&i2c_dev_class); 755 + if (res) 760 756 goto out_unreg_chrdev; 761 - } 762 - i2c_dev_class->dev_groups = i2c_groups; 763 757 764 758 /* Keep track of adapters which will be added or removed later */ 765 759 res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier); ··· 769 769 return 0; 770 770 771 771 out_unreg_class: 772 - class_destroy(i2c_dev_class); 772 + class_unregister(&i2c_dev_class); 773 773 out_unreg_chrdev: 774 774 unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS); 775 775 out: ··· 781 781 { 782 782 bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier); 783 783 i2c_for_each_dev(NULL, i2c_dev_detach_adapter); 784 - class_destroy(i2c_dev_class); 784 + class_unregister(&i2c_dev_class); 785 785 unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS); 786 786 } 787 787
+6 -6
drivers/i2c/muxes/i2c-demux-pinctrl.c
··· 32 32 const char *bus_name; 33 33 struct i2c_adapter cur_adap; 34 34 struct i2c_algorithm algo; 35 - struct i2c_demux_pinctrl_chan chan[]; 35 + struct i2c_demux_pinctrl_chan chan[] __counted_by(num_chan); 36 36 }; 37 37 38 38 static int i2c_demux_master_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ··· 167 167 int count = 0, i; 168 168 169 169 for (i = 0; i < priv->num_chan && count < PAGE_SIZE; i++) 170 - count += scnprintf(buf + count, PAGE_SIZE - count, "%d:%pOF%c", 171 - i, priv->chan[i].parent_np, 172 - i == priv->num_chan - 1 ? '\n' : ' '); 170 + count += sysfs_emit_at(buf, count, "%d:%pOF%c", 171 + i, priv->chan[i].parent_np, 172 + i == priv->num_chan - 1 ? '\n' : ' '); 173 173 174 174 return count; 175 175 } ··· 226 226 if (!priv || !props) 227 227 return -ENOMEM; 228 228 229 + priv->num_chan = num_chan; 230 + 229 231 err = of_property_read_string(np, "i2c-bus-name", &priv->bus_name); 230 232 if (err) 231 233 return err; ··· 255 253 of_changeset_update_property(&priv->chan[i].chgset, adap_np, &props[i]); 256 254 } 257 255 258 - priv->num_chan = num_chan; 259 256 priv->dev = &pdev->dev; 260 - 261 257 platform_set_drvdata(pdev, priv); 262 258 263 259 pm_runtime_no_callbacks(&pdev->dev);
+3 -4
drivers/i2c/muxes/i2c-mux-gpio.c
··· 22 22 struct gpio_desc **gpios; 23 23 }; 24 24 25 - static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) 25 + static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned int val) 26 26 { 27 27 DECLARE_BITMAP(values, BITS_PER_TYPE(val)); 28 28 ··· 58 58 struct device_node *adapter_np; 59 59 struct i2c_adapter *adapter = NULL; 60 60 struct fwnode_handle *child; 61 - unsigned *values; 61 + unsigned int *values; 62 62 int rc, i = 0; 63 63 64 64 if (is_of_node(fwnode)) { ··· 101 101 device_for_each_child_node(dev, child) { 102 102 if (is_of_node(child)) { 103 103 fwnode_property_read_u32(child, "reg", values + i); 104 - 105 104 } else if (is_acpi_node(child)) { 106 105 rc = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), values + i); 107 106 if (rc) { ··· 125 126 struct gpiomux *mux; 126 127 struct i2c_adapter *parent; 127 128 struct i2c_adapter *root; 128 - unsigned initial_state; 129 + unsigned int initial_state; 129 130 int i, ngpios, ret; 130 131 131 132 mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL);
+12 -30
drivers/misc/eeprom/at24.c
··· 92 92 * them for us. 93 93 */ 94 94 u8 bank_addr_shift; 95 - struct regmap *client_regmaps[]; 95 + struct regmap *client_regmaps[] __counted_by(num_addresses); 96 96 }; 97 97 98 98 /* ··· 191 191 AT24_CHIP_DATA(at24_data_24cs16, 16, 192 192 AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 193 193 AT24_CHIP_DATA(at24_data_24c32, 32768 / 8, AT24_FLAG_ADDR16); 194 + /* M24C32-D Additional Write lockable page (M24C32-D order codes) */ 195 + AT24_CHIP_DATA(at24_data_24c32d_wlp, 32, AT24_FLAG_ADDR16); 194 196 AT24_CHIP_DATA(at24_data_24cs32, 16, 195 197 AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 196 198 AT24_CHIP_DATA(at24_data_24c64, 65536 / 8, AT24_FLAG_ADDR16); 199 + /* M24C64-D Additional Write lockable page (M24C64-D order codes) */ 200 + AT24_CHIP_DATA(at24_data_24c64d_wlp, 32, AT24_FLAG_ADDR16); 197 201 AT24_CHIP_DATA(at24_data_24cs64, 16, 198 202 AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 199 203 AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16); ··· 226 222 { "24c16", (kernel_ulong_t)&at24_data_24c16 }, 227 223 { "24cs16", (kernel_ulong_t)&at24_data_24cs16 }, 228 224 { "24c32", (kernel_ulong_t)&at24_data_24c32 }, 225 + { "24c32d-wl", (kernel_ulong_t)&at24_data_24c32d_wlp }, 229 226 { "24cs32", (kernel_ulong_t)&at24_data_24cs32 }, 230 227 { "24c64", (kernel_ulong_t)&at24_data_24c64 }, 228 + { "24c64-wl", (kernel_ulong_t)&at24_data_24c64d_wlp }, 231 229 { "24cs64", (kernel_ulong_t)&at24_data_24cs64 }, 232 230 { "24c128", (kernel_ulong_t)&at24_data_24c128 }, 233 231 { "24c256", (kernel_ulong_t)&at24_data_24c256 }, ··· 258 252 { .compatible = "atmel,24c16", .data = &at24_data_24c16 }, 259 253 { .compatible = "atmel,24cs16", .data = &at24_data_24cs16 }, 260 254 { .compatible = "atmel,24c32", .data = &at24_data_24c32 }, 255 + { .compatible = "atmel,24c32d-wl", .data = &at24_data_24c32d_wlp }, 261 256 { .compatible = "atmel,24cs32", .data = &at24_data_24cs32 }, 262 257 { .compatible = "atmel,24c64", .data = &at24_data_24c64 }, 258 + { .compatible = "atmel,24c64d-wl", .data = &at24_data_24c64d_wlp }, 263 259 { .compatible = "atmel,24cs64", .data = &at24_data_24cs64 }, 264 260 { .compatible = "atmel,24c128", .data = &at24_data_24c128 }, 265 261 { .compatible = "atmel,24c256", .data = &at24_data_24c256 }, ··· 517 509 return 0; 518 510 } 519 511 520 - static const struct at24_chip_data *at24_get_chip_data(struct device *dev) 521 - { 522 - struct device_node *of_node = dev->of_node; 523 - const struct at24_chip_data *cdata; 524 - const struct i2c_device_id *id; 525 - 526 - id = i2c_match_id(at24_ids, to_i2c_client(dev)); 527 - 528 - /* 529 - * The I2C core allows OF nodes compatibles to match against the 530 - * I2C device ID table as a fallback, so check not only if an OF 531 - * node is present but also if it matches an OF device ID entry. 532 - */ 533 - if (of_node && of_match_device(at24_of_match, dev)) 534 - cdata = of_device_get_match_data(dev); 535 - else if (id) 536 - cdata = (void *)id->driver_data; 537 - else 538 - cdata = acpi_device_get_match_data(dev); 539 - 540 - if (!cdata) 541 - return ERR_PTR(-ENODEV); 542 - 543 - return cdata; 544 - } 545 - 546 512 static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, 547 513 struct i2c_client *base_client, 548 514 struct regmap_config *regmap_config) ··· 583 601 i2c_fn_block = i2c_check_functionality(client->adapter, 584 602 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK); 585 603 586 - cdata = at24_get_chip_data(dev); 587 - if (IS_ERR(cdata)) 588 - return PTR_ERR(cdata); 604 + cdata = i2c_get_match_data(client); 605 + if (!cdata) 606 + return -ENODEV; 589 607 590 608 err = device_property_read_u32(dev, "pagesize", &page_size); 591 609 if (err)
+5
include/linux/acpi.h
··· 1531 1531 static inline void acpi_device_notify_remove(struct device *dev) { } 1532 1532 #endif 1533 1533 1534 + static inline void acpi_use_parent_companion(struct device *dev) 1535 + { 1536 + ACPI_COMPANION_SET(dev, ACPI_COMPANION(dev->parent)); 1537 + } 1538 + 1534 1539 #endif /*_LINUX_ACPI_H*/