From 477a8d1aa762572b657bbbd3e48094a60dd14c50 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Oct 2017 17:08:54 -0600 Subject: [PATCH] BCM2708: Add support for AUX interrupts. --- arch/arm/src/bcm2708/Kconfig | 8 +- arch/arm/src/bcm2708/Make.defs | 2 +- arch/arm/src/bcm2708/bcm_aux.c | 220 ++++++++++++++++++ arch/arm/src/bcm2708/bcm_aux.h | 114 +++++++++ arch/arm/src/bcm2708/bcm_irq.c | 5 + arch/arm/src/bcm2708/bcm_lowputc.c | 2 +- .../{bcm2708_uart_spi.h => bcm2708_aux.h} | 8 +- 7 files changed, 352 insertions(+), 7 deletions(-) create mode 100644 arch/arm/src/bcm2708/bcm_aux.c create mode 100644 arch/arm/src/bcm2708/bcm_aux.h rename arch/arm/src/bcm2708/chip/{bcm2708_uart_spi.h => bcm2708_aux.h} (98%) diff --git a/arch/arm/src/bcm2708/Kconfig b/arch/arm/src/bcm2708/Kconfig index bbd7e12f241..02bc61e46d6 100644 --- a/arch/arm/src/bcm2708/Kconfig +++ b/arch/arm/src/bcm2708/Kconfig @@ -22,7 +22,13 @@ config BCM2708_MINI_UART bool "Mini-UART" config BCM2708_PL011_UART - bool "PL011UART" + bool "PL011 UART" + +config BCM2708_SPI1 + bool "SPI1" + +config BCM2708_SPI2 + bool "SPI2" endmenu # BCM2708 Peripheral Selections diff --git a/arch/arm/src/bcm2708/Make.defs b/arch/arm/src/bcm2708/Make.defs index 890b7ad14ea..b8bdd94c98d 100644 --- a/arch/arm/src/bcm2708/Make.defs +++ b/arch/arm/src/bcm2708/Make.defs @@ -72,7 +72,7 @@ endif # BCM2708-specific source files. CHIP_CSRCS = bcm_boot.c bcm_memorymap.c bcm_clockconfig.c bcm_irq.c -CHIP_CSRCS += bcm_tickless.c bcm_gpio.c bcm_lowputc.c +CHIP_CSRCS += bcm_tickless.c bcm_gpio.c bcm_aux.c bcm_lowputc.c ifeq ($(CONFIG_BCM2708_GPIO_IRQ),y) CHIP_CSRCS += bcm_gpioint.c diff --git a/arch/arm/src/bcm2708/bcm_aux.c b/arch/arm/src/bcm2708/bcm_aux.c new file mode 100644 index 00000000000..9739cc7fcbb --- /dev/null +++ b/arch/arm/src/bcm2708/bcm_aux.c @@ -0,0 +1,220 @@ +/**************************************************************************** + * arch/arm/src/bcm2708/bcm_aux.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include "up_arch.h" +#include "bcm_config.h" +#include "chip/bcm2708_aux.h" +#include "bcm_aux.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: bcm_aux_interrupt + * + * Description: + * AUX interrupt handler + * + * Input Parameters: + * Standard interrupt input parameters + * + * Returned Value: + * Always returns OK + * + * Assumptions: + * Interrupts ar disabled + * + ****************************************************************************/ + +static int bcm_aux_interrupt(int irq, FAR void *context, FAR void *arg) +{ + uint32_t auxirq; + + /* Read the pending AUX interrupts */ + + auxirq = getreg32(BCM_AUX_IRQ); + +#ifdef CONFIG_BCM2708_MINI_UART + if ((auxirq & BCM_AUX_IRQ_MU) != 0) + { + (void)bcm_mu_interrupt(irq, context, arg); + } +#endif + +#ifdef CONFIG_BCM2708_SPI1 + if ((auxirq & BCM_AUX_IRQ_SPI1) != 0) + { + (void)bcm_spi1_interrupt(irq, context, arg); + } +#endif + +#ifdef CONFIG_BCM2708_SPI2 + if ((auxirq & BCM_AUX_IRQ_SPI2) != 0) + { + (void)bcm_spi2_interrupt(irq, context, arg); + } +#endif + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: bcm_aux_irqinitialize + * + * Description: + * Called during IRQ initialize to initialize the shard AUX interrupt + * logic. + * + ****************************************************************************/ + +void bcm_aux_irqinitialize(void) +{ + /* Disable all AUX interrupt sources (Also disables all peripheral + * register accesses). + */ + + putreg32(0, BCM_AUX_ENB); + + /* Attach and enable the AUX interrupt */ + + (void)irq_attach(BCM_IRQ_AUX, bcm_aux_interrupt, NULL); + up_enable_irq(BCM_IRQ_AUX); +} + +/**************************************************************************** + * Name: bcm_aux_enable + * + * Description: + * Enable the specified AUX interrupt (also enables access to peripheral + * registers). + * + ****************************************************************************/ + +void bcm_aux_enable(enum bcm_aux_peripheral_e periph, FAR void *arg) +{ + uint32_t setbits; + + /* Read the AUX perpheral enable */ + +#ifdef CONFIG_BCM2708_MINI_UART + if (periph == BCM_AUX_MINI_UART) + { + setbits = BCM_AUX_ENB_MU; + } + else +#endif + +#ifdef CONFIG_BCM2708_SPI1 + if (periph == BCM_AUX_MINI_UART) + { + setbits = BCM_AUX_ENB_SPI1; + } + else +#endif + +#ifdef CONFIG_BCM2708_SPI2 + if (periph == BCM_AUX_MINI_UART) + { + setbits = BCM_AUX_ENB_SPI1; + } + else +#endif + { + return; + } + + modifyreg32(BCM_AUX_ENB, 0, setbits); +} + +/**************************************************************************** + * Name: bcm_aux_disable + * + * Description: + * Disable the specified AUX interrupt (also disables access to peripheral + * registers). + * + ****************************************************************************/ + +void bcm_aux_disable(enum bcm_aux_peripheral_e periph) +{ + uint32_t clrbits; + + /* Read the AUX perpheral enable */ + +#ifdef CONFIG_BCM2708_MINI_UART + if (periph == BCM_AUX_MINI_UART) + { + clrbits = BCM_AUX_ENB_MU; + } + else +#endif + +#ifdef CONFIG_BCM2708_SPI1 + if (periph == BCM_AUX_MINI_UART) + { + clrbits = BCM_AUX_ENB_SPI1; + } + else +#endif + +#ifdef CONFIG_BCM2708_SPI2 + if (periph == BCM_AUX_MINI_UART) + { + clrbits = BCM_AUX_ENB_SPI1; + } + else +#endif + { + return; + } + + modifyreg32(BCM_AUX_ENB, clrbits, 0); +} diff --git a/arch/arm/src/bcm2708/bcm_aux.h b/arch/arm/src/bcm2708/bcm_aux.h new file mode 100644 index 00000000000..7fb828da886 --- /dev/null +++ b/arch/arm/src/bcm2708/bcm_aux.h @@ -0,0 +1,114 @@ +/**************************************************************************** + * arch/arm/src/bcm2708/bcm_aux.h + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_BCM2708_BCM_AUX_H +#define __ARCH_ARM_SRC_BCM2708_BCM_AUX_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +enum bcm_aux_peripheral_e +{ + BCM_AUX_MINI_UART = 0, /* Mini UART peripheral */ + BCM_AUX_MINI_SPI1, /* SPI1 peripheral */ + BCM_AUX_MINI_SPI2, /* SPI2 peripheral */ +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: bcm_aux_irqinitialize + * + * Description: + * Called during IRQ initialize to initialize the shard AUX interrupt + * logic. + * + ****************************************************************************/ + +void bcm_aux_irqinitialize(void); + +/**************************************************************************** + * Name: bcm_aux_enable + * + * Description: + * Enable the specified AUX interrupt (also enables access to peripheral + * registers). + * + ****************************************************************************/ + +void bcm_aux_enable(enum bcm_aux_peripheral_e periph, FAR void *arg); + +/**************************************************************************** + * Name: bcm_aux_disable + * + * Description: + * Disable the specified AUX interrupt (also disables access to peripheral + * registers). + * + ****************************************************************************/ + +void bcm_aux_disable(enum bcm_aux_peripheral_e periph); + +/**************************************************************************** + * Name: bcm_[mu|spi1|spi2]_interupt + * + * Description: + * These callbacks must be provided by Mini-UART, SPI1, and SPI2 logic + * when those peripherals are configured. These callbacks will be invoked + * from interrupt level processing when an interrupt for one of those + * peripherals is received (with interrupts disabled) + * + ****************************************************************************/ + +#ifdef CONFIG_BCM2708_MINI_UART +int bcm_mu_interrupt(int irq, FAR void *context, FAR void *arg); +#endif +#ifdef CONFIG_BCM2708_SPI1 +int bcm_spi1_interrupt(int irq, FAR void *context, FAR void *arg); +#endif +#ifdef CONFIG_BCM2708_SPI2 +int bcm_spi2_interrupt(int irq, FAR void *context, FAR void *arg); +#endif + +#endif /* __ARCH_ARM_SRC_BCM2708_BCM_AUX_H */ diff --git a/arch/arm/src/bcm2708/bcm_irq.c b/arch/arm/src/bcm2708/bcm_irq.c index 90d541b0132..00a9c49c8e8 100644 --- a/arch/arm/src/bcm2708/bcm_irq.c +++ b/arch/arm/src/bcm2708/bcm_irq.c @@ -52,6 +52,7 @@ #include "up_internal.h" #include "group/group.h" +#include "bcm_aux.h" #include "bcm_gpio.h" #include "chip/bcm2708_irq.h" @@ -93,6 +94,10 @@ void up_irqinitialize(void) CURRENT_REGS = NULL; + /* Intitialize AUX interrupts */ + + bcm_aux_irqinitialize(); + #ifdef CONFIG_BCM2708_GPIO_IRQ /* Initialize GPIO interrrupts */ diff --git a/arch/arm/src/bcm2708/bcm_lowputc.c b/arch/arm/src/bcm2708/bcm_lowputc.c index 407b3eb4116..c5fccbff970 100644 --- a/arch/arm/src/bcm2708/bcm_lowputc.c +++ b/arch/arm/src/bcm2708/bcm_lowputc.c @@ -44,7 +44,7 @@ #include "up_arch.h" -#include "chip/bcm2708_uart_spi.h" +#include "chip/bcm2708_aux.h" #include "bcm_config.h" #include "bcm_lowputc.h" diff --git a/arch/arm/src/bcm2708/chip/bcm2708_uart_spi.h b/arch/arm/src/bcm2708/chip/bcm2708_aux.h similarity index 98% rename from arch/arm/src/bcm2708/chip/bcm2708_uart_spi.h rename to arch/arm/src/bcm2708/chip/bcm2708_aux.h index 60b21096432..3e97f79fb79 100644 --- a/arch/arm/src/bcm2708/chip/bcm2708_uart_spi.h +++ b/arch/arm/src/bcm2708/chip/bcm2708_aux.h @@ -1,5 +1,5 @@ /************************************************************************************ - * arch/arm/src/bcm2708/chip/bcm2708_uart.h + * arch/arm/src/bcm2708/chip/bcm2708_aux.h * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Alan Carvalho de Assis @@ -33,8 +33,8 @@ * ************************************************************************************/ -#ifndef __ARCH_ARM_SRC_BCM_CHIP_BCM_UART_H -#define __ARCH_ARM_SRC_BCM_CHIP_BCM_UART_H +#ifndef __ARCH_ARM_SRC_BCM_CHIP_BCM_AUX_H +#define __ARCH_ARM_SRC_BCM_CHIP_BCM_AUX_H /************************************************************************************ * Included Files @@ -208,4 +208,4 @@ #define BCM_AUX_SPI_STAT_TXLEVEL_SHIFT 24 /* Data units in the FX FIFO */ #define BCM_AUX_SPI_STAT_TXLEVEL_MASK (0xff << BCM_AUX_SPI_STAT_TXLEVEL_SHIFT) -#endif /* __ARCH_ARM_SRC_BCM_CHIP_BCM_UART_H */ +#endif /* __ARCH_ARM_SRC_BCM_CHIP_BCM_AUX_H */