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
October 2009
- 132 participants
- 330 discussions
[alsa-devel] [PATCH] AC97 atmel: add support for AT91(common with AVR32).
by Sedji Gaouaou 06 Oct '09
by Sedji Gaouaou 06 Oct '09
06 Oct '09
This patch add AC97 support for ATMEL AT91 boards, using the AVR32 code.
While AVR is using a DMA, the AT91 chips are using a Peripheral Data
Controller.
This is linked to the patch:
http://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=5640.
Signed-off-by: Sedji Gaouaou <sedji.gaouaou(a)atmel.com>
---
It is based on Takashi git tree(sound-2.6/for-next).
sound/atmel/Kconfig | 2 +-
sound/atmel/ac97c.c | 354 +++++++++++++++++++++++++++++++++++++--------------
2 files changed, 262 insertions(+), 94 deletions(-)
diff --git a/sound/atmel/Kconfig b/sound/atmel/Kconfig
index 6c228a9..94de43a 100644
--- a/sound/atmel/Kconfig
+++ b/sound/atmel/Kconfig
@@ -12,7 +12,7 @@ config SND_ATMEL_AC97C
tristate "Atmel AC97 Controller (AC97C) driver"
select SND_PCM
select SND_AC97_CODEC
- depends on DW_DMAC && AVR32
+ depends on (DW_DMAC && AVR32) || ARCH_AT91
help
ALSA sound driver for the Atmel AC97 controller.
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index 0c0f877..54d1365 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -13,6 +13,7 @@
#include <linux/device.h>
#include <linux/dmaengine.h>
#include <linux/dma-mapping.h>
+#include <linux/atmel_pdc.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/module.h>
@@ -31,6 +32,10 @@
#include <linux/dw_dmac.h>
+#include <mach/cpu.h>
+#include <mach/hardware.h>
+#include <mach/gpio.h>
+
#include "ac97c.h"
enum {
@@ -63,6 +68,7 @@ struct atmel_ac97c {
u64 cur_format;
unsigned int cur_rate;
unsigned long flags;
+ int period;
/* Serialize access to opened variable */
spinlock_t lock;
void __iomem *regs;
@@ -241,10 +247,13 @@ static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
params_buffer_bytes(hw_params));
if (retval < 0)
return retval;
- /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
- if (retval == 1)
- if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
- dw_dma_cyclic_free(chip->dma.tx_chan);
+
+ if (cpu_is_at32ap7000()) {
+ /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
+ if (retval == 1)
+ if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
+ dw_dma_cyclic_free(chip->dma.tx_chan);
+ }
/* Set restrictions to params. */
mutex_lock(&opened_mutex);
@@ -263,12 +272,14 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
retval = snd_pcm_lib_malloc_pages(substream,
params_buffer_bytes(hw_params));
- if (retval < 0)
- return retval;
- /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
- if (retval == 1)
- if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
- dw_dma_cyclic_free(chip->dma.rx_chan);
+ if (cpu_is_at32ap7000()) {
+ if (retval < 0)
+ return retval;
+ /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
+ if (retval == 1)
+ if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
+ dw_dma_cyclic_free(chip->dma.rx_chan);
+ }
/* Set restrictions to params. */
mutex_lock(&opened_mutex);
@@ -282,16 +293,20 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
static int atmel_ac97c_playback_hw_free(struct snd_pcm_substream *substream)
{
struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
- if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
- dw_dma_cyclic_free(chip->dma.tx_chan);
+ if (cpu_is_at32ap7000()) {
+ if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
+ dw_dma_cyclic_free(chip->dma.tx_chan);
+ }
return snd_pcm_lib_free_pages(substream);
}
static int atmel_ac97c_capture_hw_free(struct snd_pcm_substream *substream)
{
struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
- if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
- dw_dma_cyclic_free(chip->dma.rx_chan);
+ if (cpu_is_at32ap7000()) {
+ if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
+ dw_dma_cyclic_free(chip->dma.rx_chan);
+ }
return snd_pcm_lib_free_pages(substream);
}
@@ -299,9 +314,11 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
{
struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
+ int block_size = frames_to_bytes(runtime, runtime->period_size);
unsigned long word = ac97c_readl(chip, OCA);
int retval;
+ chip->period = 0;
word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
/* assign channels to AC97C channel A */
@@ -324,7 +341,8 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
switch (runtime->format) {
case SNDRV_PCM_FORMAT_S16_LE:
- word |= AC97C_CMR_CEM_LITTLE;
+ if (cpu_is_at32ap7000())
+ word |= AC97C_CMR_CEM_LITTLE;
break;
case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
word &= ~(AC97C_CMR_CEM_LITTLE);
@@ -363,9 +381,18 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
runtime->rate);
- if (!test_bit(DMA_TX_READY, &chip->flags))
- retval = atmel_ac97c_prepare_dma(chip, substream,
- DMA_TO_DEVICE);
+ if (cpu_is_at32ap7000()) {
+ if (!test_bit(DMA_TX_READY, &chip->flags))
+ retval = atmel_ac97c_prepare_dma(chip, substream,
+ DMA_TO_DEVICE);
+ } else {
+ /* Initialize and start the PDC */
+ writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
+ writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
+ writel(runtime->dma_addr + block_size,
+ chip->regs + ATMEL_PDC_TNPR);
+ writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
+ }
return retval;
}
@@ -374,9 +401,11 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
{
struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
+ int block_size = frames_to_bytes(runtime, runtime->period_size);
unsigned long word = ac97c_readl(chip, ICA);
int retval;
+ chip->period = 0;
word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
/* assign channels to AC97C channel A */
@@ -415,11 +444,15 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
word |= AC97C_CSR_OVRUN;
ac97c_writel(chip, CAMR, word);
-
/* Enable channel A event interrupt */
word = ac97c_readl(chip, IMR);
word |= AC97C_SR_CAEVT;
- ac97c_writel(chip, IER, word);
+ ac97c_writel(chip, IER, /*word*/AC97C_SR_CAEVT);
+
+ /* Enable channel A event interrupt */
+ /*word = ac97c_readl(chip, IMR);
+ word |= AC97C_SR_CAEVT;
+ ac97c_writel(chip, IER, word);*/
/* set variable rate if needed */
if (runtime->rate != 48000) {
@@ -438,9 +471,18 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
runtime->rate);
- if (!test_bit(DMA_RX_READY, &chip->flags))
- retval = atmel_ac97c_prepare_dma(chip, substream,
- DMA_FROM_DEVICE);
+ if (cpu_is_at32ap7000()) {
+ if (!test_bit(DMA_RX_READY, &chip->flags))
+ retval = atmel_ac97c_prepare_dma(chip, substream,
+ DMA_FROM_DEVICE);
+ } else {
+ /* Initialize and start the PDC */
+ writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
+ writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
+ writel(runtime->dma_addr + block_size,
+ chip->regs + ATMEL_PDC_RNPR);
+ writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
+ }
return retval;
}
@@ -449,7 +491,7 @@ static int
atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
- unsigned long camr;
+ unsigned long camr, ptcr = 0;
int retval = 0;
camr = ac97c_readl(chip, CAMR);
@@ -458,15 +500,22 @@ atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
case SNDRV_PCM_TRIGGER_START:
- retval = dw_dma_cyclic_start(chip->dma.tx_chan);
- if (retval)
- goto out;
- camr |= AC97C_CMR_CENA;
+ if (cpu_is_at32ap7000()) {
+ retval = dw_dma_cyclic_start(chip->dma.tx_chan);
+ if (retval)
+ goto out;
+ } else {
+ ptcr = ATMEL_PDC_TXTEN;
+ }
+ camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX;
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
case SNDRV_PCM_TRIGGER_STOP:
- dw_dma_cyclic_stop(chip->dma.tx_chan);
+ if (cpu_is_at32ap7000())
+ dw_dma_cyclic_stop(chip->dma.tx_chan);
+ else
+ ptcr = ATMEL_PDC_TXTDIS;
if (chip->opened <= 1)
camr &= ~AC97C_CMR_CENA;
break;
@@ -476,6 +525,8 @@ atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
}
ac97c_writel(chip, CAMR, camr);
+ if (!cpu_is_at32ap7000())
+ writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
out:
return retval;
}
@@ -484,7 +535,7 @@ static int
atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
- unsigned long camr;
+ unsigned long camr, ptcr = 0;
int retval = 0;
camr = ac97c_readl(chip, CAMR);
@@ -493,15 +544,22 @@ atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
case SNDRV_PCM_TRIGGER_START:
- retval = dw_dma_cyclic_start(chip->dma.rx_chan);
- if (retval)
- goto out;
+ if (cpu_is_at32ap7000()) {
+ retval = dw_dma_cyclic_start(chip->dma.rx_chan);
+ if (retval)
+ goto out;
+ } else {
+ ptcr = ATMEL_PDC_RXTEN;
+ }
camr |= AC97C_CMR_CENA;
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
case SNDRV_PCM_TRIGGER_STOP:
- dw_dma_cyclic_stop(chip->dma.rx_chan);
+ if (cpu_is_at32ap7000())
+ dw_dma_cyclic_stop(chip->dma.rx_chan);
+ else
+ ptcr = ATMEL_PDC_RXTDIS;
if (chip->opened <= 1)
camr &= ~AC97C_CMR_CENA;
break;
@@ -511,6 +569,8 @@ atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
}
ac97c_writel(chip, CAMR, camr);
+ if (!cpu_is_at32ap7000())
+ writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
out:
return retval;
}
@@ -523,7 +583,10 @@ atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
snd_pcm_uframes_t frames;
unsigned long bytes;
- bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
+ if (cpu_is_at32ap7000())
+ bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
+ else
+ bytes = readl(chip->regs + ATMEL_PDC_TPR);
bytes -= runtime->dma_addr;
frames = bytes_to_frames(runtime, bytes);
@@ -540,7 +603,10 @@ atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
snd_pcm_uframes_t frames;
unsigned long bytes;
- bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
+ if (cpu_is_at32ap7000())
+ bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
+ else
+ bytes = readl(chip->regs + ATMEL_PDC_RPR);
bytes -= runtime->dma_addr;
frames = bytes_to_frames(runtime, bytes);
@@ -578,20 +644,67 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
u32 sr = ac97c_readl(chip, SR);
u32 casr = ac97c_readl(chip, CASR);
u32 cosr = ac97c_readl(chip, COSR);
+ u32 camr = ac97c_readl(chip, CAMR);
if (sr & AC97C_SR_CAEVT) {
- dev_info(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n",
+ struct snd_pcm_runtime *runtime;
+ int offset, next_period, block_size;
+ dev_dbg(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n",
casr & AC97C_CSR_OVRUN ? " OVRUN" : "",
casr & AC97C_CSR_RXRDY ? " RXRDY" : "",
casr & AC97C_CSR_UNRUN ? " UNRUN" : "",
casr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "",
casr & AC97C_CSR_TXRDY ? " TXRDY" : "",
!casr ? " NONE" : "");
+ if (!cpu_is_at32ap7000()) {
+ if ((casr & camr) & AC97C_CSR_ENDTX) {
+ runtime = chip->playback_substream->runtime;
+ block_size = frames_to_bytes(runtime,
+ runtime->period_size);
+ chip->period++;
+
+ if (chip->period == runtime->periods)
+ chip->period = 0;
+ next_period = chip->period + 1;
+ if (next_period == runtime->periods)
+ next_period = 0;
+
+ offset = block_size * next_period;
+
+ writel(runtime->dma_addr + offset,
+ chip->regs + ATMEL_PDC_TNPR);
+ writel(block_size / 2,
+ chip->regs + ATMEL_PDC_TNCR);
+
+ snd_pcm_period_elapsed(
+ chip->playback_substream);
+ }
+ if ((casr & camr) & AC97C_CSR_ENDRX) {
+ runtime = chip->capture_substream->runtime;
+ block_size = frames_to_bytes(runtime,
+ runtime->period_size);
+ chip->period++;
+
+ if (chip->period == runtime->periods)
+ chip->period = 0;
+ next_period = chip->period + 1;
+ if (next_period == runtime->periods)
+ next_period = 0;
+
+ offset = block_size * next_period;
+
+ writel(runtime->dma_addr + offset,
+ chip->regs + ATMEL_PDC_RNPR);
+ writel(block_size / 2,
+ chip->regs + ATMEL_PDC_RNCR);
+ snd_pcm_period_elapsed(chip->capture_substream);
+ }
+ }
retval = IRQ_HANDLED;
}
if (sr & AC97C_SR_COEVT) {
- dev_info(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n",
+ dev_dbg(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n",
cosr & AC97C_CSR_OVRUN ? " OVRUN" : "",
cosr & AC97C_CSR_RXRDY ? " RXRDY" : "",
cosr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "",
@@ -608,15 +721,50 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
return retval;
}
+static struct ac97_pcm at91_ac97_pcm_defs[] __devinitdata = {
+ /* Playback */
+ {
+ .exclusive = 1,
+ .r = { {
+ .slots = ((1 << AC97_SLOT_PCM_LEFT)
+ | (1 << AC97_SLOT_PCM_RIGHT)),
+ } },
+ },
+ /* PCM in */
+ {
+ .stream = 1,
+ .exclusive = 1,
+ .r = { {
+ .slots = ((1 << AC97_SLOT_PCM_LEFT)
+ | (1 << AC97_SLOT_PCM_RIGHT)),
+ } }
+ },
+ /* Mic in */
+ {
+ .stream = 1,
+ .exclusive = 1,
+ .r = { {
+ .slots = (1<<AC97_SLOT_MIC),
+ } }
+ },
+};
+
static int __devinit atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
{
struct snd_pcm *pcm;
struct snd_pcm_hardware hw = atmel_ac97c_hw;
- int capture, playback, retval;
+ int capture, playback, retval, err;
capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+ if (!cpu_is_at32ap7000()) {
+ err = snd_ac97_pcm_assign(chip->ac97_bus,
+ ARRAY_SIZE(at91_ac97_pcm_defs),
+ at91_ac97_pcm_defs);
+ if (err)
+ return err;
+ }
retval = snd_pcm_new(chip->card, chip->card->shortname,
chip->pdev->id, playback, capture, &pcm);
if (retval)
@@ -775,7 +923,12 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
return -ENXIO;
}
- pclk = clk_get(&pdev->dev, "pclk");
+ if (cpu_is_at32ap7000()) {
+ pclk = clk_get(&pdev->dev, "pclk");
+ } else {
+ pclk = clk_get(&pdev->dev, "ac97_clk");
+ }
+
if (IS_ERR(pclk)) {
dev_dbg(&pdev->dev, "no peripheral clock\n");
return PTR_ERR(pclk);
@@ -844,43 +997,52 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
goto err_ac97_bus;
}
- if (pdata->rx_dws.dma_dev) {
- struct dw_dma_slave *dws = &pdata->rx_dws;
- dma_cap_mask_t mask;
+ if (cpu_is_at32ap7000()) {
+ if (pdata->rx_dws.dma_dev) {
+ struct dw_dma_slave *dws = &pdata->rx_dws;
+ dma_cap_mask_t mask;
- dws->rx_reg = regs->start + AC97C_CARHR + 2;
+ dws->rx_reg = regs->start + AC97C_CARHR + 2;
- dma_cap_zero(mask);
- dma_cap_set(DMA_SLAVE, mask);
+ dma_cap_zero(mask);
+ dma_cap_set(DMA_SLAVE, mask);
- chip->dma.rx_chan = dma_request_channel(mask, filter, dws);
+ chip->dma.rx_chan = dma_request_channel(mask, filter,
+ dws);
- dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
+ dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
dev_name(&chip->dma.rx_chan->dev->device));
- set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
- }
+ set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+ }
- if (pdata->tx_dws.dma_dev) {
- struct dw_dma_slave *dws = &pdata->tx_dws;
- dma_cap_mask_t mask;
+ if (pdata->tx_dws.dma_dev) {
+ struct dw_dma_slave *dws = &pdata->tx_dws;
+ dma_cap_mask_t mask;
- dws->tx_reg = regs->start + AC97C_CATHR + 2;
+ dws->tx_reg = regs->start + AC97C_CATHR + 2;
- dma_cap_zero(mask);
- dma_cap_set(DMA_SLAVE, mask);
+ dma_cap_zero(mask);
+ dma_cap_set(DMA_SLAVE, mask);
- chip->dma.tx_chan = dma_request_channel(mask, filter, dws);
+ chip->dma.tx_chan = dma_request_channel(mask, filter,
+ dws);
- dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
+ dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
dev_name(&chip->dma.tx_chan->dev->device));
- set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
- }
+ set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+ }
- if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
- !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
- dev_dbg(&pdev->dev, "DMA not available\n");
- retval = -ENODEV;
- goto err_dma;
+ if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
+ !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
+ dev_dbg(&pdev->dev, "DMA not available\n");
+ retval = -ENODEV;
+ goto err_dma;
+ }
+ } else {
+ /* Just pretend that we have DMA channel(for at91 i is actually
+ * the PDC */
+ set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+ set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
}
retval = atmel_ac97c_pcm_new(chip);
@@ -897,20 +1059,22 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, card);
- dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p\n",
- chip->regs);
+ dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n",
+ chip->regs, irq);
return 0;
err_dma:
- if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
- dma_release_channel(chip->dma.rx_chan);
- if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
- dma_release_channel(chip->dma.tx_chan);
- clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
- clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
- chip->dma.rx_chan = NULL;
- chip->dma.tx_chan = NULL;
+ if (cpu_is_at32ap7000()) {
+ if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
+ dma_release_channel(chip->dma.rx_chan);
+ if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
+ dma_release_channel(chip->dma.tx_chan);
+ clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+ clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+ chip->dma.rx_chan = NULL;
+ chip->dma.tx_chan = NULL;
+ }
err_ac97_bus:
snd_card_set_dev(card, NULL);
@@ -934,12 +1098,13 @@ static int atmel_ac97c_suspend(struct platform_device *pdev, pm_message_t msg)
struct snd_card *card = platform_get_drvdata(pdev);
struct atmel_ac97c *chip = card->private_data;
- if (test_bit(DMA_RX_READY, &chip->flags))
- dw_dma_cyclic_stop(chip->dma.rx_chan);
- if (test_bit(DMA_TX_READY, &chip->flags))
- dw_dma_cyclic_stop(chip->dma.tx_chan);
+ if (cpu_is_at32ap7000()) {
+ if (test_bit(DMA_RX_READY, &chip->flags))
+ dw_dma_cyclic_stop(chip->dma.rx_chan);
+ if (test_bit(DMA_TX_READY, &chip->flags))
+ dw_dma_cyclic_stop(chip->dma.tx_chan);
+ }
clk_disable(chip->pclk);
-
return 0;
}
@@ -949,11 +1114,12 @@ static int atmel_ac97c_resume(struct platform_device *pdev)
struct atmel_ac97c *chip = card->private_data;
clk_enable(chip->pclk);
- if (test_bit(DMA_RX_READY, &chip->flags))
- dw_dma_cyclic_start(chip->dma.rx_chan);
- if (test_bit(DMA_TX_READY, &chip->flags))
- dw_dma_cyclic_start(chip->dma.tx_chan);
-
+ if (cpu_is_at32ap7000()) {
+ if (test_bit(DMA_RX_READY, &chip->flags))
+ dw_dma_cyclic_start(chip->dma.rx_chan);
+ if (test_bit(DMA_TX_READY, &chip->flags))
+ dw_dma_cyclic_start(chip->dma.tx_chan);
+ }
return 0;
}
#else
@@ -978,14 +1144,16 @@ static int __devexit atmel_ac97c_remove(struct platform_device *pdev)
iounmap(chip->regs);
free_irq(chip->irq, chip);
- if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
- dma_release_channel(chip->dma.rx_chan);
- if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
- dma_release_channel(chip->dma.tx_chan);
- clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
- clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
- chip->dma.rx_chan = NULL;
- chip->dma.tx_chan = NULL;
+ if (cpu_is_at32ap7000()) {
+ if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
+ dma_release_channel(chip->dma.rx_chan);
+ if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
+ dma_release_channel(chip->dma.tx_chan);
+ clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+ clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+ chip->dma.rx_chan = NULL;
+ chip->dma.tx_chan = NULL;
+ }
snd_card_set_dev(card, NULL);
snd_card_free(card);
--
1.5.3.7
1
0
06 Oct '09
Hi,
Following your discussion on moving low-level controls from MIXER to PCM
types, I would like to suggest the following two patches:
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 3896fb9..28ca8a4 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -2160,7 +2160,7 @@ static int snd_vt1724_pro_peak_get(struct
snd_kcontrol *kcontrol,
}
static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "Multi Track Peak",
.access = SNDRV_CTL_ELEM_ACCESS_READ |
SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_vt1724_pro_peak_info,
diff --git a/envy24control/levelmeters.c b/envy24control/levelmeters.c
index 3bf1a94..9bdaace 100644
--- a/envy24control/levelmeters.c
+++ b/envy24control/levelmeters.c
@@ -262,7 +262,7 @@ void level_meters_reset_peaks(GtkButton *button,
gpointer da
void level_meters_init(void)
{
snd_ctl_elem_value_malloc(&peaks);
- snd_ctl_elem_value_set_interface(peaks, SND_CTL_ELEM_IFACE_MIXER);
+ snd_ctl_elem_value_set_interface(peaks, SND_CTL_ELEM_IFACE_PCM);
snd_ctl_elem_value_set_name(peaks, "Multi Track Peak");
}
The point is these controls are read-only, display incorrectly in
alsamixer, and are very confusing for majority of users who do not read
envy24 datasheet and the source code.
Thanks for considering this IMO useful change.
Regards,
Pavel.
3
3
[alsa-devel] [PATCHv3 7/7] ASoC: TWL6030: Detect power-up sequence completion
by Lopez Cruz, Misael 06 Oct '09
by Lopez Cruz, Misael 06 Oct '09
06 Oct '09
When the codec is powered-up through external AUDPWRON line it starts
its power-up sequence. The completion of the sequence is signaled
through the audio interrupt, and then codec is operational.
If NAUDINT irq is provided, CODEC driver starts a wait_for_completion
just after AUDPWRON line transitions from low to high. It's signaled as
complete when servicing READYINT interrupt.
If AUDPWRON gpio line is provided but NAUDINT irq is not, then CODEC
driver enables READYINT and polls on INTID register. If none of them are
provided, then CODEC uses manual power sequences and disables all audio
interrupts.
Signed-off-by: Misael Lopez Cruz <x0052729(a)ti.com>
---
sound/soc/codecs/twl6030.c | 61 +++++++++++++++++++++++++++++++++++++------
sound/soc/codecs/twl6030.h | 1 +
2 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/sound/soc/codecs/twl6030.c b/sound/soc/codecs/twl6030.c
index 56fe136..3db7f1d 100644
--- a/sound/soc/codecs/twl6030.c
+++ b/sound/soc/codecs/twl6030.c
@@ -52,6 +52,7 @@ struct twl6030_data {
int non_lp;
unsigned int sysclk;
struct snd_pcm_hw_constraint_list *sysclk_constraints;
+ struct completion ready;
};
/*
@@ -372,6 +373,7 @@ static int twl6030_power_mode_event(struct snd_soc_dapm_widget *w,
static irqreturn_t twl6030_naudint_handler(int irq, void *data)
{
struct snd_soc_codec *codec = data;
+ struct twl6030_data *priv = codec->private_data;
u8 intid;
twl_i2c_read_u8(TWL6030_MODULE_AUDIO, &intid, TWL6030_REG_INTID);
@@ -391,7 +393,7 @@ static irqreturn_t twl6030_naudint_handler(int irq, void *data)
dev_alert(codec->dev, "vib drivers over current detection\n");
break;
case TWL6030_READYINT:
- dev_alert(codec->dev, "codec is ready\n");
+ complete(&priv->ready);
break;
default:
dev_err(codec->dev, "unknown audio interrupt %d\n", intid);
@@ -626,11 +628,45 @@ static int twl6030_add_widgets(struct snd_soc_codec *codec)
return 0;
}
+static int twl6030_power_up_completion(struct snd_soc_codec *codec,
+ int naudint)
+{
+ struct twl6030_data *priv = codec->private_data;
+ int time_left;
+ u8 intid;
+
+ if (naudint) {
+ /* wait for ready interrupt with 48 ms timeout */
+ time_left = wait_for_completion_timeout(&priv->ready,
+ msecs_to_jiffies(48));
+ } else {
+ /* retry 3 times only */
+ for (time_left = 3; time_left > 0; time_left--) {
+ mdelay(16);
+ twl_i2c_read_u8(TWL6030_MODULE_AUDIO, &intid,
+ TWL6030_REG_INTID);
+ if (intid & TWL6030_READYINT)
+ break;
+ }
+ }
+
+ if (!time_left) {
+ dev_err(codec->dev, "timeout waiting for READYINT\n");
+ return -ETIMEDOUT;
+ }
+
+ priv->codec_powered = 1;
+
+ return 0;
+}
+
static int twl6030_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
struct twl6030_data *priv = codec->private_data;
int audpwron = priv->audpwron;
+ int naudint = priv->naudint;
+ int ret;
switch (level) {
case SND_SOC_BIAS_ON:
@@ -643,8 +679,10 @@ static int twl6030_set_bias_level(struct snd_soc_codec *codec,
/* use AUDPWRON line */
gpio_set_value(audpwron, 1);
- /* power-up sequence latency */
- mdelay(16);
+ /* wait for power-up completion */
+ ret = twl6030_power_up_completion(codec, naudint);
+ if (ret)
+ return ret;
/* sync registers updated during power-up sequence */
twl6030_read(codec, TWL6030_REG_NCPCTL);
@@ -653,12 +691,11 @@ static int twl6030_set_bias_level(struct snd_soc_codec *codec,
} else {
/* use manual power-up sequence */
twl6030_power_up(codec);
+ priv->codec_powered = 1;
}
/* initialize vdd/vss registers with reg_cache */
twl6030_init_vdd_regs(codec);
-
- priv->codec_powered = 1;
break;
case SND_SOC_BIAS_OFF:
if (!priv->codec_powered)
@@ -1068,6 +1105,7 @@ static int __devinit twl6030_codec_probe(struct platform_device *pdev)
mutex_init(&codec->mutex);
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);
+ init_completion(&priv->ready);
if (gpio_is_valid(audpwron)) {
ret = gpio_request(audpwron, "audpwron");
@@ -1090,10 +1128,15 @@ static int __devinit twl6030_codec_probe(struct platform_device *pdev)
if (ret)
goto gpio2_err;
} else {
- dev_warn(codec->dev,
- "no naudint irq, audio interrupts disabled\n");
- twl6030_write_reg_cache(codec, TWL6030_REG_INTMR,
- TWL6030_ALLINT_MSK);
+ if (gpio_is_valid(audpwron)) {
+ /* enable only codec ready interrupt */
+ twl6030_write_reg_cache(codec, TWL6030_REG_INTMR,
+ ~TWL6030_READYMSK & TWL6030_ALLINT_MSK);
+ } else {
+ /* no interrupts at all */
+ twl6030_write_reg_cache(codec, TWL6030_REG_INTMR,
+ TWL6030_ALLINT_MSK);
+ }
}
/* init vio registers */
diff --git a/sound/soc/codecs/twl6030.h b/sound/soc/codecs/twl6030.h
index 786fd80..cdc3a3a 100644
--- a/sound/soc/codecs/twl6030.h
+++ b/sound/soc/codecs/twl6030.h
@@ -79,6 +79,7 @@
/* INTMR (0x04) fields */
+#define TWL6030_READYMSK 0x40
#define TWL6030_ALLINT_MSK 0x7B
/* NCPCTL (0x05) fields */
--
1.5.4.3
1
0
06 Oct '09
NAUDINT interrupt line is provided by the TWL6030 codec to signal
externally events like headset plug/unplug, hook, power-up sequence
completion, etc.
Signed-off-by: Misael Lopez Cruz <x0052729(a)ti.com>
---
sound/soc/codecs/twl6030.c | 70 ++++++++++++++++++++++++++++++++++++++++---
sound/soc/codecs/twl6030.h | 14 +++++++++
2 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/twl6030.c b/sound/soc/codecs/twl6030.c
index 8548442..56fe136 100644
--- a/sound/soc/codecs/twl6030.c
+++ b/sound/soc/codecs/twl6030.c
@@ -46,6 +46,7 @@
struct twl6030_data {
struct snd_soc_codec codec;
int audpwron;
+ int naudint;
int codec_powered;
int pll;
int non_lp;
@@ -61,7 +62,7 @@ static const u8 twl6030_reg[TWL6030_CACHEREGNUM] = {
0x4B, /* TWL6030_ASICID (ro) 0x01 */
0x00, /* TWL6030_ASICREV (ro) 0x02 */
0x00, /* TWL6030_INTID 0x03 */
- 0x7B, /* TWL6030_INTMR 0x04 */
+ 0x00, /* TWL6030_INTMR 0x04 */
0x00, /* TWL6030_NCPCTRL 0x05 */
0x00, /* TWL6030_LDOCTL 0x06 */
0x00, /* TWL6030_HPPLLCTL 0x07 */
@@ -367,6 +368,39 @@ static int twl6030_power_mode_event(struct snd_soc_dapm_widget *w,
return 0;
}
+/* audio interrupt handler */
+static irqreturn_t twl6030_naudint_handler(int irq, void *data)
+{
+ struct snd_soc_codec *codec = data;
+ u8 intid;
+
+ twl_i2c_read_u8(TWL6030_MODULE_AUDIO, &intid, TWL6030_REG_INTID);
+
+ switch (intid) {
+ case TWL6030_THINT:
+ dev_alert(codec->dev, "die temp over-limit detection\n");
+ break;
+ case TWL6030_PLUGINT:
+ case TWL6030_UNPLUGINT:
+ case TWL6030_HOOKINT:
+ break;
+ case TWL6030_HFINT:
+ dev_alert(codec->dev, "hf drivers over current detection\n");
+ break;
+ case TWL6030_VIBINT:
+ dev_alert(codec->dev, "vib drivers over current detection\n");
+ break;
+ case TWL6030_READYINT:
+ dev_alert(codec->dev, "codec is ready\n");
+ break;
+ default:
+ dev_err(codec->dev, "unknown audio interrupt %d\n", intid);
+ break;
+ }
+
+ return IRQ_HANDLED;
+}
+
/*
* MICATT volume control:
* from -6 to 0 dB in 6 dB steps
@@ -993,19 +1027,23 @@ static int __devinit twl6030_codec_probe(struct platform_device *pdev)
struct twl_codec_data *twl_codec = pdev->dev.platform_data;
struct snd_soc_codec *codec;
struct twl6030_data *priv;
- int audpwron;
+ int audpwron, naudint;
int ret = 0;
priv = kzalloc(sizeof(struct twl6030_data), GFP_KERNEL);
if (priv == NULL)
return -ENOMEM;
- if (twl_codec)
+ if (twl_codec) {
audpwron = twl_codec->audpwron_gpio;
- else
+ naudint = twl_codec->naudint_irq;
+ } else {
audpwron = -EINVAL;
+ naudint = 0;
+ }
priv->audpwron = audpwron;
+ priv->naudint = naudint;
codec = &priv->codec;
codec->dev = &pdev->dev;
@@ -1043,13 +1081,28 @@ static int __devinit twl6030_codec_probe(struct platform_device *pdev)
priv->codec_powered = 0;
}
+ if (naudint) {
+ /* audio interrupt */
+ ret = request_threaded_irq(naudint, NULL,
+ twl6030_naudint_handler,
+ IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+ "twl6030_codec", codec);
+ if (ret)
+ goto gpio2_err;
+ } else {
+ dev_warn(codec->dev,
+ "no naudint irq, audio interrupts disabled\n");
+ twl6030_write_reg_cache(codec, TWL6030_REG_INTMR,
+ TWL6030_ALLINT_MSK);
+ }
+
/* init vio registers */
twl6030_init_vio_regs(codec);
/* power on device */
ret = twl6030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
if (ret)
- goto gpio2_err;
+ goto irq_err;
ret = snd_soc_register_codec(codec);
if (ret)
@@ -1068,6 +1121,9 @@ dai_err:
twl6030_codec = NULL;
reg_err:
twl6030_set_bias_level(codec, SND_SOC_BIAS_OFF);
+irq_err:
+ if (naudint)
+ free_irq(naudint, codec);
gpio2_err:
if (gpio_is_valid(audpwron))
gpio_free(audpwron);
@@ -1082,10 +1138,14 @@ static int __devexit twl6030_codec_remove(struct platform_device *pdev)
{
struct twl6030_data *priv = twl6030_codec->private_data;
int audpwron = priv->audpwron;
+ int naudint = priv->naudint;
if (gpio_is_valid(audpwron))
gpio_free(audpwron);
+ if (naudint)
+ free_irq(naudint, twl6030_codec);
+
snd_soc_unregister_dai(&twl6030_dai);
snd_soc_unregister_codec(twl6030_codec);
diff --git a/sound/soc/codecs/twl6030.h b/sound/soc/codecs/twl6030.h
index 87f1e1e..786fd80 100644
--- a/sound/soc/codecs/twl6030.h
+++ b/sound/soc/codecs/twl6030.h
@@ -67,6 +67,20 @@
#define TWL6030_VIOREGNUM 18
#define TWL6030_VDDREGNUM 21
+/* INTID (0x03) fields */
+
+#define TWL6030_THINT 0x01
+#define TWL6030_PLUGINT 0x02
+#define TWL6030_UNPLUGINT 0x04
+#define TWL6030_HOOKINT 0x08
+#define TWL6030_HFINT 0x10
+#define TWL6030_VIBINT 0x20
+#define TWL6030_READYINT 0x40
+
+/* INTMR (0x04) fields */
+
+#define TWL6030_ALLINT_MSK 0x7B
+
/* NCPCTL (0x05) fields */
#define TWL6030_NCPENA 0x01
--
1.5.4.3
1
0
[alsa-devel] [PATCHv3 5/7] ASoC: TWL6030: Add restrictions for low-power playback mode
by Lopez Cruz, Misael 06 Oct '09
by Lopez Cruz, Misael 06 Oct '09
06 Oct '09
Low-power playback mode is a special scenario where only headset path
(headset DAC and driver) is active. Only in this mode the codec can
support 44.1 and 48 kHz, low-power PLL should provide sysclk signal.
Currently, handsfree DAC and driver are the only components that can
prevent codec to enter to low-power playback mode. Other components
like earphone driver, vibrator driver or loopback (which are not yet
supported in the driver) can cause the same effect.
In order to detect conflicting paths, CODEC driver supervises
non-low-power widgets powered by DAPM mechanism, just at the point
pcm trigger callback gets called.
Signed-off-by: Misael Lopez Cruz <x0052729(a)ti.com>
---
sound/soc/codecs/twl6030.c | 79 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/twl6030.c b/sound/soc/codecs/twl6030.c
index 9fc4795..8548442 100644
--- a/sound/soc/codecs/twl6030.c
+++ b/sound/soc/codecs/twl6030.c
@@ -48,6 +48,7 @@ struct twl6030_data {
int audpwron;
int codec_powered;
int pll;
+ int non_lp;
unsigned int sysclk;
struct snd_pcm_hw_constraint_list *sysclk_constraints;
};
@@ -352,6 +353,20 @@ static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
return 0;
}
+static int twl6030_power_mode_event(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+ struct twl6030_data *priv = codec->private_data;
+
+ if (SND_SOC_DAPM_EVENT_ON(event))
+ priv->non_lp++;
+ else
+ priv->non_lp--;
+
+ return 0;
+}
+
/*
* MICATT volume control:
* from -6 to 0 dB in 6 dB steps
@@ -485,10 +500,14 @@ static const struct snd_soc_dapm_widget twl6030_dapm_widgets[] = {
TWL6030_REG_HSLCTL, 0, 0),
SND_SOC_DAPM_DAC("HSDAC Right", "Headset Playback",
TWL6030_REG_HSRCTL, 0, 0),
- SND_SOC_DAPM_DAC("HFDAC Left", "Handsfree Playback",
- TWL6030_REG_HFLCTL, 0, 0),
- SND_SOC_DAPM_DAC("HFDAC Right", "Handsfree Playback",
- TWL6030_REG_HFRCTL, 0, 0),
+ SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback",
+ TWL6030_REG_HFLCTL, 0, 0,
+ twl6030_power_mode_event,
+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+ SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback",
+ TWL6030_REG_HFRCTL, 0, 0,
+ twl6030_power_mode_event,
+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
/* Analog playback switches */
SND_SOC_DAPM_SWITCH("HSDAC Left Playback",
@@ -504,10 +523,14 @@ static const struct snd_soc_dapm_widget twl6030_dapm_widgets[] = {
SND_SOC_NOPM, 0, 0, &hsl_driver_switch_controls),
SND_SOC_DAPM_SWITCH("Headset Right Driver",
SND_SOC_NOPM, 0, 0, &hsr_driver_switch_controls),
- SND_SOC_DAPM_SWITCH("Handsfree Left Driver",
- SND_SOC_NOPM, 0, 0, &hfl_driver_switch_controls),
- SND_SOC_DAPM_SWITCH("Handsfree Right Driver",
- SND_SOC_NOPM, 0, 0, &hfr_driver_switch_controls),
+ SND_SOC_DAPM_SWITCH_E("Handsfree Left Driver",
+ SND_SOC_NOPM, 0, 0, &hfl_driver_switch_controls,
+ twl6030_power_mode_event,
+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+ SND_SOC_DAPM_SWITCH_E("Handsfree Right Driver",
+ SND_SOC_NOPM, 0, 0, &hfr_driver_switch_controls,
+ twl6030_power_mode_event,
+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
/* Analog playback PGAs */
SND_SOC_DAPM_PGA("HFDAC Left PGA",
@@ -668,6 +691,17 @@ static int twl6030_startup(struct snd_pcm_substream *substream,
return -EINVAL;
}
+ /*
+ * capture is not supported at 17.64 MHz,
+ * it's reserved for headset low-power playback scenario
+ */
+ if ((priv->sysclk == 17640000) && substream->stream) {
+ dev_err(codec->dev,
+ "capture mode is not supported at %dHz\n",
+ priv->sysclk);
+ return -EINVAL;
+ }
+
snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_RATE,
priv->sysclk_constraints);
@@ -712,6 +746,34 @@ static int twl6030_hw_params(struct snd_pcm_substream *substream,
return 0;
}
+static int twl6030_trigger(struct snd_pcm_substream *substream,
+ int cmd, struct snd_soc_dai *dai)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->card->codec;
+ struct twl6030_data *priv = codec->private_data;
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ /*
+ * low-power playback mode is restricted
+ * for headset path only
+ */
+ if ((priv->sysclk == 17640000) && priv->non_lp) {
+ dev_err(codec->dev,
+ "some enabled paths aren't supported at %dHz\n",
+ priv->sysclk);
+ return -EPERM;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
static int twl6030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
@@ -822,6 +884,7 @@ static int twl6030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
static struct snd_soc_dai_ops twl6030_dai_ops = {
.startup = twl6030_startup,
.hw_params = twl6030_hw_params,
+ .trigger = twl6030_trigger,
.set_sysclk = twl6030_set_dai_sysclk,
};
--
1.5.4.3
1
0
[alsa-devel] [PATCHv3 4/7] ASoC: TWL6030: Add support for low-power PLL
by Lopez Cruz, Misael 06 Oct '09
by Lopez Cruz, Misael 06 Oct '09
06 Oct '09
TWL6030 codec sysclk can be provided by: low-power or high
performance PLL.
The low-power PLL takes a low-frequency input at 32,768 Hz and
generates an approximate of 17.64 or 19.2 MHz.
The high-performance PLL generates an exact 19.2 MHz clock signal
from high-frequency input at 12/19.2/26/38.4 MHz.
For the particular case of headset path, PLL being used defines the
headset power mode: low-power, high-performance. Headset DAC and
output driver should be configured according to the selected mode.
17.64 MHz sysclk is recommended only for headset low-power playback
mode.
Signed-off-by: Misael Lopez Cruz <x0052729(a)ti.com>
---
sound/soc/codecs/twl6030.c | 232 +++++++++++++++++++++++++++++++++++++------
sound/soc/codecs/twl6030.h | 16 +++
2 files changed, 215 insertions(+), 33 deletions(-)
diff --git a/sound/soc/codecs/twl6030.c b/sound/soc/codecs/twl6030.c
index f97dec2..9fc4795 100644
--- a/sound/soc/codecs/twl6030.c
+++ b/sound/soc/codecs/twl6030.c
@@ -39,7 +39,7 @@
#include "twl6030.h"
-#define TWL6030_RATES (SNDRV_PCM_RATE_48000)
+#define TWL6030_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
#define TWL6030_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
/* codec private data */
@@ -47,6 +47,9 @@ struct twl6030_data {
struct snd_soc_codec codec;
int audpwron;
int codec_powered;
+ int pll;
+ unsigned int sysclk;
+ struct snd_pcm_hw_constraint_list *sysclk_constraints;
};
/*
@@ -326,6 +329,29 @@ static void twl6030_power_down(struct snd_soc_codec *codec)
mdelay(10);
}
+/* set headset dac and driver power mode */
+static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
+{
+ int hslctl, hsrctl;
+ int mask = TWL6030_HSDRVMODEL | TWL6030_HSDACMODEL;
+
+ hslctl = twl6030_read_reg_cache(codec, TWL6030_REG_HSLCTL);
+ hsrctl = twl6030_read_reg_cache(codec, TWL6030_REG_HSRCTL);
+
+ if (high_perf) {
+ hslctl &= ~mask;
+ hsrctl &= ~mask;
+ } else {
+ hslctl |= mask;
+ hsrctl |= mask;
+ }
+
+ twl6030_write(codec, TWL6030_REG_HSLCTL, hslctl);
+ twl6030_write(codec, TWL6030_REG_HSRCTL, hsrctl);
+
+ return 0;
+}
+
/*
* MICATT volume control:
* from -6 to 0 dB in 6 dB steps
@@ -607,55 +633,195 @@ static int twl6030_set_bias_level(struct snd_soc_codec *codec,
return 0;
}
+/* set of rates for each pll: low-power and high-performance */
+
+static unsigned int lp_rates[] = {
+ 44100,
+ 48000,
+};
+
+static struct snd_pcm_hw_constraint_list lp_constraints = {
+ .count = ARRAY_SIZE(lp_rates),
+ .list = lp_rates,
+};
+
+static unsigned int hp_rates[] = {
+ 48000,
+};
+
+static struct snd_pcm_hw_constraint_list hp_constraints = {
+ .count = ARRAY_SIZE(hp_rates),
+ .list = hp_rates,
+};
+
+static int twl6030_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->card->codec;
+ struct twl6030_data *priv = codec->private_data;
+
+ if (!priv->sysclk) {
+ dev_err(codec->dev,
+ "no mclk configured, call set_sysclk() on init\n");
+ return -EINVAL;
+ }
+
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ priv->sysclk_constraints);
+
+ return 0;
+}
+
+static int twl6030_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->card->codec;
+ struct twl6030_data *priv = codec->private_data;
+ u8 lppllctl;
+ int rate;
+
+ /* nothing to do for high-perf pll, it supports only 48 kHz */
+ if (priv->pll == TWL6030_HPPLL_ID)
+ return 0;
+
+ lppllctl = twl6030_read_reg_cache(codec, TWL6030_REG_LPPLLCTL);
+
+ rate = params_rate(params);
+ switch (rate) {
+ case 44100:
+ lppllctl |= TWL6030_LPLLFIN;
+ priv->sysclk = 17640000;
+ break;
+ case 48000:
+ lppllctl &= ~TWL6030_LPLLFIN;
+ priv->sysclk = 19200000;
+ break;
+ default:
+ dev_err(codec->dev, "unsupported rate %d\n", rate);
+ return -EINVAL;
+ }
+
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+
+ return 0;
+}
+
static int twl6030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
struct snd_soc_codec *codec = codec_dai->codec;
+ struct twl6030_data *priv = codec->private_data;
u8 hppllctl, lppllctl;
hppllctl = twl6030_read_reg_cache(codec, TWL6030_REG_HPPLLCTL);
- hppllctl &= ~TWL6030_MCLK_MSK;
-
- switch (freq) {
- case 12000000:
- /* mclk input, pll enabled */
- hppllctl |= TWL6030_MCLK_12000KHZ |
- TWL6030_HPLLSQRBP |
- TWL6030_HPLLENA;
- break;
- case 19200000:
- /* mclk input, pll disabled */
- hppllctl |= TWL6030_MCLK_19200KHZ |
- TWL6030_HPLLSQRBP |
- TWL6030_HPLLBP;
- break;
- case 26000000:
- /* mclk input, pll enabled */
- hppllctl |= TWL6030_MCLK_26000KHZ |
- TWL6030_HPLLSQRBP |
- TWL6030_HPLLENA;
+ lppllctl = twl6030_read_reg_cache(codec, TWL6030_REG_LPPLLCTL);
+
+ switch (clk_id) {
+ case TWL6030_SYSCLK_SEL_LPPLL:
+ switch (freq) {
+ case 32768:
+ /* headset dac and driver must be in low-power mode */
+ headset_power_mode(codec, 0);
+
+ /* clk32k input requires low-power pll */
+ lppllctl |= TWL6030_LPLLENA;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+ mdelay(5);
+ lppllctl &= ~TWL6030_HPLLSEL;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+ hppllctl &= ~TWL6030_HPLLENA;
+ twl6030_write(codec, TWL6030_REG_HPPLLCTL, hppllctl);
+ break;
+ default:
+ dev_err(codec->dev, "unknown mclk freq %d\n", freq);
+ return -EINVAL;
+ }
+
+ /* lppll divider */
+ switch (priv->sysclk) {
+ case 17640000:
+ lppllctl |= TWL6030_LPLLFIN;
+ break;
+ case 19200000:
+ lppllctl &= ~TWL6030_LPLLFIN;
+ break;
+ default:
+ /* sysclk not yet configured */
+ lppllctl &= ~TWL6030_LPLLFIN;
+ priv->sysclk = 19200000;
+ break;
+ }
+
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+
+ priv->pll = TWL6030_LPPLL_ID;
+ priv->sysclk_constraints = &lp_constraints;
break;
- case 38400000:
- /* clk slicer, pll disabled */
- hppllctl |= TWL6030_MCLK_38400KHZ |
- TWL6030_HPLLSQRENA |
- TWL6030_HPLLBP;
+ case TWL6030_SYSCLK_SEL_HPPLL:
+ hppllctl &= ~TWL6030_MCLK_MSK;
+
+ switch (freq) {
+ case 12000000:
+ /* mclk input, pll enabled */
+ hppllctl |= TWL6030_MCLK_12000KHZ |
+ TWL6030_HPLLSQRBP |
+ TWL6030_HPLLENA;
+ break;
+ case 19200000:
+ /* mclk input, pll disabled */
+ hppllctl |= TWL6030_MCLK_19200KHZ |
+ TWL6030_HPLLSQRBP |
+ TWL6030_HPLLBP;
+ break;
+ case 26000000:
+ /* mclk input, pll enabled */
+ hppllctl |= TWL6030_MCLK_26000KHZ |
+ TWL6030_HPLLSQRBP |
+ TWL6030_HPLLENA;
+ break;
+ case 38400000:
+ /* clk slicer, pll disabled */
+ hppllctl |= TWL6030_MCLK_38400KHZ |
+ TWL6030_HPLLSQRENA |
+ TWL6030_HPLLBP;
+ break;
+ default:
+ dev_err(codec->dev, "unknown mclk freq %d\n", freq);
+ return -EINVAL;
+ }
+
+ /* headset dac and driver must be in high-performance mode */
+ headset_power_mode(codec, 1);
+
+ twl6030_write(codec, TWL6030_REG_HPPLLCTL, hppllctl);
+ udelay(500);
+ lppllctl |= TWL6030_HPLLSEL;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+ lppllctl &= ~TWL6030_LPLLENA;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+
+ /* high-performance pll can provide only 19.2 MHz */
+ priv->pll = TWL6030_HPPLL_ID;
+ priv->sysclk = 19200000;
+ priv->sysclk_constraints = &hp_constraints;
break;
default:
- dev_err(codec->dev, "unknown sysclk freq %d\n", freq);
+ dev_err(codec->dev, "unknown clk_id %d\n", clk_id);
return -EINVAL;
}
- twl6030_write(codec, TWL6030_REG_HPPLLCTL, hppllctl);
-
- /* Disable LPPLL and select HPPLL */
- lppllctl = TWL6030_HPLLSEL;
- twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
-
return 0;
}
static struct snd_soc_dai_ops twl6030_dai_ops = {
+ .startup = twl6030_startup,
+ .hw_params = twl6030_hw_params,
.set_sysclk = twl6030_set_dai_sysclk,
};
diff --git a/sound/soc/codecs/twl6030.h b/sound/soc/codecs/twl6030.h
index 7375ae8..87f1e1e 100644
--- a/sound/soc/codecs/twl6030.h
+++ b/sound/soc/codecs/twl6030.h
@@ -100,10 +100,26 @@
#define TWL6030_LPLLFIN 0x08
#define TWL6030_HPLLSEL 0x10
+/* HSLCTL (0x10) fields */
+
+#define TWL6030_HSDACMODEL 0x02
+#define TWL6030_HSDRVMODEL 0x08
+
+/* HSRCTL (0x11) fields */
+
+#define TWL6030_HSDACMODER 0x02
+#define TWL6030_HSDRVMODER 0x08
+
/* ACCCTL (0x2D) fields */
#define TWL6030_RESETSPLIT 0x04
+#define TWL6030_SYSCLK_SEL_LPPLL 1
+#define TWL6030_SYSCLK_SEL_HPPLL 2
+
+#define TWL6030_HPPLL_ID 1
+#define TWL6030_LPPLL_ID 2
+
extern struct snd_soc_dai twl6030_dai;
extern struct snd_soc_codec_device soc_codec_dev_twl6030;
--
1.5.4.3
1
0
[alsa-devel] [PATCHv3 3/7] ASoC: TWL6030: Manual power-up/down sequences
by Lopez Cruz, Misael 06 Oct '09
by Lopez Cruz, Misael 06 Oct '09
06 Oct '09
TWL6030 codec device can be powered-up/down through a specific register
writes sequence. These sequences can be used when no gpio line is
provided for AUDPWRON.
When the codec is powered-up in this way, automatic power-down sequence
(triggered by thermal shutdown) is not possible.
Signed-off-by: Misael Lopez Cruz <x0052729(a)ti.com>
---
sound/soc/codecs/twl6030.c | 112 ++++++++++++++++++++++++++++++++++++++-----
sound/soc/codecs/twl6030.h | 16 ++++++
2 files changed, 115 insertions(+), 13 deletions(-)
diff --git a/sound/soc/codecs/twl6030.c b/sound/soc/codecs/twl6030.c
index 3c6c540..f97dec2 100644
--- a/sound/soc/codecs/twl6030.c
+++ b/sound/soc/codecs/twl6030.c
@@ -244,6 +244,88 @@ static void twl6030_init_vdd_regs(struct snd_soc_codec *codec)
}
}
+/* twl6030 codec manual power-up sequence */
+static void twl6030_power_up(struct snd_soc_codec *codec)
+{
+ u8 ncpctl, ldoctl, lppllctl, accctl;
+
+ ncpctl = twl6030_read_reg_cache(codec, TWL6030_REG_NCPCTL);
+ ldoctl = twl6030_read_reg_cache(codec, TWL6030_REG_LDOCTL);
+ lppllctl = twl6030_read_reg_cache(codec, TWL6030_REG_LPPLLCTL);
+ accctl = twl6030_read_reg_cache(codec, TWL6030_REG_ACCCTL);
+
+ /* enable reference system */
+ ldoctl |= TWL6030_REFENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ mdelay(10);
+ /* enable internal oscillator */
+ ldoctl |= TWL6030_OSCENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ udelay(10);
+ /* enable high-side ldo */
+ ldoctl |= TWL6030_HSLDOENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ udelay(244);
+ /* enable negative charge pump */
+ ncpctl |= TWL6030_NCPENA | TWL6030_NCPOPEN;
+ twl6030_write(codec, TWL6030_REG_NCPCTL, ncpctl);
+ udelay(488);
+ /* enable low-side ldo */
+ ldoctl |= TWL6030_LSLDOENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ udelay(244);
+ /* enable low-power pll */
+ lppllctl |= TWL6030_LPLLENA;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+ /* reset state machine */
+ accctl |= TWL6030_RESETSPLIT;
+ twl6030_write(codec, TWL6030_REG_ACCCTL, accctl);
+ mdelay(5);
+ accctl &= ~TWL6030_RESETSPLIT;
+ twl6030_write(codec, TWL6030_REG_ACCCTL, accctl);
+ /* disable internal oscillator */
+ ldoctl &= ~TWL6030_OSCENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+}
+
+/* twl6030 codec manual power-down sequence */
+static void twl6030_power_down(struct snd_soc_codec *codec)
+{
+ u8 ncpctl, ldoctl, lppllctl, accctl;
+
+ ncpctl = twl6030_read_reg_cache(codec, TWL6030_REG_NCPCTL);
+ ldoctl = twl6030_read_reg_cache(codec, TWL6030_REG_LDOCTL);
+ lppllctl = twl6030_read_reg_cache(codec, TWL6030_REG_LPPLLCTL);
+ accctl = twl6030_read_reg_cache(codec, TWL6030_REG_ACCCTL);
+
+ /* enable internal oscillator */
+ ldoctl |= TWL6030_OSCENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ udelay(10);
+ /* disable low-power pll */
+ lppllctl &= ~TWL6030_LPLLENA;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+ /* disable low-side ldo */
+ ldoctl &= ~TWL6030_LSLDOENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ udelay(244);
+ /* disable negative charge pump */
+ ncpctl &= ~(TWL6030_NCPENA | TWL6030_NCPOPEN);
+ twl6030_write(codec, TWL6030_REG_NCPCTL, ncpctl);
+ udelay(488);
+ /* disable high-side ldo */
+ ldoctl &= ~TWL6030_HSLDOENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ udelay(244);
+ /* disable internal oscillator */
+ ldoctl &= ~TWL6030_OSCENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ /* disable reference system */
+ ldoctl &= ~TWL6030_REFENA;
+ twl6030_write(codec, TWL6030_REG_LDOCTL, ldoctl);
+ mdelay(10);
+}
+
/*
* MICATT volume control:
* from -6 to 0 dB in 6 dB steps
@@ -480,12 +562,15 @@ static int twl6030_set_bias_level(struct snd_soc_codec *codec,
/* power-up sequence latency */
mdelay(16);
- }
- /* sync registers updated during power-up sequence */
- twl6030_read(codec, TWL6030_REG_NCPCTL);
- twl6030_read(codec, TWL6030_REG_LDOCTL);
- twl6030_read(codec, TWL6030_REG_LPPLLCTL);
+ /* sync registers updated during power-up sequence */
+ twl6030_read(codec, TWL6030_REG_NCPCTL);
+ twl6030_read(codec, TWL6030_REG_LDOCTL);
+ twl6030_read(codec, TWL6030_REG_LPPLLCTL);
+ } else {
+ /* use manual power-up sequence */
+ twl6030_power_up(codec);
+ }
/* initialize vdd/vss registers with reg_cache */
twl6030_init_vdd_regs(codec);
@@ -502,12 +587,16 @@ static int twl6030_set_bias_level(struct snd_soc_codec *codec,
/* power-down sequence latency */
udelay(500);
- }
- /* sync registers updated during power-down sequence */
- twl6030_read(codec, TWL6030_REG_NCPCTL);
- twl6030_read(codec, TWL6030_REG_LDOCTL);
- twl6030_write_reg_cache(codec, TWL6030_REG_LPPLLCTL, 0x00);
+ /* sync registers updated during power-down sequence */
+ twl6030_read(codec, TWL6030_REG_NCPCTL);
+ twl6030_read(codec, TWL6030_REG_LDOCTL);
+ twl6030_write_reg_cache(codec, TWL6030_REG_LPPLLCTL,
+ 0x00);
+ } else {
+ /* use manual power-down sequence */
+ twl6030_power_down(codec);
+ }
priv->codec_powered = 0;
break;
@@ -723,9 +812,6 @@ static int __devinit twl6030_codec_probe(struct platform_device *pdev)
goto gpio2_err;
priv->codec_powered = 0;
- } else {
- /* if no gpio is provided, then assume its always on */
- priv->codec_powered = 1;
}
/* init vio registers */
diff --git a/sound/soc/codecs/twl6030.h b/sound/soc/codecs/twl6030.h
index d99d469..7375ae8 100644
--- a/sound/soc/codecs/twl6030.h
+++ b/sound/soc/codecs/twl6030.h
@@ -67,6 +67,18 @@
#define TWL6030_VIOREGNUM 18
#define TWL6030_VDDREGNUM 21
+/* NCPCTL (0x05) fields */
+
+#define TWL6030_NCPENA 0x01
+#define TWL6030_NCPOPEN 0x40
+
+/* LDOCTL (0x06) fields */
+
+#define TWL6030_LSLDOENA 0x01
+#define TWL6030_HSLDOENA 0x04
+#define TWL6030_REFENA 0x40
+#define TWL6030_OSCENA 0x80
+
/* HPPLLCTL (0x07) fields */
#define TWL6030_HPLLENA 0x01
@@ -88,6 +100,10 @@
#define TWL6030_LPLLFIN 0x08
#define TWL6030_HPLLSEL 0x10
+/* ACCCTL (0x2D) fields */
+
+#define TWL6030_RESETSPLIT 0x04
+
extern struct snd_soc_dai twl6030_dai;
extern struct snd_soc_codec_device soc_codec_dev_twl6030;
--
1.5.4.3
1
0
06 Oct '09
Initial version of TWL6030 codec driver.
The TWL6030 codec uses a propietary PDM-based digital audio interface.
Audio paths supported are:
- Input: Main Mic, Sub Mic, Headset Mic, Auxiliary-FM Left/Right
- Output: Headset Left/Right, Handsfree Left/Right
Signed-off-by: Misael Lopez Cruz <x0052729(a)ti.com>
---
sound/soc/codecs/Kconfig | 4 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/twl6030.c | 824 ++++++++++++++++++++++++++++++++++++++++++++
sound/soc/codecs/twl6030.h | 94 +++++
4 files changed, 924 insertions(+), 0 deletions(-)
create mode 100644 sound/soc/codecs/twl6030.c
create mode 100644 sound/soc/codecs/twl6030.h
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index bbc97fd..0effb52 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -25,6 +25,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_TLV320AIC26 if SPI_MASTER
select SND_SOC_TLV320AIC3X if I2C
select SND_SOC_TWL4030 if TWL4030_CORE
+ select SND_SOC_TWL6030 if TWL6030_CORE
select SND_SOC_UDA134X
select SND_SOC_UDA1380 if I2C
select SND_SOC_WM8350 if MFD_WM8350
@@ -114,6 +115,9 @@ config SND_SOC_TLV320AIC3X
config SND_SOC_TWL4030
tristate
+config SND_SOC_TWL6030
+ tristate
+
config SND_SOC_UDA134X
tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 8b75305..b70c8a1 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -13,6 +13,7 @@ snd-soc-tlv320aic23-objs := tlv320aic23.o
snd-soc-tlv320aic26-objs := tlv320aic26.o
snd-soc-tlv320aic3x-objs := tlv320aic3x.o
snd-soc-twl4030-objs := twl4030.o
+snd-soc-twl6030-objs := twl6030.o
snd-soc-uda134x-objs := uda134x.o
snd-soc-uda1380-objs := uda1380.o
snd-soc-wm8350-objs := wm8350.o
@@ -50,6 +51,7 @@ obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o
obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o
+obj-$(CONFIG_SND_SOC_TWL6030) += snd-soc-twl6030.o
obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o
obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o
obj-$(CONFIG_SND_SOC_WM8350) += snd-soc-wm8350.o
diff --git a/sound/soc/codecs/twl6030.c b/sound/soc/codecs/twl6030.c
new file mode 100644
index 0000000..3c6c540
--- /dev/null
+++ b/sound/soc/codecs/twl6030.c
@@ -0,0 +1,824 @@
+/*
+ * ALSA SoC TWL6030 codec driver
+ *
+ * Author: Misael Lopez Cruz <x0052729(a)ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/i2c/twl.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+
+#include "twl6030.h"
+
+#define TWL6030_RATES (SNDRV_PCM_RATE_48000)
+#define TWL6030_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
+
+/* codec private data */
+struct twl6030_data {
+ struct snd_soc_codec codec;
+ int audpwron;
+ int codec_powered;
+};
+
+/*
+ * twl6030 register cache & default register settings
+ */
+static const u8 twl6030_reg[TWL6030_CACHEREGNUM] = {
+ 0x00, /* not used 0x00 */
+ 0x4B, /* TWL6030_ASICID (ro) 0x01 */
+ 0x00, /* TWL6030_ASICREV (ro) 0x02 */
+ 0x00, /* TWL6030_INTID 0x03 */
+ 0x7B, /* TWL6030_INTMR 0x04 */
+ 0x00, /* TWL6030_NCPCTRL 0x05 */
+ 0x00, /* TWL6030_LDOCTL 0x06 */
+ 0x00, /* TWL6030_HPPLLCTL 0x07 */
+ 0x00, /* TWL6030_LPPLLCTL 0x08 */
+ 0x00, /* TWL6030_LPPLLDIV 0x09 */
+ 0x00, /* TWL6030_AMICBCTL 0x0A */
+ 0x00, /* TWL6030_DMICBCTL 0x0B */
+ 0x18, /* TWL6030_MICLCTL 0x0C */
+ 0x18, /* TWL6030_MICRCTL 0x0D */
+ 0x00, /* TWL6030_MICGAIN 0x0E */
+ 0x1B, /* TWL6030_LINEGAIN 0x0F */
+ 0x00, /* TWL6030_HSLCTL 0x10 */
+ 0x00, /* TWL6030_HSRCTL 0x11 */
+ 0x00, /* TWL6030_HSGAIN 0x12 */
+ 0x06, /* TWL6030_EARCTL 0x13 */
+ 0x00, /* TWL6030_HFLCTL 0x14 */
+ 0x03, /* TWL6030_HFLGAIN 0x15 */
+ 0x00, /* TWL6030_HFRCTL 0x16 */
+ 0x03, /* TWL6030_HFRGAIN 0x17 */
+ 0x00, /* TWL6030_VIBCTLL 0x18 */
+ 0x00, /* TWL6030_VIBDATL 0x19 */
+ 0x00, /* TWL6030_VIBCTLR 0x1A */
+ 0x00, /* TWL6030_VIBDATR 0x1B */
+ 0x00, /* TWL6030_HKCTL1 0x1C */
+ 0x00, /* TWL6030_HKCTL2 0x1D */
+ 0x00, /* TWL6030_GPOCTL 0x1E */
+ 0x00, /* TWL6030_ALB 0x1F */
+ 0x00, /* TWL6030_DLB 0x20 */
+ 0x00, /* not used 0x21 */
+ 0x00, /* not used 0x22 */
+ 0x00, /* not used 0x23 */
+ 0x00, /* not used 0x24 */
+ 0x00, /* not used 0x25 */
+ 0x00, /* not used 0x26 */
+ 0x00, /* not used 0x27 */
+ 0x00, /* TWL6030_TRIM1 0x28 */
+ 0x00, /* TWL6030_TRIM2 0x29 */
+ 0x00, /* TWL6030_TRIM3 0x2A */
+ 0x00, /* TWL6030_HSOTRIM 0x2B */
+ 0x00, /* TWL6030_HFOTRIM 0x2C */
+ 0x09, /* TWL6030_ACCCTL 0x2D */
+ 0x00, /* TWL6030_STATUS (ro) 0x2E */
+};
+
+/*
+ * twl6030 vio/gnd registers:
+ * registers under vio/gnd supply can be accessed
+ * before the power-up sequence, after NRESPWRON goes high
+ */
+static const int twl6030_vio_reg[TWL6030_VIOREGNUM] = {
+ TWL6030_REG_ASICID,
+ TWL6030_REG_ASICREV,
+ TWL6030_REG_INTID,
+ TWL6030_REG_INTMR,
+ TWL6030_REG_NCPCTL,
+ TWL6030_REG_LDOCTL,
+ TWL6030_REG_AMICBCTL,
+ TWL6030_REG_DMICBCTL,
+ TWL6030_REG_HKCTL1,
+ TWL6030_REG_HKCTL2,
+ TWL6030_REG_GPOCTL,
+ TWL6030_REG_TRIM1,
+ TWL6030_REG_TRIM2,
+ TWL6030_REG_TRIM3,
+ TWL6030_REG_HSOTRIM,
+ TWL6030_REG_HFOTRIM,
+ TWL6030_REG_ACCCTL,
+ TWL6030_REG_STATUS,
+};
+
+/*
+ * twl6030 vdd/vss registers:
+ * registers under vdd/vss supplies can only be accessed
+ * after the power-up sequence
+ */
+static const int twl6030_vdd_reg[TWL6030_VDDREGNUM] = {
+ TWL6030_REG_HPPLLCTL,
+ TWL6030_REG_LPPLLCTL,
+ TWL6030_REG_LPPLLDIV,
+ TWL6030_REG_MICLCTL,
+ TWL6030_REG_MICRCTL,
+ TWL6030_REG_MICGAIN,
+ TWL6030_REG_LINEGAIN,
+ TWL6030_REG_HSLCTL,
+ TWL6030_REG_HSRCTL,
+ TWL6030_REG_HSGAIN,
+ TWL6030_REG_EARCTL,
+ TWL6030_REG_HFLCTL,
+ TWL6030_REG_HFLGAIN,
+ TWL6030_REG_HFRCTL,
+ TWL6030_REG_HFRGAIN,
+ TWL6030_REG_VIBCTLL,
+ TWL6030_REG_VIBDATL,
+ TWL6030_REG_VIBCTLR,
+ TWL6030_REG_VIBDATR,
+ TWL6030_REG_ALB,
+ TWL6030_REG_DLB,
+};
+
+/*
+ * read twl6030 register cache
+ */
+static inline unsigned int twl6030_read_reg_cache(struct snd_soc_codec *codec,
+ unsigned int reg)
+{
+ u8 *cache = codec->reg_cache;
+
+ if (reg >= TWL6030_CACHEREGNUM)
+ return -EIO;
+
+ return cache[reg];
+}
+
+/*
+ * write twl6030 register cache
+ */
+static inline void twl6030_write_reg_cache(struct snd_soc_codec *codec,
+ u8 reg, u8 value)
+{
+ u8 *cache = codec->reg_cache;
+
+ if (reg >= TWL6030_CACHEREGNUM)
+ return;
+ cache[reg] = value;
+}
+
+/*
+ * read from twl6030 hardware register
+ */
+static int twl6030_read(struct snd_soc_codec *codec,
+ unsigned int reg)
+{
+ u8 value;
+
+ if (reg >= TWL6030_CACHEREGNUM)
+ return -EIO;
+
+ twl_i2c_read_u8(TWL6030_MODULE_AUDIO, &value, reg);
+ twl6030_write_reg_cache(codec, reg, value);
+
+ return value;
+}
+
+/*
+ * write to the twl6030 register space
+ */
+static int twl6030_write(struct snd_soc_codec *codec,
+ unsigned int reg, unsigned int value)
+{
+ if (reg >= TWL6030_CACHEREGNUM)
+ return -EIO;
+
+ twl6030_write_reg_cache(codec, reg, value);
+ return twl_i2c_write_u8(TWL6030_MODULE_AUDIO, value, reg);
+}
+
+static void twl6030_init_vio_regs(struct snd_soc_codec *codec)
+{
+ u8 *cache = codec->reg_cache;
+ int reg, i;
+
+ /* allow registers to be accessed by i2c */
+ twl6030_write(codec, TWL6030_REG_ACCCTL, cache[TWL6030_REG_ACCCTL]);
+
+ for (i = 0; i < TWL6030_VIOREGNUM; i++) {
+ reg = twl6030_vio_reg[i];
+ /* skip read-only registers (ASICID, ASICREV, STATUS) */
+ if ((reg == TWL6030_REG_ASICID) ||
+ (reg == TWL6030_REG_ASICREV) ||
+ (reg == TWL6030_REG_STATUS))
+ continue;
+ twl6030_write(codec, reg, cache[reg]);
+ }
+}
+
+static void twl6030_init_vdd_regs(struct snd_soc_codec *codec)
+{
+ u8 *cache = codec->reg_cache;
+ int reg, i;
+
+ for (i = 0; i < TWL6030_VDDREGNUM; i++) {
+ reg = twl6030_vdd_reg[i];
+ twl6030_write(codec, reg, cache[reg]);
+ }
+}
+
+/*
+ * MICATT volume control:
+ * from -6 to 0 dB in 6 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0);
+
+/*
+ * MICGAIN volume control:
+ * from 6 to 30 dB in 6 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0);
+
+/*
+ * HSGAIN volume control:
+ * from -30 to 0 dB in 2 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0);
+
+/*
+ * HFGAIN volume control:
+ * from -52 to 6 dB in 2 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0);
+
+/* Left analog microphone selection */
+static const char *twl6030_amicl_texts[] =
+ {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"};
+
+/* Right analog microphone selection */
+static const char *twl6030_amicr_texts[] =
+ {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
+
+static const struct soc_enum twl6030_enum[] = {
+ SOC_ENUM_SINGLE(TWL6030_REG_MICLCTL, 3, 3, twl6030_amicl_texts),
+ SOC_ENUM_SINGLE(TWL6030_REG_MICRCTL, 3, 3, twl6030_amicr_texts),
+};
+
+static const struct snd_kcontrol_new amicl_control =
+ SOC_DAPM_ENUM("Route", twl6030_enum[0]);
+
+static const struct snd_kcontrol_new amicr_control =
+ SOC_DAPM_ENUM("Route", twl6030_enum[1]);
+
+/* Headset DAC playback switches */
+static const struct snd_kcontrol_new hsdacl_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HSLCTL, 5, 1, 0);
+
+static const struct snd_kcontrol_new hsdacr_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HSRCTL, 5, 1, 0);
+
+/* Handsfree DAC playback switches */
+static const struct snd_kcontrol_new hfdacl_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HFLCTL, 2, 1, 0);
+
+static const struct snd_kcontrol_new hfdacr_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HFRCTL, 2, 1, 0);
+
+/* Headset driver switches */
+static const struct snd_kcontrol_new hsl_driver_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HSLCTL, 2, 1, 0);
+
+static const struct snd_kcontrol_new hsr_driver_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HSRCTL, 2, 1, 0);
+
+/* Handsfree driver switches */
+static const struct snd_kcontrol_new hfl_driver_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HFLCTL, 4, 1, 0);
+
+static const struct snd_kcontrol_new hfr_driver_switch_controls =
+ SOC_DAPM_SINGLE("Switch", TWL6030_REG_HFRCTL, 4, 1, 0);
+
+static const struct snd_kcontrol_new twl6030_snd_controls[] = {
+ /* Capture gains */
+ SOC_DOUBLE_TLV("Capture Preamplifier Volume",
+ TWL6030_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv),
+ SOC_DOUBLE_TLV("Capture Volume",
+ TWL6030_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv),
+
+ /* Playback gains */
+ SOC_DOUBLE_TLV("Headset Playback Volume",
+ TWL6030_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
+ SOC_DOUBLE_R_TLV("Handsfree Playback Volume",
+ TWL6030_REG_HFLGAIN, TWL6030_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
+
+};
+
+static const struct snd_soc_dapm_widget twl6030_dapm_widgets[] = {
+ /* Inputs */
+ SND_SOC_DAPM_INPUT("MAINMIC"),
+ SND_SOC_DAPM_INPUT("HSMIC"),
+ SND_SOC_DAPM_INPUT("SUBMIC"),
+ SND_SOC_DAPM_INPUT("AFML"),
+ SND_SOC_DAPM_INPUT("AFMR"),
+
+ /* Outputs */
+ SND_SOC_DAPM_OUTPUT("HSOL"),
+ SND_SOC_DAPM_OUTPUT("HSOR"),
+ SND_SOC_DAPM_OUTPUT("HFL"),
+ SND_SOC_DAPM_OUTPUT("HFR"),
+
+ /* Analog input muxes for the capture amplifiers */
+ SND_SOC_DAPM_MUX("Analog Left Capture Route",
+ SND_SOC_NOPM, 0, 0, &amicl_control),
+ SND_SOC_DAPM_MUX("Analog Right Capture Route",
+ SND_SOC_NOPM, 0, 0, &amicr_control),
+
+ /* Analog capture PGAs */
+ SND_SOC_DAPM_PGA("MicAmpL",
+ TWL6030_REG_MICLCTL, 0, 0, NULL, 0),
+ SND_SOC_DAPM_PGA("MicAmpR",
+ TWL6030_REG_MICRCTL, 0, 0, NULL, 0),
+
+ /* ADCs */
+ SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture",
+ TWL6030_REG_MICLCTL, 2, 0),
+ SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture",
+ TWL6030_REG_MICRCTL, 2, 0),
+
+ /* Microphone bias */
+ SND_SOC_DAPM_MICBIAS("Headset Mic Bias",
+ TWL6030_REG_AMICBCTL, 0, 0),
+ SND_SOC_DAPM_MICBIAS("Main Mic Bias",
+ TWL6030_REG_AMICBCTL, 4, 0),
+ SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias",
+ TWL6030_REG_DMICBCTL, 0, 0),
+ SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias",
+ TWL6030_REG_DMICBCTL, 4, 0),
+
+ /* DACs */
+ SND_SOC_DAPM_DAC("HSDAC Left", "Headset Playback",
+ TWL6030_REG_HSLCTL, 0, 0),
+ SND_SOC_DAPM_DAC("HSDAC Right", "Headset Playback",
+ TWL6030_REG_HSRCTL, 0, 0),
+ SND_SOC_DAPM_DAC("HFDAC Left", "Handsfree Playback",
+ TWL6030_REG_HFLCTL, 0, 0),
+ SND_SOC_DAPM_DAC("HFDAC Right", "Handsfree Playback",
+ TWL6030_REG_HFRCTL, 0, 0),
+
+ /* Analog playback switches */
+ SND_SOC_DAPM_SWITCH("HSDAC Left Playback",
+ SND_SOC_NOPM, 0, 0, &hsdacl_switch_controls),
+ SND_SOC_DAPM_SWITCH("HSDAC Right Playback",
+ SND_SOC_NOPM, 0, 0, &hsdacr_switch_controls),
+ SND_SOC_DAPM_SWITCH("HFDAC Left Playback",
+ SND_SOC_NOPM, 0, 0, &hfdacl_switch_controls),
+ SND_SOC_DAPM_SWITCH("HFDAC Right Playback",
+ SND_SOC_NOPM, 0, 0, &hfdacr_switch_controls),
+
+ SND_SOC_DAPM_SWITCH("Headset Left Driver",
+ SND_SOC_NOPM, 0, 0, &hsl_driver_switch_controls),
+ SND_SOC_DAPM_SWITCH("Headset Right Driver",
+ SND_SOC_NOPM, 0, 0, &hsr_driver_switch_controls),
+ SND_SOC_DAPM_SWITCH("Handsfree Left Driver",
+ SND_SOC_NOPM, 0, 0, &hfl_driver_switch_controls),
+ SND_SOC_DAPM_SWITCH("Handsfree Right Driver",
+ SND_SOC_NOPM, 0, 0, &hfr_driver_switch_controls),
+
+ /* Analog playback PGAs */
+ SND_SOC_DAPM_PGA("HFDAC Left PGA",
+ TWL6030_REG_HFLCTL, 1, 0, NULL, 0),
+ SND_SOC_DAPM_PGA("HFDAC Right PGA",
+ TWL6030_REG_HFRCTL, 1, 0, NULL, 0),
+
+};
+
+static const struct snd_soc_dapm_route intercon[] = {
+ /* Capture path */
+ {"Analog Left Capture Route", "Headset Mic", "HSMIC"},
+ {"Analog Left Capture Route", "Main Mic", "MAINMIC"},
+ {"Analog Left Capture Route", "Aux/FM Left", "AFML"},
+
+ {"Analog Right Capture Route", "Headset Mic", "HSMIC"},
+ {"Analog Right Capture Route", "Sub Mic", "SUBMIC"},
+ {"Analog Right Capture Route", "Aux/FM Right", "AFMR"},
+
+ {"MicAmpL", NULL, "Analog Left Capture Route"},
+ {"MicAmpR", NULL, "Analog Right Capture Route"},
+
+ {"ADC Left", NULL, "MicAmpL"},
+ {"ADC Right", NULL, "MicAmpR"},
+
+ /* Headset playback path */
+ {"HSDAC Left Playback", "Switch", "HSDAC Left"},
+ {"HSDAC Right Playback", "Switch", "HSDAC Right"},
+
+ {"Headset Left Driver", "Switch", "HSDAC Left Playback"},
+ {"Headset Right Driver", "Switch", "HSDAC Right Playback"},
+
+ {"HSOL", NULL, "Headset Left Driver"},
+ {"HSOR", NULL, "Headset Right Driver"},
+
+ /* Handsfree playback path */
+ {"HFDAC Left Playback", "Switch", "HFDAC Left"},
+ {"HFDAC Right Playback", "Switch", "HFDAC Right"},
+
+ {"HFDAC Left PGA", NULL, "HFDAC Left Playback"},
+ {"HFDAC Right PGA", NULL, "HFDAC Right Playback"},
+
+ {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"},
+ {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"},
+
+ {"HFL", NULL, "Handsfree Left Driver"},
+ {"HFR", NULL, "Handsfree Right Driver"},
+};
+
+static int twl6030_add_widgets(struct snd_soc_codec *codec)
+{
+ snd_soc_dapm_new_controls(codec, twl6030_dapm_widgets,
+ ARRAY_SIZE(twl6030_dapm_widgets));
+
+ snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
+
+ snd_soc_dapm_new_widgets(codec);
+
+ return 0;
+}
+
+static int twl6030_set_bias_level(struct snd_soc_codec *codec,
+ enum snd_soc_bias_level level)
+{
+ struct twl6030_data *priv = codec->private_data;
+ int audpwron = priv->audpwron;
+
+ switch (level) {
+ case SND_SOC_BIAS_ON:
+ case SND_SOC_BIAS_PREPARE:
+ case SND_SOC_BIAS_STANDBY:
+ if (priv->codec_powered)
+ break;
+
+ if (gpio_is_valid(audpwron)) {
+ /* use AUDPWRON line */
+ gpio_set_value(audpwron, 1);
+
+ /* power-up sequence latency */
+ mdelay(16);
+ }
+
+ /* sync registers updated during power-up sequence */
+ twl6030_read(codec, TWL6030_REG_NCPCTL);
+ twl6030_read(codec, TWL6030_REG_LDOCTL);
+ twl6030_read(codec, TWL6030_REG_LPPLLCTL);
+
+ /* initialize vdd/vss registers with reg_cache */
+ twl6030_init_vdd_regs(codec);
+
+ priv->codec_powered = 1;
+ break;
+ case SND_SOC_BIAS_OFF:
+ if (!priv->codec_powered)
+ break;
+
+ if (gpio_is_valid(audpwron)) {
+ /* use AUDPWRON line */
+ gpio_set_value(audpwron, 0);
+
+ /* power-down sequence latency */
+ udelay(500);
+ }
+
+ /* sync registers updated during power-down sequence */
+ twl6030_read(codec, TWL6030_REG_NCPCTL);
+ twl6030_read(codec, TWL6030_REG_LDOCTL);
+ twl6030_write_reg_cache(codec, TWL6030_REG_LPPLLCTL, 0x00);
+
+ priv->codec_powered = 0;
+ break;
+ }
+
+ codec->bias_level = level;
+
+ return 0;
+}
+
+static int twl6030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+ int clk_id, unsigned int freq, int dir)
+{
+ struct snd_soc_codec *codec = codec_dai->codec;
+ u8 hppllctl, lppllctl;
+
+ hppllctl = twl6030_read_reg_cache(codec, TWL6030_REG_HPPLLCTL);
+ hppllctl &= ~TWL6030_MCLK_MSK;
+
+ switch (freq) {
+ case 12000000:
+ /* mclk input, pll enabled */
+ hppllctl |= TWL6030_MCLK_12000KHZ |
+ TWL6030_HPLLSQRBP |
+ TWL6030_HPLLENA;
+ break;
+ case 19200000:
+ /* mclk input, pll disabled */
+ hppllctl |= TWL6030_MCLK_19200KHZ |
+ TWL6030_HPLLSQRBP |
+ TWL6030_HPLLBP;
+ break;
+ case 26000000:
+ /* mclk input, pll enabled */
+ hppllctl |= TWL6030_MCLK_26000KHZ |
+ TWL6030_HPLLSQRBP |
+ TWL6030_HPLLENA;
+ break;
+ case 38400000:
+ /* clk slicer, pll disabled */
+ hppllctl |= TWL6030_MCLK_38400KHZ |
+ TWL6030_HPLLSQRENA |
+ TWL6030_HPLLBP;
+ break;
+ default:
+ dev_err(codec->dev, "unknown sysclk freq %d\n", freq);
+ return -EINVAL;
+ }
+
+ twl6030_write(codec, TWL6030_REG_HPPLLCTL, hppllctl);
+
+ /* Disable LPPLL and select HPPLL */
+ lppllctl = TWL6030_HPLLSEL;
+ twl6030_write(codec, TWL6030_REG_LPPLLCTL, lppllctl);
+
+ return 0;
+}
+
+static struct snd_soc_dai_ops twl6030_dai_ops = {
+ .set_sysclk = twl6030_set_dai_sysclk,
+};
+
+struct snd_soc_dai twl6030_dai = {
+ .name = "twl6030",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = 1,
+ .channels_max = 4,
+ .rates = TWL6030_RATES,
+ .formats = TWL6030_FORMATS,
+ },
+ .capture = {
+ .stream_name = "Capture",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = TWL6030_RATES,
+ .formats = TWL6030_FORMATS,
+ },
+ .ops = &twl6030_dai_ops,
+};
+EXPORT_SYMBOL_GPL(twl6030_dai);
+
+static int twl6030_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec = socdev->card->codec;
+
+ twl6030_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+ return 0;
+}
+
+static int twl6030_resume(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec = socdev->card->codec;
+
+ twl6030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+ twl6030_set_bias_level(codec, codec->suspend_bias_level);
+
+ return 0;
+}
+
+static struct snd_soc_codec *twl6030_codec;
+
+static int twl6030_probe(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec;
+ int ret = 0;
+
+ BUG_ON(!twl6030_codec);
+
+ codec = twl6030_codec;
+ socdev->card->codec = codec;
+
+ /* register pcms */
+ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "failed to create pcms\n");
+ return ret;
+ }
+
+ snd_soc_add_controls(codec, twl6030_snd_controls,
+ ARRAY_SIZE(twl6030_snd_controls));
+ twl6030_add_widgets(codec);
+
+ ret = snd_soc_init_card(socdev);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "failed to register card\n");
+ goto card_err;
+ }
+
+ return ret;
+
+card_err:
+ snd_soc_free_pcms(socdev);
+ snd_soc_dapm_free(socdev);
+ return ret;
+}
+
+static int twl6030_remove(struct platform_device *pdev)
+{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec = socdev->card->codec;
+
+ twl6030_set_bias_level(codec, SND_SOC_BIAS_OFF);
+ snd_soc_free_pcms(socdev);
+ snd_soc_dapm_free(socdev);
+ kfree(codec);
+
+ return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_twl6030 = {
+ .probe = twl6030_probe,
+ .remove = twl6030_remove,
+ .suspend = twl6030_suspend,
+ .resume = twl6030_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_twl6030);
+
+static int __devinit twl6030_codec_probe(struct platform_device *pdev)
+{
+ struct twl_codec_data *twl_codec = pdev->dev.platform_data;
+ struct snd_soc_codec *codec;
+ struct twl6030_data *priv;
+ int audpwron;
+ int ret = 0;
+
+ priv = kzalloc(sizeof(struct twl6030_data), GFP_KERNEL);
+ if (priv == NULL)
+ return -ENOMEM;
+
+ if (twl_codec)
+ audpwron = twl_codec->audpwron_gpio;
+ else
+ audpwron = -EINVAL;
+
+ priv->audpwron = audpwron;
+
+ codec = &priv->codec;
+ codec->dev = &pdev->dev;
+ twl6030_dai.dev = &pdev->dev;
+
+ codec->name = "twl6030";
+ codec->owner = THIS_MODULE;
+ codec->read = twl6030_read_reg_cache;
+ codec->write = twl6030_write;
+ codec->set_bias_level = twl6030_set_bias_level;
+ codec->private_data = priv;
+ codec->dai = &twl6030_dai;
+ codec->num_dai = 1;
+ codec->reg_cache_size = ARRAY_SIZE(twl6030_reg);
+ codec->reg_cache = kmemdup(twl6030_reg, sizeof(twl6030_reg),
+ GFP_KERNEL);
+ if (codec->reg_cache == NULL) {
+ ret = -ENOMEM;
+ goto cache_err;
+ }
+
+ mutex_init(&codec->mutex);
+ INIT_LIST_HEAD(&codec->dapm_widgets);
+ INIT_LIST_HEAD(&codec->dapm_paths);
+
+ if (gpio_is_valid(audpwron)) {
+ ret = gpio_request(audpwron, "audpwron");
+ if (ret)
+ goto gpio1_err;
+
+ ret = gpio_direction_output(audpwron, 0);
+ if (ret)
+ goto gpio2_err;
+
+ priv->codec_powered = 0;
+ } else {
+ /* if no gpio is provided, then assume its always on */
+ priv->codec_powered = 1;
+ }
+
+ /* init vio registers */
+ twl6030_init_vio_regs(codec);
+
+ /* power on device */
+ ret = twl6030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+ if (ret)
+ goto gpio2_err;
+
+ ret = snd_soc_register_codec(codec);
+ if (ret)
+ goto reg_err;
+
+ twl6030_codec = codec;
+
+ ret = snd_soc_register_dai(&twl6030_dai);
+ if (ret)
+ goto dai_err;
+
+ return 0;
+
+dai_err:
+ snd_soc_unregister_codec(codec);
+ twl6030_codec = NULL;
+reg_err:
+ twl6030_set_bias_level(codec, SND_SOC_BIAS_OFF);
+gpio2_err:
+ if (gpio_is_valid(audpwron))
+ gpio_free(audpwron);
+gpio1_err:
+ kfree(codec->reg_cache);
+cache_err:
+ kfree(priv);
+ return ret;
+}
+
+static int __devexit twl6030_codec_remove(struct platform_device *pdev)
+{
+ struct twl6030_data *priv = twl6030_codec->private_data;
+ int audpwron = priv->audpwron;
+
+ if (gpio_is_valid(audpwron))
+ gpio_free(audpwron);
+
+ snd_soc_unregister_dai(&twl6030_dai);
+ snd_soc_unregister_codec(twl6030_codec);
+
+ kfree(twl6030_codec);
+ twl6030_codec = NULL;
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int twl6030_codec_suspend(struct platform_device *pdev,
+ pm_message_t msg)
+{
+ return snd_soc_suspend_device(&pdev->dev);
+}
+
+static int twl6030_codec_resume(struct platform_device *pdev)
+{
+ return snd_soc_resume_device(&pdev->dev);
+}
+#else
+#define twl6030_codec_suspend NULL
+#define twl6030_codec_resume NULL
+#endif
+
+static struct platform_driver twl6030_codec_driver = {
+ .driver = {
+ .name = "twl6030_codec",
+ .owner = THIS_MODULE,
+ },
+ .probe = twl6030_codec_probe,
+ .remove = __devexit_p(twl6030_codec_remove),
+ .suspend = twl6030_codec_suspend,
+ .resume = twl6030_codec_resume,
+};
+
+static int __init twl6030_codec_init(void)
+{
+ return platform_driver_register(&twl6030_codec_driver);
+}
+module_init(twl6030_codec_init);
+
+static void __exit twl6030_codec_exit(void)
+{
+ platform_driver_unregister(&twl6030_codec_driver);
+}
+module_exit(twl6030_codec_exit);
+
+MODULE_DESCRIPTION("ASoC TWL6030 codec driver");
+MODULE_AUTHOR("Misael Lopez Cruz");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/twl6030.h b/sound/soc/codecs/twl6030.h
new file mode 100644
index 0000000..d99d469
--- /dev/null
+++ b/sound/soc/codecs/twl6030.h
@@ -0,0 +1,94 @@
+/*
+ * ALSA SoC TWL6030 codec driver
+ *
+ * Author: Misael Lopez Cruz <x0052729(a)ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __TWL6030_H__
+#define __TWL6030_H__
+
+#define TWL6030_REG_ASICID 0x01
+#define TWL6030_REG_ASICREV 0x02
+#define TWL6030_REG_INTID 0x03
+#define TWL6030_REG_INTMR 0x04
+#define TWL6030_REG_NCPCTL 0x05
+#define TWL6030_REG_LDOCTL 0x06
+#define TWL6030_REG_HPPLLCTL 0x07
+#define TWL6030_REG_LPPLLCTL 0x08
+#define TWL6030_REG_LPPLLDIV 0x09
+#define TWL6030_REG_AMICBCTL 0x0A
+#define TWL6030_REG_DMICBCTL 0x0B
+#define TWL6030_REG_MICLCTL 0x0C
+#define TWL6030_REG_MICRCTL 0x0D
+#define TWL6030_REG_MICGAIN 0x0E
+#define TWL6030_REG_LINEGAIN 0x0F
+#define TWL6030_REG_HSLCTL 0x10
+#define TWL6030_REG_HSRCTL 0x11
+#define TWL6030_REG_HSGAIN 0x12
+#define TWL6030_REG_EARCTL 0x13
+#define TWL6030_REG_HFLCTL 0x14
+#define TWL6030_REG_HFLGAIN 0x15
+#define TWL6030_REG_HFRCTL 0x16
+#define TWL6030_REG_HFRGAIN 0x17
+#define TWL6030_REG_VIBCTLL 0x18
+#define TWL6030_REG_VIBDATL 0x19
+#define TWL6030_REG_VIBCTLR 0x1A
+#define TWL6030_REG_VIBDATR 0x1B
+#define TWL6030_REG_HKCTL1 0x1C
+#define TWL6030_REG_HKCTL2 0x1D
+#define TWL6030_REG_GPOCTL 0x1E
+#define TWL6030_REG_ALB 0x1F
+#define TWL6030_REG_DLB 0x20
+#define TWL6030_REG_TRIM1 0x28
+#define TWL6030_REG_TRIM2 0x29
+#define TWL6030_REG_TRIM3 0x2A
+#define TWL6030_REG_HSOTRIM 0x2B
+#define TWL6030_REG_HFOTRIM 0x2C
+#define TWL6030_REG_ACCCTL 0x2D
+#define TWL6030_REG_STATUS 0x2E
+
+#define TWL6030_CACHEREGNUM (TWL6030_REG_STATUS + 1)
+
+#define TWL6030_VIOREGNUM 18
+#define TWL6030_VDDREGNUM 21
+
+/* HPPLLCTL (0x07) fields */
+
+#define TWL6030_HPLLENA 0x01
+#define TWL6030_HPLLRST 0x02
+#define TWL6030_HPLLBP 0x04
+#define TWL6030_HPLLSQRENA 0x08
+#define TWL6030_HPLLSQRBP 0x10
+#define TWL6030_MCLK_12000KHZ (0 << 5)
+#define TWL6030_MCLK_19200KHZ (1 << 5)
+#define TWL6030_MCLK_26000KHZ (2 << 5)
+#define TWL6030_MCLK_38400KHZ (3 << 5)
+#define TWL6030_MCLK_MSK 0x60
+
+/* LPPLLCTL (0x08) fields */
+
+#define TWL6030_LPLLENA 0x01
+#define TWL6030_LPLLRST 0x02
+#define TWL6030_LPLLSEL 0x04
+#define TWL6030_LPLLFIN 0x08
+#define TWL6030_HPLLSEL 0x10
+
+extern struct snd_soc_dai twl6030_dai;
+extern struct snd_soc_codec_device soc_codec_dev_twl6030;
+
+#endif /* End of __TWL6030_H__ */
--
1.5.4.3
1
0
06 Oct '09
Following patch series adds initial support for TWL6030 codec
driver.
Changes from v2:
- CODEC now handles scenarios where no platform data is passed
- Removed GPIOLIB dependency of codec driver
- Removed magic values, register reads instead
- Added runtime constraints depending on sysclk
- Added more constraints for switching to low-power mode
- Use request_threaded_irq instead (oneshot support required)
- wait_for_completion with timeout
- Changelog now gives a better explanation of features and
corresponding changes
Thanks,
-Misa
---
Misael Lopez Cruz (7):
OMAP4: PMIC: Add support for twl6030 codec
ASoC: TWL6030: Add twl6030 codec driver
ASoC: TWL6030: Manual power-up/down sequences
ASoC: TWL6030: Add support for low-power PLL
ASoC: TWL6030: Add restrictions for low-power playback mode
ASoC: TWL6030: Enable audio interrupt
ASoC: TWL6030: Detect power-up sequence completion
drivers/mfd/twl-core.c | 15 +
include/linux/i2c/twl.h | 7 +
sound/soc/codecs/Kconfig | 4 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/twl6030.c | 1242 ++++++++++++++++++++++++++++++++++++++++++++
sound/soc/codecs/twl6030.h | 141 +++++
6 files changed, 1411 insertions(+), 0 deletions(-)
create mode 100644 sound/soc/codecs/twl6030.c
create mode 100644 sound/soc/codecs/twl6030.h
1
0
[alsa-devel] [PATCH 18/31] HDA patch_via.c: Add 48K sample rate limit for S/PDIF streams.
by Li Bo 06 Oct '09
by Li Bo 06 Oct '09
06 Oct '09
[ALSA] HDA VIA: Add 48K sample rate limit for S/PDIF streams.
Signed-off-by: Lydia Wang <lydiawang(a)viatech.com.cn>
Index: sound-2.6/sound/pci/hda/patch_via.c
===================================================================
--- sound-2.6.orig/sound/pci/hda/patch_via.c 2009-10-05 15:11:02.000000000 +0800
+++ sound-2.6/sound/pci/hda/patch_via.c 2009-10-05 15:11:04.000000000 +0800
@@ -1228,6 +1228,7 @@
.substreams = 1,
.channels_min = 2,
.channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
/* NID is set in via_build_pcms */
.ops = {
.open = via_dig_playback_pcm_open,
@@ -1241,6 +1242,7 @@
.substreams = 1,
.channels_min = 2,
.channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
};
static int via_build_controls(struct hda_codec *codec)
@@ -2042,6 +2044,7 @@
.substreams = 1,
.channels_min = 2,
.channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
/* NID is set in via_build_pcms */
.ops = {
.open = via_dig_playback_pcm_open,
@@ -2657,6 +2660,7 @@
.substreams = 1,
.channels_min = 2,
.channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
/* NID is set in via_build_pcms */
.ops = {
.open = via_dig_playback_pcm_open,
@@ -3137,6 +3141,7 @@
.substreams = 2,
.channels_min = 2,
.channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
/* NID is set in via_build_pcms */
.ops = {
.open = via_dig_playback_pcm_open,
@@ -3581,6 +3586,7 @@
.substreams = 2,
.channels_min = 2,
.channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
/* NID is set in via_build_pcms */
.ops = {
.open = via_dig_playback_pcm_open,
3
5