hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* SPDX-License-Identifier: GPL-2.0+ */
 
#ifndef __AW883XX_H__
#define __AW883XX_H__
 
#include <linux/version.h>
#include <sound/control.h>
#include <sound/soc.h>
#include "aw_device.h"
 
/*#define AW_QCOM_PLATFORM*/
#define AW_MTK_PLATFORM
/*#define AW_SPRD_PLATFORM*/
 
#define AW883XX_CHIP_ID_REG    (0x00)
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 1)
#define AW_KERNEL_VER_OVER_4_19_1
#endif
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
#define AW_KERNEL_VER_OVER_5_4_0
MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
#endif
 
/* i2c transaction on Linux limited to 64k
 * (See Linux kernel documentation: Documentation/i2c/writing-clients)
*/
#define MAX_I2C_BUFFER_SIZE        (65536)
#define AW883XX_READ_MSG_NUM        (2)
 
#define AW_I2C_RETRIES            (5)
#define AW_I2C_RETRY_DELAY        (5)/* 5ms */
 
#define AW_READ_CHIPID_RETRY_DELAY    (5)/* 5ms */
#define AW_START_RETRIES        (5)
 
#define AW883XX_FLAG_START_ON_MUTE    (1 << 0)
#define AW883XX_FLAG_SKIP_INTERRUPTS    (1 << 1)
 
#define AW883XX_I2S_CHECK_MAX        (5)
 
#define AW883XX_SYSST_CHECK_MAX        (10)
 
#define AW883XX_BIN_TYPE_NUM        (3)
#define AW883XX_LOAD_FW_DELAY_TIME    (3000)
#define AW883XX_START_WORK_DELAY_MS    (0)
 
 
#define AW883XX_DSP_16_DATA_MASK    (0x0000ffff)
 
#define AW_GET_IV_CNT_MAX        (6)
#define AW_KCONTROL_NUM            (3)
#define AW_HW_MONITOR_DELAY        (1000)
 
enum {
   AWRW_I2C_ST_NONE = 0,
   AWRW_I2C_ST_READ,
   AWRW_I2C_ST_WRITE,
};
 
enum {
   AWRW_DSP_ST_NONE = 0,
   AWRW_DSP_READY,
};
 
enum {
   AW_SYNC_START = 0,
   AW_ASYNC_START,
};
 
 
#define AWRW_ADDR_BYTES (1)
#define AWRW_DATA_BYTES (2)
#define AWRW_HDR_LEN (24)
 
enum {
   AWRW_FLAG_WRITE = 0,
   AWRW_FLAG_READ,
};
 
enum {
   AWRW_HDR_WR_FLAG = 0,
   AWRW_HDR_ADDR_BYTES,
   AWRW_HDR_DATA_BYTES,
   AWRW_HDR_REG_NUM,
   AWRW_HDR_REG_ADDR,
   AWRW_HDR_MAX,
};
 
struct aw883xx_i2c_packet{
   unsigned char i2c_status;
   unsigned char dsp_status;
   unsigned int reg_num;
   unsigned int reg_addr;
   unsigned int dsp_addr;
   char *reg_data;
};
 
 
 
enum {
   AW883XX_STREAM_CLOSE = 0,
   AW883XX_STREAM_OPEN,
};
 
enum aw883xx_init {
   AW883XX_INIT_ST = 0,
   AW883XX_INIT_OK = 1,
   AW883XX_INIT_NG = 2,
};
 
enum aw_re_range {
   AW_RE_MIN = 1000,
   AW_RE_MAX = 40000,
};
 
 
/********************************************
 *
 * Compatible with codec and component
 *
 *******************************************/
#ifdef AW_KERNEL_VER_OVER_4_19_1
typedef struct snd_soc_component aw_snd_soc_codec_t;
typedef struct snd_soc_component_driver aw_snd_soc_codec_driver_t;
#else
typedef struct snd_soc_codec aw_snd_soc_codec_t;
typedef struct snd_soc_codec_driver aw_snd_soc_codec_driver_t;
#endif
 
struct aw_componet_codec_ops {
   aw_snd_soc_codec_t *(*kcontrol_codec)(struct snd_kcontrol *kcontrol);
   void *(*codec_get_drvdata)(aw_snd_soc_codec_t *codec);
   int (*add_codec_controls)(aw_snd_soc_codec_t *codec,
       const struct snd_kcontrol_new *controls, unsigned int num_controls);
   void (*unregister_codec)(struct device *dev);
   int (*register_codec)(struct device *dev,
           const aw_snd_soc_codec_driver_t *codec_drv,
           struct snd_soc_dai_driver *dai_drv,
           int num_dai);
};
 
struct aw883xx {
   struct i2c_client *i2c;
   struct device *dev;
   struct clk *mclk;
   struct mutex lock;
   struct mutex i2c_lock;
   aw_snd_soc_codec_t *codec;
   struct aw_componet_codec_ops *codec_ops;
   struct aw_device *aw_pa;
 
   int sysclk;
   int reset_gpio;
   int irq_gpio;
 
   unsigned char phase_sync;    /*phase sync*/
   uint32_t allow_pw;
   uint8_t pstream;
   unsigned char fw_retry_cnt;
 
   uint8_t dbg_en_prof;
   uint8_t i2c_log_en;
   uint8_t spin_flag;
 
   struct list_head list;
 
   struct workqueue_struct *work_queue;
   struct delayed_work start_work;
   struct delayed_work monitor_work;
   struct delayed_work interrupt_work;
   struct delayed_work acf_work;
 
   uint8_t reg_addr;
   uint16_t dsp_addr;
   uint16_t chip_id;
   struct aw883xx_i2c_packet i2c_packet;
};
 
int aw883xx_init(struct aw883xx *aw883xx);
int aw883xx_i2c_writes(struct aw883xx *aw883xx,
       uint8_t reg_addr, uint8_t *buf, uint16_t len);
int aw883xx_i2c_write(struct aw883xx *aw883xx,
       uint8_t reg_addr, uint16_t reg_data);
int aw883xx_reg_write(struct aw883xx *aw883xx,
       uint8_t reg_addr, uint16_t reg_data);
int aw883xx_i2c_read(struct aw883xx *aw883xx,
           uint8_t reg_addr, uint16_t *reg_data);
int aw883xx_reg_read(struct aw883xx *aw883xx,
       uint8_t reg_addr, uint16_t *reg_data);
int aw883xx_reg_write_bits(struct aw883xx *aw883xx,
       uint8_t reg_addr, uint16_t mask, uint16_t reg_data);
int aw883xx_dsp_write(struct aw883xx *aw883xx,
       uint16_t dsp_addr, uint32_t dsp_data, uint8_t data_type);
int aw883xx_dsp_read(struct aw883xx *aw883xx,
       uint16_t dsp_addr, uint32_t *dsp_data, uint8_t data_type);
int aw883xx_get_dev_num(void);
int aw883xx_get_version(char *buf, int size);
 
#endif