2019-05-26 23:55:05 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-10-03 07:58:58 -07: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2013-10-11 04:54:01 -07:00
|
|
|
#include <linux/of.h>
|
2008-10-03 07:58:58 -07: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 10:51:54 -07:00
|
|
|
#define MCLK_RATE 12000000
|
|
|
|
|
2009-07-08 10:18:19 -07: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
|
|
|
|
|
2008-10-03 07:58:58 -07: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 02:18:43 -07:00
|
|
|
/* speaker connected to LHPOUT/RHPOUT */
|
2008-10-03 07:58:58 -07:00
|
|
|
{"Ext Spk", NULL, "LHPOUT"},
|
2015-04-11 02:18:43 -07:00
|
|
|
{"Ext Spk", NULL, "RHPOUT"},
|
2008-10-03 07:58:58 -07: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 13:15:21 -07:00
|
|
|
static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
|
2008-10-03 07:58:58 -07:00
|
|
|
{
|
2023-09-11 16:49:01 -07:00
|
|
|
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
|
2018-01-15 00:52:54 -07:00
|
|
|
struct device *dev = rtd->dev;
|
2009-07-08 10:26:16 -07:00
|
|
|
int ret;
|
|
|
|
|
2018-01-15 00:52:54 -07:00
|
|
|
dev_dbg(dev, "%s called\n", __func__);
|
2008-10-03 07:58:58 -07:00
|
|
|
|
2011-05-24 02:51:16 -07:00
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_MCLK,
|
2018-01-15 00:52:54 -07:00
|
|
|
MCLK_RATE, SND_SOC_CLOCK_IN);
|
2009-07-08 10:26:16 -07:00
|
|
|
if (ret < 0) {
|
2018-01-15 00:52:54 -07:00
|
|
|
dev_err(dev, "Failed to set WM8731 SYSCLK: %d\n", ret);
|
2009-07-08 10:26:16 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-08 07:47:22 -07:00
|
|
|
#ifndef ENABLE_MIC_INPUT
|
|
|
|
snd_soc_dapm_nc_pin(&rtd->card->dapm, "Int Mic");
|
2009-07-08 10:18:19 -07:00
|
|
|
#endif
|
|
|
|
|
2008-10-03 07:58:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-05 21:13:46 -07:00
|
|
|
SND_SOC_DAILINK_DEFS(pcm,
|
|
|
|
DAILINK_COMP_ARRAY(COMP_CPU("at91rm9200_ssc.0")),
|
2019-06-27 18:47:02 -07:00
|
|
|
DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.0-001b", "wm8731-hifi")),
|
|
|
|
DAILINK_COMP_ARRAY(COMP_PLATFORM("at91rm9200_ssc.0")));
|
2019-06-05 21:13:46 -07:00
|
|
|
|
2008-10-03 07:58:58 -07:00
|
|
|
static struct snd_soc_dai_link at91sam9g20ek_dai = {
|
|
|
|
.name = "WM8731",
|
|
|
|
.stream_name = "WM8731 PCM",
|
|
|
|
.init = at91sam9g20ek_wm8731_init,
|
2015-01-01 09:16:10 -07:00
|
|
|
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|
2021-09-15 10:30:23 -07:00
|
|
|
SND_SOC_DAIFMT_CBP_CFP,
|
2023-02-25 14:48:13 -07:00
|
|
|
#ifndef ENABLE_MIC_INPUT
|
|
|
|
.playback_only = true,
|
|
|
|
#endif
|
2019-06-05 21:13:46 -07:00
|
|
|
SND_SOC_DAILINK_REG(pcm),
|
2008-10-03 07:58:58 -07:00
|
|
|
};
|
|
|
|
|
2008-11-18 13:50:34 -07:00
|
|
|
static struct snd_soc_card snd_soc_at91sam9g20ek = {
|
2009-02-16 11:00:58 -07:00
|
|
|
.name = "AT91SAMG20-EK",
|
2011-12-22 06:14:58 -07:00
|
|
|
.owner = THIS_MODULE,
|
2008-10-03 07:58:58 -07:00
|
|
|
.dai_link = &at91sam9g20ek_dai,
|
|
|
|
.num_links = 1,
|
2014-03-08 07:47:22 -07: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 02:18:43 -07:00
|
|
|
.fully_routed = true,
|
2008-10-03 07:58:58 -07:00
|
|
|
};
|
|
|
|
|
2012-12-07 07:26:21 -07:00
|
|
|
static int at91sam9g20ek_audio_probe(struct platform_device *pdev)
|
2008-10-03 07:58:58 -07:00
|
|
|
{
|
2012-11-14 03:09:11 -07:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
struct device_node *codec_np, *cpu_np;
|
2012-10-10 19:38:15 -07:00
|
|
|
struct snd_soc_card *card = &snd_soc_at91sam9g20ek;
|
2008-10-03 07:58:58 -07:00
|
|
|
int ret;
|
|
|
|
|
2012-11-14 03:09:11 -07:00
|
|
|
if (!np) {
|
2015-01-06 04:14:32 -07:00
|
|
|
return -ENODEV;
|
2012-11-14 03:09:11 -07:00
|
|
|
}
|
2009-02-16 09:04:05 -07:00
|
|
|
|
2012-11-14 03:09:10 -07:00
|
|
|
ret = atmel_ssc_set_audio(0);
|
|
|
|
if (ret) {
|
2022-03-25 08:42:41 -07:00
|
|
|
dev_err(&pdev->dev, "ssc channel is not valid: %d\n", ret);
|
|
|
|
return ret;
|
2012-11-14 03:09:10 -07:00
|
|
|
}
|
|
|
|
|
2012-10-10 19:38:15 -07:00
|
|
|
card->dev = &pdev->dev;
|
2012-11-14 03:09:11 -07:00
|
|
|
|
|
|
|
/* Parse device node info */
|
2015-01-06 04:14:32 -07: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 */
|
2019-06-05 21:13:46 -07:00
|
|
|
at91sam9g20ek_dai.codecs->name = NULL;
|
2015-01-06 04:14:32 -07:00
|
|
|
codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
|
|
|
|
if (!codec_np) {
|
|
|
|
dev_err(&pdev->dev, "codec info missing\n");
|
2022-03-25 08:42:40 -07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
2015-01-06 04:14:32 -07:00
|
|
|
}
|
2019-06-05 21:13:46 -07:00
|
|
|
at91sam9g20ek_dai.codecs->of_node = codec_np;
|
2015-01-06 04:14:32 -07:00
|
|
|
|
|
|
|
/* Parse dai and platform info */
|
2019-06-05 21:13:46 -07:00
|
|
|
at91sam9g20ek_dai.cpus->dai_name = NULL;
|
2019-06-27 18:47:02 -07:00
|
|
|
at91sam9g20ek_dai.platforms->name = NULL;
|
2015-01-06 04:14:32 -07:00
|
|
|
cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
|
|
|
|
if (!cpu_np) {
|
|
|
|
dev_err(&pdev->dev, "dai and pcm info missing\n");
|
2022-03-07 05:45:39 -07:00
|
|
|
of_node_put(codec_np);
|
2022-03-25 08:42:40 -07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
2012-11-14 03:09:11 -07:00
|
|
|
}
|
2019-06-05 21:13:46 -07:00
|
|
|
at91sam9g20ek_dai.cpus->of_node = cpu_np;
|
2019-06-27 18:47:02 -07:00
|
|
|
at91sam9g20ek_dai.platforms->of_node = cpu_np;
|
2015-01-06 04:14:32 -07:00
|
|
|
|
|
|
|
of_node_put(codec_np);
|
|
|
|
of_node_put(cpu_np);
|
2012-11-14 03:09:11 -07:00
|
|
|
|
2012-10-10 19:38:15 -07:00
|
|
|
ret = snd_soc_register_card(card);
|
2008-10-03 07:58:58 -07:00
|
|
|
if (ret) {
|
2022-05-06 06:03:49 -07:00
|
|
|
dev_err_probe(&pdev->dev, ret,
|
2022-08-05 22:45:48 -07:00
|
|
|
"snd_soc_register_card() failed\n");
|
2022-03-25 08:42:40 -07:00
|
|
|
goto err;
|
2008-10-03 07:58:58 -07:00
|
|
|
}
|
|
|
|
|
2022-03-25 08:42:40 -07:00
|
|
|
return 0;
|
2008-10-03 07:58:58 -07:00
|
|
|
|
2009-02-16 10:51:54 -07:00
|
|
|
err:
|
2012-11-14 03:09:10 -07:00
|
|
|
atmel_ssc_put_audio(0);
|
2008-10-03 07:58:58 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-15 08:05:23 -07:00
|
|
|
static void at91sam9g20ek_audio_remove(struct platform_device *pdev)
|
2008-10-03 07:58:58 -07:00
|
|
|
{
|
2012-10-10 19:38:15 -07:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
|
|
|
|
2013-01-30 20:53:40 -07:00
|
|
|
snd_soc_unregister_card(card);
|
|
|
|
atmel_ssc_put_audio(0);
|
2008-10-03 07:58:58 -07:00
|
|
|
}
|
|
|
|
|
2012-11-14 03:09:11 -07: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-10 19:38:15 -07:00
|
|
|
static struct platform_driver at91sam9g20ek_audio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "at91sam9g20ek-audio",
|
2012-11-14 03:09:11 -07:00
|
|
|
.of_match_table = of_match_ptr(at91sam9g20ek_wm8731_dt_ids),
|
2012-10-10 19:38:15 -07:00
|
|
|
},
|
|
|
|
.probe = at91sam9g20ek_audio_probe,
|
2024-09-09 08:12:30 -07:00
|
|
|
.remove = at91sam9g20ek_audio_remove,
|
2012-10-10 19:38:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(at91sam9g20ek_audio_driver);
|
2008-10-03 07:58:58 -07:00
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Sedji Gaouaou <sedji.gaouaou@atmel.com>");
|
|
|
|
MODULE_DESCRIPTION("ALSA SoC AT91SAM9G20EK_WM8731");
|
2012-10-10 19:38:15 -07:00
|
|
|
MODULE_ALIAS("platform:at91sam9g20ek-audio");
|
2008-10-03 07:58:58 -07:00
|
|
|
MODULE_LICENSE("GPL");
|