8 #include <asm/byteorder.h>
10 #include <linux/device.h>
13 #include <linux/module.h>
16 #include <linux/string.h>
26 #define OUI_APPLE 0x000a27
27 #define MODEL_APPLE_ISIGHT 0x000008
28 #define SW_ISIGHT_AUDIO 0x000010
30 #define REG_AUDIO_ENABLE 0x000
31 #define AUDIO_ENABLE 0x80000000
32 #define REG_DEF_AUDIO_GAIN 0x204
33 #define REG_GAIN_RAW_START 0x210
34 #define REG_GAIN_RAW_END 0x214
35 #define REG_GAIN_DB_START 0x218
36 #define REG_GAIN_DB_END 0x21c
37 #define REG_SAMPLE_RATE_INQUIRY 0x280
38 #define REG_ISO_TX_CONFIG 0x300
39 #define SPEED_SHIFT 16
40 #define REG_SAMPLE_RATE 0x400
41 #define RATE_48000 0x80000000
42 #define REG_GAIN 0x500
43 #define REG_MUTE 0x504
45 #define MAX_FRAMES_PER_PACKET 475
47 #define QUEUE_LENGTH 20
108 static void isight_samples(
struct isight *isight,
109 const __be16 *samples,
unsigned int count)
117 runtime = isight->
pcm->runtime;
124 samples, count1 * 4);
125 samples += count1 * 2;
129 isight_update_pointers(isight, count);
132 static void isight_pcm_abort(
struct isight *isight)
138 if (snd_pcm_running(isight->
pcm))
144 static void isight_dropped_samples(
struct isight *isight,
unsigned int total)
153 runtime = isight->
pcm->runtime;
165 isight_update_pointers(isight, dropped);
167 isight_pcm_abort(isight);
174 struct isight *isight =
data;
185 if (
likely(length >= 16 &&
188 if (
likely(count <= (length - 16) / 4)) {
192 isight_dropped_samples(isight, total);
197 isight_samples(isight, payload->
samples, count);
203 &isight->
buffer.iso_buffer,
204 isight->
buffer.packets[index].offset);
206 dev_err(&isight->
unit->device,
"queueing error: %d\n", err);
207 isight_pcm_abort(isight);
218 static int isight_connect(
struct isight *isight)
223 retry_after_bus_reset:
226 isight->
device->max_speed);
239 isight->
device->max_speed,
246 goto retry_after_bus_reset;
247 }
else if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
274 .buffer_bytes_max = 4 * 1024 * 1024,
276 .period_bytes_max = 1024 * 1024,
327 static void isight_stop_streaming(
struct isight *isight)
346 isight_stop_streaming(isight);
352 static int isight_start_streaming(
struct isight *isight)
359 isight_stop_streaming(isight);
368 err = isight_connect(isight);
379 isight->
device->max_speed,
380 4, isight_packet, isight);
382 err = PTR_ERR(isight->
context);
389 &isight->
buffer.iso_buffer,
390 isight->
buffer.packets[i].offset);
424 err = isight_start_streaming(isight);
454 static int isight_create_pcm(
struct isight *isight)
458 .close = isight_close,
460 .hw_params = isight_hw_params,
461 .hw_free = isight_hw_free,
462 .prepare = isight_prepare,
463 .trigger = isight_trigger,
464 .pointer = isight_pointer,
477 isight->
pcm->ops = &ops;
549 static int isight_create_mixer(
struct isight *isight)
553 .name =
"Mic Capture Volume",
556 .info = isight_gain_info,
557 .get = isight_gain_get,
558 .put = isight_gain_put,
562 .name =
"Mic Capture Switch",
564 .get = isight_mute_get,
565 .put = isight_mute_put,
613 fw_unit_put(isight->
unit);
629 static int isight_probe(
struct device *unit_dev)
632 struct fw_device *fw_dev = fw_parent_device(unit);
634 struct isight *isight;
645 isight->
unit = fw_unit_get(unit);
660 "Apple iSight (GUID %08x%08x) at %s, S%d",
665 err = isight_create_pcm(isight);
669 err = isight_create_mixer(isight);
682 fw_unit_put(isight->
unit);
689 static int isight_remove(
struct device *
dev)
693 isight_pcm_abort(isight);
698 isight_stop_streaming(isight);
706 static void isight_bus_reset(
struct fw_unit *unit)
711 isight_pcm_abort(isight);
714 isight_stop_streaming(isight);
730 static struct fw_driver isight_driver = {
733 .name = KBUILD_MODNAME,
735 .probe = isight_probe,
736 .remove = isight_remove,
738 .update = isight_bus_reset,
739 .id_table = isight_id_table,
742 static int __init alsa_isight_init(
void)
747 static void __exit alsa_isight_exit(
void)