1 // SPDX-License-Identifier: GPL-2.0
3 * USB Type-C Connector System Software Interface driver
5 * Copyright (C) 2017, Intel Corporation
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
9 #include <linux/completion.h>
10 #include <linux/property.h>
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/usb/typec_dp.h>
21 * UCSI_TIMEOUT_MS - PPM communication timeout
23 * Ideally we could use MIN_TIME_TO_RESPOND_WITH_BUSY (which is defined in UCSI
24 * specification) here as reference, but unfortunately we can't. It is very
25 * difficult to estimate the time it takes for the system to process the command
26 * before it is actually passed to the PPM.
28 #define UCSI_TIMEOUT_MS 5000
31 * UCSI_SWAP_TIMEOUT_MS - Timeout for role swap requests
33 * 5 seconds is close to the time it takes for CapsCounter to reach 0, so even
34 * if the PPM does not generate Connector Change events before that with
35 * partners that do not support USB Power Delivery, this should still work.
37 #define UCSI_SWAP_TIMEOUT_MS 5000
39 static int ucsi_read_message_in(struct ucsi *ucsi, void *buf,
43 * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the
46 if (ucsi->version <= UCSI_VERSION_1_2)
47 buf_size = clamp(buf_size, 0, 16);
49 return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size);
52 static int ucsi_acknowledge_command(struct ucsi *ucsi)
56 ctrl = UCSI_ACK_CC_CI;
57 ctrl |= UCSI_ACK_COMMAND_COMPLETE;
59 return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl));
62 static int ucsi_acknowledge_connector_change(struct ucsi *ucsi)
66 ctrl = UCSI_ACK_CC_CI;
67 ctrl |= UCSI_ACK_CONNECTOR_CHANGE;
69 return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl));
72 static int ucsi_exec_command(struct ucsi *ucsi, u64 command);
74 static int ucsi_read_error(struct ucsi *ucsi)
79 /* Acknowledge the command that failed */
80 ret = ucsi_acknowledge_command(ucsi);
84 ret = ucsi_exec_command(ucsi, UCSI_GET_ERROR_STATUS);
88 ret = ucsi_read_message_in(ucsi, &error, sizeof(error));
92 ret = ucsi_acknowledge_command(ucsi);
97 case UCSI_ERROR_INCOMPATIBLE_PARTNER:
99 case UCSI_ERROR_CC_COMMUNICATION_ERR:
101 case UCSI_ERROR_CONTRACT_NEGOTIATION_FAIL:
103 case UCSI_ERROR_DEAD_BATTERY:
104 dev_warn(ucsi->dev, "Dead battery condition!\n");
106 case UCSI_ERROR_INVALID_CON_NUM:
107 case UCSI_ERROR_UNREGONIZED_CMD:
108 case UCSI_ERROR_INVALID_CMD_ARGUMENT:
109 dev_err(ucsi->dev, "possible UCSI driver bug %u\n", error);
111 case UCSI_ERROR_OVERCURRENT:
112 dev_warn(ucsi->dev, "Overcurrent condition\n");
114 case UCSI_ERROR_PARTNER_REJECTED_SWAP:
115 dev_warn(ucsi->dev, "Partner rejected swap\n");
117 case UCSI_ERROR_HARD_RESET:
118 dev_warn(ucsi->dev, "Hard reset occurred\n");
120 case UCSI_ERROR_PPM_POLICY_CONFLICT:
121 dev_warn(ucsi->dev, "PPM Policy conflict\n");
123 case UCSI_ERROR_SWAP_REJECTED:
124 dev_warn(ucsi->dev, "Swap rejected\n");
126 case UCSI_ERROR_UNDEFINED:
128 dev_err(ucsi->dev, "unknown error %u\n", error);
135 static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
140 ret = ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
144 ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
148 if (cmd != UCSI_CANCEL && cci & UCSI_CCI_BUSY)
149 return ucsi_exec_command(ucsi, UCSI_CANCEL);
151 if (!(cci & UCSI_CCI_COMMAND_COMPLETE))
154 if (cci & UCSI_CCI_NOT_SUPPORTED) {
155 if (ucsi_acknowledge_command(ucsi) < 0)
157 "ACK of unsupported command failed\n");
161 if (cci & UCSI_CCI_ERROR) {
162 if (cmd == UCSI_GET_ERROR_STATUS)
164 return ucsi_read_error(ucsi);
167 if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) {
168 ret = ucsi_acknowledge_command(ucsi);
169 return ret ? ret : -EBUSY;
172 return UCSI_CCI_LENGTH(cci);
175 int ucsi_send_command(struct ucsi *ucsi, u64 command,
176 void *data, size_t size)
181 mutex_lock(&ucsi->ppm_lock);
183 ret = ucsi_exec_command(ucsi, command);
190 ret = ucsi_read_message_in(ucsi, data, size);
195 ret = ucsi_acknowledge_command(ucsi);
201 mutex_unlock(&ucsi->ppm_lock);
204 EXPORT_SYMBOL_GPL(ucsi_send_command);
206 /* -------------------------------------------------------------------------- */
209 struct delayed_work work;
210 struct list_head node;
213 struct ucsi_connector *con;
214 int (*cb)(struct ucsi_connector *);
217 static void ucsi_poll_worker(struct work_struct *work)
219 struct ucsi_work *uwork = container_of(work, struct ucsi_work, work.work);
220 struct ucsi_connector *con = uwork->con;
223 mutex_lock(&con->lock);
226 list_del(&uwork->node);
227 mutex_unlock(&con->lock);
232 ret = uwork->cb(con);
234 if (uwork->count-- && (ret == -EBUSY || ret == -ETIMEDOUT)) {
235 queue_delayed_work(con->wq, &uwork->work, uwork->delay);
237 list_del(&uwork->node);
241 mutex_unlock(&con->lock);
244 static int ucsi_partner_task(struct ucsi_connector *con,
245 int (*cb)(struct ucsi_connector *),
246 int retries, unsigned long delay)
248 struct ucsi_work *uwork;
253 uwork = kzalloc(sizeof(*uwork), GFP_KERNEL);
257 INIT_DELAYED_WORK(&uwork->work, ucsi_poll_worker);
258 uwork->count = retries;
259 uwork->delay = delay;
263 list_add_tail(&uwork->node, &con->partner_tasks);
264 queue_delayed_work(con->wq, &uwork->work, delay);
269 /* -------------------------------------------------------------------------- */
271 void ucsi_altmode_update_active(struct ucsi_connector *con)
273 const struct typec_altmode *altmode = NULL;
279 command = UCSI_GET_CURRENT_CAM | UCSI_CONNECTOR_NUMBER(con->num);
280 ret = ucsi_send_command(con->ucsi, command, &cur, sizeof(cur));
282 if (con->ucsi->version > 0x0100) {
283 dev_err(con->ucsi->dev,
284 "GET_CURRENT_CAM command failed\n");
290 if (cur < UCSI_MAX_ALTMODES)
291 altmode = typec_altmode_get_partner(con->port_altmode[cur]);
293 for (i = 0; con->partner_altmode[i]; i++)
294 typec_altmode_update_active(con->partner_altmode[i],
295 con->partner_altmode[i] == altmode);
298 static int ucsi_altmode_next_mode(struct typec_altmode **alt, u16 svid)
303 for (i = 0; alt[i]; i++) {
304 if (i > MODE_DISCOVERY_MAX)
307 if (alt[i]->svid == svid)
314 static int ucsi_next_altmode(struct typec_altmode **alt)
318 for (i = 0; i < UCSI_MAX_ALTMODES; i++)
325 static int ucsi_get_num_altmode(struct typec_altmode **alt)
329 for (i = 0; i < UCSI_MAX_ALTMODES; i++)
336 static int ucsi_register_altmode(struct ucsi_connector *con,
337 struct typec_altmode_desc *desc,
340 struct typec_altmode *alt;
345 override = !!(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE);
348 case UCSI_RECIPIENT_CON:
349 i = ucsi_next_altmode(con->port_altmode);
355 ret = ucsi_altmode_next_mode(con->port_altmode, desc->svid);
361 switch (desc->svid) {
362 case USB_TYPEC_DP_SID:
363 alt = ucsi_register_displayport(con, override, i, desc);
365 case USB_TYPEC_NVIDIA_VLINK_SID:
366 if (desc->vdo == USB_TYPEC_NVIDIA_VLINK_DBG_VDO)
367 alt = typec_port_register_altmode(con->port,
370 alt = ucsi_register_displayport(con, override,
374 alt = typec_port_register_altmode(con->port, desc);
383 con->port_altmode[i] = alt;
385 case UCSI_RECIPIENT_SOP:
386 i = ucsi_next_altmode(con->partner_altmode);
392 ret = ucsi_altmode_next_mode(con->partner_altmode, desc->svid);
398 alt = typec_partner_register_altmode(con->partner, desc);
404 con->partner_altmode[i] = alt;
410 trace_ucsi_register_altmode(recipient, alt);
415 dev_err(con->ucsi->dev, "failed to registers svid 0x%04x mode %d\n",
416 desc->svid, desc->mode);
422 ucsi_register_altmodes_nvidia(struct ucsi_connector *con, u8 recipient)
424 int max_altmodes = UCSI_MAX_ALTMODES;
425 struct typec_altmode_desc desc;
426 struct ucsi_altmode alt;
427 struct ucsi_altmode orig[UCSI_MAX_ALTMODES];
428 struct ucsi_altmode updated[UCSI_MAX_ALTMODES];
429 struct ucsi *ucsi = con->ucsi;
430 bool multi_dp = false;
437 if (recipient == UCSI_RECIPIENT_CON)
438 max_altmodes = con->ucsi->cap.num_alt_modes;
440 memset(orig, 0, sizeof(orig));
441 memset(updated, 0, sizeof(updated));
443 /* First get all the alternate modes */
444 for (i = 0; i < max_altmodes; i++) {
445 memset(&alt, 0, sizeof(alt));
446 command = UCSI_GET_ALTERNATE_MODES;
447 command |= UCSI_GET_ALTMODE_RECIPIENT(recipient);
448 command |= UCSI_GET_ALTMODE_CONNECTOR_NUMBER(con->num);
449 command |= UCSI_GET_ALTMODE_OFFSET(i);
450 len = ucsi_send_command(con->ucsi, command, &alt, sizeof(alt));
452 * We are collecting all altmodes first and then registering.
453 * Some type-C device will return zero length data beyond last
454 * alternate modes. We should not return if length is zero.
459 /* We got all altmodes, now break out and register them */
460 if (!len || !alt.svid)
463 orig[k].mid = alt.mid;
464 orig[k].svid = alt.svid;
468 * Update the original altmode table as some ppms may report
469 * multiple DP altmodes.
471 if (recipient == UCSI_RECIPIENT_CON)
472 multi_dp = ucsi->ops->update_altmodes(ucsi, orig, updated);
474 /* now register altmodes */
475 for (i = 0; i < max_altmodes; i++) {
476 memset(&desc, 0, sizeof(desc));
477 if (multi_dp && recipient == UCSI_RECIPIENT_CON) {
478 desc.svid = updated[i].svid;
479 desc.vdo = updated[i].mid;
481 desc.svid = orig[i].svid;
482 desc.vdo = orig[i].mid;
484 desc.roles = TYPEC_PORT_DRD;
489 ret = ucsi_register_altmode(con, &desc, recipient);
497 static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)
499 int max_altmodes = UCSI_MAX_ALTMODES;
500 struct typec_altmode_desc desc;
501 struct ucsi_altmode alt[2];
509 if (!(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS))
512 if (recipient == UCSI_RECIPIENT_SOP && con->partner_altmode[0])
515 if (con->ucsi->ops->update_altmodes)
516 return ucsi_register_altmodes_nvidia(con, recipient);
518 if (recipient == UCSI_RECIPIENT_CON)
519 max_altmodes = con->ucsi->cap.num_alt_modes;
521 for (i = 0; i < max_altmodes;) {
522 memset(alt, 0, sizeof(alt));
523 command = UCSI_GET_ALTERNATE_MODES;
524 command |= UCSI_GET_ALTMODE_RECIPIENT(recipient);
525 command |= UCSI_GET_ALTMODE_CONNECTOR_NUMBER(con->num);
526 command |= UCSI_GET_ALTMODE_OFFSET(i);
527 len = ucsi_send_command(con->ucsi, command, alt, sizeof(alt));
534 * This code is requesting one alt mode at a time, but some PPMs
535 * may still return two. If that happens both alt modes need be
536 * registered and the offset for the next alt mode has to be
539 num = len / sizeof(alt[0]);
542 for (j = 0; j < num; j++) {
546 memset(&desc, 0, sizeof(desc));
547 desc.vdo = alt[j].mid;
548 desc.svid = alt[j].svid;
549 desc.roles = TYPEC_PORT_DRD;
551 ret = ucsi_register_altmode(con, &desc, recipient);
560 static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
562 const struct typec_altmode *pdev;
563 struct typec_altmode **adev;
567 case UCSI_RECIPIENT_CON:
568 adev = con->port_altmode;
570 case UCSI_RECIPIENT_SOP:
571 adev = con->partner_altmode;
578 if (recipient == UCSI_RECIPIENT_SOP &&
579 (adev[i]->svid == USB_TYPEC_DP_SID ||
580 (adev[i]->svid == USB_TYPEC_NVIDIA_VLINK_SID &&
581 adev[i]->vdo != USB_TYPEC_NVIDIA_VLINK_DBG_VDO))) {
582 pdev = typec_altmode_get_partner(adev[i]);
583 ucsi_displayport_remove_partner((void *)pdev);
585 typec_unregister_altmode(adev[i]);
590 static int ucsi_read_pdos(struct ucsi_connector *con,
591 enum typec_role role, int is_partner,
592 u32 *pdos, int offset, int num_pdos)
594 struct ucsi *ucsi = con->ucsi;
598 if (ucsi->quirks & UCSI_NO_PARTNER_PDOS)
601 command = UCSI_COMMAND(UCSI_GET_PDOS) | UCSI_CONNECTOR_NUMBER(con->num);
602 command |= UCSI_GET_PDOS_PARTNER_PDO(is_partner);
603 command |= UCSI_GET_PDOS_PDO_OFFSET(offset);
604 command |= UCSI_GET_PDOS_NUM_PDOS(num_pdos - 1);
605 command |= is_source(role) ? UCSI_GET_PDOS_SRC_PDOS : 0;
606 ret = ucsi_send_command(ucsi, command, pdos + offset,
607 num_pdos * sizeof(u32));
608 if (ret < 0 && ret != -ETIMEDOUT)
609 dev_err(ucsi->dev, "UCSI_GET_PDOS failed (%d)\n", ret);
614 static int ucsi_get_pdos(struct ucsi_connector *con, enum typec_role role,
615 int is_partner, u32 *pdos)
620 /* UCSI max payload means only getting at most 4 PDOs at a time */
621 ret = ucsi_read_pdos(con, role, is_partner, pdos, 0, UCSI_MAX_PDOS);
625 num_pdos = ret / sizeof(u32); /* number of bytes to 32-bit PDOs */
626 if (num_pdos < UCSI_MAX_PDOS)
629 /* get the remaining PDOs, if any */
630 ret = ucsi_read_pdos(con, role, is_partner, pdos, UCSI_MAX_PDOS,
631 PDO_MAX_OBJECTS - UCSI_MAX_PDOS);
635 return ret / sizeof(u32) + num_pdos;
638 static int ucsi_get_src_pdos(struct ucsi_connector *con)
642 ret = ucsi_get_pdos(con, TYPEC_SOURCE, 1, con->src_pdos);
648 ucsi_port_psy_changed(con);
653 static int ucsi_check_altmodes(struct ucsi_connector *con)
655 int ret, num_partner_am;
657 ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP);
658 if (ret && ret != -ETIMEDOUT)
659 dev_err(con->ucsi->dev,
660 "con%d: failed to register partner alt modes (%d)\n",
663 /* Ignoring the errors in this case. */
664 if (con->partner_altmode[0]) {
665 num_partner_am = ucsi_get_num_altmode(con->partner_altmode);
666 if (num_partner_am > 0)
667 typec_partner_set_num_altmodes(con->partner, num_partner_am);
668 ucsi_altmode_update_active(con);
675 static int ucsi_register_partner_pdos(struct ucsi_connector *con)
677 struct usb_power_delivery_desc desc = { con->ucsi->cap.pd_version };
678 struct usb_power_delivery_capabilities_desc caps;
679 struct usb_power_delivery_capabilities *cap;
685 con->partner_pd = usb_power_delivery_register(NULL, &desc);
686 if (IS_ERR(con->partner_pd))
687 return PTR_ERR(con->partner_pd);
689 ret = ucsi_get_pdos(con, TYPEC_SOURCE, 1, caps.pdo);
691 if (ret < PDO_MAX_OBJECTS)
694 caps.role = TYPEC_SOURCE;
695 cap = usb_power_delivery_register_capabilities(con->partner_pd, &caps);
699 con->partner_source_caps = cap;
701 ret = typec_partner_set_usb_power_delivery(con->partner, con->partner_pd);
703 usb_power_delivery_unregister_capabilities(con->partner_source_caps);
708 ret = ucsi_get_pdos(con, TYPEC_SINK, 1, caps.pdo);
710 if (ret < PDO_MAX_OBJECTS)
713 caps.role = TYPEC_SINK;
715 cap = usb_power_delivery_register_capabilities(con->partner_pd, &caps);
719 con->partner_sink_caps = cap;
721 ret = typec_partner_set_usb_power_delivery(con->partner, con->partner_pd);
723 usb_power_delivery_unregister_capabilities(con->partner_sink_caps);
731 static void ucsi_unregister_partner_pdos(struct ucsi_connector *con)
733 usb_power_delivery_unregister_capabilities(con->partner_sink_caps);
734 con->partner_sink_caps = NULL;
735 usb_power_delivery_unregister_capabilities(con->partner_source_caps);
736 con->partner_source_caps = NULL;
737 usb_power_delivery_unregister(con->partner_pd);
738 con->partner_pd = NULL;
741 static void ucsi_pwr_opmode_change(struct ucsi_connector *con)
743 switch (UCSI_CONSTAT_PWR_OPMODE(con->status.flags)) {
744 case UCSI_CONSTAT_PWR_OPMODE_PD:
745 con->rdo = con->status.request_data_obj;
746 typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_PD);
747 ucsi_partner_task(con, ucsi_get_src_pdos, 30, 0);
748 ucsi_partner_task(con, ucsi_check_altmodes, 30, 0);
749 ucsi_partner_task(con, ucsi_register_partner_pdos, 1, HZ);
751 case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
753 typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_1_5A);
755 case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
757 typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_3_0A);
761 typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_USB);
766 static int ucsi_register_partner(struct ucsi_connector *con)
768 u8 pwr_opmode = UCSI_CONSTAT_PWR_OPMODE(con->status.flags);
769 struct typec_partner_desc desc;
770 struct typec_partner *partner;
775 memset(&desc, 0, sizeof(desc));
777 switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
778 case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
779 desc.accessory = TYPEC_ACCESSORY_DEBUG;
781 case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
782 desc.accessory = TYPEC_ACCESSORY_AUDIO;
788 desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD;
790 partner = typec_register_partner(con->port, &desc);
791 if (IS_ERR(partner)) {
792 dev_err(con->ucsi->dev,
793 "con%d: failed to register partner (%ld)\n", con->num,
795 return PTR_ERR(partner);
798 con->partner = partner;
803 static void ucsi_unregister_partner(struct ucsi_connector *con)
808 typec_set_mode(con->port, TYPEC_STATE_SAFE);
810 typec_partner_set_usb_power_delivery(con->partner, NULL);
811 ucsi_unregister_partner_pdos(con);
812 ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP);
813 typec_unregister_partner(con->partner);
817 static void ucsi_partner_change(struct ucsi_connector *con)
819 enum usb_role u_role = USB_ROLE_NONE;
822 switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
823 case UCSI_CONSTAT_PARTNER_TYPE_UFP:
824 case UCSI_CONSTAT_PARTNER_TYPE_CABLE_AND_UFP:
825 u_role = USB_ROLE_HOST;
827 case UCSI_CONSTAT_PARTNER_TYPE_CABLE:
828 typec_set_data_role(con->port, TYPEC_HOST);
830 case UCSI_CONSTAT_PARTNER_TYPE_DFP:
831 u_role = USB_ROLE_DEVICE;
832 typec_set_data_role(con->port, TYPEC_DEVICE);
838 if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
839 switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
840 case UCSI_CONSTAT_PARTNER_TYPE_DEBUG:
841 typec_set_mode(con->port, TYPEC_MODE_DEBUG);
843 case UCSI_CONSTAT_PARTNER_TYPE_AUDIO:
844 typec_set_mode(con->port, TYPEC_MODE_AUDIO);
847 if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) ==
848 UCSI_CONSTAT_PARTNER_FLAG_USB)
849 typec_set_mode(con->port, TYPEC_STATE_USB);
853 /* Only notify USB controller if partner supports USB data */
854 if (!(UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) & UCSI_CONSTAT_PARTNER_FLAG_USB))
855 u_role = USB_ROLE_NONE;
857 ret = usb_role_switch_set_role(con->usb_role_sw, u_role);
859 dev_err(con->ucsi->dev, "con:%d: failed to set usb role:%d\n",
863 static int ucsi_check_connection(struct ucsi_connector *con)
865 u8 prev_flags = con->status.flags;
869 command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
870 ret = ucsi_send_command(con->ucsi, command, &con->status, sizeof(con->status));
872 dev_err(con->ucsi->dev, "GET_CONNECTOR_STATUS failed (%d)\n", ret);
876 if (con->status.flags == prev_flags)
879 if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
880 ucsi_register_partner(con);
881 ucsi_pwr_opmode_change(con);
882 ucsi_partner_change(con);
884 ucsi_partner_change(con);
885 ucsi_port_psy_changed(con);
886 ucsi_unregister_partner(con);
892 static void ucsi_handle_connector_change(struct work_struct *work)
894 struct ucsi_connector *con = container_of(work, struct ucsi_connector,
896 struct ucsi *ucsi = con->ucsi;
897 enum typec_role role;
901 mutex_lock(&con->lock);
903 command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
904 ret = ucsi_send_command(ucsi, command, &con->status, sizeof(con->status));
906 dev_err(ucsi->dev, "%s: GET_CONNECTOR_STATUS failed (%d)\n",
908 clear_bit(EVENT_PENDING, &con->ucsi->flags);
912 trace_ucsi_connector_change(con->num, &con->status);
914 role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
916 if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) {
917 typec_set_pwr_role(con->port, role);
919 /* Complete pending power role swap */
920 if (!completion_done(&con->complete))
921 complete(&con->complete);
924 if (con->status.change & UCSI_CONSTAT_CONNECT_CHANGE) {
925 typec_set_pwr_role(con->port, role);
926 ucsi_port_psy_changed(con);
927 ucsi_partner_change(con);
929 if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
930 ucsi_register_partner(con);
931 ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
933 if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
934 UCSI_CONSTAT_PWR_OPMODE_PD)
935 ucsi_partner_task(con, ucsi_register_partner_pdos, 1, HZ);
937 ucsi_unregister_partner(con);
941 if (con->status.change & UCSI_CONSTAT_POWER_OPMODE_CHANGE ||
942 con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE)
943 ucsi_pwr_opmode_change(con);
945 if (con->partner && con->status.change & UCSI_CONSTAT_PARTNER_CHANGE) {
946 ucsi_partner_change(con);
948 /* Complete pending data role swap */
949 if (!completion_done(&con->complete))
950 complete(&con->complete);
953 if (con->status.change & UCSI_CONSTAT_CAM_CHANGE)
954 ucsi_partner_task(con, ucsi_check_altmodes, 1, 0);
956 mutex_lock(&ucsi->ppm_lock);
957 clear_bit(EVENT_PENDING, &con->ucsi->flags);
958 ret = ucsi_acknowledge_connector_change(ucsi);
959 mutex_unlock(&ucsi->ppm_lock);
962 dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret);
965 mutex_unlock(&con->lock);
969 * ucsi_connector_change - Process Connector Change Event
970 * @ucsi: UCSI Interface
971 * @num: Connector number
973 void ucsi_connector_change(struct ucsi *ucsi, u8 num)
975 struct ucsi_connector *con = &ucsi->connector[num - 1];
977 if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
978 dev_dbg(ucsi->dev, "Bogus connector change event\n");
982 if (!test_and_set_bit(EVENT_PENDING, &ucsi->flags))
983 schedule_work(&con->work);
985 EXPORT_SYMBOL_GPL(ucsi_connector_change);
987 /* -------------------------------------------------------------------------- */
989 static int ucsi_reset_connector(struct ucsi_connector *con, bool hard)
993 command = UCSI_CONNECTOR_RESET | UCSI_CONNECTOR_NUMBER(con->num);
994 command |= hard ? UCSI_CONNECTOR_RESET_HARD : 0;
996 return ucsi_send_command(con->ucsi, command, NULL, 0);
999 static int ucsi_reset_ppm(struct ucsi *ucsi)
1006 mutex_lock(&ucsi->ppm_lock);
1008 ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
1013 * If UCSI_CCI_RESET_COMPLETE is already set we must clear
1014 * the flag before we start another reset. Send a
1015 * UCSI_SET_NOTIFICATION_ENABLE command to achieve this.
1016 * Ignore a timeout and try the reset anyway if this fails.
1018 if (cci & UCSI_CCI_RESET_COMPLETE) {
1019 command = UCSI_SET_NOTIFICATION_ENABLE;
1020 ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
1025 tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS);
1027 ret = ucsi->ops->read(ucsi, UCSI_CCI,
1031 if (cci & UCSI_CCI_COMMAND_COMPLETE)
1033 if (time_is_before_jiffies(tmo))
1038 WARN_ON(cci & UCSI_CCI_RESET_COMPLETE);
1041 command = UCSI_PPM_RESET;
1042 ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
1047 tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS);
1050 if (time_is_before_jiffies(tmo)) {
1055 ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
1059 /* If the PPM is still doing something else, reset it again. */
1060 if (cci & ~UCSI_CCI_RESET_COMPLETE) {
1061 ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL,
1069 } while (!(cci & UCSI_CCI_RESET_COMPLETE));
1072 mutex_unlock(&ucsi->ppm_lock);
1076 static int ucsi_role_cmd(struct ucsi_connector *con, u64 command)
1080 ret = ucsi_send_command(con->ucsi, command, NULL, 0);
1081 if (ret == -ETIMEDOUT) {
1084 /* PPM most likely stopped responding. Resetting everything. */
1085 ucsi_reset_ppm(con->ucsi);
1087 c = UCSI_SET_NOTIFICATION_ENABLE | con->ucsi->ntfy;
1088 ucsi_send_command(con->ucsi, c, NULL, 0);
1090 ucsi_reset_connector(con, true);
1096 static int ucsi_dr_swap(struct typec_port *port, enum typec_data_role role)
1098 struct ucsi_connector *con = typec_get_drvdata(port);
1103 mutex_lock(&con->lock);
1105 if (!con->partner) {
1110 partner_type = UCSI_CONSTAT_PARTNER_TYPE(con->status.flags);
1111 if ((partner_type == UCSI_CONSTAT_PARTNER_TYPE_DFP &&
1112 role == TYPEC_DEVICE) ||
1113 (partner_type == UCSI_CONSTAT_PARTNER_TYPE_UFP &&
1114 role == TYPEC_HOST))
1117 reinit_completion(&con->complete);
1119 command = UCSI_SET_UOR | UCSI_CONNECTOR_NUMBER(con->num);
1120 command |= UCSI_SET_UOR_ROLE(role);
1121 command |= UCSI_SET_UOR_ACCEPT_ROLE_SWAPS;
1122 ret = ucsi_role_cmd(con, command);
1126 mutex_unlock(&con->lock);
1128 if (!wait_for_completion_timeout(&con->complete,
1129 msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
1135 mutex_unlock(&con->lock);
1140 static int ucsi_pr_swap(struct typec_port *port, enum typec_role role)
1142 struct ucsi_connector *con = typec_get_drvdata(port);
1143 enum typec_role cur_role;
1147 mutex_lock(&con->lock);
1149 if (!con->partner) {
1154 cur_role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
1156 if (cur_role == role)
1159 reinit_completion(&con->complete);
1161 command = UCSI_SET_PDR | UCSI_CONNECTOR_NUMBER(con->num);
1162 command |= UCSI_SET_PDR_ROLE(role);
1163 command |= UCSI_SET_PDR_ACCEPT_ROLE_SWAPS;
1164 ret = ucsi_role_cmd(con, command);
1168 mutex_unlock(&con->lock);
1170 if (!wait_for_completion_timeout(&con->complete,
1171 msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
1174 mutex_lock(&con->lock);
1176 /* Something has gone wrong while swapping the role */
1177 if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) !=
1178 UCSI_CONSTAT_PWR_OPMODE_PD) {
1179 ucsi_reset_connector(con, true);
1184 mutex_unlock(&con->lock);
1189 static const struct typec_operations ucsi_ops = {
1190 .dr_set = ucsi_dr_swap,
1191 .pr_set = ucsi_pr_swap
1194 /* Caller must call fwnode_handle_put() after use */
1195 static struct fwnode_handle *ucsi_find_fwnode(struct ucsi_connector *con)
1197 struct fwnode_handle *fwnode;
1200 device_for_each_child_node(con->ucsi->dev, fwnode)
1201 if (i++ == con->num)
1206 static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
1208 struct usb_power_delivery_desc desc = { ucsi->cap.pd_version};
1209 struct usb_power_delivery_capabilities_desc pd_caps;
1210 struct usb_power_delivery_capabilities *pd_cap;
1211 struct typec_capability *cap = &con->typec_cap;
1212 enum typec_accessory *accessory = cap->accessory;
1213 enum usb_role u_role = USB_ROLE_NONE;
1218 name = kasprintf(GFP_KERNEL, "%s-con%d", dev_name(ucsi->dev), con->num);
1222 con->wq = create_singlethread_workqueue(name);
1227 INIT_WORK(&con->work, ucsi_handle_connector_change);
1228 init_completion(&con->complete);
1229 mutex_init(&con->lock);
1230 INIT_LIST_HEAD(&con->partner_tasks);
1233 cap->fwnode = ucsi_find_fwnode(con);
1234 con->usb_role_sw = fwnode_usb_role_switch_get(cap->fwnode);
1235 if (IS_ERR(con->usb_role_sw))
1236 return dev_err_probe(ucsi->dev, PTR_ERR(con->usb_role_sw),
1237 "con%d: failed to get usb role switch\n", con->num);
1239 /* Delay other interactions with the con until registration is complete */
1240 mutex_lock(&con->lock);
1242 /* Get connector capability */
1243 command = UCSI_GET_CONNECTOR_CAPABILITY;
1244 command |= UCSI_CONNECTOR_NUMBER(con->num);
1245 ret = ucsi_send_command(ucsi, command, &con->cap, sizeof(con->cap));
1249 if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DRP)
1250 cap->data = TYPEC_PORT_DRD;
1251 else if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DFP)
1252 cap->data = TYPEC_PORT_DFP;
1253 else if (con->cap.op_mode & UCSI_CONCAP_OPMODE_UFP)
1254 cap->data = TYPEC_PORT_UFP;
1256 if ((con->cap.flags & UCSI_CONCAP_FLAG_PROVIDER) &&
1257 (con->cap.flags & UCSI_CONCAP_FLAG_CONSUMER))
1258 cap->type = TYPEC_PORT_DRP;
1259 else if (con->cap.flags & UCSI_CONCAP_FLAG_PROVIDER)
1260 cap->type = TYPEC_PORT_SRC;
1261 else if (con->cap.flags & UCSI_CONCAP_FLAG_CONSUMER)
1262 cap->type = TYPEC_PORT_SNK;
1264 cap->revision = ucsi->cap.typec_version;
1265 cap->pd_revision = ucsi->cap.pd_version;
1266 cap->svdm_version = SVDM_VER_2_0;
1267 cap->prefer_role = TYPEC_NO_PREFERRED_ROLE;
1269 if (con->cap.op_mode & UCSI_CONCAP_OPMODE_AUDIO_ACCESSORY)
1270 *accessory++ = TYPEC_ACCESSORY_AUDIO;
1271 if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DEBUG_ACCESSORY)
1272 *accessory = TYPEC_ACCESSORY_DEBUG;
1274 cap->driver_data = con;
1275 cap->ops = &ucsi_ops;
1277 ret = ucsi_register_port_psy(con);
1281 /* Register the connector */
1282 con->port = typec_register_port(ucsi->dev, cap);
1283 if (IS_ERR(con->port)) {
1284 ret = PTR_ERR(con->port);
1288 con->pd = usb_power_delivery_register(ucsi->dev, &desc);
1290 ret = ucsi_get_pdos(con, TYPEC_SOURCE, 0, pd_caps.pdo);
1292 if (ret < PDO_MAX_OBJECTS)
1293 pd_caps.pdo[ret] = 0;
1295 pd_caps.role = TYPEC_SOURCE;
1296 pd_cap = usb_power_delivery_register_capabilities(con->pd, &pd_caps);
1297 if (IS_ERR(pd_cap)) {
1298 ret = PTR_ERR(pd_cap);
1302 con->port_source_caps = pd_cap;
1303 typec_port_set_usb_power_delivery(con->port, con->pd);
1306 memset(&pd_caps, 0, sizeof(pd_caps));
1307 ret = ucsi_get_pdos(con, TYPEC_SINK, 0, pd_caps.pdo);
1309 if (ret < PDO_MAX_OBJECTS)
1310 pd_caps.pdo[ret] = 0;
1312 pd_caps.role = TYPEC_SINK;
1313 pd_cap = usb_power_delivery_register_capabilities(con->pd, &pd_caps);
1314 if (IS_ERR(pd_cap)) {
1315 ret = PTR_ERR(pd_cap);
1319 con->port_sink_caps = pd_cap;
1320 typec_port_set_usb_power_delivery(con->port, con->pd);
1323 /* Alternate modes */
1324 ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_CON);
1326 dev_err(ucsi->dev, "con%d: failed to register alt modes\n",
1331 /* Get the status */
1332 command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
1333 ret = ucsi_send_command(ucsi, command, &con->status, sizeof(con->status));
1335 dev_err(ucsi->dev, "con%d: failed to get status\n", con->num);
1339 ret = 0; /* ucsi_send_command() returns length on success */
1341 switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) {
1342 case UCSI_CONSTAT_PARTNER_TYPE_UFP:
1343 case UCSI_CONSTAT_PARTNER_TYPE_CABLE_AND_UFP:
1344 u_role = USB_ROLE_HOST;
1346 case UCSI_CONSTAT_PARTNER_TYPE_CABLE:
1347 typec_set_data_role(con->port, TYPEC_HOST);
1349 case UCSI_CONSTAT_PARTNER_TYPE_DFP:
1350 u_role = USB_ROLE_DEVICE;
1351 typec_set_data_role(con->port, TYPEC_DEVICE);
1357 /* Check if there is already something connected */
1358 if (con->status.flags & UCSI_CONSTAT_CONNECTED) {
1359 typec_set_pwr_role(con->port,
1360 !!(con->status.flags & UCSI_CONSTAT_PWR_DIR));
1361 ucsi_register_partner(con);
1362 ucsi_pwr_opmode_change(con);
1363 ucsi_port_psy_changed(con);
1366 /* Only notify USB controller if partner supports USB data */
1367 if (!(UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) & UCSI_CONSTAT_PARTNER_FLAG_USB))
1368 u_role = USB_ROLE_NONE;
1370 ret = usb_role_switch_set_role(con->usb_role_sw, u_role);
1372 dev_err(ucsi->dev, "con:%d: failed to set usb role:%d\n",
1378 UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
1379 UCSI_CONSTAT_PWR_OPMODE_PD) {
1380 ucsi_get_src_pdos(con);
1381 ucsi_check_altmodes(con);
1384 trace_ucsi_register_port(con->num, &con->status);
1387 fwnode_handle_put(cap->fwnode);
1389 mutex_unlock(&con->lock);
1391 if (ret && con->wq) {
1392 destroy_workqueue(con->wq);
1400 * ucsi_init - Initialize UCSI interface
1401 * @ucsi: UCSI to be initialized
1403 * Registers all ports @ucsi has and enables all notification events.
1405 static int ucsi_init(struct ucsi *ucsi)
1407 struct ucsi_connector *con, *connector;
1413 ret = ucsi_reset_ppm(ucsi);
1415 dev_err(ucsi->dev, "failed to reset PPM!\n");
1419 /* Enable basic notifications */
1420 ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;
1421 command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
1422 ret = ucsi_send_command(ucsi, command, NULL, 0);
1426 /* Get PPM capabilities */
1427 command = UCSI_GET_CAPABILITY;
1428 ret = ucsi_send_command(ucsi, command, &ucsi->cap, sizeof(ucsi->cap));
1432 if (!ucsi->cap.num_connectors) {
1437 /* Allocate the connectors. Released in ucsi_unregister() */
1438 connector = kcalloc(ucsi->cap.num_connectors + 1, sizeof(*connector), GFP_KERNEL);
1444 /* Register all connectors */
1445 for (i = 0; i < ucsi->cap.num_connectors; i++) {
1446 connector[i].num = i + 1;
1447 ret = ucsi_register_port(ucsi, &connector[i]);
1449 goto err_unregister;
1452 /* Enable all notifications */
1453 ntfy = UCSI_ENABLE_NTFY_ALL;
1454 command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
1455 ret = ucsi_send_command(ucsi, command, NULL, 0);
1457 goto err_unregister;
1459 ucsi->connector = connector;
1464 for (con = connector; con->port; con++) {
1465 ucsi_unregister_partner(con);
1466 ucsi_unregister_altmodes(con, UCSI_RECIPIENT_CON);
1467 ucsi_unregister_port_psy(con);
1469 destroy_workqueue(con->wq);
1471 usb_power_delivery_unregister_capabilities(con->port_sink_caps);
1472 con->port_sink_caps = NULL;
1473 usb_power_delivery_unregister_capabilities(con->port_source_caps);
1474 con->port_source_caps = NULL;
1475 usb_power_delivery_unregister(con->pd);
1477 typec_unregister_port(con->port);
1482 memset(&ucsi->cap, 0, sizeof(ucsi->cap));
1483 ucsi_reset_ppm(ucsi);
1488 static void ucsi_resume_work(struct work_struct *work)
1490 struct ucsi *ucsi = container_of(work, struct ucsi, resume_work);
1491 struct ucsi_connector *con;
1495 /* Restore UCSI notification enable mask after system resume */
1496 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
1497 ret = ucsi_send_command(ucsi, command, NULL, 0);
1499 dev_err(ucsi->dev, "failed to re-enable notifications (%d)\n", ret);
1503 for (con = ucsi->connector; con->port; con++) {
1504 mutex_lock(&con->lock);
1505 ucsi_partner_task(con, ucsi_check_connection, 1, 0);
1506 mutex_unlock(&con->lock);
1510 int ucsi_resume(struct ucsi *ucsi)
1512 if (ucsi->connector)
1513 queue_work(system_long_wq, &ucsi->resume_work);
1516 EXPORT_SYMBOL_GPL(ucsi_resume);
1518 static void ucsi_init_work(struct work_struct *work)
1520 struct ucsi *ucsi = container_of(work, struct ucsi, work.work);
1523 ret = ucsi_init(ucsi);
1525 dev_err_probe(ucsi->dev, ret, "PPM init failed\n");
1527 if (ret == -EPROBE_DEFER) {
1528 if (ucsi->work_count++ > UCSI_ROLE_SWITCH_WAIT_COUNT) {
1529 dev_err(ucsi->dev, "PPM init failed, stop trying\n");
1533 queue_delayed_work(system_long_wq, &ucsi->work,
1534 UCSI_ROLE_SWITCH_INTERVAL);
1539 * ucsi_get_drvdata - Return private driver data pointer
1540 * @ucsi: UCSI interface
1542 void *ucsi_get_drvdata(struct ucsi *ucsi)
1544 return ucsi->driver_data;
1546 EXPORT_SYMBOL_GPL(ucsi_get_drvdata);
1549 * ucsi_set_drvdata - Assign private driver data pointer
1550 * @ucsi: UCSI interface
1551 * @data: Private data pointer
1553 void ucsi_set_drvdata(struct ucsi *ucsi, void *data)
1555 ucsi->driver_data = data;
1557 EXPORT_SYMBOL_GPL(ucsi_set_drvdata);
1560 * ucsi_create - Allocate UCSI instance
1561 * @dev: Device interface to the PPM (Platform Policy Manager)
1562 * @ops: I/O routines
1564 struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops)
1568 if (!ops || !ops->read || !ops->sync_write || !ops->async_write)
1569 return ERR_PTR(-EINVAL);
1571 ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL);
1573 return ERR_PTR(-ENOMEM);
1575 INIT_WORK(&ucsi->resume_work, ucsi_resume_work);
1576 INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work);
1577 mutex_init(&ucsi->ppm_lock);
1583 EXPORT_SYMBOL_GPL(ucsi_create);
1586 * ucsi_destroy - Free UCSI instance
1587 * @ucsi: UCSI instance to be freed
1589 void ucsi_destroy(struct ucsi *ucsi)
1591 ucsi_debugfs_unregister(ucsi);
1594 EXPORT_SYMBOL_GPL(ucsi_destroy);
1597 * ucsi_register - Register UCSI interface
1598 * @ucsi: UCSI instance
1600 int ucsi_register(struct ucsi *ucsi)
1604 ret = ucsi->ops->read(ucsi, UCSI_VERSION, &ucsi->version,
1605 sizeof(ucsi->version));
1613 * Version format is JJ.M.N (JJ = Major version, M = Minor version,
1614 * N = sub-minor version).
1616 dev_dbg(ucsi->dev, "Registered UCSI interface with version %x.%x.%x",
1617 UCSI_BCD_GET_MAJOR(ucsi->version),
1618 UCSI_BCD_GET_MINOR(ucsi->version),
1619 UCSI_BCD_GET_SUBMINOR(ucsi->version));
1621 queue_delayed_work(system_long_wq, &ucsi->work, 0);
1623 ucsi_debugfs_register(ucsi);
1626 EXPORT_SYMBOL_GPL(ucsi_register);
1629 * ucsi_unregister - Unregister UCSI interface
1630 * @ucsi: UCSI interface to be unregistered
1632 * Unregister UCSI interface that was created with ucsi_register().
1634 void ucsi_unregister(struct ucsi *ucsi)
1636 u64 cmd = UCSI_SET_NOTIFICATION_ENABLE;
1639 /* Make sure that we are not in the middle of driver initialization */
1640 cancel_delayed_work_sync(&ucsi->work);
1641 cancel_work_sync(&ucsi->resume_work);
1643 /* Disable notifications */
1644 ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
1646 if (!ucsi->connector)
1649 for (i = 0; i < ucsi->cap.num_connectors; i++) {
1650 cancel_work_sync(&ucsi->connector[i].work);
1651 ucsi_unregister_partner(&ucsi->connector[i]);
1652 ucsi_unregister_altmodes(&ucsi->connector[i],
1653 UCSI_RECIPIENT_CON);
1654 ucsi_unregister_port_psy(&ucsi->connector[i]);
1656 if (ucsi->connector[i].wq) {
1657 struct ucsi_work *uwork;
1659 mutex_lock(&ucsi->connector[i].lock);
1661 * queue delayed items immediately so they can execute
1662 * and free themselves before the wq is destroyed
1664 list_for_each_entry(uwork, &ucsi->connector[i].partner_tasks, node)
1665 mod_delayed_work(ucsi->connector[i].wq, &uwork->work, 0);
1666 mutex_unlock(&ucsi->connector[i].lock);
1667 destroy_workqueue(ucsi->connector[i].wq);
1670 usb_power_delivery_unregister_capabilities(ucsi->connector[i].port_sink_caps);
1671 ucsi->connector[i].port_sink_caps = NULL;
1672 usb_power_delivery_unregister_capabilities(ucsi->connector[i].port_source_caps);
1673 ucsi->connector[i].port_source_caps = NULL;
1674 usb_power_delivery_unregister(ucsi->connector[i].pd);
1675 ucsi->connector[i].pd = NULL;
1676 typec_unregister_port(ucsi->connector[i].port);
1679 kfree(ucsi->connector);
1681 EXPORT_SYMBOL_GPL(ucsi_unregister);
1683 static int __init ucsi_module_init(void)
1685 ucsi_debugfs_init();
1688 module_init(ucsi_module_init);
1690 static void __exit ucsi_module_exit(void)
1692 ucsi_debugfs_exit();
1694 module_exit(ucsi_module_exit);
1696 MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>");
1697 MODULE_LICENSE("GPL v2");
1698 MODULE_DESCRIPTION("USB Type-C Connector System Software Interface driver");