Skip to contentSkip to conversation

power: twl4030: Add twl4030_i2c_read() function

PATCH New Pali Rohár 4 participants 8 messages Oct 26, 2020 – Nov 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 power: twl4030: Add twl4030_i2c_read() function

Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of single value it rather returns array of values.

---
 drivers/power/twl4030.c |  7 +++----
 include/twl4030.h       | 12 +++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/power/twl4030.c +3 -4
index b0d5cba2c4..f48af84e17 100644
@@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return 0;
 }
 
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
 {
 	struct udevice *dev;
 	int ret;
@@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
 		pr_err("unable to get I2C bus. ret %d\n", ret);
 		return ret;
 	}
-	ret = dm_i2c_reg_read(dev, reg);
-	if (ret < 0) {
+	ret = dm_i2c_read(dev, reg, valp, len);
+	if (ret) {
 		pr_err("reading from twl4030 failed. ret %d\n", ret);
 		return ret;
 	}
-	*valp = (u8)ret;
 	return 0;
 }
 #endif
include/twl4030.h +9 -3
index c27ad615ee..ef05193996 100644
@@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return i2c_write(chip_no, reg, 1, &val, 1);
 }
 
-static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
 {
-	return i2c_read(chip_no, reg, 1, val, 1);
+	return i2c_read(chip_no, reg, 1, val, len);
 }
 #else
 int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
 #endif
+
+static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+{
+	return twl4030_i2c_read(chip_no, reg, val, 1);
+}
+
 /*
  * Power
  */
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 Nokia RX-51: Convert to CONFIG_DM_I2C

---
 board/nokia/rx51/rx51.c      | 26 ++++++++++++++++++++++++--
 configs/nokia_rx51_defconfig |  2 ++
 include/configs/nokia_rx51.h |  2 ++
 3 files changed, 28 insertions(+), 2 deletions(-)
board/nokia/rx51/rx51.c +24 -2
index f624dbfbeb..9cc5eb97b3 100644
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <env.h>
 #include <init.h>
 #include <watchdog.h>
@@ -33,6 +34,7 @@
 #include <asm/setup.h>
 #include <asm/bitops.h>
 #include <asm/mach-types.h>
+#include <asm/omap_i2c.h>
 #include <asm/arch/mux.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mmc_host_def.h>
@@ -390,10 +392,16 @@ int misc_init_r(void)
 	u8 state;
 
 	/* reset lp5523 led */
+#ifndef CONFIG_DM_I2C
 	i2c_set_bus_num(1);
 	state = 0xff;
 	i2c_write(0x32, 0x3d, 1, &state, 1);
 	i2c_set_bus_num(0);
+#else
+	struct udevice *dev;
+	if (i2c_get_chip_for_busnum(1, 0x32, 1, &dev) == 0)
+		dm_i2c_reg_write(dev, 0x3d, 0xff);
+#endif
 
 	/* initialize twl4030 power managment */
 	twl4030_power_init();
@@ -626,8 +634,8 @@ int rx51_kp_tstc(struct stdio_dev *sdev)
 			continue;
 
 		/* read the key state */
-		i2c_read(TWL4030_CHIP_KEYPAD,
-			TWL4030_KEYPAD_FULL_CODE_7_0, 1, keys, 8);
+		twl4030_i2c_read(TWL4030_CHIP_KEYPAD,
+				 TWL4030_KEYPAD_FULL_CODE_7_0, keys, 8);
 
 		/* cut out modifier keys from the keystate */
 		mods = keys[4] >> 4;
@@ -684,3 +692,17 @@ void board_mmc_power_init(void)
 	twl4030_power_mmc_init(0);
 	twl4030_power_mmc_init(1);
 }
