Ignore:
Timestamp:
Apr 21, 2025, 7:17:25 PM (7 months ago)
Author:
David Azarewicz
Message:

Merge from uniaud32-exp branch

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/hda/hdac_controller.c

    r772 r777  
    6363
    6464        /* enable corb dma */
     65        if (!bus->use_pio_for_commands)
    6566        snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN);
    6667
     
    136137}
    137138
    138 /**
    139  * snd_hdac_bus_send_cmd - send a command verb via CORB
     139/* receive an Immediate Response with PIO */
     140static int snd_hdac_bus_wait_for_pio_response(struct hdac_bus *bus,
     141                                              unsigned int addr)
     142{
     143        int timeout = 50;
     144
     145        while (timeout--) {
     146                /* check IRV bit */
     147                if (snd_hdac_chip_readw(bus, IRS) & AZX_IRS_VALID) {
     148                        /* reuse rirb.res as the response return value */
     149                        bus->rirb.res[addr] = snd_hdac_chip_readl(bus, IR);
     150                        return 0;
     151                }
     152                udelay(1);
     153        }
     154
     155        dev_dbg_ratelimited(bus->dev, "get_response_pio timeout: IRS=%#x\n",
     156                            snd_hdac_chip_readw(bus, IRS));
     157
     158        bus->rirb.res[addr] = -1;
     159
     160        return -EIO;
     161}
     162
     163/**
     164 * snd_hdac_bus_send_cmd_pio - send a command verb via Immediate Command
    140165 * @bus: HD-audio core bus
    141166 * @val: encoded verb value to send
     
    143168 * Returns zero for success or a negative error code.
    144169 */
    145 int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val)
     170static int snd_hdac_bus_send_cmd_pio(struct hdac_bus *bus, unsigned int val)
     171{
     172        unsigned int addr = azx_command_addr(val);
     173        int timeout = 50;
     174        int ret = -EIO;
     175
     176        spin_lock_irq(&bus->reg_lock);
     177
     178        while (timeout--) {
     179                /* check ICB bit */
     180                if (!((snd_hdac_chip_readw(bus, IRS) & AZX_IRS_BUSY))) {
     181                        /* Clear IRV bit */
     182                        snd_hdac_chip_updatew(bus, IRS, AZX_IRS_VALID, AZX_IRS_VALID);
     183                        snd_hdac_chip_writel(bus, IC, val);
     184                        /* Set ICB bit */
     185                        snd_hdac_chip_updatew(bus, IRS, AZX_IRS_BUSY, AZX_IRS_BUSY);
     186
     187                        ret = snd_hdac_bus_wait_for_pio_response(bus, addr);
     188                        goto out;
     189                }
     190                udelay(1);
     191        }
     192
     193        dev_dbg_ratelimited(bus->dev, "send_cmd_pio timeout: IRS=%#x, val=%#x\n",
     194                            snd_hdac_chip_readw(bus, IRS), val);
     195
     196out:
     197        spin_unlock_irq(&bus->reg_lock);
     198
     199        return ret;
     200}
     201
     202/**
     203 * snd_hdac_bus_get_response_pio - receive a response via Immediate Response
     204 * @bus: HD-audio core bus
     205 * @addr: codec address
     206 * @res: pointer to store the value, NULL when not needed
     207 *
     208 * Returns zero if a value is read, or a negative error code.
     209 */
     210static int snd_hdac_bus_get_response_pio(struct hdac_bus *bus,
     211                                         unsigned int addr, unsigned int *res)
     212{
     213        if (res)
     214                *res = bus->rirb.res[addr];
     215
     216        return 0;
     217}
     218
     219/**
     220 * snd_hdac_bus_send_cmd_corb - send a command verb via CORB
     221 * @bus: HD-audio core bus
     222 * @val: encoded verb value to send
     223 *
     224 * Returns zero for success or a negative error code.
     225 */
     226static int snd_hdac_bus_send_cmd_corb(struct hdac_bus *bus, unsigned int val)
    146227{
    147228        unsigned int addr = azx_command_addr(val);
     
    177258        return 0;
    178259}
    179 EXPORT_SYMBOL_GPL(snd_hdac_bus_send_cmd);
    180260
    181261#define AZX_RIRB_EX_UNSOL_EV    (1<<4)
     
    235315
    236316/**
    237  * snd_hdac_bus_get_response - receive a response via RIRB
     317 * snd_hdac_bus_get_response_rirb - receive a response via RIRB
    238318 * @bus: HD-audio core bus
    239319 * @addr: codec address
     
    242322 * Returns zero if a value is read, or a negative error code.
    243323 */
    244 int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
    245                               unsigned int *res)
     324static int snd_hdac_bus_get_response_rirb(struct hdac_bus *bus,
     325                                          unsigned int addr, unsigned int *res)
    246326{
    247327        unsigned long timeout;
     
    300380        return -EIO;
    301381}
     382
     383/**
     384 * snd_hdac_bus_send_cmd - send a command verb via CORB or PIO
     385 * @bus: HD-audio core bus
     386 * @val: encoded verb value to send
     387 *
     388 * Returns zero for success or a negative error code.
     389 */
     390int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val)
     391{
     392        if (bus->use_pio_for_commands)
     393                return snd_hdac_bus_send_cmd_pio(bus, val);
     394
     395        return snd_hdac_bus_send_cmd_corb(bus, val);
     396}
     397EXPORT_SYMBOL_GPL(snd_hdac_bus_send_cmd);
     398
     399/**
     400 * snd_hdac_bus_get_response - receive a response via RIRB or PIO
     401 * @bus: HD-audio core bus
     402 * @addr: codec address
     403 * @res: pointer to store the value, NULL when not needed
     404 *
     405 * Returns zero if a value is read, or a negative error code.
     406 */
     407int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
     408                              unsigned int *res)
     409{
     410        if (bus->use_pio_for_commands)
     411                return snd_hdac_bus_get_response_pio(bus, addr, res);
     412
     413        return snd_hdac_bus_get_response_rirb(bus, addr, res);
     414}
    302415EXPORT_SYMBOL_GPL(snd_hdac_bus_get_response);
    303416
Note: See TracChangeset for help on using the changeset viewer.