hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
/* SPDX-License-Identifier: GPL-2.0+ */
 
#ifndef __AWINIC_DEVICE_FILE_H__
#define __AWINIC_DEVICE_FILE_H__
#include "aw_spin.h"
#include "aw_monitor.h"
#include "aw_data_type.h"
#include "aw_calib.h"
 
#define AW_DEV_DEFAULT_CH    (0)
#define AW_DEV_I2S_CHECK_MAX    (5)
#define AW_DEV_DSP_CHECK_MAX    (5)
 
 
/********************************************
 *
 * DSP I2C WRITES
 *
 *******************************************/
#define AW_DSP_I2C_WRITES
#define AW_MAX_RAM_WRITE_BYTE_SIZE    (128)
#define AW_DSP_ODD_NUM_BIT_TEST        (0x5555)
#define AW_DSP_EVEN_NUM_BIT_TEST    (0xAAAA)
#define AW_DSP_ST_CHECK_MAX        (2)
#define AW_FADE_IN_OUT_DEFAULT        (0)
#define AW_CALI_DELAY_CACL(value) ((value * 32) / 48)
 
struct aw_device;
 
enum {
   AW_DEV_VDSEL_DAC = 0,
   AW_DEV_VDSEL_VSENSE = 1,
};
 
enum {
   AW_DSP_CRC_NA = 0,
   AW_DSP_CRC_OK = 1,
};
 
enum {
   AW_DSP_CRC_DISABLE = 0,
   AW_DSP_CRC_ENABLE = 1,
};
 
enum {
   AW_DSP_FW_UPDATE_OFF = 0,
   AW_DSP_FW_UPDATE_ON = 1,
};
 
enum {
   AW_FORCE_UPDATE_OFF = 0,
   AW_FORCE_UPDATE_ON = 1,
};
 
enum {
   AW_1000_US = 1000,
   AW_2000_US = 2000,
   AW_3000_US = 3000,
   AW_4000_US = 4000,
   AW_5000_US = 5000,
   AW_10000_US = 10000,
   AW_100000_US = 100000,
};
 
enum {
   AW_DEV_TYPE_OK = 0,
   AW_DEV_TYPE_NONE = 1,
};
 
 
enum AW_DEV_STATUS {
   AW_DEV_PW_OFF = 0,
   AW_DEV_PW_ON,
};
 
enum AW_DEV_FW_STATUS {
   AW_DEV_FW_FAILED = 0,
   AW_DEV_FW_OK,
};
 
enum AW_DEV_MEMCLK {
   AW_DEV_MEMCLK_OSC = 0,
   AW_DEV_MEMCLK_PLL = 1,
};
 
enum AW_DEV_DSP_CFG {
   AW_DEV_DSP_WORK = 0,
   AW_DEV_DSP_BYPASS = 1,
};
 
enum {
   AW_DSP_16_DATA = 0,
   AW_DSP_32_DATA = 1,
};
 
enum aw_platform {
   AW_QCOM = 0,
   AW_MTK = 1,
   AW_SPRD = 2,
};
 
enum {
   AW_NOT_RCV_MODE = 0,
   AW_RCV_MODE = 1,
};
 
struct aw_device_ops {
   int (*aw_i2c_writes)(struct aw_device *aw_dev, uint8_t reg_addr, uint8_t *buf, uint16_t len);
   int (*aw_i2c_write)(struct aw_device *aw_dev, uint8_t reg_addr, uint16_t reg_data);
   int (*aw_i2c_read)(struct aw_device *aw_dev, uint8_t reg_addr, uint16_t *reg_data);
 
   int (*aw_reg_write)(struct aw_device *aw_dev, uint8_t reg_addr, uint16_t reg_data);
   int (*aw_reg_read)(struct aw_device *aw_dev, uint8_t reg_addr, uint16_t *reg_data);
   int (*aw_reg_write_bits)(struct aw_device *aw_dev, uint8_t reg_addr, uint16_t mask, uint16_t reg_data);
 
