Lines Matching defs:isight

49 struct isight {
88 static void isight_update_pointers(struct isight *isight, unsigned int count)
90 struct snd_pcm_runtime *runtime = isight->pcm->runtime;
95 ptr = isight->buffer_pointer;
99 WRITE_ONCE(isight->buffer_pointer, ptr);
101 isight->period_counter += count;
102 if (isight->period_counter >= runtime->period_size) {
103 isight->period_counter -= runtime->period_size;
104 snd_pcm_period_elapsed(isight->pcm);
108 static void isight_samples(struct isight *isight,
114 if (!READ_ONCE(isight->pcm_running))
117 runtime = isight->pcm->runtime;
118 if (isight->buffer_pointer + count <= runtime->buffer_size) {
119 memcpy(runtime->dma_area + isight->buffer_pointer * 4,
122 count1 = runtime->buffer_size - isight->buffer_pointer;
123 memcpy(runtime->dma_area + isight->buffer_pointer * 4,
129 isight_update_pointers(isight, count);
132 static void isight_pcm_abort(struct isight *isight)
134 if (READ_ONCE(isight->pcm_active))
135 snd_pcm_stop_xrun(isight->pcm);
138 static void isight_dropped_samples(struct isight *isight, unsigned int total)
144 if (!READ_ONCE(isight->pcm_running))
147 runtime = isight->pcm->runtime;
148 dropped = total - isight->total_samples;
150 if (isight->buffer_pointer + dropped <= runtime->buffer_size) {
151 memset(runtime->dma_area + isight->buffer_pointer * 4,
154 count1 = runtime->buffer_size - isight->buffer_pointer;
155 memset(runtime->dma_area + isight->buffer_pointer * 4,
159 isight_update_pointers(isight, dropped);
161 isight_pcm_abort(isight);
168 struct isight *isight = data;
173 if (isight->packet_index < 0)
175 index = isight->packet_index;
176 payload = isight->buffer.packets[index].buffer;
184 if (unlikely(total != isight->total_samples)) {
185 if (!isight->first_packet)
186 isight_dropped_samples(isight, total);
187 isight->first_packet = false;
188 isight->total_samples = total;
191 isight_samples(isight, payload->samples, count);
192 isight->total_samples += count;
196 err = fw_iso_context_queue(isight->context, &audio_packet,
197 &isight->buffer.iso_buffer,
198 isight->buffer.packets[index].offset);
200 dev_err(&isight->unit->device, "queueing error: %d\n", err);
201 isight_pcm_abort(isight);
202 isight->packet_index = -1;
205 fw_iso_context_queue_flush(isight->context);
209 isight->packet_index = index;
212 static int isight_connect(struct isight *isight)
218 ch = fw_iso_resources_allocate(&isight->resources,
220 isight->device->max_speed);
226 value = cpu_to_be32(ch | (isight->device->max_speed << SPEED_SHIFT));
227 err = snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
228 isight->audio_base + REG_ISO_TX_CONFIG,
230 isight->resources.generation);
232 fw_iso_resources_free(&isight->resources);
241 fw_iso_resources_free(&isight->resources);
266 struct isight *isight = substream->private_data;
270 return iso_packets_buffer_init(&isight->buffer, isight->unit,
278 struct isight *isight = substream->private_data;
280 iso_packets_buffer_destroy(&isight->buffer, isight->unit);
288 struct isight *isight = substream->private_data;
290 WRITE_ONCE(isight->pcm_active, true);
295 static int reg_read(struct isight *isight, int offset, __be32 *value)
297 return snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST,
298 isight->audio_base + offset, value, 4, 0);
301 static int reg_write(struct isight *isight, int offset, __be32 value)
303 return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
304 isight->audio_base + offset, &value, 4, 0);
307 static void isight_stop_streaming(struct isight *isight)
311 if (!isight->context)
314 fw_iso_context_stop(isight->context);
315 fw_iso_context_destroy(isight->context);
316 isight->context = NULL;
317 fw_iso_resources_free(&isight->resources);
319 snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
320 isight->audio_base + REG_AUDIO_ENABLE,
326 struct isight *isight = substream->private_data;
328 WRITE_ONCE(isight->pcm_active, false);
330 mutex_lock(&isight->mutex);
331 isight_stop_streaming(isight);
332 mutex_unlock(&isight->mutex);
337 static int isight_start_streaming(struct isight *isight)
342 if (isight->context) {
343 if (isight->packet_index < 0)
344 isight_stop_streaming(isight);
349 err = reg_write(isight, REG_SAMPLE_RATE, cpu_to_be32(RATE_48000));
353 err = isight_connect(isight);
357 err = reg_write(isight, REG_AUDIO_ENABLE, cpu_to_be32(AUDIO_ENABLE));
361 isight->context = fw_iso_context_create(isight->device->card,
363 isight->resources.channel,
364 isight->device->max_speed,
365 4, isight_packet, isight);
366 if (IS_ERR(isight->context)) {
367 err = PTR_ERR(isight->context);
368 isight->context = NULL;
373 err = fw_iso_context_queue(isight->context, &audio_packet,
374 &isight->buffer.iso_buffer,
375 isight->buffer.packets[i].offset);
380 isight->first_packet = true;
381 isight->packet_index = 0;
383 err = fw_iso_context_start(isight->context, -1, 0,
391 fw_iso_context_destroy(isight->context);
392 isight->context = NULL;
394 fw_iso_resources_free(&isight->resources);
395 reg_write(isight, REG_AUDIO_ENABLE, 0);
402 struct isight *isight = substream->private_data;
405 isight->buffer_pointer = 0;
406 isight->period_counter = 0;
408 mutex_lock(&isight->mutex);
409 err = isight_start_streaming(isight);
410 mutex_unlock(&isight->mutex);
417 struct isight *isight = substream->private_data;
421 WRITE_ONCE(isight->pcm_running, true);
424 WRITE_ONCE(isight->pcm_running, false);
434 struct isight *isight = substream->private_data;
436 return READ_ONCE(isight->buffer_pointer);
439 static int isight_create_pcm(struct isight *isight)
453 err = snd_pcm_new(isight->card, "iSight", 0, 0, 1, &pcm);
456 pcm->private_data = isight;
458 isight->pcm = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
459 isight->pcm->ops = &ops;
468 struct isight *isight = ctl->private_data;
472 info->value.integer.min = isight->gain_min;
473 info->value.integer.max = isight->gain_max;
481 struct isight *isight = ctl->private_data;
485 err = reg_read(isight, REG_GAIN, &gain);
497 struct isight *isight = ctl->private_data;
499 if (value->value.integer.value[0] < isight->gain_min ||
500 value->value.integer.value[0] > isight->gain_max)
503 return reg_write(isight, REG_GAIN,
510 struct isight *isight = ctl->private_data;
514 err = reg_read(isight, REG_MUTE, &mute);
526 struct isight *isight = ctl->private_data;
528 return reg_write(isight, REG_MUTE,
532 static int isight_create_mixer(struct isight *isight)
554 err = reg_read(isight, REG_GAIN_RAW_START, &value);
557 isight->gain_min = be32_to_cpu(value);
559 err = reg_read(isight, REG_GAIN_RAW_END, &value);
562 isight->gain_max = be32_to_cpu(value);
564 isight->gain_tlv[SNDRV_CTL_TLVO_TYPE] = SNDRV_CTL_TLVT_DB_MINMAX;
565 isight->gain_tlv[SNDRV_CTL_TLVO_LEN] = 2 * sizeof(unsigned int);
567 err = reg_read(isight, REG_GAIN_DB_START, &value);
570 isight->gain_tlv[SNDRV_CTL_TLVO_DB_MINMAX_MIN] =
573 err = reg_read(isight, REG_GAIN_DB_END, &value);
576 isight->gain_tlv[SNDRV_CTL_TLVO_DB_MINMAX_MAX] =
579 ctl = snd_ctl_new1(&gain_control, isight);
581 ctl->tlv.p = isight->gain_tlv;
582 err = snd_ctl_add(isight->card, ctl);
586 err = snd_ctl_add(isight->card, snd_ctl_new1(&mute_control, isight));
595 struct isight *isight = card->private_data;
597 fw_iso_resources_destroy(&isight->resources);
617 struct isight *isight;
621 sizeof(*isight), &card);
625 isight = card->private_data;
626 isight->card = card;
627 mutex_init(&isight->mutex);
628 isight->unit = fw_unit_get(unit);
629 isight->device = fw_dev;
630 isight->audio_base = get_unit_base(unit);
631 if (!isight->audio_base) {
636 fw_iso_resources_init(&isight->resources, unit);
648 err = isight_create_pcm(isight);
652 err = isight_create_mixer(isight);
660 dev_set_drvdata(&unit->device, isight);
666 mutex_destroy(&isight->mutex);
667 fw_unit_put(isight->unit);
674 struct isight *isight = dev_get_drvdata(&unit->device);
676 if (fw_iso_resources_update(&isight->resources) < 0) {
677 isight_pcm_abort(isight);
679 mutex_lock(&isight->mutex);
680 isight_stop_streaming(isight);
681 mutex_unlock(&isight->mutex);
687 struct isight *isight = dev_get_drvdata(&unit->device);
689 isight_pcm_abort(isight);
691 snd_card_disconnect(isight->card);
693 mutex_lock(&isight->mutex);
694 isight_stop_streaming(isight);
695 mutex_unlock(&isight->mutex);
698 snd_card_free(isight->card);
700 mutex_destroy(&isight->mutex);
701 fw_unit_put(isight->unit);