ASoC: soc-component: merge soc-io.c into soc-component.c
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 4 Jun 2020 08:08:03 +0000 (17:08 +0900)
committerMark Brown <broonie@kernel.org>
Mon, 15 Jun 2020 17:21:26 +0000 (18:21 +0100)
soc-io.c has snd_soc_component_xxx() functions for I/O.
We have soc-componennt.c for it.
Let's merge soc-io.c into soc-component.c

By this patch, original soc-io.c functions start to use
soc_component_err() when error case.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87h7vrw8ws.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/Makefile
sound/soc/soc-component.c
sound/soc/soc-io.c [deleted file]

index 7f17475..ddbac3a 100644 (file)
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-utils.o soc-dai.o soc-component.o
-snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o soc-link.o soc-card.o
+snd-soc-core-objs += soc-pcm.o soc-devres.o soc-ops.o soc-link.o soc-card.o
 snd-soc-core-$(CONFIG_SND_SOC_COMPRESS) += soc-compress.o
 
 ifneq ($(CONFIG_SND_SOC_TOPOLOGY),)
index 7624ff5..d121f5f 100644 (file)
@@ -2,7 +2,10 @@
 //
 // soc-component.c
 //
+// Copyright 2009-2011 Wolfson Microelectronics PLC.
 // Copyright (C) 2019 Renesas Electronics Corp.
+//
+// Mark Brown <broonie@opensource.wolfsonmicro.com>
 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
 //
 #include <linux/module.h>
@@ -400,6 +403,197 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
 
 #endif
 
