Skip to contentSkip to conversation

ASoC: SAMSUNG: Move I2S common register definition

PATCH In review Sangbeom Kim 3 participants 10 messages Jun 20, 2011 – Jun 26, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 ASoC: SAMSUNG: Move I2S common register definition

I2S registers can be used for control idma. Previously, register is defined in i2s.c. For sharing the registers, It is moved to i2s-regs.h

---
 sound/soc/samsung/i2s-regs.h |  123 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/samsung/i2s.c      |  104 +-----------------------------------
 2 files changed, 124 insertions(+), 103 deletions(-)
 create mode 100644 sound/soc/samsung/i2s-regs.h
sound/soc/samsung/i2s-regs.h new file +123 -0
new file mode 100644
index 0000000..1fa0cd1
@@ -0,0 +1,123 @@
+/*
+ * linux/sound/soc/samsung/i2s-regs.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung I2S driver's register header
+ *
+ * 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.
+ */
+
+#ifndef __SND_SOC_SAMSUNG_I2S_REGS_H
+#define __SND_SOC_SAMSUNG_I2S_REGS_H
+
+#define I2SCON		0x0
+#define I2SMOD		0x4
+#define I2SFIC		0x8
+#define I2SPSR		0xc
+#define I2STXD		0x10
+#define I2SRXD		0x14
+#define I2SFICS		0x18
+#define I2STXDS		0x1c
+
+#define CON_RSTCLR		(1 << 31)
+#define CON_FRXOFSTATUS		(1 << 26)
+#define CON_FRXORINTEN		(1 << 25)
+#define CON_FTXSURSTAT		(1 << 24)
+#define CON_FTXSURINTEN		(1 << 23)
+#define CON_TXSDMA_PAUSE	(1 << 20)
+#define CON_TXSDMA_ACTIVE	(1 << 18)
+
+#define CON_FTXURSTATUS		(1 << 17)
+#define CON_FTXURINTEN		(1 << 16)
+#define CON_TXFIFO2_EMPTY	(1 << 15)
+#define CON_TXFIFO1_EMPTY	(1 << 14)
+#define CON_TXFIFO2_FULL	(1 << 13)
+#define CON_TXFIFO1_FULL	(1 << 12)
+
+#define CON_LRINDEX		(1 << 11)
+#define CON_TXFIFO_EMPTY	(1 << 10)
+#define CON_RXFIFO_EMPTY	(1 << 9)
+#define CON_TXFIFO_FULL		(1 << 8)
+#define CON_RXFIFO_FULL		(1 << 7)
+#define CON_TXDMA_PAUSE		(1 << 6)
+#define CON_RXDMA_PAUSE		(1 << 5)
+#define CON_TXCH_PAUSE		(1 << 4)
+#define CON_RXCH_PAUSE		(1 << 3)
+#define CON_TXDMA_ACTIVE	(1 << 2)
+#define CON_RXDMA_ACTIVE	(1 << 1)
+#define CON_ACTIVE		(1 << 0)
+
+#define MOD_OPCLK_CDCLK_OUT	(0 << 30)
+#define MOD_OPCLK_CDCLK_IN	(1 << 30)
+#define MOD_OPCLK_BCLK_OUT	(2 << 30)
+#define MOD_OPCLK_PCLK		(3 << 30)
+#define MOD_OPCLK_MASK		(3 << 30)
+#define MOD_TXS_IDMA		(1 << 28) /* Sec_TXFIFO use I-DMA */
+
+#define MOD_BLCS_SHIFT		26
+#define MOD_BLCS_16BIT		(0 << MOD_BLCS_SHIFT)
+#define MOD_BLCS_8BIT		(1 << MOD_BLCS_SHIFT)
+#define MOD_BLCS_24BIT		(2 << MOD_BLCS_SHIFT)
+#define MOD_BLCS_MASK		(3 << MOD_BLCS_SHIFT)
+#define MOD_BLCP_SHIFT		24
+#define MOD_BLCP_16BIT		(0 << MOD_BLCP_SHIFT)
+#define MOD_BLCP_8BIT		(1 << MOD_BLCP_SHIFT)
+#define MOD_BLCP_24BIT		(2 << MOD_BLCP_SHIFT)
+#define MOD_BLCP_MASK		(3 << MOD_BLCP_SHIFT)
+
+#define MOD_C2DD_HHALF		(1 << 21) /* Discard Higher-half */
+#define MOD_C2DD_LHALF		(1 << 20) /* Discard Lower-half */
+#define MOD_C1DD_HHALF		(1 << 19)
+#define MOD_C1DD_LHALF		(1 << 18)
+#define MOD_DC2_EN		(1 << 17)
+#define MOD_DC1_EN		(1 << 16)
+#define MOD_BLC_16BIT		(0 << 13)
+#define MOD_BLC_8BIT		(1 << 13)
+#define MOD_BLC_24BIT		(2 << 13)
+#define MOD_BLC_MASK		(3 << 13)
+
+#define MOD_IMS_SYSMUX		(1 << 10)
+#define MOD_SLAVE		(1 << 11)
+#define MOD_TXONLY		(0 << 8)
+#define MOD_RXONLY		(1 << 8)
+#define MOD_TXRX		(2 << 8)
+#define MOD_MASK		(3 << 8)
+#define MOD_LR_LLOW		(0 << 7)
+#define MOD_LR_RLOW		(1 << 7)
+#define MOD_SDF_IIS		(0 << 5)
+#define MOD_SDF_MSB		(1 << 5)
+#define MOD_SDF_LSB		(2 << 5)
+#define MOD_SDF_MASK		(3 << 5)
+#define MOD_RCLK_256FS		(0 << 3)
+#define MOD_RCLK_512FS		(1 << 3)
+#define MOD_RCLK_384FS		(2 << 3)
+#define MOD_RCLK_768FS		(3 << 3)
+#define MOD_RCLK_MASK		(3 << 3)
+#define MOD_BCLK_32FS		(0 << 1)
+#define MOD_BCLK_48FS		(1 << 1)
+#define MOD_BCLK_16FS		(2 << 1)
+#define MOD_BCLK_24FS		(3 << 1)
+#define MOD_BCLK_MASK		(3 << 1)
+#define MOD_8BIT		(1 << 0)
+
+#define MOD_CDCLKCON		(1 << 12)
+
+#define PSR_PSREN		(1 << 15)
+
+#define FIC_TX2COUNT(x)		(((x) >>  24) & 0xf)
+#define FIC_TX1COUNT(x)		(((x) >>  16) & 0xf)
+
+#define FIC_TXFLUSH		(1 << 15)
+#define FIC_RXFLUSH		(1 << 7)
+#define FIC_TXCOUNT(x)		(((x) >>  8) & 0xf)
+#define FIC_RXCOUNT(x)		(((x) >>  0) & 0xf)
+#define FICS_TXCOUNT(x)		(((x) >>  8) & 0x7f)
+
+#endif /* __SND_SOC_SAMSUNG_I2S_REGS_H */
+
+
sound/soc/samsung/i2s.c +1 -103

