diff --git a/arch/arm/src/samv7/sam_hsmci.c b/arch/arm/src/samv7/sam_hsmci.c index 53e13de5323..361eac35fcd 100644 --- a/arch/arm/src/samv7/sam_hsmci.c +++ b/arch/arm/src/samv7/sam_hsmci.c @@ -581,9 +581,6 @@ static const struct sdio_dev_s g_callbacks = #ifdef CONFIG_SAMV7_HSMCI0 static struct sam_dev_s g_hsmci0; #endif -#ifdef CONFIG_SAMV7_HSMCI1 -static struct sam_dev_s g_hsmci1; -#endif /**************************************************************************** * Private Functions @@ -1906,13 +1903,6 @@ static int sam_attach(FAR struct sdio_dev_s *dev) irq = SAM_IRQ_HSMCI0; } else -#endif -#ifdef CONFIG_SAMV7_HSMCI1 - if (priv->hsmci == 1) - { - irq = SAM_IRQ_HSMCI1; - } - else #endif { DEBUGPANIC(); @@ -3319,44 +3309,6 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno) pid = SAM_PID_HSMCI0; } else -#endif -#ifdef CONFIG_SAMV7_HSMCI1 - if (slotno == 1) - { - /* Select HSMCI1 */ - - priv = &g_hsmci1; - - /* HSMCI1 Initialization */ - - priv->base = SAM_HSMCI1_BASE; - priv->hsmci = 1; - - /* Configure PIOs for 4-bit, wide-bus operation. NOTE: (1) the chip - * is capable of 8-bit wide bus operation but D4-D7 are not configured, - * (2) any card detection PIOs must be set up in board-specific logic. - * - * REVISIT: What about Slot B? - */ - - sam_configgpio(GPIO_MCI1_DA0); /* Data 0 of Slot A */ - sam_configgpio(GPIO_MCI1_DA1); /* Data 1 of Slot A */ - sam_configgpio(GPIO_MCI1_DA2); /* Data 2 of Slot A */ - sam_configgpio(GPIO_MCI1_DA3); /* Data 3 of Slot A */ - sam_configgpio(GPIO_MCI1_CK); /* Common SD clock */ - sam_configgpio(GPIO_MCI1_CDA); /* Command/Response of Slot A */ - - /* Enable the HSMCI1 peripheral clock This really should be done in - * sam_enable (as well as disabling peripheral clocks in sam_disable(). - */ - - sam_hsmci1_enableclk(); - - /* For DMA channel selection */ - - pid = SAM_PID_HSMCI1; - } - else #endif { DEBUGPANIC(); diff --git a/arch/arm/src/samv7/sam_hsmci_clkdiv.c b/arch/arm/src/samv7/sam_hsmci_clkdiv.c index b4779ed5c11..97d7c5199c5 100644 --- a/arch/arm/src/samv7/sam_hsmci_clkdiv.c +++ b/arch/arm/src/samv7/sam_hsmci_clkdiv.c @@ -36,7 +36,7 @@ #include "hardware/sam_hsmci.h" #include "sam_hsmci.h" -#ifdef CONFIG_SAMV7_HSMCI0 +#ifdef CONFIG_SAMV7_HSMCI /**************************************************************************** * Pre-processor Definitions diff --git a/boards/arm/samv7/common/include/board_hsmci.h b/boards/arm/samv7/common/include/board_hsmci.h new file mode 100644 index 00000000000..94dc1dced50 --- /dev/null +++ b/boards/arm/samv7/common/include/board_hsmci.h @@ -0,0 +1,90 @@ +/**************************************************************************** + * boards/arm/samv7/common/include/board_hsmci.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_SAMV7_COMMON_INCLUDE_BOARD_HSMCI_H +#define __BOARDS_ARM_SAMV7_COMMON_INCLUDE_BOARD_HSMCI_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "sam_gpio.h" + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Functions Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_hsmci_initialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int sam_hsmci_initialize(int slotno, int minor, gpio_pinset_t cdcfg, + int cdirq); + +/**************************************************************************** + * Name: sam_cardinserted + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ****************************************************************************/ + +bool sam_cardinserted(int slotno); + +/**************************************************************************** + * Name: sam_writeprotected + * + * Description: + * Check if the card in the MMCSD slot is write protected + * + ****************************************************************************/ + +bool sam_writeprotected(int slotno); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_SAMV7_COMMON_INCLUDE_BOARD_HSMCI_H */ diff --git a/boards/arm/samv7/common/include/sam_automount.h b/boards/arm/samv7/common/include/sam_automount.h index 8e783a7cb60..4ca17437364 100644 --- a/boards/arm/samv7/common/include/sam_automount.h +++ b/boards/arm/samv7/common/include/sam_automount.h @@ -25,7 +25,7 @@ * Pre-processor Definitions ****************************************************************************/ -#ifdef CONFIG_SAME70QMTECH_HSMCI0_AUTOMOUNT +#ifdef CONFIG_SAMV7_HSMCI0_AUTOMOUNT /* HSMCI0 Automounter defaults */ # ifndef CONFIG_SAMV7_HSMCI0_AUTOMOUNT_FSTYPE diff --git a/boards/arm/samv7/common/src/Make.defs b/boards/arm/samv7/common/src/Make.defs index de72e9fa61b..3e4f296d50d 100644 --- a/boards/arm/samv7/common/src/Make.defs +++ b/boards/arm/samv7/common/src/Make.defs @@ -33,6 +33,10 @@ else ifeq ($(CONFIG_BOARD_LATE_INITIALIZE),y) CSRCS += sam_progmem.c endif +ifeq ($(CONFIG_SAMV7_HSMCI0),y) +CSRCS += sam_hsmci.c +endif + ifeq ($(CONFIG_FS_AUTOMOUNTER),y) CSRCS += sam_automount.c endif diff --git a/boards/arm/samv7/common/src/sam_automount.c b/boards/arm/samv7/common/src/sam_automount.c index 175e9bc2435..461f52988f6 100644 --- a/boards/arm/samv7/common/src/sam_automount.c +++ b/boards/arm/samv7/common/src/sam_automount.c @@ -35,6 +35,7 @@ #include #include +#include "board_hsmci.h" #include "sam_automount.h" /**************************************************************************** diff --git a/boards/arm/samv7/same70-qmtech/src/sam_hsmci.c b/boards/arm/samv7/common/src/sam_hsmci.c similarity index 78% rename from boards/arm/samv7/same70-qmtech/src/sam_hsmci.c rename to boards/arm/samv7/common/src/sam_hsmci.c index c45ab50d032..4a70abaec56 100644 --- a/boards/arm/samv7/same70-qmtech/src/sam_hsmci.c +++ b/boards/arm/samv7/common/src/sam_hsmci.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/samv7/same70-qmtech/src/sam_hsmci.c + * boards/arm/samv7/common/src/sam_hsmci.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,24 +18,6 @@ * ****************************************************************************/ -/* The SAM E70 Xplained Ultraas one standard SD card connector that is - * connected to the High Speed Multimedia Card Interface (HSMCI) of the SAM - * E70. SD card connector: - * - * ------ ----------------- --------------------- - * SAME70 SAME70 Shared functionality - * Pin Function - * ------ ----------------- --------------------- - * PA30 MCDA0 (DAT0) - * PA31 MCDA1 (DAT1) - * PA26 MCDA2 (DAT2) - * PA27 MCDA3 (DAT3) Camera - * PA25 MCCK (CLK) Shield - * PA28 MCCDA (CMD) - * PD17 Card Detect (C/D) Shield - * ------ ----------------- --------------------- - */ - /**************************************************************************** * Included Files ****************************************************************************/ @@ -50,16 +32,12 @@ #include #include -#include "sam_gpio.h" #include "sam_hsmci.h" +#include "board_hsmci.h" -#include "same70-qmtech.h" - -#ifdef HAVE_AUTOMOUNTER +#ifdef CONFIG_FS_AUTOMOUNTER # include "sam_automount.h" -#endif /* HAVE_AUTOMOUNTER */ - -#ifdef HAVE_HSMCI +#endif /* CONFIG_FS_AUTOMOUNTER */ /**************************************************************************** * Pre-processor Definitions @@ -75,11 +53,9 @@ struct sam_hsmci_state_s { struct sdio_dev_s *hsmci; /* R/W device handle */ gpio_pinset_t cdcfg; /* Card detect PIO pin configuration */ - gpio_pinset_t pwrcfg; /* Power PIO pin configuration */ - uint8_t irq; /* Interrupt number (same as pid) */ + int cdirq; /* Interrupt number (same as pid) */ uint8_t slotno; /* Slot number */ bool cd; /* TRUE: card is inserted */ - xcpt_t handler; /* Interrupt handler */ }; /**************************************************************************** @@ -89,14 +65,9 @@ struct sam_hsmci_state_s /* HSCMI device state */ #ifdef CONFIG_SAMV7_HSMCI0 -static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg); - static struct sam_hsmci_state_s g_hsmci0 = { - .cdcfg = GPIO_MCI0_CD, - .irq = IRQ_MCI0_CD, - .slotno = 0, - .handler = sam_hsmci0_cardetect, + .slotno = 0 }; #endif @@ -112,7 +83,7 @@ static struct sam_hsmci_state_s g_hsmci0 = * ****************************************************************************/ -bool sam_cardinserted_internal(struct sam_hsmci_state_s *state) +static bool sam_cardinserted_internal(struct sam_hsmci_state_s *state) { bool inserted; @@ -124,7 +95,7 @@ bool sam_cardinserted_internal(struct sam_hsmci_state_s *state) } /**************************************************************************** - * Name: sam_hsmci_cardetect, sam_hsmci0_cardetect, and sam_hsmci1_cardetect + * Name: sam_hsmci_cardetect and sam_hsmci_cardetect_handler * * Description: * Card detect interrupt handlers @@ -153,9 +124,10 @@ static int sam_hsmci_cardetect(struct sam_hsmci_state_s *state) return OK; } -#ifdef CONFIG_SAMV7_HSMCI0 -static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg) +static int sam_hsmci_cardetect_handler(int irq, FAR void *context, + FAR void *arg) { + struct sam_hsmci_state_s *state = (struct sam_hsmci_state_s *)arg; int ret; /* Handle the card detect interrupt. The interrupt level logic will @@ -163,17 +135,16 @@ static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg) * device. */ - ret = sam_hsmci_cardetect(&g_hsmci0); + ret = sam_hsmci_cardetect(state); -#if defined(CONFIG_SAMV7_HSMCI0_AUTOMOUNT) +#ifdef CONFIG_FS_AUTOMOUNTER /* Let the automounter know about the insertion event */ - sam_automount_event(HSMCI0_SLOTNO, sam_cardinserted(HSMCI0_SLOTNO)); -#endif + sam_automount_event(state->slotno, sam_cardinserted(state->slotno)); +#endif /* CONFIG_FS_AUTOMOUNTER */ return ret; } -#endif /**************************************************************************** * Name: sam_hsmci_state @@ -188,7 +159,10 @@ static inline struct sam_hsmci_state_s *sam_hsmci_state(int slotno) struct sam_hsmci_state_s *state = NULL; #ifdef CONFIG_SAMV7_HSMCI0 - state = &g_hsmci0; + if (g_hsmci0.slotno == slotno) + { + state = &g_hsmci0; + } #endif return state; @@ -206,7 +180,8 @@ static inline struct sam_hsmci_state_s *sam_hsmci_state(int slotno) * ****************************************************************************/ -int sam_hsmci_initialize(int slotno, int minor) +int sam_hsmci_initialize(int slotno, int minor, gpio_pinset_t cdcfg, + int cdirq) { struct sam_hsmci_state_s *state; int ret; @@ -214,29 +189,26 @@ int sam_hsmci_initialize(int slotno, int minor) /* Get the static HSMI description */ state = sam_hsmci_state(slotno); - if (!state) + if (state == NULL) { ferr("ERROR: No state for slotno %d\n", slotno); return -EINVAL; } + state->cdcfg = cdcfg; + state->cdirq = cdirq; + /* Initialize card-detect, write-protect, and power enable PIOs */ sam_configgpio(state->cdcfg); sam_dumpgpio(state->cdcfg, "HSMCI Card Detect"); - if (state->pwrcfg != 0) - { - sam_configgpio(state->pwrcfg); - sam_dumpgpio(state->pwrcfg, "HSMCI Power"); - } - /* Mount the SDIO-based MMC/SD block driver */ /* First, get an instance of the SDIO interface */ state->hsmci = sdio_initialize(slotno); - if (!state->hsmci) + if (state->hsmci == NULL) { ferr("ERROR: Failed to initialize SDIO slot %d\n", slotno); return -ENODEV; @@ -254,7 +226,7 @@ int sam_hsmci_initialize(int slotno, int minor) /* Configure card detect interrupts */ sam_gpioirq(state->cdcfg); - irq_attach(state->irq, state->handler, NULL); + irq_attach(state->cdirq, sam_hsmci_cardetect_handler, (FAR void *)state); /* Then inform the HSMCI driver if there is or is not a card in the slot. */ @@ -263,7 +235,7 @@ int sam_hsmci_initialize(int slotno, int minor) /* Enable card detect interrupts */ - sam_gpioirqenable(state->irq); + sam_gpioirqenable(state->cdirq); return OK; } @@ -282,7 +254,7 @@ bool sam_cardinserted(int slotno) /* Get the HSMI description */ state = sam_hsmci_state(slotno); - if (!state) + if (state == NULL) { ferr("ERROR: No state for slotno %d\n", slotno); return false; @@ -307,5 +279,3 @@ bool sam_writeprotected(int slotno) return false; } - -#endif /* HAVE_HSMCI */ diff --git a/boards/arm/samv7/same70-qmtech/src/Make.defs b/boards/arm/samv7/same70-qmtech/src/Make.defs index 0f0dae0c5ba..35be697ffed 100644 --- a/boards/arm/samv7/same70-qmtech/src/Make.defs +++ b/boards/arm/samv7/same70-qmtech/src/Make.defs @@ -38,10 +38,6 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += sam_buttons.c endif -ifeq ($(CONFIG_SAMV7_HSMCI0),y) -CSRCS += sam_hsmci.c -endif - ifeq ($(CONFIG_SAMV7_SPI),y) CSRCS += sam_spi.c endif diff --git a/boards/arm/samv7/same70-qmtech/src/sam_bringup.c b/boards/arm/samv7/same70-qmtech/src/sam_bringup.c index 94ed8b54034..ab803ce24f6 100644 --- a/boards/arm/samv7/same70-qmtech/src/sam_bringup.c +++ b/boards/arm/samv7/same70-qmtech/src/sam_bringup.c @@ -39,6 +39,10 @@ #include "same70-qmtech.h" +#ifdef HAVE_HSMCI +# include "board_hsmci.h" +#endif /* HAVE_HSMCI */ + #ifdef HAVE_AUTOMOUNTER # include "sam_automount.h" #endif /* HAVE_AUTOMOUNTER */ @@ -93,7 +97,8 @@ int sam_bringup(void) #ifdef HAVE_HSMCI /* Initialize the HSMCI0 driver */ - ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR); + ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR, GPIO_HSMCI0_CD, + IRQ_HSMCI0_CD); if (ret < 0) { syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", diff --git a/boards/arm/samv7/same70-qmtech/src/same70-qmtech.h b/boards/arm/samv7/same70-qmtech/src/same70-qmtech.h index e9363176391..b0677d3d497 100644 --- a/boards/arm/samv7/same70-qmtech/src/same70-qmtech.h +++ b/boards/arm/samv7/same70-qmtech/src/same70-qmtech.h @@ -161,9 +161,9 @@ * ------ ----------------- --------------------- */ -#define GPIO_MCI0_CD (GPIO_INPUT | GPIO_CFG_PULLDOWN | GPIO_CFG_DEGLITCH | \ - GPIO_INT_BOTHEDGES | GPIO_PORT_PIOD | GPIO_PIN17) -#define IRQ_MCI0_CD SAM_IRQ_PD17 +#define GPIO_HSMCI0_CD (GPIO_INPUT | GPIO_CFG_PULLDOWN | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOD | GPIO_PIN17) +#define IRQ_HSMCI0_CD SAM_IRQ_PD17 /**************************************************************************** * Public Types @@ -228,20 +228,6 @@ int sam_dacdev_initialize(void); void sam_spidev_initialize(void); #endif -/**************************************************************************** - * Name: sam_hsmci_initialize - * - * Description: - * Initialize HSMCI support - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -int sam_hsmci_initialize(int slot, int minor); -#else -# define sam_hsmci_initialize(s,m) (-ENOSYS) -#endif - /**************************************************************************** * Name: sam_can_setup * @@ -254,45 +240,5 @@ int sam_hsmci_initialize(int slot, int minor); int sam_can_setup(void); #endif -/**************************************************************************** - * Name: sam_cardinserted - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_cardinserted(int slotno); -#else -# define sam_cardinserted(slotno) (false) -#endif - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if the card in the MMCSD slot is write protected - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_writeprotected(int slotno); -#endif - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if the card in the MMCSD slot is write protected - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_writeprotected(int slotno); -#else -# define sam_writeprotected(slotno) (false) -#endif - #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_SAMV7_SAME70_QMTECH_SRC_SAME70_QMTECH_H */ diff --git a/boards/arm/samv7/same70-xplained/src/Make.defs b/boards/arm/samv7/same70-xplained/src/Make.defs index 0af797d13fd..548a542ef06 100644 --- a/boards/arm/samv7/same70-xplained/src/Make.defs +++ b/boards/arm/samv7/same70-xplained/src/Make.defs @@ -42,10 +42,6 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += sam_buttons.c endif -ifeq ($(CONFIG_SAMV7_HSMCI0),y) -CSRCS += sam_hsmci.c -endif - ifeq ($(CONFIG_SAMV7_EMAC),y) CSRCS += sam_ethernet.c endif diff --git a/boards/arm/samv7/same70-xplained/src/sam_bringup.c b/boards/arm/samv7/same70-xplained/src/sam_bringup.c index e636a2b8469..2bbf4cb42d8 100644 --- a/boards/arm/samv7/same70-xplained/src/sam_bringup.c +++ b/boards/arm/samv7/same70-xplained/src/sam_bringup.c @@ -45,6 +45,10 @@ #include "sam_twihs.h" #include "same70-xplained.h" +#ifdef HAVE_HSMCI +# include "board_hsmci.h" +#endif /* HAVE_HSMCI */ + #ifdef HAVE_AUTOMOUNTER # include "sam_automount.h" #endif /* HAVE_AUTOMOUNTER */ @@ -184,7 +188,8 @@ int sam_bringup(void) #ifdef HAVE_HSMCI /* Initialize the HSMCI0 driver */ - ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR); + ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR, GPIO_HSMCI0_CD, + IRQ_HSMCI0_CD); if (ret < 0) { syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", diff --git a/boards/arm/samv7/same70-xplained/src/sam_hsmci.c b/boards/arm/samv7/same70-xplained/src/sam_hsmci.c deleted file mode 100644 index d28c07ba9c6..00000000000 --- a/boards/arm/samv7/same70-xplained/src/sam_hsmci.c +++ /dev/null @@ -1,311 +0,0 @@ -/**************************************************************************** - * boards/arm/samv7/same70-xplained/src/sam_hsmci.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* The SAM E70 Xplained Ultraas one standard SD card connector that is - * connected to the High Speed Multimedia Card Interface (HSMCI) of the SAM - * E70. SD card connector: - * - * ------ ----------------- --------------------- - * SAME70 SAME70 Shared functionality - * Pin Function - * ------ ----------------- --------------------- - * PA30 MCDA0 (DAT0) - * PA31 MCDA1 (DAT1) - * PA26 MCDA2 (DAT2) - * PA27 MCDA3 (DAT3) Camera - * PA25 MCCK (CLK) Shield - * PA28 MCCDA (CMD) - * PC16 Card Detect (C/D) Shield - * ------ ----------------- --------------------- - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "sam_gpio.h" -#include "sam_hsmci.h" - -#include "same70-xplained.h" - -#ifdef HAVE_AUTOMOUNTER -# include "sam_automount.h" -#endif /* HAVE_AUTOMOUNTER */ - -#ifdef HAVE_HSMCI - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This structure holds static information unique to one HSMCI peripheral */ - -struct sam_hsmci_state_s -{ - struct sdio_dev_s *hsmci; /* R/W device handle */ - gpio_pinset_t cdcfg; /* Card detect PIO pin configuration */ - gpio_pinset_t pwrcfg; /* Power PIO pin configuration */ - uint8_t irq; /* Interrupt number (same as pid) */ - uint8_t slotno; /* Slot number */ - bool cd; /* TRUE: card is inserted */ - xcpt_t handler; /* Interrupt handler */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* HSCMI device state */ - -#ifdef CONFIG_SAMV7_HSMCI0 -static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg); - -static struct sam_hsmci_state_s g_hsmci0 = -{ - .cdcfg = GPIO_MCI0_CD, - .irq = IRQ_MCI0_CD, - .slotno = 0, - .handler = sam_hsmci0_cardetect, -}; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sam_cardinserted_internal - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -bool sam_cardinserted_internal(struct sam_hsmci_state_s *state) -{ - bool inserted; - - /* Get the state of the PIO pin */ - - inserted = sam_gpioread(state->cdcfg); - finfo("Slot %d inserted: %s\n", state->slotno, inserted ? "NO" : "YES"); - return !inserted; -} - -/**************************************************************************** - * Name: sam_hsmci_cardetect, sam_hsmci0_cardetect, and sam_hsmci1_cardetect - * - * Description: - * Card detect interrupt handlers - * - ****************************************************************************/ - -static int sam_hsmci_cardetect(struct sam_hsmci_state_s *state) -{ - /* Get the current card insertion state */ - - bool cd = sam_cardinserted_internal(state); - - /* Has the card detect state changed? */ - - if (cd != state->cd) - { - /* Yes... remember that new state and inform the HSMCI driver */ - - state->cd = cd; - - /* Report the new state to the SDIO driver */ - - sdio_mediachange(state->hsmci, cd); - } - - return OK; -} - -#ifdef CONFIG_SAMV7_HSMCI0 -static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg) -{ - int ret; - - /* Handle the card detect interrupt. The interrupt level logic will - * kick of the driver-level operations to initialize the MMC/SD block - * device. - */ - - ret = sam_hsmci_cardetect(&g_hsmci0); - -#if defined(CONFIG_SAMV7_HSMCI0_AUTOMOUNT) - /* Let the automounter know about the insertion event */ - - sam_automount_event(HSMCI0_SLOTNO, sam_cardinserted(HSMCI0_SLOTNO)); -#endif - - return ret; -} -#endif - -/**************************************************************************** - * Name: sam_hsmci_state - * - * Description: - * Initialize HSMCI PIOs. - * - ****************************************************************************/ - -static inline struct sam_hsmci_state_s *sam_hsmci_state(int slotno) -{ - struct sam_hsmci_state_s *state = NULL; - -#ifdef CONFIG_SAMV7_HSMCI0 - state = &g_hsmci0; -#endif - - return state; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sam_hsmci_initialize - * - * Description: - * Perform architecture specific initialization - * - ****************************************************************************/ - -int sam_hsmci_initialize(int slotno, int minor) -{ - struct sam_hsmci_state_s *state; - int ret; - - /* Get the static HSMI description */ - - state = sam_hsmci_state(slotno); - if (!state) - { - ferr("ERROR: No state for slotno %d\n", slotno); - return -EINVAL; - } - - /* Initialize card-detect, write-protect, and power enable PIOs */ - - sam_configgpio(state->cdcfg); - sam_dumpgpio(state->cdcfg, "HSMCI Card Detect"); - - if (state->pwrcfg != 0) - { - sam_configgpio(state->pwrcfg); - sam_dumpgpio(state->pwrcfg, "HSMCI Power"); - } - - /* Mount the SDIO-based MMC/SD block driver */ - - /* First, get an instance of the SDIO interface */ - - state->hsmci = sdio_initialize(slotno); - if (!state->hsmci) - { - ferr("ERROR: Failed to initialize SDIO slot %d\n", slotno); - return -ENODEV; - } - - /* Now bind the SDIO interface to the MMC/SD driver */ - - ret = mmcsd_slotinitialize(minor, state->hsmci); - if (ret != OK) - { - ferr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); - return ret; - } - - /* Configure card detect interrupts */ - - sam_gpioirq(state->cdcfg); - irq_attach(state->irq, state->handler, NULL); - - /* Then inform the HSMCI driver if there is or is not a card in the slot. */ - - state->cd = sam_cardinserted_internal(state); - sdio_mediachange(state->hsmci, state->cd); - - /* Enable card detect interrupts */ - - sam_gpioirqenable(state->irq); - return OK; -} - -/**************************************************************************** - * Name: sam_cardinserted - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -bool sam_cardinserted(int slotno) -{ - struct sam_hsmci_state_s *state; - - /* Get the HSMI description */ - - state = sam_hsmci_state(slotno); - if (!state) - { - ferr("ERROR: No state for slotno %d\n", slotno); - return false; - } - - /* Return the state of the PIO pin */ - - return sam_cardinserted_internal(state); -} - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -bool sam_writeprotected(int slotno) -{ - /* There are no write protect pins */ - - return false; -} - -#endif /* HAVE_HSMCI */ diff --git a/boards/arm/samv7/same70-xplained/src/same70-xplained.h b/boards/arm/samv7/same70-xplained/src/same70-xplained.h index 8fa189c3596..95671e0d827 100644 --- a/boards/arm/samv7/same70-xplained/src/same70-xplained.h +++ b/boards/arm/samv7/same70-xplained/src/same70-xplained.h @@ -301,9 +301,9 @@ * ------ ----------------- --------------------- */ -#define GPIO_MCI0_CD (GPIO_INPUT | GPIO_CFG_DEFAULT | GPIO_CFG_DEGLITCH | \ - GPIO_INT_BOTHEDGES | GPIO_PORT_PIOC | GPIO_PIN16) -#define IRQ_MCI0_CD SAM_IRQ_PC16 +#define GPIO_HSMCI0_CD (GPIO_INPUT | GPIO_CFG_DEFAULT | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOC | GPIO_PIN16) +#define IRQ_HSMCI0_CD SAM_IRQ_PC16 /* USB Host * @@ -460,20 +460,6 @@ int sam_dacdev_initialize(void); void sam_spidev_initialize(void); #endif -/**************************************************************************** - * Name: sam_hsmci_initialize - * - * Description: - * Initialize HSMCI support - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -int sam_hsmci_initialize(int slot, int minor); -#else -# define sam_hsmci_initialize(s,m) (-ENOSYS) -#endif - /**************************************************************************** * Name: sam_usbinitialize * @@ -524,46 +510,6 @@ void sam_netinitialize(void); int sam_emac0_setmac(void); #endif -/**************************************************************************** - * Name: sam_cardinserted - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_cardinserted(int slotno); -#else -# define sam_cardinserted(slotno) (false) -#endif - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if the card in the MMCSD slot is write protected - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_writeprotected(int slotno); -#endif - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if the card in the MMCSD slot is write protected - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_writeprotected(int slotno); -#else -# define sam_writeprotected(slotno) (false) -#endif - /**************************************************************************** * Name: sam_at24config * diff --git a/boards/arm/samv7/samv71-xult/src/Make.defs b/boards/arm/samv7/samv71-xult/src/Make.defs index 5ae2161944d..997f623d178 100644 --- a/boards/arm/samv7/samv71-xult/src/Make.defs +++ b/boards/arm/samv7/samv71-xult/src/Make.defs @@ -42,10 +42,6 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += sam_buttons.c endif -ifeq ($(CONFIG_SAMV7_HSMCI0),y) -CSRCS += sam_hsmci.c -endif - ifeq ($(CONFIG_SAMV7_EMAC),y) CSRCS += sam_ethernet.c endif diff --git a/boards/arm/samv7/samv71-xult/src/sam_bringup.c b/boards/arm/samv7/samv71-xult/src/sam_bringup.c index 59565edc2ff..2fa5969cefc 100644 --- a/boards/arm/samv7/samv71-xult/src/sam_bringup.c +++ b/boards/arm/samv7/samv71-xult/src/sam_bringup.c @@ -71,6 +71,10 @@ # include "sam_twihs.h" #endif +#ifdef HAVE_HSMCI +# include "board_hsmci.h" +#endif /* HAVE_HSMCI */ + #ifdef HAVE_AUTOMOUNTER # include "sam_automount.h" #endif /* HAVE_AUTOMOUNTER */ @@ -301,7 +305,8 @@ int sam_bringup(void) #ifdef HAVE_HSMCI /* Initialize the HSMCI0 driver */ - ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR); + ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR, GPIO_HSMCI0_CD, + IRQ_HSMCI0_CD); if (ret < 0) { syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", diff --git a/boards/arm/samv7/samv71-xult/src/sam_hsmci.c b/boards/arm/samv7/samv71-xult/src/sam_hsmci.c deleted file mode 100644 index edc189b9a28..00000000000 --- a/boards/arm/samv7/samv71-xult/src/sam_hsmci.c +++ /dev/null @@ -1,311 +0,0 @@ -/**************************************************************************** - * boards/arm/samv7/samv71-xult/src/sam_hsmci.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/* The SAM V71 Xplained Ultra has one standard SD card connector which is - * connected to the High Speed Multimedia Card Interface (HSMCI) of the SAM - * V71. SD card connector: - * - * ------ ----------------- --------------------- - * SAMV71 SAMV71 Shared functionality - * Pin Function - * ------ ----------------- --------------------- - * PA30 MCDA0 (DAT0) - * PA31 MCDA1 (DAT1) - * PA26 MCDA2 (DAT2) - * PA27 MCDA3 (DAT3) Camera - * PA25 MCCK (CLK) Shield - * PA28 MCCDA (CMD) - * PD18 Card Detect (C/D) Shield - * ------ ----------------- --------------------- - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "sam_gpio.h" -#include "sam_hsmci.h" - -#include "samv71-xult.h" - -#ifdef HAVE_AUTOMOUNTER -# include "sam_automount.h" -#endif /* HAVE_AUTOMOUNTER */ - -#ifdef HAVE_HSMCI - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This structure holds static information unique to one HSMCI peripheral */ - -struct sam_hsmci_state_s -{ - struct sdio_dev_s *hsmci; /* R/W device handle */ - gpio_pinset_t cdcfg; /* Card detect GPIO pin configuration */ - gpio_pinset_t pwrcfg; /* Power GPIO pin configuration */ - uint8_t irq; /* Interrupt number (same as pid) */ - uint8_t slotno; /* Slot number */ - bool cd; /* TRUE: card is inserted */ - xcpt_t handler; /* Interrupt handler */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* HSCMI device state */ - -#ifdef CONFIG_SAMV7_HSMCI0 -static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg); - -static struct sam_hsmci_state_s g_hsmci0 = -{ - .cdcfg = GPIO_MCI0_CD, - .irq = IRQ_MCI0_CD, - .slotno = 0, - .handler = sam_hsmci0_cardetect, -}; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sam_cardinserted_internal - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -bool sam_cardinserted_internal(struct sam_hsmci_state_s *state) -{ - bool inserted; - - /* Get the state of the GPIO pin */ - - inserted = sam_gpioread(state->cdcfg); - mcinfo("Slot %d inserted: %s\n", state->slotno, inserted ? "NO" : "YES"); - return !inserted; -} - -/**************************************************************************** - * Name: sam_hsmci_cardetect, sam_hsmci0_cardetect, and sam_hsmci1_cardetect - * - * Description: - * Card detect interrupt handlers - * - ****************************************************************************/ - -static int sam_hsmci_cardetect(struct sam_hsmci_state_s *state) -{ - /* Get the current card insertion state */ - - bool cd = sam_cardinserted_internal(state); - - /* Has the card detect state changed? */ - - if (cd != state->cd) - { - /* Yes... remember that new state and inform the HSMCI driver */ - - state->cd = cd; - - /* Report the new state to the SDIO driver */ - - sdio_mediachange(state->hsmci, cd); - } - - return OK; -} - -#ifdef CONFIG_SAMV7_HSMCI0 -static int sam_hsmci0_cardetect(int irq, void *regs, FAR void *arg) -{ - int ret; - - /* Handle the card detect interrupt. The interrupt level logic will - * kick of the driver-level operations to initialize the MMC/SD block - * device. - */ - - ret = sam_hsmci_cardetect(&g_hsmci0); - -#if defined(CONFIG_SAMV7_HSMCI0_AUTOMOUNT) - /* Let the automounter know about the insertion event */ - - sam_automount_event(HSMCI0_SLOTNO, sam_cardinserted(HSMCI0_SLOTNO)); -#endif - - return ret; -} -#endif - -/**************************************************************************** - * Name: sam_hsmci_state - * - * Description: - * Initialize HSMCI GPIOs. - * - ****************************************************************************/ - -static inline struct sam_hsmci_state_s *sam_hsmci_state(int slotno) -{ - struct sam_hsmci_state_s *state = NULL; - -#ifdef CONFIG_SAMV7_HSMCI0 - state = &g_hsmci0; -#endif - - return state; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sam_hsmci_initialize - * - * Description: - * Perform architecture specific initialization - * - ****************************************************************************/ - -int sam_hsmci_initialize(int slotno, int minor) -{ - struct sam_hsmci_state_s *state; - int ret; - - /* Get the static HSMCI description */ - - state = sam_hsmci_state(slotno); - if (!state) - { - mcerr("ERROR: No state for slotno %d\n", slotno); - return -EINVAL; - } - - /* Initialize card-detect, write-protect, and power enable GPIOs */ - - sam_configgpio(state->cdcfg); - sam_dumpgpio(state->cdcfg, "HSMCI Card Detect"); - - if (state->pwrcfg != 0) - { - sam_configgpio(state->pwrcfg); - sam_dumpgpio(state->pwrcfg, "HSMCI Power"); - } - - /* Mount the SDIO-based MMC/SD block driver */ - - /* First, get an instance of the SDIO interface */ - - state->hsmci = sdio_initialize(slotno); - if (!state->hsmci) - { - mcerr("ERROR: Failed to initialize SDIO slot %d\n", slotno); - return -ENODEV; - } - - /* Now bind the SDIO interface to the MMC/SD driver */ - - ret = mmcsd_slotinitialize(minor, state->hsmci); - if (ret != OK) - { - mcerr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); - return ret; - } - - /* Configure card detect interrupts */ - - sam_gpioirq(state->cdcfg); - irq_attach(state->irq, state->handler, NULL); - - /* Then inform the HSMCI driver if there is or is not a card in the slot. */ - - state->cd = sam_cardinserted_internal(state); - sdio_mediachange(state->hsmci, state->cd); - - /* Enable card detect interrupts */ - - sam_gpioirqenable(state->irq); - return OK; -} - -/**************************************************************************** - * Name: sam_cardinserted - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -bool sam_cardinserted(int slotno) -{ - struct sam_hsmci_state_s *state; - - /* Get the HSMI description */ - - state = sam_hsmci_state(slotno); - if (!state) - { - mcerr("ERROR: No state for slotno %d\n", slotno); - return false; - } - - /* Return the state of the GPIO pin */ - - return sam_cardinserted_internal(state); -} - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -bool sam_writeprotected(int slotno) -{ - /* There are no write protect pins */ - - return false; -} - -#endif /* HAVE_HSMCI */ diff --git a/boards/arm/samv7/samv71-xult/src/samv71-xult.h b/boards/arm/samv7/samv71-xult/src/samv71-xult.h index 35728194881..e2c378cbaa5 100644 --- a/boards/arm/samv7/samv71-xult/src/samv71-xult.h +++ b/boards/arm/samv7/samv71-xult/src/samv71-xult.h @@ -479,9 +479,9 @@ * ------ ----------------- --------------------- */ -#define GPIO_MCI0_CD (GPIO_INPUT | GPIO_CFG_DEFAULT | GPIO_CFG_DEGLITCH | \ - GPIO_INT_BOTHEDGES | GPIO_PORT_PIOD | GPIO_PIN18) -#define IRQ_MCI0_CD SAM_IRQ_PD18 +#define GPIO_HSMCI0_CD (GPIO_INPUT | GPIO_CFG_DEFAULT | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOD | GPIO_PIN18) +#define IRQ_HSMCI0_CD SAM_IRQ_PD18 /* USB Host * @@ -680,20 +680,6 @@ void sam_spidev_initialize(void); int sam_can_setup(void); #endif -/**************************************************************************** - * Name: sam_hsmci_initialize - * - * Description: - * Initialize HSMCI support - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -int sam_hsmci_initialize(int slot, int minor); -#else -# define sam_hsmci_initialize(s,m) (-ENOSYS) -#endif - /**************************************************************************** * Name: sam_usbinitialize * @@ -732,46 +718,6 @@ void sam_netinitialize(void); int sam_emac0_setmac(void); #endif -/**************************************************************************** - * Name: sam_cardinserted - * - * Description: - * Check if a card is inserted into the selected HSMCI slot - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_cardinserted(int slotno); -#else -# define sam_cardinserted(slotno) (false) -#endif - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if the card in the MMCSD slot is write protected - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_writeprotected(int slotno); -#endif - -/**************************************************************************** - * Name: sam_writeprotected - * - * Description: - * Check if the card in the MMCSD slot is write protected - * - ****************************************************************************/ - -#ifdef HAVE_HSMCI -bool sam_writeprotected(int slotno); -#else -# define sam_writeprotected(slotno) (false) -#endif - /**************************************************************************** * Name: sam_at24config *