usb_charger: cleanup: move setting usb 2 switches to usb_charger

Move function to set D+/D- switches from board directory to
usb_charger module.

BUG=none
BRANCH=strago
TEST=make -j buildall

Change-Id: I5c5997c799cecea90448444863167af860a8f3e1
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/290421
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Alec Berg
2015-08-03 13:51:53 -07:00
committed by ChromeOS Commit Bot
parent ccc085dd9a
commit d804e8fdbd
12 changed files with 40 additions and 99 deletions

View File

@@ -176,11 +176,6 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
}
};
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* TODO: Set open / close USB switches based on param */
}
/**
* Reset PD MCU
*/

View File

@@ -10,11 +10,6 @@
#include "usb_mux.h"
#include "util.h"
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* Not implemented */
}
static int board_init_usb_mux(int port)
{
return EC_SUCCESS;

View File

@@ -171,11 +171,6 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
}
};
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* TODO: Set open / close USB switches based on param */
}
/**
* Reset PD MCU
*/

View File

@@ -160,13 +160,6 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
},
};
/**
* Store the state of our USB data switches so that they can be restored
* after pericom reset.
*/
static int usb_switch_state[CONFIG_USB_PD_PORT_COUNT];
static struct mutex usb_switch_lock[CONFIG_USB_PD_PORT_COUNT];
/**
* Store the current DP hardware route.
*/
@@ -301,25 +294,6 @@ void board_set_charge_limit(int charge_ma)
CONFIG_CHARGER_INPUT_CURRENT));
}
/**
* Set type-C port USB2.0 switch state.
*
* @param port the type-C port to change
* @param setting enum usb_switch
*/
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* If switch is not charging, then return */
if (setting == usb_switch_state[port])
return;
mutex_lock(&usb_switch_lock[port]);
if (setting != USB_SWITCH_RESTORE)
usb_switch_state[port] = setting;
pi3usb9281_set_switches(port, usb_switch_state[port]);
mutex_unlock(&usb_switch_lock[port]);
}
static void hpd_irq_deferred(void)
{
gpio_set_level(GPIO_USB_DP_HPD, 1);

View File

@@ -58,12 +58,6 @@ static int charge_current_limit;
*/
static struct ec_response_host_event_status host_event_status __aligned(4);
/*
* Store the state of our USB data switches so that they can be restored
* after pericom reset.
*/
static int usb_switch_state;
static void vbus_log(void)
{
CPRINTS("VBUS %d", gpio_get_level(GPIO_CHGR_ACOK));
@@ -373,17 +367,6 @@ struct motion_sensor_t motion_sensors[] = {
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* If switch is not changing, then return */
if (setting == usb_switch_state)
return;
if (setting != USB_SWITCH_RESTORE)
usb_switch_state = setting;
pi3usb9281_set_switches(port, usb_switch_state);
}
int extpower_is_present(void)
{
return gpio_get_level(GPIO_CHGR_ACOK);

View File

@@ -62,13 +62,6 @@ static struct ec_response_host_event_status host_event_status __aligned(4);
/* Desired input current limit */
static int desired_charge_rate_ma = -1;
/*
* Store the state of our USB data switches so that they can be restored
* after pericom reset.
*/
static int usb_switch_state[CONFIG_USB_PD_PORT_COUNT];
static struct mutex usb_switch_lock[CONFIG_USB_PD_PORT_COUNT];
/* PWM channels. Must be in the exact same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
{STM32_TIM(15), STM32_TIM_CH(2), 0, GPIO_ILIM_ADJ_PWM, GPIO_ALT_F1},
@@ -391,19 +384,6 @@ const struct i2c_port_t i2c_ports[] = {
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* If switch is not changing then return */
if (setting == usb_switch_state[port])
return;
mutex_lock(&usb_switch_lock[port]);
if (setting != USB_SWITCH_RESTORE)
usb_switch_state[port] = setting;
pi3usb9281_set_switches(port, usb_switch_state[port]);
mutex_unlock(&usb_switch_lock[port]);
}
int board_get_battery_soc(void)
{
return batt_soc;

View File

@@ -198,11 +198,6 @@ const struct button_config buttons[] = {
};
BUILD_ASSERT(ARRAY_SIZE(buttons) == CONFIG_BUTTON_COUNT);
void board_set_usb_switches(int port, enum usb_switch setting)
{
/* TODO: Set open / close USB switches based on param */
}
/**
* Reset PD MCU
*/

View File

@@ -27,6 +27,13 @@
*/
#define USB_CHG_RESET_DELAY_MS 100
/*
* Store the state of our USB data switches so that they can be restored
* after pericom reset.
*/
static int usb_switch_state[CONFIG_USB_PD_PORT_COUNT];
static struct mutex usb_switch_lock[CONFIG_USB_PD_PORT_COUNT];
int usb_charger_port_is_sourcing_vbus(int port)
{
if (port == 0)
@@ -39,6 +46,19 @@ int usb_charger_port_is_sourcing_vbus(int port)
return 0;
}
void usb_charger_set_switches(int port, enum usb_switch setting)
{
/* If switch is not changing then return */
if (setting == usb_switch_state[port])
return;
mutex_lock(&usb_switch_lock[port]);
if (setting != USB_SWITCH_RESTORE)
usb_switch_state[port] = setting;
pi3usb9281_set_switches(port, usb_switch_state[port]);
mutex_unlock(&usb_switch_lock[port]);
}
void usb_charger_task(void)
{
int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1);
@@ -89,7 +109,7 @@ void usb_charger_task(void)
* Restore data switch settings - switches return to
* closed on reset until restored.
*/
board_set_usb_switches(port, USB_SWITCH_RESTORE);
usb_charger_set_switches(port, USB_SWITCH_RESTORE);
/* Clear possible disconnect interrupt */
pi3usb9281_get_interrupts(port);
/* Mask attach interrupt */

View File

@@ -37,8 +37,10 @@ void usb_mux_set(int port, enum typec_mux mux_mode,
int res;
mux_state_t mux_state;
#ifdef CONFIG_USB_CHARGER
/* Configure USB2.0 */
board_set_usb_switches(port, usb_mode);
usb_charger_set_switches(port, usb_mode);
#endif
/* Configure superspeed lanes */
mux_state = polarity ? mux_mode | MUX_POLARITY_INVERTED : mux_mode;

View File

@@ -55,4 +55,19 @@ int usb_charge_ports_enabled(void);
*/
int usb_charger_port_is_sourcing_vbus(int port);
enum usb_switch {
USB_SWITCH_CONNECT,
USB_SWITCH_DISCONNECT,
USB_SWITCH_RESTORE,
};
/**
* Configure USB data switches on type-C port.
*
* @param port port number.
* @param setting new switch setting to configure.
*/
void usb_charger_set_switches(int port, enum usb_switch setting);
#endif /* __CROS_EC_USB_CHARGE_H */

View File

@@ -8,6 +8,7 @@
#ifndef __CROS_EC_USB_MUX_H
#define __CROS_EC_USB_MUX_H
#include "usb_charge.h"
#include "usb_pd.h"
/* USB-C mux state */

View File

@@ -1191,20 +1191,6 @@ extern const int pd_snk_pdo_cnt;
*/
int pd_get_source_pdo(const uint32_t **src_pdo);
enum usb_switch {
USB_SWITCH_CONNECT,
USB_SWITCH_DISCONNECT,
USB_SWITCH_RESTORE,
};
/**
* Configure USB data switches on type-C port.
*
* @param port port number.
* @param setting new switch setting to configure.
*/
void board_set_usb_switches(int port, enum usb_switch setting);
/**
* Request that a host event be sent to notify the AP of a PD power event.
*