some cleanup

better error handling in setup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23572 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2008-01-16 23:31:34 +00:00
parent 1839792524
commit a75118d464
3 changed files with 61 additions and 37 deletions

View File

@ -13,16 +13,16 @@
#include <Drivers.h>
#include <Errors.h>
#include <OS.h>
#include <malloc.h>
#include <fcntl.h>
#include <image.h>
#include <malloc.h>
#include <midi_driver.h>
#include <string.h>
#include "debug.h"
#include "ice1712.h"
#include "ice1712_reg.h"
#include "io.h"
#include "midi_driver.h"
#include "multi.h"
#include "util.h"
@ -137,7 +137,7 @@ static status_t
ice1712_setup(ice1712 *ice)
{
int result, i;
long result_l = 0;
status_t status = B_OK;
uint8 reg8 = 0;
ice->irq = ice->info.u.h0.interrupt_line;
@ -249,10 +249,13 @@ ice1712_setup(ice1712 *ice)
names[num_names] = NULL;
ice->buffer_ready_sem = create_sem(0, "Buffer Exchange");
if (ice->buffer_ready_sem < B_OK) {
return ice->buffer_ready_sem;
}
// TRACE_ICE(("installing interrupt : %0x\n", ice->irq));
result_l = install_io_interrupt_handler(ice->irq, ice_1712_int, ice, 0);
if (result_l == B_OK)
status = install_io_interrupt_handler(ice->irq, ice_1712_int, ice, 0);
if (status == B_OK)
TRACE_ICE(("Install Interrupt Handler == B_OK\n"));
else
TRACE_ICE(("Install Interrupt Handler != B_OK\n"));
@ -260,10 +263,21 @@ ice1712_setup(ice1712 *ice)
ice->mem_id_pb = alloc_mem(&ice->phys_addr_pb, &ice->log_addr_pb,
PLAYBACK_BUFFER_TOTAL_SIZE,
"playback buffer");
if (ice->mem_id_pb < B_OK) {
remove_io_interrupt_handler(ice->irq, ice_1712_int, ice);
delete_sem(ice->buffer_ready_sem);
return ice->mem_id_pb;
}
ice->mem_id_rec = alloc_mem(&ice->phys_addr_rec, &ice->log_addr_rec,
RECORD_BUFFER_TOTAL_SIZE,
"record buffer");
if (ice->mem_id_rec < B_OK) {
remove_io_interrupt_handler(ice->irq, ice_1712_int, ice);
delete_sem(ice->buffer_ready_sem);
delete_area(ice->mem_id_pb);
return(ice->mem_id_rec);
}
memset(ice->log_addr_pb, 0, PLAYBACK_BUFFER_TOTAL_SIZE);
memset(ice->log_addr_rec, 0, RECORD_BUFFER_TOTAL_SIZE);
@ -336,24 +350,19 @@ init_driver(void)
return ENOSYS;
}
while ((*pci->get_nth_pci_info)(i, &cards[num_cards].info) == B_OK)
{//TODO check other Vendor_ID and DEVICE_ID
if ((cards[num_cards].info.vendor_id == ICE1712_VENDOR_ID) &&
(cards[num_cards].info.device_id == ICE1712_DEVICE_ID))
{
if (num_cards == NUM_CARDS)
{
while ((*pci->get_nth_pci_info)(i, &cards[num_cards].info) == B_OK) {
//TODO check other Vendor_ID and DEVICE_ID
if ((cards[num_cards].info.vendor_id == ICE1712_VENDOR_ID)
&& (cards[num_cards].info.device_id == ICE1712_DEVICE_ID)) {
if (num_cards == NUM_CARDS) {
TRACE_ICE(("Too many ice1712 cards installed!\n"));
break;
}
if (ice1712_setup(&cards[num_cards]) != B_OK)
if (ice1712_setup(&cards[num_cards]) != B_OK) {
//Vendor_ID and Device_ID has been modified
{
TRACE_ICE(("Setup of ice1712 %d failed\n", num_cards + 1));
}
else
{
} else {
num_cards++;
}
}
@ -366,7 +375,7 @@ init_driver(void)
put_module(B_PCI_MODULE_NAME);
put_module(B_MPU_401_MODULE_NAME);
return ENODEV;
}
}
return B_OK;
}
@ -374,10 +383,12 @@ init_driver(void)
static void
ice_1712_shutdown(ice1712 *ice)
{
long result_l;
status_t result;
result_l = remove_io_interrupt_handler(ice->irq, ice_1712_int, ice);
if (result_l == B_OK)
delete_sem(ice->buffer_ready_sem);
result = remove_io_interrupt_handler(ice->irq, ice_1712_int, ice);
if (result == B_OK)
TRACE_ICE(("remove Interrupt result == B_OK\n"));
else
TRACE_ICE(("remove Interrupt result != B_OK\n"));
@ -426,8 +437,24 @@ publish_devices(void)
static status_t
ice_1712_open(const char *name, uint32 flags, void **cookie)
{//Not Implemented (partialy only)
{
int ix;
ice1712 *card = NULL;
TRACE_ICE(("===open()===\n"));
for (ix=0; ix<num_cards; ix++) {
if (!strcmp(cards[ix].name, name)) {
card = &cards[ix];
}
}
if (card == NULL) {
TRACE_ICE(("open() card not found %s\n", name));
for (ix=0; ix<num_cards; ix++) {
TRACE_ICE(("open() card available %s\n", cards[ix].name));
}
return B_ERROR;
}
*cookie = cards;
return B_OK;
}
@ -437,7 +464,7 @@ static status_t
ice_1712_close(void *cookie)
{
TRACE_ICE(("===close()===\n"));
return B_ERROR;
return B_OK;
}
@ -445,7 +472,7 @@ static status_t
ice_1712_free(void *cookie)
{
TRACE_ICE(("===free()===\n"));
return B_ERROR;
return B_OK;
}

View File

@ -268,8 +268,7 @@ int16 read_eeprom(ice1712 *ice, uint8 eeprom[32])
int i;
int16 tmp;
for (i = 0; i < 6; i++)
{
for (i = 0; i < 6; i++) {
tmp = read_i2c(ice, I2C_EEPROM_ADDRESS_READ, i);
if (tmp >= 0)
eeprom[i] = (uint8)tmp;
@ -278,8 +277,7 @@ int16 read_eeprom(ice1712 *ice, uint8 eeprom[32])
}
if (eeprom[4] > 32)
return -1;
for (i = 6; i < eeprom[4]; i++)
{
for (i = 6; i < eeprom[4]; i++) {
tmp = read_i2c(ice, I2C_EEPROM_ADDRESS_READ, i);
if (tmp >= 0)
eeprom[i] = (uint8)tmp;
@ -366,8 +364,7 @@ ak45xx_write_gpio(ice1712 *ice, uint8 reg_addr, uint8 data, uint8 chip_select)
write_gpio(ice, tmp);
snooze(AK45xx_DELAY);
for (i = 0; i < AK45xx_BITS_TO_WRITE; i++)
{
for (i = 0; i < AK45xx_BITS_TO_WRITE; i++) {
// drop clock and data bits
tmp &= ~(ice->analog_codec.clock | ice->analog_codec.data_out);
@ -415,8 +412,7 @@ cs84xx_write_gpio(ice1712 *ice, uint8 reg_addr, uint8 data, uint8 chip_select)
write_gpio(ice, tmp);
snooze(CS84xx_DELAY);
for (i = 0; i < CS84xx_BITS_TO_WRITE; i++)
{
for (i = 0; i < CS84xx_BITS_TO_WRITE; i++) {
// drop clock and data bits
tmp &= ~(ice->digital_codec.clock | ice->digital_codec.data_out);

View File

@ -95,6 +95,7 @@ start_DMA(ice1712 *card)
write_mt_uint8(card, MT_PROF_PB_CONTROL, 5);
}
status_t
ice1712_get_description(ice1712 *card, multi_description *data)
{
@ -312,19 +313,19 @@ ice1712_set_global_format(ice1712 *card, multi_format_info *data)
TRACE_ICE(("Input Sampling Rate = %#x\n", data->input.rate));
TRACE_ICE(("Output Sampling Rate = %#x\n", data->output.rate));
if ((data->input.rate == data->output.rate) &&
(card->lock_source == B_MULTI_LOCK_INTERNAL)) {
if ((data->input.rate == data->output.rate)
&& (card->lock_source == B_MULTI_LOCK_INTERNAL)) {
switch (data->input.rate)
{
case B_SR_96000 :
card->sampling_rate = 0x07;
break;
case B_SR_48000 :
card->sampling_rate = 0x00;
break;
case B_SR_88200 :
card->sampling_rate = 0x0B;
break;
case B_SR_48000 :
card->sampling_rate = 0x00;
break;
case B_SR_44100 :
card->sampling_rate = 0x08;
break;