summaryrefslogtreecommitdiff
path: root/board/fizz/usb_pd_policy.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-05-03 13:44:18 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-05-17 19:06:31 -0700
commit760c89fe3746278c9324c981d0adf6d3e79562d0 (patch)
tree1eb56808de7c8e49cb209d77366545de19ace955 /board/fizz/usb_pd_policy.c
parent120ce3eaa054bcdb3f2c33a0e11a6a821fea67ce (diff)
downloadchrome-ec-760c89fe3746278c9324c981d0adf6d3e79562d0.tar.gz
Fizz: Set up charge suppliers at boot
Fizz has two power sources: barrel jack and type-c port. It selects a power source at boot and does not dynamicall switch to the other ports after that. Fizz initializes all power suppliers of all ports to zero then initialize the source supplier (barrel jack or type-c port). When both sources are provided, it prefers a barrel jack. This detection is done by reading the voltage on PPVAR_PWR_IN. If barrel jack is detected as a sink, type-c port works as a source only. If type-c port is detected as a sink, type-c port works as a sink only. Fizz does not have a battery. So, battery module is removed. BUG=b:37573548,b:37316498 BRANCH=none TEST=Boot on both type-c & barrel jack. Change-Id: If4f5ff0c6019d06ac9dacb5dd365f5aa96bffef3 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/499547
Diffstat (limited to 'board/fizz/usb_pd_policy.c')
-rw-r--r--board/fizz/usb_pd_policy.c54
1 files changed, 49 insertions, 5 deletions
diff --git a/board/fizz/usb_pd_policy.c b/board/fizz/usb_pd_policy.c
index 122c4d39ca..69ab2b379e 100644
--- a/board/fizz/usb_pd_policy.c
+++ b/board/fizz/usb_pd_policy.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include "adc.h"
#include "atomic.h"
#include "extpower.h"
#include "charge_manager.h"
@@ -55,18 +56,19 @@ void pd_transition_voltage(int idx)
/* No-operation: we are always 5V */
}
-static uint8_t vbus_en;
-
int board_vbus_source_enabled(int port)
{
- return vbus_en;
+ if (port != 0)
+ return 0;
+ return gpio_get_level(GPIO_USB_C0_5V_EN);
}
int pd_set_power_supply_ready(int port)
{
/* Disable charging */
gpio_set_level(GPIO_USB_C0_CHARGE_L, 1);
- /* Provide VBUS */
+
+ /* Enable VBUS source */
gpio_set_level(GPIO_USB_C0_5V_EN, 1);
/* notify host of power info change */
@@ -77,7 +79,7 @@ int pd_set_power_supply_ready(int port)
void pd_power_supply_reset(int port)
{
- /* Disable VBUS */
+ /* Disable VBUS source */
gpio_set_level(GPIO_USB_C0_5V_EN, 0);
/* notify host of power info change */
@@ -243,6 +245,48 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload,
return 0;
}
+static void board_charge_manager_init(void)
+{
+ int input_voltage;
+ int i, j;
+ struct charge_port_info cpi = {
+ .voltage = USB_CHARGER_VOLTAGE_MV,
+ .current = 0,
+ };
+
+ /* Initialize all charge suppliers to 0 */
+ for (i = 0; i < CHARGE_PORT_COUNT; i++) {
+ for (j = 0; j < CHARGE_SUPPLIER_COUNT; j++)
+ charge_manager_update_charge(j, i, &cpi);
+ }
+
+ input_voltage = adc_read_channel(ADC_VBUS);
+
+ /* Initialize the power source supplier */
+ if (input_voltage > 5500) {
+ /* Power source is barrel jack */
+ CPRINTF("Source: BJ (%dmV)\n", input_voltage);
+ cpi.voltage = input_voltage;
+ cpi.current = 3330; /* TODO: Set right value */
+ charge_manager_update_charge(CHARGE_SUPPLIER_PROPRIETARY, 1,
+ &cpi);
+ /* Source only. Disable PD negotiation as a sink */
+ } else {
+ /* Power source is usb-c */
+ CPRINTF("Source: C0 (%dmV)\n", input_voltage);
+ cpi.voltage = input_voltage;
+ cpi.current = 3000; /* TODO: Set right value */
+ charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, 0, &cpi);
+ /* Sink only. Disable PD negotiation as a source */
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_charge_manager_init, HOOK_PRIO_INIT_ADC + 1);
+
+int board_get_battery_soc(void)
+{
+ return 100;
+}
+
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
static int dp_flags[CONFIG_USB_PD_PORT_COUNT];
static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT];