Skip to content

Commit 9dfd87b

Browse files
committed
device: esp32: 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 2a69690 commit 9dfd87b

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

drivers/i2c/i2c_esp32.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct i2c_esp32_data {
6262

6363
struct k_sem fifo_sem;
6464
struct k_sem transfer_sem;
65-
const struct device *clock_dev;
6665
};
6766

6867
typedef void (*irq_connect_cb)(void);
@@ -71,7 +70,7 @@ struct i2c_esp32_config {
7170
int index;
7271

7372
irq_connect_cb connect_irq;
74-
const char *clock_name;
73+
const struct device *clock_dev;
7574

7675
const struct {
7776
int sda_out;
@@ -141,7 +140,6 @@ static int i2c_esp32_configure_speed(const struct device *dev,
141140
};
142141

143142
const struct i2c_esp32_config *config = dev->config;
144-
struct i2c_esp32_data *data = dev->data;
145143

146144
uint32_t sys_clk_freq = 0;
147145
uint32_t freq_hz = speed_to_freq_tbl[speed];
@@ -151,7 +149,7 @@ static int i2c_esp32_configure_speed(const struct device *dev,
151149
return -ENOTSUP;
152150
}
153151

154-
if (clock_control_get_rate(data->clock_dev,
152+
if (clock_control_get_rate(config->clock_dev,
155153
config->peripheral_id,
156154
&sys_clk_freq)) {
157155
return -EINVAL;
@@ -205,7 +203,7 @@ static int i2c_esp32_configure(const struct device *dev, uint32_t dev_config)
205203
return ret;
206204
}
207205

208-
clock_control_on(data->clock_dev, config->peripheral_id);
206+
clock_control_on(config->clock_dev, config->peripheral_id);
209207

210208
/* MSB or LSB first is configurable for both TX and RX */
211209
if (config->mode.tx_lsb_first) {
@@ -588,7 +586,7 @@ static void i2c_esp32_connect_irq_0(void)
588586
static const struct i2c_esp32_config i2c_esp32_config_0 = {
589587
.index = 0,
590588
.connect_irq = i2c_esp32_connect_irq_0,
591-
.clock_name = DT_INST_CLOCKS_LABEL(0),
589+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0)),
592590
.peripheral_id = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(0, offset),
593591
.sig = {
594592
.sda_out = I2CEXT0_SDA_OUT_IDX,
@@ -632,7 +630,7 @@ static void i2c_esp32_connect_irq_1(void)
632630
static const struct i2c_esp32_config i2c_esp32_config_1 = {
633631
.index = 1,
634632
.connect_irq = i2c_esp32_connect_irq_1,
635-
.clock_name = DT_INST_CLOCKS_LABEL(1),
633+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(1)),
636634
.peripheral_id = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(1, offset),
637635
.sig = {
638636
.sda_out = I2CEXT1_SDA_OUT_IDX,
@@ -671,9 +669,6 @@ static int i2c_esp32_init(const struct device *dev)
671669
const struct i2c_esp32_config *config = dev->config;
672670
struct i2c_esp32_data *data = dev->data;
673671
uint32_t bitrate_cfg = i2c_map_dt_bitrate(config->bitrate);
674-
data->clock_dev = device_get_binding(config->clock_name);
675-
676-
__ASSERT_NO_MSG(data->clock_dev);
677672

678673
unsigned int key = irq_lock();
679674

drivers/serial/uart_esp32.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct uart_esp32_regs_t {
6464
struct uart_esp32_config {
6565

6666
struct uart_device_config dev_conf;
67-
const char *clock_name;
67+
const struct device *clock_dev;
6868

6969
const struct {
7070
int tx_out;
@@ -91,7 +91,6 @@ struct uart_esp32_config {
9191
/* driver data */
9292
struct uart_esp32_data {
9393
struct uart_config uart_config;
94-
const struct device *clock_dev;
9594
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
9695
uart_irq_callback_user_data_t irq_cb;
9796
void *irq_cb_data;
@@ -192,7 +191,7 @@ static int uart_esp32_set_baudrate(const struct device *dev, int baudrate)
192191
{
193192
uint32_t sys_clk_freq = 0;
194193

195-
if (clock_control_get_rate(DEV_DATA(dev)->clock_dev,
194+
if (clock_control_get_rate(DEV_CFG(dev)->clock_dev,
196195
DEV_CFG(dev)->peripheral_id,
197196
&sys_clk_freq)) {
198197
return -EINVAL;
@@ -249,7 +248,7 @@ static int uart_esp32_configure(const struct device *dev,
249248
| (UART_TX_FIFO_THRESH << UART_TXFIFO_EMPTY_THRHD_S);
250249

251250
uart_esp32_configure_pins(dev);
252-
clock_control_on(DEV_DATA(dev)->clock_dev, DEV_CFG(dev)->peripheral_id);
251+
clock_control_on(DEV_CFG(dev)->clock_dev, DEV_CFG(dev)->peripheral_id);
253252

254253
/*
255254
* Reset RX Buffer by reading all received bytes
@@ -317,12 +316,6 @@ static int uart_esp32_configure(const struct device *dev,
317316

318317
static int uart_esp32_init(const struct device *dev)
319318
{
320-
struct uart_esp32_data *data = DEV_DATA(dev);
321-
322-
data->clock_dev = device_get_binding(DEV_CFG(dev)->clock_name);
323-
324-
__ASSERT_NO_MSG(data->clock_dev);
325-
326319
uart_esp32_configure(dev, &DEV_DATA(dev)->uart_config);
327320

328321
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
@@ -503,7 +496,7 @@ static const DRAM_ATTR struct uart_esp32_config uart_esp32_cfg_port_##idx = {
503496
ESP32_UART_IRQ_HANDLER_FUNC(idx) \
504497
}, \
505498
\
506-
.clock_name = DT_INST_CLOCKS_LABEL(idx), \
499+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
507500
\
508501
.signals = { \
509502
.tx_out = U##idx##TXD_OUT_IDX, \

0 commit comments

Comments
 (0)