Alsa-devel
Threads by month
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
July 2007
- 109 participants
- 155 discussions
[alsa-devel] [RFC][PATCH] Get rid of dead code in sound/pci/ac97/ac97_patch.c
by Michal Piotrowski 01 Aug '07
by Michal Piotrowski 01 Aug '07
01 Aug '07
Hi,
File /home/devel/linux-rdc/sound/pci/ac97/ac97_patch.c line 484
Unknown CONFIG option! CONFIG_TOUCHSCREEN_WM9705
Regards,
Michal
--
LOG
http://www.stardust.webpages.pl/log/
Signed-off-by: Michal Piotrowski <michal.k.k.piotrowski(a)gmail.com>
--- linux-rdc-clean/sound/pci/ac97/ac97_patch.c 2007-07-09 01:32:17.000000000 +0200
+++ linux-rdc/sound/pci/ac97/ac97_patch.c 2007-07-31 17:26:32.000000000 +0200
@@ -481,10 +481,7 @@ static int patch_wolfson05(struct snd_ac
{
/* WM9705, WM9710 */
ac97->build_ops = &patch_wolfson_wm9705_ops;
-#ifdef CONFIG_TOUCHSCREEN_WM9705
- /* WM9705 touchscreen uses AUX and VIDEO for touch */
- ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
-#endif
+
return 0;
}
2
1
This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The
following features are suppored:
1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management
Signed-off-by: Timur Tabi <timur(a)freescale.com>
---
This code is based on git.kernel.org/pub/scm/linux/kernel/git/perex/alsa.git.
include/linux/i2c-id.h | 1 +
sound/soc/codecs/Kconfig | 20 ++
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/cs4270.c | 808 +++++++++++++++++++++++++++++++++++++++++++++
sound/soc/codecs/cs4270.h | 28 ++
5 files changed, 859 insertions(+), 0 deletions(-)
create mode 100644 sound/soc/codecs/cs4270.c
create mode 100644 sound/soc/codecs/cs4270.h
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index b690148..c4aadc6 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -119,6 +119,7 @@
#define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */
#define I2C_DRIVERID_WM8753 91 /* Wolfson WM8753 audio codec */
#define I2C_DRIVERID_LM4857 92 /* LM4857 Audio Amplifier */
+#define I2C_DRIVERID_CS4270 93 /* Cirrus Logic 4270 audio codec */
#define I2C_DRIVERID_I2CDEV 900
#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index e5fb437..7824880 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -17,3 +17,23 @@ config SND_SOC_WM8753
config SND_SOC_WM9712
tristate
depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+ tristate
+ depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+ bool
+ depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+ bool
+ depends on SND_SOC_CS4270
+
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index e39a747..7ad78e3 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -3,9 +3,11 @@ snd-soc-wm8731-objs := wm8731.o
snd-soc-wm8750-objs := wm8750.o
snd-soc-wm8753-objs := wm8753.o
snd-soc-wm9712-objs := wm9712.o
+snd-soc-cs4270-objs := cs4270.o
obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o
obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
+obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
new file mode 100644
index 0000000..b659a5d
--- /dev/null
+++ b/sound/soc/codecs/cs4270.c
@@ -0,0 +1,808 @@
+/*
+ * CS4270 ALSA SoC (ASoC) codec driver
+ *
+ * Author: Timur Tabi <timur(a)freescale.com>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ *
+ * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
+ *
+ * Current features/limitations:
+ *
+ * 1) Stand-alone and software mode is supported. Stand-alone is
+ * automatically selected if I2C is disabled or if a CS4270 is not found
+ * on the I2C bus.
+ * 2) Only I2C is supported, not SPI
+ * 3) Only Master mode is supported, not Slave.
+ * 4) The machine driver's 'startup' function must call
+ * cs4270_set_dai_sysclk() with the value of MCLK.
+ * 5) Only I2S and left-justified modes are supported
+ * 6) Power management is not supported
+ * 7) The only supported control is volume and hardware mute (if enabled)
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/soc.h>
+#include <sound/initval.h>
+#include <linux/i2c.h>
+
+#include "cs4270.h"
+
+/* Private data for the CS4270 */
+struct cs4270_private {
+ unsigned int mclk; /* Input frequency of the MCLK pin */
+ unsigned int mode; /* The mode (I2S or left-justified) */
+};
+
+/*
+ * The codec isn't really big-endian or little-endian, since the I2S
+ * interface requires data to be sent serially with the MSbit first.
+ * However, to support BE and LE I2S devices, we specify both here. That
+ * way, ALSA will always match the bit patterns.
+ */
+#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
+ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
+ SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
+ SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
+ SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
+ SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
+
+#ifdef CONFIG_I2C
+
+/* CS4270 registers addresses */
+#define CS4270_CHIPID 0x01 /* Chip ID */
+#define CS4270_PWRCTL 0x02 /* Power Control */
+#define CS4270_MODE 0x03 /* Mode Control */
+#define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */
+#define CS4270_TRANS 0x05 /* Transition Control */
+#define CS4270_MUTE 0x06 /* Mute Control */
+#define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */
+#define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */
+
+#define CS4270_FIRSTREG 0x01
+#define CS4270_LASTREG 0x08
+#define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
+
+/* Bit masks for the CS4270 registers */
+#define CS4270_CHIPID_ID 0xF0
+#define CS4270_CHIPID_REV 0x0F
+#define CS4270_PWRCTL_FREEZE 0x80
+#define CS4270_PWRCTL_PDN_ADC 0x20
+#define CS4270_PWRCTL_PDN_DAC 0x02
+#define CS4270_PWRCTL_PDN 0x01
+#define CS4270_MODE_SPEED_MASK 0x30
+#define CS4270_MODE_1X 0x00
+#define CS4270_MODE_2X 0x10
+#define CS4270_MODE_4X 0x20
+#define CS4270_MODE_SLAVE 0x30
+#define CS4270_MODE_DIV_MASK 0x0E
+#define CS4270_MODE_DIV1 0x00
+#define CS4270_MODE_DIV15 0x02
+#define CS4270_MODE_DIV2 0x04
+#define CS4270_MODE_DIV3 0x06
+#define CS4270_MODE_DIV4 0x08
+#define CS4270_MODE_POPGUARD 0x01
+#define CS4270_FORMAT_FREEZE_A 0x80
+#define CS4270_FORMAT_FREEZE_B 0x40
+#define CS4270_FORMAT_LOOPBACK 0x20
+#define CS4270_FORMAT_DAC_MASK 0x18
+#define CS4270_FORMAT_DAC_LJ 0x00
+#define CS4270_FORMAT_DAC_I2S 0x08
+#define CS4270_FORMAT_DAC_RJ16 0x18
+#define CS4270_FORMAT_DAC_RJ24 0x10
+#define CS4270_FORMAT_ADC_MASK 0x01
+#define CS4270_FORMAT_ADC_LJ 0x00
+#define CS4270_FORMAT_ADC_I2S 0x01
+#define CS4270_TRANS_ONE_VOL 0x80
+#define CS4270_TRANS_SOFT 0x40
+#define CS4270_TRANS_ZERO 0x20
+#define CS4270_TRANS_INV_ADC_A 0x08
+#define CS4270_TRANS_INV_ADC_B 0x10
+#define CS4270_TRANS_INV_DAC_A 0x02
+#define CS4270_TRANS_INV_DAC_B 0x04
+#define CS4270_TRANS_DEEMPH 0x01
+#define CS4270_MUTE_AUTO 0x20
+#define CS4270_MUTE_ADC_A 0x08
+#define CS4270_MUTE_ADC_B 0x10
+#define CS4270_MUTE_POLARITY 0x04
+#define CS4270_MUTE_DAC_A 0x01
+#define CS4270_MUTE_DAC_B 0x02
+
+/*
+ * A list of addresses on which this CS4270 could use. I2C addresses are
+ * 7 bits. For the CS4270, the upper four bits are always 1001, and the
+ * lower three bits are determined via the AD2, AD1, and AD0 pins
+ * (respectively).
+ */
+static unsigned short normal_i2c[] = {
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END
+};
+I2C_CLIENT_INSMOD;
+
+/*
+ * Pre-fill the CS4270 register cache.
+ *
+ * We use the auto-increment feature of the CS4270 to read all registers in
+ * one shot.
+ */
+static int cs4270_fill_cache(struct snd_soc_codec *codec)
+{
+ u8 *cache = codec->reg_cache;
+ struct i2c_client *i2c_client = codec->control_data;
+ s32 length;
+
+ length = i2c_smbus_read_i2c_block_data(i2c_client,
+ CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);
+
+ if (length != CS4270_NUMREGS) {
+ printk(KERN_ERR "cs4270: I2C read failure, addr=%u\n",
+ i2c_client->addr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+/*
+ * Read from the CS4270 register cache.
+ *
+ * This CS4270 registers are cached to avoid excessive I2C I/O operations.
+ * After the initial read to pre-fill the cache, the CS4270 never updates
+ * the register values, so we won't have a cache coherncy problem.
+ */
+static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
+ unsigned int reg)
+{
+ u8 *cache = codec->reg_cache;
+
+ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
+ return -EIO;
+
+ return cache[reg - CS4270_FIRSTREG];
+}
+
+/*
+ * Write to a CS4270 register via the I2C bus.
+ *
+ * This function writes the given value to the given CS4270 register, and
+ * also updates the register cache.
+ *
+ * Note that we don't use the hw_write function pointer of snd_soc_codec.
+ * That's because it's too clunky: the hw_write_t prototype does not match
+ * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
+ */
+static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
+ unsigned int value)
+{
+ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
+ return -EIO;
+
+ if (i2c_smbus_write_byte_data(codec->control_data, reg, value) == 0) {
+ /* We've written to the hardware, so update the cache */
+ u8 *cache = codec->reg_cache;
+ cache[reg - CS4270_FIRSTREG] = value;
+ return 0;
+ } else {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return -EIO;
+ }
+}
+
+/*
+ * Clock Ratio Selection for Master Mode.
+ *
+ * The data for this chart is taken from Table 5 of the CS4270 reference
+ * manual.
+ *
+ * This table is used to determine how to program the Mode Control register.
+ * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
+ * rates the CS4270 currently supports.
+ *
+ * 'ratio' is the MCLK/LRCK ratio. MCLK is usually a fixed input frequency,
+ * and LRCK is equal to the sampling rate. The CS4270 only supports sampling
+ * rates where this ratio is one of: 64, 96, 128, 192, 256, 384, 512, 768 or
+ * 1024.
+ *
+ * 'speed_mode' is the corresponding bit pattern to be written to the
+ * MODE bits of the Mode Control Register
+ *
+ * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of
+ * the Mode Control Register.
+ *
+ * In situations where a single ratio is represented by multiple speed
+ * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
+ * double-speed instead of quad-speed. However, the CS4270 errata states
+ * that Divide-By-1.5 can cause failures, so we avoid that mode where
+ * possible.
+ *
+ * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not
+ * work if VD = 3.3V. If this effects you, select the
+ * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
+ * never select any sample rates that require divide-by-1.5.
+ */
+static struct {
+ unsigned int ratio;
+ u8 speed_mode;
+ u8 mclk;
+} cs4270_mode_ratios[] = {
+ {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
+#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
+ {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
+#endif
+ {128, CS4270_MODE_2X, CS4270_MODE_DIV1},
+ {192, CS4270_MODE_4X, CS4270_MODE_DIV3},
+ {256, CS4270_MODE_1X, CS4270_MODE_DIV1},
+ {384, CS4270_MODE_2X, CS4270_MODE_DIV3},
+ {512, CS4270_MODE_1X, CS4270_MODE_DIV2},
+ {768, CS4270_MODE_1X, CS4270_MODE_DIV3},
+ {1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
+};
+
+/*
+ * Program the CS4270 with the given hardware parameters.
+ *
+ * The .dai_ops functions are used to provide board-specific data, like
+ * input frequencies, to this driver. This function takes that information,
+ * combines it with the hardware parameters provided, and programs the
+ * hardware accordingly.
+ */
+static int cs4270_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_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ unsigned int ret = 0;
+ unsigned int i;
+ unsigned int rate;
+ unsigned int ratio;
+ int reg;
+
+ /* Figure out which MCLK/LRCK ratio to use */
+
+ rate = params_rate(params); /* Sampling rate, in Hz */
+ ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_mode_ratios); i++) {
+ if (cs4270_mode_ratios[i].ratio == ratio)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(cs4270_mode_ratios)) {
+ /* We did not find a matching ratio */
+ printk(KERN_ERR "cs4270: could not find matching ratio\n");
+ return -EINVAL;
+ }
+
+ /* Freeze and power-down the codec */
+
+ ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE |
+ CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC |
+ CS4270_PWRCTL_PDN);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Program the mode control register */
+
+ reg = snd_soc_read(codec, CS4270_MODE);
+ reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
+ reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk;
+
+ ret = snd_soc_write(codec, CS4270_MODE, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Program the format register */
+
+ reg = snd_soc_read(codec, CS4270_FORMAT);
+ reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
+
+ switch (cs4270->mode) {
+ case SND_SOC_DAIFMT_I2S:
+ reg |= CS4270_FORMAT_DAC_I2S | CS4270_FORMAT_ADC_I2S;
+ break;
+ case SND_SOC_DAIFMT_LEFT_J:
+ reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
+ break;
+ default:
+ printk(KERN_ERR "cs4270: unknown format\n");
+ return -EINVAL;
+ }
+
+ ret = snd_soc_write(codec, CS4270_FORMAT, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Disable auto-mute. This feature appears to be buggy, because in
+ some situations, auto-mute will not deactivate when it should. */
+
+ reg = snd_soc_read(codec, CS4270_MUTE);
+ reg &= ~CS4270_MUTE_AUTO;
+ ret = snd_soc_write(codec, CS4270_MUTE, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Thaw and power-up the codec */
+
+ ret = snd_soc_write(codec, CS4270_PWRCTL, 0);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
+
+/*
+ * Set the CS4270 external mute
+ *
+ * This function toggles the mute bits in the MUTE register. The CS4270's
+ * mute capability is intended for external muting circuitry, so if the
+ * board does not have the MUTEA or MUTEB pins connected to such circuitry,
+ * then this function will do nothing.
+ */
+static int cs4270_mute(struct snd_soc_codec_dai *dai, int mute)
+{
+ struct snd_soc_codec *codec = dai->codec;
+ int reg6;
+
+ reg6 = snd_soc_read(codec, CS4270_MUTE);
+
+ if (mute)
+ reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
+ CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
+ else
+ reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
+ CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
+
+ return snd_soc_write(codec, CS4270_MUTE, reg6);
+}
+
+#endif
+
+/*
+ * Sampling rate <-> bit patter mapping
+ *
+ * This array maps sampling rates to their SNDRV_PCM_RATE_x equivalent.
+ *
+ * This is really something that ALSA should provide.
+ *
+ * This table is used by cs4270_set_dai_sysclk() to tell ALSA which sampling
+ * rates the CS4270 currently supports.
+ */
+static struct {
+ unsigned int rate;
+ unsigned int bit;
+} rate_map[] = {
+ {5512, SNDRV_PCM_RATE_5512},
+ {8000, SNDRV_PCM_RATE_8000},
+ {11025, SNDRV_PCM_RATE_11025},
+ {16000, SNDRV_PCM_RATE_16000},
+ {22050, SNDRV_PCM_RATE_22050},
+ {32000, SNDRV_PCM_RATE_32000},
+ {44100, SNDRV_PCM_RATE_44100},
+ {48000, SNDRV_PCM_RATE_48000},
+ {64000, SNDRV_PCM_RATE_64000},
+ {88200, SNDRV_PCM_RATE_88200},
+ {96000, SNDRV_PCM_RATE_96000},
+ {176400, SNDRV_PCM_RATE_176400},
+ {192000, SNDRV_PCM_RATE_192000}
+};
+
+/*
+ * Determine the CS4270 samples rates.
+ *
+ * 'freq' is the input frequency to MCLK. The other parameters are ignored.
+ *
+ * The value of MCLK is used to determine which sample rates are supported
+ * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
+ * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
+ *
+ * This function calculates the nine ratios and determines which ones match
+ * a standard sample rate. If there's a match, then it is added to the list
+ * of support sample rates.
+ *
+ * This function must be called by the machine driver's 'startup' function,
+ * otherwise the list of supported sample rates will not be available in
+ * time for ALSA.
+ */
+static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+ int clk_id, unsigned int freq, int dir)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ unsigned int rates = 0;
+ unsigned int rate_min = -1;
+ unsigned int rate_max = 0;
+ unsigned int i;
+
+ cs4270->mclk = freq;
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_mode_ratios); i++) {
+ unsigned int rate;
+ unsigned int j;
+ rate = freq / cs4270_mode_ratios[i].ratio;
+ for (j = 0; j < ARRAY_SIZE(rate_map); j++) {
+ if (rate == rate_map[j].rate) {
+ rates |= rate_map[j].bit;
+ if (rate < rate_min)
+ rate_min = rate;
+ if (rate > rate_max)
+ rate_max = rate;
+ }
+ }
+ }
+
+ if (!rate_max) {
+ printk(KERN_ERR "cs4270: could not find a valid rate\n");
+ return -EINVAL;
+ }
+
+ codec_dai->playback.rates = rates;
+ codec_dai->playback.rate_min = rate_min;
+ codec_dai->playback.rate_max = rate_max;
+
+ codec_dai->capture.rates = rates;
+ codec_dai->capture.rate_min = rate_min;
+ codec_dai->capture.rate_max = rate_max;
+
+ return 0;
+}
+
+/*
+ * Configure the codec for the selected audio format
+ *
+ * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
+ * codec accordingly.
+ *
+ * Currently, this function only supports SND_SOC_DAIFMT_I2S and
+ * SND_SOC_DAIFMT_LEFT_J. The CS4270 codec also supports right-justified
+ * data for playback only, but ASoC currently does not support different
+ * formats for playback vs. record.
+ */
+static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+ unsigned int format)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ int ret = 0;
+
+ switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
+ case SND_SOC_DAIFMT_I2S:
+ case SND_SOC_DAIFMT_LEFT_J:
+ cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
+ break;
+ default:
+ printk(KERN_ERR "cs4270: invalid DAI format\n");
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static int cs4270_i2c_probe(struct i2c_adapter *adap, int addr, int kind);
+
+/*
+ * Notify the driver that a new I2C bus has been found.
+ *
+ * This function is called for each I2C bus in the system. The function
+ * then asks the I2C subsystem to probe that bus at the addresses on which
+ * our device (the CS4270) could exist. If a device is found at one of
+ * those addresses, then our probe function (cs4270_i2c_probe) is called.
+ */
+static int cs4270_i2c_attach(struct i2c_adapter *adapter)
+{
+ return i2c_probe(adapter, &addr_data, cs4270_i2c_probe);
+}
+
+static int cs4270_i2c_detach(struct i2c_client *client)
+{
+ struct snd_soc_codec *codec = i2c_get_clientdata(client);
+
+ i2c_detach_client(client);
+ codec->control_data = NULL;
+
+ kfree(codec->reg_cache);
+ codec->reg_cache = NULL;
+
+ kfree(client);
+ return 0;
+}
+
+/* A list of non-DAPM controls that the CS4270 supports */
+static const struct snd_kcontrol_new cs4270_snd_controls[] = {
+ SOC_DOUBLE_R("Master Playback Volume",
+ CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 0)
+};
+
+static struct i2c_driver cs4270_i2c_driver = {
+ .driver = {
+ .name = "CS4270 I2C",
+ .owner = THIS_MODULE,
+ },
+ .id = I2C_DRIVERID_CS4270,
+ .attach_adapter = cs4270_i2c_attach,
+ .detach_client = cs4270_i2c_detach,
+};
+
+/*
+ * Global variable to store socdev for i2c probe function.
+ *
+ * If struct i2c_driver had a private_data field, we wouldn't need to use
+ * cs4270_socdec. This is the only way to pass the socdev structure to
+ * cs4270_i2c_probe().
+ *
+ * The real solution to cs4270_socdev is to create a mechanism
+ * that maps I2C addresses to snd_soc_device structures. Perhaps the
+ * creation of the snd_soc_device object should be moved out of
+ * cs4270_probe() and into cs4270_i2c_probe(), but that would make this
+ * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby
+ * the chip is *not* connected to the I2C bus, but is instead configured via
+ * input pins.
+ */
+static struct snd_soc_device *cs4270_socdev;
+
+/*
+ * Initialize the I2C interface of the CS4270
+ *
+ * This function is called for whenever the I2C subsystem finds a device
+ * at a particular address.
+ *
+ * Note: snd_soc_new_pcms() must be called before this function can be called,
+ * because of snd_ctl_add().
+ */
+static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind)
+{
+ struct snd_soc_device *socdev = cs4270_socdev;
+ struct snd_soc_codec *codec = socdev->codec;
+ struct i2c_client *i2c_client = NULL;
+ int i;
+ int ret = 0;
+
+ /* Probing all possible addresses has one drawback: if there are
+ multiple CS4270s on the bus, then you cannot specify which
+ socdev is matched with which CS4270. For now, we just reject
+ this I2C device if the socdev already has one attached. */
+ if (codec->control_data)
+ return -ENODEV;
+
+ /* Note: codec_dai->codec is NULL here */
+
+ i2c_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
+ if (!i2c_client) {
+ printk(KERN_ERR "cs4270: could not allocate I2C client\n");
+ return -ENOMEM;
+ }
+
+ codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL);
+ if (!codec->reg_cache) {
+ printk(KERN_ERR "cs4270: could not allocate register cache\n");
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ i2c_set_clientdata(i2c_client, codec);
+ strcpy(i2c_client->name, "CS4270");
+
+ i2c_client->driver = &cs4270_i2c_driver;
+ i2c_client->adapter = adapter;
+ i2c_client->addr = addr;
+
+ /* Verify that we have a CS4270 */
+
+ ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to read I2C\n");
+ goto error;
+ }
+ /* The top four bits of the chip ID should be 1100. */
+ if ((ret & 0xF0) != 0xC0) {
+ /* The device at this address is not a CS4270 codec */
+ ret = -ENODEV;
+ goto error;
+ }
+
+ printk(KERN_INFO "cs4270: found device at I2C address %X\n", addr);
+ printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF);
+
+ /* Tell the I2C layer a new client has arrived */
+
+ ret = i2c_attach_client(i2c_client);
+ if (ret) {
+ printk(KERN_ERR "cs4270: could not attach codec, "
+ "I2C address %x, error code %i\n", addr, ret);
+ goto error;
+ }
+
+ codec->control_data = i2c_client;
+ codec->read = cs4270_read_reg_cache;
+ codec->write = cs4270_i2c_write;
+ codec->reg_cache_size = CS4270_NUMREGS;
+
+ /* The I2C interface is set up, so pre-fill our register cache */
+
+ ret = cs4270_fill_cache(codec);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to fill register cache\n");
+ goto error;
+ }
+
+ /* Add the non-DAPM controls */
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) {
+ struct snd_kcontrol *kctrl =
+ snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL);
+
+ ret = snd_ctl_add(codec->card, kctrl);
+ if (ret < 0)
+ goto error;
+ }
+
+ return 0;
+
+error:
+ if (codec->control_data) {
+ i2c_detach_client(i2c_client);
+ codec->control_data = NULL;
+ }
+
+ kfree(codec->reg_cache);
+ codec->reg_cache = NULL;
+ codec->reg_cache_size = 0;
+
+ kfree(i2c_client);
+
+ return ret;
+}
+
+#endif
+
+struct snd_soc_codec_dai cs4270_dai = {
+ .name = "CS4270",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = 0,
+ .formats = CS4270_FORMATS,
+ },
+ .capture = {
+ .stream_name = "Capture",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = 0,
+ .formats = CS4270_FORMATS,
+ },
+ .dai_ops = {
+ .set_sysclk = cs4270_set_dai_sysclk,
+ .set_fmt = cs4270_set_dai_fmt,
+ }
+};
+EXPORT_SYMBOL_GPL(cs4270_dai);
+
+/*
+ * ASoC probe function
+ *
+ * This function is called when the machine driver calls
+ * platform_device_add().
+ */
+static int cs4270_probe(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec;
+ int ret = 0;
+
+ printk(KERN_INFO "CS4270 ALSA SoC Codec\n");
+
+ /* Allocate enough space for the snd_soc_codec structure
+ and our private data together. */
+ codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) +
+ sizeof(struct cs4270_private), GFP_KERNEL);
+ if (!codec) {
+ printk(KERN_ERR "cs4270: Could not allocate codec structure\n");
+ return -ENOMEM;
+ }
+
+ mutex_init(&codec->mutex);
+ INIT_LIST_HEAD(&codec->dapm_widgets);
+ INIT_LIST_HEAD(&codec->dapm_paths);
+
+ codec->name = "CS4270";
+ codec->owner = THIS_MODULE;
+ codec->dai = &cs4270_dai;
+ codec->num_dai = 1;
+ codec->private_data = codec + ALIGN(sizeof(struct snd_soc_codec), 4);
+
+ socdev->codec = codec;
+
+ /* Register PCMs */
+
+ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to create PCMs\n");
+ return ret;
+ }
+
+#ifdef CONFIG_I2C
+ cs4270_socdev = socdev;
+
+ ret = i2c_add_driver(&cs4270_i2c_driver);
+ if (ret) {
+ printk(KERN_ERR "cs4270: failed to attach driver");
+ snd_soc_free_pcms(socdev);
+ return ret;
+ }
+
+ /* Did we find a CS4270 on the I2C bus? */
+ if (codec->control_data) {
+ /* Initialize codec ops */
+ cs4270_dai.ops.hw_params = cs4270_hw_params;
+#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
+ cs4270_dai.dai_ops.digital_mute = cs4270_mute;
+#endif
+ } else
+ printk(KERN_INFO "cs4270: no I2C device found, "
+ "using stand-alone mode\n");
+#else
+ printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n");
+#endif
+
+ ret = snd_soc_register_card(socdev);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to register card\n");
+ snd_soc_free_pcms(socdev);
+ return ret;
+ }
+
+ return ret;
+}
+
+static int cs4270_remove(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+ snd_soc_free_pcms(socdev);
+
+#ifdef CONFIG_I2C
+ if (socdev->codec->control_data)
+ i2c_del_driver(&cs4270_i2c_driver);
+#endif
+
+ kfree(socdev->codec);
+ socdev->codec = NULL;
+
+ return 0;
+}
+
+/*
+ * ASoC codec device structure
+ *
+ * Assign this variable to the codec_dev field of the machine driver's
+ * snd_soc_device structure.
+ */
+struct snd_soc_codec_device soc_codec_device_cs4270 = {
+ .probe = cs4270_probe,
+ .remove = cs4270_remove
+};
+EXPORT_SYMBOL_GPL(soc_codec_device_cs4270);
+
+MODULE_AUTHOR("Timur Tabi <timur(a)freescale.com>");
+MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs4270.h b/sound/soc/codecs/cs4270.h
new file mode 100644
index 0000000..0ced49b
--- /dev/null
+++ b/sound/soc/codecs/cs4270.h
@@ -0,0 +1,28 @@
+/*
+ * Cirrus Logic CS4270 ALSA SoC Codec Driver
+ *
+ * Author: Timur Tabi <timur(a)freescale.com>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#ifndef _CS4270_H
+#define _CS4270_H
+
+/*
+ * The ASoC codec DAI structure for the CS4270. Assign this structure to
+ * the .codec_dai field of your machine driver's snd_soc_dai_link structure.
+ */
+extern struct snd_soc_codec_dai cs4270_dai;
+
+/*
+ * The ASoC codec device structure for the CS4270. Assign this structure
+ * to the .codec_dev field of your machine driver's snd_soc_device
+ * structure.
+ */
+extern struct snd_soc_codec_device soc_codec_device_cs4270;
+
+#endif
--
1.5.2.4
3
7
Hello
I have Dell Latitude D531 notebook with
00:14.2 Audio device: ATI Technologies Inc SB600 Azalia
sound card. Module snd_hda_intel is automaticaly loaded but no sound card
is detected. Here is the dmesg output:
ACPI: PCI Interrupt 0000:00:14.2[A] -> GSI 16 (level, low) -> IRQ 16
ALSA
/usr/src/modules/alsa-driver/pci/hda/../../alsa-kernel/pci/hda/hda_intel.c:558:
hda_intel: azx_get_response timeout, switching to polling mode...
ALSA
/usr/src/modules/alsa-driver/pci/hda/../../alsa-kernel/pci/hda/hda_intel.c:564:
hda_intel: azx_get_response timeout, switching to single_cmd mode...
hda_codec: No auto-config is available, default to model=ref
ALSA
/usr/src/modules/alsa-driver/pci/hda/../../alsa-kernel/pci/hda/hda_intel.c:1020:
hda-intel: no codecs initialized
ACPI: PCI interrupt for device 0000:00:14.2 disabled
I have linux kernel 2.6.22.1. Also tried alsa 1.0.14 kernel modules built
from alsa sources. The result was the same.
I have also tried all model=xxx arguments, nothing helped.
A also tried pci=noacpi but that caused boot failure.
Am I doing something wrong? Can you please help me with that?
Btw, the system is 64bit, could that be a problem?
lspci -nnv for sound card is:
00:14.2 Audio device [0403]: ATI Technologies Inc SB600 Azalia [1002:4383]
Subsystem: Dell Unknown device [1028:0206]
Flags: slow devsel, IRQ 16
Memory at febfc000 (64-bit, non-prefetchable) [size=16K]
Capabilities: [50] Power Management version 2
Thanks in advance
Marek
3
5
This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The
following features are suppored:
1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management
Signed-off-by: Timur Tabi <timur(a)freescale.com>
---
This code is based on the Liam Girdwood's ASoC tree.
Please note that I was unable to clone Liam's ASoC git repositories because
the http interface does not work for me, and my corporate firewall blocks the
git protocol. I had to download a snapshot and create a bare git repository
from it. Therefore, git may complain when trying to apply this patch.
include/linux/i2c-id.h | 1 +
sound/soc/codecs/Kconfig | 20 ++
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/cs4270.c | 812 +++++++++++++++++++++++++++++++++++++++++++++
sound/soc/codecs/cs4270.h | 28 ++
5 files changed, 863 insertions(+), 0 deletions(-)
create mode 100644 sound/soc/codecs/cs4270.c
create mode 100644 sound/soc/codecs/cs4270.h
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index 0051203..6b3d207 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -119,6 +119,7 @@
#define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */
#define I2C_DRIVERID_WM8753 91 /* Wolfson WM8753 audio codec */
#define I2C_DRIVERID_WM8951 92 /* Wolfson WM8753 audio codec */
+#define I2C_DRIVERID_CS4270 93 /* Cirrus Logic 4270 audio codec */
#define I2C_DRIVERID_I2CDEV 900
#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index e71667f..9c84eb2 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -78,4 +78,24 @@ config SND_SOC_WM9713
tristate
depends on SND_SOC
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+ tristate
+ depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+ bool
+ depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+ bool
+ depends on SND_SOC_CS4270
+
+
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 07d0b59..d9237a1 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -18,6 +18,7 @@ snd-soc-wm8976-objs := wm8976.o
snd-soc-wm8980-objs := wm8980.o
snd-soc-wm9712-objs := wm9712.o
snd-soc-wm9713-objs := wm9713.o
+snd-soc-cs4270-objs := cs4270.o
obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
@@ -39,3 +40,4 @@ obj-$(CONFIG_SND_SOC_WM8976) += snd-soc-wm8976.o
obj-$(CONFIG_SND_SOC_WM8980) += snd-soc-wm8980.o
obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
+obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
new file mode 100644
index 0000000..e1cf104
--- /dev/null
+++ b/sound/soc/codecs/cs4270.c
@@ -0,0 +1,812 @@
+/**
+ * CS4270 ALSA SoC (ASoC) codec driver
+ *
+ * Author: Timur Tabi <timur(a)freescale.com>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ *
+ * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
+ *
+ * Current features/limitations:
+ *
+ * 1) Stand-alone and software mode is supported. Stand-alone is
+ * automatically selected if I2C is disabled or if a CS4270 is not found
+ * on the I2C bus.
+ * 2) Only I2C is supported, not SPI
+ * 3) Only Master mode is supported, not Slave.
+ * 4) The machine driver's 'startup' function must call
+ * cs4270_set_dai_sysclk() with the value of MCLK.
+ * 5) Only I2S and left-justified modes are supported
+ * 6) Power management is not supported
+ * 7) The only supported control is volume and hardware mute (if enabled)
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/soc.h>
+#include <sound/initval.h>
+#include <linux/i2c.h>
+
+#include "cs4270.h"
+
+/* Private data for the CS4270 */
+struct cs4270_private {
+ unsigned int mclk; /* Input frequency of the MCLK pin */
+ unsigned int mode; /* The mode (I2S or left-justified) */
+};
+
+/**
+ * The codec isn't really big-endian or little-endian, since the I2S
+ * interface requires data to be sent serially with the MSbit first.
+ * However, to support BE and LE I2S devices, we specify both here. That
+ * way, ALSA will always match the bit patterns. Also, it appears that the
+ * CS4270 doesn't like S8.
+ *
+ * FIXME: This list should contain only signed values, not unsigned. The I2S
+ * protocol requires signed samples.
+ */
+#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
+ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
+ SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
+ SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
+ SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
+ SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
+
+#ifdef CONFIG_I2C
+
+/* CS4270 registers addresses */
+#define CS4270_CHIPID 0x01 /* Chip ID */
+#define CS4270_PWRCTL 0x02 /* Power Control */
+#define CS4270_MODE 0x03 /* Mode Control */
+#define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */
+#define CS4270_TRANS 0x05 /* Transition Control */
+#define CS4270_MUTE 0x06 /* Mute Control */
+#define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */
+#define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */
+
+#define CS4270_FIRSTREG 0x01
+#define CS4270_LASTREG 0x08
+#define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
+
+/* Bit masks for the CS4270 registers */
+#define CS4270_CHIPID_ID 0xF0
+#define CS4270_CHIPID_REV 0x0F
+#define CS4270_PWRCTL_FREEZE 0x80
+#define CS4270_PWRCTL_PDN_ADC 0x20
+#define CS4270_PWRCTL_PDN_DAC 0x02
+#define CS4270_PWRCTL_PDN 0x01
+#define CS4270_MODE_SPEED_MASK 0x30
+#define CS4270_MODE_1X 0x00
+#define CS4270_MODE_2X 0x10
+#define CS4270_MODE_4X 0x20
+#define CS4270_MODE_SLAVE 0x30
+#define CS4270_MODE_DIV_MASK 0x0E
+#define CS4270_MODE_DIV1 0x00
+#define CS4270_MODE_DIV15 0x02
+#define CS4270_MODE_DIV2 0x04
+#define CS4270_MODE_DIV3 0x06
+#define CS4270_MODE_DIV4 0x08
+#define CS4270_MODE_POPGUARD 0x01
+#define CS4270_FORMAT_FREEZE_A 0x80
+#define CS4270_FORMAT_FREEZE_B 0x40
+#define CS4270_FORMAT_LOOPBACK 0x20
+#define CS4270_FORMAT_DAC_MASK 0x18
+#define CS4270_FORMAT_DAC_LJ 0x00
+#define CS4270_FORMAT_DAC_I2S 0x08
+#define CS4270_FORMAT_DAC_RJ16 0x18
+#define CS4270_FORMAT_DAC_RJ24 0x10
+#define CS4270_FORMAT_ADC_MASK 0x01
+#define CS4270_FORMAT_ADC_LJ 0x00
+#define CS4270_FORMAT_ADC_I2S 0x01
+#define CS4270_TRANS_ONE_VOL 0x80
+#define CS4270_TRANS_SOFT 0x40
+#define CS4270_TRANS_ZERO 0x20
+#define CS4270_TRANS_INV_ADC_A 0x08
+#define CS4270_TRANS_INV_ADC_B 0x10
+#define CS4270_TRANS_INV_DAC_A 0x02
+#define CS4270_TRANS_INV_DAC_B 0x04
+#define CS4270_TRANS_DEEMPH 0x01
+#define CS4270_MUTE_AUTO 0x20
+#define CS4270_MUTE_ADC_A 0x08
+#define CS4270_MUTE_ADC_B 0x10
+#define CS4270_MUTE_POLARITY 0x04
+#define CS4270_MUTE_DAC_A 0x01
+#define CS4270_MUTE_DAC_B 0x02
+
+/**
+ * A list of addresses on which this CS4270 could use. I2C addresses are
+ * 7 bits. For the CS4270, the upper four bits are always 1001, and the
+ * lower three bits are determined via the AD2, AD1, and AD0 pins
+ * (respectively).
+ */
+static unsigned short normal_i2c[] = {
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END
+};
+I2C_CLIENT_INSMOD;
+
+/**
+ * Pre-fill the CS4270 register cache.
+ *
+ * We use the auto-increment feature of the CS4270 to read all registers in
+ * one shot.
+ */
+static int cs4270_fill_cache(struct snd_soc_codec *codec)
+{
+ u8 *cache = codec->reg_cache;
+ struct i2c_client *i2c_client = codec->control_data;
+ s32 length;
+
+ length = i2c_smbus_read_i2c_block_data(i2c_client,
+ CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);
+
+ if (length != CS4270_NUMREGS) {
+ printk(KERN_ERR "cs4270: I2C read failure, addr=%u\n",
+ i2c_client->addr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+/**
+ * Read from the CS4270 register cache.
+ *
+ * This CS4270 registers are cached to avoid excessive I2C I/O operations.
+ * After the initial read to pre-fill the cache, the CS4270 never updates
+ * the register values, so we won't have a cache coherncy problem.
+ */
+static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
+ unsigned int reg)
+{
+ u8 *cache = codec->reg_cache;
+
+ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
+ return -EIO;
+
+ return cache[reg - CS4270_FIRSTREG];
+}
+
+/**
+ * Write to a CS4270 register via the I2C bus.
+ *
+ * This function writes the given value to the given CS4270 register, and
+ * also updates the register cache.
+ *
+ * Note that we don't use the hw_write function pointer of snd_soc_codec.
+ * That's because it's too clunky: the hw_write_t prototype does not match
+ * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
+ */
+static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
+ unsigned int value)
+{
+ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
+ return -EIO;
+
+ if (i2c_smbus_write_byte_data(codec->control_data, reg, value) == 0) {
+ /* We've written to the hardware, so update the cache */
+ u8 *cache = codec->reg_cache;
+ cache[reg - CS4270_FIRSTREG] = value;
+ return 0;
+ } else {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return -EIO;
+ }
+}
+
+/**
+ * Clock Ratio Selection for Master Mode.
+ *
+ * The data for this chart is taken from Table 5 of the CS4270 reference
+ * manual.
+ *
+ * This table is used to determine how to program the Mode Control register.
+ * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
+ * rates the CS4270 currently supports.
+ *
+ * 'ratio' is the MCLK/LRCK ratio. MCLK is usually a fixed input frequency,
+ * and LRCK is equal to the sampling rate. The CS4270 only supports sampling
+ * rates where this ratio is one of: 64, 96, 128, 192, 256, 384, 512, 768 or
+ * 1024.
+ *
+ * 'speed_mode' is the corresponding bit pattern to be written to the
+ * MODE bits of the Mode Control Register
+ *
+ * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of
+ * the Mode Control Register.
+ *
+ * In situations where a single ratio is represented by multiple speed
+ * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
+ * double-speed instead of quad-speed. However, the CS4270 errata states
+ * that Divide-By-1.5 can cause failures, so we avoid that mode where
+ * possible.
+ *
+ * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not
+ * work if VD = 3.3V. If this effects you, select the
+ * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
+ * never select any sample rates that require divide-by-1.5.
+ */
+static struct {
+ unsigned int ratio;
+ u8 speed_mode;
+ u8 mclk;
+} cs4270_mode_ratios[] = {
+ {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
+#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
+ {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
+#endif
+ {128, CS4270_MODE_2X, CS4270_MODE_DIV1},
+ {192, CS4270_MODE_4X, CS4270_MODE_DIV3},
+ {256, CS4270_MODE_1X, CS4270_MODE_DIV1},
+ {384, CS4270_MODE_2X, CS4270_MODE_DIV3},
+ {512, CS4270_MODE_1X, CS4270_MODE_DIV2},
+ {768, CS4270_MODE_1X, CS4270_MODE_DIV3},
+ {1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
+};
+
+/**
+ * Program the CS4270 with the given hardware parameters.
+ *
+ * The .dai_ops functions are used to provide board-specific data, like
+ * input frequencies, to this driver. This function takes that information,
+ * combines it with the hardware parameters provided, and programs the
+ * hardware accordingly.
+ */
+static int cs4270_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_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ unsigned int ret = 0;
+ unsigned int i;
+ unsigned int rate;
+ unsigned int ratio;
+ int reg;
+
+ /* Figure out which MCLK/LRCK ratio to use */
+
+ rate = params_rate(params); /* Sampling rate, in Hz */
+ ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_mode_ratios); i++) {
+ if (cs4270_mode_ratios[i].ratio == ratio)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(cs4270_mode_ratios)) {
+ /* We did not find a matching ratio */
+ printk(KERN_ERR "cs4270: could not find matching ratio\n");
+ return -EINVAL;
+ }
+
+ /* Freeze and power-down the codec */
+
+ ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE |
+ CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC |
+ CS4270_PWRCTL_PDN);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Program the mode control register */
+
+ reg = snd_soc_read(codec, CS4270_MODE);
+ reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
+ reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk;
+
+ ret = snd_soc_write(codec, CS4270_MODE, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Program the format register */
+
+ reg = snd_soc_read(codec, CS4270_FORMAT);
+ reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
+
+ switch (cs4270->mode) {
+ case SND_SOC_DAIFMT_I2S:
+ reg |= CS4270_FORMAT_DAC_I2S | CS4270_FORMAT_ADC_I2S;
+ break;
+ case SND_SOC_DAIFMT_LEFT_J:
+ reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
+ break;
+ default:
+ printk(KERN_ERR "cs4270: unknown format\n");
+ return -EINVAL;
+ }
+
+ ret = snd_soc_write(codec, CS4270_FORMAT, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Disable auto-mute. This feature appears to be buggy, because in
+ some situations, auto-mute will not deactivate when it should. */
+
+ reg = snd_soc_read(codec, CS4270_MUTE);
+ reg &= ~CS4270_MUTE_AUTO;
+ ret = snd_soc_write(codec, CS4270_MUTE, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Thaw and power-up the codec */
+
+ ret = snd_soc_write(codec, CS4270_PWRCTL, 0);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
+
+/**
+ * Set the CS4270 external mute
+ *
+ * This function toggles the mute bits in the MUTE register. The CS4270's
+ * mute capability is intended for external muting circuitry, so if the
+ * board does not have the MUTEA or MUTEB pins connected to such circuitry,
+ * then this function will do nothing.
+ */
+static int cs4270_mute(struct snd_soc_codec_dai *dai, int mute)
+{
+ struct snd_soc_codec *codec = dai->codec;
+ int reg6;
+
+ reg6 = snd_soc_read(codec, CS4270_MUTE);
+
+ if (mute)
+ reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
+ CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
+ else
+ reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
+ CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
+
+ return snd_soc_write(codec, CS4270_MUTE, reg6);
+}
+
+#endif
+
+/**
+ * Sampling rate <-> bit patter mapping
+ *
+ * This array maps sampling rates to their SNDRV_PCM_RATE_x equivalent.
+ *
+ * This is really something that ALSA should provide.
+ *
+ * This table is used by cs4270_set_dai_sysclk() to tell ALSA which sampling
+ * rates the CS4270 currently supports.
+ */
+static struct {
+ unsigned int rate;
+ unsigned int bit;
+} rate_map[] = {
+ {5512, SNDRV_PCM_RATE_5512},
+ {8000, SNDRV_PCM_RATE_8000},
+ {11025, SNDRV_PCM_RATE_11025},
+ {16000, SNDRV_PCM_RATE_16000},
+ {22050, SNDRV_PCM_RATE_22050},
+ {32000, SNDRV_PCM_RATE_32000},
+ {44100, SNDRV_PCM_RATE_44100},
+ {48000, SNDRV_PCM_RATE_48000},
+ {64000, SNDRV_PCM_RATE_64000},
+ {88200, SNDRV_PCM_RATE_88200},
+ {96000, SNDRV_PCM_RATE_96000},
+ {176400, SNDRV_PCM_RATE_176400},
+ {192000, SNDRV_PCM_RATE_192000}
+};
+
+/**
+ * Determine the CS4270 samples rates.
+ *
+ * 'freq' is the input frequency to MCLK. The other parameters are ignored.
+ *
+ * The value of MCLK is used to determine which sample rates are supported
+ * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
+ * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
+ *
+ * This function calculates the nine ratios and determines which ones match
+ * a standard sample rate. If there's a match, then it is added to the list
+ * of support sample rates.
+ *
+ * This function must be called by the machine driver's 'startup' function,
+ * otherwise the list of supported sample rates will not be available in
+ * time for ALSA.
+ */
+static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+ int clk_id, unsigned int freq, int dir)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ unsigned int rates = 0;
+ unsigned int rate_min = -1;
+ unsigned int rate_max = 0;
+ unsigned int i;
+
+ cs4270->mclk = freq;
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_mode_ratios); i++) {
+ unsigned int rate;
+ unsigned int j;
+ rate = freq / cs4270_mode_ratios[i].ratio;
+ for (j = 0; j < ARRAY_SIZE(rate_map); j++) {
+ if (rate == rate_map[j].rate) {
+ rates |= rate_map[j].bit;
+ if (rate < rate_min)
+ rate_min = rate;
+ if (rate > rate_max)
+ rate_max = rate;
+ }
+ }
+ }
+
+ if (!rate_max) {
+ printk(KERN_ERR "cs4270: could not find a valid rate\n");
+ return -EINVAL;
+ }
+
+ codec_dai->playback.rates = rates;
+ codec_dai->playback.rate_min = rate_min;
+ codec_dai->playback.rate_max = rate_max;
+
+ codec_dai->capture.rates = rates;
+ codec_dai->capture.rate_min = rate_min;
+ codec_dai->capture.rate_max = rate_max;
+
+ return 0;
+}
+
+/**
+ * Configure the codec for the selected audio format
+ *
+ * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
+ * codec accordingly.
+ *
+ * Currently, this function only supports SND_SOC_DAIFMT_I2S and
+ * SND_SOC_DAIFMT_LEFT_J. The CS4270 codec also supports right-justified
+ * data for playback only, but ASoC currently does not support different
+ * formats for playback vs. record.
+ */
+static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+ unsigned int format)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ int ret = 0;
+
+ switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
+ case SND_SOC_DAIFMT_I2S:
+ case SND_SOC_DAIFMT_LEFT_J:
+ cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
+ break;
+ default:
+ printk(KERN_ERR "cs4270: invalid DAI format\n");
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static int cs4270_i2c_probe(struct i2c_adapter *adap, int addr, int kind);
+
+/**
+ * Notify the driver that a new I2C bus has been found.
+ *
+ * This function is called for each I2C bus in the system. The function
+ * then asks the I2C subsystem to probe that bus at the addresses on which
+ * our device (the CS4270) could exist. If a device is found at one of
+ * those addresses, then our probe function (cs4270_i2c_probe) is called.
+ */
+static int cs4270_i2c_attach(struct i2c_adapter *adapter)
+{
+ return i2c_probe(adapter, &addr_data, cs4270_i2c_probe);
+}
+
+static int cs4270_i2c_detach(struct i2c_client *client)
+{
+ struct snd_soc_codec *codec = i2c_get_clientdata(client);
+
+ i2c_detach_client(client);
+ codec->control_data = NULL;
+
+ kfree(codec->reg_cache);
+ codec->reg_cache = NULL;
+
+ kfree(client);
+ return 0;
+}
+
+/* A list of non-DAPM controls that the CS4270 supports */
+static const struct snd_kcontrol_new cs4270_snd_controls[] = {
+ SOC_DOUBLE_R("Master Playback Volume",
+ CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 0)
+};
+
+static struct i2c_driver cs4270_i2c_driver = {
+ .driver = {
+ .name = "CS4270 I2C",
+ .owner = THIS_MODULE,
+ },
+ .id = I2C_DRIVERID_CS4270,
+ .attach_adapter = cs4270_i2c_attach,
+ .detach_client = cs4270_i2c_detach,
+};
+
+/**
+ * Global variable to store socdev for i2c probe function.
+ *
+ * If struct i2c_driver had a private_data field, we wouldn't need to use
+ * cs4270_socdec. This is the only way to pass the socdev structure to
+ * cs4270_i2c_probe().
+ *
+ * The real solution to cs4270_socdev is to create a mechanism
+ * that maps I2C addresses to snd_soc_device structures. Perhaps the
+ * creation of the snd_soc_device object should be moved out of
+ * cs4270_probe() and into cs4270_i2c_probe(), but that would make this
+ * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby
+ * the chip is *not* connected to the I2C bus, but is instead configured via
+ * input pins.
+ */
+static struct snd_soc_device *cs4270_socdev;
+
+/**
+ * Initialize the I2C interface of the CS4270
+ *
+ * This function is called for whenever the I2C subsystem finds a device
+ * at a particular address.
+ *
+ * Note: snd_soc_new_pcms() must be called before this function can be called,
+ * because of snd_ctl_add().
+ */
+static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind)
+{
+ struct snd_soc_device *socdev = cs4270_socdev;
+ struct snd_soc_codec *codec = socdev->codec;
+ struct i2c_client *i2c_client = NULL;
+ int i;
+ int ret = 0;
+
+ /* Probing all possible addresses has one drawback: if there are
+ multiple CS4270s on the bus, then you cannot specify which
+ socdev is matched with which CS4270. For now, we just reject
+ this I2C device if the socdev already has one attached. */
+ if (codec->control_data)
+ return -ENODEV;
+
+ /* Note: codec_dai->codec is NULL here */
+
+ i2c_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
+ if (!i2c_client) {
+ printk(KERN_ERR "cs4270: could not allocate I2C client\n");
+ return -ENOMEM;
+ }
+
+ codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL);
+ if (!codec->reg_cache) {
+ printk(KERN_ERR "cs4270: could not allocate register cache\n");
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ i2c_set_clientdata(i2c_client, codec);
+ strcpy(i2c_client->name, "CS4270");
+
+ i2c_client->driver = &cs4270_i2c_driver;
+ i2c_client->adapter = adapter;
+ i2c_client->addr = addr;
+
+ /* Verify that we have a CS4270 */
+
+ ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to read I2C\n");
+ goto error;
+ }
+ /* The top four bits of the chip ID should be 1100. */
+ if ((ret & 0xF0) != 0xC0) {
+ /* The device at this address is not a CS4270 codec */
+ ret = -ENODEV;
+ goto error;
+ }
+
+ printk(KERN_INFO "cs4270: found device at I2C address %X\n", addr);
+ printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF);
+
+ /* Tell the I2C layer a new client has arrived */
+
+ ret = i2c_attach_client(i2c_client);
+ if (ret) {
+ printk(KERN_ERR "cs4270: could not attach codec, "
+ "I2C address %x, error code %i\n", addr, ret);
+ goto error;
+ }
+
+ codec->control_data = i2c_client;
+ codec->read = cs4270_read_reg_cache;
+ codec->write = cs4270_i2c_write;
+ codec->reg_cache_size = CS4270_NUMREGS;
+
+ /* The I2C interface is set up, so pre-fill our register cache */
+
+ ret = cs4270_fill_cache(codec);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to fill register cache\n");
+ goto error;
+ }
+
+ /* Add the non-DAPM controls */
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) {
+ struct snd_kcontrol *kctrl =
+ snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL);
+
+ ret = snd_ctl_add(codec->card, kctrl);
+ if (ret < 0)
+ goto error;
+ }
+
+ return 0;
+
+error:
+ if (codec->control_data) {
+ i2c_detach_client(i2c_client);
+ codec->control_data = NULL;
+ }
+
+ kfree(codec->reg_cache);
+ codec->reg_cache = NULL;
+ codec->reg_cache_size = 0;
+
+ kfree(i2c_client);
+
+ return ret;
+}
+
+#endif
+
+struct snd_soc_codec_dai cs4270_dai = {
+ .name = "CS4270",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = 0,
+ .formats = CS4270_FORMATS,
+ },
+ .capture = {
+ .stream_name = "Capture",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = 0,
+ .formats = CS4270_FORMATS,
+ },
+ .dai_ops = {
+ .set_sysclk = cs4270_set_dai_sysclk,
+ .set_fmt = cs4270_set_dai_fmt,
+ }
+};
+EXPORT_SYMBOL_GPL(cs4270_dai);
+
+/**
+ * ASoC probe function
+ *
+ * This function is called when the machine driver calls
+ * platform_device_add().
+ */
+static int cs4270_probe(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec;
+ int ret = 0;
+
+ printk(KERN_INFO "CS4270 ALSA SoC Codec\n");
+
+ /* Allocate enough space for the snd_soc_codec structure
+ and our private data together. */
+ codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) +
+ sizeof(struct cs4270_private), GFP_KERNEL);
+ if (!codec) {
+ printk(KERN_ERR "cs4270: Could not allocate codec structure\n");
+ return -ENOMEM;
+ }
+
+ mutex_init(&codec->mutex);
+ INIT_LIST_HEAD(&codec->dapm_widgets);
+ INIT_LIST_HEAD(&codec->dapm_paths);
+
+ codec->name = "CS4270";
+ codec->owner = THIS_MODULE;
+ codec->dai = &cs4270_dai;
+ codec->num_dai = 1;
+ codec->private_data = codec + ALIGN(sizeof(struct snd_soc_codec), 4);
+
+ socdev->codec = codec;
+
+ /* Register PCMs */
+
+ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to create PCMs\n");
+ return ret;
+ }
+
+#ifdef CONFIG_I2C
+ cs4270_socdev = socdev;
+
+ ret = i2c_add_driver(&cs4270_i2c_driver);
+ if (ret) {
+ printk(KERN_ERR "cs4270: failed to attach driver");
+ snd_soc_free_pcms(socdev);
+ return ret;
+ }
+
+ /* Did we find a CS4270 on the I2C bus? */
+ if (codec->control_data) {
+ /* Initialize codec ops */
+ cs4270_dai.ops.hw_params = cs4270_hw_params;
+#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
+ cs4270_dai.dai_ops.digital_mute = cs4270_mute;
+#endif
+ } else
+ printk(KERN_INFO "cs4270: no I2C device found, "
+ "using stand-alone mode\n");
+#else
+ printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n");
+#endif
+
+ ret = snd_soc_register_card(socdev);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to register card\n");
+ snd_soc_free_pcms(socdev);
+ return ret;
+ }
+
+ return ret;
+}
+
+static int cs4270_remove(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+ snd_soc_free_pcms(socdev);
+
+#ifdef CONFIG_I2C
+ if (socdev->codec->control_data)
+ i2c_del_driver(&cs4270_i2c_driver);
+#endif
+
+ kfree(socdev->codec);
+ socdev->codec = NULL;
+
+ return 0;
+}
+
+/**
+ * ASoC codec device structure
+ *
+ * Assign this variable to the codec_dev field of the machine driver's
+ * snd_soc_device structure.
+ */
+struct snd_soc_codec_device soc_codec_device_cs4270 = {
+ .probe = cs4270_probe,
+ .remove = cs4270_remove
+};
+EXPORT_SYMBOL_GPL(soc_codec_device_cs4270);
+
+MODULE_AUTHOR("Timur Tabi <timur(a)freescale.com>");
+MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs4270.h b/sound/soc/codecs/cs4270.h
new file mode 100644
index 0000000..35e5fe3
--- /dev/null
+++ b/sound/soc/codecs/cs4270.h
@@ -0,0 +1,28 @@
+/*
+ * Cirrus Logic CS4270 ALSA SoC Codec Driver
+ *
+ * Author: Timur Tabi <timur(a)freescale.com>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#ifndef _CS4270_H
+#define _CS4270_H
+
+/**
+ * The ASoC codec DAI structure for the CS4270. Assign this structure to
+ * the .codec_dai field of your machine driver's snd_soc_dai_link structure.
+ */
+extern struct snd_soc_codec_dai cs4270_dai;
+
+/**
+ * The ASoC codec device structure for the CS4270. Assign this structure
+ * to the .codec_dev field of your machine driver's snd_soc_device
+ * structure.
+ */
+extern struct snd_soc_codec_device soc_codec_device_cs4270;
+
+#endif
--
1.5.2.4
2
2
Hi,
I've received the following bug report about problems in the internal
mic of a Dell Latitude D820 (STAC9200). Is this a known problem? The
used tested it with a fairly updated (but non-HG) driver. I've seen a
similar problem in an HP dx2250 (ALC862) with an outdated ALSA lib,
but this doesn't seem to be the case here.
--- Excerpt of original report follows ---
On laptops which use the snd-hda-intel driver the microphone often cannot be
activated (in particular, when the system comes out of system installation).
A workaround is the following script alway helps to make the microphone work
(except after a wake-up from suspend-to-disk):
#!/bin/sh
/usr/sbin/alsactl restore
amixer -c 0 sset 'Input Source',0 Line
amixer -c 0 sset 'Input Source',0 Mic
Comments
1. After a bootstrap, the "capture volumn" control of alsamixer always has the
value 0, irrespective of what is stored in /etc/asound.state. The previously
defined value of this control can be re-established with "alsctl restore", but
that does not make the microphone work.
2. Also, when the volume settings are changed with any of the mixers, very
often the microphone will not work any more; but I have not found a
reproducable sequence that provokes the error this way.
3. The microphone can be made work if, afterwords, the sound-input switch is
toggled to "line" and back to "mic".
2
1
This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The
following features are suppored:
1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management
Signed-off-by: Timur Tabi <timur(a)freescale.com>
---
This code is based on the Liam Girdwood's ASoC tree.
Please note that I was unable to clone Liam's ASoC git repositories because
the http interface does not work for me, and my corporate firewall blocks the
git protocol. I had to download a snapshot and create a bare git repository
from it. Therefore, git may complain when trying to apply this patch.
include/linux/i2c-id.h | 1 +
sound/soc/codecs/Kconfig | 20 ++
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/cs4270.c | 803 +++++++++++++++++++++++++++++++++++++++++++++
sound/soc/codecs/cs4270.h | 28 ++
5 files changed, 854 insertions(+), 0 deletions(-)
create mode 100644 sound/soc/codecs/cs4270.c
create mode 100644 sound/soc/codecs/cs4270.h
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index 0051203..6b3d207 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -119,6 +119,7 @@
#define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */
#define I2C_DRIVERID_WM8753 91 /* Wolfson WM8753 audio codec */
#define I2C_DRIVERID_WM8951 92 /* Wolfson WM8753 audio codec */
+#define I2C_DRIVERID_CS4270 93 /* Cirrus Logic 4270 audio codec */
#define I2C_DRIVERID_I2CDEV 900
#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index e71667f..9c84eb2 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -78,4 +78,24 @@ config SND_SOC_WM9713
tristate
depends on SND_SOC
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+ tristate
+ depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+ bool
+ depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+ bool
+ depends on SND_SOC_CS4270
+
+
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 07d0b59..d9237a1 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -18,6 +18,7 @@ snd-soc-wm8976-objs := wm8976.o
snd-soc-wm8980-objs := wm8980.o
snd-soc-wm9712-objs := wm9712.o
snd-soc-wm9713-objs := wm9713.o
+snd-soc-cs4270-objs := cs4270.o
obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
@@ -39,3 +40,4 @@ obj-$(CONFIG_SND_SOC_WM8976) += snd-soc-wm8976.o
obj-$(CONFIG_SND_SOC_WM8980) += snd-soc-wm8980.o
obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
+obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
new file mode 100644
index 0000000..6719590
--- /dev/null
+++ b/sound/soc/codecs/cs4270.c
@@ -0,0 +1,803 @@
+/**
+ * CS4270 ALSA SoC (ASoC) codec driver
+ *
+ * Author: Timur Tabi <timur(a)freescale.com>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ *
+ * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
+ *
+ * Current features/limitations:
+ *
+ * 1) Stand-alone and software mode is supported. Stand-alone is
+ * automatically selected if I2C is disabled or if a CS4270 is not found
+ * on the I2C bus.
+ * 2) Only I2C is supported, not SPI
+ * 3) Only Master mode is supported, not Slave.
+ * 4) The machine driver's 'startup' function must call
+ * cs4270_set_dai_sysclk() with the value of MCLK.
+ * 5) Only I2S and left-justified modes are supported
+ * 6) Power management is not supported
+ * 7) The only supported control is volume and hardware mute (if enabled)
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/soc.h>
+#include <sound/initval.h>
+#include <linux/i2c.h>
+
+#include "cs4270.h"
+
+/* Private data for the CS4270 */
+struct cs4270_private {
+ unsigned int mclk; /* Input frequency of the MCLK pin */
+ unsigned int mode; /* The mode (I2S or left-justified) */
+};
+
+/**
+ * The codec isn't really big-endian or little-endian, since the I2S
+ * interface requires data to be sent serially with the MSbit first.
+ * However, to support BE and LE I2S devices, we specify both here. That
+ * way, ALSA will always match the bit patterns. Also, it appears that the
+ * CS4270 doesn't like S8.
+ *
+ * FIXME: This list should contain only signed values, not unsigned. The I2S
+ * protocol requires signed samples.
+ */
+#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
+ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
+ SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
+ SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
+ SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
+ SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
+
+#ifdef CONFIG_I2C
+
+/* CS4270 registers addresses */
+#define CS4270_CHIPID 0x01 /* Chip ID */
+#define CS4270_PWRCTL 0x02 /* Power Control */
+#define CS4270_MODE 0x03 /* Mode Control */
+#define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */
+#define CS4270_TRANS 0x05 /* Transition Control */
+#define CS4270_MUTE 0x06 /* Mute Control */
+#define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */
+#define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */
+
+#define CS4270_FIRSTREG 0x01
+#define CS4270_LASTREG 0x08
+#define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
+
+/* Bit masks for the CS4270 registers */
+#define CS4270_CHIPID_ID 0xF0
+#define CS4270_CHIPID_REV 0x0F
+#define CS4270_PWRCTL_FREEZE 0x80
+#define CS4270_PWRCTL_PDN_ADC 0x20
+#define CS4270_PWRCTL_PDN_DAC 0x02
+#define CS4270_PWRCTL_PDN 0x01
+#define CS4270_MODE_SPEED_MASK 0x30
+#define CS4270_MODE_1X 0x00
+#define CS4270_MODE_2X 0x10
+#define CS4270_MODE_4X 0x20
+#define CS4270_MODE_SLAVE 0x30
+#define CS4270_MODE_DIV_MASK 0x0E
+#define CS4270_MODE_DIV1 0x00
+#define CS4270_MODE_DIV15 0x02
+#define CS4270_MODE_DIV2 0x04
+#define CS4270_MODE_DIV3 0x06
+#define CS4270_MODE_DIV4 0x08
+#define CS4270_MODE_POPGUARD 0x01
+#define CS4270_FORMAT_FREEZE_A 0x80
+#define CS4270_FORMAT_FREEZE_B 0x40
+#define CS4270_FORMAT_LOOPBACK 0x20
+#define CS4270_FORMAT_DAC_MASK 0x18
+#define CS4270_FORMAT_DAC_LJ 0x00
+#define CS4270_FORMAT_DAC_I2S 0x08
+#define CS4270_FORMAT_DAC_RJ16 0x18
+#define CS4270_FORMAT_DAC_RJ24 0x10
+#define CS4270_FORMAT_ADC_MASK 0x01
+#define CS4270_FORMAT_ADC_LJ 0x00
+#define CS4270_FORMAT_ADC_I2S 0x01
+#define CS4270_TRANS_ONE_VOL 0x80
+#define CS4270_TRANS_SOFT 0x40
+#define CS4270_TRANS_ZERO 0x20
+#define CS4270_TRANS_INV_ADC_A 0x08
+#define CS4270_TRANS_INV_ADC_B 0x10
+#define CS4270_TRANS_INV_DAC_A 0x02
+#define CS4270_TRANS_INV_DAC_B 0x04
+#define CS4270_TRANS_DEEMPH 0x01
+#define CS4270_MUTE_AUTO 0x20
+#define CS4270_MUTE_ADC_A 0x08
+#define CS4270_MUTE_ADC_B 0x10
+#define CS4270_MUTE_POLARITY 0x04
+#define CS4270_MUTE_DAC_A 0x01
+#define CS4270_MUTE_DAC_B 0x02
+
+/**
+ * A list of addresses on which this CS4270 could use. I2C addresses are
+ * 7 bits. For the CS4270, the upper four bits are always 1001, and the
+ * lower three bits are determined via the AD2, AD1, and AD0 pins
+ * (respectively).
+ */
+static unsigned short normal_i2c[] = {
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END
+};
+I2C_CLIENT_INSMOD;
+
+/**
+ * Pre-fill the CS4270 register cache.
+ *
+ * We use the auto-increment feature of the CS4270 to read all registers in
+ * one shot.
+ */
+static int cs4270_fill_cache(struct snd_soc_codec *codec)
+{
+ u8 *cache = codec->reg_cache;
+ struct i2c_client *i2c_client = codec->control_data;
+ s32 length;
+
+ length = i2c_smbus_read_i2c_block_data(i2c_client,
+ CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);
+
+ if (length != CS4270_NUMREGS) {
+ printk(KERN_ERR "cs4270: I2C read failure, addr=%u\n",
+ i2c_client->addr);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+/**
+ * Read from the CS4270 register cache.
+ *
+ * This CS4270 registers are cached to avoid excessive I2C I/O operations.
+ * After the initial read to pre-fill the cache, the CS4270 never updates
+ * the register values, so we won't have a cache coherncy problem.
+ */
+static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, unsigned int reg)
+{
+ u8 *cache = codec->reg_cache;
+
+ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
+ return -EIO;
+
+ return cache[reg - CS4270_FIRSTREG];
+}
+
+/**
+ * Write to a CS4270 register via the I2C bus.
+ *
+ * This function writes the given value to the given CS4270 register, and
+ * also updates the register cache.
+ *
+ * Note that we don't use the hw_write function pointer of snd_soc_codec.
+ * That's because it's too clunky: the hw_write_t prototype does not match
+ * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
+ */
+static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
+ unsigned int value)
+{
+ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
+ return -EIO;
+
+ if (i2c_smbus_write_byte_data(codec->control_data, reg, value) == 0) {
+ /* We've written to the hardware, so update the cache */
+ u8 *cache = codec->reg_cache;
+ cache[reg - CS4270_FIRSTREG] = value;
+ return 0;
+ } else {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return -EIO;
+ }
+}
+
+/**
+ * Clock Ratio Selection for Master Mode.
+ *
+ * The data for this chart is taken from Table 5 of the CS4270 reference
+ * manual.
+ *
+ * This table is used to determine how to program the Mode Control register.
+ * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
+ * rates the CS4270 currently supports.
+ *
+ * 'ratio' is the MCLK/LRCK ratio. MCLK is usually a fixed input frequency,
+ * and LRCK is equal to the sampling rate. The CS4270 only supports sampling
+ * rates where this ratio is one of: 64, 96, 128, 192, 256, 384, 512, 768 or
+ * 1024.
+ *
+ * 'speed_mode' is the corresponding bit pattern to be written to the
+ * MODE bits of the Mode Control Register
+ *
+ * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of
+ * the Mode Control Register.
+ *
+ * In situations where a single ratio is represented by multiple speed
+ * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
+ * double-speed instead of quad-speed. However, the CS4270 errata states
+ * that Divide-By-1.5 can cause failures, so we avoid that mode where
+ * possible.
+ *
+ * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not
+ * work if VD = 3.3V. If this effects you, select the
+ * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
+ * never select any sample rates that require divide-by-1.5.
+ */
+static struct {
+ unsigned int ratio;
+ u8 speed_mode;
+ u8 mclk;
+} cs4270_mode_ratios[] = {
+ {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
+#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
+ {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
+#endif
+ {128, CS4270_MODE_2X, CS4270_MODE_DIV1},
+ {192, CS4270_MODE_4X, CS4270_MODE_DIV3},
+ {256, CS4270_MODE_1X, CS4270_MODE_DIV1},
+ {384, CS4270_MODE_2X, CS4270_MODE_DIV3},
+ {512, CS4270_MODE_1X, CS4270_MODE_DIV2},
+ {768, CS4270_MODE_1X, CS4270_MODE_DIV3},
+ {1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
+};
+
+/**
+ * Program the CS4270 with the given hardware parameters.
+ *
+ * The .dai_ops functions are used to provide board-specific data, like
+ * input frequencies, to this driver. This function takes that information,
+ * combines it with the hardware parameters provided, and programs the
+ * hardware accordingly.
+ */
+static int cs4270_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_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ unsigned int ret = 0, i, rate, ratio;
+ int reg;
+
+ /* Figure out which MCLK/LRCK ratio to use */
+
+ rate = params_rate(params); /* Sampling rate, in Hz */
+ ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
+
+ for (i=0; i<ARRAY_SIZE(cs4270_mode_ratios); i++) {
+ if (cs4270_mode_ratios[i].ratio == ratio) {
+ break;
+ }
+ }
+
+ if (i == ARRAY_SIZE(cs4270_mode_ratios)) {
+ /* We did not find a matching ratio */
+ printk(KERN_ERR "cs4270: could not find matching ratio\n");
+ return -EINVAL;
+ }
+
+ /* Freeze and power-down the codec */
+
+ ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE |
+ CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC |
+ CS4270_PWRCTL_PDN);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Program the mode control register */
+
+ reg = snd_soc_read(codec, CS4270_MODE);
+ reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
+ reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk;
+
+ ret = snd_soc_write(codec, CS4270_MODE, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Program the format register */
+
+ reg = snd_soc_read(codec, CS4270_FORMAT);
+ reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
+
+ switch (cs4270->mode) {
+ case SND_SOC_DAIFMT_I2S:
+ reg |= CS4270_FORMAT_DAC_I2S | CS4270_FORMAT_ADC_I2S;
+ break;
+ case SND_SOC_DAIFMT_LEFT_J:
+ reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
+ break;
+ default:
+ printk(KERN_ERR "cs4270: unknown format\n");
+ return -EINVAL;
+ }
+
+ ret = snd_soc_write(codec, CS4270_FORMAT, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Disable auto-mute. This feature appears to be buggy, because in
+ some situations, auto-mute will not deactivate when it should. */
+
+ reg = snd_soc_read(codec, CS4270_MUTE);
+ reg &= ~CS4270_MUTE_AUTO;
+ ret = snd_soc_write(codec, CS4270_MUTE, reg);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ /* Thaw and power-up the codec */
+
+ ret = snd_soc_write(codec, CS4270_PWRCTL, 0);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: I2C write failed\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
+
+/**
+ * Set the CS4270 external mute
+ *
+ * This function toggles the mute bits in the MUTE register. The CS4270's
+ * mute capability is intended for external muting circuitry, so if the
+ * board does not have the MUTEA or MUTEB pins connected to such circuitry,
+ * then this function will do nothing.
+ */
+static int cs4270_mute(struct snd_soc_codec_dai *dai, int mute)
+{
+ struct snd_soc_codec *codec = dai->codec;
+ int reg6;
+
+ reg6 = snd_soc_read(codec, CS4270_MUTE);
+
+ if (mute)
+ reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
+ CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
+ else
+ reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
+ CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
+
+ return snd_soc_write(codec, CS4270_MUTE, reg6);
+}
+
+#endif
+
+/**
+ * Sampling rate <-> bit patter mapping
+ *
+ * This array maps sampling rates to their SNDRV_PCM_RATE_x equivalent.
+ *
+ * This is really something that ALSA should provide.
+ *
+ * This table is used by cs4270_set_dai_sysclk() to tell ALSA which sampling
+ * rates the CS4270 currently supports.
+ */
+static struct {
+ unsigned int rate;
+ unsigned int bit;
+} rate_map[] = {
+ {5512, SNDRV_PCM_RATE_5512},
+ {8000, SNDRV_PCM_RATE_8000},
+ {11025, SNDRV_PCM_RATE_11025},
+ {16000, SNDRV_PCM_RATE_16000},
+ {22050, SNDRV_PCM_RATE_22050},
+ {32000, SNDRV_PCM_RATE_32000},
+ {44100, SNDRV_PCM_RATE_44100},
+ {48000, SNDRV_PCM_RATE_48000},
+ {64000, SNDRV_PCM_RATE_64000},
+ {88200, SNDRV_PCM_RATE_88200},
+ {96000, SNDRV_PCM_RATE_96000},
+ {176400, SNDRV_PCM_RATE_176400},
+ {192000, SNDRV_PCM_RATE_192000}
+};
+
+/**
+ * Determine the CS4270 samples rates.
+ *
+ * 'freq' is the input frequency to MCLK. The other parameters are ignored.
+ *
+ * The value of MCLK is used to determine which sample rates are supported
+ * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
+ * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
+ *
+ * This function calculates the nine ratios and determines which ones match
+ * a standard sample rate. If there's a match, then it is added to the list
+ * of support sample rates.
+ *
+ * This function must be called by the machine driver's 'startup' function,
+ * otherwise the list of supported sample rates will not be available in
+ * time for ALSA.
+ */
+static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+ int clk_id, unsigned int freq, int dir)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ unsigned int rates = 0, rate_min = -1, rate_max = 0, i, j;
+
+ cs4270->mclk = freq;
+
+ for (i=0; i<ARRAY_SIZE(cs4270_mode_ratios); i++) {
+ unsigned int rate;
+ rate = freq / cs4270_mode_ratios[i].ratio;
+ for (j = 0; j<ARRAY_SIZE(rate_map); j++) {
+ if (rate == rate_map[j].rate) {
+ rates |= rate_map[j].bit;
+ if (rate < rate_min)
+ rate_min = rate;
+ if (rate > rate_max)
+ rate_max = rate;
+ }
+ }
+ }
+
+ if (!rate_max) {
+ printk(KERN_ERR "cs4270: could not find a valid rate\n");
+ return -EINVAL;
+ }
+
+ codec_dai->playback.rates = rates;
+ codec_dai->playback.rate_min = rate_min;
+ codec_dai->playback.rate_max = rate_max;
+
+ codec_dai->capture.rates = rates;
+ codec_dai->capture.rate_min = rate_min;
+ codec_dai->capture.rate_max = rate_max;
+
+ return 0;
+}
+
+/**
+ * Configure the codec for the selected audio format
+ *
+ * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
+ * codec accordingly.
+ *
+ * Currently, this function only supports SND_SOC_DAIFMT_I2S and
+ * SND_SOC_DAIFMT_LEFT_J. The CS4270 codec also supports right-justified
+ * data for playback only, but ASoC currently does not support different
+ * formats for playback vs. record.
+ */
+static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+ unsigned int format)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ struct cs4270_private *cs4270 = codec->private_data;
+ int ret = 0;
+
+ switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
+ case SND_SOC_DAIFMT_I2S:
+ case SND_SOC_DAIFMT_LEFT_J:
+ cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
+ break;
+ default:
+ printk(KERN_ERR "cs4270: invalid DAI format\n");
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static int cs4270_i2c_probe(struct i2c_adapter *adap, int addr, int kind);
+
+/**
+ * Notify the driver that a new I2C bus has been found.
+ *
+ * This function is called for each I2C bus in the system. The function
+ * then asks the I2C subsystem to probe that bus at the addresses on which
+ * our device (the CS4270) could exist. If a device is found at one of
+ * those addresses, then our probe function (cs4270_i2c_probe) is called.
+ */
+static int cs4270_i2c_attach(struct i2c_adapter *adapter)
+{
+ return i2c_probe(adapter, &addr_data, cs4270_i2c_probe);
+}
+
+static int cs4270_i2c_detach(struct i2c_client *client)
+{
+ struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+ i2c_detach_client(client);
+ codec->control_data = NULL;
+
+ kfree(codec->reg_cache);
+ codec->reg_cache = NULL;
+
+ kfree(client);
+ return 0;
+}
+
+/* A list of non-DAPM controls that the CS4270 supports */
+static const struct snd_kcontrol_new cs4270_snd_controls[] = {
+ SOC_DOUBLE_R("Master Playback Volume", CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 0)
+};
+
+static struct i2c_driver cs4270_i2c_driver = {
+ .driver = {
+ .name = "CS4270 I2C",
+ .owner = THIS_MODULE,
+ },
+ .id = I2C_DRIVERID_CS4270,
+ .attach_adapter = cs4270_i2c_attach,
+ .detach_client = cs4270_i2c_detach,
+};
+
+/**
+ * Global variable to store socdev for i2c probe function.
+ *
+ * If struct i2c_driver had a private_data field, we wouldn't need to use
+ * cs4270_socdec. This is the only way to pass the socdev structure to
+ * cs4270_i2c_probe().
+ *
+ * The real solution to cs4270_socdev is to create a mechanism
+ * that maps I2C addresses to snd_soc_device structures. Perhaps the
+ * creation of the snd_soc_device object should be moved out of
+ * cs4270_probe() and into cs4270_i2c_probe(), but that would make this
+ * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby
+ * the chip is *not* connected to the I2C bus, but is instead configured via
+ * input pins.
+ */
+static struct snd_soc_device *cs4270_socdev;
+
+/**
+ * Initialize the I2C interface of the CS4270
+ *
+ * This function is called for whenever the I2C subsystem finds a device
+ * at a particular address.
+ *
+ * Note: snd_soc_new_pcms() must be called before this function can be called,
+ * because of snd_ctl_add().
+ */
+static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind)
+{
+ struct snd_soc_device *socdev = cs4270_socdev;
+ struct snd_soc_codec *codec = socdev->codec;
+ struct i2c_client *i2c_client = NULL;
+ int i, ret = 0;
+
+ /* Probing all possible addresses has one drawback: if there are
+ multiple CS4270s on the bus, then you cannot specify which
+ socdev is matched with which CS4270. For now, we just reject
+ this I2C device if the socdev already has one attached. */
+ if (codec->control_data) {
+ return -ENODEV;
+ }
+
+ /* Note: codec_dai->codec is NULL here */
+
+ i2c_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
+ if (!i2c_client) {
+ printk(KERN_ERR "cs4270: could not allocate I2C client\n");
+ return -ENOMEM;
+ }
+
+ codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL);
+ if (!codec->reg_cache) {
+ printk(KERN_ERR "cs4270: could not allocate register cache\n");
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ i2c_set_clientdata(i2c_client, codec);
+ strcpy(i2c_client->name, "CS4270");
+
+ i2c_client->driver = &cs4270_i2c_driver;
+ i2c_client->adapter = adapter;
+ i2c_client->addr = addr;
+
+ /* Verify that we have a CS4270 */
+
+ ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to read I2C\n");
+ goto error;
+ }
+ /* The top four bits of the chip ID should be 1100. */
+ if ((ret & 0xF0) != 0xC0) {
+ /* The device at this address is not a CS4270 codec */
+ ret = -ENODEV;
+ goto error;
+ }
+
+ printk(KERN_INFO "cs4270: found device at I2C address %X\n", addr);
+ printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF);
+
+ /* Tell the I2C layer a new client has arrived */
+
+ ret = i2c_attach_client(i2c_client);
+ if (ret) {
+ printk(KERN_ERR "cs4270: failed to attach codec at I2C addr %x\n", addr);
+ goto error;
+ }
+
+ codec->control_data = i2c_client;
+ codec->read = cs4270_read_reg_cache;
+ codec->write = cs4270_i2c_write;
+ codec->reg_cache_size = CS4270_NUMREGS;
+
+ /* The I2C interface is set up, so pre-fill our register cache */
+
+ ret = cs4270_fill_cache(codec);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to fill register cache\n");
+ goto error;
+ }
+
+ /* Add the non-DAPM controls */
+
+ for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) {
+ struct snd_kcontrol *kctrl =
+ snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL);
+
+ ret = snd_ctl_add(codec->card, kctrl);
+ if (ret < 0)
+ goto error;
+ }
+
+ return 0;
+
+error:
+ if (codec->control_data) {
+ i2c_detach_client(i2c_client);
+ codec->control_data = NULL;
+ }
+
+ kfree(codec->reg_cache);
+ codec->reg_cache = NULL;
+ codec->reg_cache_size = 0;
+
+ kfree(i2c_client);
+
+ return ret;
+}
+
+#endif
+
+struct snd_soc_codec_dai cs4270_dai = {
+ .name = "CS4270",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = 0,
+ .formats = CS4270_FORMATS,
+ },
+ .capture = {
+ .stream_name = "Capture",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = 0,
+ .formats = CS4270_FORMATS,
+ },
+ .dai_ops = {
+ .set_sysclk = cs4270_set_dai_sysclk,
+ .set_fmt = cs4270_set_dai_fmt,
+ }
+};
+EXPORT_SYMBOL_GPL(cs4270_dai);
+
+/**
+ * ASoC probe function
+ *
+ * This function is called when the machine driver calls
+ * platform_device_add().
+ */
+static int cs4270_probe(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec;
+ int ret = 0;
+
+ printk(KERN_INFO "CS4270 ALSA SoC Codec\n");
+
+ /* Allocate enough space for the snd_soc_codec structure
+ and our private data together. */
+ codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) +
+ sizeof(struct cs4270_private), GFP_KERNEL);
+ if (!codec) {
+ printk(KERN_ERR "cs4270: Could not allocate codec structure.\n");
+ return -ENOMEM;
+ }
+
+ mutex_init(&codec->mutex);
+ INIT_LIST_HEAD(&codec->dapm_widgets);
+ INIT_LIST_HEAD(&codec->dapm_paths);
+
+ codec->name = "CS4270";
+ codec->owner = THIS_MODULE;
+ codec->dai = &cs4270_dai;
+ codec->num_dai = 1;
+ codec->private_data = codec + ALIGN(sizeof(struct snd_soc_codec), 4);
+
+ socdev->codec = codec;
+
+ /* Register PCMs */
+
+ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to create PCMs\n");
+ return ret;
+ }
+
+#ifdef CONFIG_I2C
+ cs4270_socdev = socdev;
+
+ ret = i2c_add_driver(&cs4270_i2c_driver);
+ if (ret) {
+ printk(KERN_ERR "cs4270: failed to attach driver");
+ snd_soc_free_pcms(socdev);
+ return ret;
+ }
+
+ /* Did we find a CS4270 on the I2C bus? */
+ if (codec->control_data) {
+ /* Initialize codec ops */
+ cs4270_dai.ops.hw_params = cs4270_hw_params;
+#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
+ cs4270_dai.dai_ops.digital_mute = cs4270_mute;
+#endif
+ } else {
+ printk(KERN_INFO "cs4270: no I2C device found, using stand-alone mode\n");
+ }
+#else
+ printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n");
+#endif
+
+ ret = snd_soc_register_card(socdev);
+ if (ret < 0) {
+ printk(KERN_ERR "cs4270: failed to register card\n");
+ snd_soc_free_pcms(socdev);
+ return ret;
+ }
+
+ return ret;
+}
+
+static int cs4270_remove(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+ snd_soc_free_pcms(socdev);
+
+#ifdef CONFIG_I2C
+ if (socdev->codec->control_data)
+ i2c_del_driver(&cs4270_i2c_driver);
+#endif
+
+ kfree(socdev->codec);
+ socdev->codec = NULL;
+
+ return 0;
+}
+
+/**
+ * ASoC codec device structure
+ *
+ * Assign this variable to the codec_dev field of the machine driver's
+ * snd_soc_device structure.
+ */
+struct snd_soc_codec_device soc_codec_device_cs4270 = {
+ .probe = cs4270_probe,
+ .remove = cs4270_remove
+};
+EXPORT_SYMBOL_GPL(soc_codec_device_cs4270);
+
+MODULE_AUTHOR("Timur Tabi <timur(a)freescale.com>");
+MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs4270.h b/sound/soc/codecs/cs4270.h
new file mode 100644
index 0000000..35e5fe3
--- /dev/null
+++ b/sound/soc/codecs/cs4270.h
@@ -0,0 +1,28 @@
+/*
+ * Cirrus Logic CS4270 ALSA SoC Codec Driver
+ *
+ * Author: Timur Tabi <timur(a)freescale.com>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#ifndef _CS4270_H
+#define _CS4270_H
+
+/**
+ * The ASoC codec DAI structure for the CS4270. Assign this structure to
+ * the .codec_dai field of your machine driver's snd_soc_dai_link structure.
+ */
+extern struct snd_soc_codec_dai cs4270_dai;
+
+/**
+ * The ASoC codec device structure for the CS4270. Assign this structure
+ * to the .codec_dev field of your machine driver's snd_soc_device
+ * structure.
+ */
+extern struct snd_soc_codec_device soc_codec_device_cs4270;
+
+#endif
--
1.5.2.4
2
2
30 Jul '07
Hi All,
we want to use alsa library for arm platform.
while configuration we specified option for shared library.
but its alwaye creating static library after compilation.
when we build the test application pcm_min.c we got the
following error.
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0x194): In function
`snd_pcm_ladspa_free_plugins':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:188:
undefined reference to `dlclose'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0xd28): In function
`snd_pcm_ladspa_connect_controls':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:515:
undefined reference to `log'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0xd50):/home/susovan/alsa/lib/
alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:515: undefined reference to `log'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0xd74):/home/susovan/alsa/lib/
alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:536: undefined reference to `exp'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0xd9c):/home/susovan/alsa/lib/
alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:526: undefined reference to `sqrtf'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0xdac):/home/susovan/alsa/lib/
alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:536: undefined reference to `log'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0xdd4):/home/susovan/alsa/lib/
alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:536: undefined reference to `log'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0x1fac): In function
`snd_pcm_ladspa_check_file':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:1087:
undefined reference to `dlopen'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0x1fc0):/home/susovan/alsa/lib
/alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:1089: undefined reference to
`dlsym'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0x20b8):/home/susovan/alsa/lib
/alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:1132: undefined reference to
`dlclose'
/usr/lib_alsa/libasound.a(pcm_ladspa.o)(.text+0x20e0):/home/susovan/alsa/lib
/alsa-lib-1.0.14rc4/src/pcm/pcm_ladspa.c:1124: undefined reference to
`dlclose'
/usr/lib_alsa/libasound.a(dlmisc.o)(.text+0xc): In function `snd_dlopen':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/dlmisc.c:64: undefined
reference to `dlopen'
/usr/lib_alsa/libasound.a(dlmisc.o)(.text+0x24): In function `snd_dlclose':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/dlmisc.c:85: undefined
reference to `dlclose'
/usr/lib_alsa/libasound.a(dlmisc.o)(.text+0xa8): In function
`snd_dlsym_verify':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/dlmisc.c:115: undefined
reference to `dlsym'
/usr/lib_alsa/libasound.a(dlmisc.o)(.text+0x144): In function `snd_dlsym':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/dlmisc.c:161: undefined
reference to `dlsym'
/usr/lib_alsa/libasound.a(pcm_meter.o)(.text+0x74c): In function
`snd_pcm_meter_avail_update':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_meter.c:106: undefined
reference to `pthread_mutex_trylock'
/usr/lib_alsa/libasound.a(pcm_meter.o)(.text+0xa54): In function
`snd_pcm_meter_hw_params':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_meter.c:470: undefined
reference to `pthread_create'
/usr/lib_alsa/libasound.a(pcm_meter.o)(.text+0xaec): In function
`snd_pcm_meter_hw_free':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_meter.c:483: undefined
reference to `pthread_join'
/usr/lib_alsa/libasound.a(pcm_meter.o)(.text+0xf84): In function
`snd_pcm_meter_add_scope_conf':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_meter.c:664: undefined
reference to `dlsym'
/usr/lib_alsa/libasound.a(pcm_route.o)(.text+0x12c8): In function
`snd_pcm_route_convert1_many':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_route.c:453: undefined
reference to `rint'
/usr/lib_alsa/libasound.a(pcm_share.o)(.text+0x1dd0): In function
`snd_pcm_share_close':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_share.c:1243:
undefined reference to `pthread_join'
/usr/lib_alsa/libasound.a(pcm_share.o)(.text+0x21b8): In function
`snd_pcm_share_open':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_share.c:1474:
undefined reference to `pthread_create'
/usr/lib_alsa/libasound.a(pcm_softvol.o)(.text+0x18a4): In function
`softvol_load_control':
/home/susovan/alsa/lib/alsa-lib-1.0.14rc4/src/pcm/pcm_softvol.c:665:
undefined reference to `pow'
we tried with the following releases-
1)alsa-lib-1.0.14
2) alsa-lib-1.0.14a
3)alsa-lib-1.0.14rc4
But when we tried to build alsa shared library for x68 platform we did not
face
this problem , but when we built the alsa static library for x86 and tried
to compile the
test application we face the above "undefine reference " error.
Can any one help me to understand and solve this problem?
Thank you
Susovan Ghosh
Engineer (D&D )
PRDE
Ph No:-998667320
Bangalore-560048
2
1
Hi All,
I am new to alsa , I am using the Texas Instrument Davinci
Board (ARM arch) with linux-2.6.10 with alsa lib 1.0.6,
ALSA was working fine the sound was good,Then I changed the
kernel to 2.6.20 with out changeing the alsa lib
no when play sound I get humming sound/distorted sound I have
few question,
1 .Does I need to change the alsa lib also
2 .Does I need to change/ Select addtional option's in kernel(I have
copied the linux-2.6.10/.config file to linux-2.6.20)
Can any please point me where I went wrong
2
1
[alsa-devel] Patch: HDA-Codec: Add support for the ASRock K8NF6G-VSTA motherboard.
by Tobin Davis 30 Jul '07
by Tobin Davis 30 Jul '07
30 Jul '07
This patch adds ALC861VD support for the ASRock K8NF6G-VSTA motherboard.
Signed off by Tobin Davis <tdavis(a)dsl-only.net>
2
1
From: Yoichi Yuasa <yoichi_yuasa(a)tripeaks.co.jp>
Signed-off-by: Yoichi Yuasa <yoichi_yuasa(a)tripeaks.co.jp>
Signed-off-by: Ralf Baechle <ralf(a)linux-mips.org>
drivers/net/tulip/tulip_core.c | 8
drivers/serial/8250_pci.c | 20
include/linux/pci_ids.h | 1
sound/oss/Kconfig | 8
sound/oss/Makefile | 1
sound/oss/nec_vrc5477.c | 2060 -----------------------------------------
6 files changed, 2098 deletions(-)
Index: upstream-linus/drivers/net/tulip/tulip_core.c
===================================================================
--- upstream-linus.orig/drivers/net/tulip/tulip_core.c
+++ upstream-linus/drivers/net/tulip/tulip_core.c
@@ -1471,14 +1471,6 @@ static int __devinit tulip_init_one (str
sa_offset = 2; /* Grrr, damn Matrox boards. */
multiport_cnt = 4;
}
-#ifdef CONFIG_DDB5477
- if ((pdev->bus->number == 0) && (PCI_SLOT(pdev->devfn) == 4)) {
- /* DDB5477 MAC address in first EEPROM locations. */
- sa_offset = 0;
- /* No media table either */
- tp->flags &= ~HAS_MEDIA_TABLE;
- }
-#endif
#ifdef CONFIG_MIPS_COBALT
if ((pdev->bus->number == 0) &&
((PCI_SLOT(pdev->devfn) == 7) ||
Index: upstream-linus/drivers/serial/8250_pci.c
===================================================================
--- upstream-linus.orig/drivers/serial/8250_pci.c
+++ upstream-linus/drivers/serial/8250_pci.c
@@ -976,7 +976,6 @@ enum pci_board_num_t {
pbn_oxsemi,
pbn_intel_i960,
pbn_sgi_ioc3,
- pbn_nec_nile4,
pbn_computone_4,
pbn_computone_6,
pbn_computone_8,
@@ -1443,18 +1442,6 @@ static struct pciserial_board pci_boards
},
/*
- * NEC Vrc-5074 (Nile 4) builtin UART.
- */
- [pbn_nec_nile4] = {
- .flags = FL_BASE0,
- .num_ports = 1,
- .base_baud = 520833,
- .uart_offset = 8 << 3,
- .reg_shift = 3,
- .first_offset = 0x300,
- },
-
- /*
* Computone - uses IOMEM.
*/
[pbn_computone_4] = {
@@ -2345,13 +2332,6 @@ static struct pci_device_id serial_pci_t
PCI_ANY_ID, PCI_ANY_ID, 0, 0,
pbn_b2_1_115200 },
- /*
- * NEC Vrc-5074 (Nile 4) builtin UART.
- */
- { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_NILE4,
- PCI_ANY_ID, PCI_ANY_ID, 0, 0,
- pbn_nec_nile4 },
-
{ PCI_VENDOR_ID_DCI, PCI_DEVICE_ID_DCI_PCCOM2,
PCI_ANY_ID, PCI_ANY_ID, 0, 0,
pbn_b3_2_115200 },
Index: upstream-linus/sound/oss/Kconfig
===================================================================
--- upstream-linus.orig/sound/oss/Kconfig
+++ upstream-linus/sound/oss/Kconfig
@@ -31,14 +31,6 @@ config SOUND_HAL2
Say Y or M if you have an SGI Indy or Indigo2 system and want to be able to
use its on-board A2 audio system.
-config SOUND_VRC5477
- tristate "NEC Vrc5477 AC97 sound"
- depends on SOUND_PRIME && DDB5477
- help
- Say Y here to enable sound support for the NEC Vrc5477 chip, an
- integrated, multi-function controller chip for MIPS CPUs. Works
- with the AC97 codec.
-
config SOUND_AU1550_AC97
tristate "Au1550/Au1200 AC97 Sound"
select SND_AC97_CODEC
Index: upstream-linus/sound/oss/Makefile
===================================================================
--- upstream-linus.orig/sound/oss/Makefile
+++ upstream-linus/sound/oss/Makefile
@@ -37,7 +37,6 @@ obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o ms
obj-$(CONFIG_SOUND_VWSND) += vwsnd.o
obj-$(CONFIG_SOUND_ICH) += i810_audio.o ac97_codec.o
obj-$(CONFIG_SOUND_ES1371) += es1371.o ac97_codec.o
-obj-$(CONFIG_SOUND_VRC5477) += nec_vrc5477.o ac97_codec.o
obj-$(CONFIG_SOUND_AU1550_AC97) += au1550_ac97.o ac97_codec.o
obj-$(CONFIG_SOUND_TRIDENT) += trident.o ac97_codec.o
obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o
Index: upstream-linus/sound/oss/nec_vrc5477.c
===================================================================
--- upstream-linus.orig/sound/oss/nec_vrc5477.c
+++ /dev/null
@@ -1,2060 +0,0 @@
-/***********************************************************************
- * Copyright 2001 MontaVista Software Inc.
- * Author: Jun Sun, jsun(a)mvista.com or jsun(a)junsun.net
- *
- * drivers/sound/nec_vrc5477.c
- * AC97 sound dirver for NEC Vrc5477 chip (an integrated,
- * multi-function controller chip for MIPS CPUs)
- *
- * VRA support Copyright 2001 Bradley D. LaRonde <brad(a)ltc.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.
- ***********************************************************************
- */
-
-/*
- * This code is derived from ite8172.c, which is written by Steve Longerbeam.
- *
- * Features:
- * Currently we only support the following capabilities:
- * . mono output to PCM L/R (line out).
- * . stereo output to PCM L/R (line out).
- * . mono input from PCM L (line in).
- * . stereo output from PCM (line in).
- * . sampling rate at 48k or variable sampling rate
- * . support /dev/dsp, /dev/mixer devices, standard OSS devices.
- * . only support 16-bit PCM format (hardware limit, no software
- * translation)
- * . support duplex, but no trigger or realtime.
- *
- * Specifically the following are not supported:
- * . app-set frag size.
- * . mmap'ed buffer access
- */
-
-/*
- * Original comments from ite8172.c file.
- */
-
-/*
- *
- * Notes:
- *
- * 1. Much of the OSS buffer allocation, ioctl's, and mmap'ing are
- * taken, slightly modified or not at all, from the ES1371 driver,
- * so refer to the credits in es1371.c for those. The rest of the
- * code (probe, open, read, write, the ISR, etc.) is new.
- * 2. The following support is untested:
- * * Memory mapping the audio buffers, and the ioctl controls that go
- * with it.
- * * S/PDIF output.
- * 3. The following is not supported:
- * * I2S input.
- * * legacy audio mode.
- * 4. Support for volume button interrupts is implemented but doesn't
- * work yet.
- *
- * Revision history
- * 02.08.2001 0.1 Initial release
- */
-
-#include <linux/module.h>
-#include <linux/string.h>
-#include <linux/kernel.h>
-#include <linux/ioport.h>
-#include <linux/sched.h>
-#include <linux/delay.h>
-#include <linux/sound.h>
-#include <linux/slab.h>
-#include <linux/soundcard.h>
-#include <linux/pci.h>
-#include <linux/init.h>
-#include <linux/poll.h>
-#include <linux/bitops.h>
-#include <linux/proc_fs.h>
-#include <linux/spinlock.h>
-#include <linux/smp_lock.h>
-#include <linux/ac97_codec.h>
-#include <linux/mutex.h>
-
-#include <asm/io.h>
-#include <asm/dma.h>
-#include <asm/uaccess.h>
-
-/* -------------------debug macros -------------------------------------- */
-/* #undef VRC5477_AC97_DEBUG */
-#define VRC5477_AC97_DEBUG
-
-#undef VRC5477_AC97_VERBOSE_DEBUG
-/* #define VRC5477_AC97_VERBOSE_DEBUG */
-
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
-#define VRC5477_AC97_DEBUG
-#endif
-
-#if defined(VRC5477_AC97_DEBUG)
-#define ASSERT(x) if (!(x)) { \
- panic("assertion failed at %s:%d: %s\n", __FILE__, __LINE__, #x); }
-#else
-#define ASSERT(x)
-#endif /* VRC5477_AC97_DEBUG */
-
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
-static u16 inTicket; /* check sync between intr & write */
-static u16 outTicket;
-#endif
-
-/* --------------------------------------------------------------------- */
-
-#undef OSS_DOCUMENTED_MIXER_SEMANTICS
-
-static const unsigned sample_shift[] = { 0, 1, 1, 2 };
-
-#define VRC5477_INT_CLR 0x0
-#define VRC5477_INT_STATUS 0x0
-#define VRC5477_CODEC_WR 0x4
-#define VRC5477_CODEC_RD 0x8
-#define VRC5477_CTRL 0x18
-#define VRC5477_ACLINK_CTRL 0x1c
-#define VRC5477_INT_MASK 0x24
-
-#define VRC5477_DAC1_CTRL 0x30
-#define VRC5477_DAC1L 0x34
-#define VRC5477_DAC1_BADDR 0x38
-#define VRC5477_DAC2_CTRL 0x3c
-#define VRC5477_DAC2L 0x40
-#define VRC5477_DAC2_BADDR 0x44
-#define VRC5477_DAC3_CTRL 0x48
-#define VRC5477_DAC3L 0x4c
-#define VRC5477_DAC3_BADDR 0x50
-
-#define VRC5477_ADC1_CTRL 0x54
-#define VRC5477_ADC1L 0x58
-#define VRC5477_ADC1_BADDR 0x5c
-#define VRC5477_ADC2_CTRL 0x60
-#define VRC5477_ADC2L 0x64
-#define VRC5477_ADC2_BADDR 0x68
-#define VRC5477_ADC3_CTRL 0x6c
-#define VRC5477_ADC3L 0x70
-#define VRC5477_ADC3_BADDR 0x74
-
-#define VRC5477_CODEC_WR_RWC (1 << 23)
-
-#define VRC5477_CODEC_RD_RRDYA (1 << 31)
-#define VRC5477_CODEC_RD_RRDYD (1 << 30)
-
-#define VRC5477_ACLINK_CTRL_RST_ON (1 << 15)
-#define VRC5477_ACLINK_CTRL_RST_TIME 0x7f
-#define VRC5477_ACLINK_CTRL_SYNC_ON (1 << 30)
-#define VRC5477_ACLINK_CTRL_CK_STOP_ON (1 << 31)
-
-#define VRC5477_CTRL_DAC2ENB (1 << 15)
-#define VRC5477_CTRL_ADC2ENB (1 << 14)
-#define VRC5477_CTRL_DAC1ENB (1 << 13)
-#define VRC5477_CTRL_ADC1ENB (1 << 12)
-
-#define VRC5477_INT_MASK_NMASK (1 << 31)
-#define VRC5477_INT_MASK_DAC1END (1 << 5)
-#define VRC5477_INT_MASK_DAC2END (1 << 4)
-#define VRC5477_INT_MASK_DAC3END (1 << 3)
-#define VRC5477_INT_MASK_ADC1END (1 << 2)
-#define VRC5477_INT_MASK_ADC2END (1 << 1)
-#define VRC5477_INT_MASK_ADC3END (1 << 0)
-
-#define VRC5477_DMA_ACTIVATION (1 << 31)
-#define VRC5477_DMA_WIP (1 << 30)
-
-
-#define VRC5477_AC97_MODULE_NAME "NEC_Vrc5477_audio"
-#define PFX VRC5477_AC97_MODULE_NAME ": "
-
-/* --------------------------------------------------------------------- */
-
-struct vrc5477_ac97_state {
- /* list of vrc5477_ac97 devices */
- struct list_head devs;
-
- /* the corresponding pci_dev structure */
- struct pci_dev *dev;
-
- /* soundcore stuff */
- int dev_audio;
-
- /* hardware resources */
- unsigned long io;
- unsigned int irq;
-
-#ifdef VRC5477_AC97_DEBUG
- /* debug /proc entry */
- struct proc_dir_entry *ps;
- struct proc_dir_entry *ac97_ps;
-#endif /* VRC5477_AC97_DEBUG */
-
- struct ac97_codec *codec;
-
- unsigned dacChannels, adcChannels;
- unsigned short dacRate, adcRate;
- unsigned short extended_status;
-
- spinlock_t lock;
- struct mutex open_mutex;
- mode_t open_mode;
- wait_queue_head_t open_wait;
-
- struct dmabuf {
- void *lbuf, *rbuf;
- dma_addr_t lbufDma, rbufDma;
- unsigned bufOrder;
- unsigned numFrag;
- unsigned fragShift;
- unsigned fragSize; /* redundant */
- unsigned fragTotalSize; /* = numFrag * fragSize(real) */
- unsigned nextIn;
- unsigned nextOut;
- int count;
- unsigned error; /* over/underrun */
- wait_queue_head_t wait;
- /* OSS stuff */
- unsigned stopped:1;
- unsigned ready:1;
- } dma_dac, dma_adc;
-
- #define WORK_BUF_SIZE 2048
- struct {
- u16 lchannel;
- u16 rchannel;
- } workBuf[WORK_BUF_SIZE/4];
-};
-
-/* --------------------------------------------------------------------- */
-
-static LIST_HEAD(devs);
-
-/* --------------------------------------------------------------------- */
-
-static inline unsigned ld2(unsigned int x)
-{
- unsigned r = 0;
-
- if (x >= 0x10000) {
- x >>= 16;
- r += 16;
- }
- if (x >= 0x100) {
- x >>= 8;
- r += 8;
- }
- if (x >= 0x10) {
- x >>= 4;
- r += 4;
- }
- if (x >= 4) {
- x >>= 2;
- r += 2;
- }
- if (x >= 2)
- r++;
- return r;
-}
-
-/* --------------------------------------------------------------------- */
-
-static u16 rdcodec(struct ac97_codec *codec, u8 addr)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)codec->private_data;
- unsigned long flags;
- u32 result;
-
- spin_lock_irqsave(&s->lock, flags);
-
- /* wait until we can access codec registers */
- while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
-
- /* write the address and "read" command to codec */
- addr = addr & 0x7f;
- outl((addr << 16) | VRC5477_CODEC_WR_RWC, s->io + VRC5477_CODEC_WR);
-
- /* get the return result */
- udelay(100); /* workaround hardware bug */
- while ( (result = inl(s->io + VRC5477_CODEC_RD)) &
- (VRC5477_CODEC_RD_RRDYA | VRC5477_CODEC_RD_RRDYD) ) {
- /* we get either addr or data, or both */
- if (result & VRC5477_CODEC_RD_RRDYA) {
- ASSERT(addr == ((result >> 16) & 0x7f) );
- }
- if (result & VRC5477_CODEC_RD_RRDYD) {
- break;
- }
- }
-
- spin_unlock_irqrestore(&s->lock, flags);
-
- return result & 0xffff;
-}
-
-
-static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)codec->private_data;
- unsigned long flags;
-
- spin_lock_irqsave(&s->lock, flags);
-
- /* wait until we can access codec registers */
- while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
-
- /* write the address and value to codec */
- outl((addr << 16) | data, s->io + VRC5477_CODEC_WR);
-
- spin_unlock_irqrestore(&s->lock, flags);
-}
-
-
-static void waitcodec(struct ac97_codec *codec)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)codec->private_data;
-
- /* wait until we can access codec registers */
- while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
-}
-
-static int ac97_codec_not_present(struct ac97_codec *codec)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)codec->private_data;
- unsigned long flags;
- unsigned short count = 0xffff;
-
- spin_lock_irqsave(&s->lock, flags);
-
- /* wait until we can access codec registers */
- do {
- if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
- break;
- } while (--count);
-
- if (count == 0) {
- spin_unlock_irqrestore(&s->lock, flags);
- return -1;
- }
-
- /* write 0 to reset */
- outl((AC97_RESET << 16) | 0, s->io + VRC5477_CODEC_WR);
-
- /* test whether we get a response from ac97 chip */
- count = 0xffff;
- do {
- if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
- break;
- } while (--count);
-
- if (count == 0) {
- spin_unlock_irqrestore(&s->lock, flags);
- return -1;
- }
- spin_unlock_irqrestore(&s->lock, flags);
- return 0;
-}
-
-/* --------------------------------------------------------------------- */
-
-static void vrc5477_ac97_delay(int msec)
-{
- unsigned long tmo;
- signed long tmo2;
-
- if (in_interrupt())
- return;
-
- tmo = jiffies + (msec*HZ)/1000;
- for (;;) {
- tmo2 = tmo - jiffies;
- if (tmo2 <= 0)
- break;
- schedule_timeout(tmo2);
- }
-}
-
-
-static void set_adc_rate(struct vrc5477_ac97_state *s, unsigned rate)
-{
- wrcodec(s->codec, AC97_PCM_LR_ADC_RATE, rate);
- s->adcRate = rate;
-}
-
-
-static void set_dac_rate(struct vrc5477_ac97_state *s, unsigned rate)
-{
- if(s->extended_status & AC97_EXTSTAT_VRA) {
- wrcodec(s->codec, AC97_PCM_FRONT_DAC_RATE, rate);
- s->dacRate = rdcodec(s->codec, AC97_PCM_FRONT_DAC_RATE);
- }
-}
-
-static int ac97_codec_not_present(struct ac97_codec *codec)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)codec->private_data;
- unsigned long flags;
- unsigned short count = 0xffff;
-
- spin_lock_irqsave(&s->lock, flags);
-
- /* wait until we can access codec registers */
- do {
- if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
- break;
- } while (--count);
-
- if (count == 0) {
- spin_unlock_irqrestore(&s->lock, flags);
- return -1;
- }
-
- /* write 0 to reset */
- outl((AC97_RESET << 16) | 0, s->io + VRC5477_CODEC_WR);
-
- /* test whether we get a response from ac97 chip */
- count = 0xffff;
- do {
- if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
- break;
- } while (--count);
-
- if (count == 0) {
- spin_unlock_irqrestore(&s->lock, flags);
- return -1;
- }
- spin_unlock_irqrestore(&s->lock, flags);
- return 0;
-}
-
-/* --------------------------------------------------------------------- */
-
-static inline void
-stop_dac(struct vrc5477_ac97_state *s)
-{
- struct dmabuf* db = &s->dma_dac;
- unsigned long flags;
- u32 temp;
-
- spin_lock_irqsave(&s->lock, flags);
-
- if (db->stopped) {
- spin_unlock_irqrestore(&s->lock, flags);
- return;
- }
-
- /* deactivate the dma */
- outl(0, s->io + VRC5477_DAC1_CTRL);
- outl(0, s->io + VRC5477_DAC2_CTRL);
-
- /* wait for DAM completely stop */
- while (inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
- while (inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
-
- /* disable dac slots in aclink */
- temp = inl(s->io + VRC5477_CTRL);
- temp &= ~ (VRC5477_CTRL_DAC1ENB | VRC5477_CTRL_DAC2ENB);
- outl (temp, s->io + VRC5477_CTRL);
-
- /* disable interrupts */
- temp = inl(s->io + VRC5477_INT_MASK);
- temp &= ~ (VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END);
- outl (temp, s->io + VRC5477_INT_MASK);
-
- /* clear pending ones */
- outl(VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END,
- s->io + VRC5477_INT_CLR);
-
- db->stopped = 1;
-
- spin_unlock_irqrestore(&s->lock, flags);
-}
-
-static void start_dac(struct vrc5477_ac97_state *s)
-{
- struct dmabuf* db = &s->dma_dac;
- unsigned long flags;
- u32 dmaLength;
- u32 temp;
-
- spin_lock_irqsave(&s->lock, flags);
-
- if (!db->stopped) {
- spin_unlock_irqrestore(&s->lock, flags);
- return;
- }
-
- /* we should have some data to do the DMA trasnfer */
- ASSERT(db->count >= db->fragSize);
-
- /* clear pending fales interrupts */
- outl(VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END,
- s->io + VRC5477_INT_CLR);
-
- /* enable interrupts */
- temp = inl(s->io + VRC5477_INT_MASK);
- temp |= VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END;
- outl(temp, s->io + VRC5477_INT_MASK);
-
- /* setup dma base addr */
- outl(db->lbufDma + db->nextOut, s->io + VRC5477_DAC1_BADDR);
- if (s->dacChannels == 1) {
- outl(db->lbufDma + db->nextOut, s->io + VRC5477_DAC2_BADDR);
- } else {
- outl(db->rbufDma + db->nextOut, s->io + VRC5477_DAC2_BADDR);
- }
-
- /* set dma length, in the unit of 0x10 bytes */
- dmaLength = db->fragSize >> 4;
- outl(dmaLength, s->io + VRC5477_DAC1L);
- outl(dmaLength, s->io + VRC5477_DAC2L);
-
- /* activate dma */
- outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_DAC1_CTRL);
- outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_DAC2_CTRL);
-
- /* enable dac slots - we should hear the music now! */
- temp = inl(s->io + VRC5477_CTRL);
- temp |= (VRC5477_CTRL_DAC1ENB | VRC5477_CTRL_DAC2ENB);
- outl (temp, s->io + VRC5477_CTRL);
-
- /* it is time to setup next dma transfer */
- ASSERT(inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
- ASSERT(inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
-
- temp = db->nextOut + db->fragSize;
- if (temp >= db->fragTotalSize) {
- ASSERT(temp == db->fragTotalSize);
- temp = 0;
- }
-
- outl(db->lbufDma + temp, s->io + VRC5477_DAC1_BADDR);
- if (s->dacChannels == 1) {
- outl(db->lbufDma + temp, s->io + VRC5477_DAC2_BADDR);
- } else {
- outl(db->rbufDma + temp, s->io + VRC5477_DAC2_BADDR);
- }
-
- db->stopped = 0;
-
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
- outTicket = *(u16*)(db->lbuf+db->nextOut);
- if (db->count > db->fragSize) {
- ASSERT((u16)(outTicket+1) == *(u16*)(db->lbuf+temp));
- }
-#endif
-
- spin_unlock_irqrestore(&s->lock, flags);
-}
-
-static inline void stop_adc(struct vrc5477_ac97_state *s)
-{
- struct dmabuf* db = &s->dma_adc;
- unsigned long flags;
- u32 temp;
-
- spin_lock_irqsave(&s->lock, flags);
-
- if (db->stopped) {
- spin_unlock_irqrestore(&s->lock, flags);
- return;
- }
-
- /* deactivate the dma */
- outl(0, s->io + VRC5477_ADC1_CTRL);
- outl(0, s->io + VRC5477_ADC2_CTRL);
-
- /* disable adc slots in aclink */
- temp = inl(s->io + VRC5477_CTRL);
- temp &= ~ (VRC5477_CTRL_ADC1ENB | VRC5477_CTRL_ADC2ENB);
- outl (temp, s->io + VRC5477_CTRL);
-
- /* disable interrupts */
- temp = inl(s->io + VRC5477_INT_MASK);
- temp &= ~ (VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END);
- outl (temp, s->io + VRC5477_INT_MASK);
-
- /* clear pending ones */
- outl(VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END,
- s->io + VRC5477_INT_CLR);
-
- db->stopped = 1;
-
- spin_unlock_irqrestore(&s->lock, flags);
-}
-
-static void start_adc(struct vrc5477_ac97_state *s)
-{
- struct dmabuf* db = &s->dma_adc;
- unsigned long flags;
- u32 dmaLength;
- u32 temp;
-
- spin_lock_irqsave(&s->lock, flags);
-
- if (!db->stopped) {
- spin_unlock_irqrestore(&s->lock, flags);
- return;
- }
-
- /* we should at least have some free space in the buffer */
- ASSERT(db->count < db->fragTotalSize - db->fragSize * 2);
-
- /* clear pending ones */
- outl(VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END,
- s->io + VRC5477_INT_CLR);
-
- /* enable interrupts */
- temp = inl(s->io + VRC5477_INT_MASK);
- temp |= VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END;
- outl(temp, s->io + VRC5477_INT_MASK);
-
- /* setup dma base addr */
- outl(db->lbufDma + db->nextIn, s->io + VRC5477_ADC1_BADDR);
- outl(db->rbufDma + db->nextIn, s->io + VRC5477_ADC2_BADDR);
-
- /* setup dma length */
- dmaLength = db->fragSize >> 4;
- outl(dmaLength, s->io + VRC5477_ADC1L);
- outl(dmaLength, s->io + VRC5477_ADC2L);
-
- /* activate dma */
- outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_ADC1_CTRL);
- outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_ADC2_CTRL);
-
- /* enable adc slots */
- temp = inl(s->io + VRC5477_CTRL);
- temp |= (VRC5477_CTRL_ADC1ENB | VRC5477_CTRL_ADC2ENB);
- outl (temp, s->io + VRC5477_CTRL);
-
- /* it is time to setup next dma transfer */
- temp = db->nextIn + db->fragSize;
- if (temp >= db->fragTotalSize) {
- ASSERT(temp == db->fragTotalSize);
- temp = 0;
- }
- outl(db->lbufDma + temp, s->io + VRC5477_ADC1_BADDR);
- outl(db->rbufDma + temp, s->io + VRC5477_ADC2_BADDR);
-
- db->stopped = 0;
-
- spin_unlock_irqrestore(&s->lock, flags);
-}
-
-/* --------------------------------------------------------------------- */
-
-#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
-#define DMABUF_MINORDER 1
-
-static inline void dealloc_dmabuf(struct vrc5477_ac97_state *s,
- struct dmabuf *db)
-{
- if (db->lbuf) {
- ASSERT(db->rbuf);
- pci_free_consistent(s->dev, PAGE_SIZE << db->bufOrder,
- db->lbuf, db->lbufDma);
- pci_free_consistent(s->dev, PAGE_SIZE << db->bufOrder,
- db->rbuf, db->rbufDma);
- db->lbuf = db->rbuf = NULL;
- }
- db->nextIn = db->nextOut = 0;
- db->ready = 0;
-}
-
-static int prog_dmabuf(struct vrc5477_ac97_state *s,
- struct dmabuf *db,
- unsigned rate)
-{
- int order;
- unsigned bufsize;
-
- if (!db->lbuf) {
- ASSERT(!db->rbuf);
-
- db->ready = 0;
- for (order = DMABUF_DEFAULTORDER;
- order >= DMABUF_MINORDER;
- order--) {
- db->lbuf = pci_alloc_consistent(s->dev,
- PAGE_SIZE << order,
- &db->lbufDma);
- db->rbuf = pci_alloc_consistent(s->dev,
- PAGE_SIZE << order,
- &db->rbufDma);
- if (db->lbuf && db->rbuf) break;
- if (db->lbuf) {
- ASSERT(!db->rbuf);
- pci_free_consistent(s->dev,
- PAGE_SIZE << order,
- db->lbuf,
- db->lbufDma);
- }
- }
- if (!db->lbuf) {
- ASSERT(!db->rbuf);
- return -ENOMEM;
- }
-
- db->bufOrder = order;
- }
-
- db->count = 0;
- db->nextIn = db->nextOut = 0;
-
- bufsize = PAGE_SIZE << db->bufOrder;
- db->fragShift = ld2(rate * 2 / 100);
- if (db->fragShift < 4) db->fragShift = 4;
-
- db->numFrag = bufsize >> db->fragShift;
- while (db->numFrag < 4 && db->fragShift > 4) {
- db->fragShift--;
- db->numFrag = bufsize >> db->fragShift;
- }
- db->fragSize = 1 << db->fragShift;
- db->fragTotalSize = db->numFrag << db->fragShift;
- memset(db->lbuf, 0, db->fragTotalSize);
- memset(db->rbuf, 0, db->fragTotalSize);
-
- db->ready = 1;
-
- return 0;
-}
-
-static inline int prog_dmabuf_adc(struct vrc5477_ac97_state *s)
-{
- stop_adc(s);
- return prog_dmabuf(s, &s->dma_adc, s->adcRate);
-}
-
-static inline int prog_dmabuf_dac(struct vrc5477_ac97_state *s)
-{
- stop_dac(s);
- return prog_dmabuf(s, &s->dma_dac, s->dacRate);
-}
-
-
-/* --------------------------------------------------------------------- */
-/* hold spinlock for the following! */
-
-static inline void vrc5477_ac97_adc_interrupt(struct vrc5477_ac97_state *s)
-{
- struct dmabuf* adc = &s->dma_adc;
- unsigned temp;
-
- /* we need two frags avaiable because one is already being used
- * and the other will be used when next interrupt happens.
- */
- if (adc->count >= adc->fragTotalSize - adc->fragSize) {
- stop_adc(s);
- adc->error++;
- printk(KERN_INFO PFX "adc overrun\n");
- return;
- }
-
- /* set the base addr for next DMA transfer */
- temp = adc->nextIn + 2*adc->fragSize;
- if (temp >= adc->fragTotalSize) {
- ASSERT( (temp == adc->fragTotalSize) ||
- (temp == adc->fragTotalSize + adc->fragSize) );
- temp -= adc->fragTotalSize;
- }
- outl(adc->lbufDma + temp, s->io + VRC5477_ADC1_BADDR);
- outl(adc->rbufDma + temp, s->io + VRC5477_ADC2_BADDR);
-
- /* adjust nextIn */
- adc->nextIn += adc->fragSize;
- if (adc->nextIn >= adc->fragTotalSize) {
- ASSERT(adc->nextIn == adc->fragTotalSize);
- adc->nextIn = 0;
- }
-
- /* adjust count */
- adc->count += adc->fragSize;
-
- /* wake up anybody listening */
- if (waitqueue_active(&adc->wait)) {
- wake_up_interruptible(&adc->wait);
- }
-}
-
-static inline void vrc5477_ac97_dac_interrupt(struct vrc5477_ac97_state *s)
-{
- struct dmabuf* dac = &s->dma_dac;
- unsigned temp;
-
- /* next DMA transfer should already started */
- // ASSERT(inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
- // ASSERT(inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
-
- /* let us set for next next DMA transfer */
- temp = dac->nextOut + dac->fragSize*2;
- if (temp >= dac->fragTotalSize) {
- ASSERT( (temp == dac->fragTotalSize) ||
- (temp == dac->fragTotalSize + dac->fragSize) );
- temp -= dac->fragTotalSize;
- }
- outl(dac->lbufDma + temp, s->io + VRC5477_DAC1_BADDR);
- if (s->dacChannels == 1) {
- outl(dac->lbufDma + temp, s->io + VRC5477_DAC2_BADDR);
- } else {
- outl(dac->rbufDma + temp, s->io + VRC5477_DAC2_BADDR);
- }
-
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
- if (*(u16*)(dac->lbuf + dac->nextOut) != outTicket) {
- printk("assert fail: - %d vs %d\n",
- *(u16*)(dac->lbuf + dac->nextOut),
- outTicket);
- ASSERT(1 == 0);
- }
-#endif
-
- /* adjust nextOut pointer */
- dac->nextOut += dac->fragSize;
- if (dac->nextOut >= dac->fragTotalSize) {
- ASSERT(dac->nextOut == dac->fragTotalSize);
- dac->nextOut = 0;
- }
-
- /* adjust count */
- dac->count -= dac->fragSize;
- if (dac->count <=0 ) {
- /* buffer under run */
- dac->count = 0;
- dac->nextIn = dac->nextOut;
- stop_dac(s);
- }
-
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
- if (dac->count) {
- outTicket ++;
- ASSERT(*(u16*)(dac->lbuf + dac->nextOut) == outTicket);
- }
-#endif
-
- /* we cannot have both under run and someone is waiting on us */
- ASSERT(! (waitqueue_active(&dac->wait) && (dac->count <= 0)) );
-
- /* wake up anybody listening */
- if (waitqueue_active(&dac->wait))
- wake_up_interruptible(&dac->wait);
-}
-
-static irqreturn_t vrc5477_ac97_interrupt(int irq, void *dev_id)
-{
- struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)dev_id;
- u32 irqStatus;
- u32 adcInterrupts, dacInterrupts;
-
- spin_lock(&s->lock);
-
- /* get irqStatus and clear the detected ones */
- irqStatus = inl(s->io + VRC5477_INT_STATUS);
- outl(irqStatus, s->io + VRC5477_INT_CLR);
-
- /* let us see what we get */
- dacInterrupts = VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END;
- adcInterrupts = VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END;
- if (irqStatus & dacInterrupts) {
- /* we should get both interrupts, but just in case ... */
- if (irqStatus & VRC5477_INT_MASK_DAC1END) {
- vrc5477_ac97_dac_interrupt(s);
- }
- if ( (irqStatus & dacInterrupts) != dacInterrupts ) {
- printk(KERN_WARNING "vrc5477_ac97 : dac interrupts not in sync!!!\n");
- stop_dac(s);
- start_dac(s);
- }
- } else if (irqStatus & adcInterrupts) {
- /* we should get both interrupts, but just in case ... */
- if(irqStatus & VRC5477_INT_MASK_ADC1END) {
- vrc5477_ac97_adc_interrupt(s);
- }
- if ( (irqStatus & adcInterrupts) != adcInterrupts ) {
- printk(KERN_WARNING "vrc5477_ac97 : adc interrupts not in sync!!!\n");
- stop_adc(s);
- start_adc(s);
- }
- }
-
- spin_unlock(&s->lock);
- return IRQ_HANDLED;
-}
-
-/* --------------------------------------------------------------------- */
-
-static int vrc5477_ac97_open_mixdev(struct inode *inode, struct file *file)
-{
- int minor = iminor(inode);
- struct list_head *list;
- struct vrc5477_ac97_state *s;
-
- for (list = devs.next; ; list = list->next) {
- if (list == &devs)
- return -ENODEV;
- s = list_entry(list, struct vrc5477_ac97_state, devs);
- if (s->codec->dev_mixer == minor)
- break;
- }
- file->private_data = s;
- return nonseekable_open(inode, file);
-}
-
-static int vrc5477_ac97_release_mixdev(struct inode *inode, struct file *file)
-{
- return 0;
-}
-
-
-static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
- unsigned long arg)
-{
- return codec->mixer_ioctl(codec, cmd, arg);
-}
-
-static int vrc5477_ac97_ioctl_mixdev(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)file->private_data;
- struct ac97_codec *codec = s->codec;
-
- return mixdev_ioctl(codec, cmd, arg);
-}
-
-static /*const*/ struct file_operations vrc5477_ac97_mixer_fops = {
- .owner = THIS_MODULE,
- .llseek = no_llseek,
- .ioctl = vrc5477_ac97_ioctl_mixdev,
- .open = vrc5477_ac97_open_mixdev,
- .release = vrc5477_ac97_release_mixdev,
-};
-
-/* --------------------------------------------------------------------- */
-
-static int drain_dac(struct vrc5477_ac97_state *s, int nonblock)
-{
- unsigned long flags;
- int count, tmo;
-
- if (!s->dma_dac.ready)
- return 0;
-
- for (;;) {
- spin_lock_irqsave(&s->lock, flags);
- count = s->dma_dac.count;
- spin_unlock_irqrestore(&s->lock, flags);
- if (count <= 0)
- break;
- if (signal_pending(current))
- break;
- if (nonblock)
- return -EBUSY;
- tmo = 1000 * count / s->dacRate / 2;
- vrc5477_ac97_delay(tmo);
- }
- if (signal_pending(current))
- return -ERESTARTSYS;
- return 0;
-}
-
-/* --------------------------------------------------------------------- */
-
-static inline int
-copy_two_channel_adc_to_user(struct vrc5477_ac97_state *s,
- char *buffer,
- int copyCount)
-{
- struct dmabuf *db = &s->dma_adc;
- int bufStart = db->nextOut;
- for (; copyCount > 0; ) {
- int i;
- int count = copyCount;
- if (count > WORK_BUF_SIZE/2) count = WORK_BUF_SIZE/2;
- for (i=0; i< count/2; i++) {
- s->workBuf[i].lchannel =
- *(u16*)(db->lbuf + bufStart + i*2);
- s->workBuf[i].rchannel =
- *(u16*)(db->rbuf + bufStart + i*2);
- }
- if (copy_to_user(buffer, s->workBuf, count*2)) {
- return -1;
- }
-
- copyCount -= count;
- bufStart += count;
- ASSERT(bufStart <= db->fragTotalSize);
- buffer += count *2;
- }
- return 0;
-}
-
-/* return the total bytes that is copied */
-static inline int
-copy_adc_to_user(struct vrc5477_ac97_state *s,
- char * buffer,
- size_t count,
- int avail)
-{
- struct dmabuf *db = &s->dma_adc;
- int copyCount=0;
- int copyFragCount=0;
- int totalCopyCount = 0;
- int totalCopyFragCount = 0;
- unsigned long flags;
-
- /* adjust count to signel channel byte count */
- count >>= s->adcChannels - 1;
-
- /* we may have to "copy" twice as ring buffer wraps around */
- for (; (avail > 0) && (count > 0); ) {
- /* determine max possible copy count for single channel */
- copyCount = count;
- if (copyCount > avail) {
- copyCount = avail;
- }
- if (copyCount + db->nextOut > db->fragTotalSize) {
- copyCount = db->fragTotalSize - db->nextOut;
- ASSERT((copyCount % db->fragSize) == 0);
- }
-
- copyFragCount = (copyCount-1) >> db->fragShift;
- copyFragCount = (copyFragCount+1) << db->fragShift;
- ASSERT(copyFragCount >= copyCount);
-
- /* we copy differently based on adc channels */
- if (s->adcChannels == 1) {
- if (copy_to_user(buffer,
- db->lbuf + db->nextOut,
- copyCount))
- return -1;
- } else {
- /* *sigh* we have to mix two streams into one */
- if (copy_two_channel_adc_to_user(s, buffer, copyCount))
- return -1;
- }
-
- count -= copyCount;
- totalCopyCount += copyCount;
- avail -= copyFragCount;
- totalCopyFragCount += copyFragCount;
-
- buffer += copyCount << (s->adcChannels-1);
-
- db->nextOut += copyFragCount;
- if (db->nextOut >= db->fragTotalSize) {
- ASSERT(db->nextOut == db->fragTotalSize);
- db->nextOut = 0;
- }
-
- ASSERT((copyFragCount % db->fragSize) == 0);
- ASSERT( (count == 0) || (copyCount == copyFragCount));
- }
-
- spin_lock_irqsave(&s->lock, flags);
- db->count -= totalCopyFragCount;
- spin_unlock_irqrestore(&s->lock, flags);
-
- return totalCopyCount << (s->adcChannels-1);
-}
-
-static ssize_t
-vrc5477_ac97_read(struct file *file,
- char *buffer,
- size_t count,
- loff_t *ppos)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)file->private_data;
- struct dmabuf *db = &s->dma_adc;
- ssize_t ret = 0;
- unsigned long flags;
- int copyCount;
- size_t avail;
-
- if (!access_ok(VERIFY_WRITE, buffer, count))
- return -EFAULT;
-
- ASSERT(db->ready);
-
- while (count > 0) {
- // wait for samples in capture buffer
- do {
- spin_lock_irqsave(&s->lock, flags);
- if (db->stopped)
- start_adc(s);
- avail = db->count;
- spin_unlock_irqrestore(&s->lock, flags);
- if (avail <= 0) {
- if (file->f_flags & O_NONBLOCK) {
- if (!ret)
- ret = -EAGAIN;
- return ret;
- }
- interruptible_sleep_on(&db->wait);
- if (signal_pending(current)) {
- if (!ret)
- ret = -ERESTARTSYS;
- return ret;
- }
- }
- } while (avail <= 0);
-
- ASSERT( (avail % db->fragSize) == 0);
- copyCount = copy_adc_to_user(s, buffer, count, avail);
- if (copyCount <=0 ) {
- if (!ret) ret = -EFAULT;
- return ret;
- }
-
- count -= copyCount;
- buffer += copyCount;
- ret += copyCount;
- } // while (count > 0)
-
- return ret;
-}
-
-static inline int
-copy_two_channel_dac_from_user(struct vrc5477_ac97_state *s,
- const char *buffer,
- int copyCount)
-{
- struct dmabuf *db = &s->dma_dac;
- int bufStart = db->nextIn;
-
- ASSERT(db->ready);
-
- for (; copyCount > 0; ) {
- int i;
- int count = copyCount;
- if (count > WORK_BUF_SIZE/2) count = WORK_BUF_SIZE/2;
- if (copy_from_user(s->workBuf, buffer, count*2)) {
- return -1;
- }
- for (i=0; i< count/2; i++) {
- *(u16*)(db->lbuf + bufStart + i*2) =
- s->workBuf[i].lchannel;
- *(u16*)(db->rbuf + bufStart + i*2) =
- s->workBuf[i].rchannel;
- }
-
- copyCount -= count;
- bufStart += count;
- ASSERT(bufStart <= db->fragTotalSize);
- buffer += count *2;
- }
- return 0;
-
-}
-
-/* return the total bytes that is copied */
-static inline int
-copy_dac_from_user(struct vrc5477_ac97_state *s,
- const char *buffer,
- size_t count,
- int avail)
-{
- struct dmabuf *db = &s->dma_dac;
- int copyCount=0;
- int copyFragCount=0;
- int totalCopyCount = 0;
- int totalCopyFragCount = 0;
- unsigned long flags;
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
- int i;
-#endif
-
- /* adjust count to signel channel byte count */
- count >>= s->dacChannels - 1;
-
- /* we may have to "copy" twice as ring buffer wraps around */
- for (; (avail > 0) && (count > 0); ) {
- /* determine max possible copy count for single channel */
- copyCount = count;
- if (copyCount > avail) {
- copyCount = avail;
- }
- if (copyCount + db->nextIn > db->fragTotalSize) {
- copyCount = db->fragTotalSize - db->nextIn;
- ASSERT(copyCount > 0);
- }
-
- copyFragCount = copyCount;
- ASSERT(copyFragCount >= copyCount);
-
- /* we copy differently based on the number channels */
- if (s->dacChannels == 1) {
- if (copy_from_user(db->lbuf + db->nextIn,
- buffer,
- copyCount))
- return -1;
- /* fill gaps with 0 */
- memset(db->lbuf + db->nextIn + copyCount,
- 0,
- copyFragCount - copyCount);
- } else {
- /* we have demux the stream into two separate ones */
- if (copy_two_channel_dac_from_user(s, buffer, copyCount))
- return -1;
- /* fill gaps with 0 */
- memset(db->lbuf + db->nextIn + copyCount,
- 0,
- copyFragCount - copyCount);
- memset(db->rbuf + db->nextIn + copyCount,
- 0,
- copyFragCount - copyCount);
- }
-
-#if defined(VRC5477_AC97_VERBOSE_DEBUG)
- for (i=0; i< copyFragCount; i+= db->fragSize) {
- *(u16*)(db->lbuf + db->nextIn + i) = inTicket ++;
- }
-#endif
-
- count -= copyCount;
- totalCopyCount += copyCount;
- avail -= copyFragCount;
- totalCopyFragCount += copyFragCount;
-
- buffer += copyCount << (s->dacChannels - 1);
-
- db->nextIn += copyFragCount;
- if (db->nextIn >= db->fragTotalSize) {
- ASSERT(db->nextIn == db->fragTotalSize);
- db->nextIn = 0;
- }
-
- ASSERT( (count == 0) || (copyCount == copyFragCount));
- }
-
- spin_lock_irqsave(&s->lock, flags);
- db->count += totalCopyFragCount;
- if (db->stopped) {
- start_dac(s);
- }
-
- /* nextIn should not be equal to nextOut unless we are full */
- ASSERT( ( (db->count == db->fragTotalSize) &&
- (db->nextIn == db->nextOut) ) ||
- ( (db->count < db->fragTotalSize) &&
- (db->nextIn != db->nextOut) ) );
-
- spin_unlock_irqrestore(&s->lock, flags);
-
- return totalCopyCount << (s->dacChannels-1);
-
-}
-
-static ssize_t vrc5477_ac97_write(struct file *file, const char *buffer,
- size_t count, loff_t *ppos)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)file->private_data;
- struct dmabuf *db = &s->dma_dac;
- ssize_t ret;
- unsigned long flags;
- int copyCount, avail;
-
- if (!access_ok(VERIFY_READ, buffer, count))
- return -EFAULT;
- ret = 0;
-
- while (count > 0) {
- // wait for space in playback buffer
- do {
- spin_lock_irqsave(&s->lock, flags);
- avail = db->fragTotalSize - db->count;
- spin_unlock_irqrestore(&s->lock, flags);
- if (avail <= 0) {
- if (file->f_flags & O_NONBLOCK) {
- if (!ret)
- ret = -EAGAIN;
- return ret;
- }
- interruptible_sleep_on(&db->wait);
- if (signal_pending(current)) {
- if (!ret)
- ret = -ERESTARTSYS;
- return ret;
- }
- }
- } while (avail <= 0);
-
- copyCount = copy_dac_from_user(s, buffer, count, avail);
- if (copyCount < 0) {
- if (!ret) ret = -EFAULT;
- return ret;
- }
-
- count -= copyCount;
- buffer += copyCount;
- ret += copyCount;
- } // while (count > 0)
-
- return ret;
-}
-
-/* No kernel lock - we have our own spinlock */
-static unsigned int vrc5477_ac97_poll(struct file *file,
- struct poll_table_struct *wait)
-{
- struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)file->private_data;
- unsigned long flags;
- unsigned int mask = 0;
-
- if (file->f_mode & FMODE_WRITE)
- poll_wait(file, &s->dma_dac.wait, wait);
- if (file->f_mode & FMODE_READ)
- poll_wait(file, &s->dma_adc.wait, wait);
- spin_lock_irqsave(&s->lock, flags);
- if (file->f_mode & FMODE_READ) {
- if (s->dma_adc.count >= (signed)s->dma_adc.fragSize)
- mask |= POLLIN | POLLRDNORM;
- }
- if (file->f_mode & FMODE_WRITE) {
- if ((signed)s->dma_dac.fragTotalSize >=
- s->dma_dac.count + (signed)s->dma_dac.fragSize)
- mask |= POLLOUT | POLLWRNORM;
- }
- spin_unlock_irqrestore(&s->lock, flags);
- return mask;
-}
-
-#ifdef VRC5477_AC97_DEBUG
-static struct ioctl_str_t {
- unsigned int cmd;
- const char* str;
-} ioctl_str[] = {
- {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
- {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
- {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
- {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
- {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
- {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
- {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
- {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
- {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
- {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
- {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
- {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
- {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
- {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
- {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
- {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
- {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
- {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
- {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
- {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
- {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
- {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
- {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
- {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
- {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
- {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
- {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
- {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
- {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
- {OSS_GETVERSION, "OSS_GETVERSION"},
- {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
- {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
- {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
- {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
-};
-#endif
-
-static int vrc5477_ac97_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
-{
- struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)file->private_data;
- unsigned long flags;
- audio_buf_info abinfo;
- int count;
- int val, ret;
-
-#ifdef VRC5477_AC97_DEBUG
- for (count = 0; count < ARRAY_SIZE(ioctl_str); count++) {
- if (ioctl_str[count].cmd == cmd)
- break;
- }
- if (count < ARRAY_SIZE(ioctl_str))
- printk(KERN_INFO PFX "ioctl %s\n", ioctl_str[count].str);
- else
- printk(KERN_INFO PFX "ioctl unknown, 0x%x\n", cmd);
-#endif
-
- switch (cmd) {
- case OSS_GETVERSION:
- return put_user(SOUND_VERSION, (int *)arg);
-
- case SNDCTL_DSP_SYNC:
- if (file->f_mode & FMODE_WRITE)
- return drain_dac(s, file->f_flags & O_NONBLOCK);
- return 0;
-
- case SNDCTL_DSP_SETDUPLEX:
- return 0;
-
- case SNDCTL_DSP_GETCAPS:
- return put_user(DSP_CAP_DUPLEX, (int *)arg);
-
- case SNDCTL_DSP_RESET:
- if (file->f_mode & FMODE_WRITE) {
- stop_dac(s);
- synchronize_irq(s->irq);
- s->dma_dac.count = 0;
- s->dma_dac.nextIn = s->dma_dac.nextOut = 0;
- }
- if (file->f_mode & FMODE_READ) {
- stop_adc(s);
- synchronize_irq(s->irq);
- s->dma_adc.count = 0;
- s->dma_adc.nextIn = s->dma_adc.nextOut = 0;
- }
- return 0;
-
- case SNDCTL_DSP_SPEED:
- if (get_user(val, (int *)arg))
- return -EFAULT;
- if (val >= 0) {
- if (file->f_mode & FMODE_READ) {
- stop_adc(s);
- set_adc_rate(s, val);
- if ((ret = prog_dmabuf_adc(s)))
- return ret;
- }
- if (file->f_mode & FMODE_WRITE) {
- stop_dac(s);
- set_dac_rate(s, val);
- if ((ret = prog_dmabuf_dac(s)))
- return ret;
- }
- }
- return put_user((file->f_mode & FMODE_READ) ?
- s->adcRate : s->dacRate, (int *)arg);
-
- case SNDCTL_DSP_STEREO:
- if (get_user(val, (int *)arg))
- return -EFAULT;
- if (file->f_mode & FMODE_READ) {
- stop_adc(s);
- if (val)
- s->adcChannels = 2;
- else
- s->adcChannels = 1;
- if ((ret = prog_dmabuf_adc(s)))
- return ret;
- }
- if (file->f_mode & FMODE_WRITE) {
- stop_dac(s);
- if (val)
- s->dacChannels = 2;
- else
- s->dacChannels = 1;
- if ((ret = prog_dmabuf_dac(s)))
- return ret;
- }
- return 0;
-
- case SNDCTL_DSP_CHANNELS:
- if (get_user(val, (int *)arg))
- return -EFAULT;
- if (val != 0) {
- if ( (val != 1) && (val != 2)) val = 2;
-
- if (file->f_mode & FMODE_READ) {
- stop_adc(s);
- s->dacChannels = val;
- if ((ret = prog_dmabuf_adc(s)))
- return ret;
- }
- if (file->f_mode & FMODE_WRITE) {
- stop_dac(s);
- s->dacChannels = val;
- if ((ret = prog_dmabuf_dac(s)))
- return ret;
- }
- }
- return put_user(val, (int *)arg);
-
- case SNDCTL_DSP_GETFMTS: /* Returns a mask */
- return put_user(AFMT_S16_LE, (int *)arg);
-
- case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
- if (get_user(val, (int *)arg))
- return -EFAULT;
- if (val != AFMT_QUERY) {
- if (val != AFMT_S16_LE) return -EINVAL;
- if (file->f_mode & FMODE_READ) {
- stop_adc(s);
- if ((ret = prog_dmabuf_adc(s)))
- return ret;
- }
- if (file->f_mode & FMODE_WRITE) {
- stop_dac(s);
- if ((ret = prog_dmabuf_dac(s)))
- return ret;
- }
- } else {
- val = AFMT_S16_LE;
- }
- return put_user(val, (int *)arg);
-
- case SNDCTL_DSP_POST:
- return 0;
-
- case SNDCTL_DSP_GETTRIGGER:
- case SNDCTL_DSP_SETTRIGGER:
- /* NO trigger */
- return -EINVAL;
-
- case SNDCTL_DSP_GETOSPACE:
- if (!(file->f_mode & FMODE_WRITE))
- return -EINVAL;
- abinfo.fragsize = s->dma_dac.fragSize << (s->dacChannels-1);
- spin_lock_irqsave(&s->lock, flags);
- count = s->dma_dac.count;
- spin_unlock_irqrestore(&s->lock, flags);
- abinfo.bytes = (s->dma_dac.fragTotalSize - count) <<
- (s->dacChannels-1);
- abinfo.fragstotal = s->dma_dac.numFrag;
- abinfo.fragments = abinfo.bytes >> s->dma_dac.fragShift >>
- (s->dacChannels-1);
- return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
-
- case SNDCTL_DSP_GETISPACE:
- if (!(file->f_mode & FMODE_READ))
- return -EINVAL;
- abinfo.fragsize = s->dma_adc.fragSize << (s->adcChannels-1);
- spin_lock_irqsave(&s->lock, flags);
- count = s->dma_adc.count;
- spin_unlock_irqrestore(&s->lock, flags);
- if (count < 0)
- count = 0;
- abinfo.bytes = count << (s->adcChannels-1);
- abinfo.fragstotal = s->dma_adc.numFrag;
- abinfo.fragments = (abinfo.bytes >> s->dma_adc.fragShift) >>
- (s->adcChannels-1);
- return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
-
- case SNDCTL_DSP_NONBLOCK:
- file->f_flags |= O_NONBLOCK;
- return 0;
-
- case SNDCTL_DSP_GETODELAY:
- if (!(file->f_mode & FMODE_WRITE))
- return -EINVAL;
- spin_lock_irqsave(&s->lock, flags);
- count = s->dma_dac.count;
- spin_unlock_irqrestore(&s->lock, flags);
- return put_user(count, (int *)arg);
-
- case SNDCTL_DSP_GETIPTR:
- case SNDCTL_DSP_GETOPTR:
- /* we cannot get DMA ptr */
- return -EINVAL;
-
- case SNDCTL_DSP_GETBLKSIZE:
- if (file->f_mode & FMODE_WRITE)
- return put_user(s->dma_dac.fragSize << (s->dacChannels-1), (int *)arg);
- else
- return put_user(s->dma_adc.fragSize << (s->adcChannels-1), (int *)arg);
-
- case SNDCTL_DSP_SETFRAGMENT:
- /* we ignore fragment size request */
- return 0;
-
- case SNDCTL_DSP_SUBDIVIDE:
- /* what is this for? [jsun] */
- return 0;
-
- case SOUND_PCM_READ_RATE:
- return put_user((file->f_mode & FMODE_READ) ?
- s->adcRate : s->dacRate, (int *)arg);
-
- case SOUND_PCM_READ_CHANNELS:
- if (file->f_mode & FMODE_READ)
- return put_user(s->adcChannels, (int *)arg);
- else
- return put_user(s->dacChannels ? 2 : 1, (int *)arg);
-
- case SOUND_PCM_READ_BITS:
- return put_user(16, (int *)arg);
-
- case SOUND_PCM_WRITE_FILTER:
- case SNDCTL_DSP_SETSYNCRO:
- case SOUND_PCM_READ_FILTER:
- return -EINVAL;
- }
-
- return mixdev_ioctl(s->codec, cmd, arg);
-}
-
-
-static int vrc5477_ac97_open(struct inode *inode, struct file *file)
-{
- int minor = iminor(inode);
- DECLARE_WAITQUEUE(wait, current);
- unsigned long flags;
- struct list_head *list;
- struct vrc5477_ac97_state *s;
- int ret=0;
-
- nonseekable_open(inode, file);
- for (list = devs.next; ; list = list->next) {
- if (list == &devs)
- return -ENODEV;
- s = list_entry(list, struct vrc5477_ac97_state, devs);
- if (!((s->dev_audio ^ minor) & ~0xf))
- break;
- }
- file->private_data = s;
-
- /* wait for device to become free */
- mutex_lock(&s->open_mutex);
- while (s->open_mode & file->f_mode) {
-
- if (file->f_flags & O_NONBLOCK) {
- mutex_unlock(&s->open_mutex);
- return -EBUSY;
- }
- add_wait_queue(&s->open_wait, &wait);
- __set_current_state(TASK_INTERRUPTIBLE);
- mutex_unlock(&s->open_mutex);
- schedule();
- remove_wait_queue(&s->open_wait, &wait);
- set_current_state(TASK_RUNNING);
- if (signal_pending(current))
- return -ERESTARTSYS;
- mutex_lock(&s->open_mutex);
- }
-
- spin_lock_irqsave(&s->lock, flags);
-
- if (file->f_mode & FMODE_READ) {
- /* set default settings */
- set_adc_rate(s, 48000);
- s->adcChannels = 2;
-
- ret = prog_dmabuf_adc(s);
- if (ret) goto bailout;
- }
- if (file->f_mode & FMODE_WRITE) {
- /* set default settings */
- set_dac_rate(s, 48000);
- s->dacChannels = 2;
-
- ret = prog_dmabuf_dac(s);
- if (ret) goto bailout;
- }
-
- s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
-
- bailout:
- spin_unlock_irqrestore(&s->lock, flags);
-
- mutex_unlock(&s->open_mutex);
- return ret;
-}
-
-static int vrc5477_ac97_release(struct inode *inode, struct file *file)
-{
- struct vrc5477_ac97_state *s =
- (struct vrc5477_ac97_state *)file->private_data;
-
- lock_kernel();
- if (file->f_mode & FMODE_WRITE)
- drain_dac(s, file->f_flags & O_NONBLOCK);
- mutex_lock(&s->open_mutex);
- if (file->f_mode & FMODE_WRITE) {
- stop_dac(s);
- dealloc_dmabuf(s, &s->dma_dac);
- }
- if (file->f_mode & FMODE_READ) {
- stop_adc(s);
- dealloc_dmabuf(s, &s->dma_adc);
- }
- s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
- mutex_unlock(&s->open_mutex);
- wake_up(&s->open_wait);
- unlock_kernel();
- return 0;
-}
-
-static /*const*/ struct file_operations vrc5477_ac97_audio_fops = {
- .owner = THIS_MODULE,
- .llseek = no_llseek,
- .read = vrc5477_ac97_read,
- .write = vrc5477_ac97_write,
- .poll = vrc5477_ac97_poll,
- .ioctl = vrc5477_ac97_ioctl,
- // .mmap = vrc5477_ac97_mmap,
- .open = vrc5477_ac97_open,
- .release = vrc5477_ac97_release,
-};
-
-
-/* --------------------------------------------------------------------- */
-
-
-/* --------------------------------------------------------------------- */
-
-/*
- * for debugging purposes, we'll create a proc device that dumps the
- * CODEC chipstate
- */
-
-#ifdef VRC5477_AC97_DEBUG
-
-struct {
- const char *regname;
- unsigned regaddr;
-} vrc5477_ac97_regs[] = {
- {"VRC5477_INT_STATUS", VRC5477_INT_STATUS},
- {"VRC5477_CODEC_WR", VRC5477_CODEC_WR},
- {"VRC5477_CODEC_RD", VRC5477_CODEC_RD},
- {"VRC5477_CTRL", VRC5477_CTRL},
- {"VRC5477_ACLINK_CTRL", VRC5477_ACLINK_CTRL},
- {"VRC5477_INT_MASK", VRC5477_INT_MASK},
- {"VRC5477_DAC1_CTRL", VRC5477_DAC1_CTRL},
- {"VRC5477_DAC1L", VRC5477_DAC1L},
- {"VRC5477_DAC1_BADDR", VRC5477_DAC1_BADDR},
- {"VRC5477_DAC2_CTRL", VRC5477_DAC2_CTRL},
- {"VRC5477_DAC2L", VRC5477_DAC2L},
- {"VRC5477_DAC2_BADDR", VRC5477_DAC2_BADDR},
- {"VRC5477_DAC3_CTRL", VRC5477_DAC3_CTRL},
- {"VRC5477_DAC3L", VRC5477_DAC3L},
- {"VRC5477_DAC3_BADDR", VRC5477_DAC3_BADDR},
- {"VRC5477_ADC1_CTRL", VRC5477_ADC1_CTRL},
- {"VRC5477_ADC1L", VRC5477_ADC1L},
- {"VRC5477_ADC1_BADDR", VRC5477_ADC1_BADDR},
- {"VRC5477_ADC2_CTRL", VRC5477_ADC2_CTRL},
- {"VRC5477_ADC2L", VRC5477_ADC2L},
- {"VRC5477_ADC2_BADDR", VRC5477_ADC2_BADDR},
- {"VRC5477_ADC3_CTRL", VRC5477_ADC3_CTRL},
- {"VRC5477_ADC3L", VRC5477_ADC3L},
- {"VRC5477_ADC3_BADDR", VRC5477_ADC3_BADDR},
- {NULL, 0x0}
-};
-
-static int proc_vrc5477_ac97_dump (char *buf, char **start, off_t fpos,
- int length, int *eof, void *data)
-{
- struct vrc5477_ac97_state *s;
- int cnt, len = 0;
-
- if (list_empty(&devs))
- return 0;
- s = list_entry(devs.next, struct vrc5477_ac97_state, devs);
-
- /* print out header */
- len += sprintf(buf + len, "\n\t\tVrc5477 Audio Debug\n\n");
-
- // print out digital controller state
- len += sprintf (buf + len, "NEC Vrc5477 Audio Controller registers\n");
- len += sprintf (buf + len, "---------------------------------\n");
- for (cnt=0; vrc5477_ac97_regs[cnt].regname != NULL; cnt++) {
- len+= sprintf (buf + len, "%-20s = %08x\n",
- vrc5477_ac97_regs[cnt].regname,
- inl(s->io + vrc5477_ac97_regs[cnt].regaddr));
- }
-
- /* print out driver state */
- len += sprintf (buf + len, "NEC Vrc5477 Audio driver states\n");
- len += sprintf (buf + len, "---------------------------------\n");
- len += sprintf (buf + len, "dacChannels = %d\n", s->dacChannels);
- len += sprintf (buf + len, "adcChannels = %d\n", s->adcChannels);
- len += sprintf (buf + len, "dacRate = %d\n", s->dacRate);
- len += sprintf (buf + len, "adcRate = %d\n", s->adcRate);
-
- len += sprintf (buf + len, "dma_dac is %s ready\n",
- s->dma_dac.ready? "" : "not");
- if (s->dma_dac.ready) {
- len += sprintf (buf + len, "dma_dac is %s stopped.\n",
- s->dma_dac.stopped? "" : "not");
- len += sprintf (buf + len, "dma_dac.fragSize = %x\n",
- s->dma_dac.fragSize);
- len += sprintf (buf + len, "dma_dac.fragShift = %x\n",
- s->dma_dac.fragShift);
- len += sprintf (buf + len, "dma_dac.numFrag = %x\n",
- s->dma_dac.numFrag);
- len += sprintf (buf + len, "dma_dac.fragTotalSize = %x\n",
- s->dma_dac.fragTotalSize);
- len += sprintf (buf + len, "dma_dac.nextIn = %x\n",
- s->dma_dac.nextIn);
- len += sprintf (buf + len, "dma_dac.nextOut = %x\n",
- s->dma_dac.nextOut);
- len += sprintf (buf + len, "dma_dac.count = %x\n",
- s->dma_dac.count);
- }
-
- len += sprintf (buf + len, "dma_adc is %s ready\n",
- s->dma_adc.ready? "" : "not");
- if (s->dma_adc.ready) {
- len += sprintf (buf + len, "dma_adc is %s stopped.\n",
- s->dma_adc.stopped? "" : "not");
- len += sprintf (buf + len, "dma_adc.fragSize = %x\n",
- s->dma_adc.fragSize);
- len += sprintf (buf + len, "dma_adc.fragShift = %x\n",
- s->dma_adc.fragShift);
- len += sprintf (buf + len, "dma_adc.numFrag = %x\n",
- s->dma_adc.numFrag);
- len += sprintf (buf + len, "dma_adc.fragTotalSize = %x\n",
- s->dma_adc.fragTotalSize);
- len += sprintf (buf + len, "dma_adc.nextIn = %x\n",
- s->dma_adc.nextIn);
- len += sprintf (buf + len, "dma_adc.nextOut = %x\n",
- s->dma_adc.nextOut);
- len += sprintf (buf + len, "dma_adc.count = %x\n",
- s->dma_adc.count);
- }
-
- /* print out CODEC state */
- len += sprintf (buf + len, "\nAC97 CODEC registers\n");
- len += sprintf (buf + len, "----------------------\n");
- for (cnt=0; cnt <= 0x7e; cnt = cnt +2)
- len+= sprintf (buf + len, "reg %02x = %04x\n",
- cnt, rdcodec(s->codec, cnt));
-
- if (fpos >=len){
- *start = buf;
- *eof =1;
- return 0;
- }
- *start = buf + fpos;
- if ((len -= fpos) > length)
- return length;
- *eof =1;
- return len;
-
-}
-#endif /* VRC5477_AC97_DEBUG */
-
-/* --------------------------------------------------------------------- */
-
-/* maximum number of devices; only used for command line params */
-#define NR_DEVICE 5
-
-static unsigned int devindex;
-
-MODULE_AUTHOR("Monta Vista Software, jsun(a)mvista.com or jsun(a)junsun.net");
-MODULE_DESCRIPTION("NEC Vrc5477 audio (AC97) Driver");
-MODULE_LICENSE("GPL");
-
-static int __devinit vrc5477_ac97_probe(struct pci_dev *pcidev,
- const struct pci_device_id *pciid)
-{
- struct vrc5477_ac97_state *s;
-#ifdef VRC5477_AC97_DEBUG
- char proc_str[80];
-#endif
-
- if (pcidev->irq == 0)
- return -1;
-
- if (!(s = kzalloc(sizeof(struct vrc5477_ac97_state), GFP_KERNEL))) {
- printk(KERN_ERR PFX "alloc of device struct failed\n");
- return -1;
- }
-
- init_waitqueue_head(&s->dma_adc.wait);
- init_waitqueue_head(&s->dma_dac.wait);
- init_waitqueue_head(&s->open_wait);
- mutex_init(&s->open_mutex);
- spin_lock_init(&s->lock);
-
- s->dev = pcidev;
- s->io = pci_resource_start(pcidev, 0);
- s->irq = pcidev->irq;
-
- s->codec = ac97_alloc_codec();
-
- s->codec->private_data = s;
- s->codec->id = 0;
- s->codec->codec_read = rdcodec;
- s->codec->codec_write = wrcodec;
- s->codec->codec_wait = waitcodec;
-
- /* setting some other default values such as
- * adcChannels, adcRate is done in open() so that
- * no persistent state across file opens.
- */
-
- /* test if get response from ac97, if not return */
- if (ac97_codec_not_present(s->codec)) {
- printk(KERN_ERR PFX "no ac97 codec\n");
- goto err_region;
-
- }
-
- /* test if get response from ac97, if not return */
- if (ac97_codec_not_present(&(s->codec))) {
- printk(KERN_ERR PFX "no ac97 codec\n");
- goto err_region;
-
- }
-
- if (!request_region(s->io, pci_resource_len(pcidev,0),
- VRC5477_AC97_MODULE_NAME)) {
- printk(KERN_ERR PFX "io ports %#lx->%#lx in use\n",
- s->io, s->io + pci_resource_len(pcidev,0)-1);
- goto err_region;
- }
- if (request_irq(s->irq, vrc5477_ac97_interrupt, IRQF_DISABLED,
- VRC5477_AC97_MODULE_NAME, s)) {
- printk(KERN_ERR PFX "irq %u in use\n", s->irq);
- goto err_irq;
- }
-
- printk(KERN_INFO PFX "IO at %#lx, IRQ %d\n", s->io, s->irq);
-
- /* register devices */
- if ((s->dev_audio = register_sound_dsp(&vrc5477_ac97_audio_fops, -1)) < 0)
- goto err_dev1;
- if ((s->codec->dev_mixer =
- register_sound_mixer(&vrc5477_ac97_mixer_fops, -1)) < 0)
- goto err_dev2;
-
-#ifdef VRC5477_AC97_DEBUG
- /* initialize the debug proc device */
- s->ps = create_proc_read_entry(VRC5477_AC97_MODULE_NAME, 0, NULL,
- proc_vrc5477_ac97_dump, NULL);
-#endif /* VRC5477_AC97_DEBUG */
-
- /* enable pci io and bus mastering */
- if (pci_enable_device(pcidev))
- goto err_dev3;
- pci_set_master(pcidev);
-
- /* cold reset the AC97 */
- outl(VRC5477_ACLINK_CTRL_RST_ON | VRC5477_ACLINK_CTRL_RST_TIME,
- s->io + VRC5477_ACLINK_CTRL);
- while (inl(s->io + VRC5477_ACLINK_CTRL) & VRC5477_ACLINK_CTRL_RST_ON);
-
- /* codec init */
- if (!ac97_probe_codec(s->codec))
- goto err_dev3;
-
-#ifdef VRC5477_AC97_DEBUG
- sprintf(proc_str, "driver/%s/%d/ac97",
- VRC5477_AC97_MODULE_NAME, s->codec->id);
- s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
- ac97_read_proc, s->codec);
- /* TODO : why this proc file does not show up? */
-#endif
-
- /* Try to enable variable rate audio mode. */
- wrcodec(s->codec, AC97_EXTENDED_STATUS,
- rdcodec(s->codec, AC97_EXTENDED_STATUS) | AC97_EXTSTAT_VRA);
- /* Did we enable it? */
- if(rdcodec(s->codec, AC97_EXTENDED_STATUS) & AC97_EXTSTAT_VRA)
- s->extended_status |= AC97_EXTSTAT_VRA;
- else {
- s->dacRate = 48000;
- printk(KERN_INFO PFX "VRA mode not enabled; rate fixed at %d.",
- s->dacRate);
- }
-
- /* let us get the default volumne louder */
- wrcodec(s->codec, 0x2, 0x1010); /* master volume, middle */
- wrcodec(s->codec, 0xc, 0x10); /* phone volume, middle */
- // wrcodec(s->codec, 0xe, 0x10); /* misc volume, middle */
- wrcodec(s->codec, 0x10, 0x8000); /* line-in 2 line-out disable */
- wrcodec(s->codec, 0x18, 0x0707); /* PCM out (line out) middle */
-
-
- /* by default we select line in the input */
- wrcodec(s->codec, 0x1a, 0x0404);
- wrcodec(s->codec, 0x1c, 0x0f0f);
- wrcodec(s->codec, 0x1e, 0x07);
-
- /* enable the master interrupt but disable all others */
- outl(VRC5477_INT_MASK_NMASK, s->io + VRC5477_INT_MASK);
-
- /* store it in the driver field */
- pci_set_drvdata(pcidev, s);
- pcidev->dma_mask = 0xffffffff;
- /* put it into driver list */
- list_add_tail(&s->devs, &devs);
- /* increment devindex */
- if (devindex < NR_DEVICE-1)
- devindex++;
- return 0;
-
- err_dev3:
- unregister_sound_mixer(s->codec->dev_mixer);
- err_dev2:
- unregister_sound_dsp(s->dev_audio);
- err_dev1:
- printk(KERN_ERR PFX "cannot register misc device\n");
- free_irq(s->irq, s);
- err_irq:
- release_region(s->io, pci_resource_len(pcidev,0));
- err_region:
- ac97_release_codec(codec);
- kfree(s);
- return -1;
-}
-
-static void __devexit vrc5477_ac97_remove(struct pci_dev *dev)
-{
- struct vrc5477_ac97_state *s = pci_get_drvdata(dev);
-
- if (!s)
- return;
- list_del(&s->devs);
-
-#ifdef VRC5477_AC97_DEBUG
- if (s->ps)
- remove_proc_entry(VRC5477_AC97_MODULE_NAME, NULL);
-#endif /* VRC5477_AC97_DEBUG */
-
- synchronize_irq();
- free_irq(s->irq, s);
- release_region(s->io, pci_resource_len(dev,0));
- unregister_sound_dsp(s->dev_audio);
- unregister_sound_mixer(s->codec->dev_mixer);
- ac97_release_codec(s->codec);
- kfree(s);
- pci_set_drvdata(dev, NULL);
-}
-
-
-static struct pci_device_id id_table[] = {
- { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_VRC5477_AC97,
- PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
- { 0, }
-};
-
-MODULE_DEVICE_TABLE(pci, id_table);
-
-static struct pci_driver vrc5477_ac97_driver = {
- .name = VRC5477_AC97_MODULE_NAME,
- .id_table = id_table,
- .probe = vrc5477_ac97_probe,
- .remove = __devexit_p(vrc5477_ac97_remove)
-};
-
-static int __init init_vrc5477_ac97(void)
-{
- printk("Vrc5477 AC97 driver: version v0.2 time " __TIME__ " " __DATE__ " by Jun Sun\n");
- return pci_register_driver(&vrc5477_ac97_driver);
-}
-
-static void __exit cleanup_vrc5477_ac97(void)
-{
- printk(KERN_INFO PFX "unloading\n");
- pci_unregister_driver(&vrc5477_ac97_driver);
-}
-
-module_init(init_vrc5477_ac97);
-module_exit(cleanup_vrc5477_ac97);
-
Index: upstream-linus/include/linux/pci_ids.h
===================================================================
--- upstream-linus.orig/include/linux/pci_ids.h
+++ upstream-linus/include/linux/pci_ids.h
@@ -611,7 +611,6 @@
#define PCI_DEVICE_ID_NEC_CBUS_3 0x003b
#define PCI_DEVICE_ID_NEC_NAPCCARD 0x003e
#define PCI_DEVICE_ID_NEC_PCX2 0x0046 /* PowerVR */
-#define PCI_DEVICE_ID_NEC_NILE4 0x005a
#define PCI_DEVICE_ID_NEC_VRC5476 0x009b
#define PCI_DEVICE_ID_NEC_VRC4173 0x00a5
#define PCI_DEVICE_ID_NEC_VRC5477_AC97 0x00a6
2
1