xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/aw87xxx/aw87xxx.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 
3 #ifndef __AW87XXX_H__
4 #define __AW87XXX_H__
5 #include <linux/version.h>
6 #include <linux/kernel.h>
7 #include <sound/control.h>
8 #include <sound/soc.h>
9 
10 #include "aw_device.h"
11 #include "aw_monitor.h"
12 #include "aw_acf_bin.h"
13 
14 #define AW_CFG_UPDATE_DELAY
15 #define AW_CFG_UPDATE_DELAY_TIMER	(3000)
16 
17 #define AW87XXX_NO_OFF_BIN		(0)
18 #define AW87XXX_OFF_BIN_OK		(1)
19 
20 #define AW87XXX_KCONTROL_NUM		(2)
21 
22 #define AW_I2C_RETRIES			(5)
23 #define AW_I2C_RETRY_DELAY		(2)
24 #define AW_I2C_READ_MSG_NUM		(2)
25 
26 #define AW87XXX_FW_NAME_MAX		(64)
27 #define AW_NAME_BUF_MAX			(64)
28 #define AW_LOAD_FW_RETRIES		(3)
29 
30 #define AW_DEV_REG_RD_ACCESS		(1 << 0)
31 #define AW_DEV_REG_WR_ACCESS		(1 << 1)
32 
33 #define AWRW_ADDR_BYTES			(1)
34 #define AWRW_DATA_BYTES			(1)
35 #define AWRW_HDR_LEN			(24)
36 
37 /***********************************************************
38  *
39  * aw87xxx codec control compatible with kernel 4.19
40  *
41  ***********************************************************/
42 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 1)
43 #define AW_KERNEL_VER_OVER_4_19_1
44 #endif
45 
46 #ifdef AW_KERNEL_VER_OVER_4_19_1
47 typedef struct snd_soc_component aw_snd_soc_codec_t;
48 #else
49 typedef struct snd_soc_codec aw_snd_soc_codec_t;
50 #endif
51 
52 struct aw_componet_codec_ops {
53 	int (*add_codec_controls)(aw_snd_soc_codec_t *codec,
54 		const struct snd_kcontrol_new *controls, unsigned int num_controls);
55 	void (*unregister_codec)(struct device *dev);
56 };
57 
58 
59 /********************************************
60  *
61  * aw87xxx devices attributes
62  *
63  *******************************************/
64 enum {
65 	AWRW_FLAG_WRITE = 0,
66 	AWRW_FLAG_READ,
67 };
68 
69 enum {
70 	AWRW_I2C_ST_NONE = 0,
71 	AWRW_I2C_ST_READ,
72 	AWRW_I2C_ST_WRITE,
73 };
74 
75 enum {
76 	AWRW_HDR_WR_FLAG = 0,
77 	AWRW_HDR_ADDR_BYTES,
78 	AWRW_HDR_DATA_BYTES,
79 	AWRW_HDR_REG_NUM,
80 	AWRW_HDR_REG_ADDR,
81 	AWRW_HDR_MAX,
82 };
83 
84 struct aw_i2c_packet {
85 	char status;
86 	unsigned int reg_num;
87 	unsigned int reg_addr;
88 	char *reg_data;
89 };
90 
91 
92 /********************************************
93  *
94  * aw87xxx device struct
95  *
96  *******************************************/
97 struct aw87xxx {
98 	char fw_name[AW87XXX_FW_NAME_MAX];
99 	int32_t dev_index;
100 	char *current_profile;
101 	char prof_off_name[AW_PROFILE_STR_MAX];
102 	uint32_t off_bin_status;
103 	struct device *dev;
104 
105 	struct mutex reg_lock;
106 	struct aw_device aw_dev;
107 	struct aw_i2c_packet i2c_packet;
108 
109 	struct delayed_work fw_load_work;
110 	struct acf_bin_info acf_info;
111 
112 	aw_snd_soc_codec_t *codec;
113 
114 	struct list_head list;
115 
116 	struct aw_monitor monitor;
117 };
118 
119 int aw87xxx_update_profile(struct aw87xxx *aw87xxx, char *profile);
120 int aw87xxx_esd_update_profile(struct aw87xxx *aw87xxx, char *profile);
121 
122 #endif
123