trace_azx_pcm_hw_params(chip, azx_dev);
dsp_lock(azx_dev); if (dsp_is_locked(azx_dev)) {
ret = -EBUSY; goto unlock;
}
/* Set up BDLEs here, return -ENOMEM if too many BDLEs are required */
hdas->bufsize = params_buffer_bytes(hw_params);
hdas->period_bytes = params_period_bytes(hw_params);
hdas->format_val = 0;
hdas->no_period_wakeup =
(hw_params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) &&
(hw_params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); if (snd_hdac_stream_setup_periods(hdas) < 0)
ret = -ENOMEM;
if (dsp_is_locked(azx_dev) || !hstr->prepared) return -EPIPE;
switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME:
start = true; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_STOP:
start = false; break; default: return -EINVAL;
}
if (chip->get_position[stream])
pos = chip->get_position[stream](chip, azx_dev); else/* use the position buffer as default */
pos = azx_get_pos_posbuf(chip, azx_dev);
/* * azx_scale64: Scale base by mult/div while not overflowing sanely * * Derived from scale64_check_overflow in kernel/time/timekeeping.c * * The tmestamps for a 48Khz stream can overflow after (2^64/10^9)/48K which * is about 384307 ie ~4.5 days. * * This scales the calculation so that overflow will happen but after 2^64 / * 48000 secs, which is pretty large! * * In caln below: * base may overflow, but since there isn’t any additional division * performed on base it’s OK * rem can’t overflow because both are 32-bit values
*/
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
direction = 1; else
direction = 0;
/* 0th stream tag is not used, so DMA ch 0 is for 1st stream tag */ do {
timeout = 100;
dma_select = (direction << GTSCC_CDMAS_DMA_DIR_SHIFT) |
(azx_dev->core.stream_tag - 1);
snd_hdac_chip_writel(azx_bus(chip), GTSCC, dma_select);
/* Enable the capture */
snd_hdac_chip_updatel(azx_bus(chip), GTSCC, 0, GTSCC_TSCCI_MASK);
while (timeout) { if (snd_hdac_chip_readl(azx_bus(chip), GTSCC) &
GTSCC_TSCCD_MASK) break;
timeout--;
}
if (!timeout) {
dev_err(chip->card->dev, "GTSCC capture Timedout!\n"); return -EIO;
}
/* * An error occurs near frame "rollover". The clocks in * frame value indicates whether this error may have * occurred. Here we use the value of 10 i.e., * HDA_MAX_CYCLE_OFFSET
*/ if (wallclk_cycles < HDA_MAX_CYCLE_VALUE - HDA_MAX_CYCLE_OFFSET
&& wallclk_cycles > HDA_MAX_CYCLE_OFFSET) break;
/* * Sleep before we read again, else we may again get * value near to MAX_CYCLE. Try to sleep for different * amount of time so we dont hit the same number again
*/
udelay(retry_count++);
} while (retry_count != HDA_MAX_CYCLE_READ_RETRY);
if (retry_count == HDA_MAX_CYCLE_READ_RETRY) {
dev_err_ratelimited(chip->card->dev, "Error in WALFCC cycle count\n"); return -EIO;
}
/* avoid wrap-around with wall-clock */
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME,
20,
178000000);
if (chip->align_buffer_size) /* constrain buffer sizes to be multiple of 128 bytes. This is more efficient in terms of memory access but isn't required by the HDA spec and prevents users from specifying exact period/buffer sizes. For example for 44.1kHz, a period size set
to 20ms will be rounded to 19.59ms. */
buff_step = 128; else /* Don't enforce steps on buffer sizes, still need to be multiple of 4 bytes (HDA spec). Tested on Intel HDA controllers, may not work on all devices where
option needs to be disabled */
buff_step = 4;
/* disable LINK_ATIME timestamps for capture streams
until we figure out how to handle digital inputs */ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */
runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME;
}
again:
err = snd_hdac_bus_get_response(bus, addr, res); if (!err) return 0;
if (hbus->no_response_fallback) return -EIO;
if (!bus->polling_mode) {
dev_warn(chip->card->dev, "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n",
bus->last_cmd[addr]);
bus->polling_mode = 1; goto again;
}
if (chip->msi) {
dev_warn(chip->card->dev, "No response from codec, disabling MSI: last cmd=0x%08x\n",
bus->last_cmd[addr]); if (chip->ops->disable_msi_reset_irq &&
chip->ops->disable_msi_reset_irq(chip) < 0) return -EIO; goto again;
}
if (chip->probing) { /* If this critical timeout happens during the codec probing * phase, this is likely an access to a non-existing codec * slot. Better to return an error and reset the system.
*/ return -EIO;
}
/* no fallback mechanism? */ if (!chip->fallback_to_single_cmd) return -EIO;
/* a fatal communication error; need either to reset or to fallback * to the single_cmd mode
*/ if (hbus->allow_bus_reset && !hbus->response_reset && !hbus->in_reset) {
hbus->response_reset = 1;
dev_err(chip->card->dev, "No response from codec, resetting bus: last cmd=0x%08x\n",
bus->last_cmd[addr]); return -EAGAIN; /* give a chance to retry */
}
dev_err(chip->card->dev, "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n",
bus->last_cmd[addr]);
chip->single_cmd = 1;
hbus->response_reset = 0;
snd_hdac_bus_stop_cmd_io(bus); return -EIO;
}
/* * Use the single immediate command instead of CORB/RIRB for simplicity * * Note: according to Intel, this is not preferred use. The command was * intended for the BIOS only, and may get confused with unsolicited * responses. So, we shouldn't use it for normal operation from the * driver. * I left the codes, however, for debugging/testing purposes.
*/
/* receive a response */ staticint azx_single_wait_for_response(struct azx *chip, unsignedint addr)
{ int timeout = 50;
while (timeout--) { /* check IRV busy bit */ if (azx_readw(chip, IRS) & AZX_IRS_VALID) { /* reuse rirb.res as the response return value */
azx_bus(chip)->rirb.res[addr] = azx_readl(chip, IR); return 0;
}
udelay(1);
} if (printk_ratelimit())
dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n",
azx_readw(chip, IRS));
azx_bus(chip)->rirb.res[addr] = -1; return -EIO;
}
/* * The below are the main callbacks from hda_codec. * * They are just the skeleton to call sub-callbacks according to the * current setting of chip->single_cmd.
*/
if (azx_has_pm_runtime(chip)) if (!pm_runtime_active(chip->card->dev)) return IRQ_NONE;
spin_lock(&bus->reg_lock);
if (chip->disabled) goto unlock;
do {
status = azx_readl(chip, INTSTS); if (status == 0 || status == 0xffffffff) break;
handled = true;
active = false; if (snd_hdac_bus_handle_stream_irq(bus, status, stream_update))
active = true;
status = azx_readb(chip, RIRBSTS); if (status & RIRB_INT_MASK) { /* * Clearing the interrupt status here ensures that no * interrupt gets masked after the RIRB wp is read in * snd_hdac_bus_update_rirb. This avoids a possible * race condition where codec response in RIRB may * remain unserviced by IRQ, eventually falling back * to polling mode in azx_rirb_get_response.
*/
azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
active = true; if (status & RIRB_INT_RESPONSE) { if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND)
udelay(80);
snd_hdac_bus_update_rirb(bus);
}
}
} while (active && ++repeat < 10);
if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY)
bus->core.align_bdle_4k = true;
if (chip->driver_caps & AZX_DCAPS_PIO_COMMANDS)
bus->core.use_pio_for_commands = true;
/* enable sync_write flag for stable communication as default */
bus->core.sync_write = 1;
return 0;
}
EXPORT_SYMBOL_GPL(azx_bus_init);
/* Probe codecs */ int azx_probe_codecs(struct azx *chip, unsignedint max_slots)
{ struct hdac_bus *bus = azx_bus(chip); int c, codecs, err;
codecs = 0; if (!max_slots)
max_slots = AZX_DEFAULT_CODECS;
/* First try to probe all given codec slots */ for (c = 0; c < max_slots; c++) { if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { if (probe_codec(chip, c) < 0) { /* Some BIOSen give you wrong codec addresses * that don't exist
*/
dev_warn(chip->card->dev, "Codec #%d probe error; disabling it...\n", c);
bus->codec_mask &= ~(1 << c); /* no codecs */ if (bus->codec_mask == 0) break; /* More badly, accessing to a non-existing * codec often screws up the controller chip, * and disturbs the further communications. * Thus if an error occurs during probing, * better to reset the controller chip to * get back to the sanity state.
*/
azx_stop_chip(chip);
azx_init_chip(chip, true);
}
}
}
/* Then create codec instances */ for (c = 0; c < max_slots; c++) { if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { struct hda_codec *codec;
err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); if (err < 0) continue;
codec->jackpoll_interval = chip->jackpoll_interval;
codec->beep_mode = chip->beep_mode;
codec->ctl_dev_id = chip->ctl_dev_id;
codecs++;
}
} if (!codecs) {
dev_err(chip->card->dev, "no codecs initialized\n"); return -ENXIO;
} return 0;
}
EXPORT_SYMBOL_GPL(azx_probe_codecs);
/* configure each codec instance */ int azx_codec_configure(struct azx *chip)
{ struct hda_codec *codec, *next; int success = 0;
list_for_each_codec(codec, &chip->bus) { if (!snd_hda_codec_configure(codec))
success++;
}
if (success) { /* unregister failed codecs if any codec has been probed */
list_for_each_codec_safe(codec, next, &chip->bus) { if (!codec->configured) {
codec_err(codec, "Unable to configure, disabling\n");
snd_hdac_device_unregister(&codec->core);
}
}
}
/* initialize SD streams */ int azx_init_streams(struct azx *chip)
{ int i; int stream_tags[2] = { 0, 0 };
/* initialize each stream (aka device) * assign the starting bdl address to each stream (device) * and initialize
*/ for (i = 0; i < chip->num_streams; i++) { struct azx_dev *azx_dev = kzalloc(sizeof(*azx_dev), GFP_KERNEL); int dir, tag;
if (!azx_dev) return -ENOMEM;
dir = stream_direction(chip, i); /* stream tag must be unique throughout * the stream direction group, * valid values 1...15 * use separate stream tag if the flag * AZX_DCAPS_SEPARATE_STREAM_TAG is used
*/ if (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG)
tag = ++stream_tags[dir]; else
tag = i + 1;
snd_hdac_stream_init(azx_bus(chip), azx_stream(azx_dev),
i, dir, tag);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.