Hello Sascha, On 03.04.24 10:10, Sascha Hauer wrote: > +static int saradc_get_value(const char *chan) > +{ > + int ret, voltage; > + struct aiochannel *aio; > + > + if (!IS_ENABLED(CONFIG_AIODEV)) { > + pr_warn_once("AIODEV disabled, cannot read hardware id/rev\n"); > + return 0; > + } > + > + aio = aiochannel_by_name(chan); > + if (IS_ERR(aio)) > + return PTR_ERR(aio); > + > + ret = aiochannel_get_value(aio, &voltage); > + if (ret) > + return ret; > + > + return voltage; > +} Other rockchip boards have similar board code. Maybe we should have a helper in <aiodev.h> instead? > + > +static int mecsbc_get_usb_boot(void) > +{ > + return saradc_get_value("aiodev0.in_value0_mV") < 74; > +} > + > +static int mecsbc_adc_id_values[] = { > + 1800, 1662, 1521, 1354, 1214, 1059, 900, 742, 335, 589, 278, 137, 0 > +}; > + > +static int mecsbc_get_adc_id(const char *chan) > +{ > + int val; > + unsigned int t; > + > + val = saradc_get_value(chan); > + if (val < 0) > + return 0; > + > + val += 74; > + > + for (t = 0; t < ARRAY_SIZE(mecsbc_adc_id_values); t++) { > + if (val > mecsbc_adc_id_values[t]) > + return t; > + } > + > + return t; > +} > + > +static void mecsbc_process_adc(void) > +{ > + /* Check if we need to enable the USB gadget instead of booting */ > + if (mecsbc_get_usb_boot()) { > + setenv("global.boot.default", "net"); > + setenv("global.usbgadget.acm", "1"); > + setenv("global.usbgadget.autostart", "1"); > + setenv("global.system.partitions", "/dev/mmc0(mmc0)"); There's globalvar_set() which avoids parsing the string to do a device lookup by name. Looks good otherwise: Reviewed-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> Cheers, Ahmad -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |