1 /*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
13 *****************************************************************************/
15 #include <linux/platform_device.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
24 /* HACKY global pointers needed for successive probes to work : ssp
25 * But compared against the changes we will have to do in VC audio_ipc code
26 * to export 8 audio_ipc devices as a single IPC device and then monitor all
27 * four devices in a thread, this gets things done quickly and should be easier
28 * to debug if we run into issues
31 static struct snd_card *g_card;
32 static struct bcm2835_chip *g_chip;
34 static int snd_bcm2835_free(struct bcm2835_chip *chip)
40 /* component-destructor
41 * (see "Management of Cards and Components")
43 static int snd_bcm2835_dev_free(struct snd_device *device)
45 return snd_bcm2835_free(device->device_data);
48 /* chip-specific constructor
49 * (see "Management of Cards and Components")
51 static int snd_bcm2835_create(struct snd_card *card,
52 struct platform_device *pdev,
53 struct bcm2835_chip **rchip)
55 struct bcm2835_chip *chip;
57 static struct snd_device_ops ops = {
58 .dev_free = snd_bcm2835_dev_free,
63 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
69 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
71 snd_bcm2835_free(chip);
79 static int snd_bcm2835_alsa_probe_dt(struct platform_device *pdev)
81 struct device *dev = &pdev->dev;
82 struct bcm2835_chip *chip;
83 struct snd_card *card;
87 err = of_property_read_u32(dev->of_node, "brcm,pwm-channels",
90 dev_err(dev, "Failed to get DT property 'brcm,pwm-channels'");
94 if (numchans == 0 || numchans > MAX_SUBSTREAMS) {
95 numchans = MAX_SUBSTREAMS;
96 dev_warn(dev, "Illegal 'brcm,pwm-channels' value, will use %u\n",
100 err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card);
102 dev_err(dev, "Failed to create soundcard structure\n");
106 snd_card_set_dev(card, dev);
107 strcpy(card->driver, "bcm2835");
108 strcpy(card->shortname, "bcm2835 ALSA");
109 sprintf(card->longname, "%s", card->shortname);
111 err = snd_bcm2835_create(card, pdev, &chip);
113 dev_err(dev, "Failed to create bcm2835 chip\n");
117 err = snd_bcm2835_new_pcm(chip);
119 dev_err(dev, "Failed to create new bcm2835 pcm device\n");
123 err = snd_bcm2835_new_spdif_pcm(chip);
125 dev_err(dev, "Failed to create new bcm2835 spdif pcm device\n");
129 err = snd_bcm2835_new_ctl(chip);
131 dev_err(dev, "Failed to create new bcm2835 ctl\n");
135 for (i = 0; i < numchans; i++) {
136 chip->avail_substreams |= (1 << i);
137 chip->pdev[i] = pdev;
140 err = snd_card_register(card);
142 dev_err(dev, "Failed to register bcm2835 ALSA card\n");
148 platform_set_drvdata(pdev, card);
149 audio_info("bcm2835 ALSA card created with %u channels\n", numchans);
159 static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
164 drv_data = platform_get_drvdata(pdev);
166 if (drv_data == (void *)g_card) {
167 /* This is the card device */
168 snd_card_free((struct snd_card *)drv_data);
172 idx = (int)(long)drv_data;
175 /* We pass chip device numbers in audio ipc devices
176 * other than the one we registered our card with
178 idx = (int)(long)drv_data;
179 BUG_ON(!idx || idx > MAX_SUBSTREAMS);
180 g_chip->avail_substreams &= ~(1 << idx);
181 /* There should be atleast one substream registered
182 * after we are done here, as it wil be removed when
183 * the *remove* is called for the card device
185 BUG_ON(!g_chip->avail_substreams);
189 platform_set_drvdata(pdev, NULL);
196 static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
202 static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
209 static const struct of_device_id snd_bcm2835_of_match_table[] = {
210 { .compatible = "brcm,bcm2835-audio",},
213 MODULE_DEVICE_TABLE(of, snd_bcm2835_of_match_table);
215 static struct platform_driver bcm2835_alsa0_driver = {
216 .probe = snd_bcm2835_alsa_probe_dt,
217 .remove = snd_bcm2835_alsa_remove,
219 .suspend = snd_bcm2835_alsa_suspend,
220 .resume = snd_bcm2835_alsa_resume,
223 .name = "bcm2835_AUD0",
224 .owner = THIS_MODULE,
225 .of_match_table = snd_bcm2835_of_match_table,
229 static int bcm2835_alsa_device_init(void)
233 retval = platform_driver_register(&bcm2835_alsa0_driver);
235 pr_err("Error registering bcm2835_alsa0_driver %d .\n", retval);
240 static void bcm2835_alsa_device_exit(void)
242 platform_driver_unregister(&bcm2835_alsa0_driver);
245 late_initcall(bcm2835_alsa_device_init);
246 module_exit(bcm2835_alsa_device_exit);
248 MODULE_AUTHOR("Dom Cobley");
249 MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
250 MODULE_LICENSE("GPL");