Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:42

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup raspberrypi_4_spi
0007  *
0008  * @brief Raspberry Pi specific SPI definitions.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2024 Ning Yang
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifndef LIBBSP_AARCH64_RASPBERRYPI_4_SPI_H
0037 #define LIBBSP_AARCH64_RASPBERRYPI_4_SPI_H
0038 
0039 #include <bsp/utility.h>
0040 #include <bsp/rpi-gpio.h>
0041 
0042 typedef struct 
0043 {
0044   uint32_t spics;
0045 #define RPI_SPICS_LEN_LONG             BSP_BIT32(25)
0046 #define RPI_SPICS_DMA_LEN              BSP_BIT32(24)
0047 #define RPI_SPICS_CSPOL2               BSP_BIT32(23)
0048 #define RPI_SPICS_CSPOL1               BSP_BIT32(22)
0049 #define RPI_SPICS_CSPOL0               BSP_BIT32(21)
0050 #define RPI_SPICS_RXF                  BSP_BIT32(20)
0051 #define RPI_SPICS_RXR                  BSP_BIT32(19)
0052 #define RPI_SPICS_TXD                  BSP_BIT32(18)
0053 #define RPI_SPICS_RXD                  BSP_BIT32(17)
0054 #define RPI_SPICS_DONE                 BSP_BIT32(16)
0055 #define RPI_SPICS_LEN                  BSP_BIT32(13)
0056 #define RPI_SPICS_REN                  BSP_BIT32(12)
0057 #define RPI_SPICS_ADCS                 BSP_BIT32(11)
0058 #define RPI_SPICS_INTR                 BSP_BIT32(10)
0059 #define RPI_SPICS_INTD                 BSP_BIT32(9)
0060 #define RPI_SPICS_DMAEN                BSP_BIT32(8)
0061 #define RPI_SPICS_TA                   BSP_BIT32(7)
0062 #define RPI_SPICS_CSPOL                BSP_BIT32(6)
0063 #define RPI_SPICS_CLEAR_TX             BSP_BIT32(5)
0064 #define RPI_SPICS_CLEAR_RX             BSP_BIT32(4)
0065 #define RPI_SPICS_CPOL                 BSP_BIT32(3)
0066 #define RPI_SPICS_CPHA                 BSP_BIT32(2)
0067 #define RPI_SPICS_CS(val)              BSP_FLD32(val, 0, 1)
0068 #define RPI_SPICS_CS_SET(reg,val)      BSP_FLD32SET(reg, val, 0, 1)
0069   uint32_t spififo;
0070 #define RPI_SPIFIFO_DATA(val)          BSP_FLD32(val, 0, 31)
0071 #define RPI_SPIFIFO_DATA_GET(reg)      BSP_FLD32GET(reg, 0, 31)
0072 #define RPI_SPIFIFO_DATA_SET(reg, val) BSP_FLD32SET(reg, val, 0, 31)
0073   uint32_t spiclk;
0074 #define RPI_SPICLK_CDIV(val)           BSP_FLD32(val, 0, 15)
0075 #define RPI_SPICLK_CDIV_GET(reg)       BSP_FLD32GET(reg, 0, 15)
0076 #define RPI_SPICLK_CDIV_SET(reg, val)  BSP_FLD32SET(reg, val, 0, 15)
0077   uint32_t spidlen;
0078 #define RPI_SPIDLEN_LEN(val)           BSP_FLD32(val, 0, 15)
0079 #define RPI_SPIDLEN_LEN_GET(reg)       BSP_FLD32GET(reg, 0, 15)
0080 #define RPI_SPIDLEN_LEN_SET(reg, val)  BSP_FLD32SET(reg, val, 0, 15)
0081   uint32_t spiltoh;
0082 #define RPI_SPILTOH_TOH(val)           BSP_FLD32(val, 0, 3)
0083 #define RPI_SPILTOH_TOH_GET(reg)       BSP_FLD32GET(reg, 0, 3)
0084 #define RPI_SPILTOH_TOH_SET(reg, val)  BSP_FLD32SET(reg, val, 0, 3)
0085   uint32_t spidc;
0086 #define RPI_SPIDC_RPANIC(val)          BSP_FLD32(val, 24, 31)
0087 #define RPI_SPIDC_RPANIC_GET(reg)      BSP_FLD32GET(reg, 24, 31)
0088 #define RPI_SPIDC_RPANIC_SET(reg, val) BSP_FLD32SET(reg, val, 24, 31)
0089 #define RPI_SPIDC_RDREQ(val)           BSP_FLD32(val, 16, 23)
0090 #define RPI_SPIDC_RDREQ_GET(reg)       BSP_FLD32GET(reg, 16, 23)
0091 #define RPI_SPIDC_RDREQ_SET(reg, val)  BSP_FLD32SET(reg, val, 16, 23)
0092 #define RPI_SPIDC_TPANIC(val)          BSP_FLD32(val, 8, 15)
0093 #define RPI_SPIDC_TPANIC_GET(reg)      BSP_FLD32GET(reg, 8, 15)
0094 #define RPI_SPIDC_TPANIC_SET(reg, val) BSP_FLD32SET(reg, val, 8, 15)
0095 #define RPI_SPIDC_TDREQ(val)           BSP_FLD32(val, 0, 7)
0096 #define RPI_SPIDC_TDREQ_GET(reg)       BSP_FLD32GET(reg, 0, 7)
0097 #define RPI_SPIDC_TDREQ_SET(reg, val)  BSP_FLD32SET(reg, val, 0, 7)
0098 } raspberrypi_spi;
0099 
0100 typedef enum {
0101   raspberrypi_SPI0,
0102   raspberrypi_SPI3,
0103   raspberrypi_SPI4,
0104   raspberrypi_SPI5,
0105   raspberrypi_SPI6
0106 } raspberrypi_spi_device;
0107 
0108 /**
0109  * @brief Register a spi device.
0110  *
0111  * @param device The optional devices are raspberrypi_SPI0, raspberrypi_SPI3,
0112  *               raspberrypi_SPI4, raspberrypi_SPI5, raspberrypi_SPI6.
0113  *
0114  * @retval RTEMS_SUCCESSFUL Successfully registered SPI device.
0115  * @retval RTEMS_INVALID_NUMBER This status code indicates that a specified
0116  *         number was invalid.
0117  * @retval RTEMS_UNSATISFIED This status code indicates that the request was
0118  *         not satisfied.
0119  */
0120 rtems_status_code raspberrypi_spi_init(raspberrypi_spi_device device);
0121 
0122 #endif /* LIBBSP_AARCH64_RASPBERRYPI_4_SPI_H */