Loading drivers/usb/pd/policy_engine.c +103 −45 Original line number Diff line number Diff line Loading @@ -135,6 +135,14 @@ enum usbpd_control_msg_type { MSG_GET_COUNTRY_CODES, }; static const char * const usbpd_control_msg_strings[] = { "", "GoodCRC", "GotoMin", "Accept", "Reject", "Ping", "PS_RDY", "Get_Source_Cap", "Get_Sink_Cap", "DR_Swap", "PR_Swap", "VCONN_Swap", "Wait", "Soft_Reset", "", "", "Not_Supported", "Get_Source_Cap_Extended", "Get_Status", "FR_Swap", "Get_PPS_Status", "Get_Country_Codes", }; enum usbpd_data_msg_type { MSG_SOURCE_CAPABILITIES = 1, MSG_REQUEST, Loading @@ -146,6 +154,12 @@ enum usbpd_data_msg_type { MSG_VDM = 0xF, }; static const char * const usbpd_data_msg_strings[] = { "", "Source_Capabilities", "Request", "BIST", "Sink_Capabilities", "Battery_Status", "Alert", "Get_Country_Info", "", "", "", "", "", "", "", "Vendor_Defined", }; enum usbpd_ext_msg_type { MSG_SOURCE_CAPABILITIES_EXTENDED = 1, MSG_STATUS, Loading @@ -163,6 +177,29 @@ enum usbpd_ext_msg_type { MSG_COUNTRY_CODES, }; static const char * const usbpd_ext_msg_strings[] = { "", "Source_Capabilities_Extended", "Status", "Get_Battery_Cap", "Get_Battery_Status", "Get_Manufacturer_Info", "Manufacturer_Info", "Security_Request", "Security_Response", "Firmware_Update_Request", "Firmware_Update_Response", "PPS_Status", "Country_Info", "Country_Codes", }; static inline const char *msg_to_string(u8 id, bool is_data, bool is_ext) { if (is_ext) { if (id < ARRAY_SIZE(usbpd_ext_msg_strings)) return usbpd_ext_msg_strings[id]; } else if (is_data) { if (id < ARRAY_SIZE(usbpd_data_msg_strings)) return usbpd_data_msg_strings[id]; } else if (id < ARRAY_SIZE(usbpd_control_msg_strings)) { return usbpd_control_msg_strings[id]; } return "Invalid"; } enum vdm_state { VDM_NONE, DISCOVERED_ID, Loading Loading @@ -656,8 +693,12 @@ static int pd_send_msg(struct usbpd *pd, u8 msg_type, const u32 *data, pd->tx_msgid, num_data, pd->spec_rev); ret = pd_phy_write(hdr, (u8 *)data, num_data * sizeof(u32), sop); if (ret) if (ret) { usbpd_err(&pd->dev, "Error sending %s: %d\n", msg_to_string(msg_type, num_data, false), ret); return ret; } pd->tx_msgid = (pd->tx_msgid + 1) & PD_MAX_MSG_ID; return 0; Loading Loading @@ -697,8 +738,12 @@ static int pd_send_ext_msg(struct usbpd *pd, u8 msg_type, PD_MSG_HDR_EXTENDED; ret = pd_phy_write(hdr, chunked_payload, num_objs * sizeof(u32), sop); if (ret) if (ret) { usbpd_err(&pd->dev, "Error sending %s: %d\n", usbpd_ext_msg_strings[msg_type], ret); return ret; } pd->tx_msgid = (pd->tx_msgid + 1) & PD_MAX_MSG_ID; Loading Loading @@ -1013,6 +1058,7 @@ static void phy_msg_received(struct usbpd *pd, enum pd_sop_type sop, struct rx_msg *rx_msg; unsigned long flags; u16 header; u8 msg_type, num_objs; if (sop == SOPII_MSG) { usbpd_err(&pd->dev, "only SOP/SOP' supported\n"); Loading Loading @@ -1057,8 +1103,12 @@ static void phy_msg_received(struct usbpd *pd, enum pd_sop_type sop, if (PD_MSG_HDR_REV(header) < pd->spec_rev) pd->spec_rev = PD_MSG_HDR_REV(header); usbpd_dbg(&pd->dev, "received message: type(%d) num_objs(%d)\n", PD_MSG_HDR_TYPE(header), PD_MSG_HDR_COUNT(header)); msg_type = PD_MSG_HDR_TYPE(header); num_objs = PD_MSG_HDR_COUNT(header); usbpd_dbg(&pd->dev, "%s type(%d) num_objs(%d)\n", msg_to_string(msg_type, num_objs, PD_MSG_HDR_IS_EXTENDED(header)), msg_type, num_objs); if (!PD_MSG_HDR_IS_EXTENDED(header)) { rx_msg = kzalloc(sizeof(*rx_msg) + len, GFP_ATOMIC); Loading Loading @@ -1106,6 +1156,47 @@ static enum hrtimer_restart pd_timeout(struct hrtimer *timer) return HRTIMER_NORESTART; } static void log_decoded_request(struct usbpd *pd, u32 rdo) { const u32 *pdos; int pos = PD_RDO_OBJ_POS(rdo); int type; usbpd_dbg(&pd->dev, "RDO: 0x%08x\n", pd->rdo); if (pd->current_pr == PR_SINK) pdos = pd->received_pdos; else pdos = default_src_caps; type = PD_SRC_PDO_TYPE(pdos[pos - 1]); switch (type) { case PD_SRC_PDO_TYPE_FIXED: case PD_SRC_PDO_TYPE_VARIABLE: usbpd_dbg(&pd->dev, "Request Fixed/Variable PDO:%d Volt:%dmV OpCurr:%dmA Curr:%dmA\n", pos, PD_SRC_PDO_FIXED_VOLTAGE(pdos[pos - 1]) * 50, PD_RDO_FIXED_CURR(rdo) * 10, PD_RDO_FIXED_CURR_MINMAX(rdo) * 10); break; case PD_SRC_PDO_TYPE_BATTERY: usbpd_dbg(&pd->dev, "Request Battery PDO:%d OpPow:%dmW Pow:%dmW\n", pos, PD_RDO_FIXED_CURR(rdo) * 250, PD_RDO_FIXED_CURR_MINMAX(rdo) * 250); break; case PD_SRC_PDO_TYPE_AUGMENTED: usbpd_dbg(&pd->dev, "Request PPS PDO:%d Volt:%dmV Curr:%dmA\n", pos, PD_RDO_PROG_VOLTAGE(rdo) * 20, PD_RDO_PROG_CURR(rdo) * 50); break; } } /* Enters new state and executes actions on entry */ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) { Loading Loading @@ -1229,6 +1320,7 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) break; case PE_SRC_NEGOTIATE_CAPABILITY: log_decoded_request(pd, pd->rdo); pd->peer_usb_comm = PD_RDO_USB_COMM(pd->rdo); if (PD_RDO_OBJ_POS(pd->rdo) != 1 || Loading @@ -1239,7 +1331,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) /* send Reject */ ret = pd_send_msg(pd, MSG_REJECT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Reject\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -1261,7 +1352,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) /* PE_SRC_TRANSITION_SUPPLY pseudo-state */ ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -1277,7 +1367,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) */ ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading Loading @@ -1336,7 +1425,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) ret = pd_send_msg(pd, MSG_SOFT_RESET, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Soft Reset, do Hard Reset\n"); usbpd_set_state(pd, pd->current_pr == PR_SRC ? PE_SRC_HARD_RESET : PE_SNK_HARD_RESET); break; Loading Loading @@ -1418,9 +1506,10 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) /* fall-through */ case PE_SNK_SELECT_CAPABILITY: log_decoded_request(pd, pd->rdo); ret = pd_send_msg(pd, MSG_REQUEST, &pd->rdo, 1, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Request\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading Loading @@ -1948,7 +2037,6 @@ static void vconn_swap(struct usbpd *pd) ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, pd->current_pr == PR_SRC ? PE_SRC_SEND_SOFT_RESET : PE_SNK_SEND_SOFT_RESET); Loading Loading @@ -2275,10 +2363,8 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_SINK_CAPABILITIES, pd->sink_caps, pd->num_sink_caps, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Sink Caps\n"); if (ret) usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); } } else if (IS_DATA(rx_msg, MSG_REQUEST)) { pd->rdo = *(u32 *)rx_msg->payload; usbpd_set_state(pd, PE_SRC_NEGOTIATE_CAPABILITY); Loading @@ -2290,7 +2376,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2300,7 +2385,6 @@ static void usbpd_sm(struct work_struct *w) /* we'll happily accept Src->Sink requests anytime */ ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2310,7 +2394,6 @@ static void usbpd_sm(struct work_struct *w) } else if (IS_CTRL(rx_msg, MSG_VCONN_SWAP)) { ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2322,16 +2405,13 @@ static void usbpd_sm(struct work_struct *w) /* unhandled messages */ ret = pd_send_msg(pd, MSG_NOT_SUPPORTED, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Not supported\n"); if (ret) usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); } break; } else if (pd->send_pr_swap) { pd->send_pr_swap = false; ret = pd_send_msg(pd, MSG_PR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PR Swap\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2342,7 +2422,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_dr_swap = false; ret = pd_send_msg(pd, MSG_DR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending DR Swap\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading Loading @@ -2550,17 +2629,14 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_SINK_CAPABILITIES, pd->sink_caps, pd->num_sink_caps, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Sink Caps\n"); if (ret) usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); } } else if (IS_CTRL(rx_msg, MSG_GET_SOURCE_CAP) && pd->spec_rev == USBPD_REV_20) { ret = pd_send_msg(pd, MSG_SOURCE_CAPABILITIES, default_src_caps, ARRAY_SIZE(default_src_caps), SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending SRC CAPs\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2572,7 +2648,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2583,7 +2658,6 @@ static void usbpd_sm(struct work_struct *w) /* TODO: should we Reject in certain circumstances? */ ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2600,18 +2674,15 @@ static void usbpd_sm(struct work_struct *w) (pd->requested_voltage > 5000000)) { ret = pd_send_msg(pd, MSG_REJECT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Reject\n"); if (ret) usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); } break; } ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2624,7 +2695,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_GET_SOURCE_CAP_EXTENDED, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_src_cap_ext\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2643,7 +2713,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_GET_PPS_STATUS, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_pps_status\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading Loading @@ -2678,7 +2747,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_get_status = false; ret = pd_send_msg(pd, MSG_GET_STATUS, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_status\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2696,7 +2764,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_ext_msg(pd, MSG_GET_BATTERY_CAP, &pd->get_battery_cap_db, 1, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_battery_cap\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2715,7 +2782,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_ext_msg(pd, MSG_GET_BATTERY_STATUS, &pd->get_battery_status_db, 1, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_battery_status\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2733,10 +2799,8 @@ static void usbpd_sm(struct work_struct *w) /* unhandled messages */ ret = pd_send_msg(pd, MSG_NOT_SUPPORTED, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Not supported\n"); if (ret) usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); } break; } else if (pd->send_request) { pd->send_request = false; Loading @@ -2745,7 +2809,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_pr_swap = false; ret = pd_send_msg(pd, MSG_PR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PR Swap\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2756,7 +2819,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_dr_swap = false; ret = pd_send_msg(pd, MSG_DR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending DR Swap\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2778,8 +2840,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "%s: Error sending Accept, do Hard Reset\n", usbpd_state_strings[pd->current_state]); usbpd_set_state(pd, pd->current_pr == PR_SRC ? PE_SRC_HARD_RESET : PE_SNK_HARD_RESET); break; Loading Loading @@ -2864,7 +2924,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, PE_ERROR_RECOVERY); break; } Loading Loading @@ -2908,7 +2967,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, PE_ERROR_RECOVERY); break; } Loading Loading
drivers/usb/pd/policy_engine.c +103 −45 Original line number Diff line number Diff line Loading @@ -135,6 +135,14 @@ enum usbpd_control_msg_type { MSG_GET_COUNTRY_CODES, }; static const char * const usbpd_control_msg_strings[] = { "", "GoodCRC", "GotoMin", "Accept", "Reject", "Ping", "PS_RDY", "Get_Source_Cap", "Get_Sink_Cap", "DR_Swap", "PR_Swap", "VCONN_Swap", "Wait", "Soft_Reset", "", "", "Not_Supported", "Get_Source_Cap_Extended", "Get_Status", "FR_Swap", "Get_PPS_Status", "Get_Country_Codes", }; enum usbpd_data_msg_type { MSG_SOURCE_CAPABILITIES = 1, MSG_REQUEST, Loading @@ -146,6 +154,12 @@ enum usbpd_data_msg_type { MSG_VDM = 0xF, }; static const char * const usbpd_data_msg_strings[] = { "", "Source_Capabilities", "Request", "BIST", "Sink_Capabilities", "Battery_Status", "Alert", "Get_Country_Info", "", "", "", "", "", "", "", "Vendor_Defined", }; enum usbpd_ext_msg_type { MSG_SOURCE_CAPABILITIES_EXTENDED = 1, MSG_STATUS, Loading @@ -163,6 +177,29 @@ enum usbpd_ext_msg_type { MSG_COUNTRY_CODES, }; static const char * const usbpd_ext_msg_strings[] = { "", "Source_Capabilities_Extended", "Status", "Get_Battery_Cap", "Get_Battery_Status", "Get_Manufacturer_Info", "Manufacturer_Info", "Security_Request", "Security_Response", "Firmware_Update_Request", "Firmware_Update_Response", "PPS_Status", "Country_Info", "Country_Codes", }; static inline const char *msg_to_string(u8 id, bool is_data, bool is_ext) { if (is_ext) { if (id < ARRAY_SIZE(usbpd_ext_msg_strings)) return usbpd_ext_msg_strings[id]; } else if (is_data) { if (id < ARRAY_SIZE(usbpd_data_msg_strings)) return usbpd_data_msg_strings[id]; } else if (id < ARRAY_SIZE(usbpd_control_msg_strings)) { return usbpd_control_msg_strings[id]; } return "Invalid"; } enum vdm_state { VDM_NONE, DISCOVERED_ID, Loading Loading @@ -656,8 +693,12 @@ static int pd_send_msg(struct usbpd *pd, u8 msg_type, const u32 *data, pd->tx_msgid, num_data, pd->spec_rev); ret = pd_phy_write(hdr, (u8 *)data, num_data * sizeof(u32), sop); if (ret) if (ret) { usbpd_err(&pd->dev, "Error sending %s: %d\n", msg_to_string(msg_type, num_data, false), ret); return ret; } pd->tx_msgid = (pd->tx_msgid + 1) & PD_MAX_MSG_ID; return 0; Loading Loading @@ -697,8 +738,12 @@ static int pd_send_ext_msg(struct usbpd *pd, u8 msg_type, PD_MSG_HDR_EXTENDED; ret = pd_phy_write(hdr, chunked_payload, num_objs * sizeof(u32), sop); if (ret) if (ret) { usbpd_err(&pd->dev, "Error sending %s: %d\n", usbpd_ext_msg_strings[msg_type], ret); return ret; } pd->tx_msgid = (pd->tx_msgid + 1) & PD_MAX_MSG_ID; Loading Loading @@ -1013,6 +1058,7 @@ static void phy_msg_received(struct usbpd *pd, enum pd_sop_type sop, struct rx_msg *rx_msg; unsigned long flags; u16 header; u8 msg_type, num_objs; if (sop == SOPII_MSG) { usbpd_err(&pd->dev, "only SOP/SOP' supported\n"); Loading Loading @@ -1057,8 +1103,12 @@ static void phy_msg_received(struct usbpd *pd, enum pd_sop_type sop, if (PD_MSG_HDR_REV(header) < pd->spec_rev) pd->spec_rev = PD_MSG_HDR_REV(header); usbpd_dbg(&pd->dev, "received message: type(%d) num_objs(%d)\n", PD_MSG_HDR_TYPE(header), PD_MSG_HDR_COUNT(header)); msg_type = PD_MSG_HDR_TYPE(header); num_objs = PD_MSG_HDR_COUNT(header); usbpd_dbg(&pd->dev, "%s type(%d) num_objs(%d)\n", msg_to_string(msg_type, num_objs, PD_MSG_HDR_IS_EXTENDED(header)), msg_type, num_objs); if (!PD_MSG_HDR_IS_EXTENDED(header)) { rx_msg = kzalloc(sizeof(*rx_msg) + len, GFP_ATOMIC); Loading Loading @@ -1106,6 +1156,47 @@ static enum hrtimer_restart pd_timeout(struct hrtimer *timer) return HRTIMER_NORESTART; } static void log_decoded_request(struct usbpd *pd, u32 rdo) { const u32 *pdos; int pos = PD_RDO_OBJ_POS(rdo); int type; usbpd_dbg(&pd->dev, "RDO: 0x%08x\n", pd->rdo); if (pd->current_pr == PR_SINK) pdos = pd->received_pdos; else pdos = default_src_caps; type = PD_SRC_PDO_TYPE(pdos[pos - 1]); switch (type) { case PD_SRC_PDO_TYPE_FIXED: case PD_SRC_PDO_TYPE_VARIABLE: usbpd_dbg(&pd->dev, "Request Fixed/Variable PDO:%d Volt:%dmV OpCurr:%dmA Curr:%dmA\n", pos, PD_SRC_PDO_FIXED_VOLTAGE(pdos[pos - 1]) * 50, PD_RDO_FIXED_CURR(rdo) * 10, PD_RDO_FIXED_CURR_MINMAX(rdo) * 10); break; case PD_SRC_PDO_TYPE_BATTERY: usbpd_dbg(&pd->dev, "Request Battery PDO:%d OpPow:%dmW Pow:%dmW\n", pos, PD_RDO_FIXED_CURR(rdo) * 250, PD_RDO_FIXED_CURR_MINMAX(rdo) * 250); break; case PD_SRC_PDO_TYPE_AUGMENTED: usbpd_dbg(&pd->dev, "Request PPS PDO:%d Volt:%dmV Curr:%dmA\n", pos, PD_RDO_PROG_VOLTAGE(rdo) * 20, PD_RDO_PROG_CURR(rdo) * 50); break; } } /* Enters new state and executes actions on entry */ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) { Loading Loading @@ -1229,6 +1320,7 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) break; case PE_SRC_NEGOTIATE_CAPABILITY: log_decoded_request(pd, pd->rdo); pd->peer_usb_comm = PD_RDO_USB_COMM(pd->rdo); if (PD_RDO_OBJ_POS(pd->rdo) != 1 || Loading @@ -1239,7 +1331,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) /* send Reject */ ret = pd_send_msg(pd, MSG_REJECT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Reject\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -1261,7 +1352,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) /* PE_SRC_TRANSITION_SUPPLY pseudo-state */ ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -1277,7 +1367,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) */ ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading Loading @@ -1336,7 +1425,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) ret = pd_send_msg(pd, MSG_SOFT_RESET, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Soft Reset, do Hard Reset\n"); usbpd_set_state(pd, pd->current_pr == PR_SRC ? PE_SRC_HARD_RESET : PE_SNK_HARD_RESET); break; Loading Loading @@ -1418,9 +1506,10 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state) /* fall-through */ case PE_SNK_SELECT_CAPABILITY: log_decoded_request(pd, pd->rdo); ret = pd_send_msg(pd, MSG_REQUEST, &pd->rdo, 1, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Request\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading Loading @@ -1948,7 +2037,6 @@ static void vconn_swap(struct usbpd *pd) ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, pd->current_pr == PR_SRC ? PE_SRC_SEND_SOFT_RESET : PE_SNK_SEND_SOFT_RESET); Loading Loading @@ -2275,10 +2363,8 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_SINK_CAPABILITIES, pd->sink_caps, pd->num_sink_caps, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Sink Caps\n"); if (ret) usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); } } else if (IS_DATA(rx_msg, MSG_REQUEST)) { pd->rdo = *(u32 *)rx_msg->payload; usbpd_set_state(pd, PE_SRC_NEGOTIATE_CAPABILITY); Loading @@ -2290,7 +2376,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2300,7 +2385,6 @@ static void usbpd_sm(struct work_struct *w) /* we'll happily accept Src->Sink requests anytime */ ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2310,7 +2394,6 @@ static void usbpd_sm(struct work_struct *w) } else if (IS_CTRL(rx_msg, MSG_VCONN_SWAP)) { ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2322,16 +2405,13 @@ static void usbpd_sm(struct work_struct *w) /* unhandled messages */ ret = pd_send_msg(pd, MSG_NOT_SUPPORTED, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Not supported\n"); if (ret) usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); } break; } else if (pd->send_pr_swap) { pd->send_pr_swap = false; ret = pd_send_msg(pd, MSG_PR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PR Swap\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2342,7 +2422,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_dr_swap = false; ret = pd_send_msg(pd, MSG_DR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending DR Swap\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading Loading @@ -2550,17 +2629,14 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_SINK_CAPABILITIES, pd->sink_caps, pd->num_sink_caps, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Sink Caps\n"); if (ret) usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); } } else if (IS_CTRL(rx_msg, MSG_GET_SOURCE_CAP) && pd->spec_rev == USBPD_REV_20) { ret = pd_send_msg(pd, MSG_SOURCE_CAPABILITIES, default_src_caps, ARRAY_SIZE(default_src_caps), SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending SRC CAPs\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2572,7 +2648,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET); break; } Loading @@ -2583,7 +2658,6 @@ static void usbpd_sm(struct work_struct *w) /* TODO: should we Reject in certain circumstances? */ ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2600,18 +2674,15 @@ static void usbpd_sm(struct work_struct *w) (pd->requested_voltage > 5000000)) { ret = pd_send_msg(pd, MSG_REJECT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Reject\n"); if (ret) usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); } break; } ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Accept\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2624,7 +2695,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_GET_SOURCE_CAP_EXTENDED, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_src_cap_ext\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2643,7 +2713,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_GET_PPS_STATUS, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_pps_status\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading Loading @@ -2678,7 +2747,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_get_status = false; ret = pd_send_msg(pd, MSG_GET_STATUS, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_status\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2696,7 +2764,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_ext_msg(pd, MSG_GET_BATTERY_CAP, &pd->get_battery_cap_db, 1, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_battery_cap\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2715,7 +2782,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_ext_msg(pd, MSG_GET_BATTERY_STATUS, &pd->get_battery_status_db, 1, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending get_battery_status\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2733,10 +2799,8 @@ static void usbpd_sm(struct work_struct *w) /* unhandled messages */ ret = pd_send_msg(pd, MSG_NOT_SUPPORTED, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending Not supported\n"); if (ret) usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); } break; } else if (pd->send_request) { pd->send_request = false; Loading @@ -2745,7 +2809,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_pr_swap = false; ret = pd_send_msg(pd, MSG_PR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PR Swap\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2756,7 +2819,6 @@ static void usbpd_sm(struct work_struct *w) pd->send_dr_swap = false; ret = pd_send_msg(pd, MSG_DR_SWAP, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending DR Swap\n"); usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET); break; } Loading @@ -2778,8 +2840,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "%s: Error sending Accept, do Hard Reset\n", usbpd_state_strings[pd->current_state]); usbpd_set_state(pd, pd->current_pr == PR_SRC ? PE_SRC_HARD_RESET : PE_SNK_HARD_RESET); break; Loading Loading @@ -2864,7 +2924,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, PE_ERROR_RECOVERY); break; } Loading Loading @@ -2908,7 +2967,6 @@ static void usbpd_sm(struct work_struct *w) ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG); if (ret) { usbpd_err(&pd->dev, "Error sending PS_RDY\n"); usbpd_set_state(pd, PE_ERROR_RECOVERY); break; } Loading