| @@ -58,6 +58,7 @@ struct cros_typec_port { · 57 unmodified lines |
| 58 | 58 | /* Variables keeping track of switch state. */ |
| 59 | 59 | struct typec_mux_state state; |
| 60 | 60 | uint8_t mux_flags; |
| 61 | + uint8_t role; |
| 61 | 62 | |
| 62 | 63 | /* Port alt modes. */ |
| 63 | 64 | struct typec_altmode p_altmode[CROS_EC_ALTMODE_MAX]; |
| @@ -220,6 +221,9 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec, · 156 unmodified lines |
| 220 | 221 | { |
| 221 | 222 | struct cros_typec_port *port = typec->ports[port_num]; |
| 222 | 223 | |
| 224 | + if (!port->partner) |
| 225 | + return; |
| 226 | + |
| 223 | 227 | cros_typec_unregister_altmodes(typec, port_num, true); |
| 224 | 228 | |
| 225 | 229 | cros_typec_usb_disconnect_state(port); |
| @@ -235,6 +239,9 @@ static void cros_typec_remove_cable(struct cros_typec_data *typec, · 9 unmodified lines |
| 235 | 239 | { |
| 236 | 240 | struct cros_typec_port *port = typec->ports[port_num]; |
| 237 | 241 | |
| 242 | + if (!port->cable) |
| 243 | + return; |
| 244 | + |
| 238 | 245 | cros_typec_unregister_altmodes(typec, port_num, false); |
| 239 | 246 | |
| 240 | 247 | typec_unregister_plug(port->plug); |
| @@ -253,11 +260,8 @@ static void cros_unregister_ports(struct cros_typec_data *typec) · 12 unmodified lines |
| 253 | 260 | if (!typec->ports[i]) |
| 254 | 261 | continue; |
| 255 | 262 | |
| 256 | | − if (typec->ports[i]->partner) |
| 257 | | − cros_typec_remove_partner(typec, i); |
| 258 | | − |
| 259 | | − if (typec->ports[i]->cable) |
| 260 | | − cros_typec_remove_cable(typec, i); |
| 263 | + cros_typec_remove_partner(typec, i); |
| 264 | + cros_typec_remove_cable(typec, i); |
| 261 | 265 | |
| 262 | 266 | usb_role_switch_put(typec->ports[i]->role_sw); |
| 263 | 267 | typec_switch_put(typec->ports[i]->ori_sw); |
| @@ -483,6 +487,11 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec, · 219 unmodified lines |
| 483 | 487 | return -ENOTSUPP; |
| 484 | 488 | } |
| 485 | 489 | |
| 490 | + if (!pd_ctrl->dp_mode) { |
| 491 | + dev_err(typec->dev, "No valid DP mode provided.\n"); |
| 492 | + return -EINVAL; |
| 493 | + } |
| 494 | + |
| 486 | 495 | /* Status VDO. */ |
| 487 | 496 | dp_data.status = DP_STATUS_ENABLED; |
| 488 | 497 | if (port->mux_flags & USB_PD_MUX_HPD_IRQ) |
| @@ -647,11 +656,8 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, · 158 unmodified lines |
| 647 | 656 | "Failed to register partner on port: %d\n", |
| 648 | 657 | port_num); |
| 649 | 658 | } else { |
| 650 | | − if (typec->ports[port_num]->partner) |
| 651 | | − cros_typec_remove_partner(typec, port_num); |
| 652 | | − |
| 653 | | − if (typec->ports[port_num]->cable) |
| 654 | | − cros_typec_remove_cable(typec, port_num); |
| 659 | + cros_typec_remove_partner(typec, port_num); |
| 660 | + cros_typec_remove_cable(typec, port_num); |
| 655 | 661 | } |
| 656 | 662 | } |
| 657 | 663 | |
| @@ -905,6 +911,19 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num · 247 unmodified lines |
| 905 | 911 | return; |
| 906 | 912 | } |
| 907 | 913 | |
| 914 | + /* If we got a hard reset, unregister everything and return. */ |
| 915 | + if (resp.events & PD_STATUS_EVENT_HARD_RESET) { |
| 916 | + cros_typec_remove_partner(typec, port_num); |
| 917 | + cros_typec_remove_cable(typec, port_num); |
| 918 | + |
| 919 | + ret = cros_typec_send_clear_event(typec, port_num, |
| 920 | + PD_STATUS_EVENT_HARD_RESET); |
| 921 | + if (ret < 0) |
| 922 | + dev_warn(typec->dev, |
| 923 | + "Failed hard reset event clear, port: %d\n", port_num); |
| 924 | + return; |
| 925 | + } |
| 926 | + |
| 908 | 927 | /* Handle any events appropriately. */ |
| 909 | 928 | if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE && !typec->ports[port_num]->sop_disc_done) { |
| 910 | 929 | u16 sop_revision; |
| @@ -995,10 +1014,12 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) · 84 unmodified lines |
| 995 | 1014 | } |
| 996 | 1015 | |
| 997 | 1016 | /* No change needs to be made, let's exit early. */ |
| 998 | | − if (typec->ports[port_num]->mux_flags == mux_resp.flags) |
| 1017 | + if (typec->ports[port_num]->mux_flags == mux_resp.flags && |
| 1018 | + typec->ports[port_num]->role == resp.role) |
| 999 | 1019 | return 0; |
| 1000 | 1020 | |
| 1001 | 1021 | typec->ports[port_num]->mux_flags = mux_resp.flags; |
| 1022 | + typec->ports[port_num]->role = resp.role; |
| 1002 | 1023 | ret = cros_typec_configure_mux(typec, port_num, mux_resp.flags, &resp); |
| 1003 | 1024 | if (ret) |
| 1004 | 1025 | dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret); |
| @@ -1027,8 +1048,8 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec) · 22 unmodified lines |
| 1027 | 1048 | else |
| 1028 | 1049 | typec->pd_ctrl_ver = 0; |
| 1029 | 1050 | |
| 1030 | | − dev_dbg(typec->dev, "PD Control has version mask 0x%hhx\n", |
| 1031 | | − typec->pd_ctrl_ver); |
| 1051 | + dev_dbg(typec->dev, "PD Control has version mask 0x%02x\n", |
| 1052 | + typec->pd_ctrl_ver & 0xff); |
| 1032 | 1053 | |
| 1033 | 1054 | return 0; |
| 1034 | 1055 | } |