1 /*
2 * Copyright (c) 2016-2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
34 #include <ti/board/src/flash/nor/nor.h>
35 #include <ti/board/src/flash/include/board_flash.h>
37 uint32_t Nor_intf;
39 #if defined (evmK2G)
40 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
41 {
42 {
43 &Nor_spiFxnTable
44 },
45 {
46 &Nor_qspiFxnTable
47 },
48 {
49 NULL
50 },
51 {
52 NULL
53 },
54 {
55 NULL
56 }
57 };
58 #elif defined (iceK2G)
59 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
60 {
61 {
62 NULL
63 },
64 {
65 &Nor_qspiFxnTable
66 },
67 {
68 NULL
69 },
70 {
71 NULL
72 },
73 {
74 NULL
75 }
76 };
77 #elif defined (am65xx_evm) || defined (am65xx_idk)
78 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
79 {
80 {
81 NULL
82 },
83 {
84 NULL
85 },
86 {
87 NULL
88 },
89 {
90 &Nor_ospiFxnTable
91 },
92 {
93 NULL
94 }
95 };
96 #elif defined (j721e_sim) || defined (j721e_evm)
97 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
98 {
99 {
100 NULL
101 },
102 {
103 &Nor_qspiFxnTable
104 },
105 {
106 NULL
107 },
108 {
109 &Nor_ospiFxnTable
110 },
111 {
112 &Nor_hpfFxnTable
113 }
114 };
115 #elif defined (icev2AM335x)
116 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
117 {
118 {
119 NULL
120 },
121 {
122 NULL
123 },
124 {
125 &Nor_gpmcFxnTable
126 },
127 {
128 NULL
129 },
130 {
131 NULL
132 }
133 };
134 #elif defined (evmK2H) || defined (evmK2K) || defined (evmK2L) || defined (evmK2E) || defined (evmC6678) || defined (evmC6657) || defined (evmOMAPL137)
135 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
136 {
137 {
138 &Nor_spiFxnTable
139 },
140 {
141 NULL
142 },
143 {
144 NULL
145 },
146 {
147 NULL
148 },
149 {
150 NULL
151 }
152 };
153 #else
154 NOR_Config Nor_config[BOARD_FLASH_NOR_INTF_MAX] =
155 {
156 {
157 NULL
158 },
159 {
160 NULL
161 },
162 {
163 NULL
164 },
165 {
166 NULL
167 },
168 {
169 NULL
170 }
171 };
172 #endif
174 /*
175 * ======== NOR_open ========
176 */
177 NOR_HANDLE NOR_open(uint32_t norIntf, uint32_t portNum, void *params)
178 {
179 NOR_HANDLE handle = 0;
181 if ((norIntf < BOARD_FLASH_NOR_INTF_MAX) && Nor_config[norIntf].fxnTablePtr)
182 {
183 handle = Nor_config[norIntf].fxnTablePtr->openFxn(norIntf, portNum, params);
184 if (handle)
185 {
186 Nor_intf = norIntf;
187 }
188 }
190 return handle;
191 }
193 /*
194 * ======== NOR_close ========
195 */
196 void NOR_close(NOR_HANDLE handle)
197 {
198 Nor_config[Nor_intf].fxnTablePtr->closeFxn(handle);
199 }
201 /*
202 * ======== NOR_read ========
203 */
204 NOR_STATUS NOR_read(NOR_HANDLE handle, uint32_t addr,
205 uint32_t len, uint8_t *buf, uint32_t mode)
206 {
207 return (Nor_config[Nor_intf].fxnTablePtr->readFxn(handle, addr, len, buf, mode));
208 }
210 /*
211 * ======== NOR_write ========
212 */
213 NOR_STATUS NOR_write(NOR_HANDLE handle, uint32_t addr,
214 uint32_t len, uint8_t *buf, uint32_t mode)
215 {
216 return (Nor_config[Nor_intf].fxnTablePtr->writeFxn(handle, addr, len, buf, mode));
217 }
219 /*
220 * ======== NOR_erase ========
221 */
222 NOR_STATUS NOR_erase(NOR_HANDLE handle, int32_t blk, bool blkErase)
223 {
224 return (Nor_config[Nor_intf].fxnTablePtr->eraseFxn(handle, blk, blkErase));
225 }