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 <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2021-02-11 19:21:32 -06:00 committed by Kumar Gala
commit 9dfd87b931
2 changed files with 9 additions and 21 deletions

View file

@ -62,7 +62,6 @@ struct i2c_esp32_data {
struct k_sem fifo_sem;
struct k_sem transfer_sem;
const struct device *clock_dev;
};
typedef void (*irq_connect_cb)(void);
@ -71,7 +70,7 @@ struct i2c_esp32_config {
int index;
irq_connect_cb connect_irq;
const char *clock_name;
const struct device *clock_dev;
const struct {
int sda_out;
@ -141,7 +140,6 @@ static int i2c_esp32_configure_speed(const struct device *dev,
};
const struct i2c_esp32_config *config = dev->config;
struct i2c_esp32_data *data = dev->data;
uint32_t sys_clk_freq = 0;
uint32_t freq_hz = speed_to_freq_tbl[speed];
@ -151,7 +149,7 @@ static int i2c_esp32_configure_speed(const struct device *dev,
return -ENOTSUP;
}
if (clock_control_get_rate(data->clock_dev,
if (clock_control_get_rate(config->clock_dev,
config->peripheral_id,
&sys_clk_freq)) {
return -EINVAL;
@ -205,7 +203,7 @@ static int i2c_esp32_configure(const struct device *dev, uint32_t dev_config)
return ret;
}
clock_control_on(data->clock_dev, config->peripheral_id);
clock_control_on(config->clock_dev, config->peripheral_id);
/* MSB or LSB first is configurable for both TX and RX */
if (config->mode.tx_lsb_first) {
@ -588,7 +586,7 @@ static void i2c_esp32_connect_irq_0(void)
static const struct i2c_esp32_config i2c_esp32_config_0 = {
.index = 0,
.connect_irq = i2c_esp32_connect_irq_0,
.clock_name = DT_INST_CLOCKS_LABEL(0),
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0)),
.peripheral_id = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(0, offset),
.sig = {
.sda_out = I2CEXT0_SDA_OUT_IDX,
@ -632,7 +630,7 @@ static void i2c_esp32_connect_irq_1(void)
static const struct i2c_esp32_config i2c_esp32_config_1 = {
.index = 1,
.connect_irq = i2c_esp32_connect_irq_1,
.clock_name = DT_INST_CLOCKS_LABEL(1),
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(1)),
.peripheral_id = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(1, offset),
.sig = {
.sda_out = I2CEXT1_SDA_OUT_IDX,
@ -671,9 +669,6 @@ static int i2c_esp32_init(const struct device *dev)
const struct i2c_esp32_config *config = dev->config;
struct i2c_esp32_data *data = dev->data;
uint32_t bitrate_cfg = i2c_map_dt_bitrate(config->bitrate);
data->clock_dev = device_get_binding(config->clock_name);
__ASSERT_NO_MSG(data->clock_dev);
unsigned int key = irq_lock();

View file

@ -64,7 +64,7 @@ struct uart_esp32_regs_t {
struct uart_esp32_config {
struct uart_device_config dev_conf;
const char *clock_name;
const struct device *clock_dev;
const struct {
int tx_out;
@ -91,7 +91,6 @@ struct uart_esp32_config {
/* driver data */
struct uart_esp32_data {
struct uart_config uart_config;
const struct device *clock_dev;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
uart_irq_callback_user_data_t irq_cb;
void *irq_cb_data;
@ -192,7 +191,7 @@ static int uart_esp32_set_baudrate(const struct device *dev, int baudrate)
{
uint32_t sys_clk_freq = 0;
if (clock_control_get_rate(DEV_DATA(dev)->clock_dev,
if (clock_control_get_rate(DEV_CFG(dev)->clock_dev,
DEV_CFG(dev)->peripheral_id,
&sys_clk_freq)) {
return -EINVAL;
@ -249,7 +248,7 @@ static int uart_esp32_configure(const struct device *dev,
| (UART_TX_FIFO_THRESH << UART_TXFIFO_EMPTY_THRHD_S);
uart_esp32_configure_pins(dev);
clock_control_on(DEV_DATA(dev)->clock_dev, DEV_CFG(dev)->peripheral_id);
clock_control_on(DEV_CFG(dev)->clock_dev, DEV_CFG(dev)->peripheral_id);
/*
* Reset RX Buffer by reading all received bytes
@ -317,12 +316,6 @@ static int uart_esp32_configure(const struct device *dev,
static int uart_esp32_init(const struct device *dev)
{
struct uart_esp32_data *data = DEV_DATA(dev);
data->clock_dev = device_get_binding(DEV_CFG(dev)->clock_name);
__ASSERT_NO_MSG(data->clock_dev);
uart_esp32_configure(dev, &DEV_DATA(dev)->uart_config);
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
@ -503,7 +496,7 @@ static const DRAM_ATTR struct uart_esp32_config uart_esp32_cfg_port_##idx = {
ESP32_UART_IRQ_HANDLER_FUNC(idx) \
}, \
\
.clock_name = DT_INST_CLOCKS_LABEL(idx), \
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
\
.signals = { \
.tx_out = U##idx##TXD_OUT_IDX, \