1 From: Takashi Iwai <tiwai@suse.de>
2 Subject: ALSA: hda - simplify hda_bus ops callbacks
3 Patch-mainline: 2.6.29-rc1
6 The hda_bus ops callback take struct hda_bus pointer.
7 Also, the command callback takes the composed command word, instead of
8 each small bits in arguments.
10 Signed-off-by: Takashi Iwai <tiwai@suse.de>
13 sound/pci/hda/hda_codec.c | 59 +++++++++++++++++++++++++++++++++++-----------
14 sound/pci/hda/hda_codec.h | 7 ++---
15 sound/pci/hda/hda_intel.c | 55 +++++++++++++++++-------------------------
16 3 files changed, 71 insertions(+), 50 deletions(-)
18 --- a/sound/pci/hda/hda_codec.c
19 +++ b/sound/pci/hda/hda_codec.c
21 static inline void hda_keep_power_on(struct hda_codec *codec) {}
25 + * Compose a 32bit command word to be sent to the HD-audio controller
27 +static inline unsigned int
28 +make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
29 + unsigned int verb, unsigned int parm)
33 + val = (u32)(codec->addr & 0x0f) << 28;
34 + val |= (u32)direct << 27;
35 + val |= (u32)nid << 20;
42 * snd_hda_codec_read - send a command and get the response
43 * @codec: the HDA codec
46 unsigned int verb, unsigned int parm)
48 + struct hda_bus *bus = codec->bus;
51 + res = make_codec_cmd(codec, nid, direct, verb, parm);
52 snd_hda_power_up(codec);
53 - mutex_lock(&codec->bus->cmd_mutex);
54 - if (!codec->bus->ops.command(codec, nid, direct, verb, parm))
55 - res = codec->bus->ops.get_response(codec);
56 + mutex_lock(&bus->cmd_mutex);
57 + if (!bus->ops.command(bus, res))
58 + res = bus->ops.get_response(bus);
60 res = (unsigned int)-1;
61 - mutex_unlock(&codec->bus->cmd_mutex);
62 + mutex_unlock(&bus->cmd_mutex);
63 snd_hda_power_down(codec);
67 int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
68 unsigned int verb, unsigned int parm)
70 + struct hda_bus *bus = codec->bus;
74 + res = make_codec_cmd(codec, nid, direct, verb, parm);
75 snd_hda_power_up(codec);
76 - mutex_lock(&codec->bus->cmd_mutex);
77 - err = codec->bus->ops.command(codec, nid, direct, verb, parm);
78 - mutex_unlock(&codec->bus->cmd_mutex);
79 + mutex_lock(&bus->cmd_mutex);
80 + err = bus->ops.command(bus, res);
81 + mutex_unlock(&bus->cmd_mutex);
82 snd_hda_power_down(codec);
85 @@ -1796,10 +1820,14 @@
86 int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
87 int direct, unsigned int verb, unsigned int parm)
89 + struct hda_bus *bus = codec->bus;
93 + res = make_codec_cmd(codec, nid, direct, verb, parm);
94 snd_hda_power_up(codec);
95 - mutex_lock(&codec->bus->cmd_mutex);
96 - err = codec->bus->ops.command(codec, nid, direct, verb, parm);
97 + mutex_lock(&bus->cmd_mutex);
98 + err = bus->ops.command(bus, res);
100 struct hda_cache_head *c;
101 u32 key = build_cmd_cache_key(nid, verb);
102 @@ -1807,7 +1835,7 @@
106 - mutex_unlock(&codec->bus->cmd_mutex);
107 + mutex_unlock(&bus->cmd_mutex);
108 snd_hda_power_down(codec);
111 @@ -2507,6 +2535,7 @@
113 struct hda_codec *codec =
114 container_of(work, struct hda_codec, power_work.work);
115 + struct hda_bus *bus = codec->bus;
117 if (!codec->power_on || codec->power_count) {
118 codec->power_transition = 0;
119 @@ -2514,8 +2543,8 @@
122 hda_call_codec_suspend(codec);
123 - if (codec->bus->ops.pm_notify)
124 - codec->bus->ops.pm_notify(codec);
125 + if (bus->ops.pm_notify)
126 + bus->ops.pm_notify(bus);
129 static void hda_keep_power_on(struct hda_codec *codec)
130 @@ -2526,13 +2555,15 @@
132 void snd_hda_power_up(struct hda_codec *codec)
134 + struct hda_bus *bus = codec->bus;
136 codec->power_count++;
137 if (codec->power_on || codec->power_transition)
141 - if (codec->bus->ops.pm_notify)
142 - codec->bus->ops.pm_notify(codec);
143 + if (bus->ops.pm_notify)
144 + bus->ops.pm_notify(bus);
145 hda_call_codec_resume(codec);
146 cancel_delayed_work(&codec->power_work);
147 codec->power_transition = 0;
148 --- a/sound/pci/hda/hda_codec.h
149 +++ b/sound/pci/hda/hda_codec.h
150 @@ -536,15 +536,14 @@
153 /* send a single command */
154 - int (*command)(struct hda_codec *codec, hda_nid_t nid, int direct,
155 - unsigned int verb, unsigned int parm);
156 + int (*command)(struct hda_bus *bus, unsigned int cmd);
157 /* get a response from the last command */
158 - unsigned int (*get_response)(struct hda_codec *codec);
159 + unsigned int (*get_response)(struct hda_bus *bus);
160 /* free the private data */
161 void (*private_free)(struct hda_bus *);
162 #ifdef CONFIG_SND_HDA_POWER_SAVE
163 /* notify power-up/down from codec to controller */
164 - void (*pm_notify)(struct hda_codec *codec);
165 + void (*pm_notify)(struct hda_bus *bus);
169 --- a/sound/pci/hda/hda_intel.c
170 +++ b/sound/pci/hda/hda_intel.c
175 -static int azx_corb_send_cmd(struct hda_codec *codec, u32 val)
176 +static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
178 - struct azx *chip = codec->bus->private_data;
179 + struct azx *chip = bus->private_data;
182 /* add command to corb */
186 /* receive a response */
187 -static unsigned int azx_rirb_get_response(struct hda_codec *codec)
188 +static unsigned int azx_rirb_get_response(struct hda_bus *bus)
190 - struct azx *chip = codec->bus->private_data;
191 + struct azx *chip = bus->private_data;
192 unsigned long timeout;
197 if (time_after(jiffies, timeout))
199 - if (codec->bus->needs_damn_long_delay)
200 + if (bus->needs_damn_long_delay)
201 msleep(2); /* temporary workaround */
208 -static int azx_single_send_cmd(struct hda_codec *codec, u32 val)
209 +static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
211 - struct azx *chip = codec->bus->private_data;
212 + struct azx *chip = bus->private_data;
219 /* receive a response */
220 -static unsigned int azx_single_get_response(struct hda_codec *codec)
221 +static unsigned int azx_single_get_response(struct hda_bus *bus)
223 - struct azx *chip = codec->bus->private_data;
224 + struct azx *chip = bus->private_data;
228 @@ -696,38 +696,29 @@
232 -static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid,
233 - int direct, unsigned int verb,
236 - struct azx *chip = codec->bus->private_data;
239 - val = (u32)(codec->addr & 0x0f) << 28;
240 - val |= (u32)direct << 27;
241 - val |= (u32)nid << 20;
244 - chip->last_cmd = val;
245 +static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
247 + struct azx *chip = bus->private_data;
249 + chip->last_cmd = val;
250 if (chip->single_cmd)
251 - return azx_single_send_cmd(codec, val);
252 + return azx_single_send_cmd(bus, val);
254 - return azx_corb_send_cmd(codec, val);
255 + return azx_corb_send_cmd(bus, val);
259 -static unsigned int azx_get_response(struct hda_codec *codec)
260 +static unsigned int azx_get_response(struct hda_bus *bus)
262 - struct azx *chip = codec->bus->private_data;
263 + struct azx *chip = bus->private_data;
264 if (chip->single_cmd)
265 - return azx_single_get_response(codec);
266 + return azx_single_get_response(bus);
268 - return azx_rirb_get_response(codec);
269 + return azx_rirb_get_response(bus);
272 #ifdef CONFIG_SND_HDA_POWER_SAVE
273 -static void azx_power_notify(struct hda_codec *codec);
274 +static void azx_power_notify(struct hda_bus *bus);
277 /* reset codec link */
278 @@ -1905,13 +1896,13 @@
280 #ifdef CONFIG_SND_HDA_POWER_SAVE
281 /* power-up/down the controller */
282 -static void azx_power_notify(struct hda_codec *codec)
283 +static void azx_power_notify(struct hda_bus *bus)
285 - struct azx *chip = codec->bus->private_data;
286 + struct azx *chip = bus->private_data;
290 - list_for_each_entry(c, &codec->bus->codec_list, list) {
291 + list_for_each_entry(c, &bus->codec_list, list) {