usb: typec: UCSI driver overhaul
Subsystems (3)
Heikki Krogerus
maintainercover usb: typec: UCSI driver overhaul
Hi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in ucsi_ccg.c in order to handle them, so ucsi.c is not touched at all.
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface - and squash all alt modes with the same SVID into one that we supply to the ucsi.c when ever it sends GET_ALTERNATE_MODES command. Also other alt mode commands like SET_NEW_CAM can have special processing in ucsi_ccg.c and ucsi_ccg.c alone. There should not be any problem with that anymore.
thanks,
Heikki Krogerus (14):
usb: typec: Copy everything from struct typec_capability during
registration
usb: typec: Introduce typec_get_drvdata()
usb: typec: Separate the operations vector
usb: typec: tcpm: Start using struct typec_operations
usb: typec: tps6598x: Start using struct typec_operations
usb: typec: ucsi: Start using struct typec_operations
usb: typec: Remove the callback members from struct typec_capability
usb: typec: ucsi: ccg: Remove run_isr flag
usb: typec: ucsi: Simplified interface registration and I/O API
usb: typec: ucsi: acpi: Move to the new API
usb: typec: ucsi: ccg: Move to the new API
usb: typec: ucsi: Remove the old API
usb: typec: ucsi: Remove struct ucsi_control
usb: typec: ucsi: Remove all bit-fields
drivers/usb/typec/class.c | 125 +++--- drivers/usb/typec/tcpm/tcpm.c | 47 +-- drivers/usb/typec/tps6598x.c | 49 +-- drivers/usb/typec/ucsi/displayport.c | 26 +- drivers/usb/typec/ucsi/trace.c | 11 - drivers/usb/typec/ucsi/trace.h | 79 +--- drivers/usb/typec/ucsi/ucsi.c | 592 ++++++++++++++------------- drivers/usb/typec/ucsi/ucsi.h | 410 +++++++------------ drivers/usb/typec/ucsi/ucsi_acpi.c | 96 ++++- drivers/usb/typec/ucsi/ucsi_ccg.c | 214 ++++------ include/linux/usb/typec.h | 38 +- 11 files changed, 785 insertions(+), 902 deletions(-)
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 1/14 usb: typec: Copy everything from struct typec_capability during registration
Copying everything from struct typec_capability to struct typec_port during port registration.
--- drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-)
drivers/usb/typec/class.c +35 -20
@@ -46,8 +46,14 @@ struct typec_port {enum typec_role vconn_role;enum typec_pwr_opmode pwr_opmode;enum typec_port_type port_type; +enum typec_port_type fixed_role; +enum typec_port_data port_roles; +enum typec_accessory accessory[TYPEC_MAX_ACCESSORY ];struct mutex port_type_lock; +u16 revision; +u16 pd_revision; +enum typec_orientation orientation;struct typec_switch *sw;struct typec_mux *mux;
@@ -950,7 +956,7 @@ preferred_role_store(struct device *dev, struct device_attribute *attr,int role;int ret; -if (port->cap->type !=TYPEC_PORT_DRP ) { +if (port->fixed_role !=TYPEC_PORT_DRP ) {dev_dbg (dev,"Preferred role only supported with DRP ports\n" );return -EOPNOTSUPP ; }
@@ -982,7 +988,7 @@ preferred_role_show(struct device *dev, struct device_attribute *attr, {struct typec_port *port =to_typec_port (dev); -if (port->cap->type !=TYPEC_PORT_DRP ) +if (port->fixed_role !=TYPEC_PORT_DRP )return 0 ;if (port->prefer_role <0 )
@@ -1009,7 +1015,7 @@ static ssize_t data_role_store(struct device *dev,return ret;mutex_lock (&port->port_type_lock); -if (port->cap->data !=TYPEC_PORT_DRD ) { +if (port->port_roles !=TYPEC_PORT_DRD ) { ret = -EOPNOTSUPP ; goto unlock_and_ret; }
@@ -1029,7 +1035,7 @@ static ssize_t data_role_show(struct device *dev, {struct typec_port *port =to_typec_port (dev); -if (port->cap->data ==TYPEC_PORT_DRD ) +if (port->port_roles ==TYPEC_PORT_DRD )return sprintf (buf,"%s\n" , port->data_role ==TYPEC_HOST ?"[host] device" :"host [device]" );
@@ -1044,7 +1050,7 @@ static ssize_t power_role_store(struct device *dev,struct typec_port *port =to_typec_port (dev);int ret; -if (!port->cap->pd_revision) { +if (!port->pd_revision) {dev_dbg (dev,"USB Power Delivery not supported\n" );return -EOPNOTSUPP ; }
@@ -1064,9 +1070,9 @@ static ssize_t power_role_store(struct device *dev,return ret;mutex_lock (&port->port_type_lock); -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->fixed_role !=TYPEC_PORT_DRP ) {dev_dbg (dev,"port type fixed at \"%s\"" , - typec_port_power_roles[port->port_type]); + typec_port_power_roles[port->fixed_role]); ret = -EOPNOTSUPP ; goto unlock_and_ret; }
@@ -1086,7 +1092,7 @@ static ssize_t power_role_show(struct device *dev, {struct typec_port *port =to_typec_port (dev); -if (port->cap->type ==TYPEC_PORT_DRP ) +if (port->fixed_role ==TYPEC_PORT_DRP )return sprintf (buf,"%s\n" , port->pwr_role ==TYPEC_SOURCE ?"[source] sink" :"source [sink]" );
@@ -1102,7 +1108,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,int ret;enum typec_port_type type; -if (!port->cap->port_type_set || port->cap->type !=TYPEC_PORT_DRP ) { +if (!port->cap->port_type_set || port->fixed_role !=TYPEC_PORT_DRP ) {dev_dbg (dev,"changing port type not supported\n" );return -EOPNOTSUPP ; }
@@ -1114,7 +1120,7 @@ port_type_store(struct device *dev, struct device_attribute *attr, type = ret;mutex_lock (&port->port_type_lock); -if (port->port_type == type) { +if (port->fixed_role == type) { ret = size; goto unlock_and_ret; }
@@ -1123,7 +1129,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,if (ret) goto unlock_and_ret; - port->port_type = type; + port->fixed_role = type; ret = size; unlock_and_ret:
@@ -1137,11 +1143,11 @@ port_type_show(struct device *dev, struct device_attribute *attr, {struct typec_port *port =to_typec_port (dev); -if (port->cap->type ==TYPEC_PORT_DRP ) +if (port->fixed_role ==TYPEC_PORT_DRP )return sprintf (buf,"%s\n" , - typec_port_types_drp[port->port_type]); + typec_port_types_drp[port->fixed_role]); -return sprintf (buf,"[%s]\n" , typec_port_power_roles[port->cap->type]); +return sprintf (buf,"[%s]\n" , typec_port_power_roles[port->fixed_role]); }static DEVICE_ATTR_RW (port_type);
@@ -1170,7 +1176,7 @@ static ssize_t vconn_source_store(struct device *dev,bool source;int ret; -if (!port->cap->pd_revision) { +if (!port->pd_revision) {dev_dbg (dev,"VCONN swap depends on USB Power Delivery\n" );return -EOPNOTSUPP ; }
@@ -1209,10 +1215,10 @@ static ssize_t supported_accessory_modes_show(struct device *dev,ssize_t ret =0 ;int i; -for (i =0 ; i <ARRAY_SIZE (port->cap->accessory); i++) { -if (port->cap->accessory[i]) +for (i =0 ; i <ARRAY_SIZE (port->accessory); i++) { +if (port->accessory[i]) ret +=sprintf (buf + ret,"%s " , - typec_accessory_modes[port->cap->accessory[i]]); + typec_accessory_modes[port->accessory[i]]); }if (!ret)
@@ -1229,7 +1235,7 @@ static ssize_t usb_typec_revision_show(struct device *dev, char *buf) {struct typec_port *port =to_typec_port (dev); -u16 rev = port->cap->revision; +u16 rev = port->revision;return sprintf (buf,"%d.%d\n" , (rev >>8 ) &0xff , (rev >>4 ) &0xf ); }
@@ -1241,7 +1247,7 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev, {struct typec_port *p =to_typec_port (dev); -return sprintf (buf,"%d\n" , (p->cap->pd_revision >>8 ) &0xff ); +return sprintf (buf,"%d\n" , (p->pd_revision >>8 ) &0xff ); }static DEVICE_ATTR_RO (usb_power_delivery_revision);
@@ -1532,6 +1538,7 @@ struct typec_port *typec_register_port(struct device *parent,struct typec_port *port;int ret;int id; +int i; port =kzalloc (sizeof (*port),GFP_KERNEL );if (!port)
@@ -1581,8 +1588,16 @@ struct typec_port *typec_register_port(struct device *parent, port->id = id; port->cap = cap; port->port_type = cap->type; + port->fixed_role = cap->type; + port->port_roles = cap->data; port->prefer_role = cap->prefer_role; + port->revision = cap->revision; + port->pd_revision = cap->pd_revision; + +for (i =0 ; i <TYPEC_MAX_ACCESSORY ; i++) + port->accessory[i] = cap->accessory[i]; +device_initialize (&port->dev); port->dev.class = typec_class; port->dev.parent = parent;
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 2/14 usb: typec: Introduce typec_get_drvdata()
In reply to Heikki KrogerusLeaving the private driver_data pointer of the port device to the port drivers.
--- drivers/usb/typec/class.c | 11 +++++++++++ include/linux/usb/typec.h | 4 ++++ 2 files changed, 15 insertions(+)
drivers/usb/typec/class.c +11 -0
@@ -1492,6 +1492,16 @@ EXPORT_SYMBOL_GPL(typec_set_mode);/* --------------------------------------- */ +/** +* typec_get_drvdata - Return private driver data pointer +* @port: USB Type-C port +*/ +void *typec_get_drvdata (struct typec_port *port) +{ +return dev_get_drvdata (&port->dev); +} +EXPORT_SYMBOL_GPL (typec_get_drvdata); +/** * typec_port_register_altmode - Register USB Type-C Port Alternate Mode * @port: USB Type-C Port that supports the alternate mode
@@ -1604,6 +1614,7 @@ struct typec_port *typec_register_port(struct device *parent, port->dev.fwnode = cap->fwnode; port->dev.type = &typec_port_dev_type;dev_set_name (&port->dev,"port%d" , id); +dev_set_drvdata (&port->dev, cap->driver_data); port->sw =typec_switch_get (&port->dev);if (IS_ERR (port->sw)) {
include/linux/usb/typec.h +4 -0
@@ -179,6 +179,7 @@ struct typec_partner_desc {* @sw: Cable plug orientation switch * @mux: Multiplexer switch for Alternate/Accessory Modes * @fwnode: Optional fwnode of the port +* @driver_data: Private pointer for driver specific info * @try_role: Set data role preference for DRP port * @dr_set: Set Data Role * @pr_set: Set Power Role
@@ -198,6 +199,7 @@ struct typec_capability {struct typec_switch *sw;struct typec_mux *mux;struct fwnode_handle *fwnode; +void *driver_data;int (*try_role)(const struct typec_capability *,int role);
@@ -241,6 +243,8 @@ int typec_set_orientation(struct typec_port *port,enum typec_orientation typec_get_orientation (struct typec_port *port);int typec_set_mode (struct typec_port *port,int mode); +void *typec_get_drvdata (struct typec_port *port); +int typec_find_port_power_role (const char *name);int typec_find_power_role (const char *name);int typec_find_port_data_role (const char *name);
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 3/14 usb: typec: Separate the operations vector
In reply to Heikki KrogerusIntroducing struct typec_operations which has the same callbacks as struct typec_capability. The old callbacks are kept for now, but after all users have been converted, they will be removed.
--- drivers/usb/typec/class.c | 90 +++++++++++++++++++++++++-------------- include/linux/usb/typec.h | 19 +++++++++ 2 files changed, 76 insertions(+), 33 deletions(-)
drivers/usb/typec/class.c +57 -33
@@ -59,6 +59,7 @@ struct typec_port {struct typec_mux *mux;const struct typec_capability *cap; +const struct typec_operations *ops; };#define to_typec_port (_dev_) container_of(_dev_, struct typec_port, dev)
@@ -961,11 +962,6 @@ preferred_role_store(struct device *dev, struct device_attribute *attr,return -EOPNOTSUPP ; } -if (!port->cap->try_role) { -dev_dbg (dev,"Setting preferred role not supported\n" ); -return -EOPNOTSUPP ; - } - role =sysfs_match_string (typec_roles, buf);if (role <0 ) {if (sysfs_streq (buf,"none" ))
@@ -974,9 +970,18 @@ preferred_role_store(struct device *dev, struct device_attribute *attr,return -EINVAL ; } - ret = port->cap->try_role (port->cap, role); -if (ret) -return ret; +if (port->ops && port->ops->try_role) { + ret = port->ops->try_role (port, role); +if (ret) +return ret; + }else if (port->cap && port->cap->try_role) { + ret = port->cap->try_role (port->cap, role); +if (ret) +return ret; + }else { +dev_dbg (dev,"Setting preferred role not supported\n" ); +return -EOPNOTSUPP ; + } port->prefer_role = role;return size;
@@ -1005,11 +1010,6 @@ static ssize_t data_role_store(struct device *dev,struct typec_port *port =to_typec_port (dev);int ret; -if (!port->cap->dr_set) { -dev_dbg (dev,"data role swapping not supported\n" ); -return -EOPNOTSUPP ; - } - ret =sysfs_match_string (typec_data_roles, buf);if (ret <0 )return ret;
@@ -1020,9 +1020,19 @@ static ssize_t data_role_store(struct device *dev, goto unlock_and_ret; } - ret = port->cap->dr_set (port->cap, ret); -if (ret) +if (port->ops && port->ops->dr_set) { + ret = port->ops->dr_set (port, ret); +if (ret) + goto unlock_and_ret; + }else if (port->cap && port->cap->dr_set) { + ret = port->cap->dr_set (port->cap, ret); +if (ret) + goto unlock_and_ret; + }else { +dev_dbg (dev,"data role swapping not supported\n" ); + ret = -EOPNOTSUPP ; goto unlock_and_ret; + } ret = size; unlock_and_ret:
@@ -1055,11 +1065,6 @@ static ssize_t power_role_store(struct device *dev,return -EOPNOTSUPP ; } -if (!port->cap->pr_set) { -dev_dbg (dev,"power role swapping not supported\n" ); -return -EOPNOTSUPP ; - } -if (port->pwr_opmode !=TYPEC_PWR_MODE_PD ) {dev_dbg (dev,"partner unable to swap power role\n" );return -EIO ;
@@ -1077,11 +1082,21 @@ static ssize_t power_role_store(struct device *dev, goto unlock_and_ret; } - ret = port->cap->pr_set (port->cap, ret); -if (ret) +if (port->ops && port->ops->pr_set) { + ret = port->ops->pr_set (port, ret); +if (ret) + goto unlock_and_ret; + }else if (port->cap && port->cap->pr_set) { + ret = port->cap->pr_set (port->cap, ret); +if (ret) + goto unlock_and_ret; + }else { +dev_dbg (dev,"power role swapping not supported\n" ); + ret = -EOPNOTSUPP ; goto unlock_and_ret; - + } ret = size; + unlock_and_ret:mutex_unlock (&port->port_type_lock);return ret;
@@ -1108,7 +1123,8 @@ port_type_store(struct device *dev, struct device_attribute *attr,int ret;enum typec_port_type type; -if (!port->cap->port_type_set || port->fixed_role !=TYPEC_PORT_DRP ) { +if ((!port->ops || !port->ops->port_type_set) || + !port->cap->port_type_set || port->fixed_role !=TYPEC_PORT_DRP ) {dev_dbg (dev,"changing port type not supported\n" );return -EOPNOTSUPP ; }
@@ -1125,7 +1141,10 @@ port_type_store(struct device *dev, struct device_attribute *attr, goto unlock_and_ret; } - ret = port->cap->port_type_set (port->cap, type); +if (port->ops && port->ops->port_type_set) + ret = port->ops->port_type_set (port, type); +else + ret = port->cap->port_type_set (port->cap, type);if (ret) goto unlock_and_ret;
@@ -1181,18 +1200,22 @@ static ssize_t vconn_source_store(struct device *dev,return -EOPNOTSUPP ; } -if (!port->cap->vconn_set) { -dev_dbg (dev,"VCONN swapping not supported\n" ); -return -EOPNOTSUPP ; - } - ret =kstrtobool (buf, &source);if (ret)return ret; - ret = port->cap->vconn_set (port->cap, (enum typec_role )source); -if (ret) -return ret; +if (port->ops && port->ops->vconn_set) { + ret = port->ops->vconn_set (port, source); +if (ret) +return ret; + }else if (port->cap && port->cap->vconn_set) { + ret = port->cap->vconn_set (port->cap, (enum typec_role )source); +if (ret) +return ret; + }else { +dev_dbg (dev,"VCONN swapping not supported\n" ); +return -EOPNOTSUPP ; + }return size; }
@@ -1597,6 +1620,7 @@ struct typec_port *typec_register_port(struct device *parent, port->id = id; port->cap = cap; + port->ops = cap->ops; port->port_type = cap->type; port->fixed_role = cap->type; port->port_roles = cap->data;
include/linux/usb/typec.h +19 -0
@@ -168,6 +168,22 @@ struct typec_partner_desc {struct usb_pd_identity *identity; }; +/* +* struct typec_operations - USB Type-C Port Operations +* @try_role: Set data role preference for DRP port +* @dr_set: Set Data Role +* @pr_set: Set Power Role +* @vconn_set: Source VCONN +* @port_type_set: Set port type +*/ +struct typec_operations { +int (*try_role)(struct typec_port *port,int role); +int (*dr_set)(struct typec_port *port,enum typec_data_role ); +int (*pr_set)(struct typec_port *port,enum typec_role ); +int (*vconn_set)(struct typec_port *port,bool source); +int (*port_type_set)(struct typec_port *port,enum typec_port_type ); +}; +/* * struct typec_capability - USB Type-C Port Capabilities * @type: Supported power role of the port
@@ -180,6 +196,7 @@ struct typec_partner_desc {* @mux: Multiplexer switch for Alternate/Accessory Modes * @fwnode: Optional fwnode of the port * @driver_data: Private pointer for driver specific info +* @ops: Port operations vector * @try_role: Set data role preference for DRP port * @dr_set: Set Data Role * @pr_set: Set Power Role
@@ -201,6 +218,8 @@ struct typec_capability {struct fwnode_handle *fwnode;void *driver_data; +const struct typec_operations *ops; +int (*try_role)(const struct typec_capability *,int role);
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 4/14 usb: typec: tcpm: Start using struct typec_operations
In reply to Heikki KrogerusSupplying the operation callbacks as part of a struct typec_operations instead of as part of struct typec_capability during port registration.
--- drivers/usb/typec/tcpm/tcpm.c | 47 ++++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +21 -26
@@ -390,12 +390,6 @@ static enum tcpm_state tcpm_default_state(struct tcpm_port *port)return SRC_UNATTACHED ; } -static inline -struct tcpm_port *typec_cap_to_tcpm (const struct typec_capability *cap) -{ - return container_of(cap, struct tcpm_port, typec_caps); -} -static bool tcpm_port_is_disconnected (struct tcpm_port *port) { return (!port->attached && port->cc1 == TYPEC_CC_OPEN &&
@@ -3970,10 +3964,9 @@ void tcpm_pd_hard_reset(struct tcpm_port *port) }EXPORT_SYMBOL_GPL (tcpm_pd_hard_reset); -static int tcpm_dr_set (const struct typec_capability *cap, -enum typec_data_role data) +static int tcpm_dr_set (struct typec_port *p,enum typec_data_role data) { -struct tcpm_port *port =typec_cap_to_tcpm (cap); +struct tcpm_port *port =typec_get_drvdata (p);int ret;mutex_lock (&port->swap_lock);
@@ -4038,10 +4031,9 @@ static int tcpm_dr_set(const struct typec_capability *cap,return ret; } -static int tcpm_pr_set (const struct typec_capability *cap, -enum typec_role role) +static int tcpm_pr_set (struct typec_port *p,enum typec_role role) { -struct tcpm_port *port =typec_cap_to_tcpm (cap); +struct tcpm_port *port =typec_get_drvdata (p);int ret;mutex_lock (&port->swap_lock);
@@ -4082,10 +4074,9 @@ static int tcpm_pr_set(const struct typec_capability *cap,return ret; } -static int tcpm_vconn_set (const struct typec_capability *cap, -enum typec_role role) +static int tcpm_vconn_set (struct typec_port *p,bool source) { -struct tcpm_port *port =typec_cap_to_tcpm (cap); +struct tcpm_port *port =typec_get_drvdata (p);int ret;mutex_lock (&port->swap_lock);
@@ -4096,7 +4087,7 @@ static int tcpm_vconn_set(const struct typec_capability *cap, goto port_unlock; } -if (role == port->vconn_role) { +if (source == port->vconn_role) { ret =0 ; goto port_unlock; }
@@ -4122,9 +4113,9 @@ static int tcpm_vconn_set(const struct typec_capability *cap,return ret; } -static int tcpm_try_role (const struct typec_capability *cap,int role) +static int tcpm_try_role (struct typec_port *p,int role) { -struct tcpm_port *port =typec_cap_to_tcpm (cap); +struct tcpm_port *port =typec_get_drvdata (p);struct tcpc_dev *tcpc = port->tcpc;int ret =0 ;
@@ -4331,10 +4322,9 @@ static void tcpm_init(struct tcpm_port *port)tcpm_set_state (port,PORT_RESET ,0 ); } -static int tcpm_port_type_set (const struct typec_capability *cap, -enum typec_port_type type) +static int tcpm_port_type_set (struct typec_port *p,enum typec_port_type type) { -struct tcpm_port *port =typec_cap_to_tcpm (cap); +struct tcpm_port *port =typec_get_drvdata (p);mutex_lock (&port->lock);if (type == port->port_type)
@@ -4359,6 +4349,14 @@ static int tcpm_port_type_set(const struct typec_capability *cap,return 0 ; } +static const struct typec_operations tcpm_ops = { + .try_role = tcpm_try_role, + .dr_set = tcpm_dr_set, + .pr_set = tcpm_pr_set, + .vconn_set = tcpm_vconn_set, + .port_type_set = tcpm_port_type_set +}; +void tcpm_tcpc_reset (struct tcpm_port *port) {mutex_lock (&port->lock);
@@ -4770,11 +4768,8 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->typec_caps.fwnode = tcpc->fwnode; port->typec_caps.revision =0x0120 ;/* Type-C spec release 1.2 */ port->typec_caps.pd_revision =0x0300 ;/* USB-PD spec release 3.0 */ - port->typec_caps.dr_set = tcpm_dr_set; - port->typec_caps.pr_set = tcpm_pr_set; - port->typec_caps.vconn_set = tcpm_vconn_set; - port->typec_caps.try_role = tcpm_try_role; - port->typec_caps.port_type_set = tcpm_port_type_set; + port->typec_caps.driver_data = port; + port->typec_caps.ops = &tcpm_ops; port->partner_desc.identity = &port->partner_ident; port->port_type = port->typec_caps.type;
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 5/14 usb: typec: tps6598x: Start using struct typec_operations
In reply to Heikki KrogerusSupplying the operation callbacks as part of a struct typec_operations instead of as part of struct typec_capability during port registration. After this there is not need to keep the capabilities stored anywhere in the driver.
--- drivers/usb/typec/tps6598x.c | 49 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-)
drivers/usb/typec/tps6598x.c +26 -23
@@ -94,7 +94,6 @@ struct tps6598x {struct typec_port *port;struct typec_partner *partner;struct usb_pd_identity partner_identity; -struct typec_capability typec_cap; };/*
@@ -307,11 +306,10 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,return 0 ; } -static int -tps6598x_dr_set (const struct typec_capability *cap,enum typec_data_role role) +static int tps6598x_dr_set (struct typec_port *port,enum typec_data_role role) { - struct tps6598x *tps = container_of(cap, struct tps6598x, typec_cap);const char *cmd = (role ==TYPEC_DEVICE ) ?"SWUF" :"SWDF" ; +struct tps6598x *tps =typec_get_drvdata (port);u32 status;int ret;
@@ -338,11 +336,10 @@ tps6598x_dr_set(const struct typec_capability *cap, enum typec_data_role role)return ret; } -static int -tps6598x_pr_set (const struct typec_capability *cap,enum typec_role role) +static int tps6598x_pr_set (struct typec_port *port,enum typec_role role) { - struct tps6598x *tps = container_of(cap, struct tps6598x, typec_cap);const char *cmd = (role ==TYPEC_SINK ) ?"SWSk" :"SWSr" ; +struct tps6598x *tps =typec_get_drvdata (port);u32 status;int ret;
@@ -369,6 +366,11 @@ tps6598x_pr_set(const struct typec_capability *cap, enum typec_role role)return ret; } +static const struct typec_operations tps6598x_ops = { + .dr_set = tps6598x_dr_set, + .pr_set = tps6598x_pr_set, +}; +static irqreturn_t tps6598x_interrupt (int irq,void *data) {struct tps6598x *tps = data;
@@ -448,6 +450,7 @@ static const struct regmap_config tps6598x_regmap_config = {static int tps6598x_probe (struct i2c_client *client) { +struct typec_capability typec_cap = { };struct tps6598x *tps;u32 status;u32 conf;
@@ -492,40 +495,40 @@ static int tps6598x_probe(struct i2c_client *client)if (ret <0 )return ret; - tps->typec_cap.revision =USB_TYPEC_REV_1_2 ; - tps->typec_cap.pd_revision =0x200 ; - tps->typec_cap.prefer_role =TYPEC_NO_PREFERRED_ROLE ; - tps->typec_cap.pr_set = tps6598x_pr_set; - tps->typec_cap.dr_set = tps6598x_dr_set; + typec_cap.revision =USB_TYPEC_REV_1_2 ; + typec_cap.pd_revision =0x200 ; + typec_cap.prefer_role =TYPEC_NO_PREFERRED_ROLE ; + typec_cap.driver_data = tps; + typec_cap.ops = &tps6598x_ops;switch (TPS_SYSCONF_PORTINFO (conf)) {case TPS_PORTINFO_SINK_ACCESSORY :case TPS_PORTINFO_SINK : - tps->typec_cap.type =TYPEC_PORT_SNK ; - tps->typec_cap.data =TYPEC_PORT_UFP ; + typec_cap.type =TYPEC_PORT_SNK ; + typec_cap.data =TYPEC_PORT_UFP ;break ;case TPS_PORTINFO_DRP_UFP_DRD :case TPS_PORTINFO_DRP_DFP_DRD : - tps->typec_cap.type =TYPEC_PORT_DRP ; - tps->typec_cap.data =TYPEC_PORT_DRD ; + typec_cap.type =TYPEC_PORT_DRP ; + typec_cap.data =TYPEC_PORT_DRD ;break ;case TPS_PORTINFO_DRP_UFP : - tps->typec_cap.type =TYPEC_PORT_DRP ; - tps->typec_cap.data =TYPEC_PORT_UFP ; + typec_cap.type =TYPEC_PORT_DRP ; + typec_cap.data =TYPEC_PORT_UFP ;break ;case TPS_PORTINFO_DRP_DFP : - tps->typec_cap.type =TYPEC_PORT_DRP ; - tps->typec_cap.data =TYPEC_PORT_DFP ; + typec_cap.type =TYPEC_PORT_DRP ; + typec_cap.data =TYPEC_PORT_DFP ;break ;case TPS_PORTINFO_SOURCE : - tps->typec_cap.type =TYPEC_PORT_SRC ; - tps->typec_cap.data =TYPEC_PORT_DFP ; + typec_cap.type =TYPEC_PORT_SRC ; + typec_cap.data =TYPEC_PORT_DFP ;break ;default :return -ENODEV ; } - tps->port =typec_register_port (&client->dev, &tps->typec_cap); + tps->port =typec_register_port (&client->dev, &typec_cap);if (IS_ERR (tps->port))return PTR_ERR (tps->port);
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 6/14 usb: typec: ucsi: Start using struct typec_operations
In reply to Heikki KrogerusSupplying the operation callbacks as part of a struct typec_operations instead of as part of struct typec_capability during port registration.
--- drivers/usb/typec/ucsi/ucsi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +11 -11
@@ -17,9 +17,6 @@#include "ucsi.h" #include "trace.h" -#define to_ucsi_connector (_cap_) container_of(_cap_, struct ucsi_connector, \ - typec_cap) -/* * UCSI_TIMEOUT_MS - PPM communication timeout *
@@ -713,10 +710,9 @@ static int ucsi_role_cmd(struct ucsi_connector *con, struct ucsi_control *ctrl)return ret; } -static int -ucsi_dr_swap (const struct typec_capability *cap,enum typec_data_role role) +static int ucsi_dr_swap (struct typec_port *port,enum typec_data_role role) { -struct ucsi_connector *con =to_ucsi_connector (cap); +struct ucsi_connector *con =typec_get_drvdata (port);struct ucsi_control ctrl;int ret =0 ;
@@ -748,10 +744,9 @@ ucsi_dr_swap(const struct typec_capability *cap, enum typec_data_role role)return ret <0 ? ret :0 ; } -static int -ucsi_pr_swap (const struct typec_capability *cap,enum typec_role role) +static int ucsi_pr_swap (struct typec_port *port,enum typec_role role) { -struct ucsi_connector *con =to_ucsi_connector (cap); +struct ucsi_connector *con =typec_get_drvdata (port);struct ucsi_control ctrl;int ret =0 ;
@@ -788,6 +783,11 @@ ucsi_pr_swap(const struct typec_capability *cap, enum typec_role role)return ret; } +static const struct typec_operations ucsi_ops = { + .dr_set = ucsi_dr_swap, + .pr_set = ucsi_pr_swap +}; +static struct fwnode_handle *ucsi_find_fwnode (struct ucsi_connector *con) {struct fwnode_handle *fwnode;
@@ -843,8 +843,8 @@ static int ucsi_register_port(struct ucsi *ucsi, int index) *accessory =TYPEC_ACCESSORY_DEBUG ; cap->fwnode =ucsi_find_fwnode (con); - cap->dr_set = ucsi_dr_swap; - cap->pr_set = ucsi_pr_swap; + cap->driver_data = con; + cap->ops = &ucsi_ops;/* Register the connector */ con->port =typec_register_port (ucsi->dev, cap);
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 7/14 usb: typec: Remove the callback members from struct typec_capability
In reply to Heikki KrogerusThere are no more users for them.
--- drivers/usb/typec/class.c | 65 +++++++++++++-------------------------- include/linux/usb/typec.h | 17 ---------- 2 files changed, 22 insertions(+), 60 deletions(-)
drivers/usb/typec/class.c +22 -43
@@ -58,7 +58,6 @@ struct typec_port {struct typec_switch *sw;struct typec_mux *mux; -const struct typec_capability *cap;const struct typec_operations *ops; };
@@ -970,19 +969,15 @@ preferred_role_store(struct device *dev, struct device_attribute *attr,return -EINVAL ; } -if (port->ops && port->ops->try_role) { - ret = port->ops->try_role (port, role); -if (ret) -return ret; - }else if (port->cap && port->cap->try_role) { - ret = port->cap->try_role (port->cap, role); -if (ret) -return ret; - }else { +if (!port->ops || !port->ops->try_role) {dev_dbg (dev,"Setting preferred role not supported\n" );return -EOPNOTSUPP ; } + ret = port->ops->try_role (port, role); +if (ret) +return ret; + port->prefer_role = role;return size; }
@@ -1020,20 +1015,16 @@ static ssize_t data_role_store(struct device *dev, goto unlock_and_ret; } -if (port->ops && port->ops->dr_set) { - ret = port->ops->dr_set (port, ret); -if (ret) - goto unlock_and_ret; - }else if (port->cap && port->cap->dr_set) { - ret = port->cap->dr_set (port->cap, ret); -if (ret) - goto unlock_and_ret; - }else { +if (!port->ops || !port->ops->dr_set) {dev_dbg (dev,"data role swapping not supported\n" ); ret = -EOPNOTSUPP ; goto unlock_and_ret; } + ret = port->ops->dr_set (port, ret); +if (ret) + goto unlock_and_ret; + ret = size; unlock_and_ret:mutex_unlock (&port->port_type_lock);
@@ -1082,21 +1073,17 @@ static ssize_t power_role_store(struct device *dev, goto unlock_and_ret; } -if (port->ops && port->ops->pr_set) { - ret = port->ops->pr_set (port, ret); -if (ret) - goto unlock_and_ret; - }else if (port->cap && port->cap->pr_set) { - ret = port->cap->pr_set (port->cap, ret); -if (ret) - goto unlock_and_ret; - }else { +if (!port->ops || !port->ops->pr_set) {dev_dbg (dev,"power role swapping not supported\n" ); ret = -EOPNOTSUPP ; goto unlock_and_ret; } ret = size; + ret = port->ops->pr_set (port, ret); +if (ret) + goto unlock_and_ret; + unlock_and_ret:mutex_unlock (&port->port_type_lock);return ret;
@@ -1124,7 +1111,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,enum typec_port_type type;if ((!port->ops || !port->ops->port_type_set) || - !port->cap->port_type_set || port->fixed_role !=TYPEC_PORT_DRP ) { + port->fixed_role !=TYPEC_PORT_DRP ) {dev_dbg (dev,"changing port type not supported\n" );return -EOPNOTSUPP ; }
@@ -1141,10 +1128,7 @@ port_type_store(struct device *dev, struct device_attribute *attr, goto unlock_and_ret; } -if (port->ops && port->ops->port_type_set) - ret = port->ops->port_type_set (port, type); -else - ret = port->cap->port_type_set (port->cap, type); + ret = port->ops->port_type_set (port, type);if (ret) goto unlock_and_ret;
@@ -1204,19 +1188,15 @@ static ssize_t vconn_source_store(struct device *dev,if (ret)return ret; -if (port->ops && port->ops->vconn_set) { - ret = port->ops->vconn_set (port, source); -if (ret) -return ret; - }else if (port->cap && port->cap->vconn_set) { - ret = port->cap->vconn_set (port->cap, (enum typec_role )source); -if (ret) -return ret; - }else { +if (!port->ops || !port->ops->vconn_set) {dev_dbg (dev,"VCONN swapping not supported\n" );return -EOPNOTSUPP ; } + ret = port->ops->vconn_set (port, source); +if (ret) +return ret; +return size; }
@@ -1619,7 +1599,6 @@ struct typec_port *typec_register_port(struct device *parent,mutex_init (&port->port_type_lock); port->id = id; - port->cap = cap; port->ops = cap->ops; port->port_type = cap->type; port->fixed_role = cap->type;
include/linux/usb/typec.h +0 -17
@@ -197,11 +197,6 @@ struct typec_operations {* @fwnode: Optional fwnode of the port * @driver_data: Private pointer for driver specific info * @ops: Port operations vector -* @try_role: Set data role preference for DRP port -* @dr_set: Set Data Role -* @pr_set: Set Power Role -* @vconn_set: Set VCONN Role -* @port_type_set: Set port type * * Static capabilities of a single USB Type-C port. */
@@ -219,18 +214,6 @@ struct typec_capability {void *driver_data;const struct typec_operations *ops; - -int (*try_role)(const struct typec_capability *, -int role); - -int (*dr_set)(const struct typec_capability *, -enum typec_data_role ); -int (*pr_set)(const struct typec_capability *, -enum typec_role ); -int (*vconn_set)(const struct typec_capability *, -enum typec_role ); -int (*port_type_set)(const struct typec_capability *, -enum typec_port_type ); };/* Specific to try_role(). Indicates the user want's to clear the preference. */
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 8/14 usb: typec: ucsi: ccg: Remove run_isr flag
In reply to Heikki KrogerusThe "run_isr" flag is used for preventing the driver from calling the interrupt service routine in its runtime resume callback when the driver is expecting completion to a command, but what that basically does is that it hides the real problem. The real problem is that the controller is allowed to suspend in the middle of command execution.
As a more appropriate fix for the problem, using autosuspend delay time that matches UCSI_TIMEOUT_MS (5s). That prevents the controller from suspending while still in the middle of executing a command.
This fixes a potential deadlock. Both ccg_read() and ccg_write() are called with the mutex already taken at least from ccg_send_command(). In ccg_read() and ccg_write, the mutex is only acquired so that run_isr flag can be set.
--- drivers/usb/typec/ucsi/ucsi_ccg.c | 42 +++---------------------------- 1 file changed, 4 insertions(+), 38 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +4 -38
@@ -195,7 +195,6 @@ struct ucsi_ccg {/* fw build with vendor information */ u16 fw_build; -bool run_isr;/* flag to call ISR routine during resume */ struct work_struct pm_work; };
@@ -224,18 +223,6 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)if (quirks && quirks->max_read_len) max_read_len = quirks->max_read_len; -if (uc->fw_build ==CCG_FW_BUILD_NVIDIA && - uc->fw_version <=CCG_OLD_FW_VERSION ) { -mutex_lock (&uc->lock); -/* -* Do not schedule pm_work to run ISR in -* ucsi_ccg_runtime_resume() after pm_runtime_get_sync() -* since we are already in ISR path. -*/ - uc->run_isr = false; -mutex_unlock (&uc->lock); - } -pm_runtime_get_sync (uc->dev);while (rem_len >0 ) { msgs[1 ].buf = &data[len - rem_len];
@@ -278,18 +265,6 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) msgs[0 ].len = len +sizeof (rab); msgs[0 ].buf = buf; -if (uc->fw_build ==CCG_FW_BUILD_NVIDIA && - uc->fw_version <=CCG_OLD_FW_VERSION ) { -mutex_lock (&uc->lock); -/* -* Do not schedule pm_work to run ISR in -* ucsi_ccg_runtime_resume() after pm_runtime_get_sync() -* since we are already in ISR path. -*/ - uc->run_isr = false; -mutex_unlock (&uc->lock); - } -pm_runtime_get_sync (uc->dev); status =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs));if (status <0 ) {
@@ -1130,7 +1105,6 @@ static int ucsi_ccg_probe(struct i2c_client *client, uc->ppm.sync = ucsi_ccg_sync; uc->dev = dev; uc->client = client; - uc->run_isr = true;mutex_init (&uc->lock);INIT_WORK (&uc->work, ccg_update_firmware);INIT_WORK (&uc->pm_work, ccg_pm_workaround_work);
@@ -1188,6 +1162,8 @@ static int ucsi_ccg_probe(struct i2c_client *client,pm_runtime_set_active (uc->dev);pm_runtime_enable (uc->dev); +pm_runtime_use_autosuspend (uc->dev); +pm_runtime_set_autosuspend_delay (uc->dev,5000 );pm_runtime_idle (uc->dev);return 0 ;
@@ -1229,7 +1205,6 @@ static int ucsi_ccg_runtime_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct ucsi_ccg *uc =i2c_get_clientdata (client); -bool schedule = true;/* * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue
@@ -1237,17 +1212,8 @@ static int ucsi_ccg_runtime_resume(struct device *dev)* Schedule a work to call ISR as a workaround. */ if (uc->fw_build ==CCG_FW_BUILD_NVIDIA && - uc->fw_version <=CCG_OLD_FW_VERSION ) { -mutex_lock (&uc->lock); -if (!uc->run_isr) { - uc->run_isr = true; - schedule = false; - } -mutex_unlock (&uc->lock); - -if (schedule) -schedule_work (&uc->pm_work); - } + uc->fw_version <=CCG_OLD_FW_VERSION ) +schedule_work (&uc->pm_work);return 0 ; }
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 9/14 usb: typec: ucsi: Simplified interface registration and I/O API
In reply to Heikki KrogerusAdding more simplified API for interface registration and read and write operations.
The registration is split into separate creation and registration phases. That allows the drivers to properly initialize the interface before registering it if necessary.
The read and write operations are supplied in a completely separate struct ucsi_operations that is passed to the ucsi_register() function during registration. The new read and write operations will work more traditionally so that the read callback function reads a requested amount of data from an offset, and the write callback functions write the given data to the offset. The drivers will have to support both non-blocking writing and blocking writing. In blocking writing the driver itself is responsible of waiting for the completion event.
The new API makes it possible for the drivers to perform tasks also independently of the core ucsi.c, and that should allow for example quirks to be handled completely in the drivers without the need to touch ucsi.c.
The old API is kept until all drivers have been converted to the new API.
--- drivers/usb/typec/ucsi/ucsi.c | 326 +++++++++++++++++++++++++++++++--- drivers/usb/typec/ucsi/ucsi.h | 57 ++++++ 2 files changed, 354 insertions(+), 29 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +297 -29
@@ -98,6 +98,98 @@ static int ucsi_ack(struct ucsi *ucsi, u8 ack)return ret; } +static int ucsi_acknowledge_command (struct ucsi *ucsi) +{ +u64 ctrl; + + ctrl =UCSI_ACK_CC_CI ; + ctrl |=UCSI_ACK_COMMAND_COMPLETE ; + +return ucsi->ops->sync_write (ucsi,UCSI_CONTROL , &ctrl,sizeof (ctrl)); +} + +static int ucsi_acknowledge_connector_change (struct ucsi *ucsi) +{ +u64 ctrl; + + ctrl =UCSI_ACK_CC_CI ; + ctrl |=UCSI_ACK_CONNECTOR_CHANGE ; + +return ucsi->ops->async_write (ucsi,UCSI_CONTROL , &ctrl,sizeof (ctrl)); +} + +static int ucsi_exec_command (struct ucsi *ucsi,u64 command); + +static int ucsi_read_error (struct ucsi *ucsi) +{ +u16 error; +int ret; + +/* Acknowlege the command that failed */ + ret =ucsi_acknowledge_command (ucsi); +if (ret) +return ret; + + ret =ucsi_exec_command (ucsi,UCSI_GET_ERROR_STATUS ); +if (ret <0 ) +return ret; + + ret = ucsi->ops->read (ucsi,UCSI_MESSAGE_IN , &error,sizeof (error)); +if (ret) +return ret; + +switch (error) { +case UCSI_ERROR_INCOMPATIBLE_PARTNER : +return -EOPNOTSUPP ; +case UCSI_ERROR_CC_COMMUNICATION_ERR : +return -ECOMM ; +case UCSI_ERROR_CONTRACT_NEGOTIATION_FAIL : +return -EPROTO ; +case UCSI_ERROR_DEAD_BATTERY : +dev_warn (ucsi->dev,"Dead battery condition!\n" ); +return -EPERM ; +/* The following mean a bug in this driver */ +case UCSI_ERROR_INVALID_CON_NUM : +case UCSI_ERROR_UNREGONIZED_CMD : +case UCSI_ERROR_INVALID_CMD_ARGUMENT : +dev_err (ucsi->dev,"possible UCSI driver bug (0x%x)\n" , error); +return -EINVAL ; +default : +dev_err (ucsi->dev,"%s: error without status\n" , __func__); +return -EIO ; + } + +return 0 ; +} + +static int ucsi_exec_command (struct ucsi *ucsi,u64 cmd) +{ +u32 cci; +int ret; + + ret = ucsi->ops->sync_write (ucsi,UCSI_CONTROL , &cmd,sizeof (cmd)); +if (ret) +return ret; + + ret = ucsi->ops->read (ucsi,UCSI_CCI , &cci,sizeof (cci)); +if (ret) +return ret; + +if (cci &UCSI_CCI_BUSY ) +return -EBUSY ; + +if (!(cci &UCSI_CCI_COMMAND_COMPLETE )) +return -EIO ; + +if (cci &UCSI_CCI_NOT_SUPPORTED ) +return -EOPNOTSUPP ; + +if (cci &UCSI_CCI_ERROR ) +return ucsi_read_error (ucsi); + +return UCSI_CCI_LENGTH (cci); +} +static int ucsi_run_command (struct ucsi *ucsi,struct ucsi_control *ctrl,void *data,size_t size) {
@@ -106,6 +198,26 @@ static int ucsi_run_command(struct ucsi *ucsi, struct ucsi_control *ctrl,u16 error;int ret; +if (ucsi->ops) { + ret =ucsi_exec_command (ucsi, ctrl->raw_cmd); +if (ret <0 ) +return ret; + + data_length = ret; + +if (data) { + ret = ucsi->ops->read (ucsi,UCSI_MESSAGE_IN , data, size); +if (ret) +return ret; + } + + ret =ucsi_acknowledge_command (ucsi); +if (ret) +return ret; + +return data_length; + } + ret =ucsi_command (ucsi, ctrl);if (ret) goto err;
@@ -518,7 +630,7 @@ static void ucsi_partner_change(struct ucsi_connector *con)ucsi_altmode_update_active (con); } -static void ucsi_connector_change (struct work_struct *work) +static void ucsi_handle_connector_change (struct work_struct *work) { struct ucsi_connector *con = container_of(work, struct ucsi_connector, work);
@@ -580,7 +692,10 @@ static void ucsi_connector_change(struct work_struct *work)if (con->status.change &UCSI_CONSTAT_PARTNER_CHANGE )ucsi_partner_change (con); - ret =ucsi_ack (ucsi,UCSI_ACK_EVENT ); +if (ucsi->ops) + ret =ucsi_acknowledge_connector_change (ucsi); +else + ret =ucsi_ack (ucsi,UCSI_ACK_EVENT );if (ret)dev_err (ucsi->dev,"%s: ACK failed (%d)" , __func__, ret);
@@ -591,6 +706,20 @@ static void ucsi_connector_change(struct work_struct *work)mutex_unlock (&con->lock); } +/** +* ucsi_connector_change - Process Connector Change Event +* @ucsi: UCSI Interface +* @num: Connector number +*/ +void ucsi_connector_change (struct ucsi *ucsi,u8 num) +{ +struct ucsi_connector *con = &ucsi->connector[num -1 ]; + +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags)) +schedule_work (&con->work); +} +EXPORT_SYMBOL_GPL (ucsi_connector_change); +/** * ucsi_notify - PPM notification handler * @ucsi: Source UCSI Interface for the notifications
@@ -647,6 +776,39 @@ static int ucsi_reset_ppm(struct ucsi *ucsi)unsigned long tmo;int ret; +if (ucsi->ops) { +u64 command =UCSI_PPM_RESET ; +u32 cci; + + ret = ucsi->ops->async_write (ucsi,UCSI_CONTROL , &command, +sizeof (command)); +if (ret <0 ) +return ret; + + tmo = jiffies +msecs_to_jiffies (UCSI_TIMEOUT_MS ); + +do { +if (time_is_before_jiffies (tmo)) +return -ETIMEDOUT ; + + ret = ucsi->ops->read (ucsi,UCSI_CCI , &cci,sizeof (cci)); +if (ret) +return ret; + +if (cci & ~UCSI_CCI_RESET_COMPLETE ) { + ret = ucsi->ops->async_write (ucsi,UCSI_CONTROL , + &command, +sizeof (command)); +if (ret <0 ) +return ret; + } + +msleep (20 ); + }while (!(cci &UCSI_CCI_RESET_COMPLETE )); + +return 0 ; + } + ctrl.raw_cmd =0 ; ctrl.cmd.cmd =UCSI_PPM_RESET ;trace_ucsi_command (&ctrl);
@@ -807,7 +969,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)struct ucsi_control ctrl;int ret; -INIT_WORK (&con->work, ucsi_connector_change); +INIT_WORK (&con->work, ucsi_handle_connector_change);init_completion (&con->complete);mutex_init (&con->lock); con->num = index +1 ;
@@ -898,9 +1060,14 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)return 0 ; } -static void ucsi_init (struct work_struct *work) +/** +* ucsi_init - Initialize UCSI interface +* @ucsi: UCSI to be initialized +* +* Registers all ports @ucsi has and enables all notification events. +*/ +int ucsi_init (struct ucsi *ucsi) { - struct ucsi *ucsi = container_of(work, struct ucsi, work);struct ucsi_connector *con;struct ucsi_control ctrl;int ret;
@@ -956,7 +1123,7 @@ static void ucsi_init(struct work_struct *work)mutex_unlock (&ucsi->ppm_lock); -return ; +return 0 ; err_unregister:for (con = ucsi->connector; con->port; con++) {
@@ -970,49 +1137,106 @@ static void ucsi_init(struct work_struct *work)ucsi_reset_ppm (ucsi); err:mutex_unlock (&ucsi->ppm_lock); -dev_err (ucsi->dev,"PPM init failed (%d)\n" , ret); + +return ret; +} +EXPORT_SYMBOL_GPL (ucsi_init); + +static void ucsi_init_work (struct work_struct *work) +{ + struct ucsi *ucsi = container_of(work, struct ucsi, work); +int ret; + + ret =ucsi_init (ucsi); +if (ret) +dev_err (ucsi->dev,"PPM init failed (%d)\n" , ret); }/** -* ucsi_register_ppm - Register UCSI PPM Interface -* @dev: Device interface to the PPM -* @ppm: The PPM interface -* -* Allocates UCSI instance, associates it with @ppm and returns it to the -* caller, and schedules initialization of the interface. +* ucsi_get_drvdata - Return private driver data pointer +* @ucsi: UCSI interface */ -struct ucsi *ucsi_register_ppm (struct device *dev,struct ucsi_ppm *ppm) +void *ucsi_get_drvdata (struct ucsi *ucsi) +{ +return ucsi->driver_data; +} +EXPORT_SYMBOL_GPL (ucsi_get_drvdata); + +/** +* ucsi_get_drvdata - Assign private driver data pointer +* @ucsi: UCSI interface +* @data: Private data pointer +*/ +void ucsi_set_drvdata (struct ucsi *ucsi,void *data) +{ + ucsi->driver_data = data; +} +EXPORT_SYMBOL_GPL (ucsi_set_drvdata); + +/** +* ucsi_create - Allocate UCSI instance +* @dev: Device interface to the PPM (Platform Policy Manager) +* @ops: I/O routines +*/ +struct ucsi *ucsi_create (struct device *dev,const struct ucsi_operations *ops) {struct ucsi *ucsi; +if (!ops || !ops->read || !ops->sync_write || !ops->async_write) +return ERR_PTR (-EINVAL ); + ucsi =kzalloc (sizeof (*ucsi),GFP_KERNEL );if (!ucsi)return ERR_PTR (-ENOMEM ); -INIT_WORK (&ucsi->work, ucsi_init); -init_completion (&ucsi->complete); +INIT_WORK (&ucsi->work, ucsi_init_work);mutex_init (&ucsi->ppm_lock); - ucsi->dev = dev; - ucsi->ppm = ppm; + ucsi->ops = ops; + +return ucsi; +} +EXPORT_SYMBOL_GPL (ucsi_create); + +/** +* ucsi_destroy - Free UCSI instance +* @ucsi: UCSI instance to be freed +*/ +void ucsi_destroy (struct ucsi *ucsi) +{ +kfree (ucsi); +} +EXPORT_SYMBOL_GPL (ucsi_destroy); + +/** +* ucsi_register - Register UCSI interface +* @ucsi: UCSI instance +*/ +int ucsi_register (struct ucsi *ucsi) +{ +u16 version; +int ret; + + ret = ucsi->ops->read (ucsi,UCSI_VERSION , &version,sizeof (version)); +if (ret) +return ret; + +if (!version) +return -ENODEV ; -/* -* Communication with the PPM takes a lot of time. It is not reasonable -* to initialize the driver here. Using a work for now. -*/ queue_work (system_long_wq, &ucsi->work); -return ucsi; +return 0 ; } -EXPORT_SYMBOL_GPL (ucsi_register_ppm); +EXPORT_SYMBOL_GPL (ucsi_register);/** -* ucsi_unregister_ppm - Unregister UCSI PPM Interface -* @ucsi: struct ucsi associated with the PPM +* ucsi_unregister - Unregister UCSI interface +* @ucsi: UCSI interface to be unregistered * -* Unregister UCSI PPM that was created with ucsi_register(). +* Unregister UCSI interface that was created with ucsi_register(). */ -void ucsi_unregister_ppm (struct ucsi *ucsi) +void ucsi_unregister (struct ucsi *ucsi) {struct ucsi_control ctrl;int i;
@@ -1035,7 +1259,51 @@ void ucsi_unregister_ppm(struct ucsi *ucsi)ucsi_reset_ppm (ucsi);kfree (ucsi->connector); -kfree (ucsi); +} +EXPORT_SYMBOL_GPL (ucsi_unregister); + +/** +* ucsi_register_ppm - Register UCSI PPM Interface +* @dev: Device interface to the PPM +* @ppm: The PPM interface +* +* Allocates UCSI instance, associates it with @ppm and returns it to the +* caller, and schedules initialization of the interface. +*/ +struct ucsi *ucsi_register_ppm (struct device *dev,struct ucsi_ppm *ppm) +{ +struct ucsi *ucsi; + + ucsi =kzalloc (sizeof (*ucsi),GFP_KERNEL ); +if (!ucsi) +return ERR_PTR (-ENOMEM ); + +INIT_WORK (&ucsi->work, ucsi_init_work); +init_completion (&ucsi->complete); +mutex_init (&ucsi->ppm_lock); + + ucsi->dev = dev; + ucsi->ppm = ppm; + +/* +* Communication with the PPM takes a lot of time. It is not reasonable +* to initialize the driver here. Using a work for now. +*/ +queue_work (system_long_wq, &ucsi->work); + +return ucsi; +} +EXPORT_SYMBOL_GPL (ucsi_register_ppm); + +/** +* ucsi_unregister_ppm - Unregister UCSI PPM Interface +* @ucsi: struct ucsi associated with the PPM +* +* Unregister UCSI PPM that was created with ucsi_register(). +*/ +void ucsi_unregister_ppm (struct ucsi *ucsi) +{ +ucsi_unregister (ucsi); }EXPORT_SYMBOL_GPL (ucsi_unregister_ppm);
drivers/usb/typec/ucsi/ucsi.h +57 -0
75 lines not on this page · raw message
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 10/14 usb: typec: ucsi: acpi: Move to the new API
In reply to Heikki KrogerusReplacing the old "cmd" and "sync" callbacks with an implementation of struct ucsi_operations. The ACPI notification (interrupt) handler will from now on read the CCI (Command Status and Connector Change Indication) register, and call ucsi_connector_change() function and/or complete pending command completions based on it.
--- drivers/usb/typec/ucsi/ucsi_acpi.c | 96 ++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 19 deletions(-)
drivers/usb/typec/ucsi/ucsi_acpi.c +77 -19
@@ -19,7 +19,9 @@struct ucsi_acpi {struct device *dev;struct ucsi *ucsi; -struct ucsi_ppm ppm; +void __iomem *base; +struct completion complete; +unsigned long flags;guid_t guid; };
@@ -39,27 +41,78 @@ static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)return 0 ; } -static int ucsi_acpi_cmd (struct ucsi_ppm *ppm,struct ucsi_control *ctrl) +static int ucsi_acpi_read (struct ucsi *ucsi,unsigned int offset, +void *val,size_t val_len) { - struct ucsi_acpi *ua = container_of(ppm, struct ucsi_acpi, ppm); +struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi); +int ret; + + ret =ucsi_acpi_dsm (ua,UCSI_DSM_FUNC_READ ); +if (ret) +return ret; - ppm->data->ctrl.raw_cmd = ctrl->raw_cmd; +memcpy (val, ua->base + offset, val_len); + +return 0 ; +} + +static int ucsi_acpi_async_write (struct ucsi *ucsi,unsigned int offset, +const void *val,size_t val_len) +{ +struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi); + +memcpy (ua->base + offset, val, val_len);return ucsi_acpi_dsm (ua,UCSI_DSM_FUNC_WRITE ); } -static int ucsi_acpi_sync (struct ucsi_ppm *ppm) +static int ucsi_acpi_sync_write (struct ucsi *ucsi,unsigned int offset, +const void *val,size_t val_len) { - struct ucsi_acpi *ua = container_of(ppm, struct ucsi_acpi, ppm); +struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi); +int ret; + +set_bit (COMMAND_PENDING , &ua->flags); + + ret =ucsi_acpi_async_write (ucsi, offset, val, val_len); +if (ret) + goto out_clear_bit; + +if (!wait_for_completion_timeout (&ua->complete,msecs_to_jiffies (5000 ))) + ret = -ETIMEDOUT ; -return ucsi_acpi_dsm (ua,UCSI_DSM_FUNC_READ ); +out_clear_bit: +clear_bit (COMMAND_PENDING , &ua->flags); + +return ret; } +static const struct ucsi_operations ucsi_acpi_ops = { + .read = ucsi_acpi_read, + .sync_write = ucsi_acpi_sync_write, + .async_write = ucsi_acpi_async_write +}; +static void ucsi_acpi_notify (acpi_handle handle,u32 event,void *data) {struct ucsi_acpi *ua = data; +u32 cci; +int ret; + + ret =ucsi_acpi_read (ua->ucsi,UCSI_CCI , &cci,sizeof (cci)); +if (ret) { +dev_err (ua->dev,"failed to read CCI\n" ); +return ; + } + +if (UCSI_CCI_CONNECTOR (cci)) +ucsi_connector_change (ua->ucsi,UCSI_CCI_CONNECTOR (cci)); -ucsi_notify (ua->ucsi); +if (test_bit (COMMAND_PENDING , &ua->flags) && + (cci & (UCSI_CCI_BUSY | +UCSI_CCI_ACK_COMPLETE | +UCSI_CCI_COMMAND_COMPLETE ))) +complete (&ua->complete); }static int ucsi_acpi_probe (struct platform_device *pdev)
@@ -90,35 +143,39 @@ static int ucsi_acpi_probe(struct platform_device *pdev)* it can not be requested here, and we can not use * devm_ioremap_resource(). */ - ua->ppm.data =devm_ioremap (&pdev->dev, res->start,resource_size (res)); -if (!ua->ppm.data) + ua->base =devm_ioremap (&pdev->dev, res->start,resource_size (res)); +if (!ua->base)return -ENOMEM ; -if (!ua->ppm.data->version) -return -ENODEV ; - ret =guid_parse (UCSI_DSM_UUID , &ua->guid);if (ret)return ret; - ua->ppm.cmd = ucsi_acpi_cmd; - ua->ppm.sync = ucsi_acpi_sync; +init_completion (&ua->complete); ua->dev = &pdev->dev; + ua->ucsi =ucsi_create (&pdev->dev, &ucsi_acpi_ops); +if (IS_ERR (ua->ucsi)) +return PTR_ERR (ua->ucsi); + +ucsi_set_drvdata (ua->ucsi, ua); + status =acpi_install_notify_handler (ACPI_HANDLE (&pdev->dev),ACPI_DEVICE_NOTIFY , ucsi_acpi_notify, ua);if (ACPI_FAILURE (status)) {dev_err (&pdev->dev,"failed to install notify handler\n" ); +ucsi_destroy (ua->ucsi);return -ENODEV ; } - ua->ucsi =ucsi_register_ppm (&pdev->dev, &ua->ppm); -if (IS_ERR (ua->ucsi)) { + ret =ucsi_register (ua->ucsi); +if (ret) {acpi_remove_notify_handler (ACPI_HANDLE (&pdev->dev),ACPI_DEVICE_NOTIFY , ucsi_acpi_notify); -return PTR_ERR (ua->ucsi); +ucsi_destroy (ua->ucsi); +return ret; }platform_set_drvdata (pdev, ua);
@@ -130,7 +187,8 @@ static int ucsi_acpi_remove(struct platform_device *pdev) {struct ucsi_acpi *ua =platform_get_drvdata (pdev); -ucsi_unregister_ppm (ua->ucsi); +ucsi_unregister (ua->ucsi); +ucsi_destroy (ua->ucsi);acpi_remove_notify_handler (ACPI_HANDLE (&pdev->dev),ACPI_DEVICE_NOTIFY , ucsi_acpi_notify);
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 11/14 usb: typec: ucsi: ccg: Move to the new API
In reply to Heikki KrogerusReplacing the old "cmd" and "sync" callbacks with an implementation of struct ucsi_operations. The interrupt handler will from now on read the CCI (Command Status and Connector Change Indication) register, and call ucsi_connector_change() function and/or complete pending command completions based on it.
--- drivers/usb/typec/ucsi/ucsi_ccg.c | 172 +++++++++++++++--------------- 1 file changed, 87 insertions(+), 85 deletions(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +87 -85
@@ -176,8 +176,8 @@ struct ccg_resp {struct ucsi_ccg {struct device *dev;struct ucsi *ucsi; -struct ucsi_ppm ppm;struct i2c_client *client; +struct ccg_dev_info info;/* version info for boot, primary and secondary */ struct version_info version[FW2 +1 ];
@@ -196,6 +196,8 @@ struct ucsi_ccg {/* fw build with vendor information */ u16 fw_build;struct work_struct pm_work; + +struct completion complete; };static int ccg_read (struct ucsi_ccg *uc,u16 rab,u8 *data,u32 len)
@@ -243,7 +245,7 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)return 0 ; } -static int ccg_write (struct ucsi_ccg *uc,u16 rab,u8 *data,u32 len) +static int ccg_write (struct ucsi_ccg *uc,u16 rab,const u8 *data,u32 len) {struct i2c_client *client = uc->client;unsigned char *buf;
@@ -317,88 +319,91 @@ static int ucsi_ccg_init(struct ucsi_ccg *uc)return -ETIMEDOUT ; } -static int ucsi_ccg_send_data (struct ucsi_ccg *uc) +static int ucsi_ccg_read (struct ucsi *ucsi,unsigned int offset, +void *val,size_t val_len) { -u8 *ppm = (u8 *)uc->ppm.data; -int status; -u16 rab; +u16 reg =CCGX_RAB_UCSI_DATA_BLOCK (offset); - rab =CCGX_RAB_UCSI_DATA_BLOCK (offsetof(struct ucsi_data , message_out)); - status =ccg_write (uc, rab, ppm + - offsetof(struct ucsi_data , message_out), -sizeof (uc->ppm.data->message_out)); -if (status <0 ) -return status; - - rab =CCGX_RAB_UCSI_DATA_BLOCK (offsetof(struct ucsi_data , ctrl)); -return ccg_write (uc, rab, ppm + offsetof(struct ucsi_data , ctrl), -sizeof (uc->ppm.data->ctrl)); +return ccg_read (ucsi_get_drvdata (ucsi), reg, val, val_len); } -static int ucsi_ccg_recv_data (struct ucsi_ccg *uc) +static int ucsi_ccg_async_write (struct ucsi *ucsi,unsigned int offset, +const void *val,size_t val_len) { -u8 *ppm = (u8 *)uc->ppm.data; -int status; -u16 rab; +u16 reg =CCGX_RAB_UCSI_DATA_BLOCK (offset); - rab =CCGX_RAB_UCSI_DATA_BLOCK (offsetof(struct ucsi_data , cci)); - status =ccg_read (uc, rab, ppm + offsetof(struct ucsi_data , cci), -sizeof (uc->ppm.data->cci)); -if (status <0 ) -return status; - - rab =CCGX_RAB_UCSI_DATA_BLOCK (offsetof(struct ucsi_data , message_in)); -return ccg_read (uc, rab, ppm + offsetof(struct ucsi_data , message_in), -sizeof (uc->ppm.data->message_in)); +return ccg_write (ucsi_get_drvdata (ucsi), reg, val, val_len); } -static int ucsi_ccg_ack_interrupt (struct ucsi_ccg *uc) +static int ucsi_ccg_sync_write (struct ucsi *ucsi,unsigned int offset, +const void *val,size_t val_len) { -int status; -unsigned char data; +struct ucsi_ccg *uc =ucsi_get_drvdata (ucsi); +int ret; - status =ccg_read (uc,CCGX_RAB_INTR_REG , &data,sizeof (data)); -if (status <0 ) -return status; +mutex_lock (&uc->lock); +pm_runtime_get_sync (uc->dev); +set_bit (DEV_CMD_PENDING , &uc->flags); -return ccg_write (uc,CCGX_RAB_INTR_REG , &data,sizeof (data)); -} + ret =ucsi_ccg_async_write (ucsi, offset, val, val_len); +if (ret) + goto err_clear_bit; -static int ucsi_ccg_sync (struct ucsi_ppm *ppm) -{ - struct ucsi_ccg *uc = container_of(ppm, struct ucsi_ccg, ppm); -int status; +if (!wait_for_completion_timeout (&uc->complete,msecs_to_jiffies (5000 ))) + ret = -ETIMEDOUT ; - status =ucsi_ccg_recv_data (uc); -if (status <0 ) -return status; +err_clear_bit: +clear_bit (DEV_CMD_PENDING , &uc->flags); +pm_runtime_put_sync (uc->dev); +mutex_unlock (&uc->lock); -/* ack interrupt to allow next command to run */ -return ucsi_ccg_ack_interrupt (uc); +return ret; } -static int ucsi_ccg_cmd (struct ucsi_ppm *ppm,struct ucsi_control *ctrl) -{ - struct ucsi_ccg *uc = container_of(ppm, struct ucsi_ccg, ppm); - - ppm->data->ctrl.raw_cmd = ctrl->raw_cmd; -return ucsi_ccg_send_data (uc); -} +static const struct ucsi_operations ucsi_ccg_ops = { + .read = ucsi_ccg_read, + .sync_write = ucsi_ccg_sync_write, + .async_write = ucsi_ccg_async_write +};static irqreturn_t ccg_irq_handler (int irq,void *data) { +u16 reg =CCGX_RAB_UCSI_DATA_BLOCK (UCSI_CCI );struct ucsi_ccg *uc = data; +u8 intr_reg; +u32 cci; +int ret; + + ret =ccg_read (uc,CCGX_RAB_INTR_REG , &intr_reg,sizeof (intr_reg)); +if (ret) +return ret; + + ret =ccg_read (uc, reg, (void *)&cci,sizeof (cci)); +if (ret) { +dev_err (uc->dev,"failed to read CCI\n" ); + goto err_clear_irq; + } + +if (UCSI_CCI_CONNECTOR (cci)) +ucsi_connector_change (uc->ucsi,UCSI_CCI_CONNECTOR (cci)); -ucsi_notify (uc->ucsi); +if (test_bit (DEV_CMD_PENDING , &uc->flags) && + (cci & (UCSI_CCI_BUSY | +UCSI_CCI_ACK_COMPLETE | +UCSI_CCI_COMMAND_COMPLETE ))) +complete (&uc->complete); + +err_clear_irq: + ret =ccg_write (uc,CCGX_RAB_INTR_REG , &intr_reg,sizeof (intr_reg)); +if (ret) +dev_err (uc->dev,"failed to clear interrupt\n" );return IRQ_HANDLED ; }static void ccg_pm_workaround_work (struct work_struct *pm_work) { - struct ucsi_ccg *uc = container_of(pm_work, struct ucsi_ccg, pm_work); - -ucsi_notify (uc->ucsi); + ccg_irq_handler(0, container_of(pm_work, struct ucsi_ccg, pm_work)); }static int get_fw_info (struct ucsi_ccg *uc)
@@ -1027,10 +1032,10 @@ static int ccg_restart(struct ucsi_ccg *uc)return status; } - uc->ucsi =ucsi_register_ppm (dev, &uc->ppm); -if (IS_ERR (uc->ucsi)) { -dev_err (uc->dev,"ucsi_register_ppm failed\n" ); -return PTR_ERR (uc->ucsi); + status =ucsi_register (uc->ucsi); +if (status) { +dev_err (uc->dev,"failed to register the interface\n" ); +return status; }return 0 ;
@@ -1047,7 +1052,7 @@ static void ccg_update_firmware(struct work_struct *work)return ;if (flash_mode !=FLASH_NOT_NEEDED ) { -ucsi_unregister_ppm (uc->ucsi); +ucsi_unregister (uc->ucsi);free_irq (uc->irq, uc);ccg_fw_update (uc, flash_mode);
@@ -1091,21 +1096,15 @@ static int ucsi_ccg_probe(struct i2c_client *client,struct device *dev = &client->dev;struct ucsi_ccg *uc;int status; -u16 rab; uc =devm_kzalloc (dev,sizeof (*uc),GFP_KERNEL );if (!uc)return -ENOMEM ; - uc->ppm.data =devm_kzalloc (dev,sizeof (struct ucsi_data ),GFP_KERNEL ); -if (!uc->ppm.data) -return -ENOMEM ; - - uc->ppm.cmd = ucsi_ccg_cmd; - uc->ppm.sync = ucsi_ccg_sync; uc->dev = dev; uc->client = client;mutex_init (&uc->lock); +init_completion (&uc->complete);INIT_WORK (&uc->work, ccg_update_firmware);INIT_WORK (&uc->pm_work, ccg_pm_workaround_work);
@@ -1133,30 +1132,25 @@ static int ucsi_ccg_probe(struct i2c_client *client,if (uc->info.mode &CCG_DEVINFO_PDPORTS_MASK ) uc->port_num++; + uc->ucsi =ucsi_create (dev, &ucsi_ccg_ops); +if (IS_ERR (uc->ucsi)) +return PTR_ERR (uc->ucsi); + +ucsi_set_drvdata (uc->ucsi, uc); + status =request_threaded_irq (client->irq,NULL , ccg_irq_handler,IRQF_ONESHOT |IRQF_TRIGGER_HIGH ,dev_name (dev), uc);if (status <0 ) {dev_err (uc->dev,"request_threaded_irq failed - %d\n" , status); -return status; + goto out_ucsi_destroy; } uc->irq = client->irq; - uc->ucsi =ucsi_register_ppm (dev, &uc->ppm); -if (IS_ERR (uc->ucsi)) { -dev_err (uc->dev,"ucsi_register_ppm failed\n" ); -return PTR_ERR (uc->ucsi); - } - - rab =CCGX_RAB_UCSI_DATA_BLOCK (offsetof(struct ucsi_data , version)); - status =ccg_read (uc, rab, (u8 *)(uc->ppm.data) + - offsetof(struct ucsi_data , version), -sizeof (uc->ppm.data->version)); -if (status <0 ) { -ucsi_unregister_ppm (uc->ucsi); -return status; - } + status =ucsi_register (uc->ucsi); +if (status) + goto out_free_irq;i2c_set_clientdata (client, uc);
@@ -1167,6 +1161,13 @@ static int ucsi_ccg_probe(struct i2c_client *client,pm_runtime_idle (uc->dev);return 0 ; + +out_free_irq: +free_irq (uc->irq, uc); +out_ucsi_destroy: +ucsi_destroy (uc->ucsi); + +return status; }static int ucsi_ccg_remove (struct i2c_client *client)
@@ -1175,8 +1176,9 @@ static int ucsi_ccg_remove(struct i2c_client *client)cancel_work_sync (&uc->pm_work);cancel_work_sync (&uc->work); -ucsi_unregister_ppm (uc->ucsi);pm_runtime_disable (uc->dev); +ucsi_unregister (uc->ucsi); +ucsi_destroy (uc->ucsi);free_irq (uc->irq, uc);return 0 ;
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 12/14 usb: typec: ucsi: Remove the old API
In reply to Heikki KrogerusThe drivers now only use the new API, so removing the old one.
--- drivers/usb/typec/ucsi/displayport.c | 8 +- drivers/usb/typec/ucsi/trace.h | 17 -- drivers/usb/typec/ucsi/ucsi.c | 346 +++------------------------ drivers/usb/typec/ucsi/ucsi.h | 41 ---- 4 files changed, 41 insertions(+), 371 deletions(-)
drivers/usb/typec/ucsi/displayport.c +7 -1
@@ -48,8 +48,10 @@ struct ucsi_dp {static int ucsi_displayport_enter (struct typec_altmode *alt) {struct ucsi_dp *dp =typec_altmode_get_drvdata (alt); +struct ucsi *ucsi = dp->con->ucsi;struct ucsi_control ctrl;u8 cur =0 ; +u16 ver;int ret;mutex_lock (&dp->con->lock);
@@ -66,7 +68,11 @@ static int ucsi_displayport_enter(struct typec_altmode *alt)UCSI_CMD_GET_CURRENT_CAM (ctrl, dp->con->num); ret =ucsi_send_command (dp->con->ucsi, &ctrl, &cur,sizeof (cur));if (ret <0 ) { -if (dp->con->ucsi->ppm->data->version >0x0100 ) { + ret = ucsi->ops->read (ucsi,UCSI_VERSION , &ver,sizeof (ver)); +if (ret) +return ret; + +if (ver >0x0100 ) {mutex_unlock (&dp->con->lock);return ret; }
drivers/usb/typec/ucsi/trace.h +0 -17
@@ -75,23 +75,6 @@ DEFINE_EVENT(ucsi_log_command, ucsi_reset_ppm,TP_ARGS (ctrl, ret) ); -DECLARE_EVENT_CLASS (ucsi_log_cci, - TP_PROTO(u32 cci), -TP_ARGS (cci), -TP_STRUCT__entry ( -__field (u32, cci) - ), -TP_fast_assign ( - __entry->cci = cci; - ), -TP_printk ("CCI=%08x %s" , __entry->cci,ucsi_cci_str (__entry->cci)) -); - -DEFINE_EVENT (ucsi_log_cci, ucsi_notify, - TP_PROTO(u32 cci), -TP_ARGS (cci) -); - DECLARE_EVENT_CLASS(ucsi_log_connector_status, TP_PROTO(int port, struct ucsi_connector_status *status), TP_ARGS(port, status),
drivers/usb/typec/ucsi/ucsi.c +34 -312
418 lines not on this page · raw message
drivers/usb/typec/ucsi/ucsi.h +0 -41
53 lines not on this page · raw message
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 13/14 usb: typec: ucsi: Remove struct ucsi_control
In reply to Heikki KrogerusThat data structure was used for constructing the commands before executing them, but it was never really useful. Using the structure just complicated the driver. The commands are 64-bit wide, so it is enough to simply fill a u64 variable. No data structures needed.
This simplifies the driver considerable and makes it much easier to for example add support for big endian systems later on.
--- drivers/usb/typec/ucsi/displayport.c | 18 +-- drivers/usb/typec/ucsi/trace.c | 11 -- drivers/usb/typec/ucsi/trace.h | 50 +----- drivers/usb/typec/ucsi/ucsi.c | 110 +++++++------ drivers/usb/typec/ucsi/ucsi.h | 231 +++++---------------------- 5 files changed, 118 insertions(+), 302 deletions(-)
drivers/usb/typec/ucsi/displayport.c +9 -9
@@ -49,7 +49,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt) {struct ucsi_dp *dp =typec_altmode_get_drvdata (alt);struct ucsi *ucsi = dp->con->ucsi; -struct ucsi_control ctrl; +u64 command;u8 cur =0 ;u16 ver;int ret;
@@ -65,8 +65,8 @@ static int ucsi_displayport_enter(struct typec_altmode *alt)return -EOPNOTSUPP ; } -UCSI_CMD_GET_CURRENT_CAM (ctrl, dp->con->num); - ret =ucsi_send_command (dp->con->ucsi, &ctrl, &cur,sizeof (cur)); + command =UCSI_GET_CURRENT_CAM |UCSI_CONNECTOR_NUMBER (dp->con->num); + ret =ucsi_send_command (dp->con->ucsi, command, &cur,sizeof (cur));if (ret <0 ) { ret = ucsi->ops->read (ucsi,UCSI_VERSION , &ver,sizeof (ver));if (ret)
@@ -107,7 +107,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt)static int ucsi_displayport_exit (struct typec_altmode *alt) {struct ucsi_dp *dp =typec_altmode_get_drvdata (alt); -struct ucsi_control ctrl; +u64 command;int ret =0 ;mutex_lock (&dp->con->lock);
@@ -121,8 +121,8 @@ static int ucsi_displayport_exit(struct typec_altmode *alt) goto out_unlock; } - ctrl.raw_cmd =UCSI_CMD_SET_NEW_CAM (dp->con->num,0 , dp->offset,0 ); - ret =ucsi_send_command (dp->con->ucsi, &ctrl,NULL ,0 ); + command =UCSI_CMD_SET_NEW_CAM (dp->con->num,0 , dp->offset,0 ); + ret =ucsi_send_command (dp->con->ucsi, command,NULL ,0 );if (ret <0 ) goto out_unlock;
@@ -176,14 +176,14 @@ static int ucsi_displayport_status_update(struct ucsi_dp *dp)static int ucsi_displayport_configure (struct ucsi_dp *dp) {u32 pins =DP_CONF_GET_PIN_ASSIGN (dp->data.conf); -struct ucsi_control ctrl; +u64 command;if (!dp->override)return 0 ; - ctrl.raw_cmd =UCSI_CMD_SET_NEW_CAM (dp->con->num,1 , dp->offset, pins); + command =UCSI_CMD_SET_NEW_CAM (dp->con->num,1 , dp->offset, pins); -return ucsi_send_command (dp->con->ucsi, &ctrl,NULL ,0 ); +return ucsi_send_command (dp->con->ucsi, command,NULL ,0 ); } static int ucsi_displayport_vdm(struct typec_altmode *alt,
drivers/usb/typec/ucsi/trace.c +0 -11
@@ -33,17 +33,6 @@ const char *ucsi_cmd_str(u64 raw_cmd)return ucsi_cmd_strs[(cmd >=ARRAY_SIZE (ucsi_cmd_strs)) ?0 : cmd]; } -static const char *const ucsi_ack_strs[] = { - [0 ] ="" , - [UCSI_ACK_EVENT ] ="event" , - [UCSI_ACK_CMD ] ="command" , -}; - -const char *ucsi_ack_str (u8 ack) -{ -return ucsi_ack_strs[(ack >=ARRAY_SIZE (ucsi_ack_strs)) ?0 : ack]; -} -const char *ucsi_cci_str (u32 cci) {if (cci &GENMASK (7 ,0 )) {
drivers/usb/typec/ucsi/trace.h +7 -43
74 lines not on this page · raw message
drivers/usb/typec/ucsi/ucsi.c +62 -48
279 lines not on this page · raw message
drivers/usb/typec/ucsi/ucsi.h +40 -191
253 lines not on this page · raw message
Signature · 1 line
2.23.0
Heikki Krogerus
maintainerPATCH 14/14 usb: typec: ucsi: Remove all bit-fields
In reply to Heikki KrogerusWe can't use bit fields with data that is received or send to/from the device.
--- drivers/usb/typec/ucsi/trace.h | 12 ++--- drivers/usb/typec/ucsi/ucsi.c | 52 +++++++++++-------- drivers/usb/typec/ucsi/ucsi.h | 93 +++++++++++++++++----------------- 3 files changed, 85 insertions(+), 72 deletions(-)
drivers/usb/typec/ucsi/trace.h +6 -6
@@ -56,13 +56,13 @@ DECLARE_EVENT_CLASS(ucsi_log_connector_status,TP_fast_assign ( __entry->port = port - 1; __entry->change = status->change; - __entry->opmode = status->pwr_op_mode; - __entry->connected = status->connected; - __entry->pwr_dir = status->pwr_dir; - __entry->partner_flags = status->partner_flags; - __entry->partner_type = status->partner_type; + __entry->opmode =UCSI_CONSTAT_PWR_OPMODE (status->flags); + __entry->connected = !!(status->flags &UCSI_CONSTAT_CONNECTED ); + __entry->pwr_dir = !!(status->flags &UCSI_CONSTAT_PWR_DIR ); + __entry->partner_flags =UCSI_CONSTAT_PARTNER_FLAGS (status->flags); + __entry->partner_type =UCSI_CONSTAT_PARTNER_TYPE (status->flags); __entry->request_data_obj = status->request_data_obj; - __entry->bc_status = status->bc_status; + __entry->bc_status =UCSI_CONSTAT_BC_STATUS (status->pwr_status); ),TP_printk ("port%d status: change=%04x, opmode=%x, connected=%d, " "sourcing=%d, partner_flags=%x, partner_type=%x, "
drivers/usb/typec/ucsi/ucsi.c +32 -20
163 lines not on this page · raw message
drivers/usb/typec/ucsi/ucsi.h +47 -46
125 lines not on this page · raw message
Signature · 1 line
2.23.0
Hi Heikki,
Quoted 19 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched at all.
Quoted 7 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface - and squash all alt modes with the same SVID into one that we supply to the
ucsi.cwhen ever it sendsGET_ALTERNATE_MODEScommand. Also other alt mode commands likeSET_NEW_CAMcan have special processing inucsi_ccg.canducsi_ccg.calone. There should not be any problem with that anymore.
I took the changes and loaded on my GPU system and do not see altmode devices under /sys/bus/typec/devices/*. Its empty.
Below error is seen
"ucsi_ccg 4-0008: con1: failed to register alternate modes"
ucsi_run_command() is returning -16.
I will review the ccg changes and try to debug above issue.
Thanks
Quoted 36 lines
nvpublic
thanks,
Heikki Krogerus (14):
usb: typec: Copy everything from structtypec_capabilityduring
registration
usb: typec: Introducetypec_get_drvdata()
usb: typec: Separate the operations vector
usb: typec: tcpm: Start using structtypec_operations
usb: typec: tps6598x: Start using structtypec_operations
usb: typec: ucsi: Start using structtypec_operations
usb: typec: Remove the callback members from structtypec_capability
usb: typec: ucsi: ccg: Removerun_isrflag
usb: typec: ucsi: Simplified interface registration and I/O API
usb: typec: ucsi: acpi: Move to the new API
usb: typec: ucsi: ccg: Move to the new API
usb: typec: ucsi: Remove the old API
usb: typec: ucsi: Remove structucsi_control
usb: typec: ucsi: Remove all bit-fieldsdrivers/usb/typec/class.c | 125 +++--- drivers/usb/typec/tcpm/tcpm.c | 47 +-- drivers/usb/typec/tps6598x.c | 49 +-- drivers/usb/typec/ucsi/displayport.c | 26 +- drivers/usb/typec/ucsi/trace.c | 11 - drivers/usb/typec/ucsi/trace.h | 79 +--- drivers/usb/typec/ucsi/ucsi.c | 592 ++++++++++++++------------- drivers/usb/typec/ucsi/ucsi.h | 410 +++++++------------ drivers/usb/typec/ucsi/ucsi_acpi.c | 96 ++++- drivers/usb/typec/ucsi/ucsi_ccg.c | 214 ++++------ include/linux/usb/typec.h | 38 +- 11 files changed, 785 insertions(+), 902 deletions(-)--
2.23.0
Heikki Krogerus
maintainerQuoted 30 lines · Ajay Gupta
Hi Heikki,
Quoted 19 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched at all.Quoted 7 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface - and squash all alt modes with the same SVID into one that we supply to the
ucsi.cwhen ever it sendsGET_ALTERNATE_MODEScommand. Also other alt mode commands likeSET_NEW_CAMcan have special processing inucsi_ccg.canducsi_ccg.calone. There should not be any problem with that anymore.I took the changes and loaded on my GPU system and do not see altmode devices under
/sys/bus/typec/devices/*. Its empty.
Quoted 6 lines
Below error is seen
"ucsi_ccg4-0008: con1: failed to register alternate modes"
ucsi_run_command()is returning -16.I will review the ccg changes and try to debug above issue.
There is at least on obvious bug. The number of alternate modes field is wrong. The this:
drivers/usb/typec/ucsi/ucsi.c +1 -1
@@ -330,7 +330,7 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient) command |=UCSI_GET_ALTMODE_RECIPIENT (recipient); command |=UCSI_GET_ALTMODE_CONNECTOR_NUMBER (con->num); command |=UCSI_GET_ALTMODE_OFFSET (i); - command |=UCSI_GET_ALTMODE_NUM_ALTMODES (1 );/* One at a time */ + command |=UCSI_GET_ALTMODE_NUM_ALTMODES (0 );/* One at a time */ len =ucsi_run_command (con->ucsi, command, alt,sizeof (alt));if (len <=0 )return len;
Alternatively you can also just drop two last patches of the series.
thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerQuoted 30 lines · Ajay Gupta
Hi Heikki,
Quoted 19 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched at all.Quoted 7 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface - and squash all alt modes with the same SVID into one that we supply to the
ucsi.cwhen ever it sendsGET_ALTERNATE_MODEScommand. Also other alt mode commands likeSET_NEW_CAMcan have special processing inucsi_ccg.canducsi_ccg.calone. There should not be any problem with that anymore.I took the changes and loaded on my GPU system and do not see altmode devices under
/sys/bus/typec/devices/*. Its empty.
Quoted 6 lines
Below error is seen
"ucsi_ccg4-0008: con1: failed to register alternate modes"
ucsi_run_command()is returning -16.I will review the ccg changes and try to debug above issue.
I tested this series with the NVIDIA GPU PCI card that we have. The controller is reporting BUSY as responce to the GET_ALTERNATE_MODES command. I added a loop to ucsi_exec_command() where I read the CCI until the there is no UCSI_CCI_BUSY bit set, and it seems to work.
Here are both changes:
drivers/usb/typec/ucsi/ucsi.c +10 -6
@@ -102,6 +102,7 @@ static int ucsi_read_error(struct ucsi *ucsi)static int ucsi_exec_command (struct ucsi *ucsi,u64 cmd) { +unsigned long timeout;u32 cci;int ret;
@@ -109,12 +110,15 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)if (ret)return ret; - ret = ucsi->ops->read (ucsi,UCSI_CCI , &cci,sizeof (cci)); -if (ret) -return ret; + timeout = jiffies +msecs_to_jiffies (UCSI_TIMEOUT_MS ); +do { +if (time_is_before_jiffies (timeout)) +return -ETIMEDOUT ; -if (cci &UCSI_CCI_BUSY ) -return -EBUSY ; + ret = ucsi->ops->read (ucsi,UCSI_CCI , &cci,sizeof (cci)); +if (ret) +return ret; + }while (cci &UCSI_CCI_BUSY );if (!(cci &UCSI_CCI_COMMAND_COMPLETE ))return -EIO ;
@@ -330,7 +334,7 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient) command |=UCSI_GET_ALTMODE_RECIPIENT (recipient); command |=UCSI_GET_ALTMODE_CONNECTOR_NUMBER (con->num); command |=UCSI_GET_ALTMODE_OFFSET (i); - command |=UCSI_GET_ALTMODE_NUM_ALTMODES (1 );/* One at a time */ + len =ucsi_run_command (con->ucsi, command, alt,sizeof (alt));if (len <=0 )return len;
Let me know if that works.
thanks,
Signature · 1 line
heikki
Hi Heikki,
Quoted 95 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Friday, September 27, 2019 5:53 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 00/14] usb: typec: UCSI driver overhaulQuoted 19 lines · Ajay Gupta
Hi Heikki,
Quoted 18 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched atall.
Quoted 11 lines
Quoted 8 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface - and squash all alt modes with the same SVID into one that we supply to the
ucsi.cwhen ever it sendsGET_ALTERNATE_MODEScommand. Also other alt mode commands likeSET_NEW_CAMcan have special processing inucsi_ccg.canducsi_ccg.calone. There should not be any problem with that anymore.I took the changes and loaded on my GPU system and do not see altmode devices under
/sys/bus/typec/devices/*. Its empty.Quoted 6 lines
Below error is seen
"ucsi_ccg4-0008: con1: failed to register alternate modes"
ucsi_run_command()is returning -16.I will review the ccg changes and try to debug above issue.
I tested this series with the NVIDIA GPU PCI card that we have. The controller is reporting BUSY as responce to the
GET_ALTERNATE_MODEScommand. I added a loop toucsi_exec_command()where I read the CCI until the there is noUCSI_CCI_BUSYbit set, and it seems to work.Here are both changes:
drivers/usb/typec/ucsi/ucsi.c index renamed from drivers/usb/typec/ucsi/ucsi.c +0
-0
accf54d987ad..d70ee8006c34100644drivers/usb/typec/ucsi/ucsi.c +9
-5@@ -102,6 +102,7 @@ static int ucsi_read_error(struct ucsi *ucsi)static int ucsi_exec_command (struct ucsi *ucsi,u64 cmd) { +unsigned long timeout;u32 cci;int ret;@@ -109,12 +110,15 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)if (ret)return ret; - ret = ucsi->ops->read (ucsi,UCSI_CCI , &cci,sizeof (cci)); -if (ret) -return ret; + timeout = jiffies +msecs_to_jiffies (UCSI_TIMEOUT_MS ); +do { +if (time_is_before_jiffies (timeout)) +return -ETIMEDOUT ; -if (cci &UCSI_CCI_BUSY ) -return -EBUSY ; + ret = ucsi->ops->read (ucsi,UCSI_CCI , &cci,sizeof (cci)); +if (ret) +return ret; + }while (cci &UCSI_CCI_BUSY );if (!(cci &UCSI_CCI_COMMAND_COMPLETE ))return -EIO;drivers/usb/typec/ucsi/ucsi.c +0
-1@@ -330,7 +334,7 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient) command |= UCSI_GET_ALTMODE_RECIPIENT(recipient); command |=UCSI_GET_ALTMODE_CONNECTOR_NUMBER (con- >num); command |=UCSI_GET_ALTMODE_OFFSET (i); - command |=UCSI_GET_ALTMODE_NUM_ALTMODES (1 );/* One at a time */
+
Quoted 5 lines
len = ucsi_run_command(con->ucsi, command, alt, sizeof(alt)); if (len <= 0) return len;Let me know if that works.
It works now for me too. I will review rest of changes anyways and also need to update my change on altmode squashing.
Thanks
Quoted 6 lines
nvpublic
thanks,
--
heikki
Hi Heikki
Quoted 15 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
Quoted 7 lines
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched at all.We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface
How can ucsi_ccg.c get the connector alternate modes before registering ucsi interface? PPM reset, notification enable, etc. is done during ucsi registration. UCSI spec says:
" The only commands the PPM is required to process in the "PPM Idle (Notifications Disabled)" state are SET_NOTIFICATION_ENABLE and PPM_RESE"
Also, it doesn't look correct if ucsi_ccg.c has to replicate most of the stuff done in ucsi_init() of ucsi.c.
Thanks
Quoted 41 lines
nvpublic
- and squash all alt modes with the same SVID into one that we supply to theucsi.cwhen ever it sendsGET_ALTERNATE_MODEScommand. Also other alt mode commands likeSET_NEW_CAMcan have special processing inucsi_ccg.canducsi_ccg.calone. There should not be any problem with that anymore.thanks,
Heikki Krogerus (14):
usb: typec: Copy everything from structtypec_capabilityduring
registration
usb: typec: Introducetypec_get_drvdata()
usb: typec: Separate the operations vector
usb: typec: tcpm: Start using structtypec_operations
usb: typec: tps6598x: Start using structtypec_operations
usb: typec: ucsi: Start using structtypec_operations
usb: typec: Remove the callback members from structtypec_capability
usb: typec: ucsi: ccg: Removerun_isrflag
usb: typec: ucsi: Simplified interface registration and I/O API
usb: typec: ucsi: acpi: Move to the new API
usb: typec: ucsi: ccg: Move to the new API
usb: typec: ucsi: Remove the old API
usb: typec: ucsi: Remove structucsi_control
usb: typec: ucsi: Remove all bit-fieldsdrivers/usb/typec/class.c | 125 +++--- drivers/usb/typec/tcpm/tcpm.c | 47 +-- drivers/usb/typec/tps6598x.c | 49 +-- drivers/usb/typec/ucsi/displayport.c | 26 +- drivers/usb/typec/ucsi/trace.c | 11 - drivers/usb/typec/ucsi/trace.h | 79 +--- drivers/usb/typec/ucsi/ucsi.c | 592 ++++++++++++++------------- drivers/usb/typec/ucsi/ucsi.h | 410 +++++++------------ drivers/usb/typec/ucsi/ucsi_acpi.c | 96 ++++- drivers/usb/typec/ucsi/ucsi_ccg.c | 214 ++++------ include/linux/usb/typec.h | 38 +- 11 files changed, 785 insertions(+), 902 deletions(-)--
2.23.0
Heikki Krogerus
maintainerHi Ajay,
Quoted 31 lines · Ajay Gupta
Hi Heikki
Quoted 15 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
Quoted 7 lines
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched at all.We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface
How can
ucsi_ccg.cget the connector alternate modes before registering ucsi interface? PPM reset, notification enable, etc. is done during ucsi registration. UCSI spec says:
" The only commands the PPM is required to process in the "PPM Idle (Notifications Disabled)" state areSET_NOTIFICATION_ENABLEandPPM_RESE"
Quoted 2 lines
Also, it doesn't look correct if
ucsi_ccg.chas to replicate most of the stuff done inucsi_init()ofucsi.c.
How about if we split ucsi_init() into a function that first simply constructs the struct ucsi and struct ucsi_connector instances without registering anything, and into separate functions that then register the ports, altmodes and what have you. I don't think that should be a huge problem. It will make ucsi.c even more like a library, which is probable a good thing. I can prepare patches for that too if you like?
After that you should be able to get the struct ucsi instance that represents the "real" PPM without registering anything by calling a single function, most likely ucsi_init(). And after getting that you can construct the connector alternate modes that we actually register. Finally you register the final interface which does not use ucsi_ccg_ops, but instead something like ucsi_nvidia_ops.
How would this sound to you?
Br,
Signature · 1 line
heikki
Hi Heikki,
Quoted 42 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, October 3, 2019 7:25 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Quoted 20 lines · Ajay Gupta
Hi Heikki
Quoted 18 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Thursday, September 26, 2019 3:07 AM
To: Ajay Gupta <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/14] usb: typec: UCSI driver overhaulHi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched atall.
Quoted 11 lines
Quoted 4 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface
How can
ucsi_ccg.cget the connector alternate modes before registering ucsi interface? PPM reset, notification enable, etc. is done during ucsi registration. UCSI spec says:
" The only commands the PPM is required to process in the "PPM Idle (Notifications Disabled)" state areSET_NOTIFICATION_ENABLEandPPM_RESE"
Quoted 8 lines
Quoted 2 lines
Also, it doesn't look correct if
ucsi_ccg.chas to replicate most of the stuff done inucsi_init()ofucsi.c.How about if we split
ucsi_init()into a function that first simply constructs the struct ucsi and structucsi_connectorinstances without registering anything, and into separate functions that then register the ports, altmodes and what have you. I don't think that should be a huge problem. It will makeucsi.ceven more like a library, which is probable a good thing.
Do you mean the solution to follow steps (a->b->c->d1) or (a->b->c->d2) ?
a) ucsi_ccg.c calls first part of split ucsi_init()
b) ucsi_ccg.c uses ucsi_send_command() to collect actual alternate modes.
c) ucsi_ccg.c looks into actual alternate modes and squashes if duplicate altmode found. d1) ucsi_ccg.c calls new method to register connector alternate modes.
This method issues GET_ALTERNATE_MODES command again and ucsi_ccg.c is expected to send squashed alternate mode. This will require changes in .read(), .sync_write() and .async_write() to make it appear as if the squashed data coming from the ppm. OR
d2) ucsi_ccg.c calls new method to register squashed connector alternate modes. This method doesn't issue GET_ALTERNATE_MODES commands to PPM but simply registers the alternate mode values passed to this function.
If you mean the (a->b->c->d2) solution then it looks fine to me and would wait for patches from you. This solution would mean that GET_ALTERNATE_MODES for connector is done only by each ucsi_xxx.c and not by ucsi.c
Quoted 7 lines
I can prepare patches for that too if you like?
After that you should be able to get the struct ucsi instance that represents the "real" PPM without registering anything by calling a single function, most likelyucsi_init(). And after getting that you can construct the connector alternate modes that we actually register.
Finally you register the final interface which does not useucsi_ccg_ops, but instead something likeucsi_nvidia_ops.
I didn't understand this part. ucsi_ccg_ops has .read(), .sync_write() and
.async_write() interface and they remain same for all ucsi_ccg controllers.
Thanks
Quoted 8 lines
nvpublic
How would this sound to you?
Br,
--
heikki
Hi Heikki,
Quoted 49 lines
Quoted 24 lines
Quoted 8 lines
Quoted 8 lines
Hi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
Quoted 4 lines
Quoted 4 lines
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched atall.
Quoted 11 lines
Quoted 4 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface
How can
ucsi_ccg.cget the connector alternate modes before registering ucsi interface? PPM reset, notification enable, etc. is done during ucsi registration. UCSI spec says:
" The only commands the PPM is required to process in the "PPM Idle (Notifications Disabled)" state areSET_NOTIFICATION_ENABLEandPPM_RESE"Quoted 8 lines
Quoted 2 lines
Also, it doesn't look correct if
ucsi_ccg.chas to replicate most of the stuff done inucsi_init()ofucsi.c.How about if we split
ucsi_init()into a function that first simply constructs the struct ucsi and structucsi_connectorinstances without registering anything, and into separate functions that then register the ports, altmodes and what have you. I don't think that should be a huge problem. It will makeucsi.ceven more like a library, which is probablea good thing.
Do you mean the solution to follow steps (a->b->c->d1) or (a->b->c->d2) ?
a)ucsi_ccg.ccalls first part of splitucsi_init()
b)ucsi_ccg.cusesucsi_send_command()to collect actual alternate modes.
c)ucsi_ccg.clooks into actual alternate modes and squashes if duplicate altmode found.
d1)ucsi_ccg.ccalls new method to register connector alternate modes. This method issuesGET_ALTERNATE_MODEScommand again anducsi_ccg.cis expected to send squashed alternate mode. This will require changes in .read(), .sync_write() and
.async_write() to make it appear as if the squashed data coming from the ppm. OR
d2)ucsi_ccg.ccalls new method to register squashed connector alternate modes.
This method doesn't issueGET_ALTERNATE_MODEScommands to PPM but simply registers the alternate mode values passed to this function.
Quoted 3 lines
If you mean the (
a->b->c->d2) solution then it looks fine to me and would wait for patches from you. This solution would mean thatGET_ALTERNATE_MODESfor connector is done only by eachucsi_xxx.cand not byucsi.c
I am waiting for your comments on this.
Thanks
Quoted 18 lines
nvpublic
Quoted 7 lines
I can prepare patches for that too if you like?
After that you should be able to get the struct ucsi instance that represents the "real" PPM without registering anything by calling a single function, most likelyucsi_init(). And after getting that you can construct the connector alternate modes that we actually register. Finally you register the final interface which does not useucsi_ccg_ops, but instead something likeucsi_nvidia_ops.I didn't understand this part.
ucsi_ccg_opshas .read(), .sync_write() and
.async_write() interface and they remain same for allucsi_ccgcontrollers.Thanks
Quoted 6 lines
How would this sound to you?
Br,
--
heikki
Heikki Krogerus
maintainerHi,
Quoted 51 lines · Ajay Gupta
Hi Heikki,
Quoted 49 lines
Quoted 24 lines
Quoted 8 lines
Quoted 8 lines
Hi Ajay,
Here's the pretty much complete rewrite of the I/O handling that I was talking about. The first seven patches are not actually related to this stuff, but I'm including them here because the rest of the series is made on top of them. I'm including also that fix patch I send you earlier.
Quoted 4 lines
Quoted 4 lines
After this it should be easier to handle quirks. My idea how to handle the multi-instance connector alt modes is that we "emulate" the PPM in
ucsi_ccg.cin order to handle them, soucsi.cis not touched atall.
Quoted 11 lines
Quoted 4 lines
We can now get the connector alternate modes that the actual controller supplies during probe - before registering the ucsi interface
How can
ucsi_ccg.cget the connector alternate modes before registering ucsi interface? PPM reset, notification enable, etc. is done during ucsi registration. UCSI spec says:
" The only commands the PPM is required to process in the "PPM Idle (Notifications Disabled)" state areSET_NOTIFICATION_ENABLEandPPM_RESE"Quoted 8 lines
Quoted 2 lines
Also, it doesn't look correct if
ucsi_ccg.chas to replicate most of the stuff done inucsi_init()ofucsi.c.How about if we split
ucsi_init()into a function that first simply constructs the struct ucsi and structucsi_connectorinstances without registering anything, and into separate functions that then register the ports, altmodes and what have you. I don't think that should be a huge problem. It will makeucsi.ceven more like a library, which is probablea good thing.
Do you mean the solution to follow steps (a->b->c->d1) or (a->b->c->d2) ?
a)ucsi_ccg.ccalls first part of splitucsi_init()
b)ucsi_ccg.cusesucsi_send_command()to collect actual alternate modes.
c)ucsi_ccg.clooks into actual alternate modes and squashes if duplicate altmode found.
d1)ucsi_ccg.ccalls new method to register connector alternate modes. This method issuesGET_ALTERNATE_MODEScommand again anducsi_ccg.cis expected to send squashed alternate mode. This will require changes in .read(), .sync_write() and
.async_write() to make it appear as if the squashed data coming from the ppm. OR
d2)ucsi_ccg.ccalls new method to register squashed connector alternate modes.
This method doesn't issueGET_ALTERNATE_MODEScommands to PPM but simply registers the alternate mode values passed to this function.
Quoted 5 lines
Quoted 3 lines
If you mean the (
a->b->c->d2) solution then it looks fine to me and would wait for patches from you. This solution would mean thatGET_ALTERNATE_MODESfor connector is done only by eachucsi_xxx.cand not byucsi.cI am waiting for your comments on this.
Sorry Ajay. I lost track of this thread.
The above is not exactly what I had in mind, but something like that. But in any case, I'll start wringing the patches then.
thanks,
Signature · 1 line
heikki