diff options
author | Kevin K Wong <kevin.k.wong@intel.com> | 2016-03-29 18:24:24 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-04-17 12:23:07 -0700 |
commit | b10d12f1c95fa6c13c83f1da34bbaf21063d9a2b (patch) | |
tree | 659475bc971d23fec0fa5d9b671b645f8588a49c /include | |
parent | 096dec1adba5928fdff6c0d0b47d51545580a268 (diff) | |
download | chrome-ec-b10d12f1c95fa6c13c83f1da34bbaf21063d9a2b.tar.gz |
tcpm: update code to support multiple tcpm driver
BUG=chromium:593822
BRANCH=none
TEST=make buildall
Change-Id: Ic30c1b890da7639aa80a53040ecc5bebfb4be2e8
Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/336030
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/usb_pd_tcpm.h | 256 |
1 files changed, 115 insertions, 141 deletions
diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 4e1b04249e..90dae03fd2 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -47,13 +47,124 @@ enum tcpc_transmit_complete { TCPC_TX_COMPLETE_FAILED = 2, }; +struct tcpm_drv { + /** + * Initialize TCPM driver and wait for TCPC readiness. + * + * @param port Type-C port number + * + * @return EC_SUCCESS or error + */ + int (*init)(int port); + + /** + * 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 (*get_cc)(int port, int *cc1, int *cc2); + + /** + * Read VBUS + * + * @param port Type-C port number + * + * @return 0 => VBUS not detected, 1 => VBUS detected + */ + int (*get_vbus_level)(int port); + + /** + * 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 (*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 (*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 (*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 (*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 (*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 (*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 (*transmit)(int port, enum tcpm_transmit_type type, uint16_t header, + const uint32_t *data); + + /** + * TCPC is asserting alert + * + * @param port Type-C port number + */ + void (*tcpc_alert)(int port); +}; + struct tcpc_config_t { int i2c_host_port; int i2c_slave_addr; - /* - * TODO: Consider adding driver struct / function pointers to support - * different TCPM drivers on the same board. - */ + const struct tcpm_drv *drv; }; /** @@ -65,15 +176,6 @@ struct tcpc_config_t { uint16_t tcpc_get_alert_status(void); /** - * 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 @@ -85,7 +187,6 @@ void tcpc_init(int port); * * @param port Type-C port number */ -void tcpc_alert(int port); void tcpc_alert_clear(int port); /** @@ -97,131 +198,4 @@ void tcpc_alert_clear(int port); */ 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); - -/** - * Read VBUS - * - * @param port Type-C port number - * - * @return 0 => VBUS not detected, 1 => VBUS detected - */ -int tcpm_get_vbus_level(int port); - -/** - * 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 TCPC Power Status Mask - * - * @param port Type-C port number - * @param mask => new mask value - * - * @return EC_SUCCESS or error - */ -int tcpm_set_power_status_mask(int port, uint8_t mask); - -/** - * 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 */ |