Changeset 050d4fa in mainline


Ignore:
Timestamp:
2011-09-26T10:44:34Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bde691c
Parents:
c7325dd6
Message:

sb16: Use new sb_mixer_t structure.

Location:
uspace/drv/audio/sb16
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/mixer.c

    rc7325dd6 r050d4fa  
    8989};
    9090
    91 const char * mixer_type_to_str(mixer_type_t type)
     91static 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/*----------------------------------------------------------------------------*/
     117const char * mixer_type_str(mixer_type_t type)
    92118{
    93119        static const char * names[] = {
     
    100126}
    101127/*----------------------------------------------------------------------------*/
    102 int mixer_init(sb16_regs_t *regs, mixer_type_t type)
    103 {
     128int 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;
    104133        if (type == SB_MIXER_UNKNOWN)
    105134                return ENOTSUP;
     
    108137                pio_write_8(&regs->mixer_address, CT_MIXER_RESET_ADDRESS);
    109138                pio_write_8(&regs->mixer_data, 1);
     139                mixer_max_master_levels(mixer);
    110140        }
    111141        return EOK;
    112142}
    113143/*----------------------------------------------------------------------------*/
    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,
     144int mixer_get_control_item_count(const sb_mixer_t *mixer)
     145{
     146        assert(mixer);
     147        return volume_table[mixer->type].count;
     148}
     149/*----------------------------------------------------------------------------*/
     150int mixer_get_control_item_info(const sb_mixer_t *mixer, unsigned index,
    150151    const char** name, unsigned *channels, unsigned *levels)
    151152{
    152         if (index > volume_table[type].count)
     153        assert(mixer);
     154        if (index > volume_table[mixer->type].count)
    153155                return ENOENT;
    154156
    155157        if (name)
    156                 *name = volume_table[type].table[index].description;
     158                *name = volume_table[mixer->type].table[index].description;
    157159        if (channels)
    158                 *channels = volume_table[type].table[index].channels;
     160                *channels = volume_table[mixer->type].table[index].channels;
    159161        if (levels)
    160                 *levels = volume_table[type].table[index].volume_levels;
     162                *levels = volume_table[mixer->type].table[index].volume_levels;
    161163        return EOK;
    162164}
    163165/*----------------------------------------------------------------------------*/
    164 int mixer_set_volume_level(sb16_regs_t *regs, mixer_type_t type,
     166int mixer_set_volume_level(const sb_mixer_t *mixer,
    165167    unsigned index, unsigned channel, unsigned level)
    166168{
    167         if (type == SB_MIXER_UNKNOWN || type == SB_MIXER_NONE)
     169        if (mixer->type == SB_MIXER_UNKNOWN || mixer->type == SB_MIXER_NONE)
    168170                return ENOTSUP;
    169         if (index >= volume_table[type].count)
     171        if (index >= volume_table[mixer->type].count)
    170172                return ENOENT;
    171         if (level >= volume_table[type].table[index].volume_levels)
     173        if (level >= volume_table[mixer->type].table[index].volume_levels)
    172174                return ENOTSUP;
    173         if (channel >= volume_table[type].table[index].channels)
     175        if (channel >= volume_table[mixer->type].table[index].channels)
    174176                return ENOENT;
    175177
    176         const volume_item_t item = volume_table[type].table[index];
     178        const volume_item_t item = volume_table[mixer->type].table[index];
    177179        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);
    179181        if (!item.same_reg) {
    180182                const uint8_t value = level << item.shift;
    181                 pio_write_8(&regs->mixer_data, value);
     183                pio_write_8(&mixer->regs->mixer_data, value);
    182184        } else {
    183185                /* Nasty stuff */
    184                 uint8_t value = pio_read_8(&regs->mixer_data);
     186                uint8_t value = pio_read_8(&mixer->regs->mixer_data);
    185187                /* Remove value that is to be replaced register format is L:R*/
    186188                value &= (channel ? 0xf0 : 0x0f);
    187189                /* Add the new value */
    188190                value |= (level << item.shift) << (channel ? 0 : 4);
    189                 pio_write_8(&regs->mixer_data, value);
     191                pio_write_8(&mixer->regs->mixer_data, value);
    190192        }
    191193        return EOK;
    192194}
    193195/*----------------------------------------------------------------------------*/
    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))
     196unsigned 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))
    201204                return 0;
    202205
    203         const volume_item_t item = volume_table[type].table[index];
     206        const volume_item_t item = volume_table[mixer->type].table[index];
    204207        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);
    206209        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;
    208211        } else {
    209212                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);
    211214                return value >> item.shift;
    212215        }
  • uspace/drv/audio/sb16/mixer.h

    rc7325dd6 r050d4fa  
    4545} mixer_type_t;
    4646
    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,
     47typedef struct sb_mixer {
     48        sb16_regs_t *regs;
     49        mixer_type_t type;
     50} sb_mixer_t;
     51
     52const char * mixer_type_str(mixer_type_t type);
     53int mixer_init(sb_mixer_t *mixer, sb16_regs_t *regs, mixer_type_t type);
     54int mixer_get_control_item_count(const sb_mixer_t *mixer);
     55int mixer_get_control_item_info(const sb_mixer_t *mixer, unsigned index,
    5356    const char** name, unsigned *channels, unsigned *levels);
    54 int mixer_set_volume_level(sb16_regs_t *regs, mixer_type_t type,
     57int mixer_set_volume_level(const sb_mixer_t *mixer,
    5558    unsigned item, unsigned channel, unsigned level);
    56 unsigned mixer_get_volume_level(sb16_regs_t *regs, mixer_type_t type,
     59unsigned mixer_get_volume_level(const sb_mixer_t *mixer,
    5760    unsigned item, unsigned channel);
    5861#endif
  • uspace/drv/audio/sb16/sb16.c

    rc7325dd6 r050d4fa  
    9191
    9292        /* Initialize mixer */
    93         drv->mixer = mixer_type_by_dsp_version(
     93        const mixer_type_t mixer_type = mixer_type_by_dsp_version(
    9494            drv->dsp_version.major, drv->dsp_version.minor);
    9595
    96         ret = mixer_init(drv->regs, drv->mixer);
     96        ret = mixer_init(&drv->mixer, drv->regs, mixer_type);
    9797        if (ret != EOK) {
    9898                ddf_log_error("Failed to initialize SB mixer: %s.\n",
     
    100100                return ret;
    101101        }
    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));
    104104
    105105        return EOK;
  • uspace/drv/audio/sb16/sb16.h

    rc7325dd6 r050d4fa  
    4949                uint8_t minor;
    5050        } dsp_version;
    51         mixer_type_t mixer;
     51        sb_mixer_t mixer;
    5252} sb16_drv_t;
    5353
Note: See TracChangeset for help on using the changeset viewer.