1 #ifndef __UAPI_MFD_MSM_ADIE_CODEC_H
2 #define __UAPI_MFD_MSM_ADIE_CODEC_H
3 
4 #include <linux/types.h>
5 
6 /* Value Represents a entry */
7 #define ADIE_CODEC_ACTION_ENTRY       0x1
8 /* Value representing a delay wait */
9 #define ADIE_CODEC_ACTION_DELAY_WAIT      0x2
10 /* Value representing a stage reached */
11 #define ADIE_CODEC_ACTION_STAGE_REACHED   0x3
12 
13 /* This value is the state after the client sets the path */
14 #define ADIE_CODEC_PATH_OFF                                        0x0050
15 
16 /* State to which client asks the drv to proceed to where it can
17  * set up the clocks and 0-fill PCM buffers
18  */
19 #define ADIE_CODEC_DIGITAL_READY                                   0x0100
20 
21 /* State to which client asks the drv to proceed to where it can
22  * start sending data after internal steady state delay
23  */
24 #define ADIE_CODEC_DIGITAL_ANALOG_READY                            0x1000
25 
26 
27 /*  Client Asks adie to switch off the Analog portion of the
28  *  the internal codec. After the use of this path
29  */
30 #define ADIE_CODEC_ANALOG_OFF                                      0x0750
31 
32 
33 /* Client Asks adie to switch off the digital portion of the
34  *  the internal codec. After switching off the analog portion.
35  *
36  *  0-fill PCM may or maynot be sent at this point
37  *
38  */
39 #define ADIE_CODEC_DIGITAL_OFF                                     0x0600
40 
41 /* State to which client asks the drv to write the default values
42  * to the registers
43  */
44 #define ADIE_CODEC_FLASH_IMAGE                                     0x0001
45 
46 /* Path type */
47 #define ADIE_CODEC_RX 0
48 #define ADIE_CODEC_TX 1
49 #define ADIE_CODEC_LB 3
50 #define ADIE_CODEC_MAX 4
51 
52 #define ADIE_CODEC_PACK_ENTRY(reg, mask, val) ((val)|(mask << 8)|(reg << 16))
53 
54 #define ADIE_CODEC_UNPACK_ENTRY(packed, reg, mask, val) \
55 	do { \
56 		((reg) = ((packed >> 16) & (0xff))); \
57 		((mask) = ((packed >> 8) & (0xff))); \
58 		((val) = ((packed) & (0xff))); \
59 	} while (0);
60 
61 struct adie_codec_action_unit {
62 	u32 type;
63 	u32 action;
64 };
65 
66 struct adie_codec_hwsetting_entry {
67 	struct adie_codec_action_unit *actions;
68 	u32 action_sz;
69 	u32 freq_plan;
70 	u32 osr;
71 	/* u32  VolMask;
72 	 * u32  SidetoneMask;
73 	 */
74 };
75 
76 struct adie_codec_dev_profile {
77 	u32 path_type; /* RX or TX */
78 	u32 setting_sz;
79 	struct adie_codec_hwsetting_entry *settings;
80 };
81 
82 struct adie_codec_register {
83 	u8 reg;
84 	u8 mask;
85 	u8 val;
86 };
87 
88 struct adie_codec_register_image {
89 	struct adie_codec_register *regs;
90 	u32 img_sz;
91 };
92 
93 struct adie_codec_path;
94 
95 struct adie_codec_anc_data {
96 	u32 size;
97 	u32 writes[];
98 };
99 
100 struct adie_codec_operations {
101 	int	 codec_id;
102 	int (*codec_open)(struct adie_codec_dev_profile *profile,
103 				struct adie_codec_path **path_pptr);
104 	int (*codec_close)(struct adie_codec_path *path_ptr);
105 	int (*codec_setpath)(struct adie_codec_path *path_ptr,
106 				u32 freq_plan, u32 osr);
107 	int (*codec_proceed_stage)(struct adie_codec_path *path_ptr,
108 					u32 state);
109 	u32 (*codec_freq_supported)(struct adie_codec_dev_profile *profile,
110 					u32 requested_freq);
111 	int (*codec_enable_sidetone)(struct adie_codec_path *rx_path_ptr,
112 					u32 enable);
113 	int (*codec_enable_anc)(struct adie_codec_path *rx_path_ptr,
114 		u32 enable, struct adie_codec_anc_data *calibration_writes);
115 	int (*codec_set_device_digital_volume)(
116 					struct adie_codec_path *path_ptr,
117 					u32 num_channels,
118 					u32 vol_percentage);
119 
120 	int (*codec_set_device_analog_volume)(struct adie_codec_path *path_ptr,
121 						u32 num_channels,
122 						u32 volume);
123 	int (*codec_set_master_mode)(struct adie_codec_path *path_ptr,
124 					u8 master);
125 };
126 
127 int adie_codec_register_codec_operations(
128 				const struct adie_codec_operations *codec_ops);
129 int adie_codec_open(struct adie_codec_dev_profile *profile,
130 	struct adie_codec_path **path_pptr);
131 int adie_codec_setpath(struct adie_codec_path *path_ptr,
132 	u32 freq_plan, u32 osr);
133 int adie_codec_proceed_stage(struct adie_codec_path *path_ptr, u32 state);
134 int adie_codec_close(struct adie_codec_path *path_ptr);
135 u32 adie_codec_freq_supported(struct adie_codec_dev_profile *profile,
136 							u32 requested_freq);
137 int adie_codec_enable_sidetone(struct adie_codec_path *rx_path_ptr, u32 enable);
138 int adie_codec_enable_anc(struct adie_codec_path *rx_path_ptr, u32 enable,
139 	struct adie_codec_anc_data *calibration_writes);
140 int adie_codec_set_device_digital_volume(struct adie_codec_path *path_ptr,
141 		u32 num_channels, u32 vol_percentage /* in percentage */);
142 
143 int adie_codec_set_device_analog_volume(struct adie_codec_path *path_ptr,
144 		u32 num_channels, u32 volume /* in percentage */);
145 
146 int adie_codec_set_master_mode(struct adie_codec_path *path_ptr, u8 master);
147 #endif
148