mpfs: add spi driver

This adds the SPI driver for the MPFS Icicle board.

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
This commit is contained in:
Eero Nurkkala 2021-06-01 12:30:28 +03:00 committed by Xiang Xiao
parent 96bcf7678b
commit fad34e04c4
10 changed files with 1862 additions and 2 deletions

View File

@ -57,7 +57,7 @@ Peripheral Support NOTES
============ ======= =====
GPIO Yes
MMUART Yes Uart mode only
SPI No
SPI Yes
I2C No
Timers No
Watchdog No
@ -79,4 +79,4 @@ Supported Boards
boards/*/*

View File

@ -50,6 +50,14 @@ config MPFS_HAVE_UART4
# These are the peripheral selections proper
config MPFS_SPI0
bool "SPI 0"
default n
config MPFS_SPI1
bool "SPI 1"
default n
config MPFS_UART0
bool "UART 0"
default n

View File

@ -61,3 +61,7 @@ CMN_UASRCS += riscv_signal_handler.S
CHIP_CSRCS += mpfs_userspace.c
endif
ifeq ($(CONFIG_SPI),y)
CHIP_CSRCS += mpfs_spi.c
endif

View File

@ -0,0 +1,129 @@
/****************************************************************************
* arch/risc-v/src/mpfs/hardware/mpfs_spi.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 __ARCH_RISCV_SRC_MPFS_HARDWARE_MPFS_SPI_H
#define __ARCH_RISCV_SRC_MPFS_HARDWARE_MPFS_SPI_H
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* CONTROL register */
#define MPFS_SPI_RESET (1 << 31)
#define MPFS_SPI_OENOFF (1 << 30)
#define MPFS_SPI_BIGFIFO (1 << 29)
#define MPFS_SPI_CLKMODE (1 << 28)
#define MPFS_SPI_FRAMEURUN (1 << 27)
#define MPFS_SPI_SPS (1 << 26)
#define MPFS_SPI_SPH (1 << 25)
#define MPFS_SPI_SPO (1 << 24)
#define MPFS_SPI_FRAMECNT (0xffff << 8)
#define MPFS_SPI_INTTXTURUN (1 << 7)
#define MPFS_SPI_INTRXOVRFLOW (1 << 6)
#define MPFS_SPI_INTTXDATA (1 << 5)
#define MPFS_SPI_INTRXDATA (1 << 4)
#define MPFS_SPI_TRANSFPRTL (1 << 2) | (1 << 3)
#define MPFS_SPI_MODE (1 << 1)
#define MPFS_SPI_ENABLE (1 << 0)
/* FRAMESIZE register */
#define MPFS_SPI_FRAMESIZE (0x3F)
/* STATUS register */
#define MPFS_SPI_ACTIVE (1 << 14)
#define MPFS_SPI_SSEL (1 << 13)
#define MPFS_SPI_FRAMESTART (1 << 12)
#define MPFS_SPI_TXFIFOEMPNXT (1 << 11)
#define MPFS_SPI_TXFIFOEMP (1 << 10)
#define MPFS_SPI_TXFIFOFULNXT (1 << 9)
#define MPFS_SPI_TXFIFOFUL (1 << 8)
#define MPFS_SPI_RXFIFOEMPNXT (1 << 7)
#define MPFS_SPI_RXFIFOEMP (1 << 6)
#define MPFS_SPI_RXFIFOFULNXT (1 << 5)
#define MPFS_SPI_RXFIFOFUL (1 << 4)
#define MPFS_SPI_TXUNDERRUN (1 << 3)
#define MPFS_SPI_RXOVERFLOW (1 << 2)
#define MPFS_SPI_RXDATRCED (1 << 1)
#define MPFS_SPI_TXDATSENT (1 << 0)
/* INT_CLEAR register */
#define MPFS_SPI_SSEND (1 << 5)
#define MPFS_SPI_CMDINT (1 << 4)
#define MPFS_SPI_TXCHUNDRUN (1 << 3)
#define MPFS_SPI_RXCHOVRFLW (1 << 2)
#define MPFS_SPI_RXRDONECLR (1 << 1)
#define MPFS_SPI_TXDONECLR (1 << 0)
/* INTMASK register */
#define MPFS_SPI_SSENDMSKINT (1 << 5)
#define MPFS_SPI_CMDMSKINT (1 << 4)
#define MPFS_SPI_TXCHUNDDMSKINT (1 << 3)
#define MPFS_SPI_RXCHOVRFMSKINT (1 << 2)
#define MPFS_SPI_RXRDYMSKINT (1 << 1)
#define MPFS_SPI_TXDONEMSKINT (1 << 0)
/* INTRAW register */
#define MPFS_SPI_TXCHUNDR (1 << 3)
#define MPFS_SPI_RXOVRFLW (1 << 2)
#define MPFS_SPI_RXRDY (1 << 1)
#define MPFS_SPI_TXDONE (1 << 0)
/* CONTROL2 register */
#define MPFS_SPI_INTEN_SSEND (1 << 5)
#define MPFS_SPI_INTEN_CMD (1 << 4)
#define MPFS_SPI_DISFRMCNT (1 << 2)
#define MPFS_SPI_AUTOPOLL (1 << 1)
#define MPFS_SPI_AUTOSTATUS (1 << 0)
/* COMMAND register */
#define MPFS_SPI_TXNOW (1 << 6)
#define MPFS_SPI_AUTOSTALL (1 << 5)
#define MPFS_SPI_CLRFRAMECNT (1 << 4)
#define MPFS_SPI_TXFIFORST (1 << 3)
#define MPFS_SPI_RXFIFORST (1 << 2)
#define MPFS_SPI_AUTOEMPTY (1 << 1)
#define MPFS_SPI_AUTOFILL (1 << 0)
/* HWSTATUS register */
#define MPFS_SPI_USER (1 << 2) | (1 << 3)
#define MPFS_SPI_TXBUSY (1 << 1)
#define MPFS_SPI_RXBUSY (1 << 0)
/* STAT8 register */
#define MPFS_SPI_S8_ACTIVEL (1 << 6)
#define MPFS_SPI_S8_SSEL (1 << 6)
#define MPFS_SPI_S8_TXUNDERRUN (1 << 5)
#define MPFS_SPI_S8_RXOVERFLOW (1 << 4)
#define MPFS_SPI_S8_TXFIFOFUL (1 << 3)
#define MPFS_SPI_S8_RXFIFOEMP (1 << 2)
#define MPFS_SPI_S8_DONE (1 << 1)
#define MPFS_SPI_S8_FRAMESTART (1 << 0)
#endif /* __ARCH_RISCV_SRC_MPFS_HARDWARE_MPFS_SPI_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,84 @@
/****************************************************************************
* arch/risc-v/src/mpfs/mpfs_spi.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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_MPFS_MPFS_SPI_H
#define __ARCH_RISCV_SRC_MPFS_MPFS_SPI_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#include <nuttx/spi/spi.h>
#include <nuttx/spi/spi_transfer.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: mpfs_spibus_initialize
*
* Description:
* Initialize the selected SPI bus
*
* Input Parameters:
* Port number (for hardware that has multiple SPI interfaces)
*
* Returned Value:
* Valid SPI device structure reference on success; a NULL on failure
*
****************************************************************************/
struct spi_dev_s *mpfs_spibus_initialize(int port);
/****************************************************************************
* Name: mpfs_spibus_uninitialize
*
* Description:
* Uninitialize an SPI bus
*
****************************************************************************/
int mpfs_spibus_uninitialize(FAR struct spi_dev_s *dev);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_RISCV_SRC_MPFS_MPFS_SPI_H */

