blob: a6656b2a73538d654c45d398edc6084dde4235ad [file] [log] [blame]
Ricardo Neribca2e412011-06-02 15:44:45 -05001/*
2 * omap-hdmi.c
3 *
4 * OMAP ALSA SoC DAI driver for HDMI audio on OMAP4 processors.
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
6 * Authors: Jorge Candelaria <jorge.candelaria@ti.com>
7 * Ricardo Neri <ricardo.neri@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/device.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/initval.h>
32#include <sound/soc.h>
33
34#include <plat/dma.h>
35#include "omap-pcm.h"
36#include "omap-hdmi.h"
37
Ricardo Nerie412ec62012-05-18 01:42:34 -050038#define DRV_NAME "omap-hdmi-audio-dai"
Ricardo Neribca2e412011-06-02 15:44:45 -050039
Ricardo Neri26039152012-05-18 01:42:36 -050040struct hdmi_priv {
41 struct omap_pcm_dma_data dma_params;
Ricardo Neribca2e412011-06-02 15:44:45 -050042};
43
44static int omap_hdmi_dai_startup(struct snd_pcm_substream *substream,
45 struct snd_soc_dai *dai)
46{
47 int err;
48 /*
49 * Make sure that the period bytes are multiple of the DMA packet size.
50 * Largest packet size we use is 32 32-bit words = 128 bytes
51 */
52 err = snd_pcm_hw_constraint_step(substream->runtime, 0,
53 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
54 if (err < 0)
55 return err;
56
57 return 0;
58}
59
60static int omap_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
61 struct snd_pcm_hw_params *params,
62 struct snd_soc_dai *dai)
63{
Ricardo Neri26039152012-05-18 01:42:36 -050064 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
Ricardo Neribca2e412011-06-02 15:44:45 -050065 int err = 0;
66
67 switch (params_format(params)) {
68 case SNDRV_PCM_FORMAT_S16_LE:
Ricardo Neri26039152012-05-18 01:42:36 -050069 priv->dma_params.packet_size = 16;
Ricardo Neribca2e412011-06-02 15:44:45 -050070 break;
71 case SNDRV_PCM_FORMAT_S24_LE:
Ricardo Neri26039152012-05-18 01:42:36 -050072 priv->dma_params.packet_size = 32;
Ricardo Neribca2e412011-06-02 15:44:45 -050073 break;
74 default:
75 err = -EINVAL;
76 }
77
Ricardo Neri26039152012-05-18 01:42:36 -050078 priv->dma_params.data_type = OMAP_DMA_DATA_TYPE_S32;
Ricardo Neribca2e412011-06-02 15:44:45 -050079
80 snd_soc_dai_set_dma_data(dai, substream,
Ricardo Neri26039152012-05-18 01:42:36 -050081 &priv->dma_params);
Ricardo Neribca2e412011-06-02 15:44:45 -050082
83 return err;
84}
85
Lars-Peter Clausen85e76522011-11-23 11:40:40 +010086static const struct snd_soc_dai_ops omap_hdmi_dai_ops = {
Ricardo Neribca2e412011-06-02 15:44:45 -050087 .startup = omap_hdmi_dai_startup,
88 .hw_params = omap_hdmi_dai_hw_params,
89};
90
91static struct snd_soc_dai_driver omap_hdmi_dai = {
92 .playback = {
93 .channels_min = 2,
94 .channels_max = 2,
95 .rates = OMAP_HDMI_RATES,
96 .formats = OMAP_HDMI_FORMATS,
97 },
98 .ops = &omap_hdmi_dai_ops,
99};
100
101static __devinit int omap_hdmi_probe(struct platform_device *pdev)
102{
103 int ret;
104 struct resource *hdmi_rsrc;
Ricardo Neri26039152012-05-18 01:42:36 -0500105 struct hdmi_priv *hdmi_data;
106
107 hdmi_data = devm_kzalloc(&pdev->dev, sizeof(*hdmi_data), GFP_KERNEL);
108 if (hdmi_data == NULL) {
109 dev_err(&pdev->dev, "Cannot allocate memory for HDMI data\n");
110 return -ENOMEM;
111 }
Ricardo Neribca2e412011-06-02 15:44:45 -0500112
113 hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
114 if (!hdmi_rsrc) {
115 dev_err(&pdev->dev, "Cannot obtain IORESOURCE_MEM HDMI\n");
Ricardo Neri0ff5ee82012-05-18 01:42:35 -0500116 return -ENODEV;
Ricardo Neribca2e412011-06-02 15:44:45 -0500117 }
118
Ricardo Neri26039152012-05-18 01:42:36 -0500119 hdmi_data->dma_params.port_addr = hdmi_rsrc->start
Ricardo Neribca2e412011-06-02 15:44:45 -0500120 + OMAP_HDMI_AUDIO_DMA_PORT;
121
122 hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_DMA, 0);
123 if (!hdmi_rsrc) {
124 dev_err(&pdev->dev, "Cannot obtain IORESOURCE_DMA HDMI\n");
Ricardo Neri0ff5ee82012-05-18 01:42:35 -0500125 return -ENODEV;
Ricardo Neribca2e412011-06-02 15:44:45 -0500126 }
127
Ricardo Neri26039152012-05-18 01:42:36 -0500128 hdmi_data->dma_params.dma_req = hdmi_rsrc->start;
129 hdmi_data->dma_params.name = "HDMI playback";
130 hdmi_data->dma_params.sync_mode = OMAP_DMA_SYNC_PACKET;
Ricardo Neribca2e412011-06-02 15:44:45 -0500131
Ricardo Neri26039152012-05-18 01:42:36 -0500132 dev_set_drvdata(&pdev->dev, hdmi_data);
Ricardo Neribca2e412011-06-02 15:44:45 -0500133 ret = snd_soc_register_dai(&pdev->dev, &omap_hdmi_dai);
134 return ret;
135}
136
137static int __devexit omap_hdmi_remove(struct platform_device *pdev)
138{
139 snd_soc_unregister_dai(&pdev->dev);
140 return 0;
141}
142
143static struct platform_driver hdmi_dai_driver = {
144 .driver = {
145 .name = DRV_NAME,
146 .owner = THIS_MODULE,
147 },
148 .probe = omap_hdmi_probe,
149 .remove = __devexit_p(omap_hdmi_remove),
150};
151
Axel Linbeda5bf52011-11-25 10:12:16 +0800152module_platform_driver(hdmi_dai_driver);
Ricardo Neribca2e412011-06-02 15:44:45 -0500153
154MODULE_AUTHOR("Jorge Candelaria <jorge.candelaria@ti.com>");
155MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
156MODULE_DESCRIPTION("OMAP HDMI SoC Interface");
157MODULE_LICENSE("GPL");
158MODULE_ALIAS("platform:" DRV_NAME);