110 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

PATCH v3 2/4 ASoC: SAMSUNG: Add idma related register definition

This patch add idma related register definitions to support idma.

---
 sound/soc/samsung/i2s-regs.h |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
sound/soc/samsung/i2s-regs.h +20 -0
index 1fa0cd1..c0e6d9a 100644
@@ -23,6 +23,14 @@
 #define I2SRXD		0x14
 #define I2SFICS		0x18
 #define I2STXDS		0x1c
+#define I2SAHB		0x20
+#define I2SSTR0		0x24
+#define I2SSIZE		0x28
+#define I2STRNCNT	0x2c
+#define I2SLVL0ADDR	0x30
+#define I2SLVL1ADDR	0x34
+#define I2SLVL2ADDR	0x38
+#define I2SLVL3ADDR	0x3c
 
 #define CON_RSTCLR		(1 << 31)
 #define CON_FRXOFSTATUS		(1 << 26)
@@ -114,10 +122,22 @@
 
 #define FIC_TXFLUSH		(1 << 15)
 #define FIC_RXFLUSH		(1 << 7)
+
 #define FIC_TXCOUNT(x)		(((x) >>  8) & 0xf)
 #define FIC_RXCOUNT(x)		(((x) >>  0) & 0xf)
 #define FICS_TXCOUNT(x)		(((x) >>  8) & 0x7f)
 
+#define AHB_INTENLVL0		(1 << 24)
+#define AHB_LVL0INT		(1 << 20)
+#define AHB_CLRLVL0INT		(1 << 16)
+#define AHB_DMARLD		(1 << 5)
+#define AHB_INTMASK		(1 << 3)
+#define AHB_DMAEN		(1 << 0)
+#define AHB_LVLINTMASK		(0xf << 20)
+
+#define I2SSIZE_TRNMSK		(0xffff)
+#define I2SSIZE_SHIFT		(16)
+
 #endif /* __SND_SOC_SAMSUNG_I2S_REGS_H */
 
 
Signature · 1 line
1.7.1
Acked-by on v3 2/4
#2 lore raw

Re: [PATCH V3 2/4] ASoC: SAMSUNG: Add idma related register definition

Quoted 3 lines · Sangbeom Kim

This patch add idma related register definitions to support idma.

Quoted 1 line

+#define I2SSIZE_SHIFT          (16)

Btw, no operation in C can take 6 separated from 1 of 16 Though I have told already, I don't wanna be the reason of yet another revision.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw

