drivers: i2c: add pinctrl support to Arm sbcon driver
Adds necessary pinctrl support to Arm SBCon I2C driver. Signed-off-by: Samuel Chee <samche01@arm.com> Signed-off-by: Sudan Landge <sudan.landge@arm.com>
This commit is contained in:
parent
6560f57140
commit
4772e183dc
3 changed files with 29 additions and 18 deletions
|
@ -6,3 +6,4 @@ config I2C_SBCON
|
||||||
default y
|
default y
|
||||||
depends on DT_HAS_ARM_VERSATILE_I2C_ENABLED
|
depends on DT_HAS_ARM_VERSATILE_I2C_ENABLED
|
||||||
select I2C_BITBANG
|
select I2C_BITBANG
|
||||||
|
select PINCTRL
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Linaro Ltd.
|
* Copyright (c) 2017 Linaro Ltd.
|
||||||
|
* Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <zephyr/drivers/i2c.h>
|
#include <zephyr/drivers/i2c.h>
|
||||||
|
#include <zephyr/drivers/pinctrl.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(i2c_sbcon, CONFIG_I2C_LOG_LEVEL);
|
LOG_MODULE_REGISTER(i2c_sbcon, CONFIG_I2C_LOG_LEVEL);
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ struct sbcon {
|
||||||
struct i2c_sbcon_config {
|
struct i2c_sbcon_config {
|
||||||
struct sbcon *sbcon; /* Address of hardware registers */
|
struct sbcon *sbcon; /* Address of hardware registers */
|
||||||
uint32_t bitrate; /* I2C bus speed in Hz */
|
uint32_t bitrate; /* I2C bus speed in Hz */
|
||||||
|
const struct pinctrl_dev_config *pctrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Driver instance data */
|
/* Driver instance data */
|
||||||
|
@ -128,7 +130,14 @@ static int i2c_sbcon_init(const struct device *dev)
|
||||||
struct i2c_sbcon_context *context = dev->data;
|
struct i2c_sbcon_context *context = dev->data;
|
||||||
const struct i2c_sbcon_config *config = dev->config;
|
const struct i2c_sbcon_config *config = dev->config;
|
||||||
int ret;
|
int ret;
|
||||||
|
ret = pinctrl_apply_state(config->pctrl, PINCTRL_STATE_DEFAULT);
|
||||||
|
|
||||||
|
/* some pins are not available externally so,
|
||||||
|
* ignore if there is no entry for them
|
||||||
|
*/
|
||||||
|
if (ret != -ENOENT) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
i2c_bitbang_init(&context->bitbang, &io_fns, config->sbcon);
|
i2c_bitbang_init(&context->bitbang, &io_fns, config->sbcon);
|
||||||
|
|
||||||
ret = i2c_bitbang_configure(&context->bitbang,
|
ret = i2c_bitbang_configure(&context->bitbang,
|
||||||
|
@ -136,24 +145,24 @@ static int i2c_sbcon_init(const struct device *dev)
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOG_ERR("failed to configure I2C bitbang: %d", ret);
|
LOG_ERR("failed to configure I2C bitbang: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_I2C_SBCON(_num) \
|
#define DEFINE_I2C_SBCON(_num) \
|
||||||
\
|
PINCTRL_DT_INST_DEFINE(_num); \
|
||||||
static struct i2c_sbcon_context i2c_sbcon_dev_data_##_num; \
|
static struct i2c_sbcon_context i2c_sbcon_dev_data_##_num; \
|
||||||
\
|
\
|
||||||
static const struct i2c_sbcon_config i2c_sbcon_dev_cfg_##_num = { \
|
static const struct i2c_sbcon_config i2c_sbcon_dev_cfg_##_num = { \
|
||||||
.sbcon = (void *)DT_INST_REG_ADDR(_num), \
|
.sbcon = (void *)DT_INST_REG_ADDR(_num), \
|
||||||
.bitrate = DT_INST_PROP(_num, clock_frequency), \
|
.bitrate = DT_INST_PROP(_num, clock_frequency), \
|
||||||
}; \
|
.pctrl = PINCTRL_DT_INST_DEV_CONFIG_GET(_num), \
|
||||||
\
|
}; \
|
||||||
I2C_DEVICE_DT_INST_DEFINE(_num, \
|
\
|
||||||
i2c_sbcon_init, \
|
I2C_DEVICE_DT_INST_DEFINE(_num, \
|
||||||
NULL, \
|
i2c_sbcon_init, \
|
||||||
&i2c_sbcon_dev_data_##_num, \
|
NULL, \
|
||||||
&i2c_sbcon_dev_cfg_##_num, \
|
&i2c_sbcon_dev_data_##_num, \
|
||||||
PRE_KERNEL_2, CONFIG_I2C_INIT_PRIORITY, &api);
|
&i2c_sbcon_dev_cfg_##_num, \
|
||||||
|
PRE_KERNEL_2, CONFIG_I2C_INIT_PRIORITY, &api);
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(DEFINE_I2C_SBCON)
|
DT_INST_FOREACH_STATUS_OKAY(DEFINE_I2C_SBCON)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
# Copyright (c) 2018, Linaro Limited
|
# Copyright (c) 2018, Linaro Limited
|
||||||
|
# Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
description: ARM SBCon two-wire serial bus interface
|
description: ARM SBCon two-wire serial bus interface
|
||||||
|
|
||||||
compatible: "arm,versatile-i2c"
|
compatible: "arm,versatile-i2c"
|
||||||
|
|
||||||
include: i2c-controller.yaml
|
include: [i2c-controller.yaml, pinctrl-device.yaml]
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
reg:
|
reg:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue