diff options
author | Takashi Iwai <tiwai@suse.de> | 2008-11-06 10:50:40 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-11-06 10:50:40 -0500 |
commit | 33fa35ed0d7e8996cc68cc2ffc21f12b38fa03c1 (patch) | |
tree | 06edbce704c6d99034f51ce591f1fbaf93fcc1b3 /sound/pci/hda/hda_codec.c | |
parent | c238b4f4038e0e49bb241640610584a088b268b1 (diff) |
ALSA: hda - simplify hda_bus ops callbacks
The hda_bus ops callback take struct hda_bus pointer.
Also, the command callback takes the composed command word, instead of
each small bits in arguments.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r-- | sound/pci/hda/hda_codec.c | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 45695d608c76..810465bac550 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -157,6 +157,23 @@ const char *snd_hda_get_jack_type(u32 cfg) | |||
157 | >> AC_DEFCFG_DEVICE_SHIFT]; | 157 | >> AC_DEFCFG_DEVICE_SHIFT]; |
158 | } | 158 | } |
159 | 159 | ||
160 | /* | ||
161 | * Compose a 32bit command word to be sent to the HD-audio controller | ||
162 | */ | ||
163 | static inline unsigned int | ||
164 | make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, | ||
165 | unsigned int verb, unsigned int parm) | ||
166 | { | ||
167 | u32 val; | ||
168 | |||
169 | val = (u32)(codec->addr & 0x0f) << 28; | ||
170 | val |= (u32)direct << 27; | ||
171 | val |= (u32)nid << 20; | ||
172 | val |= verb << 8; | ||
173 | val |= parm; | ||
174 | return val; | ||
175 | } | ||
176 | |||
160 | /** | 177 | /** |
161 | * snd_hda_codec_read - send a command and get the response | 178 | * snd_hda_codec_read - send a command and get the response |
162 | * @codec: the HDA codec | 179 | * @codec: the HDA codec |
@@ -173,14 +190,17 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, | |||
173 | int direct, | 190 | int direct, |
174 | unsigned int verb, unsigned int parm) | 191 | unsigned int verb, unsigned int parm) |
175 | { | 192 | { |
193 | struct hda_bus *bus = codec->bus; | ||
176 | unsigned int res; | 194 | unsigned int res; |
195 | |||
196 | res = make_codec_cmd(codec, nid, direct, verb, parm); | ||
177 | snd_hda_power_up(codec); | 197 | snd_hda_power_up(codec); |
178 | mutex_lock(&codec->bus->cmd_mutex); | 198 | mutex_lock(&bus->cmd_mutex); |
179 | if (!codec->bus->ops.command(codec, nid, direct, verb, parm)) | 199 | if (!bus->ops.command(bus, res)) |
180 | res = codec->bus->ops.get_response(codec); | 200 | res = bus->ops.get_response(bus); |
181 | else | 201 | else |
182 | res = (unsigned int)-1; | 202 | res = (unsigned int)-1; |
183 | mutex_unlock(&codec->bus->cmd_mutex); | 203 | mutex_unlock(&bus->cmd_mutex); |
184 | snd_hda_power_down(codec); | 204 | snd_hda_power_down(codec); |
185 | return res; | 205 | return res; |
186 | } | 206 | } |
@@ -200,11 +220,15 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, | |||
200 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, | 220 | int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, |
201 | unsigned int verb, unsigned int parm) | 221 | unsigned int verb, unsigned int parm) |
202 | { | 222 | { |
223 | struct hda_bus *bus = codec->bus; | ||
224 | unsigned int res; | ||
203 | int err; | 225 | int err; |
226 | |||
227 | res = make_codec_cmd(codec, nid, direct, verb, parm); | ||
204 | snd_hda_power_up(codec); | 228 | snd_hda_power_up(codec); |
205 | mutex_lock(&codec->bus->cmd_mutex); | 229 | mutex_lock(&bus->cmd_mutex); |
206 | err = codec->bus->ops.command(codec, nid, direct, verb, parm); | 230 | err = bus->ops.command(bus, res); |
207 | mutex_unlock(&codec->bus->cmd_mutex); | 231 | mutex_unlock(&bus->cmd_mutex); |
208 | snd_hda_power_down(codec); | 232 | snd_hda_power_down(codec); |
209 | return err; | 233 | return err; |
210 | } | 234 | } |
@@ -1886,10 +1910,14 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) | |||
1886 | int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, | 1910 | int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, |
1887 | int direct, unsigned int verb, unsigned int parm) | 1911 | int direct, unsigned int verb, unsigned int parm) |
1888 | { | 1912 | { |
1913 | struct hda_bus *bus = codec->bus; | ||
1914 | unsigned int res; | ||
1889 | int err; | 1915 | int err; |
1916 | |||
1917 | res = make_codec_cmd(codec, nid, direct, verb, parm); | ||
1890 | snd_hda_power_up(codec); | 1918 | snd_hda_power_up(codec); |
1891 | mutex_lock(&codec->bus->cmd_mutex); | 1919 | mutex_lock(&bus->cmd_mutex); |
1892 | err = codec->bus->ops.command(codec, nid, direct, verb, parm); | 1920 | err = bus->ops.command(bus, res); |
1893 | if (!err) { | 1921 | if (!err) { |
1894 | struct hda_cache_head *c; | 1922 | struct hda_cache_head *c; |
1895 | u32 key = build_cmd_cache_key(nid, verb); | 1923 | u32 key = build_cmd_cache_key(nid, verb); |
@@ -1897,7 +1925,7 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, | |||
1897 | if (c) | 1925 | if (c) |
1898 | c->val = parm; | 1926 | c->val = parm; |
1899 | } | 1927 | } |
1900 | mutex_unlock(&codec->bus->cmd_mutex); | 1928 | mutex_unlock(&bus->cmd_mutex); |
1901 | snd_hda_power_down(codec); | 1929 | snd_hda_power_down(codec); |
1902 | return err; | 1930 | return err; |
1903 | } | 1931 | } |
@@ -2414,6 +2442,7 @@ static int set_pcm_default_values(struct hda_codec *codec, | |||
2414 | static int __devinit | 2442 | static int __devinit |
2415 | snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) | 2443 | snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) |
2416 | { | 2444 | { |
2445 | struct hda_bus *bus = codec->bus; | ||
2417 | struct hda_pcm_stream *info; | 2446 | struct hda_pcm_stream *info; |
2418 | int stream, err; | 2447 | int stream, err; |
2419 | 2448 | ||
@@ -2427,7 +2456,7 @@ snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) | |||
2427 | return err; | 2456 | return err; |
2428 | } | 2457 | } |
2429 | } | 2458 | } |
2430 | return codec->bus->ops.attach_pcm(codec, pcm); | 2459 | return bus->ops.attach_pcm(bus, codec, pcm); |
2431 | } | 2460 | } |
2432 | 2461 | ||
2433 | /** | 2462 | /** |
@@ -2628,6 +2657,7 @@ static void hda_power_work(struct work_struct *work) | |||
2628 | { | 2657 | { |
2629 | struct hda_codec *codec = | 2658 | struct hda_codec *codec = |
2630 | container_of(work, struct hda_codec, power_work.work); | 2659 | container_of(work, struct hda_codec, power_work.work); |
2660 | struct hda_bus *bus = codec->bus; | ||
2631 | 2661 | ||
2632 | if (!codec->power_on || codec->power_count) { | 2662 | if (!codec->power_on || codec->power_count) { |
2633 | codec->power_transition = 0; | 2663 | codec->power_transition = 0; |
@@ -2635,8 +2665,8 @@ static void hda_power_work(struct work_struct *work) | |||
2635 | } | 2665 | } |
2636 | 2666 | ||
2637 | hda_call_codec_suspend(codec); | 2667 | hda_call_codec_suspend(codec); |
2638 | if (codec->bus->ops.pm_notify) | 2668 | if (bus->ops.pm_notify) |
2639 | codec->bus->ops.pm_notify(codec); | 2669 | bus->ops.pm_notify(bus); |
2640 | } | 2670 | } |
2641 | 2671 | ||
2642 | static void hda_keep_power_on(struct hda_codec *codec) | 2672 | static void hda_keep_power_on(struct hda_codec *codec) |
@@ -2647,13 +2677,15 @@ static void hda_keep_power_on(struct hda_codec *codec) | |||
2647 | 2677 | ||
2648 | void snd_hda_power_up(struct hda_codec *codec) | 2678 | void snd_hda_power_up(struct hda_codec *codec) |
2649 | { | 2679 | { |
2680 | struct hda_bus *bus = codec->bus; | ||
2681 | |||
2650 | codec->power_count++; | 2682 | codec->power_count++; |
2651 | if (codec->power_on || codec->power_transition) | 2683 | if (codec->power_on || codec->power_transition) |
2652 | return; | 2684 | return; |
2653 | 2685 | ||
2654 | codec->power_on = 1; | 2686 | codec->power_on = 1; |
2655 | if (codec->bus->ops.pm_notify) | 2687 | if (bus->ops.pm_notify) |
2656 | codec->bus->ops.pm_notify(codec); | 2688 | bus->ops.pm_notify(bus); |
2657 | hda_call_codec_resume(codec); | 2689 | hda_call_codec_resume(codec); |
2658 | cancel_delayed_work(&codec->power_work); | 2690 | cancel_delayed_work(&codec->power_work); |
2659 | codec->power_transition = 0; | 2691 | codec->power_transition = 0; |