i2c: mvtwsi: disable i2c slave on Armada 38x
PATCH v3 1/2 i2c: mvtwsi: disable i2c slave on Armada 38x
Equivalent code that disables the hidden i2c0 slave already exists in the Turris Omnia platform specific code. But this hidden i2c0 slave that interferes the i2c bus is not board specific. Armada 38x SoCs and at least some Kirkwood variants are affected as well. Add code to disable this slave to the i2c bus driver to make it work on all affected hardware.
Use the bind callback because we want this to always run at boot, regardless of whether U-Boot uses the i2c bus.
---
v3:
* Fix build for SUNXI (Heiko Schocher)
v2:
* Use clrbits_le32 (Stefan Roese)
* Apply to Kirkwood (Chris Packham)
* Add review tags from Stefan and Heiko
--- drivers/i2c/mvtwsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/i2c/mvtwsi.c +24 -1
@@ -11,6 +11,7 @@#include <i2c.h> #include <linux/errno.h> #include <asm/io.h> +#include <linux/bitops.h> #include <linux/compat.h> #ifdef CONFIG_DM_I2C #include <dm.h>
@@ -70,8 +71,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ };u32 xtnd_slave_addr; -u32 reserved[2 ]; +u32 reserved0[2 ];u32 soft_reset; +u32 reserved1[27 ]; +u32 debug; };#endif
@@ -795,6 +798,25 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)return 0 ; } +static void twsi_disable_i2c_slave (struct mvtwsi_registers *twsi) +{ +#if (defined(CONFIG_ARMADA_38X ) || defined(CONFIG_KIRKWOOD )) +clrbits_le32 (&twsi->debug,BIT (18 )); +#endif +} + +static int mvtwsi_i2c_bind (struct udevice *bus) +{ +struct mvtwsi_registers *twsi =devfdt_get_addr_ptr (bus); + +/* Disable the hidden slave in i2c0 of these platforms */ +if ((IS_ENABLED (CONFIG_ARMADA_38X ) ||IS_ENABLED (CONFIG_KIRKWOOD )) + && bus->req_seq ==0 ) +twsi_disable_i2c_slave (twsi); + +return 0 ; +} +static int mvtwsi_i2c_probe (struct udevice *bus) {struct mvtwsi_i2c_dev *dev =dev_get_priv (bus);
@@ -850,6 +872,7 @@ U_BOOT_DRIVER(i2c_mvtwsi) = { .name = "i2c_mvtwsi", .id = UCLASS_I2C, .of_match = mvtwsi_i2c_ids, + .bind = mvtwsi_i2c_bind, .probe = mvtwsi_i2c_probe, .ofdata_to_platdata = mvtwsi_i2c_ofdata_to_platdata, .priv_auto_alloc_size = sizeof(struct mvtwsi_i2c_dev),
Signature · 1 line
2.17.1
PATCH v3 2/2 mvebu: turris_omnia: add note about i2c slave disable
Code that disables the i2c slave is now in the mvtwsi i2c driver. Platform must enable DM_I2C to use that code. Add a comment in the code as a reminder for the planned DM_I2C migration of Turris Omnia.
---
v2: Add Reviewed-by from Heiko
--- board/CZ.NIC/turris_omnia/turris_omnia.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_omnia/turris_omnia.c +5 -1
@@ -321,7 +321,11 @@ int board_early_init_f(void)writel (OMNIA_GPP_OUT_ENA_LOW ,MVEBU_GPIO0_BASE +0x04 );writel (OMNIA_GPP_OUT_ENA_MID ,MVEBU_GPIO1_BASE +0x04 ); -/* Disable I2C debug mode blocking 0x64 I2C address */ +/* +* Disable I2C debug mode blocking 0x64 I2C address. +* Note: that would be redundant once Turris Omnia migrates to DM_I2C, +* because the mvtwsi driver includes equivalent code. +*/ i2c_debug_reg =readl (MVEBU_TWSI_BASE +MVTWSI_ARMADA_DEBUG_REG ); i2c_debug_reg &= ~(1 <<18 );writel (i2c_debug_reg,MVEBU_TWSI_BASE +MVTWSI_ARMADA_DEBUG_REG );
Signature · 1 line
2.17.1
PATCH v3 1/2 i2c: mvtwsi: disable i2c slave on Armada 38x
In reply to Baruch SiachQuoted 54 lines · Baruch Siach
Equivalent code that disables the hidden i2c0 slave already exists in the Turris Omnia platform specific code. But this hidden i2c0 slave that interferes the i2c bus is not board specific. Armada 38x SoCs and at least some Kirkwood variants are affected as well. Add code to disable this slave to the i2c bus driver to make it work on all affected hardware.
Use the bind callback because we want this to always run at boot, regardless of whether U-Boot uses the i2c bus.
Cc Rabeeh Khoury <[email protected]>Cc Chris Packham <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Heiko Schocher <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v3:
* Fix build for SUNXI (Heiko Schocher)v2:
* Useclrbits_le32(Stefan Roese)* Apply to Kirkwood (Chris Packham)
* Add review tags from Stefan and Heiko
--- drivers/i2c/mvtwsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/i2c/mvtwsi.c +4
-1@@ -11,6 +11,7 @@#include <i2c.h> #include <linux/errno.h> #include <asm/io.h> +#include <linux/bitops.h> #include <linux/compat.h> #ifdef CONFIG_DM_I2C #include <dm.h> @@ -70,8 +71,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ };u32 xtnd_slave_addr; -u32 reserved[2 ]; +u32 reserved0[2 ];u32 soft_reset; +u32 reserved1[27 ]; +u32 debug; };#endif
drivers/i2c/mvtwsi.c static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus) · line 806
Quoted 9 lines
drivers/i2c/mvtwsi.c +6
-0@@ -795,6 +798,25 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)return 0 ; } +static void twsi_disable_i2c_slave (struct mvtwsi_registers *twsi) +{ +#if (defined(CONFIG_ARMADA_38X ) || defined(CONFIG_KIRKWOOD )) +clrbits_le32 (&twsi->debug,BIT (18 )); +#endif +}
I would prefer this version:
#if (defined(CONFIG_ARMADA_38X) || defined(CONFIG_KIRKWOOD)) static void twsi_disable_i2c_slave(struct mvtwsi_registers *twsi)
{
clrbits_le32(&twsi->debug, BIT(18));
}#else
static inline void twsi_disable_i2c_slave(struct mvtwsi_registers *twsi) {
}
#endif
Thanks,
Stefan
PATCH v3 1/2 i2c: mvtwsi: disable i2c slave on Armada 38x
Hi Stefan,
Quoted 67 lines · Stefan Roese
Quoted 53 lines · Baruch Siach
Equivalent code that disables the hidden i2c0 slave already exists in the Turris Omnia platform specific code. But this hidden i2c0 slave that interferes the i2c bus is not board specific. Armada 38x SoCs and at least some Kirkwood variants are affected as well. Add code to disable this slave to the i2c bus driver to make it work on all affected hardware.
Use the bind callback because we want this to always run at boot, regardless of whether U-Boot uses the i2c bus.
Cc Rabeeh Khoury <[email protected]>Cc Chris Packham <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Heiko Schocher <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v3:
* Fix build for SUNXI (Heiko Schocher)v2:
* Useclrbits_le32(Stefan Roese)* Apply to Kirkwood (Chris Packham)
* Add review tags from Stefan and Heiko
--- drivers/i2c/mvtwsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/i2c/mvtwsi.c +4
-1@@ -11,6 +11,7 @@#include <i2c.h> #include <linux/errno.h> #include <asm/io.h> +#include <linux/bitops.h> #include <linux/compat.h> #ifdef CONFIG_DM_I2C #include <dm.h> @@ -70,8 +71,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ };u32 xtnd_slave_addr; -u32 reserved[2 ]; +u32 reserved0[2 ];u32 soft_reset; +u32 reserved1[27 ]; +u32 debug; };#endif drivers/i2c/mvtwsi.c static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus) · line 805
Quoted 8 lines
drivers/i2c/mvtwsi.c +6
-0@@ -795,6 +798,25 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)return 0 ; } +static void twsi_disable_i2c_slave (struct mvtwsi_registers *twsi) +{ +#if (defined(CONFIG_ARMADA_38X ) || defined(CONFIG_KIRKWOOD )) +clrbits_le32 (&twsi->debug,BIT (18 )); +#endif +}I would prefer this version:
#if (
defined(CONFIG_ARMADA_38X)||defined(CONFIG_KIRKWOOD)) static voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi)
Quoted 8 lines
{ clrbits_le32(&twsi->debug, BIT(18)); }#else
static inline voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi){
}
#endif
Should I drop the IS_ENABLED condition from the bind routine, then?
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -PATCH v3 1/2 i2c: mvtwsi: disable i2c slave on Armada 38x
Hi Baruch,
Quoted 79 lines · Baruch Siach
Hi Stefan,
Quoted 67 lines · Stefan Roese
Quoted 53 lines · Baruch Siach
Equivalent code that disables the hidden i2c0 slave already exists in the Turris Omnia platform specific code. But this hidden i2c0 slave that interferes the i2c bus is not board specific. Armada 38x SoCs and at least some Kirkwood variants are affected as well. Add code to disable this slave to the i2c bus driver to make it work on all affected hardware.
Use the bind callback because we want this to always run at boot, regardless of whether U-Boot uses the i2c bus.
Cc Rabeeh Khoury <[email protected]>Cc Chris Packham <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Heiko Schocher <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v3:
* Fix build for SUNXI (Heiko Schocher)v2:
* Useclrbits_le32(Stefan Roese)* Apply to Kirkwood (Chris Packham)
* Add review tags from Stefan and Heiko
--- drivers/i2c/mvtwsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/i2c/mvtwsi.c +4
-1@@ -11,6 +11,7 @@#include <i2c.h> #include <linux/errno.h> #include <asm/io.h> +#include <linux/bitops.h> #include <linux/compat.h> #ifdef CONFIG_DM_I2C #include <dm.h> @@ -70,8 +71,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ };u32 xtnd_slave_addr; -u32 reserved[2 ]; +u32 reserved0[2 ];u32 soft_reset; +u32 reserved1[27 ]; +u32 debug; };#endif drivers/i2c/mvtwsi.c static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus) · line 805
Quoted 8 lines
drivers/i2c/mvtwsi.c +6
-0@@ -795,6 +798,25 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)return 0 ; } +static void twsi_disable_i2c_slave (struct mvtwsi_registers *twsi) +{ +#if (defined(CONFIG_ARMADA_38X ) || defined(CONFIG_KIRKWOOD )) +clrbits_le32 (&twsi->debug,BIT (18 )); +#endif +}I would prefer this version:
#if (
defined(CONFIG_ARMADA_38X)||defined(CONFIG_KIRKWOOD)) static voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi)Quoted 8 lines
{ clrbits_le32(&twsi->debug, BIT(18)); }#else
static inline voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi){
}
#endif
Quoted 1 line
Should I drop the
IS_ENABLEDcondition from the bind routine, then?
Thinking a bit more about this, perhaps its better to also add this debug register to the SUNXI register struct (with a comment, that its not used - only to enable compilation without errors) and drop the #ifdef completely.
Thanks,
Stefan
PATCH v3 1/2 i2c: mvtwsi: disable i2c slave on Armada 38x
Hi Stefan,
Quoted 78 lines · Stefan Roese
Quoted 77 lines · Baruch Siach
Quoted 75 lines · Stefan Roese
Quoted 53 lines · Baruch Siach
Equivalent code that disables the hidden i2c0 slave already exists in the Turris Omnia platform specific code. But this hidden i2c0 slave that interferes the i2c bus is not board specific. Armada 38x SoCs and at least some Kirkwood variants are affected as well. Add code to disable this slave to the i2c bus driver to make it work on all affected hardware.
Use the bind callback because we want this to always run at boot, regardless of whether U-Boot uses the i2c bus.
Cc Rabeeh Khoury <[email protected]>Cc Chris Packham <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Heiko Schocher <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v3:
* Fix build for SUNXI (Heiko Schocher)v2:
* Useclrbits_le32(Stefan Roese)* Apply to Kirkwood (Chris Packham)
* Add review tags from Stefan and Heiko
--- drivers/i2c/mvtwsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/i2c/mvtwsi.c +4
-1@@ -11,6 +11,7 @@#include <i2c.h> #include <linux/errno.h> #include <asm/io.h> +#include <linux/bitops.h> #include <linux/compat.h> #ifdef CONFIG_DM_I2C #include <dm.h> @@ -70,8 +71,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ };u32 xtnd_slave_addr; -u32 reserved[2 ]; +u32 reserved0[2 ];u32 soft_reset; +u32 reserved1[27 ]; +u32 debug; };#endif drivers/i2c/mvtwsi.c static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus) · line 805
Quoted 8 lines
drivers/i2c/mvtwsi.c +6
-0@@ -795,6 +798,25 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)return 0 ; } +static void twsi_disable_i2c_slave (struct mvtwsi_registers *twsi) +{ +#if (defined(CONFIG_ARMADA_38X ) || defined(CONFIG_KIRKWOOD )) +clrbits_le32 (&twsi->debug,BIT (18 )); +#endif +}I would prefer this version:
#if (
defined(CONFIG_ARMADA_38X)||defined(CONFIG_KIRKWOOD)) static voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi){ clrbits_le32(&twsi->debug, BIT(18)); }#else
static inline voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi){
}
#endif
Quoted 6 lines
Quoted 1 line
Should I drop the
IS_ENABLEDcondition from the bind routine, then?Thinking a bit more about this, perhaps its better to also add this debug register to the SUNXI register struct (with a comment, that its not used - only to enable compilation without errors) and drop the #ifdef completely.
I don't like this idea. It creates a non-existing register definition, and makes the code harder to comprehend.
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -PATCH v3 1/2 i2c: mvtwsi: disable i2c slave on Armada 38x
Hello Baruch,
Am 07.06.2018 um 09:18 schrieb Baruch Siach:
Quoted 83 lines
Hi Stefan,
Quoted 80 lines · Stefan Roese
Quoted 78 lines · Baruch Siach
Quoted 67 lines · Stefan Roese
Quoted 53 lines · Baruch Siach
Equivalent code that disables the hidden i2c0 slave already exists in the Turris Omnia platform specific code. But this hidden i2c0 slave that interferes the i2c bus is not board specific. Armada 38x SoCs and at least some Kirkwood variants are affected as well. Add code to disable this slave to the i2c bus driver to make it work on all affected hardware.
Use the bind callback because we want this to always run at boot, regardless of whether U-Boot uses the i2c bus.
Cc Rabeeh Khoury <[email protected]>Cc Chris Packham <[email protected]>Reviewed-by Stefan Roese <[email protected]>Reviewed-by Heiko Schocher <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v3:
* Fix build for SUNXI (Heiko Schocher)v2:
* Useclrbits_le32(Stefan Roese)* Apply to Kirkwood (Chris Packham)
* Add review tags from Stefan and Heiko
--- drivers/i2c/mvtwsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/i2c/mvtwsi.c +4
-1@@ -11,6 +11,7 @@#include <i2c.h> #include <linux/errno.h> #include <asm/io.h> +#include <linux/bitops.h> #include <linux/compat.h> #ifdef CONFIG_DM_I2C #include <dm.h> @@ -70,8 +71,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ };u32 xtnd_slave_addr; -u32 reserved[2 ]; +u32 reserved0[2 ];u32 soft_reset; +u32 reserved1[27 ]; +u32 debug; };#endif drivers/i2c/mvtwsi.c static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus) · line 805
Quoted 8 lines
drivers/i2c/mvtwsi.c +6
-0@@ -795,6 +798,25 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)return 0 ; } +static void twsi_disable_i2c_slave (struct mvtwsi_registers *twsi) +{ +#if (defined(CONFIG_ARMADA_38X ) || defined(CONFIG_KIRKWOOD )) +clrbits_le32 (&twsi->debug,BIT (18 )); +#endif +}I would prefer this version:
#if (
defined(CONFIG_ARMADA_38X)||defined(CONFIG_KIRKWOOD)) static voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi)Quoted 8 lines
{ clrbits_le32(&twsi->debug, BIT(18)); }#else
static inline voidtwsi_disable_i2c_slave(struct mvtwsi_registers *twsi){
}
#endifShould I drop the
IS_ENABLEDcondition from the bind routine, then?
Quoted 7 lines
Quoted 4 lines
Thinking a bit more about this, perhaps its better to also add this debug register to the SUNXI register struct (with a comment, that its not used - only to enable compilation without errors) and drop the #ifdef completely.
I don't like this idea. It creates a non-existing register definition, and makes the code harder to comprehend.
I like Stefans idea ... we would prevent the "#if defined..." mess.
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de