[RESEND PATCH v2 1/2] ASoC: atmel-classd: add the Audio Class D Amplifier

2015-09-27 Thread Songjun Wu
Add driver for the digital imput to PWM output stereo
class D amplifier. It comes with filter, digitally
controlled gain, an equalizer and a dmphase filter.

Signed-off-by: Songjun Wu 
---

Changes in v2:
- Change the "Mono", "Swap" and "Deemphasis" controls to
  "Mono Switch", "Swap Switch" and "Deemphasis Switch".
- Merge "EQ Bass", "EQ Medium" and "EQ Treble" controls
  into one "EQ" control.
- Change the "single-ended" and "differential" to
  "Single ended", "Differential".
- Merge separate left and right controls into one single
  stereo control.
- Add a warning if the user trys to specify an invalid
  value in function "atmel_classd_codec_probe".
- Use the "dev_get_regmap()" in function
  "atmel_classd_codec_get_remap".
- Check for errors when invoking the "clk_prepare_enable".
- Remove the "dev_info" in function "atmel_classd_probe".
- Add some code to create a sound card in function
  "atmel_classd_probe".
- Remove the DT node "Sound" and the related code.

 sound/soc/atmel/Kconfig|9 +
 sound/soc/atmel/Makefile   |2 +
 sound/soc/atmel/atmel-classd.c |  680 
 sound/soc/atmel/atmel-classd.h |  120 +++
 4 files changed, 811 insertions(+)
 create mode 100644 sound/soc/atmel/atmel-classd.c
 create mode 100644 sound/soc/atmel/atmel-classd.h

diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index 1489cd4..2d30464 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -59,4 +59,13 @@ config SND_AT91_SOC_SAM9X5_WM8731
help
  Say Y if you want to add support for audio SoC on an
  at91sam9x5 based board that is using WM8731 codec.
+
+config SND_ATMEL_SOC_CLASSD
+   tristate "Atmel ASoC driver for boards using CLASSD"
+   depends on ARCH_AT91 || COMPILE_TEST
+   select SND_ATMEL_SOC_DMA
+   select REGMAP_MMIO
+   help
+ Say Y if you want to add support for Atmel ASoC driver for boards 
using
+ CLASSD.
 endif
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index b327e5c..f6f7db4 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -11,7 +11,9 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
 snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
 snd-atmel-soc-wm8904-objs := atmel_wm8904.o
 snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o
+snd-atmel-soc-classd-objs := atmel-classd.o
 
 obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
 obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o
 obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o
