Skip to content

Commit 2a69690

Browse files
committed
drivers: i2c: NXP: Convert clock control to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access to the clock controller device. Signed-off-by: Kumar Gala <[email protected]>
1 parent de57449 commit 2a69690

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

drivers/i2c/i2c_mcux_flexcomm.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(mcux_flexcomm);
1919

2020
struct mcux_flexcomm_config {
2121
I2C_Type *base;
22-
char *clock_name;
22+
const struct device *clock_dev;
2323
clock_control_subsys_t clock_subsys;
2424
void (*irq_config_func)(const struct device *dev);
2525
uint32_t bitrate;
@@ -28,15 +28,13 @@ struct mcux_flexcomm_config {
2828
struct mcux_flexcomm_data {
2929
i2c_master_handle_t handle;
3030
struct k_sem device_sync_sem;
31-
const struct device *dev_clock;
3231
status_t callback_status;
3332
};
3433

3534
static int mcux_flexcomm_configure(const struct device *dev,
3635
uint32_t dev_config_raw)
3736
{
3837
const struct mcux_flexcomm_config *config = dev->config;
39-
struct mcux_flexcomm_data *data = dev->data;
4038
I2C_Type *base = config->base;
4139
uint32_t clock_freq;
4240
uint32_t baudrate;
@@ -64,7 +62,7 @@ static int mcux_flexcomm_configure(const struct device *dev,
6462
}
6563

6664
/* Get the clock frequency */
67-
if (clock_control_get_rate(data->dev_clock, config->clock_subsys,
65+
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
6866
&clock_freq)) {
6967
return -EINVAL;
7068
}
@@ -187,13 +185,8 @@ static int mcux_flexcomm_init(const struct device *dev)
187185

188186
k_sem_init(&data->device_sync_sem, 0, UINT_MAX);
189187

190-
data->dev_clock = device_get_binding(config->clock_name);
191-
if (data->dev_clock == NULL) {
192-
return -ENODEV;
193-
}
194-
195188
/* Get the clock frequency */
196-
if (clock_control_get_rate(data->dev_clock, config->clock_subsys,
189+
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
197190
&clock_freq)) {
198191
return -EINVAL;
199192
}
@@ -225,7 +218,7 @@ static const struct i2c_driver_api mcux_flexcomm_driver_api = {
225218
static void mcux_flexcomm_config_func_##id(const struct device *dev); \
226219
static const struct mcux_flexcomm_config mcux_flexcomm_config_##id = { \
227220
.base = (I2C_Type *) DT_INST_REG_ADDR(id), \
228-
.clock_name = DT_INST_CLOCKS_LABEL(id), \
221+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(id)), \
229222
.clock_subsys = \
230223
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(id, name),\
231224
.irq_config_func = mcux_flexcomm_config_func_##id, \

drivers/i2c/i2c_mcux_lpi2c.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(mcux_lpi2c);
2323

2424
struct mcux_lpi2c_config {
2525
LPI2C_Type *base;
26-
char *clock_name;
26+
const struct device *clock_dev;
2727
clock_control_subsys_t clock_subsys;
2828
void (*irq_config_func)(const struct device *dev);
2929
uint32_t bitrate;
@@ -41,7 +41,6 @@ static int mcux_lpi2c_configure(const struct device *dev,
4141
{
4242
const struct mcux_lpi2c_config *config = dev->config;
4343
LPI2C_Type *base = config->base;
44-
const struct device *clock_dev;
4544
uint32_t clock_freq;
4645
uint32_t baudrate;
4746

@@ -67,12 +66,7 @@ static int mcux_lpi2c_configure(const struct device *dev,
6766
return -EINVAL;
6867
}
6968

70-
clock_dev = device_get_binding(config->clock_name);
71-
if (clock_dev == NULL) {
72-
return -EINVAL;
73-
}
74-
75-
if (clock_control_get_rate(clock_dev, config->clock_subsys,
69+
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
7670
&clock_freq)) {
7771
return -EINVAL;
7872
}
@@ -193,19 +187,13 @@ static int mcux_lpi2c_init(const struct device *dev)
193187
const struct mcux_lpi2c_config *config = dev->config;
194188
struct mcux_lpi2c_data *data = dev->data;
195189
LPI2C_Type *base = config->base;
196-
const struct device *clock_dev;
197190
uint32_t clock_freq, bitrate_cfg;
198191
lpi2c_master_config_t master_config;
199192
int error;
200193

201194
k_sem_init(&data->device_sync_sem, 0, UINT_MAX);
202195

203-
clock_dev = device_get_binding(config->clock_name);
204-
if (clock_dev == NULL) {
205-
return -EINVAL;
206-
}
207-
208-
if (clock_control_get_rate(clock_dev, config->clock_subsys,
196+
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
209197
&clock_freq)) {
210198
return -EINVAL;
211199
}
@@ -239,7 +227,7 @@ static const struct i2c_driver_api mcux_lpi2c_driver_api = {
239227
\
240228
static const struct mcux_lpi2c_config mcux_lpi2c_config_##n = { \
241229
.base = (LPI2C_Type *)DT_INST_REG_ADDR(n), \
242-
.clock_name = DT_INST_CLOCKS_LABEL(n), \
230+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
243231
.clock_subsys = \
244232
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
245233
.irq_config_func = mcux_lpi2c_config_func_##n, \

0 commit comments

Comments
 (0)