2010-04-11 17:32:07 +02:00
|
|
|
/************************************************************************************
|
|
|
|
* configs/sam3u-ek/src/up_mmcsd.c
|
|
|
|
*
|
2013-06-02 18:33:57 +02:00
|
|
|
* Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-04-11 17:32:07 +02:00
|
|
|
*
|
|
|
|
* 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 <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
#include "sam_gpio.h"
|
|
|
|
#include "sam3u-ek.h"
|
2010-04-11 17:32:07 +02:00
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_HSMCI
|
2010-04-11 17:32:07 +02:00
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Definitions
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/* This needs to be extended. The card detect GPIO must be configured as an interrupt.
|
|
|
|
* when the interrupt indicating that a card has been inserted or removed is received,
|
|
|
|
* this function must call sio_mediachange() to handle that event. See
|
2013-06-02 21:57:22 +02:00
|
|
|
* arch/arm/src/sam34/sam_hsmci.h for more information.
|
2013-08-11 02:01:23 +02:00
|
|
|
*
|
|
|
|
* Also see the SAMA5D3x-EK implementation of this same logic. The card detect
|
|
|
|
* interrupt handling should be a drop-in.
|
2010-04-11 17:32:07 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef GPIO_MCI_CD
|
|
|
|
# warning "Card detect interrupt handling needed"
|
|
|
|
#endif
|
|
|
|
|
2013-08-11 02:01:23 +02:00
|
|
|
/* Usually defined in NuttX header files */
|
|
|
|
|
|
|
|
#ifndef OK
|
|
|
|
# define OK 0
|
|
|
|
#endif
|
|
|
|
|
2010-04-11 17:32:07 +02:00
|
|
|
/************************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
************************************************************************************/
|
|
|
|
|
2010-04-11 20:08:52 +02:00
|
|
|
/************************************************************************************
|
2013-06-02 21:04:40 +02:00
|
|
|
* Name: sam_hsmciinit
|
2010-04-11 17:32:07 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2010-04-11 20:08:52 +02:00
|
|
|
* Initialize HSMCI support. This function is called very early in board
|
|
|
|
* initialization.
|
2010-04-11 17:32:07 +02:00
|
|
|
*
|
2010-04-11 20:08:52 +02:00
|
|
|
************************************************************************************/
|
2010-04-11 17:32:07 +02:00
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
int sam_hsmciinit(void)
|
2010-04-11 17:32:07 +02:00
|
|
|
{
|
2010-04-11 20:08:52 +02:00
|
|
|
#ifdef GPIO_MCI_CD
|
2013-06-02 21:04:40 +02:00
|
|
|
sam_configgpio(GPIO_MCI_CD);
|
2010-04-11 17:32:07 +02:00
|
|
|
#endif
|
2010-04-11 20:08:52 +02:00
|
|
|
#ifdef GPIO_MCI_WP
|
2013-06-02 21:04:40 +02:00
|
|
|
sam_configgpio(GPIO_MCI_WP);
|
2010-04-11 17:32:07 +02:00
|
|
|
#endif
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2010-04-11 20:08:52 +02:00
|
|
|
/************************************************************************************
|
2013-06-02 21:04:40 +02:00
|
|
|
* Name: sam_cardinserted
|
2010-04-11 17:32:07 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if a card is inserted into the selected HSMCI slot
|
|
|
|
*
|
2010-04-11 20:08:52 +02:00
|
|
|
************************************************************************************/
|
2010-04-11 17:32:07 +02:00
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
bool sam_cardinserted(unsigned char slot)
|
2010-04-11 17:32:07 +02:00
|
|
|
{
|
|
|
|
if (slot == 0)
|
|
|
|
{
|
|
|
|
#ifdef GPIO_MCI_CD
|
2013-06-02 21:04:40 +02:00
|
|
|
bool inserted = sam_gpioread(GPIO_MCI_CD);
|
2010-04-11 20:08:52 +02:00
|
|
|
fvdbg("inserted: %s\n", inserted ? "NO" : "YES");
|
|
|
|
return !inserted;
|
2010-04-11 17:32:07 +02:00
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 20:08:52 +02:00
|
|
|
/************************************************************************************
|
2013-06-02 21:04:40 +02:00
|
|
|
* Name: sam_writeprotected
|
2010-04-11 17:32:07 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if a card is inserted into the selected HSMCI slot
|
|
|
|
*
|
2010-04-11 20:08:52 +02:00
|
|
|
************************************************************************************/
|
2010-04-11 17:32:07 +02:00
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
bool sam_writeprotected(unsigned char slot)
|
2010-04-11 17:32:07 +02:00
|
|
|
{
|
|
|
|
if (slot == 0)
|
|
|
|
{
|
|
|
|
#ifdef GPIO_MCI_WP
|
2013-06-02 21:04:40 +02:00
|
|
|
bool protected = sam_gpioread(GPIO_MCI_WP);
|
2010-04-11 20:08:52 +02:00
|
|
|
fvdbg("protected: %s\n", inserted ? "YES" : "NO");
|
|
|
|
return protected;
|
2010-04-11 17:32:07 +02:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#endif /* CONFIG_SAM34_HSMCI */
|