1 // SPDX-License-Identifier: GPL-2.0
3 * USB Type-C Connector Class Port Mapping Utility
5 * Copyright (C) 2021, Intel Corporation
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
9 #include <linux/acpi.h>
10 #include <linux/component.h>
11 #include <linux/usb.h>
15 static int typec_aggregate_bind(struct device *dev)
17 struct typec_port *port = to_typec_port(dev);
19 return component_bind_all(dev, &port->con);
22 static void typec_aggregate_unbind(struct device *dev)
24 struct typec_port *port = to_typec_port(dev);
26 component_unbind_all(dev, &port->con);
29 static const struct component_master_ops typec_aggregate_ops = {
30 .bind = typec_aggregate_bind,
31 .unbind = typec_aggregate_unbind,
34 struct each_port_arg {
35 struct typec_port *port;
36 struct component_match *match;
39 static int typec_port_compare(struct device *dev, void *fwnode)
41 return device_match_fwnode(dev, fwnode);
44 static int typec_port_match(struct device *dev, void *data)
46 struct acpi_device *adev = to_acpi_device(dev);
47 struct each_port_arg *arg = data;
48 struct acpi_device *con_adev;
50 con_adev = ACPI_COMPANION(&arg->port->dev);
54 if (con_adev->pld_crc == adev->pld_crc)
55 component_match_add(&arg->port->dev, &arg->match, typec_port_compare,
56 acpi_fwnode_handle(adev));
60 int typec_link_ports(struct typec_port *con)
62 struct each_port_arg arg = { .port = con, .match = NULL };
64 if (!has_acpi_companion(&con->dev))
67 acpi_bus_for_each_dev(typec_port_match, &arg);
72 * REVISIT: Now each connector can have only a single component master.
73 * So far only the USB ports connected to the USB Type-C connector share
74 * the _PLD with it, but if there one day is something else (like maybe
75 * the DisplayPort ACPI device object) that also shares the _PLD with
76 * the connector, every one of those needs to have its own component
77 * master, because each different type of component needs to be bind to
78 * the connector independently of the other components. That requires
79 * improvements to the component framework. Right now you can only have
80 * one master per device.
82 return component_master_add_with_match(&con->dev, &typec_aggregate_ops, arg.match);
85 void typec_unlink_ports(struct typec_port *con)
87 if (has_acpi_companion(&con->dev))
88 component_master_del(&con->dev, &typec_aggregate_ops);