mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 00:21:46 +00:00
Refactor the tcpm/tcpc split such that the tcpm driver implements the alert functionality since it may be unique for different tcpc chips. BUG=chrome-os-partner:41842 BRANCH=none TEST=make -j buildall. run on samus and glados. Change-Id: I23f2d7f8627d5337b8d001a09bf27622be24fe33 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/281631 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
207 lines
4.5 KiB
C
207 lines
4.5 KiB
C
/* Copyright 2015 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.
|
|
*/
|
|
|
|
/* USB Power delivery port management */
|
|
|
|
#ifndef __CROS_EC_USB_PD_TCPM_H
|
|
#define __CROS_EC_USB_PD_TCPM_H
|
|
|
|
/* Default retry count for transmitting */
|
|
#define PD_RETRY_COUNT 3
|
|
|
|
/* Time to wait for TCPC to complete transmit */
|
|
#define PD_T_TCPC_TX_TIMEOUT (100*MSEC)
|
|
|
|
enum tcpc_cc_termination_status {
|
|
TYPEC_CC_TERM_RA = 0,
|
|
TYPEC_CC_TERM_RP_DEF = 1,
|
|
TYPEC_CC_TERM_RP_1_5 = 2,
|
|
TYPEC_CC_TERM_RP_3_0 = 3,
|
|
TYPEC_CC_TERM_RD = 4,
|
|
TYPEC_CC_TERM_VCONN = 5,
|
|
TYPEC_CC_TERM_OPEN = 6
|
|
};
|
|
enum tcpc_cc_voltage_status {
|
|
TYPEC_CC_VOLT_RA = 0,
|
|
TYPEC_CC_VOLT_SNK_DEF = 1,
|
|
TYPEC_CC_VOLT_SNK_1_5 = 2,
|
|
TYPEC_CC_VOLT_SNK_3_0 = 3,
|
|
TYPEC_CC_VOLT_SRC_DEF = 4,
|
|
TYPEC_CC_VOLT_SRC_1_5 = 5,
|
|
TYPEC_CC_VOLT_SRC_3_0 = 6,
|
|
TYPEC_CC_VOLT_OPEN = 7
|
|
};
|
|
|
|
/* Check if CC voltage is within Rd */
|
|
#define TYPEC_CC_IS_RD(cc) ((cc) >= TYPEC_CC_VOLT_SNK_DEF && \
|
|
(cc) <= TYPEC_CC_VOLT_SNK_3_0)
|
|
|
|
enum tcpc_cc_pull {
|
|
TYPEC_CC_RA = 0,
|
|
TYPEC_CC_RP = 1,
|
|
TYPEC_CC_RD = 2,
|
|
TYPEC_CC_OPEN = 3,
|
|
};
|
|
|
|
enum tcpm_transmit_type {
|
|
TCPC_TX_SOP = 0,
|
|
TCPC_TX_SOP_PRIME = 1,
|
|
TCPC_TX_SOP_PRIME_PRIME = 2,
|
|
TCPC_TX_SOP_DEBUG_PRIME = 3,
|
|
TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
|
|
TCPC_TX_HARD_RESET = 5,
|
|
TCPC_TX_CABLE_RESET = 6,
|
|
TCPC_TX_BIST_MODE_2 = 7
|
|
};
|
|
|
|
enum tcpc_transmit_complete {
|
|
TCPC_TX_COMPLETE_SUCCESS = (1 << 2),
|
|
TCPC_TX_COMPLETE_DISCARDED = (1 << 1),
|
|
TCPC_TX_COMPLETE_FAILED = (1 << 0),
|
|
};
|
|
|
|
/**
|
|
* Initialize TCPM driver and wait for TCPC readiness.
|
|
*
|
|
* @param port Type-C port number
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_init(int port);
|
|
|
|
/**
|
|
* Initialize TCPC.
|
|
*
|
|
* @param port Type-C port number
|
|
*/
|
|
void tcpc_init(int port);
|
|
|
|
/**
|
|
* TCPC is asserting alert
|
|
*
|
|
* @param port Type-C port number
|
|
*/
|
|
void tcpc_alert(int port);
|
|
void tcpc_alert_clear(int port);
|
|
|
|
/**
|
|
* Run TCPC task once. This checks for incoming messages, processes
|
|
* any outgoing messages, and reads CC lines.
|
|
*
|
|
* @param port Type-C port number
|
|
* @param evt Event type that woke up this task
|
|
*/
|
|
int tcpc_run(int port, int evt);
|
|
|
|
|
|
/**
|
|
* Read TCPC alert status
|
|
*
|
|
* @param port Type-C port number
|
|
* @param alert Pointer to location to store alert status
|
|
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_alert_status(int port, int *alert);
|
|
|
|
/**
|
|
* Write TCPC Alert Mask register
|
|
*
|
|
* @param port Type-C port number
|
|
* @param mask bits to be set in Alert Mask register
|
|
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_alert_mask_set(int port, uint16_t mask);
|
|
|
|
/**
|
|
* Read the CC line status.
|
|
*
|
|
* @param port Type-C port number
|
|
* @param cc1 pointer to CC status for CC1
|
|
* @param cc2 pointer to CC status for CC2
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_get_cc(int port, int *cc1, int *cc2);
|
|
|
|
/**
|
|
* Set the CC pull resistor. This sets our role as either source or sink.
|
|
*
|
|
* @param port Type-C port number
|
|
* @param pull One of enum tcpc_cc_pull
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_set_cc(int port, int pull);
|
|
|
|
/**
|
|
* Set polarity
|
|
*
|
|
* @param port Type-C port number
|
|
* @param polarity 0=> transmit on CC1, 1=> transmit on CC2
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_set_polarity(int port, int polarity);
|
|
|
|
/**
|
|
* Set Vconn.
|
|
*
|
|
* @param port Type-C port number
|
|
* @param polarity Polarity of the CC line to read
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_set_vconn(int port, int enable);
|
|
|
|
/**
|
|
* Set PD message header to use for goodCRC
|
|
*
|
|
* @param port Type-C port number
|
|
* @param power_role Power role to use in header
|
|
* @param data_role Data role to use in header
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_set_msg_header(int port, int power_role, int data_role);
|
|
|
|
/**
|
|
* Set RX enable flag
|
|
*
|
|
* @param port Type-C port number
|
|
* @enable true for enable, false for disable
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_set_rx_enable(int port, int enable);
|
|
|
|
/**
|
|
* Read last received PD message.
|
|
*
|
|
* @param port Type-C port number
|
|
* @param payload Pointer to location to copy payload of message
|
|
* @param header of message
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_get_message(int port, uint32_t *payload, int *head);
|
|
|
|
/**
|
|
* Transmit PD message
|
|
*
|
|
* @param port Type-C port number
|
|
* @param type Transmit type
|
|
* @param header Packet header
|
|
* @param cnt Number of bytes in payload
|
|
* @param data Payload
|
|
*
|
|
* @return EC_SUCCESS or error
|
|
*/
|
|
int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
|
|
const uint32_t *data);
|
|
|
|
#endif /* __CROS_EC_USB_PD_TCPM_H */
|