[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_0_eng / packages / ti / board / src / skAM335x / skAM335x_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 }
77 /* I2C */
78 if(S_PASS == status)
79 {
80 status = PINMUXModuleConfig(CHIPDB_MOD_ID_I2C, 0U, NULL);
81 }
83 /* MMCSD */
84 if(S_PASS == status)
85 {
86 status = PINMUXModuleConfig(CHIPDB_MOD_ID_MMCSD, 0U, NULL);
87 }
88 /* LCDC */
89 if(S_PASS == status)
90 {
91 status = PINMUXModuleConfig(CHIPDB_MOD_ID_LCDC, 0U, NULL);
92 }
94 return BOARD_SOK;
95 }
98 int32_t PINMUXModuleConfig(chipdbModuleID_t moduleId, uint32_t instNum,
99 void* pParam1)
100 {
101 pinmuxModuleCfg_t* pModuleData = NULL;
102 pinmuxPerCfg_t* pInstanceData = NULL;
103 volatile const pinmuxBoardCfg_t* pPinmuxData = NULL;
104 uint32_t ctrlModBase = CHIPDBBaseAddress(CHIPDB_MOD_ID_CONTROL_MODULE, 0);
105 int32_t status = E_FAIL;
106 uint32_t index = 0;
108 /* Get module Data */
109 pPinmuxData = gEvmskPinmuxData;
110 ASSERT(NULL != pPinmuxData);
112 status = E_INVALID_MODULE_ID;
113 for(index = 0; ((S_PASS != status) &&
114 (CHIPDB_MOD_ID_INVALID != pPinmuxData[index].moduleId)); index++)
115 {
116 if(pPinmuxData[index].moduleId == moduleId)
117 {
118 pModuleData = pPinmuxData[index].modulePinCfg;
119 ASSERT(NULL != pModuleData);
120 status = S_PASS;
121 }
122 }
124 /* Get instance Data */
125 if(S_PASS == status)
126 {
127 status = E_INST_NOT_SUPP;
128 for(index = 0; ((S_PASS != status) &&
129 (CHIPDB_INVALID_INSTANCE_NUM != pModuleData[index].modInstNum)); index++)
130 {
131 if(pModuleData[index].modInstNum == instNum)
132 {
133 pInstanceData = pModuleData[index].instPins;
134 ASSERT(NULL != pInstanceData)
135 status = S_PASS;
136 }
137 }
138 }
140 /* Configure Pinmux */
141 if(S_PASS == status)
142 {
143 for(index = 0; ((uint16_t)PINMUX_INVALID_PIN !=
144 pInstanceData[index].pinOffset); index++)
145 {
146 if(NULL != pParam1)
147 {
148 if(pInstanceData[index].optParam == *(uint16_t*)pParam1)
149 {
150 HW_WR_REG32((ctrlModBase + pInstanceData[index].pinOffset),
151 pInstanceData[index].pinSettings);
152 status = S_PASS;
153 break;
154 }
155 }
156 else
157 {
158 HW_WR_REG32((ctrlModBase + pInstanceData[index].pinOffset),
159 pInstanceData[index].pinSettings);
160 }
161 }
162 if((NULL != pParam1) && ((uint16_t)PINMUX_INVALID_PIN == pInstanceData[index].pinOffset))
163 {
164 status = E_FAIL;
165 }
166 }
168 return status;
169 }