]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - psdk_cust/pdk_k2g_1_0_1_2_eng/packages/ti/boot/sbl/soc/k2g/sbl_soc.c
Merge pull request #1 in PASDK/pasdk_sr from PASDK-318-input-task-code-repetition...
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_2_eng / packages / ti / boot / sbl / soc / k2g / sbl_soc.c
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
34 #include "sbl_soc.h"
36 #include <ti/board/src/evmK2G/include/board_cfg.h>
37 #include <ti/board/src/flash/include/board_flash.h>
38 #include <ti/drv/spi/soc/SPI_soc.h>
40 /**
41  * @brief - SBL_setNSMode()
42  *  internal function to set non-secure mode
43  *
44  * @param   none
45  *
46  * @return  none
47  *
48  */
49 void SBL_setNSMode()
50 {
51     /* Set bit 10 and 11 in NSACR to allow NS access to cp10 and cp11 */
52     asm("MRC p15, 0, r0, c1, c1, 2\n");
53     asm("ORR r0, r0, #0x00000C00\n");
54     asm("MCR p15, 0, r0, c1, c1, 2\n");
56     /* Set bit 0 in SCR for NS mode */
57     asm("MRC p15, 0, r0, c1, c1, 0\n");
58     asm("ORR r0, r0, #0x1\n");
59     asm("MCR p15, 0, r0, c1, c1, 0\n");
60 }
62 /**
63  * @brief - SBL_a15EnableNeon()
64  *  internal function to enable NEON coprocessor
65  *
66  * @param   none
67  *
68  * @return  none
69  *
70  */
71 void SBL_a15EnableNeon()
72 {
73     asm("MRC p15, #0, r1, c1, c0, #2\n");
74     asm("ORR r1, r1, #(0xf << 20)\n");
75     asm("MCR p15, #0, r1, c1, c0, #2\n");
76     asm("MOV r1, #0\n");
77     asm("MCR p15, #0, r1, c7, c5, #4\n");
78     asm("MOV r0,#0x40000000\n");
79     asm("FMXR FPEXC, r0\n");
80 }
83 int32_t SBL_socInit()
84 {
85     Board_initCfg boardCfg;
86     boardCfg = BOARD_INIT_PLL | 
87         BOARD_INIT_MODULE_CLOCK | 
88         BOARD_INIT_DDR |
89         BOARD_INIT_PINMUX_CONFIG | 
90         BOARD_INIT_UART_STDIO;
91     void (*monitorFunction) (void (*)(void), ...);
93     /* A15 startup calls */
94     monitorFunction = (void (*)) 0x1000;
95     (*monitorFunction)(SBL_setNSMode);
96     (*monitorFunction)(SBL_a15EnableNeon);
98     /* Board Library Init. */
99     if (Board_init(boardCfg))
100     {
101         return -1;
102     }
103     return 0;
106 #if defined (BOOT_QSPI)
107 int32_t SBL_qspiInit(void *handle)
109     QSPI_v0_HwAttrs qspi_cfg;
111     /* Get the default QSPI init configurations */
112     QSPI_socGetInitCfg(BOARD_QSPI_NOR_INSTANCE, &qspi_cfg);
114     /* Modify the default QSPI configurations if necessary */
115     /* Turning off interrupts for baremetal mode. May be re-enabled by app */
116     qspi_cfg.intrEnable = false;
118     /* Set the default QSPI init configurations */
119     QSPI_socSetInitCfg(BOARD_QSPI_NOR_INSTANCE, &qspi_cfg);
121     /* Open the Board QSPI NOR device with QSPI port 0
122        and use default QSPI configurations */
123     *(Board_flashHandle *) handle = Board_flashOpen(BOARD_FLASH_ID_QSPIFLASH_S25FL512S,
124                             BOARD_QSPI_NOR_INSTANCE, NULL);
126     if (!handle)
127     {
128         return -1;
129     }
131     return 0;
134 int32_t SBL_qspiFlashWrite(void *handle, uint8_t *src, uint32_t length,
135     uint32_t offset)
137     Board_flashHandle h = *(Board_flashHandle *) handle;
138     uint32_t blockNum, pageNum;
139     uint32_t ioMode;
140     ioMode = BOARD_FLASH_QSPI_IO_MODE_QUAD;
141     if (Board_flashOffsetToBlkPage(h, offset, &blockNum, &pageNum))
142     {
143         return -1;
144     }
146     /* Erase block, to which data has to be written */
147     if (Board_flashEraseBlk(h, blockNum))
148     {
149         return -2;
150     }
152     /* Write buffer to flash */
153     if (Board_flashWrite(h, offset, src, length, (void *)(&ioMode)))
154     {
155         return -3;
156     }
158     return 0;
161 int32_t SBL_qspiFlashRead(void *handle, uint8_t *dst, uint32_t length,
162     uint32_t offset)
164     Board_flashHandle h = *(Board_flashHandle *) handle;
165     uint32_t ioMode;
166     ioMode = BOARD_FLASH_QSPI_IO_MODE_QUAD;
168     if (Board_flashRead(h, offset, dst, length, (void *)(&ioMode)))
169     {
170         return -1;
171     }
173     return 0;
176 int32_t SBL_qspiClose(void *handle)
178     Board_flashHandle h = *(Board_flashHandle *) handle;
179     Board_flashClose(h);
180     return 0;
182 #endif /* end of BOOT_QSPI definitions */