1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author        Notes
8  * 2010-11-13     weety     first version
9  */
10 
11 #include "dm36x.h"
12 
13 
14 /* ------------------------------------------------------------------------ *
15  *  psc_change_state( id, state )                                           *
16  *      id    = Domain #ID                                                  *
17  *      state = ( ENABLE, DISABLE, SYNCRESET, RESET )                       *
18  *              (   =3  ,   =2   ,    =1    ,   =0  )                       *
19  * ------------------------------------------------------------------------ */
psc_change_state(int id,int state)20 void psc_change_state(int id, int state)
21 {
22     rt_uint32_t mdstat, mdctl;
23 
24     if (id > DAVINCI_DM365_LPSC_KALEIDO)
25         return;
26 
27     mdstat = PSC_MDSTAT_BASE + (id * 4);
28     mdctl = PSC_MDCTL_BASE + (id * 4);
29 
30     /*
31      *  Step 0 - Ignore request if the state is already set as is
32      */
33     if ((readl(mdstat) & 0x1f) == state)
34         return;
35 
36     /*
37      *  Step 1 - Wait for PTSTAT.GOSTAT to clear
38      */
39     while (readl(PSC_PTSTAT) & 1) ;
40 
41     /*
42      *  Step 2 - Set MDCTLx.NEXT to new state
43      */
44     writel(readl(mdctl) & (~0x1f), mdctl);
45     writel(readl(mdctl) | state, mdctl);
46 
47     /*
48      *  Step 3 - Start power transition ( set PTCMD.GO to 1 )
49      */
50     writel(readl(PSC_PTCMD) | 1, PSC_PTCMD);
51 
52     /*
53      *  Step 4 - Wait for PTSTAT.GOSTAT to clear
54      */
55     while (readl(PSC_PTSTAT) & 1) ;
56 }
57 
58