# Enable SPI bus in sensor low-power island (SLPI)

Source: [https://docs.qualcomm.com/doc/80-88500-1/topic/35_Enable_SPI_bus_in_sensor_low_power_island__SLPI_.html](https://docs.qualcomm.com/doc/80-88500-1/topic/35_Enable_SPI_bus_in_sensor_low_power_island__SLPI_.html)

## About this task

The following SPI APIs are available in the core/api/buses/spi\_api.h file:

| API | Description |
| --- | --- |
| `spi_status_t spi_open (spi_instance_t instance, void **spi_handle)` | Opens an SPI port and gets an SPI handle. Sets up structures and objects for future transactions, however, does not communicate to the SPI hardware. |
| `spi_status_t spi_power_on (void *spi_handle); `<br>                  <br>`spi_status_t spi_power_off (void *spi_handle);` | Powers on and off the setup, and powers up and down the clocks and TLMM pins. |
| `spi_status_t spi_full_duplex (void *spi_handle, spi_config_t *config, spi_descriptor_t *desc, uint32 num_descriptors, callback_fn c_fn, void *c_ctxt, boolean get_timestamp);` | Performs full duplex, half duplex, or simplex transfers over the SPI bus and is the only available transfer function. The descriptor can have NULL Tx or Rx buffers when half duplex transfer is intended. Callback is invoked upon completion of the full chain of descriptors or an error condition. |
| `spi_status_t spi_close (void *spi_handle);` `i2c_status i2c_open(i2c_instance instance, void **i2c_handle)` | Releases the resources allocated to the SPI instances. |

All available SPI instances are listed in the core/api/buses/spi\_api.h file as:

    typedef enum
    {
       SPI_INSTANCE_1 = 1,
       SPI_INSTANCE_2,
       SPI_INSTANCE_3,
       SPI_INSTANCE_4,
       ………..
       SPI_INSTANCE_MAX,
    } spi_instance_t;Copy to clipboard

The memory space in the SLPI image has limited resources. Therefore, you must enable and compile the corresponding SPI instance into the final SLPI image manually. To get the SPI instance-related resources compiled or linked into the final image, define the following micro in the \SLPI.HY.1.2-XXXX\core\settings\buses\i2c\config\sdm845\slpi\spi\_devcfg.h file:

    #define SSC_USE_SPI_02 
    #define SSC_SPI_02_MISO TLMM_GPIO_CFG(2, 1, TLMM_GPIO_INPUT, TLMM_GPIO_PULL_DOWN, TLMM_GPIO_6MA)
    #define SSC_SPI_02_MOSI TLMM_GPIO_CFG(3, 1, TLMM_GPIO_OUTPUT, TLMM_GPIO_PULL_DOWN, TLMM_GPIO_6MA)
    #define SSC_SPI_02_CLK  TLMM_GPIO_CFG(4, 1, TLMM_GPIO_OUTPUT, TLMM_GPIO_NO_PULL, TLMM_GPIO_6MA)
    #define SSC_SPI_02_CS_0 TLMM_GPIO_CFG(5, 1, TLMM_GPIO_OUTPUT, TLMM_GPIO_PULL_DOWN, TLMM_GPIO_6MA)
    #define SSC_SPI_02_CS_1 TLMM_GPIO_CFG(6, 1, TLMM_GPIO_OUTPUT, TLMM_GPIO_PULL_DOWN, TLMM_GPIO_6MA)
    #define SSC_SPI_02_CS_2 TLMM_GPIO_CFG(7, 1, TLMM_GPIO_OUTPUT, TLMM_GPIO_PULL_DOWN, TLMM_GPIO_6MA)
    
    static spi_plat_device_config spi_device_config[] ={
        ……………..
    #ifdef SSC_USE_SPI_02
        {
            .core_base_addr              = (uint8 *) 0x5A00000,
            .core_offset                 = 0x00080000,
            .core_index                  = 1,
            .core_irq                    = 0,   //not used, we use GSI callback
            .min_data_length_for_dma     = 0,
            .gpi_index                   = 1,
            .qup_type                    = 2,
            .se_clock_dfs_index          = 1,
            .se_clock_frequency          = 19200,
            .uses_ddr_buffer              = FALSE,
            .miso_encoding                = SSC_SPI_02_MISO,
            .mosi_encoding                = SSC_SPI_02_MOSI,
            .clk_encoding                 = SSC_SPI_02_CLK,
            .cs_encoding                  = {SSC_SPI_02_CS_0, SSC_SPI_02_CS_1, SSC_SPI_02_CS_2, 0},
            .sleep_miso_encoding          = SSC_SPI_02_MISO_SLEEP,
            .sleep_mosi_encoding          = SSC_SPI_02_MOSI_SLEEP,
            .sleep_clk_encoding           = SSC_SPI_02_CLK_SLEEP,
            .sleep_cs_encoding            = {SSC_SPI_02_CS_0_SLEEP, SSC_SPI_02_CS_1_SLEEP, SSC_SPI_02_CS_2_SLEEP, 0},
            .tx_dma_ring_base            = gpi_tx_tre_list_base_02,
            .rx_dma_ring_base            = gpi_rx_tre_list_base_02,
        },
    #endif
        …………………..
    };Copy to clipboard

**Parent Topic:** [SPI in QUP](https://docs.qualcomm.com/doc/80-88500-1/topic/30_SPI_in_QUP_v3.html)

Last Published: Aug 18, 2023

[Previous Topic
Configure SPI in sensor core](https://docs.qualcomm.com/bundle/publicresource/80-88500-1/topics/34_Configure_SPI_in_sensor_core_.md) [Next Topic
Update QUP serial engine firmware for SPI](https://docs.qualcomm.com/bundle/publicresource/80-88500-1/topics/36_Update_QUP_v3_serial_engine_firmware_for_SPI.md)