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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
/* $NetBSD: zz9k_ax.c,v 1.1 2023/05/03 13:49:30 phx Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Alain Runa.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zz9k_ax.c,v 1.1 2023/05/03 13:49:30 phx Exp $");
/* miscellaneous */
#include <sys/types.h> /* size_t */
#include <sys/stdint.h> /* uintXX_t */
#include <sys/stdbool.h> /* bool */
/* driver(9) */
#include <sys/param.h> /* NODEV */
#include <sys/device.h> /* CFATTACH_DECL_NEW(), device_priv() */
#include <sys/errno.h> /* . */
/* bus_space(9) and zorro bus */
#include <sys/bus.h> /* bus_space_xxx(), bus_space_xxx_t */
#include <sys/cpu.h> /* kvtop() */
#include <sys/systm.h> /* aprint_xxx() */
/* mutex(9) */
#include <sys/mutex.h>
/* Interrupt related */
#include <sys/intr.h>
#include <amiga/amiga/isr.h> /* isr */
/* audio(9) */
#include <sys/audioio.h>
#include <dev/audio/audio_if.h>
/* zz9k related */
#include <amiga/dev/zz9kvar.h> /* zz9kbus_attach_args */
#include <amiga/dev/zz9kreg.h> /* ZZ9000 registers */
#include "zz9k_ax.h" /* NZZ9K_AX */
/* The allmighty softc structure */
struct zzax_softc {
device_t sc_dev;
struct bus_space_tag sc_bst;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_regh;
bus_space_handle_t sc_txbufh;
size_t sc_txbufsize;
struct isr sc_isr;
kmutex_t sc_lock;
kmutex_t sc_intr_lock;
};
static int zzax_intr(void *arg);
static void zzax_set_param(struct zzax_softc *sc, uint16_t param, uint16_t val);
/* audio_hw_if */
static int zzax_open(void *hdl, int flags);
static void zzax_close(void *hdl);
static int zzax_query_format(void *hdl, audio_format_query_t *afp);
static int zzax_set_format(void *hdl, int setmode,
const audio_params_t *play, const audio_params_t *rec,
audio_filter_reg_t *pfil, audio_filter_reg_t *rfil);
static int zzax_round_blocksize(void *hdl, int bs, int mode,
const audio_params_t *param);
static int zzax_commit_settings(void *hdl);
static int zzax_init_output(void *hdl, void *buffer, int size);
static int zzax_init_input(void *hdl, void *buffer, int size);
static int zzax_start_output(void *hdl, void *block, int blksize,
void (*intr)(void*), void *intrarg);
static int zzax_start_input(void *hdl, void *block, int blksize,
void (*intr)(void*), void *intrarg);
static int zzax_halt_output(void *hdl);
static int zzax_halt_input(void *hdl);
static int zzax_speaker_ctl(void *hdl, int on);
static int zzax_getdev(void *hdl, struct audio_device *ret);
static int zzax_set_port(void *hdl, mixer_ctrl_t *mc);
static int zzax_get_port(void *hdl, mixer_ctrl_t *mc);
static int zzax_query_devinfo(void *hdl, mixer_devinfo_t *di);
#if 0
static void *zzax_allocm(void *hdl, int direction, size_t size);
static void zzax_freem(void *hdl, void *addr, size_t size);
#endif
static size_t zzax_round_buffersize(void *hdl, int direction, size_t bufsize);
static int zzax_get_props(void *hdl);
static int zzax_trigger_output(void *hdl, void *start, void *end, int blksize,
void (*intr)(void*), void *intrarg, const audio_params_t *param);
static int zzax_trigger_input(void *hdl, void *start, void *end, int blksize,
void (*intr)(void*), void *intrarg, const audio_params_t *param);
static int zzax_dev_ioctl(void *hdl, u_long cmd, void *addr, int flag,
struct lwp *l);
static void zzax_get_locks(void *hdl, kmutex_t **intr, kmutex_t **thread);
static const struct audio_hw_if zzax_hw_if = {
.open = zzax_open,
.close = zzax_close,
.query_format = zzax_query_format,
.set_format = zzax_set_format,
.round_blocksize = zzax_round_blocksize,
.commit_settings = zzax_commit_settings,
.init_output = zzax_init_output,
.init_input = zzax_init_input,
.start_output = zzax_start_output,
.start_input = zzax_start_input,
.halt_output = zzax_halt_output,
.halt_input = zzax_halt_input,
.speaker_ctl = zzax_speaker_ctl,
.getdev = zzax_getdev,
.set_port = zzax_set_port,
.get_port = zzax_get_port,
.query_devinfo = zzax_query_devinfo,
#if 0
.allocm = zzax_allocm,
.freem = zzax_freem,
#endif
.round_buffersize = zzax_round_buffersize,
.get_props = zzax_get_props,
.trigger_output = zzax_trigger_output,
.trigger_input = zzax_trigger_input,
.dev_ioctl = zzax_dev_ioctl,
.get_locks = zzax_get_locks
};
static const struct audio_format zzax_format = {
.mode = AUMODE_PLAY,
.encoding = AUDIO_ENCODING_SLINEAR_BE,
.validbits = 16,
.precision = 16,
.channels = 2,
.channel_mask = AUFMT_STEREO,
.frequency_type = 0,
.frequency = {8000, 12000, 24000, 32000, 44100, 48000},
.priority = 0
};
static const struct audio_device zzax_device = {
.name = "ZZ9000AX",
.version = "1.13",
.config = "zzax"
};
/* mixer sets */
#define ZZAX_CHANNELS 0
/* mixer values */
#define ZZAX_VOLUME 1
#define ZZAX_OUTPUT_CLASS 2
/* driver(9) essentials */
static int zzax_match(device_t parent, cfdata_t match, void *aux);
static void zzax_attach(device_t parent, device_t self, void *aux);
CFATTACH_DECL_NEW(zz9k_ax, sizeof(struct zzax_softc),
zzax_match, zzax_attach, NULL, NULL);
/* Go ahead, make my day. */
static int
zzax_match(device_t parent, cfdata_t match, void *aux)
{
struct zz9kbus_attach_args *bap = aux;
if (strcmp(bap->zzaa_name, "zz9k_ax") != 0)
return 0;
return 1;
}
static void
zzax_attach(device_t parent, device_t self, void *aux)
{
struct zz9kbus_attach_args *bap = aux;
struct zzax_softc *sc = device_private(self);
struct zz9k_softc *psc = device_private(parent);
sc->sc_dev = self;
sc->sc_bst.base = bap->zzaa_base;
sc->sc_bst.absm = &amiga_bus_stride_1;
sc->sc_iot = &sc->sc_bst;
sc->sc_regh = psc->sc_regh;
uint16_t config = ZZREG_R(ZZ9K_AUDIO_CONFIG);
aprint_normal(": ZZ9000AX %sdetected.\n",
(config == 0) ? "not " : "");
aprint_normal_dev(sc->sc_dev,
"MNT ZZ9000AX driver is not functional yet.\n");
aprint_debug_dev(sc->sc_dev, "[DEBUG] registers at %p/%p (pa/va)\n",
(void *)kvtop((void *)sc->sc_regh),
bus_space_vaddr(sc->sc_iot, sc->sc_regh));
sc->sc_txbufsize = 0x10000;
uint32_t tx_buffer = psc->sc_zsize - sc->sc_txbufsize;
if (bus_space_map(sc->sc_iot, tx_buffer, sc->sc_txbufsize,
BUS_SPACE_MAP_LINEAR, &sc->sc_txbufh)) {
aprint_error(": Failed to map MNT ZZ9000AX audio tx buffer.\n");
return;
}
aprint_normal_dev(sc->sc_dev, "base: %p/%p size: %i\n",
(void *)kvtop((void *)sc->sc_txbufh),
bus_space_vaddr(sc->sc_iot, sc->sc_txbufh),
sc->sc_txbufsize);
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
sc->sc_isr.isr_intr = zzax_intr;
sc->sc_isr.isr_arg = sc;
sc->sc_isr.isr_ipl = 6;
add_isr(&sc->sc_isr);
audio_attach_mi(&zzax_hw_if, sc, self);
uint16_t conf = ZZREG_R(ZZ9K_AUDIO_CONFIG); /* enable interrupt */
ZZREG_W(ZZ9K_AUDIO_CONFIG, conf | ZZ9K_AUDIO_CONFIG_INT_AUDIO);
}
static int
zzax_intr(void *arg)
{
struct zzax_softc *sc = arg;
uint16_t conf = ZZREG_R(ZZ9K_CONFIG);
if ((conf & ZZ9K_CONFIG_INT_AUDIO) == 0)
return 0;
#if 0
uint16_t conf = ZZREG_R(ZZ9K_AUDIO_CONFIG); /* disable interrupt */
ZZREG_W(ZZ9K_AUDIO_CONFIG, conf & ~ZZ9K_AUDIO_CONFIG_INT_AUDIO);
#endif
ZZREG_W(ZZ9K_CONFIG, ZZ9K_CONFIG_INT_ACK | ZZ9K_CONFIG_INT_ACK_AUDIO);
mutex_spin_enter(&sc->sc_intr_lock);
/* do stuff */
mutex_spin_exit(&sc->sc_intr_lock);
#if 0
uint16_t conf = ZZREG_R(ZZ9K_AUDIO_CONFIG); /* enable interrupt */
ZZREG_W(ZZ9K_AUDIO_CONFIG, conf | ZZ9K_AUDIO_CONFIG_INT_AUDIO);
#endif
return 1;
}
static void
zzax_set_param(struct zzax_softc *sc, uint16_t param, uint16_t val)
{
ZZREG_W(ZZ9K_AUDIO_PARAM, param);
ZZREG_W(ZZ9K_AUDIO_VAL, val);
ZZREG_W(ZZ9K_AUDIO_PARAM, 0);
}
int
zzax_open(void *hdl, int flags)
{
struct zzax_softc *sc = hdl;
uint32_t buffer = (uint32_t)bus_space_vaddr(sc->sc_iot, sc->sc_txbufh);
zzax_set_param(sc, ZZ9K_AP_TX_BUF_OFFS_HI, buffer >> 16);
zzax_set_param(sc, ZZ9K_AP_TX_BUF_OFFS_HI, buffer & 0xFFFF);
printf("zzax_open: %X\n", buffer);
return 0;
}
static void
zzax_close(void *hdl)
{
printf("zzax_close:\n");
}
static int
zzax_query_format(void *hdl, audio_format_query_t *afp)
{
printf("zzax_query_format:\n");
return audio_query_format(&zzax_format, 1, afp);
}
static int
zzax_set_format(void *hdl, int setmode,
const audio_params_t *play, const audio_params_t *rec,
audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
{
struct zzax_softc *sc = hdl;
printf("zzax_set_format:\n");
if (setmode & AUMODE_PLAY) {
zzax_set_param(sc, ZZ9K_AP_DSP_SET_LOWPASS, 23900);
printf("::play->sample_rate: %i\n", play->sample_rate);
printf("::play->encoding: %i\n", play->encoding);
printf("::play->precision: %i\n", play->precision);
printf("::play->validbits: %i\n", play->validbits);
printf("::play->channels: %i\n", play->channels);
}
if (setmode & AUMODE_RECORD) {
printf("::rec->sample_rate: %i\n", rec->sample_rate);
printf("::rec->encoding: %i\n", rec->encoding);
printf("::rec->precision: %i\n", rec->precision);
printf("::rec->validbits: %i\n", rec->validbits);
printf("::rec->channels: %i\n", rec->channels);
}
return 0;
}
static int
zzax_round_blocksize(void *hdl, int bs, int mode, const audio_params_t *param)
{
printf("zzax_round_blocksize:\n");
printf("::bs: %i\n", bs);
printf("::mode: %i\n", mode);
printf("::param->sample_rate: %i\n", param->sample_rate);
printf("::param->encoding: %i\n", param->encoding);
printf("::param->precision: %i\n", param->precision);
printf("::param->validbits: %i\n", param->validbits);
printf("::param->channels: %i\n", param->channels);
return bs;
}
static int
zzax_commit_settings(void *hdl)
{
printf("zzax_commit_settings:\n");
return 0;
}
static int
zzax_init_output(void *hdl, void *buffer, int size)
{
printf("zzax_init_output:\n");
return 0;
}
static int
zzax_init_input(void *hdl, void *buffer, int size)
{
printf("zzax_init_input:\n");
return 0;
}
static int
zzax_start_output(void *hdl, void *block, int blksize,
void (*intr)(void*), void *intrarg)
{
printf("zzax_start_output:\n");
return 0;
}
static int
zzax_start_input(void *hdl, void *block, int blksize,
void (*intr)(void*), void *intrarg)
{
printf("zzax_start_input:\n");
return ENXIO;
}
static int
zzax_halt_output(void *hdl)
{
printf("zzax_halt_output:\n");
return 0;
}
static int
zzax_halt_input(void *hdl)
{
printf("zzax_halt_input:\n");
return ENXIO;
}
static int
zzax_speaker_ctl(void *hdl, int on)
{
printf("zzax_speaker_ctl:\n");
return 0;
}
static int
zzax_getdev(void *hdl, struct audio_device *ret)
{
*ret = zzax_device;
printf("zzax_getdev: %p\n", ret);
return 0;
}
static int
zzax_set_port(void *hdl, mixer_ctrl_t *mc)
{
printf("zzax_set_port:\n");
return 0;
}
static int
zzax_get_port(void *hdl, mixer_ctrl_t *mc)
{
printf("zzax_get_port:\n");
return 0;
}
static int
zzax_query_devinfo(void *hdl, mixer_devinfo_t *di)
{
switch(di->index) {
case ZZAX_CHANNELS:
strcpy(di->label.name, "speaker");
di->type = AUDIO_MIXER_SET;
di->mixer_class = ZZAX_OUTPUT_CLASS;
di->prev = AUDIO_MIXER_LAST;
di->next = AUDIO_MIXER_LAST;
di->un.s.num_mem = 1;
strcpy(di->un.s.member[0].label.name, "channel0");
di->un.s.member[0].mask = 0;
case ZZAX_VOLUME:
strcpy(di->label.name, "master");
di->type = AUDIO_MIXER_VALUE;
di->mixer_class = ZZAX_OUTPUT_CLASS;
di->prev = AUDIO_MIXER_LAST;
di->next = AUDIO_MIXER_LAST;
di->un.v.num_channels = 1;
strcpy(di->un.v.units.name, "volume");
break;
case ZZAX_OUTPUT_CLASS:
strcpy(di->label.name, "outputs");
di->type = AUDIO_MIXER_CLASS;
di->mixer_class = ZZAX_OUTPUT_CLASS;
di->prev = AUDIO_MIXER_LAST;
di->next = AUDIO_MIXER_LAST;
break;
default:
return ENXIO;
}
printf("zzax_query_devinfo: %s\n", di->label.name);
return 0;
}
#if 0
static void*
zzax_allocm(void *hdl, int direction, size_t size)
{
}
static void
zzax_freem(void *hdl, void *addr, size_t size)
{
}
#endif
static size_t
zzax_round_buffersize(void *hdl, int direction, size_t bufsize)
{
printf("zzax_round_buffersize:\n");
printf("::direction: %i\n", direction);
printf("::bufsize: %zu\n", bufsize);
return bufsize;
}
static int
zzax_get_props(void *hdl)
{
return AUDIO_PROP_PLAYBACK;
}
static int
zzax_trigger_output(void *hdl, void *start, void *end, int blksize,
void (*intr)(void*), void *intrarg, const audio_params_t *param)
{
printf("zzax_trigger_output:\n");
return 0;
}
static int
zzax_trigger_input(void *hdl, void *start, void *end, int blksize,
void (*intr)(void*), void *intrarg, const audio_params_t *param)
{
return 0;
}
static int
zzax_dev_ioctl(void *hdl, u_long cmd, void *addr, int flag, struct lwp *l)
{
printf("zzax_dev_ioctl: %lu\n", cmd);
return 0;
}
static void
zzax_get_locks(void *hdl, kmutex_t **intr, kmutex_t **thread)
{
struct zzax_softc *sc = hdl;
*intr = &sc->sc_intr_lock;
*thread = &sc->sc_lock;
}
|