summaryrefslogtreecommitdiff
path: root/common/charge_ramp.c
blob: 32e0d21ddbe5976bd65e800dcebe8f29bca21278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright 2017 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Charge input current limit ramp module for Chrome EC */

#include "charge_manager.h"
#include "common.h"
#include "system.h"
#include "usb_charge.h"
#include "util.h"

test_mockable int chg_ramp_allowed(int port, int supplier)
{
	/* Don't allow ramping in RO when write protected. */
	if (!system_is_in_rw() && system_is_locked())
		return 0;

	switch (supplier) {
	/*
	 * Use ramping for USB-C DTS suppliers (debug accessory eg suzy-q).
	 * The suzy-q simply passes through the VBUS. The power supplier behind
	 * may be a SDP/CDP which requires ramping.
	 */
	case CHARGE_SUPPLIER_TYPEC_DTS:
		return 1;
	/*
	 * Don't regulate the input voltage for USB-C chargers. It is
	 * unnecessary as the USB-C compliant adapters should never trigger it
	 * active.
	 *
	 * The USB-C spec defines their load curves should not be below
	 * 4.75V @0A and 4V @3A. We can't define the voltage regulation value
	 * higher than 4V since it limits the current reaching its max 3A. If
	 * we define the voltage regulation value lower than 4V, their load
	 * curves will never be below the voltage regulation line.
	 *
	 * Check go/charge_ramp_typec for detail.
	 */
	case CHARGE_SUPPLIER_PD:
	case CHARGE_SUPPLIER_TYPEC:
		return 0;
	/* default: fall through */
	}

	/* Otherwise ask the BC1.2 detect module */
	return usb_charger_ramp_allowed(port, supplier);
}

test_mockable int chg_ramp_max(int port, int supplier, int sup_curr)
{
	switch (supplier) {
	case CHARGE_SUPPLIER_PD:
	case CHARGE_SUPPLIER_TYPEC:
	case CHARGE_SUPPLIER_TYPEC_DTS:
		/*
		 * We should not ramp DTS beyond what they advertise, otherwise
		 * we may brownout the systems they are connected to.
		 */
		return sup_curr;
	/* default: fall through */
	}

	/* Otherwise ask the BC1.2 detect module */
	return usb_charger_ramp_max(port, supplier, sup_curr);
}