All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] sun6i: axp221: Add axp221_get_sid function
@ 2014-11-26 12:36 Hans de Goede
  2014-11-26 12:36 ` [U-Boot] [PATCH 2/2] sunxi: Add sunxi_get_sid helper function Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: Hans de Goede @ 2014-11-26 12:36 UTC (permalink / raw)
  To: u-boot

For sun6i the SID is stored in the pmic, rather then in the SoC itself,
add a function to retreive the sid.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/power/axp221.c | 27 +++++++++++++++++++++++++++
 include/axp221.h       |  6 ++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c
index 941193a..826567a 100644
--- a/drivers/power/axp221.c
+++ b/drivers/power/axp221.c
@@ -184,3 +184,30 @@ int axp221_init(void)
 
 	return 0;
 }
+
+int axp221_get_sid(unsigned int *sid)
+{
+	u8 *dest = (u8 *)sid;
+	int i, ret;
+
+	ret = axp221_init();
+	if (ret)
+		return ret;
+
+	ret = p2wi_write(AXP221_PAGE, 1);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < 16; i++) {
+		ret = p2wi_read(AXP221_SID + i, &dest[i]);
+		if (ret)
+			return ret;
+	}
+
+	p2wi_write(AXP221_PAGE, 0);
+
+	for (i = 0; i < 4; i++)
+		sid[i] = be32_to_cpu(sid[i]);
+
+	return 0;
+}
diff --git a/include/axp221.h b/include/axp221.h
index e3b4409..db219c6 100644
--- a/include/axp221.h
+++ b/include/axp221.h
@@ -10,6 +10,7 @@
 #define AXP221_CTRL_ADDR 0x3e
 #define AXP221_INIT_DATA 0x3e
 
+/* Page 0 addresses */
 #define AXP221_CHIP_ID		0x03
 #define AXP221_OUTPUT_CTRL1	0x10
 #define AXP221_OUTPUT_CTRL1_ALDO1_EN	(1 << 6)
@@ -34,6 +35,10 @@
 #define AXP221_ALDO1_CTRL	0x28
 #define AXP221_ALDO2_CTRL	0x28
 #define AXP221_ALDO3_CTRL	0x2a
+#define AXP221_PAGE		0xff
+
+/* Page 1 addresses */
+#define AXP221_SID		0x20
 
 int axp221_set_dcdc1(unsigned int mvolt);
 int axp221_set_dcdc2(unsigned int mvolt);
@@ -48,3 +53,4 @@ int axp221_set_aldo1(unsigned int mvolt);
 int axp221_set_aldo2(unsigned int mvolt);
 int axp221_set_aldo3(unsigned int mvolt);
 int axp221_init(void);
+int axp221_get_sid(unsigned int *sid);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH 2/2] sunxi: Add sunxi_get_sid helper function
  2014-11-26 12:36 [U-Boot] [PATCH 1/2] sun6i: axp221: Add axp221_get_sid function Hans de Goede
@ 2014-11-26 12:36 ` Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2014-11-26 12:36 UTC (permalink / raw)
  To: u-boot

On sun6i the SID is stored in the pmic, rather then in the SoC itself,
add a helper function to abstract this away.

This makes our MAC address generation code also work on sun6i.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 arch/arm/cpu/armv7/sunxi/cpu_info.c   | 19 +++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/cpu.h |  1 +
 board/sunxi/board.c                   | 24 +++++++++++-------------
 3 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/arch/arm/cpu/armv7/sunxi/cpu_info.c b/arch/arm/cpu/armv7/sunxi/cpu_info.c
index 5146dc4..7a3a4ca 100644
--- a/arch/arm/cpu/armv7/sunxi/cpu_info.c
+++ b/arch/arm/cpu/armv7/sunxi/cpu_info.c
@@ -10,6 +10,7 @@
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/clock.h>
+#include <axp221.h>
 
 #ifdef CONFIG_MACH_SUN6I
 int sunxi_get_ss_bonding_id(void)
@@ -72,3 +73,21 @@ int print_cpuinfo(void)
 	return 0;
 }
 #endif
+
+int sunxi_get_sid(unsigned int *sid)
+{
+#ifdef CONFIG_MACH_SUN6I
+#ifdef CONFIG_AXP221_POWER
+	return axp221_get_sid(sid);
+#else
+	return -ENODEV;
+#endif
+#else
+	int i;
+
+	for (i = 0; i< 4; i++)
+		sid[i] = readl(SUNXI_SID_BASE + 4 * i);
+
+	return 0;
+#endif
+}
diff --git a/arch/arm/include/asm/arch-sunxi/cpu.h b/arch/arm/include/asm/arch-sunxi/cpu.h
index 8aeed2f..9500262 100644
--- a/arch/arm/include/asm/arch-sunxi/cpu.h
+++ b/arch/arm/include/asm/arch-sunxi/cpu.h
@@ -147,6 +147,7 @@
 void sunxi_board_init(void);
 void sunxi_reset(void);
 int sunxi_get_ss_bonding_id(void);
+int sunxi_get_sid(unsigned int *sid);
 #endif /* __ASSEMBLY__ */
 
 #endif /* _CPU_H */
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 4c1c69a..b5dfe95 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -217,22 +217,20 @@ void sunxi_board_init(void)
 #ifdef CONFIG_MISC_INIT_R
 int misc_init_r(void)
 {
-	if (!getenv("ethaddr")) {
-		uint32_t reg_val = readl(SUNXI_SID_BASE);
+	unsigned int sid[4];
 
-		if (reg_val) {
-			uint8_t mac_addr[6];
+	if (!getenv("ethaddr") && sunxi_get_sid(sid) == 0 &&
+			sid[0] != 0 && sid[3] != 0) {
+		uint8_t mac_addr[6];
 
-			mac_addr[0] = 0x02; /* Non OUI / registered MAC address */
-			mac_addr[1] = (reg_val >>  0) & 0xff;
-			reg_val = readl(SUNXI_SID_BASE + 0x0c);
-			mac_addr[2] = (reg_val >> 24) & 0xff;
-			mac_addr[3] = (reg_val >> 16) & 0xff;
-			mac_addr[4] = (reg_val >>  8) & 0xff;
-			mac_addr[5] = (reg_val >>  0) & 0xff;
+		mac_addr[0] = 0x02; /* Non OUI / registered MAC address */
+		mac_addr[1] = (sid[0] >>  0) & 0xff;
+		mac_addr[2] = (sid[3] >> 24) & 0xff;
+		mac_addr[3] = (sid[3] >> 16) & 0xff;
+		mac_addr[4] = (sid[3] >>  8) & 0xff;
+		mac_addr[5] = (sid[3] >>  0) & 0xff;
 
-			eth_setenv_enetaddr("ethaddr", mac_addr);
-		}
+		eth_setenv_enetaddr("ethaddr", mac_addr);
 	}
 
 	return 0;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-26 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-26 12:36 [U-Boot] [PATCH 1/2] sun6i: axp221: Add axp221_get_sid function Hans de Goede
2014-11-26 12:36 ` [U-Boot] [PATCH 2/2] sunxi: Add sunxi_get_sid helper function Hans de Goede

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.