^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * helper functions for Asus Xonar cards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "xonar.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define GPIO_CS53x1_M_MASK 0x000c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define GPIO_CS53x1_M_SINGLE 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define GPIO_CS53x1_M_DOUBLE 0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define GPIO_CS53x1_M_QUAD 0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) void xonar_enable_output(struct oxygen *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct xonar_generic *data = chip->model_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) msleep(data->anti_pop_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void xonar_disable_output(struct oxygen *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct xonar_generic *data = chip->model_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void xonar_ext_power_gpio_changed(struct oxygen *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct xonar_generic *data = chip->model_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 has_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) has_power = !!(oxygen_read8(chip, data->ext_power_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) & data->ext_power_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (has_power != data->has_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) data->has_power = has_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (has_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) dev_notice(chip->card->dev, "power restored\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) dev_crit(chip->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "Hey! Don't unplug the power cable!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* TODO: stop PCMs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void xonar_init_ext_power(struct oxygen *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct xonar_generic *data = chip->model_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) oxygen_set_bits8(chip, data->ext_power_int_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) data->ext_power_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) chip->interrupt_mask |= OXYGEN_INT_GPIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) chip->model.gpio_changed = xonar_ext_power_gpio_changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) & data->ext_power_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) void xonar_init_cs53x1(struct oxygen *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void xonar_set_cs53x1_params(struct oxygen *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (params_rate(params) <= 54000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) value = GPIO_CS53x1_M_SINGLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) else if (params_rate(params) <= 108000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) value = GPIO_CS53x1_M_DOUBLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) value = GPIO_CS53x1_M_QUAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) value, GPIO_CS53x1_M_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct oxygen *chip = ctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u16 bit = ctl->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) bool invert = ctl->private_value & XONAR_GPIO_BIT_INVERT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) value->value.integer.value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit) ^ invert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct oxygen *chip = ctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u16 bit = ctl->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bool invert = ctl->private_value & XONAR_GPIO_BIT_INVERT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u16 old_bits, new_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) spin_lock_irq(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!!value->value.integer.value[0] ^ invert)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) new_bits = old_bits | bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) new_bits = old_bits & ~bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) changed = new_bits != old_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) spin_unlock_irq(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }