starfive reboot cleanup & fix
v4 cover starfive reboot cleanup & fix
This series:
- Rename device tree compatible strings to match U-Boot
- Fix code that extract I2C address from device tree
- Cleanup
The device tree nodes in this series have just been merged to U-Boot a few days ago. So please use most recent upstream U-Boot for testing this series.
Nam Cao (7):
platform: starfive: correct system clock device tree node
platform: starfive: get I2C offset address from clocks property
platform: starfive: remove redundant compatibility check in pmic_ops
platform: starfive: rename "stf,axp15060-regulator" ->
"x-powers,axp15060"
platform: starfive: drop "compatible" from struct pmic
platform: starfive: return error if needed devices are not present
platform: starfive: call starfive_jh7110_inst_init() in
pm_reset_init()platform/generic/starfive/jh7110.c | 71 ++++++++++++++++-------------- 1 file changed, 38 insertions(+), 33 deletions(-)
Signature · 1 line
2.39.2
PATCH v4 1/7 platform: starfive: correct system clock device tree node
Starfive names the system clock device tree node "starfive,jh7110-clkgen" in all their git repositories. However, a different name is used in upstream U-Boot (and also Linux): "starfive,jh7110-syscrg". Since OpenSBI gets the device tree from U-Boot, this inconsistency leads the problem that OpenSBI doesn't know the system clock device exists.
Correct this name to keep the consistency.
--- platform/generic/starfive/jh7110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
platform/generic/starfive/jh7110.c +1 -1
@@ -252,7 +252,7 @@ static int starfive_jh7110_inst_init(void *fdt) jh7110_inst.pmu_reg_base = addr; } - noff =fdt_node_offset_by_compatible (fdt,-1 ,"starfive,jh7110-clkgen" ); + noff =fdt_node_offset_by_compatible (fdt,-1 ,"starfive,jh7110-syscrg" );if (-1 < noff) { rc =fdt_get_node_addr_size (fdt, noff,0 , &addr,NULL );if (rc)
Signature · 1 line
2.39.2
PATCH v4 1/7 platform: starfive: correct system clock device tree node
Quoted 31 lines
Starfive names the system clock device tree node "starfive,jh7110-clkgen" in all their git repositories. However, a different name is used in upstream U-Boot (and also Linux): "starfive,jh7110-syscrg". Since OpenSBI gets the device tree from U-Boot, this inconsistency leads the problem that OpenSBI doesn't know the system clock device exists.
Correct this name to keep the consistency.
Signed-off-by Nam Cao <[email protected]>--- platform/generic/starfive/jh7110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)platform/generic/starfive/jh7110.c +2
-2@@ -252,7 +252,7 @@ static int starfive_jh7110_inst_init(void *fdt) jh7110_inst.pmu_reg_base = addr; } - noff =fdt_node_offset_by_compatible (fdt,-1 ,"starfive,jh7110-clkgen" ); + noff =fdt_node_offset_by_compatible (fdt,-1 , +"starfive,jh7110-syscrg" );if (-1 < noff) { rc =fdt_get_node_addr_size (fdt, noff,0 , &addr,NULL );if (rc) --
Quoted 1 line
2.39.2
The clock compatible is the same with upstream uboot and linux
PATCH v4 2/7 platform: starfive: get I2C offset address from clocks property
In reply to Nam CaoThe current code gets the I2C offset address using the device tree node
name: it get the I2C device index from the 4th character in the node name (for example, "i2c5" -> i2c device 5). However, the device tree node's name in U-Boot is actually just "i2c" without the number, so the current code cannot be used with the device tree from U-Boot.
Get the I2C offset address from the "clocks" property instead.
--- platform/generic/starfive/jh7110.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
platform/generic/starfive/jh7110.c +10 -10
@@ -29,7 +29,7 @@ struct pmic {struct jh7110 {u64 pmu_reg_base;u64 clk_reg_base; -u32 i2c_index; +u32 i2c_clk_offset; };static struct pmic pmic_inst;
@@ -67,7 +67,6 @@ static u32 selected_hartid = -1;#define AXP15060_POWER_OFF_BIT BIT(7)#define AXP15060_RESET_BIT BIT(6) -#define I2C_APB_CLK_OFFSET 0x228#define I2C_APB_CLK_ENABLE_BIT BIT(31)static int pm_system_reset_check (u32 type,u32 reason)
@@ -163,10 +162,7 @@ static void pmic_i2c_clk_enable(void)unsigned long clock_base;unsigned int val; - clock_base = jh7110_inst.clk_reg_base + -I2C_APB_CLK_OFFSET + - (jh7110_inst.i2c_index <<2 ); - + clock_base = jh7110_inst.clk_reg_base + jh7110_inst.i2c_clk_offset; val =readl ((void *)clock_base);if (!val)
@@ -241,7 +237,8 @@ static struct fdt_reset fdt_reset_pmic = {static int starfive_jh7110_inst_init (void *fdt) {int noff, rc =0 ; -const char *name; +const fdt32_t *val; +int len;u64 addr; noff =fdt_node_offset_by_compatible (fdt,-1 ,"starfive,jh7110-pmu" );
@@ -261,9 +258,12 @@ static int starfive_jh7110_inst_init(void *fdt) }if (pmic_inst.adapter) { - name =fdt_get_name (fdt, pmic_inst.adapter->id,NULL ); -if (!sbi_strncmp (name,"i2c" ,3 )) - jh7110_inst.i2c_index = name[3 ] -'0' ; + val =fdt_getprop (fdt, pmic_inst.adapter->id,"clocks" , &len); +/* The clocks property looks like this: clocks = <&syscrg JH7110_SYSCLK_I2C5_APB>; +* So check that the length is 8 bytes, and get the offset from the second value +*/ +if (val && len ==8 ) + jh7110_inst.i2c_clk_offset =fdt32_to_cpu (val[1 ]) <<2 ;else rc =SBI_EINVAL ; }
Signature · 1 line
2.39.2
PATCH v4 3/7 platform: starfive: remove redundant compatibility check in pmic_ops
In reply to Nam Caopmic_ops() is only called if a compatible device is found in device tree. It is redundant for this function to check the compability again. Remove this check.
--- platform/generic/starfive/jh7110.c | 36 ++++++++++++++---------------- 1 file changed, 17 insertions(+), 19 deletions(-)
platform/generic/starfive/jh7110.c +17 -19
@@ -133,28 +133,26 @@ static void pmic_ops(struct pmic *pmic, int type)if (ret)return ; -if (!sbi_strcmp ("stf,axp15060-regulator" , pmic->compatible)) { - ret =i2c_adapter_reg_read (pmic->adapter, pmic->dev_addr, -AXP15060_POWER_REG , &val); - -if (ret) { -sbi_printf ("%s: cannot read pmic power register\n" , - __func__); -return ; - } + ret =i2c_adapter_reg_read (pmic->adapter, pmic->dev_addr, +AXP15060_POWER_REG , &val); + +if (ret) { +sbi_printf ("%s: cannot read pmic power register\n" , + __func__); +return ; + } + val |=AXP15060_POWER_OFF_BIT ; +if (type ==SBI_SRST_RESET_TYPE_SHUTDOWN ) val |=AXP15060_POWER_OFF_BIT ; -if (type ==SBI_SRST_RESET_TYPE_SHUTDOWN ) - val |=AXP15060_POWER_OFF_BIT ; -else - val |=AXP15060_RESET_BIT ; +else + val |=AXP15060_RESET_BIT ; - ret =i2c_adapter_reg_write (pmic->adapter, pmic->dev_addr, -AXP15060_POWER_REG , val); -if (ret) -sbi_printf ("%s: cannot write pmic power register\n" , - __func__); - } + ret =i2c_adapter_reg_write (pmic->adapter, pmic->dev_addr, +AXP15060_POWER_REG , val); +if (ret) +sbi_printf ("%s: cannot write pmic power register\n" , + __func__); }static void pmic_i2c_clk_enable (void )
Signature · 1 line
2.39.2
PATCH v4 4/7 platform: starfive: rename "stf,axp15060-regulator" -> "x-powers,axp15060"
In reply to Nam CaoOpenSBI uses the device tree compatible string "stf,axp15060-regulator" for the regulator node. However, the string used by U-Boot (and Linux) is actually "x-powers,axp15060". As OpenSBI gets the device tree from U-Boot, this causes the regulator device to be undetected, and OpenSBI does not use this device to perform board reset/shutdown.
Rename this device tree compatible string to match U-Boot (and Linux).
--- platform/generic/starfive/jh7110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
platform/generic/starfive/jh7110.c +1 -1
@@ -223,7 +223,7 @@ static int pm_reset_init(void *fdt, int nodeoff, }static const struct fdt_match pm_reset_match[] = { - { .compatible ="stf,axp15060-regulator" , .data = (void *)true }, + { .compatible ="x-powers,axp15060" , .data = (void *)true }, { }, };
Signature · 1 line
2.39.2
PATCH v4 4/7 platform: starfive: rename "stf,axp15060-regulator" -> "x-powers,axp15060"
Quoted 29 lines
OpenSBI uses the device tree compatible string "stf,axp15060-regulator" for the regulator node. However, the string used by U-Boot (and Linux) is actually "x-powers,axp15060". As OpenSBI gets the device tree from U-Boot, this causes the regulator device to be undetected, and OpenSBI does not use this device to perform board reset/shutdown.
Rename this device tree compatible string to match U-Boot (and Linux).
Signed-off-by Nam Cao <[email protected]>--- platform/generic/starfive/jh7110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)platform/generic/starfive/jh7110.c +1
-2@@ -223,7 +223,7 @@ static int pm_reset_init(void *fdt, int nodeoff, }static const struct fdt_match pm_reset_match[] = { - { .compatible ="stf,axp15060-regulator" , .data = (void *)true }, + { .compatible ="x-powers,axp15060" , .data = (void *)true }, { }, }; --
Quoted 1 line
2.39.2
The pmic compatible is the same with upstream uboot and linux
PATCH v4 5/7 platform: starfive: drop "compatible" from struct pmic
In reply to Nam CaoThe member "compatible" of struct pmic is not used. Delete it.
--- platform/generic/starfive/jh7110.c | 2 -- 1 file changed, 2 deletions(-)
platform/generic/starfive/jh7110.c +0 -2
@@ -23,7 +23,6 @@struct pmic {struct i2c_adapter *adapter;u32 dev_addr; -const char *compatible; };struct jh7110 {
@@ -204,7 +203,6 @@ static int pm_reset_init(void *fdt, int nodeoff,return rc; pmic_inst.dev_addr = addr; - pmic_inst.compatible = match->compatible; i2c_bus =fdt_parent_offset (fdt, nodeoff);if (i2c_bus <0 )
Signature · 1 line
2.39.2
PATCH v4 6/7 platform: starfive: return error if needed devices are not present
In reply to Nam CaoJh7110's reset driver needs power management device and clock controller device to work. Currently, the driver proceed anyway without these devices, and invalid addresses (jh7110_inst.pmu_reg_base and jh7110_inst.clk_reg_base) are used during reboot, which causes unpredictable broken behaviors.
If these devices are not present, return -SBI_ENODEV.
--- platform/generic/starfive/jh7110.c | 4 ++++ 1 file changed, 4 insertions(+)
platform/generic/starfive/jh7110.c +4 -0
@@ -243,6 +243,8 @@ static int starfive_jh7110_inst_init(void *fdt)if (rc) goto err; jh7110_inst.pmu_reg_base = addr; + }else { +return -SBI_ENODEV ; } noff =fdt_node_offset_by_compatible (fdt,-1 ,"starfive,jh7110-syscrg" );
@@ -251,6 +253,8 @@ static int starfive_jh7110_inst_init(void *fdt)if (rc) goto err; jh7110_inst.clk_reg_base = addr; + }else { +return -SBI_ENODEV ; }if (pmic_inst.adapter) {
Signature · 1 line
2.39.2
PATCH v4 7/7 platform: starfive: call starfive_jh7110_inst_init() in pm_reset_init()
In reply to Nam CaoThe function starfive_jh7110_inst_init() initialize some power management unit address and clock addresses, needed for the reset driver. It doesn't do anything else, and also the reset driver doesn't work without calling this function. Thus, it does not make much sense that this function is independent from pm_reset_init().
Delete the separate call to starfive_jh7110_inst_init(), and instead just call this function inside pm_reset_init().
Doing this also fixes another problem: if starfive_jh7110_inst_init() returns an error code, it gets propagated to final_init() and OpenSBI hangs. This hang is not necessary, because failures within starfive_jh7110_inst_init() only mean OpenSBI cannot perform reboot or shutdown, but the system can still function normally.
--- platform/generic/starfive/jh7110.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
platform/generic/starfive/jh7110.c +6 -1
@@ -190,6 +190,8 @@ static struct sbi_system_reset_device pm_reset = { .system_reset = pm_system_reset }; +static int starfive_jh7110_inst_init (void *fdt); +static int pm_reset_init (void *fdt,int nodeoff,const struct fdt_match *match) {
@@ -215,6 +217,10 @@ static int pm_reset_init(void *fdt, int nodeoff, pmic_inst.adapter = adapter; + rc =starfive_jh7110_inst_init (fdt); +if (rc) +return rc; +sbi_system_reset_add_device (&pm_reset);return 0 ;
@@ -278,7 +284,6 @@ static int starfive_jh7110_final_init(bool cold_boot,if (cold_boot) {fdt_reset_driver_init (fdt, &fdt_reset_pmic); -return starfive_jh7110_inst_init (fdt); }return 0 ;
Signature · 1 line
2.39.2
PATCH v4 7/7 platform: starfive: call starfive_jh7110_inst_init() in pm_reset_init()
Quoted 57 lines
The function
starfive_jh7110_inst_init()initialize some power management unit address and clock addresses, needed for the reset driver. It doesn't do anything else, and also the reset driver doesn't work without calling this function. Thus, it does not make much sense that this function is independent frompm_reset_init().Delete the separate call to
starfive_jh7110_inst_init(), and instead just call this function insidepm_reset_init().Doing this also fixes another problem: if
starfive_jh7110_inst_init()returns an error code, it gets propagated tofinal_init()and OpenSBI hangs. This hang is not necessary, because failures withinstarfive_jh7110_inst_init()only mean OpenSBI cannot perform reboot or shutdown, but the system can still function normally.Signed-off-by Nam Cao <[email protected]>--- platform/generic/starfive/jh7110.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)platform/generic/starfive/jh7110.c +6
-2@@ -190,6 +190,8 @@ static struct sbi_system_reset_device pm_reset = { .system_reset = pm_system_reset }; +static int starfive_jh7110_inst_init (void *fdt); +static int pm_reset_init (void *fdt,int nodeoff,const struct fdt_match *match) {@@ -215,6 +217,10 @@ static int pm_reset_init(void *fdt, int nodeoff, pmic_inst.adapter = adapter; + rc =starfive_jh7110_inst_init (fdt); +if (rc) +return rc; +sbi_system_reset_add_device (&pm_reset);return 0 ;@@ -278,7 +284,6 @@ static int starfive_jh7110_final_init(bool cold_boot,if (cold_boot) {fdt_reset_driver_init (fdt, &fdt_reset_pmic); -return starfive_jh7110_inst_init (fdt); }return 0 ; --
Quoted 1 line
2.39.2