mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Barebox List <barebox@lists.infradead.org>
Cc: David Jander <david@protonic.nl>
Subject: Re: [PATCH] arm: boards: Add support for protonic-mecsbc board
Date: Wed, 3 Apr 2024 10:25:52 +0200	[thread overview]
Message-ID: <57e24a7d-32e0-4d6a-9c3f-4a7b0cce6a71@pengutronix.de> (raw)
In-Reply-To: <20240403081005.4149761-1-s.hauer@pengutronix.de>

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@pengutronix.de>

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 |




      reply	other threads:[~2024-04-03  8:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03  8:10 Sascha Hauer
2024-04-03  8:25 ` Ahmad Fatoum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57e24a7d-32e0-4d6a-9c3f-4a7b0cce6a71@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=david@protonic.nl \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox