2014-02-13 00:21:28 +01:00
|
|
|
/****************************************************************************
|
2019-08-16 15:40:59 +02:00
|
|
|
* boards/arm/samd2l2/samd20-xplained/src/sam_mmcsd.c
|
2014-02-13 00:21:28 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* 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
|
2014-02-13 00:21:28 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-02-13 00:21:28 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* 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.
|
2014-02-13 00:21:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/spi/spi.h>
|
|
|
|
#include <nuttx/mmcsd.h>
|
|
|
|
|
2014-02-13 01:29:23 +01:00
|
|
|
#include "sam_config.h"
|
2016-01-26 20:03:12 +01:00
|
|
|
#include "sam_spi.h"
|
|
|
|
|
2014-02-13 00:21:28 +01:00
|
|
|
#include "samd20-xplained.h"
|
|
|
|
|
2014-02-20 18:27:59 +01:00
|
|
|
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
|
2014-02-13 00:21:28 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 17:15:17 +02:00
|
|
|
* Pre-processor Definitions
|
2014-02-13 00:21:28 +01:00
|
|
|
****************************************************************************/
|
2019-08-16 15:40:59 +02:00
|
|
|
|
2014-02-13 00:21:28 +01:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
|
|
|
# error Mountpoints are disabled (CONFIG_DISABLE_MOUNTPOINT=y)
|
|
|
|
#endif
|
|
|
|
|
2018-07-22 23:54:12 +02:00
|
|
|
#ifndef SAMD2L2_HAVE_SPI0
|
2014-02-13 01:29:23 +01:00
|
|
|
# error SERCOM0 SPI support is required
|
2014-02-13 00:21:28 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_MMCSD
|
|
|
|
# error MMC/SD support is required (CONFIG_MMCSD)
|
|
|
|
#endif
|
|
|
|
|
2018-07-22 23:54:12 +02:00
|
|
|
#define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
|
2014-02-13 00:21:28 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sam_sdinitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the SPI-based SD card. Requires
|
2014-02-20 18:27:59 +01:00
|
|
|
* - CONFIG_SAMD20_XPLAINED_IOMODULE=y,
|
2014-02-13 00:21:28 +01:00
|
|
|
* - CONFIG_DISABLE_MOUNTPOINT=n,
|
|
|
|
* - CONFIG_MMCSD=y, and
|
2019-08-16 15:40:59 +02:00
|
|
|
* - SAMD2L2_HAVE_SPI0=y
|
|
|
|
* (CONFIG_SAMD2L2_SERCOM0 && CONFIG_SAMD2L2_SERCOM0_ISSPI)
|
2014-02-13 00:21:28 +01:00
|
|
|
*
|
2015-10-03 15:25:23 +02:00
|
|
|
****************************************************************************/
|
2014-02-13 00:21:28 +01:00
|
|
|
|
2014-02-20 18:27:59 +01:00
|
|
|
int sam_sdinitialize(int port, int minor)
|
2014-02-13 00:21:28 +01:00
|
|
|
{
|
|
|
|
FAR struct spi_dev_s *spi;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get the SPI driver instance for the SD chip select */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Initializing SERCOM SPI%d\n", port);
|
2014-02-13 00:21:28 +01:00
|
|
|
|
2016-01-26 20:03:12 +01:00
|
|
|
spi = sam_spibus_initialize(port);
|
2014-02-13 00:21:28 +01:00
|
|
|
if (!spi)
|
|
|
|
{
|
2016-06-13 15:43:55 +02:00
|
|
|
ferr("ERROR: Failed to initialize SPI%d\n", port);
|
2014-02-13 00:21:28 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Successfully initialized SPI%d\n", port);
|
2014-02-13 00:21:28 +01:00
|
|
|
|
|
|
|
/* Bind the SPI device for the chip select to the slot */
|
|
|
|
|
2018-07-22 23:54:12 +02:00
|
|
|
finfo("Binding SPI%d to MMC/SD slot %d\n", port, SAMD2L2_MMCSDSLOTNO);
|
2014-02-13 00:21:28 +01:00
|
|
|
|
2018-07-22 23:54:12 +02:00
|
|
|
ret = mmcsd_spislotinitialize(minor, SAMD2L2_MMCSDSLOTNO, spi);
|
2014-02-13 00:21:28 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-13 15:43:55 +02:00
|
|
|
ferr("ERROR: Failed to bind SPI%d to MMC/SD slot %d: %d\n",
|
2018-07-22 23:54:12 +02:00
|
|
|
port, SAMD2L2_MMCSDSLOTNO, ret);
|
2014-02-13 00:21:28 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-02-22 19:31:14 +01:00
|
|
|
finfo("Successfully bound SPI%d to MMC/SD slot %d\n",
|
2018-07-22 23:54:12 +02:00
|
|
|
port, SAMD2L2_MMCSDSLOTNO);
|
2014-02-13 00:21:28 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:27:59 +01:00
|
|
|
#endif /* CONFIG_SAMD20_XPLAINED_IOMODULE */
|