[U-Boot] [PATCH 0/2] i2c:soft:multi: Support for multiple soft I2C buses at TRATS

Support for multiple I2C buses handling on Samsung's TRATS development board.
Those patches add multiple I2C support at soft_i2c.c code and enables it at Trats development board.
Lukasz Majewski (2): i2c:soft:multi: Support for multiple soft I2C buses i2c:soft:multi: Enable soft I2C multibus at Trats development board
drivers/i2c/soft_i2c.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/configs/trats.h | 19 +++++++++++++------ include/i2c.h | 17 +++++++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-)

Support for multiple soft I2C buses at soft_i2c.c
This approach defines get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Up to CONFIG_SYS_MAX_I2C_BUS devices can be utilized. Common definition of I2C_X I2C buses is provided.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com --- drivers/i2c/soft_i2c.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/i2c.h | 17 +++++++++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c index 36c6114..7901f04 100644 --- a/drivers/i2c/soft_i2c.c +++ b/drivers/i2c/soft_i2c.c @@ -127,6 +127,15 @@ DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_I2C_MULTI_BUS) static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = 0; +const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS] = { + NULL, + NULL, + NULL, + NULL, + "soft_i2c_4", + "soft_i2c_5", + NULL, +}; #endif /* CONFIG_I2C_MULTI_BUS */
/*----------------------------------------------------------------------- @@ -482,3 +491,35 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) send_stop(); return(failures); } + +#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{ + switch (I2C_GET_BUS()) { + case I2C_4: + return CONFIG_SOFT_I2C_I2C4_SCL; + case I2C_5: + return CONFIG_SOFT_I2C_I2C5_SCL; + }; + + return 0; +} + +int get_multi_sda_pin(void) +{ + switch (I2C_GET_BUS()) { + case I2C_4: + return CONFIG_SOFT_I2C_I2C4_SDA; + case I2C_5: + return CONFIG_SOFT_I2C_I2C5_SDA; + }; + + return 0; +} + +int multi_i2c_init(void) +{ + return 0; +} +#endif /* CONFIG_I2C_MULTI_BUS */ diff --git a/include/i2c.h b/include/i2c.h index 1f35acf..d563d62 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -250,4 +250,21 @@ static inline void I2C_SET_BUS(unsigned int bus) i2c_set_bus_num(bus); }
+/* Multi I2C busses handling */ +#if (defined(CONFIG_SOFT_I2C) && defined(CONFIG_I2C_MULTI_BUS)) +enum { + I2C_0, + I2C_1, + I2C_2, + I2C_3, + I2C_4, + I2C_5, + I2C_6 +}; + +extern const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS]; +extern int get_multi_scl_pin(void); +extern int get_multi_sda_pin(void); +extern int multi_i2c_init(void); +#endif #endif /* _I2C_H_ */

Hello Lukasz,
On 28.08.2012 10:33, Lukasz Majewski wrote:
Support for multiple soft I2C buses at soft_i2c.c
This approach defines get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Up to CONFIG_SYS_MAX_I2C_BUS devices can be utilized. Common definition of I2C_X I2C buses is provided.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewskil.majewski@samsung.com Signed-off-by: Kyungmin Parkkyungmin.park@samsung.com
drivers/i2c/soft_i2c.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/i2c.h | 17 +++++++++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c index 36c6114..7901f04 100644 --- a/drivers/i2c/soft_i2c.c +++ b/drivers/i2c/soft_i2c.c @@ -127,6 +127,15 @@ DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_I2C_MULTI_BUS) static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = 0; +const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS] = {
- NULL,
- NULL,
- NULL,
- NULL,
- "soft_i2c_4",
- "soft_i2c_5",
- NULL,
+};
For what do you need "soft_i2c_name"? I see no usage of this in your patchset? Also why the "NULL" for 0-3 and 6 positions?
And what is, if CONFIG_SYS_MAX_I2C_BUS is < 7 ?
#endif /* CONFIG_I2C_MULTI_BUS */
/*----------------------------------------------------------------------- @@ -482,3 +491,35 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) send_stop(); return(failures); }
+#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SCL;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SCL;
- };
- return 0;
+}
+int get_multi_sda_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SDA;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SDA;
- };
- return 0;
+}
+int multi_i2c_init(void) +{
- return 0;
+} +#endif /* CONFIG_I2C_MULTI_BUS */
Again, what is with busnr = 0-3 or 6?
This is not needed in the i2c soft file. You can define this functions board specific ... so, no change in the driver is needed ... please move this to board specific code.
diff --git a/include/i2c.h b/include/i2c.h index 1f35acf..d563d62 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -250,4 +250,21 @@ static inline void I2C_SET_BUS(unsigned int bus) i2c_set_bus_num(bus); }
+/* Multi I2C busses handling */ +#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
- I2C_2,
- I2C_3,
- I2C_4,
- I2C_5,
- I2C_6
+};
+extern const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS]; +extern int get_multi_scl_pin(void); +extern int get_multi_sda_pin(void); +extern int multi_i2c_init(void); +#endif #endif /* _I2C_H_ */
bye, Heiko

