Skip to content

Commit 5b74f00

Browse files
XenuIsWatchingkartben
authored andcommitted
drivers: i3c: stm32: implement hj_response api
Implement the hj_response api for STM32 I3C. This also implements the PM calls for enabling and disabling runtime PM. For HJ to work the device must be powered on and be receiving a clock. Signed-off-by: Ryan McClelland <[email protected]>
1 parent da6bf19 commit 5b74f00

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

drivers/i3c/i3c_stm32.c

+33
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct i3c_stm32_data {
157157
uint8_t num_addr; /* Number of valid addresses */
158158
} ibi;
159159
struct k_sem ibi_lock_sem; /* Semaphore used for ibi requests */
160+
bool hj_pm_lock; /* Used as flag for setting pm */
160161
#endif
161162
};
162163
/**
@@ -1562,6 +1563,9 @@ static int i3c_stm32_init(const struct device *dev)
15621563

15631564
#ifdef CONFIG_I3C_USE_IBI
15641565
LL_I3C_EnableHJAck(i3c);
1566+
hj_pm_lock = true;
1567+
(void)pm_device_runtime_get(dev);
1568+
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
15651569
#endif
15661570

15671571
return 0;
@@ -1895,6 +1899,34 @@ static void i3c_stm32_error_isr(void *arg)
18951899

18961900
#ifdef CONFIG_I3C_USE_IBI
18971901

1902+
int i3c_stm32_ibi_hj_response(const struct device *dev, bool ack)
1903+
{
1904+
const struct i3c_stm32_config *config = dev->config;
1905+
I3C_TypeDef *i3c = config->i3c;
1906+
1907+
if (ack) {
1908+
/*
1909+
* This prevents pm_device_runtime from being called multiple times
1910+
* with redunant calls
1911+
*/
1912+
if (!hj_pm_lock) {
1913+
hj_pm_lock = true;
1914+
(void)pm_device_runtime_get(dev);
1915+
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
1916+
}
1917+
LL_I3C_EnableHJAck(i3c);
1918+
} else {
1919+
LL_I3C_DisableHJAck(i3c);
1920+
if (hj_pm_lock) {
1921+
hj_pm_lock = false;
1922+
(void)pm_device_runtime_put(dev);
1923+
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
1924+
}
1925+
}
1926+
1927+
return 0;
1928+
}
1929+
18981930
int i3c_stm32_ibi_enable(const struct device *dev, struct i3c_device_desc *target)
18991931
{
19001932
int ret = 0;
@@ -2068,6 +2100,7 @@ static DEVICE_API(i3c, i3c_stm32_driver_api) = {
20682100
.do_daa = i3c_stm32_do_daa,
20692101
.do_ccc = i3c_stm32_do_ccc,
20702102
#ifdef CONFIG_I3C_USE_IBI
2103+
.ibi_hj_response = i3c_stm32_ibi_hj_response,
20712104
.ibi_enable = i3c_stm32_ibi_enable,
20722105
.ibi_disable = i3c_stm32_ibi_disable,
20732106
#endif

0 commit comments

Comments
 (0)