2 * Emuxki BeOS Driver for Creative Labs SBLive!/Audigy series
4 * Copyright (c) 2002, Jerome Duval (jerome.duval@free.fr)
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Original code : Copyright 1999, Be Incorporated. All Rights Reserved.
29 * This file may be used under the terms of the Be Sample Code License.
39 #include "midi_driver.h"
42 extern generic_mpu401_module
* mpu401
;
50 // dprint seems to be disabled here, will have to enable it to trace
52 midi_dev
* port
= (midi_dev
*)data
;
54 LOG(("mpu401:midi_interrupt_op %x\n",op
));
55 LOG(("port = %p\n", port
));
56 if (op
== B_MPU_401_ENABLE_CARD_INT
) {
57 /* turn on MPU interrupts */
58 LOG(("emuxki: B_MPU_401_ENABLE_CARD_INT\n"));
60 emuxki_reg_write_32(&(port
->card
->config
), EMU_INTE
,
61 emuxki_reg_read_32(&(port
->card
->config
), EMU_INTE
) | EMU_INTE_MIDIRXENABLE
);
63 LOG(("INTE address: %x\n",&port
->card
->config
));
65 else if (op
== B_MPU_401_DISABLE_CARD_INT
) {
66 /* turn off MPU interrupts */
67 LOG(("emuxki: B_MPU_401_DISABLE_CARD_INT\n"));
69 emuxki_reg_write_32(&port
->card
->config
, EMU_INTE
,
70 emuxki_reg_read_32(&port
->card
->config
, EMU_INTE
) & ~ EMU_INTE_MIDIRXENABLE
);
74 LOG(("midi_interrupt_op() done\n"));
77 static status_t
midi_open(const char *name
, uint32 flags
, void **cookie
);
78 static status_t
midi_close(void *cookie
);
79 static status_t
midi_free(void *cookie
);
80 static status_t
midi_control(void *cookie
, uint32 op
, void *data
, size_t len
);
81 static status_t
midi_read(void *cookie
, off_t pos
, void *data
, size_t *len
);
82 static status_t
midi_write(void *cookie
, off_t pos
, const void *data
, size_t *len
);
85 device_hooks midi_hooks
= {
107 LOG(("midi_open()\n"));
110 for (ix
=0; ix
<num_cards
; ix
++) {
111 if (!strcmp(name
, cards
[ix
].midi
.name
)) {
115 if (ix
>= num_cards
) {
116 LOG(("bad device\n"));
120 LOG(("mpu401: %p open(): %p driver: %p\n", mpu401
, mpu401
->open_hook
, cards
[ix
].midi
.driver
));
121 ret
= (*mpu401
->open_hook
)(cards
[ix
].midi
.driver
, flags
, cookie
);
123 cards
[ix
].midi
.cookie
= *cookie
;
124 atomic_add(&cards
[ix
].midi
.count
, 1);
126 LOG(("mpu401: open returns %x / %p\n", ret
, *cookie
));
135 LOG(("midi_close()\n"));
136 return (*mpu401
->close_hook
)(cookie
);
146 LOG(("midi_free()\n"));
147 f
= (*mpu401
->free_hook
)(cookie
);
148 for (ix
=0; ix
<num_cards
; ix
++) {
149 if (cards
[ix
].midi
.cookie
== cookie
) {
150 if (atomic_add(&cards
[ix
].midi
.count
, -1) == 1) {
151 cards
[ix
].midi
.cookie
= NULL
;
152 LOG(("cleared %p card %d\n", cookie
, ix
));
157 LOG(("midi_free() done\n"));
169 return (*mpu401
->control_hook
)(cookie
, iop
, data
, len
);
180 return (*mpu401
->read_hook
)(cookie
, pos
, ptr
, nread
);
191 return (*mpu401
->write_hook
)(cookie
, pos
, ptr
, nwritten
);
196 midi_interrupt(emuxki_dev
*card
)
198 TRACE(("midi_interrupt\n"));
199 if (!card
->midi
.driver
) {
204 return (*mpu401
->interrupt_hook
)(card
->midi
.driver
);