usb: typec: add API to get sink and source config
PATCH v3 5/12 usb: typec: add API to get sink and source config
Hi,
Quoted 48 lines · Li Jun
This patch add 2 APIs to get sink and source power config from firmware description in case the port supports PD.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/typec/tcpm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/tcpm.h | 8 +++++--- 2 files changed, 52 insertions(+), 3 deletions(-)drivers/usb/typec/tcpm.c +24
-0@@ -13,6 +13,7 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/proc_fs.h> +#include <linux/property.h> #include <linux/sched/clock.h> #include <linux/seq_file.h> #include <linux/slab.h> @@ -3595,6 +3596,52 @@ static int tcpm_copy_vdos(u32 *dest_vdo, const u32 *src_vdo,return nr_vdo; } +int tcpm_get_src_config (struct fwnode_handle *fwnode,struct tcpc_config *tcfg) +{ +int ret; + +if (!fwnode) +return -EINVAL ; + + ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , +NULL ,0 ); +if (ret <=0 ) +return -EINVAL ; + + tcfg->nr_src_pdo =min (ret,PDO_MAX_OBJECTS ); +return fwnode_property_read_u32_array (fwnode,"source-pdos" , + tcfg->src_pdo, tcfg->nr_src_pdo); +} +EXPORT_SYMBOL_GPL (tcpm_get_src_config); + +int tcpm_get_snk_config (struct fwnode_handle *fwnode,struct tcpc_config *tcfg) +{ +int ret; + +if (!fwnode)
drivers/usb/typec/tcpm.c static int tcpm_copy_vdos(u32 *dest_vdo, const u32 *src_vdo, · line 3631
Quoted 10 lines
drivers/usb/typec/tcpm.c +10
-0+return -EINVAL ; + +if ((fwnode_property_read_u32 (fwnode,"max-sink-microvolt" , + &tcfg->max_snk_mv) <0 ) || + (fwnode_property_read_u32 (fwnode,"max-sink-microamp" , + &tcfg->max_snk_ma) <0 ) || + (fwnode_property_read_u32 (fwnode,"max-sink-microwatt-hours" , + &tcfg->max_snk_mw) <0 ) || + (fwnode_property_read_u32 (fwnode,"op-sink-microwatt-hours" , + &tcfg->operating_snk_mw) <0 ))
If DT is changed to use micro instead of milli, these values needs to be divided by 1000.
// Mats
Quoted 44 lines
drivers/usb/typec/tcpm.c +13
-0+return -EINVAL ; + + ret =fwnode_property_read_u32_array (fwnode,"sink-pdos" , +NULL ,0 ); +if (ret <=0 ) +return -EINVAL ; + + tcfg->nr_snk_pdo =min (ret,PDO_MAX_OBJECTS ); +return fwnode_property_read_u32_array (fwnode,"sink-pdos" , + tcfg->snk_pdo, tcfg->nr_snk_pdo); +} +EXPORT_SYMBOL_GPL (tcpm_get_snk_config); +int tcpm_update_source_capabilities (struct tcpm_port *port,const u32 *pdo,unsigned int nr_pdo) {include/linux/usb/tcpm.h +3
-3@@ -76,10 +76,10 @@ enum tcpm_transmit_type {* @alt_modes: List of supported alternate modes */ struct tcpc_config { -const u32 *src_pdo; +u32 *src_pdo;unsigned int nr_src_pdo; -const u32 *snk_pdo; +u32 *snk_pdo;unsigned int nr_snk_pdo;const u32 *snk_vdo;@@ -143,7 +143,7 @@ enum tcpc_mux_mode {* @mux: Pointer to multiplexer data */ struct tcpc_dev { -const struct tcpc_config *config; +struct tcpc_config *config;struct fwnode_handle *fwnode;int (*init)(struct tcpc_dev *dev);
include/linux/usb/tcpm.h void tcpm_pd_transmit_complete(struct tcpm_port *port, · line 195
Quoted 7 lines
include/linux/usb/tcpm.h +2
-0@@ -189,5 +189,7 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port, enum tcpm_transmit_status status);void tcpm_pd_hard_reset (struct tcpm_port *port);void tcpm_tcpc_reset (struct tcpm_port *port); +int tcpm_get_src_config (struct fwnode_handle *fwnode,struct tcpc_config *tcfg); +int tcpm_get_snk_config (struct fwnode_handle *fwnode,struct tcpc_config *tcfg);#endif /* __LINUX_USB_TCPM_H */
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html