xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/aw87xxx/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_WAIT_DSP_OPEN_TIME			(3000)
7 #define AW_VBAT_CAPACITY_MIN			(0)
8 #define AW_VBAT_CAPACITY_MAX			(100)
9 #define AW_VMAX_INIT_VAL			(0xFFFFFFFF)
10 #define AW_VBAT_MAX				(100)
11 #define AW_VMAX_MAX				(0)
12 #define AW_DEFAULT_MONITOR_TIME			(3000)
13 #define AW_WAIT_TIME				(3000)
14 #define REG_STATUS_CHECK_MAX			(10)
15 #define AW_ESD_CHECK_DELAY			(1)
16 
17 #define AW_ESD_ENABLE				(true)
18 #define AW_ESD_DISABLE				(false)
19 
20 enum aw_monitor_init {
21 	AW_MONITOR_CFG_WAIT = 0,
22 	AW_MONITOR_CFG_OK = 1,
23 };
24 
25 enum aw_monitor_hdr_info {
26 	AW_MONITOR_HDR_DATA_SIZE = 0x00000004,
27 	AW_MONITOR_HDR_DATA_BYTE_LEN = 0x00000004,
28 };
29 
30 enum aw_monitor_data_ver {
31 	AW_MONITOR_DATA_VER = 0x00000001,
32 	AW_MONITOR_DATA_VER_MAX,
33 };
34 
35 enum aw_monitor_first_enter {
36 	AW_FIRST_ENTRY = 0,
37 	AW_NOT_FIRST_ENTRY = 1,
38 };
39 
40 struct aw_bin_header {
41 	uint32_t check_sum;
42 	uint32_t header_ver;
43 	uint32_t bin_data_type;
44 	uint32_t bin_data_ver;
45 	uint32_t bin_data_size;
46 	uint32_t ui_ver;
47 	char product[8];
48 	uint32_t addr_byte_len;
49 	uint32_t data_byte_len;
50 	uint32_t device_addr;
51 	uint32_t reserve[4];
52 };
53 
54 struct aw_monitor_header {
55 	uint32_t monitor_switch;
56 	uint32_t monitor_time;
57 	uint32_t monitor_count;
58 	uint32_t step_count;
59 	uint32_t reserve[4];
60 };
61 
62 struct vmax_step_config {
63 	uint32_t vbat_min;
64 	uint32_t vbat_max;
65 	int vmax_vol;
66 };
67 
68 struct aw_monitor {
69 	bool open_dsp_en;
70 	bool esd_enable;
71 	int32_t dev_index;
72 	uint8_t first_entry;
73 	uint8_t timer_cnt;
74 	uint32_t vbat_sum;
75 	uint32_t custom_capacity;
76 	uint32_t pre_vmax;
77 
78 	int bin_status;
79 	struct aw_monitor_header monitor_hdr;
80 	struct vmax_step_config *vmax_cfg;
81 
82 	struct delayed_work with_dsp_work;
83 };
84 
85 void aw_monitor_cfg_free(struct aw_monitor *monitor);
86 int aw_monitor_bin_parse(struct device *dev,
87 			char *monitor_data, uint32_t data_len);
88 void aw_monitor_stop(struct aw_monitor *monitor);
89 void aw_monitor_start(struct aw_monitor *monitor);
90 int aw_monitor_no_dsp_get_vmax(struct aw_monitor *monitor,
91 					int32_t *vmax);
92 void aw_monitor_init(struct device *dev, struct aw_monitor *monitor,
93 				struct device_node *dev_node);
94 void aw_monitor_exit(struct aw_monitor *monitor);
95 #endif
96