Hi Heiko,
#if defined(CONFIG_I2C_MULTI_BUS) static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = 0; +const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS] = {
- NULL,
- NULL,
- NULL,
- NULL,
- "soft_i2c_4",
- "soft_i2c_5",
- NULL,
+};
For what do you need "soft_i2c_name"? I see no usage of this in your patchset? Also why the "NULL" for 0-3 and 6 positions?
And what is, if CONFIG_SYS_MAX_I2C_BUS is < 7 ?
Indeed this can be removed - it is not needed (for now).
+#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SCL;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SCL;
- };
- return 0;
+}
+int get_multi_sda_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SDA;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SDA;
- };
- return 0;
+}
+int multi_i2c_init(void) +{
- return 0;
+} +#endif /* CONFIG_I2C_MULTI_BUS */
Again, what is with busnr = 0-3 or 6?
This is not needed in the i2c soft file. You can define this functions board specific ... so, no change in the driver is needed ... please move this to board specific code.
Please consider, that get_multi_{sda|scl}_pin can be used by other boards. Those are written in a generic way (by calling I2C_GET_BUS()).
What here I'm trying to avoid is the code duplication for each board (e.g. Samsung's GONI, Universal, Trats, Origen ... etc). I can agree, that now only I2C_{4|5} are defined (since for now Samsung is using I2C_4 and I2C_5).
But other cases can be also defined.
What I see even more important is a definition of (at <i2c.h>):
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum { + I2C_0, + I2C_1, + I2C_2, + I2C_3, + I2C_4, + I2C_5, + I2C_6 +};
since this will organize the order of multiple (soft) I2C devices.
Imagine that 2 PMICs are on the board (I2C_4 and I2C_5). I need to distinct those (when calling I2C_SET|GET_BUS) And then support for another I2C device (e.g. I2C_2) at other subsystem is provided. Then I can: 1. Add common definition of I2C_X (as I've proposed) to <i2c.h> 2. Add #define I2C_X on the ./include/configs/{e.g. trats}.h board.
For second approach used I need to duplicate the code for other targets (goni, universal, origen) when needed and I cannot avoid that someone else will define other names -> like #define MINE_I2C_X on his/her ./include/configs/{board}.h

Hello Lukasz,
On 28.08.2012 12:40, Lukasz Majewski wrote:
Hi Heiko,
#if defined(CONFIG_I2C_MULTI_BUS) static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = 0; +const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS] = {
- NULL,
- NULL,
- NULL,
- NULL,
- "soft_i2c_4",
- "soft_i2c_5",
- NULL,
+};
For what do you need "soft_i2c_name"? I see no usage of this in your patchset? Also why the "NULL" for 0-3 and 6 positions?
And what is, if CONFIG_SYS_MAX_I2C_BUS is< 7 ?
Indeed this can be removed - it is not needed (for now).
Ok.
+#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SCL;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SCL;
- };
- return 0;
+}
+int get_multi_sda_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SDA;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SDA;
- };
- return 0;
+}
+int multi_i2c_init(void) +{
- return 0;
+} +#endif /* CONFIG_I2C_MULTI_BUS */
Again, what is with busnr = 0-3 or 6?
This is not needed in the i2c soft file. You can define this functions board specific ... so, no change in the driver is needed ... please move this to board specific code.
Please consider, that get_multi_{sda|scl}_pin can be used by other boards. Those are written in a generic way (by calling I2C_GET_BUS()).
Got this, but why do you index them with 4 and 5 and not with 0 and 1? What is, if another board uses 0 and 1, so this would introduce the defines CONFIG_SOFT_I2C_I2C0_SDA and CONFIG_SOFT_I2C_I2C1_SDA in the "common" get_multi_sda_pin(), which leads in compilererror for your board(s) ... your proposed get_multi_sda_pin() is currently samsung specific ...
What here I'm trying to avoid is the code duplication for each board (e.g. Samsung's GONI, Universal, Trats, Origen ... etc).
If they use all the same function, they should end in a ../samsung/common/common.c because, currently your functions are samsung specific.
common is (from my point of view) that we add in the board config file:
+#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin()
I can agree, that now only I2C_{4|5} are defined (since for now Samsung is using I2C_4 and I2C_5).
and thats samsung specific ... because other boards maybe start with I2C_0 ... and this case is not respected in your patch.
But other cases can be also defined.
Yep, and break compiling your board, as this defines are not specified.
What I see even more important is a definition of (at<i2c.h>):
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
- I2C_2,
- I2C_3,
- I2C_4,
- I2C_5,
- I2C_6
+};
since this will organize the order of multiple (soft) I2C devices.
Imagine that 2 PMICs are on the board (I2C_4 and I2C_5). I need to distinct those (when calling I2C_SET|GET_BUS) And then support for another I2C device (e.g. I2C_2) at other subsystem is provided. Then I can:
- Add common definition of I2C_X (as I've proposed) to<i2c.h>
- Add #define I2C_X on the ./include/configs/{e.g. trats}.h board.
Why add "#define I2C_X" in ./include/configs/{e.g. trats}.h ? I don´t understand this ... and you do not this in your patchserie!
For second approach used I need to duplicate the code for other targets (goni, universal, origen) when needed and I cannot avoid that someone
or make a ../samsung/common/common.c until they are samsung specific.
else will define other names -> like #define MINE_I2C_X on his/her ./include/configs/{board}.h
Ok, but if you use I2C_4 and I2C_5, you must also define the I2C_0, I2C_1, I2C_2 and I2C_3 cases in the "get_multi_*" functions, as other boards would start with I2C_0 ...
... and add a documentation in README for this ...
but I mislike to introduce such a lot of defines ... instead of defining get_multi_*() board/manufacturer/soc specific ... Maybe there is a board with 10 i2c soft busses, so we must define in all boards using soft multibus this 20 (CONFIG_SOFT_I2C_I2C*_SCL/SDA)defines ... or at least define them if not defined in include/i2c.h ... bad.
bye, Heiko

Hi Heiko,
+#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SCL;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SCL;
- };
- return 0;
+}
+int get_multi_sda_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SDA;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SDA;
- };
- return 0;
+}
+int multi_i2c_init(void) +{
- return 0;
+} +#endif /* CONFIG_I2C_MULTI_BUS */
Again, what is with busnr = 0-3 or 6?
This is not needed in the i2c soft file. You can define this functions board specific ... so, no change in the driver is needed ... please move this to board specific code.
Please consider, that get_multi_{sda|scl}_pin can be used by other boards. Those are written in a generic way (by calling I2C_GET_BUS()).
Got this, but why do you index them with 4 and 5 and not with 0 and 1? What is, if another board uses 0 and 1, so this would introduce the defines CONFIG_SOFT_I2C_I2C0_SDA and CONFIG_SOFT_I2C_I2C1_SDA in the "common" get_multi_sda_pin(), which leads in compilererror for your board(s) ... your proposed get_multi_sda_pin() is currently samsung specific ...
What here I'm trying to avoid is the code duplication for each board (e.g. Samsung's GONI, Universal, Trats, Origen ... etc).
If they use all the same function, they should end in a ../samsung/common/common.c because, currently your functions are samsung specific.
common is (from my point of view) that we add in the board config file:
+#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin()
I can agree, that now only I2C_{4|5} are defined (since for now Samsung is using I2C_4 and I2C_5).
and thats samsung specific ... because other boards maybe start with I2C_0 ... and this case is not respected in your patch.
But other cases can be also defined.
Yep, and break compiling your board, as this defines are not specified.
What I see even more important is a definition of (at<i2c.h>):
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
- I2C_2,
- I2C_3,
- I2C_4,
- I2C_5,
- I2C_6
+};
I would like to propose that, I will rename the I2C_4 -> I2C_0 and I2C_5 -> I2C_1,
then we can define at <i2c.h> :
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum { + I2C_0, + I2C_1, +};
And this would facilitate handling of SOFT_I2C numbering across relevant subsystems (e.g. PMICs and other).
since this will organize the order of multiple (soft) I2C devices.
Imagine that 2 PMICs are on the board (I2C_4 and I2C_5). I need to distinct those (when calling I2C_SET|GET_BUS) And then support for another I2C device (e.g. I2C_2) at other subsystem is provided. Then I can:
- Add common definition of I2C_X (as I've proposed) to<i2c.h>
- Add #define I2C_X on the ./include/configs/{e.g. trats}.h board.
Why add "#define I2C_X" in ./include/configs/{e.g. trats}.h ? I don´t understand this ... and you do not this in your
patchserie!
For second approach used I need to duplicate the code for other targets (goni, universal, origen) when needed and I cannot avoid that someone
or make a ../samsung/common/common.c until they are samsung specific.
else will define other names -> like #define MINE_I2C_X on his/her ./include/configs/{board}.h
Ok, but if you use I2C_4 and I2C_5, you must also define the I2C_0, I2C_1, I2C_2 and I2C_3 cases in the "get_multi_*" functions, as other boards would start with I2C_0 ...
... and add a documentation in README for this ...
but I mislike to introduce such a lot of defines ... instead of defining get_multi_*() board/manufacturer/soc specific ... Maybe there is a board with 10 i2c soft busses, so we must define in all boards using soft multibus this 20 (CONFIG_SOFT_I2C_I2C*_SCL/SDA)defines ... or at least define them if not defined in include/i2c.h ... bad.
I will move the "get_multi_*" functions to ../samsung/common/common.c
However, I think, that it would be good to add following declarations to <i2c.h>:
extern int get_multi_scl_pin(void); extern int get_multi_sda_pin(void); extern int multi_i2c_init(void);
,which can be defined on different platforms.
What is your opinion about that?

Hello Lukasz,
On 28.08.2012 14:12, Lukasz Majewski wrote:
Hi Heiko,
+#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SCL;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SCL;
- };
- return 0;
+}
+int get_multi_sda_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SDA;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SDA;
- };
- return 0;
+}
+int multi_i2c_init(void) +{
- return 0;
+} +#endif /* CONFIG_I2C_MULTI_BUS */
Again, what is with busnr = 0-3 or 6?
This is not needed in the i2c soft file. You can define this functions board specific ... so, no change in the driver is needed ... please move this to board specific code.
Please consider, that get_multi_{sda|scl}_pin can be used by other boards. Those are written in a generic way (by calling I2C_GET_BUS()).
Got this, but why do you index them with 4 and 5 and not with 0 and 1? What is, if another board uses 0 and 1, so this would introduce the defines CONFIG_SOFT_I2C_I2C0_SDA and CONFIG_SOFT_I2C_I2C1_SDA in the "common" get_multi_sda_pin(), which leads in compilererror for your board(s) ... your proposed get_multi_sda_pin() is currently samsung specific ...
What here I'm trying to avoid is the code duplication for each board (e.g. Samsung's GONI, Universal, Trats, Origen ... etc).
If they use all the same function, they should end in a ../samsung/common/common.c because, currently your functions are samsung specific.
common is (from my point of view) that we add in the board config file:
+#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin()
I can agree, that now only I2C_{4|5} are defined (since for now Samsung is using I2C_4 and I2C_5).
and thats samsung specific ... because other boards maybe start with I2C_0 ... and this case is not respected in your patch.
But other cases can be also defined.
Yep, and break compiling your board, as this defines are not specified.
What I see even more important is a definition of (at<i2c.h>):
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
- I2C_2,
- I2C_3,
- I2C_4,
- I2C_5,
- I2C_6
+};
I would like to propose that, I will rename the I2C_4 -> I2C_0 and I2C_5 -> I2C_1,
Yep!
then we can define at<i2c.h> :
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
+};
And this would facilitate handling of SOFT_I2C numbering across relevant subsystems (e.g. PMICs and other).
Ok.
since this will organize the order of multiple (soft) I2C devices.
Imagine that 2 PMICs are on the board (I2C_4 and I2C_5). I need to distinct those (when calling I2C_SET|GET_BUS) And then support for another I2C device (e.g. I2C_2) at other subsystem is provided. Then I can:
- Add common definition of I2C_X (as I've proposed) to<i2c.h>
- Add #define I2C_X on the ./include/configs/{e.g. trats}.h board.
Why add "#define I2C_X" in ./include/configs/{e.g. trats}.h ? I don´t understand this ... and you do not this in your
patchserie!
For second approach used I need to duplicate the code for other targets (goni, universal, origen) when needed and I cannot avoid that someone
or make a ../samsung/common/common.c until they are samsung
specific.
else will define other names -> like #define MINE_I2C_X on his/her ./include/configs/{board}.h
Ok, but if you use I2C_4 and I2C_5, you must also define the I2C_0, I2C_1, I2C_2 and I2C_3 cases in the "get_multi_*" functions, as other boards would start with I2C_0 ...
... and add a documentation in README for this ...
but I mislike to introduce such a lot of defines ... instead of defining get_multi_*() board/manufacturer/soc specific ... Maybe there is a board with 10 i2c soft busses, so we must define in all boards using soft multibus this 20 (CONFIG_SOFT_I2C_I2C*_SCL/SDA)defines ... or at least define them if not defined in include/i2c.h ... bad.
I will move the "get_multi_*" functions to ../samsung/common/common.c
Good.
However, I think, that it would be good to add following declarations to <i2c.h>:
extern int get_multi_scl_pin(void); extern int get_multi_sda_pin(void); extern int multi_i2c_init(void);
In the case CONFIG_I2C_MULTI_BUS is defined.
,which can be defined on different platforms.
What is your opinion about that?
I agree with this!
bye, Heiko

Hi Heiko,
Hello Lukasz,
On 28.08.2012 14:12, Lukasz Majewski wrote:
Hi Heiko,
+#if defined(CONFIG_I2C_MULTI_BUS) +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SCL;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SCL;
- };
- return 0;
+}
+int get_multi_sda_pin(void) +{
- switch (I2C_GET_BUS()) {
- case I2C_4:
return CONFIG_SOFT_I2C_I2C4_SDA;
- case I2C_5:
return CONFIG_SOFT_I2C_I2C5_SDA;
- };
- return 0;
+}
+int multi_i2c_init(void) +{
- return 0;
+} +#endif /* CONFIG_I2C_MULTI_BUS */
Again, what is with busnr = 0-3 or 6?
This is not needed in the i2c soft file. You can define this functions board specific ... so, no change in the driver is needed ... please move this to board specific code.
Please consider, that get_multi_{sda|scl}_pin can be used by other boards. Those are written in a generic way (by calling I2C_GET_BUS()).
Got this, but why do you index them with 4 and 5 and not with 0 and 1? What is, if another board uses 0 and 1, so this would introduce the defines CONFIG_SOFT_I2C_I2C0_SDA and CONFIG_SOFT_I2C_I2C1_SDA in the "common" get_multi_sda_pin(), which leads in compilererror for your board(s) ... your proposed get_multi_sda_pin() is currently samsung specific ...
What here I'm trying to avoid is the code duplication for each board (e.g. Samsung's GONI, Universal, Trats, Origen ... etc).
If they use all the same function, they should end in a ../samsung/common/common.c because, currently your functions are samsung specific.
common is (from my point of view) that we add in the board config file:
+#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin()
I can agree, that now only I2C_{4|5} are defined (since for now Samsung is using I2C_4 and I2C_5).
and thats samsung specific ... because other boards maybe start with I2C_0 ... and this case is not respected in your patch.
But other cases can be also defined.
Yep, and break compiling your board, as this defines are not specified.
What I see even more important is a definition of (at<i2c.h>):
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
- I2C_2,
- I2C_3,
- I2C_4,
- I2C_5,
- I2C_6
+};
I would like to propose that, I will rename the I2C_4 -> I2C_0 and I2C_5 -> I2C_1,
Yep!
Ok, so we have agreed.
then we can define at<i2c.h> :
+#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS)) +enum {
- I2C_0,
- I2C_1,
+};
And this would facilitate handling of SOFT_I2C numbering across relevant subsystems (e.g. PMICs and other).
Ok.
Nice,
since this will organize the order of multiple (soft) I2C devices.
Imagine that 2 PMICs are on the board (I2C_4 and I2C_5). I need to distinct those (when calling I2C_SET|GET_BUS) And then support for another I2C device (e.g. I2C_2) at other subsystem is provided. Then I can:
- Add common definition of I2C_X (as I've proposed) to<i2c.h>
- Add #define I2C_X on the ./include/configs/{e.g. trats}.h
board.
Why add "#define I2C_X" in ./include/configs/{e.g.
trats}.h ? I don´t understand this ... and you do not this in your patchserie!
For second approach used I need to duplicate the code for other targets (goni, universal, origen) when needed and I cannot avoid that someone
or make a ../samsung/common/common.c until they are samsung
specific.
else will define other names -> like #define MINE_I2C_X on his/her ./include/configs/{board}.h
Ok, but if you use I2C_4 and I2C_5, you must also define the I2C_0, I2C_1, I2C_2 and I2C_3 cases in the "get_multi_*" functions, as other boards would start with I2C_0 ...
... and add a documentation in README for this ...
but I mislike to introduce such a lot of defines ... instead of defining get_multi_*() board/manufacturer/soc specific ... Maybe there is a board with 10 i2c soft busses, so we must define in all boards using soft multibus this 20 (CONFIG_SOFT_I2C_I2C*_SCL/SDA)defines ... or at least define them if not defined in include/i2c.h ... bad.
I will move the "get_multi_*" functions to ../samsung/common/common.c
Good.
However, I think, that it would be good to add following declarations to <i2c.h>:
extern int get_multi_scl_pin(void); extern int get_multi_sda_pin(void); extern int multi_i2c_init(void);
In the case CONFIG_I2C_MULTI_BUS is defined.
,which can be defined on different platforms.
What is your opinion about that?
I agree with this!
Ok, I need this.

This commit enables multibus handling at Trats development board.
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com --- include/configs/trats.h | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/configs/trats.h b/include/configs/trats.h index c6fb2e0..bb764a5 100644 --- a/include/configs/trats.h +++ b/include/configs/trats.h @@ -235,12 +235,6 @@ #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - GENERATED_GBL_DATA_SIZE) #define CONFIG_SYS_CACHELINE_SIZE 32
-#include <asm/arch/gpio.h> -/* - * I2C Settings - */ -#define CONFIG_SOFT_I2C_GPIO_SCL exynos4_gpio_part1_get_nr(b, 7) -#define CONFIG_SOFT_I2C_GPIO_SDA exynos4_gpio_part1_get_nr(b, 6)
#define CONFIG_SOFT_I2C #define CONFIG_SOFT_I2C_READ_REPEATED_START @@ -248,6 +242,19 @@ #define CONFIG_I2C_MULTI_BUS #define CONFIG_SYS_MAX_I2C_BUS 7
+#include <asm/arch/gpio.h> + +#define CONFIG_SOFT_I2C_I2C4_SCL exynos4_gpio_part1_get_nr(b, 3) +#define CONFIG_SOFT_I2C_I2C4_SDA exynos4_gpio_part1_get_nr(b, 2) + +#define CONFIG_SOFT_I2C_I2C5_SCL exynos4_gpio_part1_get_nr(b, 7) +#define CONFIG_SOFT_I2C_I2C5_SDA exynos4_gpio_part1_get_nr(b, 6) + +#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin() +/* I2C_INIT defined to skip soft_i2c.c default one */ +#define I2C_INIT multi_i2c_init() + #define CONFIG_PMIC #define CONFIG_PMIC_I2C #define CONFIG_PMIC_MAX8997

Support for multiple I2C buses handling on Samsung's TRATS development board.
Those patches add multiple I2C support for Samsung boards and enables it at Trats.
Lukasz Majewski (2): i2c:soft:multi: Support for multiple soft I2C buses at Samsung boards i2c:soft:multi: Enable soft I2C multibus at Trats development board
board/samsung/common/Makefile | 43 +++++++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 55 ++++++++++++++++++++++++++++++++++++++ include/configs/trats.h | 19 +++++++++---- include/i2c.h | 11 +++++++ 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c

Support for multiple soft I2C buses.
The goal is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_{0|1} I2C buses is provided at <i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Heiko Schocher hs@denx.de Cc: Minkyu Kang mk7.kang@samsung.com
--- Changes for v2: - Common Samsung code has been put to board/samsung/common/multi_i2c.c file - I2C_{4|5} have been renamed to I2C_{0|1} - *soft_i2c_name[] table has been removed --- board/samsung/common/Makefile | 43 +++++++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 55 ++++++++++++++++++++++++++++++++++++++ include/i2c.h | 11 +++++++ 3 files changed, 109 insertions(+), 0 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c
diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile new file mode 100644 index 0000000..0bcd594 --- /dev/null +++ b/board/samsung/common/Makefile @@ -0,0 +1,43 @@ +# +# Copyright (C) 2012 Samsung Electronics +# Lukasz Majewski l.majewski@samsung.com +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)libsamsung.o + +COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o + +SRCS := $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS-y)) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/board/samsung/common/multi_i2c.c b/board/samsung/common/multi_i2c.c new file mode 100644 index 0000000..d8d59fb --- /dev/null +++ b/board/samsung/common/multi_i2c.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Lukasz Majewski l.majewski@samsung.com + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <i2c.h> + +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{ + switch (I2C_GET_BUS()) { + case I2C_0: + return CONFIG_SOFT_I2C_I2C0_SCL; + case I2C_1: + return CONFIG_SOFT_I2C_I2C1_SCL; + }; + + return 0; +} + +int get_multi_sda_pin(void) +{ + switch (I2C_GET_BUS()) { + case I2C_0: + return CONFIG_SOFT_I2C_I2C0_SDA; + case I2C_1: + return CONFIG_SOFT_I2C_I2C1_SDA; + }; + + return 0; +} + +int multi_i2c_init(void) +{ + return 0; +} diff --git a/include/i2c.h b/include/i2c.h index 1f35acf..00a3933 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -250,4 +250,15 @@ static inline void I2C_SET_BUS(unsigned int bus) i2c_set_bus_num(bus); }
+/* Multi I2C busses handling */ +#ifdef CONFIG_SOFT_I2C_MULTI_BUS +enum { + I2C_0, + I2C_1, +}; + +extern int get_multi_scl_pin(void); +extern int get_multi_sda_pin(void); +extern int multi_i2c_init(void); +#endif #endif /* _I2C_H_ */

This commit enables multibus handling at Samsung's Trats development board.
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Minkyu Kang mk7.kang@samsung.com
--- Changes for v2: - CONFIG_SOFT_I2C_MULTI_BUS flag added to Trats configuration --- include/configs/trats.h | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/configs/trats.h b/include/configs/trats.h index c6fb2e0..16df4cc 100644 --- a/include/configs/trats.h +++ b/include/configs/trats.h @@ -235,19 +235,26 @@ #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - GENERATED_GBL_DATA_SIZE) #define CONFIG_SYS_CACHELINE_SIZE 32
-#include <asm/arch/gpio.h> -/* - * I2C Settings - */ -#define CONFIG_SOFT_I2C_GPIO_SCL exynos4_gpio_part1_get_nr(b, 7) -#define CONFIG_SOFT_I2C_GPIO_SDA exynos4_gpio_part1_get_nr(b, 6)
#define CONFIG_SOFT_I2C #define CONFIG_SOFT_I2C_READ_REPEATED_START #define CONFIG_SYS_I2C_SPEED 50000 #define CONFIG_I2C_MULTI_BUS +#define CONFIG_SOFT_I2C_MULTI_BUS #define CONFIG_SYS_MAX_I2C_BUS 7
+#include <asm/arch/gpio.h> + +#define CONFIG_SOFT_I2C_I2C0_SCL exynos4_gpio_part1_get_nr(b, 7) +#define CONFIG_SOFT_I2C_I2C0_SDA exynos4_gpio_part1_get_nr(b, 6) + +#define CONFIG_SOFT_I2C_I2C1_SCL exynos4_gpio_part1_get_nr(b, 3) +#define CONFIG_SOFT_I2C_I2C1_SDA exynos4_gpio_part1_get_nr(b, 2) + +#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin() +#define I2C_INIT multi_i2c_init() + #define CONFIG_PMIC #define CONFIG_PMIC_I2C #define CONFIG_PMIC_MAX8997

Support for multiple I2C buses handling on Samsung's TRATS development board.
Those patches add multiple I2C support for Samsung boards and enables it at Trats.
Lukasz Majewski (2): i2c:soft:multi: Support for multiple soft I2C buses at Samsung boards i2c:soft:multi: Enable soft I2C multibus at Trats development board
board/samsung/common/Makefile | 43 +++++++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 55 ++++++++++++++++++++++++++++++++++++++ include/configs/trats.h | 21 ++++++++++---- include/i2c.h | 11 +++++++ 4 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c

Support for multiple soft I2C buses.
The goal is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_{0|1} I2C buses is provided at <i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Heiko Schocher hs@denx.de Cc: Minkyu Kang mk7.kang@samsung.com
--- Changes for v2: - Common Samsung code has been put to board/samsung/common/multi_i2c.c file - I2C_{4|5} have been renamed to I2C_{0|1} - *soft_i2c_name[] table has been removed Changes for v3: - None
--- board/samsung/common/Makefile | 43 +++++++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 55 ++++++++++++++++++++++++++++++++++++++ include/i2c.h | 11 +++++++ 3 files changed, 109 insertions(+), 0 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c
diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile new file mode 100644 index 0000000..0bcd594 --- /dev/null +++ b/board/samsung/common/Makefile @@ -0,0 +1,43 @@ +# +# Copyright (C) 2012 Samsung Electronics +# Lukasz Majewski l.majewski@samsung.com +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)libsamsung.o + +COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o + +SRCS := $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS-y)) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/board/samsung/common/multi_i2c.c b/board/samsung/common/multi_i2c.c new file mode 100644 index 0000000..d8d59fb --- /dev/null +++ b/board/samsung/common/multi_i2c.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Lukasz Majewski l.majewski@samsung.com + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <i2c.h> + +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{ + switch (I2C_GET_BUS()) { + case I2C_0: + return CONFIG_SOFT_I2C_I2C0_SCL; + case I2C_1: + return CONFIG_SOFT_I2C_I2C1_SCL; + }; + + return 0; +} + +int get_multi_sda_pin(void) +{ + switch (I2C_GET_BUS()) { + case I2C_0: + return CONFIG_SOFT_I2C_I2C0_SDA; + case I2C_1: + return CONFIG_SOFT_I2C_I2C1_SDA; + }; + + return 0; +} + +int multi_i2c_init(void) +{ + return 0; +} diff --git a/include/i2c.h b/include/i2c.h index 1f35acf..00a3933 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -250,4 +250,15 @@ static inline void I2C_SET_BUS(unsigned int bus) i2c_set_bus_num(bus); }
+/* Multi I2C busses handling */ +#ifdef CONFIG_SOFT_I2C_MULTI_BUS +enum { + I2C_0, + I2C_1, +}; + +extern int get_multi_scl_pin(void); +extern int get_multi_sda_pin(void); +extern int multi_i2c_init(void); +#endif #endif /* _I2C_H_ */

Hi Heiko,
Common definition of I2C_{0|1} I2C buses is provided at <i2c.h>.
+/* Multi I2C busses handling */ +#ifdef CONFIG_SOFT_I2C_MULTI_BUS +enum {
- I2C_0,
- I2C_1,
+};
I've got a second thought about this numbering. In the case of Trats:
I2C_0 in reality is I2C_5 (this from schematic/chip numbergin) and I2C_1 is I2C_9.
This numbering (I2C_5 and I2C_9) was proposed for v2 of this patch.
I will prepare v4 of this patch with a palatable I2C numbering solution.

This commit enables multibus handling at Samsung's Trats development board.
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Minkyu Kang mk7.kang@samsung.com
--- Changes for v2: - CONFIG_SOFT_I2C_MULTI_BUS flag added to Trats configuration
Changes for v3: - correct definition of TRATS I2C_1 pins --- include/configs/trats.h | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/include/configs/trats.h b/include/configs/trats.h index c6fb2e0..d1080d5 100644 --- a/include/configs/trats.h +++ b/include/configs/trats.h @@ -235,19 +235,28 @@ #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - GENERATED_GBL_DATA_SIZE) #define CONFIG_SYS_CACHELINE_SIZE 32
-#include <asm/arch/gpio.h> -/* - * I2C Settings - */ -#define CONFIG_SOFT_I2C_GPIO_SCL exynos4_gpio_part1_get_nr(b, 7) -#define CONFIG_SOFT_I2C_GPIO_SDA exynos4_gpio_part1_get_nr(b, 6)
#define CONFIG_SOFT_I2C #define CONFIG_SOFT_I2C_READ_REPEATED_START #define CONFIG_SYS_I2C_SPEED 50000 #define CONFIG_I2C_MULTI_BUS +#define CONFIG_SOFT_I2C_MULTI_BUS #define CONFIG_SYS_MAX_I2C_BUS 7
+#include <asm/arch/gpio.h> + +/* I2C PMIC */ +#define CONFIG_SOFT_I2C_I2C0_SCL exynos4_gpio_part1_get_nr(b, 7) +#define CONFIG_SOFT_I2C_I2C0_SDA exynos4_gpio_part1_get_nr(b, 6) + +/* I2C FG */ +#define CONFIG_SOFT_I2C_I2C1_SCL exynos4_gpio_part2_get_nr(y4, 1) +#define CONFIG_SOFT_I2C_I2C1_SDA exynos4_gpio_part2_get_nr(y4, 0) + +#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin() +#define I2C_INIT multi_i2c_init() + #define CONFIG_PMIC #define CONFIG_PMIC_I2C #define CONFIG_PMIC_MAX8997

