soc: codecs: rt5639: Implement i2c shutdown
[linux-2.6.git] / sound / soc / tegra / tegra_tdm_pcm.c
1 /*
2  * tegra_tdm_pcm.c - Tegra TDM PCM driver
3  *
4  * Author: Nitin Pai <npai@nvidia.com>
5  * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
6  *
7  * Based on code copyright/by:
8  *
9  * Copyright (c) 2009-2010, NVIDIA CORPORATION.  All rights reserved.
10  * Scott Peterson <speterson@nvidia.com>
11  * Stephen Warren <swarren@nvidia.com>
12  * Vijay Mali <vmali@nvidia.com>
13  *
14  * Copyright (C) 2010 Google, Inc.
15  * Iliyan Malchev <malchev@google.com>
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * version 2 as published by the Free Software Foundation.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29  * 02110-1301 USA
30  *
31  */
32
33 #include <linux/module.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/slab.h>
36 #include <sound/core.h>
37 #include <sound/pcm.h>
38 #include <sound/pcm_params.h>
39 #include <sound/soc.h>
40
41 #include "tegra_pcm.h"
42
43 #define DRV_NAME "tegra-tdm-pcm-audio"
44
45 static const struct snd_pcm_hardware tegra_tdm_pcm_hardware = {
46         .info                   = SNDRV_PCM_INFO_MMAP |
47                                   SNDRV_PCM_INFO_MMAP_VALID |
48                                   SNDRV_PCM_INFO_PAUSE |
49                                   SNDRV_PCM_INFO_RESUME |
50                                   SNDRV_PCM_INFO_INTERLEAVED,
51         .formats                = SNDRV_PCM_FMTBIT_S16_LE,
52         .channels_min           = 8,
53         .channels_max           = 16,
54         .period_bytes_min       = 8 * 1024,
55         .period_bytes_max       = 16 * 1024,
56         .periods_min            = 4,
57         .periods_max            = 4,
58         .buffer_bytes_max       = 16 * 4 * 1024,
59         .fifo_size              = 4,
60 };
61
62 static int tegra_tdm_pcm_open(struct snd_pcm_substream *substream)
63 {
64         return tegra_pcm_allocate(substream,
65                                         TEGRA_DMA_MODE_CONTINUOUS_DOUBLE,
66                                         &tegra_tdm_pcm_hardware);
67
68 }
69
70 static int tegra_tdm_pcm_close(struct snd_pcm_substream *substream)
71 {
72         return tegra_pcm_close(substream);
73 }
74
75 static int tegra_tdm_pcm_hw_params(struct snd_pcm_substream *substream,
76                                 struct snd_pcm_hw_params *params)
77 {
78         return tegra_pcm_hw_params(substream, params);
79 }
80
81 static int tegra_tdm_pcm_hw_free(struct snd_pcm_substream *substream)
82 {
83         return tegra_pcm_hw_free(substream);
84 }
85
86 static int tegra_tdm_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
87 {
88         return tegra_pcm_trigger(substream, cmd);
89 }
90
91 static int tegra_tdm_pcm_mmap(struct snd_pcm_substream *substream,
92                                 struct vm_area_struct *vma)
93 {
94         return tegra_pcm_mmap(substream, vma);
95 }
96
97 static struct snd_pcm_ops tegra_tdm_pcm_ops = {
98         .open           = tegra_tdm_pcm_open,
99         .close          = tegra_tdm_pcm_close,
100         .ioctl          = snd_pcm_lib_ioctl,
101         .hw_params      = tegra_tdm_pcm_hw_params,
102         .hw_free        = tegra_tdm_pcm_hw_free,
103         .trigger        = tegra_tdm_pcm_trigger,
104         .pointer        = tegra_pcm_pointer,
105         .mmap           = tegra_tdm_pcm_mmap,
106 };
107
108 static int tegra_tdm_pcm_new(struct snd_soc_pcm_runtime *rtd)
109 {
110         return tegra_pcm_dma_allocate(rtd ,
111                                 tegra_tdm_pcm_hardware.buffer_bytes_max);
112 }
113
114 static void tegra_tdm_pcm_free(struct snd_pcm *pcm)
115 {
116         return tegra_pcm_free(pcm);
117 }
118
119 struct snd_soc_platform_driver tegra_tdm_pcm_platform = {
120         .ops            = &tegra_tdm_pcm_ops,
121         .pcm_new        = tegra_tdm_pcm_new,
122         .pcm_free       = tegra_tdm_pcm_free,
123 };
124
125 static int __devinit tegra_tdm_pcm_platform_probe(struct platform_device *pdev)
126 {
127         return snd_soc_register_platform(&pdev->dev, &tegra_tdm_pcm_platform);
128 }
129
130 static int __devexit tegra_tdm_pcm_platform_remove(struct platform_device *pdev)
131 {
132         snd_soc_unregister_platform(&pdev->dev);
133         return 0;
134 }
135
136 static struct platform_driver tegra_tdm_pcm_driver = {
137         .driver = {
138                 .name = DRV_NAME,
139                 .owner = THIS_MODULE,
140         },
141         .probe = tegra_tdm_pcm_platform_probe,
142         .remove = __devexit_p(tegra_tdm_pcm_platform_remove),
143 };
144
145 static int __init snd_tegra_tdm_pcm_init(void)
146 {
147         return platform_driver_register(&tegra_tdm_pcm_driver);
148 }
149 module_init(snd_tegra_tdm_pcm_init);
150
151 static void __exit snd_tegra_tdm_pcm_exit(void)
152 {
153         platform_driver_unregister(&tegra_tdm_pcm_driver);
154 }
155 module_exit(snd_tegra_tdm_pcm_exit);
156
157 MODULE_AUTHOR("Nitin Pai <npai@nvidia.com>");
158 MODULE_DESCRIPTION("Tegra PCM ASoC driver");
159 MODULE_LICENSE("GPL");
160 MODULE_ALIAS("platform:" DRV_NAME);