ASoC: core: use regmap's parse_val to do endian translation
authorNenghua Cao <nhcao@marvell.com>
Wed, 19 Feb 2014 10:44:58 +0000 (18:44 +0800)
committerMark Brown <broonie@linaro.org>
Thu, 6 Mar 2014 09:46:31 +0000 (17:46 +0800)
    In snd_soc_bytes_put function, it forces cpu to do cpu_to_be translation,
but for mmio bus which uses REGMAP_ENDIAN_NATIVE, it doesn't need to do
endian translation. So it is better to use regmap's api which can decide
if this translation is needed according to bus configuration.

Signed-off-by: Nenghua Cao <nhcao@marvell.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
sound/soc/soc-core.c

index 45a1fafdbd7ba21f57f7f08455f9186049a1f36c..9d25c2e0fb9221efd081ed5eb8f4daa665f8580b 100644 (file)
@@ -3234,7 +3234,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
        struct soc_bytes *params = (void *)kcontrol->private_value;
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        int ret, len;
-       unsigned int val;
+       unsigned int val, mask;
        void *data;
 
        if (!codec->using_regmap)
@@ -3264,12 +3264,36 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
                        ((u8 *)data)[0] |= val;
                        break;
                case 2:
-                       ((u16 *)data)[0] &= cpu_to_be16(~params->mask);
-                       ((u16 *)data)[0] |= cpu_to_be16(val);
+                       mask = ~params->mask;
+                       ret = regmap_parse_val(codec->control_data,
+                                                       &mask, &mask);
+                       if (ret != 0)
+                               goto out;
+
+                       ((u16 *)data)[0] &= mask;
+
+                       ret = regmap_parse_val(codec->control_data,
+                                                       &val, &val);
+                       if (ret != 0)
+                               goto out;
+
+                       ((u16 *)data)[0] |= val;
                        break;
                case 4:
-                       ((u32 *)data)[0] &= cpu_to_be32(~params->mask);
-                       ((u32 *)data)[0] |= cpu_to_be32(val);
+                       mask = ~params->mask;
+                       ret = regmap_parse_val(codec->control_data,
+                                                       &mask, &mask);
+                       if (ret != 0)
+                               goto out;
+
+                       ((u32 *)data)[0] &= mask;
+
+                       ret = regmap_parse_val(codec->control_data,
+                                                       &val, &val);
+                       if (ret != 0)
+                               goto out;
+
+                       ((u32 *)data)[0] |= val;
                        break;
                default:
                        ret = -EINVAL;