Modified: trunk/sound/soc/codecs/ad1938.c (6605 => 6606)
--- trunk/sound/soc/codecs/ad1938.c 2009-06-07 21:24:10 UTC (rev 6605)
+++ trunk/sound/soc/codecs/ad1938.c 2009-06-08 08:56:28 UTC (rev 6606)
@@ -22,9 +22,8 @@
#include <sound/pcm.h>
#include <sound/initval.h>
#include <sound/soc.h>
-
+#include <linux/spi/spi.h>
#include "ad1938.h"
-#include "ad1938_spi.h"
struct snd_soc_dai ad1938_dai = {
.name = "AD1938",
@@ -43,18 +42,137 @@
};
EXPORT_SYMBOL_GPL(ad1938_dai);
+struct snd_soc_device *ad1938_socdev;
+
+/* DAC volume controls */
+static const struct snd_kcontrol_new ad1938_snd_controls[] = {
+ SOC_SINGLE("DAC L1", AD1938_DAC_L1_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC R1", AD1938_DAC_R1_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC L2", AD1938_DAC_L2_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC R2", AD1938_DAC_R2_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC L3", AD1938_DAC_L3_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC R3", AD1938_DAC_R3_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC L4", AD1938_DAC_L4_VOL, 0, 0xFF, 1),
+ SOC_SINGLE("DAC R4", AD1938_DAC_R4_VOL, 0, 0xFF, 1),
+};
+
+/* add non dapm controls */
+static int ad1938_add_controls(struct snd_soc_codec *codec)
+{
+ int err, i;
+
+ for (i = 0; i < ARRAY_SIZE(ad1938_snd_controls); i++) {
+ err = snd_ctl_add(codec->card,
+ snd_soc_cnew(&ad1938_snd_controls[i], codec, NULL));
+ if (err < 0)
+ return err;
+ }
+
+ return 0;
+}
+
+
+/*
+ * interface to read/write ad1938 register
+ */
+
+#define AD1938_SPI_ADDR 0x4
+#define AD1938_SPI_READ 0x1
+#define AD1938_SPI_BUFLEN 3
+
+/*
+ * write to the ad1938 register space
+ */
+
+static int ad1938_reg_write(struct snd_soc_codec *codec, unsigned int reg,
+ unsigned int value)
+{
+ uint8_t buf[AD1938_SPI_BUFLEN];
+ struct spi_transfer t = {
+ .tx_buf = buf,
+ .len = AD1938_SPI_BUFLEN,
+ };
+ struct spi_message m;
+
+ buf[0] = AD1938_SPI_ADDR << 1;
+ buf[1] = reg;
+ buf[2] = value;
+ spi_message_init(&m);
+ spi_message_add_tail(&t, &m);
+
+ return spi_sync(codec->control_data, &m);
+}
+
+/*
+ * read from the ad1938 register space
+ */
+
+static unsigned int ad1938_reg_read(struct snd_soc_codec *codec, unsigned int reg)
+{
+ char w_buf[AD1938_SPI_BUFLEN];
+ char r_buf[AD1938_SPI_BUFLEN];
+ int ret;
+
+ struct spi_transfer t = {
+ .tx_buf = w_buf,
+ .rx_buf = r_buf,
+ .len = AD1938_SPI_BUFLEN,
+ };
+ struct spi_message m;
+
+ w_buf[0] = (AD1938_SPI_ADDR << 1) | AD1938_SPI_READ;
+ w_buf[1] = reg;
+ w_buf[2] = 0;
+
+ spi_message_init(&m);
+ spi_message_add_tail(&t, &m);
+ ret = spi_sync(codec->control_data, &m);
+ if (ret == 0)
+ return r_buf[2];
+ else
+ return -EIO;
+}
+
+static int __devinit ad1938_spi_probe(struct spi_device *spi)
+{
+ spi->dev.power.power_state = PMSG_ON;
+ ad1938_socdev->codec->control_data = spi;
+
+ return 0;
+}
+
+static int __devexit ad1938_spi_remove(struct spi_device *spi)
+{
+ return 0;
+}
+
+static struct spi_driver ad1938_spi_driver = {
+ .driver = {
+ .name = "ad1938-spi",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+ .probe = ad1938_spi_probe,
+ .remove = __devexit_p(ad1938_spi_remove),
+};
+
+static int ad1938_spi_init(void)
+{
+ return spi_register_driver(&ad1938_spi_driver);
+}
+
+static void ad1938_spi_done(void)
+{
+ spi_unregister_driver(&ad1938_spi_driver);
+}
+
static int ad1938_soc_probe(struct platform_device *pdev)
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec;
int ret = 0;
- ret = ad1938_spi_init();
- if (ret < 0) {
- printk(KERN_ERR "ad1938: failed to init spi interface\n");
- goto spi_err;
- }
-
+ /* codec alloc and init */
codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
if (codec == NULL)
return -ENOMEM;
@@ -63,10 +181,21 @@
codec->owner = THIS_MODULE;
codec->dai = &ad1938_dai;
codec->num_dai = 1;
+ codec->write = ad1938_reg_write;
+ codec->read = ad1938_reg_read;
socdev->codec = codec;
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);
+ ad1938_socdev = socdev;
+
+ /* codec spi interface init */
+ ret = ad1938_spi_init();
+ if (ret < 0) {
+ printk(KERN_ERR "ad1938: failed to init spi interface\n");
+ goto spi_err;
+ }
+
/* register pcms */
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
if (ret < 0) {
@@ -81,23 +210,27 @@
}
/* default setting for ad1938: 8 channel AUX ADC mode, 16bit, 48000Hz */
- ad1938_spi_write(AD1938_DAC_CTRL0, 0x40);
- ad1938_spi_write(AD1938_DAC_CTRL1, 0x84);
- ad1938_spi_write(AD1938_DAC_CTRL2, 0x1A);
- ad1938_spi_write(AD1938_ADC_CTRL0, 0x32);
- ad1938_spi_write(AD1938_ADC_CTRL1, 0x43);
- ad1938_spi_write(AD1938_ADC_CTRL2, 0x6f);
- ad1938_spi_write(AD1938_PLL_CLK_CTRL0, 0x9C);
- ad1938_spi_write(AD1938_PLL_CLK_CTRL1, 0x04);
+ codec->write(codec, AD1938_DAC_CTRL0, 0x40);
+ codec->write(codec, AD1938_DAC_CTRL1, 0x84);
+ codec->write(codec, AD1938_DAC_CTRL2, 0x1A);
+ codec->write(codec, AD1938_ADC_CTRL0, 0x32);
+ codec->write(codec, AD1938_ADC_CTRL1, 0x43);
+ codec->write(codec, AD1938_ADC_CTRL2, 0x6f);
+ codec->write(codec, AD1938_PLL_CLK_CTRL0, 0x9C);
+ codec->write(codec, AD1938_PLL_CLK_CTRL1, 0x04);
+ /* register controls for ad1938 */
+ ad1938_add_controls(codec);
+
return ret;
register_err:
snd_soc_free_pcms(socdev);
pcm_err:
+ ad1938_spi_done();
+spi_err:
kfree(socdev->codec);
socdev->codec = NULL;
-spi_err:
return ret;
}
Deleted: trunk/sound/soc/codecs/ad1938_spi.c (6605 => 6606)
--- trunk/sound/soc/codecs/ad1938_spi.c 2009-06-07 21:24:10 UTC (rev 6605)
+++ trunk/sound/soc/codecs/ad1938_spi.c 2009-06-08 08:56:28 UTC (rev 6606)
@@ -1,124 +0,0 @@
-/*
- * File: sound/blackfin/ad1938_spi.c
- * Based on:
- * Author: Barry Song
- *
- * Created:
- * Description: AD1938 SPI driver
- *
- * Modified:
- * Copyright 2009 Analog Devices Inc.
- *
- * Bugs: Enter bugs at http://blackfin.uclinux.org/
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see the file COPYING, or write
- * to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <linux/device.h>
-#include <linux/init.h>
-#include <linux/spi/spi.h>
-
-#include "ad1938_spi.h"
-
-#define SPI_ADDR 0x4
-#define SPI_READ 0x1
-
-struct spi_device *ad1938_spi_dev;
-
-int ad1938_spi_read(uint8_t reg, uint8_t *val)
-{
- uint8_t w_buf[3], r_buf[3];
- int ret;
-
- struct spi_transfer t = {
- .tx_buf = w_buf,
- .rx_buf = r_buf,
- .len = 3,
- };
- struct spi_message m;
-
- w_buf[0] = (SPI_ADDR << 1) | SPI_READ;
- w_buf[1] = reg;
- w_buf[2] = 0;
- r_buf[0] = r_buf[1] = r_buf[2] = 0;
-
- spi_message_init(&m);
- spi_message_add_tail(&t, &m);
- ret = spi_sync(ad1938_spi_dev, &m);
-
- if (ret == 0)
- *val = r_buf[2];
-
- return ret;
-}
-
-
-int ad1938_spi_write(uint8_t reg, uint8_t val)
-{
- uint8_t buf[3];
-
- struct spi_transfer t = {
- .tx_buf = buf,
- .len = 3,
- };
- struct spi_message m;
-
- buf[0] = SPI_ADDR << 1;
- buf[1] = reg;
- buf[2] = val;
- spi_message_init(&m);
- spi_message_add_tail(&t, &m);
-
- return spi_sync(ad1938_spi_dev, &m);
-}
-
-int snd_ad1938_spi_probed(void)
-{
- return 0;
-}
-
-static int __devinit ad1938_spi_probe(struct spi_device *spi)
-{
- spi->dev.power.power_state = PMSG_ON;
- ad1938_spi_dev = spi;
-
- return snd_ad1938_spi_probed();
-}
-
-static int __devexit ad1938_spi_remove(struct spi_device *spi)
-{
- return 0;
-}
-
-static struct spi_driver ad1938_spi_driver = {
- .driver = {
- .name = "ad1938-spi",
- .bus = &spi_bus_type,
- .owner = THIS_MODULE,
- },
- .probe = ad1938_spi_probe,
- .remove = __devexit_p(ad1938_spi_remove),
-};
-
-int ad1938_spi_init(void)
-{
- return spi_register_driver(&ad1938_spi_driver);
-}
-
-void ad1938_spi_done(void)
-{
- spi_unregister_driver(&ad1938_spi_driver);
-}
Deleted: trunk/sound/soc/codecs/ad1938_spi.h (6605 => 6606)
--- trunk/sound/soc/codecs/ad1938_spi.h 2009-06-07 21:24:10 UTC (rev 6605)
+++ trunk/sound/soc/codecs/ad1938_spi.h 2009-06-08 08:56:28 UTC (rev 6606)
@@ -1,42 +0,0 @@
-/*
- * File: sound/blackfin/ad1938_spi.h
- * Based on:
- * Author: Barry Song
- *
- * Created: 2009-05-22
- * Description: ad1938 spi driver.
- *
- * Modified:
- * Copyright 2009 Analog Devices Inc.
- *
- * Bugs: Enter bugs at http://blackfin.uclinux.org/
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see the file COPYING, or write
- * to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef __AD1938_SPI_H__
-#define __AD1938_SPI_H__
-
-
-int ad1938_spi_init(void);
-
-void ad1938_spi_done(void);
-
-int ad1938_spi_read(uint8_t reg, uint8_t *val);
-
-int ad1938_spi_write(uint8_t reg, uint8_t val);
-
-#endif