Skip to content

Commit ff4a30d

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: typec: mux: intel_pmc_mux: Support for static SBU/HSL orientation
The SBU and HSL orientation may be fixed/static from the mux PoW. Apparently the retimer may take care of the orientation of these lines. Handling the static SBU (AUX) and HSL orientation with device properties. If the SBU orientation is static, a device property "sbu-orintation" can be used. When the property exists, the driver always sets the SBU orientation according to the property value, and when it's not set, the driver uses the cable plug orientation with SBU. And with static HSL orientation, "hsl-orientation" device property can be used in the same way. Signed-off-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8c49c9e commit ff4a30d

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

drivers/usb/typec/mux/intel_pmc_mux.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ struct pmc_usb_port {
9191

9292
u8 usb2_port;
9393
u8 usb3_port;
94+
95+
enum typec_orientation sbu_orientation;
96+
enum typec_orientation hsl_orientation;
9497
};
9598

9699
struct pmc_usb {
@@ -99,6 +102,22 @@ struct pmc_usb {
99102
struct pmc_usb_port *port;
100103
};
101104

105+
static int sbu_orientation(struct pmc_usb_port *port)
106+
{
107+
if (port->sbu_orientation)
108+
return port->sbu_orientation - 1;
109+
110+
return port->orientation - 1;
111+
}
112+
113+
static int hsl_orientation(struct pmc_usb_port *port)
114+
{
115+
if (port->hsl_orientation)
116+
return port->hsl_orientation - 1;
117+
118+
return port->orientation - 1;
119+
}
120+
102121
static int pmc_usb_command(struct pmc_usb_port *port, u8 *msg, u32 len)
103122
{
104123
u8 response[4];
@@ -151,8 +170,9 @@ pmc_usb_mux_dp(struct pmc_usb_port *port, struct typec_mux_state *state)
151170

152171
req.mode_data = (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
153172
req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
154-
req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_AUX_SHIFT;
155-
req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_HSL_SHIFT;
173+
174+
req.mode_data |= sbu_orientation(port) << PMC_USB_ALTMODE_ORI_AUX_SHIFT;
175+
req.mode_data |= hsl_orientation(port) << PMC_USB_ALTMODE_ORI_HSL_SHIFT;
156176

157177
req.mode_data |= (state->mode - TYPEC_STATE_MODAL) <<
158178
PMC_USB_ALTMODE_DP_MODE_SHIFT;
@@ -177,8 +197,9 @@ pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state)
177197

178198
req.mode_data = (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
179199
req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
180-
req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_AUX_SHIFT;
181-
req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_HSL_SHIFT;
200+
201+
req.mode_data |= sbu_orientation(port) << PMC_USB_ALTMODE_ORI_AUX_SHIFT;
202+
req.mode_data |= hsl_orientation(port) << PMC_USB_ALTMODE_ORI_HSL_SHIFT;
182203

183204
if (TBT_ADAPTER(data->device_mode) == TBT_ADAPTER_TBT3)
184205
req.mode_data |= PMC_USB_ALTMODE_TBT_TYPE;
@@ -215,8 +236,8 @@ static int pmc_usb_connect(struct pmc_usb_port *port)
215236
msg[0] |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
216237

217238
msg[1] = port->usb2_port << PMC_USB_MSG_USB2_PORT_SHIFT;
218-
msg[1] |= (port->orientation - 1) << PMC_USB_MSG_ORI_HSL_SHIFT;
219-
msg[1] |= (port->orientation - 1) << PMC_USB_MSG_ORI_AUX_SHIFT;
239+
msg[1] |= hsl_orientation(port) << PMC_USB_MSG_ORI_HSL_SHIFT;
240+
msg[1] |= sbu_orientation(port) << PMC_USB_MSG_ORI_AUX_SHIFT;
220241

221242
return pmc_usb_command(port, msg, sizeof(msg));
222243
}
@@ -300,6 +321,7 @@ static int pmc_usb_register_port(struct pmc_usb *pmc, int index,
300321
struct usb_role_switch_desc desc = { };
301322
struct typec_switch_desc sw_desc = { };
302323
struct typec_mux_desc mux_desc = { };
324+
const char *str;
303325
int ret;
304326

305327
ret = fwnode_property_read_u8(fwnode, "usb2-port-number", &port->usb2_port);
@@ -310,6 +332,14 @@ static int pmc_usb_register_port(struct pmc_usb *pmc, int index,
310332
if (ret)
311333
return ret;
312334

335+
ret = fwnode_property_read_string(fwnode, "sbu-orientation", &str);
336+
if (!ret)
337+
port->sbu_orientation = typec_find_orientation(str);
338+
339+
ret = fwnode_property_read_string(fwnode, "hsl-orientation", &str);
340+
if (!ret)
341+
port->hsl_orientation = typec_find_orientation(str);
342+
313343
port->num = index;
314344
port->pmc = pmc;
315345

0 commit comments

Comments
 (0)