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 | |
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')
-rw-r--r-- | sound/pci/hda/hda_codec.c | 62 | ||||
-rw-r--r-- | sound/pci/hda/hda_codec.h | 10 | ||||
-rw-r--r-- | sound/pci/hda/hda_intel.c | 61 |
3 files changed, 79 insertions, 54 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; |
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index c5f91c918d19..a73f0eb99283 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -556,17 +556,17 @@ typedef u16 hda_nid_t; | |||
556 | /* bus operators */ | 556 | /* bus operators */ |
557 | struct hda_bus_ops { | 557 | struct hda_bus_ops { |
558 | /* send a single command */ | 558 | /* send a single command */ |
559 | int (*command)(struct hda_codec *codec, hda_nid_t nid, int direct, | 559 | int (*command)(struct hda_bus *bus, unsigned int cmd); |
560 | unsigned int verb, unsigned int parm); | ||
561 | /* get a response from the last command */ | 560 | /* get a response from the last command */ |
562 | unsigned int (*get_response)(struct hda_codec *codec); | 561 | unsigned int (*get_response)(struct hda_bus *bus); |
563 | /* free the private data */ | 562 | /* free the private data */ |
564 | void (*private_free)(struct hda_bus *); | 563 | void (*private_free)(struct hda_bus *); |
565 | /* attach a PCM stream */ | 564 | /* attach a PCM stream */ |
566 | int (*attach_pcm)(struct hda_codec *codec, struct hda_pcm *pcm); | 565 | int (*attach_pcm)(struct hda_bus *bus, struct hda_codec *codec, |
566 | struct hda_pcm *pcm); | ||
567 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 567 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
568 | /* notify power-up/down from codec to controller */ | 568 | /* notify power-up/down from codec to controller */ |
569 | void (*pm_notify)(struct hda_codec *codec); | 569 | void (*pm_notify)(struct hda_bus *bus); |
570 | #endif | 570 | #endif |
571 | }; | 571 | }; |
572 | 572 | ||
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 614be2ec806f..bf8e6f94aebc 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -527,9 +527,9 @@ static void azx_free_cmd_io(struct azx *chip) | |||
527 | } | 527 | } |
528 | 528 | ||
529 | /* send a command */ | 529 | /* send a command */ |
530 | static int azx_corb_send_cmd(struct hda_codec *codec, u32 val) | 530 | static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) |
531 | { | 531 | { |
532 | struct azx *chip = codec->bus->private_data; | 532 | struct azx *chip = bus->private_data; |
533 | unsigned int wp; | 533 | unsigned int wp; |
534 | 534 | ||
535 | /* add command to corb */ | 535 | /* add command to corb */ |
@@ -577,9 +577,9 @@ static void azx_update_rirb(struct azx *chip) | |||
577 | } | 577 | } |
578 | 578 | ||
579 | /* receive a response */ | 579 | /* receive a response */ |
580 | static unsigned int azx_rirb_get_response(struct hda_codec *codec) | 580 | static unsigned int azx_rirb_get_response(struct hda_bus *bus) |
581 | { | 581 | { |
582 | struct azx *chip = codec->bus->private_data; | 582 | struct azx *chip = bus->private_data; |
583 | unsigned long timeout; | 583 | unsigned long timeout; |
584 | 584 | ||
585 | again: | 585 | again: |
@@ -596,7 +596,7 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec) | |||
596 | } | 596 | } |
597 | if (time_after(jiffies, timeout)) | 597 | if (time_after(jiffies, timeout)) |
598 | break; | 598 | break; |
599 | if (codec->bus->needs_damn_long_delay) | 599 | if (bus->needs_damn_long_delay) |
600 | msleep(2); /* temporary workaround */ | 600 | msleep(2); /* temporary workaround */ |
601 | else { | 601 | else { |
602 | udelay(10); | 602 | udelay(10); |
@@ -646,9 +646,9 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec) | |||
646 | */ | 646 | */ |
647 | 647 | ||
648 | /* send a command */ | 648 | /* send a command */ |
649 | static int azx_single_send_cmd(struct hda_codec *codec, u32 val) | 649 | static int azx_single_send_cmd(struct hda_bus *bus, u32 val) |
650 | { | 650 | { |
651 | struct azx *chip = codec->bus->private_data; | 651 | struct azx *chip = bus->private_data; |
652 | int timeout = 50; | 652 | int timeout = 50; |
653 | 653 | ||
654 | while (timeout--) { | 654 | while (timeout--) { |
@@ -671,9 +671,9 @@ static int azx_single_send_cmd(struct hda_codec *codec, u32 val) | |||
671 | } | 671 | } |
672 | 672 | ||
673 | /* receive a response */ | 673 | /* receive a response */ |
674 | static unsigned int azx_single_get_response(struct hda_codec *codec) | 674 | static unsigned int azx_single_get_response(struct hda_bus *bus) |
675 | { | 675 | { |
676 | struct azx *chip = codec->bus->private_data; | 676 | struct azx *chip = bus->private_data; |
677 | int timeout = 50; | 677 | int timeout = 50; |
678 | 678 | ||
679 | while (timeout--) { | 679 | while (timeout--) { |
@@ -696,38 +696,29 @@ static unsigned int azx_single_get_response(struct hda_codec *codec) | |||
696 | */ | 696 | */ |
697 | 697 | ||
698 | /* send a command */ | 698 | /* send a command */ |
699 | static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid, | 699 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val) |
700 | int direct, unsigned int verb, | ||
701 | unsigned int para) | ||
702 | { | 700 | { |
703 | struct azx *chip = codec->bus->private_data; | 701 | struct azx *chip = bus->private_data; |
704 | u32 val; | ||
705 | |||
706 | val = (u32)(codec->addr & 0x0f) << 28; | ||
707 | val |= (u32)direct << 27; | ||
708 | val |= (u32)nid << 20; | ||
709 | val |= verb << 8; | ||
710 | val |= para; | ||
711 | chip->last_cmd = val; | ||
712 | 702 | ||
703 | chip->last_cmd = val; | ||
713 | if (chip->single_cmd) | 704 | if (chip->single_cmd) |
714 | return azx_single_send_cmd(codec, val); | 705 | return azx_single_send_cmd(bus, val); |
715 | else | 706 | else |
716 | return azx_corb_send_cmd(codec, val); | 707 | return azx_corb_send_cmd(bus, val); |
717 | } | 708 | } |
718 | 709 | ||
719 | /* get a response */ | 710 | /* get a response */ |
720 | static unsigned int azx_get_response(struct hda_codec *codec) | 711 | static unsigned int azx_get_response(struct hda_bus *bus) |
721 | { | 712 | { |
722 | struct azx *chip = codec->bus->private_data; | 713 | struct azx *chip = bus->private_data; |
723 | if (chip->single_cmd) | 714 | if (chip->single_cmd) |
724 | return azx_single_get_response(codec); | 715 | return azx_single_get_response(bus); |
725 | else | 716 | else |
726 | return azx_rirb_get_response(codec); | 717 | return azx_rirb_get_response(bus); |
727 | } | 718 | } |
728 | 719 | ||
729 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 720 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
730 | static void azx_power_notify(struct hda_codec *codec); | 721 | static void azx_power_notify(struct hda_bus *bus); |
731 | #endif | 722 | #endif |
732 | 723 | ||
733 | /* reset codec link */ | 724 | /* reset codec link */ |
@@ -1184,7 +1175,8 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) | |||
1184 | return 0; | 1175 | return 0; |
1185 | } | 1176 | } |
1186 | 1177 | ||
1187 | static int azx_attach_pcm_stream(struct hda_codec *codec, struct hda_pcm *cpcm); | 1178 | static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, |
1179 | struct hda_pcm *cpcm); | ||
1188 | 1180 | ||
1189 | /* | 1181 | /* |
1190 | * Codec initialization | 1182 | * Codec initialization |
@@ -1707,9 +1699,10 @@ static void azx_pcm_free(struct snd_pcm *pcm) | |||
1707 | } | 1699 | } |
1708 | 1700 | ||
1709 | static int | 1701 | static int |
1710 | azx_attach_pcm_stream(struct hda_codec *codec, struct hda_pcm *cpcm) | 1702 | azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, |
1703 | struct hda_pcm *cpcm) | ||
1711 | { | 1704 | { |
1712 | struct azx *chip = codec->bus->private_data; | 1705 | struct azx *chip = bus->private_data; |
1713 | struct snd_pcm *pcm; | 1706 | struct snd_pcm *pcm; |
1714 | struct azx_pcm *apcm; | 1707 | struct azx_pcm *apcm; |
1715 | int pcm_dev = cpcm->device; | 1708 | int pcm_dev = cpcm->device; |
@@ -1827,13 +1820,13 @@ static void azx_stop_chip(struct azx *chip) | |||
1827 | 1820 | ||
1828 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 1821 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1829 | /* power-up/down the controller */ | 1822 | /* power-up/down the controller */ |
1830 | static void azx_power_notify(struct hda_codec *codec) | 1823 | static void azx_power_notify(struct hda_bus *bus) |
1831 | { | 1824 | { |
1832 | struct azx *chip = codec->bus->private_data; | 1825 | struct azx *chip = bus->private_data; |
1833 | struct hda_codec *c; | 1826 | struct hda_codec *c; |
1834 | int power_on = 0; | 1827 | int power_on = 0; |
1835 | 1828 | ||
1836 | list_for_each_entry(c, &codec->bus->codec_list, list) { | 1829 | list_for_each_entry(c, &bus->codec_list, list) { |
1837 | if (c->power_on) { | 1830 | if (c->power_on) { |
1838 | power_on = 1; | 1831 | power_on = 1; |
1839 | break; | 1832 | break; |