Skip to content

Commit b16fa14

Browse files
gmarullcarlescufi
authored andcommitted
[nrf fromtree] drivers: i2c: nrfx_twim: simplify PM by using pm_device_driver_init
- Driver always initializes the device in the suspended state - If CONFIG_PM_DEVICE_RUNTIME=n, device PM callback will be called with RESUME action, thus setting up pins to default state and enabling the peripheral NOTE: when CONFIG_PM_DEVICE=n, the pinctrl sleep state will not be available (-ENOENT) and so never applied, thus avoiding a pin suspended->active transition. Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit 9f0ebb6)
1 parent a6638ea commit b16fa14

15 files changed

+50
-33
lines changed

drivers/i2c/i2c_nrfx_twim.c

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -297,40 +297,26 @@ static const struct i2c_driver_api i2c_nrfx_twim_driver_api = {
297297
.recover_bus = i2c_nrfx_twim_recover_bus,
298298
};
299299

300-
#ifdef CONFIG_PM_DEVICE
301300
static int twim_nrfx_pm_action(const struct device *dev,
302301
enum pm_device_action action)
303302
{
304303
const struct i2c_nrfx_twim_config *dev_config = dev->config;
305-
int ret = 0;
306304

307305
switch (action) {
308306
case PM_DEVICE_ACTION_RESUME:
309-
ret = pinctrl_apply_state(dev_config->pcfg,
310-
PINCTRL_STATE_DEFAULT);
311-
if (ret < 0) {
312-
return ret;
313-
}
307+
(void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT);
314308
nrfx_twim_enable(&dev_config->twim);
315309
break;
316-
317310
case PM_DEVICE_ACTION_SUSPEND:
318311
nrfx_twim_disable(&dev_config->twim);
319-
320-
ret = pinctrl_apply_state(dev_config->pcfg,
321-
PINCTRL_STATE_SLEEP);
322-
if (ret < 0) {
323-
return ret;
324-
}
312+
(void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP);
325313
break;
326-
327314
default:
328-
ret = -ENOTSUP;
315+
return -ENOTSUP;
329316
}
330317

331-
return ret;
318+
return 0;
332319
}
333-
#endif /* CONFIG_PM_DEVICE */
334320

335321
static int i2c_nrfx_twim_init(const struct device *dev)
336322
{
@@ -342,28 +328,15 @@ static int i2c_nrfx_twim_init(const struct device *dev)
342328
k_sem_init(&dev_data->transfer_sync, 1, 1);
343329
k_sem_init(&dev_data->completion_sync, 0, 1);
344330

345-
int err = pinctrl_apply_state(dev_config->pcfg,
346-
COND_CODE_1(CONFIG_PM_DEVICE_RUNTIME,
347-
(PINCTRL_STATE_SLEEP),
348-
(PINCTRL_STATE_DEFAULT)));
349-
if (err < 0) {
350-
return err;
351-
}
331+
(void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP);
352332

353333
if (nrfx_twim_init(&dev_config->twim, &dev_config->twim_config,
354334
event_handler, dev_data) != NRFX_SUCCESS) {
355335
LOG_ERR("Failed to initialize device: %s", dev->name);
356336
return -EIO;
357337
}
358338

359-
#ifdef CONFIG_PM_DEVICE_RUNTIME
360-
pm_device_init_suspended(dev);
361-
pm_device_runtime_enable(dev);
362-
#else
363-
nrfx_twim_enable(&dev_config->twim);
364-
#endif
365-
366-
return 0;
339+
return pm_device_driver_init(dev, twim_nrfx_pm_action);
367340
}
368341

369342
#define I2C_NRFX_TWIM_INVALID_FREQUENCY ((nrf_twim_frequency_t)-1)

dts/arm/nordic/nrf52805.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
132132
easydma-maxcnt-bits = <14>;
133133
status = "disabled";
134+
zephyr,pm-device-runtime-auto;
134135
};
135136

