i2c: Add Starfive JHB100 I2C master/slave support
Subsystems (4)
v2 cover i2c: Add Starfive JHB100 I2C master/slave support
From: Lianfeng Ouyang <[email protected]>
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of INTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by i2c_dw_set_mode()
4. The value of FIFO depth is not obtained through registers, but written through DTS
I have written some poorly styled code to reduce changes to i2c designware and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-d w_probe_master() differs only for the two IPs in i2c_dw_set_timits_master(). In order to reuse i2c_dw_probe_master(), i2c_dw_set_timits_master is declared as __weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation to sf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Lianfeng Ouyang (3):
dt-bindings: i2c: Add StarFive JHB100 I2C
i2c: designware: Export symbols and add __weak for Starfive I2C driver
i2c: starfive: Add StarFive JHB100 I2C master/slave support
.../bindings/i2c/starfive,jhb100-i2c.yaml | 128 +++++ MAINTAINERS | 7 + drivers/i2c/busses/Kconfig | 24 + drivers/i2c/busses/Makefile | 3 + drivers/i2c/busses/i2c-designware-common.c | 72 ++- drivers/i2c/busses/i2c-designware-core.h | 20 + drivers/i2c/busses/i2c-designware-master.c | 4 +- drivers/i2c/busses/i2c-designware-platdrv.c | 6 + drivers/i2c/busses/i2c-designware-slave.c | 2 +- drivers/i2c/busses/i2c-starfive-core.h | 164 ++++++ drivers/i2c/busses/i2c-starfive-master.c | 470 ++++++++++++++++++ drivers/i2c/busses/i2c-starfive-slave.c | 180 +++++++ 12 files changed, 1060 insertions(+), 20 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml create mode 100644 drivers/i2c/busses/i2c-starfive-core.h create mode 100644 drivers/i2c/busses/i2c-starfive-master.c create mode 100644 drivers/i2c/busses/i2c-starfive-slave.c
--
2.43.0
PATCH v2 1/3 dt-bindings: i2c: Add StarFive JHB100 I2C
From: Lianfeng Ouyang <[email protected]>
Add device tree bindings for the Starfive I2C controller and its implementation
The binding defines two platform-specific compatibles for the StarFive JHB100 implementation:
- "starfive,jhb100-i2c-master"
- "starfive,jhb100-i2c-slave"
The controller supports standard I2C and SMBus protocols, programmable FIFO depths, and optional SMBus Alert routing. The binding documents the necessary clocks, resets, and timing properties.
--- .../bindings/i2c/starfive,jhb100-i2c.yaml | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +128 -0
@@ -0,0 +1,128 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) 2024 StarFive Technology Co., Ltd. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/starfive,jhb100-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive jhb100 I2C Controller + +maintainers: + - Lianfeng Ouyang <[email protected]> + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +properties: + compatible: + description: | + Must be one of: + - "starfive,jhb100-i2c-master" for master mode controller + - "starfive,jhb100-i2c-slave" for slave mode controller + enum: + - starfive,jhb100-i2c-master + - starfive,jhb100-i2c-slave + + reg: + maxItems: 1 + description: StarFive I2C controller memory mapped registers + + interrupts: + maxItems: 1 + + clocks: + minItems: 2 + maxItems: 2 + items: + - description: I2C controller reference clock source + - description: APB interface clock source + + clock-names: + minItems: 2 + maxItems: 2 + items: + - const: ref + - const: pclk + + resets: + maxItems: 1 + description: Phandle to the reset controller for the I2C controller + + clock-frequency: + description: Desired I2C bus clock frequency in Hz + enum: [100000, 400000, 1000000, 3400000] + default: 400000 + + i2c-sda-hold-time-ns: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + SDA hold time in nanoseconds, used to compute the value written into + the DW_IC_SDA_HOLD register. + default: 0 + + i2c-scl-falling-time-ns: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + SCL falling time in nanoseconds, used to compute the tLOW period. + default: 300 + + i2c-sda-falling-time-ns: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + SDA falling time in nanoseconds, used to compute the tHIGH period. + default: 300 + + starfive,mctp-i2c-ms: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + Phandle to the master I2C node associated with this slave controller. + Only used in slave mode, typically for MCTP applications. + + starfive,i2c-tx-fifo-depth: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + TX FIFO depth of the I2C controller. + default: 8 + + starfive,i2c-rx-fifo-depth: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + RX FIFO depth of the I2C controller. + default: 8 + +unevaluatedProperties: false + +required: + - compatible + - reg + - clocks + - clock-names + - interrupts + +examples: + - | + i2c@2000 { + compatible = "starfive,jhb100-i2c-master"; + reg = <0x2000 0x100>; + #address-cells = <1>; + #size-cells = <0>; + clock-frequency = <400000>; + clocks = <&i2c_refclk>, <&apb_pclk>; + clock-names = "ref", "pclk"; + interrupts = <0>; + + eeprom@64 { + compatible = "atmel,24c02"; + reg = <0x64>; + }; + }; + | + i2c@3000 { + compatible = "starfive,jhb100-i2c-slave"; + reg = <0x3000 0x100>; + clocks = <&i2c_refclk>, <&apb_pclk>; + clock-names = "ref", "pclk"; + interrupts = <1>; + starfive,mctp-i2c-ms = <&i2c_master>; + }; +...
Signature · 1 line
2.43.0
Re: [PATCH v2 1/3] dt-bindings: i2c: Add StarFive JHB100 I2C
Quoted 9 lines · lianfeng.ouyang
From: Lianfeng Ouyang <[email protected]>
Add device tree bindings for the Starfive I2C controller and its implementation
The binding defines two platform-specific compatibles for the StarFive JHB100 implementation:
- "starfive,jhb100-i2c-master"
- "starfive,jhb100-i2c-slave"
You might get the same questions as v1, till you solve them. Why do you add device role to the compatible?
Do not explain WHAT you did here. Explain the background and why you did that way.
Also, use undeprecated naming, not master/slave.
Quoted 28 lines
The controller supports standard I2C and SMBus protocols, programmable FIFO depths, and optional SMBus Alert routing. The binding documents the necessary clocks, resets, and timing properties.
Signed-off-by Lianfeng Ouyang <[email protected]>--- .../bindings/i2c/starfive,jhb100-i2c.yaml | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yamlDocumentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +11
-0@@ -0,0 +1,128 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) 2024 StarFive Technology Co., Ltd. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/starfive,jhb100-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive jhb100 I2C Controller + +maintainers: + - Lianfeng Ouyang <[email protected]>
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +10
-0+ +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +properties: + compatible: + description: | + Must be one of: + - "starfive,jhb100-i2c-master" for master mode controller + - "starfive,jhb100-i2c-slave" for slave mode controller
Drop description, redundant. Schema tells that.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 28
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ enum: + - starfive,jhb100-i2c-master + - starfive,jhb100-i2c-slave + + reg: + maxItems: 1 + description: StarFive I2C controller memory mapped registers
Drop description, redundant.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 35
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ + interrupts: + maxItems: 1 + + clocks: + minItems: 2 + maxItems: 2
Drop both, redundant.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 42
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ items: + - description: I2C controller reference clock source + - description: APB interface clock source + + clock-names: + minItems: 2 + maxItems: 2
Same. From where did you take such syntax...
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 49
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ items: + - const: ref + - const: pclk + + resets: + maxItems: 1 + description: Phandle to the reset controller for the I2C controller
Drop description. Or say something useful.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 53
Quoted 4 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +4
-0+ + clock-frequency: + description: Desired I2C bus clock frequency in Hz + enum: [100000, 400000, 1000000, 3400000]
Aren't you duplicating constraints from dtschema?
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +3
-0+ default: 400000 + + i2c-sda-hold-time-ns:
So you added a generic property - where is it documented? Generic properties must be in common schema or dtschema.
And please prove that none of the generic properties are suitable.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 57
Quoted 1 line
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +1
-0+ $ref: /schemas/types.yaml#/definitions/uint32
I don't think you tested it. And this concludes my review. I finished here. Please do not send untested bindings.
Best regards,
Krzysztof
回复: [PATCH v2 1/3] dt-bindings: i2c: Add StarFive JHB100 I2C
Hi, Krzysztof
Thanks for the review.
Quoted 130 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年5月27日 21:05
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [PATCH v2 1/3] dt-bindings: i2c: Add StarFive JHB100 I2CQuoted 9 lines · lianfeng.ouyang
From: Lianfeng Ouyang <[email protected]>
Add device tree bindings for the Starfive I2C controller and its implementation
The binding defines two platform-specific compatibles for the StarFive JHB100 implementation:
- "starfive,jhb100-i2c-master"
- "starfive,jhb100-i2c-slave"You might get the same questions as v1, till you solve them. Why do you add device role to the compatible?
Do not explain WHAT you did here. Explain the background and why you did that way.
Also, use undeprecated naming, not master/slave.
Quoted 10 lines
The controller supports standard I2C and SMBus protocols, programmable FIFO depths, and optional SMBus Alert routing. The binding documents the necessary clocks, resets, and timing properties.
Signed-off-by Lianfeng Ouyang <[email protected]>--- .../bindings/i2c/starfive,jhb100-i2c.yaml | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yamlReview
Quoted 2 lines
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yamlQuoted 16 lines
new file mode 100644
index 000000000000..c8631348121cDocumentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +11
-0@@ -0,0 +1,128 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) 2024 StarFive Technology Co., Ltd. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/starfive,jhb100-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive jhb100 I2C Controller + +maintainers: + - Lianfeng Ouyang <[email protected]>Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +10
-0+ +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +properties: + compatible: + description: | + Must be one of: + - "starfive,jhb100-i2c-master" for master mode controller + - "starfive,jhb100-i2c-slave" for slave mode controllerDrop description, redundant. Schema tells that.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 28
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ enum: + - starfive,jhb100-i2c-master + - starfive,jhb100-i2c-slave + + reg: + maxItems: 1 + description: StarFive I2C controller memory mapped registersDrop description, redundant.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 35
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ + interrupts: + maxItems: 1 + + clocks: + minItems: 2 + maxItems: 2Drop both, redundant.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 42
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ items: + - description: I2C controller reference clock source + - description: APB interface clock source + + clock-names: + minItems: 2 + maxItems: 2Same. From where did you take such syntax...
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 49
Quoted 7 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +7
-0+ items: + - const: ref + - const: pclk + + resets: + maxItems: 1 + description: Phandle to the reset controller for the I2C controllerDrop description. Or say something useful.
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 53
Quoted 4 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +4
-0+ + clock-frequency: + description: Desired I2C bus clock frequency in Hz + enum: [100000, 400000, 1000000, 3400000]Aren't you duplicating constraints from dtschema?
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +3
-0+ default: 400000 + + i2c-sda-hold-time-ns:So you added a generic property - where is it documented? Generic properties must be in common schema or dtschema.
And please prove that none of the generic properties are suitable.
Quoted 8 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 57
Quoted 1 line
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +1
-0+ $ref: /schemas/types.yaml#/definitions/uint32I don't think you tested it. And this concludes my review. I finished here. Please do not send untested bindings.
Best regards,
Krzysztof
Sorry, I didn't know I needed to run dt-binding_check before, but now I have set up the environment. Starting from the next version, I will run dt-binding_check and modify it according to your reply. Then, I will remove the description of the required system properties and the common i2c properties
Best Regards,
Lianfeng Ouyang
Re: 回复: [PATCH v2 1/3] dt-bindings: i2c: Add StarFive JHB100 I2C
Quoted 11 lines · Lianfeng Ouyang
Quoted 11 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +3
-0+ default: 400000 + + i2c-sda-hold-time-ns:So you added a generic property - where is it documented? Generic properties must be in common schema or dtschema.
And please prove that none of the generic properties are suitable.
Quoted 1 line
+ $ref: /schemas/types.yaml#/definitions/uint32
Quoted 8 lines
Quoted 6 lines
I don't think you tested it. And this concludes my review. I finished here. Please do not send untested bindings.
Best regards,
KrzysztofSorry, I didn't know I needed to run dt-binding_check before, but now I have
Every doc asks that. DTS101 slides or my earlier talks as well... Other people talks as well... and you received that request last time at v1. Please do not repeat the same mistakes because then we feel like our feedback is wasted.
Best regards,
Krzysztof
回复: 回复: [PATCH v2 1/3] dt-bindings: i2c: Add StarFive JHB100 I2C
Quoted 35 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年5月28日 15:48
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: 回复: [PATCH v2 1/3] dt-bindings: i2c: Add StarFive JHB100 I2CQuoted 11 lines · Lianfeng Ouyang
Quoted 11 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml line 56
Quoted 3 lines
Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml new file +3
-0+ default: 400000 + + i2c-sda-hold-time-ns:So you added a generic property - where is it documented? Generic properties must be in common schema or dtschema.
And please prove that none of the generic properties are suitable.
Quoted 1 line
+ $ref: /schemas/types.yaml#/definitions/uint32
Quoted 8 lines
Quoted 6 lines
I don't think you tested it. And this concludes my review. I finished here. Please do not send untested bindings.
Best regards,
KrzysztofSorry, I didn't know I needed to run dt-binding_check before, but now I have
Quoted 7 lines
Every doc asks that. DTS101 slides or my earlier talks as well... Other people talks as well... and you received that request last time at v1. Please do not repeat the same mistakes because then we feel like our feedback is wasted.
Best regards,
Krzysztof
I'm very sorry, I know that language is not strong at this moment. In order to prevent your feedback from being wasted, I will correct the relevant errors and run tests in the next version. Thank you
Best Regards,
Lianfeng Ouyang
PATCH v2 2/3 i2c: designware: Export symbols and add __weak for Starfive I2C driver
In reply to lianfeng.ouyangFrom: Lianfeng Ouyang <[email protected]>
Export several key functions (i2c_dw_probe_master, i2c_dw_init, i2c_dw_xfer_init, i2c_dw_read_clear_intrbits, etc.) and mark them as __weak. This allows the i2c starfive driver to reuse the common infrastructure while overriding the implementations where needed.
Additionally, extend the register map configuration and introduce the MODEL_STARFIVE flag to accommodate the starfive i2c IP's different register space.
--- drivers/i2c/busses/i2c-designware-common.c | 72 ++++++++++++++++----- drivers/i2c/busses/i2c-designware-core.h | 20 ++++++ drivers/i2c/busses/i2c-designware-master.c | 4 +- drivers/i2c/busses/i2c-designware-platdrv.c | 6 ++ drivers/i2c/busses/i2c-designware-slave.c | 2 +- 5 files changed, 84 insertions(+), 20 deletions(-)
drivers/i2c/busses/i2c-designware-common.c +55 -17
@@ -70,6 +70,7 @@ static const char *const abort_sources[] = { "incorrect slave-transmitter mode configuration", }; +#if !IS_ENABLED (CONFIG_I2C_STARFIVE )static int dw_reg_read (void *context,unsigned int reg,unsigned int *val) {struct dw_i2c_dev *dev = context;
@@ -87,6 +88,7 @@ static int dw_reg_write(void *context, unsigned int reg, unsigned int val) return 0; } +#endif static int dw_reg_read_swab (void *context,unsigned int reg,unsigned int *val) {
@@ -143,9 +145,15 @@ static int i2c_dw_init_regmap(struct dw_i2c_dev *dev) .val_bits = 32, .reg_stride = 4, .disable_locking = true, +#if IS_ENABLED (CONFIG_I2C_STARFIVE ) + .reg_read = sf_reg_read, + .reg_write = sf_reg_write, + .max_register = SF_IC_SMBUS_INTR_CLR, +#else .reg_read = dw_reg_read, .reg_write = dw_reg_write, .max_register = DW_IC_COMP_TYPE, +#endif };u32 reg;int ret;
@@ -162,6 +170,10 @@ static int i2c_dw_init_regmap(struct dw_i2c_dev *dev)return ret; reg =readl (dev->base +DW_IC_COMP_TYPE ); + +if ((dev->flags &MODEL_MASK ) ==MODEL_STARFIVE ) + reg =readl (dev->base + (SF_IC_COMP_TYPE & (~SF_REG_FLAG ))); +i2c_dw_release_lock (dev);if ((dev->flags &MODEL_MASK ) ==MODEL_AMD_NAVI_GPU )
@@ -359,7 +371,7 @@ static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0;#endif /* CONFIG_ACPI */ -static void i2c_dw_configure_mode (struct dw_i2c_dev *dev,int mode) +__weak void i2c_dw_configure_mode (struct dw_i2c_dev *dev,int mode) {switch (mode) {case DW_IC_MASTER :
@@ -382,7 +394,7 @@ static void i2c_dw_configure_mode(struct dw_i2c_dev *dev, int mode) } } -static void i2c_dw_write_timings (struct dw_i2c_dev *dev) +__weak void i2c_dw_write_timings (struct dw_i2c_dev *dev) {/* Write standard speed timing parameters */ regmap_write (dev->map,DW_IC_SS_SCL_HCNT , dev->ss_hcnt);
@@ -411,7 +423,7 @@ static void i2c_dw_write_timings(struct dw_i2c_dev *dev)* * The controller must be disabled before this function is called. */ -void i2c_dw_set_mode (struct dw_i2c_dev *dev,int mode) +__weak void i2c_dw_set_mode (struct dw_i2c_dev *dev,int mode) {if (mode ==DW_IC_SLAVE && !dev->slave) mode =DW_IC_MASTER ;
@@ -806,10 +818,25 @@ static int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev)if (ret)return ret; +#if IS_ENABLED (CONFIG_I2C_STARFIVE ) +u32 tx_fifo_cfg =8 , rx_fifo_cfg =8 ; + +#ifdef CONFIG_OF + ret =of_property_read_u32 (dev->dev->of_node,"starfive,i2c-tx-fifo-depth" , &tx_fifo_cfg); +if (!ret && (tx_fifo_cfg <2 || tx_fifo_cfg >256 )) + tx_fifo_cfg =8 ; + + ret =of_property_read_u32 (dev->dev->of_node,"starfive,i2c-rx-fifo-depth" , &rx_fifo_cfg); +if (!ret && (rx_fifo_cfg <2 || rx_fifo_cfg >256 )) + rx_fifo_cfg =8 ; +#endif + param = rx_fifo_cfg <<8 | tx_fifo_cfg <<16 ; +#else ret =regmap_read (dev->map,DW_IC_COMP_PARAM_1 , ¶m);i2c_dw_release_lock (dev);if (ret)return ret; +#endif tx_fifo_depth =FIELD_GET (DW_IC_FIFO_TX_FIELD , param) +1 ; rx_fifo_depth =FIELD_GET (DW_IC_FIFO_RX_FIELD , param) +1 ;
@@ -896,20 +923,29 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)if (ret)return ret; - ret =i2c_dw_probe_master (dev); -if (ret) -return ret; +if (dev->mode ==DW_IC_SLAVE ) { + ret =i2c_sf_probe_slave (dev); + }else { + ret =i2c_dw_probe_master (dev); +if (ret) +return ret; - ret =i2c_dw_init (dev); -if (ret) -return ret; + ret =i2c_dw_init (dev); +if (ret) +return ret; -if (!adap->name[0 ]) -strscpy (adap->name,"Synopsys DesignWare I2C adapter" ); +if (!adap->name[0 ]) +strscpy (adap->name,"Synopsys DesignWare I2C adapter" ); + } adap->retries =3 ; adap->algo = &i2c_dw_algo; +#if IS_ENABLED (CONFIG_I2C_STARFIVE_SLAVE ) +if (dev->mode ==DW_IC_SLAVE ) + adap->algo = &i2c_dw_slave_algo; +#else adap->quirks = &i2c_dw_quirks; +#endif adap->dev.parent = dev->dev;i2c_set_adapdata (adap, dev);
@@ -938,16 +974,18 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)if (!dev->emptyfifo_hold_master) irq_flags |=IRQF_NO_THREAD ; - ret =i2c_dw_acquire_lock (dev); -if (ret) -return ret; +if (!IS_ENABLED (CONFIG_I2C_STARFIVE ) || dev->mode ==DW_IC_MASTER ) { + ret =i2c_dw_acquire_lock (dev); +if (ret) +return ret; -__i2c_dw_write_intr_mask (dev,0 ); -i2c_dw_release_lock (dev); +__i2c_dw_write_intr_mask (dev,0 ); +i2c_dw_release_lock (dev); + }if (!(dev->flags &ACCESS_POLLING )) { ret =devm_request_irq (dev->dev, dev->irq, i2c_dw_isr, - irq_flags,dev_name (dev->dev), dev); + irq_flags,dev_name (dev->dev), dev);if (ret)return ret; }
drivers/i2c/busses/i2c-designware-core.h +20 -0
@@ -321,6 +321,11 @@ struct dw_i2c_dev {u32 bus_capacitance_pF;bool clk_freq_optimized;bool emptyfifo_hold_master; +#if IS_ENABLED (CONFIG_I2C_STARFIVE ) +u16 scl_hcnt; +u16 scl_lcnt; +struct i2c_adapter *ms_adapter;/* Bind another I2C master controller */ +#endif };#define ACCESS_INTR_MASK BIT(0)
@@ -328,6 +333,7 @@ struct dw_i2c_dev {#define ARBITRATION_SEMAPHORE BIT(2)#define ACCESS_POLLING BIT(3) +#define MODEL_STARFIVE BIT(9)#define MODEL_AMD_NAVI_GPU BIT(10)#define MODEL_WANGXUN_SP BIT(11)#define MODEL_MASK GENMASK(11, 8)
@@ -359,8 +365,14 @@ int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev);u32 i2c_dw_func (struct i2c_adapter *adap);irqreturn_t i2c_dw_isr_master (struct dw_i2c_dev *dev); +u32 i2c_dw_read_clear_intrbits (struct dw_i2c_dev *dev); +u32 i2c_dw_read_clear_intrbits_slave (struct dw_i2c_dev *dev); +extern const struct dev_pm_ops i2c_dw_dev_pm_ops; +#if IS_ENABLED (CONFIG_I2C_STARFIVE ) +#include "i2c-starfive-core.h" +#else static inline void __i2c_dw_enable (struct dw_i2c_dev *dev) { dev->status |=STATUS_ACTIVE ;
@@ -372,6 +384,7 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev)regmap_write (dev->map,DW_IC_ENABLE ,0 ); dev->status &= ~STATUS_ACTIVE; } +#endif static inline void __i2c_dw_write_intr_mask (struct dw_i2c_dev *dev,unsigned int intr_mask)
@@ -411,8 +424,15 @@ static inline irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev) { return IRQ_static inline void i2c_dw_configure (struct dw_i2c_dev *dev) { +#if IS_ENABLED (CONFIG_I2C_STARFIVE ) +if (device_is_compatible (dev->dev,"starfive,jhb100-i2c-slave" )) +i2c_sf_configure_slave (dev); +else +i2c_sf_configure_master (dev); +#else i2c_dw_configure_slave (dev);i2c_dw_configure_master (dev); +#endif }int i2c_dw_probe (struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-master.c +2 -2
@@ -31,7 +31,7 @@#define AMD_TIMEOUT_MAX_US 250#define AMD_MASTERCFG_MASK GENMASK(15, 0) -static int i2c_dw_set_timings_master (struct dw_i2c_dev *dev) +__weak int i2c_dw_set_timings_master (struct dw_i2c_dev *dev) {unsigned int comp_param1;u32 sda_falling_time, scl_falling_time;
@@ -570,7 +570,7 @@ i2c_dw_read(struct dw_i2c_dev *dev) } } -static u32 i2c_dw_read_clear_intrbits (struct dw_i2c_dev *dev) +__weak u32 i2c_dw_read_clear_intrbits (struct dw_i2c_dev *dev) {unsigned int stat, dummy;
drivers/i2c/busses/i2c-designware-platdrv.c +6 -0
@@ -151,6 +151,10 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (device_property_present (device,"wx,i2c-snps-model" )) flags =MODEL_WANGXUN_SP |ACCESS_POLLING ; +if (device_is_compatible (device,"starfive,jhb100-i2c-master" ) || +device_is_compatible (device,"starfive,jhb100-i2c-slave" )) + flags |=MODEL_STARFIVE ; + dev->dev = device; dev->irq = irq; dev->flags = flags;
@@ -255,6 +259,8 @@ static const struct of_device_id dw_i2c_of_match[] = { { .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" }, {} };MODULE_DEVICE_TABLE (of, dw_i2c_of_match);
drivers/i2c/busses/i2c-designware-slave.c +1 -1
@@ -61,7 +61,7 @@ int i2c_dw_unreg_slave(struct i2c_client *slave)return 0 ; } -static u32 i2c_dw_read_clear_intrbits_slave (struct dw_i2c_dev *dev) +__weak u32 i2c_dw_read_clear_intrbits_slave (struct dw_i2c_dev *dev) {unsigned int stat, dummy;
Signature · 1 line
2.43.0
Re: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
drivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] = { · line 263
Quoted 9 lines · lianfeng.ouyang
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0dev->dev = device; dev->irq = irq; dev->flags = flags;@@ -255,6 +259,8 @@ static const struct of_device_id dw_i2c_of_match[] = { { .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" },
So both devices are the same... Or you miss proper entry in ID table. Don't sprinkle compatibles around the code - ID table match data is for variant customization.
Best regards,
Krzysztof
回复: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
Hi, Krzysztof
Thanks for the review.
Quoted 29 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年5月27日 21:07
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [PATCH v2 2/3] i2c: designware: Export symbols and add__weakfor Starfive I2C driverdrivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] =
Quoted 4 lines · lianfeng.ouyang
drivers/i2c/busses/i2c-designware-platdrv.c +0
-0dev->dev = device; dev->irq = irq; dev->flags = flags;@@ -255,6 +259,8 @@ static const struct of_device_id dw_i2c_of_match[] ={
drivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] = { · line 263
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0{ .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" },So both devices are the same... Or you miss proper entry in ID table. Don't sprinkle compatibles around the code - ID table match data is for variant customization.
Quoted 2 lines
Best regards,
Krzysztof
Ok, Master and slave have different base addresses and interrupt numbers, but the register layout is the same, so in the next version, I will only use the same compatible ”starfive, jhb100-i2c“, and then add starfive, i2c-slave to the dts node of the slave to distinguish them
Best Regards,
Lianfeng Ouyang
Re: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
Quoted 10 lines · Lianfeng Ouyang
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] = { · line 263
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0{ .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" },So both devices are the same... Or you miss proper entry in ID table. Don't sprinkle compatibles around the code - ID table match data is for variant customization.
Quoted 7 lines
Quoted 2 lines
Best regards,
KrzysztofOk, Master and slave have different base addresses and interrupt numbers, but the register layout is the same, so in the next version, I will only use the same compatible ”starfive, jhb100-i2c“, and then add starfive, i2c-slave to the dts node of the slave to distinguish them
You do not need to distinguish same devices usually, but I still do not understand why do you need all these different compatibles and your commit msgs or binding text do not help, so I don't know what to advise.
Best regards,
Krzysztof
回复: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
Quoted 35 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年5月28日 15:46
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add__weakfor Starfive I2C driverQuoted 10 lines · Lianfeng Ouyang
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] = { · line 263
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0{ .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" },So both devices are the same... Or you miss proper entry in ID table. Don't sprinkle compatibles around the code - ID table match data is for variant customization.
Quoted 6 lines
Quoted 2 lines
Best regards,
KrzysztofOk, Master and slave have different base addresses and interrupt numbers, but the register layout is the same, so in the next version, I will only use the same compatible ”starfive, jhb100-i2c“, and then add starfive, i2c-slave to the dts
node
Quoted 1 line
of the slave to distinguish them
Quoted 7 lines
You do not need to distinguish same devices usually, but I still do not understand why do you need all these different compatibles and your commit msgs or binding text do not help, so I don't know what to advise.
Best regards,
Krzysztof
The IP corresponding to the i2c driver submitted this time is quite unique, so it should be distinguished. The master-slave of i2c designware are at the same base address and switch according to the scene, so only one is initialized in probe(). But i2c starfive has master-slave at different base addresses, and it can work simultaneously. Therefore, both roles need to be initialized in their respective probes. If we don't distinguish, we don't know if this probe is initializing the master or the slave
Best Regards,
Lianfeng Ouyang
Re: 回复: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
Quoted 43 lines · Lianfeng Ouyang
Quoted 35 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年5月28日 15:46
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add__weakfor Starfive I2C driverQuoted 10 lines · Lianfeng Ouyang
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] = { · line 263
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0{ .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" },So both devices are the same... Or you miss proper entry in ID table. Don't sprinkle compatibles around the code - ID table match data is for variant customization.
Quoted 6 lines
Quoted 2 lines
Best regards,
KrzysztofOk, Master and slave have different base addresses and interrupt numbers, but the register layout is the same, so in the next version, I will only use the same compatible ”starfive, jhb100-i2c“, and then add starfive, i2c-slave to the dts
node
Quoted 1 line
of the slave to distinguish them
Quoted 7 lines
You do not need to distinguish same devices usually, but I still do not understand why do you need all these different compatibles and your commit msgs or binding text do not help, so I don't know what to advise.
Best regards,
Krzysztof
Quoted 8 lines
The IP corresponding to the i2c driver submitted this time is quite unique, so it should be distinguished. The master-slave of i2c designware are at the same base address and switch according to the scene, so only one is initialized in
probe(). But i2c starfive has master-slave at different base addresses, and it can work simultaneously. Therefore, both roles need to be initialized in their respective probes. If we don't distinguish, we don't know if this probe is initializing the master or the slave
I don't think you read the comments. Again, you claim devices are incompatible but have exactly the same programming interface.
Best regards,
Krzysztof
回复: 回复: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
Quoted 71 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年6月3日 22:34
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: 回复: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add__weakfor Starfive I2C driverQuoted 7 lines · Lianfeng Ouyang
Quoted 7 lines
-----邮件原件-----
发件人: Krzysztof Kozlowski <[email protected]>
发送时间: 2026年5月28日 15:46
收件人: Lianfeng Ouyang <[email protected]>; Andi Shyti <[email protected]>; Rob Herring <[email protected]>; KrzysztofKozlowski
Quoted 19 lines
Quoted 19 lines
<[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; Andy Shevchenko <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: 回复: [PATCH v2 2/3] i2c: designware: Export symbols and add__weakfor Starfive I2C driverQuoted 10 lines · Lianfeng Ouyang
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c static const struct of_device_id dw_i2c_of_match[] = { · line 263
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0{ .compatible = "mobileye,eyeq6lplus-i2c" }, { .compatible = "mscc,ocelot-i2c" }, { .compatible = "snps,designware-i2c" }, + { .compatible = "starfive,jhb100-i2c-master" }, + { .compatible = "starfive,jhb100-i2c-slave" },So both devices are the same... Or you miss proper entry in ID table. Don't sprinkle compatibles around the code - ID table match data is for variant customization.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Best regards,
KrzysztofOk, Master and slave have different base addresses and interrupt numbers,
but
Quoted 1 line
Quoted 1 line
Quoted 1 line
the register layout is the same, so in the next version, I will only use the
same
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
compatible ”starfive, jhb100-i2c“, and then add starfive, i2c-slave to the dts
node
Quoted 1 line
of the slave to distinguish them
You do not need to distinguish same devices usually, but I still do not understand why do you need all these different compatibles and your commit msgs or binding text do not help, so I don't know what to advise.
Best regards,
KrzysztofQuoted 8 lines
The IP corresponding to the i2c driver submitted this time is quite unique, so it should be distinguished. The master-slave of i2c designware are at the same base address and switch according to the scene, so only one is initialized in
probe(). But i2c starfive has master-slave at different base addresses, and it can work simultaneously. Therefore, both roles need to be initialized in their respective probes. If we don't distinguish, we don't know if this probe is initializing the master or the slave
Quoted 5 lines
I don't think you read the comments. Again, you claim devices are incompatible but have exactly the same programming interface.
Best regards,
Krzysztof
Hi Krzysztof ,
Thanks for your review.
Now i2c has been changed to use the same compatible and use .data to distinguish between master and slave
Best Regards,
Lianfeng Ouyang
Andy Shevchenko
reviewerRe: [PATCH v2 2/3] i2c: designware: Export symbols and add __weak for Starfive I2C driver
In reply to lianfeng.ouyangQuoted 8 lines · lianfeng.ouyang
Export several key functions (
i2c_dw_probe_master,i2c_dw_init,i2c_dw_xfer_init,i2c_dw_read_clear_intrbits, etc.) and mark them as__weak. This allows the i2c starfive driver to reuse the common infrastructure while overriding the implementations where needed.Additionally, extend the register map configuration and introduce the
MODEL_STARFIVEflag to accommodate the starfive i2c IP's different register space.
...
Quoted 1 line
+#endif
My gosh, no.
drivers/i2c/busses/i2c-designware-common.c static int i2c_dw_init_regmap(struct dw_i2c_dev *dev) · line 152
Quoted 8 lines
drivers/i2c/busses/i2c-designware-common.c +5
-0.val_bits = 32, .reg_stride = 4, .disable_locking = true, +#if IS_ENABLED (CONFIG_I2C_STARFIVE ) + .reg_read = sf_reg_read, + .reg_write = sf_reg_write, + .max_register = SF_IC_SMBUS_INTR_CLR, +#else
No.
Just find a different way. See how Baikal T1 support was implemented (in v6.18, for example).
Quoted 4 lines
drivers/i2c/busses/i2c-designware-common.c +1
-0.reg_read = dw_reg_read, .reg_write = dw_reg_write, .max_register = DW_IC_COMP_TYPE, +#endif
...
Quoted 1 line
+#ifdef
CONFIG_OF
Definitely no.
drivers/i2c/busses/i2c-designware-common.c static int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev) · line 825
Quoted 1 line
drivers/i2c/busses/i2c-designware-common.c +1
-0+ ret =of_property_read_u32 (dev->dev->of_node,"starfive,i2c-tx-fifo-depth" , &tx_fifo_cfg);
No. Why?!
Also do not use OF-centric APIs in the driver that uses fwnode.
Quoted 14 lines
drivers/i2c/busses/i2c-designware-common.c +10
-0+if (!ret && (tx_fifo_cfg <2 || tx_fifo_cfg >256 )) + tx_fifo_cfg =8 ; + + ret =of_property_read_u32 (dev->dev->of_node,"starfive,i2c-rx-fifo-depth" , &rx_fifo_cfg); +if (!ret && (rx_fifo_cfg <2 || rx_fifo_cfg >256 )) + rx_fifo_cfg =8 ; +#endif + param = rx_fifo_cfg <<8 | tx_fifo_cfg <<16 ; +#else ret =regmap_read (dev->map,DW_IC_COMP_PARAM_1 , ¶m);i2c_dw_release_lock (dev);if (ret)return ret; +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/3 i2c: starfive: Add StarFive JHB100 I2C master/slave support
In reply to lianfeng.ouyangFrom: Lianfeng Ouyang <[email protected]>
Add support for the Starfive I2C controller found on the StarFive JHB100 platform. The controller supports both master and slave modes and uses a different register layout compared to the standard DesignWare I2C IP.
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of INTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by i2c_dw_set_mode().
4. The value of FIFO depth is not obtained through registers, but written through DTS
The driver leverages the common i2c-designware-core infrastructure exported by the previous patch, while implementing its own timing calculation, FIFO configuration, and interrupt handling to accommodate the register offsets and bit definitions.
--- MAINTAINERS | 7 + drivers/i2c/busses/Kconfig | 24 ++ drivers/i2c/busses/Makefile | 3 + drivers/i2c/busses/i2c-starfive-core.h | 164 ++++++++ drivers/i2c/busses/i2c-starfive-master.c | 470 +++++++++++++++++++++++ drivers/i2c/busses/i2c-starfive-slave.c | 180 +++++++++ 6 files changed, 848 insertions(+) create mode 100644 drivers/i2c/busses/i2c-starfive-core.h create mode 100644 drivers/i2c/busses/i2c-starfive-master.c create mode 100644 drivers/i2c/busses/i2c-starfive-slave.c
MAINTAINERS +7 -0
@@ -25319,6 +25319,13 @@ L: [email protected] S: Maintained F: arch/riscv/boot/dts/starfive/jhb100* +Starfive JHB100 I2C DRIVER +M: Lianfeng Ouyang <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/i2c/starfive,jhb100-i2c.yaml +F: drivers/i2c/busses/i2c-starfive-* + STARFIVE JHB100 PINCTRL DRIVERS M: Changhuang Liang <[email protected]> M: Lianfeng Ouyang <[email protected]>
drivers/i2c/busses/Kconfig +24 -0
@@ -640,6 +640,30 @@ config I2C_DESIGNWARE_PCI endif +config I2C_STARFIVE + tristate "Starfive i2c adapter" + select REGMAP + help + This is a driver for the Starfive I2C controller, + a variant of the DesignWare I2C IP with a different register layout. + It shares common infrastructure with the standard DesignWare I2C + driver (I2C_DESIGNWARE_CORE) + +if I2C_STARFIVE + +config I2C_STARFIVE_SLAVE + bool "Starfive i2c slave" + default I2C_STARFIVE + select I2C_SLAVE + help + If you say yes to this option, support will be included for the + Starfive i2c slave adapter. + + This is not a standalone module, this module compiles together with + i2c-starfive-core. + +endif + config I2C_DIGICOLOR tristate "Conexant Digicolor I2C driver" depends on ARCH_DIGICOLOR || COMPILE_TEST
drivers/i2c/busses/Makefile +3 -0
@@ -61,6 +61,9 @@ i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-bayt obj-$(CONFIG_I2C_DESIGNWARE_AMDISP) += i2c-designware-amdisp.o obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o i2c-designware-pci-y := i2c-designware-pcidrv.o +obj-$(CONFIG_I2C_STARFIVE) += i2c-starfive.o +i2c-starfive-y += i2c-starfive-master.o +i2c-starfive-$(CONFIG_I2C_STARFIVE_SLAVE) += i2c-starfive-slave.o obj-$(CONFIG_I2C_DIGICOLOR) += i2c-digicolor.o obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o obj-$(CONFIG_I2C_EMEV2) += i2c-emev2.o
drivers/i2c/busses/i2c-starfive-core.h new file +164 -0
164 lines not on this page · raw message
drivers/i2c/busses/i2c-starfive-master.c new file +470 -0
470 lines not on this page · raw message
drivers/i2c/busses/i2c-starfive-slave.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.43.0
Mika Westerberg
maintainerHi,
Quoted 27 lines · lianfeng.ouyang
From: Lianfeng Ouyang <[email protected]>
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided byi2c_dw_set_mode()
4. The value of FIFO depth is not obtained through registers, but written through DTS
Quoted 16 lines
I have written some poorly styled code to reduce changes to i2c designware and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation tosf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
It's not that you are not allowed to change the existing driver. It is definitely encouraged to avoid unnecessary duplication. If possible think of the core parts as library that your glue driver can call and if something is missing you can always add (or modify).
Also while there, let's start by adding support for the master operations first and then later on you can add the slave bits.
Hope this helps.
Quoted 66 lines
-----邮件原件-----
发件人: Mika Westerberg <[email protected]>
发送时间: 2026年5月27日 20:36
收件人: Lianfeng Ouyang <[email protected]>
抄送: Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Andy Shevchenko <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: [PATCH v2 0/3] i2c: Add Starfive JHB100 I2C master/slave supportHi,
Quoted 15 lines · lianfeng.ouyang
From: Lianfeng Ouyang <[email protected]>
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.Quoted 9 lines
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()Quoted 19 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
I have written some poorly styled code to reduce changes to i2c designware and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation tosf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?It's not that you are not allowed to change the existing driver. It is definitely encouraged to avoid unnecessary duplication. If possible think of the core parts as library that your glue driver can call and if something is missing you can always add (or modify).
Quoted 4 lines
Also while there, let's start by adding support for the master operations first and then later on you can add the slave bits.
Hope this helps.
Thanks for your reply. I have a general understanding. First, I will complete the i2c Starfive Master driver and appropriately modify the i2c designware related functions into callback form
Best Regards,
Lianfeng Ouyang
Andy Shevchenko
reviewerQuoted 13 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.
Quoted 11 lines
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided byi2c_dw_set_mode()
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery with full of __weak annotations that may not be present in the regular driver. There is not even a tiny bit of justification for this nonsense.
TL;DR: this series needs much more work.
Quoted 16 lines
I have written some poorly styled code to reduce changes to i2c designware and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation tosf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 64 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27
收件人: Lianfeng Ouyang <[email protected]>
抄送: Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: [PATCH v2 0/3] i2c: Add Starfive JHB100 I2C master/slave supportQuoted 13 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.Quoted 9 lines
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery with full of
__weakannotations that may not be present in the regular driver. There is not even a tiny bit of justification for this nonsense.TL;DR: this series needs much more work.
Quoted 8 lines
I have written some poorly styled code to reduce changes to i2c designware and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community isQuoted 8 lines
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation to
sf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
Thanks for the review.
In the future, the designware will be changed to the form of callback functions, and then callback functions will be passed in i2c starry - * and implemented using designware as a library
Best Regards,
Lianfeng Ouyang
Andy Shevchenko
reviewerQuoted 54 lines · Lianfeng Ouyang
Quoted 28 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27Quoted 13 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.Quoted 9 lines
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()Quoted 25 lines
Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery with full of
__weakannotations that may not be present in the regular driver. There is not even a tiny bit of justification for this nonsense.TL;DR: this series needs much more work.
Quoted 16 lines
I have written some poorly styled code to reduce changes to i2c designware and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation tosf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Quoted 5 lines
Thanks for the review.
In the future, the designware will be changed to the form of callback functions, and then callback functions will be passed in i2c starry - * and implemented using designware as a library
Why you can't specify your own regmap as it was done in Baikal case? What are the obstacles to achieve that?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 77 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 13:49
收件人: Lianfeng Ouyang <[email protected]>
抄送: Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: 回复: [PATCH v2 0/3] i2c: Add Starfive JHB100 I2C master/slave supportQuoted 27 lines · Lianfeng Ouyang
Quoted 27 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27Quoted 22 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided byQuoted 6 lines
Quoted 6 lines
i2c_dw_set_mode()Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery with full of
__weakannotations that may not be present in the regular driver.There
Quoted 5 lines
Quoted 5 lines
is not even a tiny bit of justification for this nonsense.
TL;DR: this series needs much more work.
Quoted 1 line
I have written some poorly styled code to reduce changes to i2c
designware
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community isQuoted 8 lines
Quoted 8 lines
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation to
sf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?Quoted 5 lines
Thanks for the review.
In the future, the designware will be changed to the form of callback functions, and then callback functions will be passed in i2c starry - * and implemented using designware as a library
Quoted 7 lines
Why you can't specify your own regmap as it was done in Baikal case? What are the obstacles to achieve that?
--
With Best Regards,
Andy Shevchenko
Hi Andy,
The main reasons are as follows
1. For high and low level counting settings at different rates, i2c starfive just use IC_SCL_H/LCNT to set SS, FM, FM+, UFM,
====> Therefore, it is not possible to directly use the i2c_dew_set_timits_master()
of designware, Because the definition of registers has changed
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of INTR_CLR, while designware reads different clearing registers
====> The way of operating registers is different, so it cannot be
distinguished solely by address or offset, and can only be adapted to operations belonging to i2c starfive through callback functions
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by i2c_dw_set_mode() ====> There are host and slave IP addresses separately, unlike designware where one IP supports two roles, because the logic of switching roles cannot be distinguished by address and offset
4. The value of FIFO depth is not obtained through registers, but written through DTS
====> The register does not have information on the depth of FIFO,
and manual writing of register settings is required
In addition to the above four points, the initialization, transmission, and interrupts
of i2c Starfive are basically the same as i2c Desirware. Therefore, we hope to reuse
i2c designware instead of re implementing the i2c Starfive driver, otherwise the code repetition will be high
Hope I can answer your question, thank you
Andy Shevchenko
reviewerQuoted 66 lines · Lianfeng Ouyang
Quoted 66 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 13:49Quoted 27 lines · Lianfeng Ouyang
Quoted 27 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27Quoted 22 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced features such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting and making certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revision of the Synopsys IP manual.Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided byQuoted 6 lines
Quoted 6 lines
i2c_dw_set_mode()Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery with full of
__weakannotations that may not be present in the regular driver.There
Quoted 5 lines
Quoted 5 lines
is not even a tiny bit of justification for this nonsense.
TL;DR: this series needs much more work.
Quoted 1 line
I have written some poorly styled code to reduce changes to i2c
designware
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for the two IPs ini2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community isQuoted 8 lines
Quoted 8 lines
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation to
sf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is not changed
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?Thanks for the review.
In the future, the designware will be changed to the form of callback functions, and then callback functions will be passed in i2c starry - * and implemented using designware as a library
Quoted 8 lines
Quoted 2 lines
Why you can't specify your own regmap as it was done in Baikal case? What are the obstacles to achieve that?
The main reasons are as follows
1. For high and low level counting settings at different rates, i2c starfive just use IC_SCL_H/LCNT to set SS, FM, FM+, UFM,
====> Therefore, it is not possible to directly use thei2c_dew_set_timits_master()
of designware, Because the definition of registers has changed
So, it's not a DW per se? What the DW databook reflects the register layout and other bits? I.o.w. which version of DW i2c IP is this?
Quoted 6 lines
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of
INTR_CLR, while designware reads different clearing registers
====> The way of operating registers is different, so it cannot be
distinguished solely by address or offset, and can only be adapted to operations belonging to i2c starfive through callback functions
This can be done in the custom regmap functions. You know that you may redefine the regmap IO accessors and do whatever you want there based on the registers. Yes, what you are probably talking about is a workflow.
But we basically need to see a patch-per-workflow change for each case to understand the differences better. I.o.w. if you need, for instance, separate or special IRQ handling part, create a patch to move existing code to a callback with explanation why it's needed. All the same for the timings and so on. It would be nice to have a datasheet at hand to actually read and see the differences. Without that it's even hard to propose better solutions. But current state is for sure no go.
Quoted 5 lines
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()====> There are host and slave IP addresses separately, unlike designware where one IP supports two roles, because the logic of switching roles cannot be distinguished by address and offset
This feature should be left at last, but altogether it smells like either a completely new i2c DW design (like they did for DMA and SSI at some point) and most likely will need a brand new driver explaining all of this with a link to a datasheet.
Quoted 8 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
====> The register does not have information on the depth of FIFO,
and manual writing of register settings is requiredIn addition to the above four points, the initialization, transmission, and interrupts
of i2c Starfive are basically the same as i2c Desirware. Therefore, we hope to reuse
i2c designware instead of re implementing the i2c Starfive driver, otherwise the code repetition will be high
These sounds like candidates for i2c-designware-lib.c, indeed. But the rest most likely shouldn't be intervened at all. I.o.w. please provide a detailed analysis (something like [1]) in the cover letter, or just send an RFC on the driver design before even starting considering actual coding.
Quoted 1 line
Hope I can answer your question, thank you
[1]: e539f435cb9c ("spi: dw: Add support for DesignWare DWC_ssi")
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 150 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 14:40
收件人: Lianfeng Ouyang <[email protected]>
抄送: Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: 回复: 回复: [PATCH v2 0/3] i2c: Add Starfive JHB100 I2C master/slave supportQuoted 11 lines · Lianfeng Ouyang
Quoted 11 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 13:49Quoted 7 lines · Lianfeng Ouyang
Quoted 7 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27Quoted 2 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced
features
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting andmaking
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revisionof
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
the Synopsys IP manual.
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided byQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
i2c_dw_set_mode()Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery
with
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
full of
__weakannotations that may not be present in the regular driver.There
Quoted 5 lines
Quoted 5 lines
is not even a tiny bit of justification for this nonsense.
TL;DR: this series needs much more work.
Quoted 1 line
I have written some poorly styled code to reduce changes to i2c
designware
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for thetwo
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
IPs in
i2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation tosf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is notchanged
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Thanks for the review.
In the future, the designware will be changed to the form of callback
functions,
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
and then callback functions will be passed in i2c starry - * and implemented using designware as a library
Why you can't specify your own regmap as it was done in Baikal case? What
are
Quoted 6 lines
Quoted 1 line
the obstacles to achieve that?
The main reasons are as follows
1. For high and low level counting settings at different rates, i2c starfive just use IC_SCL_H/LCNT to set SS, FM, FM+, UFM, ====> Therefore, it is not possible to directly use the
i2c_dew_set_timits_master()Quoted 1 line
of designware, Because the definition of registers has changed
So, it's not a DW per se? What the DW databook reflects the register layout and other bits? I.o.w. which version of DW i2c IP is this?
Quoted 6 lines
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of
INTR_CLR, while designware reads different clearing registers
====> The way of operating registers is different, so it cannot be
distinguished solely by address or offset, and can only be adapted to operations belonging to i2c starfive through callback functionsThis can be done in the custom regmap functions. You know that you may redefine the regmap IO accessors and do whatever you want there based on the registers. Yes, what you are probably talking about is a workflow.
But we basically need to see a patch-per-workflow change for each case to understand the differences better. I.o.w. if you need, for instance, separate or special IRQ handling part, create a patch to move existing code to a callback with explanation why it's needed. All the same for the timings and so on. It would be nice to have a datasheet at hand to actually read and see the differences. Without that it's even hard to propose better solutions. But current state is for sure no go.
Quoted 5 lines
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()====> There are host and slave IP addresses separately, unlike designware where one IP supports two roles, because the logic of switching roles cannot be distinguished by address and offsetThis feature should be left at last, but altogether it smells like either a completely new i2c DW design (like they did for DMA and SSI at some point) and most likely will need a brand new driver explaining all of this with a link to a datasheet.
Quoted 6 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
====> The register does not have information on the depth of FIFO,
and manual writing of register settings is requiredIn addition to the above four points, the initialization, transmission, and
interrupts
Quoted 1 line
of i2c Starfive are basically the same as i2c Desirware. Therefore, we hope to
reuse
Quoted 1 line
i2c designware instead of re implementing the i2c Starfive driver, otherwise
the code repetition will be high
These sounds like candidates for
i2c-designware-lib.c, indeed. But the rest most likely shouldn't be intervened at all. I.o.w. please provide a detailed analysis (something like [1]) in the cover letter, or just send an RFC on the driver design before even starting considering actual coding.
Quoted 9 lines
Quoted 1 line
Hope I can answer your question, thank you
[1]:
e539f435cb9c("spi: dw: Add support for DesignWareDWC_ssi")--
With Best Regards,
Andy Shevchenko
Okay, based on the format of e539f435cb9c, I have compiled the differences in register offsets and the differences between registers IC_CTRL and IC-INTR_CLR. Looking forward to your reply
DWC_ADV_i2c is the enhanced version of DW_apb_i2c (corresponding to existing i2c designware driver), Most of their registers are similar, but the bit fields of key registers
(e.g. IC_CTRL/IC_CON, IC_TAR, IC_ENABLE) are different, and DWC_ADV_i2c has additional registers for mission critical features and newer protocol version support.
DWC_ADV_i2c has additional features compared to DW_apb_i2c. Major enhancements
in DWC_ADV_i2c are:
- Support for I2C Bus Specification V7.0 (October 2021) and SMBus Specification V3.2 (January 2022), while DW_apb_i2c supports I2C V6.0 (April 2014) and SMBus V3.1 (March 2018)
- Support for SMBus Non-ARP Command Code Decoding and Advanced Block Read/Write
- Support for dynamic target address update (IC_DYNAMIC_TAR_UPDATE=1)
- Support for Ultra-Fast Mode (up to 5 MB/s) with dedicated timing registers
- Both DWC_ADV_i2c and DW_apb_i2c are APB slave devices, supporting APB2/APB3/APB4 interfaces with configurable data width (8/16/32 bits).
Register offset (base address 0x0 for both, DWC_ADV_i2c uses separate address blocks for operational, I2C and SMBus registers, DW_apb_i2c uses a unified register map)
DWC_ADV_i2c DW_apb_i2c
IC_HCI_VERSION 0x00 N/A IC_ENABLE 0x04 0x6c IC_RESET_CTRL 0x08 N/A IC_CAPABILITIES 0x0c N/A IC_I2C_CAPABILITIES 0x10 N/A IC_SMBUS_CAPABILITIES 0x18 0x9c IC_SMBUS_BLOCK_OFFSET 0x1c 0xa0 IC_CTRL 0x04 (I2C block) 0x00 (IC_CON) IC_TAR 0x08 (I2C block) 0x04 IC_DAR 0x0c (I2C block) 0x08 (IC_SAR) IC_HS_CADDR 0x10 (I2C block) 0x0c (IC_HS_MADDR) IC_DATA_CMD 0x58 (I2C block) 0x10 IC_UFM_TBUF_CNT 0x20 (I2C block) N/A IC_SCL_HCNT 0x24 (I2C block) 0x1c (IC_FS_SCL_HCNT) IC_SCL_LCNT 0x28 (I2C block) 0x20 (IC_FS_SCL_LCNT) IC_HS_SCL_HCNT 0x2c (I2C block) 0x24 IC_HS_SCL_LCNT 0x30 (I2C block) 0x28 IC_SDA_HOLD 0x34 (I2C block) 0x7c IC_SDA_SETUP 0x38 (I2C block) 0x94 IC_SPKLEN 0x3c (I2C block) 0xa0 (IC_FS_SPKLEN) IC_HS_SPKLEN 0x40 (I2C block) 0xa4 IC_DMA_RDLR 0x6c (I2C block) 0x90 IC_INTR_STAT 0x74 (I2C block) 0x2c IC_INTR_MASK 0x78 (I2C block) 0x30 IC_RAW_INTR_STAT 0x7c (I2C block) 0x34 IC_DAR4 0xb8 (I2C block) 0x108 (IC_SAR4) IC_SFTY_CTRL 0xc0 (I2C block) N/A IC_SMBUS_CTRL 0x04 (SMBus block) N/A IC_SMBUS_ARP_CTRL 0x08 (SMBus block) N/A IC_SMBUS_INTR_STAT 0x28 (SMBus block) 0xc8 IC_SMBUS_INTR_MASK 0x2c (SMBus block) 0xcc IC_SMBUS_INTR_RAW_STAT 0x30 (SMBus block) 0xd0
Register configuration - IC_CTRL (DWC_ADV_i2c) vs IC_CON (DW_apb_i2c)
DWC_Adv_i2c DW_apb_i2c
IC_OP_MODE bit[0] bit[0] (MASTER_MODE)
IC_SPEED bit[5:4] bit[2:1] (SPEED) IC_10BITADDR_TGT bit[8] bit[3] (IC_10BITADDR_SLAVE) IC_10BITADDR_CTRLR bit[9] bit[4] (IC_10BITADDR_MASTER) BUS_CLEAR_FEATURE_CTRL bit[14] bit[11]
Register configuration - IC_INTR_CLR
DWC_ADV_i2c DW_apb_i2c
CLR_INTR bit[0] (write) IC_INTR_CLR bit[0] (read)
CLR_RX_UNDER bit[1] (write) IC_CLR_RX_UNDER bit[0] (read) CLR_RX_OVER bit[2] (write) IC_CLR_RX_OVER bit[0] (read) CLR_TX_OVER bit[3] (write) IC_CLR_TX_OVER bit[0] (read) CLR_RD_REQ bit[4] (write) IC_CLR_RD_REQ bit[0] (read)
......
The documents used are
[1] DesignWare ® Cores Advanced I2C/SMBus Controller and Target Device Databook, Product Code H464-0, I2C Bus Spec V7.0,
[2] DesignWare ® DW_apb_i2c Databook, Version 2.03a, December 2020, I2C Bus Spec V6.0
Best Regards,
Lianfeng Ouyang
Andy Shevchenko
reviewerQuoted 136 lines · Lianfeng Ouyang
Quoted 136 lines
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 14:40
Quoted 9 lines · Lianfeng Ouyang
Quoted 9 lines
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 13:49
Quoted 6 lines · Lianfeng Ouyang
Quoted 6 lines
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27
Quoted 2 lines · lianfeng.ouyang
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced
features
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for the starfive,jhb100-i2c compatible.
2. Prepares the existing i2c-designware-core by exporting andmaking
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modules for master and slave functionality, based on the 2023-07 revisionof
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
the Synopsys IP manual.
Currently, due to the following differences, i2c designware cannot be fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads different clearing registers
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided byQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
i2c_dw_set_mode()Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly ifdeffery
with
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
full of
__weakannotations that may not be present in the regular driver.There
Quoted 5 lines
Quoted 5 lines
is not even a tiny bit of justification for this nonsense.
TL;DR: this series needs much more work.
Quoted 1 line
I have written some poorly styled code to reduce changes to i2c
designware
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only for thetwo
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
IPs in
i2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declared as__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designware reads and i2c starfive writes. Therefore, in order not to modify the relevant logic of i2c designware, I added a write operation tosf_reg_read()
So I think this version of the code is not allowed to merge, but I don't know how to handle this situation because if i2c designware is notchanged
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Thanks for the review.
In the future, the designware will be changed to the form of callback
functions,
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
and then callback functions will be passed in i2c starry - * and implemented using designware as a library
Why you can't specify your own regmap as it was done in Baikal case? What
are
Quoted 6 lines
Quoted 1 line
the obstacles to achieve that?
The main reasons are as follows
1. For high and low level counting settings at different rates, i2c starfive just use IC_SCL_H/LCNT to set SS, FM, FM+, UFM, ====> Therefore, it is not possible to directly use the
i2c_dew_set_timits_master()Quoted 1 line
of designware, Because the definition of registers has changed
So, it's not a DW per se? What the DW databook reflects the register layout and other bits? I.o.w. which version of DW i2c IP is this?
Quoted 6 lines
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of
INTR_CLR, while designware reads different clearing registers
====> The way of operating registers is different, so it cannot be
distinguished solely by address or offset, and can only be adapted to operations belonging to i2c starfive through callback functionsThis can be done in the custom regmap functions. You know that you may redefine the regmap IO accessors and do whatever you want there based on the registers. Yes, what you are probably talking about is a workflow.
But we basically need to see a patch-per-workflow change for each case to understand the differences better. I.o.w. if you need, for instance, separate or special IRQ handling part, create a patch to move existing code to a callback with explanation why it's needed. All the same for the timings and so on. It would be nice to have a datasheet at hand to actually read and see the differences. Without that it's even hard to propose better solutions. But current state is for sure no go.
Quoted 5 lines
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()====> There are host and slave IP addresses separately, unlike designware where one IP supports two roles, because the logic of switching roles cannot be distinguished by address and offsetThis feature should be left at last, but altogether it smells like either a completely new i2c DW design (like they did for DMA and SSI at some point) and most likely will need a brand new driver explaining all of this with a link to a datasheet.
Quoted 6 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
====> The register does not have information on the depth of FIFO,
and manual writing of register settings is requiredIn addition to the above four points, the initialization, transmission, and
interrupts
Quoted 1 line
of i2c Starfive are basically the same as i2c Desirware. Therefore, we hope to
reuse
Quoted 1 line
i2c designware instead of re implementing the i2c Starfive driver, otherwise
the code repetition will be high
These sounds like candidates for
i2c-designware-lib.c, indeed. But the rest most likely shouldn't be intervened at all. I.o.w. please provide a detailed analysis (something like [1]) in the cover letter, or just send an RFC on the driver design before even starting considering actual coding.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Hope I can answer your question, thank you
[1]:
e539f435cb9c("spi: dw: Add support for DesignWareDWC_ssi")Okay, based on the format of
e539f435cb9c, I have compiled the differences in register offsets and the differences between registersIC_CTRLand IC-INTR_CLR. Looking forward to your reply
Thank you for this information, it makes much more easier to see the big picture. With the given information I think you most likely need a brand new driver. No callbacks for sure. The only thing that may be done is to split really common code and data structures in i2c-designware-lib.[ch] between two. This will require quite a bit of refactoring (as you most likely don't want to inherit all quirked and hacked fields from struct dw_i2c_dev, meaning you want to have something just very basic and common between two there. means that the current struct dw_i2c_dev will be morphed to something like
drivers/i2c/busses/i2c-designware-lib.h:
struct dw_i2c_common {
...
};drivers/i2c/busses/i2c-designware-core.h:
struct dw_i2c_dev {
struct dw_i2c_common icom;
...
};and in your new driver
struct dw_adv_i2c_dev {
struct dw_i2c_common icom;
...
};And in the drivers/i2c/busses/i2c-designware-lib.c:
... dw_i2c_common_...(struct dw_i2c_common *icom, ...)
{
...
}for the shared APIs.
With that I predict a series out of ~10 patches (or more).
The brand new driver is also a solution, but to go there you need to at least have a PoC of the above to justify that the shared code makes little sense.
Quoted 71 lines
DWC_ADV_i2cis the enhanced version ofDW_apb_i2c(corresponding to existing i2c designware driver), Most of their registers are similar, but the bit fields of key registers
(e.g. IC_CTRL/IC_CON,IC_TAR,IC_ENABLE) are different, andDWC_ADV_i2chas additional registers for mission critical features and newer protocol version support.
DWC_ADV_i2chas additional features compared toDW_apb_i2c. Major enhancements
inDWC_ADV_i2care:
- Support for I2C Bus Specification V7.0 (October 2021) and SMBus Specification V3.2 (January 2022), whileDW_apb_i2csupports I2C V6.0 (April 2014) and SMBus V3.1 (March 2018)
- Support for SMBus Non-ARP Command Code Decoding and Advanced Block Read/Write
- Support for dynamic target address update (IC_DYNAMIC_TAR_UPDATE=1)
- Support for Ultra-Fast Mode (up to 5 MB/s) with dedicated timing registers
- BothDWC_ADV_i2candDW_apb_i2care APB slave devices, supporting APB2/APB3/APB4 interfaces with configurable data width (8/16/32 bits).Register offset (base address
0x0for both,DWC_ADV_i2cuses separate address blocks for operational, I2C and SMBus registers,DW_apb_i2cuses a unified register map)
DWC_ADV_i2cDW_apb_i2cIC_HCI_VERSION 0x00 N/A IC_ENABLE 0x04 0x6c IC_RESET_CTRL 0x08 N/A IC_CAPABILITIES 0x0c N/A IC_I2C_CAPABILITIES 0x10 N/A IC_SMBUS_CAPABILITIES 0x18 0x9c IC_SMBUS_BLOCK_OFFSET 0x1c 0xa0 IC_CTRL 0x04 (I2C block) 0x00 (IC_CON) IC_TAR 0x08 (I2C block) 0x04 IC_DAR 0x0c (I2C block) 0x08 (IC_SAR) IC_HS_CADDR 0x10 (I2C block) 0x0c (IC_HS_MADDR) IC_DATA_CMD 0x58 (I2C block) 0x10 IC_UFM_TBUF_CNT 0x20 (I2C block) N/A IC_SCL_HCNT 0x24 (I2C block) 0x1c (IC_FS_SCL_HCNT) IC_SCL_LCNT 0x28 (I2C block) 0x20 (IC_FS_SCL_LCNT) IC_HS_SCL_HCNT 0x2c (I2C block) 0x24 IC_HS_SCL_LCNT 0x30 (I2C block) 0x28 IC_SDA_HOLD 0x34 (I2C block) 0x7c IC_SDA_SETUP 0x38 (I2C block) 0x94 IC_SPKLEN 0x3c (I2C block) 0xa0 (IC_FS_SPKLEN) IC_HS_SPKLEN 0x40 (I2C block) 0xa4 IC_DMA_RDLR 0x6c (I2C block) 0x90 IC_INTR_STAT 0x74 (I2C block) 0x2c IC_INTR_MASK 0x78 (I2C block) 0x30 IC_RAW_INTR_STAT 0x7c (I2C block) 0x34 IC_DAR4 0xb8 (I2C block) 0x108 (IC_SAR4) IC_SFTY_CTRL 0xc0 (I2C block) N/A IC_SMBUS_CTRL 0x04 (SMBus block) N/A IC_SMBUS_ARP_CTRL 0x08 (SMBus block) N/A IC_SMBUS_INTR_STAT 0x28 (SMBus block) 0xc8 IC_SMBUS_INTR_MASK 0x2c (SMBus block) 0xcc IC_SMBUS_INTR_RAW_STAT 0x30 (SMBus block) 0xd0Register configuration -
IC_CTRL(DWC_ADV_i2c) vsIC_CON(DW_apb_i2c)
DWC_Adv_i2cDW_apb_i2c
IC_OP_MODEbit[0] bit[0] (MASTER_MODE)IC_SPEED bit[5:4] bit[2:1] (SPEED) IC_10BITADDR_TGT bit[8] bit[3] (IC_10BITADDR_SLAVE) IC_10BITADDR_CTRLR bit[9] bit[4] (IC_10BITADDR_MASTER) BUS_CLEAR_FEATURE_CTRL bit[14] bit[11]Register configuration -
IC_INTR_CLR
DWC_ADV_i2cDW_apb_i2c
CLR_INTRbit[0] (write)IC_INTR_CLRbit[0] (read)CLR_RX_UNDER bit[1] (write) IC_CLR_RX_UNDER bit[0] (read) CLR_RX_OVER bit[2] (write) IC_CLR_RX_OVER bit[0] (read) CLR_TX_OVER bit[3] (write) IC_CLR_TX_OVER bit[0] (read) CLR_RD_REQ bit[4] (write) IC_CLR_RD_REQ bit[0] (read)......
The documents used are
[1] DesignWare ® Cores Advanced I2C/SMBus Controller and Target Device Databook, Product Code H464-0, I2C Bus Spec V7.0,
[2] DesignWare ®DW_apb_i2cDatabook, Version 2.03a, December 2020, I2C Bus Spec V6.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 216 lines
-----邮件原件-----
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月5日 2:09
收件人: Lianfeng Ouyang <[email protected]>
抄送: Andi Shyti <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: 回复: 回复: 回复: [PATCH v2 0/3] i2c: Add Starfive JHB100 I2C master/slave supportQuoted 10 lines · Lianfeng Ouyang
Quoted 10 lines
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 14:40
Quoted 6 lines · Lianfeng Ouyang
Quoted 6 lines
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 13:49
Quoted 3 lines · Lianfeng Ouyang
Quoted 3 lines
发件人: Andy Shevchenko <[email protected]> 发送时间: 2026年6月3日 6:27
On Wed, May 27, 2026 at 04:50:36PM +0800, lianfeng.ouyang wrote:Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The Starfive JHB100 I2C controller is a variant of the widely-used DesignWare I2C IP, with a distinct register layout and enhanced
features
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
such as SMBus Alert and programmable FIFO depths.
The series is structured as follows:
1. Adds the device tree binding document for thestarfive,jhb100-i2c
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
compatible.
2. Prepares the existing i2c-designware-core by exporting andmaking
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
certain key functions overridable, allowing code reuse.
3. Introduces the new i2c-starfive-* driver, with separate modulesfor
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
master and slave functionality, based on the 2023-07
revision
Quoted 4 lines
Quoted 4 lines
of
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
the Synopsys IP manual.
Currently, due to the following differences, i2c designware cannot
be
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fully reused
1. For high and low level counting settings at different rates, i2c starfive can use IC_SCL-H/LCNT to set SS, FM, FM+, UFM
2. Interrupt clearing is achieved by writing 1 to the corresponding bit ofINTR_CLR, while designware reads differentclearing
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
registers
3. Master and slave require separate probe callbacks and cannotrely
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
solely on the runtime mode switching provided by
i2c_dw_set_mode()Quoted 2 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
NAK in this form. We well discourage code duplication and ugly
ifdeffery
Quoted 2 lines
Quoted 2 lines
with
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
full of
__weakannotations that may not be present in the regulardriver.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
There
Quoted 5 lines
Quoted 5 lines
is not even a tiny bit of justification for this nonsense.
TL;DR: this series needs much more work.
Quoted 1 line
I have written some poorly styled code to reduce changes to i2c
designware
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and reuse its functions by keeping aa always true, for example
1. the implementation of i2c-dw_probe_master()differs only forthe
Quoted 3 lines
Quoted 3 lines
two
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
IPs in
i2c_dw_set_timits_master(). In order to reusei2c_dw_probe_master(),i2c_dw_set_timits_masteris declaredas
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
__weak. A better approach is to use a callback function, but using a callback function requires changing more i2c designware files. I don't know what the attitude of the community is
2. For the operation of clearing interrupt flags, i2c designwarereads
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and i2c starfive writes. Therefore, in order not to modify
the
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
relevant logic of i2c designware, I added a write operation to sf_reg_read()So I think this version of the code is not allowed to merge, but I
don't
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
know how to handle this situation because if i2c designware is not
changed
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
at all, we will have to write code that is similar to i2c designware. Will this type of IP not be allowed to merge?
Thanks for the review.
In the future, the designware will be changed to the form of callback
functions,
Quoted 1 line
Quoted 1 line
Quoted 1 line
and then callback functions will be passed in i2c starry - * and
implemented
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
using designware as a library
Why you can't specify your own regmap as it was done in Baikal case?
What
Quoted 11 lines
Quoted 11 lines
are
Quoted 6 lines
Quoted 1 line
the obstacles to achieve that?
The main reasons are as follows
1. For high and low level counting settings at different rates, i2c starfive just use IC_SCL_H/LCNT to set SS, FM, FM+, UFM, ====> Therefore, it is not possible to directly use the
i2c_dew_set_timits_master()Quoted 1 line
of designware, Because the definition of registers has changed
So, it's not a DW per se? What the DW databook reflects the register layout
and
Quoted 21 lines
Quoted 21 lines
other bits? I.o.w. which version of DW i2c IP is this?
Quoted 6 lines
2. Interrupt clearing is achieved by writing 1 to the corresponding bit of
INTR_CLR, while designware reads different clearing registers
====> The way of operating registers is different, so it cannot be
distinguished solely by address or offset, and can only be adapted to operations belonging to i2c starfive through callback functionsThis can be done in the custom regmap functions. You know that you may redefine the regmap IO accessors and do whatever you want there based on the registers. Yes, what you are probably talking about is a workflow.
But we basically need to see a patch-per-workflow change for each case to understand the differences better. I.o.w. if you need, for instance, separate or special IRQ handling part, create a patch to move existing code to a callback with explanation why it's needed. All the same for the timings and so on. It would be nice to have a datasheet at hand to actually read and see the differences. Without that it's even hard to propose better solutions. But current state is for sure no go.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
3. Master and slave require separate probe callbacks and cannot rely solely on the runtime mode switching provided by
i2c_dw_set_mode()====> There are host and slave IP addresses separately, unlike designware where one IP supports two roles, because the logic of switchingroles
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
cannot be distinguished by address and offset
This feature should be left at last, but altogether it smells like either a completely new i2c DW design (like they did for DMA and SSI at some point) and most likely will need a brand new driver explaining all of this with a link to a datasheet.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
4. The value of FIFO depth is not obtained through registers, but written through DTS
====> The register does not have information on the depth of FIFO,
and manual writing of register settings is requiredIn addition to the above four points, the initialization, transmission, and
interrupts
Quoted 1 line
of i2c Starfive are basically the same as i2c Desirware. Therefore, we hope
to
Quoted 2 lines
Quoted 2 lines
reuse
Quoted 1 line
i2c designware instead of re implementing the i2c Starfive driver,
otherwise
Quoted 8 lines
Quoted 8 lines
the code repetition will be high
These sounds like candidates for
i2c-designware-lib.c, indeed. But the rest most likely shouldn't be intervened at all. I.o.w. please provide a detailed analysis (something like [1]) in the cover letter, or just send an RFC on the driver design before even starting considering actual coding.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Hope I can answer your question, thank you
[1]:
e539f435cb9c("spi: dw: Add support for DesignWareDWC_ssi")Okay, based on the format of
e539f435cb9c, I have compiled the differences in register offsets and the differences between registersIC_CTRLandIC-INTR_CLR.
Quoted 1 line
Looking forward to your reply
Thank you for this information, it makes much more easier to see the big picture.
With the given information I think you most likely need a brand new driver. No callbacks for sure. The only thing that may be done is to split really common code and data structures in i2c-designware-lib.[ch] between two. This will require quite a bit of refactoring (as you most likely don't want to inherit all quirked and hacked fields from structdw_i2c_dev, meaning you want to have something just very basic and common between two there. means that the current structdw_i2c_devwill be morphed to something like
drivers/i2c/busses/i2c-designware-lib.h:struct dw_i2c_common { ... };
drivers/i2c/busses/i2c-designware-core.h:struct dw_i2c_dev { struct dw_i2c_common icom; ... };and in your new driver
struct dw_adv_i2c_dev { struct dw_i2c_common icom; ... };And in the
drivers/i2c/busses/i2c-designware-lib.c:... dw_i2c_common_...(struct dw_i2c_common *icom, ...) { ... }
Quoted 7 lines
for the shared APIs.
With that I predict a series out of ~10 patches (or more).
The brand new driver is also a solution, but to go there you need to at least have a PoC of the above to justify that the shared code makes little sense.
Thank you for your idea. I will modify my code in this direction
Best Regards,
Lianfeng Ouyang
Quoted 99 lines
Quoted 1 line
DWC_ADV_i2cis the enhanced version ofDW_apb_i2c(corresponding toexisting i2c designware driver),
Quoted 2 lines
Most of their registers are similar, but the bit fields of key registers (e.g. IC_CTRL/IC_CON,
IC_TAR,IC_ENABLE) are different, andDWC_ADV_i2chas
Quoted 1 line
additional registers for mission critical features and newer protocol version
support.
Quoted 2 lines
DWC_ADV_i2chas additional features compared toDW_apb_i2c. Majorenhancements
Quoted 2 lines
in
DWC_ADV_i2care:
- Support for I2C Bus Specification V7.0 (October 2021) and SMBusSpecification V3.2 (January 2022),
Quoted 1 line
while
DW_apb_i2csupports I2C V6.0 (April 2014) and SMBus V3.1 (March2018)
Quoted 1 line
- Support for SMBus Non-ARP Command Code Decoding and Advanced Block
Read/Write
Quoted 3 lines
- Support for dynamic target address update (IC_DYNAMIC_TAR_UPDATE=1)
- Support for Ultra-Fast Mode (up to 5 MB/s) with dedicated timing registers
- BothDWC_ADV_i2candDW_apb_i2care APB slave devices, supportingAPB2/APB3/APB4
Quoted 3 lines
interfaces with configurable data width (8/16/32 bits).
Register offset (base address
0x0for both,DWC_ADV_i2cuses separateaddress blocks for
Quoted 1 line
operational, I2C and SMBus registers,
DW_apb_i2cuses a unified registermap)
Quoted 12 lines
DWC_ADV_i2cDW_apb_i2cIC_HCI_VERSION 0x00 N/A IC_ENABLE 0x04 0x6c IC_RESET_CTRL 0x08 N/A IC_CAPABILITIES 0x0c N/A IC_I2C_CAPABILITIES 0x10 N/A IC_SMBUS_CAPABILITIES 0x18 0x9c IC_SMBUS_BLOCK_OFFSET 0x1c 0xa0 IC_CTRL 0x04 (I2C block) 0x00 (IC_CON) IC_TAR 0x08 (I2C block) 0x04 IC_DAR 0x0c (I2C block) 0x08 (IC_SAR) IC_HS_CADDR 0x10 (I2C block) 0x0c(
IC_HS_MADDR)Quoted 3 lines
IC_DATA_CMD 0x58 (I2C block) 0x10 IC_UFM_TBUF_CNT 0x20 (I2C block) N/A IC_SCL_HCNT 0x24 (I2C block) 0x1c(
IC_FS_SCL_HCNT)Quoted 1 line
IC_SCL_LCNT0x28(I2C block)0x20(
IC_FS_SCL_LCNT)Quoted 18 lines
IC_HS_SCL_HCNT 0x2c (I2C block) 0x24 IC_HS_SCL_LCNT 0x30 (I2C block) 0x28 IC_SDA_HOLD 0x34 (I2C block) 0x7c IC_SDA_SETUP 0x38 (I2C block) 0x94 IC_SPKLEN 0x3c (I2C block) 0xa0 (IC_FS_SPKLEN) IC_HS_SPKLEN 0x40 (I2C block) 0xa4 IC_DMA_RDLR 0x6c (I2C block) 0x90 IC_INTR_STAT 0x74 (I2C block) 0x2c IC_INTR_MASK 0x78 (I2C block) 0x30 IC_RAW_INTR_STAT 0x7c (I2C block) 0x34 IC_DAR4 0xb8 (I2C block) 0x108 (IC_SAR4) IC_SFTY_CTRL 0xc0 (I2C block) N/A IC_SMBUS_CTRL 0x04 (SMBus block) N/A IC_SMBUS_ARP_CTRL 0x08 (SMBus block) N/A IC_SMBUS_INTR_STAT 0x28 (SMBus block) 0xc8 IC_SMBUS_INTR_MASK 0x2c (SMBus block) 0xcc IC_SMBUS_INTR_RAW_STAT 0x30 (SMBus block) 0xd0Quoted 3 lines
Register configuration -
IC_CTRL(DWC_ADV_i2c) vsIC_CON(DW_apb_i2c)
DWC_Adv_i2cDW_apb_i2c
IC_OP_MODEbit[0] bit[0](
MASTER_MODE)Quoted 2 lines
IC_SPEEDbit[5:4] bit[2:1] (SPEED)
IC_10BITADDR_TGTbit[8] bit[3](
IC_10BITADDR_SLAVE)Quoted 1 line
IC_10BITADDR_CTRLRbit[9] bit[4](
IC_10BITADDR_MASTER)Quoted 5 lines
BUS_CLEAR_FEATURE_CTRLbit[14] bit[11]Register configuration -
IC_INTR_CLR
DWC_ADV_i2cDW_apb_i2c
CLR_INTRbit[0] (write)IC_INTR_CLRbit[0] (read)
Quoted 1 line
CLR_RX_UNDERbit[1] (write)IC_CLR_RX_UNDERbit[0] (read)
Quoted 1 line
CLR_RX_OVERbit[2] (write)IC_CLR_RX_OVERbit[0] (read)
Quoted 1 line
CLR_TX_OVERbit[3] (write)IC_CLR_TX_OVERbit[0] (read)
Quoted 1 line
CLR_RD_REQbit[4] (write)IC_CLR_RD_REQbit[0] (read)
Quoted 4 lines
......
The documents used are
[1] DesignWare ® Cores Advanced I2C/SMBus Controller and Target DeviceDatabook, Product Code H464-0, I2C Bus Spec V7.0,
Quoted 1 line
[2] DesignWare ®
DW_apb_i2cDatabook, Version 2.03a, December 2020, I2CBus Spec V6.0
--
With Best Regards,
Andy Shevchenko