Unverified Commit 309e94a6 authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: codecs: wcd93xxx: remove code duplication

Merge series from Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>:

All the Qualcomm WCD codecs and WCD based codecs have lots of code in
common, resulting in lot of duplicate code.
This series is an attempt to clean some of this by moving the common
code to wcd-common library or to soundwire helper functions.

Currently I have done cleanups for 4 codecs wcd934x, wcd937x, wcd938x
and wcd939x, however any new Qualcomm codecs can avoid this duplication
by using the wcd-common library.

I have also added two helpers of_sdw_find_device_by_node() and
sdw_slave_get_current_bank() in soundwire layer for the codecs to use them,
this series was already acked by Soundwire maintainer Vinod.

As original cleanup series was depending on the new soundwire interfaces
I have combined both the series as they are cleaning up code
duplications.

As am touching the same codec drivers, 2 bug fixes are also added at the
start of the series.

There is still lot of code that is duplicate, but this is just a
starting point for such cleanups.

I have tested this on T14s, any testing is appreciated.
parents dfe3de7b 0266f954
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1360,6 +1360,18 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
}
EXPORT_SYMBOL(sdw_slave_get_scale_index);

int sdw_slave_get_current_bank(struct sdw_slave *slave)
{
	int tmp;

	tmp = sdw_read(slave, SDW_SCP_CTRL);
	if (tmp < 0)
		return tmp;

	return FIELD_GET(SDW_SCP_STAT_CURR_BANK, tmp);
}
EXPORT_SYMBOL_GPL(sdw_slave_get_current_bank);

static int sdw_slave_set_frequency(struct sdw_slave *slave)
{
	int scale_index;
+6 −0
Original line number Diff line number Diff line
@@ -273,4 +273,10 @@ int sdw_of_find_slaves(struct sdw_bus *bus)
	return 0;
}

struct device *of_sdw_find_device_by_node(struct device_node *np)
{
	return bus_find_device_by_of_node(&sdw_bus_type, np);
}
EXPORT_SYMBOL_GPL(of_sdw_find_device_by_node);

MODULE_IMPORT_NS("SND_SOC_SDCA");
+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

struct dentry;
struct fwnode_handle;
struct device_node;

struct sdw_bus;
struct sdw_slave;
@@ -1086,6 +1087,10 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
int sdw_stream_remove_slave(struct sdw_slave *slave,
			    struct sdw_stream_runtime *stream);

struct device *of_sdw_find_device_by_node(struct device_node *np);

int sdw_slave_get_current_bank(struct sdw_slave *sdev);

int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);

/* messaging and data APIs */
@@ -1119,6 +1124,18 @@ static inline int sdw_stream_remove_slave(struct sdw_slave *slave,
	return -EINVAL;
}

static inline struct device *of_sdw_find_device_by_node(struct device_node *np)
{
	WARN_ONCE(1, "SoundWire API is disabled");
	return NULL;
}

static inline int sdw_slave_get_current_bank(struct sdw_slave *sdev)
{
	WARN_ONCE(1, "SoundWire API is disabled");
	return -EINVAL;
}

/* messaging and data APIs */
static inline int sdw_read(struct sdw_slave *slave, u32 addr)
{
+7 −0
Original line number Diff line number Diff line
@@ -2274,6 +2274,9 @@ config SND_SOC_UDA1380
config SND_SOC_WCD_CLASSH
	tristate

config SND_SOC_WCD_COMMON
	tristate

config SND_SOC_WCD9335
	tristate "WCD9335 Codec"
	depends on SLIMBUS
@@ -2295,6 +2298,7 @@ config SND_SOC_WCD934X
	select REGMAP_IRQ
	select REGMAP_SLIMBUS
	select SND_SOC_WCD_CLASSH
	select SND_SOC_WCD_COMMON
	select SND_SOC_WCD_MBHC
	depends on MFD_WCD934X || COMPILE_TEST
	help
@@ -2306,6 +2310,7 @@ config SND_SOC_WCD937X
	tristate
	depends on SOUNDWIRE || !SOUNDWIRE
	select SND_SOC_WCD_CLASSH
	select SND_SOC_WCD_COMMON

config SND_SOC_WCD937X_SDW
	tristate "WCD9370/WCD9375 Codec - SDW"
@@ -2325,6 +2330,7 @@ config SND_SOC_WCD938X
	tristate
	depends on SOUNDWIRE || !SOUNDWIRE
	select SND_SOC_WCD_CLASSH
	select SND_SOC_WCD_COMMON
	select MULTIPLEXER

config SND_SOC_WCD938X_SDW
@@ -2344,6 +2350,7 @@ config SND_SOC_WCD939X
	depends on SOUNDWIRE || !SOUNDWIRE
	depends on TYPEC || !TYPEC
	select SND_SOC_WCD_CLASSH
	select SND_SOC_WCD_COMMON

config SND_SOC_WCD939X_SDW
	tristate "WCD9390/WCD9395 Codec - SDW"
+2 −0
Original line number Diff line number Diff line
@@ -344,6 +344,7 @@ snd-soc-uda1334-y := uda1334.o
snd-soc-uda1342-y := uda1342.o
snd-soc-uda1380-y := uda1380.o
snd-soc-wcd-classh-y := wcd-clsh-v2.o
snd-soc-wcd-common-y := wcd-common.o
snd-soc-wcd-mbhc-y := wcd-mbhc-v2.o
snd-soc-wcd9335-y := wcd9335.o
snd-soc-wcd934x-y := wcd934x.o
@@ -774,6 +775,7 @@ obj-$(CONFIG_SND_SOC_UDA1334) += snd-soc-uda1334.o
obj-$(CONFIG_SND_SOC_UDA1342)	+= snd-soc-uda1342.o
obj-$(CONFIG_SND_SOC_UDA1380)	+= snd-soc-uda1380.o
obj-$(CONFIG_SND_SOC_WCD_CLASSH)	+= snd-soc-wcd-classh.o
obj-$(CONFIG_SND_SOC_WCD_COMMON)	+= snd-soc-wcd-common.o
obj-$(CONFIG_SND_SOC_WCD_MBHC)	+= snd-soc-wcd-mbhc.o
obj-$(CONFIG_SND_SOC_WCD9335)	+= snd-soc-wcd9335.o
obj-$(CONFIG_SND_SOC_WCD934X)	+= snd-soc-wcd934x.o
Loading