Linux 4.1.18
[linux/fpc-iii.git] / include / sound / hda_regmap.h
blobdf705908480aebbf754900731834162fa8097f75
1 /*
2 * HD-audio regmap helpers
3 */
5 #ifndef __SOUND_HDA_REGMAP_H
6 #define __SOUND_HDA_REGMAP_H
8 #include <linux/regmap.h>
9 #include <sound/core.h>
10 #include <sound/hdaudio.h>
12 #define AC_AMP_FAKE_MUTE 0x10 /* fake mute bit set to amp verbs */
14 int snd_hdac_regmap_init(struct hdac_device *codec);
15 void snd_hdac_regmap_exit(struct hdac_device *codec);
16 int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec,
17 unsigned int verb);
18 int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg,
19 unsigned int *val);
20 int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg,
21 unsigned int val);
22 int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg,
23 unsigned int mask, unsigned int val);
25 /**
26 * snd_hdac_regmap_encode_verb - encode the verb to a pseudo register
27 * @nid: widget NID
28 * @verb: codec verb
30 * Returns an encoded pseudo register.
32 #define snd_hdac_regmap_encode_verb(nid, verb) \
33 (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20))
35 /**
36 * snd_hdac_regmap_encode_amp - encode the AMP verb to a pseudo register
37 * @nid: widget NID
38 * @ch: channel (left = 0, right = 1)
39 * @dir: direction (#HDA_INPUT, #HDA_OUTPUT)
40 * @idx: input index value
42 * Returns an encoded pseudo register.
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))
50 /**
51 * snd_hdac_regmap_encode_amp_stereo - encode a pseudo register for stereo AMPs
52 * @nid: widget NID
53 * @dir: direction (#HDA_INPUT, #HDA_OUTPUT)
54 * @idx: input index value
56 * Returns an encoded pseudo register.
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 | /* both bits set! */ \
61 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
62 (idx))
64 /**
65 * snd_hdac_regmap_write - Write a verb with caching
66 * @nid: codec NID
67 * @reg: verb to write
68 * @val: value to write
70 * For writing an amp value, use snd_hda_regmap_amp_update().
72 static inline int
73 snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid,
74 unsigned int verb, unsigned int val)
76 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
78 return snd_hdac_regmap_write_raw(codec, cmd, val);
81 /**
82 * snd_hda_regmap_update - Update a verb value with caching
83 * @nid: codec NID
84 * @verb: verb to update
85 * @mask: bit mask to update
86 * @val: value to update
88 * For updating an amp value, use snd_hda_regmap_amp_update().
90 static inline int
91 snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid,
92 unsigned int verb, unsigned int mask,
93 unsigned int val)
95 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
97 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
101 * snd_hda_regmap_read - Read a verb with caching
102 * @nid: codec NID
103 * @verb: verb to read
104 * @val: pointer to store the value
106 * For reading an amp value, use snd_hda_regmap_get_amp().
108 static inline int
109 snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid,
110 unsigned int verb, unsigned int *val)
112 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
114 return snd_hdac_regmap_read_raw(codec, cmd, val);
118 * snd_hdac_regmap_get_amp - Read AMP value
119 * @codec: HD-audio codec
120 * @nid: NID to read the AMP value
121 * @ch: channel (left=0 or right=1)
122 * @direction: #HDA_INPUT or #HDA_OUTPUT
123 * @index: the index value (only for input direction)
124 * @val: the pointer to store the value
126 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
127 * Returns the value or a negative error.
129 static inline int
130 snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid,
131 int ch, int dir, int idx)
133 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
134 int err, val;
136 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
137 return err < 0 ? err : val;
141 * snd_hdac_regmap_update_amp - update the AMP value
142 * @codec: HD-audio codec
143 * @nid: NID to read the AMP value
144 * @ch: channel (left=0 or right=1)
145 * @direction: #HDA_INPUT or #HDA_OUTPUT
146 * @idx: the index value (only for input direction)
147 * @mask: bit mask to set
148 * @val: the bits value to set
150 * Update the AMP value with a bit mask.
151 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
153 static inline int
154 snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid,
155 int ch, int dir, int idx, int mask, int val)
157 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
159 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
163 * snd_hdac_regmap_get_amp_stereo - Read stereo AMP values
164 * @codec: HD-audio codec
165 * @nid: NID to read the AMP value
166 * @ch: channel (left=0 or right=1)
167 * @direction: #HDA_INPUT or #HDA_OUTPUT
168 * @index: the index value (only for input direction)
169 * @val: the pointer to store the value
171 * Read stereo AMP values. The lower byte is left, the upper byte is right.
172 * Returns the value or a negative error.
174 static inline int
175 snd_hdac_regmap_get_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
176 int dir, int idx)
178 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
179 int err, val;
181 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
182 return err < 0 ? err : val;
186 * snd_hdac_regmap_update_amp_stereo - update the stereo AMP value
187 * @codec: HD-audio codec
188 * @nid: NID to read the AMP value
189 * @direction: #HDA_INPUT or #HDA_OUTPUT
190 * @idx: the index value (only for input direction)
191 * @mask: bit mask to set
192 * @val: the bits value to set
194 * Update the stereo AMP value with a bit mask.
195 * The lower byte is left, the upper byte is right.
196 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
198 static inline int
199 snd_hdac_regmap_update_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
200 int dir, int idx, int mask, int val)
202 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
204 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
208 * snd_hdac_regmap_sync_node - sync the widget node attributes
209 * @codec: HD-audio codec
210 * @nid: NID to sync
212 static inline void
213 snd_hdac_regmap_sync_node(struct hdac_device *codec, hda_nid_t nid)
215 regcache_mark_dirty(codec->regmap);
216 regcache_sync_region(codec->regmap, nid << 20, ((nid + 1) << 20) - 1);
219 #endif /* __SOUND_HDA_REGMAP_H */