Back to home page

LXR

 
 

    


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

0001 /**
0002  * @file
0003  *
0004  * @ingroup arm_beagle
0005  *
0006  * @brief SPI support API.
0007  *
0008  * Based on bsps/m68k/gen68360/spi/m360_spi.h
0009  */
0010 
0011 /*
0012  * Copyright (c) 2018 Pierre-Louis Garnier <garnie_a@epita.fr>
0013  *
0014  * The license and distribution terms for this file may be
0015  * found in the file LICENSE in this distribution or at
0016  * http://www.rtems.org/license/LICENSE.
0017  */
0018 
0019 #ifndef LIBBSP_ARM_BEAGLE_SPI_H
0020 #define LIBBSP_ARM_BEAGLE_SPI_H
0021 
0022 #include <bsp.h>
0023 #include <rtems/libi2c.h>
0024 #include <rtems/irq.h>
0025 
0026 #ifdef __cplusplus
0027 extern "C" {
0028 #endif /* __cplusplus */
0029 
0030 #define BBB_SPI_TIMEOUT 1000
0031 
0032 #define BBB_SPI_0_BUS_PATH "/dev/spi-0"
0033 
0034 #define BBB_SPI_0_IRQ AM335X_INT_SPI0INT
0035 
0036 typedef enum {
0037   SPI0,
0038   SPI1,
0039   SPI_COUNT
0040 } bbb_spi_id_t;
0041 
0042 
0043 
0044 typedef struct BEAGLE_SPI_BufferDescriptor_ {
0045     unsigned short      status;
0046     unsigned short      length;
0047     volatile void       *buffer;
0048 } BEAGLE_SPI_BufferDescriptor_t;
0049 
0050 typedef struct beagle_spi_softc {
0051   int                     initialized;
0052   rtems_id                task_id;
0053   uintptr_t               regs_base;
0054   rtems_vector_number     irq;
0055 } beagle_spi_softc_t;
0056 
0057 typedef struct {
0058   rtems_libi2c_bus_t  bus_desc;
0059   beagle_spi_softc_t softc;
0060 } beagle_spi_desc_t;
0061 
0062 /*
0063  * Initialize the driver
0064  *
0065  * Returns: o = ok or error code
0066  */
0067 rtems_status_code beagle_spi_init
0068 (
0069  rtems_libi2c_bus_t *bh                  /* bus specifier structure        */
0070 );
0071 
0072 /*
0073  * Receive some bytes from SPI device
0074  *
0075  * Returns: number of bytes received or (negative) error code
0076  */
0077 int beagle_spi_read_bytes
0078 (
0079  rtems_libi2c_bus_t *bh,                 /* bus specifier structure        */
0080  unsigned char *buf,                     /* buffer to store bytes          */
0081  int len                                 /* number of bytes to receive     */
0082 );
0083 
0084 /*
0085  * Send some bytes to SPI device
0086  *
0087  * Returns: number of bytes sent or (negative) error code
0088  */
0089 int beagle_spi_write_bytes
0090 (
0091  rtems_libi2c_bus_t *bh,                 /* bus specifier structure        */
0092  unsigned char *buf,                     /* buffer to send                 */
0093  int len                                 /* number of bytes to send        */
0094 );
0095 
0096 /*
0097  * Set SPI to desired baudrate/clock mode/character mode
0098  *
0099  * Returns: rtems_status_code
0100  */
0101 rtems_status_code beagle_spi_set_tfr_mode
0102 (
0103  rtems_libi2c_bus_t *bh,                 /* bus specifier structure        */
0104  const rtems_libi2c_tfr_mode_t *tfr_mode /* transfer mode info             */
0105 );
0106 
0107 /*
0108  * Perform selected ioctl function for SPI
0109  *
0110  * Returns: rtems_status_code
0111  */
0112 int beagle_spi_ioctl
0113 (
0114  rtems_libi2c_bus_t *bh,                 /* bus specifier structure        */
0115  int                 cmd,                /* ioctl command code             */
0116  void               *arg                 /* additional argument array      */
0117 );
0118 
0119 /*
0120  * Register SPI bus and devices
0121  *
0122  * Returns: Bus number or error code
0123  */
0124 rtems_status_code bsp_register_spi
0125 (
0126   const char         *bus_path,
0127   uintptr_t           register_base,
0128   rtems_vector_number irq
0129 );
0130 
0131 static inline rtems_status_code bbb_register_spi_0(void)
0132 {
0133   return bsp_register_spi(
0134     BBB_SPI_0_BUS_PATH,
0135     AM335X_SPI0_BASE,
0136     BBB_SPI_0_IRQ
0137   );
0138 }
0139 
0140 #ifdef __cplusplus
0141 }
0142 #endif /* __cplusplus */
0143 
0144 #endif /* LIBBSP_ARM_BEAGLE_SPI_H */