View File

@ -34,4 +34,8 @@ ifeq ($(CONFIG_ARCH_FPU),y)
CSRCS += mpfs_ostest.c
endif
ifeq ($(CONFIG_SPI),y)
CSRCS += mpfs_board_spi.c
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -0,0 +1,99 @@
/****************************************************************************
* boards/risc-v/mpfs/icicle/src/mpfs_board_spi.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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include <nuttx/spi/spi_transfer.h>
#include "mpfs_spi.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_spi_initialize
*
* Description:
* Initialize and register SPI driver for the defined SPI ports.
*
****************************************************************************/
int mpfs_board_spi_init(void)
{
int ret = OK;
#if defined(CONFIG_MPFS_SPI0) || defined(CONFIG_MPFS_SPI1)
struct spi_dev_s *spi;
#ifdef CONFIG_SPI_DRIVER
int port = 0;
#endif /* CONFIG_SPI_DRIVER */
#endif
/* Initialize SPI device */
#ifdef CONFIG_MPFS_SPI0
spi = mpfs_spibus_initialize(0);
if (spi == NULL)
{
spierr("Failed to initialize SPI0\n");
return -ENODEV;
}
#ifdef CONFIG_SPI_DRIVER
ret = spi_register(spi, port++);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to register /dev/spi0: %d\n", ret);
mpfs_spibus_uninitialize(spi);
}
#endif /* CONFIG_SPI_DRIVER */
#endif /* CONFIG_MPFS_SPI0 */
#ifdef CONFIG_MPFS_SPI1
spi = mpfs_spibus_initialize(1);
if (spi == NULL)
{
spierr("Failed to initialize SPI1\n");
return -ENODEV;
}
#ifdef CONFIG_SPI_DRIVER
ret = spi_register(spi, port);
if (ret < 0)
{
spierr("Failed to register /dev/spi%d: %d\n", port, ret);
mpfs_spibus_uninitialize(spi);
}
#endif /* CONFIG_SPI_DRIVER */
#endif /* CONFIG_MPFS_SPI1 */
return ret;
}

View File

@ -33,6 +33,7 @@
#include <nuttx/board.h>
#include <nuttx/drivers/ramdisk.h>
#include "mpfsicicle.h"
#include "mpfs.h"
/****************************************************************************
@ -57,5 +58,16 @@ int mpfs_bringup(void)
}
#endif
#if defined(CONFIG_MPFS_SPI0) || defined(CONFIG_MPFS_SPI1)
/* Configure SPI peripheral interfaces */
ret = mpfs_board_spi_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize SPI driver: %d\n", ret);
}
#endif
return ret;
}

View File

@ -42,5 +42,6 @@
#define ICICLE_GPIO_BUTTON3_ALT (GPIO_BANK2 | GPIO_PIN27 | GPIO_OUTPUT)
int mpfs_bringup(void);
int mpfs_board_spi_init(void);
#endif /* __BOARDS_RISCV_ICICLE_MPFS_SRC_MPFSICICLE_H */