linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] leds: pca955x: Add ACPI support for pca955x
@ 2016-11-29  3:18 Tin Huynh
  2016-11-29  9:08 ` Mika Westerberg
  0 siblings, 1 reply; 2+ messages in thread
From: Tin Huynh @ 2016-11-29  3:18 UTC (permalink / raw)
  To: Mika Westerberg, Rafael J. Wysocki, Richard Purdie, Jacek Anaszewski
  Cc: linux-leds, linux-kernel, linux-acpi, Loc Ho, Thang Nguyen,
	Phong Vo, patches, Tin Huynh

This patch enables ACPI support for leds-pca955x driver.

Signed-off-by: Tin Huynh <tnhuynh@apm.com>
---
 drivers/leds/leds-pca955x.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

Change from V1:
 -Remove CONFIG_ACPI.

diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index 840401a..9ac3d53 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -40,6 +40,7 @@
  *  bits the chip supports.
  */
 
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/string.h>
@@ -100,6 +101,15 @@ struct pca955x_chipdef {
 };
 MODULE_DEVICE_TABLE(i2c, pca955x_id);
 
+static const struct acpi_device_id pca955x_acpi_ids[] = {
+	{ .id = "PCA9550", .driver_data = pca9550 },
+	{ .id = "PCA9551", .driver_data = pca9551 },
+	{ .id = "PCA9552", .driver_data = pca9552 },
+	{ .id = "PCA9553", .driver_data = pca9553 },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, pca955x_acpi_ids);
+
 struct pca955x {
 	struct mutex lock;
 	struct pca955x_led *leds;
@@ -250,7 +260,16 @@ static int pca955x_probe(struct i2c_client *client,
 	struct led_platform_data *pdata;
 	int i, err;
 
-	chip = &pca955x_chipdefs[id->driver_data];
+	if (id)
+		chip = &pca955x_chipdefs[id->driver_data];
+	else {
+		const struct acpi_device_id *acpi_id;
+
+		acpi_id = acpi_match_device(pca955x_acpi_ids, &client->dev);
+		if (!acpi_id)
+			return -ENODEV;
+		chip = &pca955x_chipdefs[acpi_id->driver_data];
+	}
 	adapter = to_i2c_adapter(client->dev.parent);
 	pdata = dev_get_platdata(&client->dev);
 
@@ -358,6 +377,7 @@ static int pca955x_remove(struct i2c_client *client)
 static struct i2c_driver pca955x_driver = {
 	.driver = {
 		.name	= "leds-pca955x",
+		.acpi_match_table = ACPI_PTR(pca955x_acpi_ids),
 	},
 	.probe	= pca955x_probe,
 	.remove	= pca955x_remove,
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] leds: pca955x: Add ACPI support for pca955x
  2016-11-29  3:18 [PATCH V2] leds: pca955x: Add ACPI support for pca955x Tin Huynh
@ 2016-11-29  9:08 ` Mika Westerberg
  0 siblings, 0 replies; 2+ messages in thread
From: Mika Westerberg @ 2016-11-29  9:08 UTC (permalink / raw)
  To: Tin Huynh
  Cc: Rafael J. Wysocki, Richard Purdie, Jacek Anaszewski, linux-leds,
	linux-kernel, linux-acpi, Loc Ho, Thang Nguyen, Phong Vo,
	patches

On Tue, Nov 29, 2016 at 10:18:47AM +0700, Tin Huynh wrote:
> This patch enables ACPI support for leds-pca955x driver.
> 
> Signed-off-by: Tin Huynh <tnhuynh@apm.com>
> ---
>  drivers/leds/leds-pca955x.c |   22 +++++++++++++++++++++-
>  1 files changed, 21 insertions(+), 1 deletions(-)
> 
> Change from V1:
>  -Remove CONFIG_ACPI.
> 
> diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
> index 840401a..9ac3d53 100644
> --- a/drivers/leds/leds-pca955x.c
> +++ b/drivers/leds/leds-pca955x.c
> @@ -40,6 +40,7 @@
>   *  bits the chip supports.
>   */
>  
> +#include <linux/acpi.h>
>  #include <linux/module.h>
>  #include <linux/delay.h>
>  #include <linux/string.h>
> @@ -100,6 +101,15 @@ struct pca955x_chipdef {
>  };
>  MODULE_DEVICE_TABLE(i2c, pca955x_id);
>  
> +static const struct acpi_device_id pca955x_acpi_ids[] = {
> +	{ .id = "PCA9550", .driver_data = pca9550 },
> +	{ .id = "PCA9551", .driver_data = pca9551 },
> +	{ .id = "PCA9552", .driver_data = pca9552 },
> +	{ .id = "PCA9553", .driver_data = pca9553 },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(acpi, pca955x_acpi_ids);
> +
>  struct pca955x {
>  	struct mutex lock;
>  	struct pca955x_led *leds;
> @@ -250,7 +260,16 @@ static int pca955x_probe(struct i2c_client *client,
>  	struct led_platform_data *pdata;
>  	int i, err;
>  
> -	chip = &pca955x_chipdefs[id->driver_data];
> +	if (id)
> +		chip = &pca955x_chipdefs[id->driver_data];
> +	else {

You need to use {} in both branches. See Documentation/CodingStyle.

Otherwise looks good to me.

> +		const struct acpi_device_id *acpi_id;
> +
> +		acpi_id = acpi_match_device(pca955x_acpi_ids, &client->dev);
> +		if (!acpi_id)
> +			return -ENODEV;
> +		chip = &pca955x_chipdefs[acpi_id->driver_data];
> +	}
>  	adapter = to_i2c_adapter(client->dev.parent);
>  	pdata = dev_get_platdata(&client->dev);
>  
> @@ -358,6 +377,7 @@ static int pca955x_remove(struct i2c_client *client)
>  static struct i2c_driver pca955x_driver = {
>  	.driver = {
>  		.name	= "leds-pca955x",
> +		.acpi_match_table = ACPI_PTR(pca955x_acpi_ids),
>  	},
>  	.probe	= pca955x_probe,
>  	.remove	= pca955x_remove,
> -- 
> 1.7.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-29  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-29  3:18 [PATCH V2] leds: pca955x: Add ACPI support for pca955x Tin Huynh
2016-11-29  9:08 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).