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
|
@ -60,9 +60,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
&i2c0 {
|
&i2c0 {
|
||||||
pinmuxs = <&pinmux0 4 IOCON_FUNC1>,
|
|
||||||
<&pinmux0 5 IOCON_FUNC1>;
|
|
||||||
pinmux-names = "SCL", "SDA";
|
|
||||||
pinctrl-0 = <&i2c0_default>;
|
pinctrl-0 = <&i2c0_default>;
|
||||||
pinctrl-1 = <&i2c0_fast>;
|
pinctrl-1 = <&i2c0_fast>;
|
||||||
pinctrl-names = "default", "fast-plus";
|
pinctrl-names = "default", "fast-plus";
|
||||||
|
@ -76,9 +73,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
&i2c1 {
|
&i2c1 {
|
||||||
pinmuxs = <&pinmux0 7 (IOCON_FUNC3| IOCON_OPENDRAIN_EN)>,
|
|
||||||
<&pinmux1 24 (IOCON_FUNC2 | IOCON_OPENDRAIN_EN)>;
|
|
||||||
pinmux-names = "SCL", "SDA";
|
|
||||||
pinctrl-0 = <&i2c1_default>;
|
pinctrl-0 = <&i2c1_default>;
|
||||||
pinctrl-1 = <&i2c1_fast>;
|
pinctrl-1 = <&i2c1_fast>;
|
||||||
pinctrl-names = "default", "fast-plus";
|
pinctrl-names = "default", "fast-plus";
|
||||||
|
|
|
@ -107,12 +107,9 @@ arduino_serial: &uart4 {
|
||||||
};
|
};
|
||||||
|
|
||||||
arduino_i2c: &i2c0 {
|
arduino_i2c: &i2c0 {
|
||||||
pinmuxs = <&pinmux0 4 IOCON_FUNC1>,
|
|
||||||
<&pinmux0 5 IOCON_FUNC1>;
|
|
||||||
pinctrl-0 = <&i2c0_default>;
|
pinctrl-0 = <&i2c0_default>;
|
||||||
pinctrl-1 = <&i2c0_fast>;
|
pinctrl-1 = <&i2c0_fast>;
|
||||||
pinctrl-names = "default", "fast-plus";
|
pinctrl-names = "default", "fast-plus";
|
||||||
pinmux-names = "SCL", "SDA";
|
|
||||||
status = "okay";
|
status = "okay";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/drivers/i2c.h>
|
#include <zephyr/drivers/i2c.h>
|
||||||
#include <zephyr/drivers/pinmux.h>
|
|
||||||
#include <zephyr/drivers/clock_control.h>
|
#include <zephyr/drivers/clock_control.h>
|
||||||
#include <zephyr/dt-bindings/pinctrl/lpc11u6x-pinctrl.h>
|
|
||||||
#include "i2c_lpc11u6x.h"
|
#include "i2c_lpc11u6x.h"
|
||||||
|
|
||||||
#define DEV_BASE(dev) (((struct lpc11u6x_i2c_config *)(dev->config))->base)
|
#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;
|
const struct lpc11u6x_i2c_config *cfg = dev->config;
|
||||||
struct lpc11u6x_i2c_data *data = dev->data;
|
struct lpc11u6x_i2c_data *data = dev->data;
|
||||||
const struct device *clk_dev, *pinmux_dev;
|
const struct device *clk_dev;
|
||||||
uint32_t speed, flags = 0;
|
uint32_t speed;
|
||||||
|
int ret;
|
||||||
|
uint8_t mux_selection = PINCTRL_STATE_DEFAULT;
|
||||||
|
|
||||||
switch (I2C_SPEED_GET(dev_config)) {
|
switch (I2C_SPEED_GET(dev_config)) {
|
||||||
case I2C_SPEED_STANDARD:
|
case I2C_SPEED_STANDARD:
|
||||||
|
@ -45,7 +45,7 @@ static int lpc11u6x_i2c_configure(const struct device *dev,
|
||||||
speed = 400000;
|
speed = 400000;
|
||||||
break;
|
break;
|
||||||
case I2C_SPEED_FAST_PLUS:
|
case I2C_SPEED_FAST_PLUS:
|
||||||
flags |= IOCON_FASTI2C_EN;
|
mux_selection = PINCTRL_STATE_FAST_PLUS;
|
||||||
speed = 1000000;
|
speed = 1000000;
|
||||||
break;
|
break;
|
||||||
case I2C_SPEED_HIGH:
|
case I2C_SPEED_HIGH:
|
||||||
|
@ -67,28 +67,13 @@ static int lpc11u6x_i2c_configure(const struct device *dev,
|
||||||
k_mutex_lock(&data->mutex, K_FOREVER);
|
k_mutex_lock(&data->mutex, K_FOREVER);
|
||||||
lpc11u6x_i2c_set_bus_speed(cfg, clk_dev, speed);
|
lpc11u6x_i2c_set_bus_speed(cfg, clk_dev, speed);
|
||||||
|
|
||||||
if (!flags) {
|
ret = pinctrl_apply_state(cfg->pincfg, mux_selection);
|
||||||
goto exit;
|
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);
|
k_mutex_unlock(&data->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
|
||||||
k_mutex_unlock(&data->mutex);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lpc11u6x_i2c_transfer(const struct device *dev,
|
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;
|
const struct lpc11u6x_i2c_config *cfg = dev->config;
|
||||||
struct lpc11u6x_i2c_data *data = dev->data;
|
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 */
|
err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT);
|
||||||
pinmux_dev = device_get_binding(cfg->scl_pinmux_drv);
|
if (err) {
|
||||||
if (!pinmux_dev) {
|
return err;
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
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 */
|
/* Configure clock and de-assert reset for I2Cx */
|
||||||
clk_dev = device_get_binding(cfg->clock_drv);
|
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) \
|
#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 = { \
|
static const struct lpc11u6x_i2c_config i2c_cfg_##idx = { \
|
||||||
.base = \
|
.base = \
|
||||||
(struct lpc11u6x_i2c_regs *) DT_INST_REG_ADDR(idx), \
|
(struct lpc11u6x_i2c_regs *) DT_INST_REG_ADDR(idx), \
|
||||||
.clock_drv = DT_LABEL(DT_INST_PHANDLE(idx, clocks)), \
|
.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, \
|
.irq_config_func = lpc11u6x_i2c_isr_config_##idx, \
|
||||||
.scl_flags = \
|
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
|
||||||
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), \
|
|
||||||
.clkid = DT_INST_PHA_BY_IDX(idx, clocks, 0, clkid), \
|
.clkid = DT_INST_PHA_BY_IDX(idx, clocks, 0, clkid), \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#ifndef ZEPHYR_DRIVERS_I2C_I2C_LPC11U6X_H_
|
#ifndef ZEPHYR_DRIVERS_I2C_I2C_LPC11U6X_H_
|
||||||
#define 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_AA (1 << 2)
|
||||||
#define LPC11U6X_I2C_CONTROL_SI (1 << 3)
|
#define LPC11U6X_I2C_CONTROL_SI (1 << 3)
|
||||||
#define LPC11U6X_I2C_CONTROL_STOP (1 << 4)
|
#define LPC11U6X_I2C_CONTROL_STOP (1 << 4)
|
||||||
|
@ -66,14 +70,9 @@ struct lpc11u6x_i2c_regs {
|
||||||
struct lpc11u6x_i2c_config {
|
struct lpc11u6x_i2c_config {
|
||||||
struct lpc11u6x_i2c_regs *base;
|
struct lpc11u6x_i2c_regs *base;
|
||||||
char *clock_drv;
|
char *clock_drv;
|
||||||
char *scl_pinmux_drv;
|
|
||||||
char *sda_pinmux_drv;
|
|
||||||
void (*irq_config_func)(const struct device *dev);
|
void (*irq_config_func)(const struct device *dev);
|
||||||
uint32_t clkid;
|
uint32_t clkid;
|
||||||
uint32_t scl_flags;
|
const struct pinctrl_dev_config *pincfg;
|
||||||
uint32_t sda_flags;
|
|
||||||
uint8_t scl_pin;
|
|
||||||
uint8_t sda_pin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lpc11u6x_i2c_current_transfer {
|
struct lpc11u6x_i2c_current_transfer {
|
||||||
|
|
|
@ -5,7 +5,7 @@ description: LPC11U6X I2C Controller
|
||||||
|
|
||||||
compatible: "nxp,lpc11u6x-i2c"
|
compatible: "nxp,lpc11u6x-i2c"
|
||||||
|
|
||||||
include: i2c-controller.yaml
|
include: [i2c-controller.yaml, pinctrl-device.yaml]
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
reg:
|
reg:
|
||||||
|
@ -17,12 +17,8 @@ properties:
|
||||||
clocks:
|
clocks:
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
pinmuxs:
|
pinctrl-0:
|
||||||
type: phandle-array
|
|
||||||
required: true
|
required: true
|
||||||
description: SDA and SCL pins
|
|
||||||
|
|
||||||
pinmux-names:
|
pinctrl-names:
|
||||||
type: string-array
|
|
||||||
required: true
|
required: true
|
||||||
description: Pin names for SDA and SCL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue