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