]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - qnx/src/ipc3x_dev/ti/syslink/family/common/vayu/vayuipu/vayucore0/VAYUIpuCore0HalReset.c
QNX: Remove dead virtio-related macros
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayuipu / vayucore0 / VAYUIpuCore0HalReset.c
1 /*
2  *  @file   VAYUIpuCore0HalReset.c
3  *
4  *  @brief      Reset control module.
5  *
6  *              This module is responsible for handling reset-related hardware-
7  *              specific operations.
8  *              The implementation is specific to VAYUIPUCORE0.
9  *
10  *
11  *  ============================================================================
12  *
13  *  Copyright (c) 2013-2014, Texas Instruments Incorporated
14  *
15  *  Redistribution and use in source and binary forms, with or without
16  *  modification, are permitted provided that the following conditions
17  *  are met:
18  *
19  *  *  Redistributions of source code must retain the above copyright
20  *     notice, this list of conditions and the following disclaimer.
21  *
22  *  *  Redistributions in binary form must reproduce the above copyright
23  *     notice, this list of conditions and the following disclaimer in the
24  *     documentation and/or other materials provided with the distribution.
25  *
26  *  *  Neither the name of Texas Instruments Incorporated nor the names of
27  *     its contributors may be used to endorse or promote products derived
28  *     from this software without specific prior written permission.
29  *
30  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
43 #include <ti/syslink/Std.h>
45 /* OSAL & Utils headers */
46 #include <ti/syslink/utils/Trace.h>
47 #include <Bitops.h>
49 /* Module level headers */
50 #include <_ProcDefs.h>
51 #include <Processor.h>
53 /* Hardware Abstraction Layer headers */
54 #include <VAYUIpuHal.h>
55 #include <VAYUIpuCore0HalReset.h>
57 #include <hw/inout.h>
59 #if defined (__cplusplus)
60 extern "C" {
61 #endif
64 /* =============================================================================
65  *  Macros and types
66  * =============================================================================
67  */
68 /* M4 PRCM Regs*/
69 #define RM_IPU_RSTCTRL_OFFSET        0x210
70 #define RM_IPU_RSTST_OFFSET          0x214
72 #define CM_IPU_CLKSTCTRL_OFFSET      0x200
73 #define CM_IPU_IPU_CLKCTRL_OFFSET    0x220
75 /*
76  * empirically determined delay that is necessary between when the IPU
77  * clock is enabled and when the status bit is set
78  */
79 #define DELAY                        100
81 /*
82  * IPU1 functional clock selection
83  * 0: DPLL_ABE_X2_CLK
84  * 1: CORE_IPU_ISS_BOOST_CLK
85  */
86 #define USE_CORE_IPU_ISS_BOOST_CLK   1
88 #if USE_CORE_IPU_ISS_BOOST_CLK
89 #define IPU1_CLKSEL                  0x1000000
90 #else
91 #define IPU1_CLKSEL                  0x0
92 #endif
94 /* =============================================================================
95  * APIs called by VAYUIPUCORE0PROC module
96  * =============================================================================
97  */
98 /*!
99  *  @brief      Function to control reset operations
100  *
101  *  @param      halObj  Pointer to the HAL object
102  *  @param      cmd     Reset control command
103  *  @param      arg     Arguments specific to the reset control command
104  *
105  *  @sa
106  */
107 Int
108 VAYUIPUCORE0_halResetCtrl (Ptr halObj, Processor_ResetCtrlCmd cmd)
110     Int                 status    = PROCESSOR_SUCCESS;
111     VAYUIPU_HalObject * halObject = NULL;
112     UInt32              cmBase;
113     UInt32              prmBase;
114     UInt32              reg       = 0;
115     UInt32              counter   = DELAY;
117     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0_halResetCtrl", halObj, cmd);
119     GT_assert (curTrace, (halObj != NULL));
120     GT_assert (curTrace, (cmd < Processor_ResetCtrlCmd_EndValue));
122     halObject = (VAYUIPU_HalObject *) halObj ;
123     cmBase = halObject->cmBase;
124     prmBase = halObject->prmBase;
126     switch (cmd) {
127         case Processor_ResetCtrlCmd_Reset:
128         {
129 #ifdef SYSLINK_SYSBIOS_SMP
130             /*Put Benelli M4_0 and M4_1 to Reset*/
131             /* Put IPU core 0 and core 1 into reset */
132             SETBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 1);
133             SETBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 0);
134             /* Read back the reset control register */
135             reg = INREG32(prmBase + RM_IPU_RSTCTRL_OFFSET);
136 #else
137             /*Put ONLY Benelli M4_0 to Reset*/
138             /* Put IPU core 0 into reset */
139             SETBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 0);
140             /* Read back the reset control register */
141             reg = INREG32(prmBase + RM_IPU_RSTCTRL_OFFSET);
142 #endif
143         }
144         break;
146         case Processor_ResetCtrlCmd_MMU_Reset:
147         {
148             /* Put IPU MMU into reset */
149             SETBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 0x2);
150             /* Disable the IPU clock */
151             OUTREG32(cmBase + CM_IPU_IPU_CLKCTRL_OFFSET, 0x01);
152         }
153         break;
155         case Processor_ResetCtrlCmd_MMU_Release:
156         {
157             reg = INREG32(prmBase + RM_IPU_RSTST_OFFSET);
158             if (reg != 0x0) {
159                 Osal_printf("VAYUIPUCORE0_halResetCtrl: clearing reset status!\n");
160                 OUTREG32(prmBase + RM_IPU_RSTST_OFFSET, reg);
161                 while ((reg = INREG32(prmBase + RM_IPU_RSTST_OFFSET)) != 0x0);
162                 Osal_printf("VAYUIPUCORE0_halResetCtrl: reset state reset!\n");
163             }
164             /* Module is managed automatically by HW */
165             if (halObject->procId == MultiProc_getId("IPU1")) {
166                 /* For IPU1, select CORE_IPU_ISS_BOOST_CLK as functional clk */
167                 OUTREG32(cmBase + CM_IPU_IPU_CLKCTRL_OFFSET, 0x1 | IPU1_CLKSEL);
168             }
169             else {
170                 OUTREG32(cmBase + CM_IPU_IPU_CLKCTRL_OFFSET, 0x1);
171             }
172             /* Enable the IPU clock */
173             OUTREG32(cmBase + CM_IPU_CLKSTCTRL_OFFSET, 0x2);
175             do {
176                 if (TESTBITREG32(cmBase + CM_IPU_CLKSTCTRL_OFFSET,
177                                  8)) {
178                     Osal_printf("IPU clock enabled:"
179                                 "CORE_CM_IPU_CLKSTCTRL = 0x%x\n",
180                                 INREG32(cmBase + CM_IPU_CLKSTCTRL_OFFSET));
181                     break;
182                 }
183             } while (--counter);
185             if (counter == 0) {
186                 Osal_printf("FAILED TO ENABLE IPU CLOCK !\n");
187                 return PROCESSOR_E_OSFAILURE;
188             }
190             /* Check that releasing resets would indeed be effective */
191             reg =  INREG32(prmBase + RM_IPU_RSTCTRL_OFFSET);
192             if (reg != 0x7) {
193                 Osal_printf("VAYUIPUCORE0_halResetCtrl: "
194                             "Resets in not proper state! [0x%x]\n",
195                             reg);
196                 OUTREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 0x7);
197                 while ((INREG32(prmBase + RM_IPU_RSTCTRL_OFFSET) & 0x7) != 0x7);
198             }
200             /* De-assert RST3, and clear the Reset status */
201             Osal_printf("De-assert RST3\n");
202             CLRBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 2);
204             while (!(INREG32(prmBase + RM_IPU_RSTST_OFFSET) & 0x4));
205             Osal_printf("RST3 released!\n");
206             SETBITREG32(prmBase + RM_IPU_RSTST_OFFSET, 2);
207         }
208         break;
210         case Processor_ResetCtrlCmd_Release:
211         {
212 #ifdef SYSLINK_SYSBIOS_SMP
213             /*Bring Benelli M4_0 and M4_1 out of Reset*/
214             /* De-assert RST1 and RST2, and clear the Reset status */
215             Osal_printf("De-assert RST1\n");
216             CLRBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 0);
217             Osal_printf("De-assert RST2\n");
218             CLRBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 1);
220             while (!(INREG32(prmBase + RM_IPU_RSTST_OFFSET) & 0x3));
221             Osal_printf("RST1 & RST2 released!");
222             SETBITREG32(prmBase + RM_IPU_RSTST_OFFSET, 0);
223             SETBITREG32(prmBase + RM_IPU_RSTST_OFFSET, 1);
224 #else
225             /*Bring ONLY Benelli M4_0 out of Reset*/
226             /* De-assert RST1, and clear the Reset status */
227             Osal_printf("De-assert RST1\n");
228             CLRBITREG32(prmBase + RM_IPU_RSTCTRL_OFFSET, 0);
230             while (!(INREG32(prmBase + RM_IPU_RSTST_OFFSET) & 0x1));
231             Osal_printf("RST1 released!");
232             SETBITREG32(prmBase + RM_IPU_RSTST_OFFSET, 0);
233 #endif
235             /* Setting to HW_AUTO Mode */
236             reg = INREG32(cmBase + CM_IPU_CLKSTCTRL_OFFSET);
237             reg &= ~0x3;
238             reg |= 0x3;
239             OUTREG32(cmBase + CM_IPU_CLKSTCTRL_OFFSET, reg);
240         }
241         break;
243         case Processor_ResetCtrlCmd_PeripheralUp:
244         {
245             /* Nothing to be done to bringup the peripherals for this device. */
246         }
247         break;
249         default:
250         {
251             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
252             status = PROCESSOR_E_INVALIDARG;
253             GT_setFailureReason (curTrace,
254                                  GT_4CLASS,
255                                  "VAYUIPUCORE0_halResetCtrl",
256                                  status,
257                                  "Unsupported reset ctrl cmd specified");
258         }
259         break ;
260     }
262     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0_halResetCtrl",status);
264     /*! @retval PROCESSOR_SUCCESS Operation successful */
265     return status;
269 #if defined (__cplusplus)
271 #endif