+
+#ifdef CONFIG_DM_I2C
+static const struct omap_i2c_platdata rx51_i2c[] = {
+	{ I2C_BASE1, 2200000, OMAP_I2C_REV_V1 },
+	{ I2C_BASE2, 100000, OMAP_I2C_REV_V1 },
+	{ I2C_BASE3, 400000, OMAP_I2C_REV_V1 },
+};
+
+U_BOOT_DEVICES(rx51_i2c) = {
+	{ "i2c_omap", &rx51_i2c[0] },
+	{ "i2c_omap", &rx51_i2c[1] },
+	{ "i2c_omap", &rx51_i2c[2] },
+};
+#endif
configs/nokia_rx51_defconfig +2 -0
index e249dff774..d5f27db642 100644
@@ -59,3 +59,5 @@ CONFIG_CFB_CONSOLE_ANSI=y
 # CONFIG_VGA_AS_SINGLE_DEVICE is not set
 CONFIG_SPLASH_SCREEN=y
 # CONFIG_GZIP is not set
+CONFIG_DM=y
+CONFIG_DM_I2C=y
include/configs/nokia_rx51.h +2 -0
index c86c429413..1d7ee7fc19 100644
@@ -77,7 +77,9 @@
 
 /* commands to include */
 
+#ifndef CONFIG_DM_I2C
 #define CONFIG_SYS_I2C
+#endif
 
 /*
  * TWL4030
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 Nokia RX-51: Convert to CONFIG_DM_I2C

Quoted 1 line · Pali Roh?r

Please include something for the commit message.

Quoted 30 lines
---
 board/nokia/rx51/rx51.c      | 26 ++++++++++++++++++++++++--
 configs/nokia_rx51_defconfig |  2 ++
 include/configs/nokia_rx51.h |  2 ++
 3 files changed, 28 insertions(+), 2 deletions(-)
board/nokia/rx51/rx51.c +2 -0
index f624dbfbeb..9cc5eb97b3 100644
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <env.h>
 #include <init.h>
 #include <watchdog.h>
@@ -33,6 +34,7 @@
 #include <asm/setup.h>
 #include <asm/bitops.h>
 #include <asm/mach-types.h>
+#include <asm/omap_i2c.h>
 #include <asm/arch/mux.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mmc_host_def.h>
@@ -390,10 +392,16 @@ int misc_init_r(void)
 	u8 state;
 
 	/* reset lp5523 led */

board/nokia/rx51/rx51.c int misc_init_r(void) · line 404

Quoted 10 lines
board/nokia/rx51/rx51.c +6 -0
+#ifndef CONFIG_DM_I2C
 	i2c_set_bus_num(1);
 	state = 0xff;
 	i2c_write(0x32, 0x3d, 1, &state, 1);
 	i2c_set_bus_num(0);
+#else
+	struct udevice *dev;
+	if (i2c_get_chip_for_busnum(1, 0x32, 1, &dev) == 0)
+		dm_i2c_reg_write(dev, 0x3d, 0xff);
+#endif

At this point, and especially for boards and not drivers, just do the conversion unilaterally. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201026/4828e584/attachment.sig>
#3 lore raw

PATCH v2 1/1 Nokia RX-51: Convert to CONFIG_DM_I2C

Use twl4030_i2c_read(), i2c_get_chip_for_busnum() and remove CONFIG_SYS_I2C.

---
 board/nokia/rx51/rx51.c      | 25 +++++++++++++++++++------
 configs/nokia_rx51_defconfig |  2 ++
 include/configs/nokia_rx51.h |  2 --
 3 files changed, 21 insertions(+), 8 deletions(-)
board/nokia/rx51/rx51.c +19 -6
index f624dbfbeb..63531e1420 100644
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <env.h>
 #include <init.h>
 #include <watchdog.h>
@@ -33,6 +34,7 @@
 #include <asm/setup.h>
 #include <asm/bitops.h>
 #include <asm/mach-types.h>
+#include <asm/omap_i2c.h>
 #include <asm/arch/mux.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mmc_host_def.h>
