hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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
/* SPDX-License-Identifier: GPL-2.0+ */
 
#ifndef __AW87XXX_H__
#define __AW87XXX_H__
#include <linux/version.h>
#include <linux/kernel.h>
#include <sound/control.h>
#include <sound/soc.h>
 
#include "aw_device.h"
#include "aw_monitor.h"
#include "aw_acf_bin.h"
 
#define AW_CFG_UPDATE_DELAY
#define AW_CFG_UPDATE_DELAY_TIMER    (3000)
 
#define AW87XXX_NO_OFF_BIN        (0)
#define AW87XXX_OFF_BIN_OK        (1)
 
#define AW87XXX_KCONTROL_NUM        (2)
 
#define AW_I2C_RETRIES            (5)
#define AW_I2C_RETRY_DELAY        (2)
#define AW_I2C_READ_MSG_NUM        (2)
 
#define AW87XXX_FW_NAME_MAX        (64)
#define AW_NAME_BUF_MAX            (64)
#define AW_LOAD_FW_RETRIES        (3)
 
#define AW_DEV_REG_RD_ACCESS        (1 << 0)
#define AW_DEV_REG_WR_ACCESS        (1 << 1)
 
#define AWRW_ADDR_BYTES            (1)
#define AWRW_DATA_BYTES            (1)
#define AWRW_HDR_LEN            (24)
 
/***********************************************************
 *
 * aw87xxx codec control compatible with kernel 4.19
 *
 ***********************************************************/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 1)
#define AW_KERNEL_VER_OVER_4_19_1
#endif
 
#ifdef AW_KERNEL_VER_OVER_4_19_1
typedef struct snd_soc_component aw_snd_soc_codec_t;
#else
typedef struct snd_soc_codec aw_snd_soc_codec_t;
#endif
 
struct aw_componet_codec_ops {
   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);
};
 
 
/********************************************
 *
 * aw87xxx devices attributes
 *
 *******************************************/
enum {
   AWRW_FLAG_WRITE = 0,
   AWRW_FLAG_READ,
};
 
enum {
   AWRW_I2C_ST_NONE = 0,
   AWRW_I2C_ST_READ,
   AWRW_I2C_ST_WRITE,
};
 
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 aw_i2c_packet {
   char status;
   unsigned int reg_num;
   unsigned int reg_addr;
   char *reg_data;
};
 
 
/********************************************
 *
 * aw87xxx device struct
 *
 *******************************************/
struct aw87xxx {
   char fw_name[AW87XXX_FW_NAME_MAX];
   int32_t dev_index;
   char *current_profile;
   char prof_off_name[AW_PROFILE_STR_MAX];
   uint32_t off_bin_status;
   struct device *dev;
 
   struct mutex reg_lock;
   struct aw_device aw_dev;
   struct aw_i2c_packet i2c_packet;
 
   struct delayed_work fw_load_work;
   struct acf_bin_info acf_info;
 
   aw_snd_soc_codec_t *codec;
 
   struct list_head list;
 
   struct aw_monitor monitor;
};
 
int aw87xxx_update_profile(struct aw87xxx *aw87xxx, char *profile);
int aw87xxx_esd_update_profile(struct aw87xxx *aw87xxx, char *profile);
 
#endif