Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 293411
b: refs/heads/master
c: 2901d6e
h: refs/heads/master
i:
  293409: 9bd4c8c
  293407: f54cd5f
v: v3
  • Loading branch information
Mark Brown committed Feb 23, 2012
1 parent 6b3928c commit 945a290
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 76 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 34baf2202059a7a7624aa02a104b64a9134aa885
refs/heads/master: 2901d6ebe1f9da781a5bbb64d7c2a46c4b8e7364
119 changes: 44 additions & 75 deletions trunk/sound/soc/codecs/ak4104.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,69 +46,15 @@
#define DRV_NAME "ak4104-codec"

struct ak4104_private {
enum snd_soc_control_type control_type;
void *control_data;
struct regmap *regmap;
};

static int ak4104_fill_cache(struct snd_soc_codec *codec)
{
int i;
u8 *reg_cache = codec->reg_cache;
struct spi_device *spi = codec->control_data;

for (i = 0; i < codec->driver->reg_cache_size; i++) {
int ret = spi_w8r8(spi, i | AK4104_READ);
if (ret < 0) {
dev_err(&spi->dev, "SPI write failure\n");
return ret;
}

reg_cache[i] = ret;
}

return 0;
}

static unsigned int ak4104_read_reg_cache(struct snd_soc_codec *codec,
unsigned int reg)
{
u8 *reg_cache = codec->reg_cache;

if (reg >= codec->driver->reg_cache_size)
return -EINVAL;

return reg_cache[reg];
}

static int ak4104_spi_write(struct snd_soc_codec *codec, unsigned int reg,
unsigned int value)
{
u8 *cache = codec->reg_cache;
struct spi_device *spi = codec->control_data;

if (reg >= codec->driver->reg_cache_size)
return -EINVAL;

/* only write to the hardware if value has changed */
if (cache[reg] != value) {
u8 tmp[2] = { (reg & AK4104_REG_MASK) | AK4104_WRITE, value };

if (spi_write(spi, tmp, sizeof(tmp))) {
dev_err(&spi->dev, "SPI write failed\n");
return -EIO;
}

cache[reg] = value;
}

return 0;
}

static int ak4104_set_dai_fmt(struct snd_soc_dai *codec_dai,
unsigned int format)
{
struct snd_soc_codec *codec = codec_dai->codec;
int val = 0;
int ret;

/* set DAI format */
switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
Expand Down Expand Up @@ -192,23 +138,12 @@ static struct snd_soc_dai_driver ak4104_dai = {
static int ak4104_probe(struct snd_soc_codec *codec)
{
struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
int ret, val;

codec->control_data = ak4104->control_data;
int ret;

/* read all regs and fill the cache */
ret = ak4104_fill_cache(codec);
if (ret < 0) {
dev_err(codec->dev, "failed to fill register cache\n");
codec->control_data = ak4104->regmap;
ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
if (ret != 0)
return ret;
}

/* 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. */
if (ak4104_read_reg_cache(codec, AK4104_REG_RESERVED) !=
AK4104_RESERVED_VAL)
return -ENODEV;

/* set power-up and non-reset bits */
ret = snd_soc_update_bits(codec, AK4104_REG_CONTROL1,
Expand Down Expand Up @@ -237,13 +172,23 @@ static int ak4104_remove(struct snd_soc_codec *codec)
static struct snd_soc_codec_driver soc_codec_device_ak4104 = {
.probe = ak4104_probe,
.remove = ak4104_remove,
.reg_cache_size = AK4104_NUM_REGS,
.reg_word_size = sizeof(u8),
};

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,
};

static int ak4104_spi_probe(struct spi_device *spi)
{
struct ak4104_private *ak4104;
unsigned int val;
int ret;

spi->bits_per_word = 8;
Expand All @@ -257,17 +202,41 @@ static int ak4104_spi_probe(struct spi_device *spi)
if (ak4104 == NULL)
return -ENOMEM;

ak4104->control_data = spi;
ak4104->control_type = SND_SOC_SPI;
ak4104->regmap = regmap_init_spi(spi, &ak4104_regmap);
if (IS_ERR(ak4104->regmap)) {
ret = PTR_ERR(ak4104->regmap);
return ret;
}

/* 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)
goto err;
if (val != AK4104_RESERVED_VAL) {
ret = -ENODEV;
goto err;
}

spi_set_drvdata(spi, ak4104);

ret = snd_soc_register_codec(&spi->dev,
&soc_codec_device_ak4104, &ak4104_dai, 1);
if (ret != 0)
goto err;

return 0;

err:
regmap_exit(ak4104->regmap);
return ret;
}

static int __devexit ak4104_spi_remove(struct spi_device *spi)
{
struct ak4104_private *ak4101 = spi_get_drvdata(spi);
regmap_exit(ak4101->regmap);
snd_soc_unregister_codec(&spi->dev);
return 0;
}
Expand Down

0 comments on commit 945a290

Please sign in to comment.