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 ...
Unified · Split
| @@ -68,10 +68,14 @@ properties: · 67 unmodified lines | ||
| 68 | 68 | pattern: cs16$ |
| 69 | 69 | - items: |
| 70 | 70 | pattern: c32$ |
| 71 | + - items: | |
| 72 | + pattern: c32d-wl$ | |
| 71 | 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: |
| @@ -1,135 +0,0 @@ | ||
| 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. | |
| @@ -0,0 +1,172 @@ | ||
| 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 | + }; | |
| @@ -25,6 +25,7 @@ properties: · 24 unmodified lines | ||
| 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 |
| @@ -159,6 +160,7 @@ allOf: · 128 unmodified lines | ||
| 159 | 160 | compatible: |
| 160 | 161 | contains: |
| 161 | 162 | enum: |
| 163 | + - qcom,sc7280-cci | |
| 162 | 164 | - qcom,sm8250-cci |
| 163 | 165 | - qcom,sm8450-cci |
| 164 | 166 | then: |
| @@ -47,6 +47,7 @@ Supported adapters: · 46 unmodified lines | ||
| 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 | |
| @@ -39,6 +39,10 @@ Also, codes returned by adapter probe methods follow rules which are · 38 unmodified lines | ||
| 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 |
| @@ -8825,6 +8825,7 @@ F: include/linux/phy/ · 8824 unmodified lines | ||
| 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 |
| @@ -158,6 +158,7 @@ config I2C_I801 · 157 unmodified lines | ||
| 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. |
| @@ -221,11 +221,10 @@ static int at91_twi_probe(struct platform_device *pdev) · 220 unmodified lines | ||
| 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); |
| @@ -254,8 +253,6 @@ static int at91_twi_probe(struct platform_device *pdev) · 22 unmodified lines | ||
| 254 | 253 | |
| 255 | 254 | rc = i2c_add_numbered_adapter(&dev->adapter); |
| 256 | 255 | if (rc) { |
| 257 | − clk_disable_unprepare(dev->clk); | |
| 258 | − | |
| 259 | 256 | pm_runtime_disable(dev->dev); |
| 260 | 257 | pm_runtime_set_suspended(dev->dev); |
| 261 | 258 | |
| @@ -272,7 +269,6 @@ static void at91_twi_remove(struct platform_device *pdev) · 10 unmodified lines | ||
| 272 | 269 | struct at91_twi_dev *dev = platform_get_drvdata(pdev); |
| 273 | 270 | |
| 274 | 271 | i2c_del_adapter(&dev->adapter); |
| 275 | − clk_disable_unprepare(dev->clk); | |
| 276 | 272 | |
| 277 | 273 | pm_runtime_disable(dev->dev); |
| 278 | 274 | pm_runtime_set_suspended(dev->dev); |
| @@ -131,6 +131,8 @@ · 130 unmodified lines | ||
| 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; |
| @@ -165,7 +167,7 @@ static void i2c_int_enable(struct axxia_i2c_dev *idev, u32 mask) · 28 unmodified lines | ||
| 165 | 167 | writel(int_en | mask, idev->base + MST_INT_ENABLE); |
| 166 | 168 | } |
| 167 | 169 | |
| 168 | −/** | |
| 170 | +/* | |
| 169 | 171 | * ns_to_clk - Convert time (ns) to clock cycles for the given clock frequency. |
| 170 | 172 | */ |
| 171 | 173 | static u32 ns_to_clk(u64 ns, u32 clk_mhz) |
| @@ -263,7 +265,7 @@ static int i2c_m_recv_len(const struct i2c_msg *msg) · 91 unmodified lines | ||
| 263 | 265 | return (msg->flags & I2C_M_RECV_LEN) != 0; |
| 264 | 266 | } |
| 265 | 267 | |
| 266 | −/** | |
| 268 | +/* | |
| 267 | 269 | * axxia_i2c_empty_rx_fifo - Fetch data from RX FIFO and update SMBus block |
| 268 | 270 | * transfer length if this is the first byte of such a transfer. |
| 269 | 271 | */ |
| @@ -295,7 +297,7 @@ static int axxia_i2c_empty_rx_fifo(struct axxia_i2c_dev *idev) · 25 unmodified lines | ||
| 295 | 297 | return 0; |
| 296 | 298 | } |
| 297 | 299 | |
| 298 | −/** | |
| 300 | +/* | |
| 299 | 301 | * axxia_i2c_fill_tx_fifo - Fill TX FIFO from current message buffer. |
| 300 | 302 | * @return: Number of bytes left to transfer. |
| 301 | 303 | */ |
| @@ -160,6 +160,7 @@ struct brcmstb_i2c_dev { · 159 unmodified lines | ||
| 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 */ |
| @@ -240,7 +241,7 @@ static int brcmstb_i2c_wait_for_completion(struct brcmstb_i2c_dev *dev) · 74 unmodified lines | ||
| 240 | 241 | int ret = 0; |
| 241 | 242 | unsigned long timeout = msecs_to_jiffies(I2C_TIMEOUT); |
| 242 | 243 | |
| 243 | − if (dev->irq >= 0) { | |
| 244 | + if (dev->irq >= 0 && !dev->atomic) { | |
| 244 | 245 | if (!wait_for_completion_timeout(&dev->done, timeout)) |
| 245 | 246 | ret = -ETIMEDOUT; |
| 246 | 247 | } else { |
| @@ -287,7 +288,7 @@ static int brcmstb_send_i2c_cmd(struct brcmstb_i2c_dev *dev, · 40 unmodified lines | ||
| 287 | 288 | return rc; |
| 288 | 289 | |
| 289 | 290 | /* only if we are in interrupt mode */ |
| 290 | − if (dev->irq >= 0) | |
| 291 | + if (dev->irq >= 0 && !dev->atomic) | |
| 291 | 292 | reinit_completion(&dev->done); |
| 292 | 293 | |
| 293 | 294 | /* enable BSC CTL interrupt line */ |
| @@ -520,6 +521,23 @@ out: · 226 unmodified lines | ||
| 520 | 521 | |
| 521 | 522 | } |
| 522 | 523 | |
| 524 | +static int brcmstb_i2c_xfer_atomic(struct i2c_adapter *adapter, | |
| 525 | + struct i2c_msg msgs[], int num) | |
| 526 | +{ | |
| 527 | + struct brcmstb_i2c_dev *dev = i2c_get_adapdata(adapter); | |
| 528 | + int ret; | |
| 529 | + | |
| 530 | + if (dev->irq >= 0) | |
| 531 | + disable_irq(dev->irq); | |
| 532 | + dev->atomic = true; | |
| 533 | + ret = brcmstb_i2c_xfer(adapter, msgs, num); | |
| 534 | + dev->atomic = false; | |
| 535 | + if (dev->irq >= 0) | |
| 536 | + enable_irq(dev->irq); | |
| 537 | + | |
| 538 | + return ret; | |
| 539 | +} | |
| 540 | + | |
| 523 | 541 | static u32 brcmstb_i2c_functionality(struct i2c_adapter *adap) |
| 524 | 542 | { |
| 525 | 543 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
| @@ -528,6 +546,7 @@ static u32 brcmstb_i2c_functionality(struct i2c_adapter *adap) · 2 unmodified lines | ||
| 528 | 546 | |
| 529 | 547 | static const struct i2c_algorithm brcmstb_i2c_algo = { |
| 530 | 548 | .master_xfer = brcmstb_i2c_xfer, |
| 549 | + .master_xfer_atomic = brcmstb_i2c_xfer_atomic, | |
| 531 | 550 | .functionality = brcmstb_i2c_functionality, |
| 532 | 551 | }; |
| 533 | 552 | |
| @@ -298,7 +298,7 @@ cp2615_i2c_probe(struct usb_interface *usbif, const struct usb_device_id *id) · 297 unmodified lines | ||
| 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; |
| @@ -194,6 +194,11 @@ struct exynos5_i2c { · 193 unmodified lines | ||
| 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 | |
| @@ -265,7 +270,7 @@ static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c) · 65 unmodified lines | ||
| 265 | 270 | * exynos5_i2c_set_timing: updates the registers with appropriate |
| 266 | 271 | * timing values calculated |
| 267 | 272 | * |
| 268 | − * Timing values for operation are calculated against either 100kHz | |
| 273 | + * Timing values for operation are calculated against 100kHz, 400kHz | |
| 269 | 274 | * or 1MHz controller operating frequency. |
| 270 | 275 | * |
| 271 | 276 | * Returns 0 on success, -EINVAL if the cycle length cannot |
| @@ -328,6 +333,23 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings) · 56 unmodified lines | ||
| 328 | 333 | * |
| 329 | 334 | * Constraints: 4 <= temp, 0 <= CLK_DIV < 256, 2 <= clk_cycle <= 510 |
| 330 | 335 | * |
| 336 | + * To split SCL clock into low, high periods appropriately, one | |
| 337 | + * proportion factor for each I2C mode is used, which is calculated | |
| 338 | + * using this formula. | |
| 339 | + * ``` | |
| 340 | + * ((t_low_min + (scl_clock - t_low_min - t_high_min) / 2) / scl_clock) | |
| 341 | + * ``` | |
| 342 | + * where: | |
| 343 | + * t_low_min is the minimal value of low period of the SCL clock in us; | |
| 344 | + * t_high_min is the minimal value of high period of the SCL clock in us; | |
| 345 | + * scl_clock is converted from SCL clock frequency into us. | |
| 346 | + * | |
| 347 | + * Below are the proportion factors for these I2C modes: | |
| 348 | + * t_low_min, t_high_min, scl_clock, proportion | |
| 349 | + * Standard Mode: 4.7us, 4.0us, 10us, 0.535 | |
| 350 | + * Fast Mode: 1.3us, 0.6us, 2.5us, 0.64 | |
| 351 | + * Fast-Plus Mode: 0.5us, 0.26us, 1us, 0.62 | |
| 352 | + * | |
| 331 | 353 | */ |
| 332 | 354 | t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7; |
| 333 | 355 | temp = clkin / op_clk - 8 - t_ftl_cycle; |
| @@ -341,8 +363,19 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings) · 7 unmodified lines | ||
| 341 | 363 | return -EINVAL; |
| 342 | 364 | } |
| 343 | 365 | |
| 344 | − t_scl_l = clk_cycle / 2; | |
| 345 | − t_scl_h = clk_cycle / 2; | |
| 366 | + /* | |
| 367 | + * Scale clk_cycle to get t_scl_l using the proption factors for individual I2C modes. | |
| 368 | + */ | |
| 369 | + if (op_clk <= I2C_MAX_STANDARD_MODE_FREQ) | |
| 370 | + t_scl_l = clk_cycle * 535 / 1000; | |
| 371 | + else if (op_clk <= I2C_MAX_FAST_MODE_FREQ) | |
| 372 | + t_scl_l = clk_cycle * 64 / 100; | |
| 373 | + else | |
| 374 | + t_scl_l = clk_cycle * 62 / 100; | |
| 375 | + | |
| 376 | + if (t_scl_l > 0xFF) | |
| 377 | + t_scl_l = 0xFF; | |
| 378 | + t_scl_h = clk_cycle - t_scl_l; | |
| 346 | 379 | t_start_su = t_scl_l; |
| 347 | 380 | t_start_hd = t_scl_l; |
| 348 | 381 | t_stop_su = t_scl_l; |
| @@ -711,6 +744,22 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop) · 362 unmodified lines | ||
| 711 | 744 | spin_unlock_irqrestore(&i2c->lock, flags); |
| 712 | 745 | } |
| 713 | 746 | |
| 747 | +static bool exynos5_i2c_poll_irqs_timeout(struct exynos5_i2c *i2c, | |
| 748 | + unsigned long timeout) | |
| 749 | +{ | |
| 750 | + unsigned long time_left = jiffies + timeout; | |
| 751 | + | |
| 752 | + while (time_before(jiffies, time_left) && | |
| 753 | + !((i2c->trans_done && (i2c->msg->len == i2c->msg_ptr)) || | |
| 754 | + (i2c->state < 0))) { | |
| 755 | + while (readl(i2c->regs + HSI2C_INT_ENABLE) & | |
| 756 | + readl(i2c->regs + HSI2C_INT_STATUS)) | |
| 757 | + exynos5_i2c_irq(i2c->irq, i2c); | |
| 758 | + usleep_range(100, 200); | |
| 759 | + } | |
| 760 | + return time_before(jiffies, time_left); | |
| 761 | +} | |
| 762 | + | |
| 714 | 763 | static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, |
| 715 | 764 | struct i2c_msg *msgs, int stop) |
| 716 | 765 | { |
| @@ -725,8 +774,13 @@ static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, · 8 unmodified lines | ||
| 725 | 774 | |
| 726 | 775 | exynos5_i2c_message_start(i2c, stop); |
| 727 | 776 | |
| 728 | − timeout = wait_for_completion_timeout(&i2c->msg_complete, | |
| 729 | − EXYNOS5_I2C_TIMEOUT); | |
| 777 | + if (!i2c->atomic) | |
| 778 | + timeout = wait_for_completion_timeout(&i2c->msg_complete, | |
| 779 | + EXYNOS5_I2C_TIMEOUT); | |
| 780 | + else | |
| 781 | + timeout = exynos5_i2c_poll_irqs_timeout(i2c, | |
| 782 | + EXYNOS5_I2C_TIMEOUT); | |
| 783 | + | |
| 730 | 784 | if (timeout == 0) |
| 731 | 785 | ret = -ETIMEDOUT; |
| 732 | 786 | else |
| @@ -777,6 +831,21 @@ err_pclk: · 44 unmodified lines | ||
| 777 | 831 | return ret ?: num; |
| 778 | 832 | } |
| 779 | 833 | |
| 834 | +static int exynos5_i2c_xfer_atomic(struct i2c_adapter *adap, | |
| 835 | + struct i2c_msg *msgs, int num) | |
| 836 | +{ | |
| 837 | + struct exynos5_i2c *i2c = adap->algo_data; | |
| 838 | + int ret; | |
| 839 | + | |
| 840 | + disable_irq(i2c->irq); | |
| 841 | + i2c->atomic = true; | |
| 842 | + ret = exynos5_i2c_xfer(adap, msgs, num); | |
| 843 | + i2c->atomic = false; | |
| 844 | + enable_irq(i2c->irq); | |
| 845 | + | |
| 846 | + return ret; | |
| 847 | +} | |
| 848 | + | |
| 780 | 849 | static u32 exynos5_i2c_func(struct i2c_adapter *adap) |
| 781 | 850 | { |
| 782 | 851 | return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); |
| @@ -784,6 +853,7 @@ static u32 exynos5_i2c_func(struct i2c_adapter *adap) · 1 unmodified line | ||
| 784 | 853 | |
| 785 | 854 | static const struct i2c_algorithm exynos5_i2c_algorithm = { |
| 786 | 855 | .master_xfer = exynos5_i2c_xfer, |
| 856 | + .master_xfer_atomic = exynos5_i2c_xfer_atomic, | |
| 787 | 857 | .functionality = exynos5_i2c_func, |
| 788 | 858 | }; |
| 789 | 859 | |
| @@ -263,15 +263,10 @@ static void i2c_gpio_fault_injector_init(struct platform_device *pdev) · 262 unmodified lines | ||
| 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 | |
| @@ -79,6 +79,7 @@ · 78 unmodified lines | ||
| 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 |
| @@ -231,6 +232,7 @@ · 146 unmodified lines | ||
| 231 | 232 | #define PCI_DEVICE_ID_INTEL_JASPER_LAKE_SMBUS 0x4da3 |
| 232 | 233 | #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_P_SMBUS 0x51a3 |
| 233 | 234 | #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_M_SMBUS 0x54a3 |
| 235 | +#define PCI_DEVICE_ID_INTEL_BIRCH_STREAM_SMBUS 0x5796 | |
| 234 | 236 | #define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4 |
| 235 | 237 | #define PCI_DEVICE_ID_INTEL_RAPTOR_LAKE_S_SMBUS 0x7a23 |
| 236 | 238 | #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_S_SMBUS 0x7aa3 |
| @@ -285,7 +287,6 @@ struct i801_priv { · 48 unmodified lines | ||
| 285 | 287 | u8 *data; |
| 286 | 288 | |
| 287 | 289 | #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI |
| 288 | − const struct i801_mux_config *mux_drvdata; | |
| 289 | 290 | struct platform_device *mux_pdev; |
| 290 | 291 | struct gpiod_lookup_table *lookup; |
| 291 | 292 | #endif |
| @@ -293,10 +294,9 @@ struct i801_priv { · 1 unmodified line | ||
| 293 | 294 | |
| 294 | 295 | /* |
| 295 | 296 | * If set to true the host controller registers are reserved for |
| 296 | − * ACPI AML use. Protected by acpi_lock. | |
| 297 | + * ACPI AML use. | |
| 297 | 298 | */ |
| 298 | 299 | bool acpi_reserved; |
| 299 | − struct mutex acpi_lock; | |
| 300 | 300 | }; |
| 301 | 301 | |
| 302 | 302 | #define FEATURE_SMBUS_PEC BIT(0) |
| @@ -679,15 +679,11 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, · 376 unmodified lines | ||
| 679 | 679 | return result ? priv->status : -ETIMEDOUT; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | − 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)); | |
| 682 | + if (len == 1 && read_write == I2C_SMBUS_READ) | |
| 683 | + smbcmd |= SMBHSTCNT_LAST_BYTE; | |
| 684 | + outb_p(smbcmd | SMBHSTCNT_START, SMBHSTCNT(priv)); | |
| 690 | 685 | |
| 686 | + for (i = 1; i <= len; i++) { | |
| 691 | 687 | status = i801_wait_byte_done(priv); |
| 692 | 688 | if (status) |
| 693 | 689 | return status; |
| @@ -710,9 +706,12 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, · 16 unmodified lines | ||
| 710 | 706 | data->block[0] = len; |
| 711 | 707 | } |
| 712 | 708 | |
| 713 | − /* Retrieve/store value in SMBBLKDAT */ | |
| 714 | − if (read_write == I2C_SMBUS_READ) | |
| 709 | + if (read_write == I2C_SMBUS_READ) { | |
| 715 | 710 | data->block[i] = inb_p(SMBBLKDAT(priv)); |
| 711 | + if (i == len - 1) | |
| 712 | + outb_p(smbcmd | SMBHSTCNT_LAST_BYTE, SMBHSTCNT(priv)); | |
| 713 | + } | |
| 714 | + | |
| 716 | 715 | if (read_write == I2C_SMBUS_WRITE && i+1 <= len) |
| 717 | 716 | outb_p(data->block[i+1], SMBBLKDAT(priv)); |
| 718 | 717 | |
| @@ -875,11 +874,8 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, · 156 unmodified lines | ||
| 875 | 874 | int hwpec, ret; |
| 876 | 875 | struct i801_priv *priv = i2c_get_adapdata(adap); |
| 877 | 876 | |
| 878 | − mutex_lock(&priv->acpi_lock); | |
| 879 | − if (priv->acpi_reserved) { | |
| 880 | − mutex_unlock(&priv->acpi_lock); | |
| 877 | + if (priv->acpi_reserved) | |
| 881 | 878 | return -EBUSY; |
| 882 | − } | |
| 883 | 879 | |
| 884 | 880 | pm_runtime_get_sync(&priv->pci_dev->dev); |
| 885 | 881 | |
| @@ -920,7 +916,6 @@ out: · 34 unmodified lines | ||
| 920 | 916 | |
| 921 | 917 | pm_runtime_mark_last_busy(&priv->pci_dev->dev); |
| 922 | 918 | pm_runtime_put_autosuspend(&priv->pci_dev->dev); |
| 923 | − mutex_unlock(&priv->acpi_lock); | |
| 924 | 919 | return ret; |
| 925 | 920 | } |
| 926 | 921 | |
| @@ -1044,6 +1039,7 @@ static const struct pci_device_id i801_ids[] = { · 117 unmodified lines | ||
| 1044 | 1039 | { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_P_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, |
| 1045 | 1040 | { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_SOC_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, |
| 1046 | 1041 | { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_PCH_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, |
| 1042 | + { PCI_DEVICE_DATA(INTEL, BIRCH_STREAM_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, | |
| 1047 | 1043 | { 0, } |
| 1048 | 1044 | }; |
| 1049 | 1045 | |
| @@ -1288,7 +1284,7 @@ static void i801_probe_optional_slaves(struct i801_priv *priv) · 238 unmodified lines | ||
| 1288 | 1284 | |
| 1289 | 1285 | /* Instantiate SPD EEPROMs unless the SMBus is multiplexed */ |
| 1290 | 1286 | #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) |
| 1291 | − if (!priv->mux_drvdata) | |
| 1287 | + if (!priv->mux_pdev) | |
| 1292 | 1288 | #endif |
| 1293 | 1289 | i2c_register_spd(&priv->adapter); |
| 1294 | 1290 | } |
| @@ -1390,11 +1386,14 @@ static void i801_add_mux(struct i801_priv *priv) · 95 unmodified lines | ||
| 1390 | 1386 | const struct i801_mux_config *mux_config; |
| 1391 | 1387 | struct i2c_mux_gpio_platform_data gpio_data; |
| 1392 | 1388 | struct gpiod_lookup_table *lookup; |
| 1389 | + const struct dmi_system_id *id; | |
| 1393 | 1390 | int i; |
| 1394 | 1391 | |
| 1395 | − if (!priv->mux_drvdata) | |
| 1392 | + id = dmi_first_match(mux_dmi_table); | |
| 1393 | + if (!id) | |
| 1396 | 1394 | return; |
| 1397 | − mux_config = priv->mux_drvdata; | |
| 1395 | + | |
| 1396 | + mux_config = id->driver_data; | |
| 1398 | 1397 | |
| 1399 | 1398 | /* Prepare the platform data */ |
| 1400 | 1399 | memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data)); |
| @@ -1438,35 +1437,9 @@ static void i801_del_mux(struct i801_priv *priv) · 37 unmodified lines | ||
| 1438 | 1437 | platform_device_unregister(priv->mux_pdev); |
| 1439 | 1438 | gpiod_remove_lookup_table(priv->lookup); |
| 1440 | 1439 | } |
| 1441 | − | |
| 1442 | −static unsigned int i801_get_adapter_class(struct i801_priv *priv) | |
| 1443 | −{ | |
| 1444 | − const struct dmi_system_id *id; | |
| 1445 | − const struct i801_mux_config *mux_config; | |
| 1446 | − unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | |
| 1447 | − int i; | |
| 1448 | − | |
| 1449 | − id = dmi_first_match(mux_dmi_table); | |
| 1450 | − if (id) { | |
| 1451 | − /* Remove branch classes from trunk */ | |
| 1452 | − mux_config = id->driver_data; | |
| 1453 | − for (i = 0; i < mux_config->n_values; i++) | |
| 1454 | − class &= ~mux_config->classes[i]; | |
| 1455 | − | |
| 1456 | − /* Remember for later */ | |
| 1457 | − priv->mux_drvdata = mux_config; | |
| 1458 | − } | |
| 1459 | − | |
| 1460 | − return class; | |
| 1461 | −} | |
| 1462 | 1440 | #else |
| 1463 | 1441 | static inline void i801_add_mux(struct i801_priv *priv) { } |
| 1464 | 1442 | static inline void i801_del_mux(struct i801_priv *priv) { } |
| 1465 | − | |
| 1466 | −static inline unsigned int i801_get_adapter_class(struct i801_priv *priv) | |
| 1467 | −{ | |
| 1468 | − return I2C_CLASS_HWMON | I2C_CLASS_SPD; | |
| 1469 | −} | |
| 1470 | 1443 | #endif |
| 1471 | 1444 | |
| 1472 | 1445 | static struct platform_device * |
| @@ -1572,7 +1545,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits, · 99 unmodified lines | ||
| 1572 | 1545 | * further access from the driver itself. This device is now owned |
| 1573 | 1546 | * by the system firmware. |
| 1574 | 1547 | */ |
| 1575 | − mutex_lock(&priv->acpi_lock); | |
| 1548 | + i2c_lock_bus(&priv->adapter, I2C_LOCK_SEGMENT); | |
| 1576 | 1549 | |
| 1577 | 1550 | if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) { |
| 1578 | 1551 | priv->acpi_reserved = true; |
| @@ -1592,7 +1565,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits, · 13 unmodified lines | ||
| 1592 | 1565 | else |
| 1593 | 1566 | status = acpi_os_write_port(address, (u32)*value, bits); |
| 1594 | 1567 | |
| 1595 | − mutex_unlock(&priv->acpi_lock); | |
| 1568 | + i2c_unlock_bus(&priv->adapter, I2C_LOCK_SEGMENT); | |
| 1596 | 1569 | |
| 1597 | 1570 | return status; |
| 1598 | 1571 | } |
| @@ -1630,6 +1603,12 @@ static void i801_setup_hstcfg(struct i801_priv *priv) · 31 unmodified lines | ||
| 1630 | 1603 | pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hstcfg); |
| 1631 | 1604 | } |
| 1632 | 1605 | |
| 1606 | +static void i801_restore_regs(struct i801_priv *priv) | |
| 1607 | +{ | |
| 1608 | + outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); | |
| 1609 | + pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg); | |
| 1610 | +} | |
| 1611 | + | |
| 1633 | 1612 | static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 1634 | 1613 | { |
| 1635 | 1614 | int err, i; |
| @@ -1641,12 +1620,11 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · 5 unmodified lines | ||
| 1641 | 1620 | |
| 1642 | 1621 | i2c_set_adapdata(&priv->adapter, priv); |
| 1643 | 1622 | priv->adapter.owner = THIS_MODULE; |
| 1644 | − priv->adapter.class = i801_get_adapter_class(priv); | |
| 1623 | + priv->adapter.class = I2C_CLASS_HWMON; | |
| 1645 | 1624 | priv->adapter.algo = &smbus_algorithm; |
| 1646 | 1625 | priv->adapter.dev.parent = &dev->dev; |
| 1647 | − ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev)); | |
| 1626 | + acpi_use_parent_companion(&priv->adapter.dev); | |
| 1648 | 1627 | priv->adapter.retries = 3; |
| 1649 | − mutex_init(&priv->acpi_lock); | |
| 1650 | 1628 | |
| 1651 | 1629 | priv->pci_dev = dev; |
| 1652 | 1630 | priv->features = id->driver_data; |
| @@ -1756,6 +1734,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · 103 unmodified lines | ||
| 1756 | 1734 | if (err) { |
| 1757 | 1735 | platform_device_unregister(priv->tco_pdev); |
| 1758 | 1736 | i801_acpi_remove(priv); |
| 1737 | + i801_restore_regs(priv); | |
| 1759 | 1738 | return err; |
| 1760 | 1739 | } |
| 1761 | 1740 | |
| @@ -1780,12 +1759,10 @@ static void i801_remove(struct pci_dev *dev) · 18 unmodified lines | ||
| 1780 | 1759 | { |
| 1781 | 1760 | struct i801_priv *priv = pci_get_drvdata(dev); |
| 1782 | 1761 | |
| 1783 | − outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); | |
| 1784 | 1762 | i801_disable_host_notify(priv); |
| 1785 | 1763 | i801_del_mux(priv); |
| 1786 | 1764 | i2c_del_adapter(&priv->adapter); |
| 1787 | 1765 | i801_acpi_remove(priv); |
| 1788 | − pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); | |
| 1789 | 1766 | |
| 1790 | 1767 | platform_device_unregister(priv->tco_pdev); |
| 1791 | 1768 | |
| @@ -1793,6 +1770,8 @@ static void i801_remove(struct pci_dev *dev) · 1 unmodified line | ||
| 1793 | 1770 | if (!priv->acpi_reserved) |
| 1794 | 1771 | pm_runtime_get_noresume(&dev->dev); |
| 1795 | 1772 | |
| 1773 | + i801_restore_regs(priv); | |
| 1774 | + | |
| 1796 | 1775 | /* |
| 1797 | 1776 | * do not call pci_disable_device(dev) since it can cause hard hangs on |
| 1798 | 1777 | * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010) |
| @@ -1803,18 +1782,18 @@ static void i801_shutdown(struct pci_dev *dev) · 4 unmodified lines | ||
| 1803 | 1782 | { |
| 1804 | 1783 | struct i801_priv *priv = pci_get_drvdata(dev); |
| 1805 | 1784 | |
| 1806 | − /* Restore config registers to avoid hard hang on some systems */ | |
| 1807 | − outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); | |
| 1808 | 1785 | i801_disable_host_notify(priv); |
| 1809 | − pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); | |
| 1786 | + /* Restore config registers to avoid hard hang on some systems */ | |
| 1787 | + i801_restore_regs(priv); | |
| 1810 | 1788 | } |
| 1811 | 1789 | |
| 1812 | 1790 | static int i801_suspend(struct device *dev) |
| 1813 | 1791 | { |
| 1814 | 1792 | struct i801_priv *priv = dev_get_drvdata(dev); |
| 1815 | 1793 | |
| 1816 | − outb_p(priv->original_hstcnt, SMBHSTCNT(priv)); | |
| 1817 | − pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg); | |
| 1794 | + i2c_mark_adapter_suspended(&priv->adapter); | |
| 1795 | + i801_restore_regs(priv); | |
| 1796 | + | |
| 1818 | 1797 | return 0; |
| 1819 | 1798 | } |
| 1820 | 1799 | |
| @@ -1824,6 +1803,7 @@ static int i801_resume(struct device *dev) · 3 unmodified lines | ||
| 1824 | 1803 | |
| 1825 | 1804 | i801_setup_hstcfg(priv); |
| 1826 | 1805 | i801_enable_host_notify(&priv->adapter); |
| 1806 | + i2c_mark_adapter_resumed(&priv->adapter); | |
| 1827 | 1807 | |
| 1828 | 1808 | return 0; |
| 1829 | 1809 | } |
| @@ -1842,16 +1822,11 @@ static struct pci_driver i801_driver = { · 12 unmodified lines | ||
| 1842 | 1822 | }, |
| 1843 | 1823 | }; |
| 1844 | 1824 | |
| 1845 | −static int __init i2c_i801_init(void) | |
| 1825 | +static int __init i2c_i801_init(struct pci_driver *drv) | |
| 1846 | 1826 | { |
| 1847 | 1827 | if (dmi_name_in_vendors("FUJITSU")) |
| 1848 | 1828 | input_apanel_init(); |
| 1849 | − return pci_register_driver(&i801_driver); | |
| 1850 | −} | |
| 1851 | − | |
| 1852 | −static void __exit i2c_i801_exit(void) | |
| 1853 | −{ | |
| 1854 | − pci_unregister_driver(&i801_driver); | |
| 1829 | + return pci_register_driver(drv); | |
| 1855 | 1830 | } |
| 1856 | 1831 | |
| 1857 | 1832 | MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>"); |
| @@ -1859,5 +1834,4 @@ MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); · 1 unmodified line | ||
| 1859 | 1834 | MODULE_DESCRIPTION("I801 SMBus driver"); |
| 1860 | 1835 | MODULE_LICENSE("GPL"); |
| 1861 | 1836 | |
| 1862 | −module_init(i2c_i801_init); | |
| 1863 | −module_exit(i2c_i801_exit); | |
| 1837 | +module_driver(i801_driver, i2c_i801_init, pci_unregister_driver); | |
| @@ -1442,15 +1442,19 @@ static int mtk_i2c_probe(struct platform_device *pdev) · 1441 unmodified lines | ||
| 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 | |
| @@ -19,11 +19,10 @@ · 18 unmodified lines | ||
| 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> |
| @@ -859,7 +858,7 @@ static int · 829 unmodified lines | ||
| 859 | 858 | mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, |
| 860 | 859 | struct device *dev) |
| 861 | 860 | { |
| 862 | − const struct of_device_id *device; | |
| 861 | + const struct mv64xxx_i2c_regs *data; | |
| 863 | 862 | struct device_node *np = dev->of_node; |
| 864 | 863 | u32 bus_freq, tclk; |
| 865 | 864 | int rc = 0; |
| @@ -897,11 +896,11 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, · 31 unmodified lines | ||
| 897 | 896 | */ |
| 898 | 897 | drv_data->adapter.timeout = HZ; |
| 899 | 898 | |
| 900 | − device = of_match_device(mv64xxx_i2c_of_match_table, dev); | |
| 901 | − if (!device) | |
| 899 | + data = device_get_match_data(dev); | |
| 900 | + if (!data) | |
| 902 | 901 | return -ENODEV; |
| 903 | 902 | |
| 904 | − memcpy(&drv_data->reg_offsets, device->data, sizeof(drv_data->reg_offsets)); | |
| 903 | + memcpy(&drv_data->reg_offsets, data, sizeof(drv_data->reg_offsets)); | |
| 905 | 904 | |
| 906 | 905 | /* |
| 907 | 906 | * For controllers embedded in new SoCs activate the |
| @@ -25,11 +25,11 @@ · 24 unmodified lines | ||
| 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,7 +1358,6 @@ omap_i2c_probe(struct platform_device *pdev) · 1322 unmodified lines | ||
| 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; |
| @@ -1376,11 +1375,10 @@ omap_i2c_probe(struct platform_device *pdev) · 11 unmodified lines | ||
| 1376 | 1375 | if (IS_ERR(omap->base)) |
| 1377 | 1376 | return PTR_ERR(omap->base); |
| 1378 | 1377 | |
| 1379 | − match = of_match_device(of_match_ptr(omap_i2c_of_match), &pdev->dev); | |
| 1380 | − if (match) { | |
| 1378 | + if (pdev->dev.of_node) { | |
| 1381 | 1379 | u32 freq = I2C_MAX_STANDARD_MODE_FREQ; |
| 1382 | 1380 | |
| 1383 | − pdata = match->data; | |
| 1381 | + pdata = device_get_match_data(&pdev->dev); | |
| 1384 | 1382 | omap->flags = pdata->flags; |
| 1385 | 1383 | |
| 1386 | 1384 | of_property_read_u32(node, "clock-frequency", &freq); |
| @@ -231,7 +231,7 @@ static void i2c_powermac_create_one(struct i2c_adapter *adap, · 230 unmodified lines | ||
| 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)) |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | ||
| 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 */ |
| @@ -1252,10 +1253,8 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, · 1214 unmodified lines | ||
| 1252 | 1253 | enum pxa_i2c_types *i2c_types) |
| 1253 | 1254 | { |
| 1254 | 1255 | struct device_node *np = pdev->dev.of_node; |
| 1255 | − const struct of_device_id *of_id = | |
| 1256 | − of_match_device(i2c_pxa_dt_ids, &pdev->dev); | |
| 1257 | 1256 | |
| 1258 | − if (!of_id) | |
| 1257 | + if (!pdev->dev.of_node) | |
| 1259 | 1258 | return 1; |
| 1260 | 1259 | |
| 1261 | 1260 | /* For device tree we always use the dynamic or alias-assigned ID */ |
| @@ -1264,7 +1263,7 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, · 2 unmodified lines | ||
| 1264 | 1263 | i2c->use_pio = of_property_read_bool(np, "mrvl,i2c-polling"); |
| 1265 | 1264 | i2c->fast_mode = of_property_read_bool(np, "mrvl,i2c-fast-mode"); |
| 1266 | 1265 | |
| 1267 | − *i2c_types = (enum pxa_i2c_types)(of_id->data); | |
| 1266 | + *i2c_types = (enum pxa_i2c_types)device_get_match_data(&pdev->dev); | |
| 1268 | 1267 | |
| 1269 | 1268 | return 0; |
| 1270 | 1269 | } |
| @@ -722,6 +722,7 @@ static const struct i2c_algorithm geni_i2c_algo = { · 721 unmodified lines | ||
| 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); |
| @@ -41,6 +41,10 @@ · 40 unmodified lines | ||
| 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 | |
| @@ -84,11 +88,25 @@ · 37 unmodified lines | ||
| 84 | 88 | #define RMDMAE BIT(1) /* DMA Master Received Enable */ |
| 85 | 89 | #define TMDMAE BIT(0) /* DMA Master Transmitted Enable */ |
| 86 | 90 | |
| 91 | +/* ICCCR2 */ | |
| 92 | +#define CDFD BIT(2) /* CDF Disable */ | |
| 93 | +#define HLSE BIT(1) /* HIGH/LOW Separate Control Enable */ | |
| 94 | +#define SME BIT(0) /* SCL Mask Enable */ | |
| 95 | + | |
| 87 | 96 | /* ICFBSCR */ |
| 88 | 97 | #define TCYC17 0x0f /* 17*Tcyc delay 1st bit between SDA and SCL */ |
| 89 | 98 | |
| 90 | 99 | #define RCAR_MIN_DMA_LEN 8 |
| 91 | 100 | |
| 101 | +/* SCL low/high ratio 5:4 to meet all I2C timing specs (incl safety margin) */ | |
| 102 | +#define RCAR_SCLD_RATIO 5 | |
| 103 | +#define RCAR_SCHD_RATIO 4 | |
| 104 | +/* | |
| 105 | + * SMD should be smaller than SCLD/SCHD and is always around 20 in the docs. | |
| 106 | + * Thus, we simply use 20 which works for low and high speeds. | |
| 107 | + */ | |
| 108 | +#define RCAR_DEFAULT_SMD 20 | |
| 109 | + | |
| 92 | 110 | #define RCAR_BUS_PHASE_START (MDBS | MIE | ESG) |
| 93 | 111 | #define RCAR_BUS_PHASE_DATA (MDBS | MIE) |
| 94 | 112 | #define RCAR_BUS_PHASE_STOP (MDBS | MIE | FSB) |
| @@ -128,6 +146,8 @@ struct rcar_i2c_priv { · 33 unmodified lines | ||
| 128 | 146 | |
| 129 | 147 | int pos; |
| 130 | 148 | u32 icccr; |
| 149 | + u16 schd; | |
| 150 | + u16 scld; | |
| 131 | 151 | u8 recovery_icmcr; /* protected by adapter lock */ |
| 132 | 152 | enum rcar_i2c_type devtype; |
| 133 | 153 | struct i2c_client *slave; |
| @@ -216,11 +236,16 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv) · 82 unmodified lines | ||
| 216 | 236 | rcar_i2c_write(priv, ICMCR, MDBS); |
| 217 | 237 | rcar_i2c_write(priv, ICMSR, 0); |
| 218 | 238 | /* start clock */ |
| 219 | − rcar_i2c_write(priv, ICCCR, priv->icccr); | |
| 220 | − | |
| 221 | − if (priv->devtype == I2C_RCAR_GEN3) | |
| 239 | + if (priv->devtype < I2C_RCAR_GEN3) { | |
| 240 | + rcar_i2c_write(priv, ICCCR, priv->icccr); | |
| 241 | + } else { | |
| 242 | + rcar_i2c_write(priv, ICCCR2, CDFD | HLSE | SME); | |
| 243 | + rcar_i2c_write(priv, ICCCR, priv->icccr); | |
| 244 | + rcar_i2c_write(priv, ICMPR, RCAR_DEFAULT_SMD); | |
| 245 | + rcar_i2c_write(priv, ICHPR, priv->schd); | |
| 246 | + rcar_i2c_write(priv, ICLPR, priv->scld); | |
| 222 | 247 | rcar_i2c_write(priv, ICFBSCR, TCYC17); |
| 223 | − | |
| 248 | + } | |
| 224 | 249 | } |
| 225 | 250 | |
| 226 | 251 | static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) |
| @@ -241,7 +266,7 @@ static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) · 14 unmodified lines | ||
| 241 | 266 | |
| 242 | 267 | static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) |
| 243 | 268 | { |
| 244 | − u32 scgd, cdf, round, ick, sum, scl, cdf_width; | |
| 269 | + u32 cdf, round, ick, sum, scl, cdf_width; | |
| 245 | 270 | unsigned long rate; |
| 246 | 271 | struct device *dev = rcar_i2c_priv_to_dev(priv); |
| 247 | 272 | struct i2c_timings t = { |
| @@ -254,27 +279,17 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) · 6 unmodified lines | ||
| 254 | 279 | /* Fall back to previously used values if not supplied */ |
| 255 | 280 | i2c_parse_fw_timings(dev, &t, false); |
| 256 | 281 | |
| 257 | − switch (priv->devtype) { | |
| 258 | − case I2C_RCAR_GEN1: | |
| 259 | − cdf_width = 2; | |
| 260 | − break; | |
| 261 | − case I2C_RCAR_GEN2: | |
| 262 | − case I2C_RCAR_GEN3: | |
| 263 | − cdf_width = 3; | |
| 264 | − break; | |
| 265 | − default: | |
| 266 | − dev_err(dev, "device type error\n"); | |
| 267 | − return -EIO; | |
| 268 | − } | |
| 269 | − | |
| 270 | 282 | /* |
| 271 | 283 | * calculate SCL clock |
| 272 | 284 | * see |
| 273 | − * ICCCR | |
| 285 | + * ICCCR (and ICCCR2 for Gen3+) | |
| 274 | 286 | * |
| 275 | 287 | * ick = clkp / (1 + CDF) |
| 276 | 288 | * SCL = ick / (20 + SCGD * 8 + F[(ticf + tr + intd) * ick]) |
| 277 | 289 | * |
| 290 | + * for Gen3+: | |
| 291 | + * SCL = clkp / (8 + SMD * 2 + SCLD + SCHD +F[(ticf + tr + intd) * clkp]) | |
| 292 | + * | |
| 278 | 293 | * ick : I2C internal clock < 20 MHz |
| 279 | 294 | * ticf : I2C SCL falling time |
| 280 | 295 | * tr : I2C SCL rising time |
| @@ -284,52 +299,82 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) · 3 unmodified lines | ||
| 284 | 299 | */ |
| 285 | 300 | rate = clk_get_rate(priv->clk); |
| 286 | 301 | cdf = rate / 20000000; |
| 287 | − if (cdf >= 1U << cdf_width) { | |
| 288 | − dev_err(dev, "Input clock %lu too high\n", rate); | |
| 289 | − return -EIO; | |
| 290 | − } | |
| 291 | − ick = rate / (cdf + 1); | |
| 302 | + cdf_width = (priv->devtype == I2C_RCAR_GEN1) ? 2 : 3; | |
| 303 | + if (cdf >= 1U << cdf_width) | |
| 304 | + goto err_no_val; | |
| 305 | + | |
| 306 | + /* On Gen3+, we use cdf only for the filters, not as a SCL divider */ | |
| 307 | + ick = rate / (priv->devtype < I2C_RCAR_GEN3 ? (cdf + 1) : 1); | |
| 292 | 308 | |
| 293 | 309 | /* |
| 294 | − * it is impossible to calculate large scale | |
| 295 | − * number on u32. separate it | |
| 310 | + * It is impossible to calculate a large scale number on u32. Separate it. | |
| 296 | 311 | * |
| 297 | 312 | * F[(ticf + tr + intd) * ick] with sum = (ticf + tr + intd) |
| 298 | 313 | * = F[sum * ick / 1000000000] |
| 299 | 314 | * = F[(ick / 1000000) * sum / 1000] |
| 300 | 315 | */ |
| 301 | 316 | sum = t.scl_fall_ns + t.scl_rise_ns + t.scl_int_delay_ns; |
| 302 | − round = (ick + 500000) / 1000000 * sum; | |
| 303 | − round = (round + 500) / 1000; | |
| 317 | + round = DIV_ROUND_CLOSEST(ick, 1000000); | |
| 318 | + round = DIV_ROUND_CLOSEST(round * sum, 1000); | |
| 304 | 319 | |
| 305 | − /* | |
| 306 | − * SCL = ick / (20 + SCGD * 8 + F[(ticf + tr + intd) * ick]) | |
| 307 | − * | |
| 308 | − * Calculation result (= SCL) should be less than | |
| 309 | − * bus_speed for hardware safety | |
| 310 | − * | |
| 311 | − * We could use something along the lines of | |
| 312 | − * div = ick / (bus_speed + 1) + 1; | |
| 313 | − * scgd = (div - 20 - round + 7) / 8; | |
| 314 | − * scl = ick / (20 + (scgd * 8) + round); | |
| 315 | − * (not fully verified) but that would get pretty involved | |
| 316 | − */ | |
| 317 | − for (scgd = 0; scgd < 0x40; scgd++) { | |
| 318 | − scl = ick / (20 + (scgd * 8) + round); | |
| 319 | − if (scl <= t.bus_freq_hz) | |
| 320 | − goto scgd_find; | |
| 321 | − } | |
| 322 | − dev_err(dev, "it is impossible to calculate best SCL\n"); | |
| 323 | − return -EIO; | |
| 320 | + if (priv->devtype < I2C_RCAR_GEN3) { | |
| 321 | + u32 scgd; | |
| 322 | + /* | |
| 323 | + * SCL = ick / (20 + 8 * SCGD + F[(ticf + tr + intd) * ick]) | |
| 324 | + * 20 + 8 * SCGD + F[...] = ick / SCL | |
| 325 | + * SCGD = ((ick / SCL) - 20 - F[...]) / 8 | |
| 326 | + * Result (= SCL) should be less than bus_speed for hardware safety | |
| 327 | + */ | |
| 328 | + scgd = DIV_ROUND_UP(ick, t.bus_freq_hz ?: 1); | |
| 329 | + scgd = DIV_ROUND_UP(scgd - 20 - round, 8); | |
| 330 | + scl = ick / (20 + 8 * scgd + round); | |
| 331 | + | |
| 332 | + if (scgd > 0x3f) | |
| 333 | + goto err_no_val; | |
| 324 | 334 | |
| 325 | −scgd_find: | |
| 326 | − dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n", | |
| 327 | − scl, t.bus_freq_hz, rate, round, cdf, scgd); | |
| 335 | + dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u, SCGD: %u\n", | |
| 336 | + scl, t.bus_freq_hz, rate, round, cdf, scgd); | |
| 328 | 337 | |
| 329 | − /* keep icccr value */ | |
| 330 | − priv->icccr = scgd << cdf_width | cdf; | |
| 338 | + priv->icccr = scgd << cdf_width | cdf; | |
| 339 | + } else { | |
| 340 | + u32 x, sum_ratio = RCAR_SCHD_RATIO + RCAR_SCLD_RATIO; | |
| 341 | + /* | |
| 342 | + * SCLD/SCHD ratio and SMD default value are explained above | |
| 343 | + * where they are defined. With these definitions, we can compute | |
| 344 | + * x as a base value for the SCLD/SCHD ratio: | |
| 345 | + * | |
| 346 | + * SCL = clkp / (8 + 2 * SMD + SCLD + SCHD + F[(ticf + tr + intd) * clkp]) | |
| 347 | + * SCL = clkp / (8 + 2 * RCAR_DEFAULT_SMD + RCAR_SCLD_RATIO * x | |
| 348 | + * + RCAR_SCHD_RATIO * x + F[...]) | |
| 349 | + * | |
| 350 | + * with: sum_ratio = RCAR_SCLD_RATIO + RCAR_SCHD_RATIO | |
| 351 | + * and: smd = RCAR_DEFAULT_SMD | |
| 352 | + * | |
| 353 | + * SCL = clkp / (8 + 2 * smd + sum_ratio * x + F[...]) | |
| 354 | + * 8 + 2 * smd + sum_ratio * x + F[...] = clkp / SCL | |
| 355 | + * x = ((clkp / SCL) - 8 - 2 * smd - F[...]) / sum_ratio | |
| 356 | + */ | |
| 357 | + x = DIV_ROUND_UP(rate, t.bus_freq_hz ?: 1); | |
| 358 | + x = DIV_ROUND_UP(x - 8 - 2 * RCAR_DEFAULT_SMD - round, sum_ratio); | |
| 359 | + scl = rate / (8 + 2 * RCAR_DEFAULT_SMD + sum_ratio * x + round); | |
| 360 | + | |
| 361 | + /* Bail out if values don't fit into 16 bit or SMD became too large */ | |
| 362 | + if (x * RCAR_SCLD_RATIO > 0xffff || RCAR_DEFAULT_SMD > x * RCAR_SCHD_RATIO) | |
| 363 | + goto err_no_val; | |
| 364 | + | |
| 365 | + priv->icccr = cdf; | |
| 366 | + priv->schd = RCAR_SCHD_RATIO * x; | |
| 367 | + priv->scld = RCAR_SCLD_RATIO * x; | |
| 368 | + | |
| 369 | + dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCHD %u SCLD %u\n", | |
| 370 | + scl, t.bus_freq_hz, rate, round, cdf, priv->schd, priv->scld); | |
| 371 | + } | |
| 331 | 372 | |
| 332 | 373 | return 0; |
| 374 | + | |
| 375 | +err_no_val: | |
| 376 | + dev_err(dev, "it is impossible to calculate best SCL\n"); | |
| 377 | + return -EINVAL; | |
| 333 | 378 | } |
| 334 | 379 | |
| 335 | 380 | /* |
| @@ -843,12 +888,10 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap, · 507 unmodified lines | ||
| 843 | 888 | |
| 844 | 889 | /* Gen3 needs a reset before allowing RXDMA once */ |
| 845 | 890 | if (priv->devtype == I2C_RCAR_GEN3) { |
| 846 | − priv->flags |= ID_P_NO_RXDMA; | |
| 847 | − if (!IS_ERR(priv->rstc)) { | |
| 848 | − ret = rcar_i2c_do_reset(priv); | |
| 849 | − if (ret == 0) | |
| 850 | − priv->flags &= ~ID_P_NO_RXDMA; | |
| 851 | − } | |
| 891 | + priv->flags &= ~ID_P_NO_RXDMA; | |
| 892 | + ret = rcar_i2c_do_reset(priv); | |
| 893 | + if (ret) | |
| 894 | + goto out; | |
| 852 | 895 | } |
| 853 | 896 | |
| 854 | 897 | rcar_i2c_init(priv); |
| @@ -1099,15 +1142,6 @@ static int rcar_i2c_probe(struct platform_device *pdev) · 244 unmodified lines | ||
| 1099 | 1142 | irqhandler = rcar_i2c_gen2_irq; |
| 1100 | 1143 | } |
| 1101 | 1144 | |
| 1102 | − if (priv->devtype == I2C_RCAR_GEN3) { | |
| 1103 | − priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); | |
| 1104 | − if (!IS_ERR(priv->rstc)) { | |
| 1105 | − ret = reset_control_status(priv->rstc); | |
| 1106 | − if (ret < 0) | |
| 1107 | − priv->rstc = ERR_PTR(-ENOTSUPP); | |
| 1108 | − } | |
| 1109 | − } | |
| 1110 | − | |
| 1111 | 1145 | /* Stay always active when multi-master to keep arbitration working */ |
| 1112 | 1146 | if (of_property_read_bool(dev->of_node, "multi-master")) |
| 1113 | 1147 | priv->flags |= ID_P_PM_BLOCKED; |
| @@ -1117,6 +1151,18 @@ static int rcar_i2c_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 1117 | 1151 | if (of_property_read_bool(dev->of_node, "smbus")) |
| 1118 | 1152 | priv->flags |= ID_P_HOST_NOTIFY; |
| 1119 | 1153 | |
| 1154 | + if (priv->devtype == I2C_RCAR_GEN3) { | |
| 1155 | + priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); | |
| 1156 | + if (IS_ERR(priv->rstc)) { | |
| 1157 | + ret = PTR_ERR(priv->rstc); | |
| 1158 | + goto out_pm_put; | |
| 1159 | + } | |
| 1160 | + | |
| 1161 | + ret = reset_control_status(priv->rstc); | |
| 1162 | + if (ret < 0) | |
| 1163 | + goto out_pm_put; | |
| 1164 | + } | |
| 1165 | + | |
| 1120 | 1166 | ret = platform_get_irq(pdev, 0); |
| 1121 | 1167 | if (ret < 0) |
| 1122 | 1168 | goto out_pm_put; |
| @@ -313,7 +313,7 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) · 312 unmodified lines | ||
| 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 | /* |
| @@ -133,7 +133,7 @@ static const struct platform_device_id s3c24xx_driver_ids[] = { · 132 unmodified lines | ||
| 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,11 +377,10 @@ static inline int is_msgend(struct s3c24xx_i2c *i2c) · 237 unmodified lines | ||
| 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 | |
| @@ -544,7 +543,7 @@ static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) · 156 unmodified lines | ||
| 544 | 543 | tmp &= ~S3C2410_IICCON_IRQPEND; |
| 545 | 544 | writel(tmp, i2c->regs + S3C2410_IICCON); |
| 546 | 545 | out: |
| 547 | − return ret; | |
| 546 | + return; | |
| 548 | 547 | } |
| 549 | 548 | |
| 550 | 549 | /* |
| @@ -783,23 +783,17 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) · 782 unmodified lines | ||
| 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 | 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 | − } | |
| 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); |
| @@ -816,7 +810,7 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) · 10 unmodified lines | ||
| 816 | 810 | if (ret) { |
| 817 | 811 | dev_err(&pdev->dev, "Failed to request irq event %i\n", |
| 818 | 812 | irq_event); |
| 819 | − goto clk_free; | |
| 813 | + return ret; | |
| 820 | 814 | } |
| 821 | 815 | |
| 822 | 816 | ret = devm_request_irq(&pdev->dev, irq_error, stm32f4_i2c_isr_error, 0, |
| @@ -824,12 +818,12 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) · 1 unmodified line | ||
| 824 | 818 | if (ret) { |
| 825 | 819 | dev_err(&pdev->dev, "Failed to request irq error %i\n", |
| 826 | 820 | irq_error); |
| 827 | − goto clk_free; | |
| 821 | + return ret; | |
| 828 | 822 | } |
| 829 | 823 | |
| 830 | 824 | ret = stm32f4_i2c_hw_config(i2c_dev); |
| 831 | 825 | if (ret) |
| 832 | − goto clk_free; | |
| 826 | + return ret; | |
| 833 | 827 | |
| 834 | 828 | adap = &i2c_dev->adap; |
| 835 | 829 | i2c_set_adapdata(adap, i2c_dev); |
| @@ -845,7 +839,7 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) · 9 unmodified lines | ||
| 845 | 839 | |
| 846 | 840 | ret = i2c_add_adapter(adap); |
| 847 | 841 | if (ret) |
| 848 | − goto clk_free; | |
| 842 | + return ret; | |
| 849 | 843 | |
| 850 | 844 | platform_set_drvdata(pdev, i2c_dev); |
| 851 | 845 | |
| @@ -854,10 +848,6 @@ static int stm32f4_i2c_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 854 | 848 | dev_info(i2c_dev->dev, "STM32F4 I2C driver registered\n"); |
| 855 | 849 | |
| 856 | 850 | return 0; |
| 857 | − | |
| 858 | −clk_free: | |
| 859 | − clk_disable_unprepare(i2c_dev->clk); | |
| 860 | − return ret; | |
| 861 | 851 | } |
| 862 | 852 | |
| 863 | 853 | static void stm32f4_i2c_remove(struct platform_device *pdev) |
| @@ -865,8 +855,6 @@ static void stm32f4_i2c_remove(struct platform_device *pdev) · 1 unmodified line | ||
| 865 | 855 | struct stm32f4_i2c_dev *i2c_dev = platform_get_drvdata(pdev); |
| 866 | 856 | |
| 867 | 857 | i2c_del_adapter(&i2c_dev->adap); |
| 868 | − | |
| 869 | − clk_unprepare(i2c_dev->clk); | |
| 870 | 858 | } |
| 871 | 859 | |
| 872 | 860 | static const struct of_device_id stm32f4_i2c_match[] = { |
| @@ -325,6 +325,7 @@ struct stm32f7_i2c_alert { · 324 unmodified lines | ||
| 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; |
| @@ -357,6 +358,7 @@ struct stm32f7_i2c_dev { · 26 unmodified lines | ||
| 357 | 358 | u32 dnf_dt; |
| 358 | 359 | u32 dnf; |
| 359 | 360 | struct stm32f7_i2c_alert *alert; |
| 361 | + bool atomic; | |
| 360 | 362 | }; |
| 361 | 363 | |
| 362 | 364 | /* |
| @@ -915,7 +917,8 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, · 552 unmodified lines | ||
| 915 | 917 | |
| 916 | 918 | /* Configure DMA or enable RX/TX interrupt */ |
| 917 | 919 | i2c_dev->use_dma = false; |
| 918 | − if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) { | |
| 920 | + if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN | |
| 921 | + && !i2c_dev->atomic) { | |
| 919 | 922 | ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma, |
| 920 | 923 | msg->flags & I2C_M_RD, |
| 921 | 924 | f7_msg->count, f7_msg->buf, |
| @@ -939,6 +942,9 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, · 17 unmodified lines | ||
| 939 | 942 | cr1 |= STM32F7_I2C_CR1_TXDMAEN; |
| 940 | 943 | } |
| 941 | 944 | |
| 945 | + if (i2c_dev->atomic) | |
| 946 | + cr1 &= ~STM32F7_I2C_ALL_IRQ_MASK; /* Disable all interrupts */ | |
| 947 | + | |
| 942 | 948 | /* Configure Start/Repeated Start */ |
| 943 | 949 | cr2 |= STM32F7_I2C_CR2_START; |
| 944 | 950 | |
| @@ -1673,7 +1679,22 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data) · 728 unmodified lines | ||
| 1673 | 1679 | return IRQ_HANDLED; |
| 1674 | 1680 | } |
| 1675 | 1681 | |
| 1676 | −static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap, | |
| 1682 | +static int stm32f7_i2c_wait_polling(struct stm32f7_i2c_dev *i2c_dev) | |
| 1683 | +{ | |
| 1684 | + ktime_t timeout = ktime_add_ms(ktime_get(), i2c_dev->adap.timeout); | |
| 1685 | + | |
| 1686 | + while (ktime_compare(ktime_get(), timeout) < 0) { | |
| 1687 | + udelay(5); | |
| 1688 | + stm32f7_i2c_isr_event(0, i2c_dev); | |
| 1689 | + | |
| 1690 | + if (completion_done(&i2c_dev->complete)) | |
| 1691 | + return 1; | |
| 1692 | + } | |
| 1693 | + | |
| 1694 | + return 0; | |
| 1695 | +} | |
| 1696 | + | |
| 1697 | +static int stm32f7_i2c_xfer_core(struct i2c_adapter *i2c_adap, | |
| 1677 | 1698 | struct i2c_msg msgs[], int num) |
| 1678 | 1699 | { |
| 1679 | 1700 | struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); |
| @@ -1697,8 +1718,12 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap, · 17 unmodified lines | ||
| 1697 | 1718 | |
| 1698 | 1719 | stm32f7_i2c_xfer_msg(i2c_dev, msgs); |
| 1699 | 1720 | |
| 1700 | − time_left = wait_for_completion_timeout(&i2c_dev->complete, | |
| 1701 | − i2c_dev->adap.timeout); | |
| 1721 | + if (!i2c_dev->atomic) | |
| 1722 | + time_left = wait_for_completion_timeout(&i2c_dev->complete, | |
| 1723 | + i2c_dev->adap.timeout); | |
| 1724 | + else | |
| 1725 | + time_left = stm32f7_i2c_wait_polling(i2c_dev); | |
| 1726 | + | |
| 1702 | 1727 | ret = f7_msg->result; |
| 1703 | 1728 | if (ret) { |
| 1704 | 1729 | if (i2c_dev->use_dma) |
| @@ -1730,6 +1755,24 @@ pm_free: · 25 unmodified lines | ||
| 1730 | 1755 | return (ret < 0) ? ret : num; |
| 1731 | 1756 | } |
| 1732 | 1757 | |
| 1758 | +static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap, | |
| 1759 | + struct i2c_msg msgs[], int num) | |
| 1760 | +{ | |
| 1761 | + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); | |
| 1762 | + | |
| 1763 | + i2c_dev->atomic = false; | |
| 1764 | + return stm32f7_i2c_xfer_core(i2c_adap, msgs, num); | |
| 1765 | +} | |
| 1766 | + | |
| 1767 | +static int stm32f7_i2c_xfer_atomic(struct i2c_adapter *i2c_adap, | |
| 1768 | + struct i2c_msg msgs[], int num) | |
| 1769 | +{ | |
| 1770 | + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); | |
| 1771 | + | |
| 1772 | + i2c_dev->atomic = true; | |
| 1773 | + return stm32f7_i2c_xfer_core(i2c_adap, msgs, num); | |
| 1774 | +} | |
| 1775 | + | |
| 1733 | 1776 | static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, |
| 1734 | 1777 | unsigned short flags, char read_write, |
| 1735 | 1778 | u8 command, int size, |
| @@ -2098,6 +2141,7 @@ static u32 stm32f7_i2c_func(struct i2c_adapter *adap) · 362 unmodified lines | ||
| 2098 | 2141 | |
| 2099 | 2142 | static const struct i2c_algorithm stm32f7_i2c_algo = { |
| 2100 | 2143 | .master_xfer = stm32f7_i2c_xfer, |
| 2144 | + .master_xfer_atomic = stm32f7_i2c_xfer_atomic, | |
| 2101 | 2145 | .smbus_xfer = stm32f7_i2c_smbus_xfer, |
| 2102 | 2146 | .functionality = stm32f7_i2c_func, |
| 2103 | 2147 | .reg_slave = stm32f7_i2c_reg_slave, |
| @@ -2134,23 +2178,16 @@ static int stm32f7_i2c_probe(struct platform_device *pdev) · 30 unmodified lines | ||
| 2134 | 2178 | i2c_dev->wakeup_src = of_property_read_bool(pdev->dev.of_node, |
| 2135 | 2179 | "wakeup-source"); |
| 2136 | 2180 | |
| 2137 | − i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); | |
| 2181 | + i2c_dev->clk = devm_clk_get_enabled(&pdev->dev, NULL); | |
| 2138 | 2182 | if (IS_ERR(i2c_dev->clk)) |
| 2139 | 2183 | return dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->clk), |
| 2140 | − "Failed to get controller clock\n"); | |
| 2141 | − | |
| 2142 | − ret = clk_prepare_enable(i2c_dev->clk); | |
| 2143 | − if (ret) { | |
| 2144 | − dev_err(&pdev->dev, "Failed to prepare_enable clock\n"); | |
| 2145 | − return ret; | |
| 2146 | − } | |
| 2184 | + "Failed to enable controller clock\n"); | |
| 2147 | 2185 | |
| 2148 | 2186 | rst = devm_reset_control_get(&pdev->dev, NULL); |
| 2149 | − if (IS_ERR(rst)) { | |
| 2150 | − ret = dev_err_probe(&pdev->dev, PTR_ERR(rst), | |
| 2151 | − "Error: Missing reset ctrl\n"); | |
| 2152 | − goto clk_free; | |
| 2153 | − } | |
| 2187 | + if (IS_ERR(rst)) | |
| 2188 | + return dev_err_probe(&pdev->dev, PTR_ERR(rst), | |
| 2189 | + "Error: Missing reset ctrl\n"); | |
| 2190 | + | |
| 2154 | 2191 | reset_control_assert(rst); |
| 2155 | 2192 | udelay(2); |
| 2156 | 2193 | reset_control_deassert(rst); |
| @@ -2165,7 +2202,7 @@ static int stm32f7_i2c_probe(struct platform_device *pdev) · 8 unmodified lines | ||
| 2165 | 2202 | if (ret) { |
| 2166 | 2203 | dev_err(&pdev->dev, "Failed to request irq event %i\n", |
| 2167 | 2204 | irq_event); |
| 2168 | − goto clk_free; | |
| 2205 | + return ret; | |
| 2169 | 2206 | } |
| 2170 | 2207 | |
| 2171 | 2208 | ret = devm_request_irq(&pdev->dev, irq_error, stm32f7_i2c_isr_error, 0, |
| @@ -2173,29 +2210,28 @@ static int stm32f7_i2c_probe(struct platform_device *pdev) · 1 unmodified line | ||
| 2173 | 2210 | if (ret) { |
| 2174 | 2211 | dev_err(&pdev->dev, "Failed to request irq error %i\n", |
| 2175 | 2212 | irq_error); |
| 2176 | − goto clk_free; | |
| 2213 | + return ret; | |
| 2177 | 2214 | } |
| 2178 | 2215 | |
| 2179 | 2216 | setup = of_device_get_match_data(&pdev->dev); |
| 2180 | 2217 | if (!setup) { |
| 2181 | 2218 | dev_err(&pdev->dev, "Can't get device data\n"); |
| 2182 | − ret = -ENODEV; | |
| 2183 | − goto clk_free; | |
| 2219 | + return -ENODEV; | |
| 2184 | 2220 | } |
| 2185 | 2221 | i2c_dev->setup = *setup; |
| 2186 | 2222 | |
| 2187 | 2223 | ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup); |
| 2188 | 2224 | if (ret) |
| 2189 | − goto clk_free; | |
| 2225 | + return ret; | |
| 2190 | 2226 | |
| 2191 | 2227 | /* Setup Fast mode plus if necessary */ |
| 2192 | 2228 | if (i2c_dev->bus_rate > I2C_MAX_FAST_MODE_FREQ) { |
| 2193 | 2229 | ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev); |
| 2194 | 2230 | if (ret) |
| 2195 | − goto clk_free; | |
| 2231 | + return ret; | |
| 2196 | 2232 | ret = stm32f7_i2c_write_fm_plus_bits(i2c_dev, true); |
| 2197 | 2233 | if (ret) |
| 2198 | − goto clk_free; | |
| 2234 | + return ret; | |
| 2199 | 2235 | } |
| 2200 | 2236 | |
| 2201 | 2237 | adap = &i2c_dev->adap; |
| @@ -2306,9 +2342,6 @@ clr_wakeup_capable: · 104 unmodified lines | ||
| 2306 | 2342 | fmp_clear: |
| 2307 | 2343 | stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); |
| 2308 | 2344 | |
| 2309 | −clk_free: | |
| 2310 | − clk_disable_unprepare(i2c_dev->clk); | |
| 2311 | − | |
| 2312 | 2345 | return ret; |
| 2313 | 2346 | } |
| 2314 | 2347 | |
| @@ -2342,8 +2375,6 @@ static void stm32f7_i2c_remove(struct platform_device *pdev) · 27 unmodified lines | ||
| 2342 | 2375 | } |
| 2343 | 2376 | |
| 2344 | 2377 | stm32f7_i2c_write_fm_plus_bits(i2c_dev, false); |
| 2345 | − | |
| 2346 | − clk_disable_unprepare(i2c_dev->clk); | |
| 2347 | 2378 | } |
| 2348 | 2379 | |
| 2349 | 2380 | static int __maybe_unused stm32f7_i2c_runtime_suspend(struct device *dev) |
| @@ -201,6 +201,11 @@ static int p2wi_probe(struct platform_device *pdev) · 200 unmodified lines | ||
| 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; |
| @@ -94,7 +94,7 @@ struct i2c_atr { · 93 unmodified lines | ||
| 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 * |
| @@ -931,8 +931,9 @@ int i2c_dev_irq_from_resources(const struct resource *resources, · 930 unmodified lines | ||
| 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) |
| @@ -970,7 +971,6 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf · 31 unmodified lines | ||
| 970 | 971 | client->dev.fwnode = info->fwnode; |
| 971 | 972 | |
| 972 | 973 | device_enable_async_suspend(&client->dev); |
| 973 | − i2c_dev_set_name(adap, client, info); | |
| 974 | 974 | |
| 975 | 975 | if (info->swnode) { |
| 976 | 976 | status = device_add_software_node(&client->dev, info->swnode); |
| @@ -982,6 +982,7 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf · 5 unmodified lines | ||
| 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; |
| @@ -993,6 +994,7 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf · 5 unmodified lines | ||
| 993 | 994 | |
| 994 | 995 | out_remove_swnode: |
| 995 | 996 | device_remove_software_node(&client->dev); |
| 997 | + need_put = true; | |
| 996 | 998 | out_err_put_of_node: |
| 997 | 999 | of_node_put(info->of_node); |
| 998 | 1000 | out_err: |
| @@ -1000,7 +1002,10 @@ out_err: · 1 unmodified line | ||
| 1000 | 1002 | "Failed to register i2c client %s at 0x%02x (%d)\n", |
| 1001 | 1003 | client->name, client->addr, status); |
| 1002 | 1004 | out_err_silent: |
| 1003 | − kfree(client); | |
| 1005 | + if (need_put) | |
| 1006 | + put_device(&client->dev); | |
| 1007 | + else | |
| 1008 | + kfree(client); | |
| 1004 | 1009 | return ERR_PTR(status); |
| 1005 | 1010 | } |
| 1006 | 1011 | EXPORT_SYMBOL_GPL(i2c_new_client_device); |
| @@ -1189,9 +1194,11 @@ static void i2c_adapter_dev_release(struct device *dev) · 182 unmodified lines | ||
| 1189 | 1194 | unsigned int i2c_adapter_depth(struct i2c_adapter *adapter) |
| 1190 | 1195 | { |
| 1191 | 1196 | unsigned int depth = 0; |
| 1197 | + struct device *parent; | |
| 1192 | 1198 | |
| 1193 | − while ((adapter = i2c_parent_is_i2c_adapter(adapter))) | |
| 1194 | − depth++; | |
| 1199 | + for (parent = adapter->dev.parent; parent; parent = parent->parent) | |
| 1200 | + if (parent->type == &i2c_adapter_type) | |
| 1201 | + depth++; | |
| 1195 | 1202 | |
| 1196 | 1203 | WARN_ONCE(depth >= MAX_LOCKDEP_SUBCLASSES, |
| 1197 | 1204 | "adapter depth exceeds lockdep subclass limit\n"); |
| @@ -636,7 +636,10 @@ static const struct file_operations i2cdev_fops = { · 635 unmodified lines | ||
| 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 | { |
| @@ -665,7 +668,7 @@ static int i2cdev_attach_adapter(struct device *dev) · 22 unmodified lines | ||
| 665 | 668 | |
| 666 | 669 | device_initialize(&i2c_dev->dev); |
| 667 | 670 | i2c_dev->dev.devt = MKDEV(I2C_MAJOR, adap->nr); |
| 668 | − i2c_dev->dev.class = i2c_dev_class; | |
| 671 | + i2c_dev->dev.class = &i2c_dev_class; | |
| 669 | 672 | i2c_dev->dev.parent = &adap->dev; |
| 670 | 673 | i2c_dev->dev.release = i2cdev_dev_release; |
| 671 | 674 | |
| @@ -751,12 +754,9 @@ static int __init i2c_dev_init(void) · 79 unmodified lines | ||
| 751 | 754 | if (res) |
| 752 | 755 | goto out; |
| 753 | 756 | |
| 754 | − i2c_dev_class = class_create("i2c-dev"); | |
| 755 | − if (IS_ERR(i2c_dev_class)) { | |
| 756 | − res = PTR_ERR(i2c_dev_class); | |
| 757 | + res = class_register(&i2c_dev_class); | |
| 758 | + if (res) | |
| 757 | 759 | goto out_unreg_chrdev; |
| 758 | − } | |
| 759 | − i2c_dev_class->dev_groups = i2c_groups; | |
| 760 | 760 | |
| 761 | 761 | /* Keep track of adapters which will be added or removed later */ |
| 762 | 762 | res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier); |
| @@ -769,7 +769,7 @@ static int __init i2c_dev_init(void) · 6 unmodified lines | ||
| 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,7 +781,7 @@ static void __exit i2c_dev_exit(void) · 5 unmodified lines | ||
| 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 | |
| @@ -32,7 +32,7 @@ struct i2c_demux_pinctrl_priv { · 31 unmodified lines | ||
| 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,9 +167,9 @@ static ssize_t available_masters_show(struct device *dev, · 128 unmodified lines | ||
| 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,6 +226,8 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev) · 50 unmodified lines | ||
| 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; |
| @@ -253,9 +255,7 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev) · 21 unmodified lines | ||
| 253 | 255 | of_changeset_update_property(&priv->chan[i].chgset, adap_np, &props[i]); |
| 254 | 256 | } |
| 255 | 257 | |
| 256 | − priv->num_chan = num_chan; | |
| 257 | 258 | priv->dev = &pdev->dev; |
| 258 | − | |
| 259 | 259 | platform_set_drvdata(pdev, priv); |
| 260 | 260 | |
| 261 | 261 | pm_runtime_no_callbacks(&pdev->dev); |
| @@ -22,7 +22,7 @@ struct gpiomux { · 21 unmodified lines | ||
| 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,7 +58,7 @@ static int i2c_mux_gpio_probe_fw(struct gpiomux *mux, · 29 unmodified lines | ||
| 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,7 +101,6 @@ static int i2c_mux_gpio_probe_fw(struct gpiomux *mux, · 36 unmodified lines | ||
| 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) { |
| @@ -126,7 +125,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) · 18 unmodified lines | ||
| 126 | 125 | struct gpiomux *mux; |
| 127 | 126 | struct i2c_adapter *parent; |
| 128 | 127 | struct i2c_adapter *root; |
| 129 | − unsigned initial_state; | |
| 128 | + unsigned int initial_state; | |
| 130 | 129 | int i, ngpios, ret; |
| 131 | 130 | |
| 132 | 131 | mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); |
| @@ -92,7 +92,7 @@ struct at24_data { · 91 unmodified lines | ||
| 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,9 +191,13 @@ AT24_CHIP_DATA(at24_data_24c16, 16384 / 8, 0); · 92 unmodified lines | ||
| 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); |
| @@ -222,8 +226,10 @@ static const struct i2c_device_id at24_ids[] = { · 22 unmodified lines | ||
| 222 | 226 | { "24c16", (kernel_ulong_t)&at24_data_24c16 }, |
| 223 | 227 | { "24cs16", (kernel_ulong_t)&at24_data_24cs16 }, |
| 224 | 228 | { "24c32", (kernel_ulong_t)&at24_data_24c32 }, |
| 229 | + { "24c32d-wl", (kernel_ulong_t)&at24_data_24c32d_wlp }, | |
| 225 | 230 | { "24cs32", (kernel_ulong_t)&at24_data_24cs32 }, |
| 226 | 231 | { "24c64", (kernel_ulong_t)&at24_data_24c64 }, |
| 232 | + { "24c64-wl", (kernel_ulong_t)&at24_data_24c64d_wlp }, | |
| 227 | 233 | { "24cs64", (kernel_ulong_t)&at24_data_24cs64 }, |
| 228 | 234 | { "24c128", (kernel_ulong_t)&at24_data_24c128 }, |
| 229 | 235 | { "24c256", (kernel_ulong_t)&at24_data_24c256 }, |
| @@ -252,8 +258,10 @@ static const struct of_device_id at24_of_match[] = { · 22 unmodified lines | ||
| 252 | 258 | { .compatible = "atmel,24c16", .data = &at24_data_24c16 }, |
| 253 | 259 | { .compatible = "atmel,24cs16", .data = &at24_data_24cs16 }, |
| 254 | 260 | { .compatible = "atmel,24c32", .data = &at24_data_24c32 }, |
| 261 | + { .compatible = "atmel,24c32d-wl", .data = &at24_data_24c32d_wlp }, | |
| 255 | 262 | { .compatible = "atmel,24cs32", .data = &at24_data_24cs32 }, |
| 256 | 263 | { .compatible = "atmel,24c64", .data = &at24_data_24c64 }, |
| 264 | + { .compatible = "atmel,24c64d-wl", .data = &at24_data_24c64d_wlp }, | |
| 257 | 265 | { .compatible = "atmel,24cs64", .data = &at24_data_24cs64 }, |
| 258 | 266 | { .compatible = "atmel,24c128", .data = &at24_data_24c128 }, |
| 259 | 267 | { .compatible = "atmel,24c256", .data = &at24_data_24c256 }, |
| @@ -509,32 +517,6 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) · 249 unmodified lines | ||
| 509 | 517 | return 0; |
| 510 | 518 | } |
| 511 | 519 | |
| 512 | −static const struct at24_chip_data *at24_get_chip_data(struct device *dev) | |
| 513 | −{ | |
| 514 | − struct device_node *of_node = dev->of_node; | |
| 515 | − const struct at24_chip_data *cdata; | |
| 516 | − const struct i2c_device_id *id; | |
| 517 | − | |
| 518 | − id = i2c_match_id(at24_ids, to_i2c_client(dev)); | |
| 519 | − | |
| 520 | − /* | |
| 521 | − * The I2C core allows OF nodes compatibles to match against the | |
| 522 | − * I2C device ID table as a fallback, so check not only if an OF | |
| 523 | − * node is present but also if it matches an OF device ID entry. | |
| 524 | − */ | |
| 525 | − if (of_node && of_match_device(at24_of_match, dev)) | |
| 526 | − cdata = of_device_get_match_data(dev); | |
| 527 | − else if (id) | |
| 528 | − cdata = (void *)id->driver_data; | |
| 529 | − else | |
| 530 | − cdata = acpi_device_get_match_data(dev); | |
| 531 | − | |
| 532 | − if (!cdata) | |
| 533 | − return ERR_PTR(-ENODEV); | |
| 534 | − | |
| 535 | − return cdata; | |
| 536 | −} | |
| 537 | − | |
| 538 | 520 | static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, |
| 539 | 521 | struct i2c_client *base_client, |
| 540 | 522 | struct regmap_config *regmap_config) |
| @@ -601,9 +583,9 @@ static int at24_probe(struct i2c_client *client) · 60 unmodified lines | ||
| 601 | 583 | i2c_fn_block = i2c_check_functionality(client->adapter, |
| 602 | 584 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK); |
| 603 | 585 | |
| 604 | − cdata = at24_get_chip_data(dev); | |
| 605 | − if (IS_ERR(cdata)) | |
| 606 | − return PTR_ERR(cdata); | |
| 586 | + cdata = i2c_get_match_data(client); | |
| 587 | + if (!cdata) | |
| 588 | + return -ENODEV; | |
| 607 | 589 | |
| 608 | 590 | err = device_property_read_u32(dev, "pagesize", &page_size); |
| 609 | 591 | if (err) |
| @@ -1531,4 +1531,9 @@ static inline void acpi_device_notify(struct device *dev) { } · 1530 unmodified lines | ||
| 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*/ |