Re: [alsa-devel] [PATCH v3] davinci-mcasp: Add support for multichannel playback

2013-03-01 Thread Michal Bachraty
Hi Daniel,

Thanks for testing.

> One thing that has to be considered by users of the driver is that the
> 'serial-dir' DT property has to contain enough '1' entries for
> multichannel playback (or enough '2's for multichannel record). So this
> information is not actually something that describes the hardware, but
> rather some resource that can be and should be allocated dynamically by
> the driver at run-time. Should we consider dropping this property?

Not really, ' serial-dir' also  configures specific serializer binded with 
certain AXR pin . That means, when you have harware, which do not have aviable 
AXR0, you can enable other ARX pin.  

example:

serial-dir = <  1 0 0 0 >; /* 0: INACTIVE, 1: TX, 2: RX */ 
// activate serializer 0, active pin ARX0 in Transmit mode, first audio 
// channels are played on ARX0 pin 

serial-dir = < 0 1 1 2 >; /* 0: INACTIVE, 1: TX, 2: RX */ 
// activate serializer 1,2,3 active pin ARX1 in TX mode, ARX2, in TX mode, 
// ARX3 in RX mode

In this case, if you are using TDM mode with 2 slots, first two channels will 
be played on ARX1 and second two on ARX2. 

McAsp fills data for serializers in loop (receive and playback has separate 
loop), so if you have configuration:

serial-dir = < 1 2 0 1 >; /* 0: INACTIVE, 1: TX, 2: RX */ 
// first two channels are played on ARX0 pin, and second two on ARX3

Best,
Michal

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [alsa-devel] [PATCH v3] davinci-mcasp: Add support for multichannel playback

2013-03-01 Thread Daniel Mack
Hi Michal,

On 28.02.2013 16:07, Michal Bachraty wrote:
> Davinci McASP has support for I2S multichannel playback.
> For I2S playback/receive, each serializer is capable to play 2 channels
> (L/R) audio data.Serializer function (Playback-receive-none) is configured
> in DT, depending on hardware specification. It is possible to play less
> channels than configured in DT. For that purpose,only specific number of
> active serializers are enabled. McASP FIFO need to have DMA transfer Bcnt
> set to number of enabled serializers, otherwise no data are transfered to
> McASP and Alsa generates "DMA/IRQ playback write error (DMA or IRQ trouble?)"
> error. For TDM mode, McASP is capable to play or receive 32 channels for one
> serializer. McAsp has support for max 16 serializer, therefore max channels
> is 32 * 8.
> 
> Signed-off-by: Michal Bachraty 

Ok, I successfully tested this now, and it seems to work fine. You can
take my

  Tested-by: Daniel Mack 

One thing that has to be considered by users of the driver is that the
'serial-dir' DT property has to contain enough '1' entries for
multichannel playback (or enough '2's for multichannel record). So this
information is not actually something that describes the hardware, but
rather some resource that can be and should be allocated dynamically by
the driver at run-time. Should we consider dropping this property?



Thanks,
Daniel


