1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright 2011 Broadcom Corporation. All rights reserved. */ 3 4 #ifndef __SOUND_ARM_BCM2835_H 5 #define __SOUND_ARM_BCM2835_H 6 7 #include <linux/device.h> 8 #include <linux/wait.h> 9 #include <linux/raspberrypi/vchiq.h> 10 #include <sound/core.h> 11 #include <sound/pcm.h> 12 #include <sound/pcm-indirect.h> 13 14 #define MAX_SUBSTREAMS (8) 15 #define AVAIL_SUBSTREAMS_MASK (0xff) 16 17 enum { 18 CTRL_VOL_MUTE, 19 CTRL_VOL_UNMUTE 20 }; 21 22 /* macros for alsa2chip and chip2alsa, instead of functions */ 23 24 // convert alsa to chip volume (defined as macro rather than function call) 25 #define alsa2chip(vol) ((uint)(-(((vol) << 8) / 100))) 26 27 // convert chip to alsa volume 28 #define chip2alsa(vol) -(((vol) * 100) >> 8) 29 30 #define CHIP_MIN_VOLUME 26214 /* minimum level aka mute */ 31 32 /* Some constants for values .. */ 33 enum snd_bcm2835_route { 34 AUDIO_DEST_AUTO = 0, 35 AUDIO_DEST_HEADPHONES = 1, 36 AUDIO_DEST_HDMI = 2, 37 AUDIO_DEST_MAX, 38 }; 39 40 enum snd_bcm2835_ctrl { 41 PCM_PLAYBACK_VOLUME, 42 PCM_PLAYBACK_MUTE, 43 PCM_PLAYBACK_DEVICE, 44 }; 45 46 struct bcm2835_vchi_ctx { 47 struct vchiq_instance *instance; 48 }; 49 50 /* definition of the chip-specific record */ 51 struct bcm2835_chip { 52 struct snd_card *card; 53 struct snd_pcm *pcm; 54 struct snd_pcm *pcm_spdif; 55 struct device *dev; 56 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS]; 57 58 int volume; 59 int dest; 60 int mute; 61 62 unsigned int opened; 63 unsigned int spdif_status; 64 struct mutex audio_mutex; /* Serialize chip data access */ 65 66 struct bcm2835_vchi_ctx *vchi_ctx; 67 }; 68 69 struct bcm2835_alsa_stream { 70 struct bcm2835_chip *chip; 71 struct snd_pcm_substream *substream; 72 struct snd_pcm_indirect pcm_indirect; 73 74 int draining; 75 76 atomic_t pos; 77 unsigned int period_offset; 78 unsigned int buffer_size; 79 unsigned int period_size; 80 ktime_t interpolate_start; 81 82 struct bcm2835_audio_instance *instance; 83 int idx; 84 }; 85 86 int snd_bcm2835_new_ctl(struct bcm2835_chip *chip); 87 int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name, 88 int idx, enum snd_bcm2835_route route, 89 u32 numchannels, bool spdif); 90 91 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip); 92 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip); 93 94 int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx); 95 void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx); 96 97 int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream); 98 int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream); 99 int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream, 100 unsigned int channels, unsigned int samplerate, 101 unsigned int bps); 102 int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream); 103 int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream); 104 int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream); 105 int bcm2835_audio_set_ctls(struct bcm2835_alsa_stream *alsa_stream); 106 int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, 107 unsigned int count, 108 void *src); 109 void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream, 110 unsigned int size); 111 unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream); 112 113 #endif /* __SOUND_ARM_BCM2835_H */ 114