ALSA: hda - Allow driver to add vendor-specific verbs for regmap
[deliverable/linux.git] / include / sound / hda_regmap.h
CommitLineData
4d75faa0
TI
1/*
2 * HD-audio regmap helpers
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
12int snd_hdac_regmap_init(struct hdac_device *codec);
13void snd_hdac_regmap_exit(struct hdac_device *codec);
5e56bcea
TI
14int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec,
15 unsigned int verb);
4d75faa0
TI
16int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg,
17 unsigned int *val);
18int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg,
19 unsigned int val);
20int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg,
21 unsigned int mask, unsigned int val);
22
23/**
24 * snd_hdac_regmap_encode_verb - encode the verb to a pseudo register
25 * @nid: widget NID
26 * @verb: codec verb
27 *
28 * Returns an encoded pseudo register.
29 */
30#define snd_hdac_regmap_encode_verb(nid, verb) \
31 (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20))
32
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
39 *
40 * Returns an encoded pseudo register.
41 */
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))
47
48/**
49 * snd_hdac_regmap_write - Write a verb with caching
50 * @nid: codec NID
51 * @reg: verb to write
52 * @val: value to write
53 *
54 * For writing an amp value, use snd_hda_regmap_amp_update().
55 */
56static inline int
57snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid,
58 unsigned int verb, unsigned int val)
59{
60 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
61
62 return snd_hdac_regmap_write_raw(codec, cmd, val);
63}
64
65/**
66 * snd_hda_regmap_update - Update a verb value with caching
67 * @nid: codec NID
68 * @verb: verb to update
69 * @mask: bit mask to update
70 * @val: value to update
71 *
72 * For updating an amp value, use snd_hda_regmap_amp_update().
73 */
74static inline int
75snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid,
76 unsigned int verb, unsigned int mask,
77 unsigned int val)
78{
79 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
80
81 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
82}
83
84/**
85 * snd_hda_regmap_read - Read a verb with caching
86 * @nid: codec NID
87 * @verb: verb to read
88 * @val: pointer to store the value
89 *
90 * For reading an amp value, use snd_hda_regmap_get_amp().
91 */
92static inline int
93snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid,
94 unsigned int verb, unsigned int *val)
95{
96 unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb);
97
98 return snd_hdac_regmap_read_raw(codec, cmd, val);
99}
100
101/**
102 * snd_hdac_regmap_get_amp - Read AMP value
103 * @codec: HD-audio codec
104 * @nid: NID to read the AMP value
105 * @ch: channel (left=0 or right=1)
106 * @direction: #HDA_INPUT or #HDA_OUTPUT
107 * @index: the index value (only for input direction)
108 * @val: the pointer to store the value
109 *
110 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
111 * Returns the value or a negative error.
112 */
113static inline int
114snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid,
115 int ch, int dir, int idx)
116{
117 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
118 int err, val;
119
120 err = snd_hdac_regmap_read_raw(codec, cmd, &val);
121 return err < 0 ? err : val;
122}
123
124/**
125 * snd_hdac_regmap_update_amp - update the AMP value
126 * @codec: HD-audio codec
127 * @nid: NID to read the AMP value
128 * @ch: channel (left=0 or right=1)
129 * @direction: #HDA_INPUT or #HDA_OUTPUT
130 * @idx: the index value (only for input direction)
131 * @mask: bit mask to set
132 * @val: the bits value to set
133 *
134 * Update the AMP value with a bit mask.
135 * Returns 0 if the value is unchanged, 1 if changed, or a negative error.
136 */
137static inline int
138snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid,
139 int ch, int dir, int idx, int mask, int val)
140{
141 unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx);
142
143 return snd_hdac_regmap_update_raw(codec, cmd, mask, val);
144}
145
146#endif /* __SOUND_HDA_REGMAP_H */
This page took 0.034546 seconds and 5 git commands to generate.