Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * ALSA SoC SPDIF DIT driver |
| 3 | * |
| 4 | * This driver is used by controllers which can operate in DIT (SPDI/F) where |
| 5 | * no codec is needed. This file provides stub codec that can be used |
| 6 | * in these configurations. TI DaVinci Audio controller uses this driver. |
| 7 | * |
| 8 | * Author: Steve Chen, <schen@mvista.com> |
| 9 | * Copyright: (C) 2009 MontaVista Software, Inc., <source@mvista.com> |
| 10 | * Copyright: (C) 2009 Texas Instruments, India |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/moduleparam.h> |
Mark Brown | 37a5ddf | 2010-05-31 13:47:26 +0100 | [diff] [blame^] | 19 | #include <linux/slab.h> |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 20 | #include <sound/soc.h> |
| 21 | #include <sound/pcm.h> |
Seungwhan Youn | 3a64291 | 2010-05-27 18:13:48 +0900 | [diff] [blame] | 22 | #include <sound/initval.h> |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 23 | |
Mark Brown | 203350c | 2009-05-28 14:51:00 +0100 | [diff] [blame] | 24 | #include "spdif_transciever.h" |
| 25 | |
Kevin Hilman | 0a0cf58 | 2009-07-13 14:50:40 -0700 | [diff] [blame] | 26 | MODULE_LICENSE("GPL"); |
| 27 | |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 28 | #define STUB_RATES SNDRV_PCM_RATE_8000_96000 |
| 29 | #define STUB_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 30 | |
Seungwhan Youn | 3a64291 | 2010-05-27 18:13:48 +0900 | [diff] [blame] | 31 | static struct snd_soc_codec *spdif_dit_codec; |
| 32 | |
| 33 | static int spdif_dit_codec_probe(struct platform_device *pdev) |
| 34 | { |
| 35 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 36 | struct snd_soc_codec *codec; |
| 37 | int ret; |
| 38 | |
| 39 | if (spdif_dit_codec == NULL) { |
| 40 | dev_err(&pdev->dev, "Codec device not registered\n"); |
| 41 | return -ENODEV; |
| 42 | } |
| 43 | |
| 44 | socdev->card->codec = spdif_dit_codec; |
| 45 | codec = spdif_dit_codec; |
| 46 | |
| 47 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 48 | if (ret < 0) { |
| 49 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); |
| 50 | goto err_create_pcms; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | |
| 55 | err_create_pcms: |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | static int spdif_dit_codec_remove(struct platform_device *pdev) |
| 60 | { |
| 61 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 62 | |
| 63 | snd_soc_free_pcms(socdev); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | struct snd_soc_codec_device soc_codec_dev_spdif_dit = { |
| 69 | .probe = spdif_dit_codec_probe, |
| 70 | .remove = spdif_dit_codec_remove, |
| 71 | }; EXPORT_SYMBOL_GPL(soc_codec_dev_spdif_dit); |
| 72 | |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 73 | struct snd_soc_dai dit_stub_dai = { |
| 74 | .name = "DIT", |
| 75 | .playback = { |
| 76 | .stream_name = "Playback", |
| 77 | .channels_min = 1, |
| 78 | .channels_max = 384, |
| 79 | .rates = STUB_RATES, |
| 80 | .formats = STUB_FORMATS, |
| 81 | }, |
| 82 | }; |
Kevin Hilman | a27e304 | 2009-07-13 14:50:39 -0700 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(dit_stub_dai); |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 84 | |
| 85 | static int spdif_dit_probe(struct platform_device *pdev) |
| 86 | { |
Seungwhan Youn | 3a64291 | 2010-05-27 18:13:48 +0900 | [diff] [blame] | 87 | struct snd_soc_codec *codec; |
| 88 | int ret; |
| 89 | |
| 90 | if (spdif_dit_codec) { |
| 91 | dev_err(&pdev->dev, "Another Codec is registered\n"); |
| 92 | ret = -EINVAL; |
| 93 | goto err_reg_codec; |
| 94 | } |
| 95 | |
| 96 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 97 | if (codec == NULL) |
| 98 | return -ENOMEM; |
| 99 | |
| 100 | codec->dev = &pdev->dev; |
| 101 | |
| 102 | mutex_init(&codec->mutex); |
| 103 | |
| 104 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 105 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 106 | |
| 107 | codec->name = "spdif-dit"; |
| 108 | codec->owner = THIS_MODULE; |
| 109 | codec->dai = &dit_stub_dai; |
| 110 | codec->num_dai = 1; |
| 111 | |
| 112 | spdif_dit_codec = codec; |
| 113 | |
| 114 | ret = snd_soc_register_codec(codec); |
| 115 | if (ret < 0) { |
| 116 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); |
| 117 | goto err_reg_codec; |
| 118 | } |
| 119 | |
Mark Brown | 203350c | 2009-05-28 14:51:00 +0100 | [diff] [blame] | 120 | dit_stub_dai.dev = &pdev->dev; |
Seungwhan Youn | 3a64291 | 2010-05-27 18:13:48 +0900 | [diff] [blame] | 121 | ret = snd_soc_register_dai(&dit_stub_dai); |
| 122 | if (ret < 0) { |
| 123 | dev_err(codec->dev, "Failed to register dai: %d\n", ret); |
| 124 | goto err_reg_dai; |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | |
| 129 | err_reg_dai: |
| 130 | snd_soc_unregister_codec(codec); |
| 131 | err_reg_codec: |
| 132 | kfree(spdif_dit_codec); |
| 133 | return ret; |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static int spdif_dit_remove(struct platform_device *pdev) |
| 137 | { |
| 138 | snd_soc_unregister_dai(&dit_stub_dai); |
Seungwhan Youn | 3a64291 | 2010-05-27 18:13:48 +0900 | [diff] [blame] | 139 | snd_soc_unregister_codec(spdif_dit_codec); |
| 140 | kfree(spdif_dit_codec); |
| 141 | spdif_dit_codec = NULL; |
Chaithrika U S | be461ba | 2009-05-28 05:10:50 -0400 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static struct platform_driver spdif_dit_driver = { |
| 146 | .probe = spdif_dit_probe, |
| 147 | .remove = spdif_dit_remove, |
| 148 | .driver = { |
| 149 | .name = "spdif-dit", |
| 150 | .owner = THIS_MODULE, |
| 151 | }, |
| 152 | }; |
| 153 | |
| 154 | static int __init dit_modinit(void) |
| 155 | { |
| 156 | return platform_driver_register(&spdif_dit_driver); |
| 157 | } |
| 158 | |
| 159 | static void __exit dit_exit(void) |
| 160 | { |
| 161 | platform_driver_unregister(&spdif_dit_driver); |
| 162 | } |
| 163 | |
| 164 | module_init(dit_modinit); |
| 165 | module_exit(dit_exit); |
| 166 | |