[PATCH v3 3/7] ARM: boards: skov-imx6: add switch detection

Sascha Hauer sha at pengutronix.de
Fri Oct 1 07:29:11 PDT 2021


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 at 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 at 2100000/ethernet at 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 |



More information about the barebox mailing list