1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __SOUND_ARM_BCM2835_H
16#define __SOUND_ARM_BCM2835_H
17
18#include <linux/device.h>
19#include <linux/list.h>
20#include <linux/interrupt.h>
21#include <linux/wait.h>
22#include <sound/core.h>
23#include <sound/initval.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/pcm-indirect.h>
27#include <linux/workqueue.h>
28
29
30
31
32
33
34
35
36#ifdef AUDIO_DEBUG_ENABLE
37#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
38
39#define audio_debug(fmt, arg...) \
40 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
41
42#define audio_info(fmt, arg...) \
43 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
44
45#else
46
47#define audio_debug(fmt, arg...)
48
49#define audio_info(fmt, arg...)
50
51#endif
52
53#else
54
55#define audio_debug(fmt, arg...)
56
57#define audio_info(fmt, arg...)
58
59#endif
60
61#define audio_error(fmt, arg...) \
62 pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
63
64#define audio_warning(fmt, arg...) \
65 pr_warn("%s:%d " fmt, __func__, __LINE__, ##arg)
66
67#define audio_alert(fmt, arg...) \
68 pr_alert("%s:%d " fmt, __func__, __LINE__, ##arg)
69
70#define MAX_SUBSTREAMS (8)
71#define AVAIL_SUBSTREAMS_MASK (0xff)
72
73enum {
74 CTRL_VOL_MUTE,
75 CTRL_VOL_UNMUTE
76};
77
78
79
80
81#define alsa2chip(vol) (uint)(-(((vol) << 8) / 100))
82
83
84#define chip2alsa(vol) -(((vol) * 100) >> 8)
85
86
87enum snd_bcm2835_route {
88 AUDIO_DEST_AUTO = 0,
89 AUDIO_DEST_HEADPHONES = 1,
90 AUDIO_DEST_HDMI = 2,
91 AUDIO_DEST_MAX,
92};
93
94enum snd_bcm2835_ctrl {
95 PCM_PLAYBACK_VOLUME,
96 PCM_PLAYBACK_MUTE,
97 PCM_PLAYBACK_DEVICE,
98};
99
100
101struct bcm2835_chip {
102 struct snd_card *card;
103 struct snd_pcm *pcm;
104 struct snd_pcm *pcm_spdif;
105
106 unsigned int avail_substreams;
107 struct device *dev;
108 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
109
110 int volume;
111 int old_volume;
112 int dest;
113 int mute;
114
115 unsigned int opened;
116 unsigned int spdif_status;
117 struct mutex audio_mutex;
118};
119
120struct bcm2835_alsa_stream {
121 struct bcm2835_chip *chip;
122 struct snd_pcm_substream *substream;
123 struct snd_pcm_indirect pcm_indirect;
124
125 spinlock_t lock;
126 volatile unsigned int control;
127 volatile unsigned int status;
128
129 int open;
130 int running;
131 int draining;
132
133 int channels;
134 int params_rate;
135 int pcm_format_width;
136
137 unsigned int pos;
138 unsigned int buffer_size;
139 unsigned int period_size;
140
141 atomic_t retrieved;
142 struct bcm2835_audio_instance *instance;
143 struct workqueue_struct *my_wq;
144 int idx;
145};
146
147int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
148int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels);
149int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip);
150int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
151 const char *name,
152 enum snd_bcm2835_route route,
153 u32 numchannels);
154
155int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
156int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);
157
158int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream);
159int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream);
160int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
161 unsigned int channels, unsigned int samplerate,
162 unsigned int bps);
163int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream);
164int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream);
165int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream);
166int bcm2835_audio_set_ctls(struct bcm2835_chip *chip);
167int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
168 unsigned int count,
169 void *src);
170void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream);
171unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream);
172void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream);
173void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream);
174
175#endif
176