All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: "Guillaume La Roque (TI.com)" <glaroque@baylibre.com>,
	u-boot@lists.denx.de, Anshul Dalal <anshuld@ti.com>,
	Bryan Brattlof <bb@ti.com>
Cc: Tom Rini <trini@konsulko.com>,
	Garrett Giordano <ggiordano@phytec.com>,
	Wadim Egorov <w.egorov@phytec.de>,
	Neha Malcom Francis <n-francis@ti.com>,
	Mattijs Korpershoek <mkorpershoek@kernel.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Santhosh Kumar K <s-k6@ti.com>,
	Jonathan Humphreys <j-humphreys@ti.com>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Devarsh Thakkar <devarsht@ti.com>,
	Prasanth Babu Mantena <p-mantena@ti.com>,
	Judith Mendez <jm@ti.com>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Dhruva Gole <d-gole@ti.com>, Andrew Davis <afd@ti.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Aashvij Shenai <a-shenai@ti.com>, Peng Fan <peng.fan@nxp.com>,
	"Guillaume La Roque (TI.com)" <glaroque@baylibre.com>
Subject: Re: [PATCH v2 1/4] board: ti: common: Add generic AM6x board detection functions
Date: Mon, 27 Oct 2025 17:10:58 +0100	[thread overview]
Message-ID: <87y0owjpf1.fsf@kernel.org> (raw)
In-Reply-To: <20251024-am62xeeprom-v2-1-0e372347e7d4@baylibre.com>

Hi Guillaume,

Thank you for the patch.

On Fri, Oct 24, 2025 at 16:17, "Guillaume La Roque (TI.com)" <glaroque@baylibre.com> wrote:

> Add two new generic functions for AM6x family boards to simplify
> board-specific implementations:
>
> - do_board_detect_am6(): Generic board detection function that reads
>   the on-board EEPROM. It first attempts to read at the configured
>   address, and if that fails, tries the alternate address
>   (CONFIG_EEPROM_CHIP_ADDRESS + 1). This provides a common
>   implementation that can be used across different AM6x boards.
>
> - setup_serial_am6(): Sets up the serial number environment variable
>   from the EEPROM data. The serial number is converted from
>   hexadecimal string format to a 16-character hexadecimal
>   representation and stored in the "serial#" environment variable.
>
> Both functions are protected by CONFIG_IS_ENABLED(TI_I2C_BOARD_DETECT)
> and are designed to be used by AM62x, AM64x, AM65x, and other AM6x
> family boards.
>
> Signed-off-by: Guillaume La Roque (TI.com) <glaroque@baylibre.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>