Those patches add multiple I2C support for Samsung boards and enables it on Trats.
Lukasz Majewski (2): i2c:soft:multi: Support for multiple soft I2C buses at Samsung boards i2c:soft:multi: Enable soft I2C multibus at Trats development board
board/samsung/common/Makefile | 43 +++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 65 ++++++++++++++++++++++++++++++++++++++ board/samsung/trats/trats.c | 15 +++++++++ include/configs/trats.h | 24 ++++++++++---- include/i2c.h | 12 +++++++ 5 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c

Support for multiple soft I2C buses.
Multibus I2C support is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_X I2C buses is provided at <i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Heiko Schocher hs@denx.de Cc: Minkyu Kang mk7.kang@samsung.com
--- Changes for v2: - Common Samsung code has been put to board/samsung/common/multi_i2c.c file - I2C_{4|5} have been renamed to I2C_{0|1} - *soft_i2c_name[] table has been removed Changes for v3: - None Changes for v4: - Common definitions of available I2C buses are now defined at <i2c.h> - Compatibility layer (I2C_0) has been added temporarily to not break the Trats I2C communication with PMIC. It will be removed when redesigned PMIC will be posted --- board/samsung/common/Makefile | 43 +++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 65 ++++++++++++++++++++++++++++++++++++++ include/i2c.h | 12 +++++++ 3 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c
diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile new file mode 100644 index 0000000..0bcd594 --- /dev/null +++ b/board/samsung/common/Makefile @@ -0,0 +1,43 @@ +# +# Copyright (C) 2012 Samsung Electronics +# Lukasz Majewski l.majewski@samsung.com +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)libsamsung.o + +COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o + +SRCS := $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS-y)) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/board/samsung/common/multi_i2c.c b/board/samsung/common/multi_i2c.c new file mode 100644 index 0000000..d6c3d37 --- /dev/null +++ b/board/samsung/common/multi_i2c.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Lukasz Majewski l.majewski@samsung.com + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <i2c.h> + +/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{ + unsigned int bus = I2C_GET_BUS(); + + switch (bus) { + case I2C_0: /* I2C_0 definition - compatibility layer */ + case I2C_5: + return CONFIG_SOFT_I2C_I2C5_SCL; + case I2C_9: + return CONFIG_SOFT_I2C_I2C9_SCL; + default: + printf("I2C_%d not supported!\n", bus); + }; + + return 0; +} + +int get_multi_sda_pin(void) +{ + unsigned int bus = I2C_GET_BUS(); + + switch (bus) { + case I2C_0: /* I2C_0 definition - compatibility layer */ + case I2C_5: + return CONFIG_SOFT_I2C_I2C5_SDA; + case I2C_9: + return CONFIG_SOFT_I2C_I2C9_SDA; + default: + printf("I2C_%d not supported!\n", bus); + }; + + return 0; +} + +int multi_i2c_init(void) +{ + return 0; +} diff --git a/include/i2c.h b/include/i2c.h index 1f35acf..16f099d 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -250,4 +250,16 @@ static inline void I2C_SET_BUS(unsigned int bus) i2c_set_bus_num(bus); }
+/* Multi I2C definitions */ +enum { + I2C_0, I2C_1, I2C_2, I2C_3, I2C_4, I2C_5, I2C_6, I2C_7, + I2C_8, I2C_9, I2C_10, +}; + +/* Multi I2C busses handling */ +#ifdef CONFIG_SOFT_I2C_MULTI_BUS +extern int get_multi_scl_pin(void); +extern int get_multi_sda_pin(void); +extern int multi_i2c_init(void); +#endif #endif /* _I2C_H_ */

