Skip to content

Commit f28adb4

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Register Type C switches
Register Type C mux and switch handles, when provided via firmware bindings. These will allow the cros-ec-typec driver, and also alternate mode drivers to configure connected Muxes correctly, according to PD information retrieved from the Chrome OS EC. Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent d378cdd commit f28adb4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/platform_data/cros_usbpd_notify.h>
1515
#include <linux/platform_device.h>
1616
#include <linux/usb/typec.h>
17+
#include <linux/usb/typec_mux.h>
18+
#include <linux/usb/role.h>
1719

1820
#define DRV_NAME "cros-ec-typec"
1921

@@ -25,6 +27,9 @@ struct cros_typec_port {
2527
struct typec_partner *partner;
2628
/* Port partner PD identity info. */
2729
struct usb_pd_identity p_identity;
30+
struct typec_switch *ori_sw;
31+
struct typec_mux *mux;
32+
struct usb_role_switch *role_sw;
2833
};
2934

3035
/* Platform-specific data for the Chrome OS EC Type C controller. */
@@ -84,13 +89,50 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
8489
return 0;
8590
}
8691

92+
static int cros_typec_get_switch_handles(struct cros_typec_port *port,
93+
struct fwnode_handle *fwnode,
94+
struct device *dev)
95+
{
96+
port->mux = fwnode_typec_mux_get(fwnode, NULL);
97+
if (IS_ERR(port->mux)) {
98+
dev_dbg(dev, "Mux handle not found.\n");
99+
goto mux_err;
100+
}
101+
102+
port->ori_sw = fwnode_typec_switch_get(fwnode);
103+
if (IS_ERR(port->ori_sw)) {
104+
dev_dbg(dev, "Orientation switch handle not found.\n");
105+
goto ori_sw_err;
106+
}
107+
108+
port->role_sw = fwnode_usb_role_switch_get(fwnode);
109+
if (IS_ERR(port->role_sw)) {
110+
dev_dbg(dev, "USB role switch handle not found.\n");
111+
goto role_sw_err;
112+
}
113+
114+
return 0;
115+
116+
role_sw_err:
117+
usb_role_switch_put(port->role_sw);
118+
ori_sw_err:
119+
typec_switch_put(port->ori_sw);
120+
mux_err:
121+
typec_mux_put(port->mux);
122+
123+
return -ENODEV;
124+
}
125+
87126
static void cros_unregister_ports(struct cros_typec_data *typec)
88127
{
89128
int i;
90129

91130
for (i = 0; i < typec->num_ports; i++) {
92131
if (!typec->ports[i])
93132
continue;
133+
usb_role_switch_put(typec->ports[i]->role_sw);
134+
typec_switch_put(typec->ports[i]->ori_sw);
135+
typec_mux_put(typec->ports[i]->mux);
94136
typec_unregister_port(typec->ports[i]->port);
95137
}
96138
}
@@ -153,6 +195,11 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
153195
ret = PTR_ERR(cros_port->port);
154196
goto unregister_ports;
155197
}
198+
199+
ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
200+
if (ret)
201+
dev_dbg(dev, "No switch control for port %d\n",
202+
port_num);
156203
}
157204

158205
return 0;

0 commit comments

Comments
 (0)