Ticket #5066: ali5451_091203.patch

File ali5451_091203.patch, 10.5 KB (added by bmkx, 10 years ago)

Switching to use ac97 common code module.

  • src/add-ons/kernel/drivers/audio/ac97/ali5451/ali_multi.c

     
    1212#include <hmulti_audio.h>
    1313#include <string.h>
    1414
     15#include "ac97.h"
    1516#include "queue.h"
    1617#include "driver.h"
    1718#include "util.h"
     
    6364#define ALI_ALL_MIXERS (ALI_OUTPUT_MIXERS + ALI_INPUT_MIXERS)
    6465
    6566static const ali_ac97_mixer_info ali_ac97_mixers[ALI_ALL_MIXERS] = {
    66     {S_MASTER, NULL, AC97_MIX_MASTER, -46.5f, 0.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
    67     {S_WAVE, NULL, AC97_MIX_PCM, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
    68     {S_HEADPHONE, NULL, AC97_MIX_HEADPHONE, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
    69     {S_CD, NULL, AC97_MIX_CD, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
    70     {S_LINE, NULL, AC97_MIX_LINEIN, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
    71     {S_MIC, NULL, AC97_MIX_MIC, -34.5f, 12.0f, ALI_MIX_FT_MUTE | ALI_MIX_FT_MICBST},
    72     {S_AUX, NULL, AC97_MIX_AUX, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
    73     {S_null, "Record", AC97_MIX_RECORDGAIN, 0.0f, 22.5f,
     67    {S_MASTER, NULL, AC97_MASTER_VOLUME, -46.5f, 0.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
     68    {S_WAVE, NULL, AC97_PCM_OUT_VOLUME, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
     69    {S_HEADPHONE, NULL, AC97_AUX_OUT_VOLUME, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
     70    {S_CD, NULL, AC97_CD_VOLUME, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
     71    {S_LINE, NULL, AC97_LINE_IN_VOLUME, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
     72    {S_MIC, NULL, AC97_MIC_VOLUME, -34.5f, 12.0f, ALI_MIX_FT_MUTE | ALI_MIX_FT_MICBST},
     73    {S_AUX, NULL, AC97_AUX_IN_VOLUME, -34.5f, 12.0f, ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE},
     74    {S_null, "Record", AC97_RECORD_GAIN, 0.0f, 22.5f,
    7475        ALI_MIX_FT_STEREO | ALI_MIX_FT_MUTE | ALI_MIX_FT_GAIN | ALI_MIX_FT_INSEL},
    7576};
    7677
     
    210211
    211212    switch (gadget_id) {
    212213        case ALI_MIX_MUTE_ID:
    213             mmv->u.enable = ((ac97_read(card, mixer_info->reg) & 0x8000)
    214                     == 0x8000);
     214            mmv->u.enable = ((ac97_reg_cached_read(card->codec, mixer_info->reg)
     215                    & 0x8000) == 0x8000);
    215216            break;
    216217
    217218        case ALI_MIX_LEFT_ID:
    218219        case ALI_MIX_RIGHT_ID:
    219220            {
    220221                float val = (ALI_MIXER_GRANULARITY
    221                         * ((ac97_read(card, mixer_info->reg) >>
    222                             ((gadget_id==ALI_MIX_LEFT_ID)?8:0)) & 0x1f));
     222                        * ((ac97_reg_cached_read(card->codec, mixer_info->reg)
     223                            >> ((gadget_id==ALI_MIX_LEFT_ID)?8:0)) & 0x1f));
    223224                mmv->u.gain = ((mixer_info->features&ALI_MIX_FT_GAIN)
    224225                    ? mixer_info->min_gain+val:mixer_info->max_gain-val);
    225226            }
    226227            break;
    227228
    228229        case ALI_MIX_MIC_BOOST_ID:
    229             mmv->u.enable = ((ac97_read(card, mixer_info->reg) & 0x40) == 0x40);
     230            mmv->u.enable = ((ac97_reg_cached_read(card->codec, mixer_info->reg)
     231                    & 0x40) == 0x40);
    230232            break;
    231233
    232234        case ALI_MIX_INPUT_SELECTOR_ID:
    233             mmv->u.mux = (ac97_read(card, AC97_MIX_RECORDSELECT) & 0x7);
     235            mmv->u.mux = (ac97_reg_cached_read(card->codec,
     236                    AC97_RECORD_SELECT) & 0x7);
    234237            if (ALI_MUX_INPUTS <= mmv->u.mux) {
    235238                mmv->u.mux = 0x2;
    236                 ac97_write(card, AC97_MIX_RECORDSELECT, 0x202);
     239                ac97_reg_cached_write(card->codec, AC97_RECORD_SELECT, 0x202);
    237240            }
    238241            break;
    239242    }
     
    266269
    267270    switch (gadget_id) {
    268271        case ALI_MIX_MUTE_ID:
    269             val = ac97_read(card, mixer_info->reg);
     272            val = ac97_reg_cached_read(card->codec, mixer_info->reg);
    270273            val = mmv->u.enable ? val | 0x8000 : val & 0x7fff;
    271             ac97_write(card, mixer_info->reg, val);
     274            ac97_reg_cached_write(card->codec, mixer_info->reg, val);
    272275            break;
    273276
    274277        case ALI_MIX_LEFT_ID:
    275278        case ALI_MIX_RIGHT_ID:
    276             val = ac97_read(card, mixer_info->reg);
     279            val = ac97_reg_cached_read(card->codec, mixer_info->reg);
    277280            val &= (gadget_id == ALI_MIX_LEFT_ID) ? 0x805f : 0x9f00;
    278281            val |= (uint16) (((mixer_info->features&ALI_MIX_FT_GAIN)
    279282                    ? mixer_info->min_gain+mmv->u.gain
    280283                    : mixer_info->max_gain-mmv->u.gain)
    281284                        / ALI_MIXER_GRANULARITY) <<
    282285                            ((gadget_id == ALI_MIX_LEFT_ID) ? 8 : 0);
    283             ac97_write(card, mixer_info->reg, val);
     286            ac97_reg_cached_write(card->codec, mixer_info->reg, val);
    284287            break;
    285288
    286289        case ALI_MIX_MIC_BOOST_ID:
    287             val = ac97_read(card, mixer_info->reg);
     290            val = ac97_reg_cached_read(card->codec, mixer_info->reg);
    288291            val = mmv->u.enable ? val | 0x40 : val & 0xffbf;
    289             ac97_write(card, mixer_info->reg, val);
     292            ac97_reg_cached_write(card->codec, mixer_info->reg, val);
    290293            break;
    291294
    292295        case ALI_MIX_INPUT_SELECTOR_ID:
    293296            val = (mmv->u.mux << 8) | mmv->u.mux;
    294             ac97_write(card, AC97_MIX_RECORDSELECT, val);
     297            ac97_reg_cached_write(card->codec, AC97_RECORD_SELECT, val);
    295298            break;
    296299    }
    297300}
  • src/add-ons/kernel/drivers/audio/ac97/ali5451/driver.h

     
    7373    ulong io_base;
    7474    uint8 irq;
    7575
     76    ac97_dev *codec;
     77
    7678    spinlock lock_hw;
    7779    spinlock lock_sts;
    7880    spinlock lock_voices;
  • src/add-ons/kernel/drivers/audio/ac97/ali5451/ali_hardware.c

     
    1111#include <drivers/PCI.h>
    1212#include <hmulti_audio.h>
    1313
     14#include "ac97.h"
    1415#include "queue.h"
    1516#include "driver.h"
    1617#include "util.h"
     
    1920
    2021
    2122#define ALI_5451_V02 0x02
    22 #define ALI_AC97_CODEC_ID 0x41445374
    23 #define ALI_AC97_CAPS_HEAD 0x10
    2423
    2524// ALI registers
    2625
     
    137136}
    138137
    139138
    140 uint16
    141 ac97_read(ali_dev *card, uint8 reg)
     139static uint16
     140ac97_read(void *cookie, uint8 reg)
    142141{
     142    ali_dev *card = (ali_dev *) cookie;
    143143    uint32 ac_reg;
    144144
    145145    ac_reg = (card->info.revision == ALI_5451_V02)?ALI_ACR0:ALI_ACR1;
     
    156156}
    157157
    158158
    159 void
    160 ac97_write(ali_dev *card, uint8 reg, uint16 val)
     159static void
     160ac97_write(void *cookie, uint8 reg, uint16 val)
    161161{
     162    ali_dev *card = (ali_dev *) cookie;
    162163    uint32 dw_val;
    163164
    164165    if (!ac97_is_ready(card, ALI_ACR0) || !ac97_is_stimer_ready(card))
     
    173174
    174175
    175176static bool
    176 ac97_init(ali_dev *card)
    177 {
    178     uint16 capabilities;
    179     uint32 id;
    180 
    181     // ac97 reset
    182     ac97_write(card, AC97_REG_POWER, 0);
    183     ac97_write(card, AC97_REG_RESET, 0);
    184     snooze(100000);
    185     ac97_write(card, AC97_REG_POWER, 0);
    186     ac97_write(card, AC97_REG_GEN, 0);
    187 
    188     capabilities = ac97_read(card, AC97_REG_RESET);
    189     TRACE("ac97 capabilities: %04x\n", capabilities & 0x3ff);
    190 
    191     id = (uint32) ac97_read(card, AC97_REG_ID1) << 16
    192         | ac97_read(card, AC97_REG_ID2);
    193     TRACE("ac97 id: %08x\n", (uint) id);
    194     if (id != ALI_AC97_CODEC_ID)
    195         return false;
    196 
    197     if ((capabilities & ALI_AC97_CAPS_HEAD) != 0)
    198         ac97_write(card, AC97_JACK_SENSE, (uint16) 1 << 10);
    199             // enable headphone jack sense
    200 
    201     // some sane default values
    202     ac97_write(card, AC97_MIX_MASTER, 0x707);
    203     ac97_write(card, AC97_MIX_PCM, 0x707);
    204     ac97_write(card, AC97_MIX_HEADPHONE, 0x707);
    205 
    206     return true;
    207 }
    208 
    209 
    210 static bool
    211177hardware_reset(ali_dev *card)
    212178{
    213179    uint32 cmd_reg;
    214     uint16 val;
    215180    uint8 bval;
    216181
    217182    // pci reset
     
    235200    io_write8(card, ALI_ACR2, bval);
    236201    snooze(15000);
    237202
    238     cmd_reg = 200;
    239     while (cmd_reg--) {
    240         val = ac97_read(card, AC97_REG_POWER);
    241         if ((val & 0xf) == 0xf)
    242             break;
    243         snooze(5000);
    244     }
    245     if (cmd_reg == 0xffffffff) {
    246         TRACE("hardware reset: not ready\n");
    247         return false;
    248     }
    249 
    250203    return true;
    251204}
    252205
     
    271224
    272225    UNLOCK(card->lock_hw);
    273226
    274     if (!ac97_init(card))
    275         return B_ERROR;
     227    ac97_attach(&card->codec, ac97_read, ac97_write, card,
     228        card->info.u.h0.subsystem_vendor_id, card->info.u.h0.subsystem_id);
    276229
    277230    TRACE("hardware init ok\n");
    278231    return B_OK;
     
    290243        // clr voice interrupt flags
    291244
    292245    UNLOCK(card->lock_hw);
     246
     247    ac97_detach(card->codec);
    293248}
    294249
    295250
  • src/add-ons/kernel/drivers/audio/ac97/ali5451/Jamfile

     
    44
    55UsePrivateHeaders media ;
    66
     7SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) ] ;
     8SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) ] ;
     9
    710KernelAddon ali5451 :
    811    driver.c
    912    ali_multi.c
    1013    ali_hardware.c
    1114    util.c
     15    ac97.c
    1216;
  • src/add-ons/kernel/drivers/audio/ac97/ali5451/ali_hardware.h

     
    88#define _ALI_HARDWARE_H
    99
    1010
    11 // AC97 codec registers
    12 
    13 #define AC97_REG_RESET 0x00
    14 #define AC97_MIX_MASTER 0x02
    15 #define AC97_MIX_HEADPHONE 0x04
    16 #define AC97_MIX_MONO 0x06
    17 #define AC97_MIX_PHONE 0x0c
    18 #define AC97_MIX_MIC 0x0e
    19 #define AC97_MIX_LINEIN 0x10
    20 #define AC97_MIX_CD 0x12
    21 #define AC97_MIX_AUX 0x16
    22 #define AC97_MIX_PCM 0x18
    23 #define AC97_MIX_RECORDSELECT 0x1a
    24 #define AC97_MIX_RECORDGAIN 0x1c
    25 #define AC97_REG_GEN 0x20
    26 #define AC97_REG_POWER 0x26
    27 #define AC97_FRONT_DAC_SR 0x2c
    28 #define AC97_ADC_RATE 0x32
    29 #define AC97_JACK_SENSE 0x72
    30 #define AC97_REG_ID1 0x7c
    31 #define AC97_REG_ID2 0x7e
    32 
    33 
    34 uint16 ac97_read(ali_dev *card, uint8 reg);
    35 void ac97_write(ali_dev *card, uint8 reg, uint16 val);
    36 
    3711status_t hardware_init(ali_dev *card);
    3812void hardware_terminate(ali_dev *card);
    3913
  • src/add-ons/kernel/drivers/audio/ac97/ali5451/driver.c

     
    1313#include <string.h>
    1414#include <unistd.h>
    1515
     16#include "ac97.h"
    1617#include "queue.h"
    1718#include "ali_multi.h"
    1819#include "driver.h"
     
    293294    card->irq = card->info.u.h0.interrupt_line;
    294295    TRACE("setup: irq is: %02x\n", card->irq);
    295296
     297    card->codec = NULL;
    296298    card->lock_hw = 0;
    297299    card->lock_sts = 0;
    298300    card->lock_voices = 0;
  • src/add-ons/kernel/drivers/audio/ac97/ali5451/util.c

     
    1515#include <hmulti_audio.h>
    1616#include <string.h>
    1717
     18#include "ac97.h"
    1819#include "queue.h"
    1920#include "driver.h"
    2021#include "util.h"