All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] ASoC: pcm179x: Add I2C support, declare support for continuous rates
@ 2016-01-19 10:29 Jacob Siverskog
  2016-01-19 10:29   ` Jacob Siverskog
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jacob Siverskog @ 2016-01-19 10:29 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, Michael Trimarchi, Johan Hovold,
	alsa-devel, linux-kernel, Jacob Siverskog

This series add support for I2C and declares support for continuous
sample rates.

Please note that this has only been tested using I2C and PCM1791A. I'd
be grateful if someone can test it with other devices in the PCM179X
family and/or SPI.

These patches are against linux-next.

[V2]: Fix build issues found by kbuild test robot by adding static
keyword and proper symbol exports.

Jacob Siverskog (3):
  ASoC: pcm179x: Split into core and SPI parts
  ASoC: pcm179x: Add I2C interface driver
  ASoC: pcm179x: Support continuous rates

 .../devicetree/bindings/sound/pcm179x.txt          | 11 ++-
 sound/soc/codecs/Kconfig                           | 20 +++++-
 sound/soc/codecs/Makefile                          |  4 ++
 sound/soc/codecs/pcm179x-i2c.c                     | 82 ++++++++++++++++++++++
 sound/soc/codecs/pcm179x-spi.c                     | 81 +++++++++++++++++++++
 sound/soc/codecs/pcm179x.c                         | 66 +++--------------
 sound/soc/codecs/pcm179x.h                         | 14 +++-
 7 files changed, 217 insertions(+), 61 deletions(-)
 create mode 100644 sound/soc/codecs/pcm179x-i2c.c
 create mode 100644 sound/soc/codecs/pcm179x-spi.c

-- 
2.7.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] ASoC: pcm179x: Split into core and SPI parts
  2016-01-19 10:29 [PATCH v2 0/3] ASoC: pcm179x: Add I2C support, declare support for continuous rates Jacob Siverskog
@ 2016-01-19 10:29   ` Jacob Siverskog
  2016-01-19 10:29   ` Jacob Siverskog
  2016-01-19 10:29 ` [PATCH v2 3/3] ASoC: pcm179x: Support continuous rates Jacob Siverskog
  2 siblings, 0 replies; 11+ messages in thread
From: Jacob Siverskog @ 2016-01-19 10:29 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, Michael Trimarchi, Johan Hovold,
	alsa-devel, linux-kernel, Jacob Siverskog

The pcm179x family supports both SPI and I2C for configuration. This
patch splits the driver into core and SPI parts, in preparation for
I2C support.

Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
---
 sound/soc/codecs/Kconfig       | 11 ++++--
 sound/soc/codecs/Makefile      |  2 ++
 sound/soc/codecs/pcm179x-spi.c | 81 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/pcm179x.c     | 62 +++++---------------------------
 sound/soc/codecs/pcm179x.h     | 12 +++++++
 5 files changed, 112 insertions(+), 56 deletions(-)
 create mode 100644 sound/soc/codecs/pcm179x-spi.c

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 50693c8..eaf13cb 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -87,7 +87,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_ML26124 if I2C
 	select SND_SOC_NAU8825 if I2C
 	select SND_SOC_PCM1681 if I2C
-	select SND_SOC_PCM179X if SPI_MASTER
+	select SND_SOC_PCM179X_SPI if SPI_MASTER
 	select SND_SOC_PCM3008
 	select SND_SOC_PCM3168A_I2C if I2C
 	select SND_SOC_PCM3168A_SPI if SPI_MASTER
@@ -527,8 +527,15 @@ config SND_SOC_PCM1681
 	depends on I2C
 
 config SND_SOC_PCM179X
-	tristate "Texas Instruments PCM179X CODEC"
+	tristate
+
+config SND_SOC_PCM179X_SPI
+	tristate "Texas Instruments PCM179X CODEC family (SPI)"
 	depends on SPI_MASTER
+	select SND_SOC_PCM179X
+	help
+	  Enable support for Texas Instruments PCM179x CODEC family.
+	  Select this if your PCM179x is connected via an SPI bus.
 
 config SND_SOC_PCM3008
        tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index d44f7d3..56e94d8 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -81,6 +81,7 @@ snd-soc-ml26124-objs := ml26124.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-pcm1681-objs := pcm1681.o
 snd-soc-pcm179x-codec-objs := pcm179x.o
+snd-soc-pcm179x-spi-objs := pcm179x-spi.o
 snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-pcm3168a-objs := pcm3168a.o
 snd-soc-pcm3168a-i2c-objs := pcm3168a-i2c.o
@@ -285,6 +286,7 @@ obj-$(CONFIG_SND_SOC_ML26124)	+= snd-soc-ml26124.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
 obj-$(CONFIG_SND_SOC_PCM1681)	+= snd-soc-pcm1681.o
 obj-$(CONFIG_SND_SOC_PCM179X)	+= snd-soc-pcm179x-codec.o
+obj-$(CONFIG_SND_SOC_PCM179X_SPI)	+= snd-soc-pcm179x-spi.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_PCM3168A)	+= snd-soc-pcm3168a.o
 obj-$(CONFIG_SND_SOC_PCM3168A_I2C)	+= snd-soc-pcm3168a-i2c.o
