drivers: i2c: Update sam drivers to use pinctrl

This update Atmel sam i2c drivers to use pinctrl driver and API. It
updates all boards with new pinctrl groups format. This add missing
i2c-0 alias into sam4l_ek board.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
Gerson Fernando Budke 2022-03-12 15:56:05 -03:00 committed by Marti Bolivar
commit a27304b658
23 changed files with 127 additions and 77 deletions

View file

@ -22,6 +22,7 @@
#include <init.h>
#include <soc.h>
#include <drivers/i2c.h>
#include <drivers/pinctrl.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
@ -64,8 +65,7 @@ struct i2c_sam_twim_dev_cfg {
Twim *regs;
void (*irq_config)(void);
uint32_t bitrate;
const struct soc_gpio_pin *pin_list;
uint8_t pin_list_size;
const struct pinctrl_dev_config *pcfg;
uint8_t periph_id;
uint8_t irq_id;
@ -552,7 +552,10 @@ static int i2c_sam_twim_initialize(const struct device *dev)
k_sem_init(&data->sem, 0, 1);
/* Connect pins to the peripheral */
soc_gpio_list_configure(cfg->pin_list, cfg->pin_list_size);
ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
return ret;
}
/* Enable module's clock */
soc_pmc_peripheral_enable(cfg->periph_id);
@ -599,6 +602,7 @@ static const struct i2c_driver_api i2c_sam_twim_driver_api = {
.hs_data_strength_low = DT_INST_ENUM_IDX(n, hs_data_strength_low)
#define I2C_TWIM_SAM_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static void i2c##n##_sam_irq_config(void) \
{ \
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \
@ -606,15 +610,12 @@ static const struct i2c_driver_api i2c_sam_twim_driver_api = {
DEVICE_DT_INST_GET(n), 0); \
} \
\
static const struct soc_gpio_pin pins_twim##n[] = ATMEL_SAM_DT_INST_PINS(n); \
\
static const struct i2c_sam_twim_dev_cfg i2c##n##_sam_config = {\
.regs = (Twim *)DT_INST_REG_ADDR(n), \
.irq_config = i2c##n##_sam_irq_config, \
.periph_id = DT_INST_PROP(n, peripheral_id), \
.irq_id = DT_INST_IRQN(n), \
.pin_list = pins_twim##n, \
.pin_list_size = ARRAY_SIZE(pins_twim##n), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
.bitrate = DT_INST_PROP(n, clock_frequency), \
.hs_master_code = DT_INST_ENUM_IDX(n, hs_master_code), \
I2C_TWIM_SAM_SLEW_REGS(n), \

View file

@ -22,6 +22,7 @@
#include <init.h>
#include <soc.h>
#include <drivers/i2c.h>
#include <drivers/pinctrl.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
@ -41,8 +42,7 @@ struct i2c_sam_twi_dev_cfg {
Twi *regs;
void (*irq_config)(void);
uint32_t bitrate;
const struct soc_gpio_pin *pin_list;
uint8_t pin_list_size;
const struct pinctrl_dev_config *pcfg;
uint8_t periph_id;
uint8_t irq_id;
};
@ -303,7 +303,10 @@ static int i2c_sam_twi_initialize(const struct device *dev)
k_sem_init(&dev_data->sem, 0, 1);
/* Connect pins to the peripheral */
soc_gpio_list_configure(dev_cfg->pin_list, dev_cfg->pin_list_size);
ret = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
return ret;
}
/* Enable module's clock */
soc_pmc_peripheral_enable(dev_cfg->periph_id);
@ -333,6 +336,7 @@ static const struct i2c_driver_api i2c_sam_twi_driver_api = {
};
#define I2C_TWI_SAM_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static void i2c##n##_sam_irq_config(void) \
{ \
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \
@ -340,15 +344,12 @@ static const struct i2c_driver_api i2c_sam_twi_driver_api = {
DEVICE_DT_INST_GET(n), 0); \
} \
\
static const struct soc_gpio_pin pins_twi##n[] = ATMEL_SAM_DT_INST_PINS(n); \
\
static const struct i2c_sam_twi_dev_cfg i2c##n##_sam_config = { \
.regs = (Twi *)DT_INST_REG_ADDR(n), \
.irq_config = i2c##n##_sam_irq_config, \
.periph_id = DT_INST_PROP(n, peripheral_id), \
.irq_id = DT_INST_IRQN(n), \
.pin_list = pins_twi##n, \
.pin_list_size = ARRAY_SIZE(pins_twi##n), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
.bitrate = DT_INST_PROP(n, clock_frequency), \
}; \
\

View file

@ -20,6 +20,7 @@
#include <init.h>
#include <soc.h>
#include <drivers/i2c.h>
#include <drivers/pinctrl.h>
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
#include <logging/log.h>
@ -41,8 +42,7 @@ struct i2c_sam_twihs_dev_cfg {
Twihs *regs;
void (*irq_config)(void);
uint32_t bitrate;
const struct soc_gpio_pin *pin_list;
uint8_t pin_list_size;
const struct pinctrl_dev_config *pcfg;
uint8_t periph_id;
uint8_t irq_id;
};
@ -290,7 +290,10 @@ static int i2c_sam_twihs_initialize(const struct device *dev)
k_sem_init(&dev_data->sem, 0, 1);
/* Connect pins to the peripheral */
soc_gpio_list_configure(dev_cfg->pin_list, dev_cfg->pin_list_size);
ret = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
return ret;
}
/* Enable module's clock */
soc_pmc_peripheral_enable(dev_cfg->periph_id);
@ -320,6 +323,7 @@ static const struct i2c_driver_api i2c_sam_twihs_driver_api = {
};
#define I2C_TWIHS_SAM_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static void i2c##n##_sam_irq_config(void) \
{ \
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \
@ -327,15 +331,12 @@ static const struct i2c_driver_api i2c_sam_twihs_driver_api = {
DEVICE_DT_INST_GET(n), 0); \
} \
\
static const struct soc_gpio_pin pins_twihs##n[] = ATMEL_SAM_DT_INST_PINS(n); \
\
static const struct i2c_sam_twihs_dev_cfg i2c##n##_sam_config = {\
.regs = (Twihs *)DT_INST_REG_ADDR(n), \
.irq_config = i2c##n##_sam_irq_config, \
.periph_id = DT_INST_PROP(n, peripheral_id), \
.irq_id = DT_INST_IRQN(n), \
.pin_list = pins_twihs##n, \
.pin_list_size = ARRAY_SIZE(pins_twihs##n), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
.bitrate = DT_INST_PROP(n, clock_frequency), \
}; \
\