Skip to content

Commit 2000016

Browse files
jwrdegoedegregkh
authored andcommitted
usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch functions
Remove the unused (not implemented anywhere) tcpc_mux_dev abstraction and replace it with calling the new typec_set_orientation, usb_role_switch_set and typec_set_mode functions. Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Heikki Krogerus <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c6962c2 commit 2000016

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

drivers/usb/typec/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ if TYPEC
4848
config TYPEC_TCPM
4949
tristate "USB Type-C Port Controller Manager"
5050
depends on USB
51+
select USB_ROLE_SWITCH
5152
help
5253
The Type-C Port Controller Manager provides a USB PD and USB Type-C
5354
state machine for use with Type-C Port Controllers.

drivers/usb/typec/fusb302/fusb302.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,6 @@ static void init_tcpc_dev(struct tcpc_dev *fusb302_tcpc_dev)
12391239
fusb302_tcpc_dev->set_roles = tcpm_set_roles;
12401240
fusb302_tcpc_dev->start_drp_toggling = tcpm_start_drp_toggling;
12411241
fusb302_tcpc_dev->pd_transmit = tcpm_pd_transmit;
1242-
fusb302_tcpc_dev->mux = NULL;
12431242
}
12441243

12451244
static const char * const cc_polarity_name[] = {

drivers/usb/typec/tcpm.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/usb/pd.h>
2121
#include <linux/usb/pd_bdo.h>
2222
#include <linux/usb/pd_vdo.h>
23+
#include <linux/usb/role.h>
2324
#include <linux/usb/tcpm.h>
2425
#include <linux/usb/typec.h>
2526
#include <linux/workqueue.h>
@@ -176,6 +177,7 @@ struct tcpm_port {
176177
struct typec_port *typec_port;
177178

178179
struct tcpc_dev *tcpc;
180+
struct usb_role_switch *role_sw;
179181

180182
enum typec_role vconn_role;
181183
enum typec_role pwr_role;
@@ -604,18 +606,25 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port,
604606
EXPORT_SYMBOL_GPL(tcpm_pd_transmit_complete);
605607

606608
static int tcpm_mux_set(struct tcpm_port *port, enum tcpc_mux_mode mode,
607-
enum usb_role usb_role)
609+
enum usb_role usb_role,
610+
enum typec_orientation orientation)
608611
{
609-
int ret = 0;
612+
int ret;
610613

611-
tcpm_log(port, "Requesting mux mode %d, usb-role %d, polarity %d",
612-
mode, usb_role, port->polarity);
614+
tcpm_log(port, "Requesting mux mode %d, usb-role %d, orientation %d",
615+
mode, usb_role, orientation);
613616

614-
if (port->tcpc->mux)
615-
ret = port->tcpc->mux->set(port->tcpc->mux, mode, usb_role,
616-
port->polarity);
617+
ret = typec_set_orientation(port->typec_port, orientation);
618+
if (ret)
619+
return ret;
617620

618-
return ret;
621+
if (port->role_sw) {
622+
ret = usb_role_switch_set_role(port->role_sw, usb_role);
623+
if (ret)
624+
return ret;
625+
}
626+
627+
return typec_set_mode(port->typec_port, mode);
619628
}
620629

621630
static int tcpm_set_polarity(struct tcpm_port *port,
@@ -728,15 +737,21 @@ static int tcpm_set_attached_state(struct tcpm_port *port, bool attached)
728737
static int tcpm_set_roles(struct tcpm_port *port, bool attached,
729738
enum typec_role role, enum typec_data_role data)
730739
{
740+
enum typec_orientation orientation;
731741
enum usb_role usb_role;
732742
int ret;
733743

744+
if (port->polarity == TYPEC_POLARITY_CC1)
745+
orientation = TYPEC_ORIENTATION_NORMAL;
746+
else
747+
orientation = TYPEC_ORIENTATION_REVERSE;
748+
734749
if (data == TYPEC_HOST)
735750
usb_role = USB_ROLE_HOST;
736751
else
737752
usb_role = USB_ROLE_DEVICE;
738753

739-
ret = tcpm_mux_set(port, TYPEC_MUX_USB, usb_role);
754+
ret = tcpm_mux_set(port, TYPEC_MUX_USB, usb_role, orientation);
740755
if (ret < 0)
741756
return ret;
742757

@@ -2029,7 +2044,8 @@ static int tcpm_src_attach(struct tcpm_port *port)
20292044
out_disable_pd:
20302045
port->tcpc->set_pd_rx(port->tcpc, false);
20312046
out_disable_mux:
2032-
tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE);
2047+
tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE,
2048+
TYPEC_ORIENTATION_NONE);
20332049
return ret;
20342050
}
20352051

@@ -2073,7 +2089,8 @@ static void tcpm_reset_port(struct tcpm_port *port)
20732089
tcpm_init_vconn(port);
20742090
tcpm_set_current_limit(port, 0, 0);
20752091
tcpm_set_polarity(port, TYPEC_POLARITY_CC1);
2076-
tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE);
2092+
tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE,
2093+
TYPEC_ORIENTATION_NONE);
20772094
tcpm_set_attached_state(port, false);
20782095
port->try_src_count = 0;
20792096
port->try_snk_count = 0;
@@ -3653,6 +3670,12 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
36533670
port->partner_desc.identity = &port->partner_ident;
36543671
port->port_type = tcpc->config->type;
36553672

3673+
port->role_sw = usb_role_switch_get(port->dev);
3674+
if (IS_ERR(port->role_sw)) {
3675+
err = PTR_ERR(port->role_sw);
3676+
goto out_destroy_wq;
3677+
}
3678+
36563679
port->typec_port = typec_register_port(port->dev, &port->typec_caps);
36573680
if (IS_ERR(port->typec_port)) {
36583681
err = PTR_ERR(port->typec_port);
@@ -3688,6 +3711,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
36883711
return port;
36893712

36903713
out_destroy_wq:
3714+
usb_role_switch_put(port->role_sw);
36913715
destroy_workqueue(port->wq);
36923716
return ERR_PTR(err);
36933717
}

include/linux/usb/tcpm.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define __LINUX_USB_TCPM_H
1717

1818
#include <linux/bitops.h>
19-
#include <linux/usb/role.h>
2019
#include <linux/usb/typec.h>
2120
#include "pd.h"
2221

@@ -113,14 +112,6 @@ enum tcpc_mux_mode {
113112
TCPC_MUX_DP_ENABLED,
114113
};
115114

116-
struct tcpc_mux_dev {
117-
int (*set)(struct tcpc_mux_dev *dev, enum tcpc_mux_mode mux_mode,
118-
enum usb_role usb_role,
119-
enum typec_cc_polarity polarity);
120-
bool dfp_only;
121-
void *priv_data;
122-
};
123-
124115
/**
125116
* struct tcpc_dev - Port configuration and callback functions
126117
* @config: Pointer to port configuration
@@ -172,7 +163,6 @@ struct tcpc_dev {
172163
int (*try_role)(struct tcpc_dev *dev, int role);
173164
int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
174165
const struct pd_message *msg);
175-
struct tcpc_mux_dev *mux;
176166
};
177167

178168
struct tcpm_port;

0 commit comments

Comments
 (0)