2 * soc-ops.c -- Generic ASoC operations
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
24 #include <linux/bitops.h>
25 #include <linux/ctype.h>
26 #include <linux/slab.h>
27 #include <sound/core.h>
28 #include <sound/jack.h>
29 #include <sound/pcm.h>
30 #include <sound/pcm_params.h>
31 #include <sound/soc.h>
32 #include <sound/soc-dpcm.h>
33 #include <sound/initval.h>
36 * snd_soc_info_enum_double - enumerated double mixer info callback
37 * @kcontrol: mixer control
38 * @uinfo: control element information
40 * Callback to provide information about a double enumerated
43 * Returns 0 for success.
45 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
46 struct snd_ctl_elem_info *uinfo)
48 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
50 return snd_ctl_enum_info(uinfo, e->shift_l == e->shift_r ? 1 : 2,
53 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
56 * snd_soc_get_enum_double - enumerated double mixer get callback
57 * @kcontrol: mixer control
58 * @ucontrol: control element information
60 * Callback to get the value of a double enumerated mixer.
62 * Returns 0 for success.
64 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
65 struct snd_ctl_elem_value *ucontrol)
67 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
68 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
69 unsigned int val, item;
73 ret = snd_soc_component_read(component, e->reg, ®_val);
76 val = (reg_val >> e->shift_l) & e->mask;
77 item = snd_soc_enum_val_to_item(e, val);
78 ucontrol->value.enumerated.item[0] = item;
79 if (e->shift_l != e->shift_r) {
80 val = (reg_val >> e->shift_l) & e->mask;
81 item = snd_soc_enum_val_to_item(e, val);
82 ucontrol->value.enumerated.item[1] = item;
87 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
90 * snd_soc_put_enum_double - enumerated double mixer put callback
91 * @kcontrol: mixer control
92 * @ucontrol: control element information
94 * Callback to set the value of a double enumerated mixer.
96 * Returns 0 for success.
98 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
99 struct snd_ctl_elem_value *ucontrol)
101 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
102 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
103 unsigned int *item = ucontrol->value.enumerated.item;
107 if (item[0] >= e->items)
109 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
110 mask = e->mask << e->shift_l;
111 if (e->shift_l != e->shift_r) {
112 if (item[1] >= e->items)
114 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
115 mask |= e->mask << e->shift_r;
118 return snd_soc_component_update_bits(component, e->reg, mask, val);
120 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
123 * snd_soc_read_signed - Read a codec register and interprete as signed value
124 * @component: component
125 * @reg: Register to read
126 * @mask: Mask to use after shifting the register value
127 * @shift: Right shift of register value
128 * @sign_bit: Bit that describes if a number is negative or not.
129 * @signed_val: Pointer to where the read value should be stored
131 * This functions reads a codec register. The register value is shifted right
132 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
133 * the given registervalue into a signed integer if sign_bit is non-zero.
135 * Returns 0 on sucess, otherwise an error value
137 static int snd_soc_read_signed(struct snd_soc_component *component,
138 unsigned int reg, unsigned int mask, unsigned int shift,
139 unsigned int sign_bit, int *signed_val)
144 ret = snd_soc_component_read(component, reg, &val);
148 val = (val >> shift) & mask;
155 /* non-negative number */
156 if (!(val & BIT(sign_bit))) {
164 * The register most probably does not contain a full-sized int.
165 * Instead we have an arbitrary number of bits in a signed
166 * representation which has to be translated into a full-sized int.
167 * This is done by filling up all bits above the sign-bit.
169 ret |= ~((int)(BIT(sign_bit) - 1));
177 * snd_soc_info_volsw - single mixer info callback
178 * @kcontrol: mixer control
179 * @uinfo: control element information
181 * Callback to provide information about a single mixer control, or a double
182 * mixer control that spans 2 registers.
184 * Returns 0 for success.
186 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
187 struct snd_ctl_elem_info *uinfo)
189 struct soc_mixer_control *mc =
190 (struct soc_mixer_control *)kcontrol->private_value;
193 if (!mc->platform_max)
194 mc->platform_max = mc->max;
195 platform_max = mc->platform_max;
197 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
198 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
200 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
202 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
203 uinfo->value.integer.min = 0;
204 uinfo->value.integer.max = platform_max - mc->min;
207 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
210 * snd_soc_get_volsw - single mixer get callback
211 * @kcontrol: mixer control
212 * @ucontrol: control element information
214 * Callback to get the value of a single mixer control, or a double mixer
215 * control that spans 2 registers.
217 * Returns 0 for success.
219 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_value *ucontrol)
222 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
223 struct soc_mixer_control *mc =
224 (struct soc_mixer_control *)kcontrol->private_value;
225 unsigned int reg = mc->reg;
226 unsigned int reg2 = mc->rreg;
227 unsigned int shift = mc->shift;
228 unsigned int rshift = mc->rshift;
231 int sign_bit = mc->sign_bit;
232 unsigned int mask = (1 << fls(max)) - 1;
233 unsigned int invert = mc->invert;
238 mask = BIT(sign_bit + 1) - 1;
240 ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val);
244 ucontrol->value.integer.value[0] = val - min;
246 ucontrol->value.integer.value[0] =
247 max - ucontrol->value.integer.value[0];
249 if (snd_soc_volsw_is_stereo(mc)) {
251 ret = snd_soc_read_signed(component, reg, mask, rshift,
254 ret = snd_soc_read_signed(component, reg2, mask, shift,
259 ucontrol->value.integer.value[1] = val - min;
261 ucontrol->value.integer.value[1] =
262 max - ucontrol->value.integer.value[1];
267 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
270 * snd_soc_put_volsw - single mixer put callback
271 * @kcontrol: mixer control
272 * @ucontrol: control element information
274 * Callback to set the value of a single mixer control, or a double mixer
275 * control that spans 2 registers.
277 * Returns 0 for success.
279 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_value *ucontrol)
282 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
283 struct soc_mixer_control *mc =
284 (struct soc_mixer_control *)kcontrol->private_value;
285 unsigned int reg = mc->reg;
286 unsigned int reg2 = mc->rreg;
287 unsigned int shift = mc->shift;
288 unsigned int rshift = mc->rshift;
291 unsigned int sign_bit = mc->sign_bit;
292 unsigned int mask = (1 << fls(max)) - 1;
293 unsigned int invert = mc->invert;
295 bool type_2r = false;
296 unsigned int val2 = 0;
297 unsigned int val, val_mask;
300 mask = BIT(sign_bit + 1) - 1;
302 val = ((ucontrol->value.integer.value[0] + min) & mask);
305 val_mask = mask << shift;
307 if (snd_soc_volsw_is_stereo(mc)) {
308 val2 = ((ucontrol->value.integer.value[1] + min) & mask);
312 val_mask |= mask << rshift;
313 val |= val2 << rshift;
315 val2 = val2 << shift;
319 err = snd_soc_component_update_bits(component, reg, val_mask, val);
324 err = snd_soc_component_update_bits(component, reg2, val_mask,
329 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
332 * snd_soc_get_volsw_sx - single mixer get callback
333 * @kcontrol: mixer control
334 * @ucontrol: control element information
336 * Callback to get the value of a single mixer control, or a double mixer
337 * control that spans 2 registers.
339 * Returns 0 for success.
341 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol)
344 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
345 struct soc_mixer_control *mc =
346 (struct soc_mixer_control *)kcontrol->private_value;
347 unsigned int reg = mc->reg;
348 unsigned int reg2 = mc->rreg;
349 unsigned int shift = mc->shift;
350 unsigned int rshift = mc->rshift;
353 int mask = (1 << (fls(min + max) - 1)) - 1;
357 ret = snd_soc_component_read(component, reg, &val);
361 ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask;
363 if (snd_soc_volsw_is_stereo(mc)) {
364 ret = snd_soc_component_read(component, reg2, &val);
368 val = ((val >> rshift) - min) & mask;
369 ucontrol->value.integer.value[1] = val;
374 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
377 * snd_soc_put_volsw_sx - double mixer set callback
378 * @kcontrol: mixer control
379 * @uinfo: control element information
381 * Callback to set the value of a double mixer control that spans 2 registers.
383 * Returns 0 for success.
385 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_value *ucontrol)
388 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
389 struct soc_mixer_control *mc =
390 (struct soc_mixer_control *)kcontrol->private_value;
392 unsigned int reg = mc->reg;
393 unsigned int reg2 = mc->rreg;
394 unsigned int shift = mc->shift;
395 unsigned int rshift = mc->rshift;
398 int mask = (1 << (fls(min + max) - 1)) - 1;
400 unsigned int val, val_mask, val2 = 0;
402 val_mask = mask << shift;
403 val = (ucontrol->value.integer.value[0] + min) & mask;
406 err = snd_soc_component_update_bits(component, reg, val_mask, val);
410 if (snd_soc_volsw_is_stereo(mc)) {
411 val_mask = mask << rshift;
412 val2 = (ucontrol->value.integer.value[1] + min) & mask;
413 val2 = val2 << rshift;
415 err = snd_soc_component_update_bits(component, reg2, val_mask,
420 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
423 * snd_soc_info_volsw_range - single mixer info callback with range.
424 * @kcontrol: mixer control
425 * @uinfo: control element information
427 * Callback to provide information, within a range, about a single
430 * returns 0 for success.
432 int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_info *uinfo)
435 struct soc_mixer_control *mc =
436 (struct soc_mixer_control *)kcontrol->private_value;
440 if (!mc->platform_max)
441 mc->platform_max = mc->max;
442 platform_max = mc->platform_max;
444 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
445 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
446 uinfo->value.integer.min = 0;
447 uinfo->value.integer.max = platform_max - min;
451 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
454 * snd_soc_put_volsw_range - single mixer put value callback with range.
455 * @kcontrol: mixer control
456 * @ucontrol: control element information
458 * Callback to set the value, within a range, for a single mixer control.
460 * Returns 0 for success.
462 int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_value *ucontrol)
465 struct soc_mixer_control *mc =
466 (struct soc_mixer_control *)kcontrol->private_value;
467 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
468 unsigned int reg = mc->reg;
469 unsigned int rreg = mc->rreg;
470 unsigned int shift = mc->shift;
473 unsigned int mask = (1 << fls(max)) - 1;
474 unsigned int invert = mc->invert;
475 unsigned int val, val_mask;
479 val = (max - ucontrol->value.integer.value[0]) & mask;
481 val = ((ucontrol->value.integer.value[0] + min) & mask);
482 val_mask = mask << shift;
485 ret = snd_soc_component_update_bits(component, reg, val_mask, val);
489 if (snd_soc_volsw_is_stereo(mc)) {
491 val = (max - ucontrol->value.integer.value[1]) & mask;
493 val = ((ucontrol->value.integer.value[1] + min) & mask);
494 val_mask = mask << shift;
497 ret = snd_soc_component_update_bits(component, rreg, val_mask,
503 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
506 * snd_soc_get_volsw_range - single mixer get callback with range
507 * @kcontrol: mixer control
508 * @ucontrol: control element information
510 * Callback to get the value, within a range, of a single mixer control.
512 * Returns 0 for success.
514 int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
515 struct snd_ctl_elem_value *ucontrol)
517 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
518 struct soc_mixer_control *mc =
519 (struct soc_mixer_control *)kcontrol->private_value;
520 unsigned int reg = mc->reg;
521 unsigned int rreg = mc->rreg;
522 unsigned int shift = mc->shift;
525 unsigned int mask = (1 << fls(max)) - 1;
526 unsigned int invert = mc->invert;
530 ret = snd_soc_component_read(component, reg, &val);
534 ucontrol->value.integer.value[0] = (val >> shift) & mask;
536 ucontrol->value.integer.value[0] =
537 max - ucontrol->value.integer.value[0];
539 ucontrol->value.integer.value[0] =
540 ucontrol->value.integer.value[0] - min;
542 if (snd_soc_volsw_is_stereo(mc)) {
543 ret = snd_soc_component_read(component, rreg, &val);
547 ucontrol->value.integer.value[1] = (val >> shift) & mask;
549 ucontrol->value.integer.value[1] =
550 max - ucontrol->value.integer.value[1];
552 ucontrol->value.integer.value[1] =
553 ucontrol->value.integer.value[1] - min;
558 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
561 * snd_soc_limit_volume - Set new limit to an existing volume control.
563 * @codec: where to look for the control
564 * @name: Name of the control
565 * @max: new maximum limit
567 * Return 0 for success, else error.
569 int snd_soc_limit_volume(struct snd_soc_codec *codec,
570 const char *name, int max)
572 struct snd_card *card = codec->component.card->snd_card;
573 struct snd_kcontrol *kctl;
574 struct soc_mixer_control *mc;
578 /* Sanity check for name and max */
579 if (unlikely(!name || max <= 0))
582 list_for_each_entry(kctl, &card->controls, list) {
583 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
589 mc = (struct soc_mixer_control *)kctl->private_value;
590 if (max <= mc->max) {
591 mc->platform_max = max;
597 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
599 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
600 struct snd_ctl_elem_info *uinfo)
602 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
603 struct soc_bytes *params = (void *)kcontrol->private_value;
605 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
606 uinfo->count = params->num_regs * component->val_bytes;
610 EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
612 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
615 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
616 struct soc_bytes *params = (void *)kcontrol->private_value;
619 if (component->regmap)
620 ret = regmap_raw_read(component->regmap, params->base,
621 ucontrol->value.bytes.data,
622 params->num_regs * component->val_bytes);
626 /* Hide any masked bytes to ensure consistent data reporting */
627 if (ret == 0 && params->mask) {
628 switch (component->val_bytes) {
630 ucontrol->value.bytes.data[0] &= ~params->mask;
633 ((u16 *)(&ucontrol->value.bytes.data))[0]
634 &= cpu_to_be16(~params->mask);
637 ((u32 *)(&ucontrol->value.bytes.data))[0]
638 &= cpu_to_be32(~params->mask);
647 EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
649 int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol)
652 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
653 struct soc_bytes *params = (void *)kcontrol->private_value;
655 unsigned int val, mask;
658 if (!component->regmap || !params->num_regs)
661 len = params->num_regs * component->val_bytes;
663 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
668 * If we've got a mask then we need to preserve the register
669 * bits. We shouldn't modify the incoming data so take a
673 ret = regmap_read(component->regmap, params->base, &val);
679 switch (component->val_bytes) {
681 ((u8 *)data)[0] &= ~params->mask;
682 ((u8 *)data)[0] |= val;
685 mask = ~params->mask;
686 ret = regmap_parse_val(component->regmap,
691 ((u16 *)data)[0] &= mask;
693 ret = regmap_parse_val(component->regmap,
698 ((u16 *)data)[0] |= val;
701 mask = ~params->mask;
702 ret = regmap_parse_val(component->regmap,
707 ((u32 *)data)[0] &= mask;
709 ret = regmap_parse_val(component->regmap,
714 ((u32 *)data)[0] |= val;
722 ret = regmap_raw_write(component->regmap, params->base,
730 EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
732 int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
733 struct snd_ctl_elem_info *ucontrol)
735 struct soc_bytes_ext *params = (void *)kcontrol->private_value;
737 ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES;
738 ucontrol->count = params->max;
742 EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext);
744 int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
745 unsigned int size, unsigned int __user *tlv)
747 struct soc_bytes_ext *params = (void *)kcontrol->private_value;
748 unsigned int count = size < params->max ? size : params->max;
752 case SNDRV_CTL_TLV_OP_READ:
754 ret = params->get(tlv, count);
756 case SNDRV_CTL_TLV_OP_WRITE:
758 ret = params->put(tlv, count);
763 EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback);
766 * snd_soc_info_xr_sx - signed multi register info callback
767 * @kcontrol: mreg control
768 * @uinfo: control element information
770 * Callback to provide information of a control that can
771 * span multiple codec registers which together
772 * forms a single signed value in a MSB/LSB manner.
774 * Returns 0 for success.
776 int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_info *uinfo)
779 struct soc_mreg_control *mc =
780 (struct soc_mreg_control *)kcontrol->private_value;
781 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
783 uinfo->value.integer.min = mc->min;
784 uinfo->value.integer.max = mc->max;
788 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
791 * snd_soc_get_xr_sx - signed multi register get callback
792 * @kcontrol: mreg control
793 * @ucontrol: control element information
795 * Callback to get the value of a control that can span
796 * multiple codec registers which together forms a single
797 * signed value in a MSB/LSB manner. The control supports
798 * specifying total no of bits used to allow for bitfields
799 * across the multiple codec registers.
801 * Returns 0 for success.
803 int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
804 struct snd_ctl_elem_value *ucontrol)
806 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
807 struct soc_mreg_control *mc =
808 (struct soc_mreg_control *)kcontrol->private_value;
809 unsigned int regbase = mc->regbase;
810 unsigned int regcount = mc->regcount;
811 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
812 unsigned int regwmask = (1<<regwshift)-1;
813 unsigned int invert = mc->invert;
814 unsigned long mask = (1UL<<mc->nbits)-1;
822 for (i = 0; i < regcount; i++) {
823 ret = snd_soc_component_read(component, regbase+i, ®val);
826 val |= (regval & regwmask) << (regwshift*(regcount-i-1));
829 if (min < 0 && val > max)
833 ucontrol->value.integer.value[0] = val;
837 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
840 * snd_soc_put_xr_sx - signed multi register get callback
841 * @kcontrol: mreg control
842 * @ucontrol: control element information
844 * Callback to set the value of a control that can span
845 * multiple codec registers which together forms a single
846 * signed value in a MSB/LSB manner. The control supports
847 * specifying total no of bits used to allow for bitfields
848 * across the multiple codec registers.
850 * Returns 0 for success.
852 int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
853 struct snd_ctl_elem_value *ucontrol)
855 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
856 struct soc_mreg_control *mc =
857 (struct soc_mreg_control *)kcontrol->private_value;
858 unsigned int regbase = mc->regbase;
859 unsigned int regcount = mc->regcount;
860 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
861 unsigned int regwmask = (1<<regwshift)-1;
862 unsigned int invert = mc->invert;
863 unsigned long mask = (1UL<<mc->nbits)-1;
865 long val = ucontrol->value.integer.value[0];
866 unsigned int i, regval, regmask;
872 for (i = 0; i < regcount; i++) {
873 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
874 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
875 err = snd_soc_component_update_bits(component, regbase+i,
883 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
886 * snd_soc_get_strobe - strobe get callback
887 * @kcontrol: mixer control
888 * @ucontrol: control element information
890 * Callback get the value of a strobe mixer control.
892 * Returns 0 for success.
894 int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
895 struct snd_ctl_elem_value *ucontrol)
897 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
898 struct soc_mixer_control *mc =
899 (struct soc_mixer_control *)kcontrol->private_value;
900 unsigned int reg = mc->reg;
901 unsigned int shift = mc->shift;
902 unsigned int mask = 1 << shift;
903 unsigned int invert = mc->invert != 0;
907 ret = snd_soc_component_read(component, reg, &val);
913 if (shift != 0 && val != 0)
915 ucontrol->value.enumerated.item[0] = val ^ invert;
919 EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
922 * snd_soc_put_strobe - strobe put callback
923 * @kcontrol: mixer control
924 * @ucontrol: control element information
926 * Callback strobe a register bit to high then low (or the inverse)
927 * in one pass of a single mixer enum control.
929 * Returns 1 for success.
931 int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
932 struct snd_ctl_elem_value *ucontrol)
934 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
935 struct soc_mixer_control *mc =
936 (struct soc_mixer_control *)kcontrol->private_value;
937 unsigned int reg = mc->reg;
938 unsigned int shift = mc->shift;
939 unsigned int mask = 1 << shift;
940 unsigned int invert = mc->invert != 0;
941 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
942 unsigned int val1 = (strobe ^ invert) ? mask : 0;
943 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
946 err = snd_soc_component_update_bits(component, reg, mask, val1);
950 return snd_soc_component_update_bits(component, reg, mask, val2);
952 EXPORT_SYMBOL_GPL(snd_soc_put_strobe);