[PATCH v2 6/7] spi: implement rescan

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Mar 9 05:03:55 PST 2023


On 09.03.23 12:52, Sascha Hauer wrote:
> Implement rescan to register and probe newly added devices via device
> tree overlays.
> 
> While this is easy to do at SPI core level this is not the whole truth.
> Many SPI controllers do not use their native chipselects for the SPI
> devices, but GPIOs instead. These currently won't be rescanned when new
> devices are added, so the chipselects for the new devices must be be
> present in the base device tree already. You have been warned.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/spi/spi.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 3684647f6e..ee467d055b 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -29,6 +29,7 @@ struct boardinfo {
>  };
>  
>  static LIST_HEAD(board_list);
> +static LIST_HEAD(spi_controller_list);
>  
>  /**
>   * spi_new_device - instantiate one new SPI device
> @@ -120,6 +121,12 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
>  	for_each_available_child_of_node(node, n) {
>  		struct spi_board_info chip = {};
>  
> +		if (n->dev) {
> +			dev_dbg(ctrl->dev, "of_i2c: skipping already registered %s\n",
> +				dev_name(n->dev));

s/of_i2c/of_spi/

> +			continue;
> +		}
> +
>  		chip.name = xstrdup(n->name);
>  		chip.bus_num = ctrl->bus_num;
>  		/* Mode (clock phase/polarity/etc.) */
> @@ -142,6 +149,17 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
>  	}
>  }
>  
> +static void spi_controller_rescan(struct device *dev)
> +{
> +	struct spi_controller *ctrl;
> +
> +	list_for_each_entry(ctrl, &spi_controller_list, list) {
> +		if (ctrl->dev != dev)
> +			continue;
> +		spi_of_register_slaves(ctrl);
> +	}
> +}
> +
>  /**
>   * spi_register_board_info - register SPI devices for a given board
>   * @info: array of chip descriptors
> @@ -196,8 +214,6 @@ static void scan_boardinfo(struct spi_controller *ctrl)
>  	}
>  }
>  
> -static LIST_HEAD(spi_controller_list);
> -
>  static int spi_controller_check_ops(struct spi_controller *ctlr)
>  {
>  	/*
> @@ -274,6 +290,9 @@ int spi_register_controller(struct spi_controller *ctrl)
>  	scan_boardinfo(ctrl);
>  	status = 0;
>  
> +	if (!ctrl->dev->rescan)
> +		ctrl->dev->rescan = spi_controller_rescan;
> +
>  	return status;
>  }
>  EXPORT_SYMBOL(spi_register_controller);

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