typec: tcpm: Populate fwnode for use in power_supply core
Subsystems (3)
cover typec: tcpm: Populate fwnode for use in power_supply core
This patch set adds support for passing a fwnode pointer as part of the psy config structure, when intialising the psy core, so that calling code can be written to be agnostic of the HW description required for the platform. The TCPM code is updated subsequently to make use of this new field.
For now the main FW support in the psy core is still just DT based but in the future ACPI will likely be added and can use this field.
Adam Thomson (2):
power: supply: Add fwnode pointer to power_supply_config struct
typec: tcpm: Provide fwnode pointer as part of psy_cfg
drivers/power/supply/power_supply_core.c | 4 +++- drivers/usb/typec/tcpm.c | 2 ++ include/linux/power_supply.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.1
PATCH 1/2 power: supply: Add fwnode pointer to power_supply_config struct
To allow users of the power supply framework to be hw description agnostic, this commit adds the ability to pass a fwnode pointer, via the power_supply_config structure, to the initialisation code of the core, instead of explicitly specifying of_ndoe. If that fwnode pointer is provided then it will automatically resolve down to of_node on platforms which support it, otherwise it will be NULL.
In the future, when ACPI support is added, this can be modified to accommodate ACPI without the need to change calling code which already provides the fwnode handle in this manner.
--- drivers/power/supply/power_supply_core.c | 4 +++- include/linux/power_supply.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/power/supply/power_supply_core.c +3 -1
@@ -19,6 +19,7 @@#include <linux/err.h> #include <linux/of.h> #include <linux/power_supply.h> +#include <linux/property.h> #include <linux/thermal.h> #include "power_supply.h"
@@ -874,7 +875,8 @@ static void psy_unregister_cooler(struct power_supply *psy) psy->desc = desc;if (cfg) { psy->drv_data = cfg->drv_data; - psy->of_node = cfg->of_node; + psy->of_node = + cfg->fwnode ?to_of_node (cfg->fwnode) : cfg->of_node; psy->supplied_to = cfg->supplied_to; psy->num_supplicants = cfg->num_supplicants; }
include/linux/power_supply.h +2 -0
@@ -199,6 +199,8 @@ enum power_supply_notifier_events {/* Run-time specific power supply configuration */ struct power_supply_config {struct device_node *of_node; +struct fwnode_handle *fwnode; +/* Driver private data */ void *drv_data;
Signature · 1 line
1.9.1
Re: [PATCH 1/2] power: supply: Add fwnode pointer to power_supply_config struct
Hi,
Quoted 7 lines · Adam Thomson
To allow users of the power supply framework to be hw description agnostic, this commit adds the ability to pass a fwnode pointer, via the
power_supply_configstructure, to the initialisation code of the core, instead of explicitly specifyingof_ndoe. If that fwnode pointer is provided then it will automatically resolve down toof_nodeon platforms which support it, otherwise it will be NULL.
Quoted 7 lines
In the future, when ACPI support is added, this can be modified to accommodate ACPI without the need to change calling code which already provides the fwnode handle in this manner.
Signed-off-by Adam Thomson <[email protected]>Suggested-by Heikki Krogerus <[email protected]>---
-- Sebastian
Quoted 42 lines
drivers/power/supply/power_supply_core.c | 4 +++- include/linux/power_supply.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)drivers/power/supply/power_supply_core.c +3
-1@@ -19,6 +19,7 @@#include <linux/err.h> #include <linux/of.h> #include <linux/power_supply.h> +#include <linux/property.h> #include <linux/thermal.h> #include "power_supply.h" @@ -874,7 +875,8 @@ static void psy_unregister_cooler(struct power_supply *psy) psy->desc = desc;if (cfg) { psy->drv_data = cfg->drv_data; - psy->of_node = cfg->of_node; + psy->of_node = + cfg->fwnode ?to_of_node (cfg->fwnode) : cfg->of_node; psy->supplied_to = cfg->supplied_to; psy->num_supplicants = cfg->num_supplicants; }include/linux/power_supply.h +2
-0@@ -199,6 +199,8 @@ enum power_supply_notifier_events {/* Run-time specific power supply configuration */ struct power_supply_config {struct device_node *of_node; +struct fwnode_handle *fwnode; +/* Driver private data */ void *drv_data;Signature · 1 line
1.9.1
Re: [PATCH 1/2] power: supply: Add fwnode pointer to power_supply_config struct
In reply to Adam ThomsonQuoted 7 lines · Adam Thomson
To allow users of the power supply framework to be hw description agnostic, this commit adds the ability to pass a fwnode pointer, via the
power_supply_configstructure, to the initialisation code of the core, instead of explicitly specifyingof_ndoe. If that fwnode pointer is provided then it will automatically resolve down toof_nodeon platforms which support it, otherwise it will be NULL.
Quoted 6 lines
In the future, when ACPI support is added, this can be modified to accommodate ACPI without the need to change calling code which already provides the fwnode handle in this manner.
Signed-off-by Adam Thomson <[email protected]>Suggested-by Heikki Krogerus <[email protected]>
Thanks Adam! FWIW:
Quoted 32 lines
--- drivers/power/supply/power_supply_core.c | 4 +++- include/linux/power_supply.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)drivers/power/supply/power_supply_core.c +3
-1@@ -19,6 +19,7 @@#include <linux/err.h> #include <linux/of.h> #include <linux/power_supply.h> +#include <linux/property.h> #include <linux/thermal.h> #include "power_supply.h" @@ -874,7 +875,8 @@ static void psy_unregister_cooler(struct power_supply *psy) psy->desc = desc;if (cfg) { psy->drv_data = cfg->drv_data; - psy->of_node = cfg->of_node; + psy->of_node = + cfg->fwnode ?to_of_node (cfg->fwnode) : cfg->of_node; psy->supplied_to = cfg->supplied_to; psy->num_supplicants = cfg->num_supplicants; }include/linux/power_supply.h +0
-0
include/linux/power_supply.h enum power_supply_notifier_events { · line 205
Quoted 7 lines
include/linux/power_supply.h +2
-0@@ -199,6 +199,8 @@ enum power_supply_notifier_events {/* Run-time specific power supply configuration */ struct power_supply_config {struct device_node *of_node; +struct fwnode_handle *fwnode; +/* Driver private data */ void *drv_data;
Thanks,
Signature · 1 line
heikki
PATCH 2/2 typec: tcpm: Provide fwnode pointer as part of psy_cfg
In reply to Adam ThomsonFor supply registration, provide fwnode pointer of the port device, via the power_supply_config structure, to allow other psy drivers to add us as a supplier. At present this only applies to DT based platforms using the 'power-supplies' DT property, but in the future should also work for ACPI platforms when the relevant support is added to the power_supply core.
--- drivers/usb/typec/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/tcpm.c +2 -0
@@ -14,6 +14,7 @@#include <linux/mutex.h> #include <linux/power_supply.h> #include <linux/proc_fs.h> +#include <linux/property.h> #include <linux/sched/clock.h> #include <linux/seq_file.h> #include <linux/slab.h>
@@ -4500,6 +4501,7 @@ static int devm_tcpm_psy_register(struct tcpm_port *port)char *psy_name; psy_cfg.drv_data = port; + psy_cfg.fwnode =dev_fwnode (port->dev); psy_name =devm_kzalloc (port->dev, psy_name_len,GFP_KERNEL );if (!psy_name)return -ENOMEM ;
Signature · 1 line
1.9.1
Re: [PATCH 2/2] typec: tcpm: Provide fwnode pointer as part of psy_cfg
Quoted 9 lines · Adam Thomson
For supply registration, provide fwnode pointer of the port device, via the
power_supply_configstructure, to allow other psy drivers to add us as a supplier. At present this only applies to DT based platforms using the 'power-supplies' DT property, but in the future should also work for ACPI platforms when the relevant support is added to thepower_supplycore.Signed-off-by Adam Thomson <[email protected]>Suggested-by Heikki Krogerus <[email protected]>
Quoted 27 lines
--- drivers/usb/typec/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/tcpm.c +2
-0@@ -14,6 +14,7 @@#include <linux/mutex.h> #include <linux/power_supply.h> #include <linux/proc_fs.h> +#include <linux/property.h> #include <linux/sched/clock.h> #include <linux/seq_file.h> #include <linux/slab.h> @@ -4500,6 +4501,7 @@ static int devm_tcpm_psy_register(struct tcpm_port *port)char *psy_name; psy_cfg.drv_data = port; + psy_cfg.fwnode =dev_fwnode (port->dev); psy_name =devm_kzalloc (port->dev, psy_name_len,GFP_KERNEL );if (!psy_name)return -ENOMEM ;Signature · 1 line
1.9.1
Re: [PATCH 2/2] typec: tcpm: Provide fwnode pointer as part of psy_cfg
In reply to Adam ThomsonQuoted 9 lines · Adam Thomson
For supply registration, provide fwnode pointer of the port device, via the
power_supply_configstructure, to allow other psy drivers to add us as a supplier. At present this only applies to DT based platforms using the 'power-supplies' DT property, but in the future should also work for ACPI platforms when the relevant support is added to thepower_supplycore.Signed-off-by Adam Thomson <[email protected]>Suggested-by Heikki Krogerus <[email protected]>
Quoted 17 lines
--- drivers/usb/typec/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/tcpm.c +1
-0@@ -14,6 +14,7 @@#include <linux/mutex.h> #include <linux/power_supply.h> #include <linux/proc_fs.h> +#include <linux/property.h> #include <linux/sched/clock.h> #include <linux/seq_file.h> #include <linux/slab.h>
drivers/usb/typec/tcpm.c static int devm_tcpm_psy_register(struct tcpm_port *port) · line 4507
Quoted 7 lines
drivers/usb/typec/tcpm.c +1
-0@@ -4500,6 +4501,7 @@ static int devm_tcpm_psy_register(struct tcpm_port *port)char *psy_name; psy_cfg.drv_data = port; + psy_cfg.fwnode =dev_fwnode (port->dev); psy_name =devm_kzalloc (port->dev, psy_name_len,GFP_KERNEL );if (!psy_name)return -ENOMEM ;
Thanks,
Signature · 1 line
heikki