/** * struct channel - private structure to keep channel specific data * @substream: stores the substream structure * @pcm_hardware: low-level hardware description * @iface: interface for which the channel belongs to * @cfg: channel configuration * @card: registered sound card * @list: list for private use * @id: channel index * @period_pos: current period position (ring buffer) * @buffer_pos: current buffer position (ring buffer) * @is_stream_running: identifies whether a stream is running or not * @opened: set when the stream is opened * @playback_task: playback thread * @playback_waitq: waitq used by playback thread * @copy_fn: copy function for PCM-specific format and width
*/ struct channel { struct snd_pcm_substream *substream; struct snd_pcm_hardware pcm_hardware; struct most_interface *iface; struct most_channel_config *cfg; struct snd_card *card; struct list_head list; int id; unsignedint period_pos; unsignedint buffer_pos; bool is_stream_running; struct task_struct *playback_task;
wait_queue_head_t playback_waitq; void (*copy_fn)(void *alsa, void *most, unsignedint bytes);
};
/** * get_channel - get pointer to channel * @iface: interface structure * @channel_id: channel ID * * This traverses the channel list and returns the channel matching the * ID and interface. * * Returns pointer to channel on success or NULL otherwise.
*/ staticstruct channel *get_channel(struct most_interface *iface, int channel_id)
{ struct sound_adapter *adpt = iface->priv; struct channel *channel;
if (frames > fr0) { /* wrap around at end of ring buffer */
channel->copy_fn(runtime->dma_area,
mbo->virt_address + fr0 * frame_bytes,
(frames - fr0) * frame_bytes);
}
/** * playback_thread - function implements the playback thread * @data: private data * * Thread which does the playback functionality in a loop. It waits for a free * MBO from mostcore for a particular channel and copy the data from ring buffer * to MBO. Submit the MBO back to mostcore, after copying the data. * * Returns 0 on success or error code otherwise.
*/ staticint playback_thread(void *data)
{ struct channel *const channel = data;
if (channel->is_stream_running)
period_elapsed = copy_data(channel, mbo); else
memset(mbo->virt_address, 0, mbo->buffer_length);
most_submit_mbo(mbo); if (period_elapsed)
snd_pcm_period_elapsed(channel->substream);
} return 0;
}
/** * pcm_open - implements open callback function for PCM middle layer * @substream: pointer to ALSA PCM substream * * This is called when a PCM substream is opened. At least, the function should * initialize the runtime->hw record. * * Returns 0 on success or error code otherwise.
*/ staticint pcm_open(struct snd_pcm_substream *substream)
{ struct channel *channel = substream->private_data; struct snd_pcm_runtime *runtime = substream->runtime; struct most_channel_config *cfg = channel->cfg; int ret;
channel->substream = substream;
if (cfg->direction == MOST_CH_TX) {
channel->playback_task = kthread_run(playback_thread, channel, "most_audio_playback"); if (IS_ERR(channel->playback_task)) {
pr_err("Couldn't start thread\n"); return PTR_ERR(channel->playback_task);
}
}
ret = most_start_channel(channel->iface, channel->id, &comp); if (ret) {
pr_err("most_start_channel() failed!\n"); if (cfg->direction == MOST_CH_TX)
kthread_stop(channel->playback_task); return ret;
}
runtime->hw = channel->pcm_hardware; return 0;
}
/** * pcm_close - implements close callback function for PCM middle layer * @substream: sub-stream pointer * * Obviously, this is called when a PCM substream is closed. Any private * instance for a PCM substream allocated in the open callback will be * released here. * * Returns 0 on success or error code otherwise.
*/ staticint pcm_close(struct snd_pcm_substream *substream)
{ struct channel *channel = substream->private_data;
/** * pcm_prepare - implements prepare callback function for PCM middle layer * @substream: substream pointer * * This callback is called when the PCM is "prepared". Format rate, sample rate, * etc., can be set here. This callback can be called many times at each setup. * * Returns 0 on success or error code otherwise.
*/ staticint pcm_prepare(struct snd_pcm_substream *substream)
{ struct channel *channel = substream->private_data; struct snd_pcm_runtime *runtime = substream->runtime; struct most_channel_config *cfg = channel->cfg; int width = snd_pcm_format_physical_width(runtime->format);
/** * pcm_trigger - implements trigger callback function for PCM middle layer * @substream: substream pointer * @cmd: action to perform * * This is called when the PCM is started, stopped or paused. The action will be * specified in the second argument, SNDRV_PCM_TRIGGER_XXX * * Returns 0 on success or error code otherwise.
*/ staticint pcm_trigger(struct snd_pcm_substream *substream, int cmd)
{ struct channel *channel = substream->private_data;
case SNDRV_PCM_TRIGGER_STOP:
channel->is_stream_running = false; return 0;
default: return -EINVAL;
} return 0;
}
/** * pcm_pointer - implements pointer callback function for PCM middle layer * @substream: substream pointer * * This callback is called when the PCM middle layer inquires the current * hardware position on the buffer. The position must be returned in frames, * ranging from 0 to buffer_size-1.
*/ static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
{ struct channel *channel = substream->private_data;
for (i = 0; i < ARRAY_SIZE(sinfo); i++) { if (!strcmp(sample_res, sinfo[i].sample_res)) goto found;
}
pr_err("Unsupported PCM format\n"); return -EINVAL;
found: if (!ch_num) {
pr_err("Bad number of channels\n"); return -EINVAL;
}
if (cfg->subbuffer_size != ch_num * sinfo[i].bytes) {
pr_err("Audio resolution doesn't fit subbuffer size\n"); return -EINVAL;
}
/** * audio_probe_channel - probe function of the driver module * @iface: pointer to interface instance * @channel_id: channel index/ID * @cfg: pointer to actual channel configuration * @device_name: name of the device to be created in /dev * @arg_list: string that provides the desired audio resolution * * Creates sound card, pcm device, sets pcm ops and registers sound card. * * Returns 0 on success or error code otherwise.
*/ staticint audio_probe_channel(struct most_interface *iface, int channel_id, struct most_channel_config *cfg, char *device_name, char *arg_list)
{ struct channel *channel; struct sound_adapter *adpt; struct snd_pcm *pcm; int playback_count = 0; int capture_count = 0; int ret; int direction;
u16 ch_num; char *sample_res; char arg_list_cpy[STRING_SIZE];
if (cfg->data_type != MOST_CH_SYNC) {
pr_err("Incompatible channel type\n"); return -EINVAL;
}
strscpy(arg_list_cpy, arg_list, STRING_SIZE);
ret = split_arg_list(arg_list_cpy, &ch_num, &sample_res); if (ret < 0) return ret;
list_for_each_entry(adpt, &adpt_list, list) { if (adpt->iface != iface) continue; if (adpt->registered) return -ENOSPC;
adpt->pcm_dev_idx++; goto skip_adpt_alloc;
}
adpt = kzalloc(sizeof(*adpt), GFP_KERNEL); if (!adpt) return -ENOMEM;
staticint audio_create_sound_card(void)
{ int ret; struct sound_adapter *adpt;
list_for_each_entry(adpt, &adpt_list, list) { if (!adpt->registered) goto adpt_alloc;
} return -ENODEV;
adpt_alloc:
ret = snd_card_register(adpt->card); if (ret < 0) {
release_adapter(adpt); return ret;
}
adpt->registered = true; return 0;
}
/** * audio_disconnect_channel - function to disconnect a channel * @iface: pointer to interface instance * @channel_id: channel index * * This frees allocated memory and removes the sound card from ALSA * * Returns 0 on success or error code otherwise.
*/ staticint audio_disconnect_channel(struct most_interface *iface, int channel_id)
{ struct channel *channel; struct sound_adapter *adpt = iface->priv;
channel = get_channel(iface, channel_id); if (!channel) return -EINVAL;
list_del(&channel->list);
kfree(channel); if (list_empty(&adpt->dev_list))
release_adapter(adpt); return 0;
}
/** * audio_rx_completion - completion handler for rx channels * @mbo: pointer to buffer object that has completed * * This searches for the channel this MBO belongs to and copy the data from MBO * to ring buffer * * Returns 0 on success or error code otherwise.
*/ staticint audio_rx_completion(struct mbo *mbo)
{ struct channel *channel = get_channel(mbo->ifp, mbo->hdm_channel_id); bool period_elapsed = false;
if (!channel) return -EINVAL; if (channel->is_stream_running)
period_elapsed = copy_data(channel, mbo);
most_put_mbo(mbo); if (period_elapsed)
snd_pcm_period_elapsed(channel->substream); return 0;
}
/** * audio_tx_completion - completion handler for tx channels * @iface: pointer to interface instance * @channel_id: channel index/ID * * This searches the channel that belongs to this combination of interface * pointer and channel ID and wakes a process sitting in the wait queue of * this channel. * * Returns 0 on success or error code otherwise.
*/ staticint audio_tx_completion(struct most_interface *iface, int channel_id)
{ struct channel *channel = get_channel(iface, channel_id);
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.