PATCH v3 3/4 ASoC: SAMSUNG: Modify I2S driver to support idma

In reply to Sangbeom Kim

Previously, I2S driver only can support system dma. In this patch, i2s driver can support internal dma too.

---
 sound/soc/samsung/i2s.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
sound/soc/samsung/i2s.c +13 -0
index 1568eea..8b29c78 100644
@@ -21,6 +21,7 @@
 #include <plat/audio.h>
 
 #include "dma.h"
+#include "idma.h"
 #include "i2s.h"
 #include "i2s-regs.h"
 
@@ -544,9 +545,12 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
 {
 	struct i2s_dai *i2s = to_info(dai);
 	u32 mod = readl(i2s->addr + I2SMOD);
+	u32 ahb = 0;
 
 	if (!is_secondary(i2s))
 		mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
+	else
+		ahb = readl(i2s->addr + I2SAHB);
 
 	switch (params_channels(params)) {
 	case 6:
@@ -600,6 +604,13 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
 				params_format(params));
 		return -EINVAL;
 	}
+
+	if (is_secondary(i2s)) {
+		ahb |= (AHB_DMARLD | AHB_INTMASK);
+		mod |= MOD_TXS_IDMA;
+		writel(ahb, i2s->addr + I2SAHB);
+	}
+
 	writel(mod, i2s->addr + I2SMOD);
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -1068,6 +1079,8 @@ static __devinit int samsung_i2s_probe(struct platform_device *pdev)
 			ret = -ENOMEM;
 			goto err2;
 		}
+		idma_reg_addr_init((void *)ioremap(regs_base, 0x100),
+					i2s_cfg->idma_addr);
 		sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
 		sec_dai->dma_playback.client =
 			(struct s3c2410_dma_client *)&sec_dai->dma_playback;
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH V3 3/4] ASoC: SAMSUNG: Modify I2S driver to support idma

Quoted 5 lines · Sangbeom Kim

+
+       if (is_secondary(i2s)) {
+               ahb |= (AHB_DMARLD | AHB_INTMASK);

+               mod |= MOD_TXS_IDMA;

This unconditional setting stealthily switches to using iDMA. Sorry I didn't notice it in last revision.

Quoted 3 lines

+               writel(ahb, i2s->addr + I2SAHB);
+       }
+

I meant, this is _dma_ related setting of post-24xx So it had better be done in hw_params of idma.c

sound/soc/samsung/i2s.c static __devinit int samsung_i2s_probe(struct platform_device *pdev) · line 1083

Quoted 6 lines
sound/soc/samsung/i2s.c +2 -0
@@ -1068,6 +1079,8 @@ static __devinit int samsung_i2s_probe(struct platform_device *pdev)
                        ret = -ENOMEM;
                        goto err2;
                }
+               idma_reg_addr_init((void *)ioremap(regs_base, 0x100),
+                                       i2s_cfg->idma_addr);

Oh dear! Not a great idea to do multiple mapping, even worse is doing it transiently during a function call.
Perhaps provide base and iBuff address via platform data of samsung-idma and pass only _once_ ioremap'ed address from here.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw

PATCH v3 4/4 ASoC: SAMSUNG: Add I2S0 internal dma driver

In reply to Sangbeom Kim

I2S in Exynos4 and S5PC110(S5PV210) has a internal dma. It can be used low power audio mode and 2nd channel transfer.

---
 sound/soc/samsung/Makefile |    2 +
 sound/soc/samsung/idma.c   |  480 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/samsung/idma.h   |   26 +++
 3 files changed, 508 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/samsung/idma.c
 create mode 100644 sound/soc/samsung/idma.h
sound/soc/samsung/Makefile +2 -0
index 683843a..2b9e251 100644
@@ -1,5 +1,6 @@
 # S3c24XX Platform Support
 snd-soc-s3c24xx-objs := dma.o
+snd-soc-idma-objs := idma.o
 snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
 snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
 snd-soc-ac97-objs := ac97.o
@@ -16,6 +17,7 @@ obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o
 obj-$(CONFIG_SND_SAMSUNG_SPDIF) += snd-soc-samsung-spdif.o
 obj-$(CONFIG_SND_SAMSUNG_PCM) += snd-soc-pcm.o
 obj-$(CONFIG_SND_SAMSUNG_I2S) += snd-soc-i2s.o
+obj-$(CONFIG_SND_SAMSUNG_I2S) += snd-soc-idma.o
 
 # S3C24XX Machine Support
 snd-soc-jive-wm8750-objs := jive_wm8750.o
sound/soc/samsung/idma.c new file +480 -0

480 lines not on this page · raw message

