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