checkpatch: improve "no space is necessary after a cast" test
[linux-2.6/btrfs-unstable.git] / include / sound / hda_regmap.h
blob53a18b3635e24a458700a21566c56a10d0704c56
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 int snd_hdac_regmap_init(struct hdac_device *codec);
13 void snd_hdac_regmap_exit(struct hdac_device *codec);
14 int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec,
15 unsigned int verb);
16 int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg,
17 unsigned int *val);
18 int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg,
19 unsigned int val);
20 int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg,
21 unsigned int mask, unsigned int val);
23 /**
24 * snd_hdac_regmap_encode_verb - encode the verb to a pseudo register
25 * @nid: widget NID
26 * @verb: codec verb
28 * Returns an encoded pseudo register.
30 #define snd_hdac_regmap_encode_verb(nid, verb) \
31 (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20))
33 /**
34 * snd_hdac_regmap_encode_amp - encode the AMP verb to a pseudo register
35 * @nid: widget NID
36 * @ch: channel (left = 0, right = 1)
37 * @dir: direction (#HDA_INPUT, #HDA_OUTPUT)
38 * @idx: input index value
40 * Returns an encoded pseudo register.
42 #define snd_hdac_regmap_encode_amp(nid, ch, dir, idx) \
43 (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \
44 ((ch) ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT) | \
45 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
46 (idx))
48 /**
49 * snd_hdac_regmap_encode_amp_stereo - encode a pseudo register for stereo AMPs
50 * @nid: widget NID
51 * @dir: direction (#HDA_INPUT, #HDA_OUTPUT)
52 * @idx: input index value
54 * Returns an encoded pseudo register.
56 #define snd_hdac_regmap_encode_amp_stereo(nid, dir, idx) \
57 (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \
58 AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT | /* both bits set! */ \
59 ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \
60 (idx))
62 /**
63 * snd_hdac_regmap_write - Write a verb with caching
64 * @nid: codec NID
65 * @reg: verb to write
66 * @val: value to write
68 * For writing an amp value, use snd_hda_regmap_amp_update().
70 static inline int
71 snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid,
72 unsigned int verb, unsigned int val)
74 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
76 return snd_hdac_regmap_write_raw(codec, cmd, val);
79 /**
80 * snd_hda_regmap_update - Update a verb value with caching
81 * @nid: codec NID
82 * @verb: verb to update
83 * @mask: bit mask to update
84 * @val: value to update
86 * For updating an amp value, use snd_hda_regmap_amp_update().
88 static inline int
89 snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid,
90 unsigned int verb, unsigned int mask,
91 unsigned int val)
93 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
95 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
98 /**
99 * snd_hda_regmap_read - Read a verb with caching
100 * @nid: codec NID
101 * @verb: verb to read
102 * @val: pointer to store the value
104 * For reading an amp value, use snd_hda_regmap_get_amp().
106 static inline int
107 snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid,
108 unsigned int verb, unsigned int *val)
110 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
112 return snd_hdac_regmap_read_raw(codec, cmd, val);
116 * snd_hdac_regmap_get_amp - Read AMP value
117 * @codec: HD-audio codec
118 * @nid: NID to read the AMP value
119 * @ch: channel (left=0 or right=1)
120 * @direction: #HDA_INPUT or #HDA_OUTPUT
121 * @index: the index value (only for input direction)
122 * @val: the pointer to store the value
124 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
125 * Returns the value or a negative error.
127 static inline int
128 snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid,
129 int ch, int dir, int idx)
131 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
132 int err, val;
134 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
135 return err < 0 ? err : val;
139 * snd_hdac_regmap_update_amp - update the AMP value
140 * @codec: HD-audio codec
141 * @nid: NID to read the AMP value
142 * @ch: channel (left=0 or right=1)
143 * @direction: #HDA_INPUT or #HDA_OUTPUT
144 * @idx: the index value (only for input direction)
145 * @mask: bit mask to set
146 * @val: the bits value to set
148 * Update the AMP value with a bit mask.
149 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
151 static inline int
152 snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid,
153 int ch, int dir, int idx, int mask, int val)
155 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
157 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
161 * snd_hdac_regmap_get_amp_stereo - Read stereo AMP values
162 * @codec: HD-audio codec
163 * @nid: NID to read the AMP value
164 * @ch: channel (left=0 or right=1)
165 * @direction: #HDA_INPUT or #HDA_OUTPUT
166 * @index: the index value (only for input direction)
167 * @val: the pointer to store the value
169 * Read stereo AMP values. The lower byte is left, the upper byte is right.
170 * Returns the value or a negative error.
172 static inline int
173 snd_hdac_regmap_get_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
174 int dir, int idx)
176 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
177 int err, val;
179 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
180 return err < 0 ? err : val;
184 * snd_hdac_regmap_update_amp_stereo - update the stereo AMP value
185 * @codec: HD-audio codec
186 * @nid: NID to read the AMP value
187 * @direction: #HDA_INPUT or #HDA_OUTPUT
188 * @idx: the index value (only for input direction)
189 * @mask: bit mask to set
190 * @val: the bits value to set
192 * Update the stereo AMP value with a bit mask.
193 * The lower byte is left, the upper byte is right.
194 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
196 static inline int
197 snd_hdac_regmap_update_amp_stereo(struct hdac_device *codec, hda_nid_t nid,
198 int dir, int idx, int mask, int val)
200 unsigned int cmd = snd_hdac_regmap_encode_amp_stereo(nid, dir, idx);
202 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
206 * snd_hdac_regmap_sync_node - sync the widget node attributes
207 * @codec: HD-audio codec
208 * @nid: NID to sync
210 static inline void
211 snd_hdac_regmap_sync_node(struct hdac_device *codec, hda_nid_t nid)
213 regcache_mark_dirty(codec->regmap);
214 regcache_sync_region(codec->regmap, nid << 20, ((nid + 1) << 20) - 1);
217 #endif /* __SOUND_HDA_REGMAP_H */