From 1335176bfaef31097d13d70c7693c0d9d419e1c7 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 9 Apr 2020 16:08:32 -0500 Subject: [PATCH] soc: arm: atmel_sam: Add macros to create a soc_gpio_pin info from dts Add a set of macros that will create a struct soc_gpio_pin initialization based on data extracted from device tree. This should allow replacing the static data in soc_pinmap.h with data coming from devicetree instead. Signed-off-by: Kumar Gala --- soc/arm/atmel_sam/common/atmel_sam_dt.h | 46 +++++++++++++++++++++++++ soc/arm/atmel_sam/sam3x/soc.h | 1 + soc/arm/atmel_sam/sam4e/soc.h | 1 + soc/arm/atmel_sam/sam4s/soc.h | 1 + soc/arm/atmel_sam/same70/soc.h | 1 + soc/arm/atmel_sam/samv71/soc.h | 1 + 6 files changed, 51 insertions(+) create mode 100644 soc/arm/atmel_sam/common/atmel_sam_dt.h diff --git a/soc/arm/atmel_sam/common/atmel_sam_dt.h b/soc/arm/atmel_sam/common/atmel_sam_dt.h new file mode 100644 index 00000000000..5b21c2bfcb6 --- /dev/null +++ b/soc/arm/atmel_sam/common/atmel_sam_dt.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 Linaro Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** @file + * @brief Atmel SAM MCU family devicetree helper macros + */ + +#ifndef _ATMEL_SAM_DT_H_ +#define _ATMEL_SAM_DT_H_ + +/* Devicetree related macros to construct pin mux config data */ + +/* Get a node id from a pinctrl-0 prop at index 'i' */ +#define NODE_ID_FROM_PINCTRL_0(inst, i) \ + DT_INST_PHANDLE_BY_IDX(inst, pinctrl_0, i) + +/* Get PIN associated with pinctrl-0 pin at index 'i' */ +#define ATMEL_SAM_PIN(inst, i) \ + DT_PHA(NODE_ID_FROM_PINCTRL_0(inst, i), atmel_pins, pin) + +/* Get PIO register address associated with pinctrl-0 pin at index 'i' */ +#define ATMEL_SAM_PIN_TO_PIO_REG_ADDR(inst, i) \ + DT_REG_ADDR(DT_PHANDLE(NODE_ID_FROM_PINCTRL_0(inst, i), atmel_pins)) + +/* Get peripheral id for PIO associated with pinctrl-0 pin at index 'i' */ +#define ATMEL_SAM_PIN_2_PIO_PERIPH_ID(inst, i) \ + DT_PROP_BY_PHANDLE(NODE_ID_FROM_PINCTRL_0(inst, i),\ + atmel_pins, peripheral_id) + +/* Get peripheral cfg associated wiith pinctrl-0 pin at index 'i' */ +#define ATMEL_SAM_PIN_PERIPH(inst, i) \ + DT_PHA(NODE_ID_FROM_PINCTRL_0(inst, i), atmel_pins, peripheral) + +/* Construct a soc_gpio_pin element for pin cfg */ +#define ATMEL_SAM_DT_PIN(inst, idx) \ + { \ + 1 << ATMEL_SAM_PIN(inst, idx), \ + (Pio *)ATMEL_SAM_PIN_TO_PIO_REG_ADDR(inst, idx),\ + ATMEL_SAM_PIN_2_PIO_PERIPH_ID(inst, idx), \ + ATMEL_SAM_PIN_PERIPH(inst, idx) << 16 \ + } + +#endif /* _ATMEL_SAM_SOC_DT_H_ */ diff --git a/soc/arm/atmel_sam/sam3x/soc.h b/soc/arm/atmel_sam/sam3x/soc.h index 8270192dc84..432b291c80c 100644 --- a/soc/arm/atmel_sam/sam3x/soc.h +++ b/soc/arm/atmel_sam/sam3x/soc.h @@ -45,6 +45,7 @@ #include "../common/soc_pmc.h" #include "../common/soc_gpio.h" +#include "../common/atmel_sam_dt.h" /** Processor Clock (HCLK) Frequency */ #define SOC_ATMEL_SAM_HCLK_FREQ_HZ DT_ARM_CORTEX_M3_0_CLOCK_FREQUENCY diff --git a/soc/arm/atmel_sam/sam4e/soc.h b/soc/arm/atmel_sam/sam4e/soc.h index feca2f64154..7eecfa32c0f 100644 --- a/soc/arm/atmel_sam/sam4e/soc.h +++ b/soc/arm/atmel_sam/sam4e/soc.h @@ -37,6 +37,7 @@ #include "../common/soc_pmc.h" #include "../common/soc_gpio.h" +#include "../common/atmel_sam_dt.h" #endif /* !_ASMLANGUAGE */ diff --git a/soc/arm/atmel_sam/sam4s/soc.h b/soc/arm/atmel_sam/sam4s/soc.h index 1f96509e52f..25cd5d94c09 100644 --- a/soc/arm/atmel_sam/sam4s/soc.h +++ b/soc/arm/atmel_sam/sam4s/soc.h @@ -48,6 +48,7 @@ #include "../common/soc_pmc.h" #include "../common/soc_gpio.h" +#include "../common/atmel_sam_dt.h" #endif /* !_ASMLANGUAGE */ diff --git a/soc/arm/atmel_sam/same70/soc.h b/soc/arm/atmel_sam/same70/soc.h index 5b2daefffc8..f06c2da08af 100644 --- a/soc/arm/atmel_sam/same70/soc.h +++ b/soc/arm/atmel_sam/same70/soc.h @@ -65,6 +65,7 @@ #include "../common/soc_pmc.h" #include "../common/soc_gpio.h" +#include "../common/atmel_sam_dt.h" /* Add include for DTS generated information */ #include diff --git a/soc/arm/atmel_sam/samv71/soc.h b/soc/arm/atmel_sam/samv71/soc.h index bf7e4242b9a..081e343a4fe 100644 --- a/soc/arm/atmel_sam/samv71/soc.h +++ b/soc/arm/atmel_sam/samv71/soc.h @@ -66,6 +66,7 @@ #include "../common/soc_pmc.h" #include "../common/soc_gpio.h" +#include "../common/atmel_sam_dt.h" /* Add include for DTS generated information */ #include