6b13f685e
김민수
BSP 최초 추가
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
static int enable_midi_input(struct echoaudio *chip, char enable)
{
DE_MID(("enable_midi_input(%d)
", enable));
if (wait_handshake(chip))
return -EIO;
if (enable) {
chip->mtc_state = MIDI_IN_STATE_NORMAL;
chip->comm_page->flags |=
cpu_to_le32(DSP_FLAG_MIDI_INPUT);
} else
chip->comm_page->flags &=
~cpu_to_le32(DSP_FLAG_MIDI_INPUT);
clear_handshake(chip);
return send_vector(chip, DSP_VC_UPDATE_FLAGS);
}
static int write_midi(struct echoaudio *chip, u8 *data, int bytes)
{
if (snd_BUG_ON(bytes <= 0 || bytes >= MIDI_OUT_BUFFER_SIZE))
return -EINVAL;
if (wait_handshake(chip))
return -EIO;
if (! (get_dsp_register(chip, CHI32_STATUS_REG) & CHI32_STATUS_REG_HF4))
return 0;
chip->comm_page->midi_output[0] = bytes;
memcpy(&chip->comm_page->midi_output[1], data, bytes);
chip->comm_page->midi_out_free_count = 0;
clear_handshake(chip);
send_vector(chip, DSP_VC_MIDI_WRITE);
DE_MID(("write_midi: %d
", bytes));
return bytes;
}
static inline int mtc_process_data(struct echoaudio *chip, short midi_byte)
{
switch (chip->mtc_state) {
case MIDI_IN_STATE_NORMAL:
if (midi_byte == 0xF1)
chip->mtc_state = MIDI_IN_STATE_TS_HIGH;
break;
case MIDI_IN_STATE_TS_HIGH:
chip->mtc_state = MIDI_IN_STATE_TS_LOW;
return MIDI_IN_SKIP_DATA;
break;
case MIDI_IN_STATE_TS_LOW:
chip->mtc_state = MIDI_IN_STATE_F1_DATA;
return MIDI_IN_SKIP_DATA;
break;
case MIDI_IN_STATE_F1_DATA:
chip->mtc_state = MIDI_IN_STATE_NORMAL;
break;
}
return 0;
}
static int midi_service_irq(struct echoaudio *chip)
{
short int count, midi_byte, i, received;
count = le16_to_cpu(chip->comm_page->midi_input[0]);
if (snd_BUG_ON(count >= MIDI_IN_BUFFER_SIZE))
return 0;
i = 1;
received = 0;
for (i = 1; i <= count; i++) {
midi_byte = le16_to_cpu(chip->comm_page->midi_input[i]);
if (mtc_process_data(chip, midi_byte) == MIDI_IN_SKIP_DATA)
continue;
chip->midi_buffer[received++] = (u8)midi_byte;
}
return received;
}
static int snd_echo_midi_input_open(struct snd_rawmidi_substream *substream)
{
struct echoaudio *chip = substream->rmidi->private_data;
chip->midi_in = substream;
DE_MID(("rawmidi_iopen
"));
return 0;
}
static void snd_echo_midi_input_trigger(struct snd_rawmidi_substream *substream,
int up)
{
struct echoaudio *chip = substream->rmidi->private_data;
if (up != chip->midi_input_enabled) {
spin_lock_irq(&chip->lock);
enable_midi_input(chip, up);
spin_unlock_irq(&chip->lock);
chip->midi_input_enabled = up;
}
}
static int snd_echo_midi_input_close(struct snd_rawmidi_substream *substream)
{
struct echoaudio *chip = substream->rmidi->private_data;
chip->midi_in = NULL;
DE_MID(("rawmidi_iclose
"));
return 0;
}
static int snd_echo_midi_output_open(struct snd_rawmidi_substream *substream)
{
struct echoaudio *chip = substream->rmidi->private_data;
chip->tinuse = 0;
chip->midi_full = 0;
chip->midi_out = substream;
DE_MID(("rawmidi_oopen
"));
return 0;
}
static void snd_echo_midi_output_write(unsigned long data)
{
struct echoaudio *chip = (struct echoaudio *)data;
unsigned long flags;
int bytes, sent, time;
unsigned char buf[MIDI_OUT_BUFFER_SIZE - 1];
DE_MID(("snd_echo_midi_output_write
"));
sent = bytes = 0;
spin_lock_irqsave(&chip->lock, flags);
chip->midi_full = 0;
if (!snd_rawmidi_transmit_empty(chip->midi_out)) {
bytes = snd_rawmidi_transmit_peek(chip->midi_out, buf,
MIDI_OUT_BUFFER_SIZE - 1);
DE_MID(("Try to send %d bytes...
", bytes));
sent = write_midi(chip, buf, bytes);
if (sent < 0) {
snd_printk(KERN_ERR "write_midi() error %d
", sent);
sent = 9000;
chip->midi_full = 1;
} else if (sent > 0) {
DE_MID(("%d bytes sent
", sent));
snd_rawmidi_transmit_ack(chip->midi_out, sent);
} else {
DE_MID(("Full
"));
sent = 32;
chip->midi_full = 1;
}
}
if (!snd_rawmidi_transmit_empty(chip->midi_out) && chip->tinuse) {
time = (sent << 3) / 25 + 1;
mod_timer(&chip->timer, jiffies + (time * HZ + 999) / 1000);
DE_MID(("Timer armed(%d)
", ((time * HZ + 999) / 1000)));
}
spin_unlock_irqrestore(&chip->lock, flags);
}
static void snd_echo_midi_output_trigger(struct snd_rawmidi_substream *substream,
int up)
{
struct echoaudio *chip = substream->rmidi->private_data;
DE_MID(("snd_echo_midi_output_trigger(%d)
", up));
spin_lock_irq(&chip->lock);
if (up) {
if (!chip->tinuse) {
init_timer(&chip->timer);
chip->timer.function = snd_echo_midi_output_write;
chip->timer.data = (unsigned long)chip;
chip->tinuse = 1;
}
} else {
if (chip->tinuse) {
chip->tinuse = 0;
spin_unlock_irq(&chip->lock);
del_timer_sync(&chip->timer);
DE_MID(("Timer removed
"));
return;
}
}
spin_unlock_irq(&chip->lock);
if (up && !chip->midi_full)
snd_echo_midi_output_write((unsigned long)chip);
}
static int snd_echo_midi_output_close(struct snd_rawmidi_substream *substream)
{
struct echoaudio *chip = substream->rmidi->private_data;
chip->midi_out = NULL;
DE_MID(("rawmidi_oclose
"));
return 0;
}
static struct snd_rawmidi_ops snd_echo_midi_input = {
.open = snd_echo_midi_input_open,
.close = snd_echo_midi_input_close,
.trigger = snd_echo_midi_input_trigger,
};
static struct snd_rawmidi_ops snd_echo_midi_output = {
.open = snd_echo_midi_output_open,
.close = snd_echo_midi_output_close,
.trigger = snd_echo_midi_output_trigger,
};
static int snd_echo_midi_create(struct snd_card *card,
struct echoaudio *chip)
{
int err;
if ((err = snd_rawmidi_new(card, card->shortname, 0, 1, 1,
&chip->rmidi)) < 0)
return err;
strcpy(chip->rmidi->name, card->shortname);
chip->rmidi->private_data = chip;
snd_rawmidi_set_ops(chip->rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
&snd_echo_midi_input);
snd_rawmidi_set_ops(chip->rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
&snd_echo_midi_output);
chip->rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX;
DE_INIT(("MIDI ok
"));
return 0;
}
|