From e5ba48784875afbfc94fe0649fb419f138ea1488 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 14 May 2021 14:32:49 +0200 Subject: [PATCH] Revert "usb: typec: tcpm: Address incorrect values of tcpm psy for pps supply" This reverts commit 9d7bb10859b9f7bd72c987369e005e633fe86c12 which is commit e3a0720224873587954b55d193d5b4abb14f0443 upstream in 5.4.119 as it breaks the kernel abi. If it needs to come back, it needs to be done in an abi-preserving way. Bug: 161946584 Cc: Badhri Jagan Sridharan Signed-off-by: Greg Kroah-Hartman Change-Id: I775217d3cbf88fb65a1a90cb68fd2ff80c7ddb62 --- drivers/usb/typec/tcpm/tcpm.c | 88 ++++++++++++++--------------------- 1 file changed, 35 insertions(+), 53 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 4575cf047b6f..f7da2d607857 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -181,27 +181,12 @@ struct pd_mode_data { struct typec_altmode_desc altmode_desc[ALTMODE_DISCOVERY_MAX]; }; -/* - * @min_volt: Actual min voltage at the local port - * @req_min_volt: Requested min voltage to the port partner - * @max_volt: Actual max voltage at the local port - * @req_max_volt: Requested max voltage to the port partner - * @max_curr: Actual max current at the local port - * @req_max_curr: Requested max current of the port partner - * @req_out_volt: Requested output voltage to the port partner - * @req_op_curr: Requested operating current to the port partner - * @supported: Parter has atleast one APDO hence supports PPS - * @active: PPS mode is active - */ struct pd_pps_data { u32 min_volt; - u32 req_min_volt; u32 max_volt; - u32 req_max_volt; u32 max_curr; - u32 req_max_curr; - u32 req_out_volt; - u32 req_op_curr; + u32 out_volt; + u32 op_curr; bool supported; bool active; }; @@ -1776,8 +1761,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, break; case SNK_NEGOTIATE_PPS_CAPABILITIES: /* Revert data back from any requested PPS updates */ - port->pps_data.req_out_volt = port->supply_voltage; - port->pps_data.req_op_curr = port->current_limit; + port->pps_data.out_volt = port->supply_voltage; + port->pps_data.op_curr = port->current_limit; port->pps_status = (type == PD_CTRL_WAIT ? -EAGAIN : -EOPNOTSUPP); tcpm_set_state(port, SNK_READY, 0); @@ -1809,11 +1794,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, break; case SNK_NEGOTIATE_PPS_CAPABILITIES: port->pps_data.active = true; - port->pps_data.min_volt = port->pps_data.req_min_volt; - port->pps_data.max_volt = port->pps_data.req_max_volt; - port->pps_data.max_curr = port->pps_data.req_max_curr; - port->req_supply_voltage = port->pps_data.req_out_volt; - port->req_current_limit = port->pps_data.req_op_curr; + port->req_supply_voltage = port->pps_data.out_volt; + port->req_current_limit = port->pps_data.op_curr; tcpm_set_state(port, SNK_TRANSITION_SINK, 0); break; case SOFT_RESET_SEND: @@ -2327,16 +2309,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port) src = port->source_caps[src_pdo]; snk = port->snk_pdo[snk_pdo]; - port->pps_data.req_min_volt = max(pdo_pps_apdo_min_voltage(src), - pdo_pps_apdo_min_voltage(snk)); - port->pps_data.req_max_volt = min(pdo_pps_apdo_max_voltage(src), - pdo_pps_apdo_max_voltage(snk)); - port->pps_data.req_max_curr = min_pps_apdo_current(src, snk); - port->pps_data.req_out_volt = min(port->pps_data.max_volt, - max(port->pps_data.min_volt, - port->pps_data.req_out_volt)); - port->pps_data.req_op_curr = min(port->pps_data.max_curr, - port->pps_data.req_op_curr); + port->pps_data.min_volt = max(pdo_pps_apdo_min_voltage(src), + pdo_pps_apdo_min_voltage(snk)); + port->pps_data.max_volt = min(pdo_pps_apdo_max_voltage(src), + pdo_pps_apdo_max_voltage(snk)); + port->pps_data.max_curr = min_pps_apdo_current(src, snk); + port->pps_data.out_volt = min(port->pps_data.max_volt, + max(port->pps_data.min_volt, + port->pps_data.out_volt)); + port->pps_data.op_curr = min(port->pps_data.max_curr, + port->pps_data.op_curr); power_supply_changed(port->psy); } @@ -2464,10 +2446,10 @@ static int tcpm_pd_build_pps_request(struct tcpm_port *port, u32 *rdo) tcpm_log(port, "Invalid APDO selected!"); return -EINVAL; } - max_mv = port->pps_data.req_max_volt; - max_ma = port->pps_data.req_max_curr; - out_mv = port->pps_data.req_out_volt; - op_ma = port->pps_data.req_op_curr; + max_mv = port->pps_data.max_volt; + max_ma = port->pps_data.max_curr; + out_mv = port->pps_data.out_volt; + op_ma = port->pps_data.op_curr; break; default: tcpm_log(port, "Invalid PDO selected!"); @@ -2514,8 +2496,8 @@ static int tcpm_pd_build_pps_request(struct tcpm_port *port, u32 *rdo) tcpm_log(port, "Requesting APDO %d: %u mV, %u mA", src_pdo_index, out_mv, op_ma); - port->pps_data.req_op_curr = op_ma; - port->pps_data.req_out_volt = out_mv; + port->pps_data.op_curr = op_ma; + port->pps_data.out_volt = out_mv; return 0; } @@ -4183,7 +4165,7 @@ static int tcpm_try_role(struct typec_port *p, int role) return ret; } -static int tcpm_pps_set_op_curr(struct tcpm_port *port, u16 req_op_curr) +static int tcpm_pps_set_op_curr(struct tcpm_port *port, u16 op_curr) { unsigned int target_mw; int ret; @@ -4201,22 +4183,22 @@ static int tcpm_pps_set_op_curr(struct tcpm_port *port, u16 req_op_curr) goto port_unlock; } - if (req_op_curr > port->pps_data.max_curr) { + if (op_curr > port->pps_data.max_curr) { ret = -EINVAL; goto port_unlock; } - target_mw = (req_op_curr * port->supply_voltage) / 1000; + target_mw = (op_curr * port->pps_data.out_volt) / 1000; if (target_mw < port->operating_snk_mw) { ret = -EINVAL; goto port_unlock; } /* Round down operating current to align with PPS valid steps */ - req_op_curr = req_op_curr - (req_op_curr % RDO_PROG_CURR_MA_STEP); + op_curr = op_curr - (op_curr % RDO_PROG_CURR_MA_STEP); reinit_completion(&port->pps_complete); - port->pps_data.req_op_curr = req_op_curr; + port->pps_data.op_curr = op_curr; port->pps_status = 0; port->pps_pending = true; tcpm_set_state(port, SNK_NEGOTIATE_PPS_CAPABILITIES, 0); @@ -4238,7 +4220,7 @@ swap_unlock: return ret; } -static int tcpm_pps_set_out_volt(struct tcpm_port *port, u16 req_out_volt) +static int tcpm_pps_set_out_volt(struct tcpm_port *port, u16 out_volt) { unsigned int target_mw; int ret; @@ -4256,23 +4238,23 @@ static int tcpm_pps_set_out_volt(struct tcpm_port *port, u16 req_out_volt) goto port_unlock; } - if (req_out_volt < port->pps_data.min_volt || - req_out_volt > port->pps_data.max_volt) { + if (out_volt < port->pps_data.min_volt || + out_volt > port->pps_data.max_volt) { ret = -EINVAL; goto port_unlock; } - target_mw = (port->current_limit * req_out_volt) / 1000; + target_mw = (port->pps_data.op_curr * out_volt) / 1000; if (target_mw < port->operating_snk_mw) { ret = -EINVAL; goto port_unlock; } /* Round down output voltage to align with PPS valid steps */ - req_out_volt = req_out_volt - (req_out_volt % RDO_PROG_VOLT_MV_STEP); + out_volt = out_volt - (out_volt % RDO_PROG_VOLT_MV_STEP); reinit_completion(&port->pps_complete); - port->pps_data.req_out_volt = req_out_volt; + port->pps_data.out_volt = out_volt; port->pps_status = 0; port->pps_pending = true; tcpm_set_state(port, SNK_NEGOTIATE_PPS_CAPABILITIES, 0); @@ -4321,8 +4303,8 @@ static int tcpm_pps_activate(struct tcpm_port *port, bool activate) /* Trigger PPS request or move back to standard PDO contract */ if (activate) { - port->pps_data.req_out_volt = port->supply_voltage; - port->pps_data.req_op_curr = port->current_limit; + port->pps_data.out_volt = port->supply_voltage; + port->pps_data.op_curr = port->current_limit; tcpm_set_state(port, SNK_NEGOTIATE_PPS_CAPABILITIES, 0); } else { tcpm_set_state(port, SNK_NEGOTIATE_CAPABILITIES, 0);