2019-04-19 18:21:39 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
//
|
|
|
|
// h1940_uda1380.c - ALSA SoC Audio Layer
|
|
|
|
//
|
|
|
|
// Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
|
|
|
|
// Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
|
|
|
|
//
|
|
|
|
// Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
|
2010-12-10 03:17:56 +08:00
|
|
|
|
ASoC: h1940: Fix compilation error due to missing header
Add linux/types.h to fix this compilation error:
In file included from arch/arm/mach-s3c2410/include/mach/gpio-fns.h:27:0,
from arch/arm/mach-s3c2410/include/mach/gpio.h:27,
from /home/anarsoul/work/pda-linux/linux-next/arch/arm/include/asm/gpio.h:5,
from include/linux/gpio.h:18,
from sound/soc/samsung/rx1950_uda1380.c:20:
arch/arm/plat-samsung/include/plat/gpio-cfg.h:29:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘s3c_gpio_pull_t’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:30:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘s5p_gpio_drvstr_t’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:57:2: error: expected specifier-qualifier-list before ‘s3c_gpio_pull_t’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:148:47: error: expected declaration specifiers or ‘...’ before ‘s3c_gpio_pull_t’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:156:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘s3c_gpio_getpull’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:175:24: error: expected declaration specifiers or ‘...’ before ‘s3c_gpio_pull_t’
arch/arm/plat-samsung/include/plat/gpio-cfg.h: In function ‘s3c_gpio_cfgrange_nopull’:
arch/arm/plat-samsung/include/plat/gpio-cfg.h:180:47: error: ‘s3c_gpio_pull_t’ undeclared (first use in this function)
arch/arm/plat-samsung/include/plat/gpio-cfg.h:180:47: note: each undeclared identifier is reported only once for each function it appears in
arch/arm/plat-samsung/include/plat/gpio-cfg.h:180:47: error: expected ‘)’ before numeric constant
arch/arm/plat-samsung/include/plat/gpio-cfg.h:180:47: error: too many arguments to function ‘s3c_gpio_cfgall_range’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:174:12: note: declared here
arch/arm/plat-samsung/include/plat/gpio-cfg.h: At top level:
arch/arm/plat-samsung/include/plat/gpio-cfg.h:199:26: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘s5p_gpio_get_drvstr’
arch/arm/plat-samsung/include/plat/gpio-cfg.h:210:50: error: expected declaration specifiers or ‘...’ before ‘s5p_gpio_drvstr_t’
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Jassi Brar <jassisinghbrar@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2011-08-12 22:52:59 +08:00
|
|
|
#include <linux/types.h>
|
2010-12-10 03:17:56 +08:00
|
|
|
#include <linux/gpio.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2010-12-10 03:17:56 +08:00
|
|
|
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/jack.h>
|
|
|
|
|
2013-04-12 01:08:42 +08:00
|
|
|
#include "regs-iis.h"
|
2010-12-10 03:17:56 +08:00
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
2014-01-22 20:00:38 +08:00
|
|
|
#include <mach/gpio-samsung.h>
|
2010-12-10 03:17:56 +08:00
|
|
|
#include "s3c24xx-i2s.h"
|
|
|
|
|
2015-10-22 16:43:21 +08:00
|
|
|
static const unsigned int rates[] = {
|
2010-12-10 03:17:56 +08:00
|
|
|
11025,
|
|
|
|
22050,
|
|
|
|
44100,
|
|
|
|
};
|
|
|
|
|
2015-10-22 16:43:21 +08:00
|
|
|
static const struct snd_pcm_hw_constraint_list hw_rates = {
|
2010-12-10 03:17:56 +08:00
|
|
|
.count = ARRAY_SIZE(rates),
|
|
|
|
.list = rates,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct snd_soc_jack hp_jack;
|
|
|
|
|
|
|
|
static struct snd_soc_jack_pin hp_jack_pins[] = {
|
|
|
|
{
|
|
|
|
.pin = "Headphone Jack",
|
|
|
|
.mask = SND_JACK_HEADPHONE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.pin = "Speaker",
|
|
|
|
.mask = SND_JACK_HEADPHONE,
|
|
|
|
.invert = 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct snd_soc_jack_gpio hp_jack_gpios[] = {
|
|
|
|
{
|
|
|
|
.gpio = S3C2410_GPG(4),
|
|
|
|
.name = "hp-gpio",
|
|
|
|
.report = SND_JACK_HEADPHONE,
|
|
|
|
.invert = 1,
|
|
|
|
.debounce_time = 200,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int h1940_startup(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
|
|
|
|
return snd_pcm_hw_constraint_list(runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
&hw_rates);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int h1940_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
int div;
|
|
|
|
int ret;
|
|
|
|
unsigned int rate = params_rate(params);
|
|
|
|
|
|
|
|
switch (rate) {
|
|
|
|
case 11025:
|
|
|
|
case 22050:
|
|
|
|
case 44100:
|
|
|
|
div = s3c24xx_i2s_get_clockrate() / (384 * rate);
|
|
|
|
if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (192 * rate))
|
|
|
|
div++;
|
|
|
|
break;
|
|
|
|
default:
|
2014-01-22 20:00:41 +08:00
|
|
|
dev_err(rtd->dev, "%s: rate %d is not supported\n",
|
2010-12-10 03:17:56 +08:00
|
|
|
__func__, rate);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select clock source */
|
|
|
|
ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate,
|
|
|
|
SND_SOC_CLOCK_OUT);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set MCLK division for sample rate */
|
|
|
|
ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
|
|
|
|
S3C2410_IISMOD_384FS);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set BCLK division for sample rate */
|
|
|
|
ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
|
|
|
|
S3C2410_IISMOD_32FS);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set prescaler division for sample rate */
|
|
|
|
ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
|
|
|
|
S3C24XX_PRESCALE(div, div));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_ops h1940_ops = {
|
|
|
|
.startup = h1940_startup,
|
|
|
|
.hw_params = h1940_hw_params,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int h1940_spk_power(struct snd_soc_dapm_widget *w,
|
|
|
|
struct snd_kcontrol *kcontrol, int event)
|
|
|
|
{
|
|
|
|
if (SND_SOC_DAPM_EVENT_ON(event))
|
2013-01-03 02:18:58 +08:00
|
|
|
gpio_set_value(S3C_GPIO_END + 9, 1);
|
2010-12-10 03:17:56 +08:00
|
|
|
else
|
2013-01-03 02:18:58 +08:00
|
|
|
gpio_set_value(S3C_GPIO_END + 9, 0);
|
2010-12-10 03:17:56 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* h1940 machine dapm widgets */
|
|
|
|
static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_HP("Headphone Jack", NULL),
|
|
|
|
SND_SOC_DAPM_MIC("Mic Jack", NULL),
|
|
|
|
SND_SOC_DAPM_SPK("Speaker", h1940_spk_power),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* h1940 machine audio_map */
|
|
|
|
static const struct snd_soc_dapm_route audio_map[] = {
|
|
|
|
/* headphone connected to VOUTLHP, VOUTRHP */
|
|
|
|
{"Headphone Jack", NULL, "VOUTLHP"},
|
|
|
|
{"Headphone Jack", NULL, "VOUTRHP"},
|
|
|
|
|
|
|
|
/* ext speaker connected to VOUTL, VOUTR */
|
|
|
|
{"Speaker", NULL, "VOUTL"},
|
|
|
|
{"Speaker", NULL, "VOUTR"},
|
|
|
|
|
|
|
|
/* mic is connected to VINM */
|
|
|
|
{"VINM", NULL, "Mic Jack"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *s3c24xx_snd_device;
|
|
|
|
|
|
|
|
static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
2015-03-04 17:33:33 +08:00
|
|
|
snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
|
|
|
|
&hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
|
2010-12-10 03:17:56 +08:00
|
|
|
|
|
|
|
snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
|
|
|
|
hp_jack_gpios);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* s3c24xx digital audio interface glue - connects codec <--> CPU */
|
2019-06-06 12:09:25 +08:00
|
|
|
SND_SOC_DAILINK_DEFS(uda1380,
|
|
|
|
DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")),
|
|
|
|
DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-001a", "uda1380-hifi")),
|
|
|
|
DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis")));
|
|
|
|
|
2010-12-10 03:17:56 +08:00
|
|
|
static struct snd_soc_dai_link h1940_uda1380_dai[] = {
|
|
|
|
{
|
|
|
|
.name = "uda1380",
|
|
|
|
.stream_name = "UDA1380 Duplex",
|
|
|
|
.init = h1940_uda1380_init,
|
2015-01-02 00:16:20 +08:00
|
|
|
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|
|
|
|
SND_SOC_DAIFMT_CBS_CFS,
|
2010-12-10 03:17:56 +08:00
|
|
|
.ops = &h1940_ops,
|
2019-06-06 12:09:25 +08:00
|
|
|
SND_SOC_DAILINK_REG(uda1380),
|
2010-12-10 03:17:56 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct snd_soc_card h1940_asoc = {
|
|
|
|
.name = "h1940",
|
2011-12-22 10:53:15 +08:00
|
|
|
.owner = THIS_MODULE,
|
2010-12-10 03:17:56 +08:00
|
|
|
.dai_link = h1940_uda1380_dai,
|
|
|
|
.num_links = ARRAY_SIZE(h1940_uda1380_dai),
|
2011-10-08 20:30:06 +08:00
|
|
|
|
|
|
|
.dapm_widgets = uda1380_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
|
|
|
|
.dapm_routes = audio_map,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(audio_map),
|
2010-12-10 03:17:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init h1940_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!machine_is_h1940())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* configure some gpios */
|
2013-01-03 02:18:58 +08:00
|
|
|
ret = gpio_request(S3C_GPIO_END + 9, "speaker-power");
|
2010-12-10 03:17:56 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_out;
|
|
|
|
|
2013-01-03 02:18:58 +08:00
|
|
|
ret = gpio_direction_output(S3C_GPIO_END + 9, 0);
|
2010-12-10 03:17:56 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_gpio;
|
|
|
|
|
|
|
|
s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
|
|
|
|
if (!s3c24xx_snd_device) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_gpio;
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc);
|
|
|
|
ret = platform_device_add(s3c24xx_snd_device);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto err_plat;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_plat:
|
|
|
|
platform_device_put(s3c24xx_snd_device);
|
|
|
|
err_gpio:
|
2013-01-03 02:18:58 +08:00
|
|
|
gpio_free(S3C_GPIO_END + 9);
|
2010-12-10 03:17:56 +08:00
|
|
|
|
|
|
|
err_out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit h1940_exit(void)
|
|
|
|
{
|
|
|
|
platform_device_unregister(s3c24xx_snd_device);
|
2013-01-03 02:18:58 +08:00
|
|
|
gpio_free(S3C_GPIO_END + 9);
|
2010-12-10 03:17:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(h1940_init);
|
|
|
|
module_exit(h1940_exit);
|
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
|
|
|
|
MODULE_DESCRIPTION("ALSA SoC H1940");
|
|
|
|
MODULE_LICENSE("GPL");
|