Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 24th, 2011  |  syntax: C  |  size: 7.72 KB  |  views: 54  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * sam9263_wm8974  --  SoC audio for AT91SAM9263-based
  3.  *                      ATMEL AT91SAM9263ek board.
  4.  *
  5.  *  Copyright (C) 2005 SAN People
  6.  *  Copyright (C) 2008 Atmel
  7.  *  Copyright (C) 2011 FEW Bauer GmbH
  8.  *
  9.  * Authors: Matthias Wieloch <matthias.wieloch@few-bauer.de>
  10.  *
  11.  * Based on sam9g20_wm8974.c by:
  12.  * Sedji Gaouaou <sedji.gaouaou@atmel.com>
  13.  * Copyright 2008 Atmel
  14.  * Based on ati_b1_wm8731.c by:
  15.  * Frank Mandarino <fmandarino@endrelia.com>
  16.  * Copyright 2006 Endrelia Technologies Inc.
  17.  * Based on corgi.c by:
  18.  * Copyright 2005 Wolfson Microelectronics PLC.
  19.  * Copyright 2005 Openedhand Ltd.
  20.  *
  21.  * This program is free software; you can redistribute it and/or modify
  22.  * it under the terms of the GNU General Public License as published by
  23.  * the Free Software Foundation; either version 2 of the License, or
  24.  * (at your option) any later version.
  25.  *
  26.  * This program is distributed in the hope that it will be useful,
  27.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29.  * GNU General Public License for more details.
  30.  *
  31.  * You should have received a copy of the GNU General Public License
  32.  * along with this program; if not, write to the Free Software
  33.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  34.  */
  35.  
  36. #include <linux/module.h>
  37. #include <linux/moduleparam.h>
  38. #include <linux/kernel.h>
  39. #include <linux/clk.h>
  40. #include <linux/timer.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/i2c.h>
  44.  
  45. #include <linux/atmel-ssc.h>
  46.  
  47. #include <sound/core.h>
  48. #include <sound/pcm.h>
  49. #include <sound/pcm_params.h>
  50. #include <sound/soc.h>
  51.  
  52. #include <asm/mach-types.h>
  53. #include <mach/hardware.h>
  54. #include <mach/gpio.h>
  55.  
  56. #include "../codecs/wm8974.h"
  57. #include "atmel-pcm.h"
  58. #include "atmel_ssc_dai.h"
  59.  
  60. #define MCLK_RATE 12288000
  61.  
  62. /*
  63.  * As shipped the board does not have inputs.  However, it is relatively
  64.  * straightforward to modify the board to hook them up so support is left
  65.  * in the driver.
  66.  */
  67. #define ENABLE_MIC_INPUT 1
  68.  
  69. //static struct clk *mclk;
  70.  
  71. static int at91sam9263ek_hw_params(struct snd_pcm_substream *substream,
  72.         struct snd_pcm_hw_params *params)
  73. {
  74.         struct snd_soc_pcm_runtime *rtd = substream->private_data;
  75.         struct snd_soc_dai *codec_dai = rtd->codec_dai;
  76.         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  77.         int ret;
  78.  
  79.         /* set codec DAI configuration */
  80.         ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  81.                 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  82.         if (ret < 0)
  83.                 return ret;
  84.  
  85.         /* set cpu DAI configuration */
  86.         ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  87.                 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  88.         if (ret < 0)
  89.                 return ret;
  90.  
  91.         return 0;
  92. }
  93.  
  94. static struct snd_soc_ops at91sam9263ek_ops = {
  95.         .hw_params = at91sam9263ek_hw_params,
  96. };
  97.  
  98. static int at91sam9263ek_set_bias_level(struct snd_soc_card *card,
  99.                                         enum snd_soc_bias_level level)
  100. {
  101.         //static int mclk_on;
  102.         int ret = 0;
  103.  
  104.         switch (level) {
  105.         case SND_SOC_BIAS_ON:
  106.         case SND_SOC_BIAS_PREPARE:
  107.                 /*if (!mclk_on)
  108.                         ret = clk_enable(mclk);
  109.                 if (ret == 0)
  110.                         mclk_on = 1;*/
  111.                 break;
  112.  
  113.         case SND_SOC_BIAS_OFF:
  114.         case SND_SOC_BIAS_STANDBY:
  115.                 /*if (mclk_on)
  116.                         clk_disable(mclk);
  117.                 mclk_on = 0;*/
  118.                 break;
  119.         }
  120.  
  121.         return ret;
  122. }
  123.  
  124. static const struct snd_soc_dapm_widget at91sam9263ek_dapm_widgets[] = {
  125.         SND_SOC_DAPM_MIC("Int Mic", NULL),
  126.         SND_SOC_DAPM_SPK("Ext Spk", NULL),
  127. };
  128.  
  129. static const struct snd_soc_dapm_route intercon[] = {
  130.  
  131.                 /* Speaker output mixer */
  132.                 {"Speaker Mixer", "PCM Playback Switch", "DAC"},
  133.                 {"Speaker Mixer", "Aux Playback Switch", "Aux Input"},
  134.                 {"Speaker Mixer", "Line Bypass Switch", "Boost Mixer"},
  135.                 /* speaker connected to SPKOUTP */
  136.                 {"SpkN Out", NULL, "Speaker Mixer"},
  137.                 {"SpkP Out", NULL, "Speaker Mixer"},
  138.                 {"SPKOUTN", NULL, "SpkN Out"},
  139.                 {"SPKOUTP", NULL, "SpkP Out"},
  140.  
  141.                 /* Input PGA */
  142.                 {"Input PGA", "Aux Switch", "Aux Input"},
  143.                 {"Input PGA", "MicN Switch", "MICN"},
  144.                 {"Input PGA", "MicP Switch", "MICP"},
  145. };
  146.  
  147. /*
  148.  * Logic for a wm8974 as connected on a at91sam9263ek board.
  149.  */
  150. static int at91sam9263ek_wm8974_init(struct snd_soc_pcm_runtime *rtd)
  151. {
  152.         struct snd_soc_codec *codec = rtd->codec;
  153.         struct snd_soc_dapm_context *dapm = &codec->dapm;
  154.         //int ret;
  155.  
  156.         printk(KERN_DEBUG
  157.                         "at91sam9263ek_wm8974 "
  158.                         ": at91sam9263ek_wm8974_init() called\n");
  159.  
  160.         /*ret = snd_soc_dai_set_sysclk(codec_dai, WM8974_MCLKDIV,
  161.                 MCLK_RATE, SND_SOC_CLOCK_IN);
  162.         if (ret < 0) {
  163.                 printk(KERN_ERR "Failed to set WM8974 SYSCLK: %d\n", ret);
  164.                 return ret;
  165.         }*/
  166.  
  167.         /* Add specific widgets */
  168.         snd_soc_dapm_new_controls(dapm, at91sam9263ek_dapm_widgets,
  169.                                   ARRAY_SIZE(at91sam9263ek_dapm_widgets));
  170.         /* Set up specific audio path interconnects */
  171.         snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
  172.  
  173.         /* not connected */
  174.         snd_soc_dapm_nc_pin(dapm, "MONOOUT");
  175.         snd_soc_dapm_nc_pin(dapm, "AUX");
  176.  
  177. #ifdef ENABLE_MIC_INPUT
  178.         snd_soc_dapm_enable_pin(dapm, "Int Mic");
  179. #else
  180.         snd_soc_dapm_nc_pin(dapm, "Int Mic");
  181. #endif
  182.  
  183.         /* always connected */
  184.         snd_soc_dapm_enable_pin(dapm, "Ext Spk");
  185.  
  186.         snd_soc_dapm_sync(dapm);
  187.  
  188.         return 0;
  189. }
  190.  
  191. static struct snd_soc_dai_link at91sam9263ek_dai = {
  192.         .name = "WM8974",
  193.         .stream_name = "WM8974 PCM",
  194.         .cpu_dai_name = "atmel-ssc-dai.1",
  195.         .codec_dai_name = "wm8974-hifi",
  196.         .init = at91sam9263ek_wm8974_init,
  197.         .platform_name = "atmel-pcm-audio",
  198.         .codec_name = "wm8974-codec.0-001a",
  199.         .ops = &at91sam9263ek_ops,
  200. };
  201.  
  202. static struct snd_soc_card snd_soc_at91sam9263ek = {
  203.         .name = "AT91SAM263-EK",
  204.         .dai_link = &at91sam9263ek_dai,
  205.         .num_links = 1,
  206.         .set_bias_level = at91sam9263ek_set_bias_level,
  207. };
  208.  
  209. static struct platform_device *at91sam9263ek_snd_device;
  210.  
  211. static int __init at91sam9263ek_init(void)
  212. {
  213.         struct ssc_device *ssc = NULL;
  214.  
  215.         //struct clk *pllb;
  216.         int ret;
  217.  
  218.         if (!(machine_is_at91sam9263ek()))
  219.                 return -ENODEV;
  220.  
  221.         ret = atmel_ssc_set_audio(1);
  222.         if (ret != 0) {
  223.                 pr_err("Failed to set SSC 1 for audio: %d\n", ret);
  224.                 return ret;
  225.         }
  226.  
  227.         /*
  228.          * Codec MCLK is supplied by PCK0 - set it up.
  229.          */
  230.         /*mclk = clk_get(NULL, "pck0");
  231.         if (IS_ERR(mclk)) {
  232.                 printk(KERN_ERR "ASoC: Failed to get MCLK\n");
  233.                 ret = PTR_ERR(mclk);
  234.                 goto err;
  235.         }
  236.  
  237.         pllb = clk_get(NULL, "pllb");
  238.         if (IS_ERR(pllb)) {
  239.                 printk(KERN_ERR "ASoC: Failed to get PLLB\n");
  240.                 ret = PTR_ERR(pllb);
  241.                 goto err_mclk;
  242.         }
  243.         ret = clk_set_parent(mclk, pllb);
  244.         clk_put(pllb);
  245.         if (ret != 0) {
  246.                 printk(KERN_ERR "ASoC: Failed to set MCLK parent\n");
  247.                 goto err_mclk;
  248.         }
  249.  
  250.         clk_set_rate(mclk, MCLK_RATE);*/
  251.  
  252.         /*ssc = ssc_request(1);
  253.  
  254.         if (IS_ERR(ssc)) {
  255.                 printk(KERN_ERR "ASoC: Failed to request SSC 1\n");
  256.                 ret = PTR_ERR(ssc);
  257.                 ssc = NULL;
  258.                 goto err_ssc;
  259.         }*/
  260.  
  261.         at91sam9263ek_snd_device = platform_device_alloc("soc-audio", -1);
  262.         if (!at91sam9263ek_snd_device) {
  263.                 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  264.                 ret = -ENOMEM;
  265.                 goto err_mclk;
  266.         }
  267.  
  268.         platform_set_drvdata(at91sam9263ek_snd_device,
  269.                         &snd_soc_at91sam9263ek);
  270.  
  271.         ret = platform_device_add(at91sam9263ek_snd_device);
  272.         if (ret) {
  273.                 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  274.                 goto err_device_add;
  275.         }
  276.  
  277.         return ret;
  278.  
  279. err_device_add:
  280.         platform_device_put(at91sam9263ek_snd_device);
  281. /*err_ssc:
  282.         ssc_free(ssc);*/
  283. err_mclk:
  284.         /*clk_put(mclk);
  285.         mclk = NULL;*/
  286. //err:
  287.         return ret;
  288. }
  289.  
  290. static void __exit at91sam9263ek_exit(void)
  291. {
  292.         platform_device_unregister(at91sam9263ek_snd_device);
  293.         at91sam9263ek_snd_device = NULL;
  294.         //clk_put(mclk);
  295.         //mclk = NULL;
  296. }
  297.  
  298. module_init(at91sam9263ek_init);
  299. module_exit(at91sam9263ek_exit);
  300.  
  301. /* Module information */
  302. MODULE_AUTHOR("Matthias Wieloch <matthias.wieloch@few-bauer.de>");
  303. MODULE_DESCRIPTION("ALSA SoC AT91SAM9263EK_WM8974");
  304. MODULE_LICENSE("GPL");
  305.  
  306.