i2c: nordic: switch to phandle arrays for pinmux

Deprecate the scl-pin and sda-pin properties in the devicetree.
Provide new scl-gpios and sda-gpios properties instead.

This lets the user specify SCL and SDA like this:

   &i2c0 {
         scl-gpios = <&gpio0 1 0>;
         sda-gpios = <&gpio1 4 0>;
   };

Instead of having to use:

   &i2c0 {
         scl-pin = <1>;
         sda-pin = <36>;
   };

Provide error checking and understandable error messages for invalid
configurations.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2020-12-13 17:06:02 -08:00 committed by Carles Cufí
commit 821c03a14a
3 changed files with 53 additions and 6 deletions

View file

@ -9,6 +9,7 @@
#include <dt-bindings/i2c/i2c.h>
#include <nrfx_twim.h>
#include <sys/util.h>
#include <soc.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(i2c_nrfx_twim, CONFIG_I2C_LOG_LEVEL);
@ -324,6 +325,14 @@ static int twim_nrfx_pm_control(const struct device *dev,
BUILD_ASSERT(I2C_FREQUENCY(idx) != \
I2C_NRFX_TWIM_INVALID_FREQUENCY, \
"Wrong I2C " #idx " frequency setting in dts"); \
NRF_DT_PSEL_CHECK_EXACTLY_ONE(I2C(idx), \
sda_pin, "sda-pin", \
sda_gpios, "sda-gpios"); \
NRF_DT_PSEL_CHECK_EXACTLY_ONE(I2C(idx), \
scl_pin, "scl-pin", \
scl_gpios, "scl-gpios"); \
NRF_DT_CHECK_GPIO_CTLR_IS_SOC(I2C(idx), sda_gpios, "sda-gpios"); \
NRF_DT_CHECK_GPIO_CTLR_IS_SOC(I2C(idx), scl_gpios, "scl-gpios"); \
static int twim_##idx##_init(const struct device *dev) \
{ \
IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), \
@ -344,8 +353,8 @@ static int twim_nrfx_pm_control(const struct device *dev,
static const struct i2c_nrfx_twim_config twim_##idx##z_config = { \
.twim = NRFX_TWIM_INSTANCE(idx), \
.config = { \
.scl = DT_PROP(I2C(idx), scl_pin), \
.sda = DT_PROP(I2C(idx), sda_pin), \
.scl = NRF_DT_PSEL(I2C(idx), scl_pin, scl_gpios, 0), \
.sda = NRF_DT_PSEL(I2C(idx), sda_pin, sda_gpios, 0), \
.frequency = I2C_FREQUENCY(idx), \
} \
}; \