1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright 2011 Broadcom Corporation. All rights reserved. */
4 #ifndef __SOUND_ARM_BCM2835_H
5 #define __SOUND_ARM_BCM2835_H
7 #include <linux/device.h>
8 #include <linux/list.h>
9 #include <linux/interrupt.h>
10 #include <linux/wait.h>
11 #include <sound/core.h>
12 #include <sound/initval.h>
13 #include <sound/pcm.h>
14 #include <sound/pcm_params.h>
15 #include <sound/pcm-indirect.h>
16 #include <linux/workqueue.h>
18 #include "interface/vchi/vchi.h"
21 * #define AUDIO_DEBUG_ENABLE
22 * #define AUDIO_VERBOSE_DEBUG_ENABLE
27 #ifdef AUDIO_DEBUG_ENABLE
28 #ifdef AUDIO_VERBOSE_DEBUG_ENABLE
30 #define audio_debug(fmt, arg...) \
31 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
33 #define audio_info(fmt, arg...) \
34 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
38 #define audio_debug(fmt, arg...)
40 #define audio_info(fmt, arg...)
42 #endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
46 #define audio_debug(fmt, arg...)
48 #define audio_info(fmt, arg...)
50 #endif /* AUDIO_DEBUG_ENABLE */
52 #define audio_error(fmt, arg...) \
53 pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
55 #define audio_warning(fmt, arg...) \
56 pr_warn("%s:%d " fmt, __func__, __LINE__, ##arg)
58 #define audio_alert(fmt, arg...) \
59 pr_alert("%s:%d " fmt, __func__, __LINE__, ##arg)
61 #define MAX_SUBSTREAMS (8)
62 #define AVAIL_SUBSTREAMS_MASK (0xff)
69 /* macros for alsa2chip and chip2alsa, instead of functions */
71 // convert alsa to chip volume (defined as macro rather than function call)
72 #define alsa2chip(vol) (uint)(-(((vol) << 8) / 100))
74 // convert chip to alsa volume
75 #define chip2alsa(vol) -(((vol) * 100) >> 8)
77 /* Some constants for values .. */
78 enum snd_bcm2835_route {
80 AUDIO_DEST_HEADPHONES = 1,
85 enum snd_bcm2835_ctrl {
91 struct bcm2835_vchi_ctx {
92 VCHI_INSTANCE_T vchi_instance;
93 VCHI_CONNECTION_T *vchi_connection;
96 /* definition of the chip-specific record */
98 struct snd_card *card;
100 struct snd_pcm *pcm_spdif;
101 /* Bitmat for valid reg_base and irq numbers */
102 unsigned int avail_substreams;
104 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
107 int old_volume; /* stores the volume value whist muted */
112 unsigned int spdif_status;
113 struct mutex audio_mutex;
115 struct bcm2835_vchi_ctx *vchi_ctx;
118 struct bcm2835_alsa_stream {
119 struct bcm2835_chip *chip;
120 struct snd_pcm_substream *substream;
121 struct snd_pcm_indirect pcm_indirect;
131 int pcm_format_width;
134 unsigned int buffer_size;
135 unsigned int period_size;
138 struct bcm2835_audio_instance *instance;
139 struct workqueue_struct *my_wq;
143 int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
144 int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels);
145 int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip);
146 int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
148 enum snd_bcm2835_route route,
151 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
152 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);
154 int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx);
155 void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx);
157 int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream);
158 int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream);
159 int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
160 unsigned int channels, unsigned int samplerate,
162 int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream);
163 int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream);
164 int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream);
165 int bcm2835_audio_set_ctls(struct bcm2835_chip *chip);
166 int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
169 void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream);
170 unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream);
171 void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream);
172 void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream);
174 #endif /* __SOUND_ARM_BCM2835_H */