Path: blob/master/sound/soc/davinci/davinci-sffsdr.c
10817 views
/*1* ASoC driver for Lyrtech SFFSDR board.2*3* Author: Hugo Villeneuve4* Copyright (C) 2008 Lyrtech inc5*6* Based on ASoC driver for TI DAVINCI EVM platform, original copyright follow:7* Copyright: (C) 2007 MontaVista Software, Inc., <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License version 2 as11* published by the Free Software Foundation.12*/1314#include <linux/module.h>15#include <linux/moduleparam.h>16#include <linux/timer.h>17#include <linux/interrupt.h>18#include <linux/platform_device.h>19#include <linux/gpio.h>20#include <sound/core.h>21#include <sound/pcm.h>22#include <sound/soc.h>2324#include <asm/dma.h>25#include <asm/mach-types.h>26#ifdef CONFIG_SFFSDR_FPGA27#include <asm/plat-sffsdr/sffsdr-fpga.h>28#endif2930#include <mach/edma.h>3132#include "../codecs/pcm3008.h"33#include "davinci-pcm.h"34#include "davinci-i2s.h"3536/*37* CLKX and CLKR are the inputs for the Sample Rate Generator.38* FSX and FSR are outputs, driven by the sample Rate Generator.39*/40#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \41SND_SOC_DAIFMT_CBM_CFS | \42SND_SOC_DAIFMT_IB_NF)4344static int sffsdr_hw_params(struct snd_pcm_substream *substream,45struct snd_pcm_hw_params *params)46{47struct snd_soc_pcm_runtime *rtd = substream->private_data;48struct snd_soc_dai *cpu_dai = rtd->cpu_dai;49int fs;50int ret = 0;5152/* Fsref can be 32000, 44100 or 48000. */53fs = params_rate(params);5455#ifndef CONFIG_SFFSDR_FPGA56/* Without the FPGA module, the Fs is fixed at 44100 Hz */57if (fs != 44100) {58pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");59return -EINVAL;60}61#endif6263/* set cpu DAI configuration */64ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);65if (ret < 0)66return ret;6768pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);6970#ifndef CONFIG_SFFSDR_FPGA71return 0;72#else73return sffsdr_fpga_set_codec_fs(fs);74#endif75}7677static struct snd_soc_ops sffsdr_ops = {78.hw_params = sffsdr_hw_params,79};8081/* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */82static struct snd_soc_dai_link sffsdr_dai = {83.name = "PCM3008", /* Codec name */84.stream_name = "PCM3008 HiFi",85.cpu_dai_name = "davinci-mcbsp",86.codec_dai_name = "pcm3008-hifi",87.codec_name = "pcm3008-codec",88.platform_name = "davinci-pcm-audio",89.ops = &sffsdr_ops,90};9192/* davinci-sffsdr audio machine driver */93static struct snd_soc_card snd_soc_sffsdr = {94.name = "DaVinci SFFSDR",95.dai_link = &sffsdr_dai,96.num_links = 1,97};9899/* sffsdr audio private data */100static struct pcm3008_setup_data sffsdr_pcm3008_setup = {101.dem0_pin = GPIO(45),102.dem1_pin = GPIO(46),103.pdad_pin = GPIO(47),104.pdda_pin = GPIO(38),105};106107struct platform_device pcm3008_codec = {108.name = "pcm3008-codec",109.id = 0,110.dev = {111.platform_data = &sffsdr_pcm3008_setup,112},113};114115static struct resource sffsdr_snd_resources[] = {116{117.start = DAVINCI_MCBSP_BASE,118.end = DAVINCI_MCBSP_BASE + SZ_8K - 1,119.flags = IORESOURCE_MEM,120},121};122123static struct evm_snd_platform_data sffsdr_snd_data = {124.tx_dma_ch = DAVINCI_DMA_MCBSP_TX,125.rx_dma_ch = DAVINCI_DMA_MCBSP_RX,126};127128static struct platform_device *sffsdr_snd_device;129130static int __init sffsdr_init(void)131{132int ret;133134if (!machine_is_sffsdr())135return -EINVAL;136137platform_device_register(&pcm3008_codec);138139sffsdr_snd_device = platform_device_alloc("soc-audio", 0);140if (!sffsdr_snd_device) {141printk(KERN_ERR "platform device allocation failed\n");142return -ENOMEM;143}144145platform_set_drvdata(sffsdr_snd_device, &snd_soc_sffsdr);146platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data,147sizeof(sffsdr_snd_data));148149ret = platform_device_add_resources(sffsdr_snd_device,150sffsdr_snd_resources,151ARRAY_SIZE(sffsdr_snd_resources));152if (ret) {153printk(KERN_ERR "platform device add resources failed\n");154goto error;155}156157ret = platform_device_add(sffsdr_snd_device);158if (ret)159goto error;160161return ret;162163error:164platform_device_put(sffsdr_snd_device);165return ret;166}167168static void __exit sffsdr_exit(void)169{170platform_device_unregister(sffsdr_snd_device);171platform_device_unregister(&pcm3008_codec);172}173174module_init(sffsdr_init);175module_exit(sffsdr_exit);176177MODULE_AUTHOR("Hugo Villeneuve");178MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");179MODULE_LICENSE("GPL");180181182