Re: [PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-04 Thread Mark Brown
On Tue, Aug 04, 2020 at 04:37:07PM +, codrin.ciubota...@microchip.com wrote:
> On 03.08.2020 20:11, Claudiu Beznea - M18063 wrote:
> > 
> > 
> > On 03.08.2020 19:11, Codrin Ciubotariu - M19940 wrote:
> >> On 03.08.2020 16:06, Claudiu Beznea - M18063 wrote:

Please delete unneeded context from mails when replying.  Doing this
makes it much easier to find your reply in the message, helping ensure
it won't be missed by people scrolling through the irrelevant quoted
material.


signature.asc
Description: PGP signature


Re: [PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-04 Thread Codrin.Ciubotariu
On 03.08.2020 20:11, Claudiu Beznea - M18063 wrote:
> 
> 
> On 03.08.2020 19:11, Codrin Ciubotariu - M19940 wrote:
>> On 03.08.2020 16:06, Claudiu Beznea - M18063 wrote:
>>>
>>>
>>> On 03.08.2020 11:18, Codrin Ciubotariu wrote:
 The new SPDIF TX controller is a serial port compliant with the IEC-
 60958 standard. It also supports programmable User Data and Channel
 Status fields.

 This IP is embedded in Microchip's sama7g5 SoC.

 Signed-off-by: Codrin Ciubotariu 
 ---

 Changes in v2, v3:
- none;

sound/soc/atmel/Kconfig|  12 +
sound/soc/atmel/Makefile   |   2 +
sound/soc/atmel/mchp-spdiftx.c | 864 +
3 files changed, 878 insertions(+)
create mode 100644 sound/soc/atmel/mchp-spdiftx.c

 diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
 index 71f2d42188c4..93beb7d670a3 100644
 --- a/sound/soc/atmel/Kconfig
 +++ b/sound/soc/atmel/Kconfig
 @@ -132,4 +132,16 @@ config SND_MCHP_SOC_I2S_MCC
  and supports a Time Division Multiplexed (TDM) interface with
  external multi-channel audio codecs.

 +config SND_MCHP_SOC_SPDIFTX
 +  tristate "Microchip ASoC driver for boards using S/PDIF TX"
 +  depends on OF && (ARCH_AT91 || COMPILE_TEST)
 +  select SND_SOC_GENERIC_DMAENGINE_PCM
 +  select REGMAP_MMIO
 +  help
 +Say Y or M if you want to add support for Microchip S/PDIF TX ASoc
 +driver on the following Microchip platforms:
 +- sama7g5
 +
 +This S/PDIF TX driver is compliant with IEC-60958 standard and
 +includes programable User Data and Channel Status fields.
endif
 diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
 index c7d2989791be..3fd89a0063df 100644
 --- a/sound/soc/atmel/Makefile
 +++ b/sound/soc/atmel/Makefile
 @@ -5,6 +5,7 @@ snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
snd-soc-atmel-i2s-objs := atmel-i2s.o
snd-soc-mchp-i2s-mcc-objs := mchp-i2s-mcc.o
 +snd-soc-mchp-spdiftx-objs := mchp-spdiftx.o

# pdc and dma need to both be built-in if any user of
# ssc is built-in.
 @@ -17,6 +18,7 @@ endif
obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
obj-$(CONFIG_SND_MCHP_SOC_I2S_MCC) += snd-soc-mchp-i2s-mcc.o
 +obj-$(CONFIG_SND_MCHP_SOC_SPDIFTX) += snd-soc-mchp-spdiftx.o

# AT91 Machine Support
snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
 diff --git a/sound/soc/atmel/mchp-spdiftx.c 
 b/sound/soc/atmel/mchp-spdiftx.c
 new file mode 100644
 index ..738f6788212e
 --- /dev/null
 +++ b/sound/soc/atmel/mchp-spdiftx.c
 @@ -0,0 +1,864 @@
 +// SPDX-License-Identifier: GPL-2.0
 +//
 +// Driver for Microchip S/PDIF TX Controller
 +//
 +// Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
 +//
 +// Author: Codrin Ciubotariu 
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +
 +/*
 + *  S/PDIF Transmitter Controller Register map 
 + */
 +#define SPDIFTX_CR0x00/* Control Register */
 +#define SPDIFTX_MR0x04/* Mode Register */
>>>
>>> This register is read/write either in atomic and non-atomic contextes but
>>> not protected everywhere the same way.
>>
>> I only need the TXEN bit from this register in an atomic context, this
>> is why there are also non-atomic contexts.
>>
>>>
 +#define SPDIFTX_CDR   0x0C/* Common Data Register 
 */
 +
 +#define SPDIFTX_IER   0x14/* Interrupt Enable 
 Register */
 +#define SPDIFTX_IDR   0x18/* Interrupt Disable 
 Register */
 +#define SPDIFTX_IMR   0x1C/* Interrupt Mask 
 Register */
 +#define SPDIFTX_ISR   0x20/* Interrupt Status 
 Register */
 +
 +#define SPDIFTX_CH1UD(reg)(0x50 + (reg) * 4)  /* User Data 1 
 Register x */
 +#define SPDIFTX_CH1S(reg) (0x80 + (reg) * 4)  /* Channel Status 1 
 Register x */
 +
 +#define SPDIFTX_VERSION   0xF0
 +
 +/*
 + *  Control Register (Write-only) 
 + */
 +#define SPDIFTX_CR_SWRST  BIT(0)  /* Software Reset */
 +#define SPDIFTX_CR_FCLR   BIT(1)  /* FIFO clear */
 +
 +/*
 + *  Mode Register (Read/Write) 
 + */
 +/* Transmit Enable */
 +#define SPDIFTX_MR_TXEN_MASK  GENMASK(0, 0)
 +#define SPDIFTX_MR_TXEN_DISABLE   (0 << 0)
 

Re: [PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-03 Thread Claudiu.Beznea


On 03.08.2020 19:11, Codrin Ciubotariu - M19940 wrote:
> On 03.08.2020 16:06, Claudiu Beznea - M18063 wrote:
>>
>>
>> On 03.08.2020 11:18, Codrin Ciubotariu wrote:
>>> The new SPDIF TX controller is a serial port compliant with the IEC-
>>> 60958 standard. It also supports programmable User Data and Channel
>>> Status fields.
>>>
>>> This IP is embedded in Microchip's sama7g5 SoC.
>>>
>>> Signed-off-by: Codrin Ciubotariu 
>>> ---
>>>
>>> Changes in v2, v3:
>>>   - none;
>>>
>>>   sound/soc/atmel/Kconfig|  12 +
>>>   sound/soc/atmel/Makefile   |   2 +
>>>   sound/soc/atmel/mchp-spdiftx.c | 864 +
>>>   3 files changed, 878 insertions(+)
>>>   create mode 100644 sound/soc/atmel/mchp-spdiftx.c
>>>
>>> diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
>>> index 71f2d42188c4..93beb7d670a3 100644
>>> --- a/sound/soc/atmel/Kconfig
>>> +++ b/sound/soc/atmel/Kconfig
>>> @@ -132,4 +132,16 @@ config SND_MCHP_SOC_I2S_MCC
>>>   and supports a Time Division Multiplexed (TDM) interface with
>>>   external multi-channel audio codecs.
>>>   
>>> +config SND_MCHP_SOC_SPDIFTX
>>> +   tristate "Microchip ASoC driver for boards using S/PDIF TX"
>>> +   depends on OF && (ARCH_AT91 || COMPILE_TEST)
>>> +   select SND_SOC_GENERIC_DMAENGINE_PCM
>>> +   select REGMAP_MMIO
>>> +   help
>>> + Say Y or M if you want to add support for Microchip S/PDIF TX ASoc
>>> + driver on the following Microchip platforms:
>>> + - sama7g5
>>> +
>>> + This S/PDIF TX driver is compliant with IEC-60958 standard and
>>> + includes programable User Data and Channel Status fields.
>>>   endif
>>> diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
>>> index c7d2989791be..3fd89a0063df 100644
>>> --- a/sound/soc/atmel/Makefile
>>> +++ b/sound/soc/atmel/Makefile
>>> @@ -5,6 +5,7 @@ snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
>>>   snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
>>>   snd-soc-atmel-i2s-objs := atmel-i2s.o
>>>   snd-soc-mchp-i2s-mcc-objs := mchp-i2s-mcc.o
>>> +snd-soc-mchp-spdiftx-objs := mchp-spdiftx.o
>>>   
>>>   # pdc and dma need to both be built-in if any user of
>>>   # ssc is built-in.
>>> @@ -17,6 +18,7 @@ endif
>>>   obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
>>>   obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
>>>   obj-$(CONFIG_SND_MCHP_SOC_I2S_MCC) += snd-soc-mchp-i2s-mcc.o
>>> +obj-$(CONFIG_SND_MCHP_SOC_SPDIFTX) += snd-soc-mchp-spdiftx.o
>>>   
>>>   # AT91 Machine Support
>>>   snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
>>> diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c
>>> new file mode 100644
>>> index ..738f6788212e
>>> --- /dev/null
>>> +++ b/sound/soc/atmel/mchp-spdiftx.c
>>> @@ -0,0 +1,864 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +//
>>> +// Driver for Microchip S/PDIF TX Controller
>>> +//
>>> +// Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
>>> +//
>>> +// Author: Codrin Ciubotariu 
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +/*
>>> + *  S/PDIF Transmitter Controller Register map 
>>> + */
>>> +#define SPDIFTX_CR 0x00/* Control Register */
>>> +#define SPDIFTX_MR 0x04/* Mode Register */
>>
>> This register is read/write either in atomic and non-atomic contextes but
>> not protected everywhere the same way.
> 
> I only need the TXEN bit from this register in an atomic context, this 
> is why there are also non-atomic contexts.
> 
>>
>>> +#define SPDIFTX_CDR0x0C/* Common Data Register 
>>> */
>>> +
>>> +#define SPDIFTX_IER0x14/* Interrupt Enable 
>>> Register */
>>> +#define SPDIFTX_IDR0x18/* Interrupt Disable 
>>> Register */
>>> +#define SPDIFTX_IMR0x1C/* Interrupt Mask 
>>> Register */
>>> +#define SPDIFTX_ISR0x20/* Interrupt Status 
>>> Register */
>>> +
>>> +#define SPDIFTX_CH1UD(reg) (0x50 + (reg) * 4)  /* User Data 1 Register 
>>> x */
>>> +#define SPDIFTX_CH1S(reg)  (0x80 + (reg) * 4)  /* Channel Status 1 
>>> Register x */
>>> +
>>> +#define SPDIFTX_VERSION0xF0
>>> +
>>> +/*
>>> + *  Control Register (Write-only) 
>>> + */
>>> +#define SPDIFTX_CR_SWRST   BIT(0)  /* Software Reset */
>>> +#define SPDIFTX_CR_FCLRBIT(1)  /* FIFO clear */
>>> +
>>> +/*
>>> + *  Mode Register (Read/Write) 
>>> + */
>>> +/* Transmit Enable */
>>> +#define SPDIFTX_MR_TXEN_MASK   GENMASK(0, 0)
>>> +#define SPDIFTX_MR_TXEN_DISABLE(0 << 0)
>>> +#define SPDIFTX_MR_TXEN_ENABLE (1 << 0)
>>> +
>>> +/* Multichannel Transfer */
>>> +#define SPDIFTX_MR_MULTICH_MASKGENAMSK(1, 1)
>>> +#define SPDIFTX_MR_MULTICH_MONO(0 << 1)
>>> +#define 

Re: [PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-03 Thread Claudiu.Beznea


On 03.08.2020 19:11, Codrin Ciubotariu - M19940 wrote:
> On 03.08.2020 16:06, Claudiu Beznea - M18063 wrote:
>>
>>
>> On 03.08.2020 11:18, Codrin Ciubotariu wrote:
>>> The new SPDIF TX controller is a serial port compliant with the IEC-
>>> 60958 standard. It also supports programmable User Data and Channel
>>> Status fields.
>>>
>>> This IP is embedded in Microchip's sama7g5 SoC.
>>>
>>> Signed-off-by: Codrin Ciubotariu 
>>> ---
>>>
>>> Changes in v2, v3:
>>>   - none;
>>>
>>>   sound/soc/atmel/Kconfig|  12 +
>>>   sound/soc/atmel/Makefile   |   2 +
>>>   sound/soc/atmel/mchp-spdiftx.c | 864 +
>>>   3 files changed, 878 insertions(+)
>>>   create mode 100644 sound/soc/atmel/mchp-spdiftx.c
>>>
>>> diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
>>> index 71f2d42188c4..93beb7d670a3 100644
>>> --- a/sound/soc/atmel/Kconfig
>>> +++ b/sound/soc/atmel/Kconfig
>>> @@ -132,4 +132,16 @@ config SND_MCHP_SOC_I2S_MCC
>>>   and supports a Time Division Multiplexed (TDM) interface with
>>>   external multi-channel audio codecs.
>>>   
>>> +config SND_MCHP_SOC_SPDIFTX
>>> +   tristate "Microchip ASoC driver for boards using S/PDIF TX"
>>> +   depends on OF && (ARCH_AT91 || COMPILE_TEST)
>>> +   select SND_SOC_GENERIC_DMAENGINE_PCM
>>> +   select REGMAP_MMIO
>>> +   help
>>> + Say Y or M if you want to add support for Microchip S/PDIF TX ASoc
>>> + driver on the following Microchip platforms:
>>> + - sama7g5
>>> +
>>> + This S/PDIF TX driver is compliant with IEC-60958 standard and
>>> + includes programable User Data and Channel Status fields.
>>>   endif
>>> diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
>>> index c7d2989791be..3fd89a0063df 100644
>>> --- a/sound/soc/atmel/Makefile
>>> +++ b/sound/soc/atmel/Makefile
>>> @@ -5,6 +5,7 @@ snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
>>>   snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
>>>   snd-soc-atmel-i2s-objs := atmel-i2s.o
>>>   snd-soc-mchp-i2s-mcc-objs := mchp-i2s-mcc.o
>>> +snd-soc-mchp-spdiftx-objs := mchp-spdiftx.o
>>>   
>>>   # pdc and dma need to both be built-in if any user of
>>>   # ssc is built-in.
>>> @@ -17,6 +18,7 @@ endif
>>>   obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
>>>   obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
>>>   obj-$(CONFIG_SND_MCHP_SOC_I2S_MCC) += snd-soc-mchp-i2s-mcc.o
>>> +obj-$(CONFIG_SND_MCHP_SOC_SPDIFTX) += snd-soc-mchp-spdiftx.o
>>>   
>>>   # AT91 Machine Support
>>>   snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
>>> diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c
>>> new file mode 100644
>>> index ..738f6788212e
>>> --- /dev/null
>>> +++ b/sound/soc/atmel/mchp-spdiftx.c
>>> @@ -0,0 +1,864 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +//
>>> +// Driver for Microchip S/PDIF TX Controller
>>> +//
>>> +// Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
>>> +//
>>> +// Author: Codrin Ciubotariu 
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +/*
>>> + *  S/PDIF Transmitter Controller Register map 
>>> + */
>>> +#define SPDIFTX_CR 0x00/* Control Register */
>>> +#define SPDIFTX_MR 0x04/* Mode Register */
>>
>> This register is read/write either in atomic and non-atomic contextes but
>> not protected everywhere the same way.
> 
> I only need the TXEN bit from this register in an atomic context, this 
> is why there are also non-atomic contexts.
> 
>>
>>> +#define SPDIFTX_CDR0x0C/* Common Data Register 
>>> */
>>> +
>>> +#define SPDIFTX_IER0x14/* Interrupt Enable 
>>> Register */
>>> +#define SPDIFTX_IDR0x18/* Interrupt Disable 
>>> Register */
>>> +#define SPDIFTX_IMR0x1C/* Interrupt Mask 
>>> Register */
>>> +#define SPDIFTX_ISR0x20/* Interrupt Status 
>>> Register */
>>> +
>>> +#define SPDIFTX_CH1UD(reg) (0x50 + (reg) * 4)  /* User Data 1 Register 
>>> x */
>>> +#define SPDIFTX_CH1S(reg)  (0x80 + (reg) * 4)  /* Channel Status 1 
>>> Register x */
>>> +
>>> +#define SPDIFTX_VERSION0xF0
>>> +
>>> +/*
>>> + *  Control Register (Write-only) 
>>> + */
>>> +#define SPDIFTX_CR_SWRST   BIT(0)  /* Software Reset */
>>> +#define SPDIFTX_CR_FCLRBIT(1)  /* FIFO clear */
>>> +
>>> +/*
>>> + *  Mode Register (Read/Write) 
>>> + */
>>> +/* Transmit Enable */
>>> +#define SPDIFTX_MR_TXEN_MASK   GENMASK(0, 0)
>>> +#define SPDIFTX_MR_TXEN_DISABLE(0 << 0)
>>> +#define SPDIFTX_MR_TXEN_ENABLE (1 << 0)
>>> +
>>> +/* Multichannel Transfer */
>>> +#define SPDIFTX_MR_MULTICH_MASKGENAMSK(1, 1)
>>> +#define SPDIFTX_MR_MULTICH_MONO(0 << 1)
>>> +#define 

Re: [PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-03 Thread Codrin.Ciubotariu
On 03.08.2020 16:06, Claudiu Beznea - M18063 wrote:
> 
> 
> On 03.08.2020 11:18, Codrin Ciubotariu wrote:
>> The new SPDIF TX controller is a serial port compliant with the IEC-
>> 60958 standard. It also supports programmable User Data and Channel
>> Status fields.
>>
>> This IP is embedded in Microchip's sama7g5 SoC.
>>
>> Signed-off-by: Codrin Ciubotariu 
>> ---
>>
>> Changes in v2, v3:
>>   - none;
>>
>>   sound/soc/atmel/Kconfig|  12 +
>>   sound/soc/atmel/Makefile   |   2 +
>>   sound/soc/atmel/mchp-spdiftx.c | 864 +
>>   3 files changed, 878 insertions(+)
>>   create mode 100644 sound/soc/atmel/mchp-spdiftx.c
>>
>> diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
>> index 71f2d42188c4..93beb7d670a3 100644
>> --- a/sound/soc/atmel/Kconfig
>> +++ b/sound/soc/atmel/Kconfig
>> @@ -132,4 +132,16 @@ config SND_MCHP_SOC_I2S_MCC
>>and supports a Time Division Multiplexed (TDM) interface with
>>external multi-channel audio codecs.
>>   
>> +config SND_MCHP_SOC_SPDIFTX
>> +tristate "Microchip ASoC driver for boards using S/PDIF TX"
>> +depends on OF && (ARCH_AT91 || COMPILE_TEST)
>> +select SND_SOC_GENERIC_DMAENGINE_PCM
>> +select REGMAP_MMIO
>> +help
>> +  Say Y or M if you want to add support for Microchip S/PDIF TX ASoc
>> +  driver on the following Microchip platforms:
>> +  - sama7g5
>> +
>> +  This S/PDIF TX driver is compliant with IEC-60958 standard and
>> +  includes programable User Data and Channel Status fields.
>>   endif
>> diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
>> index c7d2989791be..3fd89a0063df 100644
>> --- a/sound/soc/atmel/Makefile
>> +++ b/sound/soc/atmel/Makefile
>> @@ -5,6 +5,7 @@ snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
>>   snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
>>   snd-soc-atmel-i2s-objs := atmel-i2s.o
>>   snd-soc-mchp-i2s-mcc-objs := mchp-i2s-mcc.o
>> +snd-soc-mchp-spdiftx-objs := mchp-spdiftx.o
>>   
>>   # pdc and dma need to both be built-in if any user of
>>   # ssc is built-in.
>> @@ -17,6 +18,7 @@ endif
>>   obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
>>   obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
>>   obj-$(CONFIG_SND_MCHP_SOC_I2S_MCC) += snd-soc-mchp-i2s-mcc.o
>> +obj-$(CONFIG_SND_MCHP_SOC_SPDIFTX) += snd-soc-mchp-spdiftx.o
>>   
>>   # AT91 Machine Support
>>   snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
>> diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c
>> new file mode 100644
>> index ..738f6788212e
>> --- /dev/null
>> +++ b/sound/soc/atmel/mchp-spdiftx.c
>> @@ -0,0 +1,864 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +//
>> +// Driver for Microchip S/PDIF TX Controller
>> +//
>> +// Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
>> +//
>> +// Author: Codrin Ciubotariu 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/*
>> + *  S/PDIF Transmitter Controller Register map 
>> + */
>> +#define SPDIFTX_CR  0x00/* Control Register */
>> +#define SPDIFTX_MR  0x04/* Mode Register */
> 
> This register is read/write either in atomic and non-atomic contextes but
> not protected everywhere the same way.

I only need the TXEN bit from this register in an atomic context, this 
is why there are also non-atomic contexts.

> 
>> +#define SPDIFTX_CDR 0x0C/* Common Data Register */
>> +
>> +#define SPDIFTX_IER 0x14/* Interrupt Enable Register */
>> +#define SPDIFTX_IDR 0x18/* Interrupt Disable Register */
>> +#define SPDIFTX_IMR 0x1C/* Interrupt Mask Register */
>> +#define SPDIFTX_ISR 0x20/* Interrupt Status Register */
>> +
>> +#define SPDIFTX_CH1UD(reg)  (0x50 + (reg) * 4)  /* User Data 1 Register 
>> x */
>> +#define SPDIFTX_CH1S(reg)   (0x80 + (reg) * 4)  /* Channel Status 1 
>> Register x */
>> +
>> +#define SPDIFTX_VERSION 0xF0
>> +
>> +/*
>> + *  Control Register (Write-only) 
>> + */
>> +#define SPDIFTX_CR_SWRSTBIT(0)  /* Software Reset */
>> +#define SPDIFTX_CR_FCLR BIT(1)  /* FIFO clear */
>> +
>> +/*
>> + *  Mode Register (Read/Write) 
>> + */
>> +/* Transmit Enable */
>> +#define SPDIFTX_MR_TXEN_MASKGENMASK(0, 0)
>> +#define SPDIFTX_MR_TXEN_DISABLE (0 << 0)
>> +#define SPDIFTX_MR_TXEN_ENABLE  (1 << 0)
>> +
>> +/* Multichannel Transfer */
>> +#define SPDIFTX_MR_MULTICH_MASK GENAMSK(1, 1)
>> +#define SPDIFTX_MR_MULTICH_MONO (0 << 1)
>> +#define SPDIFTX_MR_MULTICH_DUAL (1 << 1)
>> +
>> +/* Data Word Endian Mode */
>> +#define SPDIFTX_MR_ENDIAN_MASK  GENMASK(2, 2)
>> +#define SPDIFTX_MR_ENDIAN_LITTLE(0 << 2)
>> +#define SPDIFTX_MR_ENDIAN_BIG  

Re: [PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-03 Thread Claudiu.Beznea


On 03.08.2020 11:18, Codrin Ciubotariu wrote:
> The new SPDIF TX controller is a serial port compliant with the IEC-
> 60958 standard. It also supports programmable User Data and Channel
> Status fields.
> 
> This IP is embedded in Microchip's sama7g5 SoC.
> 
> Signed-off-by: Codrin Ciubotariu 
> ---
> 
> Changes in v2, v3:
>  - none;
> 
>  sound/soc/atmel/Kconfig|  12 +
>  sound/soc/atmel/Makefile   |   2 +
>  sound/soc/atmel/mchp-spdiftx.c | 864 +
>  3 files changed, 878 insertions(+)
>  create mode 100644 sound/soc/atmel/mchp-spdiftx.c
> 
> diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
> index 71f2d42188c4..93beb7d670a3 100644
> --- a/sound/soc/atmel/Kconfig
> +++ b/sound/soc/atmel/Kconfig
> @@ -132,4 +132,16 @@ config SND_MCHP_SOC_I2S_MCC
> and supports a Time Division Multiplexed (TDM) interface with
> external multi-channel audio codecs.
>  
> +config SND_MCHP_SOC_SPDIFTX
> + tristate "Microchip ASoC driver for boards using S/PDIF TX"
> + depends on OF && (ARCH_AT91 || COMPILE_TEST)
> + select SND_SOC_GENERIC_DMAENGINE_PCM
> + select REGMAP_MMIO
> + help
> +   Say Y or M if you want to add support for Microchip S/PDIF TX ASoc
> +   driver on the following Microchip platforms:
> +   - sama7g5
> +
> +   This S/PDIF TX driver is compliant with IEC-60958 standard and
> +   includes programable User Data and Channel Status fields.
>  endif
> diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
> index c7d2989791be..3fd89a0063df 100644
> --- a/sound/soc/atmel/Makefile
> +++ b/sound/soc/atmel/Makefile
> @@ -5,6 +5,7 @@ snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
>  snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
>  snd-soc-atmel-i2s-objs := atmel-i2s.o
>  snd-soc-mchp-i2s-mcc-objs := mchp-i2s-mcc.o
> +snd-soc-mchp-spdiftx-objs := mchp-spdiftx.o
>  
>  # pdc and dma need to both be built-in if any user of
>  # ssc is built-in.
> @@ -17,6 +18,7 @@ endif
>  obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
>  obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
>  obj-$(CONFIG_SND_MCHP_SOC_I2S_MCC) += snd-soc-mchp-i2s-mcc.o
> +obj-$(CONFIG_SND_MCHP_SOC_SPDIFTX) += snd-soc-mchp-spdiftx.o
>  
>  # AT91 Machine Support
>  snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
> diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c
> new file mode 100644
> index ..738f6788212e
> --- /dev/null
> +++ b/sound/soc/atmel/mchp-spdiftx.c
> @@ -0,0 +1,864 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Driver for Microchip S/PDIF TX Controller
> +//
> +// Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
> +//
> +// Author: Codrin Ciubotariu 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + *  S/PDIF Transmitter Controller Register map 
> + */
> +#define SPDIFTX_CR   0x00/* Control Register */
> +#define SPDIFTX_MR   0x04/* Mode Register */

This register is read/write either in atomic and non-atomic contextes but
not protected everywhere the same way.

> +#define SPDIFTX_CDR  0x0C/* Common Data Register */
> +
> +#define SPDIFTX_IER  0x14/* Interrupt Enable Register */
> +#define SPDIFTX_IDR  0x18/* Interrupt Disable Register */
> +#define SPDIFTX_IMR  0x1C/* Interrupt Mask Register */
> +#define SPDIFTX_ISR  0x20/* Interrupt Status Register */
> +
> +#define SPDIFTX_CH1UD(reg)   (0x50 + (reg) * 4)  /* User Data 1 Register 
> x */
> +#define SPDIFTX_CH1S(reg)(0x80 + (reg) * 4)  /* Channel Status 1 
> Register x */
> +
> +#define SPDIFTX_VERSION  0xF0
> +
> +/*
> + *  Control Register (Write-only) 
> + */
> +#define SPDIFTX_CR_SWRST BIT(0)  /* Software Reset */
> +#define SPDIFTX_CR_FCLR  BIT(1)  /* FIFO clear */
> +
> +/*
> + *  Mode Register (Read/Write) 
> + */
> +/* Transmit Enable */
> +#define SPDIFTX_MR_TXEN_MASK GENMASK(0, 0)
> +#define SPDIFTX_MR_TXEN_DISABLE  (0 << 0)
> +#define SPDIFTX_MR_TXEN_ENABLE   (1 << 0)
> +
> +/* Multichannel Transfer */
> +#define SPDIFTX_MR_MULTICH_MASK  GENAMSK(1, 1)
> +#define SPDIFTX_MR_MULTICH_MONO  (0 << 1)
> +#define SPDIFTX_MR_MULTICH_DUAL  (1 << 1)
> +
> +/* Data Word Endian Mode */
> +#define SPDIFTX_MR_ENDIAN_MASK   GENMASK(2, 2)
> +#define SPDIFTX_MR_ENDIAN_LITTLE (0 << 2)
> +#define SPDIFTX_MR_ENDIAN_BIG(1 << 2)
> +
> +/* Data Justification */
> +#define SPDIFTX_MR_JUSTIFY_MASK  GENMASK(3, 3)
> +#define SPDIFTX_MR_JUSTIFY_LSB   (0 << 3)
> +#define SPDIFTX_MR_JUSTIFY_MSB   (1 << 3)
> +
> +/* Common Audio Register Transfer Mode */
> +#define 

[PATCH v3 2/2] ASoC: mchp-spdiftx: add driver for S/PDIF TX Controller

2020-08-03 Thread Codrin Ciubotariu
The new SPDIF TX controller is a serial port compliant with the IEC-
60958 standard. It also supports programmable User Data and Channel
Status fields.

This IP is embedded in Microchip's sama7g5 SoC.

Signed-off-by: Codrin Ciubotariu 
---

Changes in v2, v3:
 - none;

 sound/soc/atmel/Kconfig|  12 +
 sound/soc/atmel/Makefile   |   2 +
 sound/soc/atmel/mchp-spdiftx.c | 864 +
 3 files changed, 878 insertions(+)
 create mode 100644 sound/soc/atmel/mchp-spdiftx.c

diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index 71f2d42188c4..93beb7d670a3 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -132,4 +132,16 @@ config SND_MCHP_SOC_I2S_MCC
  and supports a Time Division Multiplexed (TDM) interface with
  external multi-channel audio codecs.
 
+config SND_MCHP_SOC_SPDIFTX
+   tristate "Microchip ASoC driver for boards using S/PDIF TX"
+   depends on OF && (ARCH_AT91 || COMPILE_TEST)
+   select SND_SOC_GENERIC_DMAENGINE_PCM
+   select REGMAP_MMIO
+   help
+ Say Y or M if you want to add support for Microchip S/PDIF TX ASoc
+ driver on the following Microchip platforms:
+ - sama7g5
+
+ This S/PDIF TX driver is compliant with IEC-60958 standard and
+ includes programable User Data and Channel Status fields.
 endif
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index c7d2989791be..3fd89a0063df 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -5,6 +5,7 @@ snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
 snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
 snd-soc-atmel-i2s-objs := atmel-i2s.o
 snd-soc-mchp-i2s-mcc-objs := mchp-i2s-mcc.o
+snd-soc-mchp-spdiftx-objs := mchp-spdiftx.o
 
 # pdc and dma need to both be built-in if any user of
 # ssc is built-in.
@@ -17,6 +18,7 @@ endif
 obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
 obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
 obj-$(CONFIG_SND_MCHP_SOC_I2S_MCC) += snd-soc-mchp-i2s-mcc.o
+obj-$(CONFIG_SND_MCHP_SOC_SPDIFTX) += snd-soc-mchp-spdiftx.o
 
 # AT91 Machine Support
 snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c
new file mode 100644
index ..738f6788212e
--- /dev/null
+++ b/sound/soc/atmel/mchp-spdiftx.c
@@ -0,0 +1,864 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Driver for Microchip S/PDIF TX Controller
+//
+// Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
+//
+// Author: Codrin Ciubotariu 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ *  S/PDIF Transmitter Controller Register map 
+ */
+#define SPDIFTX_CR 0x00/* Control Register */
+#define SPDIFTX_MR 0x04/* Mode Register */
+#define SPDIFTX_CDR0x0C/* Common Data Register */
+
+#define SPDIFTX_IER0x14/* Interrupt Enable Register */
+#define SPDIFTX_IDR0x18/* Interrupt Disable Register */
+#define SPDIFTX_IMR0x1C/* Interrupt Mask Register */
+#define SPDIFTX_ISR0x20/* Interrupt Status Register */
+
+#define SPDIFTX_CH1UD(reg) (0x50 + (reg) * 4)  /* User Data 1 Register 
x */
+#define SPDIFTX_CH1S(reg)  (0x80 + (reg) * 4)  /* Channel Status 1 
Register x */
+
+#define SPDIFTX_VERSION0xF0
+
+/*
+ *  Control Register (Write-only) 
+ */
+#define SPDIFTX_CR_SWRST   BIT(0)  /* Software Reset */
+#define SPDIFTX_CR_FCLRBIT(1)  /* FIFO clear */
+
+/*
+ *  Mode Register (Read/Write) 
+ */
+/* Transmit Enable */
+#define SPDIFTX_MR_TXEN_MASK   GENMASK(0, 0)
+#define SPDIFTX_MR_TXEN_DISABLE(0 << 0)
+#define SPDIFTX_MR_TXEN_ENABLE (1 << 0)
+
+/* Multichannel Transfer */
+#define SPDIFTX_MR_MULTICH_MASKGENAMSK(1, 1)
+#define SPDIFTX_MR_MULTICH_MONO(0 << 1)
+#define SPDIFTX_MR_MULTICH_DUAL(1 << 1)
+
+/* Data Word Endian Mode */
+#define SPDIFTX_MR_ENDIAN_MASK GENMASK(2, 2)
+#define SPDIFTX_MR_ENDIAN_LITTLE   (0 << 2)
+#define SPDIFTX_MR_ENDIAN_BIG  (1 << 2)
+
+/* Data Justification */
+#define SPDIFTX_MR_JUSTIFY_MASKGENMASK(3, 3)
+#define SPDIFTX_MR_JUSTIFY_LSB (0 << 3)
+#define SPDIFTX_MR_JUSTIFY_MSB (1 << 3)
+
+/* Common Audio Register Transfer Mode */
+#define SPDIFTX_MR_CMODE_MASK  GENMASK(5, 4)
+#define SPDIFTX_MR_CMODE_INDEX_ACCESS  (0 << 4)
+#define SPDIFTX_MR_CMODE_TOGGLE_ACCESS (1 << 4)
+#define SPDIFTX_MR_CMODE_INTERLVD_ACCESS   (2 << 4)
+
+/* Valid Bits per Sample */
+#define SPDIFTX_MR_VBPS_MASK   GENMASK(13, 8)
+#define SPDIFTX_MR_VBPS(bps)   (((bps) << 8) & SPDIFTX_MR_VBPS_MASK)
+
+/* Chunk Size */