> ---
>  board/ti/common/board_detect.c | 43 ++++++++++++++++++++++++++++++++++++++++++
>  board/ti/common/board_detect.h | 22 +++++++++++++++++++++
>  2 files changed, 65 insertions(+)
>
> diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
> index a43cc075b92..d49e26fa453 100644
> --- a/board/ti/common/board_detect.c
> +++ b/board/ti/common/board_detect.c
> @@ -824,3 +824,46 @@ bool __maybe_unused board_ti_was_eeprom_read(void)
>  	else
>  		return false;
>  }
> +
> +#if CONFIG_IS_ENABLED(TI_I2C_BOARD_DETECT)
> +int do_board_detect_am6(void)
> +{
> +	int ret;
> +
> +	ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
> +					 CONFIG_EEPROM_CHIP_ADDRESS);
> +	if (ret) {
> +		printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
> +		       CONFIG_EEPROM_CHIP_ADDRESS,
> +		       CONFIG_EEPROM_CHIP_ADDRESS + 1);
> +		ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
> +						 CONFIG_EEPROM_CHIP_ADDRESS +
> +							 1);
> +		if (ret)
> +			pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
> +			       CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
> +	}
> +
> +	return ret;
> +}
> +
> +void setup_serial_am6(void)
> +{
> +	struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
> +	unsigned long board_serial;
> +	char *endp;
> +	char serial_string[17] = { 0 };
> +
> +	if (env_get("serial#"))
> +		return;
> +
> +	board_serial = simple_strtoul(ep->serial, &endp, 16);
> +	if (*endp != '\0') {
> +		pr_err("Error: Can't set serial# to %s\n", ep->serial);
> +		return;
> +	}
> +
> +	snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
> +	env_set("serial#", serial_string);
> +}
> +#endif
> diff --git a/board/ti/common/board_detect.h b/board/ti/common/board_detect.h
> index b057f3b2269..26ada2a449c 100644
> --- a/board/ti/common/board_detect.h
> +++ b/board/ti/common/board_detect.h
> @@ -313,6 +313,28 @@ int __maybe_unused ti_i2c_eeprom_am6_get(int bus_addr, int dev_addr,
>   */
>  int __maybe_unused ti_i2c_eeprom_am6_get_base(int bus_addr, int dev_addr);
>  
> +/**
> + * do_board_detect_am6() - Detect AM6x board and read EEPROM data
> + *
> + * This is a generic board detection function for AM6x family boards.
> + * It attempts to read the on-board EEPROM at the configured address,
> + * and if that fails, tries the alternate address (CONFIG_EEPROM_CHIP_ADDRESS + 1).
> + *
> + * Return: 0 on success or corresponding error on failure.
> + */
> +int do_board_detect_am6(void);
> +
> +/**
> + * setup_serial_am6() - Setup serial number environment variable for AM6x boards
> + *
> + * This function reads the serial number from the AM6x EEPROM data and
> + * sets the "serial#" environment variable. The serial number is converted
> + * from hexadecimal string format to a 16-character hexadecimal representation.
> + *
> + * EEPROM should be already read before calling this function.
> + */
> +void setup_serial_am6(void);
> +
>  #ifdef CONFIG_TI_I2C_BOARD_DETECT
>  /**
>   * board_ti_is() - Board detection logic for TI EVMs
>
> -- 
> 2.34.1

  reply	other threads:[~2025-10-27 16:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-24 14:17 [PATCH v2 0/4] board: ti: am62x: Add EEPROM support and refactor board detection Guillaume La Roque (TI.com)
2025-10-24 14:17 ` [PATCH v2 1/4] board: ti: common: Add generic AM6x board detection functions Guillaume La Roque (TI.com)
2025-10-27 16:10   ` Mattijs Korpershoek [this message]
2025-10-24 14:17 ` [PATCH v2 2/4] board: am62x: Add support for reading eeprom data Guillaume La Roque (TI.com)
2025-10-27 16:13   ` Mattijs Korpershoek
2025-10-27 18:08   ` Andrew Davis
2025-10-31  8:22     ` Guillaume La Roque
2025-10-24 14:17 ` [PATCH v2 3/4] board: am64x: Use generic AM6x board detection functions Guillaume La Roque (TI.com)
2025-10-27 16:15   ` Mattijs Korpershoek
2025-10-24 14:17 ` [PATCH v2 4/4] board: am65x: Use generic AM6x board detection function Guillaume La Roque (TI.com)
2025-10-27 16:18   ` Mattijs Korpershoek

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=87y0owjpf1.fsf@kernel.org \
    --to=mkorpershoek@kernel.org \
    --cc=a-shenai@ti.com \
    --cc=afd@ti.com \
    --cc=anshuld@ti.com \
    --cc=bb@ti.com \
    --cc=d-gole@ti.com \
    --cc=devarsht@ti.com \
    --cc=ggiordano@phytec.com \
    --cc=glaroque@baylibre.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=j-humphreys@ti.com \
    --cc=jm@ti.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=n-francis@ti.com \
    --cc=neil.armstrong@linaro.org \
    --cc=p-mantena@ti.com \
    --cc=peng.fan@nxp.com \
    --cc=s-k6@ti.com \
    --cc=semen.protsenko@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    --cc=w.egorov@phytec.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.