sun6i: axp221: Add axp221_get_sid function
Subsystems (3)
PATCH 1/2 sun6i: axp221: Add axp221_get_sid function
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 <[email protected]>
--- drivers/power/axp221.c | 27 +++++++++++++++++++++++++++ include/axp221.h | 6 ++++++ 2 files changed, 33 insertions(+)
drivers/power/axp221.c +27 -0
@@ -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 ; +}
include/axp221.h +6 -0
@@ -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 0x20int 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);
Signature · 1 line
2.1.0
PATCH 2/2 sunxi: Add sunxi_get_sid helper function
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 <[email protected]>
--- 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(-)
arch/arm/cpu/armv7/sunxi/cpu_info.c +19 -0
@@ -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 +}
arch/arm/include/asm/arch-sunxi/cpu.h +1 -0
@@ -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 */
board/sunxi/board.c +11 -13
@@ -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 ;
Signature · 1 line
2.1.0