2010-08-30 02:28:08 -06:00
|
|
|
/*
|
|
|
|
* rx1950.c -- ALSA Soc Audio Layer
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
|
|
|
|
*
|
|
|
|
* Based on smdk2440.c and magician.c
|
|
|
|
*
|
|
|
|
* Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com
|
|
|
|
* Philipp Zabel <philipp.zabel@gmail.com>
|
|
|
|
* Denis Grigoriev <dgreenday@gmail.com>
|
|
|
|
* Vasily Khoruzhick <anarsoul@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
ASoC: rx1950: 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 08:53:00 -06:00
|
|
|
#include <linux/types.h>
|
2010-08-30 02:28:08 -06:00
|
|
|
#include <linux/gpio.h>
|
2011-07-15 10:38:28 -06:00
|
|
|
#include <linux/module.h>
|
2010-08-30 02:28:08 -06:00
|
|
|
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/jack.h>
|
|
|
|
|
2014-01-22 05:00:38 -07:00
|
|
|
#include <mach/gpio-samsung.h>
|
2013-04-11 11:08:42 -06:00
|
|
|
#include "regs-iis.h"
|
2010-09-07 08:04:15 -06:00
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
2010-08-30 02:28:08 -06:00
|
|
|
#include "s3c24xx-i2s.h"
|
|
|
|
|
|
|
|
static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd);
|
2014-06-03 04:31:46 -06:00
|
|
|
static int rx1950_uda1380_card_remove(struct snd_soc_card *card);
|
2010-08-30 02:28:08 -06:00
|
|
|
static int rx1950_startup(struct snd_pcm_substream *substream);
|
|
|
|
static int rx1950_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params);
|
|
|
|
static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
|
|
|
|
struct snd_kcontrol *kcontrol, int event);
|
|
|
|
|
|
|
|
static unsigned int rates[] = {
|
|
|
|
16000,
|
|
|
|
44100,
|
|
|
|
48000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct snd_pcm_hw_constraint_list hw_rates = {
|
|
|
|
.count = ARRAY_SIZE(rates),
|
|
|
|
.list = rates,
|
|
|
|
.mask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
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[] = {
|
|
|
|
[0] = {
|
|
|
|
.gpio = S3C2410_GPG(12),
|
|
|
|
.name = "hp-gpio",
|
|
|
|
.report = SND_JACK_HEADPHONE,
|
|
|
|
.invert = 1,
|
|
|
|
.debounce_time = 200,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct snd_soc_ops rx1950_ops = {
|
|
|
|
.startup = rx1950_startup,
|
|
|
|
.hw_params = rx1950_hw_params,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* s3c24xx digital audio interface glue - connects codec <--> CPU */
|
|
|
|
static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
|
|
|
|
{
|
|
|
|
.name = "uda1380",
|
|
|
|
.stream_name = "UDA1380 Duplex",
|
|
|
|
.cpu_dai_name = "s3c24xx-iis",
|
|
|
|
.codec_dai_name = "uda1380-hifi",
|
|
|
|
.init = rx1950_uda1380_init,
|
2012-12-07 01:29:21 -07:00
|
|
|
.platform_name = "s3c24xx-iis",
|
2010-08-30 02:28:08 -06:00
|
|
|
.codec_name = "uda1380-codec.0-001a",
|
2015-01-01 09:16:23 -07:00
|
|
|
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|
|
|
|
SND_SOC_DAIFMT_CBS_CFS,
|
2010-08-30 02:28:08 -06:00
|
|
|
.ops = &rx1950_ops,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rx1950 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", rx1950_spk_power),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rx1950 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"},
|
|
|
|
};
|
|
|
|
|
2011-10-08 06:30:35 -06:00
|
|
|
static struct snd_soc_card rx1950_asoc = {
|
|
|
|
.name = "rx1950",
|
2011-12-21 19:53:15 -07:00
|
|
|
.owner = THIS_MODULE,
|
ASoC: free jack GPIOs before the sound card is freed
This is the same change as commit fb6b8e71448a "ASoC: tegra: free jack
GPIOs before the sound card is freed", but applied to all other ASoC
machine drivers where code inspection indicates the same problem exists.
That commit's description is:
==========
snd_soc_jack_add_gpios() schedules a work queue item to poll the GPIO to
generate an initial jack status report. If sound card initialization
fails, that work item needs to be cancelled, so it doesn't run after the
card has been freed. Specifically, freeing the card calls
snd_jack_dev_free() which calls snd_jack_dev_disconnect() which sets
jack->input_dev = NULL, and input_dev is used by snd_jack_report(), which
is called from the work queue item.
snd_soc_jack_free_gpios() cancels the work item. The Tegra ASoC machine
drivers do call this function in the platform driver remove() callback.
However, this happens after the sound card is freed, at least when the
card is freed due to errors late during snd_soc_instantiate_card(). This
leaves a window where the work item can execute after the card is freed.
In next-20140522, sound card initialization does fail for unrelated
reasons, and hits the problem described above.
To solve this, fix the Tegra ASoC machine drivers to clean up the Jack
GPIOs during the snd_soc_card's .remove() callback, which is executed
before the overall card object is freed. also, guard the cleanup call
based on whether we actually setup up the GPIOs in the first place.
Ideally, we'd do the cleanup in a struct snd_soc_dai_link .fini/remove
function to match where the GPIOs get set up. However, there is no such
callback.
==========
Note that I have not even compile-tested this in most cases, since most
of the drivers rely on specific mach-* support I don't have enabled, and
don't support COMPILE_TEST. Testing by the relevant board maintainers
would be useful.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2014-05-30 12:42:57 -06:00
|
|
|
.remove = rx1950_uda1380_card_remove,
|
2011-10-08 06:30:35 -06:00
|
|
|
.dai_link = rx1950_uda1380_dai,
|
|
|
|
.num_links = ARRAY_SIZE(rx1950_uda1380_dai),
|
|
|
|
|
|
|
|
.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-08-30 02:28:08 -06:00
|
|
|
static struct platform_device *s3c24xx_snd_device;
|
|
|
|
|
|
|
|
static int rx1950_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 rx1950_spk_power(struct snd_soc_dapm_widget *w,
|
|
|
|
struct snd_kcontrol *kcontrol, int event)
|
|
|
|
{
|
|
|
|
if (SND_SOC_DAPM_EVENT_ON(event))
|
|
|
|
gpio_set_value(S3C2410_GPA(1), 1);
|
|
|
|
else
|
|
|
|
gpio_set_value(S3C2410_GPA(1), 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rx1950_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);
|
|
|
|
int clk_source, fs_mode;
|
|
|
|
|
|
|
|
switch (rate) {
|
|
|
|
case 16000:
|
|
|
|
case 48000:
|
|
|
|
clk_source = S3C24XX_CLKSRC_PCLK;
|
2010-09-07 08:04:18 -06:00
|
|
|
fs_mode = S3C2410_IISMOD_256FS;
|
|
|
|
div = s3c24xx_i2s_get_clockrate() / (256 * rate);
|
|
|
|
if (s3c24xx_i2s_get_clockrate() % (256 * rate) > (128 * rate))
|
2010-08-30 02:28:08 -06:00
|
|
|
div++;
|
|
|
|
break;
|
|
|
|
case 44100:
|
|
|
|
case 88200:
|
|
|
|
clk_source = S3C24XX_CLKSRC_MPLL;
|
2010-11-13 05:53:41 -07:00
|
|
|
fs_mode = S3C2410_IISMOD_384FS;
|
|
|
|
div = 1;
|
2010-08-30 02:28:08 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "%s: rate %d is not supported\n",
|
|
|
|
__func__, rate);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select clock source */
|
|
|
|
ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, 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,
|
2010-11-13 05:53:41 -07:00
|
|
|
fs_mode);
|
2010-08-30 02:28:08 -06:00
|
|
|
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 int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
2015-03-04 02:33:36 -07:00
|
|
|
snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
|
|
|
|
&hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
|
2010-08-30 02:28:08 -06:00
|
|
|
|
|
|
|
snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
|
|
|
|
hp_jack_gpios);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-03 04:31:46 -06:00
|
|
|
static int rx1950_uda1380_card_remove(struct snd_soc_card *card)
|
ASoC: free jack GPIOs before the sound card is freed
This is the same change as commit fb6b8e71448a "ASoC: tegra: free jack
GPIOs before the sound card is freed", but applied to all other ASoC
machine drivers where code inspection indicates the same problem exists.
That commit's description is:
==========
snd_soc_jack_add_gpios() schedules a work queue item to poll the GPIO to
generate an initial jack status report. If sound card initialization
fails, that work item needs to be cancelled, so it doesn't run after the
card has been freed. Specifically, freeing the card calls
snd_jack_dev_free() which calls snd_jack_dev_disconnect() which sets
jack->input_dev = NULL, and input_dev is used by snd_jack_report(), which
is called from the work queue item.
snd_soc_jack_free_gpios() cancels the work item. The Tegra ASoC machine
drivers do call this function in the platform driver remove() callback.
However, this happens after the sound card is freed, at least when the
card is freed due to errors late during snd_soc_instantiate_card(). This
leaves a window where the work item can execute after the card is freed.
In next-20140522, sound card initialization does fail for unrelated
reasons, and hits the problem described above.
To solve this, fix the Tegra ASoC machine drivers to clean up the Jack
GPIOs during the snd_soc_card's .remove() callback, which is executed
before the overall card object is freed. also, guard the cleanup call
based on whether we actually setup up the GPIOs in the first place.
Ideally, we'd do the cleanup in a struct snd_soc_dai_link .fini/remove
function to match where the GPIOs get set up. However, there is no such
callback.
==========
Note that I have not even compile-tested this in most cases, since most
of the drivers rely on specific mach-* support I don't have enabled, and
don't support COMPILE_TEST. Testing by the relevant board maintainers
would be useful.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2014-05-30 12:42:57 -06:00
|
|
|
{
|
|
|
|
snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
|
|
|
|
hp_jack_gpios);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-30 02:28:08 -06:00
|
|
|
static int __init rx1950_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-09-07 08:04:15 -06:00
|
|
|
if (!machine_is_rx1950())
|
|
|
|
return -ENODEV;
|
|
|
|
|
2010-08-30 02:28:08 -06:00
|
|
|
/* configure some gpios */
|
|
|
|
ret = gpio_request(S3C2410_GPA(1), "speaker-power");
|
|
|
|
if (ret)
|
|
|
|
goto err_gpio;
|
|
|
|
|
|
|
|
ret = gpio_direction_output(S3C2410_GPA(1), 0);
|
|
|
|
if (ret)
|
|
|
|
goto err_gpio_conf;
|
|
|
|
|
|
|
|
s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
|
|
|
|
if (!s3c24xx_snd_device) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_plat_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc);
|
|
|
|
ret = platform_device_add(s3c24xx_snd_device);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
platform_device_put(s3c24xx_snd_device);
|
|
|
|
goto err_plat_add;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_plat_add:
|
|
|
|
err_plat_alloc:
|
|
|
|
err_gpio_conf:
|
|
|
|
gpio_free(S3C2410_GPA(1));
|
|
|
|
|
|
|
|
err_gpio:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit rx1950_exit(void)
|
|
|
|
{
|
|
|
|
platform_device_unregister(s3c24xx_snd_device);
|
|
|
|
gpio_free(S3C2410_GPA(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(rx1950_init);
|
|
|
|
module_exit(rx1950_exit);
|
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Vasily Khoruzhick");
|
|
|
|
MODULE_DESCRIPTION("ALSA SoC RX1950");
|
|
|
|
MODULE_LICENSE("GPL");
|