136137
spi0: spi@40004000 {

dts/arm/nordic/nrf52810.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
136136
easydma-maxcnt-bits = <10>;
137137
status = "disabled";
138+
zephyr,pm-device-runtime-auto;
138139
};
139140

140141
spi0: spi@40004000 {

dts/arm/nordic/nrf52811.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
148148
easydma-maxcnt-bits = <14>;
149149
status = "disabled";
150+
zephyr,pm-device-runtime-auto;
150151
};
151152

152153
spi1: spi@40003000 {

dts/arm/nordic/nrf52820.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
150150
easydma-maxcnt-bits = <15>;
151151
status = "disabled";
152+
zephyr,pm-device-runtime-auto;
152153
};
153154

154155
spi0: spi@40003000 {
@@ -185,6 +186,7 @@
185186
interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>;
186187
easydma-maxcnt-bits = <15>;
187188
status = "disabled";
189+
zephyr,pm-device-runtime-auto;
188190
};
189191

190192
spi1: spi@40004000 {

dts/arm/nordic/nrf52832.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
136136
easydma-maxcnt-bits = <8>;
137137
status = "disabled";
138+
zephyr,pm-device-runtime-auto;
138139
};
139140

140141
spi0: spi@40003000 {
@@ -171,6 +172,7 @@
171172
interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>;
172173
easydma-maxcnt-bits = <8>;
173174
status = "disabled";
175+
zephyr,pm-device-runtime-auto;
174176
};
175177

176178
spi1: spi@40004000 {

dts/arm/nordic/nrf52833.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
150150
easydma-maxcnt-bits = <16>;
151151
status = "disabled";
152+
zephyr,pm-device-runtime-auto;
152153
};
153154

154155
spi0: spi@40003000 {
@@ -185,6 +186,7 @@
185186
interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>;
186187
easydma-maxcnt-bits = <16>;
187188
status = "disabled";
189+
zephyr,pm-device-runtime-auto;
188190
};
189191

190192
spi1: spi@40004000 {

dts/arm/nordic/nrf52840.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>;
138138
easydma-maxcnt-bits = <16>;
139139
status = "disabled";
140+
zephyr,pm-device-runtime-auto;
140141
};
141142

142143
spi0: spi@40003000 {
@@ -173,6 +174,7 @@
173174
interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>;
174175
easydma-maxcnt-bits = <16>;
175176
status = "disabled";
177+
zephyr,pm-device-runtime-auto;
176178
};
177179

178180
spi1: spi@40004000 {

dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ i2c0: i2c@8000 {
108108
interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>;
109109
easydma-maxcnt-bits = <16>;
110110
status = "disabled";
111+
zephyr,pm-device-runtime-auto;
111112
};
112113

113114
spi0: spi@8000 {
@@ -149,6 +150,7 @@ i2c1: i2c@9000 {
149150
interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>;
150151
easydma-maxcnt-bits = <16>;
151152
status = "disabled";
153+
zephyr,pm-device-runtime-auto;
152154
};
153155

154156
spi1: spi@9000 {
@@ -203,6 +205,7 @@ i2c2: i2c@b000 {
203205
interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>;
204206
easydma-maxcnt-bits = <16>;
205207
status = "disabled";
208+
zephyr,pm-device-runtime-auto;
206209
};
207210

208211
spi2: spi@b000 {
@@ -244,6 +247,7 @@ i2c3: i2c@c000 {
244247
interrupts = <12 NRF_DEFAULT_IRQ_PRIORITY>;
245248
easydma-maxcnt-bits = <16>;
246249
status = "disabled";
250+
zephyr,pm-device-runtime-auto;
247251
};
248252

249253
spi3: spi@c000 {

dts/arm/nordic/nrf5340_cpunet.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>;
206206
easydma-maxcnt-bits = <16>;
207207
status = "disabled";
208+
zephyr,pm-device-runtime-auto;
208209
};
209210

210211
spi0: spi@41013000 {

0 commit comments

Comments
 (0)