2009-03-09 09:13:17 +08:00
|
|
|
/*
|
|
|
|
* AK4104 ALSA SoC (ASoC) driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-03-09 09:13:17 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <linux/spi/spi.h>
|
2012-11-14 18:28:39 +08:00
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/of_gpio.h>
|
2009-03-09 09:13:17 +08:00
|
|
|
#include <sound/asoundef.h>
|
|
|
|
|
|
|
|
/* AK4104 registers addresses */
|
|
|
|
#define AK4104_REG_CONTROL1 0x00
|
|
|
|
#define AK4104_REG_RESERVED 0x01
|
|
|
|
#define AK4104_REG_CONTROL2 0x02
|
|
|
|
#define AK4104_REG_TX 0x03
|
|
|
|
#define AK4104_REG_CHN_STATUS(x) ((x) + 0x04)
|
|
|
|
#define AK4104_NUM_REGS 10
|
|
|
|
|
|
|
|
#define AK4104_REG_MASK 0x1f
|
|
|
|
#define AK4104_READ 0xc0
|
|
|
|
#define AK4104_WRITE 0xe0
|
|
|
|
#define AK4104_RESERVED_VAL 0x5b
|
|
|
|
|
|
|
|
/* Bit masks for AK4104 registers */
|
|
|
|
#define AK4104_CONTROL1_RSTN (1 << 0)
|
|
|
|
#define AK4104_CONTROL1_PW (1 << 1)
|
|
|
|
#define AK4104_CONTROL1_DIF0 (1 << 2)
|
|
|
|
#define AK4104_CONTROL1_DIF1 (1 << 3)
|
|
|
|
|
|
|
|
#define AK4104_CONTROL2_SEL0 (1 << 0)
|
|
|
|
#define AK4104_CONTROL2_SEL1 (1 << 1)
|
|
|
|
#define AK4104_CONTROL2_MODE (1 << 2)
|
|
|
|
|
|
|
|
#define AK4104_TX_TXE (1 << 0)
|
|
|
|
#define AK4104_TX_V (1 << 1)
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
#define DRV_NAME "ak4104-codec"
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
struct ak4104_private {
|
2012-02-18 04:14:18 +08:00
|
|
|
struct regmap *regmap;
|
2009-03-09 09:13:17 +08:00
|
|
|
};
|
|
|
|
|
2013-08-08 02:01:40 +08:00
|
|
|
static const struct snd_soc_dapm_widget ak4104_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_OUTPUT("TX"),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_route ak4104_dapm_routes[] = {
|
|
|
|
{ "TX", NULL, "Playback" },
|
|
|
|
};
|
|
|
|
|
2009-03-09 09:13:17 +08:00
|
|
|
static int ak4104_set_dai_fmt(struct snd_soc_dai *codec_dai,
|
|
|
|
unsigned int format)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2013-03-07 05:22:15 +08:00
|
|
|
struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
|
2009-03-09 09:13:17 +08:00
|
|
|
int val = 0;
|
2012-02-18 04:14:18 +08:00
|
|
|
int ret;
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
/* set DAI format */
|
|
|
|
switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
val |= AK4104_CONTROL1_DIF0;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
val |= AK4104_CONTROL1_DIF0 | AK4104_CONTROL1_DIF1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(codec->dev, "invalid dai format\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This device can only be slave */
|
|
|
|
if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-03-07 05:22:15 +08:00
|
|
|
ret = regmap_update_bits(ak4104->regmap, AK4104_REG_CONTROL1,
|
|
|
|
AK4104_CONTROL1_DIF0 | AK4104_CONTROL1_DIF1,
|
|
|
|
val);
|
2012-02-18 04:04:41 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
2009-03-09 09:13:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ak4104_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2012-04-04 22:58:16 +08:00
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
2013-03-07 05:22:15 +08:00
|
|
|
struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
|
2013-03-07 05:22:16 +08:00
|
|
|
int ret, val = 0;
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
/* set the IEC958 bits: consumer mode, no copyright bit */
|
|
|
|
val |= IEC958_AES0_CON_NOT_COPYRIGHT;
|
2013-03-07 05:22:15 +08:00
|
|
|
regmap_write(ak4104->regmap, AK4104_REG_CHN_STATUS(0), val);
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
val = 0;
|
|
|
|
|
|
|
|
switch (params_rate(params)) {
|
2012-10-07 23:51:23 +08:00
|
|
|
case 22050:
|
|
|
|
val |= IEC958_AES3_CON_FS_22050;
|
|
|
|
break;
|
|
|
|
case 24000:
|
|
|
|
val |= IEC958_AES3_CON_FS_24000;
|
|
|
|
break;
|
|
|
|
case 32000:
|
|
|
|
val |= IEC958_AES3_CON_FS_32000;
|
|
|
|
break;
|
2009-03-09 09:13:17 +08:00
|
|
|
case 44100:
|
|
|
|
val |= IEC958_AES3_CON_FS_44100;
|
|
|
|
break;
|
|
|
|
case 48000:
|
|
|
|
val |= IEC958_AES3_CON_FS_48000;
|
|
|
|
break;
|
2012-10-07 23:51:23 +08:00
|
|
|
case 88200:
|
|
|
|
val |= IEC958_AES3_CON_FS_88200;
|
|
|
|
break;
|
|
|
|
case 96000:
|
|
|
|
val |= IEC958_AES3_CON_FS_96000;
|
|
|
|
break;
|
|
|
|
case 176400:
|
|
|
|
val |= IEC958_AES3_CON_FS_176400;
|
|
|
|
break;
|
|
|
|
case 192000:
|
|
|
|
val |= IEC958_AES3_CON_FS_192000;
|
2009-03-09 09:13:17 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(codec->dev, "unsupported sampling rate\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-03-07 05:22:16 +08:00
|
|
|
ret = regmap_write(ak4104->regmap, AK4104_REG_CHN_STATUS(3), val);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* enable transmitter */
|
|
|
|
ret = regmap_update_bits(ak4104->regmap, AK4104_REG_TX,
|
|
|
|
AK4104_TX_TXE, AK4104_TX_TXE);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ak4104_hw_free(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
|
|
|
struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
/* disable transmitter */
|
|
|
|
return regmap_update_bits(ak4104->regmap, AK4104_REG_TX,
|
|
|
|
AK4104_TX_TXE, 0);
|
2009-03-09 09:13:17 +08:00
|
|
|
}
|
|
|
|
|
2011-11-23 18:40:40 +08:00
|
|
|
static const struct snd_soc_dai_ops ak4101_dai_ops = {
|
2009-03-12 00:51:31 +08:00
|
|
|
.hw_params = ak4104_hw_params,
|
2013-03-07 05:22:16 +08:00
|
|
|
.hw_free = ak4104_hw_free,
|
2009-03-12 00:51:31 +08:00
|
|
|
.set_fmt = ak4104_set_dai_fmt,
|
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_dai_driver ak4104_dai = {
|
|
|
|
.name = "ak4104-hifi",
|
2009-03-09 09:13:17 +08:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "Playback",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
2010-01-13 18:25:05 +08:00
|
|
|
.rates = SNDRV_PCM_RATE_8000_192000,
|
2009-03-09 09:13:17 +08:00
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE
|
|
|
|
},
|
2009-03-12 00:51:31 +08:00
|
|
|
.ops = &ak4101_dai_ops,
|
2009-03-09 09:13:17 +08:00
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int ak4104_probe(struct snd_soc_codec *codec)
|
2009-03-09 09:13:17 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
|
2012-02-18 04:14:18 +08:00
|
|
|
int ret;
|
2009-03-09 09:13:17 +08:00
|
|
|
|
2012-02-18 04:14:18 +08:00
|
|
|
codec->control_data = ak4104->regmap;
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
/* set power-up and non-reset bits */
|
2013-03-07 05:22:15 +08:00
|
|
|
ret = regmap_update_bits(ak4104->regmap, AK4104_REG_CONTROL1,
|
|
|
|
AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN,
|
|
|
|
AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN);
|
2009-03-09 09:13:17 +08:00
|
|
|
if (ret < 0)
|
2010-03-18 04:15:21 +08:00
|
|
|
return ret;
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
/* enable transmitter */
|
2013-03-07 05:22:15 +08:00
|
|
|
ret = regmap_update_bits(ak4104->regmap, AK4104_REG_TX,
|
|
|
|
AK4104_TX_TXE, AK4104_TX_TXE);
|
2009-03-09 09:13:17 +08:00
|
|
|
if (ret < 0)
|
2010-03-18 04:15:21 +08:00
|
|
|
return ret;
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int ak4104_remove(struct snd_soc_codec *codec)
|
2009-03-09 09:13:17 +08:00
|
|
|
{
|
2013-03-07 05:22:15 +08:00
|
|
|
struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
regmap_update_bits(ak4104->regmap, AK4104_REG_CONTROL1,
|
|
|
|
AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN, 0);
|
2009-03-09 09:13:17 +08:00
|
|
|
|
2012-02-18 04:04:41 +08:00
|
|
|
return 0;
|
2009-03-09 09:13:17 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_codec_driver soc_codec_device_ak4104 = {
|
|
|
|
.probe = ak4104_probe,
|
|
|
|
.remove = ak4104_remove,
|
2013-08-08 02:01:40 +08:00
|
|
|
|
|
|
|
.dapm_widgets = ak4104_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(ak4104_dapm_widgets),
|
|
|
|
.dapm_routes = ak4104_dapm_routes,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(ak4104_dapm_routes),
|
2012-02-18 04:14:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_config ak4104_regmap = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
|
|
|
|
.max_register = AK4104_NUM_REGS - 1,
|
|
|
|
.read_flag_mask = AK4104_READ,
|
|
|
|
.write_flag_mask = AK4104_WRITE,
|
|
|
|
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
2010-03-18 04:15:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ak4104_spi_probe(struct spi_device *spi)
|
2009-03-09 09:13:17 +08:00
|
|
|
{
|
2012-11-14 18:28:39 +08:00
|
|
|
struct device_node *np = spi->dev.of_node;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct ak4104_private *ak4104;
|
2012-02-18 04:14:18 +08:00
|
|
|
unsigned int val;
|
2009-03-09 09:13:17 +08:00
|
|
|
int ret;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
spi->bits_per_word = 8;
|
|
|
|
spi->mode = SPI_MODE_0;
|
|
|
|
ret = spi_setup(spi);
|
|
|
|
if (ret < 0)
|
2009-03-09 09:13:17 +08:00
|
|
|
return ret;
|
|
|
|
|
2011-12-20 14:37:12 +08:00
|
|
|
ak4104 = devm_kzalloc(&spi->dev, sizeof(struct ak4104_private),
|
|
|
|
GFP_KERNEL);
|
2010-03-18 04:15:21 +08:00
|
|
|
if (ak4104 == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-11-22 12:08:36 +08:00
|
|
|
ak4104->regmap = devm_regmap_init_spi(spi, &ak4104_regmap);
|
2012-02-18 04:14:18 +08:00
|
|
|
if (IS_ERR(ak4104->regmap)) {
|
|
|
|
ret = PTR_ERR(ak4104->regmap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-14 18:28:39 +08:00
|
|
|
if (np) {
|
|
|
|
enum of_gpio_flags flags;
|
|
|
|
int gpio = of_get_named_gpio_flags(np, "reset-gpio", 0, &flags);
|
|
|
|
|
|
|
|
if (gpio_is_valid(gpio)) {
|
|
|
|
ret = devm_gpio_request_one(&spi->dev, gpio,
|
|
|
|
flags & OF_GPIO_ACTIVE_LOW ?
|
|
|
|
GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
|
|
|
|
"ak4104 reset");
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-18 04:14:18 +08:00
|
|
|
/* read the 'reserved' register - according to the datasheet, it
|
|
|
|
* should contain 0x5b. Not a good way to verify the presence of
|
|
|
|
* the device, but there is no hardware ID register. */
|
|
|
|
ret = regmap_read(ak4104->regmap, AK4104_REG_RESERVED, &val);
|
|
|
|
if (ret != 0)
|
2012-11-22 12:08:36 +08:00
|
|
|
return ret;
|
|
|
|
if (val != AK4104_RESERVED_VAL)
|
|
|
|
return -ENODEV;
|
2012-02-18 04:14:18 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
spi_set_drvdata(spi, ak4104);
|
|
|
|
|
|
|
|
ret = snd_soc_register_codec(&spi->dev,
|
|
|
|
&soc_codec_device_ak4104, &ak4104_dai, 1);
|
|
|
|
return ret;
|
2009-03-09 09:13:17 +08:00
|
|
|
}
|
|
|
|
|
2012-12-07 22:26:37 +08:00
|
|
|
static int ak4104_spi_remove(struct spi_device *spi)
|
2009-03-09 09:13:17 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_unregister_codec(&spi->dev);
|
2009-03-09 09:13:17 +08:00
|
|
|
return 0;
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
2009-03-09 09:13:17 +08:00
|
|
|
|
2012-10-07 23:51:24 +08:00
|
|
|
static const struct of_device_id ak4104_of_match[] = {
|
|
|
|
{ .compatible = "asahi-kasei,ak4104", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, ak4104_of_match);
|
|
|
|
|
2009-03-09 09:13:17 +08:00
|
|
|
static struct spi_driver ak4104_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
.owner = THIS_MODULE,
|
2012-10-07 23:51:24 +08:00
|
|
|
.of_match_table = ak4104_of_match,
|
2009-03-09 09:13:17 +08:00
|
|
|
},
|
|
|
|
.probe = ak4104_spi_probe,
|
2012-12-07 22:26:37 +08:00
|
|
|
.remove = ak4104_spi_remove,
|
2009-03-09 09:13:17 +08:00
|
|
|
};
|
|
|
|
|
2012-02-17 14:50:35 +08:00
|
|
|
module_spi_driver(ak4104_spi_driver);
|
2009-03-09 09:13:17 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
|
|
|
|
MODULE_DESCRIPTION("Asahi Kasei AK4104 ALSA SoC driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|