Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 293401
b: refs/heads/master
c: f831b05
h: refs/heads/master
i:
  293399: e7ec785
v: v3
  • Loading branch information
Mark Brown committed Feb 21, 2012
1 parent 4c729b7 commit f913f7a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 71d08516b80638a69d5efea4e8cb832c053f9dd9
refs/heads/master: f831b055ececb3172f7fe498db5ca1fb43ff644d
9 changes: 9 additions & 0 deletions trunk/include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@
((unsigned long)&(struct soc_bytes) \
{.base = xbase, .num_regs = xregs }) }

#define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
.info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
.put = snd_soc_bytes_put, .private_value = \
((unsigned long)&(struct soc_bytes) \
{.base = xbase, .num_regs = xregs, \
.mask = xmask }) }

/*
* Simplified versions of above macros, declaring a struct and calculating
* ARRAY_SIZE internally
Expand Down Expand Up @@ -904,6 +912,7 @@ struct soc_mixer_control {
struct soc_bytes {
int base;
int num_regs;
u32 mask;
};

/* enumerated kcontrol */
Expand Down
74 changes: 67 additions & 7 deletions trunk/sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2763,6 +2763,25 @@ int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
else
ret = -EINVAL;

/* Hide any masked bytes to ensure consistent data reporting */
if (ret == 0 && params->mask) {
switch (codec->val_bytes) {
case 1:
ucontrol->value.bytes.data[0] &= ~params->mask;
break;
case 2:
((u16 *)(&ucontrol->value.bytes.data))[0]
&= ~params->mask;
break;
case 4:
((u32 *)(&ucontrol->value.bytes.data))[0]
&= ~params->mask;
break;
default:
return -EINVAL;
}
}

return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
Expand All @@ -2772,14 +2791,55 @@ 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;
int ret, len;
unsigned int val;
void *data;

if (codec->using_regmap)
ret = regmap_raw_write(codec->control_data, params->base,
ucontrol->value.bytes.data,
params->num_regs * codec->val_bytes);
else
ret = -EINVAL;
if (!codec->using_regmap)
return -EINVAL;

data = ucontrol->value.bytes.data;
len = params->num_regs * codec->val_bytes;

/*
* If we've got a mask then we need to preserve the register
* bits. We shouldn't modify the incoming data so take a
* copy.
*/
if (params->mask) {
ret = regmap_read(codec->control_data, params->base, &val);
if (ret != 0)
return ret;

val &= params->mask;

data = kmemdup(data, len, GFP_KERNEL);
if (!data)
return -ENOMEM;

switch (codec->val_bytes) {
case 1:
((u8 *)data)[0] &= ~params->mask;
((u8 *)data)[0] |= val;
break;
case 2:
((u16 *)data)[0] &= cpu_to_be16(~params->mask);
((u16 *)data)[0] |= cpu_to_be16(val);
break;
case 4:
((u32 *)data)[0] &= cpu_to_be32(~params->mask);
((u32 *)data)[0] |= cpu_to_be32(val);
break;
default:
return -EINVAL;
}
}

ret = regmap_raw_write(codec->control_data, params->base,
data, len);

if (params->mask)
kfree(data);

return ret;
}
Expand Down

0 comments on commit f913f7a

Please sign in to comment.