drivers: dac: Add sam support to pinctrl

This add support to pinctrl at Atmel sam dac driver.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
Gerson Fernando Budke 2022-03-13 14:39:09 -03:00 committed by Marti Bolivar
parent 0f472f6d1b
commit 3a940cea79
2 changed files with 14 additions and 1 deletions

View file

@ -18,6 +18,7 @@
#include <soc.h> #include <soc.h>
#include <device.h> #include <device.h>
#include <drivers/dac.h> #include <drivers/dac.h>
#include <drivers/pinctrl.h>
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_REGISTER(dac_sam, CONFIG_DAC_LOG_LEVEL); LOG_MODULE_REGISTER(dac_sam, CONFIG_DAC_LOG_LEVEL);
@ -31,6 +32,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_SOC_SERIES_SAME70) ||
/* Device constant configuration parameters */ /* Device constant configuration parameters */
struct dac_sam_dev_cfg { struct dac_sam_dev_cfg {
Dacc *regs; Dacc *regs;
const struct pinctrl_dev_config *pcfg;
void (*irq_config)(void); void (*irq_config)(void);
uint8_t irq_id; uint8_t irq_id;
uint8_t periph_id; uint8_t periph_id;
@ -119,6 +121,7 @@ static int dac_sam_init(const struct device *dev)
const struct dac_sam_dev_cfg *const dev_cfg = dev->config; const struct dac_sam_dev_cfg *const dev_cfg = dev->config;
struct dac_sam_dev_data *const dev_data = dev->data; struct dac_sam_dev_data *const dev_data = dev->data;
Dacc *const dac = dev_cfg->regs; Dacc *const dac = dev_cfg->regs;
int retval;
/* Configure interrupts */ /* Configure interrupts */
dev_cfg->irq_config(); dev_cfg->irq_config();
@ -131,6 +134,11 @@ static int dac_sam_init(const struct device *dev)
/* Enable DAC clock in PMC */ /* Enable DAC clock in PMC */
soc_pmc_peripheral_enable(dev_cfg->periph_id); soc_pmc_peripheral_enable(dev_cfg->periph_id);
retval = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (retval < 0) {
return retval;
}
/* Set Mode Register */ /* Set Mode Register */
dac->DACC_MR = DACC_MR_PRESCALER(dev_cfg->prescaler); dac->DACC_MR = DACC_MR_PRESCALER(dev_cfg->prescaler);
@ -155,8 +163,11 @@ static void dacc_irq_config(void)
DEVICE_DT_INST_GET(0), 0); DEVICE_DT_INST_GET(0), 0);
} }
PINCTRL_DT_INST_DEFINE(0);
static const struct dac_sam_dev_cfg dacc_sam_config = { static const struct dac_sam_dev_cfg dacc_sam_config = {
.regs = (Dacc *)DT_INST_REG_ADDR(0), .regs = (Dacc *)DT_INST_REG_ADDR(0),
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
.irq_id = DT_INST_IRQN(0), .irq_id = DT_INST_IRQN(0),
.irq_config = dacc_irq_config, .irq_config = dacc_irq_config,
.periph_id = DT_INST_PROP(0, peripheral_id), .periph_id = DT_INST_PROP(0, peripheral_id),

View file

@ -5,7 +5,9 @@ description: Atmel SAM family DAC
compatible: "atmel,sam-dac" compatible: "atmel,sam-dac"
include: dac-controller.yaml include:
- name: dac-controller.yaml
- name: pinctrl-device.yaml
properties: properties:
reg: reg: