ASoC: es8323: update codec es8323 driver
[firefly-linux-kernel-4.4.55.git] / sound / soc / codecs / aic3xxx_cfw.h
1 /**
2  * \file Codec Firmware Declarations
3  */
4
5 #ifndef CFW_FIRMWARE_H_
6 #define CFW_FIRMWARE_H_
7
8 /** \defgroup bt Basic Types */
9 /* @{ */
10 #ifndef AIC3XXX_CFW_HOST_BLD
11 #include <asm-generic/int-ll64.h>
12 #else
13 typedef unsigned char u8;
14 typedef unsigned short int u16;
15 typedef unsigned long  int u32;
16 #endif
17 typedef signed char i8;
18 typedef signed short int i16;
19 typedef signed long  int i32;
20
21 #define CFW_FW_MAGIC 0xC0D1F1ED
22 /* @} */
23
24
25 /** \defgroup pd Arbitrary Limitations */
26 /* @{ */
27 #ifndef CFW_MAX_ID
28 #    define CFW_MAX_ID          (64)    ///<Max length of string identifies
29 #endif
30 #ifndef CFW_MAX_DESC
31 #   define  CFW_MAX_DESC        (512)   ///<Max length of description
32 #endif
33 #ifndef CFW_MAX_NOVLY
34 #    define CFW_MAX_NOVLY       (4)     ///<Max number of overlays per PFW
35 #endif
36
37 #ifndef CFW_MAX_NCFG
38 #    define CFW_MAX_NCFG        (16)    ///<Max number of configurations per PFW
39 #endif
40
41 #ifndef CFW_MAX_TRANSITIONS
42 #    define CFW_MAX_TRANSITIONS (32)    ///<max number of pre-defined transition
43 #endif
44
45 #ifndef CFW_MAX_NPFW
46 #    define CFW_MAX_NPFW        (16)    ///<Max number fo process flows
47 #endif
48
49 #ifndef CFW_MAX_MODES
50 #    define CFW_MAX_MODES       (32)    ///<Max number of modes
51 #endif
52
53 #ifndef CFW_MAX_ASI
54 #    define CFW_MAX_ASI         (4)     ///<Max number ASIs in a single device
55 #endif
56
57 /* @} */
58
59
60
61 /** \defgroup st Enums, Flags, Macros and Supporting Types */
62 /* @{ */
63
64 /**
65  * Sample rate bitmask
66  *
67  */ 
68 enum cfw_fs {
69     CFW_FS_8KHZ     = 0x0001u,
70     CFW_FS_11KHZ    = 0x0002u,
71     CFW_FS_16KHZ    = 0x0004u,
72     CFW_FS_22KHZ    = 0x0008u,
73     CFW_FS_24KHZ    = 0x0010u,
74     CFW_FS_32KHZ    = 0x0020u,
75     CFW_FS_44KHZ    = 0x0040u,
76     CFW_FS_48KHZ    = 0x0080u,
77     CFW_FS_88KHZ    = 0x0100u,
78     CFW_FS_96KHZ    = 0x0200u,
79     CFW_FS_176KHZ   = 0x0400u,
80     CFW_FS_192KHZ   = 0x0800u,
81     CFW_FS_ANY      = 0x8000u,
82     CFW_FS_ALL      = 0x0FFFu,
83 };
84
85 /**
86  * Sample rate index
87  *
88  */
89 enum cfw_fsi {
90     CFW_FSI_8KHZ,
91     CFW_FSI_11KHZ,
92     CFW_FSI_16KHZ,
93     CFW_FSI_22KHZ,
94     CFW_FSI_24KHZ,
95     CFW_FSI_32KHZ,
96     CFW_FSI_44KHZ,
97     CFW_FSI_48KHZ,
98     CFW_FSI_88KHZ,
99     CFW_FSI_96KHZ,
100     CFW_FSI_176KHZ,
101     CFW_FSI_192KHZ,
102     CFW_FSI_ANY = 15,
103 };
104
105
106 /**
107  * Device Family Identifier
108  *
109  */
110 typedef enum __attribute__ ((__packed__)) cfw_dfamily {
111     CFW_DFM_TYPE_A,
112     CFW_DFM_TYPE_B,
113     CFW_DFM_TYPE_C
114 } cfw_dfamily;
115
116 /**
117  * Device Identifier
118  *
119  */
120 typedef enum __attribute__ ((__packed__)) cfw_device {
121     CFW_DEV_DAC3120,
122     CFW_DEV_DAC3100,
123
124     CFW_DEV_AIC3120,
125     CFW_DEV_AIC3100,
126     CFW_DEV_AIC3110,
127     CFW_DEV_AIC3111,
128
129     CFW_DEV_AIC36,
130
131     CFW_DEV_AIC3206,
132     CFW_DEV_AIC3204,
133     CFW_DEV_AIC3254,
134     CFW_DEV_AIC3256,
135     CFW_DEV_AIC3253,
136     
137     CFW_DEV_AIC3212,
138     CFW_DEV_AIC3262,
139     CFW_DEV_AIC3017,
140     CFW_DEV_AIC3008,
141
142 } cfw_device;
143
144 /**
145  * Transition Sequence Identifier
146  *
147  */
148 typedef enum cfw_transition_t {
149     CFW_TRN_INIT,
150     CFW_TRN_RESUME,
151     CFW_TRN_NEUTRAL,
152     CFW_TRN_SUSPEND,
153     CFW_TRN_EXIT,
154     CFW_TRN_N
155 } cfw_transition_t;
156 static const char * const cfw_transition_id[] = {
157     [CFW_TRN_INIT] "INIT",
158     [CFW_TRN_RESUME] "RESUME",
159     [CFW_TRN_NEUTRAL] "NEUTRAL",
160     [CFW_TRN_SUSPEND] "SUSPEND",
161     [CFW_TRN_EXIT] "EXIT",
162 };
163
164 /* @} */
165
166 /** \defgroup ds Data Structures */
167 /* @{ */
168
169
170 /**
171 * CFW Meta Command
172 * These commands do not appear in the register
173 * set of the device.
174 * Mainly delay, wait and set_bits.
175 */
176 typedef enum __attribute__ ((__packed__)) cfw_meta_cmd {
177     CFW_META_DELAY = 0x80,
178     CFW_META_UPDTBITS,
179     CFW_META_WAITBITS,
180     CFW_META_LOCK,
181 } cfw_meta_cmd;
182
183 /**
184 * CFW Delay
185 * Used for the meta command delay
186 * Has one parameter of delay time in ms
187 */
188 typedef struct cfw_meta_delay {
189     u16 delay;
190     cfw_meta_cmd mcmd;
191     u8  unused1;
192 } cfw_meta_delay;
193
194 /**
195 * CFW set_bits or wait
196 * Both these meta commands have same arguments
197 * mcmd will be used to specify which command it is
198 * has parameters of book, page, offset and mask
199 */
200 typedef struct cfw_meta_bitop {
201     u16 unused1;
202     cfw_meta_cmd mcmd;
203     u8   mask;
204 } cfw_meta_bitop;
205
206 /**
207 * CFW meta register
208 * Contains the data structures for the meta commands
209 */
210 typedef union cfw_meta_register {
211     struct {
212         u16 unused1;
213         cfw_meta_cmd mcmd;
214         u8 unused2;
215     };
216     cfw_meta_delay delay;
217     cfw_meta_bitop bitop;
218 } cfw_meta_register;
219
220
221 /**
222  * CFW Register
223  *
224  * A single reg write
225  *
226  */
227 typedef union cfw_register {
228     struct {
229         u8 book;
230         u8 page;
231         u8 offset;
232         u8 data;
233     };
234     u32 bpod;
235     cfw_meta_register meta;
236 } cfw_register;
237
238 /**
239  * CFW Burst
240  *
241  * A single I2C/SPI burst write sequence
242  *
243  */
244 typedef struct cfw_burst {
245     u32 length;
246     union {
247         cfw_register reg;
248         struct {
249             u8 bpo[3];
250             u8 data[1];
251         };
252     };
253 } cfw_burst;
254
255
256
257 /**
258  * CFW Command
259  *
260  * Can be a either a
261  *      -# single register write, 
262  *      -# a burst write, or
263  *      -# meta-command 
264  *
265  */
266 typedef union cfw_cmd {
267     cfw_register reg;
268     cfw_burst    *burst;
269 }  cfw_cmd;
270
271
272 /**
273  * CFW Block Type
274  *
275  * Block identifier
276  *
277  */
278 typedef enum __attribute__ ((__packed__)) cfw_block_t {
279     CFW_BLOCK_SYSTEM_PRE,
280     CFW_BLOCK_A_INST,
281     CFW_BLOCK_A_A_COEF,
282     CFW_BLOCK_A_B_COEF,
283     CFW_BLOCK_A_F_COEF,
284     CFW_BLOCK_D_INST,
285     CFW_BLOCK_D_A1_COEF,
286     CFW_BLOCK_D_B1_COEF,
287     CFW_BLOCK_D_A2_COEF,
288     CFW_BLOCK_D_B2_COEF,
289     CFW_BLOCK_D_F_COEF,
290     CFW_BLOCK_SYSTEM_POST,
291     CFW_BLOCK_N,
292     CFW_BLOCK_BURSTS = 0x80
293 } cfw_block_t;
294 #define CFW_BLOCK_BURSTS(x) ((x)&CFW_BLOCK_BURSTS)
295 #define CFW_BLOCK_D_A_COEF CFW_BLOCK_D_A1_COEF
296 #define CFW_BLOCK_D_B_COEF CFW_BLOCK_D_B1_COEF
297
298 /**
299  * CFW Block
300  *
301  * A block of logically grouped sequences/commands/meta-commands
302  *
303  */
304 typedef struct cfw_block  {
305     cfw_block_t type;
306     int ncmds;
307     cfw_cmd cmd[1];
308 } cfw_block;
309
310
311 /**
312  * CFW Image
313  *
314  * A downloadable image
315  */
316 typedef struct cfw_image {
317     char name[CFW_MAX_ID];  ///< Name of the pfw/overlay/configuration
318     char desc[CFW_MAX_DESC];    ///< User string
319     cfw_block *block[CFW_BLOCK_N];
320 } cfw_image;
321
322
323 /**
324  * Sysclk source
325  *
326  */
327 typedef enum __attribute__ ((__packed__)) cfw_sclk_source {
328     CFW_SYSCLK_MCLK1,
329     CFW_SYSCLK_MCLK2,
330     CFW_SYSCLK_BCLK1,
331     CFW_SYSCLK_GPIO1,
332     CFW_SYSCLK_PLL_CLK,
333     CFW_SYSCLK_BCLK2,
334     CFW_SYSCLK_GPI1,
335     CFW_SYSCLK_HF_REF_CLK,
336     CFW_SYSCLK_HF_OSC_CLK,
337     CFW_SYSCLK_GPIO2,
338     CFW_SYSCLK_GPI2,
339 } cfw_sclk_source;
340
341     
342 /**
343  * Process flow
344  *
345  * Complete description of a process flow
346  */
347 typedef struct cfw_pfw {
348     char name[CFW_MAX_ID];  ///< Name of the process flow
349     char desc[CFW_MAX_DESC];    ///< User string
350     u32 version;
351     u16 supported_fs;       ///< Sampling  rates at which this process flow may run (bit mask; see \ref cfw_fs)
352     u8  prb_a;
353     u8  prb_d;
354     int novly;              ///< Number of overlays (1 or more)
355     int ncfg;              ///< Number of configurations (0 or more)
356     cfw_block *pll;
357     cfw_image *base;           ///< Base sequence
358     cfw_image *ovly_cfg[CFW_MAX_NOVLY][CFW_MAX_NCFG]; ///< Overlay and cfg
359                                                 ///< patches (if any)
360 } cfw_pfw;
361
362
363 /**
364  * Process transition
365  *
366  * Sequence for specific state transisitions within the driver
367  *
368  */
369 typedef struct cfw_transition {
370     u32 id;
371     char name[CFW_MAX_ID];  ///< Name of the transition    
372     char desc[CFW_MAX_DESC];    ///< User string
373     cfw_block *block;
374 } cfw_transition;
375
376 /**
377  * Device audio mode
378  *
379  * Structure linking various operating modes to process flows,
380  * configurations and sequences
381  *
382  */
383 typedef struct cfw_mode {
384     u32 id;
385     char name[CFW_MAX_ID];
386     char desc[CFW_MAX_DESC];    ///< User string
387     u32 flags;
388     u8  pfw;
389     u8  ovly;
390     u8  cfg;
391     u32 supported_cfgs;
392     cfw_block *entry;
393     cfw_block *exit;
394 } cfw_mode;
395
396 /**
397  * CFW Project 
398  *
399  * Top level structure describing the CFW project
400  */
401 typedef struct cfw_project {
402     u32 magic;
403     u32 bmagic;
404     u32 size;
405     u32 cksum;
406     u32 version;
407     u32 tstamp;
408     char name[CFW_MAX_ID];      ///< Project name
409     char desc[CFW_MAX_DESC];    ///< User string
410     cfw_dfamily dfamily;
411     cfw_device  device;
412     u32  flags;
413     cfw_sclk_source clksrc;     ///< Clock source
414     u32  clkfreq;               ///< Clock frequency
415     cfw_transition *transition[CFW_MAX_TRANSITIONS];
416     u16  npfw;                  ///< Number of process flows
417     u16  nmode;                  ///< Number of operating modes
418     cfw_pfw  *pfw[CFW_MAX_NPFW]; ///< Indices to PFW locations
419     cfw_mode *mode[CFW_MAX_MODES];
420 } cfw_project;
421
422
423 /* @} */
424
425 #endif /* CFW_FIRMWARE_H_ */