diff mbox

[v2,6/7] mfd: cros_ec: Instantiate sub-devices from device tree

Message ID 1408974008-17184-7-git-send-email-javier.martinez@collabora.co.uk
State Not Applicable
Headers show

Commit Message

Javier Martinez Canillas Aug. 25, 2014, 1:40 p.m. UTC
From: Todd Broch <tbroch@chromium.org>

If the EC device tree node has sub-nodes, try to instantiate them as
MFD sub-devices.  We can configure the EC features provided by the board.

Signed-off-by: Todd Broch <tbroch@chromium.org>
Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
---

Changes since v1:
 - Don't leave an empty struct mfd_cell array. Suggested by Lee Jones.
 - Just use of_platform_populate() instead of manually iterating through
   sub-devices and calling mfd_add_devices. Suggested by Lee Jones.
---
 drivers/mfd/cros_ec.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

Comments

Lee Jones Sept. 4, 2014, 8:25 a.m. UTC | #1
On Mon, 25 Aug 2014, Javier Martinez Canillas wrote:
> From: Todd Broch <tbroch@chromium.org>
> 
> If the EC device tree node has sub-nodes, try to instantiate them as
> MFD sub-devices.  We can configure the EC features provided by the board.
> 
> Signed-off-by: Todd Broch <tbroch@chromium.org>
> Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
> ---
> 
> Changes since v1:
>  - Don't leave an empty struct mfd_cell array. Suggested by Lee Jones.
>  - Just use of_platform_populate() instead of manually iterating through
>    sub-devices and calling mfd_add_devices. Suggested by Lee Jones.
> ---
>  drivers/mfd/cros_ec.c | 35 ++++++++++++++++-------------------
>  1 file changed, 16 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
> index cd0c93c..ab70791 100644
> --- a/drivers/mfd/cros_ec.c
> +++ b/drivers/mfd/cros_ec.c
> @@ -21,6 +21,7 @@
>  #include <linux/slab.h>
>  #include <linux/module.h>
>  #include <linux/mfd/core.h>
> +#include <linux/of_platform.h>
>  #include <linux/mfd/cros_ec.h>
>  #include <linux/mfd/cros_ec_commands.h>
>  #include <linux/delay.h>
> @@ -107,22 +108,12 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
>  }
>  EXPORT_SYMBOL(cros_ec_cmd_xfer);
>  
> -static const struct mfd_cell cros_devs[] = {
> -	{
> -		.name = "cros-ec-keyb",
> -		.id = 1,
> -		.of_compatible = "google,cros-ec-keyb",
> -	},
> -	{
> -		.name = "cros-ec-i2c-tunnel",
> -		.id = 2,
> -		.of_compatible = "google,cros-ec-i2c-tunnel",
> -	},
> -};
> -
>  int cros_ec_register(struct cros_ec_device *ec_dev)
>  {
>  	struct device *dev = ec_dev->dev;
> +#ifdef CONFIG_OF
> +	struct device_node *node = dev->of_node;
> +#endif

Drop the #ifdiffery.

>  	int err = 0;
>  
>  	if (ec_dev->din_size) {
> @@ -138,13 +129,19 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
>  
>  	mutex_init(&ec_dev->lock);
>  
> -	err = mfd_add_devices(dev, 0, cros_devs,
> -			      ARRAY_SIZE(cros_devs),
> -			      NULL, ec_dev->irq, NULL);
> -	if (err) {
> -		dev_err(dev, "failed to add mfd devices\n");
> -		return err;
> +#ifdef CONFIG_OF

And here.

> +	/*
> +	 * Add sub-devices declared in the device tree.  NOTE they should NOT be
> +	 * declared in cros_devs
> +	 */

Drop this comment.  cros_devs no longer exists and we know what
of_platform_populate() does.

> +	if (node) {
> +		err = of_platform_populate(node, NULL, NULL, dev);
> +		if (err) {
> +			dev_err(dev, "fail to add %s\n", node->full_name);

That's not true.  Just put "Failed to register subordinate devices".

> +			return err;
> +		}
>  	}
> +#endif
>  
>  	dev_info(dev, "Chrome EC device registered\n");
>
Javier Martinez Canillas Sept. 8, 2014, 10:57 a.m. UTC | #2
Hello Lee,

Sorry for the delay but had been on holidays last week.

On 09/04/2014 10:25 AM, Lee Jones wrote:
>>  
>> -static const struct mfd_cell cros_devs[] = {
>> -	{
>> -		.name = "cros-ec-keyb",
>> -		.id = 1,
>> -		.of_compatible = "google,cros-ec-keyb",
>> -	},
>> -	{
>> -		.name = "cros-ec-i2c-tunnel",
>> -		.id = 2,
>> -		.of_compatible = "google,cros-ec-i2c-tunnel",
>> -	},
>> -};
>> -
>>  int cros_ec_register(struct cros_ec_device *ec_dev)
>>  {
>>  	struct device *dev = ec_dev->dev;
>> +#ifdef CONFIG_OF
>> +	struct device_node *node = dev->of_node;
>> +#endif
> 
> Drop the #ifdiffery.
>

I used the #ifdef guards because I remembered of_node being conditionally
build but I see that this is not longer true after commmit:

c9e358d driver-core: remove conditionals around devicetree pointers

So I'll remove it, thanks for the pointer.

>>  	int err = 0;
>>  
>>  	if (ec_dev->din_size) {
>> @@ -138,13 +129,19 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
>>  
>>  	mutex_init(&ec_dev->lock);
>>  
>> -	err = mfd_add_devices(dev, 0, cros_devs,
>> -			      ARRAY_SIZE(cros_devs),
>> -			      NULL, ec_dev->irq, NULL);
>> -	if (err) {
>> -		dev_err(dev, "failed to add mfd devices\n");
>> -		return err;
>> +#ifdef CONFIG_OF
> 
> And here.
> 

Nod.

>> +	/*
>> +	 * Add sub-devices declared in the device tree.  NOTE they should NOT be
>> +	 * declared in cros_devs
>> +	 */
> 
> Drop this comment.  cros_devs no longer exists and we know what
> of_platform_populate() does.
> 

Ok.

>> +	if (node) {
>> +		err = of_platform_populate(node, NULL, NULL, dev);
>> +		if (err) {
>> +			dev_err(dev, "fail to add %s\n", node->full_name);
> 
> That's not true.  Just put "Failed to register subordinate devices".
> 

Ok.

>> +			return err;
>> +		}
>>  	}
>> +#endif
>>  
>>  	dev_info(dev, "Chrome EC device registered\n");
>>  
> 

Thanks a lot for the feedback and best regards,
Javier

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index cd0c93c..ab70791 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -21,6 +21,7 @@ 
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/mfd/core.h>
+#include <linux/of_platform.h>
 #include <linux/mfd/cros_ec.h>
 #include <linux/mfd/cros_ec_commands.h>
 #include <linux/delay.h>
@@ -107,22 +108,12 @@  int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
 }
 EXPORT_SYMBOL(cros_ec_cmd_xfer);
 
-static const struct mfd_cell cros_devs[] = {
-	{
-		.name = "cros-ec-keyb",
-		.id = 1,
-		.of_compatible = "google,cros-ec-keyb",
-	},
-	{
-		.name = "cros-ec-i2c-tunnel",
-		.id = 2,
-		.of_compatible = "google,cros-ec-i2c-tunnel",
-	},
-};
-
 int cros_ec_register(struct cros_ec_device *ec_dev)
 {
 	struct device *dev = ec_dev->dev;
+#ifdef CONFIG_OF
+	struct device_node *node = dev->of_node;
+#endif
 	int err = 0;
 
 	if (ec_dev->din_size) {
@@ -138,13 +129,19 @@  int cros_ec_register(struct cros_ec_device *ec_dev)
 
 	mutex_init(&ec_dev->lock);
 
-	err = mfd_add_devices(dev, 0, cros_devs,
-			      ARRAY_SIZE(cros_devs),
-			      NULL, ec_dev->irq, NULL);
-	if (err) {
-		dev_err(dev, "failed to add mfd devices\n");
-		return err;
+#ifdef CONFIG_OF
+	/*
+	 * Add sub-devices declared in the device tree.  NOTE they should NOT be
+	 * declared in cros_devs
+	 */
+	if (node) {
+		err = of_platform_populate(node, NULL, NULL, dev);
+		if (err) {
+			dev_err(dev, "fail to add %s\n", node->full_name);
+			return err;
+		}
 	}
+#endif
 
 	dev_info(dev, "Chrome EC device registered\n");