diff mbox series

[v2,4/4,media] ad5820: Add support for of-autoload

Message ID 20180920183151.2933-1-ricardo.ribalda@gmail.com (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Ricardo Ribalda Delgado Sept. 20, 2018, 6:31 p.m. UTC
Since kernel 4.16, i2c devices with DT compatible tag are modprobed
using their DT modalias.
Without this patch, if this driver is build as module it would never
be autoprobed.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/i2c/ad5820.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Pavel Machek Sept. 20, 2018, 6:55 p.m. UTC | #1
On Thu 2018-09-20 20:31:51, Ricardo Ribalda Delgado wrote:
> Since kernel 4.16, i2c devices with DT compatible tag are modprobed
> using their DT modalias.
> Without this patch, if this driver is build as module it would never
> be autoprobed.
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>

1,4: Acked-by: Pavel Machek <pavel@ucw.cz>
Laurent Pinchart Sept. 20, 2018, 8:10 p.m. UTC | #2
Hi Ricardo,

Thank you for the patch.

On Thursday, 20 September 2018 21:31:51 EEST Ricardo Ribalda Delgado wrote:
> Since kernel 4.16, i2c devices with DT compatible tag are modprobed
> using their DT modalias.
> Without this patch, if this driver is build as module it would never
> be autoprobed.
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  drivers/media/i2c/ad5820.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c
> index 20931217e3b1..75b9b8aa5533 100644
> --- a/drivers/media/i2c/ad5820.c
> +++ b/drivers/media/i2c/ad5820.c
> @@ -375,12 +375,19 @@ static const struct i2c_device_id ad5820_id_table[] =
> { };
>  MODULE_DEVICE_TABLE(i2c, ad5820_id_table);
> 
> +static const struct of_device_id ad5820_of_table[] = {
> +	{ .compatible = "adi,"AD5820_NAME },

I'd spell this out explicitly, to make it easier to grep for the compatible 
string.

> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, ad5820_of_table);
> +
>  static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume);
> 
>  static struct i2c_driver ad5820_i2c_driver = {
>  	.driver		= {
>  		.name	= AD5820_NAME,
>  		.pm	= &ad5820_pm,
> +		.of_match_table = ad5820_of_table,

As the driver doesn't depend on CONFIG_OF, would it make sense to use 
of_config_ptr() (and to compile the of table conditionally on CONFIG_OF) ?

>  	},
>  	.probe		= ad5820_probe,
>  	.remove		= ad5820_remove,
Sakari Ailus Sept. 20, 2018, 8:18 p.m. UTC | #3
Hi Laurent,

On Thu, Sep 20, 2018 at 11:10:23PM +0300, Laurent Pinchart wrote:
> > +MODULE_DEVICE_TABLE(of, ad5820_of_table);
> > +
> >  static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume);
> > 
> >  static struct i2c_driver ad5820_i2c_driver = {
> >  	.driver		= {
> >  		.name	= AD5820_NAME,
> >  		.pm	= &ad5820_pm,
> > +		.of_match_table = ad5820_of_table,
> 
> As the driver doesn't depend on CONFIG_OF, would it make sense to use 
> of_config_ptr() (and to compile the of table conditionally on CONFIG_OF) ?

You get ACPI support as a bonus if you don't use of_config_ptr(). :-) Other
changes could be needed but this enables probing the driver for a device.

In this case the probability of anyone using this device on an ACPI system
could be pretty low though.
diff mbox series

Patch

diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c
index 20931217e3b1..75b9b8aa5533 100644
--- a/drivers/media/i2c/ad5820.c
+++ b/drivers/media/i2c/ad5820.c
@@ -375,12 +375,19 @@  static const struct i2c_device_id ad5820_id_table[] = {
 };
 MODULE_DEVICE_TABLE(i2c, ad5820_id_table);
 
+static const struct of_device_id ad5820_of_table[] = {
+	{ .compatible = "adi,"AD5820_NAME },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ad5820_of_table);
+
 static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume);
 
 static struct i2c_driver ad5820_i2c_driver = {
 	.driver		= {
 		.name	= AD5820_NAME,
 		.pm	= &ad5820_pm,
+		.of_match_table = ad5820_of_table,
 	},
 	.probe		= ad5820_probe,
 	.remove		= ad5820_remove,