> ---
>  sound/soc/davinci/davinci-mcasp.c |   66 
> -
>  sound/soc/davinci/davinci-pcm.c   |   16 +
>  sound/soc/davinci/davinci-pcm.h   |1 +
>  3 files changed, 68 insertions(+), 15 deletions(-)
> 
> diff --git a/sound/soc/davinci/davinci-mcasp.c 
> b/sound/soc/davinci/davinci-mcasp.c
> index d2ca682..0a1af1a 100644
> --- a/sound/soc/davinci/davinci-mcasp.c
> +++ b/sound/soc/davinci/davinci-mcasp.c
> @@ -235,6 +235,10 @@
>  #define DISMOD   (val)(val<<2)
>  #define TXSTATE  BIT(4)
>  #define RXSTATE  BIT(5)
> +#define SRMOD_MASK   3
> +#define SRMOD_INACTIVE   0
> +#define SRMOD_TX 1
> +#define SRMOD_RX 2
>  
>  /*
>   * DAVINCI_MCASP_LBCTL_REG - Loop Back Control Register Bits
> @@ -657,12 +661,15 @@ static int davinci_config_channel_size(struct 
> davinci_audio_dev *dev,
>   return 0;
>  }
>  
> -static void davinci_hw_common_param(struct davinci_audio_dev *dev, int 
> stream)
> +static int davinci_hw_common_param(struct davinci_audio_dev *dev, int stream,
> + int channels)
>  {
>   int i;
>   u8 tx_ser = 0;
>   u8 rx_ser = 0;
> -
> + u8 ser;
> + u8 slots = dev->tdm_slots;
> + u8 max_active_serializers = (channels + slots - 1) / slots;
>   /* Default configuration */
>   mcasp_set_bits(dev->base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
>  
> @@ -680,16 +687,42 @@ static void davinci_hw_common_param(struct 
> davinci_audio_dev *dev, int stream)
>   }
>  
>   for (i = 0; i < dev->num_serializer; i++) {
> + if (dev->serial_dir[i] == TX_MODE)
> + tx_ser++;
> + if (dev->serial_dir[i] == RX_MODE)
> + rx_ser++;
> + }
> +
> + if (stream == SNDRV_PCM_STREAM_PLAYBACK)
> + ser = tx_ser;
> + else
> + ser = rx_ser;
> +
> + if (ser < max_active_serializers) {
> + dev_warn(dev->dev, "stream has more channels (%d) than are "
> + "enabled in mcasp (%d)\n", channels, ser * slots);
> + return -EINVAL;
> + }
> +
> + tx_ser = 0;
> + rx_ser = 0;
> +
> + for (i = 0; i < dev->num_serializer; i++) {
>   mcasp_set_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i),
>   dev->serial_dir[i]);
> - if (dev->serial_dir[i] == TX_MODE) {
> + if (dev->serial_dir[i] == TX_MODE &&
> + tx_ser < max_active_serializers) {
>   mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG,
>   AXR(i));
>   tx_ser++;
> - } else if (dev->serial_dir[i] == RX_MODE) {
> + } else if (dev->serial_dir[i] == RX_MODE &&
> + rx_ser < max_active_serializers) {
>   mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG,
>   AXR(i));
>   rx_ser++;
> + } else {
> + mcasp_mod_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i),
> + SRMOD_INACTIVE, SRMOD_MASK);
>   }
>   }
>  
> @@ -729,6 +762,8 @@ static void davinci_hw_common_param(struct 
> davinci_audio_dev *dev, int stream)
>   ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK);
>   }
>   }
> +
> + return 0;
>  }
>  
>  static void davinci_hw_param(struct davinci_audio_dev *dev, int stream)

Re: [alsa-devel] [PATCH v3] davinci-mcasp: Add support for multichannel playback

2013-03-01 Thread Daniel Mack
Hi Michal,

On 28.02.2013 16:07, Michal Bachraty wrote:
 Davinci McASP has support for I2S multichannel playback.
 For I2S playback/receive, each serializer is capable to play 2 channels
 (L/R) audio data.Serializer function (Playback-receive-none) is configured
 in DT, depending on hardware specification. It is possible to play less
 channels than configured in DT. For that purpose,only specific number of
 active serializers are enabled. McASP FIFO need to have DMA transfer Bcnt
 set to number of enabled serializers, otherwise no data are transfered to
 McASP and Alsa generates DMA/IRQ playback write error (DMA or IRQ trouble?)
 error. For TDM mode, McASP is capable to play or receive 32 channels for one
 serializer. McAsp has support for max 16 serializer, therefore max channels
 is 32 * 8.
 
 Signed-off-by: Michal Bachraty michal.bachr...@streamunlimited.com

Ok, I successfully tested this now, and it seems to work fine. You can
take my

  Tested-by: Daniel Mack zon...@gmail.com

One thing that has to be considered by users of the driver is that the
'serial-dir' DT property has to contain enough '1' entries for
multichannel playback (or enough '2's for multichannel record). So this
information is not actually something that describes the hardware, but
rather some resource that can be and should be allocated dynamically by
the driver at run-time. Should we consider dropping this property?



