671b1d64d69f3ccb36d17be4c9d4c17cb3d4b4d5
[platform/kernel/u-boot.git] / arch / arm / mach-keystone / include / mach / psc_defs.h
1 /*
2  * (C) Copyright 2012-2014
3  *     Texas Instruments Incorporated, <www.ti.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7 #ifndef _PSC_DEFS_H_
8 #define _PSC_DEFS_H_
9
10 #include <asm/arch/hardware.h>
11
12 /*
13  * FILE PURPOSE: Local Power Sleep Controller definitions
14  *
15  * FILE NAME: psc_defs.h
16  *
17  * DESCRIPTION: Provides local definitions for the power saver controller
18  *
19  */
20
21 /* Register offsets */
22 #define PSC_REG_PTCMD           0x120
23 #define PSC_REG_PSTAT           0x128
24 #define PSC_REG_PDSTAT(x)       (0x200 + (4 * (x)))
25 #define PSC_REG_PDCTL(x)        (0x300 + (4 * (x)))
26 #define PSC_REG_MDCFG(x)        (0x600 + (4 * (x)))
27 #define PSC_REG_MDSTAT(x)       (0x800 + (4 * (x)))
28 #define PSC_REG_MDCTL(x)        (0xa00 + (4 * (x)))
29
30
31 static inline u32 _boot_bit_mask(u32 x, u32 y)
32 {
33         u32 val = (1 << (x - y + 1)) - 1;
34         return val << y;
35 }
36
37 static inline u32 boot_read_bitfield(u32 z, u32 x, u32 y)
38 {
39         u32 val = z & _boot_bit_mask(x, y);
40         return val >> y;
41 }
42
43 #define BOOT_SET_BITFIELD(z, f, x, y)  ((((u32)z) & ~_boot_bit_mask(x, y)) | \
44                                         ((((u32)f) << (y)) & _boot_bit_mask(x, y)))
45
46 /* PDCTL */
47 #define PSC_REG_PDCTL_SET_NEXT(x, y)        BOOT_SET_BITFIELD((x), (y), 0, 0)
48 #define PSC_REG_PDCTL_SET_PDMODE(x, y)      BOOT_SET_BITFIELD((x), (y), 15, 12)
49
50 /* PDSTAT */
51 #define PSC_REG_PDSTAT_GET_STATE(x)         boot_read_bitfield((x), 4, 0)
52
53 /* MDCFG */
54 #define PSC_REG_MDCFG_GET_PD(x)             boot_read_bitfield((x), 20, 16)
55 #define PSC_REG_MDCFG_GET_RESET_ISO(x)      boot_read_bitfield((x), 14, 14)
56
57 /* MDCTL */
58 #define PSC_REG_MDCTL_SET_NEXT(x, y)        BOOT_SET_BITFIELD((x), (y), 4, 0)
59 #define PSC_REG_MDCTL_SET_LRSTZ(x, y)       BOOT_SET_BITFIELD((x), (y), 8, 8)
60 #define PSC_REG_MDCTL_GET_LRSTZ(x)          boot_read_bitfield((x), 8, 8)
61 #define PSC_REG_MDCTL_SET_RESET_ISO(x, y)   BOOT_SET_BITFIELD((x), (y), \
62                                                                   12, 12)
63
64 /* MDSTAT */
65 #define PSC_REG_MDSTAT_GET_STATUS(x)        boot_read_bitfield((x), 5, 0)
66 #define PSC_REG_MDSTAT_GET_LRSTZ(x)         boot_read_bitfield((x), 8, 8)
67 #define PSC_REG_MDSTAT_GET_LRSTDONE(x)      boot_read_bitfield((x), 9, 9)
68 #define PSC_REG_MDSTAT_GET_MRSTZ(x)         boot_read_bitfield((x), 10, 10)
69 #define PSC_REG_MDSTAT_GET_MRSTDONE(x)      boot_read_bitfield((x), 11, 11)
70
71 /* PDCTL states */
72 #define PSC_REG_VAL_PDCTL_NEXT_ON           1
73 #define PSC_REG_VAL_PDCTL_NEXT_OFF          0
74
75 #define PSC_REG_VAL_PDCTL_PDMODE_SLEEP      0
76
77 /* MDCTL states */
78 #define PSC_REG_VAL_MDCTL_NEXT_SWRSTDISABLE     0
79 #define PSC_REG_VAL_MDCTL_NEXT_OFF              2
80 #define PSC_REG_VAL_MDCTL_NEXT_ON               3
81
82 /* MDSTAT states */
83 #define PSC_REG_VAL_MDSTAT_STATE_ON             3
84 #define PSC_REG_VAL_MDSTAT_STATE_ENABLE_IN_PROG 0x24
85 #define PSC_REG_VAL_MDSTAT_STATE_OFF            2
86 #define PSC_REG_VAL_MDSTAT_STATE_DISABLE_IN_PROG1       0x20
87 #define PSC_REG_VAL_MDSTAT_STATE_DISABLE_IN_PROG2       0x21
88 #define PSC_REG_VAL_MDSTAT_STATE_DISABLE_IN_PROG3       0x22
89
90 /*
91  * Timeout limit on checking PTSTAT. This is the number of times the
92  * wait function will be called before giving up.
93  */
94 #define PSC_PTSTAT_TIMEOUT_LIMIT    100
95
96 u32 psc_get_domain_num(u32 mod_num);
97 int psc_enable_module(u32 mod_num);
98 int psc_disable_module(u32 mod_num);
99 int psc_disable_domain(u32 domain_num);
100 int psc_module_keep_in_reset_enabled(u32 mod_num, bool gate_clocks);
101 int psc_module_release_from_reset(u32 mod_num);
102
103 #endif /* _PSC_DEFS_H_ */