   int (*aw_dsp_write)(struct aw_device *aw_dev, uint16_t dsp_addr, uint32_t reg_data, uint8_t data_type);
   int (*aw_dsp_read)(struct aw_device *aw_dev, uint16_t dsp_addr, uint32_t *dsp_data, uint8_t data_type);
   int (*aw_dsp_write_bits)(struct aw_device *aw_dev, uint16_t dsp_addr, uint16_t mask, uint16_t dsp_data);
 
   int (*aw_set_volume)(struct aw_device *aw_dev, uint16_t value);
   int (*aw_get_volume)(struct aw_device *aw_dev, uint16_t *value);
   unsigned int (*aw_reg_val_to_db)(unsigned int value);
 
   void (*aw_i2s_tx_enable)(struct aw_device *aw_dev, bool flag);
   int (*aw_get_dev_num)(void);
 
   bool (*aw_check_wr_access)(int reg);
   bool (*aw_check_rd_access)(int reg);
   int (*aw_get_reg_num)(void);
   int (*aw_get_version)(char *buf, int size);
   int (*aw_read_dsp_pid)(struct aw_device *aw_dev);
   int (*aw_get_hw_mon_st)(struct aw_device *aw_dev, bool *is_enable, uint8_t *temp_flag);
   int (*aw_cali_svc_get_iv_st)(struct aw_device *aw_dev);
   void (*aw_set_cfg_f0_fs)(struct aw_device *aw_dev, uint32_t *f0_fs);
   int (*aw_dsp_fw_check)(struct aw_device *aw_dev);
};
 
struct aw_int_desc {
   unsigned int mask_reg;            /*interrupt mask reg*/
   unsigned int st_reg;            /*interrupt status reg*/
   unsigned int mask_default;        /*default mask close all*/
   unsigned int int_mask;            /*set mask*/
   unsigned int intst_mask;        /*interrupt check mask*/
   uint16_t sysint_st;            /*interrupt reg status*/
};
 
struct aw_pwd_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int enable;
   unsigned int disable;
};
 
struct aw_vcalb_desc {
   unsigned int icalk_reg;
   unsigned int icalk_reg_mask;
   unsigned int icalk_sign_mask;
   unsigned int icalk_neg_mask;
   int icalk_value_factor;
 
   unsigned int vcalk_reg;
   unsigned int vcalk_reg_mask;
   unsigned int vcalk_sign_mask;
   unsigned int vcalk_neg_mask;
   unsigned int vcalk_shift;
   int vcalk_value_factor;
 
   unsigned int vcalb_dsp_reg;
   unsigned char data_type;
   int cabl_base_value;
   int vcal_factor;
   int vscal_factor;
   int iscal_factor;
 
   unsigned int vcalb_adj_shift;
 
   unsigned int vcalb_vsense_reg;
   int vscal_factor_vsense_in;
   int vcalk_value_factor_vsense_in;
   unsigned int vcalk_dac_shift;
   unsigned int vcalk_dac_mask;
   unsigned int vcalk_dac_neg_mask;
   unsigned int vcalk_vdsel_mask;
};
 
struct aw_mute_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int enable;
   unsigned int disable;
};
 
struct aw_sysst_desc {
   unsigned int reg;
   unsigned int st_check;
   unsigned int st_mask;
   unsigned int pll_check;
   unsigned int dsp_check;
   unsigned int dsp_mask;
};
 
struct aw_profctrl_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int rcv_mode_val;
   unsigned int cur_mode;
};
 
struct aw_volume_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int shift;
   int init_volume;
   int mute_volume;
};
 
struct aw_dsp_en_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int enable;
   unsigned int disable;
};
 
struct aw_memclk_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int mcu_hclk;
   unsigned int osc_clk;
};
 
struct aw_watch_dog_desc {
   unsigned int reg;
   unsigned int mask;
};
 
struct aw_dsp_mem_desc {
   unsigned int dsp_madd_reg;
   unsigned int dsp_mdat_reg;
   unsigned int dsp_fw_base_addr;
   unsigned int dsp_cfg_base_addr;
};
 
struct aw_voltage_desc {
   unsigned int reg;
   unsigned int vbat_range;
   unsigned int int_bit;
};
 
struct aw_temperature_desc {
   unsigned int reg;
   unsigned int sign_mask;
   unsigned int neg_mask;
};
 
