Skip to content

Commit 6cc41f7

Browse files
committed
drivers: i2c: i2c_dw: Add capability for handling reset device
Reset the device on initializing if reset-node is available in dts. `snps,desingware-i2c` does not define reset-node itself. Add more of an element that inherits `reset-device.yaml` to the `compatible` section to allow defining the reset-node for using this feature. For example. ``` compatible = "reset-device-inherit-node", "snps,designware-i2c"; ``` Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 15d4668 commit 6cc41f7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/i2c/i2c_dw.c

+21
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#if defined(CONFIG_PINCTRL)
2222
#include <zephyr/drivers/pinctrl.h>
2323
#endif
24+
#if defined(CONFIG_RESET)
25+
#include <zephyr/drivers/reset.h>
26+
#endif
2427

2528
#include <errno.h>
2629
#include <zephyr/sys/sys_io.h>
@@ -847,6 +850,15 @@ static int i2c_dw_initialize(const struct device *dev)
847850
union ic_con_register ic_con;
848851
int ret = 0;
849852

853+
#if defined(CONFIG_RESET)
854+
if (rom->reset.dev) {
855+
ret = reset_line_toggle_dt(&rom->reset);
856+
if (ret) {
857+
return ret;
858+
}
859+
}
860+
#endif
861+
850862
#if defined(CONFIG_PINCTRL)
851863
ret = pinctrl_apply_state(rom->pcfg, PINCTRL_STATE_DEFAULT);
852864
if (ret) {
@@ -922,6 +934,14 @@ static int i2c_dw_initialize(const struct device *dev)
922934
#define PINCTRL_DW_CONFIG(n)
923935
#endif
924936

937+
#if defined(CONFIG_RESET)
938+
#define RESET_DW_CONFIG(n) \
939+
IF_ENABLED(DT_INST_NODE_HAS_PROP(0, resets), \
940+
(.reset = RESET_DT_SPEC_INST_GET(n),))
941+
#else
942+
#define RESET_DW_CONFIG(n)
943+
#endif
944+
925945
#define I2C_DW_INIT_PCIE0(n)
926946
#define I2C_DW_INIT_PCIE1(n) DEVICE_PCIE_INST_INIT(n, pcie),
927947
#define I2C_DW_INIT_PCIE(n) \
@@ -985,6 +1005,7 @@ static int i2c_dw_initialize(const struct device *dev)
9851005
I2C_CONFIG_REG_INIT(n) \
9861006
.config_func = i2c_config_##n, \
9871007
.bitrate = DT_INST_PROP(n, clock_frequency), \
1008+
RESET_DW_CONFIG(n) \
9881009
PINCTRL_DW_CONFIG(n) \
9891010
I2C_DW_INIT_PCIE(n) \
9901011
}; \

drivers/i2c/i2c_dw.h

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "DW I2C in DT needs CONFIG_PCIE");
1818
#include <zephyr/drivers/pcie/pcie.h>
1919
#endif
2020

21+
#if defined(CONFIG_RESET)
22+
#include <zephyr/drivers/reset.h>
23+
#endif
24+
2125
#ifdef __cplusplus
2226
extern "C" {
2327
#endif
@@ -93,6 +97,9 @@ struct i2c_dw_rom_config {
9397
#if defined(CONFIG_PINCTRL)
9498
const struct pinctrl_dev_config *pcfg;
9599
#endif
100+
#if defined(CONFIG_RESET)
101+
const struct reset_dt_spec reset;
102+
#endif
96103

97104
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
98105
struct pcie_dev *pcie;

0 commit comments

Comments
 (0)