Changeset 050d4fa in mainline
- Timestamp:
- 2011-09-26T10:44:34Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bde691c
- Parents:
- c7325dd6
- Location:
- uspace/drv/audio/sb16
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/mixer.c
rc7325dd6 r050d4fa 89 89 }; 90 90 91 const char * mixer_type_to_str(mixer_type_t type) 91 static void mixer_max_master_levels(sb_mixer_t *mixer) 92 { 93 assert(mixer); 94 /* Set Master to maximum */ 95 if (!mixer_get_control_item_count(mixer)) 96 return; 97 unsigned levels = 0, channels = 0, current_level; 98 const char *name = NULL; 99 mixer_get_control_item_info(mixer, 0, &name, &channels, &levels); 100 unsigned channel = 0; 101 for (;channel < channels; ++channel) { 102 current_level = 103 mixer_get_volume_level(mixer, 0, channel); 104 ddf_log_note("Setting %s channel %d to %d (%d).\n", 105 name, channel, levels - 1, current_level); 106 107 mixer_set_volume_level(mixer, 0, channel, levels - 1); 108 109 current_level = 110 mixer_get_volume_level(mixer, 0, channel); 111 ddf_log_note("%s channel %d set to %d.\n", 112 name, channel, current_level); 113 } 114 115 } 116 /*----------------------------------------------------------------------------*/ 117 const char * mixer_type_str(mixer_type_t type) 92 118 { 93 119 static const char * names[] = { … … 100 126 } 101 127 /*----------------------------------------------------------------------------*/ 102 int mixer_init(sb16_regs_t *regs, mixer_type_t type) 103 { 128 int mixer_init(sb_mixer_t *mixer, sb16_regs_t *regs, mixer_type_t type) 129 { 130 assert(mixer); 131 mixer->regs = regs; 132 mixer->type = type; 104 133 if (type == SB_MIXER_UNKNOWN) 105 134 return ENOTSUP; … … 108 137 pio_write_8(®s->mixer_address, CT_MIXER_RESET_ADDRESS); 109 138 pio_write_8(®s->mixer_data, 1); 139 mixer_max_master_levels(mixer); 110 140 } 111 141 return EOK; 112 142 } 113 143 /*----------------------------------------------------------------------------*/ 114 void mixer_load_volume_levels(sb16_regs_t *regs, mixer_type_t type) 115 { 116 /* Set Master to maximum */ 117 if (!mixer_get_control_item_count(type)) 118 return; 119 unsigned levels = 0, channels = 0, current_level; 120 const char *name = NULL; 121 mixer_get_control_item_info(type, 0, &name, &channels, &levels); 122 unsigned channel = 0; 123 for (;channel < channels; ++channel) { 124 current_level = 125 mixer_get_volume_level(regs, type, 0, channel); 126 ddf_log_note("Setting %s channel %d to %d (%d).\n", 127 name, channel, levels - 1, current_level); 128 129 mixer_set_volume_level(regs, type, 0, channel, levels - 1); 130 131 current_level = 132 mixer_get_volume_level(regs, type, 0, channel); 133 ddf_log_note("%s channel %d set to %d.\n", 134 name, channel, current_level); 135 } 136 137 } 138 /*----------------------------------------------------------------------------*/ 139 void mixer_store_volume_levels(sb16_regs_t *regs, mixer_type_t type) 140 { 141 /* No place to store the values. */ 142 } 143 /*----------------------------------------------------------------------------*/ 144 int mixer_get_control_item_count(mixer_type_t type) 145 { 146 return volume_table[type].count; 147 } 148 /*----------------------------------------------------------------------------*/ 149 int mixer_get_control_item_info(mixer_type_t type, unsigned index, 144 int mixer_get_control_item_count(const sb_mixer_t *mixer) 145 { 146 assert(mixer); 147 return volume_table[mixer->type].count; 148 } 149 /*----------------------------------------------------------------------------*/ 150 int mixer_get_control_item_info(const sb_mixer_t *mixer, unsigned index, 150 151 const char** name, unsigned *channels, unsigned *levels) 151 152 { 152 if (index > volume_table[type].count) 153 assert(mixer); 154 if (index > volume_table[mixer->type].count) 153 155 return ENOENT; 154 156 155 157 if (name) 156 *name = volume_table[ type].table[index].description;158 *name = volume_table[mixer->type].table[index].description; 157 159 if (channels) 158 *channels = volume_table[ type].table[index].channels;160 *channels = volume_table[mixer->type].table[index].channels; 159 161 if (levels) 160 *levels = volume_table[ type].table[index].volume_levels;162 *levels = volume_table[mixer->type].table[index].volume_levels; 161 163 return EOK; 162 164 } 163 165 /*----------------------------------------------------------------------------*/ 164 int mixer_set_volume_level( sb16_regs_t *regs, mixer_type_t type,166 int mixer_set_volume_level(const sb_mixer_t *mixer, 165 167 unsigned index, unsigned channel, unsigned level) 166 168 { 167 if ( type == SB_MIXER_UNKNOWN ||type == SB_MIXER_NONE)169 if (mixer->type == SB_MIXER_UNKNOWN || mixer->type == SB_MIXER_NONE) 168 170 return ENOTSUP; 169 if (index >= volume_table[ type].count)171 if (index >= volume_table[mixer->type].count) 170 172 return ENOENT; 171 if (level >= volume_table[ type].table[index].volume_levels)173 if (level >= volume_table[mixer->type].table[index].volume_levels) 172 174 return ENOTSUP; 173 if (channel >= volume_table[ type].table[index].channels)175 if (channel >= volume_table[mixer->type].table[index].channels) 174 176 return ENOENT; 175 177 176 const volume_item_t item = volume_table[ type].table[index];178 const volume_item_t item = volume_table[mixer->type].table[index]; 177 179 const uint8_t address = item.address + (item.same_reg ? 0 : channel); 178 pio_write_8(& regs->mixer_address, address);180 pio_write_8(&mixer->regs->mixer_address, address); 179 181 if (!item.same_reg) { 180 182 const uint8_t value = level << item.shift; 181 pio_write_8(& regs->mixer_data, value);183 pio_write_8(&mixer->regs->mixer_data, value); 182 184 } else { 183 185 /* Nasty stuff */ 184 uint8_t value = pio_read_8(& regs->mixer_data);186 uint8_t value = pio_read_8(&mixer->regs->mixer_data); 185 187 /* Remove value that is to be replaced register format is L:R*/ 186 188 value &= (channel ? 0xf0 : 0x0f); 187 189 /* Add the new value */ 188 190 value |= (level << item.shift) << (channel ? 0 : 4); 189 pio_write_8(& regs->mixer_data, value);191 pio_write_8(&mixer->regs->mixer_data, value); 190 192 } 191 193 return EOK; 192 194 } 193 195 /*----------------------------------------------------------------------------*/ 194 unsigned mixer_get_volume_level(sb16_regs_t *regs, mixer_type_t type, 195 unsigned index, unsigned channel) 196 { 197 if (type == SB_MIXER_UNKNOWN 198 || type == SB_MIXER_NONE 199 || (index >= volume_table[type].count) 200 || (channel >= volume_table[type].table[index].channels)) 196 unsigned mixer_get_volume_level(const sb_mixer_t *mixer, unsigned index, 197 unsigned channel) 198 { 199 assert(mixer); 200 if (mixer->type == SB_MIXER_UNKNOWN 201 || mixer->type == SB_MIXER_NONE 202 || (index >= volume_table[mixer->type].count) 203 || (channel >= volume_table[mixer->type].table[index].channels)) 201 204 return 0; 202 205 203 const volume_item_t item = volume_table[ type].table[index];206 const volume_item_t item = volume_table[mixer->type].table[index]; 204 207 const uint8_t address = item.address + (item.same_reg ? 0 : channel); 205 pio_write_8(& regs->mixer_address, address);208 pio_write_8(&mixer->regs->mixer_address, address); 206 209 if (!item.same_reg) { 207 return pio_read_8(& regs->mixer_data) >> item.shift;210 return pio_read_8(&mixer->regs->mixer_data) >> item.shift; 208 211 } else { 209 212 const uint8_t value = 210 pio_read_8(& regs->mixer_data) >> (channel ? 0 : 4);213 pio_read_8(&mixer->regs->mixer_data) >> (channel ? 0 : 4); 211 214 return value >> item.shift; 212 215 } -
uspace/drv/audio/sb16/mixer.h
rc7325dd6 r050d4fa 45 45 } mixer_type_t; 46 46 47 const char * mixer_type_to_str(mixer_type_t type); 48 int mixer_init(sb16_regs_t *regs, mixer_type_t type); 49 void mixer_load_volume_levels(sb16_regs_t *regs, mixer_type_t type); 50 void mixer_store_volume_levels(sb16_regs_t *regs, mixer_type_t type); 51 int mixer_get_control_item_count(mixer_type_t type); 52 int mixer_get_control_item_info(mixer_type_t type, unsigned index, 47 typedef struct sb_mixer { 48 sb16_regs_t *regs; 49 mixer_type_t type; 50 } sb_mixer_t; 51 52 const char * mixer_type_str(mixer_type_t type); 53 int mixer_init(sb_mixer_t *mixer, sb16_regs_t *regs, mixer_type_t type); 54 int mixer_get_control_item_count(const sb_mixer_t *mixer); 55 int mixer_get_control_item_info(const sb_mixer_t *mixer, unsigned index, 53 56 const char** name, unsigned *channels, unsigned *levels); 54 int mixer_set_volume_level( sb16_regs_t *regs, mixer_type_t type,57 int mixer_set_volume_level(const sb_mixer_t *mixer, 55 58 unsigned item, unsigned channel, unsigned level); 56 unsigned mixer_get_volume_level( sb16_regs_t *regs, mixer_type_t type,59 unsigned mixer_get_volume_level(const sb_mixer_t *mixer, 57 60 unsigned item, unsigned channel); 58 61 #endif -
uspace/drv/audio/sb16/sb16.c
rc7325dd6 r050d4fa 91 91 92 92 /* Initialize mixer */ 93 drv->mixer= mixer_type_by_dsp_version(93 const mixer_type_t mixer_type = mixer_type_by_dsp_version( 94 94 drv->dsp_version.major, drv->dsp_version.minor); 95 95 96 ret = mixer_init( drv->regs, drv->mixer);96 ret = mixer_init(&drv->mixer, drv->regs, mixer_type); 97 97 if (ret != EOK) { 98 98 ddf_log_error("Failed to initialize SB mixer: %s.\n", … … 100 100 return ret; 101 101 } 102 mixer_load_volume_levels(drv->regs, drv->mixer);103 ddf_log_note("Initialized mixer: %s.\n", mixer_type_to_str(drv->mixer));102 ddf_log_note("Initialized mixer: %s.\n", 103 mixer_type_str(drv->mixer.type)); 104 104 105 105 return EOK; -
uspace/drv/audio/sb16/sb16.h
rc7325dd6 r050d4fa 49 49 uint8_t minor; 50 50 } dsp_version; 51 mixer_type_t mixer;51 sb_mixer_t mixer; 52 52 } sb16_drv_t; 53 53
Note:
See TracChangeset
for help on using the changeset viewer.