1*2ca47137SSimon Glass /* SPDX-License-Identifier: GPL-2.0+ */
2*2ca47137SSimon Glass /*
3*2ca47137SSimon Glass  * Intel HDA audio codec config. This is a mechanicm to configure codecs when
4*2ca47137SSimon Glass  * using Intel HDA audio.
5*2ca47137SSimon Glass  *
6*2ca47137SSimon Glass  * Copyright 2018 Google LLC
7*2ca47137SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
8*2ca47137SSimon Glass  */
9*2ca47137SSimon Glass 
10*2ca47137SSimon Glass #ifndef __AZALIA_H
11*2ca47137SSimon Glass #define __AZALIA_H
12*2ca47137SSimon Glass 
13*2ca47137SSimon Glass #define AZALIA_CODEC_SHIFT		28
14*2ca47137SSimon Glass #define AZALIA_NID_SHIFT		20
15*2ca47137SSimon Glass #define AZALIA_VERB_SHIFT		8
16*2ca47137SSimon Glass 
17*2ca47137SSimon Glass /* Supported opcodes */
18*2ca47137SSimon Glass #define AZALIA_OPCODE_CONFIG_DEFAULT	0x71c
19*2ca47137SSimon Glass #define AZALIA_OPCODE_IMPL_ID		0x720
20*2ca47137SSimon Glass #define AZALIA_OPCODE_READ_PARAM	0xf00
21*2ca47137SSimon Glass 
22*2ca47137SSimon Glass #define AZALIA_PARAM_VENDOR_ID		0
23*2ca47137SSimon Glass 
24*2ca47137SSimon Glass /* Generate the register value to write a particular byte of a 32-bit value */
25*2ca47137SSimon Glass #define AZALIA_SET_BYTE(codec, nid, opcode, val, byte)		\
26*2ca47137SSimon Glass 	((codec) << AZALIA_CODEC_SHIFT |			\
27*2ca47137SSimon Glass 	 (nid) << AZALIA_NID_SHIFT |			\
28*2ca47137SSimon Glass 	 ((opcode) + (byte)) << AZALIA_VERB_SHIFT |		\
29*2ca47137SSimon Glass 	 (((val) >> ((byte) * 8)) & 0xff))
30*2ca47137SSimon Glass 
31*2ca47137SSimon Glass /* Generate the register value to write all bytes of a 32-bit value */
32*2ca47137SSimon Glass #define AZALIA_WORD(codec, nid, opcode, val)			\
33*2ca47137SSimon Glass 	 (AZALIA_SET_BYTE(codec, nid, opcode, val, 0) |	\
34*2ca47137SSimon Glass 	  AZALIA_SET_BYTE(codec, nid, opcode, val, 1) |		\
35*2ca47137SSimon Glass 	  AZALIA_SET_BYTE(codec, nid, opcode, val, 2) |		\
36*2ca47137SSimon Glass 	  AZALIA_SET_BYTE(codec, nid, opcode, val, 3))
37*2ca47137SSimon Glass 
38*2ca47137SSimon Glass #define AZALIA_PIN_CFG(codec, nid, val)				\
39*2ca47137SSimon Glass 	 AZALIA_WORD(codec, nid, AZALIA_OPCODE_CONFIG_DEFAULT, val)
40*2ca47137SSimon Glass 
41*2ca47137SSimon Glass #define AZALIA_SUBVENDOR(codec, val)				\
42*2ca47137SSimon Glass 	 AZALIA_WORD(codec, 1, AZALIA_OPCODE_IMPL_ID, val)
43*2ca47137SSimon Glass 
44*2ca47137SSimon Glass #endif /* __AZALIA_H */
45