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