diff options
author | Mark Brown <broonie@kernel.org> | 2014-10-28 18:15:31 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2014-10-29 07:15:10 -0400 |
commit | 7077148fb50a120d20a50516a332ed6eb9233c16 (patch) | |
tree | c057c8f5ef91ed7191e92bebe65d691b022fb405 /sound/soc/soc-core.c | |
parent | c1b4d1c7774189002bc08766ec10e339dfbc98d6 (diff) |
ASoC: core: Split ops out of soc-core.c
The main ASoC source file is getting quite large and the standard ops don't
really have anything to do with the rest of the file so split them out into
a separate file.
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r-- | sound/soc/soc-core.c | 919 |
1 files changed, 0 insertions, 919 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 47c378abb9a2..a2b51edf6d83 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -2334,925 +2334,6 @@ int snd_soc_add_dai_controls(struct snd_soc_dai *dai, | |||
2334 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); | 2334 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); |
2335 | 2335 | ||
2336 | /** | 2336 | /** |
2337 | * snd_soc_info_enum_double - enumerated double mixer info callback | ||
2338 | * @kcontrol: mixer control | ||
2339 | * @uinfo: control element information | ||
2340 | * | ||
2341 | * Callback to provide information about a double enumerated | ||
2342 | * mixer control. | ||
2343 | * | ||
2344 | * Returns 0 for success. | ||
2345 | */ | ||
2346 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, | ||
2347 | struct snd_ctl_elem_info *uinfo) | ||
2348 | { | ||
2349 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | ||
2350 | |||
2351 | return snd_ctl_enum_info(uinfo, e->shift_l == e->shift_r ? 1 : 2, | ||
2352 | e->items, e->texts); | ||
2353 | } | ||
2354 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); | ||
2355 | |||
2356 | /** | ||
2357 | * snd_soc_get_enum_double - enumerated double mixer get callback | ||
2358 | * @kcontrol: mixer control | ||
2359 | * @ucontrol: control element information | ||
2360 | * | ||
2361 | * Callback to get the value of a double enumerated mixer. | ||
2362 | * | ||
2363 | * Returns 0 for success. | ||
2364 | */ | ||
2365 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, | ||
2366 | struct snd_ctl_elem_value *ucontrol) | ||
2367 | { | ||
2368 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2369 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | ||
2370 | unsigned int val, item; | ||
2371 | unsigned int reg_val; | ||
2372 | int ret; | ||
2373 | |||
2374 | ret = snd_soc_component_read(component, e->reg, ®_val); | ||
2375 | if (ret) | ||
2376 | return ret; | ||
2377 | val = (reg_val >> e->shift_l) & e->mask; | ||
2378 | item = snd_soc_enum_val_to_item(e, val); | ||
2379 | ucontrol->value.enumerated.item[0] = item; | ||
2380 | if (e->shift_l != e->shift_r) { | ||
2381 | val = (reg_val >> e->shift_l) & e->mask; | ||
2382 | item = snd_soc_enum_val_to_item(e, val); | ||
2383 | ucontrol->value.enumerated.item[1] = item; | ||
2384 | } | ||
2385 | |||
2386 | return 0; | ||
2387 | } | ||
2388 | EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); | ||
2389 | |||
2390 | /** | ||
2391 | * snd_soc_put_enum_double - enumerated double mixer put callback | ||
2392 | * @kcontrol: mixer control | ||
2393 | * @ucontrol: control element information | ||
2394 | * | ||
2395 | * Callback to set the value of a double enumerated mixer. | ||
2396 | * | ||
2397 | * Returns 0 for success. | ||
2398 | */ | ||
2399 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, | ||
2400 | struct snd_ctl_elem_value *ucontrol) | ||
2401 | { | ||
2402 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2403 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | ||
2404 | unsigned int *item = ucontrol->value.enumerated.item; | ||
2405 | unsigned int val; | ||
2406 | unsigned int mask; | ||
2407 | |||
2408 | if (item[0] >= e->items) | ||
2409 | return -EINVAL; | ||
2410 | val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; | ||
2411 | mask = e->mask << e->shift_l; | ||
2412 | if (e->shift_l != e->shift_r) { | ||
2413 | if (item[1] >= e->items) | ||
2414 | return -EINVAL; | ||
2415 | val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; | ||
2416 | mask |= e->mask << e->shift_r; | ||
2417 | } | ||
2418 | |||
2419 | return snd_soc_component_update_bits(component, e->reg, mask, val); | ||
2420 | } | ||
2421 | EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); | ||
2422 | |||
2423 | /** | ||
2424 | * snd_soc_read_signed - Read a codec register and interprete as signed value | ||
2425 | * @component: component | ||
2426 | * @reg: Register to read | ||
2427 | * @mask: Mask to use after shifting the register value | ||
2428 | * @shift: Right shift of register value | ||
2429 | * @sign_bit: Bit that describes if a number is negative or not. | ||
2430 | * @signed_val: Pointer to where the read value should be stored | ||
2431 | * | ||
2432 | * This functions reads a codec register. The register value is shifted right | ||
2433 | * by 'shift' bits and masked with the given 'mask'. Afterwards it translates | ||
2434 | * the given registervalue into a signed integer if sign_bit is non-zero. | ||
2435 | * | ||
2436 | * Returns 0 on sucess, otherwise an error value | ||
2437 | */ | ||
2438 | static int snd_soc_read_signed(struct snd_soc_component *component, | ||
2439 | unsigned int reg, unsigned int mask, unsigned int shift, | ||
2440 | unsigned int sign_bit, int *signed_val) | ||
2441 | { | ||
2442 | int ret; | ||
2443 | unsigned int val; | ||
2444 | |||
2445 | ret = snd_soc_component_read(component, reg, &val); | ||
2446 | if (ret < 0) | ||
2447 | return ret; | ||
2448 | |||
2449 | val = (val >> shift) & mask; | ||
2450 | |||
2451 | if (!sign_bit) { | ||
2452 | *signed_val = val; | ||
2453 | return 0; | ||
2454 | } | ||
2455 | |||
2456 | /* non-negative number */ | ||
2457 | if (!(val & BIT(sign_bit))) { | ||
2458 | *signed_val = val; | ||
2459 | return 0; | ||
2460 | } | ||
2461 | |||
2462 | ret = val; | ||
2463 | |||
2464 | /* | ||
2465 | * The register most probably does not contain a full-sized int. | ||
2466 | * Instead we have an arbitrary number of bits in a signed | ||
2467 | * representation which has to be translated into a full-sized int. | ||
2468 | * This is done by filling up all bits above the sign-bit. | ||
2469 | */ | ||
2470 | ret |= ~((int)(BIT(sign_bit) - 1)); | ||
2471 | |||
2472 | *signed_val = ret; | ||
2473 | |||
2474 | return 0; | ||
2475 | } | ||
2476 | |||
2477 | /** | ||
2478 | * snd_soc_info_volsw - single mixer info callback | ||
2479 | * @kcontrol: mixer control | ||
2480 | * @uinfo: control element information | ||
2481 | * | ||
2482 | * Callback to provide information about a single mixer control, or a double | ||
2483 | * mixer control that spans 2 registers. | ||
2484 | * | ||
2485 | * Returns 0 for success. | ||
2486 | */ | ||
2487 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, | ||
2488 | struct snd_ctl_elem_info *uinfo) | ||
2489 | { | ||
2490 | struct soc_mixer_control *mc = | ||
2491 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2492 | int platform_max; | ||
2493 | |||
2494 | if (!mc->platform_max) | ||
2495 | mc->platform_max = mc->max; | ||
2496 | platform_max = mc->platform_max; | ||
2497 | |||
2498 | if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) | ||
2499 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | ||
2500 | else | ||
2501 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
2502 | |||
2503 | uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; | ||
2504 | uinfo->value.integer.min = 0; | ||
2505 | uinfo->value.integer.max = platform_max - mc->min; | ||
2506 | return 0; | ||
2507 | } | ||
2508 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw); | ||
2509 | |||
2510 | /** | ||
2511 | * snd_soc_get_volsw - single mixer get callback | ||
2512 | * @kcontrol: mixer control | ||
2513 | * @ucontrol: control element information | ||
2514 | * | ||
2515 | * Callback to get the value of a single mixer control, or a double mixer | ||
2516 | * control that spans 2 registers. | ||
2517 | * | ||
2518 | * Returns 0 for success. | ||
2519 | */ | ||
2520 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, | ||
2521 | struct snd_ctl_elem_value *ucontrol) | ||
2522 | { | ||
2523 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2524 | struct soc_mixer_control *mc = | ||
2525 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2526 | unsigned int reg = mc->reg; | ||
2527 | unsigned int reg2 = mc->rreg; | ||
2528 | unsigned int shift = mc->shift; | ||
2529 | unsigned int rshift = mc->rshift; | ||
2530 | int max = mc->max; | ||
2531 | int min = mc->min; | ||
2532 | int sign_bit = mc->sign_bit; | ||
2533 | unsigned int mask = (1 << fls(max)) - 1; | ||
2534 | unsigned int invert = mc->invert; | ||
2535 | int val; | ||
2536 | int ret; | ||
2537 | |||
2538 | if (sign_bit) | ||
2539 | mask = BIT(sign_bit + 1) - 1; | ||
2540 | |||
2541 | ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val); | ||
2542 | if (ret) | ||
2543 | return ret; | ||
2544 | |||
2545 | ucontrol->value.integer.value[0] = val - min; | ||
2546 | if (invert) | ||
2547 | ucontrol->value.integer.value[0] = | ||
2548 | max - ucontrol->value.integer.value[0]; | ||
2549 | |||
2550 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2551 | if (reg == reg2) | ||
2552 | ret = snd_soc_read_signed(component, reg, mask, rshift, | ||
2553 | sign_bit, &val); | ||
2554 | else | ||
2555 | ret = snd_soc_read_signed(component, reg2, mask, shift, | ||
2556 | sign_bit, &val); | ||
2557 | if (ret) | ||
2558 | return ret; | ||
2559 | |||
2560 | ucontrol->value.integer.value[1] = val - min; | ||
2561 | if (invert) | ||
2562 | ucontrol->value.integer.value[1] = | ||
2563 | max - ucontrol->value.integer.value[1]; | ||
2564 | } | ||
2565 | |||
2566 | return 0; | ||
2567 | } | ||
2568 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw); | ||
2569 | |||
2570 | /** | ||
2571 | * snd_soc_put_volsw - single mixer put callback | ||
2572 | * @kcontrol: mixer control | ||
2573 | * @ucontrol: control element information | ||
2574 | * | ||
2575 | * Callback to set the value of a single mixer control, or a double mixer | ||
2576 | * control that spans 2 registers. | ||
2577 | * | ||
2578 | * Returns 0 for success. | ||
2579 | */ | ||
2580 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, | ||
2581 | struct snd_ctl_elem_value *ucontrol) | ||
2582 | { | ||
2583 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2584 | struct soc_mixer_control *mc = | ||
2585 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2586 | unsigned int reg = mc->reg; | ||
2587 | unsigned int reg2 = mc->rreg; | ||
2588 | unsigned int shift = mc->shift; | ||
2589 | unsigned int rshift = mc->rshift; | ||
2590 | int max = mc->max; | ||
2591 | int min = mc->min; | ||
2592 | unsigned int sign_bit = mc->sign_bit; | ||
2593 | unsigned int mask = (1 << fls(max)) - 1; | ||
2594 | unsigned int invert = mc->invert; | ||
2595 | int err; | ||
2596 | bool type_2r = false; | ||
2597 | unsigned int val2 = 0; | ||
2598 | unsigned int val, val_mask; | ||
2599 | |||
2600 | if (sign_bit) | ||
2601 | mask = BIT(sign_bit + 1) - 1; | ||
2602 | |||
2603 | val = ((ucontrol->value.integer.value[0] + min) & mask); | ||
2604 | if (invert) | ||
2605 | val = max - val; | ||
2606 | val_mask = mask << shift; | ||
2607 | val = val << shift; | ||
2608 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2609 | val2 = ((ucontrol->value.integer.value[1] + min) & mask); | ||
2610 | if (invert) | ||
2611 | val2 = max - val2; | ||
2612 | if (reg == reg2) { | ||
2613 | val_mask |= mask << rshift; | ||
2614 | val |= val2 << rshift; | ||
2615 | } else { | ||
2616 | val2 = val2 << shift; | ||
2617 | type_2r = true; | ||
2618 | } | ||
2619 | } | ||
2620 | err = snd_soc_component_update_bits(component, reg, val_mask, val); | ||
2621 | if (err < 0) | ||
2622 | return err; | ||
2623 | |||
2624 | if (type_2r) | ||
2625 | err = snd_soc_component_update_bits(component, reg2, val_mask, | ||
2626 | val2); | ||
2627 | |||
2628 | return err; | ||
2629 | } | ||
2630 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); | ||
2631 | |||
2632 | /** | ||
2633 | * snd_soc_get_volsw_sx - single mixer get callback | ||
2634 | * @kcontrol: mixer control | ||
2635 | * @ucontrol: control element information | ||
2636 | * | ||
2637 | * Callback to get the value of a single mixer control, or a double mixer | ||
2638 | * control that spans 2 registers. | ||
2639 | * | ||
2640 | * Returns 0 for success. | ||
2641 | */ | ||
2642 | int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, | ||
2643 | struct snd_ctl_elem_value *ucontrol) | ||
2644 | { | ||
2645 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2646 | struct soc_mixer_control *mc = | ||
2647 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2648 | unsigned int reg = mc->reg; | ||
2649 | unsigned int reg2 = mc->rreg; | ||
2650 | unsigned int shift = mc->shift; | ||
2651 | unsigned int rshift = mc->rshift; | ||
2652 | int max = mc->max; | ||
2653 | int min = mc->min; | ||
2654 | int mask = (1 << (fls(min + max) - 1)) - 1; | ||
2655 | unsigned int val; | ||
2656 | int ret; | ||
2657 | |||
2658 | ret = snd_soc_component_read(component, reg, &val); | ||
2659 | if (ret < 0) | ||
2660 | return ret; | ||
2661 | |||
2662 | ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask; | ||
2663 | |||
2664 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2665 | ret = snd_soc_component_read(component, reg2, &val); | ||
2666 | if (ret < 0) | ||
2667 | return ret; | ||
2668 | |||
2669 | val = ((val >> rshift) - min) & mask; | ||
2670 | ucontrol->value.integer.value[1] = val; | ||
2671 | } | ||
2672 | |||
2673 | return 0; | ||
2674 | } | ||
2675 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx); | ||
2676 | |||
2677 | /** | ||
2678 | * snd_soc_put_volsw_sx - double mixer set callback | ||
2679 | * @kcontrol: mixer control | ||
2680 | * @uinfo: control element information | ||
2681 | * | ||
2682 | * Callback to set the value of a double mixer control that spans 2 registers. | ||
2683 | * | ||
2684 | * Returns 0 for success. | ||
2685 | */ | ||
2686 | int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, | ||
2687 | struct snd_ctl_elem_value *ucontrol) | ||
2688 | { | ||
2689 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2690 | struct soc_mixer_control *mc = | ||
2691 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2692 | |||
2693 | unsigned int reg = mc->reg; | ||
2694 | unsigned int reg2 = mc->rreg; | ||
2695 | unsigned int shift = mc->shift; | ||
2696 | unsigned int rshift = mc->rshift; | ||
2697 | int max = mc->max; | ||
2698 | int min = mc->min; | ||
2699 | int mask = (1 << (fls(min + max) - 1)) - 1; | ||
2700 | int err = 0; | ||
2701 | unsigned int val, val_mask, val2 = 0; | ||
2702 | |||
2703 | val_mask = mask << shift; | ||
2704 | val = (ucontrol->value.integer.value[0] + min) & mask; | ||
2705 | val = val << shift; | ||
2706 | |||
2707 | err = snd_soc_component_update_bits(component, reg, val_mask, val); | ||
2708 | if (err < 0) | ||
2709 | return err; | ||
2710 | |||
2711 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2712 | val_mask = mask << rshift; | ||
2713 | val2 = (ucontrol->value.integer.value[1] + min) & mask; | ||
2714 | val2 = val2 << rshift; | ||
2715 | |||
2716 | err = snd_soc_component_update_bits(component, reg2, val_mask, | ||
2717 | val2); | ||
2718 | } | ||
2719 | return err; | ||
2720 | } | ||
2721 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); | ||
2722 | |||
2723 | /** | ||
2724 | * snd_soc_info_volsw_range - single mixer info callback with range. | ||
2725 | * @kcontrol: mixer control | ||
2726 | * @uinfo: control element information | ||
2727 | * | ||
2728 | * Callback to provide information, within a range, about a single | ||
2729 | * mixer control. | ||
2730 | * | ||
2731 | * returns 0 for success. | ||
2732 | */ | ||
2733 | int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, | ||
2734 | struct snd_ctl_elem_info *uinfo) | ||
2735 | { | ||
2736 | struct soc_mixer_control *mc = | ||
2737 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2738 | int platform_max; | ||
2739 | int min = mc->min; | ||
2740 | |||
2741 | if (!mc->platform_max) | ||
2742 | mc->platform_max = mc->max; | ||
2743 | platform_max = mc->platform_max; | ||
2744 | |||
2745 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
2746 | uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; | ||
2747 | uinfo->value.integer.min = 0; | ||
2748 | uinfo->value.integer.max = platform_max - min; | ||
2749 | |||
2750 | return 0; | ||
2751 | } | ||
2752 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range); | ||
2753 | |||
2754 | /** | ||
2755 | * snd_soc_put_volsw_range - single mixer put value callback with range. | ||
2756 | * @kcontrol: mixer control | ||
2757 | * @ucontrol: control element information | ||
2758 | * | ||
2759 | * Callback to set the value, within a range, for a single mixer control. | ||
2760 | * | ||
2761 | * Returns 0 for success. | ||
2762 | */ | ||
2763 | int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, | ||
2764 | struct snd_ctl_elem_value *ucontrol) | ||
2765 | { | ||
2766 | struct soc_mixer_control *mc = | ||
2767 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2768 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2769 | unsigned int reg = mc->reg; | ||
2770 | unsigned int rreg = mc->rreg; | ||
2771 | unsigned int shift = mc->shift; | ||
2772 | int min = mc->min; | ||
2773 | int max = mc->max; | ||
2774 | unsigned int mask = (1 << fls(max)) - 1; | ||
2775 | unsigned int invert = mc->invert; | ||
2776 | unsigned int val, val_mask; | ||
2777 | int ret; | ||
2778 | |||
2779 | if (invert) | ||
2780 | val = (max - ucontrol->value.integer.value[0]) & mask; | ||
2781 | else | ||
2782 | val = ((ucontrol->value.integer.value[0] + min) & mask); | ||
2783 | val_mask = mask << shift; | ||
2784 | val = val << shift; | ||
2785 | |||
2786 | ret = snd_soc_component_update_bits(component, reg, val_mask, val); | ||
2787 | if (ret < 0) | ||
2788 | return ret; | ||
2789 | |||
2790 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2791 | if (invert) | ||
2792 | val = (max - ucontrol->value.integer.value[1]) & mask; | ||
2793 | else | ||
2794 | val = ((ucontrol->value.integer.value[1] + min) & mask); | ||
2795 | val_mask = mask << shift; | ||
2796 | val = val << shift; | ||
2797 | |||
2798 | ret = snd_soc_component_update_bits(component, rreg, val_mask, | ||
2799 | val); | ||
2800 | } | ||
2801 | |||
2802 | return ret; | ||
2803 | } | ||
2804 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range); | ||
2805 | |||
2806 | /** | ||
2807 | * snd_soc_get_volsw_range - single mixer get callback with range | ||
2808 | * @kcontrol: mixer control | ||
2809 | * @ucontrol: control element information | ||
2810 | * | ||
2811 | * Callback to get the value, within a range, of a single mixer control. | ||
2812 | * | ||
2813 | * Returns 0 for success. | ||
2814 | */ | ||
2815 | int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, | ||
2816 | struct snd_ctl_elem_value *ucontrol) | ||
2817 | { | ||
2818 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2819 | struct soc_mixer_control *mc = | ||
2820 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2821 | unsigned int reg = mc->reg; | ||
2822 | unsigned int rreg = mc->rreg; | ||
2823 | unsigned int shift = mc->shift; | ||
2824 | int min = mc->min; | ||
2825 | int max = mc->max; | ||
2826 | unsigned int mask = (1 << fls(max)) - 1; | ||
2827 | unsigned int invert = mc->invert; | ||
2828 | unsigned int val; | ||
2829 | int ret; | ||
2830 | |||
2831 | ret = snd_soc_component_read(component, reg, &val); | ||
2832 | if (ret) | ||
2833 | return ret; | ||
2834 | |||
2835 | ucontrol->value.integer.value[0] = (val >> shift) & mask; | ||
2836 | if (invert) | ||
2837 | ucontrol->value.integer.value[0] = | ||
2838 | max - ucontrol->value.integer.value[0]; | ||
2839 | else | ||
2840 | ucontrol->value.integer.value[0] = | ||
2841 | ucontrol->value.integer.value[0] - min; | ||
2842 | |||
2843 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2844 | ret = snd_soc_component_read(component, rreg, &val); | ||
2845 | if (ret) | ||
2846 | return ret; | ||
2847 | |||
2848 | ucontrol->value.integer.value[1] = (val >> shift) & mask; | ||
2849 | if (invert) | ||
2850 | ucontrol->value.integer.value[1] = | ||
2851 | max - ucontrol->value.integer.value[1]; | ||
2852 | else | ||
2853 | ucontrol->value.integer.value[1] = | ||
2854 | ucontrol->value.integer.value[1] - min; | ||
2855 | } | ||
2856 | |||
2857 | return 0; | ||
2858 | } | ||
2859 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); | ||
2860 | |||
2861 | /** | ||
2862 | * snd_soc_limit_volume - Set new limit to an existing volume control. | ||
2863 | * | ||
2864 | * @codec: where to look for the control | ||
2865 | * @name: Name of the control | ||
2866 | * @max: new maximum limit | ||
2867 | * | ||
2868 | * Return 0 for success, else error. | ||
2869 | */ | ||
2870 | int snd_soc_limit_volume(struct snd_soc_codec *codec, | ||
2871 | const char *name, int max) | ||
2872 | { | ||
2873 | struct snd_card *card = codec->component.card->snd_card; | ||
2874 | struct snd_kcontrol *kctl; | ||
2875 | struct soc_mixer_control *mc; | ||
2876 | int found = 0; | ||
2877 | int ret = -EINVAL; | ||
2878 | |||
2879 | /* Sanity check for name and max */ | ||
2880 | if (unlikely(!name || max <= 0)) | ||
2881 | return -EINVAL; | ||
2882 | |||
2883 | list_for_each_entry(kctl, &card->controls, list) { | ||
2884 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { | ||
2885 | found = 1; | ||
2886 | break; | ||
2887 | } | ||
2888 | } | ||
2889 | if (found) { | ||
2890 | mc = (struct soc_mixer_control *)kctl->private_value; | ||
2891 | if (max <= mc->max) { | ||
2892 | mc->platform_max = max; | ||
2893 | ret = 0; | ||
2894 | } | ||
2895 | } | ||
2896 | return ret; | ||
2897 | } | ||
2898 | EXPORT_SYMBOL_GPL(snd_soc_limit_volume); | ||
2899 | |||
2900 | int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, | ||
2901 | struct snd_ctl_elem_info *uinfo) | ||
2902 | { | ||
2903 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2904 | struct soc_bytes *params = (void *)kcontrol->private_value; | ||
2905 | |||
2906 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; | ||
2907 | uinfo->count = params->num_regs * component->val_bytes; | ||
2908 | |||
2909 | return 0; | ||
2910 | } | ||
2911 | EXPORT_SYMBOL_GPL(snd_soc_bytes_info); | ||
2912 | |||
2913 | int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, | ||
2914 | struct snd_ctl_elem_value *ucontrol) | ||
2915 | { | ||
2916 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2917 | struct soc_bytes *params = (void *)kcontrol->private_value; | ||
2918 | int ret; | ||
2919 | |||
2920 | if (component->regmap) | ||
2921 | ret = regmap_raw_read(component->regmap, params->base, | ||
2922 | ucontrol->value.bytes.data, | ||
2923 | params->num_regs * component->val_bytes); | ||
2924 | else | ||
2925 | ret = -EINVAL; | ||
2926 | |||
2927 | /* Hide any masked bytes to ensure consistent data reporting */ | ||
2928 | if (ret == 0 && params->mask) { | ||
2929 | switch (component->val_bytes) { | ||
2930 | case 1: | ||
2931 | ucontrol->value.bytes.data[0] &= ~params->mask; | ||
2932 | break; | ||
2933 | case 2: | ||
2934 | ((u16 *)(&ucontrol->value.bytes.data))[0] | ||
2935 | &= cpu_to_be16(~params->mask); | ||
2936 | break; | ||
2937 | case 4: | ||
2938 | ((u32 *)(&ucontrol->value.bytes.data))[0] | ||
2939 | &= cpu_to_be32(~params->mask); | ||
2940 | break; | ||
2941 | default: | ||
2942 | return -EINVAL; | ||
2943 | } | ||
2944 | } | ||
2945 | |||
2946 | return ret; | ||
2947 | } | ||
2948 | EXPORT_SYMBOL_GPL(snd_soc_bytes_get); | ||
2949 | |||
2950 | int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, | ||
2951 | struct snd_ctl_elem_value *ucontrol) | ||
2952 | { | ||
2953 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
2954 | struct soc_bytes *params = (void *)kcontrol->private_value; | ||
2955 | int ret, len; | ||
2956 | unsigned int val, mask; | ||
2957 | void *data; | ||
2958 | |||
2959 | if (!component->regmap || !params->num_regs) | ||
2960 | return -EINVAL; | ||
2961 | |||
2962 | len = params->num_regs * component->val_bytes; | ||
2963 | |||
2964 | data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); | ||
2965 | if (!data) | ||
2966 | return -ENOMEM; | ||
2967 | |||
2968 | /* | ||
2969 | * If we've got a mask then we need to preserve the register | ||
2970 | * bits. We shouldn't modify the incoming data so take a | ||
2971 | * copy. | ||
2972 | */ | ||
2973 | if (params->mask) { | ||
2974 | ret = regmap_read(component->regmap, params->base, &val); | ||
2975 | if (ret != 0) | ||
2976 | goto out; | ||
2977 | |||
2978 | val &= params->mask; | ||
2979 | |||
2980 | switch (component->val_bytes) { | ||
2981 | case 1: | ||
2982 | ((u8 *)data)[0] &= ~params->mask; | ||
2983 | ((u8 *)data)[0] |= val; | ||
2984 | break; | ||
2985 | case 2: | ||
2986 | mask = ~params->mask; | ||
2987 | ret = regmap_parse_val(component->regmap, | ||
2988 | &mask, &mask); | ||
2989 | if (ret != 0) | ||
2990 | goto out; | ||
2991 | |||
2992 | ((u16 *)data)[0] &= mask; | ||
2993 | |||
2994 | ret = regmap_parse_val(component->regmap, | ||
2995 | &val, &val); | ||
2996 | if (ret != 0) | ||
2997 | goto out; | ||
2998 | |||
2999 | ((u16 *)data)[0] |= val; | ||
3000 | break; | ||
3001 | case 4: | ||
3002 | mask = ~params->mask; | ||
3003 | ret = regmap_parse_val(component->regmap, | ||
3004 | &mask, &mask); | ||
3005 | if (ret != 0) | ||
3006 | goto out; | ||
3007 | |||
3008 | ((u32 *)data)[0] &= mask; | ||
3009 | |||
3010 | ret = regmap_parse_val(component->regmap, | ||
3011 | &val, &val); | ||
3012 | if (ret != 0) | ||
3013 | goto out; | ||
3014 | |||
3015 | ((u32 *)data)[0] |= val; | ||
3016 | break; | ||
3017 | default: | ||
3018 | ret = -EINVAL; | ||
3019 | goto out; | ||
3020 | } | ||
3021 | } | ||
3022 | |||
3023 | ret = regmap_raw_write(component->regmap, params->base, | ||
3024 | data, len); | ||
3025 | |||
3026 | out: | ||
3027 | kfree(data); | ||
3028 | |||
3029 | return ret; | ||
3030 | } | ||
3031 | EXPORT_SYMBOL_GPL(snd_soc_bytes_put); | ||
3032 | |||
3033 | int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol, | ||
3034 | struct snd_ctl_elem_info *ucontrol) | ||
3035 | { | ||
3036 | struct soc_bytes_ext *params = (void *)kcontrol->private_value; | ||
3037 | |||
3038 | ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES; | ||
3039 | ucontrol->count = params->max; | ||
3040 | |||
3041 | return 0; | ||
3042 | } | ||
3043 | EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext); | ||
3044 | |||
3045 | int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, | ||
3046 | unsigned int size, unsigned int __user *tlv) | ||
3047 | { | ||
3048 | struct soc_bytes_ext *params = (void *)kcontrol->private_value; | ||
3049 | unsigned int count = size < params->max ? size : params->max; | ||
3050 | int ret = -ENXIO; | ||
3051 | |||
3052 | switch (op_flag) { | ||
3053 | case SNDRV_CTL_TLV_OP_READ: | ||
3054 | if (params->get) | ||
3055 | ret = params->get(tlv, count); | ||
3056 | break; | ||
3057 | case SNDRV_CTL_TLV_OP_WRITE: | ||
3058 | if (params->put) | ||
3059 | ret = params->put(tlv, count); | ||
3060 | break; | ||
3061 | } | ||
3062 | return ret; | ||
3063 | } | ||
3064 | EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback); | ||
3065 | |||
3066 | /** | ||
3067 | * snd_soc_info_xr_sx - signed multi register info callback | ||
3068 | * @kcontrol: mreg control | ||
3069 | * @uinfo: control element information | ||
3070 | * | ||
3071 | * Callback to provide information of a control that can | ||
3072 | * span multiple codec registers which together | ||
3073 | * forms a single signed value in a MSB/LSB manner. | ||
3074 | * | ||
3075 | * Returns 0 for success. | ||
3076 | */ | ||
3077 | int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, | ||
3078 | struct snd_ctl_elem_info *uinfo) | ||
3079 | { | ||
3080 | struct soc_mreg_control *mc = | ||
3081 | (struct soc_mreg_control *)kcontrol->private_value; | ||
3082 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
3083 | uinfo->count = 1; | ||
3084 | uinfo->value.integer.min = mc->min; | ||
3085 | uinfo->value.integer.max = mc->max; | ||
3086 | |||
3087 | return 0; | ||
3088 | } | ||
3089 | EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx); | ||
3090 | |||
3091 | /** | ||
3092 | * snd_soc_get_xr_sx - signed multi register get callback | ||
3093 | * @kcontrol: mreg control | ||
3094 | * @ucontrol: control element information | ||
3095 | * | ||
3096 | * Callback to get the value of a control that can span | ||
3097 | * multiple codec registers which together forms a single | ||
3098 | * signed value in a MSB/LSB manner. The control supports | ||
3099 | * specifying total no of bits used to allow for bitfields | ||
3100 | * across the multiple codec registers. | ||
3101 | * | ||
3102 | * Returns 0 for success. | ||
3103 | */ | ||
3104 | int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, | ||
3105 | struct snd_ctl_elem_value *ucontrol) | ||
3106 | { | ||
3107 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
3108 | struct soc_mreg_control *mc = | ||
3109 | (struct soc_mreg_control *)kcontrol->private_value; | ||
3110 | unsigned int regbase = mc->regbase; | ||
3111 | unsigned int regcount = mc->regcount; | ||
3112 | unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; | ||
3113 | unsigned int regwmask = (1<<regwshift)-1; | ||
3114 | unsigned int invert = mc->invert; | ||
3115 | unsigned long mask = (1UL<<mc->nbits)-1; | ||
3116 | long min = mc->min; | ||
3117 | long max = mc->max; | ||
3118 | long val = 0; | ||
3119 | unsigned int regval; | ||
3120 | unsigned int i; | ||
3121 | int ret; | ||
3122 | |||
3123 | for (i = 0; i < regcount; i++) { | ||
3124 | ret = snd_soc_component_read(component, regbase+i, ®val); | ||
3125 | if (ret) | ||
3126 | return ret; | ||
3127 | val |= (regval & regwmask) << (regwshift*(regcount-i-1)); | ||
3128 | } | ||
3129 | val &= mask; | ||
3130 | if (min < 0 && val > max) | ||
3131 | val |= ~mask; | ||
3132 | if (invert) | ||
3133 | val = max - val; | ||
3134 | ucontrol->value.integer.value[0] = val; | ||
3135 | |||
3136 | return 0; | ||
3137 | } | ||
3138 | EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx); | ||
3139 | |||
3140 | /** | ||
3141 | * snd_soc_put_xr_sx - signed multi register get callback | ||
3142 | * @kcontrol: mreg control | ||
3143 | * @ucontrol: control element information | ||
3144 | * | ||
3145 | * Callback to set the value of a control that can span | ||
3146 | * multiple codec registers which together forms a single | ||
3147 | * signed value in a MSB/LSB manner. The control supports | ||
3148 | * specifying total no of bits used to allow for bitfields | ||
3149 | * across the multiple codec registers. | ||
3150 | * | ||
3151 | * Returns 0 for success. | ||
3152 | */ | ||
3153 | int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, | ||
3154 | struct snd_ctl_elem_value *ucontrol) | ||
3155 | { | ||
3156 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
3157 | struct soc_mreg_control *mc = | ||
3158 | (struct soc_mreg_control *)kcontrol->private_value; | ||
3159 | unsigned int regbase = mc->regbase; | ||
3160 | unsigned int regcount = mc->regcount; | ||
3161 | unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; | ||
3162 | unsigned int regwmask = (1<<regwshift)-1; | ||
3163 | unsigned int invert = mc->invert; | ||
3164 | unsigned long mask = (1UL<<mc->nbits)-1; | ||
3165 | long max = mc->max; | ||
3166 | long val = ucontrol->value.integer.value[0]; | ||
3167 | unsigned int i, regval, regmask; | ||
3168 | int err; | ||
3169 | |||
3170 | if (invert) | ||
3171 | val = max - val; | ||
3172 | val &= mask; | ||
3173 | for (i = 0; i < regcount; i++) { | ||
3174 | regval = (val >> (regwshift*(regcount-i-1))) & regwmask; | ||
3175 | regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; | ||
3176 | err = snd_soc_component_update_bits(component, regbase+i, | ||
3177 | regmask, regval); | ||
3178 | if (err < 0) | ||
3179 | return err; | ||
3180 | } | ||
3181 | |||
3182 | return 0; | ||
3183 | } | ||
3184 | EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx); | ||
3185 | |||
3186 | /** | ||
3187 | * snd_soc_get_strobe - strobe get callback | ||
3188 | * @kcontrol: mixer control | ||
3189 | * @ucontrol: control element information | ||
3190 | * | ||
3191 | * Callback get the value of a strobe mixer control. | ||
3192 | * | ||
3193 | * Returns 0 for success. | ||
3194 | */ | ||
3195 | int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, | ||
3196 | struct snd_ctl_elem_value *ucontrol) | ||
3197 | { | ||
3198 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
3199 | struct soc_mixer_control *mc = | ||
3200 | (struct soc_mixer_control *)kcontrol->private_value; | ||
3201 | unsigned int reg = mc->reg; | ||
3202 | unsigned int shift = mc->shift; | ||
3203 | unsigned int mask = 1 << shift; | ||
3204 | unsigned int invert = mc->invert != 0; | ||
3205 | unsigned int val; | ||
3206 | int ret; | ||
3207 | |||
3208 | ret = snd_soc_component_read(component, reg, &val); | ||
3209 | if (ret) | ||
3210 | return ret; | ||
3211 | |||
3212 | val &= mask; | ||
3213 | |||
3214 | if (shift != 0 && val != 0) | ||
3215 | val = val >> shift; | ||
3216 | ucontrol->value.enumerated.item[0] = val ^ invert; | ||
3217 | |||
3218 | return 0; | ||
3219 | } | ||
3220 | EXPORT_SYMBOL_GPL(snd_soc_get_strobe); | ||
3221 | |||
3222 | /** | ||
3223 | * snd_soc_put_strobe - strobe put callback | ||
3224 | * @kcontrol: mixer control | ||
3225 | * @ucontrol: control element information | ||
3226 | * | ||
3227 | * Callback strobe a register bit to high then low (or the inverse) | ||
3228 | * in one pass of a single mixer enum control. | ||
3229 | * | ||
3230 | * Returns 1 for success. | ||
3231 | */ | ||
3232 | int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, | ||
3233 | struct snd_ctl_elem_value *ucontrol) | ||
3234 | { | ||
3235 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); | ||
3236 | struct soc_mixer_control *mc = | ||
3237 | (struct soc_mixer_control *)kcontrol->private_value; | ||
3238 | unsigned int reg = mc->reg; | ||
3239 | unsigned int shift = mc->shift; | ||
3240 | unsigned int mask = 1 << shift; | ||
3241 | unsigned int invert = mc->invert != 0; | ||
3242 | unsigned int strobe = ucontrol->value.enumerated.item[0] != 0; | ||
3243 | unsigned int val1 = (strobe ^ invert) ? mask : 0; | ||
3244 | unsigned int val2 = (strobe ^ invert) ? 0 : mask; | ||
3245 | int err; | ||
3246 | |||
3247 | err = snd_soc_component_update_bits(component, reg, mask, val1); | ||
3248 | if (err < 0) | ||
3249 | return err; | ||
3250 | |||
3251 | return snd_soc_component_update_bits(component, reg, mask, val2); | ||
3252 | } | ||
3253 | EXPORT_SYMBOL_GPL(snd_soc_put_strobe); | ||
3254 | |||
3255 | /** | ||
3256 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. | 2337 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
3257 | * @dai: DAI | 2338 | * @dai: DAI |
3258 | * @clk_id: DAI specific clock ID | 2339 | * @clk_id: DAI specific clock ID |