Hello Lukasz,
On 05.09.2012 11:15, Lukasz Majewski wrote:
Support for multiple soft I2C buses.
Multibus I2C support is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_X I2C buses is provided at<i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewskil.majewski@samsung.com Signed-off-by: Kyungmin Parkkyungmin.park@samsung.com Cc: Heiko Schocherhs@denx.de Cc: Minkyu Kangmk7.kang@samsung.com
Changes for v2:
- Common Samsung code has been put to board/samsung/common/multi_i2c.c file
- I2C_{4|5} have been renamed to I2C_{0|1}
- *soft_i2c_name[] table has been removed
Changes for v3:
- None
Changes for v4:
- Common definitions of available I2C buses are now defined at<i2c.h>
- Compatibility layer (I2C_0) has been added temporarily to not break the Trats I2C communication with PMIC. It will be removed when redesigned PMIC will be posted
board/samsung/common/Makefile | 43 +++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 65 ++++++++++++++++++++++++++++++++++++++ include/i2c.h | 12 +++++++ 3 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c
[...]
+######################################################################### diff --git a/board/samsung/common/multi_i2c.c b/board/samsung/common/multi_i2c.c new file mode 100644 index 0000000..d6c3d37 --- /dev/null +++ b/board/samsung/common/multi_i2c.c @@ -0,0 +1,65 @@
[...]
+/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- unsigned int bus = I2C_GET_BUS();
- switch (bus) {
- case I2C_0: /* I2C_0 definition - compatibility layer */
- case I2C_5:
Is this correct, that you want to use 2 i2c busses on the same pin?
Beside of that, you get my:
Acked-by: Heiko Schocher hs@denx.de
bye, Heiko

Hi Heiko,
Thanks for comments.
Hello Lukasz,
On 05.09.2012 11:15, Lukasz Majewski wrote:
Support for multiple soft I2C buses.
Multibus I2C support is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_X I2C buses is provided at<i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewskil.majewski@samsung.com Signed-off-by: Kyungmin Parkkyungmin.park@samsung.com Cc: Heiko Schocherhs@denx.de Cc: Minkyu Kangmk7.kang@samsung.com
Changes for v2:
- Common Samsung code has been put to
board/samsung/common/multi_i2c.c file
- I2C_{4|5} have been renamed to I2C_{0|1}
- *soft_i2c_name[] table has been removed
Changes for v3:
- None
Changes for v4:
- Common definitions of available I2C buses are now defined
at<i2c.h>
- Compatibility layer (I2C_0) has been added temporarily to not
break the Trats I2C communication with PMIC. It will be removed when redesigned PMIC will be posted
board/samsung/common/Makefile | 43 +++++++++++++++++++++++++ board/samsung/common/multi_i2c.c | 65 ++++++++++++++++++++++++++++++++++++++ include/i2c.h | 12 +++++++ 3 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 board/samsung/common/Makefile create mode 100644 board/samsung/common/multi_i2c.c
[...]
+######################################################################### diff --git a/board/samsung/common/multi_i2c.c b/board/samsung/common/multi_i2c.c new file mode 100644 index 0000000..d6c3d37 --- /dev/null +++ b/board/samsung/common/multi_i2c.c @@ -0,0 +1,65 @@
[...]
+/* Handle multiple I2C buses instances */ +int get_multi_scl_pin(void) +{
- unsigned int bus = I2C_GET_BUS();
- switch (bus) {
- case I2C_0: /* I2C_0 definition - compatibility layer */
- case I2C_5:
Is this correct, that you want to use 2 i2c busses on the same pin?
Yes, this is correct.
Let me share with you the "master" plan for this. The I2C_0 is needed to keep the TRATS working with current PMIC implementation.
I'm working on redesign of current PMIC implementation to support other devices responsible for power management (e.g. fuel gauge, charger, PMIC), which in case of TRATS are connected via multiple I2C buses (I2C_5 and I2C_9).
The I2C_0 case is for preserving correct operation of TRATS board until PMIC 2.0 wont be introduced to u-boot mailing list.
It will be removed just after PMIC 2.0 acceptance.
I hope, that I've expressed my intentions clearly.
Beside of that, you get my:
Acked-by: Heiko Schocher hs@denx.de
bye, Heiko

Hi Minkyu,
Support for multiple soft I2C buses.
Multibus I2C support is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_X I2C buses is provided at <i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Heiko Schocher hs@denx.de Cc: Minkyu Kang mk7.kang@samsung.com
Changes for v2:
- Common Samsung code has been put to
board/samsung/common/multi_i2c.c file
- I2C_{4|5} have been renamed to I2C_{0|1}
- *soft_i2c_name[] table has been removed
Changes for v3:
- None
Changes for v4:
- Common definitions of available I2C buses are now defined at <i2c.h>
- Compatibility layer (I2C_0) has been added temporarily to not break
the Trats I2C communication with PMIC. It will be removed when redesigned PMIC will be posted
Can you evaluate those patches.
Those were acked-by Heiko already.

Dear Lukasz,
On 12 September 2012 16:06, Lukasz Majewski l.majewski@samsung.com wrote:
Hi Minkyu,
Support for multiple soft I2C buses.
Multibus I2C support is achieved by defining get_multi_{sda|scl}_pin functions to switch between multiple "soft" I2C buses.
Common definition of I2C_X I2C buses is provided at <i2c.h>.
TEST HW: Samsung's Exynos4210 evt.0.1 - Trats development board
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Heiko Schocher hs@denx.de Cc: Minkyu Kang mk7.kang@samsung.com
Changes for v2:
- Common Samsung code has been put to
board/samsung/common/multi_i2c.c file
- I2C_{4|5} have been renamed to I2C_{0|1}
- *soft_i2c_name[] table has been removed
Changes for v3:
- None
Changes for v4:
- Common definitions of available I2C buses are now defined at <i2c.h>
- Compatibility layer (I2C_0) has been added temporarily to not break
the Trats I2C communication with PMIC. It will be removed when redesigned PMIC will be posted
Can you evaluate those patches.
Those were acked-by Heiko already.
OK. please wait few days. I will check pending patches soon.
Thanks. Minkyu Kang.

This commit enables multibus handling at Samsung's Trats development board.
Signed-off-by: Lukasz Majewski l.majewski@samsung.com Signed-off-by: Kyungmin Park kyungmin.park@samsung.com Cc: Minkyu Kang mk7.kang@samsung.com
--- Changes for v2: - CONFIG_SOFT_I2C_MULTI_BUS flag added to Trats configuration
Changes for v3: - correct definition of TRATS I2C_1 pins
Changes for v4: - Assign I2C numbers reflecting the HW structure of Trats board - Change the max I2C numbers to 15 from 7 - i2c_init_board() function defined for trats board --- board/samsung/trats/trats.c | 15 +++++++++++++++ include/configs/trats.h | 24 +++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c index 4f9cb5a..e11a892 100644 --- a/board/samsung/trats/trats.c +++ b/board/samsung/trats/trats.c @@ -75,6 +75,21 @@ int board_init(void) return 0; }
+void i2c_init_board(void) +{ + struct exynos4_gpio_part1 *gpio1 = + (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1(); + struct exynos4_gpio_part2 *gpio2 = + (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2(); + + /* I2C_5 -> PMIC */ + s5p_gpio_direction_output(&gpio1->b, 7, 1); + s5p_gpio_direction_output(&gpio1->b, 6, 1); + /* I2C_9 -> FG */ + s5p_gpio_direction_output(&gpio2->y4, 0, 1); + s5p_gpio_direction_output(&gpio2->y4, 1, 1); +} + int dram_init(void) { gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) + diff --git a/include/configs/trats.h b/include/configs/trats.h index c6fb2e0..866c047 100644 --- a/include/configs/trats.h +++ b/include/configs/trats.h @@ -235,18 +235,28 @@ #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_LOAD_ADDR - GENERATED_GBL_DATA_SIZE) #define CONFIG_SYS_CACHELINE_SIZE 32
-#include <asm/arch/gpio.h> -/* - * I2C Settings - */ -#define CONFIG_SOFT_I2C_GPIO_SCL exynos4_gpio_part1_get_nr(b, 7) -#define CONFIG_SOFT_I2C_GPIO_SDA exynos4_gpio_part1_get_nr(b, 6)
#define CONFIG_SOFT_I2C #define CONFIG_SOFT_I2C_READ_REPEATED_START +#define CONFIG_SYS_I2C_INIT_BOARD #define CONFIG_SYS_I2C_SPEED 50000 #define CONFIG_I2C_MULTI_BUS -#define CONFIG_SYS_MAX_I2C_BUS 7 +#define CONFIG_SOFT_I2C_MULTI_BUS +#define CONFIG_SYS_MAX_I2C_BUS 15 + +#include <asm/arch/gpio.h> + +/* I2C PMIC */ +#define CONFIG_SOFT_I2C_I2C5_SCL exynos4_gpio_part1_get_nr(b, 7) +#define CONFIG_SOFT_I2C_I2C5_SDA exynos4_gpio_part1_get_nr(b, 6) + +/* I2C FG */ +#define CONFIG_SOFT_I2C_I2C9_SCL exynos4_gpio_part2_get_nr(y4, 1) +#define CONFIG_SOFT_I2C_I2C9_SDA exynos4_gpio_part2_get_nr(y4, 0) + +#define CONFIG_SOFT_I2C_GPIO_SCL get_multi_scl_pin() +#define CONFIG_SOFT_I2C_GPIO_SDA get_multi_sda_pin() +#define I2C_INIT multi_i2c_init()
#define CONFIG_PMIC #define CONFIG_PMIC_I2C

Hello Lukasz,
On 05.09.2012 11:15, Lukasz Majewski wrote:
This commit enables multibus handling at Samsung's Trats development board.
Signed-off-by: Lukasz Majewskil.majewski@samsung.com Signed-off-by: Kyungmin Parkkyungmin.park@samsung.com Cc: Minkyu Kangmk7.kang@samsung.com
Changes for v2:
- CONFIG_SOFT_I2C_MULTI_BUS flag added to Trats configuration
Changes for v3:
- correct definition of TRATS I2C_1 pins
Changes for v4:
- Assign I2C numbers reflecting the HW structure of Trats board
- Change the max I2C numbers to 15 from 7
- i2c_init_board() function defined for trats board
board/samsung/trats/trats.c | 15 +++++++++++++++ include/configs/trats.h | 24 +++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-)
Acked-by: Heiko Schocher hs@denx.de
bye, Heiko
participants (3)
-
Heiko Schocher
-
Lukasz Majewski
-
Minkyu Kang