drivers: watchdog: drop DEV_DATA/DEV_CFG usage

Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-18 17:00:11 +01:00 committed by Carles Cufí
commit b00150339a
4 changed files with 38 additions and 39 deletions

View file

@ -64,12 +64,9 @@ struct wdt_esp32_config {
int irq_source;
};
#define DEV_CFG(dev) \
((const struct wdt_esp32_config *const)(dev)->config)
#define DEV_DATA(dev) \
((struct wdt_esp32_data *)(dev)->data)
#define DEV_BASE(dev) \
((volatile struct wdt_esp32_regs_t *)(DEV_CFG(dev))->base)
((volatile struct wdt_esp32_regs_t *) \
((const struct wdt_esp32_config *const)(dev)->config)->base)
/* ESP32 ignores writes to any register if WDTWPROTECT doesn't contain the
* magic value of TIMG_WDT_WKEY_VALUE. The datasheet recommends unsealing,
@ -126,20 +123,23 @@ static int wdt_esp32_feed(const struct device *dev, int channel_id)
static void set_interrupt_enabled(const struct device *dev, bool setting)
{
*DEV_CFG(dev)->irq_regs.timer_int_clr |= TIMG_WDT_INT_CLR;
const struct wdt_esp32_config *config = dev->config;
struct wdt_esp32_data *data = dev->data;
*config->irq_regs.timer_int_clr |= TIMG_WDT_INT_CLR;
if (setting) {
*DEV_CFG(dev)->irq_regs.timer_int_ena |= TIMG_WDT_INT_ENA;
irq_enable(DEV_DATA(dev)->irq_line);
*config->irq_regs.timer_int_ena |= TIMG_WDT_INT_ENA;
irq_enable(data->irq_line);
} else {
*DEV_CFG(dev)->irq_regs.timer_int_ena &= ~TIMG_WDT_INT_ENA;
irq_disable(DEV_DATA(dev)->irq_line);
*config->irq_regs.timer_int_ena &= ~TIMG_WDT_INT_ENA;
irq_disable(data->irq_line);
}
}
static int wdt_esp32_set_config(const struct device *dev, uint8_t options)
{
struct wdt_esp32_data *data = DEV_DATA(dev);
struct wdt_esp32_data *data = dev->data;
uint32_t v = DEV_BASE(dev)->config0;
if (!data) {
@ -195,7 +195,7 @@ static int wdt_esp32_set_config(const struct device *dev, uint8_t options)
static int wdt_esp32_install_timeout(const struct device *dev,
const struct wdt_timeout_cfg *cfg)
{
struct wdt_esp32_data *data = DEV_DATA(dev);
struct wdt_esp32_data *data = dev->data;
if (cfg->flags != WDT_FLAG_RESET_SOC) {
return -ENOTSUP;
@ -217,8 +217,8 @@ static int wdt_esp32_install_timeout(const struct device *dev,
static int wdt_esp32_init(const struct device *dev)
{
const struct wdt_esp32_config *const config = DEV_CFG(dev);
struct wdt_esp32_data *data = DEV_DATA(dev);
const struct wdt_esp32_config *const config = dev->config;
struct wdt_esp32_data *data = dev->data;
#ifdef CONFIG_WDT_DISABLE_AT_BOOT
wdt_esp32_disable(dev);
@ -268,13 +268,14 @@ static const struct wdt_driver_api wdt_api = {
static void wdt_esp32_isr(void *arg)
{
const struct device *dev = (const struct device *)arg;
struct wdt_esp32_data *data = DEV_DATA(dev);
const struct wdt_esp32_config *config = dev->config;
struct wdt_esp32_data *data = dev->data;
if (data->callback) {
data->callback(dev, 0);
}
*DEV_CFG(dev)->irq_regs.timer_int_clr |= TIMG_WDT_INT_CLR;
*config->irq_regs.timer_int_clr |= TIMG_WDT_INT_CLR;
}

View file

@ -41,10 +41,6 @@ struct wdt_gecko_data {
};
#define DEV_NAME(dev) ((dev)->name)
#define DEV_DATA(dev) \
((struct wdt_gecko_data *)(dev)->data)
#define DEV_CFG(dev) \
((const struct wdt_gecko_cfg *)(dev)->config)
static uint32_t wdt_gecko_get_timeout_from_persel(int perSel)
{
@ -93,8 +89,8 @@ static int wdt_gecko_convert_window(uint32_t window, uint32_t period)
static int wdt_gecko_setup(const struct device *dev, uint8_t options)
{
const struct wdt_gecko_cfg *config = DEV_CFG(dev);
struct wdt_gecko_data *data = DEV_DATA(dev);
const struct wdt_gecko_cfg *config = dev->config;
struct wdt_gecko_data *data = dev->data;
WDOG_TypeDef *wdog = config->base;
if (!data->timeout_installed) {
@ -130,8 +126,8 @@ static int wdt_gecko_setup(const struct device *dev, uint8_t options)
static int wdt_gecko_disable(const struct device *dev)
{
const struct wdt_gecko_cfg *config = DEV_CFG(dev);
struct wdt_gecko_data *data = DEV_DATA(dev);
const struct wdt_gecko_cfg *config = dev->config;
struct wdt_gecko_data *data = dev->data;
WDOG_TypeDef *wdog = config->base;
WDOGn_Enable(wdog, false);
@ -144,7 +140,7 @@ static int wdt_gecko_disable(const struct device *dev)
static int wdt_gecko_install_timeout(const struct device *dev,
const struct wdt_timeout_cfg *cfg)
{
struct wdt_gecko_data *data = DEV_DATA(dev);
struct wdt_gecko_data *data = dev->data;
data->wdog_config = (WDOG_Init_TypeDef)WDOG_INIT_DEFAULT;
uint32_t installed_timeout;
@ -216,7 +212,7 @@ static int wdt_gecko_install_timeout(const struct device *dev,
static int wdt_gecko_feed(const struct device *dev, int channel_id)
{
const struct wdt_gecko_cfg *config = DEV_CFG(dev);
const struct wdt_gecko_cfg *config = dev->config;
WDOG_TypeDef *wdog = config->base;
if (channel_id != 0) {
@ -232,8 +228,8 @@ static int wdt_gecko_feed(const struct device *dev, int channel_id)
static void wdt_gecko_isr(const struct device *dev)
{
const struct wdt_gecko_cfg *config = DEV_CFG(dev);
struct wdt_gecko_data *data = DEV_DATA(dev);
const struct wdt_gecko_cfg *config = dev->config;
struct wdt_gecko_data *data = dev->data;
WDOG_TypeDef *wdog = config->base;
uint32_t flags;
@ -248,7 +244,7 @@ static void wdt_gecko_isr(const struct device *dev)
static int wdt_gecko_init(const struct device *dev)
{
const struct wdt_gecko_cfg *config = DEV_CFG(dev);
const struct wdt_gecko_cfg *config = dev->config;
#ifdef CONFIG_WDT_DISABLE_AT_BOOT
/* Ignore any errors */

