usb-c: Remove VBUS measurement and control

A USB-C VBUS driver will be used to measure VBUS
instead of accessing the measurement hardware
directly.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
This commit is contained in:
Sam Hurst 2022-06-23 10:22:49 -07:00 committed by Anas Nashif
commit 1a5e2c9c13
5 changed files with 3 additions and 271 deletions

View file

@ -1,3 +1,4 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
add_subdirectory_ifdef(CONFIG_USBC_TCPC_DRIVER tcpc) add_subdirectory_ifdef(CONFIG_USBC_TCPC_DRIVER tcpc)
add_subdirectory_ifdef(CONFIG_USBC_VBUS_DRIVER vbus)

View file

@ -1,6 +1,7 @@
# USBC configuration options # USB-C configuration options
# Copyright 2022 The Chromium OS Authors # Copyright 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
source "drivers/usb_c/tcpc/Kconfig" source "drivers/usb_c/tcpc/Kconfig"
source "drivers/usb_c/vbus/Kconfig"

View file

@ -1224,116 +1224,6 @@ static void ucpd_set_vconn_cb(const struct device *dev,
data->vconn_cb = vconn_cb; data->vconn_cb = vconn_cb;
} }
/**
* @brief Sets a callback that can measure the value of VBUS if the TCPC is
* unable to or the system is configured in a way that does not use
* the VBUS measurement and detection capabilities of the TCPC.
*
*/
static void ucpd_set_vbus_measure_cb(const struct device *dev,
tcpc_vbus_cb_t vbus_cb)
{
struct tcpc_data *data = dev->data;
data->vbus_cb = vbus_cb;
}
/**
* @brief Sets a callback that can discharge VBUS if the TCPC is
* unable to or the system is configured in a way that does not use
* the discharge VBUS capabilities of the TCPC.
*
*/
static void ucpd_set_discharge_vbus_cb(const struct device *dev,
tcpc_discharge_vbus_cb_t discharge_vbus_cb)
{
struct tcpc_data *data = dev->data;
data->discharge_vbus_cb = discharge_vbus_cb;
}
/**
* @brief Checks if VBUS is at a particular level
*
* @return true if VBUS is at the level voltage, else false
*/
static bool ucpd_check_vbus_level(const struct device *dev,
enum tc_vbus_level level)
{
struct tcpc_data *data = dev->data;
int vbus_meas;
int ret;
if (data->vbus_cb == NULL) {
return false;
}
/* Call user supplied callback to measure VBUS */
ret = data->vbus_cb(dev, &vbus_meas);
if (ret) {
return false;
}
switch (level) {
case TC_VBUS_SAFE0V:
return (vbus_meas < PD_V_SAFE_0V_MAX_MV);
case TC_VBUS_PRESENT:
return (vbus_meas >= PD_V_SAFE_5V_MIN_MV);
case TC_VBUS_REMOVED:
return (vbus_meas < TC_V_SINK_DISCONNECT_MAX_MV);
}
return false;
}
/**
* @brief Reads and returns VBUS measured in mV
*
* @return 0 on success
* @return -EIO on failure
* @return -EFAULT on buf being NULL
*/
static int ucpd_get_vbus(const struct device *dev, int *vbus_meas)
{
struct tcpc_data *data = dev->data;
int ret;
if (vbus_meas == NULL) {
return -EFAULT;
}
if (data->vbus_cb == NULL) {
return -EIO;
}
/* Call user supplied callback to measure VBUS */
ret = data->vbus_cb(dev, vbus_meas);
return ret;
}
/**
* @brief Enable or Disable Discharging of VBUS
*
* @return 0 on success
* @return -EIO on failure
*/
static int ucpd_set_discharge_vbus(const struct device *dev, bool enable)
{
struct tcpc_data *data = dev->data;
int ret;
if (data->discharge_vbus_cb == NULL) {
return -EIO;
}
/* Call user supplied callback to discharge VBUS */
ret = data->discharge_vbus_cb(dev, enable);
return ret;
}
/** /**
* @brief UCPD interrupt init * @brief UCPD interrupt init
*/ */
@ -1431,14 +1321,9 @@ static const struct tcpc_driver_api driver_api = {
.set_alert_handler_cb = ucpd_set_alert_handler_cb, .set_alert_handler_cb = ucpd_set_alert_handler_cb,
.get_cc = ucpd_get_cc, .get_cc = ucpd_get_cc,
.set_rx_enable = ucpd_set_rx_enable, .set_rx_enable = ucpd_set_rx_enable,
.set_vbus_measure_cb = ucpd_set_vbus_measure_cb,
.set_discharge_vbus_cb = ucpd_set_discharge_vbus_cb,
.check_vbus_level = ucpd_check_vbus_level,
.is_rx_pending_msg = ucpd_is_rx_pending_msg, .is_rx_pending_msg = ucpd_is_rx_pending_msg,
.receive_data = ucpd_receive_data, .receive_data = ucpd_receive_data,
.transmit_data = ucpd_transmit_data, .transmit_data = ucpd_transmit_data,
.get_vbus = ucpd_get_vbus,
.set_discharge_vbus = ucpd_set_discharge_vbus,
.select_rp_value = ucpd_select_rp_value, .select_rp_value = ucpd_select_rp_value,
.get_rp_value = ucpd_get_rp_value, .get_rp_value = ucpd_get_rp_value,
.set_cc = ucpd_set_cc, .set_cc = ucpd_set_cc,

View file

@ -264,10 +264,6 @@ struct tcpc_config {
* @brief Driver data * @brief Driver data
*/ */
struct tcpc_data { struct tcpc_data {
/* VBUS callback function */
tcpc_vbus_cb_t vbus_cb;
/* Discharge VBUS callback function */
tcpc_discharge_vbus_cb_t discharge_vbus_cb;
/* VCONN callback function */ /* VCONN callback function */
tcpc_vconn_control_cb_t vconn_cb; tcpc_vconn_control_cb_t vconn_cb;
/* Alert information */ /* Alert information */

View file

@ -115,8 +115,6 @@ struct tcpc_chip_info {
}; };
}; };
typedef int (*tcpc_vbus_cb_t)(const struct device *dev, int *vbus_meas);
typedef int (*tcpc_discharge_vbus_cb_t)(const struct device *dev, bool enable);
typedef int (*tcpc_vconn_control_cb_t)(const struct device *dev, bool enable); typedef int (*tcpc_vconn_control_cb_t)(const struct device *dev, bool enable);
typedef void (*tcpc_alert_handler_cb_t)(const struct device *dev, void *data, typedef void (*tcpc_alert_handler_cb_t)(const struct device *dev, void *data,
enum tcpc_alert alert); enum tcpc_alert alert);
@ -125,11 +123,6 @@ __subsystem struct tcpc_driver_api {
int (*init)(const struct device *dev); int (*init)(const struct device *dev);
int (*get_cc)(const struct device *dev, enum tc_cc_voltage_state *cc1, int (*get_cc)(const struct device *dev, enum tc_cc_voltage_state *cc1,
enum tc_cc_voltage_state *cc2); enum tc_cc_voltage_state *cc2);
void (*set_vbus_measure_cb)(const struct device *dev, tcpc_vbus_cb_t vbus_cb);
void (*set_discharge_vbus_cb)(const struct device *dev,
tcpc_discharge_vbus_cb_t discharge_vbus_cb);
bool (*check_vbus_level)(const struct device *dev, enum tc_vbus_level level);
int (*get_vbus)(const struct device *dev, int *vbus_meas);
int (*select_rp_value)(const struct device *dev, enum tc_rp_value rp); int (*select_rp_value)(const struct device *dev, enum tc_rp_value rp);
int (*get_rp_value)(const struct device *dev, enum tc_rp_value *rp); int (*get_rp_value)(const struct device *dev, enum tc_rp_value *rp);
int (*set_cc)(const struct device *dev, enum tc_cc_pull pull); int (*set_cc)(const struct device *dev, enum tc_cc_pull pull);
@ -150,8 +143,6 @@ __subsystem struct tcpc_driver_api {
uint32_t mask); uint32_t mask);
int (*mask_status_register)(const struct device *dev, enum tcpc_status_reg reg, int (*mask_status_register)(const struct device *dev, enum tcpc_status_reg reg,
uint32_t mask); uint32_t mask);
int (*set_discharge_vbus)(const struct device *dev, bool enable);
int (*enable_auto_discharge_disconnect)(const struct device *dev, bool enable);
int (*set_debug_accessory)(const struct device *dev, bool enable); int (*set_debug_accessory)(const struct device *dev, bool enable);
int (*set_debug_detach)(const struct device *dev); int (*set_debug_detach)(const struct device *dev);
int (*set_drp_toggle)(const struct device *dev, bool enable); int (*set_drp_toggle)(const struct device *dev, bool enable);
@ -272,99 +263,6 @@ static inline int tcpc_get_cc(const struct device *dev,
return api->get_cc(dev, cc1, cc2); return api->get_cc(dev, cc1, cc2);
} }
/**
* @brief Sets a callback that can measure the value of VBUS if the TCPC is
* unable to or the system is configured in a way that does not use
* the VBUS measurement and detection capabilities of the TCPC.
*
* The callback is called in tcpc_check_vbus_level and tcpc_get_vbus
* functions if vbus_cb isn't NULL.
*
* @param dev Runtime device structure
* @param vbus_cb pointer to callback function that returns a voltage
* measurement
*/
static inline void tcpc_set_vbus_measure_cb(const struct device *dev,
tcpc_vbus_cb_t vbus_cb)
{
const struct tcpc_driver_api *api =
(const struct tcpc_driver_api *)dev->api;
__ASSERT(api->set_vbus_measure_cb != NULL,
"Callback pointer should not be NULL");
api->set_vbus_measure_cb(dev, vbus_cb);
}
/**
* @brief Sets a callback that can discharge VBUS if the TCPC is
* unable to or the system is configured in a way that does not use
* the discharge VBUS capabilities of the TCPC.
*
* The callback is called in tcpc_set_discharge_vbus functions if
* discharge_vbus_cb isn't NULL.
*
* @param dev Runtime device structure
* @param discharge_vbus_cb pointer to callback function that discharges VBUS
*/
static inline void tcpc_set_discharge_vbus_cb(const struct device *dev,
tcpc_discharge_vbus_cb_t discharge_vbus_cb)
{
const struct tcpc_driver_api *api =
(const struct tcpc_driver_api *)dev->api;
__ASSERT(api->set_discharge_vbus_cb != NULL,
"Callback pointer should not be NULL");
api->set_discharge_vbus_cb(dev, discharge_vbus_cb);
}
/**
* @brief Checks if VBUS is at a particular level
*
* @param dev Runtime device structure
* @param level The level voltage to check against
*
* @return true if VBUS is at the level voltage
* @return false if VBUS is not at that level voltage
*/
static inline bool tcpc_check_vbus_level(const struct device *dev,
enum tc_vbus_level level)
{
const struct tcpc_driver_api *api =
(const struct tcpc_driver_api *)dev->api;
__ASSERT(api->check_vbus_level != NULL,
"Callback pointer should not be NULL");
return api->check_vbus_level(dev, level);
}
/**
* @brief Reads and returns VBUS measured in mV
*
* This function uses the TCPC to measure VBUS if possible or calls the
* callback function set by tcpc_set_vbus_measure_callback. In the event that
* the TCPC can measure VBUS and the VBUS callback measuring function is
* set, this function uses the callback function.
*
* @param dev Runtime device structure
* @param vbus_meas pointer where the measured VBUS voltage is stored
*
* @return 0 on success
* @return -EIO on failure
*/
static inline int tcpc_get_vbus(const struct device *dev, int *vbus_meas)
{
const struct tcpc_driver_api *api =
(const struct tcpc_driver_api *)dev->api;
__ASSERT(api->get_vbus != NULL,
"Callback pointer should not be NULL");
return api->get_vbus(dev, vbus_meas);
}
/** /**
* @brief Sets the value of CC pull up resistor used when operating as a Source * @brief Sets the value of CC pull up resistor used when operating as a Source
* *
@ -741,55 +639,6 @@ static inline int tcpc_mask_status_register(const struct device *dev,
return api->mask_status_register(dev, reg, mask); return api->mask_status_register(dev, reg, mask);
} }
/**
* @brief Enables discharge TypeC VBUS on Source / Sink disconnect
* and power role swap
*
* @param dev Runtime device structure
* @param enable The TypeC VBUS is discharged on disconnect or power
* role swap when true
*
* @return 0 on success
* @return -EIO on failure
* @return -ENOSYS if not implemented
*/
static inline int tcpc_set_discharge_vbus(const struct device *dev, bool enable)
{
const struct tcpc_driver_api *api =
(const struct tcpc_driver_api *)dev->api;
if (api->set_discharge_vbus == NULL) {
return -ENOSYS;
}
return api->set_discharge_vbus(dev, enable);
}
/**
* @brief TCPC automatically discharge TypeC VBUS on Source / Sink disconnect
* an power role swap
*
* @param dev Runtime device structure
* @param enable The TCPC automatically discharges VBUS on disconnect or
* power role swap
*
* @return 0 on success
* @return -EIO on failure
* @return -ENOSYS if not implemented
*/
static inline int tcpc_enable_auto_discharge_disconnect(
const struct device *dev, bool enable)
{
const struct tcpc_driver_api *api =
(const struct tcpc_driver_api *)dev->api;
if (api->enable_auto_discharge_disconnect == NULL) {
return -ENOSYS;
}
return api->enable_auto_discharge_disconnect(dev, enable);
}
/** /**
* @brief Manual control of TCPC DebugAccessory control * @brief Manual control of TCPC DebugAccessory control
* *