Changeset c67195c in mainline for uspace/drv/audio/hdaudio/hdactl.c


Ignore:
Timestamp:
2014-08-26T13:03:28Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1e92bc3
Parents:
6747b929
Message:

Fix resetting of CORBRP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/hdaudio/hdactl.c

    r6747b929 rc67195c  
    5555};
    5656
     57/** Perform set-reset handshake on a 16-bit register.
     58 *
     59 * The bit(s) specified in the mask are written as 1, then we wait
     60 * for them to read as 1. Then we write them as 0 and we wait for them
     61 * to read as 0.
     62 */
     63static int hda_ctl_reg16_set_reset(uint16_t *reg, uint16_t mask)
     64{
     65        uint16_t val;
     66        int wcnt;
     67
     68        val = hda_reg16_read(reg);
     69        hda_reg16_write(reg, val | mask);
     70
     71        wcnt = 1000;
     72        while (wcnt > 0) {
     73                val = hda_reg16_read(reg);
     74                if ((val & mask) == mask)
     75                        break;
     76
     77                async_usleep(1000);
     78                --wcnt;
     79        }
     80
     81        if ((val & mask) != mask)
     82                return ETIMEOUT;
     83
     84        val = hda_reg16_read(reg);
     85        hda_reg16_write(reg, val & ~mask);
     86
     87        wcnt = 1000;
     88        while (wcnt > 0) {
     89                val = hda_reg16_read(reg);
     90                if ((val & mask) == 0)
     91                        break;
     92
     93                async_usleep(1000);
     94                --wcnt;
     95        }
     96
     97        if ((val & mask) != 0)
     98                return ETIMEOUT;
     99
     100        return EOK;
     101}
     102
    57103/** Select an appropriate CORB/RIRB size.
    58104 *
     
    150196
    151197        /* Reset CORB Read Pointer */
    152         hda_reg16_write(&hda->regs->corbrp, BIT_V(uint16_t, corbrp_rst));
    153 
    154         /* Reset CORB Write Poitner */
     198        rc = hda_ctl_reg16_set_reset(&hda->regs->corbrp,
     199            BIT_V(uint16_t, corbrp_rst));
     200        if (rc != EOK) {
     201                ddf_msg(LVL_NOTE, "Failed resetting CORBRP");
     202                goto error;
     203        }
     204
     205        /* Reset CORB Write Pointer */
    155206        hda_reg16_write(&hda->regs->corbwp, 0);
    156207
     
    356407        int wcnt;
    357408
    358         wcnt = 10*1000;
    359 
     409        ddf_msg(LVL_NOTE, "hda_solrb_read()");
     410        wcnt = 100;
     411
     412        ddf_msg(LVL_NOTE, "hda_solrb_read() - lock mutex");
    360413        fibril_mutex_lock(&hda->ctl->solrb_lock);
    361414
    362415        while (count > 0) {
     416                ddf_msg(LVL_NOTE, "hda_solrb_read() - while(1)");
    363417                while (count > 0 && hda->ctl->solrb_rp != hda->ctl->solrb_wp) {
     418                        ddf_msg(LVL_NOTE, "hda_solrb_read() - while(2)");
    364419                        ++hda->ctl->solrb_rp;
    365420                        resp = hda->ctl->solrb[hda->ctl->solrb_rp];
    366421
    367                         ddf_msg(LVL_DEBUG2, "solrb RESPONSE resp=0x%x respex=0x%x",
     422                        ddf_msg(LVL_NOTE, "solrb RESPONSE resp=0x%x respex=0x%x",
    368423                            resp.resp, resp.respex);
    369424                        if ((resp.respex & BIT_V(uint32_t, respex_unsol)) == 0) {
     
    375430
    376431                if (count > 0) {
     432                        ddf_msg(LVL_NOTE, "hda_solrb_read() - count > 0");
    377433                        while (wcnt > 0 && hda->ctl->solrb_wp == hda->ctl->solrb_rp) {
     434                                ddf_msg(LVL_NOTE, "hda_solrb_read() - while(3), wcnt=%d", wcnt);
    378435                                fibril_mutex_unlock(&hda->ctl->solrb_lock);
    379                                 async_usleep(100);
     436                                ddf_msg(LVL_NOTE, "hda_solrb_read() - sleep");
     437                                async_usleep(10000);
     438                                ddf_msg(LVL_NOTE, "hda_solrb_read() - re-lock");
    380439                                fibril_mutex_lock(&hda->ctl->solrb_lock);
    381440                                --wcnt;
     
    384443                        if (hda->ctl->solrb_wp == hda->ctl->solrb_rp) {
    385444                                ddf_msg(LVL_NOTE, "hda_solrb_read() time out");
     445                                ddf_msg(LVL_NOTE, "corbwp=%d corbrp=%d",
     446                                    hda_reg16_read(&hda->regs->corbwp),
     447                                    hda_reg16_read(&hda->regs->corbrp));
     448                                ddf_msg(LVL_NOTE, "corbctl=0x%x, corbsts=0x%x",
     449                                    hda_reg8_read(&hda->regs->corbctl),
     450                                    hda_reg8_read(&hda->regs->corbsts));
     451                                ddf_msg(LVL_NOTE, "rirbwp=%d",
     452                                    hda_reg16_read(&hda->regs->rirbwp));
     453                                ddf_msg(LVL_NOTE, "rirbctl=0x%x, rirbsts=0x%x",
     454                                    hda_reg8_read(&hda->regs->rirbctl),
     455                                    hda_reg8_read(&hda->regs->rirbsts));
    386456                                fibril_mutex_unlock(&hda->ctl->solrb_lock);
    387457                                return ETIMEOUT;
     
    391461
    392462        fibril_mutex_unlock(&hda->ctl->solrb_lock);
     463        ddf_msg(LVL_NOTE, "hda_solrb_read() success");
    393464        return EOK;
    394465}
Note: See TracChangeset for help on using the changeset viewer.