ALSA: hda - Handle get/set power verb symmetrically via regmap
[linux-2.6-block.git] / include / sound / hdaudio.h
CommitLineData
e3d280fc
TI
1/*
2 * HD-audio core stuff
3 */
4
5#ifndef __SOUND_HDAUDIO_H
6#define __SOUND_HDAUDIO_H
7
8#include <linux/device.h>
d068ebc2
TI
9#include <sound/hda_verbs.h>
10
7639a06c
TI
11/* codec node id */
12typedef u16 hda_nid_t;
13
d068ebc2
TI
14struct hdac_bus;
15struct hdac_device;
16struct hdac_driver;
3256be65 17struct hdac_widget_tree;
e3d280fc
TI
18
19/*
20 * exported bus type
21 */
22extern struct bus_type snd_hda_bus_type;
23
71fc4c7e
TI
24/*
25 * generic arrays
26 */
27struct snd_array {
28 unsigned int used;
29 unsigned int alloced;
30 unsigned int elem_size;
31 unsigned int alloc_align;
32 void *list;
33};
34
e3d280fc
TI
35/*
36 * HD-audio codec base device
37 */
38struct hdac_device {
39 struct device dev;
40 int type;
d068ebc2
TI
41 struct hdac_bus *bus;
42 unsigned int addr; /* codec address */
43 struct list_head list; /* list point for bus codec_list */
7639a06c
TI
44
45 hda_nid_t afg; /* AFG node id */
46 hda_nid_t mfg; /* MFG node id */
47
48 /* ids */
49 unsigned int vendor_id;
50 unsigned int subsystem_id;
51 unsigned int revision_id;
52 unsigned int afg_function_id;
53 unsigned int mfg_function_id;
54 unsigned int afg_unsol:1;
55 unsigned int mfg_unsol:1;
56
57 unsigned int power_caps; /* FG power caps */
58
59 const char *vendor_name; /* codec vendor name */
60 const char *chip_name; /* codec chip name */
61
05852448
TI
62 /* verb exec op override */
63 int (*exec_verb)(struct hdac_device *dev, unsigned int cmd,
64 unsigned int flags, unsigned int *res);
65
7639a06c
TI
66 /* widgets */
67 unsigned int num_nodes;
68 hda_nid_t start_nid, end_nid;
69
70 /* misc flags */
71 atomic_t in_pm; /* suspend/resume being performed */
3256be65
TI
72
73 /* sysfs */
74 struct hdac_widget_tree *widgets;
4d75faa0
TI
75
76 /* regmap */
77 struct regmap *regmap;
5e56bcea 78 struct snd_array vendor_verbs;
4d75faa0 79 bool lazy_cache:1; /* don't wake up for writes */
faa75f8a 80 bool caps_overwriting:1; /* caps overwrite being in process */
e3d280fc
TI
81};
82
83/* device/driver type used for matching */
84enum {
85 HDA_DEV_CORE,
86 HDA_DEV_LEGACY,
87};
88
7639a06c
TI
89/* direction */
90enum {
91 HDA_INPUT, HDA_OUTPUT
92};
93
e3d280fc
TI
94#define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev)
95
7639a06c
TI
96int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus,
97 const char *name, unsigned int addr);
98void snd_hdac_device_exit(struct hdac_device *dev);
3256be65
TI
99int snd_hdac_device_register(struct hdac_device *codec);
100void snd_hdac_device_unregister(struct hdac_device *codec);
7639a06c
TI
101
102int snd_hdac_refresh_widgets(struct hdac_device *codec);
103
104unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
105 unsigned int verb, unsigned int parm);
05852448
TI
106int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
107 unsigned int flags, unsigned int *res);
7639a06c
TI
108int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
109 unsigned int verb, unsigned int parm, unsigned int *res);
01ed3c06
TI
110int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm,
111 unsigned int *res);
9ba17b4d
TI
112int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid,
113 int parm);
faa75f8a
TI
114int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid,
115 unsigned int parm, unsigned int val);
7639a06c
TI
116int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid,
117 hda_nid_t *conn_list, int max_conns);
118int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid,
119 hda_nid_t *start_id);
120
01ed3c06
TI
121/**
122 * snd_hdac_read_parm - read a codec parameter
123 * @codec: the codec object
124 * @nid: NID to read a parameter
125 * @parm: parameter to read
126 *
127 * Returns -1 for error. If you need to distinguish the error more
128 * strictly, use _snd_hdac_read_parm() directly.
129 */
130static inline int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid,
131 int parm)
132{
133 unsigned int val;
134
135 return _snd_hdac_read_parm(codec, nid, parm, &val) < 0 ? -1 : val;
136}
137
7639a06c
TI
138#ifdef CONFIG_PM
139void snd_hdac_power_up(struct hdac_device *codec);
140void snd_hdac_power_down(struct hdac_device *codec);
141#else
142static inline void snd_hdac_power_up(struct hdac_device *codec) {}
143static inline void snd_hdac_power_down(struct hdac_device *codec) {}
144#endif
145
e3d280fc
TI
146/*
147 * HD-audio codec base driver
148 */
149struct hdac_driver {
150 struct device_driver driver;
151 int type;
152 int (*match)(struct hdac_device *dev, struct hdac_driver *drv);
d068ebc2 153 void (*unsol_event)(struct hdac_device *dev, unsigned int event);
e3d280fc
TI
154};
155
156#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver)
157
d068ebc2
TI
158/*
159 * HD-audio bus base driver
160 */
161struct hdac_bus_ops {
162 /* send a single command */
163 int (*command)(struct hdac_bus *bus, unsigned int cmd);
164 /* get a response from the last command */
165 int (*get_response)(struct hdac_bus *bus, unsigned int addr,
166 unsigned int *res);
167};
168
169#define HDA_UNSOL_QUEUE_SIZE 64
170
171struct hdac_bus {
172 struct device *dev;
173 const struct hdac_bus_ops *ops;
174
175 /* codec linked list */
176 struct list_head codec_list;
177 unsigned int num_codecs;
178
179 /* link caddr -> codec */
180 struct hdac_device *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1];
181
182 /* unsolicited event queue */
183 u32 unsol_queue[HDA_UNSOL_QUEUE_SIZE * 2]; /* ring buffer */
184 unsigned int unsol_rp, unsol_wp;
185 struct work_struct unsol_work;
186
187 /* bit flags of powered codecs */
188 unsigned long codec_powered;
189
190 /* flags */
191 bool sync_write:1; /* sync after verb write */
192
193 /* locks */
194 struct mutex cmd_mutex;
195};
196
197int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
198 const struct hdac_bus_ops *ops);
199void snd_hdac_bus_exit(struct hdac_bus *bus);
200int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr,
201 unsigned int cmd, unsigned int *res);
202int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr,
203 unsigned int cmd, unsigned int *res);
204void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex);
205
206int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec);
207void snd_hdac_bus_remove_device(struct hdac_bus *bus,
208 struct hdac_device *codec);
209
7639a06c
TI
210static inline void snd_hdac_codec_link_up(struct hdac_device *codec)
211{
212 set_bit(codec->addr, &codec->bus->codec_powered);
213}
214
215static inline void snd_hdac_codec_link_down(struct hdac_device *codec)
216{
217 clear_bit(codec->addr, &codec->bus->codec_powered);
218}
219
71fc4c7e
TI
220/*
221 * generic array helpers
222 */
223void *snd_array_new(struct snd_array *array);
224void snd_array_free(struct snd_array *array);
225static inline void snd_array_init(struct snd_array *array, unsigned int size,
226 unsigned int align)
227{
228 array->elem_size = size;
229 array->alloc_align = align;
230}
231
232static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
233{
234 return array->list + idx * array->elem_size;
235}
236
237static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
238{
239 return (unsigned long)(ptr - array->list) / array->elem_size;
240}
241
e3d280fc 242#endif /* __SOUND_HDAUDIO_H */