Add support for MSCC Ocelot i2c
Subsystems (6)
Alexandre Belloni
maintainercover Add support for MSCC Ocelot i2c
Hi,
Because the designware IP was not able to the the SDA hold time, MSCC has its own implementation. Add support for it and then add i2c on ocelot boards.
I would expect patches 1 to 3 to go through the i2c tree and 4-5 through the mips tree once patch 3 has been reviewed by the DT maintainers.
Alexandre Belloni (5):
i2c: designware: factorize setting SDA hold time
i2c: designware: allow IP specific sda_hold_time
i2c: designware: add MSCC Ocelot support
mips: dts: mscc: Add i2c on ocelot
mips: dts: mscc: enable i2c on ocelot_pcb123
.../bindings/i2c/i2c-designware.txt | 5 ++- arch/mips/boot/dts/mscc/ocelot.dtsi | 19 +++++++++++ arch/mips/boot/dts/mscc/ocelot_pcb123.dts | 5 +++ drivers/i2c/busses/i2c-designware-common.c | 33 +++++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 3 ++ drivers/i2c/busses/i2c-designware-master.c | 22 +------------ drivers/i2c/busses/i2c-designware-platdrv.c | 20 +++++++++++ drivers/i2c/busses/i2c-designware-slave.c | 22 +------------ 8 files changed, 86 insertions(+), 43 deletions(-)
Signature · 1 line
2.18.0
Alexandre Belloni
maintainerPATCH 1/5 i2c: designware: factorize setting SDA hold time
Factorize setting the SDA hold time in a new function i2c_dw_set_sda_hold_time() that is used for both master and slave mode.
This conveniently pulls the fix for the spurious warning from commit 7a20e707aae2 ("i2c: designware: suppress unneeded SDA hold time warnings") in slave mode.
--- drivers/i2c/busses/i2c-designware-common.c | 27 ++++++++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-master.c | 22 +----------------- drivers/i2c/busses/i2c-designware-slave.c | 22 +----------------- 4 files changed, 30 insertions(+), 42 deletions(-)
drivers/i2c/busses/i2c-designware-common.c +27 -0
@@ -293,5 +293,32 @@ u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev) }EXPORT_SYMBOL_GPL (i2c_dw_read_comp_param); +void i2c_dw_set_sda_hold_time (struct dw_i2c_dev *dev) +{ +u32 reg; + +/* Configure SDA Hold Time if required. */ + reg =dw_readl (dev,DW_IC_COMP_VERSION ); +if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) { +if (!dev->sda_hold_time) { +/* Keep previous hold time setting if no one set it. */ + dev->sda_hold_time =dw_readl (dev,DW_IC_SDA_HOLD ); + } +/* +* Workaround for avoiding TX arbitration lost in case I2C +* slave pulls SDA down "too quickly" after falling egde of +* SCL by enabling non-zero SDA RX hold. Specification says it +* extends incoming SDA low to high transition while SCL is +* high but it apprears to help also above issue. +*/ +if (!(dev->sda_hold_time &DW_IC_SDA_HOLD_RX_MASK )) + dev->sda_hold_time |=1 <<DW_IC_SDA_HOLD_RX_SHIFT ; +dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); + }else if (dev->sda_hold_time) { +dev_warn (dev->dev, +"Hardware too old to adjust SDA hold time.\n" ); + } +} +MODULE_DESCRIPTION ("Synopsys DesignWare I2C bus adapter core" );MODULE_LICENSE ("GPL" );
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -306,6 +306,7 @@ int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev);u32 i2c_dw_func (struct i2c_adapter *adap);void i2c_dw_disable (struct dw_i2c_dev *dev);void i2c_dw_disable_int (struct dw_i2c_dev *dev); +void i2c_dw_set_sda_hold_time (struct dw_i2c_dev *dev);static inline void __i2c_dw_enable (struct dw_i2c_dev *dev) {
drivers/i2c/busses/i2c-designware-master.c +1 -21
@@ -146,27 +146,7 @@ static int i2c_dw_init_master(struct dw_i2c_dev *dev) } } -/* Configure SDA Hold Time if required */ - reg =dw_readl (dev,DW_IC_COMP_VERSION ); -if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) { -if (!dev->sda_hold_time) { -/* Keep previous hold time setting if no one set it */ - dev->sda_hold_time =dw_readl (dev,DW_IC_SDA_HOLD ); - } -/* -* Workaround for avoiding TX arbitration lost in case I2C -* slave pulls SDA down "too quickly" after falling egde of -* SCL by enabling non-zero SDA RX hold. Specification says it -* extends incoming SDA low to high transition while SCL is -* high but it apprears to help also above issue. -*/ -if (!(dev->sda_hold_time &DW_IC_SDA_HOLD_RX_MASK )) - dev->sda_hold_time |=1 <<DW_IC_SDA_HOLD_RX_SHIFT ; -dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); - }else if (dev->sda_hold_time) { -dev_warn (dev->dev, -"Hardware too old to adjust SDA hold time.\n" ); - } +i2c_dw_set_sda_hold_time (dev);i2c_dw_configure_fifo_master (dev);i2c_dw_release_lock (dev);
drivers/i2c/busses/i2c-designware-slave.c +1 -21
@@ -77,27 +77,7 @@ static int i2c_dw_init_slave(struct dw_i2c_dev *dev)/* Disable the adapter. */ __i2c_dw_disable (dev); -/* Configure SDA Hold Time if required. */ - reg =dw_readl (dev,DW_IC_COMP_VERSION ); -if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) { -if (!dev->sda_hold_time) { -/* Keep previous hold time setting if no one set it. */ - dev->sda_hold_time =dw_readl (dev,DW_IC_SDA_HOLD ); - } -/* -* Workaround for avoiding TX arbitration lost in case I2C -* slave pulls SDA down "too quickly" after falling egde of -* SCL by enabling non-zero SDA RX hold. Specification says it -* extends incoming SDA low to high transition while SCL is -* high but it apprears to help also above issue. -*/ -if (!(dev->sda_hold_time &DW_IC_SDA_HOLD_RX_MASK )) - dev->sda_hold_time |=1 <<DW_IC_SDA_HOLD_RX_SHIFT ; -dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); - }else { -dev_warn (dev->dev, -"Hardware too old to adjust SDA hold time.\n" ); - } +i2c_dw_set_sda_hold_time (dev);i2c_dw_configure_fifo_slave (dev);i2c_dw_release_lock (dev);
Signature · 1 line
2.18.0
Alexandre Belloni
maintainerPATCH 2/5 i2c: designware: allow IP specific sda_hold_time
In reply to Alexandre BelloniBecause some old designware IPs were not supporting setting an SDA hold time, vendors developed their own solution. Add a way for the final driver to provide its own SDA hold time handling.
--- drivers/i2c/busses/i2c-designware-common.c | 6 ++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + 2 files changed, 7 insertions(+)
drivers/i2c/busses/i2c-designware-common.c +6 -0
@@ -297,6 +297,12 @@ void i2c_dw_set_sda_hold_time(struct dw_i2c_dev *dev) {u32 reg; +if (dev->set_sda_hold_time) { + dev->set_sda_hold_time (dev); + +return ; + } +/* Configure SDA Hold Time if required. */ reg =dw_readl (dev,DW_IC_COMP_VERSION );if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) {
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -283,6 +283,7 @@ struct dw_i2c_dev {void (*disable)(struct dw_i2c_dev *dev);void (*disable_int)(struct dw_i2c_dev *dev);int (*init)(struct dw_i2c_dev *dev); +int (*set_sda_hold_time)(struct dw_i2c_dev *dev);int mode;struct i2c_bus_recovery_info rinfo; };
Signature · 1 line
2.18.0
Alexandre Belloni
maintainerPATCH 3/5 i2c: designware: add MSCC Ocelot support
In reply to Alexandre BelloniThe Microsemi Ocelot I2C controller is a designware IP. It also has a second set of registers to allow tweaking SDA hold time and spike filtering.
--- .../bindings/i2c/i2c-designware.txt | 5 ++++- drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +4 -1
@@ -2,7 +2,7 @@ Required properties : - - compatible : should be "snps,designware-i2c" + - compatible : should be "snps,designware-i2c" or "mscc,ocelot-i2c" - reg : Offset and length of the register set for the device - interrupts : <IRQ> where IRQ is the interrupt number.
@@ -11,6 +11,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. Optional properties : + - reg : for "mscc,ocelot-i2c", a second register set to configure the SDA hold + time, named ICPU_CFG:TWI_DELAY in the datasheet. + - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. This option is only supported in hardware blocks version 1.11a or newer.
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -237,6 +237,7 @@struct dw_i2c_dev {struct device *dev;void __iomem *base; +void __iomem *base_ext;struct completion cmd_complete;struct clk *clk;struct reset_control *rst;
drivers/i2c/busses/i2c-designware-platdrv.c +20 -0
@@ -204,6 +204,18 @@ static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) dev->mode =DW_IC_SLAVE ; } +#define MSCC_ICPU_CFG_TWI_DELAY 0x0 +#define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) +#define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 + +static int mscc_twi_set_sda_hold_time (struct dw_i2c_dev *dev) +{ +writel ((dev->sda_hold_time <<1 ) |MSCC_ICPU_CFG_TWI_DELAY_ENABLE , + dev->base_ext +MSCC_ICPU_CFG_TWI_DELAY ); + +return 0 ; +} +static void dw_i2c_set_fifo_size (struct dw_i2c_dev *dev,int id) {u32 param, tx_fifo_depth, rx_fifo_depth;
@@ -342,6 +354,13 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) 1000000); } +if (of_device_is_compatible (pdev->dev.of_node,"mscc,ocelot-i2c" )) { + mem =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); + dev->base_ext =devm_ioremap_resource (&pdev->dev, mem); +if (!IS_ERR (dev->base_ext)) + dev->set_sda_hold_time = mscc_twi_set_sda_hold_time; + } +dw_i2c_set_fifo_size (dev, pdev->id); adap = &dev->adapter;
@@ -410,6 +429,7 @@ static int dw_i2c_plat_remove(struct platform_device *pdev)#ifdef CONFIG_OF static const struct of_device_id dw_i2c_of_match[] = { { .compatible ="snps,designware-i2c" , }, + { .compatible ="mscc,ocelot-i2c" , }, {}, };MODULE_DEVICE_TABLE (of, dw_i2c_of_match);
Signature · 1 line
2.18.0
Alexandre Belloni
maintainerPATCH 4/5 mips: dts: mscc: Add i2c on ocelot
In reply to Alexandre BelloniOcelot has an i2c controller, add it. There is only one possible pinmux configuration so add it as well.
--- arch/mips/boot/dts/mscc/ocelot.dtsi | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/mips/boot/dts/mscc/ocelot.dtsi +19 -0
@@ -78,6 +78,20 @@ status = "disabled"; }; + i2c: i2c@100400 { + compatible = "mscc,ocelot-i2c", "snps,designware-i2c"; + pinctrl-0 = <&i2c_pins>; + pinctrl-names = "default"; + reg = <0x100400 0x100>, <0x198 0x8>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <8>; + i2c-sda-hold-time-ns = <300>; + clocks = <&ahb_clk>; + + status = "disabled"; + }; + uart2: serial@100800 { pinctrl-0 = <&uart2_pins>; pinctrl-names = "default";
@@ -178,6 +192,11 @@ pins = "GPIO_12", "GPIO_13"; function = "uart2"; }; + + i2c_pins: i2c-pins { + pins = "GPIO_16", "GPIO_17"; + function = "twi"; + }; }; mdio0: mdio@107009c {
Signature · 1 line
2.18.0
Alexandre Belloni
maintainerPATCH 5/5 mips: dts: mscc: enable i2c on ocelot_pcb123
In reply to Alexandre BelloniEnable the i2c controller on ocelot PCB123. While there are no i2c devices on the board itself, it can be used to control the SFP transceivers.
--- arch/mips/boot/dts/mscc/ocelot_pcb123.dts | 5 +++++ 1 file changed, 5 insertions(+)
arch/mips/boot/dts/mscc/ocelot_pcb123.dts +5 -0
@@ -26,6 +26,11 @@ status = "okay"; }; +&i2c { + clock-frequency = <100000>; + status = "okay"; +}; + &mdio0 { status = "okay"; };
Signature · 1 line
2.18.0
Andy Shevchenko
reviewerRe: [PATCH 1/5] i2c: designware: factorize setting SDA hold time
In reply to Alexandre BelloniQuoted 8 lines · Alexandre Belloni
Factorize setting the SDA hold time in a new function
i2c_dw_set_sda_hold_time()that is used for both master and slave mode.This conveniently pulls the fix for the spurious warning from commit
7a20e707aae2("i2c: designware: suppress unneeded SDA hold time warnings")
in slave mode.
Isn't this a duplication of
commit 1080ee7e28e1cea86310739e5dd4612868768aed
Author: Jarkko Nikula <[email protected]> Date: Tue Jun 19 14:23:22 2018 +0300
i2c: designware: Move SDA hold time configuration to common code
?
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Andy Shevchenko
reviewerRe: [PATCH 3/5] i2c: designware: add MSCC Ocelot support
In reply to Alexandre BelloniQuoted 3 lines · Alexandre Belloni
The Microsemi Ocelot I2C controller is a designware IP. It also has a second set of registers to allow tweaking SDA hold time and spike filtering.
Can you elaborate a bit?
Are they platform specific? Are they shadow registers? Are they something else? Datasheet link / excerpt would be also good to read.
Documentation/devicetree/bindings/i2c/i2c-designware.txt Recommended properties : · line 16
Quoted 5 lines
Optional properties :
+ - reg : for "mscc,ocelot-i2c", a second register set to configure the SDA holdDocumentation/devicetree/bindings/i2c/i2c-designware.txt +2
-0+ time, named ICPU_CFG:TWI_DELAY in the datasheet. +
Hmm... Is this registers unique to the SoC in question? Is address of them fixed or may be configured on RTL level?
If former is right, why do we need a separate property?
drivers/i2c/busses/i2c-designware-platdrv.c static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) · line 217
Quoted 13 lines
drivers/i2c/busses/i2c-designware-platdrv.c +7
-0+#define MSCC_ICPU_CFG_TWI_DELAY 0x0 +#define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) +#define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 + +static int mscc_twi_set_sda_hold_time (struct dw_i2c_dev *dev) +{ + writel((dev->sda_hold_time << 1) |
MSCC_ICPU_CFG_TWI_DELAY_ENABLE,drivers/i2c/busses/i2c-designware-platdrv.c +4
-0+ dev->base_ext + MSCC_ICPU_CFG_TWI_DELAY); + +return 0 ; +}
Hmm... And does how this make native DesignWare IP's registers obsolete?
Quoted 2 lines
(quoted diff) +1
-0+ if (of_device_is_compatible(pdev->dev.of_node, "mscc,ocelot-i2c"))
Can't you just ask for this unconditionally? Why not? (It seems I might have known why not, but can we use named resource instead in case this is not so SoC specific)
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Andy Shevchenko
reviewerQuoted 10 lines · Alexandre Belloni
Hi,
Because the designware IP was not able to the the SDA hold time, MSCC has
its own implementation. Add support for it and then add i2c on ocelot boards.I would expect patches 1 to 3 to go through the i2c tree and 4-5 through
the mips tree once patch 3 has been reviewed by the DT maintainers.
Without reading datasheet it all feels like a wrong place to put.
But maybe that SoC (SoC family?) has some update to DesignWare IP. Btw, what the version of DW IP it's using? 2.00a? More older, more recent?
Quoted 18 lines
Alexandre Belloni (5):
i2c: designware: factorize setting SDA hold time
i2c: designware: allow IP specificsda_hold_time
i2c: designware: add MSCC Ocelot support
mips: dts: mscc: Add i2c on ocelot
mips: dts: mscc: enable i2c onocelot_pcb123.../bindings/i2c/i2c-designware.txt | 5 ++- arch/mips/boot/dts/mscc/ocelot.dtsi | 19 +++++++++++ arch/mips/boot/dts/mscc/ocelot_pcb123.dts | 5 +++ drivers/i2c/busses/i2c-designware-common.c | 33 +++++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 3 ++ drivers/i2c/busses/i2c-designware-master.c | 22 +------------ drivers/i2c/busses/i2c-designware-platdrv.c | 20 +++++++++++ drivers/i2c/busses/i2c-designware-slave.c | 22 +------------ 8 files changed, 86 insertions(+), 43 deletions(-)
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Alexandre Belloni
maintainerRe: [PATCH 1/5] i2c: designware: factorize setting SDA hold time
In reply to Andy ShevchenkoQuoted 12 lines · Andy Shevchenko
Quoted 8 lines · Alexandre Belloni
Factorize setting the SDA hold time in a new function
i2c_dw_set_sda_hold_time()that is used for both master and slave mode.This conveniently pulls the fix for the spurious warning from commit
7a20e707aae2("i2c: designware: suppress unneeded SDA hold time warnings")
in slave mode.Isn't this a duplication of
Quoted 8 lines
commit
1080ee7e28e1cea86310739e5dd4612868768aedAuthor: Jarkko Nikula <[email protected]> Date: Tue Jun 19 14:23:22 2018 +0300i2c: designware: Move SDA hold time configuration to common code
?
Indeed, I was on 4.18-rc1, not -next.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Alexandre Belloni
maintainerRe: [PATCH 3/5] i2c: designware: add MSCC Ocelot support
In reply to Andy ShevchenkoQuoted 16 lines · Andy Shevchenko
Quoted 3 lines · Alexandre Belloni
The Microsemi Ocelot I2C controller is a designware IP. It also has a second set of registers to allow tweaking SDA hold time and spike filtering.
Can you elaborate a bit?
Are they platform specific? Are they shadow registers? Are they something else? Datasheet link / excerpt would be also good to read.
Documentation/devicetree/bindings/i2c/i2c-designware.txt Recommended properties : · line 16
Quoted 5 lines
Optional properties :
+ - reg : for "mscc,ocelot-i2c", a second register set to configure the SDA holdDocumentation/devicetree/bindings/i2c/i2c-designware.txt +2
-0+ time, named ICPU_CFG:TWI_DELAY in the datasheet. +
Quoted 5 lines
Hmm... Is this registers unique to the SoC in question? Is address of them fixed or may be configured on RTL level?
If former is right, why do we need a separate property?
Those are registers from the SoC, their position varies depending on the SoC.
Even if the position was fixed, I'm pretty sure another register set is needed. It is not a new property.
Quoted 16 lines
drivers/i2c/busses/i2c-designware-platdrv.c static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) · line 217
Quoted 13 lines
drivers/i2c/busses/i2c-designware-platdrv.c +7
-0+#define MSCC_ICPU_CFG_TWI_DELAY 0x0 +#define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) +#define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 + +static int mscc_twi_set_sda_hold_time (struct dw_i2c_dev *dev) +{ + writel((dev->sda_hold_time << 1) |
MSCC_ICPU_CFG_TWI_DELAY_ENABLE,drivers/i2c/busses/i2c-designware-platdrv.c +4
-0+ dev->base_ext + MSCC_ICPU_CFG_TWI_DELAY); + +return 0 ; +}Hmm... And does how this make native DesignWare IP's registers obsolete?
DW_IC_SDA_HOLD doesn't exist in this version of the IP. It is replaced by this SoC specific register.
Quoted 8 lines
Quoted 3 lines
(quoted diff) +1
-0+ if (of_device_is_compatible(pdev->dev.of_node, "mscc,ocelot-i2c"))
Can't you just ask for this unconditionally? Why not? (It seems I might have known why not, but can we use named resource instead in case this is not so SoC specific)
It is SoC specific.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Alexandre Belloni
maintainerQuoted 12 lines · Andy Shevchenko
Quoted 10 lines · Alexandre Belloni
Hi,
Because the designware IP was not able to the the SDA hold time, MSCC has
its own implementation. Add support for it and then add i2c on ocelot boards.I would expect patches 1 to 3 to go through the i2c tree and 4-5 through
the mips tree once patch 3 has been reviewed by the DT maintainers.
Quoted 6 lines
Without reading datasheet it all feels like a wrong place to put.
But maybe that SoC (SoC family?) has some update to DesignWare IP. Btw, what the version of DW IP it's using? 2.00a? More older, more recent?
COMP_VERSION reads 0x3131302A so it is before DW_IC_SDA_HOLD_MIN_VERS.
Quoted 23 lines
Quoted 19 lines
Alexandre Belloni (5):
i2c: designware: factorize setting SDA hold time
i2c: designware: allow IP specificsda_hold_time
i2c: designware: add MSCC Ocelot support
mips: dts: mscc: Add i2c on ocelot
mips: dts: mscc: enable i2c onocelot_pcb123.../bindings/i2c/i2c-designware.txt | 5 ++- arch/mips/boot/dts/mscc/ocelot.dtsi | 19 +++++++++++ arch/mips/boot/dts/mscc/ocelot_pcb123.dts | 5 +++ drivers/i2c/busses/i2c-designware-common.c | 33 +++++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 3 ++ drivers/i2c/busses/i2c-designware-master.c | 22 +------------ drivers/i2c/busses/i2c-designware-platdrv.c | 20 +++++++++++ drivers/i2c/busses/i2c-designware-slave.c | 22 +------------ 8 files changed, 86 insertions(+), 43 deletions(-)Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH 2/5] i2c: designware: allow IP specific sda_hold_time
In reply to Alexandre BelloniQuoted 6 lines · Alexandre Belloni
Because some old designware IPs were not supporting setting an SDA hold
time, vendors developed their own solution. Add a way for the final driver
to provide its own SDA hold time handling.
Thanks for information you provided. See my comment below. After addressing it,
Quoted 13 lines
Signed-off-by Alexandre Belloni <[email protected]>--- drivers/i2c/busses/i2c-designware-common.c | 6 ++++++ drivers/i2c/busses/i2c-designware-core.h | 1 + 2 files changed, 7 insertions(+)drivers/i2c/busses/i2c-designware-common.c +0
-0@@ -297,6 +297,12 @@ void i2c_dw_set_sda_hold_time(struct dw_i2c_dev *dev)
drivers/i2c/busses/i2c-designware-common.c void i2c_dw_set_sda_hold_time(struct dw_i2c_dev · line 307
Quoted 10 lines
drivers/i2c/busses/i2c-designware-common.c +5
-0{u32 reg; +if (dev->set_sda_hold_time) { + dev->set_sda_hold_time (dev); + +return ; + }
I would rather inject this, for now (*), into if-else-if ladder, i.e.
if (reg >= DW_IC_SDA_HOLD_MIN_VERS) {
...
} else if (dev->set_sda_hold_time) { // <<<
...
} else if (dev->sda_hold_time) {
...
(*) Since your IP is of v1.10a I don't believe any new version of IP would shadow existing DW IP registers, thus version check is okay to have first in my opinion.
Quoted 20 lines
drivers/i2c/busses/i2c-designware-common.c +1
-0+drivers/i2c/busses/i2c-designware-common.c +0
-0/* Configure SDA Hold Time if required. */ reg =dw_readl (dev,DW_IC_COMP_VERSION );if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) {drivers/i2c/busses/i2c-designware-core.h +1
-0@@ -283,6 +283,7 @@ struct dw_i2c_dev {void (*disable)(struct dw_i2c_dev *dev);void (*disable_int)(struct dw_i2c_dev *dev);int (*init)(struct dw_i2c_dev *dev); +int (*set_sda_hold_time)(struct dw_i2c_dev *dev);drivers/i2c/busses/i2c-designware-core.h +0
-0int mode;struct i2c_bus_recovery_info rinfo; };
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Andy Shevchenko
reviewerRe: [PATCH 3/5] i2c: designware: add MSCC Ocelot support
In reply to Alexandre BelloniQuoted 3 lines · Alexandre Belloni
The Microsemi Ocelot I2C controller is a designware IP. It also has a second set of registers to allow tweaking SDA hold time and spike filtering.
Thanks for information you provided. See my comments below.
drivers/i2c/busses/i2c-designware-core.h line 240
Quoted 4 lines
struct
dw_i2c_dev{drivers/i2c/busses/i2c-designware-core.h +1
-0struct device *dev;void __iomem *base; +void __iomem *base_ext;
Maybe simple "ext"? Up to you.
drivers/i2c/busses/i2c-designware-platdrv.c static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) · line 217
Quoted 12 lines
drivers/i2c/busses/i2c-designware-platdrv.c +7
-0+#define MSCC_ICPU_CFG_TWI_DELAY 0x0 +#define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) +#define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 + +static int mscc_twi_set_sda_hold_time (struct dw_i2c_dev *dev) +{ + writel((dev->sda_hold_time << 1) |
MSCC_ICPU_CFG_TWI_DELAY_ENABLE,drivers/i2c/busses/i2c-designware-platdrv.c +4
-0+ dev->base_ext + MSCC_ICPU_CFG_TWI_DELAY); + +return 0 ; +}
(1)
Review
Quoted 10 lines
(quoted diff) +1
-0+ if (of_device_is_compatible(pdev->dev.of_node, "mscc,ocelot-i2c")) {
(quoted diff) +2
-0+ mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); + dev->base_ext = devm_ioremap_resource(&pdev->dev,mem);
(quoted diff) +2
-0+ if (!IS_ERR(dev->base_ext)) + dev->set_sda_hold_time =
mscc_twi_set_sda_hold_time;(quoted diff) +1
-0+ }
(2)
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_remove(struct platform_device *pdev) · line 434
Quoted 5 lines
static const struct
of_device_iddw_i2c_of_match[] = {drivers/i2c/busses/i2c-designware-platdrv.c +1
-0{ .compatible = "snps,designware-i2c", }, + { .compatible = "mscc,ocelot-i2c", }, {}, };
(3)
I would rather place them in analogue how we do for ACPI, i.e.
--- 8< --- 8< ---
...
#define MODEL_MSCC_OCELOT 0x00000200
#define MODEL_MASK 0x00000f00
...
#ifdef CONFIG_OF
-->(1)
int dw_i2c_of_configure(pdev)
{
...
-->(2) (perhaps we don't care if it goes without condition, or move it below in the corresponding case?
...
switch(dev->flags & MODEL_MASK) {
case MODEL_MSCC_OCELOT:
...
break;
default:
break;
}
return 0;
}
-->(3)
...
{ .compatible = "mscc,ocelot-i2c", .data = (void *)MODEL_MSCC_OCELOT },
...
#else
static inline int dw_i2c_of_configure(pdev) { return -ENODEV; } #endif
...
->probe():
...
/* REPLACE THIS in dw_i2c_acpi_configure() by below in ->probe():
* id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev-
Quoted 1 line
dev);
* if (id && id->driver_data)
* dev->flags |= (u32)id->driver_data;
*/
dev->flags |= (u32)device_get_match_data(&pdev->dev);
if (&pdev->dev.of_node)
dw_i2c_of_configure(pdev);...
--- 8< --- 8< ---
What do you think?
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Andy Shevchenko
reviewerRe: [PATCH 3/5] i2c: designware: add MSCC Ocelot support
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Alexandre Belloni
The Microsemi Ocelot I2C controller is a designware IP. It also has a
second set of registers to allow tweaking SDA hold time and spike filtering.What do you think?
You can also split it to 2-3 patches, like:
- move to device_get_match_data()
- move OF device table above in the code (no func changes)
- add support for MSCC
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Rob Herring
maintainerRe: [PATCH 3/5] i2c: designware: add MSCC Ocelot support
In reply to Alexandre BelloniQuoted 17 lines · Alexandre Belloni
The Microsemi Ocelot I2C controller is a designware IP. It also has a second set of registers to allow tweaking SDA hold time and spike filtering.
Cc Rob Herring <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- .../bindings/i2c/i2c-designware.txt | 5 ++++- drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0
Documentation/devicetree/bindings/i2c/i2c-designware.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-designware.txt +1
-1@@ -2,7 +2,7 @@ Required properties : - - compatible : should be "snps,designware-i2c" + - compatible : should be "snps,designware-i2c" or "mscc,ocelot-i2c"
Sounds like the registers are optional (or could be initialized by firmware), so shouldn't 'snps,designware-i2c' be a fallback compatible?
Documentation/devicetree/bindings/i2c/i2c-designware.txt Recommended properties : · line 18
Quoted 12 lines
Documentation/devicetree/bindings/i2c/i2c-designware.txt +3
-0- reg : Offset and length of the register set for the device - interrupts : <IRQ> where IRQ is the interrupt number.@@ -11,6 +11,9 @@ Recommended properties : - clock-frequency : desired I2C bus clock frequency in Hz. Optional properties : + - reg : for "mscc,ocelot-i2c", a second register set to configure the SDA hold + time, named ICPU_CFG:TWI_DELAY in the datasheet. + - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. This option is only supported in hardware blocks version 1.11a or newer.
Perhaps this needs an update too? It sounds like Microsemi fixed this problem on their own before version 1.11a of the IP block.
Rob