usb_i2c: Fail if board I2C bridge is disabled

Add usb_i2c_board_is_enabled().

On Cr50, this is now also connected to the I2C CCD capability.  The
USB-I2C bridge can only be used when the capability is available.

On other platforms (Servo V4, etc.) where usb_i2c_board_enable() is
a no-op, add a dummy implementation which always returns true.

See go/cr50-ccd-wp for more information.

BUG=b:62537474
BRANCH=cr50
TEST=manual with CR50_DEV=1
	Connect host PC to dev board USB port
	On host PC:
		sudo servod -c ccd_cr50.xml -c reef_r1_inas.xml
		dut-control pp3300_ec_shv_reg --> fail, error 0x8001

	ccdoops --> reset I2C config
	ccd i2c disable --> I2C disabled

	On host PC:
		sudo servod -c ccd_cr50.xml -c reef_r1_inas.xml
		dut-control pp3300_ec_shv_reg --> fail, error 0x0006

	ccd i2c enable --> I2C enabled
	ccdunlock --> I2C disabled
	ccdoops --> I2C enabled
	ccdset i2c unlesslocked
	ccdlock --> I2C disabled
	ccdunlock --> I2C enabled

Change-Id: Ia3df32e239a5f7c5915bc6c7e408ce0dc8b26c89
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/590577
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
This commit is contained in:
Randall Spangler
2017-07-25 16:22:27 -07:00
committed by chrome-bot
parent ddbfe690e2
commit 00ea73ab16
11 changed files with 84 additions and 6 deletions

View File

@@ -130,6 +130,9 @@ enum ccd_capability {
/* Allow Cr50 firmware update without wiping TPM data */
CCD_CAP_CR50_FW_UPDATE_WITHOUT_TPM_WIPE = 14,
/* Access to I2C via USB */
CCD_CAP_I2C = 15,
/* Number of currently defined capabilities */
CCD_CAP_COUNT
};

View File

@@ -45,6 +45,7 @@
* 0x0003: Write count invalid (mismatch with merged payload)
* 0x0004: Read count invalid (> 60 bytes)
* 0x0005: The port specified is invalid.
* 0x0006: The I2C interface is disabled.
* 0x8000: Unknown error mask
* The bottom 15 bits will contain the bottom 15 bits from the EC
* error code.
@@ -60,6 +61,7 @@ enum usb_i2c_error {
USB_I2C_WRITE_COUNT_INVALID = 0x0003,
USB_I2C_READ_COUNT_INVALID = 0x0004,
USB_I2C_PORT_INVALID = 0x0005,
USB_I2C_DISABLED = 0x0006,
USB_I2C_UNKNOWN_ERROR = 0x8000,
};
@@ -149,8 +151,27 @@ void usb_i2c_deferred(struct usb_i2c_config const *config);
/*
* These functions should be implemented by the board to provide any board
* specific operations required to enable or disable access to the I2C device.
* specific operations required to enable or disable access to the I2C device,
* and to return the current board enable state.
*/
/**
* Enable the I2C device
*
* @return EC_SUCCESS or non-zero error code.
*/
int usb_i2c_board_enable(void);
/**
* Disable the I2C device
*/
void usb_i2c_board_disable(void);
/**
* Check if the I2C device is enabled
*
* @return 1 if enabled, 0 if disabled.
*/
int usb_i2c_board_is_enabled(void);
#endif /* __CROS_USB_I2C_H */