@@ -386,14 +388,13 @@ static void omap3_update_aux_cr_secure_rx51(u32 set_bits, u32 clear_bits)
  */
 int misc_init_r(void)
 {
+	struct udevice *dev;
 	char buf[12];
 	u8 state;
 
 	/* reset lp5523 led */
-	i2c_set_bus_num(1);
-	state = 0xff;
-	i2c_write(0x32, 0x3d, 1, &state, 1);
-	i2c_set_bus_num(0);
+	if (i2c_get_chip_for_busnum(1, 0x32, 1, &dev) == 0)
+		dm_i2c_reg_write(dev, 0x3d, 0xff);
 
 	/* initialize twl4030 power managment */
 	twl4030_power_init();
@@ -626,8 +627,8 @@ int rx51_kp_tstc(struct stdio_dev *sdev)
 			continue;
 
 		/* read the key state */
-		i2c_read(TWL4030_CHIP_KEYPAD,
-			TWL4030_KEYPAD_FULL_CODE_7_0, 1, keys, 8);
+		twl4030_i2c_read(TWL4030_CHIP_KEYPAD,
+				 TWL4030_KEYPAD_FULL_CODE_7_0, keys, 8);
 
 		/* cut out modifier keys from the keystate */
 		mods = keys[4] >> 4;
@@ -684,3 +685,15 @@ void board_mmc_power_init(void)
 	twl4030_power_mmc_init(0);
 	twl4030_power_mmc_init(1);
 }
+
+static const struct omap_i2c_platdata rx51_i2c[] = {
+	{ I2C_BASE1, 2200000, OMAP_I2C_REV_V1 },
+	{ I2C_BASE2, 100000, OMAP_I2C_REV_V1 },
+	{ I2C_BASE3, 400000, OMAP_I2C_REV_V1 },
+};
+
+U_BOOT_DEVICES(rx51_i2c) = {
+	{ "i2c_omap", &rx51_i2c[0] },
+	{ "i2c_omap", &rx51_i2c[1] },
+	{ "i2c_omap", &rx51_i2c[2] },
+};
configs/nokia_rx51_defconfig +2 -0
index e249dff774..d5f27db642 100644
@@ -59,3 +59,5 @@ CONFIG_CFB_CONSOLE_ANSI=y
 # CONFIG_VGA_AS_SINGLE_DEVICE is not set
 CONFIG_SPLASH_SCREEN=y
 # CONFIG_GZIP is not set
+CONFIG_DM=y
+CONFIG_DM_I2C=y
include/configs/nokia_rx51.h +0 -2
index c86c429413..9b89120342 100644
@@ -77,8 +77,6 @@
 
 /* commands to include */
 
-#define CONFIG_SYS_I2C
-
 /*
  * TWL4030
  */
Signature · 1 line
2.20.1
#5 lore raw

PATCH 1/2 power: twl4030: Add twl4030_i2c_read() function

In reply to Pali Rohár

Hi,

Quoted 2 lines · Pali Roh?r

Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of single value it rather returns array of values.

Just minor comment.
Is there a reason not to touch twl4030_i2c_write_u8()?

Best Regards,
Jaehoon Chung

Quoted 64 lines
---
 drivers/power/twl4030.c |  7 +++----
 include/twl4030.h       | 12 +++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/power/twl4030.c +3 -4
index b0d5cba2c4..f48af84e17 100644
@@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return 0;
 }
 
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
 {
 	struct udevice *dev;
 	int ret;
@@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
 		pr_err("unable to get I2C bus. ret %d\n", ret);
 		return ret;
 	}
-	ret = dm_i2c_reg_read(dev, reg);
-	if (ret < 0) {
+	ret = dm_i2c_read(dev, reg, valp, len);
+	if (ret) {
 		pr_err("reading from twl4030 failed. ret %d\n", ret);
 		return ret;
 	}
-	*valp = (u8)ret;
 	return 0;
 }
 #endif
include/twl4030.h +9 -3
index c27ad615ee..ef05193996 100644
@@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return i2c_write(chip_no, reg, 1, &val, 1);
 }
 
-static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
 {
-	return i2c_read(chip_no, reg, 1, val, 1);
+	return i2c_read(chip_no, reg, 1, val, len);
 }
 #else
 int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
 #endif
+
+static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+{
+	return twl4030_i2c_read(chip_no, reg, val, 1);
+}
+
 /*
  * Power
  */
