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 <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-04-09 16:08:32 -05:00 committed by Kumar Gala
commit 1335176bfa
6 changed files with 51 additions and 0 deletions

View file

@ -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_ */

View file

@ -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

View file

@ -37,6 +37,7 @@
#include "../common/soc_pmc.h"
#include "../common/soc_gpio.h"
#include "../common/atmel_sam_dt.h"
#endif /* !_ASMLANGUAGE */

View file

@ -48,6 +48,7 @@
#include "../common/soc_pmc.h"
#include "../common/soc_gpio.h"
#include "../common/atmel_sam_dt.h"
#endif /* !_ASMLANGUAGE */

View file

@ -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 <devicetree.h>

View file

@ -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 <devicetree.h>