View file

@ -43,13 +43,11 @@ struct wdt_sam_dev_data {
static struct wdt_sam_dev_data wdt_sam_data = { 0 };
#define DEV_CFG(dev) \
((const struct wdt_sam_dev_cfg *const)(dev)->config)
static void wdt_sam_isr(const struct device *dev)
{
const struct wdt_sam_dev_cfg *config = dev->config;
uint32_t wdt_sr;
Wdt *const wdt = DEV_CFG(dev)->regs;
Wdt *const wdt = config->regs;
struct wdt_sam_dev_data *data = dev->data;
/* Clear status bit to acknowledge interrupt by dummy read. */
@ -83,7 +81,9 @@ int wdt_sam_convert_timeout(uint32_t timeout, uint32_t sclk)
static int wdt_sam_disable(const struct device *dev)
{
Wdt *const wdt = DEV_CFG(dev)->regs;
const struct wdt_sam_dev_cfg *config = dev->config;
Wdt *const wdt = config->regs;
struct wdt_sam_dev_data *data = dev->data;
/* since Watchdog mode register is 'write-once', we can't disable if
@ -106,8 +106,9 @@ static int wdt_sam_disable(const struct device *dev)
static int wdt_sam_setup(const struct device *dev, uint8_t options)
{
const struct wdt_sam_dev_cfg *config = dev->config;
Wdt *const wdt = DEV_CFG(dev)->regs;
Wdt *const wdt = config->regs;
struct wdt_sam_dev_data *data = dev->data;
if (!data->timeout_valid) {
@ -208,12 +209,14 @@ static int wdt_sam_install_timeout(const struct device *dev,
static int wdt_sam_feed(const struct device *dev, int channel_id)
{
const struct wdt_sam_dev_cfg *config = dev->config;
/*
* On watchdog restart the Watchdog counter is immediately
* reloaded/feeded with the 12-bit watchdog counter
* value from WDT_MR and restarted
*/
Wdt *const wdt = DEV_CFG(dev)->regs;
Wdt *const wdt = config->regs;
wdt->WDT_CR |= WDT_CR_KEY_PASSWD | WDT_CR_WDRSTT;

View file

@ -59,10 +59,9 @@ struct wdt_sifive_dev_data {
bool timeout_valid;
};
#define DEV_CFG(dev) \
((const struct wdt_sifive_device_config *const)(dev)->config)
#define DEV_REG(dev) \
((struct wdt_sifive_reg *)(DEV_CFG(dev))->regs)
((struct wdt_sifive_reg *) \
((const struct wdt_sifive_device_config *const)(dev)->config)->regs)
/**
* @brief Set maximum length of timeout to watchdog