xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/aw883xx/aw_monitor.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 
3 #ifndef __AW_MONITOR_H__
4 #define __AW_MONITOR_H__
5 
6 /*#define AW_DEBUG*/
7 /*#define AW_SYS_BATTERY_ST*/
8 
9 struct aw_table;
10 
11 #define AW_TABLE_SIZE	sizeof(struct aw_table)
12 #define AW_MONITOR_DEFAULT_FLAG (0)
13 
14 #define IPEAK_NONE	(0xFF)
15 #define GAIN_NONE	(0xFF)
16 #define VMAX_NONE	(0xFFFFFFFF)
17 
18 
19 #define AW_GET_32_DATA(w, x, y, z) \
20 		((uint32_t)((((uint8_t)w) << 24) | (((uint8_t)x) << 16) | (((uint8_t)y) << 8) | ((uint8_t)z)))
21 #define AW_GET_16_DATA(x, y) \
22 		((uint16_t)((((uint8_t)x) << 8) | (uint8_t)y))
23 
24 enum {
25 	AW_MON_LOGIC_OR = 0,
26 	AW_MON_LOGIC_AND = 1,
27 };
28 
29 enum {
30 	AW_FIRST_ENTRY = 0,
31 	AW_NOT_FIRST_ENTRY = 1,
32 };
33 
34 enum aw_monitor_hdr_ver {
35 	AW_MONITOR_HDR_VER_0_1_1 = 0x00010100,
36 };
37 
38 enum aw_monitor_init {
39 	AW_MON_CFG_ST = 0,
40 	AW_MON_CFG_OK = 1,
41 };
42 
43 #define MONITOR_EN_MASK  0x01
44 
45 enum {
46 	MONITOR_EN_BIT = 0,
47 	MONITOR_LOGIC_BIT = 1,
48 	MONITOR_IPEAK_EN_BIT = 2,
49 	MONITOR_GAIN_EN_BIT = 3,
50 	MONITOR_VMAX_EN_BIT = 4,
51 	MONITOR_TEMP_EN_BIT = 5,
52 	MONITOR_VOL_EN_BIT = 6,
53 };
54 
55 enum {
56 	AW_INTERNAL_TEMP = 0,
57 	AW_EXTERNAL_TEMP = 1,
58 };
59 
60 struct aw_monitor_hdr_v_0_1_1 {
61 	uint32_t check_sum;
62 	uint32_t monitor_ver;
63 	char chip_type[16];
64 	uint32_t ui_ver;
65 	uint32_t monitor_time;
66 	uint32_t monitor_count;
67 	uint32_t enable_flag;
68 		/* [bit 31:7]*/
69 		/* [bit 6: vol en]*/
70 		/* [bit 5: temp en]*/
71 		/* [bit 4: vmax en]*/
72 		/* [bit 3: gain en]*/
73 		/* [bit 2: ipeak en]*/
74 		/* [bit 1: & or | flag]*/
75 		/* [bit 0: monitor en]*/
76 	uint32_t temp_aplha;
77 	uint32_t temp_num;
78 	uint32_t single_temp_size;
79 	uint32_t temp_offset;
80 	uint32_t vol_aplha;
81 	uint32_t vol_num;
82 	uint32_t single_vol_size;
83 	uint32_t vol_offset;
84 	uint32_t reserver[3];
85 };
86 
87 struct aw_table {
88 	int16_t min_val;
89 	int16_t max_val;
90 	uint16_t ipeak;
91 	uint16_t gain;
92 	uint32_t vmax;
93 };
94 
95 struct aw_table_info {
96 	uint8_t table_num;
97 	struct aw_table *aw_table;
98 };
99 
100 struct aw_monitor_cfg {
101 	uint8_t monitor_status;
102 	uint32_t monitor_switch;
103 	uint32_t monitor_time;
104 	uint32_t monitor_count;
105 	uint32_t logic_switch;
106 	uint32_t temp_switch;
107 	uint32_t temp_aplha;
108 	uint32_t vol_switch;
109 	uint32_t vol_aplha;
110 	uint32_t ipeak_switch;
111 	uint32_t gain_switch;
112 	uint32_t vmax_switch;
113 	struct aw_table_info temp_info;
114 	struct aw_table_info vol_info;
115 };
116 
117 struct aw_monitor_trace {
118 	int32_t pre_val;
119 	int32_t sum_val;
120 	struct aw_table aw_table;
121 };
122 
123 
124 /******************************************************************
125 * struct aw882xx monitor
126 *******************************************************************/
127 struct aw_monitor_desc {
128 	struct delayed_work delay_work;
129 	struct delayed_work hw_monitor_work;
130 	struct aw_monitor_cfg monitor_cfg;
131 	bool hw_mon_en;
132 
133 	uint8_t hw_temp_flag;
134 	uint8_t first_entry;
135 	uint8_t samp_count;
136 	uint32_t pre_vmax;
137 	uint32_t hw_monitor_delay;
138 
139 	struct aw_monitor_trace temp_trace;
140 	struct aw_monitor_trace vol_trace;
141 
142 #ifdef AW_DEBUG
143 	uint16_t test_vol;
144 	int16_t test_temp;
145 #endif
146 };
147 
148 /******************************************************************
149 * aw882xx monitor functions
150 *******************************************************************/
151 void aw_monitor_start(struct aw_monitor_desc *monitor_desc);
152 int aw_monitor_stop(struct aw_monitor_desc *monitor_desc);
153 void aw_monitor_init(struct aw_monitor_desc *monitor_desc);
154 void aw_monitor_deinit(struct aw_monitor_desc *monitor_desc);
155 int aw_monitor_parse_fw(struct aw_monitor_desc *monitor_desc,
156 				uint8_t *data, uint32_t data_len);
157 
158 #endif
159 
160