diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-27 14:44:54 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-03-03 05:28:36 -0500 |
commit | bcd96557bd0ab1129fcdde073d5700aed8fcb942 (patch) | |
tree | 8f246b3fc0b986ba9d105f632aa7cef485123825 | |
parent | 9a6246ff78ac33af78f82704cde6fec361597eea (diff) |
ALSA: hda - Build PCMs and controls at codec driver probe
This makes the code flow easier -- instead of the controller driver
calling snd_hda_build_pcms() and snd_hda_build_controls() explicitly,
the codec driver itself builds PCMs and controls at probe time. Then
the controller driver only needs to call snd_card_register().
Also, this allows us the full bind/unbind control, too. Even when a
codec driver is bound later, it automatically registers the new PCM
and controls by itself.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/hda/hda_bind.c | 22 | ||||
-rw-r--r-- | sound/pci/hda/hda_codec.c | 67 | ||||
-rw-r--r-- | sound/pci/hda/hda_codec.h | 2 | ||||
-rw-r--r-- | sound/pci/hda/hda_intel.c | 10 | ||||
-rw-r--r-- | sound/pci/hda/hda_tegra.c | 10 |
5 files changed, 17 insertions, 94 deletions
diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 311896a23cd1..a49bc45c2ea5 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c | |||
@@ -106,16 +106,28 @@ static int hda_codec_driver_probe(struct device *dev) | |||
106 | } | 106 | } |
107 | 107 | ||
108 | err = codec->preset->patch(codec); | 108 | err = codec->preset->patch(codec); |
109 | if (err < 0) { | 109 | if (err < 0) |
110 | module_put(owner); | 110 | goto error_module; |
111 | goto error; | 111 | |
112 | err = snd_hda_codec_build_pcms(codec); | ||
113 | if (err < 0) | ||
114 | goto error_module; | ||
115 | err = snd_hda_codec_build_controls(codec); | ||
116 | if (err < 0) | ||
117 | goto error_module; | ||
118 | if (codec->card->registered) { | ||
119 | err = snd_card_register(codec->card); | ||
120 | if (err < 0) | ||
121 | goto error_module; | ||
112 | } | 122 | } |
113 | 123 | ||
114 | return 0; | 124 | return 0; |
115 | 125 | ||
126 | error_module: | ||
127 | module_put(owner); | ||
128 | |||
116 | error: | 129 | error: |
117 | codec->preset = NULL; | 130 | snd_hda_codec_cleanup_for_unbind(codec); |
118 | memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); | ||
119 | return err; | 131 | return err; |
120 | } | 132 | } |
121 | 133 | ||
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 2c7e481a9171..7085d3733d0d 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -4031,36 +4031,6 @@ const struct dev_pm_ops hda_codec_driver_pm = { | |||
4031 | NULL) | 4031 | NULL) |
4032 | }; | 4032 | }; |
4033 | 4033 | ||
4034 | /** | ||
4035 | * snd_hda_build_controls - build mixer controls | ||
4036 | * @bus: the BUS | ||
4037 | * | ||
4038 | * Creates mixer controls for each codec included in the bus. | ||
4039 | * | ||
4040 | * Returns 0 if successful, otherwise a negative error code. | ||
4041 | */ | ||
4042 | int snd_hda_build_controls(struct hda_bus *bus) | ||
4043 | { | ||
4044 | struct hda_codec *codec; | ||
4045 | |||
4046 | list_for_each_entry(codec, &bus->codec_list, list) { | ||
4047 | int err = snd_hda_codec_build_controls(codec); | ||
4048 | if (err < 0) { | ||
4049 | codec_err(codec, | ||
4050 | "cannot build controls for #%d (error %d)\n", | ||
4051 | codec->addr, err); | ||
4052 | err = snd_hda_codec_reset(codec); | ||
4053 | if (err < 0) { | ||
4054 | codec_err(codec, | ||
4055 | "cannot revert codec\n"); | ||
4056 | return err; | ||
4057 | } | ||
4058 | } | ||
4059 | } | ||
4060 | return 0; | ||
4061 | } | ||
4062 | EXPORT_SYMBOL_GPL(snd_hda_build_controls); | ||
4063 | |||
4064 | /* | 4034 | /* |
4065 | * add standard channel maps if not specified | 4035 | * add standard channel maps if not specified |
4066 | */ | 4036 | */ |
@@ -4693,43 +4663,6 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) | |||
4693 | } | 4663 | } |
4694 | 4664 | ||
4695 | /** | 4665 | /** |
4696 | * snd_hda_build_pcms - build PCM information | ||
4697 | * @bus: the BUS | ||
4698 | * | ||
4699 | * Create PCM information for each codec included in the bus. | ||
4700 | * | ||
4701 | * The build_pcms codec patch is requested to create and assign new | ||
4702 | * hda_pcm objects. The codec is responsible to call snd_hda_codec_pcm_new() | ||
4703 | * and fills the fields. Later they are instantiated by this function. | ||
4704 | * | ||
4705 | * At least, substreams, channels_min and channels_max must be filled for | ||
4706 | * each stream. substreams = 0 indicates that the stream doesn't exist. | ||
4707 | * When rates and/or formats are zero, the supported values are queried | ||
4708 | * from the given nid. The nid is used also by the default ops.prepare | ||
4709 | * and ops.cleanup callbacks. | ||
4710 | * | ||
4711 | * The driver needs to call ops.open in its open callback. Similarly, | ||
4712 | * ops.close is supposed to be called in the close callback. | ||
4713 | * ops.prepare should be called in the prepare or hw_params callback | ||
4714 | * with the proper parameters for set up. | ||
4715 | * ops.cleanup should be called in hw_free for clean up of streams. | ||
4716 | * | ||
4717 | * This function returns 0 if successful, or a negative error code. | ||
4718 | */ | ||
4719 | int snd_hda_build_pcms(struct hda_bus *bus) | ||
4720 | { | ||
4721 | struct hda_codec *codec; | ||
4722 | |||
4723 | list_for_each_entry(codec, &bus->codec_list, list) { | ||
4724 | int err = snd_hda_codec_build_pcms(codec); | ||
4725 | if (err < 0) | ||
4726 | return err; | ||
4727 | } | ||
4728 | return 0; | ||
4729 | } | ||
4730 | EXPORT_SYMBOL_GPL(snd_hda_build_pcms); | ||
4731 | |||
4732 | /** | ||
4733 | * snd_hda_add_new_ctls - create controls from the array | 4666 | * snd_hda_add_new_ctls - create controls from the array |
4734 | * @codec: the HDA codec | 4667 | * @codec: the HDA codec |
4735 | * @knew: the array of struct snd_kcontrol_new | 4668 | * @knew: the array of struct snd_kcontrol_new |
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index fc62ca51fd35..46d253e2f266 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -516,13 +516,11 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid); | |||
516 | /* | 516 | /* |
517 | * Mixer | 517 | * Mixer |
518 | */ | 518 | */ |
519 | int snd_hda_build_controls(struct hda_bus *bus); | ||
520 | int snd_hda_codec_build_controls(struct hda_codec *codec); | 519 | int snd_hda_codec_build_controls(struct hda_codec *codec); |
521 | 520 | ||
522 | /* | 521 | /* |
523 | * PCM | 522 | * PCM |
524 | */ | 523 | */ |
525 | int snd_hda_build_pcms(struct hda_bus *bus); | ||
526 | int snd_hda_codec_parse_pcms(struct hda_codec *codec); | 524 | int snd_hda_codec_parse_pcms(struct hda_codec *codec); |
527 | int snd_hda_codec_build_pcms(struct hda_codec *codec); | 525 | int snd_hda_codec_build_pcms(struct hda_codec *codec); |
528 | 526 | ||
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index f7fb1b51d446..e81461a413b8 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -1895,16 +1895,6 @@ static int azx_probe_continue(struct azx *chip) | |||
1895 | goto out_free; | 1895 | goto out_free; |
1896 | } | 1896 | } |
1897 | 1897 | ||
1898 | /* create PCM streams */ | ||
1899 | err = snd_hda_build_pcms(chip->bus); | ||
1900 | if (err < 0) | ||
1901 | goto out_free; | ||
1902 | |||
1903 | /* create mixer controls */ | ||
1904 | err = snd_hda_build_controls(chip->bus); | ||
1905 | if (err < 0) | ||
1906 | goto out_free; | ||
1907 | |||
1908 | err = snd_card_register(chip->card); | 1898 | err = snd_card_register(chip->card); |
1909 | if (err < 0) | 1899 | if (err < 0) |
1910 | goto out_free; | 1900 | goto out_free; |
diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 1359fdd20f02..7586abe91dfb 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c | |||
@@ -497,16 +497,6 @@ static int hda_tegra_probe(struct platform_device *pdev) | |||
497 | if (err < 0) | 497 | if (err < 0) |
498 | goto out_free; | 498 | goto out_free; |
499 | 499 | ||
500 | /* create PCM streams */ | ||
501 | err = snd_hda_build_pcms(chip->bus); | ||
502 | if (err < 0) | ||
503 | goto out_free; | ||
504 | |||
505 | /* create mixer controls */ | ||
506 | err = snd_hda_build_controls(chip->bus); | ||
507 | if (err < 0) | ||
508 | goto out_free; | ||
509 | |||
510 | err = snd_card_register(chip->card); | 500 | err = snd_card_register(chip->card); |
511 | if (err < 0) | 501 | if (err < 0) |
512 | goto out_free; | 502 | goto out_free; |