blob: 19be03a7555a5425b3df295112de95b6aa6bea97 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* Copyright 2020 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.
*/
#include "chg_control.h"
#include "gpio.h"
#include "ioexpanders.h"
#include "registers.h"
#include "timer.h"
#include "usb_pd.h"
#define CHG_P5V_POWER 0
#define CHG_VBUS_POWER 1
void chg_reset(void)
{
/* Disconnect DUT Power */
chg_power_select(CHG_POWER_OFF);
/* Disconnect CHG CC1(Rd) and CC2(Rd) */
chg_attach_cc_rds(0);
/* Give time for CHG to detach, use tErrorRecovery. */
msleep(PD_T_ERROR_RECOVERY);
/* Connect CHG CC1(Rd) and CC2(Rd) to detect charger */
chg_attach_cc_rds(1);
}
void chg_power_select(enum chg_power_select_t type)
{
switch (type) {
case CHG_POWER_OFF:
dut_chg_en(0);
vbus_dischrg_en(1);
break;
case CHG_POWER_PP5000:
vbus_dischrg_en(0);
host_or_chg_ctl(CHG_P5V_POWER);
dut_chg_en(1);
break;
case CHG_POWER_VBUS:
vbus_dischrg_en(0);
host_or_chg_ctl(CHG_VBUS_POWER);
dut_chg_en(1);
break;
}
}
void chg_attach_cc_rds(bool en)
{
if (en) {
/*
* Configure USB_CHG_CC1_MCU and USB_CHG_CC2_MCU as
* ANALOG input
*/
STM32_GPIO_MODER(GPIO_A) = (STM32_GPIO_MODER(GPIO_A)
| (3 << (2*2)) | /* PA2 in ANALOG mode */
(3 << (2*4))); /* PA4 in ANALOG mode */
} else {
/*
* Configure USB_CHG_CC1_MCU and USB_CHG_CC2_MCU as GPIO and
* drive high to trigger disconnect.
* NOTE: The CC line has an external fixed Rd pull-down.
* Driving the CC line High overrides the pull down and this
* triggers a disconnection.
*/
/* Set level high */
gpio_set_level(GPIO_USB_CHG_CC1_MCU, 1);
gpio_set_level(GPIO_USB_CHG_CC2_MCU, 1);
/* Disable Analog mode and Enable GPO */
STM32_GPIO_MODER(GPIO_A) = (STM32_GPIO_MODER(GPIO_A)
& ~(3 << (2*2) | /* PA2 disable ADC */
3 << (2*4))) /* PA4 disable ADC */
| (1 << (2*2) | /* Set as GPO */
1 << (2*4)); /* Set as GPO */
}
}
|