Skip to content

Commit 0d8495d

Browse files
author
Prashant Malani
committed
platform/chrome: cros_ec_typec: Get mux state inside configure_mux
Move the function which gets current mux state inside the cros_typec_configure_mux() function. It is better to group those bits of functionality together, and it makes it easier to move around cros_typec_configure_mux() later. While we are doing this, also inline the cros_typec_get_mux_info() inside of cros_typec_configure_mux(). Signed-off-by: Prashant Malani <pmalani@chromium.org> Reviewed-by: Tzung-Bi Shih <tzungbi@google.com> Link: https://lore.kernel.org/chrome-platform/20220208184721.1697194-3-pmalani@chromium.org/
1 parent 53a0023 commit 0d8495d

1 file changed

Lines changed: 23 additions & 32 deletions

File tree

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -513,27 +513,38 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
513513
}
514514

515515
static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
516-
uint8_t mux_flags,
517516
struct ec_response_usb_pd_control_v2 *pd_ctrl)
518517
{
519518
struct cros_typec_port *port = typec->ports[port_num];
519+
struct ec_response_usb_pd_mux_info resp;
520+
struct ec_params_usb_pd_mux_info req = {
521+
.port = port_num,
522+
};
520523
struct ec_params_usb_pd_mux_ack mux_ack;
521524
enum typec_orientation orientation;
522525
int ret;
523526

527+
ret = cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO,
528+
&req, sizeof(req), &resp, sizeof(resp));
529+
if (ret < 0) {
530+
dev_warn(typec->dev, "Failed to get mux info for port: %d, err = %d\n",
531+
port_num, ret);
532+
return ret;
533+
}
534+
524535
/* No change needs to be made, let's exit early. */
525-
if (port->mux_flags == mux_flags && port->role == pd_ctrl->role)
536+
if (port->mux_flags == resp.flags && port->role == pd_ctrl->role)
526537
return 0;
527538

528-
port->mux_flags = mux_flags;
539+
port->mux_flags = resp.flags;
529540
port->role = pd_ctrl->role;
530541

531-
if (mux_flags == USB_PD_MUX_NONE) {
542+
if (port->mux_flags == USB_PD_MUX_NONE) {
532543
ret = cros_typec_usb_disconnect_state(port);
533544
goto mux_ack;
534545
}
535546

536-
if (mux_flags & USB_PD_MUX_POLARITY_INVERTED)
547+
if (port->mux_flags & USB_PD_MUX_POLARITY_INVERTED)
537548
orientation = TYPEC_ORIENTATION_REVERSE;
538549
else
539550
orientation = TYPEC_ORIENTATION_NORMAL;
@@ -548,22 +559,22 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
548559
if (ret)
549560
return ret;
550561

551-
if (mux_flags & USB_PD_MUX_USB4_ENABLED) {
562+
if (port->mux_flags & USB_PD_MUX_USB4_ENABLED) {
552563
ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl);
553-
} else if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
564+
} else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) {
554565
ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl);
555-
} else if (mux_flags & USB_PD_MUX_DP_ENABLED) {
566+
} else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) {
556567
ret = cros_typec_enable_dp(typec, port_num, pd_ctrl);
557-
} else if (mux_flags & USB_PD_MUX_SAFE_MODE) {
568+
} else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) {
558569
ret = cros_typec_usb_safe_state(port);
559-
} else if (mux_flags & USB_PD_MUX_USB_ENABLED) {
570+
} else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) {
560571
port->state.alt = NULL;
561572
port->state.mode = TYPEC_STATE_USB;
562573
ret = typec_mux_set(port->mux, &port->state);
563574
} else {
564575
dev_dbg(typec->dev,
565576
"Unrecognized mode requested, mux flags: %x\n",
566-
mux_flags);
577+
port->mux_flags);
567578
}
568579

569580
mux_ack:
@@ -638,17 +649,6 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec,
638649
}
639650
}
640651

641-
static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num,
642-
struct ec_response_usb_pd_mux_info *resp)
643-
{
644-
struct ec_params_usb_pd_mux_info req = {
645-
.port = port_num,
646-
};
647-
648-
return cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
649-
sizeof(req), resp, sizeof(*resp));
650-
}
651-
652652
/*
653653
* Helper function to register partner/plug altmodes.
654654
*/
@@ -946,7 +946,6 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
946946
{
947947
struct ec_params_usb_pd_control req;
948948
struct ec_response_usb_pd_control_v2 resp;
949-
struct ec_response_usb_pd_mux_info mux_resp;
950949
int ret;
951950

952951
if (port_num < 0 || port_num >= typec->num_ports) {
@@ -982,15 +981,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
982981
cros_typec_handle_status(typec, port_num);
983982

984983
/* Update the switches if they exist, according to requested state */
985-
ret = cros_typec_get_mux_info(typec, port_num, &mux_resp);
986-
if (ret < 0) {
987-
dev_warn(typec->dev,
988-
"Failed to get mux info for port: %d, err = %d\n",
989-
port_num, ret);
990-
return 0;
991-
}
992-
993-
ret = cros_typec_configure_mux(typec, port_num, mux_resp.flags, &resp);
984+
ret = cros_typec_configure_mux(typec, port_num, &resp);
994985
if (ret)
995986
dev_warn(typec->dev, "Configure muxes failed, err = %d\n", ret);
996987

0 commit comments

Comments
 (0)