struct aw_ipeak_desc {
   unsigned int reg;
   unsigned int mask;
};
 
struct aw_vmax_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int init_vmax;
};
 
struct aw_soft_rst {
   uint8_t reg;
   uint16_t reg_value;
};
 
struct aw_cali_cfg_desc {
   unsigned int actampth_reg;
   unsigned char actampth_data_type;
 
   unsigned int noiseampth_reg;
   unsigned char noiseampth_data_type;
 
   unsigned int ustepn_reg;
   unsigned char ustepn_data_type;
 
   unsigned int alphan_reg;
   unsigned int alphan_data_type;
};
 
struct aw_dsp_vol_desc {
   unsigned int reg;
   unsigned int mute_st;
   unsigned int noise_st;
   unsigned int mask;
};
 
struct aw_amppd_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int enable;
   unsigned int disable;
};
 
struct aw_f0_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int shift;
};
 
struct aw_cfgf0_fs_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
};
 
struct aw_q_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int shift;
};
 
struct aw_ra_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
};
 
struct aw_noise_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int mask;
};
 
struct aw_hw_mon_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int mask;
   unsigned int enable;
   unsigned int disable;
};
 
struct aw_ste_re_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int shift;
};
 
struct aw_adpz_re_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int shift;
};
 
struct aw_adpz_t0_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   uint16_t coilalpha_reg;
   unsigned char coil_type;
};
 
struct aw_spkr_temp_desc {
   unsigned int reg;
};
 
struct aw_dsp_crc_desc {
   unsigned int ctl_reg;
   unsigned int ctl_mask;
   unsigned int ctl_enable;
   unsigned int ctl_disable;
 
   unsigned int dsp_reg;
   unsigned char data_type;
};
 
struct aw_cco_mux_desc {
   unsigned int reg;
   unsigned int mask;
   unsigned int divider;
   unsigned int bypass;
};
 
struct aw_hw_temp_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
};
 
struct aw_re_range_desc {
   uint32_t re_min;
   uint32_t re_max;
   uint32_t re_min_default;
   uint32_t re_max_default;
};
 
struct aw_cali_delay_desc {
   unsigned int dsp_reg;
   unsigned char data_type;
   unsigned int delay;
};
 
struct aw_chansel_desc {
   unsigned int rxchan_reg;
   unsigned int rxchan_mask;
   unsigned int txchan_reg;
   unsigned int txchan_mask;
 
   unsigned int rx_left;
   unsigned int rx_right;
   unsigned int tx_left;
   unsigned int tx_right;
};
 
struct aw_tx_en_desc {
   unsigned int tx_en_mask;
   unsigned int tx_disable;
};
 
struct aw_dsp_st {
   unsigned int dsp_reg_s1;
   unsigned int dsp_reg_e1;
 
   unsigned int dsp_reg_s2;
   unsigned int dsp_reg_e2;
};
 
struct aw_container {
   int len;
   uint8_t data[];
};
 
struct aw_device {
   int status;
   struct mutex *i2c_lock;
 
   unsigned char cur_prof;    /*current profile index*/
   unsigned char set_prof;    /*set profile index*/
   unsigned char dsp_crc_st;
   uint16_t chip_id;
 
   unsigned int channel;    /*pa channel select*/
   unsigned int fade_step;
 
   struct i2c_client *i2c;
   struct device *dev;
   char *acf;
   void *private_data;
 
   uint32_t fade_en;
   unsigned char dsp_cfg;
 
   uint32_t dsp_fw_len;
   uint32_t dsp_cfg_len;
   uint8_t platform;
   uint8_t fw_status;    /*load cfg status*/
   struct aw_prof_info prof_info;
   struct aw_sec_data_desc crc_dsp_cfg;
 
