Commit 0c1c7337 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branch 'asoc/topic/ak4104' into asoc-next

parents 0bfbbc00 a273cd13
AK4104 S/PDIF transmitter
This device supports SPI mode only.
Required properties:
- compatible : "asahi-kasei,ak4104"
- reg : The chip select number on the SPI bus
Optional properties:
- reset-gpio : a GPIO spec for the reset pin. If specified, it will be
deasserted before communication to the device starts.
Example:
spdif: ak4104@0 {
compatible = "asahi-kasei,ak4104";
reg = <0>;
spi-max-frequency = <5000000>;
};
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <sound/soc.h> #include <sound/soc.h>
#include <sound/initval.h> #include <sound/initval.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <sound/asoundef.h> #include <sound/asoundef.h>
/* AK4104 registers addresses */ /* AK4104 registers addresses */
...@@ -98,14 +100,32 @@ static int ak4104_hw_params(struct snd_pcm_substream *substream, ...@@ -98,14 +100,32 @@ static int ak4104_hw_params(struct snd_pcm_substream *substream,
val = 0; val = 0;
switch (params_rate(params)) { switch (params_rate(params)) {
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;
case 44100: case 44100:
val |= IEC958_AES3_CON_FS_44100; val |= IEC958_AES3_CON_FS_44100;
break; break;
case 48000: case 48000:
val |= IEC958_AES3_CON_FS_48000; val |= IEC958_AES3_CON_FS_48000;
break; break;
case 32000: case 88200:
val |= IEC958_AES3_CON_FS_32000; 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;
break; break;
default: default:
dev_err(codec->dev, "unsupported sampling rate\n"); dev_err(codec->dev, "unsupported sampling rate\n");
...@@ -186,6 +206,7 @@ static const struct regmap_config ak4104_regmap = { ...@@ -186,6 +206,7 @@ static const struct regmap_config ak4104_regmap = {
static int ak4104_spi_probe(struct spi_device *spi) static int ak4104_spi_probe(struct spi_device *spi)
{ {
struct device_node *np = spi->dev.of_node;
struct ak4104_private *ak4104; struct ak4104_private *ak4104;
unsigned int val; unsigned int val;
int ret; int ret;
...@@ -201,49 +222,59 @@ static int ak4104_spi_probe(struct spi_device *spi) ...@@ -201,49 +222,59 @@ static int ak4104_spi_probe(struct spi_device *spi)
if (ak4104 == NULL) if (ak4104 == NULL)
return -ENOMEM; return -ENOMEM;
ak4104->regmap = regmap_init_spi(spi, &ak4104_regmap); ak4104->regmap = devm_regmap_init_spi(spi, &ak4104_regmap);
if (IS_ERR(ak4104->regmap)) { if (IS_ERR(ak4104->regmap)) {
ret = PTR_ERR(ak4104->regmap); ret = PTR_ERR(ak4104->regmap);
return ret; return ret;
} }
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;
}
}
/* read the 'reserved' register - according to the datasheet, it /* read the 'reserved' register - according to the datasheet, it
* should contain 0x5b. Not a good way to verify the presence of * should contain 0x5b. Not a good way to verify the presence of
* the device, but there is no hardware ID register. */ * the device, but there is no hardware ID register. */
ret = regmap_read(ak4104->regmap, AK4104_REG_RESERVED, &val); ret = regmap_read(ak4104->regmap, AK4104_REG_RESERVED, &val);
if (ret != 0) if (ret != 0)
goto err; return ret;
if (val != AK4104_RESERVED_VAL) { if (val != AK4104_RESERVED_VAL)
ret = -ENODEV; return -ENODEV;
goto err;
}
spi_set_drvdata(spi, ak4104); spi_set_drvdata(spi, ak4104);
ret = snd_soc_register_codec(&spi->dev, ret = snd_soc_register_codec(&spi->dev,
&soc_codec_device_ak4104, &ak4104_dai, 1); &soc_codec_device_ak4104, &ak4104_dai, 1);
if (ret != 0)
goto err;
return 0;
err:
regmap_exit(ak4104->regmap);
return ret; return ret;
} }
static int __devexit ak4104_spi_remove(struct spi_device *spi) 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); snd_soc_unregister_codec(&spi->dev);
return 0; return 0;
} }
static const struct of_device_id ak4104_of_match[] = {
{ .compatible = "asahi-kasei,ak4104", },
{ }
};
MODULE_DEVICE_TABLE(of, ak4104_of_match);
static struct spi_driver ak4104_spi_driver = { static struct spi_driver ak4104_spi_driver = {
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = ak4104_of_match,
}, },
.probe = ak4104_spi_probe, .probe = ak4104_spi_probe,
.remove = __devexit_p(ak4104_spi_remove), .remove = __devexit_p(ak4104_spi_remove),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment