Browse Source

asoc: codecs: Update logic for active ch cnt calculation

Use number of bits set in active_ch_mask to calculate
active channel count. This fixes improper update of
channel count if same kcontrol is issued more than
once.

Change-Id: I84dc33ad5b6dbfc3babf5bbfeab1e2e71af5983b
Signed-off-by: Rohit kumar <[email protected]>
Rohit kumar 4 years ago
parent
commit
e25a1fdc64

+ 3 - 8
asoc/codecs/bolero/rx-macro.c

@@ -6,6 +6,7 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
+#include <linux/bitops.h>
 #include <linux/clk.h>
 #include <linux/pm_runtime.h>
 #include <sound/soc.h>
@@ -436,7 +437,6 @@ struct rx_macro_priv {
 	struct device_node *rx_swr_gpio_p;
 	struct snd_soc_component *component;
 	unsigned long active_ch_mask[RX_MACRO_MAX_DAIS];
-	unsigned long active_ch_cnt[RX_MACRO_MAX_DAIS];
 	u16 bit_width[RX_MACRO_MAX_DAIS];
 	char __iomem *rx_io_base;
 	char __iomem *rx_mclk_mode_muxsel;
@@ -1133,7 +1133,7 @@ static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
 		if ((ch_mask & 0x10) || (ch_mask & 0x20))
 			ch_mask = 0x1;
 		*rx_slot = ch_mask;
-		*rx_num = rx_priv->active_ch_cnt[dai->id];
+		*rx_num = hweight_long(ch_mask);
 		dev_dbg(rx_priv->dev,
 			"%s: dai->id:%d, ch_mask:0x%x, active_ch_cnt:%d active_mask: 0x%x\n",
 			__func__, dai->id, *rx_slot, *rx_num, rx_priv->active_ch_mask[dai->id]);
@@ -2110,11 +2110,7 @@ static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
 
 	switch (rx_port_value) {
 	case 0:
-		if (rx_priv->active_ch_cnt[aif_rst]) {
-			clear_bit(widget->shift,
-				&rx_priv->active_ch_mask[aif_rst]);
-			rx_priv->active_ch_cnt[aif_rst]--;
-		}
+		clear_bit(widget->shift, &rx_priv->active_ch_mask[aif_rst]);
 		break;
 	case 1:
 	case 2:
@@ -2122,7 +2118,6 @@ static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
 	case 4:
 		set_bit(widget->shift,
 			&rx_priv->active_ch_mask[rx_port_value]);
-		rx_priv->active_ch_cnt[rx_port_value]++;
 		break;
 	default:
 		dev_err(component->dev,

+ 5 - 7
asoc/codecs/bolero/tx-macro.c

@@ -4,6 +4,7 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/bitops.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
@@ -162,7 +163,6 @@ struct tx_macro_priv {
 	u32 version;
 	u32 is_used_tx_swr_gpio;
 	unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
-	unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
 	char __iomem *tx_io_base;
 	struct platform_device *pdev_child_devices
 			[TX_MACRO_CHILD_DEVICES_MAX];
@@ -663,13 +663,11 @@ static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
 	if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
 		return -EINVAL;
 
-	if (enable) {
+	if (enable)
 		set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
-		tx_priv->active_ch_cnt[dai_id]++;
-	} else {
-		tx_priv->active_ch_cnt[dai_id]--;
+	else
 		clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
-	}
+
 	snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
 
 	return 0;
@@ -1245,7 +1243,7 @@ static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
 	case TX_MACRO_AIF2_CAP:
 	case TX_MACRO_AIF3_CAP:
 		*tx_slot = tx_priv->active_ch_mask[dai->id];
-		*tx_num = tx_priv->active_ch_cnt[dai->id];
+		*tx_num = hweight_long(tx_priv->active_ch_mask[dai->id]);
 		break;
 	default:
 		dev_err(tx_dev, "%s: Invalid AIF\n", __func__);

+ 4 - 7
asoc/codecs/bolero/va-macro.c

@@ -4,6 +4,7 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/bitops.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
@@ -143,7 +144,6 @@ struct va_macro_priv {
 	struct hpf_work va_hpf_work[VA_MACRO_NUM_DECIMATORS];
 	struct va_mute_work va_mute_dwork[VA_MACRO_NUM_DECIMATORS];
 	unsigned long active_ch_mask[VA_MACRO_MAX_DAIS];
-	unsigned long active_ch_cnt[VA_MACRO_MAX_DAIS];
 	u16 dmic_clk_div;
 	u16 va_mclk_users;
 	int swr_clk_users;
@@ -1051,13 +1051,10 @@ static int va_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
 	if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
 		return -EINVAL;
 
-	if (enable) {
+	if (enable)
 		set_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
-		va_priv->active_ch_cnt[dai_id]++;
-	} else {
+	else
 		clear_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
-		va_priv->active_ch_cnt[dai_id]--;
-	}
 
 	snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
 
@@ -1552,7 +1549,7 @@ static int va_macro_get_channel_map(struct snd_soc_dai *dai,
 	case VA_MACRO_AIF2_CAP:
 	case VA_MACRO_AIF3_CAP:
 		*tx_slot = va_priv->active_ch_mask[dai->id];
-		*tx_num = va_priv->active_ch_cnt[dai->id];
+		*tx_num = hweight_long(va_priv->active_ch_mask[dai->id]);
 		break;
 	default:
 		dev_err(va_dev, "%s: Invalid AIF\n", __func__);

+ 3 - 13
asoc/codecs/bolero/wsa-macro.c

@@ -203,7 +203,6 @@ enum {
  * @rx_0_count: RX0 interpolation users
  * @rx_1_count: RX1 interpolation users
  * @active_ch_mask: channel mask for all AIF DAIs
- * @active_ch_cnt: channel count of all AIF DAIs
  * @rx_port_value: mixer ctl value of WSA RX MUXes
  * @wsa_io_base: Base address of WSA macro addr space
  */
@@ -227,7 +226,6 @@ struct wsa_macro_priv {
 	int rx_0_count;
 	int rx_1_count;
 	unsigned long active_ch_mask[WSA_MACRO_MAX_DAIS];
-	unsigned long active_ch_cnt[WSA_MACRO_MAX_DAIS];
 	int rx_port_value[WSA_MACRO_RX_MAX];
 	char __iomem *wsa_io_base;
 	struct platform_device *pdev_child_devices
@@ -801,7 +799,7 @@ static int wsa_macro_get_channel_map(struct snd_soc_dai *dai,
 	switch (dai->id) {
 	case WSA_MACRO_AIF_VI:
 		*tx_slot = wsa_priv->active_ch_mask[dai->id];
-		*tx_num = wsa_priv->active_ch_cnt[dai->id];
+		*tx_num = hweight_long(wsa_priv->active_ch_mask[dai->id]);
 		break;
 	case WSA_MACRO_AIF1_PB:
 	case WSA_MACRO_AIF_MIX1_PB:
@@ -2242,17 +2240,13 @@ static int wsa_macro_rx_mux_put(struct snd_kcontrol *kcontrol,
 
 	switch (rx_port_value) {
 	case 0:
-		if (wsa_priv->active_ch_cnt[aif_rst]) {
-			clear_bit(bit_input,
-				  &wsa_priv->active_ch_mask[aif_rst]);
-			wsa_priv->active_ch_cnt[aif_rst]--;
-		}
+		clear_bit(bit_input,
+			  &wsa_priv->active_ch_mask[aif_rst]);
 		break;
 	case 1:
 	case 2:
 		set_bit(bit_input,
 			&wsa_priv->active_ch_mask[rx_port_value]);
-		wsa_priv->active_ch_cnt[rx_port_value]++;
 		break;
 	default:
 		dev_err(wsa_dev,
@@ -2462,14 +2456,12 @@ static int wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
 			set_bit(WSA_MACRO_TX0,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
-			wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]++;
 		}
 		if (spk_tx_id == WSA_MACRO_TX1 &&
 			!test_bit(WSA_MACRO_TX1,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
 			set_bit(WSA_MACRO_TX1,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
-			wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]++;
 		}
 	} else {
 		if (spk_tx_id == WSA_MACRO_TX0 &&
@@ -2477,14 +2469,12 @@ static int wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
 			clear_bit(WSA_MACRO_TX0,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
-			wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]--;
 		}
 		if (spk_tx_id == WSA_MACRO_TX1 &&
 			test_bit(WSA_MACRO_TX1,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
 			clear_bit(WSA_MACRO_TX1,
 				&wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
-			wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]--;
 		}
 	}
 	snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);