Skip to contentSkip to conversation

switch to generic PMIC driver for i.MX boards

U-Boot Superseded Stefano Babic 9 participants 42 messages Oct 8, 2011 – Oct 24, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Changes from V1: please ignore V1, a couple of patches were not sent.

This patchset is based on ?ukasz Majewski's patches that introduce a generic PMIC (Power Microcontroller) driver:

http://patchwork.ozlabs.org/patch/117565/
http://patchwork.ozlabs.org/patch/117563/
http://patchwork.ozlabs.org/patch/117818/
http://patchwork.ozlabs.org/patch/118071/

The patchset replaced the old driver used on i.MX boards (Freescale PMIC) and switches to the new generic driver.

 board/davedenx/qong/qong.c        |   11 ++-
 board/efikamx/efikamx.c           |   51 +++++----
 board/freescale/mx35pdk/mx35pdk.c |   18 ++-
 board/freescale/mx51evk/mx51evk.c |   47 ++++----
 board/freescale/mx53evk/mx53evk.c |   17 ++-
 board/ttcontrol/vision2/vision2.c |   33 +++---
 drivers/i2c/mxc_i2c.c             |    5 +
 drivers/misc/Makefile             |    1 -
 drivers/misc/fsl_pmic.c           |  235 -------------------------------------
 drivers/misc/pmic_fsl.c           |   17 ++-
 drivers/rtc/mc13783-rtc.c         |   20 ++--
 include/configs/efikamx.h         |    5 +-
 include/configs/imx31_litekit.h   |    9 +-
 include/configs/mx31ads.h         |    8 +-
 include/configs/mx31pdk.h         |    6 +-
 include/configs/mx35pdk.h         |    5 +-
 include/configs/mx51evk.h         |    6 +-
 include/configs/mx53evk.h         |    5 +-
 include/configs/qong.h            |    5 +-
 include/configs/vision2.h         |    5 +-
 20 files changed, 174 insertions(+), 335 deletions(-)

[PATCH 01/13] MX5: vision2: use new pmic driver [PATCH 02/13] RTC: Switch mc13783 to generic pmic code [PATCH 03/13] MX3: qong: use new pmic driver
[PATCH V2 04/13] MX5: efikamx/efikasb: use new pmic driver [PATCH 05/13] I2c: add missing i2c_set_bus_num to mxc_i2c [PATCH V2 06/13] misc: pmic: addI2C support to pmic_fsl driver [PATCH 07/13] MX35: mx35pdk: use new pmic driver [PATCH V2 08/13] MX5: mx51evk: use new pmic driver [PATCH V2 09/13] MX5: mx53evk: use new pmic driver [PATCH 10/13] MX31: mx31_litekit: use new pmic driver [PATCH 11/13] MX31: mx31ads: use new pmic driver [PATCH 12/13] MX31: mx31pdk: use new pmic driver [PATCH 13/13] misc: pmic: drop old Freescale's pmic driver

#1 lore raw

PATCH 1/13 MX5: vision2: use new pmic driver

Switch to new pmic generic driver.

---
 board/ttcontrol/vision2/vision2.c |   33 +++++++++++++++++++--------------
 include/configs/vision2.h         |    5 ++++-
 2 files changed, 23 insertions(+), 15 deletions(-)
board/ttcontrol/vision2/vision2.c +19 -14
index e496f64..d3815b2 100644
@@ -34,6 +34,7 @@
 #include <asm/errno.h>
 #include <i2c.h>
 #include <mmc.h>
+#include <pmic.h>
 #include <fsl_esdhc.h>
 #include <fsl_pmic.h>
 #include <mc13892.h>
@@ -313,59 +314,63 @@ static void reset_peripherals(int reset)
 static void power_init_mx51(void)
 {
 	unsigned int val;
+	struct pmic *p;
+
+	pmic_init();
+	p = get_pmic();
 
 	/* Write needed to Power Gate 2 register */
-	val = pmic_reg_read(REG_POWER_MISC);
+	pmic_reg_read(p, REG_POWER_MISC, &val);
 
 	/* enable VCAM with 2.775V to enable read from PMIC */
 	val = VCAMCONFIG | VCAMEN;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 
 	/*
 	 * Set switchers in Auto in NORMAL mode & STANDBY mode
 	 * Setup the switcher mode for SW1 & SW2
 	 */
-	val = pmic_reg_read(REG_SW_4);
+	pmic_reg_read(p, REG_SW_4, &val);
 	val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
 		(SWMODE_MASK << SWMODE2_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
-	pmic_reg_write(REG_SW_4, val);
+	pmic_reg_write(p, REG_SW_4, val);
 
 	/* Setup the switcher mode for SW3 & SW4 */
-	val = pmic_reg_read(REG_SW_5);
+	pmic_reg_read(p, REG_SW_5, &val);
 	val &= ~((SWMODE_MASK << SWMODE4_SHIFT) |
 		(SWMODE_MASK << SWMODE3_SHIFT));
 	val |= (SWMODE_AUTO_AUTO << SWMODE4_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE3_SHIFT);
-	pmic_reg_write(REG_SW_5, val);
+	pmic_reg_write(p, REG_SW_5, val);
 
 
 	/* Set VGEN3 to 1.8V, VCAM to 3.0V */
-	val = pmic_reg_read(REG_SETTING_0);
+	pmic_reg_read(p, REG_SETTING_0, &val);
 	val &= ~(VCAM_MASK | VGEN3_MASK);
 	val |= VCAM_3_0;
-	pmic_reg_write(REG_SETTING_0, val);
+	pmic_reg_write(p, REG_SETTING_0, val);
 
 	/* Set VVIDEO to 2.775V, VAUDIO to 3V0, VSD to 1.8V */
-	val = pmic_reg_read(REG_SETTING_1);
+	pmic_reg_read(p, REG_SETTING_1, &val);
 	val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
 	val |= VVIDEO_2_775 | VAUDIO_3_0 | VSD_1_8;
-	pmic_reg_write(REG_SETTING_1, val);
+	pmic_reg_write(p, REG_SETTING_1, val);
 
 	/* Configure VGEN3 and VCAM regulators to use external PNP */
 	val = VGEN3CONFIG | VCAMCONFIG;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 	udelay(200);
 
 	/* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
 	val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
 		VVIDEOEN | VAUDIOEN  | VSDEN;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 
-	val = pmic_reg_read(REG_POWER_CTL2);
+	pmic_reg_read(p, REG_POWER_CTL2, &val);
 	val |= WDIRESET;
-	pmic_reg_write(REG_POWER_CTL2, val);
+	pmic_reg_write(p, REG_POWER_CTL2, val);
 
 	udelay(2500);
 
include/configs/vision2.h +4 -1
index 4c6ed3d..17d1d15 100644
@@ -91,11 +91,14 @@
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 
 /* PMIC Controller */
-#define CONFIG_FSL_PMIC
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS	0
 #define CONFIG_FSL_PMIC_CS	0
 #define CONFIG_FSL_PMIC_CLK	2500000
 #define CONFIG_FSL_PMIC_MODE	SPI_MODE_0
+#define CONFIG_FSL_PMIC_BITLEN	32
 #define CONFIG_RTC_MC13783
 
 /*
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/13 RTC: Switch mc13783 to generic pmic code

In reply to Stefano Babic
---
 drivers/rtc/mc13783-rtc.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
drivers/rtc/mc13783-rtc.c +12 -8
index 4e18f80..70ea8a1 100644
@@ -23,24 +23,27 @@
 #include <common.h>
 #include <rtc.h>
 #include <spi.h>
+#include <pmic.h>
 #include <fsl_pmic.h>
 
 int rtc_get(struct rtc_time *rtc)
 {
 	u32 day1, day2, time;
 	int tim, i = 0;
+	struct pmic *p = get_pmic();
+	int ret;
 
 	do {
-		day1 = pmic_reg_read(REG_RTC_DAY);
-		if (day1 < 0)
+		ret = pmic_reg_read(p, REG_RTC_DAY, &day1);
+		if (ret < 0)
 			return -1;
 
-		time = pmic_reg_read(REG_RTC_TIME);
-		if (time < 0)
+		ret = pmic_reg_read(p, REG_RTC_TIME, &time);
+		if (ret < 0)
 			return -1;
 
-		day2 = pmic_reg_read(REG_RTC_DAY);
-		if (day2 < 0)
+		ret = pmic_reg_read(p, REG_RTC_DAY, &day2);
+		if (ret < 0)
 			return -1;
 
 	} while (day1 != day2 && i++ < 3);
@@ -58,14 +61,15 @@ int rtc_get(struct rtc_time *rtc)
 int rtc_set(struct rtc_time *rtc)
 {
 	u32 time, day;
+	struct pmic *p = get_pmic();
 
 	time = mktime(rtc->tm_year, rtc->tm_mon, rtc->tm_mday,
 		      rtc->tm_hour, rtc->tm_min, rtc->tm_sec);
 	day = time / 86400;
 	time %= 86400;
 
-	pmic_reg_write(REG_RTC_DAY, day);
-	pmic_reg_write(REG_RTC_TIME, time);
+	pmic_reg_write(p, REG_RTC_DAY, day);
+	pmic_reg_write(p, REG_RTC_TIME, time);
 
 	return 0;
 }
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/13 MX3: qong: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
 board/davedenx/qong/qong.c |   11 ++++++++---
 include/configs/qong.h     |    5 ++++-
 2 files changed, 12 insertions(+), 4 deletions(-)
board/davedenx/qong/qong.c +8 -3
index 9fca1f8..a9f2ef0 100644
@@ -28,6 +28,7 @@
 #include <asm/arch/sys_proto.h>
 #include <asm/io.h>
 #include <nand.h>
+#include <pmic.h>
 #include <fsl_pmic.h>
 #include <asm/gpio.h>
 #include "qong_fpga.h"
@@ -176,11 +177,15 @@ int board_init (void)
 int board_late_init(void)
 {
 	u32 val;
+	struct pmic *p;
+
+	pmic_init();
+	p = get_pmic();
 
 	/* Enable RTC battery */
-	val = pmic_reg_read(REG_POWER_CTL0);
-	pmic_reg_write(REG_POWER_CTL0, val | COINCHEN);
-	pmic_reg_write(REG_INT_STATUS1, RTCRSTI);
+	pmic_reg_read(p, REG_POWER_CTL0, &val);
+	pmic_reg_write(p, REG_POWER_CTL0, val | COINCHEN);
+	pmic_reg_write(p, REG_INT_STATUS1, RTCRSTI);
 
 #ifdef CONFIG_HW_WATCHDOG
 	mxc_hw_watchdog_enable();
include/configs/qong.h +4 -1
index 78b3701..ec99021 100644
@@ -60,11 +60,14 @@
 #define CONFIG_DEFAULT_SPI_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
 #define CONFIG_RTC_MC13783
 
-#define CONFIG_FSL_PMIC
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS	1
 #define CONFIG_FSL_PMIC_CS	0
 #define CONFIG_FSL_PMIC_CLK	100000
 #define CONFIG_FSL_PMIC_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
+#define CONFIG_FSL_PMIC_BITLEN	32
 
 /* FPGA */
 #define CONFIG_FPGA
Signature · 1 line
1.7.1
#4 lore raw

PATCH v2 4/13 MX5: efikamx/efikasb: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---

Changes:

-moved pmic_init into power_init() (Marek Vasut)

 board/efikamx/efikamx.c   |   51 ++++++++++++++++++++++++--------------------
 include/configs/efikamx.h |    5 +++-
 2 files changed, 32 insertions(+), 24 deletions(-)
board/efikamx/efikamx.c +28 -23
index 0c4e24b..b78bf6c 100644
@@ -34,6 +34,7 @@
 #include <i2c.h>
 #include <mmc.h>
 #include <fsl_esdhc.h>
+#include <pmic.h>
 #include <fsl_pmic.h>
 #include <mc13892.h>
 
@@ -205,34 +206,38 @@ static void power_init(void)
 {
 	unsigned int val;
 	struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
+	struct pmic *p;
+
+	pmic_init();
+	p = get_pmic();
 
 	/* Write needed to Power Gate 2 register */
-	val = pmic_reg_read(REG_POWER_MISC);
+	pmic_reg_read(p, REG_POWER_MISC, &val);
 	val &= ~PWGT2SPIEN;
-	pmic_reg_write(REG_POWER_MISC, val);
+	pmic_reg_write(p, REG_POWER_MISC, val);
 
 	/* Externally powered */
-	val = pmic_reg_read(REG_CHARGE);
+	pmic_reg_read(p, REG_CHARGE, &val);
 	val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
-	pmic_reg_write(REG_CHARGE, val);
+	pmic_reg_write(p, REG_CHARGE, val);
 
 	/* power up the system first */
-	pmic_reg_write(REG_POWER_MISC, PWUP);
+	pmic_reg_write(p, REG_POWER_MISC, PWUP);
 
 	/* Set core voltage to 1.1V */
-	val = pmic_reg_read(REG_SW_0);
+	pmic_reg_read(p, REG_SW_0, &val);
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
-	pmic_reg_write(REG_SW_0, val);
+	pmic_reg_write(p, REG_SW_0, val);
 
 	/* Setup VCC (SW2) to 1.25 */
-	val = pmic_reg_read(REG_SW_1);
+	pmic_reg_read(p, REG_SW_1, &val);
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
-	pmic_reg_write(REG_SW_1, val);
+	pmic_reg_write(p, REG_SW_1, val);
 
 	/* Setup 1V2_DIG1 (SW3) to 1.25 */
-	val = pmic_reg_read(REG_SW_2);
+	pmic_reg_read(p, REG_SW_2, &val);
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
-	pmic_reg_write(REG_SW_2, val);
+	pmic_reg_write(p, REG_SW_2, val);
 	udelay(50);
 
 	/* Raise the core frequency to 800MHz */
@@ -240,46 +245,46 @@ static void power_init(void)
 
 	/* Set switchers in Auto in NORMAL mode & STANDBY mode */
 	/* Setup the switcher mode for SW1 & SW2*/
-	val = pmic_reg_read(REG_SW_4);
+	pmic_reg_read(p, REG_SW_4, &val);
 	val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
 		(SWMODE_MASK << SWMODE2_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
-	pmic_reg_write(REG_SW_4, val);
+	pmic_reg_write(p, REG_SW_4, val);
 
 	/* Setup the switcher mode for SW3 & SW4 */
-	val = pmic_reg_read(REG_SW_5);
+	pmic_reg_read(p, REG_SW_5, &val);
 	val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
 		(SWMODE_MASK << SWMODE4_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
-	pmic_reg_write(REG_SW_5, val);
+	pmic_reg_write(p, REG_SW_5, val);
 
 	/* Set VDIG to 1.65V, VGEN3 to 1.8V, VCAM to 2.6V */
-	val = pmic_reg_read(REG_SETTING_0);
+	pmic_reg_read(p, REG_SETTING_0, &val);
 	val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
 	val |= VDIG_1_65 | VGEN3_1_8 | VCAM_2_6;
-	pmic_reg_write(REG_SETTING_0, val);
+	pmic_reg_write(p, REG_SETTING_0, val);
 
 	/* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
-	val = pmic_reg_read(REG_SETTING_1);
+	pmic_reg_read(p, REG_SETTING_1, &val);
 	val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
 	val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775;
-	pmic_reg_write(REG_SETTING_1, val);
+	pmic_reg_write(p, REG_SETTING_1, val);
 
 	/* Configure VGEN3 and VCAM regulators to use external PNP */
 	val = VGEN3CONFIG | VCAMCONFIG;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 	udelay(200);
 
 	/* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
 	val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
 		VVIDEOEN | VAUDIOEN  | VSDEN;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 
-	val = pmic_reg_read(REG_POWER_CTL2);
+	pmic_reg_read(p, REG_POWER_CTL2, &val);
 	val |= WDIRESET;
-	pmic_reg_write(REG_POWER_CTL2, val);
+	pmic_reg_write(p, REG_POWER_CTL2, val);
 
 	udelay(2500);
 }
include/configs/efikamx.h +4 -1
index 54f48e4..7e4b424 100644
@@ -124,11 +124,14 @@
 #endif
 
 /* SPI PMIC */
-#define CONFIG_FSL_PMIC
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS		0
 #define CONFIG_FSL_PMIC_CS		(0 | 120 << 8)
 #define CONFIG_FSL_PMIC_CLK		25000000
 #define CONFIG_FSL_PMIC_MODE		(SPI_MODE_0 | SPI_CS_HIGH)
+#define CONFIG_FSL_PMIC_BITLEN	32
 #define CONFIG_RTC_MC13783
 #endif
 
Signature · 1 line
1.7.1
#6 lore raw

PATCH 5/13 I2c: add missing i2c_set_bus_num to mxc_i2c

In reply to Stefano Babic

The function i2c_set_bus_num() is used on most SOCs. The driver does not support multiple I2C busses, and an empty function is added to be compatible with general code (example: PMIC driver).

---
 drivers/i2c/mxc_i2c.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/i2c/mxc_i2c.c +5 -0
index 2869d7c..de878ce 100644
@@ -450,4 +450,9 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len)
 
 	return ret;
 }
+
+int i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
 #endif /* CONFIG_HARD_I2C */
Signature · 1 line
1.7.1
#7 lore raw

PATCH 5/13 I2c: add missing i2c_set_bus_num to mxc_i2c

Hello Stefano,

Quoted 10 lines · Stefano Babic

The function i2c_set_bus_num() is used on most SOCs. The driver does not support multiple I2C busses, and an empty function is added to be compatible with general code (example: PMIC driver).

---
 drivers/i2c/mxc_i2c.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Hmm... it would be better to add a weak function in u-boot/common/cmd_i2c.c ... as it is done for i2c_set_bus_speed() and i2c_get_bus_speed() functions.

bye,
Heiko

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

PATCH 5/13 I2c: add missing i2c_set_bus_num to mxc_i2c

Quoted 14 lines · Heiko Schocher

Hello Stefano,

Quoted 10 lines · Stefano Babic

The function i2c_set_bus_num() is used on most SOCs. The driver does not support multiple I2C busses, and an empty function is added to be compatible with general code (example: PMIC driver).

---
 drivers/i2c/mxc_i2c.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Quoted 3 lines

Hmm... it would be better to add a weak function in u-boot/common/cmd_i2c.c ... as it is done for i2c_set_bus_speed() and i2c_get_bus_speed() functions.

Good idea, I missed it..changed in V2.

Stefano

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#9 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

In reply to Stefano Babic

New default, weak i2c_set_bus_num() function.

---
Changes since V1:

- add a weak function i2c_set_bus_num() to cmd_i2c.c instead of adding a dummy function to mxc_i2c.c. (Heiko Schocher)

 common/cmd_i2c.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
common/cmd_i2c.c +8 -0
index 3ea75f7..0f925d1 100644
@@ -158,6 +158,14 @@ int __def_i2c_set_bus_speed(unsigned int speed)
 int i2c_set_bus_speed(unsigned int)
 	__attribute__((weak, alias("__def_i2c_set_bus_speed")));
 
+int __def_i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
+int i2c_set_bus_num(unsigned int)
+	__attribute__((weak, alias("__def_i2c_set_bus_num")));
+
+
 /*
  * get_alen: small parser helper function to get address length
  * returns the address length
Signature · 1 line
1.7.1
#10 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

Hello Stefano,

Quoted 19 lines · Stefano Babic

New default, weak i2c_set_bus_num() function.

---
Changes since V1:

- add a weak function i2c_set_bus_num() to cmd_i2c.c instead of adding a dummy function to mxc_i2c.c. (Heiko Schocher)

 common/cmd_i2c.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
common/cmd_i2c.c +0 -0
index 3ea75f7..0f925d1 100644
@@ -158,6 +158,14 @@ int __def_i2c_set_bus_speed(unsigned int speed)
 int i2c_set_bus_speed(unsigned int)

common/cmd_i2c.c int __def_i2c_set_bus_speed(unsigned int speed) · line 168

Quoted 10 lines
common/cmd_i2c.c +8 -0
 	__attribute__((weak, alias("__def_i2c_set_bus_speed")));
 
+int __def_i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
+int i2c_set_bus_num(unsigned int)
+	__attribute__((weak, alias("__def_i2c_set_bus_num")));
+
+

Please just one new line ;-)

Beside of this, you get my:

common/cmd_i2c.c int __def_i2c_set_bus_speed(unsigned int speed) · line 171

Quoted 3 lines
common/cmd_i2c.c +0 -0
 /*
  * get_alen: small parser helper function to get address length
  * returns the address length

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
#11 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

In reply to Stefano Babic
Quoted 4 lines · Stefano Babic

New default, weak i2c_set_bus_num() function.

I would prefer to see a new set of I2C functions that take a bus number as a parameter, so that we can eliminate i2c_set_bus_num() (and the global variable it modifies) altogether.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#12 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

Quoted 9 lines · On Monday 10 October 2011 13:53:48 Tabi Timur-B04825 wrote:
Quoted 4 lines · Stefano Babic

New default, weak i2c_set_bus_num() function.

I would prefer to see a new set of I2C functions that take a bus number as a parameter, so that we can eliminate i2c_set_bus_num() (and the global variable it modifies) altogether.

i think that'd require a much larger rework of the framework and thus would be better to do in addition to Stefano's work rather than in place of ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111010/930bd0a4/attachment.pgp

#13 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

Quoted 2 lines · Mike Frysinger

i think that'd require a much larger rework of the framework and thus would be better to do in addition to Stefano's work rather than in place of ?

Hmmm... I guess it would be easier to do the rework eventually if i2c_set_bus_num() is universal, instead of just for PowerPC.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#14 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

In reply to Mike Frysinger
Quoted 7 lines · Mike Frysinger
Quoted 6 lines · On Monday 10 October 2011 13:53:48 Tabi Timur-B04825 wrote:
Quoted 4 lines · Stefano Babic

New default, weak i2c_set_bus_num() function.

Quoted 6 lines
Quoted 3 lines

I would prefer to see a new set of I2C functions that take a bus number as a parameter, so that we can eliminate i2c_set_bus_num() (and the global variable it modifies) altogether.

i think that'd require a much larger rework of the framework and thus would be better to do in addition to Stefano's work rather than in place of ?

Right - this patch is only due to the fact that the mxc_i2c.c has no i2c_set_bus_num(), while it is present in several SOCs (not only powerpc).

I see now that the pmic patches calls i2c_set_bus_num() instead of the macro I2C_SET_BUS(), that is protected in case CONFIG_I2C_MULTI_BUS is not set (I have only now discovered...). Maybe I should drop my patch and change the pmic to use this macro.

Regards,
Stefano

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#15 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

In reply to Tabi Timur-B04825

Hello Tabi,

Quoted 9 lines · Tabi Timur-B04825 wrote:
Quoted 4 lines · Stefano Babic

New default, weak i2c_set_bus_num() function.

I would prefer to see a new set of I2C functions that take a bus number as a parameter, so that we can eliminate i2c_set_bus_num() (and the global variable it modifies) altogether.

Then please have a look at:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=shortlog;h=refs/heads/multibus_v2

It is a complete i2c rework with adding multiadapter/multibus to the i2c framework (and a i2c_core.c) ... It needs a rebase and tests, but my last tests (Ok, 6 months ago ... :-( ) on 2 powerpc architectures and one arm looked good ...

bye,
Heiko

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

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

Dear Heiko Schocher,

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

Then please have a look at:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=shortlog;h=refs/heads/multibus_v2

It is a complete i2c rework with adding multiadapter/multibus to the i2c framework (and a i2c_core.c) ... It needs a rebase and tests, but my last tests (Ok, 6 months ago ... :-( ) on 2 powerpc architectures and one arm looked good ...

How about pulling this into mainline right now? It makes little sense to watch this bit-rotting even further. Every interested party had more than enough time for testing now.

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
"To IBM, 'open' means there is a modicum  of  interoperability  among
some of their equipment."                            - Harv Masterson
#17 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

Quoted 13 lines · Wolfgang Denk

Dear Heiko Schocher,

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

Then please have a look at:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=shortlog;h=refs/heads/multi
bus_v2

It is a complete i2c rework with adding multiadapter/multibus to the i2c framework (and a i2c_core.c) ... It needs a rebase and tests, but my last tests (Ok, 6 months ago ... :-( ) on 2 powerpc architectures and one arm looked good ...

Quoted 7 lines

How about pulling this into mainline right now? It makes little sense to watch this bit-rotting even further. Every interested party had more than enough time for testing now.

Best regards,

Wolfgang Denk

This will be useful for us. We have a number of boards which use I2C switches and muxes plus many of our devices have multiple I2C buses.

-Aaron

Signature · 2 lines
Aaron Williams <[email protected]>
 (408) 943-7198
#18 lore raw

PATCH v2 5/13 i2c: Create common default i2c_set_bus_num() function

In reply to Wolfgang Denk

Hello Wolfgang,

Quoted 7 lines · Wolfgang Denk

Dear Heiko Schocher,

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

Then please have a look at:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=shortlog;h=refs/heads/multibus_v2

Quoted 8 lines
Quoted 4 lines

It is a complete i2c rework with adding multiadapter/multibus to the i2c framework (and a i2c_core.c) ... It needs a rebase and tests, but my last tests (Ok, 6 months ago ... :-( ) on 2 powerpc architectures and one arm looked good ...

How about pulling this into mainline right now? It makes little sense to watch this bit-rotting even further. Every interested party had more than enough time for testing now.

Hmm... I had to rebase this and test it ... sorry, didn't found time to hold this in sync with mainline in the last months ... and after the rebase I only want to see this in mainline if tests on some different archs are done (at least powerpc and arm) ...

bye,
Heiko

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

PATCH 7/13 MX35: mx35pdk: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
 board/freescale/mx35pdk/mx35pdk.c |   18 ++++++++++++------
 include/configs/mx35pdk.h         |    5 +++--
 2 files changed, 15 insertions(+), 8 deletions(-)
board/freescale/mx35pdk/mx35pdk.c +12 -6
index 9eefe5e..f6da51a 100644
@@ -30,6 +30,7 @@
 #include <asm/arch/mx35_pins.h>
 #include <asm/arch/iomux.h>
 #include <i2c.h>
+#include <pmic.h>
 #include <fsl_pmic.h>
 #include <mc9sdz60.h>
 #include <mc13892.h>
@@ -204,9 +205,10 @@ int board_init(void)
 
 static inline int pmic_detect(void)
 {
-	int id;
+	unsigned int id;
+	struct pmic *p = get_pmic();
 
-	id = pmic_reg_read(REG_IDENTIFICATION);
+	pmic_reg_read(p, REG_IDENTIFICATION, &id);
 
 	id = (id >> 6) & 0x7;
 	if (id == 0x7)
@@ -227,15 +229,19 @@ int board_late_init(void)
 {
 	u8 val;
 	u32 pmic_val;
+	struct pmic *p;
 
+	pmic_init();
 	if (pmic_detect()) {
+		p = get_pmic();
 		mxc_request_iomux(MX35_PIN_WATCHDOG_RST, MUX_CONFIG_SION |
 					MUX_CONFIG_ALT1);
 
-		pmic_val = pmic_reg_read(REG_SETTING_0);
-		pmic_reg_write(REG_SETTING_0, pmic_val | VO_1_30V | VO_1_50V);
-		pmic_val = pmic_reg_read(REG_MODE_0);
-		pmic_reg_write(REG_MODE_0, pmic_val | VGEN3EN);
+		pmic_reg_read(p, REG_SETTING_0, &pmic_val);
+		pmic_reg_write(p, REG_SETTING_0,
+			pmic_val | VO_1_30V | VO_1_50V);
+		pmic_reg_read(p, REG_MODE_0, &pmic_val);
+		pmic_reg_write(p, REG_MODE_0, pmic_val | VGEN3EN);
 
 		mxc_request_iomux(MX35_PIN_COMPARE, MUX_CONFIG_GPIO);
 		mxc_iomux_set_input(MUX_IN_GPIO1_IN_5, INPUT_CTL_PATH0);
include/configs/mx35pdk.h +3 -2
index 4e9022d..946e64b 100644
@@ -69,8 +69,9 @@
 /*
  * PMIC Configs
  */
-#define CONFIG_FSL_PMIC
-#define CONFIG_FSL_PMIC_I2C
+#define CONFIG_PMIC
+#define CONFIG_PMIC_I2C
+#define CONFIG_PMIC_FSL
 #define CONFIG_SYS_FSL_PMIC_I2C_ADDR	0x08
 
 /*
Signature · 1 line
1.7.1
#20 lore raw

PATCH v2 6/13 misc: pmic: addI2C support to pmic_fsl driver

In reply to Stefano Babic

---

Changes since V1:

- drop wrong assignment for p->interface (Sergei Shtylyov)

 drivers/misc/pmic_fsl.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
drivers/misc/pmic_fsl.c +13 -4
index 13dde47..b6e809a 100644
@@ -26,6 +26,7 @@
 #include <pmic.h>
 #include <fsl_pmic.h>
 
+#if defined(CONFIG_PMIC_SPI)
 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 {
 	if ((val == NULL) && (write))
@@ -33,25 +34,33 @@ static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 	else
 		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
 }
+#endif
 
 int pmic_init(void)
 {
 	struct pmic *p = get_pmic();
 	static const char name[] = "FSL_PMIC";
 
-	puts("Board PMIC init\n");
-
 	p->name = name;
-	p->interface = PMIC_SPI;
 	p->number_of_regs = PMIC_NUM_OF_REGS;
-	p->bus = CONFIG_FSL_PMIC_BUS;
 
+#if defined(CONFIG_PMIC_SPI)
+	p->interface = PMIC_SPI;
+	p->bus = CONFIG_FSL_PMIC_BUS;
 	p->hw.spi.cs = CONFIG_FSL_PMIC_CS;
 	p->hw.spi.clk = CONFIG_FSL_PMIC_CLK;
 	p->hw.spi.mode = CONFIG_FSL_PMIC_MODE;
 	p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN;
 	p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
 	p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
+#elif defined(CONFIG_PMIC_I2C)
+	p->interface = PMIC_I2C;
+	p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR;
+	p->hw.i2c.tx_num = 3;
+	p->bus = I2C_PMIC;
+#else
+#error "You must select CONFIG_PMIC_SPI or CONFIG_PMIC_I2C"
+#endif
 
 	return 0;
 }
Signature · 1 line
1.7.1
#21 lore raw

PATCH v2 8/13 MX5: mx51evk: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
Changes:

-moved pmic_init into power_init() (Marek Vasut)

 board/freescale/mx51evk/mx51evk.c |   47 ++++++++++++++++++++----------------
 include/configs/mx51evk.h         |    6 ++++-
 2 files changed, 31 insertions(+), 22 deletions(-)
board/freescale/mx51evk/mx51evk.c +26 -21
index 8da1ee8..73ca513 100644
@@ -32,6 +32,7 @@
 #include <i2c.h>
 #include <mmc.h>
 #include <fsl_esdhc.h>
+#include <pmic.h>
 #include <fsl_pmic.h>
 #include <mc13892.h>
 
@@ -182,34 +183,38 @@ static void power_init(void)
 {
 	unsigned int val;
 	struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
+	struct pmic *p;
+
+	pmic_init();
+	p = get_pmic();
 
 	/* Write needed to Power Gate 2 register */
-	val = pmic_reg_read(REG_POWER_MISC);
+	pmic_reg_read(p, REG_POWER_MISC, &val);
 	val &= ~PWGT2SPIEN;
-	pmic_reg_write(REG_POWER_MISC, val);
+	pmic_reg_write(p, REG_POWER_MISC, val);
 
 	/* Externally powered */
-	val = pmic_reg_read(REG_CHARGE);
+	pmic_reg_read(p, REG_CHARGE, &val);
 	val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
-	pmic_reg_write(REG_CHARGE, val);
+	pmic_reg_write(p, REG_CHARGE, val);
 
 	/* power up the system first */
-	pmic_reg_write(REG_POWER_MISC, PWUP);
+	pmic_reg_write(p, REG_POWER_MISC, PWUP);
 
 	/* Set core voltage to 1.1V */
-	val = pmic_reg_read(REG_SW_0);
+	pmic_reg_read(p, REG_SW_0, &val);
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
-	pmic_reg_write(REG_SW_0, val);
+	pmic_reg_write(p, REG_SW_0, val);
 
 	/* Setup VCC (SW2) to 1.25 */
-	val = pmic_reg_read(REG_SW_1);
+	pmic_reg_read(p, REG_SW_1, &val);
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
-	pmic_reg_write(REG_SW_1, val);
+	pmic_reg_write(p, REG_SW_1, val);
 
 	/* Setup 1V2_DIG1 (SW3) to 1.25 */
-	val = pmic_reg_read(REG_SW_2);
+	pmic_reg_read(p, REG_SW_2, &val);
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
-	pmic_reg_write(REG_SW_2, val);
+	pmic_reg_write(p, REG_SW_2, val);
 	udelay(50);
 
 	/* Raise the core frequency to 800MHz */
@@ -217,36 +222,36 @@ static void power_init(void)
 
 	/* Set switchers in Auto in NORMAL mode & STANDBY mode */
 	/* Setup the switcher mode for SW1 & SW2*/
-	val = pmic_reg_read(REG_SW_4);
+	pmic_reg_read(p, REG_SW_4, &val);
 	val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
 		(SWMODE_MASK << SWMODE2_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
-	pmic_reg_write(REG_SW_4, val);
+	pmic_reg_write(p, REG_SW_4, val);
 
 	/* Setup the switcher mode for SW3 & SW4 */
-	val = pmic_reg_read(REG_SW_5);
+	pmic_reg_read(p, REG_SW_5, &val);
 	val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
 		(SWMODE_MASK << SWMODE4_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
-	pmic_reg_write(REG_SW_5, val);
+	pmic_reg_write(p, REG_SW_5, val);
 
 	/* Set VDIG to 1.65V, VGEN3 to 1.8V, VCAM to 2.6V */
-	val = pmic_reg_read(REG_SETTING_0);
+	pmic_reg_read(p, REG_SETTING_0, &val);
 	val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
 	val |= VDIG_1_65 | VGEN3_1_8 | VCAM_2_6;
-	pmic_reg_write(REG_SETTING_0, val);
+	pmic_reg_write(p, REG_SETTING_0, val);
 
 	/* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
-	val = pmic_reg_read(REG_SETTING_1);
+	pmic_reg_read(p, REG_SETTING_1, &val);
 	val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
 	val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775;
-	pmic_reg_write(REG_SETTING_1, val);
+	pmic_reg_write(p, REG_SETTING_1, val);
 
 	/* Configure VGEN3 and VCAM regulators to use external PNP */
 	val = VGEN3CONFIG | VCAMCONFIG;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 	udelay(200);
 
 	gpio_direction_output(46, 0);
@@ -257,7 +262,7 @@ static void power_init(void)
 	/* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
 	val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
 		VVIDEOEN | VAUDIOEN  | VSDEN;
-	pmic_reg_write(REG_MODE_1, val);
+	pmic_reg_write(p, REG_MODE_1, val);
 
 	udelay(500);
 
include/configs/mx51evk.h +5 -1
index d62a4f2..6faaa6c 100644
@@ -70,11 +70,15 @@
 
 #define CONFIG_MXC_SPI
 
-#define CONFIG_FSL_PMIC
+/* PMIC Controller */
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS	0
 #define CONFIG_FSL_PMIC_CS	0
 #define CONFIG_FSL_PMIC_CLK	2500000
 #define CONFIG_FSL_PMIC_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
+#define CONFIG_FSL_PMIC_BITLEN	32
 
 /*
  * MMC Configs
Signature · 1 line
1.7.1
#22 lore raw

PATCH 10/13 MX31: mx31_litekit: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
 include/configs/imx31_litekit.h |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
include/configs/imx31_litekit.h +6 -3
index 5e976bc..65e301e 100644
@@ -72,13 +72,16 @@
 #define CONFIG_DEFAULT_SPI_BUS	1
 #define CONFIG_DEFAULT_SPI_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
 
-#define CONFIG_FSL_PMIC
+/* PMIC Controller */
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS	1
 #define CONFIG_FSL_PMIC_CS	0
 #define CONFIG_FSL_PMIC_CLK	1000000
 #define CONFIG_FSL_PMIC_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
-
-#define CONFIG_RTC_MC13783	1
+#define CONFIG_FSL_PMIC_BITLEN	32
+#define CONFIG_RTC_MC13783
 
 /* allow to overwrite serial and ethaddr */
 #define CONFIG_ENV_OVERWRITE
Signature · 1 line
1.7.1
#23 lore raw

PATCH 11/13 MX31: mx31ads: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
 include/configs/mx31ads.h |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
include/configs/mx31ads.h +6 -2
index 0bea858..fcc5316 100644
@@ -69,12 +69,16 @@
 #define CONFIG_DEFAULT_SPI_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
 #define CONFIG_MXC_GPIO
 
-#define CONFIG_FSL_PMIC
+/* PMIC Controller */
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS	1
 #define CONFIG_FSL_PMIC_CS	0
 #define CONFIG_FSL_PMIC_CLK	1000000
 #define CONFIG_FSL_PMIC_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
-#define CONFIG_RTC_MC13783	1
+#define CONFIG_FSL_PMIC_BITLEN	32
+#define CONFIG_RTC_MC13783
 
 /* allow to overwrite serial and ethaddr */
 #define CONFIG_ENV_OVERWRITE
Signature · 1 line
1.7.1
#24 lore raw

PATCH 12/13 MX31: mx31pdk: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
 include/configs/mx31pdk.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
include/configs/mx31pdk.h +5 -1
index cd156d8..08c06e1 100644
@@ -70,11 +70,15 @@
 #define CONFIG_DEFAULT_SPI_BUS	1
 #define CONFIG_DEFAULT_SPI_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
 
-#define CONFIG_FSL_PMIC
+/* PMIC Controller */
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
 #define CONFIG_FSL_PMIC_BUS	1
 #define CONFIG_FSL_PMIC_CS	2
 #define CONFIG_FSL_PMIC_CLK	1000000
 #define CONFIG_FSL_PMIC_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
+#define CONFIG_FSL_PMIC_BITLEN	32
 #define CONFIG_RTC_MC13783
 
 /* allow to overwrite serial and ethaddr */
Signature · 1 line
1.7.1
#25 lore raw

PATCH 13/13 misc: pmic: drop old Freescale's pmic driver

In reply to Stefano Babic
---
 drivers/misc/Makefile   |    1 -
 drivers/misc/fsl_pmic.c |  235 -----------------------------------------------
 2 files changed, 0 insertions(+), 236 deletions(-)
 delete mode 100644 drivers/misc/fsl_pmic.c
drivers/misc/Makefile +0 -1
index f732a95..a709707 100644
@@ -28,7 +28,6 @@ LIB	:= $(obj)libmisc.o
 COBJS-$(CONFIG_ALI152X) += ali512x.o
 COBJS-$(CONFIG_DS4510)  += ds4510.o
 COBJS-$(CONFIG_FSL_LAW) += fsl_law.o
-COBJS-$(CONFIG_FSL_PMIC) += fsl_pmic.o
 COBJS-$(CONFIG_GPIO_LED) += gpio_led.o
 COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o
 COBJS-$(CONFIG_NS87308) += ns87308.o
drivers/misc/fsl_pmic.c deleted +0 -235

235 lines not on this page · raw message

Signature · 1 line
1.7.1
#26 lore raw

PATCH 13/13 misc: pmic: drop old Freescale's pmic driver

Quoted 7 lines · Stefano Babic
---
  drivers/misc/Makefile   |    1 -
  drivers/misc/fsl_pmic.c |  235 -----------------------------------------------
  2 files changed, 0 insertions(+), 236 deletions(-)

delete mode 100644 drivers/misc/fsl_pmic.c

I just checked PMIC action on our board (i.mx31 and mc13783) and the new code is not working here, it even:

TT01> pmic write 20 17
raise: Signal # 8 caught
<reg num> = 32 is invalid. Should be less than 0
TT01> pmic read 20
<reg num> = 32 is invalid. Should be less than 0
PMIC: Register read failed

0x20: 0x00000000

At first glance I found in pmic_fsl.c:

static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)

{
     if ((val == NULL) && (write))
         return *val & ~(1 << 31);
     else
         return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
}

which must be wrong. NULL is de-referenced in both cases and this error is even forced by pmic_spi.c:

     if (write) {
         pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
         pmic_tx &= ~(1 << 31);

Probably val == NULL was meant as escape not to touch the pmic_tx value, in the original driver it's done that way.
One could fix this by using a static variable in pmic_spi_prepare_tx(), but I'm
not sure if this was the intention.

I wonder why it was missed during testing as it seems configuration independent.
Helmut

--
Scanned by MailScanner.

#27 lore raw

PATCH 13/13 misc: pmic: drop old Freescale's pmic driver

Quoted 9 lines · Helmut Raiger
Quoted 8 lines · Stefano Babic
---
  drivers/misc/Makefile   |    1 -
  drivers/misc/fsl_pmic.c |  235
-----------------------------------------------
  2 files changed, 0 insertions(+), 236 deletions(-)

delete mode 100644 drivers/misc/fsl_pmic.c

Hi Helmut,

Quoted 22 lines

I just checked PMIC action on our board (i.mx31 and mc13783) and the new code is not working here, it even:

TT01> pmic write 20 17
raise: Signal # 8 caught
<reg num> = 32 is invalid. Should be less than 0
TT01> pmic read 20
<reg num> = 32 is invalid. Should be less than 0
PMIC: Register read failed

0x20: 0x00000000

At first glance I found in pmic_fsl.c:

static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)

{
    if ((val == NULL) && (write))
        return *val & ~(1 << 31);
    else
        return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
}
Quoted 2 lines

which must be wrong. NULL is de-referenced in both cases and this error is even forced by pmic_spi.c:

This is wrong - it is checked for NULL and then de-referenced...

Quoted 8 lines
    if (write) {
        pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
        pmic_tx &= ~(1 << 31);

Probably val == NULL was meant as escape not to touch the pmic_tx value, in the original driver it's done that way.

Then there is too much statements. If spi.prepare_tx() should clear the MSB with ~(1 << 31), why we need the second one :

pmic_tx &= ~(1 << 31);

something went simply wrong...

Because (from the old driver) the second SPI transfer is done to read back the programmed value, we can maybe use :

     if (write) {
         pmic_tx = p->hw.spi.prepare_tx(reg, &val, 0);

and of course, we should fix the wrong prepare_tx()..

Quoted 4 lines

One could fix this by using a static variable in pmic_spi_prepare_tx(), but I'm
not sure if this was the intention.

Well, it makes no sense - the prepare_tx() should not know the history, and only rely on the parameters.

Quoted 2 lines

I wonder why it was missed during testing as it seems configuration independent.

I wonder, too. I have tested with the 'date' command, that means writing into the internal RTC registers of the MC13783. I cannot explain what goes wrong, but of course the code is buggy and must be fixed.

Best regards,
Stefano Babic

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#28 lore raw

PATCH 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

This fixes write access to PMIC registers, the bug was introduced partly in commit 64aac65099 and in commit c9fe76dd91. It was tested on an i.mx31 with a mc13783.

---
 drivers/misc/pmic_fsl.c |    5 +----
 drivers/misc/pmic_spi.c |    1 -
 2 files changed, 1 insertions(+), 5 deletions(-)
drivers/misc/pmic_fsl.c +1 -4
index b6e809a..0ff75ed 100644
@@ -29,10 +29,7 @@
 #if defined(CONFIG_PMIC_SPI)
 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 {
-	if ((val == NULL) && (write))
-		return *val & ~(1 << 31);
-	else
-		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+	return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
 }
 #endif
 
drivers/misc/pmic_spi.c +0 -1
index ff35377..e772884 100644
@@ -76,7 +76,6 @@ static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
 	}
 
 	if (write) {
-		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
 		pmic_tx &= ~(1 << 31);
 		tmp = cpu_to_be32(pmic_tx);
 		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
Signature · 6 lines
1.7.4.4



--
Scanned by MailScanner.
#29 lore raw

PATCH 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

drivers/misc/pmic_fsl.c

Quoted 12 lines · Helmut Raiger

This fixes write access to PMIC registers, the bug was introduced partly in commit 64aac65099 and in commit c9fe76dd91. It was tested on an i.mx31 with a mc13783.

---
 drivers/misc/pmic_fsl.c |    5 +----
 drivers/misc/pmic_spi.c |    1 -
 2 files changed, 1 insertions(+), 5 deletions(-)
drivers/misc/pmic_fsl.c +0 -0
index b6e809a..0ff75ed 100644

Hi Helmut,

Quoted 19 lines
drivers/misc/pmic_fsl.c +1 -4
@@ -29,10 +29,7 @@
 #if defined(CONFIG_PMIC_SPI)
 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 {
-	if ((val == NULL) && (write))
-		return *val & ~(1 << 31);
-	else
-		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+	return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
 }
 #endif
 
drivers/misc/pmic_spi.c +0 -0
index ff35377..e772884 100644

drivers/misc/pmic_spi.c static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write) · line 79

Quoted 5 lines
drivers/misc/pmic_spi.c +0 -1
@@ -76,7 +76,6 @@ static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
 	}
 
 	if (write) {
-		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
 		pmic_tx &= ~(1 << 31);

This fixes the issue with the Freescale PMIC, but...

The new driver introduces a level of abstraction to make easier to introduce other PMICs that are driven with SPI / I2C. For this reason, PMIC specific code must be inside the specific driver (pmic_fsl.c) and not in the general (pmic_core.c and pmic_spi.c). And clearing the MSB is part of the Freescale's protocol, and for this reason should be moved inside the prepare function.

Best regards,
Stefano Babic

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-0 Fax: +49-8142-66989-80  Email: [email protected]
=====================================================================
#30 lore raw

PATCH 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

Quoted 10 lines · Stefano Babic

This fixes the issue with the Freescale PMIC, but...

The new driver introduces a level of abstraction to make easier to introduce other PMICs that are driven with SPI / I2C. For this reason, PMIC specific code must be inside the specific driver (pmic_fsl.c) and not in the general (pmic_core.c and pmic_spi.c). And clearing the MSB is part of the Freescale's protocol, and for this reason should be moved inside the prepare function.

Quoted 3 lines

Best regards,
Stefano Babic

Ah yes, I stumbled over git again (and again and again). :-[ See [Resend V2].

Helmut

--
Scanned by MailScanner.

#31 lore raw

PATCH v2 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

In reply to Helmut Raiger

This fixes write access to PMIC registers, the bug was introduced partly in commit 64aac65099 and in commit c9fe76dd91. It was tested on an i.mx31 with a mc13783.

---
V2: threw in the wrong readback line in V1

 drivers/misc/pmic_fsl.c |    5 +----
 drivers/misc/pmic_spi.c |    1 -
 2 files changed, 1 insertions(+), 5 deletions(-)
drivers/misc/pmic_fsl.c +1 -4
index b6e809a..0ff75ed 100644
@@ -29,10 +29,7 @@
 #if defined(CONFIG_PMIC_SPI)
 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 {
-	if ((val == NULL) && (write))
-		return *val & ~(1 << 31);
-	else
-		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+	return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
 }
 #endif
 
drivers/misc/pmic_spi.c +0 -1
index ff35377..e772884 100644
@@ -76,7 +76,6 @@ static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
 	}
 
 	if (write) {
-		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
 		pmic_tx &= ~(1 << 31);
 		tmp = cpu_to_be32(pmic_tx);
 		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
Signature · 6 lines
1.7.4.4



--
Scanned by MailScanner.
#32 lore raw

PATCH RESEND v2 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

In reply to Helmut Raiger

This fixes write access to PMIC registers, the bug was introduced partly in commit 64aac65099 and in commit c9fe76dd91. It was tested on an i.mx31 with a mc13783.

---
V2: threw in the wrong read back line (again and again)

 drivers/misc/pmic_fsl.c |    5 +----
 drivers/misc/pmic_spi.c |    3 +--
 2 files changed, 2 insertions(+), 6 deletions(-)
drivers/misc/pmic_fsl.c +1 -4
index b6e809a..0ff75ed 100644
@@ -29,10 +29,7 @@
 #if defined(CONFIG_PMIC_SPI)
 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 {
-	if ((val == NULL) && (write))
-		return *val & ~(1 << 31);
-	else
-		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+	return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
 }
 #endif
 
drivers/misc/pmic_spi.c +1 -2
index ff35377..5a0dd22 100644
@@ -76,8 +76,7 @@ static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
 	}
 
 	if (write) {
-		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
-		pmic_tx &= ~(1 << 31);
+		pmic_tx = p->hw.spi.prepare_tx(reg, val, 0);
 		tmp = cpu_to_be32(pmic_tx);
 		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
 			pmic_spi_flags)) {
Signature · 6 lines
1.7.4.4



--
Scanned by MailScanner.
#33 lore raw

PATCH RESEND v2 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

Quoted 8 lines · Helmut Raiger

This fixes write access to PMIC registers, the bug was introduced partly in commit 64aac65099 and in commit c9fe76dd91. It was tested on an i.mx31 with a mc13783.

---
V2: threw in the wrong read back line (again and again)

Hi Helmut,

Quoted 25 lines
 drivers/misc/pmic_fsl.c |    5 +----
 drivers/misc/pmic_spi.c |    3 +--
 2 files changed, 2 insertions(+), 6 deletions(-)
drivers/misc/pmic_fsl.c +1 -4
index b6e809a..0ff75ed 100644
@@ -29,10 +29,7 @@
 #if defined(CONFIG_PMIC_SPI)
 static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
 {
-	if ((val == NULL) && (write))
-		return *val & ~(1 << 31);
-	else
-		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+	return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
 }
 #endif
 
drivers/misc/pmic_spi.c +0 -0
index ff35377..5a0dd22 100644

drivers/misc/pmic_spi.c static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write) · line 82

Quoted 9 lines
drivers/misc/pmic_spi.c +1 -2
@@ -76,8 +76,7 @@ static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
 	}
 
 	if (write) {
-		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
-		pmic_tx &= ~(1 << 31);
+		pmic_tx = p->hw.spi.prepare_tx(reg, val, 0);
 		tmp = cpu_to_be32(pmic_tx);
 		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
 			pmic_spi_flags)) {

Right. I wait just a bit for further comments, then I will push to u-boot-imx.

Best regards,
Stefano Babic

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#34 lore raw

PATCH RESEND v2 1/1 misc: pmic: fix regression in pmic_fsl.c (SPI)

In reply to Helmut Raiger
Quoted 7 lines · Helmut Raiger

This fixes write access to PMIC registers, the bug was introduced partly in commit 64aac65099 and in commit c9fe76dd91. It was tested on an i.mx31 with a mc13783.

---
V2: threw in the wrong read back line (again and again)

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#35 lore raw

PATCH v2 9/13 MX5: mx53evk: use new pmic driver

In reply to Stefano Babic

Switch to new pmic generic driver.

---
Changes:

-moved pmic_init into power_init() (Marek Vasut)

 board/freescale/mx53evk/mx53evk.c |   17 +++++++++++------
 include/configs/mx53evk.h         |    5 +++--
 2 files changed, 14 insertions(+), 8 deletions(-)
board/freescale/mx53evk/mx53evk.c +11 -6
index fd821c0..eab9c5f 100644
@@ -32,6 +32,7 @@
 #include <i2c.h>
 #include <mmc.h>
 #include <fsl_esdhc.h>
+#include <pmic.h>
 #include <fsl_pmic.h>
 #include <asm/gpio.h>
 #include <mc13892.h>
@@ -124,12 +125,16 @@ static void setup_i2c(unsigned int port_number)
 void power_init(void)
 {
 	unsigned int val;
+	struct pmic *p;
+
+	pmic_init();
+	p = get_pmic();
 
 	/* Set VDDA to 1.25V */
-	val = pmic_reg_read(REG_SW_2);
+	pmic_reg_read(p, REG_SW_2, &val);
 	val &= ~SWX_OUT_MASK;
 	val |= SWX_OUT_1_25;
-	pmic_reg_write(REG_SW_2, val);
+	pmic_reg_write(p, REG_SW_2, val);
 
 	/*
 	 * Need increase VCC and VDDA to 1.3V
@@ -137,16 +142,16 @@ void power_init(void)
 	 */
 	if (is_soc_rev(CHIP_REV_2_0) == 0) {
 		/* Set VCC to 1.3V for TO2 */
-		val = pmic_reg_read(REG_SW_1);
+		pmic_reg_read(p, REG_SW_1, &val);
 		val &= ~SWX_OUT_MASK;
 		val |= SWX_OUT_1_30;
-		pmic_reg_write(REG_SW_1, val);
+		pmic_reg_write(p, REG_SW_1, val);
 
 		/* Set VDDA to 1.3V for TO2 */
-		val = pmic_reg_read(REG_SW_2);
+		pmic_reg_read(p, REG_SW_2, &val);
 		val &= ~SWX_OUT_MASK;
 		val |= SWX_OUT_1_30;
-		pmic_reg_write(REG_SW_2, val);
+		pmic_reg_write(p, REG_SW_2, val);
 	}
 }
 
include/configs/mx53evk.h +3 -2
index b127b06..dfe07bf 100644
@@ -59,8 +59,9 @@
 #define CONFIG_SYS_I2C_SLAVE            0xfe
 
 /* PMIC Configs */
-#define CONFIG_FSL_PMIC
-#define CONFIG_FSL_PMIC_I2C
+#define CONFIG_PMIC
+#define CONFIG_PMIC_I2C
+#define CONFIG_PMIC_FSL
 #define CONFIG_SYS_FSL_PMIC_I2C_ADDR    8
 
 /* MMC Configs */
Signature · 1 line
1.7.1
#36 lore raw

PATCH v3 5/13 i2c: Create common default i2c_set_bus_num() function

In reply to Stefano Babic

New default, weak i2c_set_bus_num() function.

---
Changes since V2:

- codestyling: drop newline (Heiko Schocher)

Changes since V1:

- add a weak function i2c_set_bus_num() to cmd_i2c.c instead of adding a dummy function to mxc_i2c.c. (Heiko Schocher)

 common/cmd_i2c.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
common/cmd_i2c.c +7 -0
index 3ea75f7..8baa541 100644
@@ -158,6 +158,13 @@ int __def_i2c_set_bus_speed(unsigned int speed)
 int i2c_set_bus_speed(unsigned int)
 	__attribute__((weak, alias("__def_i2c_set_bus_speed")));
 
+int __def_i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
+int i2c_set_bus_num(unsigned int)
+	__attribute__((weak, alias("__def_i2c_set_bus_num")));
+
 /*
  * get_alen: small parser helper function to get address length
  * returns the address length
Signature · 1 line
1.7.1
#37 lore raw

PATCH v3 5/13 i2c: Create common default i2c_set_bus_num() function

common/cmd_i2c.c int __def_i2c_set_bus_speed(unsigned int speed) · line 166

Quoted 6 lines · On Monday 10 October 2011 06:50:12 Stefano Babic wrote:
common/cmd_i2c.c +6 -0
+int __def_i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
+int i2c_set_bus_num(unsigned int)
+	__attribute__((weak, alias("__def_i2c_set_bus_num")));

any reason this can't just be:
__weak int i2c_set_bus_num(unsigned int bus)

{
	return 0;
}

i can understand having a default func when it actually does something, but i don't see much value in a stub that returns 0
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111010/93d9d00b/attachment.pgp

#38 lore raw

PATCH v3 5/13 i2c: Create common default i2c_set_bus_num() function

Quoted 1 line · Mike Frysinger

On Monday 10 October 2011 06:50:12 Stefano Babic wrote:

Hi Mike,

Quoted 9 lines

common/cmd_i2c.c int __def_i2c_set_bus_speed(unsigned int speed) · line 166

Quoted 6 lines
common/cmd_i2c.c +6 -0
+int __def_i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
+int i2c_set_bus_num(unsigned int)
+	__attribute__((weak, alias("__def_i2c_set_bus_num")));

any reason this can't just be:
__weak int i2c_set_bus_num(unsigned int bus)

Quoted 6 lines
{
	return 0;
}

i can understand having a default func when it actually does something, but i don't see much value in a stub that returns 0

It seems to me that this is the commonly used style in u-boot. The same happens for the i2c_init_board, some lines before, and in a lot of other modules:

void __def_i2c_init_board(void)

{
        return;
}
void i2c_init_board(void)
        __attribute__((weak, alias("__def_i2c_init_board")));

Simply grepping in u-boot code, the default function is defined even if it does nothing,

Regards,
Stefano

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#39 lore raw

PATCH v3 5/13 i2c: Create common default i2c_set_bus_num() function

Quoted 25 lines · On Monday 10 October 2011 11:31:39 Stefano Babic wrote:
Quoted 12 lines · Mike Frysinger

common/cmd_i2c.c int __def_i2c_set_bus_speed(unsigned int speed) · line 166

Quoted 6 lines · On Monday 10 October 2011 06:50:12 Stefano Babic wrote:
common/cmd_i2c.c +6 -0
+int __def_i2c_set_bus_num(unsigned int bus)
+{
+	return 0;
+}
+int i2c_set_bus_num(unsigned int)
+	__attribute__((weak, alias("__def_i2c_set_bus_num")));

any reason this can't just be:
__weak int i2c_set_bus_num(unsigned int bus)
{

Quoted 6 lines
	return 0;

}

i can understand having a default func when it actually does something, but i don't see much value in a stub that returns 0

It seems to me that this is the commonly used style in u-boot. The same happens for the i2c_init_board, some lines before, and in a lot of other modules:

void __def_i2c_init_board(void)

Quoted 8 lines
{
        return;
}
void i2c_init_board(void)
        __attribute__((weak, alias("__def_i2c_init_board")));

Simply grepping in u-boot code, the default function is defined even if it does nothing,

i believe we have two standards. i'm not sure which gets used more, or if it's just a wash. i think it makes sense to have an accessible default func if it does something useful, but not if it's just a stub.

in the __def/weak style above, unless people use --gc-sections when linking (i think we've got many people doing this now, but not all), you end up with dead code in the binary. in the code i proposed, the func gets discarded both when using --gc-sections and when not.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111010/836d1287/attachment.pgp

#40 lore raw

PATCH v3 5/13 i2c: Create common default i2c_set_bus_num() function

On 10/10/2011 07:51 PM, Mike Frysinger wrote:

Hi Mike,

Quoted 1 line

i believe we have two standards.

Well, two standards means we have no standard...;-)

Quoted 8 lines

i'm not sure which gets used more, or if
it's just a wash. i think it makes sense to have an accessible default func if it does something useful, but not if it's just a stub.

in the __def/weak style above, unless people use --gc-sections when linking (i think we've got many people doing this now, but not all), you end up with dead code in the binary. in the code i proposed, the func gets discarded both when using --gc-sections and when not.

You are right, but probably it makes no difference. I checked and it seems that only a few architectute (m68k, sparc and microblaze) do not set --gc-sections.

After the Heiko's post and our discussion, I think that this patch is another work-around waiting for the Heiko's patches to go to mainline. And it becomes a second work-around, because there is already the I2C_SET_BUS() for boards supporting only one bus. Two work-around are too much...

I drop this patch and I will make use of I2C_SET_BUS() in pmic. This is coherent with the actual u-boot code.

Regards,
Stefano

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-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#41 lore raw

PATCH v3 5/13 i2c: Create common default i2c_set_bus_num() function

Quoted 5 lines · On Tuesday 11 October 2011 13:30:24 Stefano Babic wrote:
Quoted 4 lines · Mike Frysinger

i'm not sure which gets used more, or if
it's just a wash. i think it makes sense to have an accessible default func if it does something useful, but not if it's just a stub.

Quoted 8 lines
Quoted 4 lines

in the __def/weak style above, unless people use --gc-sections when linking (i think we've got many people doing this now, but not all), you end up with dead code in the binary. in the code i proposed, the func gets discarded both when using --gc-sections and when not.

You are right, but probably it makes no difference. I checked and it seems that only a few architectute (m68k, sparc and microblaze) do not set --gc-sections.

i would think the microblaze missing would be an oversight as it's "newer" code. don't know (or honestly, care) how hard it would be to make m68k/sparc sane. but it would be nice to get everyone using gc-sections as we could move that into common code and all new arches would start out sane ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111011/9ca332d2/attachment.pgp