Path: blob/master/sound/soc/kirkwood/kirkwood-t5325.c
10817 views
/*1* kirkwood-t5325.c2*3* (c) 2010 Arnaud Patard <[email protected]>4*5* This program is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License as published by the7* Free Software Foundation; either version 2 of the License, or (at your8* option) any later version.9*/1011#include <linux/module.h>12#include <linux/moduleparam.h>13#include <linux/interrupt.h>14#include <linux/platform_device.h>15#include <linux/slab.h>16#include <sound/soc.h>17#include <mach/kirkwood.h>18#include <plat/audio.h>19#include <asm/mach-types.h>20#include "../codecs/alc5623.h"2122static int t5325_hw_params(struct snd_pcm_substream *substream,23struct snd_pcm_hw_params *params)24{25struct snd_soc_pcm_runtime *rtd = substream->private_data;26struct snd_soc_dai *codec_dai = rtd->codec_dai;27struct snd_soc_dai *cpu_dai = rtd->cpu_dai;28int ret;29unsigned int freq, fmt;3031fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;32ret = snd_soc_dai_set_fmt(cpu_dai, fmt);33if (ret < 0)34return ret;3536ret = snd_soc_dai_set_fmt(codec_dai, fmt);37if (ret < 0)38return ret;3940freq = params_rate(params) * 256;4142return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);4344}4546static struct snd_soc_ops t5325_ops = {47.hw_params = t5325_hw_params,48};4950static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = {51SND_SOC_DAPM_HP("Headphone Jack", NULL),52SND_SOC_DAPM_SPK("Speaker", NULL),53SND_SOC_DAPM_MIC("Mic Jack", NULL),54};5556static const struct snd_soc_dapm_route t5325_route[] = {57{ "Headphone Jack", NULL, "HPL" },58{ "Headphone Jack", NULL, "HPR" },5960{"Speaker", NULL, "SPKOUT"},61{"Speaker", NULL, "SPKOUTN"},6263{ "MIC1", NULL, "Mic Jack" },64{ "MIC2", NULL, "Mic Jack" },65};6667static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)68{69struct snd_soc_codec *codec = rtd->codec;70struct snd_soc_dapm_context *dapm = &codec->dapm;7172snd_soc_dapm_new_controls(dapm, t5325_dapm_widgets,73ARRAY_SIZE(t5325_dapm_widgets));7475snd_soc_dapm_add_routes(dapm, t5325_route, ARRAY_SIZE(t5325_route));7677snd_soc_dapm_enable_pin(dapm, "Mic Jack");78snd_soc_dapm_enable_pin(dapm, "Headphone Jack");79snd_soc_dapm_enable_pin(dapm, "Speaker");8081snd_soc_dapm_sync(dapm);8283return 0;84}8586static struct snd_soc_dai_link t5325_dai[] = {87{88.name = "ALC5621",89.stream_name = "ALC5621 HiFi",90.cpu_dai_name = "kirkwood-i2s",91.platform_name = "kirkwood-pcm-audio",92.codec_dai_name = "alc5621-hifi",93.codec_name = "alc562x-codec.0-001a",94.ops = &t5325_ops,95.init = t5325_dai_init,96},97};9899100static struct snd_soc_card t5325 = {101.name = "t5325",102.dai_link = t5325_dai,103.num_links = ARRAY_SIZE(t5325_dai),104};105106static struct platform_device *t5325_snd_device;107108static int __init t5325_init(void)109{110int ret;111112if (!machine_is_t5325())113return 0;114115t5325_snd_device = platform_device_alloc("soc-audio", -1);116if (!t5325_snd_device)117return -ENOMEM;118119platform_set_drvdata(t5325_snd_device,120&t5325);121122ret = platform_device_add(t5325_snd_device);123if (ret) {124printk(KERN_ERR "%s: platform_device_add failed\n", __func__);125platform_device_put(t5325_snd_device);126}127128return ret;129}130module_init(t5325_init);131132static void __exit t5325_exit(void)133{134platform_device_unregister(t5325_snd_device);135}136module_exit(t5325_exit);137138MODULE_AUTHOR("Arnaud Patard <[email protected]>");139MODULE_DESCRIPTION("ALSA SoC t5325 audio client");140MODULE_LICENSE("GPL");141142143