drivers: i2c: npcx: add support to wake up from sleep mode

Add support to wake up from sleep mode by START condition when i2c
is configured to target mode.

Signed-off-by: Alvis Sun <yfsun@nuvoton.com>
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
Mulin Chao 2024-06-05 17:51:17 +08:00 committed by Benjamin Cabé
commit 47f472aa5c
5 changed files with 195 additions and 27 deletions

View file

@ -105,6 +105,35 @@ void npcx_pinctrl_i2c_port_sel(int controller, int port)
}
}
void npcx_i2c_target_start_wk_enable(int controller, bool enable)
{
struct glue_reg *const inst_glue = HAL_GLUE_INST();
if (enable) {
/* Clear Start condition detection status */
inst_glue->SMB_SBD |= BIT(controller);
/* Enable wake up event assertion */
inst_glue->SMB_EEN |= BIT(controller);
} else {
/* Disable wake up event assertion */
inst_glue->SMB_EEN &= ~BIT(controller);
}
}
void npcx_i2c_target_clear_detection_event(void)
{
struct glue_reg *const inst_glue = HAL_GLUE_INST();
uint8_t een = inst_glue->SMB_EEN;
uint8_t sbd = inst_glue->SMB_SBD;
/* Clear Start condition detection status */
for (uint8_t i = 0; i < 8; i++) {
if ((een & BIT(i)) != 0 && (sbd & BIT(i)) != 0) {
inst_glue->SMB_SBD |= BIT(i);
}
}
}
int npcx_pinctrl_flash_write_protect_set(void)
{
struct scfg_reg *inst_scfg = HAL_SFCG_INST();

View file

@ -94,6 +94,20 @@ void npcx_host_interface_sel(enum npcx_hif_type hif_type);
*/
void npcx_i3c_target_sel(uint8_t module, bool enable);
/**
* @brief Enable smb controller wake up event detection in target mode
*
* @param controller i2c controller device
* @param enable True to enable wake up event detection, false to disable.
*/
void npcx_i2c_target_start_wk_enable(int controller, bool enable);
/**
* @brief Clear wake up event detection status in target mode
*
*/
void npcx_i2c_target_clear_detection_event(void);
#ifdef __cplusplus
}
#endif