+obj-$(CONFIG_SND_ATMEL_SOC_CLASSD) += snd-atmel-soc-classd.o
diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c
new file mode 100644
index 000..ab630b3
--- /dev/null
+++ b/sound/soc/atmel/atmel-classd.c
@@ -0,0 +1,680 @@
+/* Atmel ALSA SoC Audio Class D Amplifier (CLASSD) driver
+ *
+ * Copyright (C) 2015 Atmel
+ *
+ * Author: Songjun Wu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or later
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "atmel-classd.h"
+
+struct atmel_classd_pdata {
+   bool non_overlap_enable;
+   int non_overlap_time;
+   int pwm_type;
+   const char *card_name;
+};
+
+struct atmel_classd {
+   dma_addr_t phy_base;
+   struct regmap *regmap;
+   struct clk *pclk;
+   struct clk *gclk;
+   struct clk *aclk;
+   int irq;
+   const struct atmel_classd_pdata *pdata;
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id atmel_classd_of_match[] = {
+   {
+   .compatible = "atmel,sama5d2-classd",
+   }, {
+   /* sentinel */
+   }
+};
+MODULE_DEVICE_TABLE(of, atmel_classd_of_match);
+
+static struct atmel_classd_pdata *atmel_classd_dt_init(struct device *dev)
+{
+   struct device_node *np = dev->of_node;
+   struct atmel_classd_pdata *pdata;
+   const char *pwm_type;
+   int ret;
+
+   if (!np) {
+   dev_err(dev, "device node not found\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_string(np, "atmel,pwm-type", _type);
+   if ((ret == 0) && (strcmp(pwm_type, "diff") == 0))
+   pdata->pwm_type = CLASSD_MR_PWMTYP_DIFF;
+   else
+   pdata->pwm_type = CLASSD_MR_PWMTYP_SINGLE;
+
+   ret = of_property_read_u32(np,
+   "atmel,non-overlap-time", >non_overlap_time);
+   if (ret)
+   pdata->non_overlap_enable = false;
+   else
+   pdata->non_overlap_enable = true;
+
+   ret = of_property_read_string(np, "atmel,model", 

[RESEND PATCH v2 1/2] ASoC: atmel-classd: add the Audio Class D Amplifier

2015-09-27 Thread Songjun Wu
Add driver for the digital imput to PWM output stereo
class D amplifier. It comes with filter, digitally
controlled gain, an equalizer and a dmphase filter.

Signed-off-by: Songjun Wu 
---

Changes in v2:
- Change the "Mono", "Swap" and "Deemphasis" controls to
  "Mono Switch", "Swap Switch" and "Deemphasis Switch".
- Merge "EQ Bass", "EQ Medium" and "EQ Treble" controls
  into one "EQ" control.
- Change the "single-ended" and "differential" to
  "Single ended", "Differential".
- Merge separate left and right controls into one single
  stereo control.
- Add a warning if the user trys to specify an invalid
  value in function "atmel_classd_codec_probe".
- Use the "dev_get_regmap()" in function
  "atmel_classd_codec_get_remap".
- Check for errors when invoking the "clk_prepare_enable".
- Remove the "dev_info" in function "atmel_classd_probe".
- Add some code to create a sound card in function
  "atmel_classd_probe".
- Remove the DT node "Sound" and the related code.

 sound/soc/atmel/Kconfig|9 +
 sound/soc/atmel/Makefile   |2 +
 sound/soc/atmel/atmel-classd.c |  680 
 sound/soc/atmel/atmel-classd.h |  120 +++
 4 files changed, 811 insertions(+)
 create mode 100644 sound/soc/atmel/atmel-classd.c
 create mode 100644 sound/soc/atmel/atmel-classd.h

diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index 1489cd4..2d30464 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -59,4 +59,13 @@ config SND_AT91_SOC_SAM9X5_WM8731
help
  Say Y if you want to add support for audio SoC on an
  at91sam9x5 based board that is using WM8731 codec.
+
+config SND_ATMEL_SOC_CLASSD
+   tristate "Atmel ASoC driver for boards using CLASSD"
+   depends on ARCH_AT91 || COMPILE_TEST
+   select SND_ATMEL_SOC_DMA
+   select REGMAP_MMIO
+   help
+ Say Y if you want to add support for Atmel ASoC driver for boards 
using
+ CLASSD.
 endif
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index b327e5c..f6f7db4 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -11,7 +11,9 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
 snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
 snd-atmel-soc-wm8904-objs := atmel_wm8904.o
 snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o
+snd-atmel-soc-classd-objs := atmel-classd.o
 
 obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
 obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o
 obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o
+obj-$(CONFIG_SND_ATMEL_SOC_CLASSD) += snd-atmel-soc-classd.o
diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c
new file mode 100644
index 000..ab630b3
--- /dev/null
+++ b/sound/soc/atmel/atmel-classd.c
@@ -0,0 +1,680 @@
+/* Atmel ALSA SoC Audio Class D Amplifier (CLASSD) driver
+ *
+ * Copyright (C) 2015 Atmel
+ *
+ * Author: Songjun Wu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or later
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "atmel-classd.h"
+
+struct atmel_classd_pdata {
+   bool non_overlap_enable;
+   int non_overlap_time;
+   int pwm_type;
+   const char *card_name;
+};
+
+struct atmel_classd {
+   dma_addr_t phy_base;
+   struct regmap *regmap;
+   struct clk *pclk;
+   struct clk *gclk;
+   struct clk *aclk;
+   int irq;
+   const struct atmel_classd_pdata *pdata;
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id atmel_classd_of_match[] = {
+   {
+   .compatible = "atmel,sama5d2-classd",
+   }, {
+   /* sentinel */
+   }
+};
+MODULE_DEVICE_TABLE(of, atmel_classd_of_match);
+
+static struct atmel_classd_pdata *atmel_classd_dt_init(struct device *dev)
+{
+   struct device_node *np = dev->of_node;
+   struct atmel_classd_pdata *pdata;
+   const char *pwm_type;
+   int ret;
+
+   if (!np) {
+   dev_err(dev, "device node not found\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_string(np, "atmel,pwm-type", _type);
+   if ((ret == 0) && (strcmp(pwm_type, "diff") == 0))
+   pdata->pwm_type = CLASSD_MR_PWMTYP_DIFF;
+   else
+   pdata->pwm_type = CLASSD_MR_PWMTYP_SINGLE;
+
+   ret = of_property_read_u32(np,
+   "atmel,non-overlap-time", >non_overlap_time);
+   if (ret)
+   pdata->non_overlap_enable = false;
+   else
+   pdata->non_overlap_enable = true;
+
+   ret = 

[PATCH v2 1/2] ASoC: atmel-classd: add the Audio Class D Amplifier

2015-09-23 Thread Songjun Wu
Add driver for the digital imput to PWM output stereo
class D amplifier. It comes with filter, digitally
controlled gain, an equalizer and a dmphase filter.

Signed-off-by: Songjun Wu 
---

Changes in v2:
- Change the "Mono", "Swap" and "Deemphasis" controls to
  "Mono Switch", "Swap Switch" and "Deemphasis Switch".
- Merge "EQ Bass", "EQ Medium" and "EQ Treble" controls
  into one "EQ" control.
- Change the "single-ended" and "differential" to
  "Single ended", "Differential".
- Merge separate left and right controls into one single
  stereo control.
- Add a warning if the user trys to specify an invalid
  value in function "atmel_classd_codec_probe".
- Use the "dev_get_regmap()" in function
  "atmel_classd_codec_get_remap".
- Check for errors when invoking the "clk_prepare_enable".
- Remove the "dev_info" in function "atmel_classd_probe".
- Add some code to create a sound card in function
  "atmel_classd_probe".
- Remove the DT node "Sound" and the related code.

 sound/soc/atmel/Kconfig|9 +
 sound/soc/atmel/Makefile   |2 +
 sound/soc/atmel/atmel-classd.c |  680 
 sound/soc/atmel/atmel-classd.h |  120 +++
 4 files changed, 811 insertions(+)
 create mode 100644 sound/soc/atmel/atmel-classd.c
 create mode 100644 sound/soc/atmel/atmel-classd.h

diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index 1489cd4..2d30464 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -59,4 +59,13 @@ config SND_AT91_SOC_SAM9X5_WM8731
help
  Say Y if you want to add support for audio SoC on an
  at91sam9x5 based board that is using WM8731 codec.
+
+config SND_ATMEL_SOC_CLASSD
+   tristate "Atmel ASoC driver for boards using CLASSD"
+   depends on ARCH_AT91 || COMPILE_TEST
+   select SND_ATMEL_SOC_DMA
+   select REGMAP_MMIO
+   help
+ Say Y if you want to add support for Atmel ASoC driver for boards 
using
+ CLASSD.
 endif
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index b327e5c..f6f7db4 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -11,7 +11,9 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
 snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
 snd-atmel-soc-wm8904-objs := atmel_wm8904.o
 snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o
+snd-atmel-soc-classd-objs := atmel-classd.o
 
 obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
 obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o
 obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o
+obj-$(CONFIG_SND_ATMEL_SOC_CLASSD) += snd-atmel-soc-classd.o
diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c
new file mode 100644
index 000..ab630b3
--- /dev/null
+++ b/sound/soc/atmel/atmel-classd.c
@@ -0,0 +1,680 @@
+/* Atmel ALSA SoC Audio Class D Amplifier (CLASSD) driver
+ *
+ * Copyright (C) 2015 Atmel
+ *
+ * Author: Songjun Wu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or later
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "atmel-classd.h"
+
+struct atmel_classd_pdata {
+   bool non_overlap_enable;
+   int non_overlap_time;
+   int pwm_type;
+   const char *card_name;
+};
+
+struct atmel_classd {
+   dma_addr_t phy_base;
+   struct regmap *regmap;
+   struct clk *pclk;
+   struct clk *gclk;
+   struct clk *aclk;
+   int irq;
+   const struct atmel_classd_pdata *pdata;
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id atmel_classd_of_match[] = {
+   {
+   .compatible = "atmel,sama5d2-classd",
+   }, {
+   /* sentinel */
+   }
+};
+MODULE_DEVICE_TABLE(of, atmel_classd_of_match);
+
+static struct atmel_classd_pdata *atmel_classd_dt_init(struct device *dev)
+{
+   struct device_node *np = dev->of_node;
+   struct atmel_classd_pdata *pdata;
+   const char *pwm_type;
+   int ret;
+
+   if (!np) {
+   dev_err(dev, "device node not found\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_string(np, "atmel,pwm-type", _type);
+   if ((ret == 0) && (strcmp(pwm_type, "diff") == 0))
+   pdata->pwm_type = CLASSD_MR_PWMTYP_DIFF;
+   else
+   pdata->pwm_type = CLASSD_MR_PWMTYP_SINGLE;
+
+   ret = of_property_read_u32(np,
+   "atmel,non-overlap-time", >non_overlap_time);
+   if (ret)
+   pdata->non_overlap_enable = false;
+   else
+   pdata->non_overlap_enable = true;
+
+   ret = of_property_read_string(np, "atmel,model", 

[PATCH v2 1/2] ASoC: atmel-classd: add the Audio Class D Amplifier

2015-09-23 Thread Songjun Wu
Add driver for the digital imput to PWM output stereo
class D amplifier. It comes with filter, digitally
controlled gain, an equalizer and a dmphase filter.

Signed-off-by: Songjun Wu 
---

Changes in v2:
- Change the "Mono", "Swap" and "Deemphasis" controls to
  "Mono Switch", "Swap Switch" and "Deemphasis Switch".
- Merge "EQ Bass", "EQ Medium" and "EQ Treble" controls
  into one "EQ" control.
- Change the "single-ended" and "differential" to
  "Single ended", "Differential".
- Merge separate left and right controls into one single
  stereo control.
- Add a warning if the user trys to specify an invalid
  value in function "atmel_classd_codec_probe".
- Use the "dev_get_regmap()" in function
  "atmel_classd_codec_get_remap".
- Check for errors when invoking the "clk_prepare_enable".
- Remove the "dev_info" in function "atmel_classd_probe".
- Add some code to create a sound card in function
  "atmel_classd_probe".
- Remove the DT node "Sound" and the related code.

 sound/soc/atmel/Kconfig|9 +
 sound/soc/atmel/Makefile   |2 +
 sound/soc/atmel/atmel-classd.c |  680 
 sound/soc/atmel/atmel-classd.h |  120 +++
 4 files changed, 811 insertions(+)
 create mode 100644 sound/soc/atmel/atmel-classd.c
 create mode 100644 sound/soc/atmel/atmel-classd.h

diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index 1489cd4..2d30464 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -59,4 +59,13 @@ config SND_AT91_SOC_SAM9X5_WM8731
help
  Say Y if you want to add support for audio SoC on an
  at91sam9x5 based board that is using WM8731 codec.
+
+config SND_ATMEL_SOC_CLASSD
+   tristate "Atmel ASoC driver for boards using CLASSD"
+   depends on ARCH_AT91 || COMPILE_TEST
+   select SND_ATMEL_SOC_DMA
+   select REGMAP_MMIO
+   help
+ Say Y if you want to add support for Atmel ASoC driver for boards 
using
+ CLASSD.
 endif
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index b327e5c..f6f7db4 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -11,7 +11,9 @@ obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
 snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
 snd-atmel-soc-wm8904-objs := atmel_wm8904.o
 snd-soc-sam9x5-wm8731-objs := sam9x5_wm8731.o
+snd-atmel-soc-classd-objs := atmel-classd.o
 
 obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
 obj-$(CONFIG_SND_ATMEL_SOC_WM8904) += snd-atmel-soc-wm8904.o
 obj-$(CONFIG_SND_AT91_SOC_SAM9X5_WM8731) += snd-soc-sam9x5-wm8731.o
+obj-$(CONFIG_SND_ATMEL_SOC_CLASSD) += snd-atmel-soc-classd.o
diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c
new file mode 100644
index 000..ab630b3
--- /dev/null
+++ b/sound/soc/atmel/atmel-classd.c
@@ -0,0 +1,680 @@
+/* Atmel ALSA SoC Audio Class D Amplifier (CLASSD) driver
+ *
+ * Copyright (C) 2015 Atmel
+ *
+ * Author: Songjun Wu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or later
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "atmel-classd.h"
+
+struct atmel_classd_pdata {
+   bool non_overlap_enable;
+   int non_overlap_time;
+   int pwm_type;
+   const char *card_name;
+};
+
+struct atmel_classd {
+   dma_addr_t phy_base;
+   struct regmap *regmap;
+   struct clk *pclk;
+   struct clk *gclk;
+   struct clk *aclk;
+   int irq;
+   const struct atmel_classd_pdata *pdata;
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id atmel_classd_of_match[] = {
+   {
+   .compatible = "atmel,sama5d2-classd",
+   }, {
+   /* sentinel */
+   }
+};
+MODULE_DEVICE_TABLE(of, atmel_classd_of_match);
+
+static struct atmel_classd_pdata *atmel_classd_dt_init(struct device *dev)
+{
+   struct device_node *np = dev->of_node;
+   struct atmel_classd_pdata *pdata;
+   const char *pwm_type;
+   int ret;
+
+   if (!np) {
+   dev_err(dev, "device node not found\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_string(np, "atmel,pwm-type", _type);
+   if ((ret == 0) && (strcmp(pwm_type, "diff") == 0))
+   pdata->pwm_type = CLASSD_MR_PWMTYP_DIFF;
+   else
+   pdata->pwm_type = CLASSD_MR_PWMTYP_SINGLE;
+
+   ret = of_property_read_u32(np,
+   "atmel,non-overlap-time", >non_overlap_time);
+   if (ret)
+   pdata->non_overlap_enable = false;
+   else
+   pdata->non_overlap_enable = true;
+
+   ret =