Generic MPU401 driver: Add Ice1712 card, Fix line size > 80
This commit is contained in:
committed by
Jérôme Duval
parent
1684be5e39
commit
6ffb178a00
@@ -28,7 +28,8 @@
|
||||
/*-----------------------------*/
|
||||
|
||||
static status_t
|
||||
create_device(int port, void ** out_storage, uint32 workarounds, void (*interrupt_op)(int32 op, void * card), void * card)
|
||||
create_device(int port, void ** out_storage, uint32 workarounds,
|
||||
void (*interrupt_op)(int32 op, void * card), void * card)
|
||||
{
|
||||
mpu401device mpu_device;
|
||||
mpu401device *mpuptr;
|
||||
@@ -41,7 +42,8 @@ create_device(int port, void ** out_storage, uint32 workarounds, void (*interrup
|
||||
mpu_device.interrupt_op = interrupt_op;
|
||||
mpu_device.card = card;
|
||||
|
||||
LOG(("create_device count= %ld, addrport 0x%x, workarounds: %d",mpu_device.count, mpu_device.addrport, mpu_device.workarounds));
|
||||
LOG(("create_device count= %ld, addrport 0x%x, workarounds: %d",
|
||||
mpu_device.count, mpu_device.addrport, mpu_device.workarounds));
|
||||
|
||||
// basically, each call to create device allocates memory for
|
||||
//a structure with the specific device info. The pointer to this is
|
||||
@@ -57,15 +59,14 @@ create_device(int port, void ** out_storage, uint32 workarounds, void (*interrup
|
||||
/*-----------------------------*/
|
||||
|
||||
static status_t
|
||||
create_device_v2(int port, void ** out_storage, uint32 workarounds, void (*interrupt_op)(int32 op, void * card), void * card)
|
||||
create_device_v2(int port, void ** out_storage, uint32 workarounds,
|
||||
void (*interrupt_op)(int32 op, void * card), void * card)
|
||||
{
|
||||
mpu401device *mpuptr;
|
||||
mpu401device mpu_device;
|
||||
|
||||
LOG(("v2: create_device, **out_storage %p ,workarounds %ld ,void *card %p\n",out_storage, workarounds, card));
|
||||
|
||||
// not sure exactly how v2 of the module works. I think that two ports are
|
||||
// created. One for midi in data, and another for midi out data.
|
||||
// not sure exactly how v2 of the module works. I think that two ports
|
||||
// are created. One for midi in data, and another for midi out data.
|
||||
// Instead of transfering data using a buffer and pointer, the midi
|
||||
// data is transfered via the global ports.
|
||||
// If the ports are created in the midi server, then the port id's
|
||||
@@ -73,16 +74,18 @@ create_device_v2(int port, void ** out_storage, uint32 workarounds, void (*inter
|
||||
// If the ports are created in this hook call, the the port id's
|
||||
// should be returned to the midi server.
|
||||
|
||||
// One version of read/write hook functions are used for both v1, v2. Therefore, in
|
||||
// those calls, it needs to be known whether the mididata is to be read/written
|
||||
// to a buffer, or to the port.
|
||||
// One version of read/write hook functions are used for both v1, v2.
|
||||
// Therefore, in those calls, it needs to be known whether the mididata
|
||||
// is to be read/written to a buffer, or to the port.
|
||||
|
||||
mpu_device.addrport = port;
|
||||
mpu_device.workarounds = workarounds;
|
||||
mpu_device.V2 = TRUE;
|
||||
mpu_device.count =1;
|
||||
mpu_device.count = 1;
|
||||
mpu_device.card = card;
|
||||
|
||||
LOG(("create_device count= %ld, addrport 0x%x, workarounds: %d",
|
||||
mpu_device.count, mpu_device.addrport, mpu_device.workarounds));
|
||||
|
||||
mpuptr = (mpu401device*)malloc(sizeof(mpu401device));
|
||||
memcpy(mpuptr, &mpu_device, sizeof(mpu_device));
|
||||
@@ -100,8 +103,9 @@ delete_device(void * storage)
|
||||
{
|
||||
mpu401device * mpu_device = (mpu401device *)storage;
|
||||
|
||||
LOG(("device->addrport= 0x%x count= %ld\n",mpu_device->addrport, mpu_device->count));
|
||||
LOG(("delete_device: *storage:%p\n",storage));
|
||||
LOG(("device->addrport= 0x%x count= %ld\n",
|
||||
mpu_device->addrport, mpu_device->count));
|
||||
LOG(("delete_device: *storage:%p\n", storage));
|
||||
|
||||
free(mpu_device); // free the memory allocated in create_device
|
||||
|
||||
@@ -119,8 +123,10 @@ midi_open(void * storage, uint32 flags, void ** out_cookie)
|
||||
int ack_byte;
|
||||
mpu401device * mpu_device = (mpu401device *)storage;
|
||||
|
||||
LOG(("open() flags: %ld, * storage: %p, **out_cookie: %p\n",flags, storage,out_cookie));
|
||||
LOG(("open: device->addrport 0x%x ,workarounds 0x%x\n",mpu_device->addrport, mpu_device->workarounds));
|
||||
LOG(("open() flags: %ld, *storage: %p, **out_cookie: %p\n", flags,
|
||||
storage, out_cookie));
|
||||
LOG(("open: device->addrport 0x%x ,workarounds 0x%x\n",
|
||||
mpu_device->addrport, mpu_device->workarounds));
|
||||
|
||||
// the undocumented V2 module is not complete
|
||||
// we will allow the device to be created since some drivers depend on it
|
||||
@@ -129,29 +135,55 @@ midi_open(void * storage, uint32 flags, void ** out_cookie)
|
||||
return B_ERROR;
|
||||
|
||||
switch (mpu_device->workarounds){
|
||||
case 0x11020004: // This is still required for Creative Audigy, Audidy2
|
||||
case 0x11020004: // Still required for Creative Audigy, Audigy2
|
||||
case 0x11020005:
|
||||
case 0:
|
||||
// don't know the current mpu state
|
||||
PRINT(("reset MPU401\n"));
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD, mpu_device->workarounds, MPU401_RESET);
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds, MPU401_RESET);
|
||||
snooze(30000);
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD, mpu_device->workarounds, MPU401_RESET);
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds, MPU401_RESET);
|
||||
snooze(30000);
|
||||
ack_byte = Read_MPU401(mpu_device->addrport, UARTDATA, mpu_device->workarounds);
|
||||
ack_byte = Read_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds);
|
||||
PRINT(("enable UART mode\n"));
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD, mpu_device->workarounds, MPU401_UART);
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds, MPU401_UART);
|
||||
snooze(30000);
|
||||
ack_byte = Read_MPU401(mpu_device->addrport, UARTDATA, mpu_device->workarounds );
|
||||
ack_byte = Read_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds );
|
||||
PRINT(("port cmd ack is 0x%x\n", ack_byte));
|
||||
*out_cookie = mpu_device;
|
||||
break;
|
||||
case 0x14121712:
|
||||
PRINT(("reset MPU401\n"));
|
||||
Write_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds, 0x00);
|
||||
snooze(30000);
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds, MPU401_RESET);
|
||||
snooze(30000);
|
||||
ack_byte = Read_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds);
|
||||
PRINT(("enable UART mode\n"));
|
||||
Write_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds, 0x00);
|
||||
snooze(30000);
|
||||
Write_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds, MPU401_UART);
|
||||
snooze(30000);
|
||||
ack_byte = Read_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds );
|
||||
PRINT(("port cmd ack is 0x%x\n", ack_byte));
|
||||
break;
|
||||
case 1:
|
||||
// Some devices are always in UART mode
|
||||
PRINT(("already in UART mode\n"));
|
||||
break;
|
||||
default:
|
||||
PRINT(("Unknown workaround value: %d\n", mpu_device->workarounds));
|
||||
PRINT(("Unknown workaround: %d\n", mpu_device->workarounds));
|
||||
break;
|
||||
} //end switch
|
||||
|
||||
@@ -164,12 +196,12 @@ midi_open(void * storage, uint32 flags, void ** out_cookie)
|
||||
mpu_device->writesemaphore = create_sem(1, semname);
|
||||
|
||||
// clear midi-in buffer
|
||||
mbuf_bytes=0;
|
||||
mbuf_bytes = 0;
|
||||
mbuf_current=0;
|
||||
mbuf_start=0;
|
||||
|
||||
//Enable midi interrupts
|
||||
mpu_device->interrupt_op(B_MPU_401_ENABLE_CARD_INT, mpu_device->card );
|
||||
mpu_device->interrupt_op(B_MPU_401_ENABLE_CARD_INT, mpu_device->card);
|
||||
|
||||
if ((mpu_device->readsemaphore > B_OK)
|
||||
&& (mpu_device->writesemaphore > B_OK)) {
|
||||
@@ -192,7 +224,7 @@ midi_close(void * cookie)
|
||||
return B_ERROR;
|
||||
|
||||
//Disable soundcard midi interrupts
|
||||
mpu_device->interrupt_op(B_MPU_401_DISABLE_CARD_INT, mpu_device->card );
|
||||
mpu_device->interrupt_op(B_MPU_401_DISABLE_CARD_INT, mpu_device->card);
|
||||
|
||||
// Delete the semaphores
|
||||
delete_sem(mpu_device->readsemaphore);
|
||||
@@ -249,7 +281,8 @@ midi_read(void *cookie, off_t pos, void *buffer, size_t *num_bytes)
|
||||
|
||||
i=0;
|
||||
*num_bytes=0;
|
||||
bestat = acquire_sem_etc ( mpu_device->readsemaphore, 1, B_CAN_INTERRUPT, 0);
|
||||
bestat = acquire_sem_etc(mpu_device->readsemaphore, 1,
|
||||
B_CAN_INTERRUPT, 0);
|
||||
if (bestat == B_INTERRUPTED) {
|
||||
//PRINT(("acquire_sem B_INTERRUPTED!\n"));
|
||||
return B_INTERRUPTED;
|
||||
@@ -258,15 +291,14 @@ midi_read(void *cookie, off_t pos, void *buffer, size_t *num_bytes)
|
||||
TRACE(("acquire_sem not B_OK %d\n",(int)bestat));
|
||||
*num_bytes = 1;
|
||||
return B_INTERRUPTED;
|
||||
}
|
||||
if (bestat == B_OK) {
|
||||
} else {
|
||||
status = lock();
|
||||
*(data+i) = mpubuffer[mbuf_start];
|
||||
i++;
|
||||
mbuf_start++; // pointer to data in ringbuffer
|
||||
if (mbuf_start >= (MBUF_ELEMENTS-1))
|
||||
mbuf_start = 0; //wraparound of ringbuffer
|
||||
*num_bytes =1; // tell caller how many bytes are being returned in buffer
|
||||
*num_bytes = 1; // How many bytes are being returned in buffer
|
||||
if (mbuf_bytes>0)
|
||||
mbuf_bytes--; // bytes read from buffer, so decrement buffer count
|
||||
unlock(status);
|
||||
@@ -291,13 +323,17 @@ midi_write(void * cookie, off_t pos, const void * data, size_t * num_bytes)
|
||||
count = *num_bytes;
|
||||
|
||||
/* Only for deep debugging..will slow things down */
|
||||
//PRINT(("write %d bytes, addrport 0x%x, workarounds 0x%x\n",(int)count,mpu_device->addrport, mpu_device->workarounds));
|
||||
/*PRINT(("write %d bytes, addrport 0x%x, workarounds 0x%x\n",
|
||||
(int)count, mpu_device->addrport, mpu_device->workarounds));*/
|
||||
|
||||
acquire_sem(mpu_device->writesemaphore);
|
||||
for (i=0; i<count; i++) {
|
||||
// wait until device is ready
|
||||
while ((Read_MPU401(mpu_device->addrport, UARTCMD, mpu_device->workarounds) & MPU401_OK2WR));
|
||||
Write_MPU401(mpu_device->addrport, UARTDATA, mpu_device->workarounds, *(bufdata+i));
|
||||
while ((Read_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds) & MPU401_OK2WR));
|
||||
|
||||
Write_MPU401(mpu_device->addrport, UARTDATA,
|
||||
mpu_device->workarounds, *(bufdata+i));
|
||||
}
|
||||
|
||||
*num_bytes = 0;
|
||||
@@ -314,26 +350,32 @@ interrupt_hook(void * cookie)
|
||||
status_t bestat;
|
||||
mpu401device *mpu_device = (mpu401device *)cookie;
|
||||
|
||||
//PRINT(("irq! port: 0x%x\n",mpu_device->addrport)); /* Only for deep debugging..will slow things down */
|
||||
/* Only for deep debugging..will slow things down */
|
||||
//PRINT(("irq! port: 0x%x\n",mpu_device->addrport));
|
||||
|
||||
/* Input data is available when bit 7 of the Status port is zero. Conversely, when bit 7 is
|
||||
is a one, no MIDI data is available. Reading from the data port will often clear the
|
||||
interrupt signal depending on the sound card. */
|
||||
/* Input data is available when bit 7 of the Status port is zero.
|
||||
Conversely, when bit 7 is is a one, no MIDI data is available.
|
||||
Reading from the data port will often clear the interrupt signal
|
||||
depending on the sound card. */
|
||||
|
||||
if ((Read_MPU401(mpu_device->addrport, UARTCMD, mpu_device->workarounds) & MPU401_OK2RD) == 0) {
|
||||
if ((Read_MPU401(mpu_device->addrport, UARTCMD,
|
||||
mpu_device->workarounds) & MPU401_OK2RD) == 0) {
|
||||
/* Okay, midi data waiting to be read from device */
|
||||
if (mbuf_current >= (MBUF_ELEMENTS-1))
|
||||
mbuf_current = 0;
|
||||
|
||||
/* store midi data byte into buffer */
|
||||
mpubuffer[mbuf_current] = Read_MPU401(mpu_device->addrport,
|
||||
UARTDATA, mpu_device->workarounds); /* store midi data byte into buffer */
|
||||
UARTDATA, mpu_device->workarounds);
|
||||
mbuf_current++; /* pointer to next blank byte */
|
||||
mbuf_bytes++; /* increment count of midi data bytes */
|
||||
|
||||
bestat = release_sem_etc(mpu_device->readsemaphore, 1, B_DO_NOT_RESCHEDULE);
|
||||
bestat = release_sem_etc(mpu_device->readsemaphore, 1,
|
||||
B_DO_NOT_RESCHEDULE);
|
||||
|
||||
return TRUE; //B_INVOKE_SCHEDULER
|
||||
}
|
||||
|
||||
/* No midi data from this interrupt */
|
||||
return FALSE; //B_UNHANDLED_INTERRUPT
|
||||
}
|
||||
@@ -341,13 +383,15 @@ interrupt_hook(void * cookie)
|
||||
/*-----------------------------------------------------------------*/
|
||||
|
||||
uchar
|
||||
Read_MPU401(unsigned int addrport, const char cmdtype, unsigned int workarounds)
|
||||
Read_MPU401(unsigned int addrport, const char cmdtype,
|
||||
unsigned int workarounds)
|
||||
{
|
||||
uchar mpudatabyte;
|
||||
cpu_status status;
|
||||
unsigned int regptr;
|
||||
|
||||
//PRINT(("read workaround 0x%x\n",workarounds)); /* Only for deep debugging..will slow things down */
|
||||
/* Only for deep debugging..will slow things down */
|
||||
//PRINT(("read workaround 0x%x\n",workarounds));
|
||||
switch (workarounds) {
|
||||
case 0x11020004: /* Creative Audigy Gameport */
|
||||
regptr = (((I_MPU1 + cmdtype) << 16) & PTR_ADDRESS_MASK);
|
||||
@@ -365,8 +409,14 @@ Read_MPU401(unsigned int addrport, const char cmdtype, unsigned int workarounds)
|
||||
unlock(status);
|
||||
break;
|
||||
|
||||
case 0x14121712:
|
||||
status = lock();
|
||||
mpudatabyte = gPCI->read_io_8(addrport + cmdtype);
|
||||
unlock(status);
|
||||
break;
|
||||
|
||||
default:
|
||||
mpudatabyte = gISA->read_io_8(addrport + cmdtype );
|
||||
mpudatabyte = gISA->read_io_8(addrport + cmdtype);
|
||||
break;
|
||||
}
|
||||
return mpudatabyte;
|
||||
@@ -374,7 +424,8 @@ Read_MPU401(unsigned int addrport, const char cmdtype, unsigned int workarounds)
|
||||
|
||||
|
||||
status_t
|
||||
Write_MPU401(unsigned int addrport, const char cmdtype, unsigned int workarounds, uchar mpudatabyte )
|
||||
Write_MPU401(unsigned int addrport, const char cmdtype,
|
||||
unsigned int workarounds, uchar mpudatabyte)
|
||||
{
|
||||
cpu_status status;
|
||||
unsigned int regptr;
|
||||
@@ -398,6 +449,12 @@ Write_MPU401(unsigned int addrport, const char cmdtype, unsigned int workarounds
|
||||
unlock(status);
|
||||
break;
|
||||
|
||||
case 0x14121712:
|
||||
status = lock();
|
||||
gPCI->write_io_8(addrport + cmdtype, mpudatabyte);
|
||||
unlock(status);
|
||||
break;
|
||||
|
||||
default:
|
||||
gISA->write_io_8(addrport + cmdtype, mpudatabyte);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user