| 1 | /* |
| 2 | * sound/ubicom32/ubi32-generic-capture.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-capture" |
| 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_capture_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_capture_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-C", THIS_MODULE, sizeof(struct ubi32_snd_priv)); |
| 69 | |
| 70 | if (card == NULL) { |
| 71 | return -ENOMEM; |
| 72 | } |
| 73 | |
| 74 | card->private_free = snd_ubi32_generic_capture_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 | ubi32_priv->is_capture = 1; |
| 82 | |
| 83 | /* |
| 84 | * Create the new PCM instance |
| 85 | */ |
| 86 | err = snd_ubi32_pcm_probe(ubi32_priv, dev); |
| 87 | if (err < 0) { |
| 88 | snd_card_free(card); |
| 89 | return err; |
| 90 | } |
| 91 | |
| 92 | strcpy(card->driver, "Ubi32-Generic-C"); |
| 93 | strcpy(card->shortname, "Ubi32-Generic-C"); |
| 94 | snprintf(card->longname, sizeof(card->longname), |
| 95 | "%s at sendirq=%d.%d recvirq=%d.%d regs=%p", |
| 96 | card->shortname, ubi32_priv->tx_irq, ubi32_priv->irq_idx, |
| 97 | ubi32_priv->rx_irq, ubi32_priv->irq_idx, ubi32_priv->adr); |
| 98 | |
| 99 | snd_card_set_dev(card, &dev->dev); |
| 100 | |
| 101 | /* Register the sound card */ |
| 102 | if ((err = snd_card_register(card)) != 0) { |
| 103 | snd_printk(KERN_INFO "snd_card_register error\n"); |
| 104 | } |
| 105 | |
| 106 | /* Store card for access from other methods */ |
| 107 | platform_set_drvdata(dev, card); |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Ubicom audio driver remove() method |
| 114 | */ |
| 115 | static int __devexit snd_ubi32_generic_capture_remove(struct platform_device *dev) |
| 116 | { |
| 117 | struct snd_card *card; |
| 118 | struct ubi32_snd_priv *ubi32_priv; |
| 119 | |
| 120 | card = platform_get_drvdata(dev); |
| 121 | ubi32_priv = card->private_data; |
| 122 | snd_ubi32_pcm_remove(ubi32_priv); |
| 123 | |
| 124 | snd_card_free(platform_get_drvdata(dev)); |
| 125 | platform_set_drvdata(dev, NULL); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Platform driver definition |
| 131 | */ |
| 132 | static struct platform_driver snd_ubi32_generic_capture_driver = { |
| 133 | .driver = { |
| 134 | .name = DRIVER_NAME, |
| 135 | .owner = THIS_MODULE, |
| 136 | }, |
| 137 | .probe = snd_ubi32_generic_capture_probe, |
| 138 | .remove = __devexit_p(snd_ubi32_generic_capture_remove), |
| 139 | }; |
| 140 | |
| 141 | /* |
| 142 | * snd_ubi32_generic_capture_init |
| 143 | */ |
| 144 | static int __init snd_ubi32_generic_capture_init(void) |
| 145 | { |
| 146 | return platform_driver_register(&snd_ubi32_generic_capture_driver); |
| 147 | } |
| 148 | module_init(snd_ubi32_generic_capture_init); |
| 149 | |
| 150 | /* |
| 151 | * snd_ubi32_generic_capture_exit |
| 152 | */ |
| 153 | static void __exit snd_ubi32_generic_capture_exit(void) |
| 154 | { |
| 155 | platform_driver_unregister(&snd_ubi32_generic_capture_driver); |
| 156 | } |
| 157 | module_exit(snd_ubi32_generic_capture_exit); |
| 158 | |
| 159 | /* |
| 160 | * Module properties |
| 161 | */ |
| 162 | //#if defined(CONFIG_SND_UBI32_AUDIO_I2C) |
| 163 | //MODULE_ALIAS("i2c:snd-ubi32"); |
| 164 | //#endif |
| 165 | MODULE_AUTHOR("Patrick Tjin"); |
| 166 | MODULE_DESCRIPTION("Driver for Ubicom32 audio devices"); |
| 167 | MODULE_LICENSE("GPL"); |
| 168 | |