boards/arm/samv7: move HSMCI interface to common

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2022-01-19 18:09:38 +02:00 committed by Xiang Xiao
parent face0514b6
commit 767cf282c7
18 changed files with 153 additions and 917 deletions

View File

@ -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();

View File

@ -36,7 +36,7 @@
#include "hardware/sam_hsmci.h"
#include "sam_hsmci.h"
#ifdef CONFIG_SAMV7_HSMCI0
#ifdef CONFIG_SAMV7_HSMCI
/****************************************************************************
* Pre-processor Definitions

View File

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

View File

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

View File

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

View File

@ -35,6 +35,7 @@
#include <nuttx/clock.h>
#include <nuttx/fs/automount.h>
#include "board_hsmci.h"
#include "sam_automount.h"
/****************************************************************************

View File

@ -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 <nuttx/sdio.h>
#include <nuttx/mmcsd.h>
#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 */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/sdio.h>
#include <nuttx/mmcsd.h>
#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 */

View File

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

View File

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

View File

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

View File

@ -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 <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/sdio.h>
#include <nuttx/mmcsd.h>
#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 */

View File

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