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


Ignore:
Timestamp:
2014-08-14T14:21:28Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
65b09c1
Parents:
8d070710
Message:

Discover function groups and widgets.

File:
1 edited

Legend:

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

    r8d070710 rd2d5329  
    4242#include <stdint.h>
    4343
     44#include "codec.h"
    4445#include "hdactl.h"
    4546#include "regif.h"
     
    4950        ctrl_init_wait_max = 10,
    5051        codec_enum_wait_us = 512,
    51         corb_wait_max = 10
     52        corb_wait_max = 10,
     53        rirb_wait_max = 100
    5254};
    5355
     
    231233
    232234        /* Set RINTCNT - Qemu won't read from CORB if this is zero */
    233         hda_reg16_write(&hda->regs->rintcnt, 2);
     235        hda_reg16_write(&hda->regs->rintcnt, 128);
    234236
    235237        hda->ctl->rirb_rp = 0;
     
    336338}
    337339
    338 static void hda_rirb_read(hda_t *hda)
     340static int hda_rirb_read(hda_t *hda, hda_rirb_entry_t *data, size_t count)
    339341{
    340342        size_t wp;
    341343        hda_rirb_entry_t resp;
    342344        hda_rirb_entry_t *rirb;
     345        int wcnt;
    343346
    344347        rirb = (hda_rirb_entry_t *)hda->ctl->rirb_virt;
    345348
    346         wp = hda_get_rirbwp(hda);
    347         ddf_msg(LVL_NOTE, "hda_rirb_read: wp=%d", wp);
    348         while (hda->ctl->rirb_rp != wp) {
    349                 ++hda->ctl->rirb_rp;
    350                 resp = rirb[hda->ctl->rirb_rp];
    351 
    352                 ddf_msg(LVL_NOTE, "RESPONSE resp=0x%x respex=0x%x",
    353                     resp.resp, resp.respex);
    354         }
    355 }
    356 
    357 #include "spec/codec.h"
     349        while (count > 0) {
     350                wp = hda_get_rirbwp(hda);
     351                ddf_msg(LVL_NOTE, "hda_rirb_read: wp=%d", wp);
     352                while (count > 0 && hda->ctl->rirb_rp != wp) {
     353                        ++hda->ctl->rirb_rp;
     354                        resp = rirb[hda->ctl->rirb_rp];
     355
     356                        ddf_msg(LVL_NOTE, "RESPONSE resp=0x%x respex=0x%x",
     357                            resp.resp, resp.respex);
     358                        if ((resp.respex & BIT_V(uint32_t, respex_unsol)) == 0) {
     359                                /* Solicited response */
     360                                *data++ = resp;
     361                                --count;
     362                        }
     363                }
     364
     365                if (count > 0) {
     366                        wcnt = rirb_wait_max;
     367                        while (wcnt > 0 && hda_get_rirbwp(hda) == hda->ctl->rirb_rp) {
     368                                async_usleep(100);
     369                                --wcnt;
     370                        }
     371
     372                        if (hda_get_rirbwp(hda) == hda->ctl->rirb_rp)
     373                                return ETIMEOUT;
     374                }
     375        }
     376
     377        return EOK;
     378}
     379
    358380hda_ctl_t *hda_ctl_init(hda_t *hda)
    359381{
     
    426448                goto error;
    427449
    428         uint32_t verb;
    429         verb = (0 << 28) | (0 << 20) | ((hda_get_param) << 8) | (hda_sub_nc);
    430         rc = hda_corb_write(hda, &verb, 1);
    431         ddf_msg(LVL_NOTE, "hda_corb_write -> %d", rc);
    432         rc = hda_corb_write(hda, &verb, 1);
    433         ddf_msg(LVL_NOTE, "hda_corb_write -> %d", rc);
    434         rc = hda_corb_write(hda, &verb, 1);
    435         ddf_msg(LVL_NOTE, "hda_corb_write -> %d", rc);
    436         rc = hda_corb_write(hda, &verb, 1);
    437         ddf_msg(LVL_NOTE, "hda_corb_write -> %d", rc);
    438 
    439         async_usleep(100*1000);
    440         hda_rirb_read(hda);
     450        hda->ctl->codec = hda_codec_init(hda, 0);
     451        if (hda->ctl->codec == NULL)
     452                goto error;
    441453
    442454        return ctl;
     
    447459}
    448460
     461int hda_cmd(hda_t *hda, uint32_t verb, uint32_t *resp)
     462{
     463        int rc;
     464        hda_rirb_entry_t rentry;
     465
     466        rc = hda_corb_write(hda, &verb, 1);
     467        if (rc != EOK)
     468                return rc;
     469
     470        if (resp != NULL) {
     471                rc = hda_rirb_read(hda, &rentry, 1);
     472                if (rc != EOK)
     473                        return rc;
     474
     475                /* XXX Verify that response came from the correct codec */
     476                *resp = rentry.resp;
     477        }
     478
     479        return EOK;
     480}
     481
    449482void hda_ctl_fini(hda_ctl_t *ctl)
    450483{
Note: See TracChangeset for help on using the changeset viewer.