diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c index cb370c0625..1c70af54ef 100644 --- a/arch/arm/mach-rockchip/spl.c +++ b/arch/arm/mach-rockchip/spl.c @@ -265,13 +265,10 @@ void spl_perform_fixups(struct spl_image_info *spl_image) #ifdef CONFIG_SPL_KERNEL_BOOT static int spl_rockchip_dnl_key_pressed(void) { - int key = false; -#if defined(CONFIG_DM_KEY) && defined(CONFIG_SPL_INPUT) - key = key_read(KEY_VOLUMEUP); - - return key_is_pressed(key); +#if defined(CONFIG_SPL_INPUT) + return key_read(KEY_VOLUMEUP); #else - return key; + return 0; #endif } diff --git a/common/image-fit.c b/common/image-fit.c index d0403e5e47..259ac75792 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1925,6 +1925,13 @@ static const char *fit_get_image_type_property(int type) return "unknown"; } +#ifndef USE_HOSTCC +__weak int fit_board_verify_required_sigs(void) +{ + return 0; +} +#endif + int fit_image_load_index(bootm_headers_t *images, ulong addr, const char **fit_unamep, const char **fit_uname_configp, int arch, int image_type, int image_index, int bootstage_id, @@ -1946,6 +1953,15 @@ int fit_image_load_index(bootm_headers_t *images, ulong addr, const char *prop_name; int ret; +#ifndef USE_HOSTCC + /* If board required sigs, check self */ + if (fit_board_verify_required_sigs() && + !IS_ENABLED(CONFIG_FIT_SIGNATURE)) { + printf("Verified-boot requires CONFIG_FIT_SIGNATURE enabled\n"); + hang(); + } +#endif + fit = map_sysmem(addr, 0); fit_uname = fit_unamep ? *fit_unamep : NULL; fit_uname_config = fit_uname_configp ? *fit_uname_configp : NULL; diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index d36b1565d3..7b30ad331b 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -401,6 +401,13 @@ static int spl_internal_load_simple_fit(struct spl_image_info *spl_image, return -1; } + /* if board sigs verify required, check self */ + if (fit_board_verify_required_sigs() && + !IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) { + printf("Verified-boot requires CONFIG_SPL_FIT_SIGNATURE enabled\n"); + hang(); + } + /* verify the configure node by keys, if required */ #ifdef CONFIG_SPL_FIT_SIGNATURE int conf_noffset; diff --git a/drivers/adc/Kconfig b/drivers/adc/Kconfig index 8094420548..2130cbbbca 100644 --- a/drivers/adc/Kconfig +++ b/drivers/adc/Kconfig @@ -11,6 +11,13 @@ config ADC - support supply's phandle with auto-enable - supply polarity setting in fdt +config ADC_REQ_REGULATOR + bool "Enable regulator control for ADC drivers" + depends on ADC + default n + help + ADC may depend on regulator power supply and require control. + config ADC_EXYNOS bool "Enable Exynos 54xx ADC driver" help diff --git a/drivers/adc/adc-uclass.c b/drivers/adc/adc-uclass.c index a4c20f4d35..e8c7262b09 100644 --- a/drivers/adc/adc-uclass.c +++ b/drivers/adc/adc-uclass.c @@ -47,6 +47,7 @@ static int check_channel(struct udevice *dev, int value, bool number_or_mask, return -EINVAL; } +#ifdef CONFIG_ADC_REQ_REGULATOR static int adc_supply_enable(struct udevice *dev) { struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev); @@ -68,6 +69,9 @@ static int adc_supply_enable(struct udevice *dev) return ret; } +#else +static inline int adc_supply_enable(struct udevice *dev) { return 0; } +#endif int adc_data_mask(struct udevice *dev, unsigned int *data_mask) { @@ -256,6 +260,7 @@ try_manual: return _adc_channels_single_shot(dev, channel_mask, channels); } +#ifdef CONFIG_ADC_REQ_REGULATOR static int adc_vdd_platdata_update(struct udevice *dev) { struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev); @@ -280,7 +285,11 @@ static int adc_vdd_platdata_update(struct udevice *dev) return 0; } +#else +static inline int adc_vdd_platdata_update(struct udevice *dev) { return 0; } +#endif +#ifdef CONFIG_ADC_REQ_REGULATOR static int adc_vss_platdata_update(struct udevice *dev) { struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev); @@ -299,6 +308,9 @@ static int adc_vss_platdata_update(struct udevice *dev) return 0; } +#else +static inline int adc_vss_platdata_update(struct udevice *dev) { return 0; } +#endif int adc_vdd_value(struct udevice *dev, int *uV) { diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 2c6a1e24dc..ab432429aa 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -105,6 +105,12 @@ config ADC_KEY help This adds a driver for the adc keys support. +config SPL_ADC_KEY + bool "Enable SPL adc keys support without DM" + depends on SPL_INPUT + help + This adds a driver for the SPL adc keys support + config GPIO_KEY bool "Enable gpio keys support" depends on DM_KEY diff --git a/drivers/input/Makefile b/drivers/input/Makefile index 3d6469cd70..d7ce0f3c73 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -5,7 +5,7 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-$(CONFIG_DM_KEY) += key-uclass.o +obj-$(CONFIG_$(SPL_)DM_KEY) += key-uclass.o obj-$(CONFIG_DM_RC) += rc-uclass.o obj-$(CONFIG_RK_IR) += rockchip_ir.o @@ -13,7 +13,6 @@ obj-y += input.o obj-$(CONFIG_$(SPL_TPL_)CROS_EC_KEYB) += cros_ec_keyb.o obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += key_matrix.o obj-$(CONFIG_$(SPL_TPL_)DM_KEYBOARD) += keyboard-uclass.o -obj-$(CONFIG_RK8XX_PWRKEY) += rk8xx_pwrkey.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_I8042_KEYB) += i8042.o @@ -21,12 +20,15 @@ obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o obj-$(CONFIG_TWL4030_INPUT) += twl4030.o obj-$(CONFIG_TWL6030_INPUT) += twl6030.o obj-$(CONFIG_RK8XX_PWRKEY) += rk8xx_pwrkey.o +obj-$(CONFIG_ADC_KEY) += adc_key.o +obj-$(CONFIG_GPIO_KEY) += gpio_key.o +obj-$(CONFIG_RK_KEY) += rk_key.o +obj-$(CONFIG_RK8XX_PWRKEY) += rk8xx_pwrkey.o ifdef CONFIG_PS2KBD obj-y += keyboard.o pc_keyb.o obj-$(CONFIG_PS2MULT) += ps2mult.o ps2ser.o endif -endif -obj-$(CONFIG_ADC_KEY) += adc_key.o -obj-$(CONFIG_GPIO_KEY) += gpio_key.o -obj-$(CONFIG_RK_KEY) += rk_key.o +else +obj-$(CONFIG_SPL_ADC_KEY) += spl_adc_key.o +endif diff --git a/drivers/input/spl_adc_key.c b/drivers/input/spl_adc_key.c new file mode 100644 index 0000000000..be234c6a2e --- /dev/null +++ b/drivers/input/spl_adc_key.c @@ -0,0 +1,73 @@ +/* + * (C) Copyright 2020 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +int key_read(int code) +{ + const void *fdt_blob = gd->fdt_blob; + int adc_node, offset; + int cd, channel, adc; + int ret, vref, mv; + int min, max; + int margin = 30; + uint val; + u32 chn[2]; + + adc_node = fdt_node_offset_by_compatible(fdt_blob, 0, "adc-keys"); + if (adc_node < 0) { + debug("No 'adc-keys' node, ret=%d\n", adc_node); + return 0; + } + + ret = fdtdec_get_int_array(fdt_blob, adc_node, "io-channels", + chn, ARRAY_SIZE(chn)); + if (ret) { + debug("Can't read 'io-channels', ret=%d\n", ret); + return 0; + } + + vref = fdtdec_get_int(fdt_blob, adc_node, + "keyup-threshold-microvolt", -1); + if (vref < 0) { + debug("Can't read 'keyup-threshold-microvolt'\n"); + return 0; + } + + channel = chn[1]; + + for (offset = fdt_first_subnode(fdt_blob, adc_node); + offset >= 0; + offset = fdt_next_subnode(fdt_blob, offset)) { + cd = fdtdec_get_int(fdt_blob, offset, "linux,code", -1); + if (cd == code) { + mv = fdtdec_get_int(fdt_blob, offset, + "press-threshold-microvolt", -1); + if (mv < 0) { + debug("Can't read 'press-threshold-microvolt'\n"); + return 0; + } + + adc = mv / (vref / 1024); /* 10-bit adc */ + max = adc + margin; + min = adc > margin ? adc - margin : 0; + ret = adc_channel_single_shot("saradc", channel, &val); + if (ret) { + debug("Failed to read adc%d, ret=%d\n", + channel, ret); + return 0; + } + + return (val >= min && val <= max); + } + } + + return 0; +} diff --git a/include/image.h b/include/image.h index afe2d06744..cc84b49728 100644 --- a/include/image.h +++ b/include/image.h @@ -1056,6 +1056,8 @@ int fit_image_verify_with_data(const void *fit, int image_noffset, int fit_image_verify(const void *fit, int noffset); int fit_config_verify(const void *fit, int conf_noffset); int fit_all_image_verify(const void *fit); +int fit_board_verify_required_sigs(void); + int fit_image_check_os(const void *fit, int noffset, uint8_t os); int fit_image_check_arch(const void *fit, int noffset, uint8_t arch); int fit_image_check_type(const void *fit, int noffset, uint8_t type);