[PATCH v2] staging: iio: adis16240: add device to module device table

Jonathan Cameron jic23 at kernel.org
Sun May 19 11:00:29 UTC 2019

On Sat, 18 May 2019 18:44:34 -0300
Lucas Oshiro <lucasseikioshiro at gmail.com> wrote:

> Add a of_device_id struct and MODULE_DEVICE_TABLE call, in order to add
> device-tree support for this driver.
> Signed-off-by: Lucas Oshiro <lucasseikioshiro at gmail.com>
> Signed-off-by: Rodrigo Ribeiro <rodrigorsdc at gmail.com>
> Co-developed-by: Rodrigo Ribeiro <rodrigorsdc at gmail.com>

Hi Lucas, Rodrigo,

The description isn't 100% accurate but it's close enough.
Ever since devicetree was introduced, there has been a fallback mode for
i2c and spi devices in which, in the absence of either a devicetree match table
or an ACPI one, an attempt is made to match against the older i2c_device_id
table entries.

So it'll 'work' for devicetree bindings without this patch, but by a less
controlled route and one that doesn't allow for the possibility of
multiple manufacturers using the same part number.

Hence these are good changes to make.  Simplifying the description to enabling
devicetree probing is fine though.

Under drivers/spi.c, devices probed via a device tree binding use:
of_register_spi_device (applied to all children of an spi bus, so the slave
devices).  This calls of_modalias_node which performs a copy of the
compatible without the manufacturer ID into the modalias field.
Later, spi_match_device is called, which first attempts
of_driver_match_device which I think does the precise match.

If that fails, it tries ACPI, and failing that it falls back to matching
the modalias against the id_table entries.   Thus it can still
work without these entries but they do make it simpler and more consistent.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.



> ---
>  drivers/staging/iio/accel/adis16240.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c
> index b80e0d248b0f..8c6d23604eca 100644
> --- a/drivers/staging/iio/accel/adis16240.c
> +++ b/drivers/staging/iio/accel/adis16240.c
> @@ -435,6 +435,12 @@ static int adis16240_remove(struct spi_device *spi)
>  	return 0;
>  }
> +static const struct of_device_id adis16240_of_match[] = {
> +	{ .compatible = "adi,adis16240" },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, adis16240_of_match);
> +
>  static struct spi_driver adis16240_driver = {
>  	.driver = {
>  		.name = "adis16240",

More information about the devel mailing list