2008-10-03 18:58:58 +04:00
|
|
|
/*
|
|
|
|
* sam9g20_wm8731 -- SoC audio for AT91SAM9G20-based
|
|
|
|
* ATMEL AT91SAM9G20ek board.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 SAN People
|
|
|
|
* Copyright (C) 2008 Atmel
|
|
|
|
*
|
|
|
|
* Authors: Sedji Gaouaou <sedji.gaouaou@atmel.com>
|
|
|
|
*
|
|
|
|
* Based on ati_b1_wm8731.c by:
|
|
|
|
* Frank Mandarino <fmandarino@endrelia.com>
|
|
|
|
* Copyright 2006 Endrelia Technologies Inc.
|
|
|
|
* Based on corgi.c by:
|
|
|
|
* Copyright 2005 Wolfson Microelectronics PLC.
|
|
|
|
* Copyright 2005 Openedhand Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
2009-02-16 23:49:16 +03:00
|
|
|
#include <linux/i2c.h>
|
2013-10-11 15:54:01 +04:00
|
|
|
#include <linux/of.h>
|
2008-10-03 18:58:58 +04:00
|
|
|
|
|
|
|
#include <linux/atmel-ssc.h>
|
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#include "../codecs/wm8731.h"
|
|
|
|
#include "atmel-pcm.h"
|
|
|
|
#include "atmel_ssc_dai.h"
|
|
|
|
|
2009-02-16 20:51:54 +03:00
|
|
|
#define MCLK_RATE 12000000
|
|
|
|
|
2009-07-08 21:18:19 +04:00
|
|
|
/*
|
|
|
|
* As shipped the board does not have inputs. However, it is relatively
|
|
|
|
* straightforward to modify the board to hook them up so support is left
|
|
|
|
* in the driver.
|
|
|
|
*/
|
|
|
|
#undef ENABLE_MIC_INPUT
|
|
|
|
|
2009-02-16 20:51:54 +03:00
|
|
|
static struct clk *mclk;
|
2008-10-03 18:58:58 +04:00
|
|
|
|
2009-02-16 20:51:54 +03:00
|
|
|
static int at91sam9g20ek_set_bias_level(struct snd_soc_card *card,
|
2011-06-06 22:13:23 +04:00
|
|
|
struct snd_soc_dapm_context *dapm,
|
2009-02-16 20:51:54 +03:00
|
|
|
enum snd_soc_bias_level level)
|
|
|
|
{
|
|
|
|
static int mclk_on;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case SND_SOC_BIAS_ON:
|
|
|
|
case SND_SOC_BIAS_PREPARE:
|
|
|
|
if (!mclk_on)
|
|
|
|
ret = clk_enable(mclk);
|
|
|
|
if (ret == 0)
|
|
|
|
mclk_on = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
|
|
if (mclk_on)
|
|
|
|
clk_disable(mclk);
|
|
|
|
mclk_on = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-03 18:58:58 +04:00
|
|
|
|
|
|
|
static const struct snd_soc_dapm_widget at91sam9g20ek_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_MIC("Int Mic", NULL),
|
|
|
|
SND_SOC_DAPM_SPK("Ext Spk", NULL),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_route intercon[] = {
|
|
|
|
|
2015-04-11 12:18:43 +03:00
|
|
|
/* speaker connected to LHPOUT/RHPOUT */
|
2008-10-03 18:58:58 +04:00
|
|
|
{"Ext Spk", NULL, "LHPOUT"},
|
2015-04-11 12:18:43 +03:00
|
|
|
{"Ext Spk", NULL, "RHPOUT"},
|
2008-10-03 18:58:58 +04:00
|
|
|
|
|
|
|
/* mic is connected to Mic Jack, with WM8731 Mic Bias */
|
|
|
|
{"MICIN", NULL, "Mic Bias"},
|
|
|
|
{"Mic Bias", NULL, "Int Mic"},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logic for a wm8731 as connected on a at91sam9g20ek board.
|
|
|
|
*/
|
2010-03-17 23:15:21 +03:00
|
|
|
static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
|
2008-10-03 18:58:58 +04:00
|
|
|
{
|
2010-03-17 23:15:21 +03:00
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2009-07-08 21:26:16 +04:00
|
|
|
int ret;
|
|
|
|
|
2008-10-03 18:58:58 +04:00
|
|
|
printk(KERN_DEBUG
|
|
|
|
"at91sam9g20ek_wm8731 "
|
|
|
|
": at91sam9g20ek_wm8731_init() called\n");
|
|
|
|
|
2011-05-24 13:51:16 +04:00
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_MCLK,
|
2009-07-08 21:26:16 +04:00
|
|
|
MCLK_RATE, SND_SOC_CLOCK_IN);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "Failed to set WM8731 SYSCLK: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-08 18:47:22 +04:00
|
|
|
#ifndef ENABLE_MIC_INPUT
|
|
|
|
snd_soc_dapm_nc_pin(&rtd->card->dapm, "Int Mic");
|
2009-07-08 21:18:19 +04:00
|
|
|
#endif
|
|
|
|
|
2008-10-03 18:58:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_dai_link at91sam9g20ek_dai = {
|
|
|
|
.name = "WM8731",
|
|
|
|
.stream_name = "WM8731 PCM",
|
2012-11-14 14:09:10 +04:00
|
|
|
.cpu_dai_name = "at91rm9200_ssc.0",
|
2010-03-17 23:15:21 +03:00
|
|
|
.codec_dai_name = "wm8731-hifi",
|
2008-10-03 18:58:58 +04:00
|
|
|
.init = at91sam9g20ek_wm8731_init,
|
2012-11-14 14:09:10 +04:00
|
|
|
.platform_name = "at91rm9200_ssc.0",
|
2011-03-27 17:35:15 +04:00
|
|
|
.codec_name = "wm8731.0-001b",
|
2015-01-01 19:16:10 +03:00
|
|
|
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|
|
|
|
SND_SOC_DAIFMT_CBM_CFM,
|
2008-10-03 18:58:58 +04:00
|
|
|
};
|
|
|
|
|
2008-11-18 23:50:34 +03:00
|
|
|
static struct snd_soc_card snd_soc_at91sam9g20ek = {
|
2009-02-16 21:00:58 +03:00
|
|
|
.name = "AT91SAMG20-EK",
|
2011-12-22 17:14:58 +04:00
|
|
|
.owner = THIS_MODULE,
|
2008-10-03 18:58:58 +04:00
|
|
|
.dai_link = &at91sam9g20ek_dai,
|
|
|
|
.num_links = 1,
|
2009-02-16 20:51:54 +03:00
|
|
|
.set_bias_level = at91sam9g20ek_set_bias_level,
|
2014-03-08 18:47:22 +04:00
|
|
|
|
|
|
|
.dapm_widgets = at91sam9g20ek_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(at91sam9g20ek_dapm_widgets),
|
|
|
|
.dapm_routes = intercon,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(intercon),
|
2015-04-11 12:18:43 +03:00
|
|
|
.fully_routed = true,
|
2008-10-03 18:58:58 +04:00
|
|
|
};
|
|
|
|
|
2012-12-07 18:26:21 +04:00
|
|
|
static int at91sam9g20ek_audio_probe(struct platform_device *pdev)
|
2008-10-03 18:58:58 +04:00
|
|
|
{
|
2012-11-14 14:09:11 +04:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
struct device_node *codec_np, *cpu_np;
|
2009-02-16 20:51:54 +03:00
|
|
|
struct clk *pllb;
|
2012-10-11 06:38:15 +04:00
|
|
|
struct snd_soc_card *card = &snd_soc_at91sam9g20ek;
|
2008-10-03 18:58:58 +04:00
|
|
|
int ret;
|
|
|
|
|
2012-11-14 14:09:11 +04:00
|
|
|
if (!np) {
|
2015-01-06 14:14:32 +03:00
|
|
|
return -ENODEV;
|
2012-11-14 14:09:11 +04:00
|
|
|
}
|
2009-02-16 19:04:05 +03:00
|
|
|
|
2012-11-14 14:09:10 +04:00
|
|
|
ret = atmel_ssc_set_audio(0);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "ssc channel is not valid\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-02-16 20:51:54 +03:00
|
|
|
/*
|
|
|
|
* Codec MCLK is supplied by PCK0 - set it up.
|
|
|
|
*/
|
|
|
|
mclk = clk_get(NULL, "pck0");
|
|
|
|
if (IS_ERR(mclk)) {
|
|
|
|
printk(KERN_ERR "ASoC: Failed to get MCLK\n");
|
|
|
|
ret = PTR_ERR(mclk);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
pllb = clk_get(NULL, "pllb");
|
2010-11-22 18:59:13 +03:00
|
|
|
if (IS_ERR(pllb)) {
|
2009-02-16 20:51:54 +03:00
|
|
|
printk(KERN_ERR "ASoC: Failed to get PLLB\n");
|
2010-11-22 18:59:13 +03:00
|
|
|
ret = PTR_ERR(pllb);
|
2009-02-16 20:51:54 +03:00
|
|
|
goto err_mclk;
|
|
|
|
}
|
|
|
|
ret = clk_set_parent(mclk, pllb);
|
|
|
|
clk_put(pllb);
|
|
|
|
if (ret != 0) {
|
|
|
|
printk(KERN_ERR "ASoC: Failed to set MCLK parent\n");
|
|
|
|
goto err_mclk;
|
|
|
|
}
|
|
|
|
|
|
|
|
clk_set_rate(mclk, MCLK_RATE);
|
|
|
|
|
2012-10-11 06:38:15 +04:00
|
|
|
card->dev = &pdev->dev;
|
2012-11-14 14:09:11 +04:00
|
|
|
|
|
|
|
/* Parse device node info */
|
2015-01-06 14:14:32 +03:00
|
|
|
ret = snd_soc_of_parse_card_name(card, "atmel,model");
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = snd_soc_of_parse_audio_routing(card,
|
|
|
|
"atmel,audio-routing");
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Parse codec info */
|
|
|
|
at91sam9g20ek_dai.codec_name = NULL;
|
|
|
|
codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
|
|
|
|
if (!codec_np) {
|
|
|
|
dev_err(&pdev->dev, "codec info missing\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
at91sam9g20ek_dai.codec_of_node = codec_np;
|
|
|
|
|
|
|
|
/* Parse dai and platform info */
|
|
|
|
at91sam9g20ek_dai.cpu_dai_name = NULL;
|
|
|
|
at91sam9g20ek_dai.platform_name = NULL;
|
|
|
|
cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
|
|
|
|
if (!cpu_np) {
|
|
|
|
dev_err(&pdev->dev, "dai and pcm info missing\n");
|
|
|
|
return -EINVAL;
|
2012-11-14 14:09:11 +04:00
|
|
|
}
|
2015-01-06 14:14:32 +03:00
|
|
|
at91sam9g20ek_dai.cpu_of_node = cpu_np;
|
|
|
|
at91sam9g20ek_dai.platform_of_node = cpu_np;
|
|
|
|
|
|
|
|
of_node_put(codec_np);
|
|
|
|
of_node_put(cpu_np);
|
2012-11-14 14:09:11 +04:00
|
|
|
|
2012-10-11 06:38:15 +04:00
|
|
|
ret = snd_soc_register_card(card);
|
2008-10-03 18:58:58 +04:00
|
|
|
if (ret) {
|
2012-10-11 06:38:15 +04:00
|
|
|
printk(KERN_ERR "ASoC: snd_soc_register_card() failed\n");
|
2008-10-03 18:58:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2009-02-16 20:51:54 +03:00
|
|
|
err_mclk:
|
|
|
|
clk_put(mclk);
|
|
|
|
mclk = NULL;
|
|
|
|
err:
|
2012-11-14 14:09:10 +04:00
|
|
|
atmel_ssc_put_audio(0);
|
2008-10-03 18:58:58 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-07 18:26:21 +04:00
|
|
|
static int at91sam9g20ek_audio_remove(struct platform_device *pdev)
|
2008-10-03 18:58:58 +04:00
|
|
|
{
|
2012-10-11 06:38:15 +04:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
|
|
|
|
2013-01-31 07:53:40 +04:00
|
|
|
clk_disable(mclk);
|
2009-02-16 20:51:54 +03:00
|
|
|
mclk = NULL;
|
2013-01-31 07:53:40 +04:00
|
|
|
snd_soc_unregister_card(card);
|
|
|
|
atmel_ssc_put_audio(0);
|
2012-10-11 06:38:15 +04:00
|
|
|
|
|
|
|
return 0;
|
2008-10-03 18:58:58 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 14:09:11 +04:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id at91sam9g20ek_wm8731_dt_ids[] = {
|
|
|
|
{ .compatible = "atmel,at91sam9g20ek-wm8731-audio", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, at91sam9g20ek_wm8731_dt_ids);
|
|
|
|
#endif
|
|
|
|
|
2012-10-11 06:38:15 +04:00
|
|
|
static struct platform_driver at91sam9g20ek_audio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "at91sam9g20ek-audio",
|
2012-11-14 14:09:11 +04:00
|
|
|
.of_match_table = of_match_ptr(at91sam9g20ek_wm8731_dt_ids),
|
2012-10-11 06:38:15 +04:00
|
|
|
},
|
|
|
|
.probe = at91sam9g20ek_audio_probe,
|
2012-12-07 18:26:21 +04:00
|
|
|
.remove = at91sam9g20ek_audio_remove,
|
2012-10-11 06:38:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(at91sam9g20ek_audio_driver);
|
2008-10-03 18:58:58 +04:00
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Sedji Gaouaou <sedji.gaouaou@atmel.com>");
|
|
|
|
MODULE_DESCRIPTION("ALSA SoC AT91SAM9G20EK_WM8731");
|
2012-10-11 06:38:15 +04:00
|
|
|
MODULE_ALIAS("platform:at91sam9g20ek-audio");
|
2008-10-03 18:58:58 +04:00
|
|
|
MODULE_LICENSE("GPL");
|