diff --git a/sound/soc/codecs/pcm179x-spi.c b/sound/soc/codecs/pcm179x-spi.c
new file mode 100644
index 0000000..c883c4e
--- /dev/null
+++ b/sound/soc/codecs/pcm179x-spi.c
@@ -0,0 +1,81 @@
+/*
+ * PCM179X ASoC SPI driver
+ *
+ * Copyright (c) Amarula Solutions B.V. 2013
+ *
+ *     Michael Trimarchi <michael@amarulasolutions.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/spi/spi.h>
+#include <linux/regmap.h>
+
+#include "pcm179x.h"
+
+static int pcm179x_spi_probe(struct spi_device *spi)
+{
+	struct pcm179x_private *pcm179x;
+	int ret;
+
+	pcm179x = devm_kzalloc(&spi->dev, sizeof(struct pcm179x_private),
+				GFP_KERNEL);
+	if (!pcm179x)
+		return -ENOMEM;
+
+	spi_set_drvdata(spi, pcm179x);
+
+	pcm179x->dev = &spi->dev;
+
+	pcm179x->regmap = devm_regmap_init_spi(spi, &pcm179x_regmap_config);
+	if (IS_ERR(pcm179x->regmap)) {
+		ret = PTR_ERR(pcm179x->regmap);
+		dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
+		return ret;
+	}
+
+	return pcm179x_common_init(pcm179x);
+}
+
+static int pcm179x_spi_remove(struct spi_device *spi)
+{
+	return pcm179x_common_exit(spi_get_drvdata(spi));
+}
+
+static const struct of_device_id pcm179x_of_match[] = {
+	{ .compatible = "ti,pcm1792a", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, pcm179x_of_match);
+
+static const struct spi_device_id pcm179x_spi_ids[] = {
+	{ "pcm179x", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(spi, pcm179x_spi_ids);
+
+static struct spi_driver pcm179x_spi_driver = {
+	.driver = {
+		.name = "pcm179x",
+		.of_match_table = of_match_ptr(pcm179x_of_match),
+	},
+	.id_table = pcm179x_spi_ids,
+	.probe = pcm179x_spi_probe,
+	.remove = pcm179x_spi_remove,
+};
+
+module_spi_driver(pcm179x_spi_driver);
+
+MODULE_DESCRIPTION("ASoC PCM179X SPI driver");
+MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c
index a56c7b7..d35d2ae 100644
--- a/sound/soc/codecs/pcm179x.c
+++ b/sound/soc/codecs/pcm179x.c
@@ -20,7 +20,6 @@
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
-#include <linux/spi/spi.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -29,7 +28,6 @@
 #include <sound/soc.h>
 #include <sound/tlv.h>
 #include <linux/of.h>
-#include <linux/of_device.h>
 
 #include "pcm179x.h"
 
@@ -70,12 +68,6 @@ static bool pcm179x_writeable_reg(struct device *dev, unsigned register reg)
 	return accessible && reg != 0x16 && reg != 0x17;
 }
 
-struct pcm179x_private {
-	struct regmap *regmap;
-	unsigned int format;
-	unsigned int rate;
-};
-
 static int pcm179x_set_dai_fmt(struct snd_soc_dai *codec_dai,
                              unsigned int format)
 {
@@ -194,13 +186,7 @@ static struct snd_soc_dai_driver pcm179x_dai = {
 	.ops = &pcm179x_dai_ops,
 };
 
-static const struct of_device_id pcm179x_of_match[] = {
-	{ .compatible = "ti,pcm1792a", },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, pcm179x_of_match);
-
-static const struct regmap_config pcm179x_regmap = {
+const struct regmap_config pcm179x_regmap_config = {
 	.reg_bits		= 8,
 	.val_bits		= 8,
 	.max_register		= 23,
@@ -209,6 +195,7 @@ static const struct regmap_config pcm179x_regmap = {
 	.writeable_reg		= pcm179x_writeable_reg,
 	.readable_reg		= pcm179x_accessible_reg,
 };
+EXPORT_SYMBOL_GPL(pcm179x_regmap_config);
 
 static struct snd_soc_codec_driver soc_codec_dev_pcm179x = {
 	.controls		= pcm179x_controls,
@@ -219,52 +206,19 @@ static struct snd_soc_codec_driver soc_codec_dev_pcm179x = {
 	.num_dapm_routes	= ARRAY_SIZE(pcm179x_dapm_routes),
 };
 
-static int pcm179x_spi_probe(struct spi_device *spi)
+int pcm179x_common_init(struct pcm179x_private *priv)
 {
-	struct pcm179x_private *pcm179x;
-	int ret;
-
-	pcm179x = devm_kzalloc(&spi->dev, sizeof(struct pcm179x_private),
-				GFP_KERNEL);
-	if (!pcm179x)
-		return -ENOMEM;
-
-	spi_set_drvdata(spi, pcm179x);
-
-	pcm179x->regmap = devm_regmap_init_spi(spi, &pcm179x_regmap);
-	if (IS_ERR(pcm179x->regmap)) {
-		ret = PTR_ERR(pcm179x->regmap);
-		dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
-		return ret;
-	}
-
-	return snd_soc_register_codec(&spi->dev,
+	return snd_soc_register_codec(priv->dev,
 			&soc_codec_dev_pcm179x, &pcm179x_dai, 1);
 }
+EXPORT_SYMBOL_GPL(pcm179x_common_init);
 
-static int pcm179x_spi_remove(struct spi_device *spi)
+int pcm179x_common_exit(struct pcm179x_private *priv)
 {
-	snd_soc_unregister_codec(&spi->dev);
+	snd_soc_unregister_codec(priv->dev);
 	return 0;
 }
-
-static const struct spi_device_id pcm179x_spi_ids[] = {
-	{ "pcm179x", 0 },
-	{ },
-};
-MODULE_DEVICE_TABLE(spi, pcm179x_spi_ids);
-
-static struct spi_driver pcm179x_codec_driver = {
-	.driver = {
-		.name = "pcm179x",
-		.of_match_table = of_match_ptr(pcm179x_of_match),
-	},
-	.id_table = pcm179x_spi_ids,
-	.probe = pcm179x_spi_probe,
-	.remove = pcm179x_spi_remove,
-};
-
-module_spi_driver(pcm179x_codec_driver);
+EXPORT_SYMBOL_GPL(pcm179x_common_exit);
 
 MODULE_DESCRIPTION("ASoC PCM179X driver");
 MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
diff --git a/sound/soc/codecs/pcm179x.h b/sound/soc/codecs/pcm179x.h
index c6fdc06..d1536e0 100644
--- a/sound/soc/codecs/pcm179x.h
+++ b/sound/soc/codecs/pcm179x.h
@@ -17,6 +17,13 @@
 #ifndef __PCM179X_H__
 #define __PCM179X_H__
 
+struct pcm179x_private {
+	struct device *dev;
+	struct regmap *regmap;
+	unsigned int format;
+	unsigned int rate;
+};
+
 #define PCM1792A_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_8000_48000 | \
 			SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
 			SNDRV_PCM_RATE_192000)
@@ -24,4 +31,9 @@
 #define PCM1792A_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \
 			  SNDRV_PCM_FMTBIT_S16_LE)
 
+extern const struct regmap_config pcm179x_regmap_config;
+
+int pcm179x_common_init(struct pcm179x_private *priv);
+int pcm179x_common_exit(struct pcm179x_private *priv);
+
 #endif
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] ASoC: pcm179x: Split into core and SPI parts
@ 2016-01-19 10:29   ` Jacob Siverskog
  0 siblings, 0 replies; 11+ messages in thread
From: Jacob Siverskog @ 2016-01-19 10:29 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: alsa-devel, Takashi Iwai, linux-kernel, Johan Hovold,
	Jacob Siverskog, Michael Trimarchi

The pcm179x family supports both SPI and I2C for configuration. This
patch splits the driver into core and SPI parts, in preparation for
I2C support.

Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
---
 sound/soc/codecs/Kconfig       | 11 ++++--
 sound/soc/codecs/Makefile      |  2 ++
 sound/soc/codecs/pcm179x-spi.c | 81 ++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/pcm179x.c     | 62 +++++---------------------------
 sound/soc/codecs/pcm179x.h     | 12 +++++++
 5 files changed, 112 insertions(+), 56 deletions(-)
 create mode 100644 sound/soc/codecs/pcm179x-spi.c

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 50693c8..eaf13cb 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -87,7 +87,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_ML26124 if I2C
 	select SND_SOC_NAU8825 if I2C
 	select SND_SOC_PCM1681 if I2C
-	select SND_SOC_PCM179X if SPI_MASTER
+	select SND_SOC_PCM179X_SPI if SPI_MASTER
 	select SND_SOC_PCM3008
 	select SND_SOC_PCM3168A_I2C if I2C
 	select SND_SOC_PCM3168A_SPI if SPI_MASTER
@@ -527,8 +527,15 @@ config SND_SOC_PCM1681
 	depends on I2C
 
 config SND_SOC_PCM179X
-	tristate "Texas Instruments PCM179X CODEC"
+	tristate
+
+config SND_SOC_PCM179X_SPI
+	tristate "Texas Instruments PCM179X CODEC family (SPI)"
 	depends on SPI_MASTER
+	select SND_SOC_PCM179X
+	help
+	  Enable support for Texas Instruments PCM179x CODEC family.
+	  Select this if your PCM179x is connected via an SPI bus.
 
 config SND_SOC_PCM3008
        tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index d44f7d3..56e94d8 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -81,6 +81,7 @@ snd-soc-ml26124-objs := ml26124.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-pcm1681-objs := pcm1681.o
 snd-soc-pcm179x-codec-objs := pcm179x.o
+snd-soc-pcm179x-spi-objs := pcm179x-spi.o
 snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-pcm3168a-objs := pcm3168a.o
 snd-soc-pcm3168a-i2c-objs := pcm3168a-i2c.o
@@ -285,6 +286,7 @@ obj-$(CONFIG_SND_SOC_ML26124)	+= snd-soc-ml26124.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
 obj-$(CONFIG_SND_SOC_PCM1681)	+= snd-soc-pcm1681.o
 obj-$(CONFIG_SND_SOC_PCM179X)	+= snd-soc-pcm179x-codec.o
+obj-$(CONFIG_SND_SOC_PCM179X_SPI)	+= snd-soc-pcm179x-spi.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_PCM3168A)	+= snd-soc-pcm3168a.o
 obj-$(CONFIG_SND_SOC_PCM3168A_I2C)	+= snd-soc-pcm3168a-i2c.o
diff --git a/sound/soc/codecs/pcm179x-spi.c b/sound/soc/codecs/pcm179x-spi.c
new file mode 100644
index 0000000..c883c4e
--- /dev/null
+++ b/sound/soc/codecs/pcm179x-spi.c
@@ -0,0 +1,81 @@
+/*
+ * PCM179X ASoC SPI driver
+ *
+ * Copyright (c) Amarula Solutions B.V. 2013
+ *
+ *     Michael Trimarchi <michael@amarulasolutions.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/spi/spi.h>
+#include <linux/regmap.h>
+
+#include "pcm179x.h"
+
+static int pcm179x_spi_probe(struct spi_device *spi)
+{
+	struct pcm179x_private *pcm179x;
+	int ret;
+
+	pcm179x = devm_kzalloc(&spi->dev, sizeof(struct pcm179x_private),
+				GFP_KERNEL);
+	if (!pcm179x)
+		return -ENOMEM;
+
+	spi_set_drvdata(spi, pcm179x);
+
+	pcm179x->dev = &spi->dev;
+
+	pcm179x->regmap = devm_regmap_init_spi(spi, &pcm179x_regmap_config);
+	if (IS_ERR(pcm179x->regmap)) {
+		ret = PTR_ERR(pcm179x->regmap);
+		dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
+		return ret;
+	}
+
+	return pcm179x_common_init(pcm179x);
+}
+
+static int pcm179x_spi_remove(struct spi_device *spi)
+{
+	return pcm179x_common_exit(spi_get_drvdata(spi));
+}
+
+static const struct of_device_id pcm179x_of_match[] = {
+	{ .compatible = "ti,pcm1792a", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, pcm179x_of_match);
+
+static const struct spi_device_id pcm179x_spi_ids[] = {
+	{ "pcm179x", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(spi, pcm179x_spi_ids);
+
+static struct spi_driver pcm179x_spi_driver = {
+	.driver = {
+		.name = "pcm179x",
+		.of_match_table = of_match_ptr(pcm179x_of_match),
+	},
+	.id_table = pcm179x_spi_ids,
+	.probe = pcm179x_spi_probe,
+	.remove = pcm179x_spi_remove,
+};
+
+module_spi_driver(pcm179x_spi_driver);
+
+MODULE_DESCRIPTION("ASoC PCM179X SPI driver");
+MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c
index a56c7b7..d35d2ae 100644
--- a/sound/soc/codecs/pcm179x.c
+++ b/sound/soc/codecs/pcm179x.c
@@ -20,7 +20,6 @@
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
-#include <linux/spi/spi.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -29,7 +28,6 @@
 #include <sound/soc.h>
 #include <sound/tlv.h>
 #include <linux/of.h>
-#include <linux/of_device.h>
 
 #include "pcm179x.h"
 
@@ -70,12 +68,6 @@ static bool pcm179x_writeable_reg(struct device *dev, unsigned register reg)
 	return accessible && reg != 0x16 && reg != 0x17;
 }
 
-struct pcm179x_private {
-	struct regmap *regmap;
-	unsigned int format;
-	unsigned int rate;
-};
-
 static int pcm179x_set_dai_fmt(struct snd_soc_dai *codec_dai,
                              unsigned int format)
 {
@@ -194,13 +186,7 @@ static struct snd_soc_dai_driver pcm179x_dai = {
 	.ops = &pcm179x_dai_ops,
 };
 
-static const struct of_device_id pcm179x_of_match[] = {
-	{ .compatible = "ti,pcm1792a", },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, pcm179x_of_match);
-
-static const struct regmap_config pcm179x_regmap = {
+const struct regmap_config pcm179x_regmap_config = {
 	.reg_bits		= 8,
 	.val_bits		= 8,
 	.max_register		= 23,
@@ -209,6 +195,7 @@ static const struct regmap_config pcm179x_regmap = {
 	.writeable_reg		= pcm179x_writeable_reg,
 	.readable_reg		= pcm179x_accessible_reg,
 };
+EXPORT_SYMBOL_GPL(pcm179x_regmap_config);
 
 static struct snd_soc_codec_driver soc_codec_dev_pcm179x = {
 	.controls		= pcm179x_controls,
@@ -219,52 +206,19 @@ static struct snd_soc_codec_driver soc_codec_dev_pcm179x = {
 	.num_dapm_routes	= ARRAY_SIZE(pcm179x_dapm_routes),
 };
 
-static int pcm179x_spi_probe(struct spi_device *spi)
+int pcm179x_common_init(struct pcm179x_private *priv)
 {
-	struct pcm179x_private *pcm179x;
-	int ret;
-
-	pcm179x = devm_kzalloc(&spi->dev, sizeof(struct pcm179x_private),
-				GFP_KERNEL);
-	if (!pcm179x)
-		return -ENOMEM;
-
-	spi_set_drvdata(spi, pcm179x);
-
-	pcm179x->regmap = devm_regmap_init_spi(spi, &pcm179x_regmap);
-	if (IS_ERR(pcm179x->regmap)) {
-		ret = PTR_ERR(pcm179x->regmap);
-		dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
-		return ret;
-	}
-
-	return snd_soc_register_codec(&spi->dev,
+	return snd_soc_register_codec(priv->dev,
 			&soc_codec_dev_pcm179x, &pcm179x_dai, 1);
 }
+EXPORT_SYMBOL_GPL(pcm179x_common_init);
 
-static int pcm179x_spi_remove(struct spi_device *spi)
+int pcm179x_common_exit(struct pcm179x_private *priv)
 {
-	snd_soc_unregister_codec(&spi->dev);
+	snd_soc_unregister_codec(priv->dev);
 	return 0;
 }
-
-static const struct spi_device_id pcm179x_spi_ids[] = {
-	{ "pcm179x", 0 },
-	{ },
-};
-MODULE_DEVICE_TABLE(spi, pcm179x_spi_ids);
-
-static struct spi_driver pcm179x_codec_driver = {
-	.driver = {
-		.name = "pcm179x",
-		.of_match_table = of_match_ptr(pcm179x_of_match),
-	},
-	.id_table = pcm179x_spi_ids,
-	.probe = pcm179x_spi_probe,
-	.remove = pcm179x_spi_remove,
-};
-
-module_spi_driver(pcm179x_codec_driver);
+EXPORT_SYMBOL_GPL(pcm179x_common_exit);
 
 MODULE_DESCRIPTION("ASoC PCM179X driver");
 MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
diff --git a/sound/soc/codecs/pcm179x.h b/sound/soc/codecs/pcm179x.h
index c6fdc06..d1536e0 100644
--- a/sound/soc/codecs/pcm179x.h
+++ b/sound/soc/codecs/pcm179x.h
@@ -17,6 +17,13 @@
 #ifndef __PCM179X_H__
 #define __PCM179X_H__
 
+struct pcm179x_private {
+	struct device *dev;
+	struct regmap *regmap;
+	unsigned int format;
+	unsigned int rate;
+};
+
 #define PCM1792A_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_8000_48000 | \
 			SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
 			SNDRV_PCM_RATE_192000)
@@ -24,4 +31,9 @@
 #define PCM1792A_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \
 			  SNDRV_PCM_FMTBIT_S16_LE)
 
+extern const struct regmap_config pcm179x_regmap_config;
+
+int pcm179x_common_init(struct pcm179x_private *priv);
+int pcm179x_common_exit(struct pcm179x_private *priv);
+
 #endif
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
  2016-01-19 10:29 [PATCH v2 0/3] ASoC: pcm179x: Add I2C support, declare support for continuous rates Jacob Siverskog
@ 2016-01-19 10:29   ` Jacob Siverskog
  2016-01-19 10:29   ` Jacob Siverskog
  2016-01-19 10:29 ` [PATCH v2 3/3] ASoC: pcm179x: Support continuous rates Jacob Siverskog
  2 siblings, 0 replies; 11+ messages in thread
From: Jacob Siverskog @ 2016-01-19 10:29 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, Michael Trimarchi, Johan Hovold,
	alsa-devel, linux-kernel, Jacob Siverskog

The PCM179x family supports both SPI and I2C. This patch adds support
for the I2C interface.

Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
---
 .../devicetree/bindings/sound/pcm179x.txt          | 11 ++-
 sound/soc/codecs/Kconfig                           |  9 +++
 sound/soc/codecs/Makefile                          |  2 +
 sound/soc/codecs/pcm179x-i2c.c                     | 82 ++++++++++++++++++++++
 4 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/codecs/pcm179x-i2c.c

diff --git a/Documentation/devicetree/bindings/sound/pcm179x.txt b/Documentation/devicetree/bindings/sound/pcm179x.txt
index 4ae70d3..436c2b2 100644
--- a/Documentation/devicetree/bindings/sound/pcm179x.txt
+++ b/Documentation/devicetree/bindings/sound/pcm179x.txt
@@ -1,6 +1,6 @@
 Texas Instruments pcm179x DT bindings
 
-This driver supports the SPI bus.
+This driver supports both the I2C and SPI bus.
 
 Required properties:
 
@@ -9,6 +9,11 @@ Required properties:
 For required properties on SPI, please consult
 Documentation/devicetree/bindings/spi/spi-bus.txt
 
+Required properties on I2C:
+
+ - reg: the I2C address
+
+
 Examples:
 
 	codec_spi: 1792a@0 {
@@ -16,3 +21,7 @@ Examples:
 		spi-max-frequency = <600000>;
 	};
 
+	codec_i2c: 1792a@4c {
+		compatible = "ti,pcm1792a";
+		reg = <0x4c>;
+	};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index eaf13cb..45269cc 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -87,6 +87,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_ML26124 if I2C
 	select SND_SOC_NAU8825 if I2C
 	select SND_SOC_PCM1681 if I2C
+	select SND_SOC_PCM179X_I2C if I2C
 	select SND_SOC_PCM179X_SPI if SPI_MASTER
 	select SND_SOC_PCM3008
 	select SND_SOC_PCM3168A_I2C if I2C
@@ -529,6 +530,14 @@ config SND_SOC_PCM1681
 config SND_SOC_PCM179X
 	tristate
 
+config SND_SOC_PCM179X_I2C
+	tristate "Texas Instruments PCM179X CODEC family (I2C)"
+	depends on I2C
+	select SND_SOC_PCM179X
+	help
+	  Enable support for Texas Instruments PCM179x CODEC family.
+	  Select this if your PCM179x is connected via an I2C bus.
+
 config SND_SOC_PCM179X_SPI
 	tristate "Texas Instruments PCM179X CODEC family (SPI)"
 	depends on SPI_MASTER
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 56e94d8..9acd777 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -81,6 +81,7 @@ snd-soc-ml26124-objs := ml26124.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-pcm1681-objs := pcm1681.o
 snd-soc-pcm179x-codec-objs := pcm179x.o
+snd-soc-pcm179x-i2c-objs := pcm179x-i2c.o
 snd-soc-pcm179x-spi-objs := pcm179x-spi.o
 snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-pcm3168a-objs := pcm3168a.o
@@ -286,6 +287,7 @@ obj-$(CONFIG_SND_SOC_ML26124)	+= snd-soc-ml26124.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
 obj-$(CONFIG_SND_SOC_PCM1681)	+= snd-soc-pcm1681.o
 obj-$(CONFIG_SND_SOC_PCM179X)	+= snd-soc-pcm179x-codec.o
+obj-$(CONFIG_SND_SOC_PCM179X_I2C)	+= snd-soc-pcm179x-i2c.o
 obj-$(CONFIG_SND_SOC_PCM179X_SPI)	+= snd-soc-pcm179x-spi.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_PCM3168A)	+= snd-soc-pcm3168a.o
diff --git a/sound/soc/codecs/pcm179x-i2c.c b/sound/soc/codecs/pcm179x-i2c.c
new file mode 100644
index 0000000..5a5d61a
--- /dev/null
+++ b/sound/soc/codecs/pcm179x-i2c.c
@@ -0,0 +1,82 @@
+/*
+ * PCM179X ASoC I2C driver
+ *
+ * Copyright (c) Teenage Engineering AB 2016
+ *
+ *     Jacob Siverskog <jacob@teenage.engineering>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+
+#include "pcm179x.h"
+
+static int pcm179x_i2c_probe(struct i2c_client *client,
+			      const struct i2c_device_id *id)
+{
+	struct pcm179x_private *pcm179x;
+	int ret;
+
+	pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
+				GFP_KERNEL);
+	if (!pcm179x)
+		return -ENOMEM;
+
+	i2c_set_clientdata(client, pcm179x);
+
+	pcm179x->dev = &client->dev;
+
+	pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
+	if (IS_ERR(pcm179x->regmap)) {
+		ret = PTR_ERR(pcm179x->regmap);
+		dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
+		return ret;
+	}
+
+	return pcm179x_common_init(pcm179x);
+}
+
+static int pcm179x_i2c_remove(struct i2c_client *client)
+{
+	return pcm179x_common_exit(i2c_get_clientdata(client));
+}
+
+static const struct of_device_id pcm179x_of_match[] = {
+	{ .compatible = "ti,pcm1792a", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, pcm179x_of_match);
+
+static const struct i2c_device_id pcm179x_i2c_ids[] = {
+	{ "pcm179x", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, pcm179x_i2c_ids);
+
+static struct i2c_driver pcm179x_i2c_driver = {
+	.driver = {
+		.name	= "pcm179x",
+		.of_match_table = of_match_ptr(pcm179x_of_match),
+	},
+	.id_table	= pcm179x_i2c_ids,
+	.probe		= pcm179x_i2c_probe,
+	.remove		= pcm179x_i2c_remove,
+};
+
+module_i2c_driver(pcm179x_i2c_driver);
+
+MODULE_DESCRIPTION("ASoC PCM179X I2C driver");
+MODULE_AUTHOR("Jacob Siverskog <jacob@teenage.engineering>");
+MODULE_LICENSE("GPL");
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
@ 2016-01-19 10:29   ` Jacob Siverskog
  0 siblings, 0 replies; 11+ messages in thread
From: Jacob Siverskog @ 2016-01-19 10:29 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: alsa-devel, Takashi Iwai, linux-kernel, Johan Hovold,
	Jacob Siverskog, Michael Trimarchi

The PCM179x family supports both SPI and I2C. This patch adds support
for the I2C interface.

Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
---
 .../devicetree/bindings/sound/pcm179x.txt          | 11 ++-
 sound/soc/codecs/Kconfig                           |  9 +++
 sound/soc/codecs/Makefile                          |  2 +
 sound/soc/codecs/pcm179x-i2c.c                     | 82 ++++++++++++++++++++++
 4 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/codecs/pcm179x-i2c.c

diff --git a/Documentation/devicetree/bindings/sound/pcm179x.txt b/Documentation/devicetree/bindings/sound/pcm179x.txt
index 4ae70d3..436c2b2 100644
--- a/Documentation/devicetree/bindings/sound/pcm179x.txt
+++ b/Documentation/devicetree/bindings/sound/pcm179x.txt
@@ -1,6 +1,6 @@
 Texas Instruments pcm179x DT bindings
 
-This driver supports the SPI bus.
+This driver supports both the I2C and SPI bus.
 
 Required properties:
 
@@ -9,6 +9,11 @@ Required properties:
 For required properties on SPI, please consult
 Documentation/devicetree/bindings/spi/spi-bus.txt
 
+Required properties on I2C:
+
+ - reg: the I2C address
+
+
 Examples:
 
 	codec_spi: 1792a@0 {
@@ -16,3 +21,7 @@ Examples:
 		spi-max-frequency = <600000>;
 	};
 
+	codec_i2c: 1792a@4c {
+		compatible = "ti,pcm1792a";
+		reg = <0x4c>;
+	};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index eaf13cb..45269cc 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -87,6 +87,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_ML26124 if I2C
 	select SND_SOC_NAU8825 if I2C
 	select SND_SOC_PCM1681 if I2C
+	select SND_SOC_PCM179X_I2C if I2C
 	select SND_SOC_PCM179X_SPI if SPI_MASTER
 	select SND_SOC_PCM3008
 	select SND_SOC_PCM3168A_I2C if I2C
@@ -529,6 +530,14 @@ config SND_SOC_PCM1681
 config SND_SOC_PCM179X
 	tristate
 
+config SND_SOC_PCM179X_I2C
+	tristate "Texas Instruments PCM179X CODEC family (I2C)"
+	depends on I2C
+	select SND_SOC_PCM179X
+	help
+	  Enable support for Texas Instruments PCM179x CODEC family.
+	  Select this if your PCM179x is connected via an I2C bus.
+
 config SND_SOC_PCM179X_SPI
 	tristate "Texas Instruments PCM179X CODEC family (SPI)"
 	depends on SPI_MASTER
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 56e94d8..9acd777 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -81,6 +81,7 @@ snd-soc-ml26124-objs := ml26124.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-pcm1681-objs := pcm1681.o
 snd-soc-pcm179x-codec-objs := pcm179x.o
+snd-soc-pcm179x-i2c-objs := pcm179x-i2c.o
 snd-soc-pcm179x-spi-objs := pcm179x-spi.o
 snd-soc-pcm3008-objs := pcm3008.o
 snd-soc-pcm3168a-objs := pcm3168a.o
@@ -286,6 +287,7 @@ obj-$(CONFIG_SND_SOC_ML26124)	+= snd-soc-ml26124.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
 obj-$(CONFIG_SND_SOC_PCM1681)	+= snd-soc-pcm1681.o
 obj-$(CONFIG_SND_SOC_PCM179X)	+= snd-soc-pcm179x-codec.o
+obj-$(CONFIG_SND_SOC_PCM179X_I2C)	+= snd-soc-pcm179x-i2c.o
 obj-$(CONFIG_SND_SOC_PCM179X_SPI)	+= snd-soc-pcm179x-spi.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
 obj-$(CONFIG_SND_SOC_PCM3168A)	+= snd-soc-pcm3168a.o
diff --git a/sound/soc/codecs/pcm179x-i2c.c b/sound/soc/codecs/pcm179x-i2c.c
new file mode 100644
index 0000000..5a5d61a
--- /dev/null
+++ b/sound/soc/codecs/pcm179x-i2c.c
@@ -0,0 +1,82 @@
+/*
+ * PCM179X ASoC I2C driver
+ *
+ * Copyright (c) Teenage Engineering AB 2016
+ *
+ *     Jacob Siverskog <jacob@teenage.engineering>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+
+#include "pcm179x.h"
+
+static int pcm179x_i2c_probe(struct i2c_client *client,
+			      const struct i2c_device_id *id)
+{
+	struct pcm179x_private *pcm179x;
+	int ret;
+
+	pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
+				GFP_KERNEL);
+	if (!pcm179x)
+		return -ENOMEM;
+
+	i2c_set_clientdata(client, pcm179x);
+
+	pcm179x->dev = &client->dev;
+
+	pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
+	if (IS_ERR(pcm179x->regmap)) {
+		ret = PTR_ERR(pcm179x->regmap);
+		dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
+		return ret;
+	}
+
+	return pcm179x_common_init(pcm179x);
+}
+
+static int pcm179x_i2c_remove(struct i2c_client *client)
+{
+	return pcm179x_common_exit(i2c_get_clientdata(client));
+}
+
+static const struct of_device_id pcm179x_of_match[] = {
+	{ .compatible = "ti,pcm1792a", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, pcm179x_of_match);
+
+static const struct i2c_device_id pcm179x_i2c_ids[] = {
+	{ "pcm179x", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, pcm179x_i2c_ids);
+
+static struct i2c_driver pcm179x_i2c_driver = {
+	.driver = {
+		.name	= "pcm179x",
+		.of_match_table = of_match_ptr(pcm179x_of_match),
+	},
+	.id_table	= pcm179x_i2c_ids,
+	.probe		= pcm179x_i2c_probe,
+	.remove		= pcm179x_i2c_remove,
+};
+
+module_i2c_driver(pcm179x_i2c_driver);
+
+MODULE_DESCRIPTION("ASoC PCM179X I2C driver");
+MODULE_AUTHOR("Jacob Siverskog <jacob@teenage.engineering>");
+MODULE_LICENSE("GPL");
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/3] ASoC: pcm179x: Support continuous rates
  2016-01-19 10:29 [PATCH v2 0/3] ASoC: pcm179x: Add I2C support, declare support for continuous rates Jacob Siverskog
  2016-01-19 10:29   ` Jacob Siverskog
  2016-01-19 10:29   ` Jacob Siverskog
@ 2016-01-19 10:29 ` Jacob Siverskog
  2 siblings, 0 replies; 11+ messages in thread
From: Jacob Siverskog @ 2016-01-19 10:29 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, Michael Trimarchi, Johan Hovold,
	alsa-devel, linux-kernel, Jacob Siverskog

According to the PCM179x data sheets sampling frequencies between 10
kHz and 200 kHz are supported. Specify support in the driver.

Tested with PCM1791A.

References:
http://www.ti.com/lit/ds/symlink/pcm1791a.pdf
http://www.ti.com/lit/ds/symlink/pcm1792a.pdf
http://www.ti.com/lit/ds/symlink/pcm1795.pdf
http://www.ti.com/lit/ds/symlink/pcm1796.pdf

Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
---
 sound/soc/codecs/pcm179x.c | 4 +++-
 sound/soc/codecs/pcm179x.h | 4 ----
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c
index d35d2ae..6e40be2 100644
--- a/sound/soc/codecs/pcm179x.c
+++ b/sound/soc/codecs/pcm179x.c
@@ -181,7 +181,9 @@ static struct snd_soc_dai_driver pcm179x_dai = {
 		.stream_name = "Playback",
 		.channels_min = 2,
 		.channels_max = 2,
-		.rates = PCM1792A_RATES,
+		.rates = SNDRV_PCM_RATE_CONTINUOUS,
+		.rate_min = 10000,
+		.rate_max = 200000,
 		.formats = PCM1792A_FORMATS, },
 	.ops = &pcm179x_dai_ops,
 };
diff --git a/sound/soc/codecs/pcm179x.h b/sound/soc/codecs/pcm179x.h
index d1536e0..7829157 100644
--- a/sound/soc/codecs/pcm179x.h
+++ b/sound/soc/codecs/pcm179x.h
@@ -24,10 +24,6 @@ struct pcm179x_private {
 	unsigned int rate;
 };
 
-#define PCM1792A_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_8000_48000 | \
-			SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
-			SNDRV_PCM_RATE_192000)
-
 #define PCM1792A_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \
 			  SNDRV_PCM_FMTBIT_S16_LE)
 
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
  2016-01-19 10:29   ` Jacob Siverskog
  (?)
@ 2016-01-19 10:50   ` Michael Trimarchi
  2016-01-19 13:51     ` Johan Hovold
  -1 siblings, 1 reply; 11+ messages in thread
From: Michael Trimarchi @ 2016-01-19 10:50 UTC (permalink / raw)
  To: Jacob Siverskog
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Johan Hovold, alsa-devel, LKML

Hi Jacob

On Tue, Jan 19, 2016 at 11:29 AM, Jacob Siverskog
<jacob@teenage.engineering> wrote:
> The PCM179x family supports both SPI and I2C. This patch adds support
> for the I2C interface.
>
> Reviewed-by: Johan Hovold <johan@kernel.org>
> Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
> ---
>  .../devicetree/bindings/sound/pcm179x.txt          | 11 ++-
>  sound/soc/codecs/Kconfig                           |  9 +++
>  sound/soc/codecs/Makefile                          |  2 +
>  sound/soc/codecs/pcm179x-i2c.c                     | 82 ++++++++++++++++++++++
>  4 files changed, 103 insertions(+), 1 deletion(-)
>  create mode 100644 sound/soc/codecs/pcm179x-i2c.c
>
> diff --git a/Documentation/devicetree/bindings/sound/pcm179x.txt b/Documentation/devicetree/bindings/sound/pcm179x.txt
> index 4ae70d3..436c2b2 100644
> --- a/Documentation/devicetree/bindings/sound/pcm179x.txt
> +++ b/Documentation/devicetree/bindings/sound/pcm179x.txt
> @@ -1,6 +1,6 @@
>  Texas Instruments pcm179x DT bindings
>
> -This driver supports the SPI bus.
> +This driver supports both the I2C and SPI bus.
>
>  Required properties:
>
> @@ -9,6 +9,11 @@ Required properties:
>  For required properties on SPI, please consult
>  Documentation/devicetree/bindings/spi/spi-bus.txt
>
> +Required properties on I2C:
> +
> + - reg: the I2C address
> +
> +
>  Examples:
>
>         codec_spi: 1792a@0 {
> @@ -16,3 +21,7 @@ Examples:
>                 spi-max-frequency = <600000>;
>         };
>
> +       codec_i2c: 1792a@4c {
> +               compatible = "ti,pcm1792a";
> +               reg = <0x4c>;
> +       };
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index eaf13cb..45269cc 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -87,6 +87,7 @@ config SND_SOC_ALL_CODECS
>         select SND_SOC_ML26124 if I2C
>         select SND_SOC_NAU8825 if I2C
>         select SND_SOC_PCM1681 if I2C
> +       select SND_SOC_PCM179X_I2C if I2C
>         select SND_SOC_PCM179X_SPI if SPI_MASTER
>         select SND_SOC_PCM3008
>         select SND_SOC_PCM3168A_I2C if I2C
> @@ -529,6 +530,14 @@ config SND_SOC_PCM1681
>  config SND_SOC_PCM179X
>         tristate
>
> +config SND_SOC_PCM179X_I2C
> +       tristate "Texas Instruments PCM179X CODEC family (I2C)"
> +       depends on I2C
> +       select SND_SOC_PCM179X
> +       help
> +         Enable support for Texas Instruments PCM179x CODEC family.
> +         Select this if your PCM179x is connected via an I2C bus.
> +
>  config SND_SOC_PCM179X_SPI
>         tristate "Texas Instruments PCM179X CODEC family (SPI)"
>         depends on SPI_MASTER
> diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
> index 56e94d8..9acd777 100644
> --- a/sound/soc/codecs/Makefile
> +++ b/sound/soc/codecs/Makefile
> @@ -81,6 +81,7 @@ snd-soc-ml26124-objs := ml26124.o
>  snd-soc-nau8825-objs := nau8825.o
>  snd-soc-pcm1681-objs := pcm1681.o
>  snd-soc-pcm179x-codec-objs := pcm179x.o
> +snd-soc-pcm179x-i2c-objs := pcm179x-i2c.o
>  snd-soc-pcm179x-spi-objs := pcm179x-spi.o
>  snd-soc-pcm3008-objs := pcm3008.o
>  snd-soc-pcm3168a-objs := pcm3168a.o
> @@ -286,6 +287,7 @@ obj-$(CONFIG_SND_SOC_ML26124)       += snd-soc-ml26124.o
>  obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
>  obj-$(CONFIG_SND_SOC_PCM1681)  += snd-soc-pcm1681.o
>  obj-$(CONFIG_SND_SOC_PCM179X)  += snd-soc-pcm179x-codec.o
> +obj-$(CONFIG_SND_SOC_PCM179X_I2C)      += snd-soc-pcm179x-i2c.o
>  obj-$(CONFIG_SND_SOC_PCM179X_SPI)      += snd-soc-pcm179x-spi.o
>  obj-$(CONFIG_SND_SOC_PCM3008)  += snd-soc-pcm3008.o
>  obj-$(CONFIG_SND_SOC_PCM3168A) += snd-soc-pcm3168a.o
> diff --git a/sound/soc/codecs/pcm179x-i2c.c b/sound/soc/codecs/pcm179x-i2c.c
> new file mode 100644
> index 0000000..5a5d61a
> --- /dev/null
> +++ b/sound/soc/codecs/pcm179x-i2c.c
> @@ -0,0 +1,82 @@
> +/*
> + * PCM179X ASoC I2C driver
> + *
> + * Copyright (c) Teenage Engineering AB 2016
> + *
> + *     Jacob Siverskog <jacob@teenage.engineering>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/i2c.h>
> +#include <linux/regmap.h>
> +
> +#include "pcm179x.h"
> +
> +static int pcm179x_i2c_probe(struct i2c_client *client,
> +                             const struct i2c_device_id *id)
> +{
> +       struct pcm179x_private *pcm179x;
> +       int ret;
> +
> +       pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
> +                               GFP_KERNEL);
> +       if (!pcm179x)
> +               return -ENOMEM;
> +
> +       i2c_set_clientdata(client, pcm179x);
> +
> +       pcm179x->dev = &client->dev;
> +
> +       pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
> +       if (IS_ERR(pcm179x->regmap)) {
> +               ret = PTR_ERR(pcm179x->regmap);
> +               dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
> +               return ret;
> +       }
> +

sound/soc/codecs/adau1781-spi.c

I like more how was done here for private data and codec data. What do
you think?

Michael

> +       return pcm179x_common_init(pcm179x);
> +}
> +
> +static int pcm179x_i2c_remove(struct i2c_client *client)
> +{
> +       return pcm179x_common_exit(i2c_get_clientdata(client));
> +}
> +
> +static const struct of_device_id pcm179x_of_match[] = {
> +       { .compatible = "ti,pcm1792a", },
> +       { }
> +};
> +MODULE_DEVICE_TABLE(of, pcm179x_of_match);
> +
> +static const struct i2c_device_id pcm179x_i2c_ids[] = {
> +       { "pcm179x", 0 },
> +       { }
> +};
> +MODULE_DEVICE_TABLE(i2c, pcm179x_i2c_ids);
> +
> +static struct i2c_driver pcm179x_i2c_driver = {
> +       .driver = {
> +               .name   = "pcm179x",
> +               .of_match_table = of_match_ptr(pcm179x_of_match),
> +       },
> +       .id_table       = pcm179x_i2c_ids,
> +       .probe          = pcm179x_i2c_probe,
> +       .remove         = pcm179x_i2c_remove,
> +};
> +
> +module_i2c_driver(pcm179x_i2c_driver);
> +
> +MODULE_DESCRIPTION("ASoC PCM179X I2C driver");
> +MODULE_AUTHOR("Jacob Siverskog <jacob@teenage.engineering>");
> +MODULE_LICENSE("GPL");
> --
> 2.7.0
>



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
  2016-01-19 10:50   ` Michael Trimarchi
@ 2016-01-19 13:51     ` Johan Hovold
  2016-01-20  4:58         ` Michael Trimarchi
  0 siblings, 1 reply; 11+ messages in thread
From: Johan Hovold @ 2016-01-19 13:51 UTC (permalink / raw)
  To: Michael Trimarchi
  Cc: Jacob Siverskog, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Johan Hovold, alsa-devel, LKML

On Tue, Jan 19, 2016 at 11:50:35AM +0100, Michael Trimarchi wrote:
> Hi Jacob
> 
> On Tue, Jan 19, 2016 at 11:29 AM, Jacob Siverskog
> <jacob@teenage.engineering> wrote:
> > The PCM179x family supports both SPI and I2C. This patch adds support
> > for the I2C interface.
> >
> > Reviewed-by: Johan Hovold <johan@kernel.org>
> > Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
> > ---

> > +static int pcm179x_i2c_probe(struct i2c_client *client,
> > +                             const struct i2c_device_id *id)
> > +{
> > +       struct pcm179x_private *pcm179x;
> > +       int ret;
> > +
> > +       pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
> > +                               GFP_KERNEL);
> > +       if (!pcm179x)
> > +               return -ENOMEM;
> > +
> > +       i2c_set_clientdata(client, pcm179x);
> > +
> > +       pcm179x->dev = &client->dev;
> > +
> > +       pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
> > +       if (IS_ERR(pcm179x->regmap)) {
> > +               ret = PTR_ERR(pcm179x->regmap);
> > +               dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
> > +               return ret;
> > +       }
> > +
> 
> sound/soc/codecs/adau1781-spi.c
> 
> I like more how was done here for private data and codec data. What do
> you think?

Why do you prefer that?

Having a common_exit() to clean up whatever was done in common_init()
seems like a better design than open-coding this in both of the i2c and
spi drivers (if that's what you were referring to).

> > +       return pcm179x_common_init(pcm179x);
> > +}
> > +
> > +static int pcm179x_i2c_remove(struct i2c_client *client)
> > +{
> > +       return pcm179x_common_exit(i2c_get_clientdata(client));
> > +}

Thanks,
Johan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
  2016-01-19 13:51     ` Johan Hovold
@ 2016-01-20  4:58         ` Michael Trimarchi
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Trimarchi @ 2016-01-20  4:58 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Jacob Siverskog, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, alsa-devel, LKML

Hi

On Tue, Jan 19, 2016 at 2:51 PM, Johan Hovold <johan@kernel.org> wrote:
> On Tue, Jan 19, 2016 at 11:50:35AM +0100, Michael Trimarchi wrote:
>> Hi Jacob
>>
>> On Tue, Jan 19, 2016 at 11:29 AM, Jacob Siverskog
>> <jacob@teenage.engineering> wrote:
>> > The PCM179x family supports both SPI and I2C. This patch adds support
>> > for the I2C interface.
>> >
>> > Reviewed-by: Johan Hovold <johan@kernel.org>
>> > Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
>> > ---
>
>> > +static int pcm179x_i2c_probe(struct i2c_client *client,
>> > +                             const struct i2c_device_id *id)
>> > +{
>> > +       struct pcm179x_private *pcm179x;
>> > +       int ret;
>> > +
>> > +       pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
>> > +                               GFP_KERNEL);
>> > +       if (!pcm179x)
>> > +               return -ENOMEM;
>> > +
>> > +       i2c_set_clientdata(client, pcm179x);
>> > +
>> > +       pcm179x->dev = &client->dev;
>> > +
>> > +       pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
>> > +       if (IS_ERR(pcm179x->regmap)) {
>> > +               ret = PTR_ERR(pcm179x->regmap);
>> > +               dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
>> > +               return ret;
>> > +       }
>> > +
>>
>> sound/soc/codecs/adau1781-spi.c
>>
>> I like more how was done here for private data and codec data. What do
>> you think?
>
> Why do you prefer that?
>
> Having a common_exit() to clean up whatever was done in common_init()
> seems like a better design than open-coding this in both of the i2c and
> spi drivers (if that's what you were referring to).
>

private data can be allocated in common code and you can pass the
regmap in the common init.
As I can understand in that way more common code is shared between i2c
and spi and make much
more clean and easy. I had a look very quick but I think that this was
the key point of that example

Michael

>> > +       return pcm179x_common_init(pcm179x);
>> > +}
>> > +
>> > +static int pcm179x_i2c_remove(struct i2c_client *client)
>> > +{
>> > +       return pcm179x_common_exit(i2c_get_clientdata(client));
>> > +}
>
> Thanks,
> Johan



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
@ 2016-01-20  4:58         ` Michael Trimarchi
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Trimarchi @ 2016-01-20  4:58 UTC (permalink / raw)
  To: Johan Hovold
  Cc: alsa-devel, LKML, Takashi Iwai, Liam Girdwood, Jacob Siverskog,
	Mark Brown

Hi

On Tue, Jan 19, 2016 at 2:51 PM, Johan Hovold <johan@kernel.org> wrote:
> On Tue, Jan 19, 2016 at 11:50:35AM +0100, Michael Trimarchi wrote:
>> Hi Jacob
>>
>> On Tue, Jan 19, 2016 at 11:29 AM, Jacob Siverskog
>> <jacob@teenage.engineering> wrote:
>> > The PCM179x family supports both SPI and I2C. This patch adds support
>> > for the I2C interface.
>> >
>> > Reviewed-by: Johan Hovold <johan@kernel.org>
>> > Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
>> > ---
>
>> > +static int pcm179x_i2c_probe(struct i2c_client *client,
>> > +                             const struct i2c_device_id *id)
>> > +{
>> > +       struct pcm179x_private *pcm179x;
>> > +       int ret;
>> > +
>> > +       pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
>> > +                               GFP_KERNEL);
>> > +       if (!pcm179x)
>> > +               return -ENOMEM;
>> > +
>> > +       i2c_set_clientdata(client, pcm179x);
>> > +
>> > +       pcm179x->dev = &client->dev;
>> > +
>> > +       pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
>> > +       if (IS_ERR(pcm179x->regmap)) {
>> > +               ret = PTR_ERR(pcm179x->regmap);
>> > +               dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
>> > +               return ret;
>> > +       }
>> > +
>>
>> sound/soc/codecs/adau1781-spi.c
>>
>> I like more how was done here for private data and codec data. What do
>> you think?
>
> Why do you prefer that?
>
> Having a common_exit() to clean up whatever was done in common_init()
> seems like a better design than open-coding this in both of the i2c and
> spi drivers (if that's what you were referring to).
>

private data can be allocated in common code and you can pass the
regmap in the common init.
As I can understand in that way more common code is shared between i2c
and spi and make much
more clean and easy. I had a look very quick but I think that this was
the key point of that example

Michael

>> > +       return pcm179x_common_init(pcm179x);
>> > +}
>> > +
>> > +static int pcm179x_i2c_remove(struct i2c_client *client)
>> > +{
>> > +       return pcm179x_common_exit(i2c_get_clientdata(client));
>> > +}
>
> Thanks,
> Johan



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver
  2016-01-20  4:58         ` Michael Trimarchi
  (?)
@ 2016-01-20 17:26         ` Johan Hovold
  -1 siblings, 0 replies; 11+ messages in thread
From: Johan Hovold @ 2016-01-20 17:26 UTC (permalink / raw)
  To: Michael Trimarchi
  Cc: Johan Hovold, Jacob Siverskog, Liam Girdwood, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, alsa-devel, LKML

On Wed, Jan 20, 2016 at 05:58:26AM +0100, Michael Trimarchi wrote:
> Hi
> 
> On Tue, Jan 19, 2016 at 2:51 PM, Johan Hovold <johan@kernel.org> wrote:
> > On Tue, Jan 19, 2016 at 11:50:35AM +0100, Michael Trimarchi wrote:
> >> Hi Jacob
> >>
> >> On Tue, Jan 19, 2016 at 11:29 AM, Jacob Siverskog
> >> <jacob@teenage.engineering> wrote:
> >> > The PCM179x family supports both SPI and I2C. This patch adds support
> >> > for the I2C interface.
> >> >
> >> > Reviewed-by: Johan Hovold <johan@kernel.org>
> >> > Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
> >> > ---
> >
> >> > +static int pcm179x_i2c_probe(struct i2c_client *client,
> >> > +                             const struct i2c_device_id *id)
> >> > +{
> >> > +       struct pcm179x_private *pcm179x;
> >> > +       int ret;
> >> > +
> >> > +       pcm179x = devm_kzalloc(&client->dev, sizeof(struct pcm179x_private),
> >> > +                               GFP_KERNEL);
> >> > +       if (!pcm179x)
> >> > +               return -ENOMEM;
> >> > +
> >> > +       i2c_set_clientdata(client, pcm179x);
> >> > +
> >> > +       pcm179x->dev = &client->dev;
> >> > +
> >> > +       pcm179x->regmap = devm_regmap_init_i2c(client, &pcm179x_regmap_config);
> >> > +       if (IS_ERR(pcm179x->regmap)) {
> >> > +               ret = PTR_ERR(pcm179x->regmap);
> >> > +               dev_err(&client->dev, "Failed to register regmap: %d\n", ret);
> >> > +               return ret;
> >> > +       }
> >> > +
> >>
> >> sound/soc/codecs/adau1781-spi.c
> >>
> >> I like more how was done here for private data and codec data. What do
> >> you think?
> >
> > Why do you prefer that?
> >
> > Having a common_exit() to clean up whatever was done in common_init()
> > seems like a better design than open-coding this in both of the i2c and
> > spi drivers (if that's what you were referring to).
> >
> 
> private data can be allocated in common code and you can pass the
> regmap in the common init.
> As I can understand in that way more common code is shared between i2c
> and spi and make much
> more clean and easy. I had a look very quick but I think that this was
> the key point of that example

You're right, and this seems to be how the other codec drivers do this
(unlike mfd for example). Some have a shared remove function, while most
call snd_soc_unregister_codec from the driver's remove callback, which
was what I found a bit odd as registration was done by the common init
code.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-20 17:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19 10:29 [PATCH v2 0/3] ASoC: pcm179x: Add I2C support, declare support for continuous rates Jacob Siverskog
2016-01-19 10:29 ` [PATCH v2 1/3] ASoC: pcm179x: Split into core and SPI parts Jacob Siverskog
2016-01-19 10:29   ` Jacob Siverskog
2016-01-19 10:29 ` [PATCH v2 2/3] ASoC: pcm179x: Add I2C interface driver Jacob Siverskog
2016-01-19 10:29   ` Jacob Siverskog
2016-01-19 10:50   ` Michael Trimarchi
2016-01-19 13:51     ` Johan Hovold
2016-01-20  4:58       ` Michael Trimarchi
2016-01-20  4:58         ` Michael Trimarchi
2016-01-20 17:26         ` Johan Hovold
2016-01-19 10:29 ` [PATCH v2 3/3] ASoC: pcm179x: Support continuous rates Jacob Siverskog

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.