ASoC: fsi: FSI2 device support
cover ASoC: fsi: FSI2 device support
Dear Mark
These patches are FSI2 support
Kuninori Morimoto (4):
ASoC: fsi: ensures process inside master lock
ASoC: fsi: Add FIFO size calculate
ASoC: fsi: IRQ related process had be united
ASoC: fsi: Add FSI2 device support
ARM SH-MOBILE series have FSI2/FMSI device which are advance version of FSI.
Above patches add simple FSI2 support.
These patches are tested on AP4 board
Best regards
--
Kuninori Morimoto
PATCH 1/4 ASoC: fsi: ensures process inside master lock
Bit operation for fsi_master should be done inside master lock. But soft-reset/interrupt operation were outside of it. This patch modify this problem.
It still allow to INT_ST outside-operation on fsi_interrupt, but it is not problem.
Because this register doesn't need the bit operation.
--- sound/soc/sh/fsi.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
sound/soc/sh/fsi.c +11 -11
@@ -79,6 +79,12 @@#define INT_A_IN (1 << 4)#define INT_A_OUT (1 << 0) +/* SOFT_RST */ +#define PBSR (1 << 12)/* Port B Software Reset */ +#define PASR (1 << 8)/* Port A Software Reset */ +#define IR (1 << 4)/* Interrupt Reset */ +#define FSISR (1 << 0)/* Software Reset */ +#define FSI_RATES SNDRV_PCM_RATE_8000_96000#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
@@ -372,18 +378,13 @@ static void fsi_irq_init(struct fsi_priv *fsi, int is_play)static void fsi_soft_all_reset (struct fsi_master *master) { -u32 status =fsi_master_read (master,SOFT_RST ); -/* port AB reset */ - status &=0x000000ff ; -fsi_master_write (master,SOFT_RST , status); +fsi_master_mask_set (master,SOFT_RST ,PASR |PBSR ,0 );mdelay (10 );/* soft reset */ - status &=0x000000f0 ; -fsi_master_write (master,SOFT_RST , status); - status |=0x00000001 ; -fsi_master_write (master,SOFT_RST , status); +fsi_master_mask_set (master,SOFT_RST ,FSISR ,0 ); +fsi_master_mask_set (master,SOFT_RST ,FSISR ,FSISR );mdelay (10 ); }
@@ -558,12 +559,11 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)static irqreturn_t fsi_interrupt (int irq,void *data) {struct fsi_master *master = data; -u32 status =fsi_master_read (master,SOFT_RST ) & ~0x00000010 ;u32 int_st =fsi_master_read (master,INT_ST );/* clear irq status */ -fsi_master_write (master,SOFT_RST , status); -fsi_master_write (master,SOFT_RST , status |0x00000010 ); +fsi_master_mask_set (master,SOFT_RST ,IR ,0 ); +fsi_master_mask_set (master,SOFT_RST ,IR ,IR );if (int_st &INT_A_OUT )fsi_data_push (&master->fsia,0 );
Signature · 1 line
1.6.3.3
Re: [PATCH 1/4] ASoC: fsi: ensures process inside master lock
Quoted 7 lines · Kuninori Morimoto
Bit operation for
fsi_mastershould be done inside master lock. But soft-reset/interrupt operation were outside of it. This patch modify this problem.
It still allow toINT_SToutside-operation onfsi_interrupt, but it is not problem.
Because this register doesn't need the bit operation.
Quoted 5 lines
Signed-off-by Kuninori Morimoto <[email protected]>--- sound/soc/sh/fsi.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
PATCH 2/4 ASoC: fsi: Add FIFO size calculate
In reply to Kuninori Morimoto--- sound/soc/sh/fsi.c | 48 +++++++++++++++++++++++------------------------- 1 files changed, 23 insertions(+), 25 deletions(-)
sound/soc/sh/fsi.c +23 -25
@@ -46,8 +46,9 @@#define MUTE 0x020C#define CLK_RST 0x0210#define SOFT_RST 0x0214 +#define FIFO_SZ 0x0218#define MREG_START INT_ST -#define MREG_END SOFT_RST +#define MREG_END FIFO_SZ/* DO_FMT */ /* DI_FMT */
@@ -85,6 +86,11 @@#define IR (1 << 4)/* Interrupt Reset */ #define FSISR (1 << 0)/* Software Reset */ +/* FIFO_SZ */ +#define OUT_SZ_MASK 0x7 +#define BO_SZ_SHIFT 8 +#define AO_SZ_SHIFT 0 +#define FSI_RATES SNDRV_PCM_RATE_8000_96000#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
@@ -590,11 +596,12 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) {struct fsi_priv *fsi =fsi_get_priv (substream); +struct fsi_master *master =fsi_get_master (fsi);const char *msg;u32 flags =fsi_get_info_flags (fsi);u32 fmt;u32 reg; -u32 data; +u32 data, i;int is_play = (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK );int is_master;int ret =0 ;
@@ -668,31 +675,22 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,dev_err (dai->dev,"unknown format.\n" );return -EINVAL ; } - -switch (fsi->chan) { -case 1 : - fsi->fifo_max =256 ; -break ; -case 2 : - fsi->fifo_max =128 ; -break ; -case 3 : -case 4 : - fsi->fifo_max =64 ; -break ; -case 5 : -case 6 : -case 7 : -case 8 : - fsi->fifo_max =32 ; -break ; -default : -dev_err (dai->dev,"channel size error.\n" ); -return -EINVAL ; - } -fsi_reg_write (fsi, reg, data); +/* calculate FIFO size */ + data =fsi_master_read (master,FIFO_SZ ); + data >>=fsi_is_port_a (fsi) ?AO_SZ_SHIFT :BO_SZ_SHIFT ; + data &=OUT_SZ_MASK ; + fsi->fifo_max =256 ; +for (i =0 ; i < data; i++) + fsi->fifo_max <<=1 ; +dev_dbg (dai->dev,"fifo = %d words\n" , fsi->fifo_max); + +for (i =1 ; i < fsi->chan; i *=2 ) +if (fsi->chan > i) + fsi->fifo_max >>=1 ; +dev_dbg (dai->dev,"%d channel %d store\n" , fsi->chan, fsi->fifo_max); +/* * clear clk reset if master mode */
Signature · 1 line
1.6.3.3
Re: [PATCH 2/4] ASoC: fsi: Add FIFO size calculate
Quoted 72 lines · Kuninori Morimoto
Signed-off-by Kuninori Morimoto <[email protected]>--- sound/soc/sh/fsi.c | 48 +++++++++++++++++++++++------------------------- 1 files changed, 23 insertions(+), 25 deletions(-)sound/soc/sh/fsi.c +9
-24@@ -46,8 +46,9 @@#define MUTE 0x020C#define CLK_RST 0x0210#define SOFT_RST 0x0214 +#define FIFO_SZ 0x0218#define MREG_START INT_ST -#define MREG_END SOFT_RST +#define MREG_END FIFO_SZ/* DO_FMT */ /* DI_FMT */ @@ -85,6 +86,11 @@#define IR (1 << 4)/* Interrupt Reset */ #define FSISR (1 << 0)/* Software Reset */ +/* FIFO_SZ */ +#define OUT_SZ_MASK 0x7 +#define BO_SZ_SHIFT 8 +#define AO_SZ_SHIFT 0 +#define FSI_RATES SNDRV_PCM_RATE_8000_96000#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)@@ -590,11 +596,12 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) {struct fsi_priv *fsi =fsi_get_priv (substream); +struct fsi_master *master =fsi_get_master (fsi);const char *msg;u32 flags =fsi_get_info_flags (fsi);u32 fmt;u32 reg; -u32 data; +u32 data, i;int is_play = (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK );int is_master;int ret =0 ;@@ -668,31 +675,22 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,dev_err (dai->dev,"unknown format.\n" );return -EINVAL ; } - -switch (fsi->chan) { -case 1 : - fsi->fifo_max =256 ; -break ; -case 2 : - fsi->fifo_max =128 ; -break ; -case 3 : -case 4 : - fsi->fifo_max =64 ; -break ; -case 5 : -case 6 : -case 7 : -case 8 : - fsi->fifo_max =32 ; -break ; -default : -dev_err (dai->dev,"channel size error.\n" ); -return -EINVAL ; - }
sound/soc/sh/fsi.c static int fsi_dai_startup(struct snd_pcm_substream *substream, · line 686
Quoted 10 lines
sound/soc/sh/fsi.c +7
-1-fsi_reg_write (fsi, reg, data); +/* calculate FIFO size */ + data =fsi_master_read (master,FIFO_SZ ); + data >>=fsi_is_port_a (fsi) ?AO_SZ_SHIFT :BO_SZ_SHIFT ; + data &=OUT_SZ_MASK ; + fsi->fifo_max =256 ; +for (i =0 ; i < data; i++) + fsi->fifo_max <<=1 ;
You don't really need the for loop here if you calculate the shift size and perform the shift in 1 operation. e.g.
fsi->fifo_max <<= data;
sound/soc/sh/fsi.c static int fsi_dai_startup(struct snd_pcm_substream *substream, · line 691
Quoted 5 lines
sound/soc/sh/fsi.c +5
-0+dev_dbg (dai->dev,"fifo = %d words\n" , fsi->fifo_max); + +for (i =1 ; i < fsi->chan; i *=2 ) +if (fsi->chan > i) + fsi->fifo_max >>=1 ;
Is the if really needed here. You may also want to calculate the shift size rather than looping too.
Thanks
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Re: [PATCH 2/4] ASoC: fsi: Add FIFO size calculate
Dear Liam, Mark
Thank you for checking patch
Quoted 10 lines
sound/soc/sh/fsi.c static int fsi_dai_startup(struct snd_pcm_substream *substream, · line 686
Quoted 7 lines
sound/soc/sh/fsi.c +7
-0+/* calculate FIFO size */ + data =fsi_master_read (master,FIFO_SZ ); + data >>=fsi_is_port_a (fsi) ?AO_SZ_SHIFT :BO_SZ_SHIFT ; + data &=OUT_SZ_MASK ; + fsi->fifo_max =256 ; +for (i =0 ; i < data; i++) + fsi->fifo_max <<=1 ;You don't really need the for loop here if you calculate the shift size and perform the shift in 1 operation. e.g.
Indeed
Thank you. I will modify this.
Quoted 8 lines
sound/soc/sh/fsi.c static int fsi_dai_startup(struct snd_pcm_substream *substream, · line 691
Quoted 5 lines
sound/soc/sh/fsi.c +5
-0+dev_dbg (dai->dev,"fifo = %d words\n" , fsi->fifo_max); + +for (i =1 ; i < fsi->chan; i *=2 ) +if (fsi->chan > i) + fsi->fifo_max >>=1 ;Is the if really needed here. You may also want to calculate the shift size rather than looping too.
This calculate number of sample data.
And it is depend on channel size.
If chip fifo size is 256, the number of sample data will be...
1 chan : 256 (256 x 1 = 256)
2 chan : 128 (128 x 2 = 256)
3 chan : 64 ( 64 x 3 = 192) 4 chan : 64 ( 64 x 4 = 256) 5 chan : 32 ( 32 x 5 = 160) 6 chan : 32 ( 32 x 6 = 192) 7 chan : 32 ( 32 x 7 = 224) 8 chan : 32 ( 32 x 8 = 256)
Above calculation is needed. but yes un-understandable. I don't know a method computable by one line. So, I will add tiny comment/document here.
OK ?
Quoted 2 lines
As Liam said it'd
be good if you could check what's going on with these old dates.
Sorry so much
Best regards
--
Kuninori Morimoto
Re: [PATCH 2/4] ASoC: fsi: Add FIFO size calculate
Quoted 23 lines · Kuninori Morimoto
Quoted 9 lines
sound/soc/sh/fsi.c static int fsi_dai_startup(struct snd_pcm_substream *substream, · line 691
Quoted 6 lines
sound/soc/sh/fsi.c +5
-0+dev_dbg (dai->dev,"fifo = %d words\n" , fsi->fifo_max); + +for (i =1 ; i < fsi->chan; i *=2 ) +if (fsi->chan > i) + fsi->fifo_max >>=1 ;Is the if really needed here. You may also want to calculate the shift size rather than looping too.
This calculate number of sample data.
And it is depend on channel size.
If chip fifo size is 256, the number of sample data will be...1 chan : 256 (256 x 1 = 256)
2 chan : 128 (128 x 2 = 256)3 chan : 64 ( 64 x 3 = 192) 4 chan : 64 ( 64 x 4 = 256) 5 chan : 32 ( 32 x 5 = 160) 6 chan : 32 ( 32 x 6 = 192) 7 chan : 32 ( 32 x 7 = 224) 8 chan : 32 ( 32 x 8 = 256)
Quoted 5 lines
Above calculation is needed. but yes un-understandable. I don't know a method computable by one line. So, I will add tiny comment/document here.
OK ?
Yes, this sounds fine :)
It wasn't understandable from the original code.
Thanks
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
PATCH 3/4 ASoC: fsi: IRQ related process had be united
In reply to Kuninori Morimoto--- sound/soc/sh/fsi.c | 53 ++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 39 insertions(+), 14 deletions(-)
sound/soc/sh/fsi.c +39 -14
@@ -328,7 +328,7 @@ static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play)/************************************************************************ -ctrl function +irq function ************************************************************************/
@@ -350,6 +350,35 @@ static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)fsi_master_mask_set (master,IEMSK , data,0 ); } +static u32 fsi_irq_get_status (struct fsi_master *master) +{ +return fsi_master_read (master,INT_ST ); +} + +static void fsi_irq_clear_all_status (struct fsi_master *master) +{ +fsi_master_write (master,INT_ST ,0x0000000 ); +} + +static void fsi_irq_clear_status (struct fsi_priv *fsi) +{ +u32 data =0 ; +struct fsi_master *master =fsi_get_master (fsi); + + data |=fsi_port_ab_io_bit (fsi,0 ); + data |=fsi_port_ab_io_bit (fsi,1 ); + +/* clear interrupt factor */ +fsi_master_mask_set (master,INT_ST , data,0 ); +} + +/************************************************************************ + + +ctrl function + + +************************************************************************/ static void fsi_clk_ctrl (struct fsi_priv *fsi,int enable) {u32 val =fsi_is_port_a (fsi) ? (1 <<0 ) : (1 <<4 );
@@ -361,25 +390,17 @@ static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable)fsi_master_mask_set (master,CLK_RST , val,0 ); } -static void fsi_irq_init (struct fsi_priv *fsi,int is_play) +static void fsi_fifo_init (struct fsi_priv *fsi,int is_play) { -u32 data;u32 ctrl; - data =fsi_port_ab_io_bit (fsi, is_play); ctrl = is_play ?DOFF_CTL :DIFF_CTL ; -/* set IMSK */ -fsi_irq_disable (fsi, is_play); -/* set interrupt generation factor */ fsi_reg_write (fsi, ctrl,IRQ_HALF );/* clear FIFO */ fsi_reg_mask_set (fsi, ctrl,FIFO_CLR ,FIFO_CLR ); - -/* clear interrupt factor */ -fsi_master_mask_set (fsi_get_master (fsi),INT_ST , data,0 ); }static void fsi_soft_all_reset (struct fsi_master *master)
@@ -565,7 +586,7 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)static irqreturn_t fsi_interrupt (int irq,void *data) {struct fsi_master *master = data; -u32 int_st =fsi_master_read (master,INT_ST ); +u32 int_st =fsi_irq_get_status (master);/* clear irq status */ fsi_master_mask_set (master,SOFT_RST ,IR ,0 );
@@ -580,7 +601,7 @@ static irqreturn_t fsi_interrupt(int irq, void *data)if (int_st &INT_B_IN )fsi_data_pop (&master->fsib,0 ); -fsi_master_write (master,INT_ST ,0x0000000 ); +fsi_irq_clear_all_status (master);return IRQ_HANDLED ; }
@@ -697,8 +718,12 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,if (is_master)fsi_clk_ctrl (fsi,1 ); -/* irq setting */ -fsi_irq_init (fsi, is_play); +/* irq clear */ +fsi_irq_disable (fsi, is_play); +fsi_irq_clear_status (fsi); + +/* fifo init */ +fsi_fifo_init (fsi, is_play);return ret; }
Signature · 1 line
1.6.3.3
Re: [PATCH 3/4] ASoC: fsi: IRQ related process had be united
Quoted 4 lines · Kuninori Morimoto
Signed-off-by Kuninori Morimoto <[email protected]>--- sound/soc/sh/fsi.c | 53 ++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 39 insertions(+), 14 deletions(-)
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
PATCH 4/4 ASoC: fsi: Add FSI2 device support
In reply to Kuninori MorimotoARM-SHMOBILE series have FIFO-buffered serial interface 2 (FSI2) device which is advanced version of FSI.
This patch add simple support for it.
--- sound/soc/sh/Kconfig | 3 +- sound/soc/sh/fsi.c | 56 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 11 deletions(-)
sound/soc/sh/Kconfig +1 -2
@@ -1,5 +1,5 @@ menu "SoC Audio support for SuperH" - depends on SUPERH + depends on SUPERH || ARCH_SHMOBILE config SND_SOC_PCM_SH7760 tristate "SoC Audio support for Renesas SH7760"
@@ -22,7 +22,6 @@ config SND_SOC_SH4_SSI config SND_SOC_SH4_FSI tristate "SH4 FSI support" - depends on CPU_SUBTYPE_SH7724 help This option enables FSI sound support
sound/soc/sh/fsi.c +47 -9
141 lines not on this page · raw message
Signature · 1 line
1.6.3.3
Re: [PATCH 4/4] ASoC: fsi: Add FSI2 device support
Quoted 5 lines · Kuninori Morimoto
ARM-SHMOBILE series have FIFO-buffered serial interface 2 (FSI2) device which is advanced version of FSI.
This patch add simple support for it.Signed-off-by Kuninori Morimoto <[email protected]>
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Quoted 10 lines · Kuninori Morimoto
Dear Mark
These patches are FSI2 support
Kuninori Morimoto (4):
ASoC: fsi: ensures process inside master lock
ASoC: fsi: Add FIFO size calculate
ASoC: fsi: IRQ related process had be united
ASoC: fsi: Add FSI2 device support
Quoted 4 lines
ARM SH-MOBILE series have FSI2/FMSI device which are advance version of FSI.
Above patches add simple FSI2 support.
These patches are tested on AP4 board
Btw, your clock appears to be a bit broken, patch 2/4 has a time stamp from 7 days ago...
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Quoted 7 lines · Kuninori Morimoto
These patches are FSI2 support
Kuninori Morimoto (4):
ASoC: fsi: ensures process inside master lock
ASoC: fsi: Add FIFO size calculate
ASoC: fsi: IRQ related process had be united
ASoC: fsi: Add FSI2 device support
Applied patches 1 and 3, patch 4 was OK but won't apply without the FIFO size change (and presumably depends on that anyway). As Liam said it'd be good if you could check what's going on with these old dates.
Thanks.