Skip to contentSkip to conversation

max17042: propagate of_node to power supply device

PATCH In review Pierre Bourdon 3 participants 5 messages Feb 20, 2018 – Feb 22, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 max17042: propagate of_node to power supply device

max17042_get_status uses the core power_supply_am_i_supplied. That function relies on DT properties to figure out the power supply topology, and will error out without DT.

Fixes max17042 battery status being reported as "unknown".

---
 drivers/power/supply/max17042_battery.c | 1 +
 1 file changed, 1 insertion(+)
drivers/power/supply/max17042_battery.c +1 -0
index 35dde81b1c9b..1a568df383db 100644
@@ -1053,6 +1053,7 @@ static int max17042_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, chip);
 	psy_cfg.drv_data = chip;
+	psy_cfg.of_node = dev->of_node;
 
 	/* When current is not measured,
 	 * CURRENT_NOW and CURRENT_AVG properties should be invisible. */
Signature · 1 line
2.16.1.291.g4437f3f132-goog
#1 lore raw
Quoted 5 lines · Pierre Bourdon

max17042_get_status uses the core power_supply_am_i_supplied. That function relies on DT properties to figure out the power supply topology, and will error out without DT.

+ psy_cfg.of_node = dev->of_node;

Perhaps do this in general manner, see how GPIOLIB takes care of it:

$ git grep -n -A4 -w CONFIG_OF_GPIO -- drivers/gpio/gpiolib.c
drivers/gpio/gpiolib.c:1161:#ifdef CONFIG_OF_GPIO
drivers/gpio/gpiolib.c-1162-    /* If the gpiochip has an assigned OF
node this takes precedence */
drivers/gpio/gpiolib.c-1163-    if (chip->of_node)
drivers/gpio/gpiolib.c-1164-            gdev->dev.of_node = chip->of_node;
drivers/gpio/gpiolib.c-1165-#endif
...
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Pierre Bourdon

max17042_get_status uses the core power_supply_am_i_supplied. That function relies on DT properties to figure out the power supply topology, and will error out without DT.

+ psy_cfg.of_node = dev->of_node;

Perhaps do this in general manner, see how GPIOLIB takes care of it:

Quoted 8 lines
$ git grep -n -A4 -w CONFIG_OF_GPIO -- drivers/gpio/gpiolib.c
drivers/gpio/gpiolib.c:1161:#ifdef CONFIG_OF_GPIO
drivers/gpio/gpiolib.c-1162-    /* If the gpiochip has an assigned OF
node this takes precedence */
drivers/gpio/gpiolib.c-1163-    if (chip->of_node)
drivers/gpio/gpiolib.c-1164-            gdev->dev.of_node = chip->of_node;
drivers/gpio/gpiolib.c-1165-#endif
...

Makes sense. From a quick look in existing drivers, it looks like the only values being used currently as psy_cfg.of_node are the nodes from the parent device, so it seems like it could be made generic.

Are we aware of any driver that is not propagating the of_node on purpose? Is this something that should be supported? If not, I guess we could get rid of power_supply_config.of_node and always use the one from the parent device in __power_supply_register.

(I'm very new to this codebase, sorry for the possibly dumb questions!)

Signature · 1 line
Pierre Bourdon (delroth@)
#3 lore raw

Hi,

Quoted 24 lines · Pierre Bourdon (delroth)
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Pierre Bourdon

max17042_get_status uses the core power_supply_am_i_supplied. That function relies on DT properties to figure out the power supply topology, and will error out without DT.

+ psy_cfg.of_node = dev->of_node;

Perhaps do this in general manner, see how GPIOLIB takes care of it:

Quoted 8 lines
$ git grep -n -A4 -w CONFIG_OF_GPIO -- drivers/gpio/gpiolib.c
drivers/gpio/gpiolib.c:1161:#ifdef CONFIG_OF_GPIO
drivers/gpio/gpiolib.c-1162-    /* If the gpiochip has an assigned OF
node this takes precedence */
drivers/gpio/gpiolib.c-1163-    if (chip->of_node)
drivers/gpio/gpiolib.c-1164-            gdev->dev.of_node = chip->of_node;
drivers/gpio/gpiolib.c-1165-#endif
...

Makes sense. From a quick look in existing drivers, it looks like the only values being used currently as psy_cfg.of_node are the nodes from the parent device, so it seems like it could be made generic.

Quoted 6 lines

Are we aware of any driver that is not propagating the of_node on purpose? Is this something that should be supported? If not, I guess we could get rid of power_supply_config.of_node and always use the one from the parent device in __power_supply_register.

(I'm very new to this codebase, sorry for the possibly dumb questions!)

I think it makes sense to keep psy_cfg.of_node in case a driver needs to use a subnode for some reason. I think it makes sense to use dev->of_node as default value, though. Anyways I have applied this patch to my fixes branch.

-- Sebastian

#4 lore raw
In reply to Pierre Bourdon

Hi,

Quoted 8 lines · Pierre Bourdon

max17042_get_status uses the core power_supply_am_i_supplied. That function relies on DT properties to figure out the power supply topology, and will error out without DT.

Fixes max17042 battery status being reported as "unknown".

---

Thanks, queued to power-supply's fixes branch.

-- Sebastian

Quoted 18 lines
 drivers/power/supply/max17042_battery.c | 1 +
 1 file changed, 1 insertion(+)
drivers/power/supply/max17042_battery.c +1 -0
index 35dde81b1c9b..1a568df383db 100644
@@ -1053,6 +1053,7 @@ static int max17042_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, chip);
 	psy_cfg.drv_data = chip;
+	psy_cfg.of_node = dev->of_node;
 
 	/* When current is not measured,
 	 * CURRENT_NOW and CURRENT_AVG properties should be invisible. */
Signature · 1 line
2.16.1.291.g4437f3f132-goog