#6 lore raw

PATCH 1/2 power: twl4030: Add twl4030_i2c_read() function

Quoted 8 lines · On Wednesday 28 October 2020 06:45:51 Jaehoon Chung wrote:

Hi,

Quoted 2 lines · Pali Roh?r

Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of single value it rather returns array of values.

Just minor comment.
Is there a reason not to touch twl4030_i2c_write_u8()?

Well, it is because I have no usage for twl4030_i2c_write() yet. So I have not touched write functions.

This new twl4030_i2c_read() function is used in PATCH 2/2.

Quoted 68 lines

Best Regards,
Jaehoon Chung

Quoted 64 lines
---
 drivers/power/twl4030.c |  7 +++----
 include/twl4030.h       | 12 +++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/power/twl4030.c +3 -4
index b0d5cba2c4..f48af84e17 100644
@@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return 0;
 }
 
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
 {
 	struct udevice *dev;
 	int ret;
@@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
 		pr_err("unable to get I2C bus. ret %d\n", ret);
 		return ret;
 	}
-	ret = dm_i2c_reg_read(dev, reg);
-	if (ret < 0) {
+	ret = dm_i2c_read(dev, reg, valp, len);
+	if (ret) {
 		pr_err("reading from twl4030 failed. ret %d\n", ret);
 		return ret;
 	}
-	*valp = (u8)ret;
 	return 0;
 }
 #endif
include/twl4030.h +9 -3
index c27ad615ee..ef05193996 100644
@@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return i2c_write(chip_no, reg, 1, &val, 1);
 }
 
-static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
 {
-	return i2c_read(chip_no, reg, 1, val, 1);
+	return i2c_read(chip_no, reg, 1, val, len);
 }
 #else
 int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
 #endif
+
+static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+{
+	return twl4030_i2c_read(chip_no, reg, val, 1);
+}
+
 /*
  * Power
  */
#7 lore raw

PATCH 1/2 power: twl4030: Add twl4030_i2c_read() function

Quoted 7 lines · Pali Roh?r
Quoted 6 lines · On Wednesday 28 October 2020 06:45:51 Jaehoon Chung wrote:

Hi,

Quoted 2 lines · Pali Roh?r

Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of single value it rather returns array of values.

Quoted 13 lines
Quoted 2 lines

Just minor comment.
Is there a reason not to touch twl4030_i2c_write_u8()?

Well, it is because I have no usage for twl4030_i2c_write() yet. So I have not touched write functions.

This new twl4030_i2c_read() function is used in PATCH 2/2.

Quoted 5 lines

Best Regards,
Jaehoon Chung

Quoted 2 lines

Best Regards,
Jaehoon Chung

Quoted 64 lines
Quoted 63 lines
Quoted 62 lines
---
 drivers/power/twl4030.c |  7 +++----
 include/twl4030.h       | 12 +++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/power/twl4030.c +3 -4
index b0d5cba2c4..f48af84e17 100644
@@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return 0;
 }
 
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
 {
 	struct udevice *dev;
 	int ret;
@@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
 		pr_err("unable to get I2C bus. ret %d\n", ret);
 		return ret;
 	}
-	ret = dm_i2c_reg_read(dev, reg);
-	if (ret < 0) {
+	ret = dm_i2c_read(dev, reg, valp, len);
+	if (ret) {
 		pr_err("reading from twl4030 failed. ret %d\n", ret);
 		return ret;
 	}
-	*valp = (u8)ret;
 	return 0;
 }
 #endif
include/twl4030.h +9 -3
index c27ad615ee..ef05193996 100644
@@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return i2c_write(chip_no, reg, 1, &val, 1);
 }
 
-static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
 {
-	return i2c_read(chip_no, reg, 1, val, 1);
+	return i2c_read(chip_no, reg, 1, val, len);
 }
 #else
 int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
 #endif
+
+static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+{
+	return twl4030_i2c_read(chip_no, reg, val, 1);
+}
+
 /*
  * Power
  */