mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-09-09 13:42:34 +00:00
These changes were obtained by running a script created by Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following specification: 1. Read the contents of all dts_fixup.h files in Zephyr 2. Check the left-hand side of the #define macros (i.e. the X in #define X Y) 3. Check if that name is also the name of a Kconfig option 3.a If it is, then do nothing 3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it has neither of these two prefixes 4. Replace the use of the changed #define in the code itself (.c, .h, .ld) Additionally, some tweaks had to be added to this script to catch some of the macros used in the code in a parameterized form, e.g.: - CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS - CONFIG_UART_##idx##_TX_PIN - I2C_SBCON_##_num##_BASE_ADDR and to prevent adding DT_ prefix to the following symbols: - FLASH_START - FLASH_SIZE - SRAM_START - SRAM_SIZE - _ROM_ADDR - _ROM_SIZE - _RAM_ADDR - _RAM_SIZE which are surprisingly also defined in some dts_fixup.h files. Finally, some manual corrections had to be done as well: - name##_IRQ -> DT_##name##_IRQ in uart_stm32.c Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
93 lines
2.1 KiB
C
93 lines
2.1 KiB
C
/*
|
|
* Copyright (c) 2018 Google LLC.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <pinmux.h>
|
|
#include <soc.h>
|
|
|
|
struct pinmux_sam0_config {
|
|
PortGroup *regs;
|
|
};
|
|
|
|
static int pinmux_sam0_set(struct device *dev, u32_t pin, u32_t func)
|
|
{
|
|
const struct pinmux_sam0_config *cfg = dev->config->config_info;
|
|
bool odd_pin = pin & 1;
|
|
int idx = pin / 2;
|
|
|
|
/* Each pinmux register holds the config for two pins. The
|
|
* even numbered pin goes in the bits 0..3 and the odd
|
|
* numbered pin in bits 4..7.
|
|
*/
|
|
if (odd_pin) {
|
|
cfg->regs->PMUX[idx].bit.PMUXO = func;
|
|
} else {
|
|
cfg->regs->PMUX[idx].bit.PMUXE = func;
|
|
}
|
|
cfg->regs->PINCFG[pin].bit.PMUXEN = 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pinmux_sam0_get(struct device *dev, u32_t pin, u32_t *func)
|
|
{
|
|
const struct pinmux_sam0_config *cfg = dev->config->config_info;
|
|
bool odd_pin = pin & 1;
|
|
int idx = pin / 2;
|
|
|
|
if (odd_pin) {
|
|
*func = cfg->regs->PMUX[idx].bit.PMUXO;
|
|
} else {
|
|
*func = cfg->regs->PMUX[idx].bit.PMUXE;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pinmux_sam0_pullup(struct device *dev, u32_t pin, u8_t func)
|
|
{
|
|
return -ENOTSUP;
|
|
}
|
|
|
|
static int pinmux_sam0_input(struct device *dev, u32_t pin, u8_t func)
|
|
{
|
|
return -ENOTSUP;
|
|
}
|
|
|
|
static int pinmux_sam0_init(struct device *dev)
|
|
{
|
|
/* Nothing to do. The GPIO clock is enabled at reset. */
|
|
return 0;
|
|
}
|
|
|
|
const struct pinmux_driver_api pinmux_sam0_api = {
|
|
.set = pinmux_sam0_set,
|
|
.get = pinmux_sam0_get,
|
|
.pullup = pinmux_sam0_pullup,
|
|
.input = pinmux_sam0_input,
|
|
};
|
|
|
|
#if DT_PINMUX_SAM0_A_BASE_ADDRESS
|
|
static const struct pinmux_sam0_config pinmux_sam0_config_0 = {
|
|
.regs = (PortGroup *)DT_PINMUX_SAM0_A_BASE_ADDRESS,
|
|
};
|
|
|
|
DEVICE_AND_API_INIT(pinmux_sam0_0, DT_PINMUX_SAM0_A_LABEL,
|
|
pinmux_sam0_init, NULL, &pinmux_sam0_config_0,
|
|
PRE_KERNEL_1, CONFIG_PINMUX_INIT_PRIORITY,
|
|
&pinmux_sam0_api);
|
|
#endif
|
|
|
|
#if DT_PINMUX_SAM0_B_BASE_ADDRESS
|
|
static const struct pinmux_sam0_config pinmux_sam0_config_1 = {
|
|
.regs = (PortGroup *)DT_PINMUX_SAM0_B_BASE_ADDRESS,
|
|
};
|
|
|
|
DEVICE_AND_API_INIT(pinmux_sam0_1, DT_PINMUX_SAM0_B_LABEL,
|
|
pinmux_sam0_init, NULL, &pinmux_sam0_config_1,
|
|
PRE_KERNEL_1, CONFIG_PINMUX_INIT_PRIORITY,
|
|
&pinmux_sam0_api);
|
|
#endif
|