sound/soc/samsung/idma.h new file +26 -0
new file mode 100644
index 0000000..94d3580
@@ -0,0 +1,26 @@
+/*
+ * linux/sound/soc/samsung/idma.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd
+ *		http://www.samsung.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.
+ *
+ */
+
+#ifndef __SND_SOC_SAMSUNG_IDMA_H_
+#define __SND_SOC_SAMSUNG_IDMA_H_
+
+extern void idma_reg_addr_init(void *regs, dma_addr_t addr);
+
+/* dma_state */
+#define LPAM_DMA_STOP	0
+#define LPAM_DMA_START	1
+
+#define MAX_IDMA_PERIOD (105 * 1024)
+#define MAX_IDMA_BUFFER (128 * 1024)
+
+#endif /* __SND_SOC_SAMSUNG_IDMA_H_ */
Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH V3 4/4] ASoC: SAMSUNG: Add I2S0 internal dma driver

Review

Quoted 2 lines · Sangbeom Kim
(quoted diff) +2 -0
+
+static struct device *dev;

Dear there is more to the first argument of dev_dbg, than to silence the compiler.
Please extract _real_ device underneath samsung_idma, rather than using this placeholder.

Quoted 11 lines

+static const struct snd_pcm_hardware idma_hardware = {
+       .info = SNDRV_PCM_INFO_INTERLEAVED |
+                   SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                   SNDRV_PCM_INFO_MMAP |
+                   SNDRV_PCM_INFO_MMAP_VALID |
+                   SNDRV_PCM_INFO_PAUSE |
+                   SNDRV_PCM_INFO_RESUME,
+       .formats = SNDRV_PCM_FMTBIT_S16_LE |

+                   SNDRV_PCM_FMTBIT_U16_LE |
+                   SNDRV_PCM_FMTBIT_S24_LE |
+                   SNDRV_PCM_FMTBIT_U24_LE |
Quoted 9 lines

+                   SNDRV_PCM_FMTBIT_U8 |
+                   SNDRV_PCM_FMTBIT_S8,
+       .channels_min = 2,
+       .channels_max = 2,
+       .buffer_bytes_max = MAX_IDMA_BUFFER,
+       .period_bytes_min = 128,
+       .period_bytes_max = MAX_IDMA_PERIOD,
+       .periods_min = 1,
+       .periods_max = 2,

How about ouput of aply -v sample.wav ?
Most probably ALSA uses 2 periods of MAX_IDMA_BUFFER/2 bytes each. Is that what you expect ? I would want ALSA to always use 1 period of MAX_IDMA_PERIOD bytes and ring-buffer of MAX_IDMA_BUFFER bytes.

Quoted 6 lines

+struct idma_ctrl {
+       spinlock_t      lock;
+       int             state;
+       dma_addr_t      start;
+       dma_addr_t      pos;
+       dma_addr_t      end;

This 'end' member is useless. Perhaps ringbuffer 'size' will be more useful.

sound/soc/samsung/idma.c line 258

Quoted 12 lines

+       dma_addr_t      period;
+       dma_addr_t      periodsz;
+       void            *token;
+       void            (*cb)(void *dt, int bytes_xfer);

sound/soc/samsung/idma.c new file +6 -0
+};
+
 
 
+
+       if (res >= snd_pcm_lib_buffer_bytes(substream)) {
+                       res = 0;
+       }

Dropping braces would be nice.

Quoted 2 lines

+               addr += prtd->period;
+               addr %= prtd->periodsz;

This is wrong. Perhaps you want...
            addr += prtd->periodsz;
            addr %= prtd->size;
I doubt one could miss this error if the driver was tested.

sound/soc/samsung/idma.c line 478

Quoted 2 lines
sound/soc/samsung/idma.c new file +2 -0
+
+MODULE_AUTHOR("Jaswinder Singh, <[email protected]>");

Sent emails will bounce from [email protected]. Please use [email protected]

sound/soc/samsung/idma.h line 24

Quoted 2 lines
sound/soc/samsung/idma.h new file +2 -0
+#define MAX_IDMA_PERIOD (105 * 1024)
+#define MAX_IDMA_BUFFER (128 * 1024)

IIRC not all SoCs have same size iBuff ?
Maybe passing via platform_data would be good ?
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#8 lore raw
In reply to Sangbeom Kim

sound/soc/samsung/i2s-regs.h line 25

Quoted 8 lines · Sangbeom Kim
sound/soc/samsung/i2s-regs.h new file +8 -0
+#define I2SCON		0x0
+#define I2SMOD		0x4
+#define I2SFIC		0x8
+#define I2SPSR		0xc
+#define I2STXD		0x10
+#define I2SRXD		0x14
+#define I2SFICS		0x18
+#define I2STXDS		0x1c

It'd be better to namespace things in header files, though if the header is only included in a single driver it doesn't really matter so much.