Re: [PATCH] ASoC: fsl_sai: Set SAI Channel Mode to Output Mode

2019-09-01 Thread Cosmin-Gabriel Samoila
Looks good to me!

Best regards,
Cosmin

On Sat, 2019-08-31 at 01:55 +0300, Daniel Baluta wrote:
> From SAI datasheet:
> 
> CHMOD, configures if transmit data pins are configured for TDM mode
> or Output mode.
>   * (0) TDM mode, transmit data pins are tri-stated when slots
> are
>   masked or channels are disabled.
>   * (1) Output mode, transmit data pins are never tri-stated and
>   will output zero when slots are masked or channels are
> disabled.
> 
> When data pins are tri-stated, there is noise on some channels
> when FS clock value is high and data is read while fsclk is
> transitioning from high to low.
> 
> Fix this by setting CHMOD to Output Mode so that pins will output
> zero
> when slots are masked or channels are disabled.
> 
> Cc: NXP Linux Team 
> Signed-off-by: Cosmin-Gabriel Samoila 
> Signed-off-by: Daniel Baluta 
> ---
>  sound/soc/fsl/fsl_sai.c | 15 ---
>  sound/soc/fsl/fsl_sai.h |  2 ++
>  2 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> index e896b577b1f7..b9daab0eb6eb 100644
> --- a/sound/soc/fsl/fsl_sai.c
> +++ b/sound/soc/fsl/fsl_sai.c
> @@ -467,6 +467,12 @@ static int fsl_sai_hw_params(struct
> snd_pcm_substream *substream,
>  
>   val_cr4 |= FSL_SAI_CR4_FRSZ(slots);
>  
> + /*
> +  * set CHMOD to Output Mode so that transmit data pins will
> +  * output zero when slots are masked or channels are disabled
> +  */
> + val_cr4 |= FSL_SAI_CR4_CHMOD;
> +
>   /*
>* For SAI master mode, when Tx(Rx) sync with Rx(Tx) clock,
> Rx(Tx) will
>* generate bclk and frame clock for Tx(Rx), we should set
> RCR4(TCR4),
> @@ -477,7 +483,8 @@ static int fsl_sai_hw_params(struct
> snd_pcm_substream *substream,
>   if (!sai->is_slave_mode) {
>   if (!sai->synchronous[TX] && sai->synchronous[RX] &&
> !tx) {
>   regmap_update_bits(sai->regmap,
> FSL_SAI_TCR4(ofs),
> - FSL_SAI_CR4_SYWD_MASK |
> FSL_SAI_CR4_FRSZ_MASK,
> + FSL_SAI_CR4_SYWD_MASK |
> FSL_SAI_CR4_FRSZ_MASK |
> + FSL_SAI_CR4_CHMOD_MASK,
>   val_cr4);
>   regmap_update_bits(sai->regmap,
> FSL_SAI_TCR5(ofs),
>   FSL_SAI_CR5_WNW_MASK |
> FSL_SAI_CR5_W0W_MASK |
> @@ -486,7 +493,8 @@ static int fsl_sai_hw_params(struct
> snd_pcm_substream *substream,
>   ~0UL - ((1 << channels) - 1));
>   } else if (!sai->synchronous[RX] && sai-
> >synchronous[TX] && tx) {
>   regmap_update_bits(sai->regmap,
> FSL_SAI_RCR4(ofs),
> - FSL_SAI_CR4_SYWD_MASK |
> FSL_SAI_CR4_FRSZ_MASK,
> + FSL_SAI_CR4_SYWD_MASK |
> FSL_SAI_CR4_FRSZ_MASK |
> + FSL_SAI_CR4_CHMOD_MASK,
>   val_cr4);
>   regmap_update_bits(sai->regmap,
> FSL_SAI_RCR5(ofs),
>   FSL_SAI_CR5_WNW_MASK |
> FSL_SAI_CR5_W0W_MASK |
> @@ -497,7 +505,8 @@ static int fsl_sai_hw_params(struct
> snd_pcm_substream *substream,
>   }
>  
>   regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs),
> -FSL_SAI_CR4_SYWD_MASK |
> FSL_SAI_CR4_FRSZ_MASK,
> +FSL_SAI_CR4_SYWD_MASK |
> FSL_SAI_CR4_FRSZ_MASK |
> +FSL_SAI_CR4_CHMOD_MASK,
>  val_cr4);
>   regmap_update_bits(sai->regmap, FSL_SAI_xCR5(tx, ofs),
>  FSL_SAI_CR5_WNW_MASK | FSL_SAI_CR5_W0W_MASK
> |
> diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
> index f96f8d97489d..1e3b4a6889a8 100644
> --- a/sound/soc/fsl/fsl_sai.h
> +++ b/sound/soc/fsl/fsl_sai.h
> @@ -119,6 +119,8 @@
>  #define FSL_SAI_CR4_FRSZ_MASK(0x1f << 16)
>  #define FSL_SAI_CR4_SYWD(x)  (((x) - 1) << 8)
>  #define FSL_SAI_CR4_SYWD_MASK(0x1f << 8)
> +#define FSL_SAI_CR4_CHMODBIT(5)
> +#define FSL_SAI_CR4_CHMOD_MASK   GENMASK(5, 5)
>  #define FSL_SAI_CR4_MF   BIT(4)
>  #define FSL_SAI_CR4_FSE  BIT(3)
>  #define FSL_SAI_CR4_FSP  BIT(1)



[PATCH 0/2] Fix coding style issues in AK4458 DAC

2018-02-20 Thread Cosmin-Gabriel Samoila
Modify SPDX license comment style and sort headers alphabetically.

Cosmin-Gabriel Samoila (2):
  ASoC: ak4458: Modify SPDX license format
  ASoC: ak4458: Sort headers alphabetically

 sound/soc/codecs/ak4458.c | 23 +++
 sound/soc/codecs/ak4458.h |  2 +-
 2 files changed, 12 insertions(+), 13 deletions(-)

-- 
2.7.4



[PATCH 1/2] ASoC: ak4458: Modify SPDX license format

2018-02-20 Thread Cosmin-Gabriel Samoila
Modify SPDX comment style to match the rules. Since the original
code had a GPL-2.0 license and SPDX is compatible with GPL-2.0+,
we also modified the MODULE_LICENSE.

Signed-off-by: Cosmin-Gabriel Samoila 
---
 sound/soc/codecs/ak4458.c | 13 ++---
 sound/soc/codecs/ak4458.h |  2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/ak4458.c b/sound/soc/codecs/ak4458.c
index d2815ac..8a49dd2 100644
--- a/sound/soc/codecs/ak4458.c
+++ b/sound/soc/codecs/ak4458.c
@@ -1,10 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
-/*
- * Audio driver for AK4458 DAC
- *
- * Copyright (C) 2016 Asahi Kasei Microdevices Corporation
- * Copyright 2018 NXP
- */
+//
+// Audio driver for AK4458 DAC
+//
+// Copyright (C) 2016 Asahi Kasei Microdevices Corporation
+// Copyright 2018 NXP
 
 #include 
 #include 
@@ -655,4 +654,4 @@ module_i2c_driver(ak4458_i2c_driver);
 MODULE_AUTHOR("Junichi Wakasugi ");
 MODULE_AUTHOR("Mihai Serban ");
 MODULE_DESCRIPTION("ASoC AK4458 DAC driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/ak4458.h b/sound/soc/codecs/ak4458.h
index 16d9d22..f906215 100644
--- a/sound/soc/codecs/ak4458.h
+++ b/sound/soc/codecs/ak4458.h
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Audio driver for AK4458
  *
-- 
2.7.4



[PATCH 2/2] ASoC: ak4458: Sort headers alphabetically

2018-02-20 Thread Cosmin-Gabriel Samoila
Keep headers sorted alphabetically.

Signed-off-by: Cosmin-Gabriel Samoila 
---
 sound/soc/codecs/ak4458.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/ak4458.c b/sound/soc/codecs/ak4458.c
index 8a49dd2..31ec0ba 100644
--- a/sound/soc/codecs/ak4458.c
+++ b/sound/soc/codecs/ak4458.c
@@ -5,19 +5,19 @@
 // Copyright (C) 2016 Asahi Kasei Microdevices Corporation
 // Copyright 2018 NXP
 
-#include 
 #include 
-#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
-#include 
+#include 
+#include 
+#include 
 #include 
 #include 
-#include 
 #include 
-#include 
 
 #include "ak4458.h"
 
-- 
2.7.4



[PATCH v3 1/2] ASoC: codecs: Add support for AK4458 DAC driver

2018-02-14 Thread Cosmin-Gabriel Samoila
The AK4458 is a 32-bit 8ch Premium DAC that corresponds
to a 768kHz PCM input and an 11.2MHz DSD input at maximum.
It supports I2S, DSD and TDM modes with 24 or 32 bit MSB
or 16, 24, 32 LSB formats. Its datasheet is available here:
https://www.akm.com/akm/en/file/datasheet/AK4458VN.pdf

Signed-off-by: Junichi Wakasugi 
Signed-off-by: Mihai Serban 
Signed-off-by: Shengjiu Wang 
Signed-off-by: Cosmin-Gabriel Samoila 
---
 sound/soc/codecs/Kconfig  |   6 +
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/ak4458.c | 659 ++
 sound/soc/codecs/ak4458.h |  86 ++
 4 files changed, 753 insertions(+)
 create mode 100644 sound/soc/codecs/ak4458.c
 create mode 100644 sound/soc/codecs/ak4458.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 2b331f7..7f6fb5e 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -35,6 +35,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_ADAU7002
select SND_SOC_ADS117X
select SND_SOC_AK4104 if SPI_MASTER
+   select SND_SOC_AK4458 if I2C
select SND_SOC_AK4535 if I2C
select SND_SOC_AK4554
select SND_SOC_AK4613 if I2C
@@ -375,6 +376,11 @@ config SND_SOC_AK4104
tristate "AKM AK4104 CODEC"
depends on SPI_MASTER
 
+config SND_SOC_AK4458
+   tristate "AKM AK4458 CODEC"
+   depends on I2C
+   select REGMAP_I2C
+
 config SND_SOC_AK4535
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 4053c72..339b674 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -27,6 +27,7 @@ snd-soc-adav801-objs := adav801.o
 snd-soc-adav803-objs := adav803.o
 snd-soc-ads117x-objs := ads117x.o
 snd-soc-ak4104-objs := ak4104.o
+snd-soc-ak4458-objs := ak4458.o
 snd-soc-ak4535-objs := ak4535.o
 snd-soc-ak4554-objs := ak4554.o
 snd-soc-ak4613-objs := ak4613.o
@@ -270,6 +271,7 @@ obj-$(CONFIG_SND_SOC_ADAV801)  += snd-soc-adav801.o
 obj-$(CONFIG_SND_SOC_ADAV803)  += snd-soc-adav803.o
 obj-$(CONFIG_SND_SOC_ADS117X)  += snd-soc-ads117x.o
 obj-$(CONFIG_SND_SOC_AK4104)   += snd-soc-ak4104.o
+obj-$(CONFIG_SND_SOC_AK4458)   += snd-soc-ak4458.o
 obj-$(CONFIG_SND_SOC_AK4535)   += snd-soc-ak4535.o
 obj-$(CONFIG_SND_SOC_AK4554)   += snd-soc-ak4554.o
 obj-$(CONFIG_SND_SOC_AK4613)   += snd-soc-ak4613.o
diff --git a/sound/soc/codecs/ak4458.c b/sound/soc/codecs/ak4458.c
new file mode 100644
index 000..b579cda
--- /dev/null
+++ b/sound/soc/codecs/ak4458.c
@@ -0,0 +1,659 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Audio driver for AK4458 DAC
+ *
+ * Copyright (C) 2016 Asahi Kasei Microdevices Corporation
+ * Copyright 2018 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ak4458.h"
+
+/* AK4458 Codec Private Data */
+struct ak4458_priv {
+   struct device *dev;
+   struct regmap *regmap;
+   struct gpio_desc *reset_gpiod;
+   struct gpio_desc *mute_gpiod;
+   int digfil; /* SSLOW, SD, SLOW bits */
+   int fs; /* sampling rate */
+   int fmt;
+   int slots;
+   int slot_width;
+};
+
+static const struct reg_default ak4458_reg_defaults[] = {
+   { 0x00, 0x0C }, /*  0x00AK4458_00_CONTROL1  */
+   { 0x01, 0x22 }, /*  0x01AK4458_01_CONTROL2  */
+   { 0x02, 0x00 }, /*  0x02AK4458_02_CONTROL3  */
+   { 0x03, 0xFF }, /*  0x03AK4458_03_LCHATT*/
+   { 0x04, 0xFF }, /*  0x04AK4458_04_RCHATT*/
+   { 0x05, 0x00 }, /*  0x05AK4458_05_CONTROL4  */
+   { 0x06, 0x00 }, /*  0x06AK4458_06_DSD1  */
+   { 0x07, 0x03 }, /*  0x07AK4458_07_CONTROL5  */
+   { 0x08, 0x00 }, /*  0x08AK4458_08_SOUND_CONTROL */
+   { 0x09, 0x00 }, /*  0x09AK4458_09_DSD2  */
+   { 0x0A, 0x0D }, /*  0x0AAK4458_0A_CONTROL6  */
+   { 0x0B, 0x0C }, /*  0x0BAK4458_0B_CONTROL7  */
+   { 0x0C, 0x00 }, /*  0x0CAK4458_0C_CONTROL8  */
+   { 0x0D, 0x00 }, /*  0x0DAK4458_0D_CONTROL9  */
+   { 0x0E, 0x50 }, /*  0x0EAK4458_0E_CONTROL10 */
+   { 0x0F, 0xFF }, /*  0x0FAK4458_0F_L2CHATT   */
+   { 0x10, 0xFF }, /*  0x10AK4458_10_R2CHATT   */
+   { 0x11, 0xFF }, /*  0x11AK4458_11_L3CHATT   */
+   { 0x12, 0xFF }, /*  0x12AK4458_12_R3CHATT   */
+   { 0x13, 0xFF }, /*  0x13AK4458_13_L4CHATT   */
+   { 0x14, 0xFF }, /*  0x14AK4458_14_R4CHATT   */
+};
+
+/*
+ * Volume control:
+ * from -127 to 0 dB in 0.5 dB steps (mute instead of -127.5 dB)
+ */
+static DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
+
+/*
+ * DEM1 bit DEM0 bit Mode
+ * 0 0 44.1kHz
+ * 0 1 OFF (default)
+ * 1 0 48kHz
+ * 1 1 32kHz
+ */
+static const char *

[PATCH v3 0/2] Add support for AK4458 DAC

2018-02-14 Thread Cosmin-Gabriel Samoila
We support Normal Mode, TDM Mode and PM.

Changes since V2:
- remove unused code left from V1
- rewrite set_dai_fmt to only remember the format since
- the format is rewritten in hw_params
- use defined constants for mode in set_tdm_slot function
- use GENMASK
- add commit message for bindings patch
- modify bindings description text since we only support I2C for now
- rename ak4458_codec_probe to ak4458_probe
- write whole implementation of regmap init and gpiod get in i2c_probe
- added ak4458_remove where we power_off the chip

Changes since V1:
- support only i2c
- i2c probe / remove/suspend/ resume moved into shared code 

- change enum array to separate variables
- aggregate Volume control for Left and Right Channel
- remove mux from DAPM
- remove unused functions
- remove unused controls
- remove unused macros
- use snd_soc_update_bits instead of soc_read + soc_write
- use GPIOD
- use SPDX identifier
- use dac@10 instgitead of ak4458@10
- use explicit power_on/off functions
- add __maybe_unused attribute
- use probe_new for i2c_probe

Cosmin-Gabriel Samoila (2):
  ASoC: codecs: Add support for AK4458 DAC driver
  ASoC: ak4458: Add bindings for AK4458 DAC

 Documentation/devicetree/bindings/sound/ak4458.txt |  23 +
 sound/soc/codecs/Kconfig   |   6 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/ak4458.c  | 659 +
 sound/soc/codecs/ak4458.h  |  86 +++
 5 files changed, 776 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ak4458.txt
 create mode 100644 sound/soc/codecs/ak4458.c
 create mode 100644 sound/soc/codecs/ak4458.h

-- 
2.7.4



[PATCH v3 2/2] ASoC: ak4458: Add bindings for AK4458 DAC

2018-02-14 Thread Cosmin-Gabriel Samoila
Document the bindings for AK4458 DAC

Signed-off-by: Cosmin-Gabriel Samoila 
---
 Documentation/devicetree/bindings/sound/ak4458.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ak4458.txt

diff --git a/Documentation/devicetree/bindings/sound/ak4458.txt 
b/Documentation/devicetree/bindings/sound/ak4458.txt
new file mode 100644
index 000..7839be7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ak4458.txt
@@ -0,0 +1,23 @@
+AK4458 audio DAC
+
+This device supports I2C mode.
+
+Required properties:
+
+- compatible : "asahi-kasei,ak4458"
+- reg : The I2C address of the device for I2C
+
+Optional properties:
+- reset-gpios: A GPIO specifier for the power down & reset pin
+- mute-gpios: A GPIO specifier for the soft mute pin
+
+Example:
+
+&i2c {
+   ak4458: dac@10 {
+   compatible = "asahi-kasei,ak4458";
+   reg = <0x10>;
+   reset-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>
+   mute-gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>
+   };
+};
-- 
2.7.4



[PATCH v2 1/2] ASoC: codecs: Add support for AK4458 DAC driver

2018-02-13 Thread Cosmin-Gabriel Samoila
The AK4458 is a 32-bit 8ch Premium DAC that corresponds
to a 768kHz PCM input and an 11.2MHz DSD input at maximum.
It supports I2S, DSD and TDM modes with 24 or 32 bit MSB
or 16, 24, 32 LSB formats. Its datasheet is available here:
https://www.akm.com/akm/en/file/datasheet/AK4458VN.pdf

Signed-off-by: Junichi Wakasugi 
Signed-off-by: Mihai Serban 
Signed-off-by: Shengjiu Wang 
Signed-off-by: Cosmin-Gabriel Samoila 
---
 sound/soc/codecs/Kconfig  |   6 +
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/ak4458.c | 684 ++
 sound/soc/codecs/ak4458.h |  75 +
 4 files changed, 767 insertions(+)
 create mode 100644 sound/soc/codecs/ak4458.c
 create mode 100644 sound/soc/codecs/ak4458.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 2b331f7..7f6fb5e 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -35,6 +35,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_ADAU7002
select SND_SOC_ADS117X
select SND_SOC_AK4104 if SPI_MASTER
+   select SND_SOC_AK4458 if I2C
select SND_SOC_AK4535 if I2C
select SND_SOC_AK4554
select SND_SOC_AK4613 if I2C
@@ -375,6 +376,11 @@ config SND_SOC_AK4104
tristate "AKM AK4104 CODEC"
depends on SPI_MASTER
 
+config SND_SOC_AK4458
+   tristate "AKM AK4458 CODEC"
+   depends on I2C
+   select REGMAP_I2C
+
 config SND_SOC_AK4535
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index da15713..7f5d575 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -27,6 +27,7 @@ snd-soc-adav801-objs := adav801.o
 snd-soc-adav803-objs := adav803.o
 snd-soc-ads117x-objs := ads117x.o
 snd-soc-ak4104-objs := ak4104.o
+snd-soc-ak4458-objs := ak4458.o
 snd-soc-ak4535-objs := ak4535.o
 snd-soc-ak4554-objs := ak4554.o
 snd-soc-ak4613-objs := ak4613.o
@@ -270,6 +271,7 @@ obj-$(CONFIG_SND_SOC_ADAV801)  += snd-soc-adav801.o
 obj-$(CONFIG_SND_SOC_ADAV803)  += snd-soc-adav803.o
 obj-$(CONFIG_SND_SOC_ADS117X)  += snd-soc-ads117x.o
 obj-$(CONFIG_SND_SOC_AK4104)   += snd-soc-ak4104.o
+obj-$(CONFIG_SND_SOC_AK4458)   += snd-soc-ak4458.o
 obj-$(CONFIG_SND_SOC_AK4535)   += snd-soc-ak4535.o
 obj-$(CONFIG_SND_SOC_AK4554)   += snd-soc-ak4554.o
 obj-$(CONFIG_SND_SOC_AK4613)   += snd-soc-ak4613.o
diff --git a/sound/soc/codecs/ak4458.c b/sound/soc/codecs/ak4458.c
new file mode 100644
index 000..7da3f65
--- /dev/null
+++ b/sound/soc/codecs/ak4458.c
@@ -0,0 +1,684 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Audio driver for AK4458 DAC
+ *
+ * Copyright (C) 2016 Asahi Kasei Microdevices Corporation
+ * Copyright 2018 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ak4458.h"
+
+/* AK4458 Codec Private Data */
+struct ak4458_priv {
+   struct device *dev;
+   struct regmap *regmap;
+   struct gpio_desc *reset_gpiod;
+   struct gpio_desc *mute_gpiod;
+   int digfil; /* SSLOW, SD, SLOW bits */
+   int fs; /* sampling rate */
+   int fmt;
+   int slots;
+   int slot_width;
+};
+
+static const struct reg_default ak4458_reg_defaults[] = {
+   { 0x00, 0x0C }, /*  0x00AK4458_00_CONTROL1  */
+   { 0x01, 0x22 }, /*  0x01AK4458_01_CONTROL2  */
+   { 0x02, 0x00 }, /*  0x02AK4458_02_CONTROL3  */
+   { 0x03, 0xFF }, /*  0x03AK4458_03_LCHATT*/
+   { 0x04, 0xFF }, /*  0x04AK4458_04_RCHATT*/
+   { 0x05, 0x00 }, /*  0x05AK4458_05_CONTROL4  */
+   { 0x06, 0x00 }, /*  0x06AK4458_06_DSD1  */
+   { 0x07, 0x03 }, /*  0x07AK4458_07_CONTROL5  */
+   { 0x08, 0x00 }, /*  0x08AK4458_08_SOUND_CONTROL */
+   { 0x09, 0x00 }, /*  0x09AK4458_09_DSD2  */
+   { 0x0A, 0x0D }, /*  0x0AAK4458_0A_CONTROL6  */
+   { 0x0B, 0x0C }, /*  0x0BAK4458_0B_CONTROL7  */
+   { 0x0C, 0x00 }, /*  0x0CAK4458_0C_CONTROL8  */
+   { 0x0D, 0x00 }, /*  0x0DAK4458_0D_CONTROL9  */
+   { 0x0E, 0x50 }, /*  0x0EAK4458_0E_CONTROL10 */
+   { 0x0F, 0xFF }, /*  0x0FAK4458_0F_L2CHATT   */
+   { 0x10, 0xFF }, /*  0x10AK4458_10_R2CHATT   */
+   { 0x11, 0xFF }, /*  0x11AK4458_11_L3CHATT   */
+   { 0x12, 0xFF }, /*  0x12AK4458_12_R3CHATT   */
+   { 0x13, 0xFF }, /*  0x13AK4458_13_L4CHATT   */
+   { 0x14, 0xFF }, /*  0x14AK4458_14_R4CHATT   */
+};
+
+/*
+ * Volume control:
+ * from -127 to 0 dB in 0.5 dB steps (mute instead of -127.5 dB)
+ */
+static DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
+
+/*
+ * DEM1 bit DEM0 bit Mode
+ * 0 0 44.1kHz
+ * 0 1 OFF (default)
+ * 1 0 48kHz
+ * 1 1 32kHz
+ */
+static const char *

[PATCH v2 0/2] Add support for AK4458 DAC

2018-02-13 Thread Cosmin-Gabriel Samoila
We support Normal Mode, TDM Mode and PM.

Changes since V1:
- support only i2c
- i2c probe / remove/suspend/ resume moved into shared code
- change enum array to separate variables
- aggregate Volume control for Left and Right Channel
- remove mux from DAPM
- remove unused functions
- remove unused controls
- remove unused macros
- use snd_soc_update_bits instead of soc_read + soc_write
- use GPIOD
- use SPDX identifier
- use dac@10 instgitead of ak4458@10
- use explicit power_on/off functions
- add __maybe_unused attribute
- use probe_new for i2c_probe

Cosmin-Gabriel Samoila (2):
  ASoC: codecs: Add support for AK4458 DAC driver
  ASoC: ak4458: Add bindings for AK4458 DAC

 Documentation/devicetree/bindings/sound/ak4458.txt |  23 +
 sound/soc/codecs/Kconfig   |   6 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/ak4458.c  | 684 +
 sound/soc/codecs/ak4458.h  |  75 +++
 5 files changed, 790 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ak4458.txt
 create mode 100644 sound/soc/codecs/ak4458.c
 create mode 100644 sound/soc/codecs/ak4458.h

-- 
2.7.4



[PATCH v2 2/2] ASoC: ak4458: Add bindings for AK4458 DAC

2018-02-13 Thread Cosmin-Gabriel Samoila
Signed-off-by: Junichi Wakasugi 
Signed-off-by: Mihai Serban 
Signed-off-by: Shengjiu Wang 
Signed-off-by: Cosmin-Gabriel Samoila 
---
 Documentation/devicetree/bindings/sound/ak4458.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ak4458.txt

diff --git a/Documentation/devicetree/bindings/sound/ak4458.txt 
b/Documentation/devicetree/bindings/sound/ak4458.txt
new file mode 100644
index 000..9bab245
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ak4458.txt
@@ -0,0 +1,23 @@
+AK4458 audio DAC
+
+This device supports both I2C and SPI modes.
+
+Required properties:
+
+- compatible : "asahi-kasei,ak4458"
+- reg : The I2C address of the device for I2C, the chip select number for SPI.
+
+Optional properties:
+- reset-gpios: A GPIO specifier for the power down & reset pin
+- mute-gpios: A GPIO specifier for the soft mute pin
+
+Example:
+
+&i2c {
+   ak4458: dac@10 {
+   compatible = "asahi-kasei,ak4458";
+   reg = <0x10>;
+   reset-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>
+   mute-gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>
+   };
+};
-- 
2.7.4



[PATCH] ASoC: codecs: Add support for AK4458 DAC driver

2018-01-31 Thread Cosmin-Gabriel Samoila
The AK4458 is a 32-bit 8ch Premium DAC that corresponds
to a 768kHz PCM input and an 11.2MHz DSD input at maximum.
It supports I2S, DSD and TDM modes with 24 or 32 bit MSB
or 16, 24, 32 LSB formats. Its datasheet is available here:
https://www.akm.com/akm/en/file/datasheet/AK4458VN.pdf

Signed-off-by: Junichi Wakasugi 
Signed-off-by: Mihai Serban 
Signed-off-by: Shengjiu Wang 
Signed-off-by: Cosmin-Gabriel Samoila 
---
 Documentation/devicetree/bindings/sound/ak4458.txt |   23 +
 sound/soc/codecs/Kconfig   |   18 +
 sound/soc/codecs/Makefile  |6 +
 sound/soc/codecs/ak4458-i2c.c  |   79 ++
 sound/soc/codecs/ak4458-spi.c  |   61 ++
 sound/soc/codecs/ak4458.c  | 1132 
 sound/soc/codecs/ak4458.h  |  127 +++
 7 files changed, 1446 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ak4458.txt
 create mode 100644 sound/soc/codecs/ak4458-i2c.c
 create mode 100644 sound/soc/codecs/ak4458-spi.c
 create mode 100644 sound/soc/codecs/ak4458.c
 create mode 100644 sound/soc/codecs/ak4458.h

diff --git a/Documentation/devicetree/bindings/sound/ak4458.txt 
b/Documentation/devicetree/bindings/sound/ak4458.txt
new file mode 100644
index 000..b9e6eb3
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ak4458.txt
@@ -0,0 +1,23 @@
+AK4458 audio DAC
+
+This device supports both I2C and SPI modes.
+
+Required properties:
+
+- compatible : "asahi-kasei,ak4458"
+- reg : The I2C address of the device for I2C, the chip select number for SPI.
+- asahi-kasei,pdn-gpios: A GPIO specifier for the GPIO controlling
+   the power down & reset pin.
+- asahi-kasei,mute-gpios: A GPIO specifier for the GPIO controlling
+   the soft mute pin.
+
+Example:
+
+&i2c {
+   ak4458: ak4458@10 {
+   compatible = "asahi-kasei,ak4458";
+   reg = <0x10>;
+   asahi-kasei,pdn-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>
+   asahi-kasei,mute-gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>
+   };
+};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 2b331f7..488bf48 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -35,6 +35,9 @@ config SND_SOC_ALL_CODECS
select SND_SOC_ADAU7002
select SND_SOC_ADS117X
select SND_SOC_AK4104 if SPI_MASTER
+   select SND_SOC_AK4458
+   select SND_SOC_AK4458_I2C if I2C
+   select SND_SOC_AK4458_SPI if SPI_MASTER
select SND_SOC_AK4535 if I2C
select SND_SOC_AK4554
select SND_SOC_AK4613 if I2C
@@ -375,6 +378,21 @@ config SND_SOC_AK4104
tristate "AKM AK4104 CODEC"
depends on SPI_MASTER
 
+config SND_SOC_AK4458
+   tristate
+
+config SND_SOC_AK4458_I2C
+   tristate "AKM AK4458 DAC I2c"
+   depends on I2C
+   select SND_SOC_AK4458
+   select REGMAP_I2C
+
+config SND_SOC_AK4458_SPI
+   tristate "AKM AK4458 DAC SPI"
+   depends on SPI_MASTER
+   select SND_SOC_AK4458
+   select REGMAP_SPI
+
 config SND_SOC_AK4535
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index da15713..53bd24b 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -27,6 +27,9 @@ snd-soc-adav801-objs := adav801.o
 snd-soc-adav803-objs := adav803.o
 snd-soc-ads117x-objs := ads117x.o
 snd-soc-ak4104-objs := ak4104.o
+snd-soc-ak4458-objs := ak4458.o
+snd-soc-ak4458-i2c-objs := ak4458-i2c.o
+snd-soc-ak4458-spi-objs := ak4458-spi.o
 snd-soc-ak4535-objs := ak4535.o
 snd-soc-ak4554-objs := ak4554.o
 snd-soc-ak4613-objs := ak4613.o
@@ -270,6 +273,9 @@ obj-$(CONFIG_SND_SOC_ADAV801)  += snd-soc-adav801.o
 obj-$(CONFIG_SND_SOC_ADAV803)  += snd-soc-adav803.o
 obj-$(CONFIG_SND_SOC_ADS117X)  += snd-soc-ads117x.o
 obj-$(CONFIG_SND_SOC_AK4104)   += snd-soc-ak4104.o
+obj-$(CONFIG_SND_SOC_AK4458)   += snd-soc-ak4458.o
+obj-$(CONFIG_SND_SOC_AK4458_I2C)   += snd-soc-ak4458-i2c.o
+obj-$(CONFIG_SND_SOC_AK4458_SPI)   += snd-soc-ak4458-spi.o
 obj-$(CONFIG_SND_SOC_AK4535)   += snd-soc-ak4535.o
 obj-$(CONFIG_SND_SOC_AK4554)   += snd-soc-ak4554.o
 obj-$(CONFIG_SND_SOC_AK4613)   += snd-soc-ak4613.o
diff --git a/sound/soc/codecs/ak4458-i2c.c b/sound/soc/codecs/ak4458-i2c.c
new file mode 100644
index 000..9313aef
--- /dev/null
+++ b/sound/soc/codecs/ak4458-i2c.c
@@ -0,0 +1,79 @@
+/*
+ * ak4458-i2c.c  --  AK4458 DAC - I2C
+ *
+ * Copyright 2018 NXP
+ *
+ * Author: Mihai Serban 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNES

[PATCH] Drivers: isdn: hisax: isac.c: Fix assignment and check into one expression.

2016-03-25 Thread Cosmin-Gabriel Samoila
Fix variable assignment inside if statement. It is error-prone and hard to read.

Signed-off-by: Cosmin-Gabriel Samoila 
---
 drivers/isdn/hisax/isac.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
index 7fdf78f..df7e05c 100644
--- a/drivers/isdn/hisax/isac.c
+++ b/drivers/isdn/hisax/isac.c
@@ -215,9 +215,11 @@ isac_interrupt(struct IsdnCardState *cs, u_char val)
if (count == 0)
count = 32;
isac_empty_fifo(cs, count);
-   if ((count = cs->rcvidx) > 0) {
+   count = cs->rcvidx;
+   if (count > 0) {
cs->rcvidx = 0;
-   if (!(skb = alloc_skb(count, GFP_ATOMIC)))
+   skb = alloc_skb(count, GFP_ATOMIC);
+   if (!skb)
printk(KERN_WARNING "HiSax: D receive 
out of memory\n");
else {
memcpy(skb_put(skb, count), cs->rcvbuf, 
count);
@@ -251,7 +253,8 @@ isac_interrupt(struct IsdnCardState *cs, u_char val)
cs->tx_skb = NULL;
}
}
-   if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
+   cs->tx_skb = skb_dequeue(&cs->sq);
+   if (cs->tx_skb) {
cs->tx_cnt = 0;
isac_fill_fifo(cs);
} else
@@ -313,7 +316,8 @@ afterXPR:
 #if ARCOFI_USE
if (v1 & 0x08) {
if (!cs->dc.isac.mon_rx) {
-   if (!(cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
+   cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
+   if (!cs->dc.isac.mon_rx) {
if (cs->debug & L1_DEB_WARN)
debugl1(cs, "ISAC MON 
RX out of memory!");
cs->dc.isac.mocr &= 0xf0;
@@ -343,7 +347,8 @@ afterXPR:
afterMONR0:
if (v1 & 0x80) {
if (!cs->dc.isac.mon_rx) {
-   if (!(cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
+   cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
+   if (!cs->dc.isac.mon_rx) {
if (cs->debug & L1_DEB_WARN)
debugl1(cs, "ISAC MON 
RX out of memory!");
cs->dc.isac.mocr &= 0x0f;
-- 
1.9.1



[PATCH 2/2] isdn: hisax: isac: fixed code style issues.

2016-03-13 Thread Cosmin-Gabriel Samoila
Fixed errors and warnings reported by checkpatch.pl.

Signed-off-by: Cosmin-Gabriel Samoila 
---
 drivers/isdn/hisax/isac.c | 32 ++--
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
index 7fdf78f..419abe1 100644
--- a/drivers/isdn/hisax/isac.c
+++ b/drivers/isdn/hisax/isac.c
@@ -24,9 +24,8 @@
 #define DBUSY_TIMER_VALUE 80
 #define ARCOFI_USE 1
 
-static char *ISACVer[] =
-{"2086/2186 V1.1", "2085 B1", "2085 B2",
- "2085 V2.3"};
+static char *ISACVer[] = {"2086/2186 V1.1", "2085 B1", "2085 B2",
+"2085 V2.3"};
 
 void ISACVersion(struct IsdnCardState *cs, char *s)
 {
@@ -215,9 +214,11 @@ isac_interrupt(struct IsdnCardState *cs, u_char val)
if (count == 0)
count = 32;
isac_empty_fifo(cs, count);
-   if ((count = cs->rcvidx) > 0) {
+   count = cs->rcvidx;
+   if (count > 0) {
cs->rcvidx = 0;
-   if (!(skb = alloc_skb(count, GFP_ATOMIC)))
+   skb = alloc_skb(count, GFP_ATOMIC);
+   if (!skb)
printk(KERN_WARNING "HiSax: D receive 
out of memory\n");
else {
memcpy(skb_put(skb, count), cs->rcvbuf, 
count);
@@ -251,11 +252,12 @@ isac_interrupt(struct IsdnCardState *cs, u_char val)
cs->tx_skb = NULL;
}
}
-   if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
+   cs->tx_skb = skb_dequeue(&cs->sq);
+   if (cs->tx_skb) {
cs->tx_cnt = 0;
isac_fill_fifo(cs);
-   } else
-   schedule_event(cs, D_XMTBUFREADY);
+   }
+   schedule_event(cs, D_XMTBUFREADY);
}
 afterXPR:
if (val & 0x04) {   /* CISQ */
@@ -313,7 +315,8 @@ afterXPR:
 #if ARCOFI_USE
if (v1 & 0x08) {
if (!cs->dc.isac.mon_rx) {
-   if (!(cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
+   cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
+   if (!cs->dc.isac.mon_rx) {
if (cs->debug & L1_DEB_WARN)
debugl1(cs, "ISAC MON 
RX out of memory!");
cs->dc.isac.mocr &= 0xf0;
@@ -340,10 +343,11 @@ afterXPR:
cs->writeisac(cs, ISAC_MOCR, 
cs->dc.isac.mocr);
}
}
-   afterMONR0:
+afterMONR0:
if (v1 & 0x80) {
if (!cs->dc.isac.mon_rx) {
-   if (!(cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
+   cs->dc.isac.mon_rx = 
kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
+   if (!cs->dc.isac.mon_rx) {
if (cs->debug & L1_DEB_WARN)
debugl1(cs, "ISAC MON 
RX out of memory!");
cs->dc.isac.mocr &= 0x0f;
@@ -368,7 +372,7 @@ afterXPR:
cs->dc.isac.mocr |= 0x40;
cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
}
-   afterMONR1:
+afterMONR1:
if (v1 & 0x04) {
cs->dc.isac.mocr &= 0xf0;
cs->writeisac(cs, ISAC_MOCR, cs->dc.isac.mocr);
@@ -405,7 +409,7 @@ afterXPR:
if (cs->debug & L1_DEB_MONITOR)
debugl1(cs, "ISAC %02x -> MOX0", 
cs->dc.isac.mon_tx[cs->dc.isac.mon_txp - 1]);
}
-   AfterMOX0:
+AfterMOX0:
if (v1 & 0x20) {
if ((!cs->dc.isac.mon_tx) || 
(cs->dc.isac.mon_txc &&
  
(cs->dc.isac.mon_txp >= cs->dc.isac.mon_txc) &&
@@ -428,7 +432,7 @@ afterXPR:
if (cs->debug & L1_DEB_MONITOR)
debugl1(cs, "ISAC %02x -> MOX1", 
cs->dc.isac.mon_tx[cs->dc.isac.mon_txp - 1]);
}
-   AfterMOX1:;
+AfterMOX1:;
 #endif
}
}
-- 
1.9.1



[PATCH] spi: spi-adi-v3: fixed coding style issues.

2016-03-13 Thread Cosmin-Gabriel Samoila
Fixed coding style issues detected using checkpatch.pl.

Signed-off-by: Cosmin-Gabriel Samoila 
---
 drivers/spi/spi-adi-v3.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-adi-v3.c b/drivers/spi/spi-adi-v3.c
index a16b25d..06121cc 100644
--- a/drivers/spi/spi-adi-v3.c
+++ b/drivers/spi/spi-adi-v3.c
@@ -43,9 +43,9 @@ enum adi_spi_state {
 struct adi_spi_master;
 
 struct adi_spi_transfer_ops {
-   void (*write) (struct adi_spi_master *);
-   void (*read) (struct adi_spi_master *);
-   void (*duplex) (struct adi_spi_master *);
+   void (*write)(struct adi_spi_master *);
+   void (*read)(struct adi_spi_master *);
+   void (*duplex)(struct adi_spi_master *);
 };
 
 /* runtime info for spi master */
@@ -150,10 +150,12 @@ static int adi_spi_flush(struct adi_spi_master *drv_data)
 }
 
 /* Chip select operation functions for cs_change flag */
-static void adi_spi_cs_active(struct adi_spi_master *drv_data, struct 
adi_spi_device *chip)
+static void adi_spi_cs_active(struct adi_spi_master *drv_data,
+ struct adi_spi_device *chip)
 {
if (likely(chip->cs < MAX_CTRL_CS)) {
u32 reg;
+
reg = ioread32(&drv_data->regs->ssel);
reg &= ~chip->ssel;
iowrite32(reg, &drv_data->regs->ssel);
@@ -167,6 +169,7 @@ static void adi_spi_cs_deactive(struct adi_spi_master 
*drv_data,
 {
if (likely(chip->cs < MAX_CTRL_CS)) {
u32 reg;
+
reg = ioread32(&drv_data->regs->ssel);
reg |= chip->ssel;
iowrite32(reg, &drv_data->regs->ssel);
@@ -185,6 +188,7 @@ static inline void adi_spi_cs_enable(struct adi_spi_master 
*drv_data,
 {
if (chip->cs < MAX_CTRL_CS) {
u32 reg;
+
reg = ioread32(&drv_data->regs->ssel);
reg |= chip->ssel >> 8;
iowrite32(reg, &drv_data->regs->ssel);
@@ -196,6 +200,7 @@ static inline void adi_spi_cs_disable(struct adi_spi_master 
*drv_data,
 {
if (chip->cs < MAX_CTRL_CS) {
u32 reg;
+
reg = ioread32(&drv_data->regs->ssel);
reg &= ~(chip->ssel >> 8);
iowrite32(reg, &drv_data->regs->ssel);
@@ -686,8 +691,9 @@ static int adi_spi_setup(struct spi_device *spi)
}
} else {
chip->cs_gpio = chip->cs - MAX_CTRL_CS;
-   ret = gpio_request_one(chip->cs_gpio, 
GPIOF_OUT_INIT_HIGH,
-   dev_name(&spi->dev));
+   ret = gpio_request_one(chip->cs_gpio,
+  GPIOF_OUT_INIT_HIGH,
+  dev_name(&spi->dev));
if (ret) {
dev_err(&spi->dev, "gpio_request_one() 
error\n");
goto error;
-- 
1.9.1



[PATCH] iommu: io-pgtable: fixed a brace coding style issue.

2016-03-12 Thread Cosmin-Gabriel Samoila
Fixed a coding style issue.

Signed-off-by: Cosmin-Gabriel Samoila 
---
 drivers/iommu/io-pgtable.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iommu/io-pgtable.c b/drivers/iommu/io-pgtable.c
index 6f2e319..a4a9a42 100644
--- a/drivers/iommu/io-pgtable.c
+++ b/drivers/iommu/io-pgtable.c
@@ -25,8 +25,7 @@
 #include "io-pgtable.h"
 
 static const struct io_pgtable_init_fns *
-io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] =
-{
+io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
 #ifdef CONFIG_IOMMU_IO_PGTABLE_LPAE
[ARM_32_LPAE_S1] = &io_pgtable_arm_32_lpae_s1_init_fns,
[ARM_32_LPAE_S2] = &io_pgtable_arm_32_lpae_s2_init_fns,
-- 
1.9.1