Skip to content

Commit

Permalink
drivers: i2c: i2c_dw: Add capability for handling reset device
Browse files Browse the repository at this point in the history
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 <tokita.hiroshi@gmail.com>
  • Loading branch information
soburi authored and fabiobaltieri committed Sep 11, 2023
1 parent 5f17a16 commit e2f47c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/i2c/i2c_dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#if defined(CONFIG_PINCTRL)
#include <zephyr/drivers/pinctrl.h>
#endif
#if defined(CONFIG_RESET)
#include <zephyr/drivers/reset.h>
#endif

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

#if defined(CONFIG_RESET)
if (rom->reset.dev) {
ret = reset_line_toggle_dt(&rom->reset);
if (ret) {
return ret;
}
}
#endif

#if defined(CONFIG_PINCTRL)
ret = pinctrl_apply_state(rom->pcfg, PINCTRL_STATE_DEFAULT);
if (ret) {
Expand Down Expand Up @@ -922,6 +934,14 @@ static int i2c_dw_initialize(const struct device *dev)
#define PINCTRL_DW_CONFIG(n)
#endif

#if defined(CONFIG_RESET)
#define RESET_DW_CONFIG(n) \
IF_ENABLED(DT_INST_NODE_HAS_PROP(0, resets), \
(.reset = RESET_DT_SPEC_INST_GET(n),))
#else
#define RESET_DW_CONFIG(n)
#endif

#define I2C_DW_INIT_PCIE0(n)
#define I2C_DW_INIT_PCIE1(n) DEVICE_PCIE_INST_INIT(n, pcie),
#define I2C_DW_INIT_PCIE(n) \
Expand Down Expand Up @@ -985,6 +1005,7 @@ static int i2c_dw_initialize(const struct device *dev)
I2C_CONFIG_REG_INIT(n) \
.config_func = i2c_config_##n, \
.bitrate = DT_INST_PROP(n, clock_frequency), \
RESET_DW_CONFIG(n) \
PINCTRL_DW_CONFIG(n) \
I2C_DW_INIT_PCIE(n) \
}; \
Expand Down
7 changes: 7 additions & 0 deletions drivers/i2c/i2c_dw.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "DW I2C in DT needs CONFIG_PCIE");
#include <zephyr/drivers/pcie/pcie.h>
#endif

#if defined(CONFIG_RESET)
#include <zephyr/drivers/reset.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -93,6 +97,9 @@ struct i2c_dw_rom_config {
#if defined(CONFIG_PINCTRL)
const struct pinctrl_dev_config *pcfg;
#endif
#if defined(CONFIG_RESET)
const struct reset_dt_spec reset;
#endif

#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
struct pcie_dev *pcie;
Expand Down

0 comments on commit e2f47c0

Please sign in to comment.