drivers: esp32: Convert esp32 drivers to new DT_INST macros

Convert older DT_INST_ macro use in esp32 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-03-24 16:00:26 -05:00 committed by Kumar Gala
commit 8ea8925ebe
8 changed files with 52 additions and 38 deletions

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_trng
#include <string.h>
#include <drivers/entropy.h>
@ -17,7 +19,7 @@ static inline u32_t entropy_esp32_get_u32(void)
* https://www.esp32.com/viewtopic.php?f=2&t=3033&p=14227
* also check: ECO and Workarounds for Bugs Document, point 3.3
*/
volatile u32_t *rng_data_reg = (u32_t *)DT_INST_0_ESPRESSIF_ESP32_TRNG_BASE_ADDRESS;
volatile u32_t *rng_data_reg = (u32_t *)DT_INST_REG_ADDR(0);
/* Read just once. This is not optimal as the generator has
* limited throughput due to scarce sources of entropy, specially
@ -54,7 +56,7 @@ static struct entropy_driver_api entropy_esp32_api_funcs = {
.get_entropy = entropy_esp32_get_entropy
};
DEVICE_AND_API_INIT(entropy_esp32, DT_INST_0_ESPRESSIF_ESP32_TRNG_LABEL,
DEVICE_AND_API_INIT(entropy_esp32, DT_INST_LABEL(0),
entropy_esp32_init, NULL, NULL,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_esp32_api_funcs);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_gpio
/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <soc/dport_reg.h>
#include <soc/gpio_reg.h>
@ -361,10 +363,10 @@ static struct gpio_esp32_data gpio_1_data = { /* 32..39 */
#define GPIO_DEVICE_INIT(_id) \
static struct gpio_driver_config gpio_##_id##_cfg = { \
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_##_id##_ESPRESSIF_ESP32_GPIO_NGPIOS),\
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_PROP(_id, ngpios)),\
}; \
DEVICE_AND_API_INIT(gpio_esp32_##_id, \
DT_INST_##_id##_ESPRESSIF_ESP32_GPIO_LABEL, \
DT_INST_LABEL(_id), \
gpio_esp32_init, \
&gpio_##_id##_data, &gpio_##_id##_cfg, \
POST_KERNEL, \

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_i2c
/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <soc/dport_reg.h>
#include <soc/i2c_reg.h>
@ -564,7 +566,7 @@ static const struct i2c_driver_api i2c_esp32_driver_api = {
.transfer = i2c_esp32_transfer,
};
#ifdef DT_INST_0_ESPRESSIF_ESP32_I2C
#if DT_HAS_DRV_INST(0)
DEVICE_DECLARE(i2c_esp32_0);
static void i2c_esp32_connect_irq_0(void)
@ -583,8 +585,8 @@ static const struct i2c_esp32_config i2c_esp32_config_0 = {
.scl_in = I2CEXT0_SCL_IN_IDX,
},
.pins = {
.scl = DT_INST_0_ESPRESSIF_ESP32_I2C_SCL_PIN,
.sda = DT_INST_0_ESPRESSIF_ESP32_I2C_SDA_PIN,
.scl = DT_INST_PROP(0, scl_pin),
.sda = DT_INST_PROP(0, sda_pin),
},
.peripheral = {
.clk = DPORT_I2C_EXT0_CLK_EN,
@ -601,18 +603,18 @@ static const struct i2c_esp32_config i2c_esp32_config_0 = {
.line = CONFIG_I2C_ESP32_0_IRQ,
},
.default_config = I2C_MODE_MASTER, /* FIXME: Zephyr don't support I2C_SLAVE_MODE */
.bitrate = DT_INST_0_ESPRESSIF_ESP32_I2C_CLOCK_FREQUENCY,
.bitrate = DT_INST_PROP(0, clock_frequency),
};
static struct i2c_esp32_data i2c_esp32_data_0;
DEVICE_AND_API_INIT(i2c_esp32_0, DT_INST_0_ESPRESSIF_ESP32_I2C_LABEL, &i2c_esp32_init,
DEVICE_AND_API_INIT(i2c_esp32_0, DT_INST_LABEL(0), &i2c_esp32_init,
&i2c_esp32_data_0, &i2c_esp32_config_0,
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY,
&i2c_esp32_driver_api);
#endif /* DT_INST_0_ESPRESSIF_ESP32_I2C */
#endif /* DT_HAS_DRV_INST(0) */
#ifdef DT_INST_1_ESPRESSIF_ESP32_I2C
#if DT_HAS_DRV_INST(1)
DEVICE_DECLARE(i2c_esp32_1);
static void i2c_esp32_connect_irq_1(void)
@ -631,8 +633,8 @@ static const struct i2c_esp32_config i2c_esp32_config_1 = {
.scl_in = I2CEXT1_SCL_IN_IDX,
},
.pins = {
.scl = DT_INST_1_ESPRESSIF_ESP32_I2C_SCL_PIN,
.sda = DT_INST_1_ESPRESSIF_ESP32_I2C_SDA_PIN,
.scl = DT_INST_PROP(1, scl_pin),
.sda = DT_INST_PROP(1, sda_pin),
},
.peripheral = {
.clk = DPORT_I2C_EXT1_CLK_EN,
@ -649,16 +651,16 @@ static const struct i2c_esp32_config i2c_esp32_config_1 = {
.line = CONFIG_I2C_ESP32_1_IRQ,
},
.default_config = I2C_MODE_MASTER, /* FIXME: Zephyr don't support I2C_SLAVE_MODE */
.bitrate = DT_INST_1_ESPRESSIF_ESP32_I2C_CLOCK_FREQUENCY,
.bitrate = DT_INST_PROP(1, clock_frequency),
};
static struct i2c_esp32_data i2c_esp32_data_1;
DEVICE_AND_API_INIT(i2c_esp32_1, DT_INST_1_ESPRESSIF_ESP32_I2C_LABEL, &i2c_esp32_init,
DEVICE_AND_API_INIT(i2c_esp32_1, DT_INST_LABEL(1), &i2c_esp32_init,
&i2c_esp32_data_1, &i2c_esp32_config_1,
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY,
&i2c_esp32_driver_api);
#endif /* DT_INST_1_ESPRESSIF_ESP32_I2C */
#endif /* DT_HAS_DRV_INST(1) */
static int i2c_esp32_init(struct device *dev)
{

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_pinmux
/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <soc/gpio_reg.h>
#include <soc/io_mux_reg.h>
@ -53,7 +55,7 @@ static u32_t *reg_for_pin(u32_t pin)
return NULL;
}
return (u32_t *)(DT_INST_0_ESPRESSIF_ESP32_PINMUX_BASE_ADDRESS + off);
return (u32_t *)(DT_INST_REG_ADDR(0) + off);
}
static int set_reg(u32_t pin, u32_t clr_mask, u32_t set_mask)

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_gpio
/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <esp_intr_alloc.h>
#include <soc/dport_reg.h>
@ -92,14 +94,14 @@ static const char *esp32_get_gpio_for_pin(int pin)
{
if (pin < 32) {
#if defined(CONFIG_GPIO_ESP32_0)
return DT_INST_0_ESPRESSIF_ESP32_GPIO_LABEL;
return DT_INST_LABEL(0);
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_0 */
}
#if defined(CONFIG_GPIO_ESP32_1)
return DT_INST_1_ESPRESSIF_ESP32_GPIO_LABEL;
return DT_INST_LABEL(1);
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_1 */

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_uart
/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <rom/ets_sys.h>
#include <soc/dport_reg.h>
@ -480,9 +482,9 @@ ESP32_UART_IRQ_HANDLER_DECL(idx); \
static const struct uart_esp32_config uart_esp32_cfg_port_##idx = { \
.dev_conf = { \
.base = \
(u8_t *)DT_INST_##idx##_ESPRESSIF_ESP32_UART_BASE_ADDRESS, \
(u8_t *)DT_INST_REG_ADDR(idx), \
.sys_clk_freq = \
DT_INST_0_CADENCE_TENSILICA_XTENSA_LX6_CLOCK_FREQUENCY,\
DT_PROP(DT_INST(0, cadence_tensilica_xtensa_lx6), clock_frequency),\
ESP32_UART_IRQ_HANDLER_FUNC(idx) \
}, \
\
@ -499,12 +501,12 @@ static const struct uart_esp32_config uart_esp32_cfg_port_##idx = { \
}, \
\
.pins = { \
.tx = DT_INST_##idx##_ESPRESSIF_ESP32_UART_TX_PIN, \
.rx = DT_INST_##idx##_ESPRESSIF_ESP32_UART_RX_PIN, \
.tx = DT_INST_PROP(idx, tx_pin), \
.rx = DT_INST_PROP(idx, rx_pin), \
IF_ENABLED( \
DT_INST_##idx##_ESPRESSIF_ESP32_UART_HW_FLOW_CONTROL, \
(.rts = DT_INST_##idx##_ESPRESSIF_ESP32_UART_RTS_PIN, \
.cts = DT_INST_##idx##_ESPRESSIF_ESP32_UART_CTS_PIN, \
DT_INST_PROP(idx, hw_flow_control), \
(.rts = DT_INST_PROP(idx, rts_pin), \
.cts = DT_INST_PROP(idx, cts_pin), \
)) \
}, \
\
@ -516,18 +518,18 @@ static const struct uart_esp32_config uart_esp32_cfg_port_##idx = { \
\
static struct uart_esp32_data uart_esp32_data_##idx = { \
.uart_config = { \
.baudrate = DT_INST_##idx##_ESPRESSIF_ESP32_UART_CURRENT_SPEED,\
.baudrate = DT_INST_PROP(idx, current_speed),\
.parity = UART_CFG_PARITY_NONE, \
.stop_bits = UART_CFG_STOP_BITS_1, \
.data_bits = UART_CFG_DATA_BITS_8, \
.flow_ctrl = IS_ENABLED( \
DT_INST_##idx##_ESPRESSIF_ESP32_UART_HW_FLOW_CONTROL) ?\
DT_INST_PROP(idx, hw_flow_control)) ?\
UART_CFG_FLOW_CTRL_RTS_CTS : UART_CFG_FLOW_CTRL_NONE \
} \
}; \
\
DEVICE_AND_API_INIT(uart_esp32_##idx, \
DT_INST_##idx##_ESPRESSIF_ESP32_UART_LABEL, \
DT_INST_LABEL(idx), \
uart_esp32_init, \
&uart_esp32_data_##idx, \
&uart_esp32_cfg_port_##idx, \
@ -537,14 +539,14 @@ DEVICE_AND_API_INIT(uart_esp32_##idx, \
\
ESP32_UART_IRQ_HANDLER(idx)
#ifdef DT_INST_0_ESPRESSIF_ESP32_UART
#if DT_HAS_DRV_INST(0)
ESP32_UART_INIT(0);
#endif
#ifdef DT_INST_1_ESPRESSIF_ESP32_UART
#if DT_HAS_DRV_INST(1)
ESP32_UART_INIT(1);
#endif
#ifdef DT_INST_2_ESPRESSIF_ESP32_UART
#if DT_HAS_DRV_INST(2)
ESP32_UART_INIT(2);
#endif

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT espressif_esp32_watchdog
/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <soc/rtc_cntl_reg.h>
#include <soc/timer_group_reg.h>
@ -237,7 +239,7 @@ static const struct wdt_driver_api wdt_api = {
\
static struct wdt_esp32_data wdt##idx##_data; \
static struct wdt_esp32_config wdt_esp32_config##idx = { \
.base = (struct wdt_esp32_regs_t *) DT_INST_##idx##_ESPRESSIF_ESP32_WATCHDOG_BASE_ADDRESS, \
.base = (struct wdt_esp32_regs_t *) DT_INST_REG_ADDR(idx), \
.irq_regs = { \
.timer_int_ena = (u32_t *)TIMG_INT_ENA_TIMERS_REG(idx), \
.timer_int_clr = (u32_t *)TIMG_INT_CLR_TIMERS_REG(idx), \
@ -249,7 +251,7 @@ static const struct wdt_driver_api wdt_api = {
.connect_irq = wdt_esp32_connect_irq_func##idx \
}; \
\
DEVICE_AND_API_INIT(wdt_esp32_##idx, DT_INST_##idx##_ESPRESSIF_ESP32_WATCHDOG_LABEL, \
DEVICE_AND_API_INIT(wdt_esp32_##idx, DT_INST_LABEL(idx), \
wdt_esp32_init, \
&wdt##idx##_data, \
&wdt_esp32_config##idx, \
@ -268,10 +270,10 @@ static void wdt_esp32_isr(struct device *dev)
}
#ifdef DT_INST_0_ESPRESSIF_ESP32_WATCHDOG
#if DT_HAS_DRV_INST(0)
ESP32_WDT_INIT(0);
#endif
#ifdef DT_INST_1_ESPRESSIF_ESP32_WATCHDOG
#if DT_HAS_DRV_INST(1)
ESP32_WDT_INIT(1);
#endif

View file

@ -9,14 +9,14 @@ static const char *gpio_esp32_get_gpio_for_pin(int pin)
{
if (pin < 32) {
#if defined(CONFIG_GPIO_ESP32_0)
return DT_INST_0_ESPRESSIF_ESP32_GPIO_LABEL;
return DT_LABEL(DT_INST(0, espressif_esp32_gpio));
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_0 */
}
#if defined(CONFIG_GPIO_ESP32_1)
return DT_INST_1_ESPRESSIF_ESP32_GPIO_LABEL;
return DT_LABEL(DT_INST(1, espressif_esp32_gpio));
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_1 */