1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for Intel PMC USB mux control
5 * Copyright (C) 2020 Intel Corporation
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
9 #include <linux/acpi.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/property.h>
13 #include <linux/usb/pd.h>
14 #include <linux/usb/role.h>
15 #include <linux/usb/typec_mux.h>
16 #include <linux/usb/typec_dp.h>
17 #include <linux/usb/typec_tbt.h>
18 #include <linux/debugfs.h>
19 #include <linux/usb.h>
21 #include <asm/intel_scu_ipc.h>
23 #define PMC_USBC_CMD 0xa7
25 /* Response status bits */
26 #define PMC_USB_RESP_STATUS_FAILURE BIT(0)
27 #define PMC_USB_RESP_STATUS_FATAL BIT(1)
29 /* "Usage" OOB Message field values */
38 #define PMC_USB_MSG_USB2_PORT_SHIFT 0
39 #define PMC_USB_MSG_USB3_PORT_SHIFT 4
40 #define PMC_USB_MSG_UFP_SHIFT 4
41 #define PMC_USB_MSG_ORI_HSL_SHIFT 5
42 #define PMC_USB_MSG_ORI_AUX_SHIFT 6
44 /* Alt Mode Request */
53 #define PMC_USB_MODE_TYPE_SHIFT 4
56 PMC_USB_MODE_TYPE_USB,
58 PMC_USB_MODE_TYPE_TBT,
61 /* Common Mode Data bits */
62 #define PMC_USB_ALTMODE_RETIMER_CABLE BIT(2)
64 #define PMC_USB_ALTMODE_ORI_SHIFT 1
65 #define PMC_USB_ALTMODE_UFP_SHIFT 3
67 /* DP specific Mode Data bits */
68 #define PMC_USB_ALTMODE_DP_MODE_SHIFT 8
70 /* TBT specific Mode Data bits */
71 #define PMC_USB_ALTMODE_TBT_TYPE BIT(17)
72 #define PMC_USB_ALTMODE_CABLE_TYPE BIT(18)
73 #define PMC_USB_ALTMODE_ACTIVE_LINK BIT(20)
74 #define PMC_USB_ALTMODE_ACTIVE_CABLE BIT(22)
75 #define PMC_USB_ALTMODE_FORCE_LSR BIT(23)
76 #define PMC_USB_ALTMODE_CABLE_SPD(_s_) (((_s_) & GENMASK(2, 0)) << 25)
77 #define PMC_USB_ALTMODE_CABLE_USB31 1
78 #define PMC_USB_ALTMODE_CABLE_10GPS 2
79 #define PMC_USB_ALTMODE_CABLE_20GPS 3
80 #define PMC_USB_ALTMODE_TBT_GEN(_g_) (((_g_) & GENMASK(1, 0)) << 28)
82 /* Display HPD Request bits */
83 #define PMC_USB_DP_HPD_LVL BIT(4)
84 #define PMC_USB_DP_HPD_IRQ BIT(5)
87 * Input Output Manager (IOM) PORT STATUS
89 #define IOM_PORT_STATUS_ACTIVITY_TYPE_MASK GENMASK(9, 6)
90 #define IOM_PORT_STATUS_ACTIVITY_TYPE_SHIFT 6
91 #define IOM_PORT_STATUS_ACTIVITY_TYPE_USB 0x03
92 /* activity type: Safe Mode */
93 #define IOM_PORT_STATUS_ACTIVITY_TYPE_SAFE_MODE 0x04
94 /* activity type: Display Port */
95 #define IOM_PORT_STATUS_ACTIVITY_TYPE_DP 0x05
96 /* activity type: Display Port Multi Function Device */
97 #define IOM_PORT_STATUS_ACTIVITY_TYPE_DP_MFD 0x06
98 /* activity type: Thunderbolt */
99 #define IOM_PORT_STATUS_ACTIVITY_TYPE_TBT 0x07
100 #define IOM_PORT_STATUS_ACTIVITY_TYPE_ALT_MODE_USB 0x0c
101 #define IOM_PORT_STATUS_ACTIVITY_TYPE_ALT_MODE_TBT_USB 0x0d
102 /* Upstream Facing Port Information */
103 #define IOM_PORT_STATUS_UFP BIT(10)
104 /* Display Port Hot Plug Detect status */
105 #define IOM_PORT_STATUS_DHPD_HPD_STATUS_MASK GENMASK(13, 12)
106 #define IOM_PORT_STATUS_DHPD_HPD_STATUS_SHIFT 12
107 #define IOM_PORT_STATUS_DHPD_HPD_STATUS_ASSERT 0x01
108 #define IOM_PORT_STATUS_DHPD_HPD_SOURCE_TBT BIT(14)
109 #define IOM_PORT_STATUS_CONNECTED BIT(31)
111 #define IOM_PORT_ACTIVITY_IS(_status_, _type_) \
112 ((((_status_) & IOM_PORT_STATUS_ACTIVITY_TYPE_MASK) >> \
113 IOM_PORT_STATUS_ACTIVITY_TYPE_SHIFT) == \
114 (IOM_PORT_STATUS_ACTIVITY_TYPE_##_type_))
116 #define IOM_PORT_HPD_ASSERTED(_status_) \
117 ((((_status_) & IOM_PORT_STATUS_DHPD_HPD_STATUS_MASK) >> \
118 IOM_PORT_STATUS_DHPD_HPD_STATUS_SHIFT) & \
119 IOM_PORT_STATUS_DHPD_HPD_STATUS_ASSERT)
121 /* IOM port status register */
122 #define IOM_PORT_STATUS_REGS(_offset_, _size_) ((_offset_) | (_size_))
123 #define IOM_PORT_STATUS_REGS_SZ_MASK BIT(0)
124 #define IOM_PORT_STATUS_REGS_SZ_4 0
125 #define IOM_PORT_STATUS_REGS_SZ_8 1
126 #define IOM_PORT_STATUS_REGS_OFFSET(_d_) \
127 ((_d_) & ~IOM_PORT_STATUS_REGS_SZ_MASK)
128 #define IOM_PORT_STATUS_REGS_SIZE(_d_) \
129 (4 << ((_d_) & IOM_PORT_STATUS_REGS_SZ_MASK))
133 struct pmc_usb_port {
137 struct typec_mux_dev *typec_mux;
138 struct typec_switch_dev *typec_sw;
139 struct usb_role_switch *usb_sw;
141 enum typec_orientation orientation;
147 enum typec_orientation sbu_orientation;
148 enum typec_orientation hsl_orientation;
154 struct intel_scu_ipc_dev *ipc;
155 struct pmc_usb_port *port;
156 struct acpi_device *iom_adev;
157 void __iomem *iom_base;
158 u32 iom_port_status_offset;
159 u8 iom_port_status_size;
161 struct dentry *dentry;
164 static struct dentry *pmc_mux_debugfs_root;
166 static void update_port_status(struct pmc_usb_port *port)
170 /* SoC expects the USB Type-C port numbers to start with 0 */
171 port_num = port->usb3_port - 1;
173 port->iom_status = readl(port->pmc->iom_base +
174 port->pmc->iom_port_status_offset +
175 port_num * port->pmc->iom_port_status_size);
178 static int sbu_orientation(struct pmc_usb_port *port)
180 if (port->sbu_orientation)
181 return port->sbu_orientation - 1;
183 return port->orientation - 1;
186 static int hsl_orientation(struct pmc_usb_port *port)
188 if (port->hsl_orientation)
189 return port->hsl_orientation - 1;
191 return port->orientation - 1;
194 static int pmc_usb_send_command(struct intel_scu_ipc_dev *ipc, u8 *msg, u32 len)
201 * Error bit will always be 0 with the USBC command.
202 * Status can be checked from the response message if the
203 * function intel_scu_ipc_dev_command succeeds.
205 ret = intel_scu_ipc_dev_command(ipc, PMC_USBC_CMD, 0, msg,
206 len, response, sizeof(response));
211 status_res = (msg[0] & 0xf) < PMC_USB_SAFE_MODE ?
212 response[2] : response[1];
214 if (status_res & PMC_USB_RESP_STATUS_FAILURE) {
215 if (status_res & PMC_USB_RESP_STATUS_FATAL)
224 static int pmc_usb_command(struct pmc_usb_port *port, u8 *msg, u32 len)
230 * If PMC is busy then retry the command once again
232 while (retry_count--) {
233 ret = pmc_usb_send_command(port->pmc->ipc, msg, len);
242 pmc_usb_mux_dp_hpd(struct pmc_usb_port *port, struct typec_displayport_data *dp)
247 msg[0] = PMC_USB_DP_HPD;
248 msg[0] |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
250 /* Configure HPD first if HPD,IRQ comes together */
251 if (!IOM_PORT_HPD_ASSERTED(port->iom_status) &&
252 dp->status & DP_STATUS_IRQ_HPD &&
253 dp->status & DP_STATUS_HPD_STATE) {
254 msg[1] = PMC_USB_DP_HPD_LVL;
255 ret = pmc_usb_command(port, msg, sizeof(msg));
260 if (dp->status & DP_STATUS_IRQ_HPD)
261 msg[1] = PMC_USB_DP_HPD_IRQ;
263 if (dp->status & DP_STATUS_HPD_STATE)
264 msg[1] |= PMC_USB_DP_HPD_LVL;
266 return pmc_usb_command(port, msg, sizeof(msg));
270 pmc_usb_mux_dp(struct pmc_usb_port *port, struct typec_mux_state *state)
272 struct typec_displayport_data *data = state->data;
273 struct altmode_req req = { };
276 if (IOM_PORT_ACTIVITY_IS(port->iom_status, DP) ||
277 IOM_PORT_ACTIVITY_IS(port->iom_status, DP_MFD)) {
278 if (IOM_PORT_HPD_ASSERTED(port->iom_status) &&
279 (!(data->status & DP_STATUS_IRQ_HPD) &&
280 data->status & DP_STATUS_HPD_STATE))
283 return pmc_usb_mux_dp_hpd(port, state->data);
286 req.usage = PMC_USB_ALT_MODE;
287 req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
288 req.mode_type = PMC_USB_MODE_TYPE_DP << PMC_USB_MODE_TYPE_SHIFT;
290 req.mode_data = (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
291 req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
293 req.mode_data |= (state->mode - TYPEC_STATE_MODAL) <<
294 PMC_USB_ALTMODE_DP_MODE_SHIFT;
296 ret = pmc_usb_command(port, (void *)&req, sizeof(req));
300 if (data->status & (DP_STATUS_IRQ_HPD | DP_STATUS_HPD_STATE))
301 return pmc_usb_mux_dp_hpd(port, state->data);
307 pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state)
309 struct typec_thunderbolt_data *data = state->data;
310 u8 cable_rounded = TBT_CABLE_ROUNDED_SUPPORT(data->cable_mode);
311 u8 cable_speed = TBT_CABLE_SPEED(data->cable_mode);
312 struct altmode_req req = { };
314 if (IOM_PORT_ACTIVITY_IS(port->iom_status, TBT) ||
315 IOM_PORT_ACTIVITY_IS(port->iom_status, ALT_MODE_TBT_USB))
318 req.usage = PMC_USB_ALT_MODE;
319 req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
320 req.mode_type = PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT;
322 req.mode_data = (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
323 req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
325 if (TBT_ADAPTER(data->device_mode) == TBT_ADAPTER_TBT3)
326 req.mode_data |= PMC_USB_ALTMODE_TBT_TYPE;
328 if (data->cable_mode & TBT_CABLE_OPTICAL)
329 req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE;
331 if (data->cable_mode & TBT_CABLE_LINK_TRAINING)
332 req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
334 if (acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1072", NULL) ||
335 acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1079", NULL)) {
336 if ((data->enter_vdo & TBT_ENTER_MODE_ACTIVE_CABLE) ||
337 (data->cable_mode & TBT_CABLE_RETIMER))
338 req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE;
340 if (data->enter_vdo & TBT_ENTER_MODE_ACTIVE_CABLE)
341 req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
343 if (data->cable_mode & TBT_CABLE_RETIMER)
344 req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE;
347 req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed);
349 req.mode_data |= PMC_USB_ALTMODE_TBT_GEN(cable_rounded);
351 return pmc_usb_command(port, (void *)&req, sizeof(req));
355 pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
357 struct enter_usb_data *data = state->data;
358 struct altmode_req req = { };
361 if (IOM_PORT_ACTIVITY_IS(port->iom_status, TBT) ||
362 IOM_PORT_ACTIVITY_IS(port->iom_status, ALT_MODE_TBT_USB))
365 req.usage = PMC_USB_ALT_MODE;
366 req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
367 req.mode_type = PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT;
370 req.mode_data = PMC_USB_ALTMODE_FORCE_LSR;
372 if (data->active_link_training)
373 req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
375 req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
376 req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
378 switch ((data->eudo & EUDO_CABLE_TYPE_MASK) >> EUDO_CABLE_TYPE_SHIFT) {
379 case EUDO_CABLE_TYPE_PASSIVE:
381 case EUDO_CABLE_TYPE_OPTICAL:
382 req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE;
384 case EUDO_CABLE_TYPE_RE_TIMER:
385 if (!acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1072", NULL) ||
386 !acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1079", NULL))
387 req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE;
390 if (acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1072", NULL) ||
391 acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1079", NULL))
392 req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE;
394 req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
396 /* Configure data rate to rounded in the case of Active TBT3
399 req.mode_data |= PMC_USB_ALTMODE_TBT_GEN(1);
403 cable_speed = (data->eudo & EUDO_CABLE_SPEED_MASK) >> EUDO_CABLE_SPEED_SHIFT;
404 req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed);
406 return pmc_usb_command(port, (void *)&req, sizeof(req));
409 static int pmc_usb_mux_safe_state(struct pmc_usb_port *port,
410 struct typec_mux_state *state)
414 if (IOM_PORT_ACTIVITY_IS(port->iom_status, SAFE_MODE))
417 if ((IOM_PORT_ACTIVITY_IS(port->iom_status, DP) ||
418 IOM_PORT_ACTIVITY_IS(port->iom_status, DP_MFD)) &&
419 state->alt && state->alt->svid == USB_TYPEC_DP_SID)
422 if ((IOM_PORT_ACTIVITY_IS(port->iom_status, TBT) ||
423 IOM_PORT_ACTIVITY_IS(port->iom_status, ALT_MODE_TBT_USB)) &&
424 state->alt && state->alt->svid == USB_TYPEC_TBT_SID)
427 msg = PMC_USB_SAFE_MODE;
428 msg |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
430 return pmc_usb_command(port, &msg, sizeof(msg));
433 static int pmc_usb_disconnect(struct pmc_usb_port *port)
435 struct typec_displayport_data data = { };
438 if (!(port->iom_status & IOM_PORT_STATUS_CONNECTED))
441 /* Clear DisplayPort HPD if it's still asserted. */
442 if (IOM_PORT_HPD_ASSERTED(port->iom_status))
443 pmc_usb_mux_dp_hpd(port, &data);
445 msg[0] = PMC_USB_DISCONNECT;
446 msg[0] |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
448 msg[1] = port->usb2_port << PMC_USB_MSG_USB2_PORT_SHIFT;
450 return pmc_usb_command(port, msg, sizeof(msg));
453 static int pmc_usb_connect(struct pmc_usb_port *port, enum usb_role role)
455 u8 ufp = role == USB_ROLE_DEVICE ? 1 : 0;
459 if (port->orientation == TYPEC_ORIENTATION_NONE)
462 if (port->iom_status & IOM_PORT_STATUS_CONNECTED) {
463 if (port->role == role || port->role == USB_ROLE_NONE)
467 ret = pmc_usb_disconnect(port);
472 msg[0] = PMC_USB_CONNECT;
473 msg[0] |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
475 msg[1] = port->usb2_port << PMC_USB_MSG_USB2_PORT_SHIFT;
476 msg[1] |= ufp << PMC_USB_MSG_UFP_SHIFT;
477 msg[1] |= hsl_orientation(port) << PMC_USB_MSG_ORI_HSL_SHIFT;
478 msg[1] |= sbu_orientation(port) << PMC_USB_MSG_ORI_AUX_SHIFT;
480 return pmc_usb_command(port, msg, sizeof(msg));
484 pmc_usb_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state)
486 struct pmc_usb_port *port = typec_mux_get_drvdata(mux);
488 update_port_status(port);
490 if (port->orientation == TYPEC_ORIENTATION_NONE || port->role == USB_ROLE_NONE)
493 if (state->mode == TYPEC_STATE_SAFE)
494 return pmc_usb_mux_safe_state(port, state);
495 if (state->mode == TYPEC_STATE_USB)
496 return pmc_usb_connect(port, port->role);
499 switch (state->alt->svid) {
500 case USB_TYPEC_TBT_SID:
501 return pmc_usb_mux_tbt(port, state);
502 case USB_TYPEC_DP_SID:
503 return pmc_usb_mux_dp(port, state);
506 switch (state->mode) {
507 case TYPEC_MODE_USB2:
508 /* REVISIT: Try with usb3_port set to 0? */
510 case TYPEC_MODE_USB3:
511 return pmc_usb_connect(port, port->role);
512 case TYPEC_MODE_USB4:
513 return pmc_usb_mux_usb4(port, state);
520 static int pmc_usb_set_orientation(struct typec_switch_dev *sw,
521 enum typec_orientation orientation)
523 struct pmc_usb_port *port = typec_switch_get_drvdata(sw);
525 update_port_status(port);
527 port->orientation = orientation;
532 static int pmc_usb_set_role(struct usb_role_switch *sw, enum usb_role role)
534 struct pmc_usb_port *port = usb_role_switch_get_drvdata(sw);
537 update_port_status(port);
539 if (role == USB_ROLE_NONE)
540 ret = pmc_usb_disconnect(port);
542 ret = pmc_usb_connect(port, role);
549 static int pmc_usb_register_port(struct pmc_usb *pmc, int index,
550 struct fwnode_handle *fwnode)
552 struct pmc_usb_port *port = &pmc->port[index];
553 struct usb_role_switch_desc desc = { };
554 struct typec_switch_desc sw_desc = { };
555 struct typec_mux_desc mux_desc = { };
559 ret = fwnode_property_read_u8(fwnode, "usb2-port-number", &port->usb2_port);
563 ret = fwnode_property_read_u8(fwnode, "usb3-port-number", &port->usb3_port);
567 ret = fwnode_property_read_string(fwnode, "sbu-orientation", &str);
569 port->sbu_orientation = typec_find_orientation(str);
571 ret = fwnode_property_read_string(fwnode, "hsl-orientation", &str);
573 port->hsl_orientation = typec_find_orientation(str);
578 sw_desc.fwnode = fwnode;
579 sw_desc.drvdata = port;
580 sw_desc.name = fwnode_get_name(fwnode);
581 sw_desc.set = pmc_usb_set_orientation;
583 port->typec_sw = typec_switch_register(pmc->dev, &sw_desc);
584 if (IS_ERR(port->typec_sw))
585 return PTR_ERR(port->typec_sw);
587 mux_desc.fwnode = fwnode;
588 mux_desc.drvdata = port;
589 mux_desc.name = fwnode_get_name(fwnode);
590 mux_desc.set = pmc_usb_mux_set;
592 port->typec_mux = typec_mux_register(pmc->dev, &mux_desc);
593 if (IS_ERR(port->typec_mux)) {
594 ret = PTR_ERR(port->typec_mux);
595 goto err_unregister_switch;
598 desc.fwnode = fwnode;
599 desc.driver_data = port;
600 desc.name = fwnode_get_name(fwnode);
601 desc.set = pmc_usb_set_role;
603 port->usb_sw = usb_role_switch_register(pmc->dev, &desc);
604 if (IS_ERR(port->usb_sw)) {
605 ret = PTR_ERR(port->usb_sw);
606 goto err_unregister_mux;
612 typec_mux_unregister(port->typec_mux);
614 err_unregister_switch:
615 typec_switch_unregister(port->typec_sw);
620 /* IOM ACPI IDs and IOM_PORT_STATUS_OFFSET */
621 static const struct acpi_device_id iom_acpi_ids[] = {
623 { "INTC1072", IOM_PORT_STATUS_REGS(0x560, IOM_PORT_STATUS_REGS_SZ_4) },
626 { "INTC1079", IOM_PORT_STATUS_REGS(0x160, IOM_PORT_STATUS_REGS_SZ_4) },
629 { "INTC107A", IOM_PORT_STATUS_REGS(0x160, IOM_PORT_STATUS_REGS_SZ_4) },
632 { "INTC10EA", IOM_PORT_STATUS_REGS(0x150, IOM_PORT_STATUS_REGS_SZ_8) },
636 static int pmc_usb_probe_iom(struct pmc_usb *pmc)
638 struct list_head resource_list;
639 struct resource_entry *rentry;
640 static const struct acpi_device_id *dev_id;
641 struct acpi_device *adev = NULL;
644 for (dev_id = &iom_acpi_ids[0]; dev_id->id[0]; dev_id++) {
645 adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
652 pmc->iom_port_status_offset = IOM_PORT_STATUS_REGS_OFFSET(dev_id->driver_data);
653 pmc->iom_port_status_size = IOM_PORT_STATUS_REGS_SIZE(dev_id->driver_data);
655 INIT_LIST_HEAD(&resource_list);
656 ret = acpi_dev_get_memory_resources(adev, &resource_list);
662 rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node);
664 pmc->iom_base = devm_ioremap_resource(pmc->dev, rentry->res);
666 acpi_dev_free_resource_list(&resource_list);
668 if (!pmc->iom_base) {
673 if (IS_ERR(pmc->iom_base)) {
675 return PTR_ERR(pmc->iom_base);
678 pmc->iom_adev = adev;
683 static int port_iom_status_show(struct seq_file *s, void *unused)
685 struct pmc_usb_port *port = s->private;
687 update_port_status(port);
688 seq_printf(s, "0x%08x\n", port->iom_status);
692 DEFINE_SHOW_ATTRIBUTE(port_iom_status);
694 static void pmc_mux_port_debugfs_init(struct pmc_usb_port *port)
696 struct dentry *debugfs_dir;
699 snprintf(name, sizeof(name), "port%d", port->usb3_port - 1);
701 debugfs_dir = debugfs_create_dir(name, port->pmc->dentry);
702 debugfs_create_file("iom_status", 0400, debugfs_dir, port,
703 &port_iom_status_fops);
706 static int pmc_usb_probe(struct platform_device *pdev)
708 struct fwnode_handle *fwnode = NULL;
713 pmc = devm_kzalloc(&pdev->dev, sizeof(*pmc), GFP_KERNEL);
717 device_for_each_child_node(&pdev->dev, fwnode)
720 /* The IOM microcontroller has a limitation of max 4 ports. */
721 if (pmc->num_ports > 4) {
722 dev_err(&pdev->dev, "driver limited to 4 ports\n");
726 pmc->port = devm_kcalloc(&pdev->dev, pmc->num_ports,
727 sizeof(struct pmc_usb_port), GFP_KERNEL);
731 pmc->ipc = devm_intel_scu_ipc_dev_get(&pdev->dev);
735 pmc->dev = &pdev->dev;
737 ret = pmc_usb_probe_iom(pmc);
741 pmc->dentry = debugfs_create_dir(dev_name(pmc->dev), pmc_mux_debugfs_root);
744 * For every physical USB connector (USB2 and USB3 combo) there is a
745 * child ACPI device node under the PMC mux ACPI device object.
747 for (i = 0; i < pmc->num_ports; i++) {
748 fwnode = device_get_next_child_node(pmc->dev, fwnode);
752 ret = pmc_usb_register_port(pmc, i, fwnode);
754 fwnode_handle_put(fwnode);
755 goto err_remove_ports;
758 pmc_mux_port_debugfs_init(&pmc->port[i]);
761 platform_set_drvdata(pdev, pmc);
766 for (i = 0; i < pmc->num_ports; i++) {
767 typec_switch_unregister(pmc->port[i].typec_sw);
768 typec_mux_unregister(pmc->port[i].typec_mux);
769 usb_role_switch_unregister(pmc->port[i].usb_sw);
772 acpi_dev_put(pmc->iom_adev);
774 debugfs_remove(pmc->dentry);
779 static void pmc_usb_remove(struct platform_device *pdev)
781 struct pmc_usb *pmc = platform_get_drvdata(pdev);
784 for (i = 0; i < pmc->num_ports; i++) {
785 typec_switch_unregister(pmc->port[i].typec_sw);
786 typec_mux_unregister(pmc->port[i].typec_mux);
787 usb_role_switch_unregister(pmc->port[i].usb_sw);
790 acpi_dev_put(pmc->iom_adev);
792 debugfs_remove(pmc->dentry);
795 static const struct acpi_device_id pmc_usb_acpi_ids[] = {
799 MODULE_DEVICE_TABLE(acpi, pmc_usb_acpi_ids);
801 static struct platform_driver pmc_usb_driver = {
803 .name = "intel_pmc_usb",
804 .acpi_match_table = ACPI_PTR(pmc_usb_acpi_ids),
806 .probe = pmc_usb_probe,
807 .remove_new = pmc_usb_remove,
810 static int __init pmc_usb_init(void)
812 pmc_mux_debugfs_root = debugfs_create_dir("intel_pmc_mux", usb_debug_root);
814 return platform_driver_register(&pmc_usb_driver);
816 module_init(pmc_usb_init);
818 static void __exit pmc_usb_exit(void)
820 platform_driver_unregister(&pmc_usb_driver);
821 debugfs_remove(pmc_mux_debugfs_root);
823 module_exit(pmc_usb_exit);
825 MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>");
826 MODULE_LICENSE("GPL v2");
827 MODULE_DESCRIPTION("Intel PMC USB mux control");