drivers: i2c: telink_b91: replace Pinmux by Pinctrl
Updated driver to use new Pinctrl driver. Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
This commit is contained in:
parent
b49dd6b1b4
commit
693833eb5e
1 changed files with 25 additions and 35 deletions
|
@ -14,14 +14,12 @@ LOG_MODULE_REGISTER(i2c_telink);
|
||||||
|
|
||||||
#include <drivers/i2c.h>
|
#include <drivers/i2c.h>
|
||||||
#include "i2c-priv.h"
|
#include "i2c-priv.h"
|
||||||
#include <drivers/pinmux.h>
|
#include <drivers/pinctrl.h>
|
||||||
#include <dt-bindings/pinctrl/b91-pinctrl.h>
|
|
||||||
|
|
||||||
/* I2C configuration structure */
|
/* I2C configuration structure */
|
||||||
struct i2c_b91_cfg {
|
struct i2c_b91_cfg {
|
||||||
uint32_t bitrate;
|
uint32_t bitrate;
|
||||||
const uint32_t *pinctrl_list;
|
const struct pinctrl_dev_config *pcfg;
|
||||||
size_t pinctrl_list_size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* I2C data structure */
|
/* I2C data structure */
|
||||||
|
@ -124,7 +122,6 @@ static int i2c_b91_transfer(const struct device *dev,
|
||||||
static int i2c_b91_init(const struct device *dev)
|
static int i2c_b91_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
const struct device *pinmux;
|
|
||||||
const struct i2c_b91_cfg *cfg = dev->config;
|
const struct i2c_b91_cfg *cfg = dev->config;
|
||||||
struct i2c_b91_data *data = dev->data;
|
struct i2c_b91_data *data = dev->data;
|
||||||
uint32_t dev_config = (I2C_MODE_MASTER | i2c_map_dt_bitrate(cfg->bitrate));
|
uint32_t dev_config = (I2C_MODE_MASTER | i2c_map_dt_bitrate(cfg->bitrate));
|
||||||
|
@ -139,16 +136,11 @@ static int i2c_b91_init(const struct device *dev)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get pinmux driver */
|
/* configure pins */
|
||||||
pinmux = DEVICE_DT_GET(DT_NODELABEL(pinmux));
|
status = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
|
||||||
if (!device_is_ready(pinmux)) {
|
if (status < 0) {
|
||||||
return -ENODEV;
|
LOG_ERR("Failed to configure I2C pins");
|
||||||
}
|
return status;
|
||||||
|
|
||||||
/* config pins */
|
|
||||||
for (int i = 0; i < cfg->pinctrl_list_size; i++) {
|
|
||||||
pinmux_pin_set(pinmux, B91_PINMUX_GET_PIN(cfg->pinctrl_list[i]),
|
|
||||||
B91_PINMUX_GET_FUNC(cfg->pinctrl_list[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -164,25 +156,23 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) <= 1,
|
||||||
"unsupported I2C instance");
|
"unsupported I2C instance");
|
||||||
|
|
||||||
/* I2C driver registration */
|
/* I2C driver registration */
|
||||||
#define I2C_B91_INIT(inst) \
|
#define I2C_B91_INIT(inst) \
|
||||||
\
|
\
|
||||||
static const uint32_t i2c_pins_##inst[] = \
|
PINCTRL_DT_INST_DEFINE(inst); \
|
||||||
B91_PINMUX_DT_INST_GET_ARRAY(inst, 0); \
|
\
|
||||||
\
|
static struct i2c_b91_data i2c_b91_data_##inst; \
|
||||||
static struct i2c_b91_data i2c_b91_data_##inst; \
|
\
|
||||||
\
|
static struct i2c_b91_cfg i2c_b91_cfg_##inst = { \
|
||||||
static struct i2c_b91_cfg i2c_b91_cfg_##inst = { \
|
.bitrate = DT_INST_PROP(inst, clock_frequency), \
|
||||||
.bitrate = DT_INST_PROP(inst, clock_frequency), \
|
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
|
||||||
.pinctrl_list_size = ARRAY_SIZE(i2c_pins_##inst), \
|
}; \
|
||||||
.pinctrl_list = i2c_pins_##inst \
|
\
|
||||||
}; \
|
I2C_DEVICE_DT_INST_DEFINE(inst, i2c_b91_init, \
|
||||||
\
|
NULL, \
|
||||||
I2C_DEVICE_DT_INST_DEFINE(inst, i2c_b91_init, \
|
&i2c_b91_data_##inst, \
|
||||||
NULL, \
|
&i2c_b91_cfg_##inst, \
|
||||||
&i2c_b91_data_##inst, \
|
POST_KERNEL, \
|
||||||
&i2c_b91_cfg_##inst, \
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||||
POST_KERNEL, \
|
&i2c_b91_api);
|
||||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
|
||||||
&i2c_b91_api);
|
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(I2C_B91_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(I2C_B91_INIT)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue