static int snd_bcm2835_alsa_probe_dt(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct bcm2835_chip *chip; struct snd_card *card; u32 numchans; int err, i; err = of_property_read_u32(dev->of_node, "brcm,pwm-channels", &numchans); if (err) { dev_err(dev, "Failed to get DT property 'brcm,pwm-channels'"); return err; } if (numchans == 0 || numchans > MAX_SUBSTREAMS) { numchans = MAX_SUBSTREAMS; dev_warn(dev, "Illegal 'brcm,pwm-channels' value, will use %u\n", numchans); } err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card); if (err) { dev_err(dev, "Failed to create soundcard structure\n"); return err; } snd_card_set_dev(card, dev); strcpy(card->driver, "bcm2835"); strcpy(card->shortname, "bcm2835 ALSA"); sprintf(card->longname, "%s", card->shortname); err = snd_bcm2835_create(card, pdev, &chip); if (err < 0) { dev_err(dev, "Failed to create bcm2835 chip\n"); goto err_free; } err = snd_bcm2835_new_pcm(chip); if (err < 0) { dev_err(dev, "Failed to create new bcm2835 pcm device\n"); goto err_free; } err = snd_bcm2835_new_spdif_pcm(chip); if (err < 0) { dev_err(dev, "Failed to create new bcm2835 spdif pcm device\n"); goto err_free; } err = snd_bcm2835_new_ctl(chip); if (err < 0) { dev_err(dev, "Failed to create new bcm2835 ctl\n"); goto err_free; } for (i = 0; i < numchans; i++) { chip->avail_substreams |= (1 << i); chip->pdev[i] = pdev; } err = snd_card_register(card); if (err) { dev_err(dev, "Failed to register bcm2835 ALSA card\n"); goto err_free; } g_card = card; g_chip = chip; platform_set_drvdata(pdev, card); audio_info("bcm2835 ALSA card created with %u channels\n", numchans); return 0; err_free: snd_card_free(card); return err; }
static int snd_bcm2835_alsa_probe(struct platform_device *pdev) { static int dev; bcm2835_chip_t *chip; struct snd_card *card; int err; if (dev >= MAX_SUBSTREAMS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } if (dev > 0) goto add_register_map; err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card); if (err < 0) goto out; snd_card_set_dev(g_card, &pdev->dev); strcpy(g_card->driver, "bcm2835"); strcpy(g_card->shortname, "bcm2835 ALSA"); sprintf(g_card->longname, "%s", g_card->shortname); err = snd_bcm2835_create(g_card, pdev, &chip); if (err < 0) { dev_err(&pdev->dev, "Failed to create bcm2835 chip\n"); goto out_bcm2835_create; } g_chip = chip; err = snd_bcm2835_new_pcm(chip); if (err < 0) { dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n"); goto out_bcm2835_new_pcm; } err = snd_bcm2835_new_spdif_pcm(chip); if (err < 0) { dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n"); goto out_bcm2835_new_spdif; } err = snd_bcm2835_new_ctl(chip); if (err < 0) { dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n"); goto out_bcm2835_new_ctl; } add_register_map: card = g_card; chip = g_chip; BUG_ON(!(card && chip)); chip->avail_substreams |= (1 << dev); chip->pdev[dev] = pdev; if (dev == 0) { err = snd_card_register(card); if (err < 0) { dev_err(&pdev->dev, "Failed to register bcm2835 ALSA card \n"); goto out_card_register; } platform_set_drvdata(pdev, card); audio_info("bcm2835 ALSA card created!\n"); } else { audio_info("bcm2835 ALSA chip created!\n"); platform_set_drvdata(pdev, (void *)dev); } dev++; return 0; out_card_register: out_bcm2835_new_ctl: out_bcm2835_new_spdif: out_bcm2835_new_pcm: out_bcm2835_create: BUG_ON(!g_card); if (snd_card_free(g_card)) dev_err(&pdev->dev, "Failed to free Registered alsa card\n"); g_card = NULL; out: dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */ dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n"); return err; }