drivers: i2c: add pinctrl driver support

Replace soc-specific pin functions with Zephyr pinctrl api functions for
pin-mux configuration in i2c driver.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
Mulin Chao 2022-02-21 19:02:23 -08:00 committed by Maureen Helm
commit a4b07c396d
7 changed files with 45 additions and 23 deletions

View file

@ -0,0 +1,12 @@
/*
* Copyright (c) 2022 Nuvoton Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <nuvoton/npcx/npcx7/npcx7-pinctrl.dtsi>
&i2c0_0_sda_scl_gpb4_b5 {
bias-pull-up; /* Enable internal pull-up for i2c0_0 */
pinmux-locked; /* Lock pinmuxing */
};

View file

@ -7,7 +7,7 @@
/dts-v1/;
#include <nuvoton/npcx7m6fb.dtsi>
#include <nuvoton/npcx/npcx7/npcx7-pinctrl.dtsi>
#include "npcx7m6fb_evb-pinctrl.dtsi"
/ {
model = "Nuvoton NPCX7M6FB evaluation board";
@ -91,6 +91,8 @@
&i2c0_0 {
status = "okay";
pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>;
pinctrl-names = "default";
clock-frequency = <I2C_BITRATE_FAST>;
};

View file

@ -0,0 +1,12 @@
/*
* Copyright (c) 2022 Nuvoton Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <nuvoton/npcx/npcx9/npcx9-pinctrl.dtsi>
&i2c0_0_sda_scl_gpb4_b5 {
bias-pull-up; /* Enable internal pull-up for i2c0_0 */
pinmux-locked; /* Lock pinmuxing */
};

View file

@ -7,7 +7,7 @@
/dts-v1/;
#include <nuvoton/npcx9m6f.dtsi>
#include <nuvoton/npcx/npcx9/npcx9-pinctrl.dtsi>
#include "npcx9m6f_evb-pinctrl.dtsi"
/ {
model = "Nuvoton NPCX9M6F evaluation board";
@ -104,6 +104,8 @@
&i2c0_0 {
status = "okay";
pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>;
pinctrl-names = "default";
clock-frequency = <I2C_BITRATE_FAST>;
};

View file

@ -31,6 +31,7 @@
#include <assert.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/dt-bindings/i2c/i2c.h>
#include <soc.h>
@ -42,12 +43,11 @@ LOG_MODULE_REGISTER(i2c_npcx_port, LOG_LEVEL_ERR);
/* Device config */
struct i2c_npcx_port_config {
/* pinmux configuration */
const uint8_t alts_size;
const struct npcx_alt *alts_list;
uint32_t bitrate;
uint8_t port;
const struct device *i2c_ctrl;
/* pinmux configuration */
const struct pinctrl_dev_config *pcfg;
};
/* I2C api functions */
@ -131,7 +131,12 @@ static int i2c_npcx_port_init(const struct device *dev)
int ret;
/* Configure pin-mux for I2C device */
npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1);
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
LOG_ERR("I2C pinctrl setup failed (%d)", ret);
return ret;
}
/* Setup initial i2c configuration */
i2c_config = (I2C_MODE_MASTER | i2c_map_dt_bitrate(config->bitrate));
@ -151,15 +156,13 @@ static const struct i2c_driver_api i2c_port_npcx_driver_api = {
/* I2C port init macro functions */
#define NPCX_I2C_PORT_INIT(inst) \
static const struct npcx_alt i2c_port_alts##inst[] = \
NPCX_DT_ALT_ITEMS_LIST(inst); \
PINCTRL_DT_INST_DEFINE(inst); \
\
static const struct i2c_npcx_port_config i2c_npcx_port_cfg_##inst = { \
.port = DT_INST_PROP(inst, port), \
.bitrate = DT_INST_PROP(inst, clock_frequency), \
.alts_size = ARRAY_SIZE(i2c_port_alts##inst), \
.alts_list = i2c_port_alts##inst, \
.i2c_ctrl = DEVICE_DT_GET(DT_INST_PHANDLE(inst, controller)), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, \

View file

@ -609,7 +609,6 @@
#size-cells = <0>;
port = <0x00>;
controller = <&i2c_ctrl0>;
pinctrl-0 = <&alt2_i2c0_0_sl>; /* PINB5.B4 */
label = "I2C_0_PORT_0";
status = "disabled";
};
@ -620,7 +619,6 @@
#size-cells = <0>;
port = <0x10>;
controller = <&i2c_ctrl1>;
pinctrl-0 = <&alt2_i2c1_0_sl>; /* PIN90.87 */
label = "I2C_1_PORT_0";
status = "disabled";
};
@ -631,7 +629,6 @@
#size-cells = <0>;
port = <0x20>;
controller = <&i2c_ctrl2>;
pinctrl-0 = <&alt2_i2c2_0_sl>; /* PIN92.91 */
label = "I2C_2_PORT_0";
status = "disabled";
};
@ -642,7 +639,6 @@
#size-cells = <0>;
port = <0x30>;
controller = <&i2c_ctrl3>;
pinctrl-0 = <&alt2_i2c3_0_sl>; /* PIND1.D0 */
label = "I2C_3_PORT_0";
status = "disabled";
};
@ -653,7 +649,6 @@
#size-cells = <0>;
port = <0x41>;
controller = <&i2c_ctrl4>;
pinctrl-0 = <&alt6_i2c4_1_sl>; /* PINF3.F2 */
label = "I2C_4_PORT_1";
status = "disabled";
};
@ -664,7 +659,6 @@
#size-cells = <0>;
port = <0x50>;
controller = <&i2c_ctrl5>;
pinctrl-0 = <&alt2_i2c5_0_sl>; /* PIN33.36 */
label = "I2C_5_PORT_0";
status = "disabled";
};
@ -675,7 +669,6 @@
#size-cells = <0>;
port = <0x51>;
controller = <&i2c_ctrl5>;
pinctrl-0 = <&alt6_i2c5_1_sl>; /* PINF5.F4 */
label = "I2C_5_PORT_1";
status = "disabled";
};
@ -686,7 +679,6 @@
#size-cells = <0>;
port = <0x60>;
controller = <&i2c_ctrl6>;
pinctrl-0 = <&alt2_i2c6_0_sl>; /* PINC2.C1 */
label = "I2C_6_PORT_0";
status = "disabled";
};
@ -697,7 +689,6 @@
#size-cells = <0>;
port = <0x61>;
controller = <&i2c_ctrl6>;
pinctrl-0 = <&alt6_i2c6_1_sl>; /* PINE4.E3 */
label = "I2C_6_PORT_1";
status = "disabled";
};
@ -708,7 +699,6 @@
#size-cells = <0>;
port = <0x70>;
controller = <&i2c_ctrl7>;
pinctrl-0 = <&alt2_i2c7_0_sl>; /* PINB3.B2 */
label = "I2C_7_PORT_0";
status = "disabled";
};

View file

@ -5,7 +5,7 @@ description: Nuvoton, NPCX-I2C port pads node
compatible: "nuvoton,npcx-i2c-port"
include: i2c-controller.yaml
include: [i2c-controller.yaml, pinctrl-device.yaml]
properties:
port:
@ -19,9 +19,10 @@ properties:
description: i2c controller to handle signals from port pads
pinctrl-0:
type: phandles
required: true
description: configurations of pinmux controllers
pinctrl-names:
required: true
clock-frequency:
required: true