| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2010, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: flash data store abstraction |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | #ifndef __BSPI_FLASH_H__ |
|---|
| 23 | #define __BSPI_FLASH_H__ |
|---|
| 24 | |
|---|
| 25 | #include "bsettop_types.h" |
|---|
| 26 | |
|---|
| 27 | /*************************************************************************** |
|---|
| 28 | Summary: |
|---|
| 29 | The SPI flash interface handle. |
|---|
| 30 | |
|---|
| 31 | Description: |
|---|
| 32 | An opaque handle SPI device control. |
|---|
| 33 | |
|---|
| 34 | See Also: |
|---|
| 35 | bspi_open() |
|---|
| 36 | |
|---|
| 37 | ****************************************************************************/ |
|---|
| 38 | typedef struct bspi *bspi_t; |
|---|
| 39 | |
|---|
| 40 | /*************************************************************************** |
|---|
| 41 | Summary: |
|---|
| 42 | SPI flash settings structure. |
|---|
| 43 | |
|---|
| 44 | Description: |
|---|
| 45 | SPI Flash configuration parameters for the attached flash type. |
|---|
| 46 | |
|---|
| 47 | See Also: |
|---|
| 48 | bspi_identify() |
|---|
| 49 | |
|---|
| 50 | ****************************************************************************/ |
|---|
| 51 | typedef struct bspi_settings_t |
|---|
| 52 | { |
|---|
| 53 | unsigned char se_cmd; /* Flash sector erase command */ |
|---|
| 54 | unsigned int sector_size; /* Flash sector size */ |
|---|
| 55 | unsigned int page_size; /* Flash page size (usually 0x100) */ |
|---|
| 56 | unsigned int total_size; /* Flash size */ |
|---|
| 57 | }bspi_settings_t; |
|---|
| 58 | |
|---|
| 59 | #ifdef __cplusplus |
|---|
| 60 | extern "C" { |
|---|
| 61 | #endif |
|---|
| 62 | |
|---|
| 63 | /*************************************************************************** |
|---|
| 64 | Summary: |
|---|
| 65 | Use RDID command to determine flash settings. |
|---|
| 66 | |
|---|
| 67 | Description: |
|---|
| 68 | Uses RDID command to determine flash type and configure the settings structure. |
|---|
| 69 | |
|---|
| 70 | Returns: |
|---|
| 71 | non-zero on failure. |
|---|
| 72 | |
|---|
| 73 | See Also: |
|---|
| 74 | bspi_open(), |
|---|
| 75 | |
|---|
| 76 | ****************************************************************************/ |
|---|
| 77 | bresult bspi_identify( |
|---|
| 78 | bspi_settings_t *p_settings /* [out] SPI flash settings structure */ |
|---|
| 79 | ); |
|---|
| 80 | /*************************************************************************** |
|---|
| 81 | Summary: |
|---|
| 82 | Initialize and return SPI interface handle. |
|---|
| 83 | |
|---|
| 84 | Description: |
|---|
| 85 | Initialize and return a SPI interface handle. This function |
|---|
| 86 | expects the bspi_settings_t structure to be initialized. |
|---|
| 87 | |
|---|
| 88 | Returns: |
|---|
| 89 | SPI interface handle, non-zero on failure. |
|---|
| 90 | |
|---|
| 91 | See Also: |
|---|
| 92 | bspi_close(), bspi_identify(), |
|---|
| 93 | |
|---|
| 94 | ****************************************************************************/ |
|---|
| 95 | bresult bspi_open( |
|---|
| 96 | bspi_t *h_spi, /* [out] Return SPI handle */ |
|---|
| 97 | bspi_settings_t *p_settings /* [in] SPI flash settings */ |
|---|
| 98 | ); |
|---|
| 99 | /*************************************************************************** |
|---|
| 100 | Summary: |
|---|
| 101 | Release SPI interface handle. |
|---|
| 102 | |
|---|
| 103 | Description: |
|---|
| 104 | Release SPI interface handle and any other SPI flash resources. |
|---|
| 105 | |
|---|
| 106 | Returns: |
|---|
| 107 | non-zero on failure. |
|---|
| 108 | |
|---|
| 109 | See Also: |
|---|
| 110 | bspi_open(), |
|---|
| 111 | |
|---|
| 112 | ****************************************************************************/ |
|---|
| 113 | bresult bspi_close( |
|---|
| 114 | bspi_t h_spi /* [in] SPI handle */ |
|---|
| 115 | ); |
|---|
| 116 | |
|---|
| 117 | /*************************************************************************** |
|---|
| 118 | Summary: |
|---|
| 119 | Reads a single byte from flash using the SPI interface, not memory mapped spi. |
|---|
| 120 | |
|---|
| 121 | Description: |
|---|
| 122 | Reads a single byte from flash using the SPI interface, not the memory mapped SPI |
|---|
| 123 | interface. It will disable the BSP (memory mapped SPI interface) temporarily. |
|---|
| 124 | |
|---|
| 125 | Returns: |
|---|
| 126 | non-zero on failure. |
|---|
| 127 | |
|---|
| 128 | See Also: |
|---|
| 129 | bspi_open(), |
|---|
| 130 | |
|---|
| 131 | ****************************************************************************/ |
|---|
| 132 | bresult bspi_read( |
|---|
| 133 | bspi_t h_spi, /* [in] SPI handle */ |
|---|
| 134 | unsigned int offset, /* [in] Offset in bytes */ |
|---|
| 135 | unsigned char *data /* [out] buffer to receive data */ |
|---|
| 136 | ); |
|---|
| 137 | |
|---|
| 138 | /*************************************************************************** |
|---|
| 139 | Summary: |
|---|
| 140 | Erase flash sector at offset. |
|---|
| 141 | |
|---|
| 142 | Description: |
|---|
| 143 | Erase flash sector at offset. It will disable the BSP (memory mapped |
|---|
| 144 | SPI interface) temporarily. |
|---|
| 145 | |
|---|
| 146 | Returns: |
|---|
| 147 | non-zero on failure. |
|---|
| 148 | |
|---|
| 149 | See Also: |
|---|
| 150 | bspi_open(),bspi_page_program() |
|---|
| 151 | |
|---|
| 152 | ****************************************************************************/ |
|---|
| 153 | bresult bspi_sector_erase( |
|---|
| 154 | bspi_t h_spi, /* [in] SPI handle */ |
|---|
| 155 | unsigned int offset /* [in] Offset in bytes */ |
|---|
| 156 | ); |
|---|
| 157 | |
|---|
| 158 | /*************************************************************************** |
|---|
| 159 | Summary: |
|---|
| 160 | Program the flash page at offset with the data provided in the buffer. |
|---|
| 161 | |
|---|
| 162 | Description: |
|---|
| 163 | Program the flash page at offset with the data provided in the buffer. |
|---|
| 164 | It will disable the BSP (memory mapped SPI interface) temporarily. |
|---|
| 165 | |
|---|
| 166 | Returns: |
|---|
| 167 | non-zero on failure. |
|---|
| 168 | |
|---|
| 169 | See Also: |
|---|
| 170 | bspi_open(), bspi_sector_erase() |
|---|
| 171 | |
|---|
| 172 | ****************************************************************************/ |
|---|
| 173 | bresult bspi_page_program( |
|---|
| 174 | bspi_t h_spi, /* [in] SPI handle */ |
|---|
| 175 | unsigned int offset, /* [in] Offset in bytes */ |
|---|
| 176 | unsigned char *buf, /* [in] Data buffer to program */ |
|---|
| 177 | int len /* [in] Size in bytes of data buffer */ |
|---|
| 178 | ); |
|---|
| 179 | /*************************************************************************** |
|---|
| 180 | Summary: |
|---|
| 181 | Flush BSPI interface. |
|---|
| 182 | ****************************************************************************/ |
|---|
| 183 | void bspi_flush(void); |
|---|
| 184 | |
|---|
| 185 | void mspi_enable_bspi(void); |
|---|
| 186 | void mspi_disable_bspi(void); |
|---|
| 187 | |
|---|
| 188 | #ifdef __cplusplus |
|---|
| 189 | } |
|---|
| 190 | #endif |
|---|
| 191 | |
|---|
| 192 | #endif /* __BSPI_FLASH_H__ */ |
|---|
| 193 | |
|---|