mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v3 3/7] ARM: boards: skov-imx6: add switch detection
Date: Fri, 1 Oct 2021 16:29:11 +0200
Message-ID: <20211001142911.GY24834@pengutronix.de> (raw)
In-Reply-To: <20210920111528.14575-4-o.rempel@pengutronix.de>

On Mon, Sep 20, 2021 at 01:15:24PM +0200, Oleksij Rempel wrote:
> There are board variants with same board ID but not switch. Detect this
> variants.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  arch/arm/boards/skov-imx6/board.c | 158 +++++++++++++++++++++++++-----
>  1 file changed, 134 insertions(+), 24 deletions(-)
> 
> diff --git a/arch/arm/boards/skov-imx6/board.c b/arch/arm/boards/skov-imx6/board.c
> index 030ac62c52..a94c2cd25c 100644
> --- a/arch/arm/boards/skov-imx6/board.c
> +++ b/arch/arm/boards/skov-imx6/board.c
> @@ -11,6 +11,7 @@
>  #include <net.h>
>  #include <of_gpio.h>
>  #include <gpio.h>
> +#include <linux/micrel_phy.h>
>  
>  #include "version.h"
>  
> @@ -130,6 +131,9 @@ copy_mac_from_eth0:
>  	return eth_of_fixup_node_from_eth_device(root, node_path, ethname);
>  }
>  
> +#define SKOV_GPIO_MDIO_BUS	0
> +#define SKOV_LAN1_PHY_ADDR	1
> +
>  #define MAX_V_GPIO 8
>  
>  struct board_description {
> @@ -303,20 +307,121 @@ static const struct board_description imx6_variants[] = {
>  };
>  
>  static int skov_board_no = -1;
> +static bool skov_no_switch = false;

I think a skov_have_switch variable would be more intuitive.

> +static const char *no_switch_suffix = "-noswitch";
>  
> -static int skov_imx6_fixup(struct device_node *root, void *unused)
> +static void fixup_machine_compatible(const char *compat,
> +				     struct device_node *root)
>  {
> +	int cclen = 0, clen = strlen(compat) + 1;
> +	const char *curcompat;
> +	void *buf;
> +
> +	if (!root) {
> +		root = of_get_root_node();
> +		if (!root)
> +			return;
> +	}
> +
> +	curcompat = of_get_property(root, "compatible", &cclen);
> +
> +	buf = xzalloc(cclen + clen);
> +
> +	memcpy(buf, compat, clen);
> +	memcpy(buf + clen, curcompat, cclen);
> +
> +	/*
> +	 * Prepend the compatible from board entry to the machine compatible.
> +	 * Used to match bootspec entries against it.
> +	 */
> +	of_set_property(root, "compatible", buf, cclen + clen, true);
> +
> +	free(buf);
> +}
> +
> +static void fixup_noswitch_machine_compatible(struct device_node *root)
> +{
> +	const char *compat = imx6_variants[skov_board_no].dts_compatible;
> +	const char *generic = "skov,imx6";
> +	size_t size, size_generic;
> +	char *buf;
>  	int ret;
> -	const char *val;
> -	uint32_t brightness;
> +
> +	size = strlen(compat) + strlen(no_switch_suffix) + 1;
> +	size_generic = strlen(generic) + strlen(no_switch_suffix) + 1;
> +	size = max(size, size_generic);
> +	buf = xzalloc(size);
> +	if (!buf) {
> +		pr_warn("Can't allocate buffer\n");
> +		return;
> +	}

No need to check xzallox return value.

> +
> +	/* add generic compatible, so systemd&co can make right decisions */
> +	ret = snprintf(buf, size, "%s%s", generic, no_switch_suffix);
> +	if (ret >= 0)
> +		fixup_machine_compatible(buf, root);
> +	else
> +		pr_warn("Can't prepare generic compatible string\n");
> +
> +	/* add specific compatible as fallback, in case this board has new
> +	 * challenges.
> +	 */
> +	ret = snprintf(buf, size, "%s%s", compat, no_switch_suffix);
> +	if (ret >= 0)
> +		fixup_machine_compatible(buf, root);
> +	else
> +		pr_warn("Can't prepare specific compatible string\n");
> +
> +	free(buf);

Looks like this code could be more straight forward using two xasprintf
calls.

> +}
> +
> +static void skov_imx6_no_switch(struct device_node *root)
> +{
>  	struct device_node *node;
> -	struct device_node *chosen = of_create_node(root, "/chosen");
> +	int ret;
> +
> +	fixup_noswitch_machine_compatible(root);
>  
> +	node = of_find_node_by_path_from(root, "/soc/bus@2100000/ethernet@2188000");
> +	if (!node) {
> +		pr_warn("Did not find node to disable it\n");
> +	} else {

Please use positive logic like you did below.

Sascha

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-10-01 14:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 11:15 [PATCH v3 0/7] add noswitch support for skov boards Oleksij Rempel
2021-09-20 11:15 ` [PATCH v3 1/7] ARM: dts: skov-imx6: add USB nodes Oleksij Rempel
2021-09-20 11:15 ` [PATCH v3 2/7] ARM: boards: skov-imx6: fixup_machine_compatible() add optional root node Oleksij Rempel
2021-09-20 11:15 ` [PATCH v3 3/7] ARM: boards: skov-imx6: add switch detection Oleksij Rempel
2021-10-01 14:29   ` Sascha Hauer [this message]
2021-09-20 11:15 ` [PATCH v3 4/7] ARM: boards: skov-imx6: disable eth0 for barebox if no switch is detected Oleksij Rempel
2021-09-20 11:15 ` [PATCH v3 5/7] ARM: boards: skov-imx6: fixup different DTS variants Oleksij Rempel
2021-09-20 11:15 ` [PATCH v3 6/7] ARM: boards: skov-imx6: start using deep-probe Oleksij Rempel
2021-09-20 11:15 ` [PATCH v3 7/7] ARM: boards: skov-imx6: add defaultenv with eth1-discover script Oleksij Rempel

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=20211001142911.GY24834@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=o.rempel@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

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git