1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - PM - include - common
3   File:     pm_common.h
4 
5   Copyright 2003-2008 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-10-31#$
14   $Rev: 9171 $
15   $Author: yada $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NITRO_PM_COMMON_H_
19 #define NITRO_PM_COMMON_H_
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifdef SDK_NITRO
26 //---------------- NITRO
27 #include <nitro/misc.h>
28 #include <nitro/types.h>
29 #ifdef SDK_ARM9
30 #include <nitro/hw/ARM9/ioreg_PAD.h>
31 #else  // SDK_ARM9
32 #include <nitro/hw/ARM7/ioreg_PAD.h>
33 #endif // SDK_ARM9
34 
35 #else
36 //---------------- TWL
37 #include <twl/misc.h>
38 #include <twl/types.h>
39 #ifdef SDK_ARM9
40 #include <twl/hw/ARM9/ioreg_PAD.h>
41 #else  // SDK_ARM9
42 #include <twl/hw/ARM7/ioreg_PAD.h>
43 #endif // SDK_ARM9
44 #include <twl/spi/common/pm_common.h>
45 #endif
46 
47 
48 //================================================================
49 //    PMIC register parameter
50 //================================================================
51 //---------------- address
52 #define REG_PMIC_CTL_ADDR        0     // R/W
53 #define REG_PMIC_STAT_ADDR       1     // R
54 #define REG_PMIC_OP_CTL_ADDR     2     // R/W
55 #define REG_PMIC_PGA_GAIN_ADDR   3     // R/W
56 #define REG_PMIC_BL_CTL_ADDR     4     // R/W(bit0-3), R(bit4,5,7)
57 #define PMIC_REG_NUMS            5     // nums of register
58 
59 //---------------- each register spec
60 //---- PMIC_CTL
61 #define PMIC_CTL_SND_PWR        (1<< 0)
62 #define PMIC_CTL_SND_VOLCTRL    (1<< 1)
63 #define PMIC_CTL_BKLT1          (1<< 2)
64 #define PMIC_CTL_BKLT2          (1<< 3)
65 #define PMIC_CTL_LED_SW         (1<< 4)
66 #define PMIC_CTL_LED_SP         (1<< 5)
67 #define PMIC_CTL_PWR_OFF        (1<< 6)
68 
69 //---- PMIC_STAT
70 #define PMIC_STAT_VDET          (1<< 0)
71 
72 //---- PMIC_OP_CTL
73 #define PMIC_OP_CTL             (1<< 0)
74 
75 //---- PMIC_PGA_GAIN
76 #define PMIC_PGA_GAIN_SHIFT     0
77 #define PMIC_PGA_GAIN_SCALE     4
78 #define PMIC_PGA_GAIN_MASK      ((PMIC_PGA_GAIN_SCALE-1)<< PMIC_PGA_GAIN_SHIFT)
79 
80 //---- PMIC_BL_CTL
81 #define PMIC_BL_CTL_BL_SHIFT    0
82 #define PMIC_BL_CTL_BL_MASK     (3<< PMIC_BL_CTL_BL_SHIFT)
83 #define PMIC_BL_CTL_ADPT_SW     (1<< 2)
84 #define PMIC_BL_CTL_ADPT_DETECT (1<< 3)
85 #define PMIC_BL_CTL_VERSION     (1<< 6)
86 
87 
88 //---------------- PMIC register access spec
89 #define PMIC_REG_READ           1
90 #define PMIC_REG_WRITE          0
91 #define PMIC_REG_OP_SHIFT       7
92 #define PMIC_REG_OP_MASK        1
93 
94 //================================================================
95 //    UTILITY command to access PMIC
96 //================================================================
97 //---- pm ulitity proc number
98 enum
99 {
100     PM_UTIL_DUMMY = 0,
101     PM_UTIL_LED_ON,
102     PM_UTIL_LED_BLINK_HIGH_SPEED,
103     PM_UTIL_LED_BLINK_LOW_SPEED,
104     PM_UTIL_LCD1_BACKLIGHT_ON,
105     PM_UTIL_LCD1_BACKLIGHT_OFF,
106     PM_UTIL_LCD2_BACKLIGHT_ON,
107     PM_UTIL_LCD2_BACKLIGHT_OFF,
108     PM_UTIL_LCD12_BACKLIGHT_ON,
109     PM_UTIL_LCD12_BACKLIGHT_OFF,
110     PM_UTIL_SOUND_POWER_ON,
111     PM_UTIL_SOUND_POWER_OFF,
112     PM_UTIL_SOUND_VOL_CTRL_ON,
113     PM_UTIL_SOUND_VOL_CTRL_OFF,
114     PM_UTIL_FORCE_POWER_OFF,
115 
116 	//get status
117 	PM_UTIL_GET_STATUS,
118 
119 	//set status
120 	PM_UTIL_SET_AMP,
121 	PM_UTIL_SET_AMPGAIN,
122 	PM_UTIL_SET_BLINK,
123 
124 #ifdef SDK_TWL
125 	//reset & shutdown
126 	PM_UTIL_FORCE_RESET_HARDWARE,
127 	PM_UTIL_FORCE_EXIT,
128 
129 	//wireless LED
130 	PM_UTIL_WIRELESS_LED,
131 
132 	//amp gain
133 	PM_UTIL_SET_AMPGAIN_LEVEL,
134 #endif
135 
136 #ifdef SDK_TWL
137 	// set backlight brightness (for system. don't use)
138 	PMi_UTIL_SET_BACKLIGHT_BRIGHTNESS,
139 #endif
140 
141 	//direct register op. (for debug. don't use)
142 	PMi_UTIL_READREG,
143 	PMi_UTIL_WRITEREG,
144 	PMi_UTIL_PMIC_10,
145 
146 	//dummy end
147 	PM_UTIL_DUMMYEND
148 };
149 
150 // ( parameter for PM_UTIL_GET_STATUS )
151 enum
152 {
153 	PM_UTIL_PARAM_BATTERY,
154 	PM_UTIL_PARAM_BATTERY_LEVEL,
155 	PM_UTIL_PARAM_AC_ADAPTER,
156 	PM_UTIL_PARAM_BACKLIGHT,
157 	PM_UTIL_PARAM_SOUND_POWER,
158 	PM_UTIL_PARAM_SOUND_VOLUME,
159 	PM_UTIL_PARAM_AMP,
160 	PM_UTIL_PARAM_AMPGAIN,
161 	PM_UTIL_PARAM_BLINK,
162 
163 #ifdef SDK_TWL
164 	PM_UTIL_PARAM_AMPGAIN_LEVEL,
165 #endif
166 #ifdef SDK_TWL
167 	// get backlight brightness (for system. don't use)
168 	PMi_UTIL_GET_BACKLIGHT_BRIGHTNESS,
169 #endif
170 
171 	PM_UTIL_PARAM_DUMMYEND
172 };
173 
174 //================================================================
175 //    NOTIFY command from ARM7 to ARM9
176 //================================================================
177 #ifdef SDK_TWL
178 #define PM_NOTIFY_POWER_SWITCH    0
179 #define PM_NOTIFY_RESET_HARDWARE  1
180 #define PM_NOTIFY_SHUTDOWN        2
181 #define PM_NOTIFY_BATTERY_CHANGED 3
182 #define PM_NOTIFY_BATTERY_LOW     4
183 #define PM_NOTIFY_BATTERY_EMPTY   5
184 #endif
185 
186 //================================================================
187 //    BAUDRATE parameter
188 //================================================================
189 #define PM_BAUDRATE_4MHZ          0
190 #define PM_BAUDRATE_2MHZ          1
191 #define PM_BAUDRATE_1MHZ          2
192 #define PM_BAUDRATE_512KHZ        3
193 
194 //---- default
195 #define PM_BAUDRATE_PMIC_DEFAULT  PM_BAUDRATE_1MHZ
196 
197 //================================================================
198 //    SLEEP parameter
199 //================================================================
200 //---- factors to wake up from sleep mode
201 #define PM_TRIGGER_KEY              (1 << 0)
202 #define PM_TRIGGER_RTC_ALARM        (1 << 1)
203 #define PM_TRIGGER_COVER_OPEN       (1 << 2)
204 #define PM_TRIGGER_CARD             (1 << 3)
205 #define PM_TRIGGER_CARTRIDGE        (1 << 4)
206 #ifdef SDK_TWL
207 #define PM_TRIGGER_SDIO             (1 << 5)
208 #define PM_TRIGGER_MASK             (PM_TRIGGER_KEY|PM_TRIGGER_RTC_ALARM|PM_TRIGGER_COVER_OPEN|PM_TRIGGER_CARD|PM_TRIGGER_CARTRIDGE|PM_TRIGGER_SDIO)
209 #else
210 #define PM_TRIGGER_MASK             (PM_TRIGGER_KEY|PM_TRIGGER_RTC_ALARM|PM_TRIGGER_COVER_OPEN|PM_TRIGGER_CARD|PM_TRIGGER_CARTRIDGE)
211 #endif
212 typedef u32 PMWakeUpTrigger;
213 
214 //---- logic for key interrupt
215 #define PM_PAD_LOGIC_OR    (0 << REG_PAD_KEYCNT_LOGIC_SHIFT)
216 #define PM_PAD_LOGIC_AND   (1 << REG_PAD_KEYCNT_LOGIC_SHIFT)
217 typedef u32 PMLogic;
218 
219 //---- backlight to recover from sleep  (uses in library)
220 #define PM_BACKLIGHT_RECOVER_TOP_SHIFT      6
221 #define PM_BACKLIGHT_RECOVER_BOTTOM_SHIFT   7
222 #define PM_BACKLIGHT_RECOVER_TOP_MASK       (1<<PM_BACKLIGHT_RECOVER_TOP_SHIFT)
223 #define PM_BACKLIGHT_RECOVER_TOP_ON         PM_BACKLIGHT_RECOVER_TOP_MASK
224 #define PM_BACKLIGHT_RECOVER_TOP_OFF        0
225 #define PM_BACKLIGHT_RECOVER_BOTTOM_MASK    (1<<PM_BACKLIGHT_RECOVER_BOTTOM_SHIFT)
226 #define PM_BACKLIGHT_RECOVER_BOTTOM_ON      PM_BACKLIGHT_RECOVER_BOTTOM_MASK
227 #define PM_BACKLIGHT_RECOVER_BOTTOM_OFF     0
228 #define PM_BACKLIGHT_RECOVER_MASK           (PM_BACKLIGHT_RECOVER_TOP_MASK | PM_BACKLIGHT_RECOVER_BOTTOM_MASK)
229 
230 //================================================================
231 //     LED pattern parameter
232 //================================================================
233 //---- LED blink pattern
234 typedef enum
235 {
236     PM_LED_PATTERN_NONE = 0,           // don't care
237     PM_LED_PATTERN_ON = 1,
238     PM_LED_PATTERN_BLINK_LOW = 2,
239     PM_LED_PATTERN_BLINK_HIGH = 3,
240     PM_LED_PATTERN_BLINK1 = 4,
241     PM_LED_PATTERN_BLINK2 = 5,
242     PM_LED_PATTERN_BLINK3 = 6,
243     PM_LED_PATTERN_BLINK4 = 7,
244     PM_LED_PATTERN_BLINK5 = 8,
245     PM_LED_PATTERN_BLINK6 = 9,
246     PM_LED_PATTERN_BLINK8 = 10,
247     PM_LED_PATTERN_BLINK10 = 11,
248     PM_LED_PATTERN_PATTERN1 = 12,
249     PM_LED_PATTERN_PATTERN2 = 13,
250     PM_LED_PATTERN_PATTERN3 = 14,
251     PM_LED_PATTERN_WIRELESS = 15
252 }
253 PMLEDPattern;
254 
255 #define PM_LED_PATTERN_MAX  PM_LED_PATTERN_WIRELESS
256 
257 
258 //---- LED status
259 typedef enum
260 {
261     PM_LED_NONE = 0,                   // dummy
262     PM_LED_ON = 1,
263     PM_LED_BLINK_LOW = 2,
264     PM_LED_BLINK_HIGH = 3
265 }
266 PMLEDStatus;
267 
268 #ifdef SDK_TWL
269 //---- Wireless LED status
270 typedef enum
271 {
272     PM_WIRELESS_LED_OFF = FALSE,
273     PM_WIRELESS_LED_ON  = TRUE
274 }
275 PMWirelessLEDStatus;
276 #endif
277 
278 //================================================================
279 //     BATTERY
280 //================================================================
281 //---- battery level status ( empty: 0, 1,..., 5 : full )
282 typedef u16 PMBatteryLevel;
283 #define PM_BATTERY_LEVEL_MIN      0
284 #define PM_BATTERY_LEVEL_MAX      5
285 
286 
287 //================================================================
288 #ifdef SDK_TWL
289 //---- pm reset flag ID
290 #define   PM_RESET_FLAG_NONE       0
291 #define   PM_RESET_FLAG_FORCED     1
292 
293 //---- amp gain level
294 #define   PM_AMPGAIN_LEVEL_SCALE   120
295 #define   PM_AMPGAIN_LEVEL_MIN     0
296 #define   PM_AMPGAIN_LEVEL_MAX     (PM_AMPGAIN_LEVEL_SCALE - 1)
297 #endif
298 #define   PM_AMPGAIN_LEVEL_DS0     31
299 #define   PM_AMPGAIN_LEVEL_DS1     43
300 #define   PM_AMPGAIN_LEVEL_DS2     55
301 #define   PM_AMPGAIN_LEVEL_DS3     67
302 
303 //---- status of folding
304 #define   PM_READING               -1
305 
306 #define   PM_SUCCESS               0
307 #define   PM_BUSY                  1
308 #define   PM_INVALID_COMMAND       0xffff
309 
310 #define   PM_RESULT_NONE           0xff
311 #define   PM_RESULT_SUCCESS        (PM_SUCCESS)
312 #define   PM_RESULT_BUSY           (PM_BUSY)
313 #define   PM_RESULT_ERROR          2
314 #define   PM_RESULT_NA             3
315 
316 //----status of PXI
317 #define   PM_PXI_RESULT_EXCLUSIVE  0xffff
318 
319 //================================================================
320 
321 
322 #ifdef __cplusplus
323 } /* extern "C" */
324 #endif
325 
326 /* NITRO_PM_COMMON_H_ */
327 #endif
328 
329