Skip to contentSkip to conversation

i2c, core: optimze i2c_set_bus_num()

PATCH New Heiko Schocher 2 participants 5 messages Oct 4, 2013 – Oct 17, 2013 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c, core: optimze i2c_set_bus_num()

check first, if we are on the bus, we want to enable. If so, return immediately, do not calc max adapter number, nor check other things.

---
 drivers/i2c/i2c_core.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/i2c/i2c_core.c +10 -8
index d1072e8..170423a 100644
@@ -278,20 +278,22 @@ unsigned int i2c_get_bus_num(void)
  */
 int i2c_set_bus_num(unsigned int bus)
 {
-	int max = ll_entry_count(struct i2c_adapter, i2c);
+	int max;
+
+	if ((bus == I2C_BUS) && (I2C_ADAP->init_done > 0))
+		return 0;
 
-	if (I2C_ADAPTER(bus) >= max) {
-		printf("Error, wrong i2c adapter %d max %d possible\n",
-		       I2C_ADAPTER(bus), max);
-		return -2;
-	}
 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
 	if (bus >= CONFIG_SYS_NUM_I2C_BUSES)
 		return -1;
 #endif
 
-	if ((bus == I2C_BUS) && (I2C_ADAP->init_done > 0))
-		return 0;
+	max = ll_entry_count(struct i2c_adapter, i2c);
+	if (I2C_ADAPTER(bus) >= max) {
+		printf("Error, wrong i2c adapter %d max %d possible\n",
+		       I2C_ADAPTER(bus), max);
+		return -2;
+	}
 
 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
 	i2c_mux_disconnet_all();
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 i2c, core: optimze i2c_set_bus_num()

Hi Heiko,

Quoted 31 lines

check first, if we are on the bus, we want to enable. If so, return immediately, do not calc max adapter number, nor check other things.

---
 drivers/i2c/i2c_core.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/i2c/i2c_core.c +4 -6
index d1072e8..170423a 100644
@@ -278,20 +278,22 @@ unsigned int i2c_get_bus_num(void)
  */
 int i2c_set_bus_num(unsigned int bus)
 {
-	int max = ll_entry_count(struct i2c_adapter, i2c);
+	int max;
+
+	if ((bus == I2C_BUS) && (I2C_ADAP->init_done > 0))
+		return 0;
 
-	if (I2C_ADAPTER(bus) >= max) {
-		printf("Error, wrong i2c adapter %d max %d
 possible\n",
-		       I2C_ADAPTER(bus), max);
-		return -2;
-	}
 #ifndef CONFIG_SYS_I2C_DIRECT_BUS

drivers/i2c/i2c_core.c unsigned int i2c_get_bus_num(void) · line 295

Quoted 10 lines
drivers/i2c/i2c_core.c +3 -2
 	if (bus >= CONFIG_SYS_NUM_I2C_BUSES)
 		return -1;
 #endif
 
-	if ((bus == I2C_BUS) && (I2C_ADAP->init_done > 0))
-		return 0;
+	max = ll_entry_count(struct i2c_adapter, i2c);
+	if (I2C_ADAPTER(bus) >= max) {
+		printf("Error, wrong i2c adapter %d max %d
 possible\n",

Since you are the maintainer of the i2c code, you will decide if those changes shall be applied (they are really cosmetic) :-).

My suggestion: printf -> error() macro @ common.h

drivers/i2c/i2c_core.c unsigned int i2c_get_bus_num(void) · line 295

Quoted 2 lines
drivers/i2c/i2c_core.c +2 -0
+		       I2C_ADAPTER(bus), max);
+		return -2;

I've noticed that i2c_core uses -1/-2 return values for errors globaly.

So for a new code we could start using defines from errno.h (-2 -> -ENODEV) ?

Quoted 4 lines
drivers/i2c/i2c_core.c +1 -0
+	}
 

#ifndef CONFIG_SYS_I2C_DIRECT_BUS
i2c_mux_disconnet_all();

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#2 lore raw

PATCH 1/1 i2c, core: optimze i2c_set_bus_num()

Hello Lukasz,

Am 04.10.2013 10:42, schrieb Lukasz Majewski:

Quoted 37 lines

Hi Heiko,

Quoted 35 lines

check first, if we are on the bus, we want to enable. If so, return immediately, do not calc max adapter number, nor check other things.

---
  drivers/i2c/i2c_core.c | 18 ++++++++++--------
  1 file changed, 10 insertions(+), 8 deletions(-)
drivers/i2c/i2c_core.c +4 -6
index d1072e8..170423a 100644
@@ -278,20 +278,22 @@ unsigned int i2c_get_bus_num(void)
   */
  int i2c_set_bus_num(unsigned int bus)
  {
-	int max = ll_entry_count(struct i2c_adapter, i2c);
+	int max;
+
+	if ((bus == I2C_BUS)&&  (I2C_ADAP->init_done>  0))
+		return 0;
 
-	if (I2C_ADAPTER(bus)>= max) {
-		printf("Error, wrong i2c adapter %d max %d
 possible\n",
-		       I2C_ADAPTER(bus), max);
-		return -2;
-	}
  #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  	if (bus>= CONFIG_SYS_NUM_I2C_BUSES)
  		return -1;
  #endif
 
Quoted 9 lines

drivers/i2c/i2c_core.c unsigned int i2c_get_bus_num(void) · line 295

Quoted 6 lines
drivers/i2c/i2c_core.c +3 -2
-	if ((bus == I2C_BUS)&&  (I2C_ADAP->init_done>  0))
-		return 0;
+	max = ll_entry_count(struct i2c_adapter, i2c);
+	if (I2C_ADAPTER(bus)>= max) {
+		printf("Error, wrong i2c adapter %d max %d
 possible\n",

Since you are the maintainer of the i2c code, you will decide if those changes shall be applied (they are really cosmetic) :-).

Exactly for this reason a "Acked-by" would not disturb me ;-)

Quoted 1 line

My suggestion: printf -> error() macro @ common.h

Yep ... but this should be a seperate patch.

Quoted 8 lines

drivers/i2c/i2c_core.c unsigned int i2c_get_bus_num(void) · line 295

Quoted 2 lines
drivers/i2c/i2c_core.c +2 -0
+		       I2C_ADAPTER(bus), max);
+		return -2;

I've noticed that i2c_core uses -1/-2 return values for errors globaly.

So for a new code we could start using defines from errno.h (-2 -> -ENODEV) ?

Yes, good point!

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 i2c, core: optimze i2c_set_bus_num()

Hi Heiko,

Quoted 50 lines

Hello Lukasz,

Am 04.10.2013 10:42, schrieb Lukasz Majewski:

Quoted 37 lines

Hi Heiko,

Quoted 35 lines

check first, if we are on the bus, we want to enable. If so, return immediately, do not calc max adapter number, nor check other things.

---
  drivers/i2c/i2c_core.c | 18 ++++++++++--------
  1 file changed, 10 insertions(+), 8 deletions(-)
drivers/i2c/i2c_core.c +4 -6
index d1072e8..170423a 100644
@@ -278,20 +278,22 @@ unsigned int i2c_get_bus_num(void)
   */
  int i2c_set_bus_num(unsigned int bus)
  {
-	int max = ll_entry_count(struct i2c_adapter, i2c);
+	int max;
+
+	if ((bus == I2C_BUS)&&  (I2C_ADAP->init_done>  0))
+		return 0;
 
-	if (I2C_ADAPTER(bus)>= max) {
-		printf("Error, wrong i2c adapter %d max %d
 possible\n",
-		       I2C_ADAPTER(bus), max);
-		return -2;
-	}
  #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  	if (bus>= CONFIG_SYS_NUM_I2C_BUSES)
  		return -1;
  #endif
 
Quoted 9 lines

drivers/i2c/i2c_core.c unsigned int i2c_get_bus_num(void) · line 295

Quoted 6 lines
drivers/i2c/i2c_core.c +3 -2
-	if ((bus == I2C_BUS)&&  (I2C_ADAP->init_done>  0))
-		return 0;
+	max = ll_entry_count(struct i2c_adapter, i2c);
+	if (I2C_ADAPTER(bus)>= max) {
+		printf("Error, wrong i2c adapter %d max %d
 possible\n",

Since you are the maintainer of the i2c code, you will decide if those changes shall be applied (they are really cosmetic) :-).

Quoted 1 line

Exactly for this reason a "Acked-by" would not disturb me ;-)

So as requested :-) :

Quoted 18 lines
Quoted 2 lines

My suggestion: printf -> error() macro @ common.h

Yep ... but this should be a seperate patch.

Quoted 8 lines

drivers/i2c/i2c_core.c unsigned int i2c_get_bus_num(void) · line 295

Quoted 2 lines
drivers/i2c/i2c_core.c +2 -0
+		       I2C_ADAPTER(bus), max);
+		return -2;

I've noticed that i2c_core uses -1/-2 return values for errors globaly.

So for a new code we could start using defines from errno.h (-2 -> -ENODEV) ?

Yes, good point!

bye,
Heiko

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#4 lore raw

PATCH 1/1 i2c, core: optimze i2c_set_bus_num()

In reply to Heiko Schocher

Hello Heiko,

Am 04.10.2013 07:36, schrieb Heiko Schocher:

Quoted 9 lines

check first, if we are on the bus, we want to enable. If so, return immediately, do not calc max adapter number, nor check other things.

---
  drivers/i2c/i2c_core.c | 18 ++++++++++--------
  1 file changed, 10 insertions(+), 8 deletions(-)

Applied to u-boot-i2c.git

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