| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * (C)Copyright 2014 Marvell Hefei Branch. All Rights Reserved. |
| 4 | * |
| 5 | * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL. |
| 6 | * The copyright notice above does not evidence any actual or intended |
| 7 | * publication of such source code. |
| 8 | * This Module contains Proprietary Information of Marvell and should be |
| 9 | * treated as Confidential. |
| 10 | * The information in this file is provided for the exclusive use of the |
| 11 | * licensees of Marvell. |
| 12 | * Such users have the right to use, modify, and incorporate this code into |
| 13 | * products for purposes authorized by the license agreement provided they |
| 14 | * include this notice and the associated copyright notice with any such |
| 15 | * product. |
| 16 | * The information in this file is provided "AS IS" without warranty. |
| 17 | * |
| 18 | ******************************************************************************/ |
| 19 | |
| 20 | #include "spi.h" |
| 21 | #include "xllp_dmac.h" |
| 22 | |
| 23 | VUINT_T ssp_52mhz = 0; |
| 24 | |
| 25 | __attribute__ ((aligned(16))) XLLP_DMAC_DESCRIPTOR_T pRX_data, pTX_cmd; |
| 26 | __attribute__ ((aligned(16)))unsigned int tx_command[2112] = {0}; |
| 27 | UINT_T spi_tx_dma, spi_rx_dma; |
| 28 | |
| 29 | void Assert_CS(void) |
| 30 | { |
| 31 | *pGPIO_CR |= GPIO_CS_SET; |
| 32 | |
| 33 | while (*pGPIO_LR & GPIO_CS_SET); |
| 34 | } |
| 35 | |
| 36 | void Deassert_CS(void) |
| 37 | { |
| 38 | *pGPIO_SR |= GPIO_CS_SET; |
| 39 | |
| 40 | while (!(*pGPIO_LR & GPIO_CS_SET)); |
| 41 | } |
| 42 | |
| 43 | void ROW_DELAY(UINT_T x) |
| 44 | { |
| 45 | while (x > 0) |
| 46 | { |
| 47 | x--; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void SPI_DisableSSP(void) |
| 52 | { |
| 53 | //make sure SSP is disabled |
| 54 | reg_bit_clr(SSP_CR0, SSP_CR0_SSE); |
| 55 | //reset SSP CR's |
| 56 | reg_write(SSP_CR0, SSP_CR0_INITIAL); |
| 57 | reg_write(SSP_CR1, SSP_CR1_INITIAL); |
| 58 | } |
| 59 | |
| 60 | void SPI_WaitSSPComplete(void) |
| 61 | { |
| 62 | while (*SSP_SR & (SSP_SSSR_BSY | SSP_SSSR_TFL)) |
| 63 | { |
| 64 | ROW_DELAY(DEFAULT_TIMEOUT); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /*********************************************************** |
| 69 | * SPI_Write_Read |
| 70 | * PIO mode to write and then read out the data |
| 71 | * Returns: |
| 72 | * None |
| 73 | *************************************************************/ |
| 74 | void SPI_Write_Read(unsigned char *cmd, unsigned char *data, unsigned char len) |
| 75 | { |
| 76 | unsigned char i; |
| 77 | |
| 78 | for (i = 0; i < len; i++) |
| 79 | { |
| 80 | BU_REG_WRITE8(SSP_DR, cmd[i]); |
| 81 | SPI_WaitSSPComplete(); |
| 82 | |
| 83 | data[i] = BU_REG_READ8(SSP_DR); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void SPI_GetSSPDMAReqNum(UINT_T *tx, UINT_T *rx) |
| 88 | { |
| 89 | UINT_T SPI_DMA_TXReqNum = DMAC_SSP_2_TX; |
| 90 | UINT_T SPI_DMA_RXReqNum = DMAC_SSP_2_RX; |
| 91 | |
| 92 | #if NZA3 |
| 93 | switch (PlatformGetRevisionID()) |
| 94 | { |
| 95 | case 0xF0: |
| 96 | case 0xF2: |
| 97 | SPI_DMA_TXReqNum = DMAC_SSP_2_TX_Z2; |
| 98 | SPI_DMA_RXReqNum = DMAC_SSP_2_RX_Z2; |
| 99 | break; |
| 100 | |
| 101 | case 0xF3: |
| 102 | default: // here we suppose next step uses same SPI DMA reqest number as Z3 |
| 103 | break; |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | *tx = SPI_DMA_TXReqNum; |
| 108 | *rx = SPI_DMA_RXReqNum; |
| 109 | } |
| 110 | |