Path: blob/master/sound/soc/blackfin/bf5xx-ad193x.c
10817 views
/*1* File: sound/soc/blackfin/bf5xx-ad193x.c2* Author: Barry Song <[email protected]>3*4* Created: Thur June 4 20095* Description: Board driver for ad193x sound chip6*7* Bugs: Enter bugs at http://blackfin.uclinux.org/8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, see the file COPYING, or write21* to the Free Software Foundation, Inc.,22* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA23*/2425#include <linux/module.h>26#include <linux/moduleparam.h>27#include <linux/device.h>28#include <sound/core.h>29#include <sound/pcm.h>30#include <sound/soc.h>31#include <sound/pcm_params.h>3233#include <asm/blackfin.h>34#include <asm/cacheflush.h>35#include <asm/irq.h>36#include <asm/dma.h>37#include <asm/portmux.h>3839#include "../codecs/ad193x.h"4041#include "bf5xx-tdm-pcm.h"42#include "bf5xx-tdm.h"4344static struct snd_soc_card bf5xx_ad193x;4546static int bf5xx_ad193x_hw_params(struct snd_pcm_substream *substream,47struct snd_pcm_hw_params *params)48{49struct snd_soc_pcm_runtime *rtd = substream->private_data;50struct snd_soc_dai *cpu_dai = rtd->cpu_dai;51struct snd_soc_dai *codec_dai = rtd->codec_dai;52unsigned int clk = 0;53unsigned int channel_map[] = {0, 1, 2, 3, 4, 5, 6, 7};54int ret = 0;5556switch (params_rate(params)) {57case 48000:58clk = 12288000;59break;60}6162/* set cpu DAI configuration */63ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |64SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);65if (ret < 0)66return ret;6768/* set codec DAI configuration */69ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |70SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);71if (ret < 0)72return ret;7374/* set the codec system clock for DAC and ADC */75ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,76SND_SOC_CLOCK_IN);77if (ret < 0)78return ret;7980/* set codec DAI slots, 8 channels, all channels are enabled */81ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xFF, 0xFF, 8, 32);82if (ret < 0)83return ret;8485/* set cpu DAI channel mapping */86ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),87channel_map, ARRAY_SIZE(channel_map), channel_map);88if (ret < 0)89return ret;9091return 0;92}9394static struct snd_soc_ops bf5xx_ad193x_ops = {95.hw_params = bf5xx_ad193x_hw_params,96};9798static struct snd_soc_dai_link bf5xx_ad193x_dai[] = {99{100.name = "ad193x",101.stream_name = "AD193X",102.cpu_dai_name = "bfin-tdm.0",103.codec_dai_name ="ad193x-hifi",104.platform_name = "bfin-tdm-pcm-audio",105.codec_name = "ad193x.5",106.ops = &bf5xx_ad193x_ops,107},108{109.name = "ad193x",110.stream_name = "AD193X",111.cpu_dai_name = "bfin-tdm.1",112.codec_dai_name ="ad193x-hifi",113.platform_name = "bfin-tdm-pcm-audio",114.codec_name = "ad193x.5",115.ops = &bf5xx_ad193x_ops,116},117};118119static struct snd_soc_card bf5xx_ad193x = {120.name = "bfin-ad193x",121.dai_link = &bf5xx_ad193x_dai[CONFIG_SND_BF5XX_SPORT_NUM],122.num_links = 1,123};124125static struct platform_device *bfxx_ad193x_snd_device;126127static int __init bf5xx_ad193x_init(void)128{129int ret;130131bfxx_ad193x_snd_device = platform_device_alloc("soc-audio", -1);132if (!bfxx_ad193x_snd_device)133return -ENOMEM;134135platform_set_drvdata(bfxx_ad193x_snd_device, &bf5xx_ad193x);136ret = platform_device_add(bfxx_ad193x_snd_device);137138if (ret)139platform_device_put(bfxx_ad193x_snd_device);140141return ret;142}143144static void __exit bf5xx_ad193x_exit(void)145{146platform_device_unregister(bfxx_ad193x_snd_device);147}148149module_init(bf5xx_ad193x_init);150module_exit(bf5xx_ad193x_exit);151152/* Module information */153MODULE_AUTHOR("Barry Song");154MODULE_DESCRIPTION("ALSA SoC AD193X board driver");155MODULE_LICENSE("GPL");156157158159