   struct aw_int_desc int_desc;
   struct aw_pwd_desc pwd_desc;
   struct aw_mute_desc mute_desc;
   struct aw_vcalb_desc vcalb_desc;
   struct aw_sysst_desc sysst_desc;
   struct aw_profctrl_desc profctrl_desc;
   struct aw_volume_desc volume_desc;
   struct aw_dsp_en_desc dsp_en_desc;
   struct aw_memclk_desc memclk_desc;
   struct aw_watch_dog_desc watch_dog_desc;
   struct aw_dsp_mem_desc dsp_mem_desc;
   struct aw_voltage_desc voltage_desc;
   struct aw_temperature_desc temp_desc;
   struct aw_vmax_desc vmax_desc;
   struct aw_ipeak_desc ipeak_desc;
   struct aw_soft_rst soft_rst;
   struct aw_cali_cfg_desc cali_cfg_desc;
   struct aw_ra_desc ra_desc;
   struct aw_dsp_vol_desc dsp_vol_desc;
   struct aw_noise_desc noise_desc;
   struct aw_f0_desc f0_desc;
   struct aw_cfgf0_fs_desc cfgf0_fs_desc;
   struct aw_q_desc q_desc;
   struct aw_hw_mon_desc hw_mon_desc;
   struct aw_ste_re_desc ste_re_desc;
   struct aw_adpz_re_desc adpz_re_desc;
   struct aw_adpz_t0_desc t0_desc;
   struct aw_amppd_desc amppd_desc;
   struct aw_spkr_temp_desc spkr_temp_desc;
   struct aw_dsp_crc_desc dsp_crc_desc;
   struct aw_cco_mux_desc cco_mux_desc;
   struct aw_hw_temp_desc hw_temp_desc;
 
   struct aw_cali_desc cali_desc;
   struct aw_monitor_desc monitor_desc;
   struct aw_re_range_desc re_range;
   struct aw_spin_desc spin_desc;
   struct aw_chansel_desc chansel_desc;
   struct aw_tx_en_desc tx_en_desc;
   struct aw_cali_delay_desc cali_delay_desc;
   struct aw_dsp_st dsp_st_desc;
 
   struct aw_device_ops ops;
   struct list_head list_node;
};
 
 
void aw_dev_deinit(struct aw_device *aw_dev);
int aw_device_init(struct aw_device *aw_dev, struct aw_container *aw_prof);
int aw_device_start(struct aw_device *aw_dev);
int aw_device_stop(struct aw_device *aw_dev);
 
int aw_dev_fw_update(struct aw_device *aw_dev, bool up_dsp_fw_en, bool force_up_en);
int aw_dev_get_int_status(struct aw_device *aw_dev, uint16_t *int_status);
void aw_dev_set_volume_step(struct aw_device *aw_dev, unsigned int step);
int aw_dev_set_intmask(struct aw_device *aw_dev, bool flag);
void aw_dev_clear_int_status(struct aw_device *aw_dev);
int aw_dev_get_volume_step(struct aw_device *aw_dev);
int aw_device_probe(struct aw_device *aw_dev);
int aw_device_remove(struct aw_device *aw_dev);
int aw_dev_syspll_check(struct aw_device *aw_dev);
int aw_dev_get_dsp_status(struct aw_device *aw_dev);
 
void aw_dev_set_fade_vol_step(struct aw_device *aw_dev, unsigned int step);
int aw_dev_get_fade_vol_step(struct aw_device *aw_dev);
void aw_dev_get_fade_time(unsigned int *time, bool fade_in);
void aw_dev_set_fade_time(unsigned int time, bool fade_in);
int aw_dev_get_hmute(struct aw_device *aw_dev);
int aw_dev_sysst_check(struct aw_device *aw_dev);
int aw_dev_get_list_head(struct list_head **head);
int aw_dev_dsp_check(struct aw_device *aw_dev);
void aw_dev_memclk_select(struct aw_device *aw_dev, unsigned char flag);
void aw_dev_dsp_enable(struct aw_device *aw_dev, bool dsp);
void aw_dev_mute(struct aw_device *aw_dev, bool mute);
int aw_dev_dsp_fw_update(struct aw_device *aw_dev,
           uint8_t *data, uint32_t len);
int aw_dev_dsp_cfg_update(struct aw_device *aw_dev,
           uint8_t *data, uint32_t len);
int aw_dev_modify_dsp_cfg(struct aw_device *aw_dev,
           unsigned int addr, uint32_t dsp_data, unsigned char data_type);
int aw_dev_get_iis_status(struct aw_device *aw_dev);
 
#endif