Path: blob/master/sound/soc/blackfin/bf5xx-ssm2602.c
10817 views
/*1* File: sound/soc/blackfin/bf5xx-ssm2602.c2* Author: Cliff Cai <[email protected]>3*4* Created: Tue June 06 20085* Description: board driver for SSM2602 sound chip6*7* Modified:8* Copyright 2008 Analog Devices Inc.9*10* Bugs: Enter bugs at http://blackfin.uclinux.org/11*12* This program is free software; you can redistribute it and/or modify13* it under the terms of the GNU General Public License as published by14* the Free Software Foundation; either version 2 of the License, or15* (at your option) any later version.16*17* This program is distributed in the hope that it will be useful,18* but WITHOUT ANY WARRANTY; without even the implied warranty of19* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the20* GNU General Public License for more details.21*22* You should have received a copy of the GNU General Public License23* along with this program; if not, see the file COPYING, or write24* to the Free Software Foundation, Inc.,25* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA26*/2728#include <linux/module.h>29#include <linux/moduleparam.h>30#include <linux/device.h>3132#include <sound/core.h>33#include <sound/pcm.h>34#include <sound/soc.h>35#include <sound/pcm_params.h>3637#include <asm/dma.h>38#include <asm/portmux.h>39#include <linux/gpio.h>40#include "../codecs/ssm2602.h"41#include "bf5xx-sport.h"42#include "bf5xx-i2s-pcm.h"4344static struct snd_soc_card bf5xx_ssm2602;4546static int bf5xx_ssm2602_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 *codec_dai = rtd->codec_dai;51struct snd_soc_dai *cpu_dai = rtd->cpu_dai;52unsigned int clk = 0;53int ret = 0;5455pr_debug("%s rate %d format %x\n", __func__, params_rate(params),56params_format(params));57/*58* If you are using a crystal source which frequency is not 12MHz59* then modify the below case statement with frequency of the crystal.60*61* If you are using the SPORT to generate clocking then this is62* where to do it.63*/6465switch (params_rate(params)) {66case 8000:67case 16000:68case 48000:69case 96000:70case 11025:71case 22050:72case 44100:73clk = 12000000;74break;75}7677/*78* CODEC is master for BCLK and LRC in this configuration.79*/8081/* set codec DAI configuration */82ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |83SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);84if (ret < 0)85return ret;86/* set cpu DAI configuration */87ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |88SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);89if (ret < 0)90return ret;9192ret = snd_soc_dai_set_sysclk(codec_dai, SSM2602_SYSCLK, clk,93SND_SOC_CLOCK_IN);94if (ret < 0)95return ret;9697return 0;98}99100static struct snd_soc_ops bf5xx_ssm2602_ops = {101.hw_params = bf5xx_ssm2602_hw_params,102};103104static struct snd_soc_dai_link bf5xx_ssm2602_dai[] = {105{106.name = "ssm2602",107.stream_name = "SSM2602",108.cpu_dai_name = "bfin-i2s.0",109.codec_dai_name = "ssm2602-hifi",110.platform_name = "bfin-i2s-pcm-audio",111.codec_name = "ssm2602.0-001b",112.ops = &bf5xx_ssm2602_ops,113},114{115.name = "ssm2602",116.stream_name = "SSM2602",117.cpu_dai_name = "bfin-i2s.1",118.codec_dai_name = "ssm2602-hifi",119.platform_name = "bfin-i2s-pcm-audio",120.codec_name = "ssm2602.0-001b",121.ops = &bf5xx_ssm2602_ops,122},123};124125static struct snd_soc_card bf5xx_ssm2602 = {126.name = "bfin-ssm2602",127.dai_link = &bf5xx_ssm2602_dai[CONFIG_SND_BF5XX_SPORT_NUM],128.num_links = 1,129};130131static struct platform_device *bf5xx_ssm2602_snd_device;132133static int __init bf5xx_ssm2602_init(void)134{135int ret;136137pr_debug("%s enter\n", __func__);138bf5xx_ssm2602_snd_device = platform_device_alloc("soc-audio", -1);139if (!bf5xx_ssm2602_snd_device)140return -ENOMEM;141142platform_set_drvdata(bf5xx_ssm2602_snd_device, &bf5xx_ssm2602);143ret = platform_device_add(bf5xx_ssm2602_snd_device);144145if (ret)146platform_device_put(bf5xx_ssm2602_snd_device);147148return ret;149}150151static void __exit bf5xx_ssm2602_exit(void)152{153pr_debug("%s enter\n", __func__);154platform_device_unregister(bf5xx_ssm2602_snd_device);155}156157module_init(bf5xx_ssm2602_init);158module_exit(bf5xx_ssm2602_exit);159160/* Module information */161MODULE_AUTHOR("Cliff Cai");162MODULE_DESCRIPTION("ALSA SoC SSM2602 BF527-EZKIT");163MODULE_LICENSE("GPL");164165166167