Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 1 | /* |
| 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> |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 33 | #include <video/omapdss.h> |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 34 | |
| 35 | #include <plat/dma.h> |
| 36 | #include "omap-pcm.h" |
| 37 | #include "omap-hdmi.h" |
| 38 | |
Ricardo Neri | e412ec6 | 2012-05-18 01:42:34 -0500 | [diff] [blame] | 39 | #define DRV_NAME "omap-hdmi-audio-dai" |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 40 | |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 41 | struct hdmi_priv { |
| 42 | struct omap_pcm_dma_data dma_params; |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 43 | struct omap_dss_device *dssdev; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | static int omap_hdmi_dai_startup(struct snd_pcm_substream *substream, |
| 47 | struct snd_soc_dai *dai) |
| 48 | { |
| 49 | int err; |
| 50 | /* |
| 51 | * Make sure that the period bytes are multiple of the DMA packet size. |
| 52 | * Largest packet size we use is 32 32-bit words = 128 bytes |
| 53 | */ |
| 54 | err = snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 55 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128); |
| 56 | if (err < 0) |
| 57 | return err; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 62 | static int omap_hdmi_dai_prepare(struct snd_pcm_substream *substream, |
| 63 | struct snd_soc_dai *dai) |
| 64 | { |
| 65 | struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai); |
| 66 | |
| 67 | return priv->dssdev->driver->audio_enable(priv->dssdev); |
| 68 | } |
| 69 | |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 70 | static int omap_hdmi_dai_hw_params(struct snd_pcm_substream *substream, |
| 71 | struct snd_pcm_hw_params *params, |
| 72 | struct snd_soc_dai *dai) |
| 73 | { |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 74 | struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai); |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 75 | int err = 0; |
| 76 | |
| 77 | switch (params_format(params)) { |
| 78 | case SNDRV_PCM_FORMAT_S16_LE: |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 79 | priv->dma_params.packet_size = 16; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 80 | break; |
| 81 | case SNDRV_PCM_FORMAT_S24_LE: |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 82 | priv->dma_params.packet_size = 32; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 83 | break; |
| 84 | default: |
| 85 | err = -EINVAL; |
| 86 | } |
| 87 | |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 88 | priv->dma_params.data_type = OMAP_DMA_DATA_TYPE_S32; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 89 | |
| 90 | snd_soc_dai_set_dma_data(dai, substream, |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 91 | &priv->dma_params); |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 92 | |
| 93 | return err; |
| 94 | } |
| 95 | |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 96 | static int omap_hdmi_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 97 | struct snd_soc_dai *dai) |
| 98 | { |
| 99 | struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai); |
| 100 | int err = 0; |
| 101 | |
| 102 | switch (cmd) { |
| 103 | case SNDRV_PCM_TRIGGER_START: |
| 104 | case SNDRV_PCM_TRIGGER_RESUME: |
| 105 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 106 | err = priv->dssdev->driver->audio_start(priv->dssdev); |
| 107 | break; |
| 108 | case SNDRV_PCM_TRIGGER_STOP: |
| 109 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 110 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 111 | priv->dssdev->driver->audio_stop(priv->dssdev); |
| 112 | break; |
| 113 | default: |
| 114 | err = -EINVAL; |
| 115 | } |
| 116 | return err; |
| 117 | } |
| 118 | |
| 119 | static void omap_hdmi_dai_shutdown(struct snd_pcm_substream *substream, |
| 120 | struct snd_soc_dai *dai) |
| 121 | { |
| 122 | struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai); |
| 123 | |
| 124 | priv->dssdev->driver->audio_disable(priv->dssdev); |
| 125 | } |
| 126 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 127 | static const struct snd_soc_dai_ops omap_hdmi_dai_ops = { |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 128 | .startup = omap_hdmi_dai_startup, |
| 129 | .hw_params = omap_hdmi_dai_hw_params, |
| 130 | }; |
| 131 | |
| 132 | static struct snd_soc_dai_driver omap_hdmi_dai = { |
| 133 | .playback = { |
| 134 | .channels_min = 2, |
| 135 | .channels_max = 2, |
| 136 | .rates = OMAP_HDMI_RATES, |
| 137 | .formats = OMAP_HDMI_FORMATS, |
| 138 | }, |
| 139 | .ops = &omap_hdmi_dai_ops, |
| 140 | }; |
| 141 | |
| 142 | static __devinit int omap_hdmi_probe(struct platform_device *pdev) |
| 143 | { |
| 144 | int ret; |
| 145 | struct resource *hdmi_rsrc; |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 146 | struct hdmi_priv *hdmi_data; |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 147 | bool hdmi_dev_found = false; |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 148 | |
| 149 | hdmi_data = devm_kzalloc(&pdev->dev, sizeof(*hdmi_data), GFP_KERNEL); |
| 150 | if (hdmi_data == NULL) { |
| 151 | dev_err(&pdev->dev, "Cannot allocate memory for HDMI data\n"); |
| 152 | return -ENOMEM; |
| 153 | } |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 154 | |
| 155 | hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 156 | if (!hdmi_rsrc) { |
| 157 | dev_err(&pdev->dev, "Cannot obtain IORESOURCE_MEM HDMI\n"); |
Ricardo Neri | 0ff5ee8 | 2012-05-18 01:42:35 -0500 | [diff] [blame] | 158 | return -ENODEV; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 159 | } |
| 160 | |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 161 | hdmi_data->dma_params.port_addr = hdmi_rsrc->start |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 162 | + OMAP_HDMI_AUDIO_DMA_PORT; |
| 163 | |
| 164 | hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 165 | if (!hdmi_rsrc) { |
| 166 | dev_err(&pdev->dev, "Cannot obtain IORESOURCE_DMA HDMI\n"); |
Ricardo Neri | 0ff5ee8 | 2012-05-18 01:42:35 -0500 | [diff] [blame] | 167 | return -ENODEV; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 170 | hdmi_data->dma_params.dma_req = hdmi_rsrc->start; |
| 171 | hdmi_data->dma_params.name = "HDMI playback"; |
| 172 | hdmi_data->dma_params.sync_mode = OMAP_DMA_SYNC_PACKET; |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 173 | |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 174 | /* |
| 175 | * TODO: We assume that there is only one DSS HDMI device. Future |
| 176 | * OMAP implementations may support more than one HDMI devices and |
| 177 | * we should provided separate audio support for all of them. |
| 178 | */ |
| 179 | /* Find an HDMI device. */ |
| 180 | for_each_dss_dev(hdmi_data->dssdev) { |
| 181 | omap_dss_get_device(hdmi_data->dssdev); |
| 182 | |
| 183 | if (!hdmi_data->dssdev->driver) { |
| 184 | omap_dss_put_device(hdmi_data->dssdev); |
| 185 | continue; |
| 186 | } |
| 187 | |
| 188 | if (hdmi_data->dssdev->type == OMAP_DISPLAY_TYPE_HDMI) { |
| 189 | hdmi_dev_found = true; |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (!hdmi_dev_found) { |
| 195 | dev_err(&pdev->dev, "no driver for HDMI display found\n"); |
| 196 | return -ENODEV; |
| 197 | } |
| 198 | |
Ricardo Neri | 2603915 | 2012-05-18 01:42:36 -0500 | [diff] [blame] | 199 | dev_set_drvdata(&pdev->dev, hdmi_data); |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 200 | ret = snd_soc_register_dai(&pdev->dev, &omap_hdmi_dai); |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 201 | |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | static int __devexit omap_hdmi_remove(struct platform_device *pdev) |
| 206 | { |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 207 | struct hdmi_priv *hdmi_data = dev_get_drvdata(&pdev->dev); |
| 208 | |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 209 | snd_soc_unregister_dai(&pdev->dev); |
Ricardo Neri | a48d9b7 | 2012-05-18 01:42:37 -0500 | [diff] [blame^] | 210 | |
| 211 | if (hdmi_data == NULL) { |
| 212 | dev_err(&pdev->dev, "cannot obtain HDMi data\n"); |
| 213 | return -ENODEV; |
| 214 | } |
| 215 | |
| 216 | omap_dss_put_device(hdmi_data->dssdev); |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static struct platform_driver hdmi_dai_driver = { |
| 221 | .driver = { |
| 222 | .name = DRV_NAME, |
| 223 | .owner = THIS_MODULE, |
| 224 | }, |
| 225 | .probe = omap_hdmi_probe, |
| 226 | .remove = __devexit_p(omap_hdmi_remove), |
| 227 | }; |
| 228 | |
Axel Lin | beda5bf5 | 2011-11-25 10:12:16 +0800 | [diff] [blame] | 229 | module_platform_driver(hdmi_dai_driver); |
Ricardo Neri | bca2e41 | 2011-06-02 15:44:45 -0500 | [diff] [blame] | 230 | |
| 231 | MODULE_AUTHOR("Jorge Candelaria <jorge.candelaria@ti.com>"); |
| 232 | MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>"); |
| 233 | MODULE_DESCRIPTION("OMAP HDMI SoC Interface"); |
| 234 | MODULE_LICENSE("GPL"); |
| 235 | MODULE_ALIAS("platform:" DRV_NAME); |