Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21ba1207 authored by Jack Pham's avatar Jack Pham
Browse files

usb: pd: Always request maximum available current from PDO



Currently when selecting a PDO the request object is specifying
900mA as the operating current, which is suboptimal if the
supply is capable of more. Instead, simply request for the
maximum available. In the case where a PDO does not meet the
minimum current, set the capability mismatch flag and indicate
the required amount via the maximum field in the request.

Change-Id: I521059ab1c1d95df95fdede84512e73c5d9b2329
Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
parent 9a2bd8b7
Loading
Loading
Loading
Loading
+7 −9
Original line number Original line Diff line number Diff line
@@ -240,9 +240,6 @@ static void *usbpd_ipc_log;
static int min_sink_current = 900;
static int min_sink_current = 900;
module_param(min_sink_current, int, S_IRUSR | S_IWUSR);
module_param(min_sink_current, int, S_IRUSR | S_IWUSR);


static int max_sink_current = 3000;
module_param(max_sink_current, int, S_IRUSR | S_IWUSR);

static const u32 default_src_caps[] = { 0x36019096 };	/* VSafe5V @ 1.5A */
static const u32 default_src_caps[] = { 0x36019096 };	/* VSafe5V @ 1.5A */


static const u32 default_snk_caps[] = { 0x2601905A,	/* 5V @ 900mA */
static const u32 default_snk_caps[] = { 0x2601905A,	/* 5V @ 900mA */
@@ -406,8 +403,8 @@ static int pd_send_msg(struct usbpd *pd, u8 hdr_type, const u32 *data,


static int pd_select_pdo(struct usbpd *pd, int pdo_pos)
static int pd_select_pdo(struct usbpd *pd, int pdo_pos)
{
{
	int curr = min_sink_current;
	int curr;
	int max_current = max_sink_current;
	int max_current;
	bool mismatch = false;
	bool mismatch = false;
	u32 pdo = pd->received_pdos[pdo_pos - 1];
	u32 pdo = pd->received_pdos[pdo_pos - 1];


@@ -417,18 +414,19 @@ static int pd_select_pdo(struct usbpd *pd, int pdo_pos)
		return -ENOTSUPP;
		return -ENOTSUPP;
	}
	}


	curr = max_current = PD_SRC_PDO_FIXED_MAX_CURR(pdo) * 10;

	/*
	/*
	 * Check if the PDO has enough current, otherwise set the
	 * Check if the PDO has enough current, otherwise set the
	 * Capability Mismatch flag
	 * Capability Mismatch flag
	 */
	 */
	if ((PD_SRC_PDO_FIXED_MAX_CURR(pdo) * 10) < curr) {
	if (curr < min_sink_current) {
		mismatch = true;
		mismatch = true;
		max_current = curr;
		max_current = min_sink_current;
		curr = PD_SRC_PDO_FIXED_MAX_CURR(pdo) * 10;
	}
	}


	pd->requested_voltage = PD_SRC_PDO_FIXED_VOLTAGE(pdo) * 50 * 1000;
	pd->requested_voltage = PD_SRC_PDO_FIXED_VOLTAGE(pdo) * 50 * 1000;
	pd->requested_current = max_current;
	pd->requested_current = curr;
	pd->requested_pdo = pdo_pos;
	pd->requested_pdo = pdo_pos;
	pd->rdo = PD_RDO_FIXED(pdo_pos, 0, mismatch, 1, 1, curr / 10,
	pd->rdo = PD_RDO_FIXED(pdo_pos, 0, mismatch, 1, 1, curr / 10,
			max_current / 10);
			max_current / 10);