xref: /rk3399_ARM-atf/plat/mediatek/drivers/spmi/spmi_sw.h (revision cf2df874cd09305ac7282fadb0fef6be597dfffb)
1 /*
2  * Copyright (c) 2025, Mediatek Inc. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef SPMI_SW_H
8 #define SPMI_SW_H
9 
10 #include <common/debug.h>
11 #include <drivers/delay_timer.h>
12 #include <mt_timer.h>
13 
14 enum spmi_regs {
15 	SPMI_OP_ST_CTRL,
16 	SPMI_GRP_ID_EN,
17 	SPMI_OP_ST_STA,
18 	SPMI_MST_SAMPL,
19 	SPMI_MST_REQ_EN,
20 	/* RCS support */
21 	SPMI_RCS_CTRL,
22 	SPMI_SLV_3_0_EINT,
23 	SPMI_SLV_7_4_EINT,
24 	SPMI_SLV_B_8_EINT,
25 	SPMI_SLV_F_C_EINT,
26 	SPMI_REC_CTRL,
27 	SPMI_REC0,
28 	SPMI_REC1,
29 	SPMI_REC2,
30 	SPMI_REC3,
31 	SPMI_REC4,
32 	SPMI_REC_CMD_DEC,
33 	SPMI_DEC_DBG,
34 	SPMI_MST_DBG
35 };
36 
37 /* DEBUG MARCO */
38 #define SPMITAG			"[SPMI] "
39 #define SPMI_ERR(fmt, arg...)	ERROR(SPMITAG fmt, ##arg)
40 #define SPMI_ERRL(fmt, arg...)	ERROR(fmt, ##arg)
41 #define SPMI_INFO(fmt, arg...)	INFO(SPMITAG fmt, ##arg)
42 
43 #define wait_us(cond, timeout)			\
44 ({						\
45 	uint64_t __now, __end, __ret;		\
46 						\
47 	__end = sched_clock() + timeout;	\
48 	for (;;) {				\
49 		if (cond) {			\
50 			__ret = timeout;	\
51 			break;			\
52 		}				\
53 		__now = sched_clock();		\
54 		if (__end <= __now) {		\
55 			__ret = 0;		\
56 			break;			\
57 		}				\
58 	}					\
59 	__ret;					\
60 })
61 
62 enum {
63 	SPMI_RESET = 0,
64 	SPMI_SLEEP,
65 	SPMI_SHUTDOWN,
66 	SPMI_WAKEUP
67 };
68 
69 #endif
70