Add support for SPI through i.MX8MP ecspi module.

Configure SPI for Verdin evaluation board
This commit is contained in:
Philippe Leduc
2023-09-21 08:26:32 +02:00
committed by Alan Carvalho de Assis
parent 21beb284bc
commit f38cdb09b4
13 changed files with 1310 additions and 3 deletions
+39
View File
@@ -84,6 +84,45 @@ if MX8MP_I2C
in any real driver application.
endif # MX8MP_I2C
#####################################################################
# SPI Configuration (Master)
#####################################################################
config MX8MP_SPI
bool "SPI Master"
select SPI
---help---
Build in support for SPI master mode.
if MX8MP_SPI
config MX8MP_SPI1
bool "SPI1"
default n
select SPI
config MX8MP_SPI2
bool "SPI2"
default n
select SPI
config MX8MP_SPI3
bool "SPI3"
default n
select SPI
config MX8MP_SPI_DRIVER
bool "SPI character driver"
default n
select SPI_DRIVER
---help---
Build in support for a character driver at /dev/spi[N] that may b
used to perform SPI bus transfers from applications. The intent of
this driver is to support SPI testing.
endif # MX8MP_SPI
endmenu
# These "hidden" settings determine whether a peripheral option is available
+4
View File
@@ -39,3 +39,7 @@ endif
ifeq ($(CONFIG_I2C),y)
CHIP_CSRCS += mx8mp_i2c.c
endif
ifeq ($(CONFIG_SPI),y)
CHIP_CSRCS += mx8mp_ecspi.c
endif
+102
View File
@@ -0,0 +1,102 @@
/****************************************************************************
* arch/arm/src/mx8mp/hardware/mx8mp_ecspi.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_ARM_SRC_MX8MP_HARDWARE_MX8MP_ECSPI_H
#define __ARCH_ARM_SRC_MX8MP_HARDWARE_MX8MP_ECSPI_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* ECSPI Register Offsets ***************************************************/
#define RXDATA_OFFSET 0x0000
#define TXDATA_OFFSET 0x0004
#define CONREG_OFFSET 0x0008
#define CONFIGREG_OFFSET 0x000c
#define INTREG_OFFSET 0x0010
#define DMAREG_OFFSET 0x0014
#define STATREG_OFFSET 0x0018
#define PERIODREG_OFFSET 0x001C
#define TESTREG_OFFSET 0x0020
#define MSGDATA_OFFSET 0x0040
/* ECSPI Register Bit Definitions *******************************************/
#define CONREG_BURST_LENGTH (20)
#define CONREG_CHANNEL_SELECT (18)
#define CONREG_PRE_DIVIDER (12)
#define CONREG_POST_DIVIDER (8)
#define CONREG_CHANNEL_MODE (4)
#define CONREG_SMC (1 << 3)
#define CONREG_XCH (1 << 2)
#define CONREG_HT (1 << 1)
#define CONREG_EN (1 << 0)
#define CONFIGREG_HT_LENGTH (24)
#define CONFIGREG_SLCK_CTL (20)
#define CONFIGREG_DATA_CTL (16)
#define CONFIGREG_SS_POL (12)
#define CONFIGREG_SS_CTL (8)
#define CONFIGREG_SCLK_POL (4)
#define CONFIGREG_SCLK_PHA (0)
#define INTREG_TCEN (1 << 7)
#define INTREG_ROEN (1 << 6)
#define INTREG_RFEN (1 << 5)
#define INTREG_RDREN (1 << 4)
#define INTREG_RREN (1 << 3)
#define INTREG_TFEN (1 << 2)
#define INTREG_TDREN (1 << 1)
#define INTREG_TEEN (1 << 0)
#define DMAREG_RXTDEN (1 << 31)
#define DMAREG_RX_DMA_LENGTH (24)
#define DMAREG_RXDEN (1 << 23)
#define DMAREG_RX_THRESHOLD (16)
#define DMAREG_TEDEN (1 << 7)
#define DMAREG_TX_THRESHOLD (0)
#define STATREG_TC (1 << 7)
#define STATREG_RO (1 << 6)
#define STATREG_RF (1 << 5)
#define STATREG_RDR (1 << 4)
#define STATREG_RR (1 << 3)
#define STATREG_TF (1 << 2)
#define STATREG_TDR (1 << 1)
#define STATREG_TE (1 << 0)
#define PERIODREG_CSD_CTL (16)
#define PERIODREG_CSRC (1 << 15)
#define PERIODREG_SAMPLE_PERIOD (0)
#define TESTREG_LBC (1 << 31)
#define TESTREG_RXCNT (8)
#define TESTREG_TXCNT (0)
/****************************************************************************
* Inline Functions
****************************************************************************/
#endif /* __ARCH_ARM_SRC_MX8MP_HARDWARE_MX8MP_ECSPI_H */
@@ -924,5 +924,6 @@
#define GPIO_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE | PAD_CTL_DSE2)
#define UART_PAD_CTRL (PAD_CTL_PUE | PAD_CTL_PE)
#define SPI_PAD_CTRL (PAD_CTL_PUE)
#endif /* __ARCH_ARM_SRC_MX8MP_HARDWARE_MX8MP_PINMUX_H */
File diff suppressed because it is too large Load Diff
+114
View File
@@ -0,0 +1,114 @@
/****************************************************************************
* arch/arm/src/mx8mp/mx8mp_ecspi.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_ARM_SRC_MX8MP_MX8MP_ECSPI_H
#define __ARCH_ARM_SRC_MX8MP_MX8MP_ECSPI_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Data
****************************************************************************/
struct spi_dev_s;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: mx8mp_spibus_initialize
*
* Description:
* Initialize the selected SPI bus
*
* Input Parameters:
* bus 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 *mx8mp_spibus_initialize(int bus);
/****************************************************************************
* Name:
* mx8mp_spi[n]select, mx8mp_spi[n]status, and mx8mp_spi[n]cmddata
*
* Description:
* These external functions must be provided by board-specific logic.
* They are implementations of the select, status, and cmddata methods of
* the SPI interface defined by struct spi_ops_s
* (see include/nuttx/spi/spi.h). All other methods including
* mx8mp_spibus_initialize()) are provided by common Kinetis logic.
* To use this common SPI logic on your board:
*
* 1. Provide logic in mx8mp_boardinitialize() to configure SPI chip
* select pins.
* 2. Provide mx8mp_spi[n]select() and mx8mp_spi[n]status() functions
* in your board-specific logic. These functions will perform chip
* selection and status operations using GPIOs in the way your board is
* configured.
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
* mx8mp_spi[n]cmddata() functions in your board-specific logic.
* These functions will perform cmd/data selection operations using
* GPIOs in the way your board is configured.
* 3. Add a call to mx8mp_spibus_initialize() in your low level
* application initialization logic
* 4. The handle returned by mx8mp_spibus_initialize() may then be used
* to bind the SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
****************************************************************************/
#ifdef CONFIG_MX8MP_SPI1
void mx8mp_spi1_select(struct spi_dev_s *dev,
uint32_t devid, bool selected);
uint8_t mx8mp_spi1_status(struct spi_dev_s *dev, uint32_t devid);
#ifdef CONFIG_SPI_CMDDATA
int mx8mp_spi1_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd);
#endif
#endif
#ifdef CONFIG_MX8MP_SPI2
void mx8mp_spi2_select(struct spi_dev_s *dev,
uint32_t devid, bool selected);
uint8_t mx8mp_spi2_status(struct spi_dev_s *dev, uint32_t devid);
#ifdef CONFIG_SPI_CMDDATA
int mx8mp_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd);
#endif
#endif
#ifdef CONFIG_MX8MP_SPI3
void mx8mp_spi3_select(struct spi_dev_s *dev,
uint32_t devid, bool selected);
uint8_t mx8mp_spi3_status(struct spi_dev_s *dev, uint32_t devid);
#ifdef CONFIG_SPI_CMDDATA
int mx8mp_spi3_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd);
#endif
#endif
#endif /* __ARCH_ARM_SRC_MX8MP_MX8MP_ECSPI_H */
+2 -1
View File
@@ -22,12 +22,13 @@
* Included Files
****************************************************************************/
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/signal.h>
#include <nuttx/i2c/i2c_master.h>
#include "mx8mp_i2c.h"
#include "mx8mp_ccm.h"
#include "hardware/mx8mp_memorymap.h"
#include "hardware/mx8mp_i2c.h"
#include <debug.h>
#include "arm_internal.h"
+6 -2
View File
@@ -26,8 +26,12 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/i2c/i2c_master.h>
#include "hardware/mx8mp_i2c.h"
/****************************************************************************
* Public Data
****************************************************************************/
struct i2c_master_s;
/****************************************************************************
* Public Function Prototypes
@@ -34,6 +34,14 @@ ifeq ($(CONFIG_MX8MP_I2C_DRIVER),y)
CSRCS += mx8mp_i2cdev.c
endif
ifeq ($(CONFIG_SPI),y)
CSRCS += mx8mp_spi.c
endif
ifeq ($(CONFIG_MX8MP_SPI_DRIVER),y)
CSRCS += mx8mp_spidev.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += mx8mp_autoleds.c
else
@@ -115,5 +115,15 @@ int mx8mp_bringup(void)
}
#endif
#ifdef CONFIG_MX8MP_SPI_DRIVER
/* Initialize SPI buses */
ret = mx8mp_spidev_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: spidev_initialize() failed: %d\n", ret);
}
#endif
return ret;
}
@@ -0,0 +1,122 @@
/****************************************************************************
* boards/arm/mx8mp/verdin-mx8mp/src/mx8mp_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 <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/spi/spi.h>
#include "arm_internal.h"
#include "chip.h"
#include "mx8mp_gpio.h"
#include <arch/board/board.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mx8mp_spi1/2/3select and mx8mp_spi1/2/3status
*
* Description:
* The external functions, mx8mp_spi1/2/3select and mx8mp_spi1/2/3status
* must be provided by board-specific logic.
* They are implementations of the select and status methods of the SPI
* interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h).
*
****************************************************************************/
#ifdef CONFIG_MX8MP_SPI1
void mx8mp_spi1_select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid,
selected ? "assert" : "de-assert");
/* nothing to do : CS handled by module */
}
uint8_t mx8mp_spi1_status(struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#ifdef CONFIG_SPI_CMDDATA
int mx8mp_spi1_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return -ENODEV;
}
#endif
#endif
#ifdef CONFIG_MX8MP_SPI2
void mx8mp_spi2_select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid,
selected ? "assert" : "de-assert");
mx8mp_gpio_write(GPIO_SPI2_CS, !selected);
}
uint8_t mx8mp_spi2_status(struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#ifdef CONFIG_SPI_CMDDATA
int mx8mp_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return -ENODEV;
}
#endif
#endif
#ifdef CONFIG_MX8MP_SPI3
void mx8mp_spi3_select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid,
selected ? "assert" : "de-assert");
mx8mp_gpio_write(GPIO_SPI3_CS, !selected);
}
uint8_t mx8mp_spi3_status(struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#ifdef CONFIG_SPI_CMDDATA
int mx8mp_spi3_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return -ENODEV;
}
#endif
#endif
@@ -0,0 +1,138 @@
/****************************************************************************
* boards/arm/mx8mp/verdin-mx8mp/src/mx8mp_spidev.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 <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/spi/spi_transfer.h>
#include "arm_internal.h"
#include "chip.h"
#include "mx8mp_ecspi.h"
#include "verdin-mx8mp.h"
#include <arch/board/board.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: board_spidev_initialize
*
* Description:
* Initialize and register spi driver for the specified spi port
*
****************************************************************************/
int board_spidev_initialize(int port)
{
int ret;
struct spi_dev_s *spi;
spiinfo("Initializing /dev/spi%d..\n", port);
/* Initialize spi device */
spi = mx8mp_spibus_initialize(port);
if (!spi)
{
i2cerr("ERROR: Failed to initialize spi%d.\n", port);
return -ENODEV;
}
ret = spi_register(spi, port);
if (ret < 0)
{
i2cerr("ERROR: Failed to register spi%d: %d\n", port, ret);
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mx8mp_spidev_initialize
*
* Description:
* Called to configure all spi drivers
*
****************************************************************************/
int mx8mp_spidev_initialize(void)
{
int ret = 0;
#ifdef CONFIG_MX8MP_SPI1
mx8mp_iomuxc_config(IOMUX_SPI1_MISO);
mx8mp_iomuxc_config(IOMUX_SPI1_MOSI);
mx8mp_iomuxc_config(IOMUX_SPI1_CLK);
mx8mp_iomuxc_config(IOMUX_SPI1_CS);
ret = board_spidev_initialize(1);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C1.\n");
return ret;
}
#endif
#ifdef CONFIG_MX8MP_SPI2
mx8mp_iomuxc_config(IOMUXC_SPI2_MISO);
mx8mp_iomuxc_config(IOMUXC_SPI2_MOSI);
mx8mp_iomuxc_config(IOMUXC_SPI2_CLK);
mx8mp_iomuxc_config(IOMUXC_SPI2_CS);
mx8mp_gpio_config(GPIO_SPI2_CS);
ret = board_spidev_initialize(2);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C2.\n");
return ret;
}
#endif
#ifdef CONFIG_MX8MP_SPI3
mx8mp_iomuxc_config(IOMUXC_SPI3_MISO);
mx8mp_iomuxc_config(IOMUXC_SPI3_MOSI);
mx8mp_iomuxc_config(IOMUXC_SPI3_CLK);
mx8mp_iomuxc_config(IOMUXC_SPI3_CS);
mx8mp_gpio_config(GPIO_SPI3_CS);
ret = board_spidev_initialize(3);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C3.\n");
return ret;
}
#endif
return ret;
}
@@ -51,6 +51,13 @@
#define BUTTON_1_IRQ MX8MP_IRQ_SOFT_GPIO1_7
#define BUTTON_1_IOMUX IOMUXC_GPIO1_IO07_GPIO1_IO07, 0, GPIO_PAD_CTRL
/* SPIs */
#define IOMUX_SPI1_CLK IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK, 0, SPI_PAD_CTRL
#define IOMUX_SPI1_MOSI IOMUXC_ECSPI1_MISO_ECSPI1_MISO, 0, SPI_PAD_CTRL
#define IOMUX_SPI1_MISO IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI, 0, SPI_PAD_CTRL
#define IOMUX_SPI1_CS IOMUXC_ECSPI1_SS0_ECSPI1_SS0, 0, SPI_PAD_CTRL
/****************************************************************************
* Public Types
****************************************************************************/
@@ -85,5 +92,15 @@ int mx8mp_bringup(void);
int mx8mp_i2cdev_initialize(void);
/****************************************************************************
* Name: mx8mp_spidev_initialize
*
* Description:
* Called to configure all spi
*
****************************************************************************/
int mx8mp_spidev_initialize(void);
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_MX8MP_MX8MP_VERDIN_SRC_VERDIN_MX8MP_H */