Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: hda - Split snd_hda_build_pcms()

snd_hda_build_pcms() does actually three things: let the codec driver
build up hda_pcm list, set the PCM default values, and call the
attach_pcm bus ops for each hda_pcm instance. The former two are
basically independent from the bus implementation, so it'd make the
code a bit more readable.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

+60 -43
+59 -43
sound/pci/hda/hda_codec.c
··· 4569 4569 return -EAGAIN; 4570 4570 } 4571 4571 4572 - /* 4573 - * attach a new PCM stream 4574 - */ 4575 - static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) 4572 + /* call build_pcms ops of the given codec and set up the default parameters */ 4573 + int snd_hda_codec_parse_pcms(struct hda_codec *codec) 4576 4574 { 4577 - struct hda_bus *bus = codec->bus; 4578 - struct hda_pcm_stream *info; 4579 - int stream, err; 4575 + unsigned int pcm; 4576 + int err; 4580 4577 4581 - if (snd_BUG_ON(!pcm->name)) 4582 - return -EINVAL; 4583 - for (stream = 0; stream < 2; stream++) { 4584 - info = &pcm->stream[stream]; 4585 - if (info->substreams) { 4578 + if (codec->num_pcms) 4579 + return 0; /* already parsed */ 4580 + 4581 + if (!codec->patch_ops.build_pcms) 4582 + return 0; 4583 + 4584 + err = codec->patch_ops.build_pcms(codec); 4585 + if (err < 0) { 4586 + codec_err(codec, "cannot build PCMs for #%d (error %d)\n", 4587 + codec->addr, err); 4588 + return err; 4589 + } 4590 + 4591 + for (pcm = 0; pcm < codec->num_pcms; pcm++) { 4592 + struct hda_pcm *cpcm = &codec->pcm_info[pcm]; 4593 + int stream; 4594 + 4595 + for (stream = 0; stream < 2; stream++) { 4596 + struct hda_pcm_stream *info = &cpcm->stream[stream]; 4597 + 4598 + if (!info->substreams) 4599 + continue; 4600 + if (snd_BUG_ON(!cpcm->name)) 4601 + return -EINVAL; 4586 4602 err = set_pcm_default_values(codec, info); 4587 - if (err < 0) 4603 + if (err < 0) { 4604 + codec_warn(codec, 4605 + "fail to setup default for PCM %s\n", 4606 + cpcm->name); 4588 4607 return err; 4608 + } 4589 4609 } 4590 4610 } 4591 - return bus->ops.attach_pcm(bus, codec, pcm); 4611 + 4612 + return 0; 4592 4613 } 4593 4614 4594 4615 /* assign all PCMs of the given codec */ 4595 4616 int snd_hda_codec_build_pcms(struct hda_codec *codec) 4596 4617 { 4618 + struct hda_bus *bus = codec->bus; 4597 4619 unsigned int pcm; 4598 - int err; 4620 + int dev, err; 4599 4621 4600 - if (!codec->num_pcms) { 4601 - if (!codec->patch_ops.build_pcms) 4602 - return 0; 4603 - err = codec->patch_ops.build_pcms(codec); 4604 - if (err < 0) { 4605 - codec_err(codec, 4606 - "cannot build PCMs for #%d (error %d)\n", 4607 - codec->addr, err); 4608 - err = snd_hda_codec_reset(codec); 4609 - if (err < 0) { 4610 - codec_err(codec, 4611 - "cannot revert codec\n"); 4612 - return err; 4613 - } 4614 - } 4622 + if (snd_BUG_ON(!bus->ops.attach_pcm)) 4623 + return -EINVAL; 4624 + 4625 + err = snd_hda_codec_parse_pcms(codec); 4626 + if (err < 0) { 4627 + snd_hda_codec_reset(codec); 4628 + return err; 4615 4629 } 4630 + 4631 + /* attach a new PCM streams */ 4616 4632 for (pcm = 0; pcm < codec->num_pcms; pcm++) { 4617 4633 struct hda_pcm *cpcm = &codec->pcm_info[pcm]; 4618 - int dev; 4619 4634 4635 + if (cpcm->pcm) 4636 + continue; /* already attached */ 4620 4637 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) 4621 4638 continue; /* no substreams assigned */ 4622 4639 4623 - if (!cpcm->pcm) { 4624 - dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); 4625 - if (dev < 0) 4626 - continue; /* no fatal error */ 4627 - cpcm->device = dev; 4628 - err = snd_hda_attach_pcm(codec, cpcm); 4629 - if (err < 0) { 4630 - codec_err(codec, 4631 - "cannot attach PCM stream %d for codec #%d\n", 4632 - dev, codec->addr); 4633 - continue; /* no fatal error */ 4634 - } 4640 + dev = get_empty_pcm_device(bus, cpcm->pcm_type); 4641 + if (dev < 0) 4642 + continue; /* no fatal error */ 4643 + cpcm->device = dev; 4644 + err = bus->ops.attach_pcm(bus, codec, cpcm); 4645 + if (err < 0) { 4646 + codec_err(codec, 4647 + "cannot attach PCM stream %d for codec #%d\n", 4648 + dev, codec->addr); 4649 + continue; /* no fatal error */ 4635 4650 } 4636 4651 } 4652 + 4637 4653 return 0; 4638 4654 } 4639 4655
+1
sound/pci/hda/hda_codec.h
··· 517 517 * PCM 518 518 */ 519 519 int snd_hda_build_pcms(struct hda_bus *bus); 520 + int snd_hda_codec_parse_pcms(struct hda_codec *codec); 520 521 int snd_hda_codec_build_pcms(struct hda_codec *codec); 521 522 522 523 int snd_hda_codec_prepare(struct hda_codec *codec,