tools/testing/nvdimm: dynamic label support
[linux-2.6/btrfs-unstable.git] / include / sound / hda_regmap.h
blobca64f0f50b4533df080a2daa6b1cba2fdf5f0a12
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_read_raw_uncached(struct hdac_device *codec,
21 unsigned int reg, unsigned int *val);
22 int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg,
23 unsigned int val);
24 int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg,
25 unsigned int mask, unsigned int val);
27 /**
28 * snd_hdac_regmap_encode_verb - encode the verb to a pseudo register
29 * @nid: widget NID
30 * @verb: codec verb
32 * Returns an encoded pseudo register.
34 #define snd_hdac_regmap_encode_verb(nid, verb) \
35 (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20))
37 /**
38 * snd_hdac_regmap_encode_amp - encode the AMP verb to a pseudo register
39 * @nid: widget NID
40 * @ch: channel (left = 0, right = 1)
41 * @dir: direction (#HDA_INPUT, #HDA_OUTPUT)
42 * @idx: input index value
44 * Returns an encoded pseudo register.
46 #define snd_hdac_regmap_encode_amp(nid, ch, dir, idx) \
47 (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \
48 ((ch) ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT) | \
49 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
50 (idx))
52 /**
53 * snd_hdac_regmap_encode_amp_stereo - encode a pseudo register for stereo AMPs
54 * @nid: widget NID
55 * @dir: direction (#HDA_INPUT, #HDA_OUTPUT)
56 * @idx: input index value
58 * Returns an encoded pseudo register.
60 #define snd_hdac_regmap_encode_amp_stereo(nid, dir, idx) \
61 (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \
62 AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT | /* both bits set! */ \
63 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
64 (idx))
66 /**
67 * snd_hdac_regmap_write - Write a verb with caching
68 * @nid: codec NID
69 * @reg: verb to write
70 * @val: value to write
72 * For writing an amp value, use snd_hdac_regmap_update_amp().
74 static inline int
75 snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid,
76 unsigned int verb, unsigned int val)
78 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
80 return snd_hdac_regmap_write_raw(codec, cmd, val);
83 /**
84 * snd_hda_regmap_update - Update a verb value with caching
85 * @nid: codec NID
86 * @verb: verb to update
87 * @mask: bit mask to update
88 * @val: value to update
90 * For updating an amp value, use snd_hdac_regmap_update_amp().
92 static inline int
93 snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid,
94 unsigned int verb, unsigned int mask,
95 unsigned int val)
97 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
99 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
103 * snd_hda_regmap_read - Read a verb with caching
104 * @nid: codec NID
105 * @verb: verb to read
106 * @val: pointer to store the value
108 * For reading an amp value, use snd_hda_regmap_get_amp().
110 static inline int
111 snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid,
112 unsigned int verb, unsigned int *val)
114 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
116 return snd_hdac_regmap_read_raw(codec, cmd, val);
120 * snd_hdac_regmap_get_amp - Read AMP value
121 * @codec: HD-audio codec
122 * @nid: NID to read the AMP value
123 * @ch: channel (left=0 or right=1)
124 * @direction: #HDA_INPUT or #HDA_OUTPUT
125 * @index: the index value (only for input direction)
126 * @val: the pointer to store the value
128 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
129 * Returns the value or a negative error.
131 static inline int
132 snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid,
133 int ch, int dir, int idx)
135 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
136 int err, val;
138 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
139 return err < 0 ? err : val;
143 * snd_hdac_regmap_update_amp - update the AMP value
144 * @codec: HD-audio codec
145 * @nid: NID to read the AMP value
146 * @ch: channel (left=0 or right=1)
147 * @direction: #HDA_INPUT or #HDA_OUTPUT
148 * @idx: the index value (only for input direction)
149 * @mask: bit mask to set
150 * @val: the bits value to set
152 * Update the AMP value with a bit mask.
153 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
155 static inline int
156 snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid,
157 int ch, int dir, int idx, int mask, int val)
159 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
161 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
165 * snd_hdac_regmap_get_amp_stereo - Read stereo AMP values
166 * @codec: HD-audio codec
167 * @nid: NID to read the AMP value
168 * @ch: channel (left=0 or right=1)
169 * @direction: #HDA_INPUT or #HDA_OUTPUT
170 * @index: the index value (only for input direction)
171 * @val: the pointer to store the value
173 * Read stereo AMP values. The lower byte is left, the upper byte is right.
174 * Returns the value or a negative error.
176 static inline int
177 snd_hdac_regmap_get_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
178 int dir, int idx)
180 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
181 int err, val;
183 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
184 return err < 0 ? err : val;
188 * snd_hdac_regmap_update_amp_stereo - update the stereo AMP value
189 * @codec: HD-audio codec
190 * @nid: NID to read the AMP value
191 * @direction: #HDA_INPUT or #HDA_OUTPUT
192 * @idx: the index value (only for input direction)
193 * @mask: bit mask to set
194 * @val: the bits value to set
196 * Update the stereo AMP value with a bit mask.
197 * The lower byte is left, the upper byte is right.
198 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
200 static inline int
201 snd_hdac_regmap_update_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
202 int dir, int idx, int mask, int val)
204 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
206 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
210 * snd_hdac_regmap_sync_node - sync the widget node attributes
211 * @codec: HD-audio codec
212 * @nid: NID to sync
214 static inline void
215 snd_hdac_regmap_sync_node(struct hdac_device *codec, hda_nid_t nid)
217 regcache_mark_dirty(codec->regmap);
218 regcache_sync_region(codec->regmap, nid << 20, ((nid + 1) << 20) - 1);
221 #endif /* __SOUND_HDA_REGMAP_H */