Author: korli Date: 2010-02-01 22:27:42 +0100 (Mon, 01 Feb 2010) New Revision: 35385 Changeset: http://dev.haiku-os.org/changeset/35385/haiku Removed: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.c Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/midi.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/multi.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/multi.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/util.c Log: update from Jerome Leveque, with style changes by me (I hope you don't mind). Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile 2010-02-01 21:18:11 UTC (rev 35384) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile 2010-02-01 21:27:42 UTC (rev 35385) @@ -5,7 +5,6 @@ UsePrivateHeaders media ; KernelAddon ice1712 : - debug.c ice1712.c io.c midi.c Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h 2010-02-01 21:18:11 UTC (rev 35384) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h 2010-02-01 21:27:42 UTC (rev 35385) @@ -8,47 +8,22 @@ * All rights reserved * Distributed under the terms of the MIT license. */ +#ifndef _DEBUG_ICE1712_H_ +#define _DEBUG_ICE1712_H_ -#ifndef _DEBUG_H_ -#define _DEBUG_H_ +#include <Debug.h> -/* - * PRINT() executes dprintf if DEBUG = 0 (disabled), or expands to LOG() when DEBUG > 0 - * TRACE() executes dprintf if DEBUG > 0 - * LOG() executes dprintf and writes to the logfile if DEBUG > 0 - */ - -/* DEBUG == 0, no debugging, PRINT writes to syslog - * DEBUG == 1, TRACE & LOG, PRINT - * DEBUG == 2, TRACE & LOG, PRINT with snooze() - */ -#undef DEBUG - -#ifndef DEBUG -// #define DEBUG 1 +#ifdef TRACE +# undef TRACE #endif -#undef PRINT_ICE -#undef TRACE_ICE -#undef ASSERT_ICE - -#if DEBUG > 0 - #define PRINT_ICE(a) log_printf a -// #define TRACE_ICE(a) debug_printf a - #define TRACE_ICE(a) log_printf a - #define LOG_ICE(a) log_printf a - #define LOG_CREATE_ICE() log_create() - #define ASSERT_ICE(a) if (a) {} else LOG_ICE(("ASSERT failed! file = %s, line = %d\n",__FILE__,__LINE__)) - void log_create(); - void log_printf(const char *text,...); - void debug_printf(const char *text,...); +#define TRACE_MULTI_AUDIO +#ifdef TRACE_MULTI_AUDIO +# define TRACE(a...) dprintf("\33[34mice1712:\33[0m " a) #else - void debug_printf(const char *text,...); - #define PRINT_ICE(a) debug_printf a - #define TRACE_ICE(a) ((void)(0)) - #define ASSERT_ICE(a) ((void)(0)) - #define LOG_ICE(a) ((void)(0)) - #define LOG_CREATE_ICE() +# define TRACE(a...) ; #endif -#endif +#define ICE1712_VERY_VERBOSE 0 + +#endif // _DEBUG_ICE1712_H_ Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c 2010-02-01 21:18:11 UTC (rev 35384) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c 2010-02-01 21:27:42 UTC (rev 35385) @@ -25,7 +25,6 @@ #include "multi.h" #include "util.h" - //------------------------------------------------------ //------------------------------------------------------ @@ -66,6 +65,10 @@ //extern status_t unload_kernel_addon(image_id imid); //------------------------------------------------------ + +static status_t load_settings(ice1712 *ice); +static status_t save_settings(ice1712 *ice); + //------------------------------------------------------ status_t init_hardware(void) @@ -74,8 +77,7 @@ pci_info info; memset(cards, 0, sizeof(ice1712) * NUM_CARDS); - LOG_CREATE_ICE(); - TRACE_ICE(("===init_hardware()===\n")); + TRACE("===init_hardware()===\n"); if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci)) return ENOSYS; @@ -83,7 +85,7 @@ while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { if ((info.vendor_id == ICE1712_VENDOR_ID) && (info.device_id == ICE1712_DEVICE_ID)) { - TRACE_ICE(("Found at least 1 card\n")); + TRACE("Found at least 1 card\n"); put_module(B_PCI_MODULE_NAME); return B_OK; } @@ -107,6 +109,7 @@ if (reg8 != 0) { ice->buffer++; ice->played_time = system_time(); + ice->frames_count += ice->buffer_size; release_sem_etc(ice->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); write_mt_uint8(ice, MT_DMA_INT_MASK_STATUS, reg8); @@ -153,10 +156,10 @@ result = read_eeprom(ice, ice->eeprom_data); -/* TRACE_ICE(("EEprom -> ")); +/* TRACE("EEprom -> "); for (i = 0; i < 32; i++) - TRACE_ICE(("%x, ", eeprom_data[i])); - TRACE_ICE(("<- EEprom\n"));*/ + TRACE("%x, ", eeprom_data[i]); + TRACE("<- EEprom\n");*/ write_ccs_uint8(ice, CCS_SERR_SHADOW, 0x01); @@ -164,15 +167,15 @@ ice->info.device_id = ice->eeprom_data[E2PROM_MAP_SUBVENDOR_HIGH] << 8 | ice->eeprom_data[E2PROM_MAP_SUBVENDOR_LOW]; ice->info.vendor_id = ice->eeprom_data[E2PROM_MAP_SUBDEVICE_HIGH] << 8 | ice->eeprom_data[E2PROM_MAP_SUBDEVICE_LOW]; ice->product = ice->info.vendor_id << 16 | ice->info.device_id; - TRACE_ICE(("Product ID : 0x%x\n", ice->product)); + TRACE("Product ID : 0x%x\n", ice->product); write_cci_uint8(ice, CCI_GPIO_WRITE_MASK, ice->eeprom_data[E2PROM_MAP_GPIOMASK]); write_cci_uint8(ice, CCI_GPIO_DATA, ice->eeprom_data[E2PROM_MAP_GPIOSTATE]); write_cci_uint8(ice, CCI_GPIO_DIRECTION_CONTROL, ice->eeprom_data[E2PROM_MAP_GPIODIR]); - TRACE_ICE(("CCI_GPIO_WRITE_MASK : 0x%x\n", ice->eeprom_data[E2PROM_MAP_GPIOMASK])); - TRACE_ICE(("CCI_GPIO_DATA : 0x%x\n", ice->eeprom_data[E2PROM_MAP_GPIOSTATE])); - TRACE_ICE(("CCI_GPIO_DIRECTION_CONTROL : 0x%x\n", ice->eeprom_data[E2PROM_MAP_GPIODIR])); + TRACE("CCI_GPIO_WRITE_MASK : 0x%x\n", ice->eeprom_data[E2PROM_MAP_GPIOMASK]); + TRACE("CCI_GPIO_DATA : 0x%x\n", ice->eeprom_data[E2PROM_MAP_GPIOSTATE]); + TRACE("CCI_GPIO_DIRECTION_CONTROL : 0x%x\n", ice->eeprom_data[E2PROM_MAP_GPIODIR]); //Write Configuration in the PCI configuration Register @@ -181,7 +184,7 @@ (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x62, 1, ice->eeprom_data[E2PROM_MAP_I2S]); (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x63, 1, ice->eeprom_data[E2PROM_MAP_SPDIF]); - TRACE_ICE(("E2PROM_MAP_CONFIG : 0x%x\n", ice->eeprom_data[E2PROM_MAP_CONFIG])); + TRACE("E2PROM_MAP_CONFIG : 0x%x\n", ice->eeprom_data[E2PROM_MAP_CONFIG]); reg8 = ice->eeprom_data[E2PROM_MAP_CONFIG]; //Bits signification for E2PROM_MAP_CONFIG Byte // @@ -199,14 +202,14 @@ reg8 >>= 2; if ((reg8 & 0x01) != 0) {//Consumer AC'97 Exist - TRACE_ICE(("Consumer AC'97 does exist\n")); + TRACE("Consumer AC'97 does exist\n"); //For now do nothing /* write_ccs_uint8(ice, CCS_CONS_AC97_COMMAND_STATUS, 0x40); snooze(10000); write_ccs_uint8(ice, CCS_CONS_AC97_COMMAND_STATUS, 0x00); snooze(20000); */ } else { - TRACE_ICE(("Consumer AC'97 does NOT exist\n")); + TRACE("Consumer AC'97 does NOT exist\n"); } reg8 >>= 1; ice->nb_MPU401 = (reg8 & 0x1) + 1; @@ -216,30 +219,37 @@ names[num_names++] = ice->midi_interf[i].name; } - TRACE_ICE(("E2PROM_MAP_SPDIF : 0x%x\n", ice->eeprom_data[E2PROM_MAP_SPDIF])); + TRACE("E2PROM_MAP_SPDIF : 0x%x\n", ice->eeprom_data[E2PROM_MAP_SPDIF]); ice->spdif_config = ice->eeprom_data[E2PROM_MAP_SPDIF]; - switch (ice->product) - { + switch (ice->product) { case ICE1712_SUBDEVICE_DELTA66 : case ICE1712_SUBDEVICE_DELTA44 : - ice->gpio_cs_mask = DELTA66_CLK | DELTA66_DOUT | DELTA66_CODEC_CS_0 | DELTA66_CODEC_CS_1; - ice->analog_codec = (codec_info){DELTA66_CLK, 0, DELTA66_DOUT}; + ice->commlines.clock = DELTA66_CLK; + ice->commlines.data_in = 0; + ice->commlines.data_out = DELTA66_DOUT; + ice->commlines.cs_mask = DELTA66_CLK | DELTA66_DOUT | DELTA66_CODEC_CS_0 | DELTA66_CODEC_CS_1; break; case ICE1712_SUBDEVICE_DELTA410 : case ICE1712_SUBDEVICE_AUDIOPHILE_2496 : case ICE1712_SUBDEVICE_DELTADIO2496 : - ice->gpio_cs_mask = AP2496_CLK | AP2496_DIN | AP2496_DOUT | AP2496_SPDIF_CS | AP2496_CODEC_CS; - ice->analog_codec = (codec_info){AP2496_CLK, AP2496_DIN, AP2496_DOUT}; + ice->commlines.clock = AP2496_CLK; + ice->commlines.data_in = AP2496_DIN; + ice->commlines.data_out = AP2496_DOUT; + ice->commlines.cs_mask = AP2496_CLK | AP2496_DIN | AP2496_DOUT | AP2496_SPDIF_CS | AP2496_CODEC_CS; break; case ICE1712_SUBDEVICE_DELTA1010 : case ICE1712_SUBDEVICE_DELTA1010LT : - ice->gpio_cs_mask = DELTA1010LT_CLK | DELTA1010LT_DIN | DELTA1010LT_DOUT | DELTA1010LT_CS_NONE; - ice->analog_codec = (codec_info){DELTA1010LT_CLK, DELTA1010LT_DIN, DELTA1010LT_DOUT}; + ice->commlines.clock = DELTA1010LT_CLK; + ice->commlines.data_in = DELTA1010LT_DIN; + ice->commlines.data_out = DELTA1010LT_DOUT; + ice->commlines.cs_mask = DELTA1010LT_CLK | DELTA1010LT_DIN | DELTA1010LT_DOUT | DELTA1010LT_CS_NONE; break; case ICE1712_SUBDEVICE_VX442 : - ice->gpio_cs_mask = VX442_SPDIF_CS | VX442_CODEC_CS_0 | VX442_CODEC_CS_1; - ice->analog_codec = (codec_info){VX442_CLK, VX442_DIN, VX442_DOUT}; + ice->commlines.clock = VX442_CLK; + ice->commlines.data_in = VX442_DIN; + ice->commlines.data_out = VX442_DOUT; + ice->commlines.cs_mask = VX442_SPDIF_CS | VX442_CODEC_CS_0 | VX442_CODEC_CS_1; break; } @@ -252,12 +262,12 @@ return ice->buffer_ready_sem; } -// TRACE_ICE(("installing interrupt : %0x\n", ice->irq)); +// TRACE("installing interrupt : %0x\n", ice->irq); status = install_io_interrupt_handler(ice->irq, ice_1712_int, ice, 0); if (status == B_OK) - TRACE_ICE(("Install Interrupt Handler == B_OK\n")); + TRACE("Install Interrupt Handler == B_OK\n"); else - TRACE_ICE(("Install Interrupt Handler != B_OK\n")); + TRACE("Install Interrupt Handler != B_OK\n"); ice->mem_id_pb = alloc_mem(&ice->phys_addr_pb, &ice->log_addr_pb, PLAYBACK_BUFFER_TOTAL_SIZE, @@ -281,10 +291,12 @@ memset(ice->log_addr_pb, 0, PLAYBACK_BUFFER_TOTAL_SIZE); memset(ice->log_addr_rec, 0, RECORD_BUFFER_TOTAL_SIZE); + load_settings(ice); + ice->sampling_rate = 0x08; ice->buffer = 0; - ice->output_buffer_size = MAX_BUFFER_FRAMES; - ice->input_buffer_size = MAX_BUFFER_FRAMES; + ice->frames_count = 0; + ice->buffer_size = MAX_BUFFER_FRAMES; ice->total_output_channels = ice->nb_DAC; if (ice->spdif_config & NO_IN_YES_OUT) @@ -295,10 +307,17 @@ ice->total_input_channels += 2; //Write bits in the GPIO - write_cci_uint8(ice, CCI_GPIO_WRITE_MASK, ~(ice->gpio_cs_mask)); + write_cci_uint8(ice, CCI_GPIO_WRITE_MASK, ~(ice->commlines.cs_mask)); //Deselect CS - write_cci_uint8(ice, CCI_GPIO_DATA, ice->gpio_cs_mask); + write_cci_uint8(ice, CCI_GPIO_DATA, ice->commlines.cs_mask); + //Set the rampe volume to a faster one + write_mt_uint16(ice, MT_VOLUME_CONTROL_RATE, 0x01); + + //Digital Mixer To DAC 0 and SPDIF Out +// write_mt_uint16(ice, MT_ROUTING_CONTROL_PSDOUT, 0x0101); +// write_mt_uint16(ice, MT_ROUTING_CONTROL_SPDOUT, 0x0005); + //Just to route all input to all output // write_mt_uint16(ice, MT_ROUTING_CONTROL_PSDOUT, 0xAAAA); // write_mt_uint32(ice, MT_CAPTURED_DATA, 0x76543210); @@ -318,15 +337,15 @@ write_ccs_uint8(ice, CCS_CONTROL_STATUS, 0x41); reg8 = read_ccs_uint8(ice, CCS_INTERRUPT_MASK); - TRACE_ICE(("-----CCS----- = %x\n", reg8)); + TRACE("-----CCS----- = %x\n", reg8); write_ccs_uint8(ice, CCS_INTERRUPT_MASK, 0x6F); /* reg16 = read_ds_uint16(ice, DS_DMA_INT_MASK); - TRACE_ICE(("-----DS_DMA----- = %x\n", reg16)); + TRACE("-----DS_DMA----- = %x\n", reg16); write_ds_uint16(ice, DS_DMA_INT_MASK, 0x0000); */ reg8 = read_mt_uint8(ice, MT_DMA_INT_MASK_STATUS); - TRACE_ICE(("-----MT_DMA----- = %x\n", reg8)); + TRACE("-----MT_DMA----- = %x\n", reg8); write_mt_uint8(ice, MT_DMA_INT_MASK_STATUS, 0x00); return B_OK; @@ -339,7 +358,7 @@ int i = 0; num_cards = 0; - TRACE_ICE(("===init_driver()===\n")); + TRACE("===init_driver()===\n"); if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci)) return ENOSYS; @@ -354,13 +373,13 @@ 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")); + TRACE("Too many ice1712 cards installed!\n"); break; } 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)); + TRACE("Setup of ice1712 %d failed\n", (int)(num_cards + 1)); } else { num_cards++; } @@ -368,7 +387,7 @@ i++; } - TRACE_ICE(("Number of succesfully initialised card : %d\n", num_cards)); + TRACE("Number of succesfully initialised card : %d\n", (int)num_cards); if (num_cards == 0) { put_module(B_PCI_MODULE_NAME); @@ -388,9 +407,9 @@ result = remove_io_interrupt_handler(ice->irq, ice_1712_int, ice); if (result == B_OK) - TRACE_ICE(("remove Interrupt result == B_OK\n")); + TRACE("remove Interrupt result == B_OK\n"); else - TRACE_ICE(("remove Interrupt result != B_OK\n")); + TRACE("remove Interrupt result != B_OK\n"); if (ice->mem_id_pb != B_ERROR) delete_area(ice->mem_id_pb); @@ -399,6 +418,8 @@ delete_area(ice->mem_id_rec); codec_write(ice, AK45xx_RESET_REGISTER, 0x00); + + save_settings(ice); } @@ -407,7 +428,7 @@ { int ix, cnt = num_cards; - TRACE_ICE(("===uninit_driver()===\n")); + TRACE("===uninit_driver()===\n"); num_cards = 0; @@ -425,10 +446,10 @@ publish_devices(void) { int ix = 0; - TRACE_ICE(("===publish_devices()===\n")); + TRACE("===publish_devices()===\n"); for (ix=0; names[ix]; ix++) { - TRACE_ICE(("publish %s\n", names[ix])); + TRACE("publish %s\n", names[ix]); } return (const char **)names; } @@ -439,7 +460,7 @@ { int ix; ice1712 *card = NULL; - TRACE_ICE(("===open()===\n")); + TRACE("===open()===\n"); for (ix=0; ix<num_cards; ix++) { if (!strcmp(cards[ix].name, name)) { @@ -448,9 +469,9 @@ } if (card == NULL) { - TRACE_ICE(("open() card not found %s\n", name)); + TRACE("open() card not found %s\n", name); for (ix=0; ix<num_cards; ix++) { - TRACE_ICE(("open() card available %s\n", cards[ix].name)); + TRACE("open() card available %s\n", cards[ix].name); } return B_ERROR; } @@ -462,7 +483,7 @@ static status_t ice_1712_close(void *cookie) { - TRACE_ICE(("===close()===\n")); + TRACE("===close()===\n"); return B_OK; } @@ -470,7 +491,7 @@ static status_t ice_1712_free(void *cookie) { - TRACE_ICE(("===free()===\n")); + TRACE("===free()===\n"); return B_OK; } @@ -478,89 +499,88 @@ static status_t ice_1712_control(void *cookie, uint32 op, void *arg, size_t len) { - switch (op) - { + switch (op) { case B_MULTI_GET_DESCRIPTION : - TRACE_ICE(("B_MULTI_GET_DESCRIPTION\n")); + TRACE("B_MULTI_GET_DESCRIPTION\n"); return ice1712_get_description((ice1712 *)cookie, (multi_description*)arg); case B_MULTI_GET_EVENT_INFO : - TRACE_ICE(("B_MULTI_GET_EVENT_INFO\n")); + TRACE("B_MULTI_GET_EVENT_INFO\n"); return B_ERROR; case B_MULTI_SET_EVENT_INFO : - TRACE_ICE(("B_MULTI_SET_EVENT_INFO\n")); + TRACE("B_MULTI_SET_EVENT_INFO\n"); return B_ERROR; case B_MULTI_GET_EVENT : - TRACE_ICE(("B_MULTI_GET_EVENT\n")); + TRACE("B_MULTI_GET_EVENT\n"); return B_ERROR; case B_MULTI_GET_ENABLED_CHANNELS : - TRACE_ICE(("B_MULTI_GET_ENABLED_CHANNELS\n")); + TRACE("B_MULTI_GET_ENABLED_CHANNELS\n"); return ice1712_get_enabled_channels((ice1712*)cookie, (multi_channel_enable*)arg); case B_MULTI_SET_ENABLED_CHANNELS : - TRACE_ICE(("B_MULTI_SET_ENABLED_CHANNELS\n")); + TRACE("B_MULTI_SET_ENABLED_CHANNELS\n"); return ice1712_set_enabled_channels((ice1712*)cookie, (multi_channel_enable*)arg); case B_MULTI_GET_GLOBAL_FORMAT : - TRACE_ICE(("B_MULTI_GET_GLOBAL_FORMAT\n")); + TRACE("B_MULTI_GET_GLOBAL_FORMAT\n"); return ice1712_get_global_format((ice1712*)cookie, (multi_format_info *)arg); case B_MULTI_SET_GLOBAL_FORMAT : - TRACE_ICE(("B_MULTI_SET_GLOBAL_FORMAT\n")); + TRACE("B_MULTI_SET_GLOBAL_FORMAT\n"); return ice1712_set_global_format((ice1712*)cookie, (multi_format_info *)arg); case B_MULTI_GET_CHANNEL_FORMATS : - TRACE_ICE(("B_MULTI_GET_CHANNEL_FORMATS\n")); + TRACE("B_MULTI_GET_CHANNEL_FORMATS\n"); return B_ERROR; case B_MULTI_SET_CHANNEL_FORMATS : - TRACE_ICE(("B_MULTI_SET_CHANNEL_FORMATS\n")); + TRACE("B_MULTI_SET_CHANNEL_FORMATS\n"); return B_ERROR; case B_MULTI_GET_MIX : - TRACE_ICE(("B_MULTI_GET_MIX\n")); + TRACE("B_MULTI_GET_MIX\n"); return ice1712_get_mix((ice1712*)cookie, (multi_mix_value_info *)arg); case B_MULTI_SET_MIX : - TRACE_ICE(("B_MULTI_SET_MIX\n")); + TRACE("B_MULTI_SET_MIX\n"); return ice1712_set_mix((ice1712*)cookie, (multi_mix_value_info *)arg); case B_MULTI_LIST_MIX_CHANNELS : - TRACE_ICE(("B_MULTI_LIST_MIX_CHANNELS\n")); + TRACE("B_MULTI_LIST_MIX_CHANNELS\n"); return ice1712_list_mix_channels((ice1712*)cookie, (multi_mix_channel_info *)arg); case B_MULTI_LIST_MIX_CONTROLS : - TRACE_ICE(("B_MULTI_LIST_MIX_CONTROLS\n")); + TRACE("B_MULTI_LIST_MIX_CONTROLS\n"); return ice1712_list_mix_controls((ice1712*)cookie, (multi_mix_control_info *)arg); case B_MULTI_LIST_MIX_CONNECTIONS : - TRACE_ICE(("B_MULTI_LIST_MIX_CONNECTIONS\n")); + TRACE("B_MULTI_LIST_MIX_CONNECTIONS\n"); return ice1712_list_mix_connections((ice1712*)cookie, (multi_mix_connection_info *)arg); case B_MULTI_GET_BUFFERS : - TRACE_ICE(("B_MULTI_GET_BUFFERS\n")); + TRACE("B_MULTI_GET_BUFFERS\n"); return ice1712_get_buffers((ice1712*)cookie, (multi_buffer_list*)arg); case B_MULTI_SET_BUFFERS : - TRACE_ICE(("B_MULTI_SET_BUFFERS\n")); + TRACE("B_MULTI_SET_BUFFERS\n"); return B_ERROR; case B_MULTI_SET_START_TIME : - TRACE_ICE(("B_MULTI_SET_START_TIME\n")); + TRACE("B_MULTI_SET_START_TIME\n"); return B_ERROR; case B_MULTI_BUFFER_EXCHANGE : -// TRACE_ICE(("B_MULTI_BUFFER_EXCHANGE\n")); +// TRACE("B_MULTI_BUFFER_EXCHANGE\n"); return ice1712_buffer_exchange((ice1712*)cookie, (multi_buffer_info *)arg); case B_MULTI_BUFFER_FORCE_STOP : - TRACE_ICE(("B_MULTI_BUFFER_FORCE_STOP\n")); + TRACE("B_MULTI_BUFFER_FORCE_STOP\n"); return ice1712_buffer_force_stop((ice1712*)cookie); case B_MULTI_LIST_EXTENSIONS : - TRACE_ICE(("B_MULTI_LIST_EXTENSIONS\n")); + TRACE("B_MULTI_LIST_EXTENSIONS\n"); return B_ERROR; case B_MULTI_GET_EXTENSION : - TRACE_ICE(("B_MULTI_GET_EXTENSION\n")); + TRACE("B_MULTI_GET_EXTENSION\n"); return B_ERROR; case B_MULTI_SET_EXTENSION : - TRACE_ICE(("B_MULTI_SET_EXTENSION\n")); + TRACE("B_MULTI_SET_EXTENSION\n"); return B_ERROR; case B_MULTI_LIST_MODES : - TRACE_ICE(("B_MULTI_LIST_MODES\n")); + TRACE("B_MULTI_LIST_MODES\n"); return B_ERROR; case B_MULTI_GET_MODE : - TRACE_ICE(("B_MULTI_GET_MODE\n")); + TRACE("B_MULTI_GET_MODE\n"); return B_ERROR; case B_MULTI_SET_MODE : - TRACE_ICE(("B_MULTI_SET_MODE\n")); + TRACE("B_MULTI_SET_MODE\n"); return B_ERROR; default : - TRACE_ICE(("ERROR: unknown multi_control %#x\n", op)); + TRACE("ERROR: unknown multi_control %#x\n", (int)op); return B_ERROR; } } @@ -569,7 +589,7 @@ static status_t ice_1712_read(void *cookie, off_t position, void *buf, size_t *num_bytes) { - TRACE_ICE(("===read()===\n")); + TRACE("===read()===\n"); *num_bytes = 0; return B_IO_ERROR; } @@ -578,13 +598,13 @@ static status_t ice_1712_write(void *cookie, off_t position, const void *buffer, size_t *num_bytes) { - TRACE_ICE(("===write()===\n")); + TRACE("===write()===\n"); *num_bytes = 0; return B_IO_ERROR; } -device_hooks ice_1712_hooks = +device_hooks ice1712_hooks = { ice_1712_open, ice_1712_close, @@ -598,24 +618,131 @@ NULL }; +/* +device_hooks ice1712Midi_hooks = +{ + ice1712Midi_open, + ice1712Midi_close, + ice1712Midi_free, + ice1712Midi_control, + ice1712Midi_read, + ice1712Midi_write, + NULL, + NULL, + NULL, + NULL +}; +*/ device_hooks * find_device(const char * name) { int ix; - PRINT_ICE(("ice1712: find_device(%s)\n", name)); + TRACE("ice1712: find_device(%s)\n", name); for (ix=0; ix<num_cards; ix++) { -/*#if MIDI - if (!strcmp(cards[ix].midi.name, name)) { + +/* if (!strcmp(cards[ix].midi.name, name)) { return &midi_hooks; + }*/ + + if (!strcmp(cards[ix].name, name)) { + return &ice1712_hooks; } -#endif -*/ if (!strcmp(cards[ix].name, name)) { - return &ice_1712_hooks; - } } - PRINT_ICE(("ice1712: find_device(%s) failed\n", name)); + TRACE("ice1712: find_device(%s) failed\n", name); return NULL; } + +//----------------------------------------------------------------------------- + +status_t +load_settings(ice1712 *ice) +{ + int i; + for (i = 0; i < 10; i++) { + ice->settings.playback[i].volume = -10.5; + ice->settings.playback[i].mute = false; + } + + for (i = 0; i < 10; i++) { + ice->settings.record[i].volume = -10.5; + ice->settings.record[i].mute = false; + } + + ice->settings.clock = 0; + ice->settings.sample_rate = 3; + ice->settings.buffer_size = 3; + ice->settings.debug_mode = 0; + + //S/PDIF Settings + ice->settings.out_format = 0; + ice->settings.emphasis = 0; + ice->settings.copy_mode = 0; + + return apply_settings(ice); +} + + +status_t +save_settings(ice1712 *ice) +{ + return B_OK; +} + + +#define ICE1712_MUTE_VALUE (0x7F) + +status_t +apply_settings(ice1712 *card) +{ + int i; + uint16 val; + + for (i = 0; i < 10; i++) { + //Select the channel + write_mt_uint8(card, MT_VOLUME_CONTROL_CHANNEL_INDEX, i); + + if (card->settings.playback[i].mute) { + val = (ICE1712_MUTE_VALUE << 0) | (ICE1712_MUTE_VALUE << 8); + } else { + unsigned char volume = card->settings.playback[i].volume / -1.5; + if (i & 1) {//a right channel + val = ICE1712_MUTE_VALUE << 0; //Mute left volume + val |= volume << 8; + } else {//a left channel + val = ICE1712_MUTE_VALUE << 8; //Mute right volume + val |= volume << 0; + } + } + + write_mt_uint16(card, MT_LR_VOLUME_CONTROL, val); + if (ICE1712_VERY_VERBOSE) + TRACE("Apply Settings %d : 0x%x\n", i, val); + } + + for (i = 0; i < 10; i++) { + //Select the channel + write_mt_uint8(card, MT_VOLUME_CONTROL_CHANNEL_INDEX, i + 10); + + if (card->settings.record[i].mute == true) { + val = (ICE1712_MUTE_VALUE << 0) | (ICE1712_MUTE_VALUE << 8); + } else { + unsigned char volume = card->settings.record[i].volume / -1.5; + if (i & 1) {//a right channel + val = ICE1712_MUTE_VALUE << 0; //Mute left volume + val |= volume << 8; + } else {//a left channel + val = ICE1712_MUTE_VALUE << 8; //Mute right volume + val |= volume << 0; + } + } + + write_mt_uint16(card, MT_LR_VOLUME_CONTROL, val); + } + + + return B_OK; +} + Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.h 2010-02-01 21:18:11 UTC (rev 35384) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.h 2010-02-01 21:27:42 UTC (rev 35385) @@ -13,15 +13,13 @@ #define _ICE1712_H_ #include <PCI.h> -#include "hmulti_audio.h" #define DRIVER_NAME "ice1712" -#define VERSION "0.3" +#define VERSION "0.4" #define ICE1712_VENDOR_ID 0x1412 #define ICE1712_DEVICE_ID 0x1712 - typedef enum product_t { ICE1712_SUBDEVICE_DELTA1010 = 0x121430d6, ICE1712_SUBDEVICE_DELTADIO2496 = 0x121431d6, @@ -38,7 +36,7 @@ #define MAX_DAC 10 #define SWAPPING_BUFFERS 2 #define SAMPLE_SIZE 4 -#define MIN_BUFFER_FRAMES 64 +#define MIN_BUFFER_FRAMES 256 #define MAX_BUFFER_FRAMES 2048 #define PLAYBACK_BUFFER_SIZE (MAX_BUFFER_FRAMES * MAX_DAC * SAMPLE_SIZE) @@ -52,6 +50,7 @@ #define MIXER_OUT_LEFT 10 #define MIXER_OUT_RIGHT 11 + typedef enum { NO_IN_NO_OUT = 0, NO_IN_YES_OUT = 1, @@ -59,6 +58,7 @@ YES_IN_YES_OUT = 3, } _spdif_config_ ; + typedef struct _midi_dev { struct _ice1712_ *card; void *driver; @@ -67,16 +67,46 @@ char name[64]; } midi_dev; -typedef struct codec_info + +typedef struct _codec_commlines { uint8 clock; uint8 data_in; uint8 data_out; - uint8 reserved[5]; -} codec_info; + uint8 cs_mask; //a Mask for removing all Chip select + uint8 reserved[4]; +} codec_comm_lines; -typedef struct _ice1712_ + +typedef struct channel_volume { + float volume; + bool mute; +} channel_volume; + + +typedef struct ice1712_settings +{ + channel_volume playback[10]; //Can't change the volume of the digital mixer + channel_volume record[10]; + + //General Settings + uint8 clock; //an index + uint8 sample_rate; //an index + uint8 buffer_size; //an index + uint8 debug_mode; //an index for debugging + + //S/PDif Settings + uint8 out_format; //an index + uint8 emphasis; //an index + uint8 copy_mode; //an index + + uint8 reserved[32]; +} ice1712_settings; + + +typedef struct ice1712 +{ uint32 irq; pci_info info; char name[128]; @@ -96,34 +126,38 @@ int8 nb_MPU401; product_t product; - uint8 gpio_cs_mask; //a Mask for removing all Chip select - //We hope all manufacturer will not use different codec on the same card - codec_info analog_codec; - codec_info digital_codec; + //We hope all manufacturers will use same communication lines for speaking with codec + codec_comm_lines commlines; uint32 buffer; bigtime_t played_time; + uint32 buffer_size; //in frames + uint32 frames_count; //Output area_id mem_id_pb; void *phys_addr_pb, *log_addr_pb; - uint32 output_buffer_size; //in frames uint8 total_output_channels; //Input area_id mem_id_rec; void *phys_addr_rec, *log_addr_rec; - uint32 input_buffer_size; //in frames uint8 total_input_channels; sem_id buffer_ready_sem; uint8 sampling_rate; //in the format of the register uint32 lock_source; - + + ice1712_settings settings; } ice1712; + +status_t apply_settings(ice1712 *card); + + +//For midi.c extern int32 num_cards; extern ice1712 cards[NUM_CARDS]; @@ -164,27 +198,15 @@ #define VX442_CODEC_CS_0 0x20 // ?? #0 #define VX442_CODEC_CS_1 0x40 // ?? #1 -#define AK45xx_BITS_TO_WRITE 16 -//2 - Chip Address (10b) -//1 - R/W (Always 1 for Writing) -//5 - Register Address -//8 - Data +#define GPIO_I2C_DELAY 5 //Clock Delay for writing I2C data throw GPIO //Register definition for the AK45xx codec (xx = 24 or 28) -#define AK45xx_DELAY 100 //Clock Delay #define AK45xx_CHIP_ADDRESS 0x02 //Chip address of the codec #define AK45xx_RESET_REGISTER 0x01 #define AK45xx_CLOCK_FORMAT_REGISTER 0x02 //Other register are not defined cause they are not used, I'm very lazy... -#define CS84xx_BITS_TO_WRITE 24 -//7 - Chip Address (0010000b) -//1 - R/W (1 for Reading) -//8 - Register MAP -//8 - Data - //Register definition for the CS84xx codec (xx = 27) -#define CS84xx_DELAY 100 //Clock Delay #define CS84xx_CHIP_ADDRESS 0x10 //Chip address of the codec #define CS84xx_CONTROL_1_PORT_REG 0x01 #define CS84xx_CONTROL_2_PORT_REG 0x02 @@ -192,6 +214,8 @@ #define CS84xx_CLOCK_SOURCE_REG 0x04 #define CS84xx_SERIAL_INPUT_FORMAT_REG 0x05 #define CS84xx_SERIAL_OUTPUT_FORMAT_REG 0x06 + +#define CS84xx_VERSION_AND_CHIP_ID 0x7F //Other register are not defined cause they are not used, I'm very lazy... @@ -217,7 +241,7 @@ } */ -//This map come from ALSA sound drivers +//This map comes from ALSA sound drivers #define E2PROM_MAP_SUBVENDOR_LOW 0x00 #define E2PROM_MAP_SUBVENDOR_HIGH 0x01 #define E2PROM_MAP_SUBDEVICE_LOW 0x02 Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.c 2010-02-01 21:18:11 UTC (rev 35384) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.c 2010-02-01 21:27:42 UTC (rev 35385) @@ -15,13 +15,22 @@ extern pci_module_info *pci; - static void ak45xx_write_gpio(ice1712 *ice, uint8 reg_addr, uint8 data, uint8 chip_select); static void cs84xx_write_gpio(ice1712 *ice, uint8 reg_addr, uint8 data, uint8 chip_select); +static uint8 ak45xx_read_gpio(ice1712 *ice, uint8 reg_addr, + uint8 chip_select) {return 0;} //Unimplemented + +static uint8 cs84xx_read_gpio(ice1712 *ice, uint8 reg_addr, + uint8 chip_select); + +static void write_gpio_byte(ice1712 *ice, uint8 data, uint8 gpio_data); +static uint8 read_gpio_byte(ice1712 *ice, uint8 gpio_data); + + //Address are [PCI_10] + xx uint8 @@ -86,42 +95,42 @@ //Address are [PCI_14] + xx uint8 -read_ddma_uint8(ice1712 *ice, int8 regno) +read_ddma_uint8(ice1712 *ice, int8 regno) { return pci->read_io_8(ice->DDMA + regno); }; uint16 -read_ddma_uint16(ice1712 *ice, int8 regno) +read_ddma_uint16(ice1712 *ice, int8 regno) { return pci->read_io_16(ice->DDMA + regno); }; uint32 -read_ddma_uint32(ice1712 *ice, int8 regno) +read_ddma_uint32(ice1712 *ice, int8 regno) { return pci->read_io_32(ice->DDMA + regno); }; void -write_ddma_uint8(ice1712 *ice, int8 regno, uint8 value) +write_ddma_uint8(ice1712 *ice, int8 regno, uint8 value) { pci->write_io_8(ice->DDMA + regno, value); }; void -write_ddma_uint16(ice1712 *ice, int8 regno, uint16 value) +write_ddma_uint16(ice1712 *ice, int8 regno, uint16 value) { pci->write_io_16(ice->DDMA + regno, value); }; void -write_ddma_uint32(ice1712 *ice, int8 regno, uint32 value) +write_ddma_uint32(ice1712 *ice, int8 regno, uint32 value) { pci->write_io_32(ice->DDMA + regno, value); }; @@ -216,6 +225,7 @@ return pci->read_io_32(ice->Multi_Track + regno); }; + void write_mt_uint8(ice1712 *ice, int8 regno, uint8 value) { @@ -291,26 +301,25 @@ void codec_write(ice1712 *ice, uint8 reg_addr, uint8 data) { - switch (ice->product) - { - case ICE1712_SUBDEVICE_DELTA66 : - case ICE1712_SUBDEVICE_DELTA44 : + switch (ice->product) { + case ICE1712_SUBDEVICE_DELTA66: + case ICE1712_SUBDEVICE_DELTA44: ak45xx_write_gpio(ice, reg_addr, data, DELTA66_CODEC_CS_0); ak45xx_write_gpio(ice, reg_addr, data, DELTA66_CODEC_CS_1); break; - case ICE1712_SUBDEVICE_DELTA410 : - case ICE1712_SUBDEVICE_AUDIOPHILE_2496 : - case ICE1712_SUBDEVICE_DELTADIO2496 : [... truncated: 1421 lines follow ...]