[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / board / src / bbbAM335x / bbbAM335x_pinmux.c
1 /**
2 * @file icev2am335x_pinmux.c
3 *
4 * @brief
5 * This is the pin configuration for ICE V2 AM335x.
6 *
7 * \par
8 * ============================================================================
9 * @n (C) Copyright 2009-2015, Texas Instruments, Inc.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the
21 * distribution.
22 *
23 * Neither the name of Texas Instruments Incorporated nor the names of
24 * its contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 * \par
40 */
42 #include <stdint.h>
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include "board_internal.h"
46 #include "types.h"
47 #include "hw_types.h"
48 #include "chipdb.h"
49 #include "pinmux.h"
50 #include "error.h"
51 #include "am335x_pinmux.h"
52 #include "debug.h"
54 Board_STATUS Board_pinmuxConfig (void)
55 {
56 int32_t status;
58 /* UART */
59 status = PINMUXModuleConfig(CHIPDB_MOD_ID_UART, 0U, NULL);
61 /* CPSW */
62 if(S_PASS == status)
63 {
64 status = PINMUXModuleConfig(CHIPDB_MOD_ID_CPSW, 0U, NULL);
65 }
67 /* GPIO */
68 if(S_PASS == status)
69 {
70 status = PINMUXModuleConfig(CHIPDB_MOD_ID_GPIO, 0U, NULL);
71 }
72 if(S_PASS == status)
73 {
74 status = PINMUXModuleConfig(CHIPDB_MOD_ID_GPIO, 1U, NULL);
75 }
76 if(S_PASS == status)
77 {
78 status = PINMUXModuleConfig(CHIPDB_MOD_ID_GPIO, 3U, NULL);
79 }
81 /* I2C */
82 if(S_PASS == status)
83 {
84 status = PINMUXModuleConfig(CHIPDB_MOD_ID_I2C, 0U, NULL);
85 }
87 /* MCSPI */
88 if(S_PASS == status)
89 {
90 status = PINMUXModuleConfig(CHIPDB_MOD_ID_MCSPI, 1U, NULL);
91 }
93 /* MMCSD */
94 if(S_PASS == status)
95 {
96 status = PINMUXModuleConfig(CHIPDB_MOD_ID_MMCSD, 0U, NULL);
97 }
98 if(S_PASS == status)
99 {
100 status = PINMUXModuleConfig(CHIPDB_MOD_ID_MMCSD, 1U, NULL);
101 }
103 return BOARD_SOK;
104 }
107 int32_t PINMUXModuleConfig(chipdbModuleID_t moduleId, uint32_t instNum,
108 void* pParam1)
109 {
110 pinmuxModuleCfg_t* pModuleData = NULL;
111 pinmuxPerCfg_t* pInstanceData = NULL;
112 volatile const pinmuxBoardCfg_t* pPinmuxData = NULL;
113 uint32_t ctrlModBase = CHIPDBBaseAddress(CHIPDB_MOD_ID_CONTROL_MODULE, 0);
114 int32_t status = E_FAIL;
115 uint32_t index = 0;
117 /* Get module Data */
118 pPinmuxData = gBbbPinmuxData;
119 ASSERT(NULL != pPinmuxData);
121 status = E_INVALID_MODULE_ID;
122 for(index = 0; ((S_PASS != status) &&
123 (CHIPDB_MOD_ID_INVALID != pPinmuxData[index].moduleId)); index++)
124 {
125 if(pPinmuxData[index].moduleId == moduleId)
126 {
127 pModuleData = pPinmuxData[index].modulePinCfg;
128 ASSERT(NULL != pModuleData);
129 status = S_PASS;
130 }
131 }
133 /* Get instance Data */
134 if(S_PASS == status)
135 {
136 status = E_INST_NOT_SUPP;
137 for(index = 0; ((S_PASS != status) &&
138 (CHIPDB_INVALID_INSTANCE_NUM != pModuleData[index].modInstNum)); index++)
139 {
140 if(pModuleData[index].modInstNum == instNum)
141 {
142 pInstanceData = pModuleData[index].instPins;
143 ASSERT(NULL != pInstanceData)
144 status = S_PASS;
145 }
146 }
147 }
149 /* Configure Pinmux */
150 if(S_PASS == status)
151 {
152 for(index = 0; ((uint16_t)PINMUX_INVALID_PIN !=
153 pInstanceData[index].pinOffset); index++)
154 {
155 if(NULL != pParam1)
156 {
157 if(pInstanceData[index].optParam == *(uint16_t*)pParam1)
158 {
159 HW_WR_REG32((ctrlModBase + pInstanceData[index].pinOffset),
160 pInstanceData[index].pinSettings);
161 status = S_PASS;
162 break;
163 }
164 }
165 else
166 {
167 HW_WR_REG32((ctrlModBase + pInstanceData[index].pinOffset),
168 pInstanceData[index].pinSettings);
169 }
170 }
171 if((NULL != pParam1) && ((uint16_t)PINMUX_INVALID_PIN == pInstanceData[index].pinOffset))
172 {
173 status = E_FAIL;
174 }
175 }
177 return status;
178 }