Skip to content

Commit

Permalink
usb: typec: tcpci: Add callback for evaluating contaminant presence
Browse files Browse the repository at this point in the history
This change adds callback to evaluate presence of contaminant in
the TCPCI layer.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
  • Loading branch information
Badhri Jagan Sridharan authored and intel-lab-lkp committed Dec 4, 2022
1 parent 4e87426 commit 652f2aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions drivers/usb/typec/tcpm/tcpci.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ static void tcpci_frs_sourcing_vbus(struct tcpc_dev *dev)
tcpci->data->frs_sourcing_vbus(tcpci, tcpci->data);
}

static bool tcpci_is_potential_contaminant(struct tcpc_dev *dev, enum tcpm_state current_state)
{
struct tcpci *tcpci = tcpc_to_tcpci(dev);

if (tcpci->data->is_potential_contaminant)
return tcpci->data->is_potential_contaminant(tcpci, tcpci->data, current_state);

return false;
}

static void tcpci_check_contaminant(struct tcpc_dev *dev)
{
struct tcpci *tcpci = tcpc_to_tcpci(dev);

if (tcpci->data->check_contaminant)
tcpci->data->check_contaminant(tcpci, tcpci->data);
}

static int tcpci_set_bist_data(struct tcpc_dev *tcpc, bool enable)
{
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
Expand Down Expand Up @@ -777,6 +795,8 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
tcpci->tcpc.enable_frs = tcpci_enable_frs;
tcpci->tcpc.frs_sourcing_vbus = tcpci_frs_sourcing_vbus;
tcpci->tcpc.set_partner_usb_comm_capable = tcpci_set_partner_usb_comm_capable;
tcpci->tcpc.is_potential_contaminant = tcpci_is_potential_contaminant;
tcpci->tcpc.check_contaminant = tcpci_check_contaminant;

if (tcpci->data->auto_discharge_disconnect) {
tcpci->tcpc.enable_auto_vbus_discharge = tcpci_enable_auto_vbus_discharge;
Expand Down
13 changes: 13 additions & 0 deletions include/linux/usb/tcpci.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ struct tcpci;
* Optional; The USB Communications Capable bit indicates if port
* partner is capable of communication over the USB data lines
* (e.g. D+/- or SS Tx/Rx). Called to notify the status of the bit.
* @check_contaminant:
* Optional; The callback is invoked when chiplevel drivers indicated
* that the USB port needs to be checked for contaminant presence.
* Chip level drivers are expected to check for contaminant and call
* tcpm_clean_port when the port is clean to put the port back into
* toggling state.
* @is_potential_contaminant:
* Optional; TCPM invokes the callback for every TCPM state machine
* transition. Chiplevel drivers can monitor the state machine
* transitions to flag for potential contaminant presence.
*/
struct tcpci_data {
struct regmap *regmap;
Expand All @@ -204,6 +214,9 @@ struct tcpci_data {
void (*frs_sourcing_vbus)(struct tcpci *tcpci, struct tcpci_data *data);
void (*set_partner_usb_comm_capable)(struct tcpci *tcpci, struct tcpci_data *data,
bool capable);
void (*check_contaminant)(struct tcpci *tcpci, struct tcpci_data *data);
bool (*is_potential_contaminant)(struct tcpci *tcpci, struct tcpci_data *data,
enum tcpm_state current_state);
};

struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);
Expand Down

0 comments on commit 652f2aa

Please sign in to comment.