disable sstrip when using musl
[lede.git] / target / linux / ubicom32 / files / sound / ubicom32 / ubi32-generic.c
1 /*
2  * sound/ubicom32/ubi32-generic.c
3  *      Interface to ubicom32 virtual audio peripheral
4  *
5  * (C) Copyright 2009, Ubicom, Inc.
6  *
7  * This file is part of the Ubicom32 Linux Kernel Port.
8  *
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.
13  *
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.
18  *
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/>.
22  *
23  * Ubicom32 implementation derived from (with many thanks):
24  *   arch/m68knommu
25  *   arch/blackfin
26  *   arch/parisc
27  */
28
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>
35 #include "ubi32.h"
36
37 #define DRIVER_NAME "snd-ubi32-generic"
38
39 /*
40  * Module properties
41  */
42 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
43
44 /*
45  * Card private data free function
46  */
47 void snd_ubi32_generic_free(struct snd_card *card)
48 {
49         /*
50          * Free all the fields in the snd_ubi32_priv struct
51          */
52         // Nothing to free at this time because ubi32_priv just maintains pointers
53 }
54
55 /*
56  * Ubicom audio driver probe() method.  Args change depending on whether we use
57  * platform_device or i2c_device.
58  */
59 static int snd_ubi32_generic_probe(struct platform_device *dev)
60 {
61         struct snd_card *card;
62         struct ubi32_snd_priv *ubi32_priv;
63         int err;
64
65         /*
66          * Create a snd_card structure
67          */
68         card = snd_card_new(index, "Ubi32-Generic", THIS_MODULE, sizeof(struct ubi32_snd_priv));
69
70         if (card == NULL) {
71                 return -ENOMEM;
72         }
73
74         card->private_free = snd_ubi32_generic_free; /* Not sure if correct */
75         ubi32_priv = card->private_data;
76
77         /*
78          * Initialize the snd_card's private data structure
79          */
80         ubi32_priv->card = card;
81
82         /*
83          * Create the new PCM instance
84          */
85         err = snd_ubi32_pcm_probe(ubi32_priv, dev);
86         if (err < 0) {
87                 snd_card_free(card);
88                 return err;
89         }
90
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);
97
98         snd_card_set_dev(card, &dev->dev);
99
100         /* Register the sound card */
101         if ((err = snd_card_register(card)) != 0) {
102                 snd_printk(KERN_INFO "snd_card_register error\n");
103         }
104
105         /* Store card for access from other methods */
106         platform_set_drvdata(dev, card);
107
108         return 0;
109 }
110
111 /*
112  * Ubicom audio driver remove() method
113  */
114 static int __devexit snd_ubi32_generic_remove(struct platform_device *dev)
115 {
116         struct snd_card *card;
117         struct ubi32_snd_priv *ubi32_priv;
118
119         card = platform_get_drvdata(dev);
120         ubi32_priv = card->private_data;
121         snd_ubi32_pcm_remove(ubi32_priv);
122
123         snd_card_free(platform_get_drvdata(dev));
124         platform_set_drvdata(dev, NULL);
125         return 0;
126 }
127
128 /*
129  * Platform driver definition
130  */
131 static struct platform_driver snd_ubi32_generic_driver = {
132         .driver = {
133                 .name = DRIVER_NAME,
134                 .owner = THIS_MODULE,
135         },
136         .probe = snd_ubi32_generic_probe,
137         .remove = __devexit_p(snd_ubi32_generic_remove),
138 };
139
140 /*
141  * snd_ubi32_generic_init
142  */
143 static int __init snd_ubi32_generic_init(void)
144 {
145         return platform_driver_register(&snd_ubi32_generic_driver);
146 }
147 module_init(snd_ubi32_generic_init);
148
149 /*
150  * snd_ubi32_generic_exit
151  */
152 static void __exit snd_ubi32_generic_exit(void)
153 {
154         platform_driver_unregister(&snd_ubi32_generic_driver);
155 }
156 module_exit(snd_ubi32_generic_exit);
157
158 /*
159  * Module properties
160  */
161 //#if defined(CONFIG_SND_UBI32_AUDIO_I2C)
162 //MODULE_ALIAS("i2c:snd-ubi32");
163 //#endif
164 MODULE_AUTHOR("Aaron Jow, Patrick Tjin");
165 MODULE_DESCRIPTION("Driver for Ubicom32 audio devices");
166 MODULE_LICENSE("GPL");