Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * PC-Speaker driver for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Mixer implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2001-2008  Stas Sergeev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^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 "pcsp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static int pcsp_enable_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 			    struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	uinfo->value.integer.max = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int pcsp_enable_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 			   struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	ucontrol->value.integer.value[0] = chip->enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int pcsp_enable_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 			   struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int enab = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (enab != chip->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		chip->enable = enab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int pcsp_treble_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			    struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	uinfo->value.enumerated.items = chip->max_treble + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (uinfo->value.enumerated.item > chip->max_treble)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		uinfo->value.enumerated.item = chip->max_treble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	sprintf(uinfo->value.enumerated.name, "%lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		(unsigned long)PCSP_CALC_RATE(uinfo->value.enumerated.item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			   struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	ucontrol->value.enumerated.item[0] = chip->treble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			   struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int treble = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (treble != chip->treble) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		chip->treble = treble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #if PCSP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		printk(KERN_INFO "PCSP: rate set to %li\n", PCSP_RATE());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			    struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	uinfo->value.integer.max = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			   struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ucontrol->value.integer.value[0] = chip->pcspkr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			   struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int spkr = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (spkr != chip->pcspkr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		chip->pcspkr = spkr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.name =		ctl_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.info =		pcsp_##ctl_type##_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.get =		pcsp_##ctl_type##_get, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.put =		pcsp_##ctl_type##_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const struct snd_kcontrol_new snd_pcsp_controls_pcm[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static const struct snd_kcontrol_new snd_pcsp_controls_spkr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	PCSP_MIXER_CONTROL(pcspkr, "Beep Playback Switch"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int snd_pcsp_ctls_add(struct snd_pcsp *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			     const struct snd_kcontrol_new *ctls, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct snd_card *card = chip->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		err = snd_ctl_add(card, snd_ctl_new1(ctls + i, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct snd_card *card = chip->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!nopcm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			ARRAY_SIZE(snd_pcsp_controls_pcm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_spkr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		ARRAY_SIZE(snd_pcsp_controls_spkr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	strcpy(card->mixername, "PC-Speaker");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }