Skip to contentSkip to conversation

Moving i2c_board_init to after i2c_init operations

U-Boot New Richard Retanubun 3 participants 11 messages Apr 9, 2010 – Apr 14, 2010

lore
Share & tools
lore
#0 lore raw

Hi Heiko,

I am trying to do something similar to what you did in this commit:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=commit;h=39df00d9aecfb465b9eec9af593f9b763fb5209a

and I have a question, must i2c_board_init for fsl_i2c.c be called before
the actual controller initialization? (i.e. setting the bus speed and the controller's slave address)

if we call it at the end of i2c_init, we can take advantage of the setups done before, no?

Most of the other implementation does it in the beginning because they can change the i2c pins to GPIO and 'bit-bang' the reset pattern, and then change it back to i2c pins.

The alternative is of course to assume nothing in i2c_board_init, and configure everything (I kinda liked to use set_i2c_bus_speed, rather than hardcoding something).

Since the kmeter1 board is the only user of i2c_board_init in fsl_i2c.c, would you be opposed if I submit a patch that moves the call for i2c_board_init to the end of i2c_init?

Or, can I make another 'callpoint' (e.g. i2c_reset_bus) and call that at the end?

Thanks for your time.

- Richard Retanubun

#1 lore raw

Hello Richard,

Quoted 11 lines · Richard Retanubun

I am trying to do something similar to what you did in this commit:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=commit;h=39df00d9aecfb465b9eec9af593f9b763fb5209a

and I have a question, must i2c_board_init for fsl_i2c.c be called before the actual controller initialization? (i.e. setting the bus speed and the controller's slave address)

if we call it at the end of i2c_init, we can take advantage of the setups done before, no?

Yes, you are right.

Quoted 4 lines

Most of the other implementation does it in the beginning because they can change the
i2c pins to GPIO and 'bit-bang' the reset pattern, and then change it back to i2c pins.

Yep.

Quoted 8 lines

The alternative is of course to assume nothing in i2c_board_init, and configure everything
(I kinda liked to use set_i2c_bus_speed, rather than hardcoding something).

Since the kmeter1 board is the only user of i2c_board_init in fsl_i2c.c, would you be
opposed if I submit a patch that moves the call for i2c_board_init to the end of i2c_init?

No, this is OK, and looks cleaner to me. Thanks!

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

PATCH 1/1 fsl_i2c: Move i2c_board_init to after i2c_init operations

Dear richardretanubun at ruggedcom.com,

Quoted 9 lines · In message <[email protected]> you wrote:

From 00f84e4a9a2d13971c9328fc815825456b25f760 Mon Sep 17 00:00:00 2001
From: Richard Retanubun <[email protected]>
Date: Mon, 12 Apr 2010 13:32:09 -0400
Subject: [PATCH] fsl_i2c: Move the call for i2c_init_board to the end of i2c_init

This patch moved the call to i2c_init_board to the end of i2c_init. This allows the board fixup functions to take advantage of the setups done by i2c_init (i.e. bus speed and slave address).

Quoted 6 lines

On other boards, i2c_init_board is called before i2c_init operation because the method of resetting i2c bus typically uses GPIOs to bit-bang SCLK. For i2c controllers that is using fsl_i2c this is unneccessary because there is a i2c register access sequence that accomplish the same thing, and it is better to do the accesses after the bus speed and slave address have been configured.

I dislike such inconsitent behaviour. It would be better if we could rely on a specific initialization sequence, i. e. the function always be called at the beginning or always at the end. Having to deal with a situation where one or the other might happen, even on the same hardware, depending on if we use the HW or the SW I2C driver, sounds like a nightmare to me.

If you need a late init function, then better add a new one.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Have you lived in this village all your life?"        "No, not yet."
#4 lore raw

PATCH 1/1 fsl_i2c: Move i2c_board_init to after i2c_init operations

Quoted 2 lines · Wolfgang Denk

If you need a late init function, then better add a new one.

Hi Wolfgang,

That is one of the options I put forth, what would be a name you like for this callpoint?

i2c_board_late_init ??

- Richard

#5 lore raw

PATCH 1/1 fsl_i2c: Move i2c_board_init to after i2c_init operations

Dear Richard,

Quoted 4 lines · In message <[email protected]> you wrote:

That is one of the options I put forth, what would be a name you like for this callpoint?

i2c_board_late_init ??

I think we agree that it's not exactly an elegant name, but given the fact that we already have board_late_init() it would be at least consistent.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Never underestimate the power of human stupidity  when  it  comes  to
using technology they don't understand.
#7 lore raw

PATCH 1/1 fsl_i2c: Add i2c_board_late_init

Dear richardretanubun at ruggedcom.com,

Quoted 27 lines · In message <[email protected]> you wrote:

From d0d9e0df99ce9035db43ebcf9d48601fa6f096d4 Mon Sep 17 00:00:00 2001
From: Richard Retanubun <[email protected]>
Date: Mon, 12 Apr 2010 15:08:17 -0400
Subject: [PATCH] fsl_i2c: Added a callpoint for i2c_board_late_init

This patch adds a callpoint in i2c_init that allows board specific i2c board initialization (typically for i2c bus reset) that is called after i2c_init operations, allowing the i2c_board_late_init function to use the pre-configured i2c bus speed and slave address.
---

Hi Wolfgang & Heiko,

This is the patch that adds another callpoint. Thanks for all the feedback.

- Richard

 drivers/i2c/fsl_i2c.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/i2c/fsl_i2c.c +0 -0
index 2241990..a1a62fa 100644
@@ -249,6 +249,14 @@ i2c_init(int speed, int slaveadd)
 	writeb(0x0, &dev->sr);			/* clear status register */

drivers/i2c/fsl_i2c.c i2c_init(int speed, int slaveadd) · line 259

Quoted 10 lines
drivers/i2c/fsl_i2c.c +8 -0
 	writeb(I2C_CR_MEN, &dev->cr);		/* start I2C controller */
 #endif
+
+#ifdef CONFIG_SYS_I2C_BOARD_LATE_INIT
+	/* Call board specific i2c bus reset routine after the bus has been   */
+	/* initialized. Use either this callpoint or i2c_init_board; which is */
+	/* called before i2c_init operations.                                 */
+	/* For details about this problem see doc/I2C_Edge_Conditions.        */
+	i2c_board_late_init();
+#endif

Incorrect multiline comment style.

Instead of adding more #ifdef'ery we now tend to use weak symbols - but I'm not sure about this here in this context, though. Heiko, what do you think about this?

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There's an old proverb that says just about whatever you want it to.
#8 lore raw

PATCH 1/1 fsl_i2c: Add i2c_board_late_init

Hello Wolfgang, Richard,

Quoted 34 lines · Wolfgang Denk

Dear richardretanubun at ruggedcom.com,

Quoted 31 lines · In message <[email protected]> you wrote:

From d0d9e0df99ce9035db43ebcf9d48601fa6f096d4 Mon Sep 17 00:00:00 2001
From: Richard Retanubun <[email protected]>
Date: Mon, 12 Apr 2010 15:08:17 -0400
Subject: [PATCH] fsl_i2c: Added a callpoint for i2c_board_late_init

This patch adds a callpoint in i2c_init that allows board specific i2c board initialization (typically for i2c bus reset) that is called after i2c_init operations, allowing the i2c_board_late_init function to use the pre-configured i2c bus speed and slave address.
---

Hi Wolfgang & Heiko,

This is the patch that adds another callpoint. Thanks for all the feedback.

- Richard

 drivers/i2c/fsl_i2c.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/i2c/fsl_i2c.c +2 -0
index 2241990..a1a62fa 100644
@@ -249,6 +249,14 @@ i2c_init(int speed, int slaveadd)
 	writeb(0x0, &dev->sr);			/* clear status register */
 	writeb(I2C_CR_MEN, &dev->cr);		/* start I2C controller */
 #endif
+
+#ifdef CONFIG_SYS_I2C_BOARD_LATE_INIT
Quoted 8 lines

drivers/i2c/fsl_i2c.c i2c_init(int speed, int slaveadd) · line 259

Quoted 6 lines
drivers/i2c/fsl_i2c.c +6 -0
+	/* Call board specific i2c bus reset routine after the bus has been   */
+	/* initialized. Use either this callpoint or i2c_init_board; which is */
+	/* called before i2c_init operations.                                 */
+	/* For details about this problem see doc/I2C_Edge_Conditions.        */
+	i2c_board_late_init();
+#endif

Incorrect multiline comment style.

Yep, Richard please fix this. Also it would be nice to have an entry in the README for your new callpoint.

Quoted 3 lines

Instead of adding more #ifdef'ery we now tend to use weak symbols - but I'm not sure about this here in this context, though. Heiko, what do you think about this?

I would prefer here the define version, but common uboot style is, as you said, using weak symbols ... If using here weak symbols, I vote for changing the "#ifdef CONFIG_SYS_I2C_INIT_BOARD" case also to weak.

Thanks.

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany