diff options
author | Roland Hieber <r.hieber@pengutronix.de> | 2018-08-13 15:02:53 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-08-14 08:54:40 +0200 |
commit | e85280472f58496f451d75ad139aedba3793ab91 (patch) | |
tree | 680e3275b5c49f976685094db4aef31b91a5ce0f /arch/arm/mach-mxs | |
parent | 7158c5987e6999f1fd89b7170c685a7b29bc8322 (diff) | |
download | barebox-e85280472f58496f451d75ad139aedba3793ab91.tar.gz barebox-e85280472f58496f451d75ad139aedba3793ab91.tar.xz |
ARM: MXS: refactor mx2*_power_init source configuration
Having three ints as parameter suggests that we can use up to 2^3
power configurations for the system, but when we look at the code, the
power setup is packaged in if {...} else if {...} else if {...} blocks,
so setting more than one parameter to 1 is useless here.
Refactor the parameters into an enum to get rid of that suggestion.
Signed-off-by: Roland Hieber <r.hieber@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-mxs')
-rw-r--r-- | arch/arm/mach-mxs/include/mach/init.h | 24 | ||||
-rw-r--r-- | arch/arm/mach-mxs/power-init.c | 49 |
2 files changed, 37 insertions, 36 deletions
diff --git a/arch/arm/mach-mxs/include/mach/init.h b/arch/arm/mach-mxs/include/mach/init.h index 66dfd635de..878cf4ad62 100644 --- a/arch/arm/mach-mxs/include/mach/init.h +++ b/arch/arm/mach-mxs/include/mach/init.h @@ -12,10 +12,26 @@ void mxs_early_delay(int delay); -void mx23_power_init(int __has_battery, int __use_battery_input, - int __use_5v_input); -void mx28_power_init(int __has_battery, int __use_battery_input, - int __use_5v_input); +/** + * Power configuration of the system: + * - POWER_USE_5V: use 5V input as power supply + * - POWER_USE_BATTERY: use battery input when the system is supplied by a battery + * - POWER_USE_BATTERY_INPUT: use battery input when the system is supplied by + * a DC source (instead of a real battery) on the battery input + */ +enum mxs_power_config { + POWER_USE_5V = 0b00000000, + POWER_USE_BATTERY = 0b00000001, + POWER_USE_BATTERY_INPUT = 0b00000010, +}; +extern int power_config; +static inline enum mxs_power_config mxs_power_config_get_use(void) { + return (power_config & 0b00000011); +} + + +void mx23_power_init(const int config); +void mx28_power_init(const int config); void mxs_power_wait_pswitch(void); extern const uint32_t mx28_dram_vals_default[190]; diff --git a/arch/arm/mach-mxs/power-init.c b/arch/arm/mach-mxs/power-init.c index 595b51c5ba..14f9b7cca7 100644 --- a/arch/arm/mach-mxs/power-init.c +++ b/arch/arm/mach-mxs/power-init.c @@ -24,21 +24,7 @@ #include <mach/regs-rtc.h> #include <mach/regs-lradc.h> -/* - * has_battery - true when this board has a battery. - */ -static int has_battery; - -/* - * use_battery_input - true when this board is supplied from the - * battery input, but has a DC source instead of a real battery - */ -static int use_battery_input; - -/* - * use_5v_input - true when this board can use the 5V input - */ -static int use_5v_input; +int power_config; static void mxs_power_status(void) { @@ -514,7 +500,8 @@ static void mxs_power_enable_4p2(void) POWER_5VCTRL_HEADROOM_ADJ_MASK, 0x4 << POWER_5VCTRL_HEADROOM_ADJ_OFFSET); - if (has_battery || use_battery_input) + if (mxs_power_config_get_use() == POWER_USE_BATTERY || + mxs_power_config_get_use() == POWER_USE_BATTERY_INPUT) dropout_ctrl = POWER_DCDC4P2_DROPOUT_CTRL_SRC_SEL; else dropout_ctrl = POWER_DCDC4P2_DROPOUT_CTRL_SRC_4P2; @@ -1182,16 +1169,15 @@ static void mx23_ungate_power(void) * * This function calls all the power block initialization functions in * proper sequence to start the power block. + * + * @config: see enum mxs_power_config for possible options */ -void mx23_power_init(int __has_battery, int __use_battery_input, - int __use_5v_input) +void mx23_power_init(const int config) { struct mxs_power_regs *power_regs = (struct mxs_power_regs *)IMX_POWER_BASE; - has_battery = __has_battery; - use_battery_input = __use_battery_input; - use_5v_input = __use_5v_input; + power_config = config; mx23_ungate_power(); @@ -1204,11 +1190,11 @@ void mx23_power_init(int __has_battery, int __use_battery_input, mxs_src_power_init(); - if (has_battery) + if (mxs_power_config_get_use() == POWER_USE_BATTERY) mxs_power_configure_power_source(); - else if (use_battery_input) + else if (mxs_power_config_get_use() == POWER_USE_BATTERY_INPUT) mxs_enable_battery_input(); - else if (use_5v_input) + else if (mxs_power_config_get_use() == POWER_USE_5V) mxs_boot_valid_5v(); mxs_power_clock2pll(); @@ -1243,16 +1229,15 @@ void mx23_power_init(int __has_battery, int __use_battery_input, * * This function calls all the power block initialization functions in * proper sequence to start the power block. + * + * @config: see enum mxs_power_config for possible options */ -void mx28_power_init(int __has_battery, int __use_battery_input, - int __use_5v_input) +void mx28_power_init(const int config) { struct mxs_power_regs *power_regs = (struct mxs_power_regs *)IMX_POWER_BASE; - has_battery = __has_battery; - use_battery_input = __use_battery_input; - use_5v_input = __use_5v_input; + power_config = config; mxs_power_status(); mxs_power_clock2xtal(); @@ -1264,11 +1249,11 @@ void mx28_power_init(int __has_battery, int __use_battery_input, mxs_src_power_init(); - if (has_battery) + if (mxs_power_config_get_use() == POWER_USE_BATTERY) mxs_power_configure_power_source(); - else if (use_battery_input) + else if (mxs_power_config_get_use() == POWER_USE_BATTERY_INPUT) mxs_enable_battery_input(); - else if (use_5v_input) + else if (mxs_power_config_get_use() == POWER_USE_5V) mxs_boot_valid_5v(); mxs_power_clock2pll(); |