drivers: i2c: i2c_lpc11u6x: enable pin control
Enable pin control for lpc11u6x i2c driver, and remove pinmux usage from board level DTS files. Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
parent
8e07e21424
commit
069280c8a4
5 changed files with 26 additions and 69 deletions
|
@ -8,9 +8,7 @@
|
|||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/pinmux.h>
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
#include <zephyr/dt-bindings/pinctrl/lpc11u6x-pinctrl.h>
|
||||
#include "i2c_lpc11u6x.h"
|
||||
|
||||
#define DEV_BASE(dev) (((struct lpc11u6x_i2c_config *)(dev->config))->base)
|
||||
|
@ -34,8 +32,10 @@ static int lpc11u6x_i2c_configure(const struct device *dev,
|
|||
{
|
||||
const struct lpc11u6x_i2c_config *cfg = dev->config;
|
||||
struct lpc11u6x_i2c_data *data = dev->data;
|
||||
const struct device *clk_dev, *pinmux_dev;
|
||||
uint32_t speed, flags = 0;
|
||||
const struct device *clk_dev;
|
||||
uint32_t speed;
|
||||
int ret;
|
||||
uint8_t mux_selection = PINCTRL_STATE_DEFAULT;
|
||||
|
||||
switch (I2C_SPEED_GET(dev_config)) {
|
||||
case I2C_SPEED_STANDARD:
|
||||
|
@ -45,7 +45,7 @@ static int lpc11u6x_i2c_configure(const struct device *dev,
|
|||
speed = 400000;
|
||||
break;
|
||||
case I2C_SPEED_FAST_PLUS:
|
||||
flags |= IOCON_FASTI2C_EN;
|
||||
mux_selection = PINCTRL_STATE_FAST_PLUS;
|
||||
speed = 1000000;
|
||||
break;
|
||||
case I2C_SPEED_HIGH:
|
||||
|
@ -67,28 +67,13 @@ static int lpc11u6x_i2c_configure(const struct device *dev,
|
|||
k_mutex_lock(&data->mutex, K_FOREVER);
|
||||
lpc11u6x_i2c_set_bus_speed(cfg, clk_dev, speed);
|
||||
|
||||
if (!flags) {
|
||||
goto exit;
|
||||
ret = pinctrl_apply_state(cfg->pincfg, mux_selection);
|
||||
if (ret) {
|
||||
k_mutex_unlock(&data->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
pinmux_dev = device_get_binding(cfg->scl_pinmux_drv);
|
||||
if (!pinmux_dev) {
|
||||
goto err;
|
||||
}
|
||||
pinmux_pin_set(pinmux_dev, cfg->scl_pin, cfg->scl_flags | flags);
|
||||
|
||||
pinmux_dev = device_get_binding(cfg->sda_pinmux_drv);
|
||||
if (!pinmux_dev) {
|
||||
goto err;
|
||||
}
|
||||
pinmux_pin_set(pinmux_dev, cfg->sda_pin, cfg->sda_flags | flags);
|
||||
|
||||
exit:
|
||||
k_mutex_unlock(&data->mutex);
|
||||
return 0;
|
||||
err:
|
||||
k_mutex_unlock(&data->mutex);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int lpc11u6x_i2c_transfer(const struct device *dev,
|
||||
|
@ -328,20 +313,13 @@ static int lpc11u6x_i2c_init(const struct device *dev)
|
|||
{
|
||||
const struct lpc11u6x_i2c_config *cfg = dev->config;
|
||||
struct lpc11u6x_i2c_data *data = dev->data;
|
||||
const struct device *pinmux_dev, *clk_dev;
|
||||
const struct device *clk_dev;
|
||||
int err;
|
||||
|
||||
/* Configure SCL and SDA pins */
|
||||
pinmux_dev = device_get_binding(cfg->scl_pinmux_drv);
|
||||
if (!pinmux_dev) {
|
||||
return -EINVAL;
|
||||
err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
pinmux_pin_set(pinmux_dev, cfg->scl_pin, cfg->scl_flags);
|
||||
|
||||
pinmux_dev = device_get_binding(cfg->sda_pinmux_drv);
|
||||
if (!pinmux_dev) {
|
||||
return -EINVAL;
|
||||
}
|
||||
pinmux_pin_set(pinmux_dev, cfg->sda_pin, cfg->sda_flags);
|
||||
|
||||
/* Configure clock and de-assert reset for I2Cx */
|
||||
clk_dev = device_get_binding(cfg->clock_drv);
|
||||
|
@ -377,23 +355,16 @@ static const struct i2c_driver_api i2c_api = {
|
|||
|
||||
#define LPC11U6X_I2C_INIT(idx) \
|
||||
\
|
||||
static void lpc11u6x_i2c_isr_config_##idx(const struct device *dev); \
|
||||
static void lpc11u6x_i2c_isr_config_##idx(const struct device *dev); \
|
||||
\
|
||||
PINCTRL_DT_INST_DEFINE(idx); \
|
||||
\
|
||||
static const struct lpc11u6x_i2c_config i2c_cfg_##idx = { \
|
||||
.base = \
|
||||
(struct lpc11u6x_i2c_regs *) DT_INST_REG_ADDR(idx), \
|
||||
.clock_drv = DT_LABEL(DT_INST_PHANDLE(idx, clocks)), \
|
||||
.scl_pinmux_drv = \
|
||||
DT_LABEL(DT_INST_PHANDLE_BY_NAME(idx, pinmuxs, scl)), \
|
||||
.sda_pinmux_drv = \
|
||||
DT_LABEL(DT_INST_PHANDLE_BY_NAME(idx, pinmuxs, sda)), \
|
||||
.irq_config_func = lpc11u6x_i2c_isr_config_##idx, \
|
||||
.scl_flags = \
|
||||
DT_INST_PHA_BY_NAME(idx, pinmuxs, scl, function), \
|
||||
.sda_flags = \
|
||||
DT_INST_PHA_BY_NAME(idx, pinmuxs, sda, function), \
|
||||
.scl_pin = DT_INST_PHA_BY_NAME(idx, pinmuxs, scl, pin), \
|
||||
.sda_pin = DT_INST_PHA_BY_NAME(idx, pinmuxs, sda, pin), \
|
||||
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
|
||||
.clkid = DT_INST_PHA_BY_IDX(idx, clocks, 0, clkid), \
|
||||
}; \
|
||||
\
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#ifndef ZEPHYR_DRIVERS_I2C_I2C_LPC11U6X_H_
|
||||
#define ZEPHYR_DRIVERS_I2C_I2C_LPC11U6X_H_
|
||||
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
|
||||
#define PINCTRL_STATE_FAST_PLUS PINCTRL_STATE_PRIV_START
|
||||
|
||||
#define LPC11U6X_I2C_CONTROL_AA (1 << 2)
|
||||
#define LPC11U6X_I2C_CONTROL_SI (1 << 3)
|
||||
#define LPC11U6X_I2C_CONTROL_STOP (1 << 4)
|
||||
|
@ -66,14 +70,9 @@ struct lpc11u6x_i2c_regs {
|
|||
struct lpc11u6x_i2c_config {
|
||||
struct lpc11u6x_i2c_regs *base;
|
||||
char *clock_drv;
|
||||
char *scl_pinmux_drv;
|
||||
char *sda_pinmux_drv;
|
||||
void (*irq_config_func)(const struct device *dev);
|
||||
uint32_t clkid;
|
||||
uint32_t scl_flags;
|
||||
uint32_t sda_flags;
|
||||
uint8_t scl_pin;
|
||||
uint8_t sda_pin;
|
||||
const struct pinctrl_dev_config *pincfg;
|
||||
};
|
||||
|
||||
struct lpc11u6x_i2c_current_transfer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue