1
2
3
4
5#ifndef __SOUND_HDA_REGMAP_H
6#define __SOUND_HDA_REGMAP_H
7
8#include <linux/regmap.h>
9#include <sound/core.h>
10#include <sound/hdaudio.h>
11
12#define AC_AMP_FAKE_MUTE 0x10
13
14int snd_hdac_regmap_init(struct hdac_device *codec);
15void snd_hdac_regmap_exit(struct hdac_device *codec);
16int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec,
17 unsigned int verb);
18int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg,
19 unsigned int *val);
20int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg,
21 unsigned int val);
22int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg,
23 unsigned int mask, unsigned int val);
24
25
26
27
28
29
30
31
32#define snd_hdac_regmap_encode_verb(nid, verb) \
33 (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20))
34
35
36
37
38
39
40
41
42
43
44#define snd_hdac_regmap_encode_amp(nid, ch, dir, idx) \
45 (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \
46 ((ch) ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT) | \
47 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
48 (idx))
49
50
51
52
53
54
55
56
57
58#define snd_hdac_regmap_encode_amp_stereo(nid, dir, idx) \
59 (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \
60 AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT | \
61 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
62 (idx))
63
64
65
66
67
68
69
70
71
72static inline int
73snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid,
74 unsigned int verb, unsigned int val)
75{
76 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
77
78 return snd_hdac_regmap_write_raw(codec, cmd, val);
79}
80
81
82
83
84
85
86
87
88
89
90static inline int
91snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid,
92 unsigned int verb, unsigned int mask,
93 unsigned int val)
94{
95 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
96
97 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
98}
99
100
101
102
103
104
105
106
107
108static inline int
109snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid,
110 unsigned int verb, unsigned int *val)
111{
112 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
113
114 return snd_hdac_regmap_read_raw(codec, cmd, val);
115}
116
117
118
119
120
121
122
123
124
125
126
127
128
129static inline int
130snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid,
131 int ch, int dir, int idx)
132{
133 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
134 int err, val;
135
136 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
137 return err < 0 ? err : val;
138}
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153static inline int
154snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid,
155 int ch, int dir, int idx, int mask, int val)
156{
157 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
158
159 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
160}
161
162
163
164
165
166
167
168
169
170
171
172
173
174static inline int
175snd_hdac_regmap_get_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
176 int dir, int idx)
177{
178 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
179 int err, val;
180
181 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
182 return err < 0 ? err : val;
183}
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198static inline int
199snd_hdac_regmap_update_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
200 int dir, int idx, int mask, int val)
201{
202 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
203
204 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
205}
206
207
208
209
210
211
212static inline void
213snd_hdac_regmap_sync_node(struct hdac_device *codec, hda_nid_t nid)
214{
215 regcache_mark_dirty(codec->regmap);
216 regcache_sync_region(codec->regmap, nid << 20, ((nid + 1) << 20) - 1);
217}
218
219#endif
220