Thanks,
Daniel


 ---
  sound/soc/davinci/davinci-mcasp.c |   66 
 -
  sound/soc/davinci/davinci-pcm.c   |   16 +
  sound/soc/davinci/davinci-pcm.h   |1 +
  3 files changed, 68 insertions(+), 15 deletions(-)
 
 diff --git a/sound/soc/davinci/davinci-mcasp.c 
 b/sound/soc/davinci/davinci-mcasp.c
 index d2ca682..0a1af1a 100644
 --- a/sound/soc/davinci/davinci-mcasp.c
 +++ b/sound/soc/davinci/davinci-mcasp.c
 @@ -235,6 +235,10 @@
  #define DISMOD   (val)(val2)
  #define TXSTATE  BIT(4)
  #define RXSTATE  BIT(5)
 +#define SRMOD_MASK   3
 +#define SRMOD_INACTIVE   0
 +#define SRMOD_TX 1
 +#define SRMOD_RX 2
  
  /*
   * DAVINCI_MCASP_LBCTL_REG - Loop Back Control Register Bits
 @@ -657,12 +661,15 @@ static int davinci_config_channel_size(struct 
 davinci_audio_dev *dev,
   return 0;
  }
  
 -static void davinci_hw_common_param(struct davinci_audio_dev *dev, int 
 stream)
 +static int davinci_hw_common_param(struct davinci_audio_dev *dev, int stream,
 + int channels)
  {
   int i;
   u8 tx_ser = 0;
   u8 rx_ser = 0;
 -
 + u8 ser;
 + u8 slots = dev-tdm_slots;
 + u8 max_active_serializers = (channels + slots - 1) / slots;
   /* Default configuration */
   mcasp_set_bits(dev-base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
  
 @@ -680,16 +687,42 @@ static void davinci_hw_common_param(struct 
 davinci_audio_dev *dev, int stream)
   }
  
   for (i = 0; i  dev-num_serializer; i++) {
 + if (dev-serial_dir[i] == TX_MODE)
 + tx_ser++;
 + if (dev-serial_dir[i] == RX_MODE)
 + rx_ser++;
 + }
 +
 + if (stream == SNDRV_PCM_STREAM_PLAYBACK)
 + ser = tx_ser;
 + else
 + ser = rx_ser;
 +
 + if (ser  max_active_serializers) {
 + dev_warn(dev-dev, stream has more channels (%d) than are 
 + enabled in mcasp (%d)\n, channels, ser * slots);
 + return -EINVAL;
 + }
 +
 + tx_ser = 0;
 + rx_ser = 0;
 +
 + for (i = 0; i  dev-num_serializer; i++) {
   mcasp_set_bits(dev-base + DAVINCI_MCASP_XRSRCTL_REG(i),
   dev-serial_dir[i]);
 - if (dev-serial_dir[i] == TX_MODE) {
 + if (dev-serial_dir[i] == TX_MODE 
 + tx_ser  max_active_serializers) {
   mcasp_set_bits(dev-base + DAVINCI_MCASP_PDIR_REG,
   AXR(i));
   tx_ser++;
 - } else if (dev-serial_dir[i] == RX_MODE) {
 + } else if (dev-serial_dir[i] == RX_MODE 
 + rx_ser  max_active_serializers) {
   mcasp_clr_bits(dev-base + DAVINCI_MCASP_PDIR_REG,
   AXR(i));
   rx_ser++;
 + } else {
 + mcasp_mod_bits(dev-base + DAVINCI_MCASP_XRSRCTL_REG(i),
 + SRMOD_INACTIVE, SRMOD_MASK);
   }
   }
  
 @@ -729,6 +762,8 @@ static void davinci_hw_common_param(struct 
 davinci_audio_dev *dev, int stream)
   ((dev-rxnumevt * rx_ser)  8), NUMEVT_MASK);
   }
   }
 +
 + return 0;
  }
  
  static void davinci_hw_param(struct davinci_audio_dev *dev, int stream)
 @@ -812,8 +847,14 @@ static int davinci_mcasp_hw_params(struct 
 snd_pcm_substream *substream,
 

Re: [alsa-devel] [PATCH v3] davinci-mcasp: Add support for multichannel playback

2013-03-01 Thread Michal Bachraty
Hi Daniel,

Thanks for testing.

 One thing that has to be considered by users of the driver is that the
 'serial-dir' DT property has to contain enough '1' entries for
 multichannel playback (or enough '2's for multichannel record). So this
 information is not actually something that describes the hardware, but
 rather some resource that can be and should be allocated dynamically by
 the driver at run-time. Should we consider dropping this property?

Not really, ' serial-dir' also  configures specific serializer binded with 
certain AXR pin . That means, when you have harware, which do not have aviable 
AXR0, you can enable other ARX pin.  

example:

serial-dir =   1 0 0 0 ; /* 0: INACTIVE, 1: TX, 2: RX */ 
// activate serializer 0, active pin ARX0 in Transmit mode, first audio 
// channels are played on ARX0 pin 

serial-dir =  0 1 1 2 ; /* 0: INACTIVE, 1: TX, 2: RX */ 
// activate serializer 1,2,3 active pin ARX1 in TX mode, ARX2, in TX mode, 
// ARX3 in RX mode

In this case, if you are using TDM mode with 2 slots, first two channels will 
be played on ARX1 and second two on ARX2. 

McAsp fills data for serializers in loop (receive and playback has separate 
loop), so if you have configuration:

serial-dir =  1 2 0 1 ; /* 0: INACTIVE, 1: TX, 2: RX */ 
// first two channels are played on ARX0 pin, and second two on ARX3

Best,
Michal

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/