+/**
+ * snd_soc_component_read() - Read register value
+ * @component: Component to read from
+ * @reg: Register to read
+ * @val: Pointer to where the read value is stored
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+int snd_soc_component_read(struct snd_soc_component *component,
+                          unsigned int reg, unsigned int *val)
+{
+       int ret;
+
+       if (component->regmap)
+               ret = regmap_read(component->regmap, reg, val);
+       else if (component->driver->read) {
+               *val = component->driver->read(component, reg);
+               ret = 0;
+       }
+       else
+               ret = -EIO;
+
+       return soc_component_ret(component, ret);
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_read);
+
+unsigned int snd_soc_component_read32(struct snd_soc_component *component,
+                                     unsigned int reg)
+{
+       unsigned int val;
+       int ret;
+
+       ret = snd_soc_component_read(component, reg, &val);
+       if (ret < 0)
+               return soc_component_ret(component, -1);
+
+       return val;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_read32);
+
+/**
+ * snd_soc_component_write() - Write register value
+ * @component: Component to write to
+ * @reg: Register to write
+ * @val: Value to write to the register
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+int snd_soc_component_write(struct snd_soc_component *component,
+                           unsigned int reg, unsigned int val)
+{
+       int ret = -EIO;
+
+       if (component->regmap)
+               ret = regmap_write(component->regmap, reg, val);
+       else if (component->driver->write)
+               ret = component->driver->write(component, reg, val);
+
+       return soc_component_ret(component, ret);
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_write);
+
+static int snd_soc_component_update_bits_legacy(
+       struct snd_soc_component *component, unsigned int reg,
+       unsigned int mask, unsigned int val, bool *change)
+{
+       unsigned int old, new;
+       int ret;
+
+       mutex_lock(&component->io_mutex);
+
+       ret = snd_soc_component_read(component, reg, &old);
+       if (ret < 0)
+               goto out_unlock;
+
+       new = (old & ~mask) | (val & mask);
+       *change = old != new;
+       if (*change)
+               ret = snd_soc_component_write(component, reg, new);
+out_unlock:
+       mutex_unlock(&component->io_mutex);
+
+       return soc_component_ret(component, ret);
+}
+
+/**
+ * snd_soc_component_update_bits() - Perform read/modify/write cycle
+ * @component: Component to update
+ * @reg: Register to update
+ * @mask: Mask that specifies which bits to update
+ * @val: New value for the bits specified by mask
+ *
+ * Return: 1 if the operation was successful and the value of the register
+ * changed, 0 if the operation was successful, but the value did not change.
+ * Returns a negative error code otherwise.
+ */
+int snd_soc_component_update_bits(struct snd_soc_component *component,
+                                 unsigned int reg, unsigned int mask, unsigned int val)
+{
+       bool change;
+       int ret;
+
+       if (component->regmap)
+               ret = regmap_update_bits_check(component->regmap, reg, mask,
+                                              val, &change);
+       else
+               ret = snd_soc_component_update_bits_legacy(component, reg,
+                                                          mask, val, &change);
+
+       if (ret < 0)
+               return soc_component_ret(component, ret);
+       return change;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
+
+/**
+ * snd_soc_component_update_bits_async() - Perform asynchronous
+ *  read/modify/write cycle
+ * @component: Component to update
+ * @reg: Register to update
+ * @mask: Mask that specifies which bits to update
+ * @val: New value for the bits specified by mask
+ *
+ * This function is similar to snd_soc_component_update_bits(), but the update
+ * operation is scheduled asynchronously. This means it may not be completed
+ * when the function returns. To make sure that all scheduled updates have been
+ * completed snd_soc_component_async_complete() must be called.
+ *
+ * Return: 1 if the operation was successful and the value of the register
+ * changed, 0 if the operation was successful, but the value did not change.
+ * Returns a negative error code otherwise.
+ */
+int snd_soc_component_update_bits_async(struct snd_soc_component *component,
+                                       unsigned int reg, unsigned int mask, unsigned int val)
+{
+       bool change;
+       int ret;
+
+       if (component->regmap)
+               ret = regmap_update_bits_check_async(component->regmap, reg,
+                                                    mask, val, &change);
+       else
+               ret = snd_soc_component_update_bits_legacy(component, reg,
+                                                          mask, val, &change);
+
+       if (ret < 0)
+               return soc_component_ret(component, ret);
+       return change;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
+
+/**
+ * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
+ * @component: Component for which to wait
+ *
+ * This function blocks until all asynchronous I/O which has previously been
+ * scheduled using snd_soc_component_update_bits_async() has completed.
+ */
+void snd_soc_component_async_complete(struct snd_soc_component *component)
+{
+       if (component->regmap)
+               regmap_async_complete(component->regmap);
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
+
+/**
+ * snd_soc_component_test_bits - Test register for change
+ * @component: component
+ * @reg: Register to test
+ * @mask: Mask that specifies which bits to test
+ * @value: Value to test against
+ *
+ * Tests a register with a new value and checks if the new value is
+ * different from the old value.
+ *
+ * Return: 1 for change, otherwise 0.
+ */
+int snd_soc_component_test_bits(struct snd_soc_component *component,
+                               unsigned int reg, unsigned int mask, unsigned int value)
+{
+       unsigned int old, new;
+       int ret;
+
+       ret = snd_soc_component_read(component, reg, &old);
+       if (ret < 0)
+               return soc_component_ret(component, ret);
+       new = (old & ~mask) | value;
+       return old != new;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
+
 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
deleted file mode 100644 (file)
index 1ff9175..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-//
-// soc-io.c  --  ASoC register I/O helpers
-//
-// Copyright 2009-2011 Wolfson Microelectronics PLC.
-//
-// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
-
-#include <linux/i2c.h>
-#include <linux/spi/spi.h>
-#include <linux/regmap.h>
-#include <linux/export.h>
-#include <sound/soc.h>
-
-/**
- * snd_soc_component_read() - Read register value
- * @component: Component to read from
- * @reg: Register to read
- * @val: Pointer to where the read value is stored
- *
- * Return: 0 on success, a negative error code otherwise.
- */
-int snd_soc_component_read(struct snd_soc_component *component,
-       unsigned int reg, unsigned int *val)
-{
-       int ret;
-
-       if (component->regmap)
-               ret = regmap_read(component->regmap, reg, val);
-       else if (component->driver->read) {
-               *val = component->driver->read(component, reg);
-               ret = 0;
-       }
-       else
-               ret = -EIO;
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_read);
-
-unsigned int snd_soc_component_read32(struct snd_soc_component *component,
-                                     unsigned int reg)
-{
-       unsigned int val;
-       int ret;
-
-       ret = snd_soc_component_read(component, reg, &val);
-       if (ret < 0)
-               return -1;
-
-       return val;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_read32);
-
-/**
- * snd_soc_component_write() - Write register value
- * @component: Component to write to
- * @reg: Register to write
- * @val: Value to write to the register
- *
- * Return: 0 on success, a negative error code otherwise.
- */
-int snd_soc_component_write(struct snd_soc_component *component,
-       unsigned int reg, unsigned int val)
-{
-       if (component->regmap)
-               return regmap_write(component->regmap, reg, val);
-       else if (component->driver->write)
-               return component->driver->write(component, reg, val);
-       else
-               return -EIO;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_write);
-
-static int snd_soc_component_update_bits_legacy(
-       struct snd_soc_component *component, unsigned int reg,
-       unsigned int mask, unsigned int val, bool *change)
-{
-       unsigned int old, new;
-       int ret;
-
-       mutex_lock(&component->io_mutex);
-
-       ret = snd_soc_component_read(component, reg, &old);
-       if (ret < 0)
-               goto out_unlock;
-
-       new = (old & ~mask) | (val & mask);
-       *change = old != new;
-       if (*change)
-               ret = snd_soc_component_write(component, reg, new);
-out_unlock:
-       mutex_unlock(&component->io_mutex);
-
-       return ret;
-}
-
-/**
- * snd_soc_component_update_bits() - Perform read/modify/write cycle
- * @component: Component to update
- * @reg: Register to update
- * @mask: Mask that specifies which bits to update
- * @val: New value for the bits specified by mask
- *
- * Return: 1 if the operation was successful and the value of the register
- * changed, 0 if the operation was successful, but the value did not change.
- * Returns a negative error code otherwise.
- */
-int snd_soc_component_update_bits(struct snd_soc_component *component,
-       unsigned int reg, unsigned int mask, unsigned int val)
-{
-       bool change;
-       int ret;
-
-       if (component->regmap)
-               ret = regmap_update_bits_check(component->regmap, reg, mask,
-                       val, &change);
-       else
-               ret = snd_soc_component_update_bits_legacy(component, reg,
-                       mask, val, &change);
-
-       if (ret < 0)
-               return ret;
-       return change;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
-
-/**
- * snd_soc_component_update_bits_async() - Perform asynchronous
- *  read/modify/write cycle
- * @component: Component to update
- * @reg: Register to update
- * @mask: Mask that specifies which bits to update
- * @val: New value for the bits specified by mask
- *
- * This function is similar to snd_soc_component_update_bits(), but the update
- * operation is scheduled asynchronously. This means it may not be completed
- * when the function returns. To make sure that all scheduled updates have been
- * completed snd_soc_component_async_complete() must be called.
- *
- * Return: 1 if the operation was successful and the value of the register
- * changed, 0 if the operation was successful, but the value did not change.
- * Returns a negative error code otherwise.
- */
-int snd_soc_component_update_bits_async(struct snd_soc_component *component,
-       unsigned int reg, unsigned int mask, unsigned int val)
-{
-       bool change;
-       int ret;
-
-       if (component->regmap)
-               ret = regmap_update_bits_check_async(component->regmap, reg,
-                       mask, val, &change);
-       else
-               ret = snd_soc_component_update_bits_legacy(component, reg,
-                       mask, val, &change);
-
-       if (ret < 0)
-               return ret;
-       return change;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
-
-/**
- * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
- * @component: Component for which to wait
- *
- * This function blocks until all asynchronous I/O which has previously been
- * scheduled using snd_soc_component_update_bits_async() has completed.
- */
-void snd_soc_component_async_complete(struct snd_soc_component *component)
-{
-       if (component->regmap)
-               regmap_async_complete(component->regmap);
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
-
-/**
- * snd_soc_component_test_bits - Test register for change
- * @component: component
- * @reg: Register to test
- * @mask: Mask that specifies which bits to test
- * @value: Value to test against
- *
- * Tests a register with a new value and checks if the new value is
- * different from the old value.
- *
- * Return: 1 for change, otherwise 0.
- */
-int snd_soc_component_test_bits(struct snd_soc_component *component,
-       unsigned int reg, unsigned int mask, unsigned int value)
-{
-       unsigned int old, new;
-       int ret;
-
-       ret = snd_soc_component_read(component, reg, &old);
-       if (ret < 0)
-               return ret;
-       new = (old & ~mask) | value;
-       return old != new;
-}
-EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);