2 * sound/ubicom32/ubi32-generic.c
3 * Interface to ubicom32 virtual audio peripheral
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
29 #include <linux/platform_device.h>
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
32 #include <sound/core.h>
33 #include <sound/pcm.h>
34 #include <sound/initval.h>
37 #define DRIVER_NAME "snd-ubi32-generic"
42 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
45 * Card private data free function
47 void snd_ubi32_generic_free(struct snd_card *card)
50 * Free all the fields in the snd_ubi32_priv struct
52 // Nothing to free at this time because ubi32_priv just maintains pointers
56 * Ubicom audio driver probe() method. Args change depending on whether we use
57 * platform_device or i2c_device.
59 static int snd_ubi32_generic_probe(struct platform_device *dev)
61 struct snd_card *card;
62 struct ubi32_snd_priv *ubi32_priv;
66 * Create a snd_card structure
68 card = snd_card_new(index, "Ubi32-Generic", THIS_MODULE, sizeof(struct ubi32_snd_priv));
74 card->private_free = snd_ubi32_generic_free; /* Not sure if correct */
75 ubi32_priv = card->private_data;
78 * Initialize the snd_card's private data structure
80 ubi32_priv->card = card;
83 * Create the new PCM instance
85 err = snd_ubi32_pcm_probe(ubi32_priv, dev);
91 strcpy(card->driver, "Ubi32-Generic");
92 strcpy(card->shortname, "Ubi32-Generic");
93 snprintf(card->longname, sizeof(card->longname),
94 "%s at sendirq=%d.%d recvirq=%d.%d regs=%p",
95 card->shortname, ubi32_priv->tx_irq, ubi32_priv->irq_idx,
96 ubi32_priv->rx_irq, ubi32_priv->irq_idx, ubi32_priv->adr);
98 snd_card_set_dev(card, &dev->dev);
100 /* Register the sound card */
101 if ((err = snd_card_register(card)) != 0) {
102 snd_printk(KERN_INFO "snd_card_register error\n");
105 /* Store card for access from other methods */
106 platform_set_drvdata(dev, card);
112 * Ubicom audio driver remove() method
114 static int __devexit snd_ubi32_generic_remove(struct platform_device *dev)
116 struct snd_card *card;
117 struct ubi32_snd_priv *ubi32_priv;
119 card = platform_get_drvdata(dev);
120 ubi32_priv = card->private_data;
121 snd_ubi32_pcm_remove(ubi32_priv);
123 snd_card_free(platform_get_drvdata(dev));
124 platform_set_drvdata(dev, NULL);
129 * Platform driver definition
131 static struct platform_driver snd_ubi32_generic_driver = {
134 .owner = THIS_MODULE,
136 .probe = snd_ubi32_generic_probe,
137 .remove = __devexit_p(snd_ubi32_generic_remove),
141 * snd_ubi32_generic_init
143 static int __init snd_ubi32_generic_init(void)
145 return platform_driver_register(&snd_ubi32_generic_driver);
147 module_init(snd_ubi32_generic_init);
150 * snd_ubi32_generic_exit
152 static void __exit snd_ubi32_generic_exit(void)
154 platform_driver_unregister(&snd_ubi32_generic_driver);
156 module_exit(snd_ubi32_generic_exit);
161 //#if defined(CONFIG_SND_UBI32_AUDIO_I2C)
162 //MODULE_ALIAS("i2c:snd-ubi32");
164 MODULE_AUTHOR("Aaron Jow, Patrick Tjin");
165 MODULE_DESCRIPTION("Driver for Ubicom32 audio devices");
166 MODULE_LICENSE("GPL");