1 // SPDX-License-Identifier: GPL-2.0
3 * USB Type-C Connector Class
5 * Copyright (C) 2017, Intel Corporation
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
9 #include <linux/device.h>
10 #include <linux/module.h>
11 #include <linux/mutex.h>
12 #include <linux/property.h>
13 #include <linux/slab.h>
19 enum typec_plug_index index;
25 enum typec_plug_type type;
26 struct usb_pd_identity *identity;
27 unsigned int active:1;
30 struct typec_partner {
32 unsigned int usb_pd:1;
33 struct usb_pd_identity *identity;
34 enum typec_accessory accessory;
44 enum typec_data_role data_role;
45 enum typec_role pwr_role;
46 enum typec_role vconn_role;
47 enum typec_pwr_opmode pwr_opmode;
48 enum typec_port_type port_type;
49 struct mutex port_type_lock;
51 enum typec_orientation orientation;
52 struct typec_switch *sw;
53 struct typec_mux *mux;
55 const struct typec_capability *cap;
56 const struct typec_operations *ops;
59 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
60 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
61 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
62 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
64 static const struct device_type typec_partner_dev_type;
65 static const struct device_type typec_cable_dev_type;
66 static const struct device_type typec_plug_dev_type;
68 #define is_typec_partner(_dev_) (_dev_->type == &typec_partner_dev_type)
69 #define is_typec_cable(_dev_) (_dev_->type == &typec_cable_dev_type)
70 #define is_typec_plug(_dev_) (_dev_->type == &typec_plug_dev_type)
72 static DEFINE_IDA(typec_index_ida);
73 static struct class *typec_class;
75 /* ------------------------------------------------------------------------- */
76 /* Common attributes */
78 static const char * const typec_accessory_modes[] = {
79 [TYPEC_ACCESSORY_NONE] = "none",
80 [TYPEC_ACCESSORY_AUDIO] = "analog_audio",
81 [TYPEC_ACCESSORY_DEBUG] = "debug",
84 static struct usb_pd_identity *get_pd_identity(struct device *dev)
86 if (is_typec_partner(dev)) {
87 struct typec_partner *partner = to_typec_partner(dev);
89 return partner->identity;
90 } else if (is_typec_cable(dev)) {
91 struct typec_cable *cable = to_typec_cable(dev);
93 return cable->identity;
98 static ssize_t id_header_show(struct device *dev, struct device_attribute *attr,
101 struct usb_pd_identity *id = get_pd_identity(dev);
103 return sprintf(buf, "0x%08x\n", id->id_header);
105 static DEVICE_ATTR_RO(id_header);
107 static ssize_t cert_stat_show(struct device *dev, struct device_attribute *attr,
110 struct usb_pd_identity *id = get_pd_identity(dev);
112 return sprintf(buf, "0x%08x\n", id->cert_stat);
114 static DEVICE_ATTR_RO(cert_stat);
116 static ssize_t product_show(struct device *dev, struct device_attribute *attr,
119 struct usb_pd_identity *id = get_pd_identity(dev);
121 return sprintf(buf, "0x%08x\n", id->product);
123 static DEVICE_ATTR_RO(product);
125 static struct attribute *usb_pd_id_attrs[] = {
126 &dev_attr_id_header.attr,
127 &dev_attr_cert_stat.attr,
128 &dev_attr_product.attr,
132 static const struct attribute_group usb_pd_id_group = {
134 .attrs = usb_pd_id_attrs,
137 static const struct attribute_group *usb_pd_id_groups[] = {
142 static void typec_report_identity(struct device *dev)
144 sysfs_notify(&dev->kobj, "identity", "id_header");
145 sysfs_notify(&dev->kobj, "identity", "cert_stat");
146 sysfs_notify(&dev->kobj, "identity", "product");
149 /* ------------------------------------------------------------------------- */
150 /* Alternate Modes */
152 static int altmode_match(struct device *dev, void *data)
154 struct typec_altmode *adev = to_typec_altmode(dev);
155 struct typec_device_id *id = data;
157 if (!is_typec_altmode(dev))
160 return ((adev->svid == id->svid) && (adev->mode == id->mode));
163 static void typec_altmode_set_partner(struct altmode *altmode)
165 struct typec_altmode *adev = &altmode->adev;
166 struct typec_device_id id = { adev->svid, adev->mode, };
167 struct typec_port *port = typec_altmode2port(adev);
168 struct altmode *partner;
171 dev = device_find_child(&port->dev, &id, altmode_match);
175 /* Bind the port alt mode to the partner/plug alt mode. */
176 partner = to_altmode(to_typec_altmode(dev));
177 altmode->partner = partner;
179 /* Bind the partner/plug alt mode to the port alt mode. */
180 if (is_typec_plug(adev->dev.parent)) {
181 struct typec_plug *plug = to_typec_plug(adev->dev.parent);
183 partner->plug[plug->index] = altmode;
185 partner->partner = altmode;
189 static void typec_altmode_put_partner(struct altmode *altmode)
191 struct altmode *partner = altmode->partner;
192 struct typec_altmode *adev;
193 struct typec_altmode *partner_adev;
198 adev = &altmode->adev;
199 partner_adev = &partner->adev;
201 if (is_typec_plug(adev->dev.parent)) {
202 struct typec_plug *plug = to_typec_plug(adev->dev.parent);
204 partner->plug[plug->index] = NULL;
206 partner->partner = NULL;
208 put_device(&partner_adev->dev);
212 * typec_altmode_update_active - Report Enter/Exit mode
213 * @adev: Handle to the alternate mode
214 * @active: True when the mode has been entered
216 * If a partner or cable plug executes Enter/Exit Mode command successfully, the
217 * drivers use this routine to report the updated state of the mode.
219 void typec_altmode_update_active(struct typec_altmode *adev, bool active)
223 if (adev->active == active)
226 if (!is_typec_port(adev->dev.parent) && adev->dev.driver) {
228 module_put(adev->dev.driver->owner);
230 WARN_ON(!try_module_get(adev->dev.driver->owner));
233 adev->active = active;
234 snprintf(dir, sizeof(dir), "mode%d", adev->mode);
235 sysfs_notify(&adev->dev.kobj, dir, "active");
236 sysfs_notify(&adev->dev.kobj, NULL, "active");
237 kobject_uevent(&adev->dev.kobj, KOBJ_CHANGE);
239 EXPORT_SYMBOL_GPL(typec_altmode_update_active);
242 * typec_altmode2port - Alternate Mode to USB Type-C port
243 * @alt: The Alternate Mode
245 * Returns handle to the port that a cable plug or partner with @alt is
248 struct typec_port *typec_altmode2port(struct typec_altmode *alt)
250 if (is_typec_plug(alt->dev.parent))
251 return to_typec_port(alt->dev.parent->parent->parent);
252 if (is_typec_partner(alt->dev.parent))
253 return to_typec_port(alt->dev.parent->parent);
254 if (is_typec_port(alt->dev.parent))
255 return to_typec_port(alt->dev.parent);
259 EXPORT_SYMBOL_GPL(typec_altmode2port);
262 vdo_show(struct device *dev, struct device_attribute *attr, char *buf)
264 struct typec_altmode *alt = to_typec_altmode(dev);
266 return sprintf(buf, "0x%08x\n", alt->vdo);
268 static DEVICE_ATTR_RO(vdo);
271 description_show(struct device *dev, struct device_attribute *attr, char *buf)
273 struct typec_altmode *alt = to_typec_altmode(dev);
275 return sprintf(buf, "%s\n", alt->desc ? alt->desc : "");
277 static DEVICE_ATTR_RO(description);
280 active_show(struct device *dev, struct device_attribute *attr, char *buf)
282 struct typec_altmode *alt = to_typec_altmode(dev);
284 return sprintf(buf, "%s\n", alt->active ? "yes" : "no");
287 static ssize_t active_store(struct device *dev, struct device_attribute *attr,
288 const char *buf, size_t size)
290 struct typec_altmode *adev = to_typec_altmode(dev);
291 struct altmode *altmode = to_altmode(adev);
295 ret = kstrtobool(buf, &enter);
299 if (adev->active == enter)
302 if (is_typec_port(adev->dev.parent)) {
303 typec_altmode_update_active(adev, enter);
305 /* Make sure that the partner exits the mode before disabling */
306 if (altmode->partner && !enter && altmode->partner->adev.active)
307 typec_altmode_exit(&altmode->partner->adev);
308 } else if (altmode->partner) {
309 if (enter && !altmode->partner->adev.active) {
310 dev_warn(dev, "port has the mode disabled\n");
315 /* Note: If there is no driver, the mode will not be entered */
316 if (adev->ops && adev->ops->activate) {
317 ret = adev->ops->activate(adev, enter);
324 static DEVICE_ATTR_RW(active);
327 supported_roles_show(struct device *dev, struct device_attribute *attr,
330 struct altmode *alt = to_altmode(to_typec_altmode(dev));
333 switch (alt->roles) {
335 ret = sprintf(buf, "source\n");
338 ret = sprintf(buf, "sink\n");
342 ret = sprintf(buf, "source sink\n");
347 static DEVICE_ATTR_RO(supported_roles);
350 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
352 struct typec_altmode *adev = to_typec_altmode(dev);
354 return sprintf(buf, "%u\n", adev->mode);
356 static DEVICE_ATTR_RO(mode);
359 svid_show(struct device *dev, struct device_attribute *attr, char *buf)
361 struct typec_altmode *adev = to_typec_altmode(dev);
363 return sprintf(buf, "%04x\n", adev->svid);
365 static DEVICE_ATTR_RO(svid);
367 static struct attribute *typec_altmode_attrs[] = {
368 &dev_attr_active.attr,
375 static umode_t typec_altmode_attr_is_visible(struct kobject *kobj,
376 struct attribute *attr, int n)
378 struct typec_altmode *adev = to_typec_altmode(kobj_to_dev(kobj));
380 if (attr == &dev_attr_active.attr)
381 if (!adev->ops || !adev->ops->activate)
387 static struct attribute_group typec_altmode_group = {
388 .is_visible = typec_altmode_attr_is_visible,
389 .attrs = typec_altmode_attrs,
392 static const struct attribute_group *typec_altmode_groups[] = {
393 &typec_altmode_group,
397 static int altmode_id_get(struct device *dev)
401 if (is_typec_partner(dev))
402 ids = &to_typec_partner(dev)->mode_ids;
403 else if (is_typec_plug(dev))
404 ids = &to_typec_plug(dev)->mode_ids;
406 ids = &to_typec_port(dev)->mode_ids;
408 return ida_simple_get(ids, 0, 0, GFP_KERNEL);
411 static void altmode_id_remove(struct device *dev, int id)
415 if (is_typec_partner(dev))
416 ids = &to_typec_partner(dev)->mode_ids;
417 else if (is_typec_plug(dev))
418 ids = &to_typec_plug(dev)->mode_ids;
420 ids = &to_typec_port(dev)->mode_ids;
422 ida_simple_remove(ids, id);
425 static void typec_altmode_release(struct device *dev)
427 struct altmode *alt = to_altmode(to_typec_altmode(dev));
429 if (!is_typec_port(dev->parent))
430 typec_altmode_put_partner(alt);
432 altmode_id_remove(alt->adev.dev.parent, alt->id);
436 const struct device_type typec_altmode_dev_type = {
437 .name = "typec_alternate_mode",
438 .groups = typec_altmode_groups,
439 .release = typec_altmode_release,
442 static struct typec_altmode *
443 typec_register_altmode(struct device *parent,
444 const struct typec_altmode_desc *desc)
446 unsigned int id = altmode_id_get(parent);
447 bool is_port = is_typec_port(parent);
451 alt = kzalloc(sizeof(*alt), GFP_KERNEL);
453 altmode_id_remove(parent, id);
454 return ERR_PTR(-ENOMEM);
457 alt->adev.svid = desc->svid;
458 alt->adev.mode = desc->mode;
459 alt->adev.vdo = desc->vdo;
460 alt->roles = desc->roles;
463 alt->attrs[0] = &dev_attr_vdo.attr;
464 alt->attrs[1] = &dev_attr_description.attr;
465 alt->attrs[2] = &dev_attr_active.attr;
468 alt->attrs[3] = &dev_attr_supported_roles.attr;
469 alt->adev.active = true; /* Enabled by default */
472 sprintf(alt->group_name, "mode%d", desc->mode);
473 alt->group.name = alt->group_name;
474 alt->group.attrs = alt->attrs;
475 alt->groups[0] = &alt->group;
477 alt->adev.dev.parent = parent;
478 alt->adev.dev.groups = alt->groups;
479 alt->adev.dev.type = &typec_altmode_dev_type;
480 dev_set_name(&alt->adev.dev, "%s.%u", dev_name(parent), id);
482 /* Link partners and plugs with the ports */
484 typec_altmode_set_partner(alt);
486 /* The partners are bind to drivers */
487 if (is_typec_partner(parent))
488 alt->adev.dev.bus = &typec_bus;
490 ret = device_register(&alt->adev.dev);
492 dev_err(parent, "failed to register alternate mode (%d)\n",
494 put_device(&alt->adev.dev);
502 * typec_unregister_altmode - Unregister Alternate Mode
503 * @adev: The alternate mode to be unregistered
505 * Unregister device created with typec_partner_register_altmode(),
506 * typec_plug_register_altmode() or typec_port_register_altmode().
508 void typec_unregister_altmode(struct typec_altmode *adev)
510 if (IS_ERR_OR_NULL(adev))
512 typec_mux_put(to_altmode(adev)->mux);
513 device_unregister(&adev->dev);
515 EXPORT_SYMBOL_GPL(typec_unregister_altmode);
517 /* ------------------------------------------------------------------------- */
518 /* Type-C Partners */
520 static ssize_t accessory_mode_show(struct device *dev,
521 struct device_attribute *attr,
524 struct typec_partner *p = to_typec_partner(dev);
526 return sprintf(buf, "%s\n", typec_accessory_modes[p->accessory]);
528 static DEVICE_ATTR_RO(accessory_mode);
530 static ssize_t supports_usb_power_delivery_show(struct device *dev,
531 struct device_attribute *attr,
534 struct typec_partner *p = to_typec_partner(dev);
536 return sprintf(buf, "%s\n", p->usb_pd ? "yes" : "no");
538 static DEVICE_ATTR_RO(supports_usb_power_delivery);
540 static struct attribute *typec_partner_attrs[] = {
541 &dev_attr_accessory_mode.attr,
542 &dev_attr_supports_usb_power_delivery.attr,
545 ATTRIBUTE_GROUPS(typec_partner);
547 static void typec_partner_release(struct device *dev)
549 struct typec_partner *partner = to_typec_partner(dev);
551 ida_destroy(&partner->mode_ids);
555 static const struct device_type typec_partner_dev_type = {
556 .name = "typec_partner",
557 .groups = typec_partner_groups,
558 .release = typec_partner_release,
562 * typec_partner_set_identity - Report result from Discover Identity command
563 * @partner: The partner updated identity values
565 * This routine is used to report that the result of Discover Identity USB power
566 * delivery command has become available.
568 int typec_partner_set_identity(struct typec_partner *partner)
570 if (!partner->identity)
573 typec_report_identity(&partner->dev);
576 EXPORT_SYMBOL_GPL(typec_partner_set_identity);
579 * typec_partner_register_altmode - Register USB Type-C Partner Alternate Mode
580 * @partner: USB Type-C Partner that supports the alternate mode
581 * @desc: Description of the alternate mode
583 * This routine is used to register each alternate mode individually that
584 * @partner has listed in response to Discover SVIDs command. The modes for a
585 * SVID listed in response to Discover Modes command need to be listed in an
588 * Returns handle to the alternate mode on success or ERR_PTR on failure.
590 struct typec_altmode *
591 typec_partner_register_altmode(struct typec_partner *partner,
592 const struct typec_altmode_desc *desc)
594 return typec_register_altmode(&partner->dev, desc);
596 EXPORT_SYMBOL_GPL(typec_partner_register_altmode);
599 * typec_register_partner - Register a USB Type-C Partner
600 * @port: The USB Type-C Port the partner is connected to
601 * @desc: Description of the partner
603 * Registers a device for USB Type-C Partner described in @desc.
605 * Returns handle to the partner on success or ERR_PTR on failure.
607 struct typec_partner *typec_register_partner(struct typec_port *port,
608 struct typec_partner_desc *desc)
610 struct typec_partner *partner;
613 partner = kzalloc(sizeof(*partner), GFP_KERNEL);
615 return ERR_PTR(-ENOMEM);
617 ida_init(&partner->mode_ids);
618 partner->usb_pd = desc->usb_pd;
619 partner->accessory = desc->accessory;
621 if (desc->identity) {
623 * Creating directory for the identity only if the driver is
624 * able to provide data to it.
626 partner->dev.groups = usb_pd_id_groups;
627 partner->identity = desc->identity;
630 partner->dev.class = typec_class;
631 partner->dev.parent = &port->dev;
632 partner->dev.type = &typec_partner_dev_type;
633 dev_set_name(&partner->dev, "%s-partner", dev_name(&port->dev));
635 ret = device_register(&partner->dev);
637 dev_err(&port->dev, "failed to register partner (%d)\n", ret);
638 put_device(&partner->dev);
644 EXPORT_SYMBOL_GPL(typec_register_partner);
647 * typec_unregister_partner - Unregister a USB Type-C Partner
648 * @partner: The partner to be unregistered
650 * Unregister device created with typec_register_partner().
652 void typec_unregister_partner(struct typec_partner *partner)
654 if (!IS_ERR_OR_NULL(partner))
655 device_unregister(&partner->dev);
657 EXPORT_SYMBOL_GPL(typec_unregister_partner);
659 /* ------------------------------------------------------------------------- */
660 /* Type-C Cable Plugs */
662 static void typec_plug_release(struct device *dev)
664 struct typec_plug *plug = to_typec_plug(dev);
666 ida_destroy(&plug->mode_ids);
670 static const struct device_type typec_plug_dev_type = {
671 .name = "typec_plug",
672 .release = typec_plug_release,
676 * typec_plug_register_altmode - Register USB Type-C Cable Plug Alternate Mode
677 * @plug: USB Type-C Cable Plug that supports the alternate mode
678 * @desc: Description of the alternate mode
680 * This routine is used to register each alternate mode individually that @plug
681 * has listed in response to Discover SVIDs command. The modes for a SVID that
682 * the plug lists in response to Discover Modes command need to be listed in an
685 * Returns handle to the alternate mode on success or ERR_PTR on failure.
687 struct typec_altmode *
688 typec_plug_register_altmode(struct typec_plug *plug,
689 const struct typec_altmode_desc *desc)
691 return typec_register_altmode(&plug->dev, desc);
693 EXPORT_SYMBOL_GPL(typec_plug_register_altmode);
696 * typec_register_plug - Register a USB Type-C Cable Plug
697 * @cable: USB Type-C Cable with the plug
698 * @desc: Description of the cable plug
700 * Registers a device for USB Type-C Cable Plug described in @desc. A USB Type-C
701 * Cable Plug represents a plug with electronics in it that can response to USB
702 * Power Delivery SOP Prime or SOP Double Prime packages.
704 * Returns handle to the cable plug on success or ERR_PTR on failure.
706 struct typec_plug *typec_register_plug(struct typec_cable *cable,
707 struct typec_plug_desc *desc)
709 struct typec_plug *plug;
713 plug = kzalloc(sizeof(*plug), GFP_KERNEL);
715 return ERR_PTR(-ENOMEM);
717 sprintf(name, "plug%d", desc->index);
719 ida_init(&plug->mode_ids);
720 plug->index = desc->index;
721 plug->dev.class = typec_class;
722 plug->dev.parent = &cable->dev;
723 plug->dev.type = &typec_plug_dev_type;
724 dev_set_name(&plug->dev, "%s-%s", dev_name(cable->dev.parent), name);
726 ret = device_register(&plug->dev);
728 dev_err(&cable->dev, "failed to register plug (%d)\n", ret);
729 put_device(&plug->dev);
735 EXPORT_SYMBOL_GPL(typec_register_plug);
738 * typec_unregister_plug - Unregister a USB Type-C Cable Plug
739 * @plug: The cable plug to be unregistered
741 * Unregister device created with typec_register_plug().
743 void typec_unregister_plug(struct typec_plug *plug)
745 if (!IS_ERR_OR_NULL(plug))
746 device_unregister(&plug->dev);
748 EXPORT_SYMBOL_GPL(typec_unregister_plug);
753 type_show(struct device *dev, struct device_attribute *attr, char *buf)
755 struct typec_cable *cable = to_typec_cable(dev);
757 return sprintf(buf, "%s\n", cable->active ? "active" : "passive");
759 static DEVICE_ATTR_RO(type);
761 static const char * const typec_plug_types[] = {
762 [USB_PLUG_NONE] = "unknown",
763 [USB_PLUG_TYPE_A] = "type-a",
764 [USB_PLUG_TYPE_B] = "type-b",
765 [USB_PLUG_TYPE_C] = "type-c",
766 [USB_PLUG_CAPTIVE] = "captive",
769 static ssize_t plug_type_show(struct device *dev,
770 struct device_attribute *attr, char *buf)
772 struct typec_cable *cable = to_typec_cable(dev);
774 return sprintf(buf, "%s\n", typec_plug_types[cable->type]);
776 static DEVICE_ATTR_RO(plug_type);
778 static struct attribute *typec_cable_attrs[] = {
780 &dev_attr_plug_type.attr,
783 ATTRIBUTE_GROUPS(typec_cable);
785 static void typec_cable_release(struct device *dev)
787 struct typec_cable *cable = to_typec_cable(dev);
792 static const struct device_type typec_cable_dev_type = {
793 .name = "typec_cable",
794 .groups = typec_cable_groups,
795 .release = typec_cable_release,
798 static int cable_match(struct device *dev, void *data)
800 return is_typec_cable(dev);
804 * typec_cable_get - Get a reference to the USB Type-C cable
805 * @port: The USB Type-C Port the cable is connected to
807 * The caller must decrement the reference count with typec_cable_put() after
810 struct typec_cable *typec_cable_get(struct typec_port *port)
814 dev = device_find_child(&port->dev, NULL, cable_match);
818 return to_typec_cable(dev);
820 EXPORT_SYMBOL_GPL(typec_cable_get);
823 * typec_cable_put - Decrement the reference count on USB Type-C cable
824 * @cable: The USB Type-C cable
826 void typec_cable_put(struct typec_cable *cable)
828 put_device(&cable->dev);
830 EXPORT_SYMBOL_GPL(typec_cable_put);
833 * typec_cable_is_active - Check is the USB Type-C cable active or passive
834 * @cable: The USB Type-C Cable
836 * Return 1 if the cable is active or 0 if it's passive.
838 int typec_cable_is_active(struct typec_cable *cable)
840 return cable->active;
842 EXPORT_SYMBOL_GPL(typec_cable_is_active);
845 * typec_cable_set_identity - Report result from Discover Identity command
846 * @cable: The cable updated identity values
848 * This routine is used to report that the result of Discover Identity USB power
849 * delivery command has become available.
851 int typec_cable_set_identity(struct typec_cable *cable)
853 if (!cable->identity)
856 typec_report_identity(&cable->dev);
859 EXPORT_SYMBOL_GPL(typec_cable_set_identity);
862 * typec_register_cable - Register a USB Type-C Cable
863 * @port: The USB Type-C Port the cable is connected to
864 * @desc: Description of the cable
866 * Registers a device for USB Type-C Cable described in @desc. The cable will be
867 * parent for the optional cable plug devises.
869 * Returns handle to the cable on success or ERR_PTR on failure.
871 struct typec_cable *typec_register_cable(struct typec_port *port,
872 struct typec_cable_desc *desc)
874 struct typec_cable *cable;
877 cable = kzalloc(sizeof(*cable), GFP_KERNEL);
879 return ERR_PTR(-ENOMEM);
881 cable->type = desc->type;
882 cable->active = desc->active;
884 if (desc->identity) {
886 * Creating directory for the identity only if the driver is
887 * able to provide data to it.
889 cable->dev.groups = usb_pd_id_groups;
890 cable->identity = desc->identity;
893 cable->dev.class = typec_class;
894 cable->dev.parent = &port->dev;
895 cable->dev.type = &typec_cable_dev_type;
896 dev_set_name(&cable->dev, "%s-cable", dev_name(&port->dev));
898 ret = device_register(&cable->dev);
900 dev_err(&port->dev, "failed to register cable (%d)\n", ret);
901 put_device(&cable->dev);
907 EXPORT_SYMBOL_GPL(typec_register_cable);
910 * typec_unregister_cable - Unregister a USB Type-C Cable
911 * @cable: The cable to be unregistered
913 * Unregister device created with typec_register_cable().
915 void typec_unregister_cable(struct typec_cable *cable)
917 if (!IS_ERR_OR_NULL(cable))
918 device_unregister(&cable->dev);
920 EXPORT_SYMBOL_GPL(typec_unregister_cable);
922 /* ------------------------------------------------------------------------- */
923 /* USB Type-C ports */
925 static const char * const typec_orientations[] = {
926 [TYPEC_ORIENTATION_NONE] = "unknown",
927 [TYPEC_ORIENTATION_NORMAL] = "normal",
928 [TYPEC_ORIENTATION_REVERSE] = "reverse",
931 static const char * const typec_roles[] = {
932 [TYPEC_SINK] = "sink",
933 [TYPEC_SOURCE] = "source",
936 static const char * const typec_data_roles[] = {
937 [TYPEC_DEVICE] = "device",
938 [TYPEC_HOST] = "host",
941 static const char * const typec_port_power_roles[] = {
942 [TYPEC_PORT_SRC] = "source",
943 [TYPEC_PORT_SNK] = "sink",
944 [TYPEC_PORT_DRP] = "dual",
947 static const char * const typec_port_data_roles[] = {
948 [TYPEC_PORT_DFP] = "host",
949 [TYPEC_PORT_UFP] = "device",
950 [TYPEC_PORT_DRD] = "dual",
953 static const char * const typec_port_types_drp[] = {
954 [TYPEC_PORT_SRC] = "dual [source] sink",
955 [TYPEC_PORT_SNK] = "dual source [sink]",
956 [TYPEC_PORT_DRP] = "[dual] source sink",
960 preferred_role_store(struct device *dev, struct device_attribute *attr,
961 const char *buf, size_t size)
963 struct typec_port *port = to_typec_port(dev);
967 if (port->cap->type != TYPEC_PORT_DRP) {
968 dev_dbg(dev, "Preferred role only supported with DRP ports\n");
972 if (!port->ops || !port->ops->try_role) {
973 dev_dbg(dev, "Setting preferred role not supported\n");
977 role = sysfs_match_string(typec_roles, buf);
979 if (sysfs_streq(buf, "none"))
980 role = TYPEC_NO_PREFERRED_ROLE;
985 ret = port->ops->try_role(port, role);
989 port->prefer_role = role;
994 preferred_role_show(struct device *dev, struct device_attribute *attr,
997 struct typec_port *port = to_typec_port(dev);
999 if (port->cap->type != TYPEC_PORT_DRP)
1002 if (port->prefer_role < 0)
1005 return sprintf(buf, "%s\n", typec_roles[port->prefer_role]);
1007 static DEVICE_ATTR_RW(preferred_role);
1009 static ssize_t data_role_store(struct device *dev,
1010 struct device_attribute *attr,
1011 const char *buf, size_t size)
1013 struct typec_port *port = to_typec_port(dev);
1016 if (!port->ops || !port->ops->dr_set) {
1017 dev_dbg(dev, "data role swapping not supported\n");
1021 ret = sysfs_match_string(typec_data_roles, buf);
1025 mutex_lock(&port->port_type_lock);
1026 if (port->cap->data != TYPEC_PORT_DRD) {
1028 goto unlock_and_ret;
1031 ret = port->ops->dr_set(port, ret);
1033 goto unlock_and_ret;
1037 mutex_unlock(&port->port_type_lock);
1041 static ssize_t data_role_show(struct device *dev,
1042 struct device_attribute *attr, char *buf)
1044 struct typec_port *port = to_typec_port(dev);
1046 if (port->cap->data == TYPEC_PORT_DRD)
1047 return sprintf(buf, "%s\n", port->data_role == TYPEC_HOST ?
1048 "[host] device" : "host [device]");
1050 return sprintf(buf, "[%s]\n", typec_data_roles[port->data_role]);
1052 static DEVICE_ATTR_RW(data_role);
1054 static ssize_t power_role_store(struct device *dev,
1055 struct device_attribute *attr,
1056 const char *buf, size_t size)
1058 struct typec_port *port = to_typec_port(dev);
1061 if (!port->ops || !port->ops->pr_set) {
1062 dev_dbg(dev, "power role swapping not supported\n");
1066 if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
1067 dev_dbg(dev, "partner unable to swap power role\n");
1071 ret = sysfs_match_string(typec_roles, buf);
1075 mutex_lock(&port->port_type_lock);
1076 if (port->port_type != TYPEC_PORT_DRP) {
1077 dev_dbg(dev, "port type fixed at \"%s\"",
1078 typec_port_power_roles[port->port_type]);
1080 goto unlock_and_ret;
1083 ret = port->ops->pr_set(port, ret);
1085 goto unlock_and_ret;
1089 mutex_unlock(&port->port_type_lock);
1093 static ssize_t power_role_show(struct device *dev,
1094 struct device_attribute *attr, char *buf)
1096 struct typec_port *port = to_typec_port(dev);
1098 if (port->cap->type == TYPEC_PORT_DRP)
1099 return sprintf(buf, "%s\n", port->pwr_role == TYPEC_SOURCE ?
1100 "[source] sink" : "source [sink]");
1102 return sprintf(buf, "[%s]\n", typec_roles[port->pwr_role]);
1104 static DEVICE_ATTR_RW(power_role);
1107 port_type_store(struct device *dev, struct device_attribute *attr,
1108 const char *buf, size_t size)
1110 struct typec_port *port = to_typec_port(dev);
1112 enum typec_port_type type;
1114 if (port->cap->type != TYPEC_PORT_DRP ||
1115 !port->ops || !port->ops->port_type_set) {
1116 dev_dbg(dev, "changing port type not supported\n");
1120 ret = sysfs_match_string(typec_port_power_roles, buf);
1125 mutex_lock(&port->port_type_lock);
1127 if (port->port_type == type) {
1129 goto unlock_and_ret;
1132 ret = port->ops->port_type_set(port, type);
1134 goto unlock_and_ret;
1136 port->port_type = type;
1140 mutex_unlock(&port->port_type_lock);
1145 port_type_show(struct device *dev, struct device_attribute *attr,
1148 struct typec_port *port = to_typec_port(dev);
1150 if (port->cap->type == TYPEC_PORT_DRP)
1151 return sprintf(buf, "%s\n",
1152 typec_port_types_drp[port->port_type]);
1154 return sprintf(buf, "[%s]\n", typec_port_power_roles[port->cap->type]);
1156 static DEVICE_ATTR_RW(port_type);
1158 static const char * const typec_pwr_opmodes[] = {
1159 [TYPEC_PWR_MODE_USB] = "default",
1160 [TYPEC_PWR_MODE_1_5A] = "1.5A",
1161 [TYPEC_PWR_MODE_3_0A] = "3.0A",
1162 [TYPEC_PWR_MODE_PD] = "usb_power_delivery",
1165 static ssize_t power_operation_mode_show(struct device *dev,
1166 struct device_attribute *attr,
1169 struct typec_port *port = to_typec_port(dev);
1171 return sprintf(buf, "%s\n", typec_pwr_opmodes[port->pwr_opmode]);
1173 static DEVICE_ATTR_RO(power_operation_mode);
1175 static ssize_t vconn_source_store(struct device *dev,
1176 struct device_attribute *attr,
1177 const char *buf, size_t size)
1179 struct typec_port *port = to_typec_port(dev);
1183 if (!port->cap->pd_revision) {
1184 dev_dbg(dev, "VCONN swap depends on USB Power Delivery\n");
1188 if (!port->ops || !port->ops->vconn_set) {
1189 dev_dbg(dev, "VCONN swapping not supported\n");
1193 ret = kstrtobool(buf, &source);
1197 ret = port->ops->vconn_set(port, (enum typec_role)source);
1204 static ssize_t vconn_source_show(struct device *dev,
1205 struct device_attribute *attr, char *buf)
1207 struct typec_port *port = to_typec_port(dev);
1209 return sprintf(buf, "%s\n",
1210 port->vconn_role == TYPEC_SOURCE ? "yes" : "no");
1212 static DEVICE_ATTR_RW(vconn_source);
1214 static ssize_t supported_accessory_modes_show(struct device *dev,
1215 struct device_attribute *attr,
1218 struct typec_port *port = to_typec_port(dev);
1222 for (i = 0; i < ARRAY_SIZE(port->cap->accessory); i++) {
1223 if (port->cap->accessory[i])
1224 ret += sprintf(buf + ret, "%s ",
1225 typec_accessory_modes[port->cap->accessory[i]]);
1229 return sprintf(buf, "none\n");
1231 buf[ret - 1] = '\n';
1235 static DEVICE_ATTR_RO(supported_accessory_modes);
1237 static ssize_t usb_typec_revision_show(struct device *dev,
1238 struct device_attribute *attr,
1241 struct typec_port *port = to_typec_port(dev);
1242 u16 rev = port->cap->revision;
1244 return sprintf(buf, "%d.%d\n", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
1246 static DEVICE_ATTR_RO(usb_typec_revision);
1248 static ssize_t usb_power_delivery_revision_show(struct device *dev,
1249 struct device_attribute *attr,
1252 struct typec_port *p = to_typec_port(dev);
1254 return sprintf(buf, "%d\n", (p->cap->pd_revision >> 8) & 0xff);
1256 static DEVICE_ATTR_RO(usb_power_delivery_revision);
1258 static ssize_t orientation_show(struct device *dev,
1259 struct device_attribute *attr,
1262 struct typec_port *port = to_typec_port(dev);
1264 return sprintf(buf, "%s\n", typec_orientations[port->orientation]);
1266 static DEVICE_ATTR_RO(orientation);
1268 static struct attribute *typec_attrs[] = {
1269 &dev_attr_data_role.attr,
1270 &dev_attr_power_operation_mode.attr,
1271 &dev_attr_power_role.attr,
1272 &dev_attr_preferred_role.attr,
1273 &dev_attr_supported_accessory_modes.attr,
1274 &dev_attr_usb_power_delivery_revision.attr,
1275 &dev_attr_usb_typec_revision.attr,
1276 &dev_attr_vconn_source.attr,
1277 &dev_attr_port_type.attr,
1278 &dev_attr_orientation.attr,
1282 static umode_t typec_attr_is_visible(struct kobject *kobj,
1283 struct attribute *attr, int n)
1285 struct typec_port *port = to_typec_port(kobj_to_dev(kobj));
1287 if (attr == &dev_attr_data_role.attr) {
1288 if (port->cap->data != TYPEC_PORT_DRD ||
1289 !port->ops || !port->ops->dr_set)
1291 } else if (attr == &dev_attr_power_role.attr) {
1292 if (port->cap->type != TYPEC_PORT_DRP ||
1293 !port->ops || !port->ops->pr_set)
1295 } else if (attr == &dev_attr_vconn_source.attr) {
1296 if (!port->cap->pd_revision ||
1297 !port->ops || !port->ops->vconn_set)
1299 } else if (attr == &dev_attr_preferred_role.attr) {
1300 if (port->cap->type != TYPEC_PORT_DRP ||
1301 !port->ops || !port->ops->try_role)
1303 } else if (attr == &dev_attr_port_type.attr) {
1304 if (!port->ops || !port->ops->port_type_set)
1306 if (port->cap->type != TYPEC_PORT_DRP)
1308 } else if (attr == &dev_attr_orientation.attr) {
1309 if (port->cap->orientation_aware)
1317 static struct attribute_group typec_group = {
1318 .is_visible = typec_attr_is_visible,
1319 .attrs = typec_attrs,
1322 static const struct attribute_group *typec_groups[] = {
1327 static int typec_uevent(struct device *dev, struct kobj_uevent_env *env)
1331 ret = add_uevent_var(env, "TYPEC_PORT=%s", dev_name(dev));
1333 dev_err(dev, "failed to add uevent TYPEC_PORT\n");
1338 static void typec_release(struct device *dev)
1340 struct typec_port *port = to_typec_port(dev);
1342 ida_simple_remove(&typec_index_ida, port->id);
1343 ida_destroy(&port->mode_ids);
1344 typec_switch_put(port->sw);
1345 typec_mux_put(port->mux);
1350 const struct device_type typec_port_dev_type = {
1351 .name = "typec_port",
1352 .groups = typec_groups,
1353 .uevent = typec_uevent,
1354 .release = typec_release,
1357 /* --------------------------------------- */
1358 /* Driver callbacks to report role updates */
1361 * typec_set_data_role - Report data role change
1362 * @port: The USB Type-C Port where the role was changed
1363 * @role: The new data role
1365 * This routine is used by the port drivers to report data role changes.
1367 void typec_set_data_role(struct typec_port *port, enum typec_data_role role)
1369 if (port->data_role == role)
1372 port->data_role = role;
1373 sysfs_notify(&port->dev.kobj, NULL, "data_role");
1374 kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
1376 EXPORT_SYMBOL_GPL(typec_set_data_role);
1379 * typec_set_pwr_role - Report power role change
1380 * @port: The USB Type-C Port where the role was changed
1381 * @role: The new data role
1383 * This routine is used by the port drivers to report power role changes.
1385 void typec_set_pwr_role(struct typec_port *port, enum typec_role role)
1387 if (port->pwr_role == role)
1390 port->pwr_role = role;
1391 sysfs_notify(&port->dev.kobj, NULL, "power_role");
1392 kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
1394 EXPORT_SYMBOL_GPL(typec_set_pwr_role);
1397 * typec_set_vconn_role - Report VCONN source change
1398 * @port: The USB Type-C Port which VCONN role changed
1399 * @role: Source when @port is sourcing VCONN, or Sink when it's not
1401 * This routine is used by the port drivers to report if the VCONN source is
1404 void typec_set_vconn_role(struct typec_port *port, enum typec_role role)
1406 if (port->vconn_role == role)
1409 port->vconn_role = role;
1410 sysfs_notify(&port->dev.kobj, NULL, "vconn_source");
1411 kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
1413 EXPORT_SYMBOL_GPL(typec_set_vconn_role);
1415 static int partner_match(struct device *dev, void *data)
1417 return is_typec_partner(dev);
1421 * typec_set_pwr_opmode - Report changed power operation mode
1422 * @port: The USB Type-C Port where the mode was changed
1423 * @opmode: New power operation mode
1425 * This routine is used by the port drivers to report changed power operation
1426 * mode in @port. The modes are USB (default), 1.5A, 3.0A as defined in USB
1427 * Type-C specification, and "USB Power Delivery" when the power levels are
1428 * negotiated with methods defined in USB Power Delivery specification.
1430 void typec_set_pwr_opmode(struct typec_port *port,
1431 enum typec_pwr_opmode opmode)
1433 struct device *partner_dev;
1435 if (port->pwr_opmode == opmode)
1438 port->pwr_opmode = opmode;
1439 sysfs_notify(&port->dev.kobj, NULL, "power_operation_mode");
1440 kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
1442 partner_dev = device_find_child(&port->dev, NULL, partner_match);
1444 struct typec_partner *partner = to_typec_partner(partner_dev);
1446 if (opmode == TYPEC_PWR_MODE_PD && !partner->usb_pd) {
1447 partner->usb_pd = 1;
1448 sysfs_notify(&partner_dev->kobj, NULL,
1449 "supports_usb_power_delivery");
1450 kobject_uevent(&partner_dev->kobj, KOBJ_CHANGE);
1452 put_device(partner_dev);
1455 EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
1458 * typec_find_pwr_opmode - Get the typec power operation mode capability
1459 * @name: power operation mode string
1461 * This routine is used to find the typec_pwr_opmode by its string @name.
1463 * Returns typec_pwr_opmode if success, otherwise negative error code.
1465 int typec_find_pwr_opmode(const char *name)
1467 return match_string(typec_pwr_opmodes,
1468 ARRAY_SIZE(typec_pwr_opmodes), name);
1470 EXPORT_SYMBOL_GPL(typec_find_pwr_opmode);
1473 * typec_find_orientation - Convert orientation string to enum typec_orientation
1474 * @name: Orientation string
1476 * This routine is used to find the typec_orientation by its string name @name.
1478 * Returns the orientation value on success, otherwise negative error code.
1480 int typec_find_orientation(const char *name)
1482 return match_string(typec_orientations, ARRAY_SIZE(typec_orientations),
1485 EXPORT_SYMBOL_GPL(typec_find_orientation);
1488 * typec_find_port_power_role - Get the typec port power capability
1489 * @name: port power capability string
1491 * This routine is used to find the typec_port_type by its string name.
1493 * Returns typec_port_type if success, otherwise negative error code.
1495 int typec_find_port_power_role(const char *name)
1497 return match_string(typec_port_power_roles,
1498 ARRAY_SIZE(typec_port_power_roles), name);
1500 EXPORT_SYMBOL_GPL(typec_find_port_power_role);
1503 * typec_find_power_role - Find the typec one specific power role
1504 * @name: power role string
1506 * This routine is used to find the typec_role by its string name.
1508 * Returns typec_role if success, otherwise negative error code.
1510 int typec_find_power_role(const char *name)
1512 return match_string(typec_roles, ARRAY_SIZE(typec_roles), name);
1514 EXPORT_SYMBOL_GPL(typec_find_power_role);
1517 * typec_find_port_data_role - Get the typec port data capability
1518 * @name: port data capability string
1520 * This routine is used to find the typec_port_data by its string name.
1522 * Returns typec_port_data if success, otherwise negative error code.
1524 int typec_find_port_data_role(const char *name)
1526 return match_string(typec_port_data_roles,
1527 ARRAY_SIZE(typec_port_data_roles), name);
1529 EXPORT_SYMBOL_GPL(typec_find_port_data_role);
1531 /* ------------------------------------------ */
1532 /* API for Multiplexer/DeMultiplexer Switches */
1535 * typec_set_orientation - Set USB Type-C cable plug orientation
1536 * @port: USB Type-C Port
1537 * @orientation: USB Type-C cable plug orientation
1539 * Set cable plug orientation for @port.
1541 int typec_set_orientation(struct typec_port *port,
1542 enum typec_orientation orientation)
1546 ret = typec_switch_set(port->sw, orientation);
1550 port->orientation = orientation;
1551 sysfs_notify(&port->dev.kobj, NULL, "orientation");
1552 kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
1556 EXPORT_SYMBOL_GPL(typec_set_orientation);
1559 * typec_get_orientation - Get USB Type-C cable plug orientation
1560 * @port: USB Type-C Port
1562 * Get current cable plug orientation for @port.
1564 enum typec_orientation typec_get_orientation(struct typec_port *port)
1566 return port->orientation;
1568 EXPORT_SYMBOL_GPL(typec_get_orientation);
1571 * typec_set_mode - Set mode of operation for USB Type-C connector
1572 * @port: USB Type-C connector
1573 * @mode: Accessory Mode, USB Operation or Safe State
1575 * Configure @port for Accessory Mode @mode. This function will configure the
1576 * muxes needed for @mode.
1578 int typec_set_mode(struct typec_port *port, int mode)
1580 struct typec_mux_state state = { };
1584 return typec_mux_set(port->mux, &state);
1586 EXPORT_SYMBOL_GPL(typec_set_mode);
1588 /* --------------------------------------- */
1591 * typec_get_drvdata - Return private driver data pointer
1592 * @port: USB Type-C port
1594 void *typec_get_drvdata(struct typec_port *port)
1596 return dev_get_drvdata(&port->dev);
1598 EXPORT_SYMBOL_GPL(typec_get_drvdata);
1601 * typec_port_register_altmode - Register USB Type-C Port Alternate Mode
1602 * @port: USB Type-C Port that supports the alternate mode
1603 * @desc: Description of the alternate mode
1605 * This routine is used to register an alternate mode that @port is capable of
1608 * Returns handle to the alternate mode on success or ERR_PTR on failure.
1610 struct typec_altmode *
1611 typec_port_register_altmode(struct typec_port *port,
1612 const struct typec_altmode_desc *desc)
1614 struct typec_altmode *adev;
1615 struct typec_mux *mux;
1617 mux = typec_mux_get(&port->dev, desc);
1619 return ERR_CAST(mux);
1621 adev = typec_register_altmode(&port->dev, desc);
1625 to_altmode(adev)->mux = mux;
1629 EXPORT_SYMBOL_GPL(typec_port_register_altmode);
1632 * typec_register_port - Register a USB Type-C Port
1633 * @parent: Parent device
1634 * @cap: Description of the port
1636 * Registers a device for USB Type-C Port described in @cap.
1638 * Returns handle to the port on success or ERR_PTR on failure.
1640 struct typec_port *typec_register_port(struct device *parent,
1641 const struct typec_capability *cap)
1643 struct typec_port *port;
1647 port = kzalloc(sizeof(*port), GFP_KERNEL);
1649 return ERR_PTR(-ENOMEM);
1651 id = ida_simple_get(&typec_index_ida, 0, 0, GFP_KERNEL);
1657 switch (cap->type) {
1658 case TYPEC_PORT_SRC:
1659 port->pwr_role = TYPEC_SOURCE;
1660 port->vconn_role = TYPEC_SOURCE;
1662 case TYPEC_PORT_SNK:
1663 port->pwr_role = TYPEC_SINK;
1664 port->vconn_role = TYPEC_SINK;
1666 case TYPEC_PORT_DRP:
1667 if (cap->prefer_role != TYPEC_NO_PREFERRED_ROLE)
1668 port->pwr_role = cap->prefer_role;
1670 port->pwr_role = TYPEC_SINK;
1674 switch (cap->data) {
1675 case TYPEC_PORT_DFP:
1676 port->data_role = TYPEC_HOST;
1678 case TYPEC_PORT_UFP:
1679 port->data_role = TYPEC_DEVICE;
1681 case TYPEC_PORT_DRD:
1682 if (cap->prefer_role == TYPEC_SOURCE)
1683 port->data_role = TYPEC_HOST;
1685 port->data_role = TYPEC_DEVICE;
1689 ida_init(&port->mode_ids);
1690 mutex_init(&port->port_type_lock);
1693 port->ops = cap->ops;
1694 port->port_type = cap->type;
1695 port->prefer_role = cap->prefer_role;
1697 device_initialize(&port->dev);
1698 port->dev.class = typec_class;
1699 port->dev.parent = parent;
1700 port->dev.fwnode = cap->fwnode;
1701 port->dev.type = &typec_port_dev_type;
1702 dev_set_name(&port->dev, "port%d", id);
1703 dev_set_drvdata(&port->dev, cap->driver_data);
1705 port->cap = kmemdup(cap, sizeof(*cap), GFP_KERNEL);
1707 put_device(&port->dev);
1708 return ERR_PTR(-ENOMEM);
1711 port->sw = typec_switch_get(&port->dev);
1712 if (IS_ERR(port->sw)) {
1713 ret = PTR_ERR(port->sw);
1714 put_device(&port->dev);
1715 return ERR_PTR(ret);
1718 port->mux = typec_mux_get(&port->dev, NULL);
1719 if (IS_ERR(port->mux)) {
1720 ret = PTR_ERR(port->mux);
1721 put_device(&port->dev);
1722 return ERR_PTR(ret);
1725 ret = device_add(&port->dev);
1727 dev_err(parent, "failed to register port (%d)\n", ret);
1728 put_device(&port->dev);
1729 return ERR_PTR(ret);
1734 EXPORT_SYMBOL_GPL(typec_register_port);
1737 * typec_unregister_port - Unregister a USB Type-C Port
1738 * @port: The port to be unregistered
1740 * Unregister device created with typec_register_port().
1742 void typec_unregister_port(struct typec_port *port)
1744 if (!IS_ERR_OR_NULL(port))
1745 device_unregister(&port->dev);
1747 EXPORT_SYMBOL_GPL(typec_unregister_port);
1749 static int __init typec_init(void)
1753 ret = bus_register(&typec_bus);
1757 ret = class_register(&typec_mux_class);
1759 goto err_unregister_bus;
1761 typec_class = class_create(THIS_MODULE, "typec");
1762 if (IS_ERR(typec_class)) {
1763 ret = PTR_ERR(typec_class);
1764 goto err_unregister_mux_class;
1769 err_unregister_mux_class:
1770 class_unregister(&typec_mux_class);
1773 bus_unregister(&typec_bus);
1777 subsys_initcall(typec_init);
1779 static void __exit typec_exit(void)
1781 class_destroy(typec_class);
1782 ida_destroy(&typec_index_ida);
1783 bus_unregister(&typec_bus);
1784 class_unregister(&typec_mux_class);
1786 module_exit(typec_exit);
1788 MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>");
1789 MODULE_LICENSE("GPL v2");
1790 MODULE_DESCRIPTION("USB Type-C Connector Class");