coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pmic_wrap_common.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef SOC_MEDIATEK_PMIC_WRAP_COMMON_H
4 #define SOC_MEDIATEK_PMIC_WRAP_COMMON_H
5 
6 #include <console/console.h>
7 
8 #define PWRAPTAG "[PWRAP] "
9 #define pwrap_err(fmt, arg ...) printk(BIOS_ERR, PWRAPTAG "ERROR,line=%d" fmt, \
10  __LINE__, ## arg)
11 
12 /* external API */
13 s32 pwrap_wacs2(u32 write, u16 adr, u16 wdata, u16 *rdata, u32 init_check);
14 s32 pwrap_init(void);
15 static inline s32 pwrap_read(u16 addr, u16 *rdata)
16 {
17  return pwrap_wacs2(0, addr, 0, rdata, 1);
18 }
19 
20 static inline s32 pwrap_write(u16 addr, u16 wdata)
21 {
22  return pwrap_wacs2(1, addr, wdata, 0, 1);
23 }
24 
25 static inline u16 pwrap_read_field(u16 reg, u16 mask, u16 shift)
26 {
27  u16 rdata;
28 
29  pwrap_read(reg, &rdata);
30  rdata &= (mask << shift);
31  rdata = (rdata >> shift);
32 
33  return rdata;
34 }
35 
36 static inline void pwrap_write_field(u16 reg, u16 val, u16 mask, u16 shift)
37 {
38  u16 old, new;
39 
40  pwrap_read(reg, &old);
41  new = old & ~(mask << shift);
42  new |= (val << shift);
43  pwrap_write(reg, new);
44 }
45 
46 /* internal API */
48 
49 static inline s32 pwrap_read_nochk(u16 addr, u16 *rdata)
50 {
51  return pwrap_wacs2(0, addr, 0, rdata, 0);
52 }
53 
54 static inline s32 pwrap_write_nochk(u16 addr, u16 wdata)
55 {
56  return pwrap_wacs2(1, addr, wdata, 0, 0);
57 }
58 
59 /* dewrapper default value */
60 enum {
62  WRITE_TEST_VALUE = 0xa55a
63 };
64 
65 /* timeout setting */
66 enum {
69 };
70 
71 /* manual command */
72 enum {
73  OP_WR = 0x1,
74  OP_CSH = 0x0,
75  OP_CSL = 0x1,
76  OP_OUTS = 0x8,
77 };
78 
79 enum {
86 };
87 
88 enum {
89  RDATA_INIT_DONE_V2_SHIFT = 22, /* 8186 */
90  RDATA_SYS_IDLE_V2_SHIFT = 23, /* 8186 */
91 };
92 
93 enum {
100 };
101 
102 /* WACS_FSM */
103 enum {
105  WACS_FSM_REQ = 0x02,
106  WACS_FSM_WFDLE = 0x04, /* wait for dle, wait for read data done */
107  WACS_FSM_WFVLDCLR = 0x06, /* finish read data, wait for valid flag
108  * clearing */
111  WACS_SYNC_BUSY = 0x00
112 };
113 
114 /* error information flag */
115 enum {
141  E_PWR_SWITCH_DIO = 32
142 };
143 
145 
146 static inline u32 wait_for_fsm_vldclr(u32 x)
147 {
148  return ((x >> RDATA_WACS_FSM_SHIFT) & RDATA_WACS_FSM_MASK) !=
150 }
151 
152 static inline u32 wait_for_sync(u32 x)
153 {
154  return ((x >> RDATA_SYNC_IDLE_SHIFT) & RDATA_SYNC_IDLE_MASK) !=
156 }
157 
159 {
160  return ((((x >> RDATA_WACS_FSM_SHIFT) & RDATA_WACS_FSM_MASK) !=
163 }
164 
166 {
167  return x != 3;
168 }
169 
170 u32 wait_for_state_idle(u32 timeout_us, void *wacs_register,
171  void *wacs_vldclr_register, u32 *read_reg);
172 
174  void *wacs_register, u32 *read_reg);
175 
176 #endif /* SOC_MEDIATEK_PMIC_WRAP_COMMON_H */
static u32 addr
Definition: cirrus.c:14
int x
Definition: edid.c:994
static s32 pwrap_write_nochk(u16 addr, u16 wdata)
static u32 wait_for_sync(u32 x)
s32 pwrap_reset_spislv(void)
Definition: pmic_wrap.c:66
u32(* loop_condition_fp)(u32)
static u32 wait_for_idle_and_sync(u32 x)
@ WACS_FSM_REQ
@ WACS_FSM_WFDLE
@ WACS_SYNC_BUSY
@ WACS_FSM_WFVLDCLR
@ WACS_SYNC_IDLE
@ WACS_INIT_DONE
@ WACS_FSM_IDLE
@ RDATA_SYS_IDLE_V2_SHIFT
@ RDATA_INIT_DONE_V2_SHIFT
@ WRITE_TEST_VALUE
@ DEFAULT_VALUE_READ_TEST
@ RDATA_WACS_FSM_MASK
@ RDATA_SYNC_IDLE_MASK
@ RDATA_WACS_REQ_MASK
@ RDATA_SYS_IDLE_MASK
@ RDATA_WACS_RDATA_MASK
@ RDATA_INIT_DONE_MASK
u32 wait_for_state_ready(loop_condition_fp fp, u32 timeout_us, void *wacs_register, u32 *read_reg)
Definition: pmic_wrap.c:46
static s32 pwrap_read_nochk(u16 addr, u16 *rdata)
u32 wait_for_state_idle(u32 timeout_us, void *wacs_register, void *wacs_vldclr_register, u32 *read_reg)
Definition: pmic_wrap.c:7
@ RDATA_WACS_FSM_SHIFT
@ RDATA_INIT_DONE_V1_SHIFT
@ RDATA_WACS_REQ_SHIFT
@ RDATA_WACS_RDATA_SHIFT
@ RDATA_SYS_IDLE_V1_SHIFT
@ RDATA_SYNC_IDLE_SHIFT
s32 pwrap_init(void)
Definition: pmic_wrap.c:154
s32 pwrap_wacs2(u32 write, u16 adr, u16 wdata, u16 *rdata, u32 init_check)
Definition: pmic_wrap.c:99
@ OP_OUTS
@ OP_WR
@ OP_CSH
@ OP_CSL
static s32 pwrap_read(u16 addr, u16 *rdata)
static u32 wait_for_cipher_ready(u32 x)
static u32 wait_for_fsm_vldclr(u32 x)
@ E_PWR_RESET_TIMEOUT
@ E_PWR_INIT_SIDLY_FAIL
@ E_PWR_SWITCH_DIO
@ E_PWR_INIT_SIDLY
@ E_PWR_INIT_ENABLE_PMIC
@ E_PWR_INIT_DIO
@ E_PWR_WAIT_IDLE_TIMEOUT_READ
@ E_PWR_INIT_CIPHER
@ E_PWR_INVALID_OP_MANUAL
@ E_PWR_NOT_IDLE_STATE
@ E_PWR_READ_TEST_FAIL
@ E_PWR_WAIT_IDLE_TIMEOUT
@ E_PWR_WRITE_TEST_FAIL
@ E_PWR_INVALID_ARG
@ E_PWR_INVALID_RW
@ E_PWR_INIT_WRITE_TEST
@ E_PWR_INIT_REG_CLOCK
@ E_PWR_NOT_INIT_DONE_READ
@ E_PWR_NOT_INIT_DONE
@ E_PWR_INVALID_WDAT
@ E_PWR_INVALID_ADDR
@ E_PWR_INIT_ENABLE_EVENT
@ E_PWR_INIT_ENABLE_DEWRAP
@ E_PWR_TIMEOUT
@ E_PWR_INIT_ENABLE_CRC
@ E_PWR_INIT_RESET_SPI
static u16 pwrap_read_field(u16 reg, u16 mask, u16 shift)
static s32 pwrap_write(u16 addr, u16 wdata)
static void pwrap_write_field(u16 reg, u16 val, u16 mask, u16 shift)
@ TIMEOUT_READ_US
@ TIMEOUT_WAIT_IDLE_US
static const int mask[4]
Definition: gpio.c:308
static void read_reg(const void *src, void *value, uint32_t size)
Definition: spi.c:230
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
int32_t s32
Definition: stdint.h:50
u8 val
Definition: sys.c:300