Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ads117x.c -- Driver for ads1174/8 ADC chips |
| 3 | * |
| 4 | * Copyright 2009 ShotSpotter Inc. |
| 5 | * Author: Graeme Gregory <gg@slimlogic.co.uk> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <sound/core.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/initval.h> |
| 20 | #include <sound/soc.h> |
| 21 | |
| 22 | #include "ads117x.h" |
| 23 | |
| 24 | #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000) |
| 25 | |
| 26 | #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 27 | |
| 28 | struct snd_soc_dai ads117x_dai = { |
| 29 | /* ADC */ |
| 30 | .name = "ADS117X ADC", |
| 31 | .id = 1, |
| 32 | .capture = { |
| 33 | .stream_name = "Capture", |
| 34 | .channels_min = 1, |
| 35 | .channels_max = 32, |
| 36 | .rates = ADS117X_RATES, |
| 37 | .formats = ADS117X_FORMATS,}, |
| 38 | }; |
| 39 | EXPORT_SYMBOL_GPL(ads117x_dai); |
| 40 | |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 41 | static int ads117x_probe(struct platform_device *pdev) |
| 42 | { |
| 43 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 44 | struct snd_soc_codec *codec; |
| 45 | int ret; |
| 46 | |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 47 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 48 | if (codec == NULL) |
| 49 | return -ENOMEM; |
| 50 | |
| 51 | socdev->card->codec = codec; |
| 52 | mutex_init(&codec->mutex); |
| 53 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 54 | INIT_LIST_HEAD(&codec->dapm_paths); |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 55 | codec->name = "ADS117X"; |
| 56 | codec->owner = THIS_MODULE; |
| 57 | codec->dai = &ads117x_dai; |
| 58 | codec->num_dai = 1; |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 59 | |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 60 | /* register pcms */ |
| 61 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 62 | if (ret < 0) { |
| 63 | printk(KERN_ERR "ads117x: failed to create pcms\n"); |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 64 | kfree(codec); |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 65 | return ret; |
| 66 | } |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 67 | |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 68 | return 0; |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static int ads117x_remove(struct platform_device *pdev) |
| 72 | { |
| 73 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 74 | struct snd_soc_codec *codec = socdev->card->codec; |
| 75 | |
| 76 | snd_soc_free_pcms(socdev); |
| 77 | kfree(codec); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | struct snd_soc_codec_device soc_codec_dev_ads117x = { |
| 83 | .probe = ads117x_probe, |
| 84 | .remove = ads117x_remove, |
| 85 | }; |
| 86 | EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x); |
| 87 | |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 88 | static __devinit int ads117x_platform_probe(struct platform_device *pdev) |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 89 | { |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 90 | ads117x_dai.dev = &pdev->dev; |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 91 | return snd_soc_register_dai(&ads117x_dai); |
| 92 | } |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 93 | |
| 94 | static int __devexit ads117x_platform_remove(struct platform_device *pdev) |
| 95 | { |
| 96 | snd_soc_unregister_dai(&ads117x_dai); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static struct platform_driver ads117x_codec_driver = { |
| 101 | .driver = { |
| 102 | .name = "ads117x", |
| 103 | .owner = THIS_MODULE, |
| 104 | }, |
| 105 | |
| 106 | .probe = ads117x_platform_probe, |
| 107 | .remove = __devexit_p(ads117x_platform_remove), |
| 108 | }; |
| 109 | |
| 110 | static int __init ads117x_init(void) |
| 111 | { |
| 112 | return platform_driver_register(&ads117x_codec_driver); |
| 113 | } |
| 114 | module_init(ads117x_init); |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 115 | |
| 116 | static void __exit ads117x_exit(void) |
| 117 | { |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 118 | platform_driver_unregister(&ads117x_codec_driver); |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 119 | } |
| 120 | module_exit(ads117x_exit); |
| 121 | |
| 122 | MODULE_DESCRIPTION("ASoC ads117x driver"); |
| 123 | MODULE_AUTHOR("Graeme Gregory"); |
| 124 | MODULE_LICENSE("GPL"); |