isight.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*
  2. * Apple iSight audio driver
  3. *
  4. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  5. * Licensed under the terms of the GNU General Public License, version 2.
  6. */
  7. #include <asm/byteorder.h>
  8. #include <linux/delay.h>
  9. #include <linux/device.h>
  10. #include <linux/firewire.h>
  11. #include <linux/firewire-constants.h>
  12. #include <linux/module.h>
  13. #include <linux/mod_devicetable.h>
  14. #include <linux/mutex.h>
  15. #include <linux/string.h>
  16. #include <sound/control.h>
  17. #include <sound/core.h>
  18. #include <sound/initval.h>
  19. #include <sound/pcm.h>
  20. #include <sound/tlv.h>
  21. #include "lib.h"
  22. #include "iso-resources.h"
  23. #include "packets-buffer.h"
  24. #define OUI_APPLE 0x000a27
  25. #define MODEL_APPLE_ISIGHT 0x000008
  26. #define SW_ISIGHT_AUDIO 0x000010
  27. #define REG_AUDIO_ENABLE 0x000
  28. #define AUDIO_ENABLE 0x80000000
  29. #define REG_DEF_AUDIO_GAIN 0x204
  30. #define REG_GAIN_RAW_START 0x210
  31. #define REG_GAIN_RAW_END 0x214
  32. #define REG_GAIN_DB_START 0x218
  33. #define REG_GAIN_DB_END 0x21c
  34. #define REG_SAMPLE_RATE_INQUIRY 0x280
  35. #define REG_ISO_TX_CONFIG 0x300
  36. #define SPEED_SHIFT 16
  37. #define REG_SAMPLE_RATE 0x400
  38. #define RATE_48000 0x80000000
  39. #define REG_GAIN 0x500
  40. #define REG_MUTE 0x504
  41. #define MAX_FRAMES_PER_PACKET 475
  42. #define QUEUE_LENGTH 20
  43. struct isight {
  44. struct snd_card *card;
  45. struct fw_unit *unit;
  46. struct fw_device *device;
  47. u64 audio_base;
  48. struct fw_address_handler iris_handler;
  49. struct snd_pcm_substream *pcm;
  50. struct mutex mutex;
  51. struct iso_packets_buffer buffer;
  52. struct fw_iso_resources resources;
  53. struct fw_iso_context *context;
  54. bool pcm_active;
  55. bool pcm_running;
  56. bool first_packet;
  57. int packet_index;
  58. u32 total_samples;
  59. unsigned int buffer_pointer;
  60. unsigned int period_counter;
  61. s32 gain_min, gain_max;
  62. unsigned int gain_tlv[4];
  63. };
  64. struct audio_payload {
  65. __be32 sample_count;
  66. __be32 signature;
  67. __be32 sample_total;
  68. __be32 reserved;
  69. __be16 samples[2 * MAX_FRAMES_PER_PACKET];
  70. };
  71. MODULE_DESCRIPTION("iSight audio driver");
  72. MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  73. MODULE_LICENSE("GPL v2");
  74. static struct fw_iso_packet audio_packet = {
  75. .payload_length = sizeof(struct audio_payload),
  76. .interrupt = 1,
  77. .header_length = 4,
  78. };
  79. static void isight_update_pointers(struct isight *isight, unsigned int count)
  80. {
  81. struct snd_pcm_runtime *runtime = isight->pcm->runtime;
  82. unsigned int ptr;
  83. smp_wmb(); /* update buffer data before buffer pointer */
  84. ptr = isight->buffer_pointer;
  85. ptr += count;
  86. if (ptr >= runtime->buffer_size)
  87. ptr -= runtime->buffer_size;
  88. ACCESS_ONCE(isight->buffer_pointer) = ptr;
  89. isight->period_counter += count;
  90. if (isight->period_counter >= runtime->period_size) {
  91. isight->period_counter -= runtime->period_size;
  92. snd_pcm_period_elapsed(isight->pcm);
  93. }
  94. }
  95. static void isight_samples(struct isight *isight,
  96. const __be16 *samples, unsigned int count)
  97. {
  98. struct snd_pcm_runtime *runtime;
  99. unsigned int count1;
  100. if (!ACCESS_ONCE(isight->pcm_running))
  101. return;
  102. runtime = isight->pcm->runtime;
  103. if (isight->buffer_pointer + count <= runtime->buffer_size) {
  104. memcpy(runtime->dma_area + isight->buffer_pointer * 4,
  105. samples, count * 4);
  106. } else {
  107. count1 = runtime->buffer_size - isight->buffer_pointer;
  108. memcpy(runtime->dma_area + isight->buffer_pointer * 4,
  109. samples, count1 * 4);
  110. samples += count1 * 2;
  111. memcpy(runtime->dma_area, samples, (count - count1) * 4);
  112. }
  113. isight_update_pointers(isight, count);
  114. }
  115. static void isight_pcm_abort(struct isight *isight)
  116. {
  117. unsigned long flags;
  118. if (ACCESS_ONCE(isight->pcm_active)) {
  119. snd_pcm_stream_lock_irqsave(isight->pcm, flags);
  120. if (snd_pcm_running(isight->pcm))
  121. snd_pcm_stop(isight->pcm, SNDRV_PCM_STATE_XRUN);
  122. snd_pcm_stream_unlock_irqrestore(isight->pcm, flags);
  123. }
  124. }
  125. static void isight_dropped_samples(struct isight *isight, unsigned int total)
  126. {
  127. struct snd_pcm_runtime *runtime;
  128. u32 dropped;
  129. unsigned int count1;
  130. if (!ACCESS_ONCE(isight->pcm_running))
  131. return;
  132. runtime = isight->pcm->runtime;
  133. dropped = total - isight->total_samples;
  134. if (dropped < runtime->buffer_size) {
  135. if (isight->buffer_pointer + dropped <= runtime->buffer_size) {
  136. memset(runtime->dma_area + isight->buffer_pointer * 4,
  137. 0, dropped * 4);
  138. } else {
  139. count1 = runtime->buffer_size - isight->buffer_pointer;
  140. memset(runtime->dma_area + isight->buffer_pointer * 4,
  141. 0, count1 * 4);
  142. memset(runtime->dma_area, 0, (dropped - count1) * 4);
  143. }
  144. isight_update_pointers(isight, dropped);
  145. } else {
  146. isight_pcm_abort(isight);
  147. }
  148. }
  149. static void isight_packet(struct fw_iso_context *context, u32 cycle,
  150. size_t header_length, void *header, void *data)
  151. {
  152. struct isight *isight = data;
  153. const struct audio_payload *payload;
  154. unsigned int index, length, count, total;
  155. int err;
  156. if (isight->packet_index < 0)
  157. return;
  158. index = isight->packet_index;
  159. payload = isight->buffer.packets[index].buffer;
  160. length = be32_to_cpup(header) >> 16;
  161. if (likely(length >= 16 &&
  162. payload->signature == cpu_to_be32(0x73676874/*"sght"*/))) {
  163. count = be32_to_cpu(payload->sample_count);
  164. if (likely(count <= (length - 16) / 4)) {
  165. total = be32_to_cpu(payload->sample_total);
  166. if (unlikely(total != isight->total_samples)) {
  167. if (!isight->first_packet)
  168. isight_dropped_samples(isight, total);
  169. isight->first_packet = false;
  170. isight->total_samples = total;
  171. }
  172. isight_samples(isight, payload->samples, count);
  173. isight->total_samples += count;
  174. }
  175. }
  176. err = fw_iso_context_queue(isight->context, &audio_packet,
  177. &isight->buffer.iso_buffer,
  178. isight->buffer.packets[index].offset);
  179. if (err < 0) {
  180. dev_err(&isight->unit->device, "queueing error: %d\n", err);
  181. isight_pcm_abort(isight);
  182. isight->packet_index = -1;
  183. return;
  184. }
  185. fw_iso_context_queue_flush(isight->context);
  186. if (++index >= QUEUE_LENGTH)
  187. index = 0;
  188. isight->packet_index = index;
  189. }
  190. static int isight_connect(struct isight *isight)
  191. {
  192. int ch, err, rcode, errors = 0;
  193. __be32 value;
  194. retry_after_bus_reset:
  195. ch = fw_iso_resources_allocate(&isight->resources,
  196. sizeof(struct audio_payload),
  197. isight->device->max_speed);
  198. if (ch < 0) {
  199. err = ch;
  200. goto error;
  201. }
  202. value = cpu_to_be32(ch | (isight->device->max_speed << SPEED_SHIFT));
  203. for (;;) {
  204. rcode = fw_run_transaction(
  205. isight->device->card,
  206. TCODE_WRITE_QUADLET_REQUEST,
  207. isight->device->node_id,
  208. isight->resources.generation,
  209. isight->device->max_speed,
  210. isight->audio_base + REG_ISO_TX_CONFIG,
  211. &value, 4);
  212. if (rcode == RCODE_COMPLETE) {
  213. return 0;
  214. } else if (rcode == RCODE_GENERATION) {
  215. fw_iso_resources_free(&isight->resources);
  216. goto retry_after_bus_reset;
  217. } else if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
  218. err = -EIO;
  219. goto err_resources;
  220. }
  221. msleep(5);
  222. }
  223. err_resources:
  224. fw_iso_resources_free(&isight->resources);
  225. error:
  226. return err;
  227. }
  228. static int isight_open(struct snd_pcm_substream *substream)
  229. {
  230. static const struct snd_pcm_hardware hardware = {
  231. .info = SNDRV_PCM_INFO_MMAP |
  232. SNDRV_PCM_INFO_MMAP_VALID |
  233. SNDRV_PCM_INFO_BATCH |
  234. SNDRV_PCM_INFO_INTERLEAVED |
  235. SNDRV_PCM_INFO_BLOCK_TRANSFER,
  236. .formats = SNDRV_PCM_FMTBIT_S16_BE,
  237. .rates = SNDRV_PCM_RATE_48000,
  238. .rate_min = 48000,
  239. .rate_max = 48000,
  240. .channels_min = 2,
  241. .channels_max = 2,
  242. .buffer_bytes_max = 4 * 1024 * 1024,
  243. .period_bytes_min = MAX_FRAMES_PER_PACKET * 4,
  244. .period_bytes_max = 1024 * 1024,
  245. .periods_min = 2,
  246. .periods_max = UINT_MAX,
  247. };
  248. struct isight *isight = substream->private_data;
  249. substream->runtime->hw = hardware;
  250. return iso_packets_buffer_init(&isight->buffer, isight->unit,
  251. QUEUE_LENGTH,
  252. sizeof(struct audio_payload),
  253. DMA_FROM_DEVICE);
  254. }
  255. static int isight_close(struct snd_pcm_substream *substream)
  256. {
  257. struct isight *isight = substream->private_data;
  258. iso_packets_buffer_destroy(&isight->buffer, isight->unit);
  259. return 0;
  260. }
  261. static int isight_hw_params(struct snd_pcm_substream *substream,
  262. struct snd_pcm_hw_params *hw_params)
  263. {
  264. struct isight *isight = substream->private_data;
  265. int err;
  266. err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
  267. params_buffer_bytes(hw_params));
  268. if (err < 0)
  269. return err;
  270. ACCESS_ONCE(isight->pcm_active) = true;
  271. return 0;
  272. }
  273. static int reg_read(struct isight *isight, int offset, __be32 *value)
  274. {
  275. return snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST,
  276. isight->audio_base + offset, value, 4);
  277. }
  278. static int reg_write(struct isight *isight, int offset, __be32 value)
  279. {
  280. return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
  281. isight->audio_base + offset, &value, 4);
  282. }
  283. static void isight_stop_streaming(struct isight *isight)
  284. {
  285. if (!isight->context)
  286. return;
  287. fw_iso_context_stop(isight->context);
  288. fw_iso_context_destroy(isight->context);
  289. isight->context = NULL;
  290. fw_iso_resources_free(&isight->resources);
  291. reg_write(isight, REG_AUDIO_ENABLE, 0);
  292. }
  293. static int isight_hw_free(struct snd_pcm_substream *substream)
  294. {
  295. struct isight *isight = substream->private_data;
  296. ACCESS_ONCE(isight->pcm_active) = false;
  297. mutex_lock(&isight->mutex);
  298. isight_stop_streaming(isight);
  299. mutex_unlock(&isight->mutex);
  300. return snd_pcm_lib_free_vmalloc_buffer(substream);
  301. }
  302. static int isight_start_streaming(struct isight *isight)
  303. {
  304. unsigned int i;
  305. int err;
  306. if (isight->context) {
  307. if (isight->packet_index < 0)
  308. isight_stop_streaming(isight);
  309. else
  310. return 0;
  311. }
  312. err = reg_write(isight, REG_SAMPLE_RATE, cpu_to_be32(RATE_48000));
  313. if (err < 0)
  314. goto error;
  315. err = isight_connect(isight);
  316. if (err < 0)
  317. goto error;
  318. err = reg_write(isight, REG_AUDIO_ENABLE, cpu_to_be32(AUDIO_ENABLE));
  319. if (err < 0)
  320. goto err_resources;
  321. isight->context = fw_iso_context_create(isight->device->card,
  322. FW_ISO_CONTEXT_RECEIVE,
  323. isight->resources.channel,
  324. isight->device->max_speed,
  325. 4, isight_packet, isight);
  326. if (IS_ERR(isight->context)) {
  327. err = PTR_ERR(isight->context);
  328. isight->context = NULL;
  329. goto err_resources;
  330. }
  331. for (i = 0; i < QUEUE_LENGTH; ++i) {
  332. err = fw_iso_context_queue(isight->context, &audio_packet,
  333. &isight->buffer.iso_buffer,
  334. isight->buffer.packets[i].offset);
  335. if (err < 0)
  336. goto err_context;
  337. }
  338. isight->first_packet = true;
  339. isight->packet_index = 0;
  340. err = fw_iso_context_start(isight->context, -1, 0,
  341. FW_ISO_CONTEXT_MATCH_ALL_TAGS/*?*/);
  342. if (err < 0)
  343. goto err_context;
  344. return 0;
  345. err_context:
  346. fw_iso_context_destroy(isight->context);
  347. isight->context = NULL;
  348. err_resources:
  349. fw_iso_resources_free(&isight->resources);
  350. reg_write(isight, REG_AUDIO_ENABLE, 0);
  351. error:
  352. return err;
  353. }
  354. static int isight_prepare(struct snd_pcm_substream *substream)
  355. {
  356. struct isight *isight = substream->private_data;
  357. int err;
  358. isight->buffer_pointer = 0;
  359. isight->period_counter = 0;
  360. mutex_lock(&isight->mutex);
  361. err = isight_start_streaming(isight);
  362. mutex_unlock(&isight->mutex);
  363. return err;
  364. }
  365. static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
  366. {
  367. struct isight *isight = substream->private_data;
  368. switch (cmd) {
  369. case SNDRV_PCM_TRIGGER_START:
  370. ACCESS_ONCE(isight->pcm_running) = true;
  371. break;
  372. case SNDRV_PCM_TRIGGER_STOP:
  373. ACCESS_ONCE(isight->pcm_running) = false;
  374. break;
  375. default:
  376. return -EINVAL;
  377. }
  378. return 0;
  379. }
  380. static snd_pcm_uframes_t isight_pointer(struct snd_pcm_substream *substream)
  381. {
  382. struct isight *isight = substream->private_data;
  383. return ACCESS_ONCE(isight->buffer_pointer);
  384. }
  385. static int isight_create_pcm(struct isight *isight)
  386. {
  387. static struct snd_pcm_ops ops = {
  388. .open = isight_open,
  389. .close = isight_close,
  390. .ioctl = snd_pcm_lib_ioctl,
  391. .hw_params = isight_hw_params,
  392. .hw_free = isight_hw_free,
  393. .prepare = isight_prepare,
  394. .trigger = isight_trigger,
  395. .pointer = isight_pointer,
  396. .page = snd_pcm_lib_get_vmalloc_page,
  397. .mmap = snd_pcm_lib_mmap_vmalloc,
  398. };
  399. struct snd_pcm *pcm;
  400. int err;
  401. err = snd_pcm_new(isight->card, "iSight", 0, 0, 1, &pcm);
  402. if (err < 0)
  403. return err;
  404. pcm->private_data = isight;
  405. strcpy(pcm->name, "iSight");
  406. isight->pcm = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
  407. isight->pcm->ops = &ops;
  408. return 0;
  409. }
  410. static int isight_gain_info(struct snd_kcontrol *ctl,
  411. struct snd_ctl_elem_info *info)
  412. {
  413. struct isight *isight = ctl->private_data;
  414. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  415. info->count = 1;
  416. info->value.integer.min = isight->gain_min;
  417. info->value.integer.max = isight->gain_max;
  418. return 0;
  419. }
  420. static int isight_gain_get(struct snd_kcontrol *ctl,
  421. struct snd_ctl_elem_value *value)
  422. {
  423. struct isight *isight = ctl->private_data;
  424. __be32 gain;
  425. int err;
  426. err = reg_read(isight, REG_GAIN, &gain);
  427. if (err < 0)
  428. return err;
  429. value->value.integer.value[0] = (s32)be32_to_cpu(gain);
  430. return 0;
  431. }
  432. static int isight_gain_put(struct snd_kcontrol *ctl,
  433. struct snd_ctl_elem_value *value)
  434. {
  435. struct isight *isight = ctl->private_data;
  436. if (value->value.integer.value[0] < isight->gain_min ||
  437. value->value.integer.value[0] > isight->gain_max)
  438. return -EINVAL;
  439. return reg_write(isight, REG_GAIN,
  440. cpu_to_be32(value->value.integer.value[0]));
  441. }
  442. static int isight_mute_get(struct snd_kcontrol *ctl,
  443. struct snd_ctl_elem_value *value)
  444. {
  445. struct isight *isight = ctl->private_data;
  446. __be32 mute;
  447. int err;
  448. err = reg_read(isight, REG_MUTE, &mute);
  449. if (err < 0)
  450. return err;
  451. value->value.integer.value[0] = !mute;
  452. return 0;
  453. }
  454. static int isight_mute_put(struct snd_kcontrol *ctl,
  455. struct snd_ctl_elem_value *value)
  456. {
  457. struct isight *isight = ctl->private_data;
  458. return reg_write(isight, REG_MUTE,
  459. (__force __be32)!value->value.integer.value[0]);
  460. }
  461. static int isight_create_mixer(struct isight *isight)
  462. {
  463. static const struct snd_kcontrol_new gain_control = {
  464. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  465. .name = "Mic Capture Volume",
  466. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  467. SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  468. .info = isight_gain_info,
  469. .get = isight_gain_get,
  470. .put = isight_gain_put,
  471. };
  472. static const struct snd_kcontrol_new mute_control = {
  473. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  474. .name = "Mic Capture Switch",
  475. .info = snd_ctl_boolean_mono_info,
  476. .get = isight_mute_get,
  477. .put = isight_mute_put,
  478. };
  479. __be32 value;
  480. struct snd_kcontrol *ctl;
  481. int err;
  482. err = reg_read(isight, REG_GAIN_RAW_START, &value);
  483. if (err < 0)
  484. return err;
  485. isight->gain_min = be32_to_cpu(value);
  486. err = reg_read(isight, REG_GAIN_RAW_END, &value);
  487. if (err < 0)
  488. return err;
  489. isight->gain_max = be32_to_cpu(value);
  490. isight->gain_tlv[0] = SNDRV_CTL_TLVT_DB_MINMAX;
  491. isight->gain_tlv[1] = 2 * sizeof(unsigned int);
  492. err = reg_read(isight, REG_GAIN_DB_START, &value);
  493. if (err < 0)
  494. return err;
  495. isight->gain_tlv[2] = (s32)be32_to_cpu(value) * 100;
  496. err = reg_read(isight, REG_GAIN_DB_END, &value);
  497. if (err < 0)
  498. return err;
  499. isight->gain_tlv[3] = (s32)be32_to_cpu(value) * 100;
  500. ctl = snd_ctl_new1(&gain_control, isight);
  501. if (ctl)
  502. ctl->tlv.p = isight->gain_tlv;
  503. err = snd_ctl_add(isight->card, ctl);
  504. if (err < 0)
  505. return err;
  506. err = snd_ctl_add(isight->card, snd_ctl_new1(&mute_control, isight));
  507. if (err < 0)
  508. return err;
  509. return 0;
  510. }
  511. static void isight_card_free(struct snd_card *card)
  512. {
  513. struct isight *isight = card->private_data;
  514. fw_iso_resources_destroy(&isight->resources);
  515. fw_unit_put(isight->unit);
  516. fw_device_put(isight->device);
  517. mutex_destroy(&isight->mutex);
  518. }
  519. static u64 get_unit_base(struct fw_unit *unit)
  520. {
  521. struct fw_csr_iterator i;
  522. int key, value;
  523. fw_csr_iterator_init(&i, unit->directory);
  524. while (fw_csr_iterator_next(&i, &key, &value))
  525. if (key == CSR_OFFSET)
  526. return CSR_REGISTER_BASE + value * 4;
  527. return 0;
  528. }
  529. static int isight_probe(struct device *unit_dev)
  530. {
  531. struct fw_unit *unit = fw_unit(unit_dev);
  532. struct fw_device *fw_dev = fw_parent_device(unit);
  533. struct snd_card *card;
  534. struct isight *isight;
  535. int err;
  536. err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*isight), &card);
  537. if (err < 0)
  538. return err;
  539. snd_card_set_dev(card, unit_dev);
  540. isight = card->private_data;
  541. isight->card = card;
  542. mutex_init(&isight->mutex);
  543. isight->unit = fw_unit_get(unit);
  544. isight->device = fw_device_get(fw_dev);
  545. isight->audio_base = get_unit_base(unit);
  546. if (!isight->audio_base) {
  547. dev_err(&unit->device, "audio unit base not found\n");
  548. err = -ENXIO;
  549. goto err_unit;
  550. }
  551. fw_iso_resources_init(&isight->resources, unit);
  552. card->private_free = isight_card_free;
  553. strcpy(card->driver, "iSight");
  554. strcpy(card->shortname, "Apple iSight");
  555. snprintf(card->longname, sizeof(card->longname),
  556. "Apple iSight (GUID %08x%08x) at %s, S%d",
  557. fw_dev->config_rom[3], fw_dev->config_rom[4],
  558. dev_name(&unit->device), 100 << fw_dev->max_speed);
  559. strcpy(card->mixername, "iSight");
  560. err = isight_create_pcm(isight);
  561. if (err < 0)
  562. goto error;
  563. err = isight_create_mixer(isight);
  564. if (err < 0)
  565. goto error;
  566. err = snd_card_register(card);
  567. if (err < 0)
  568. goto error;
  569. dev_set_drvdata(unit_dev, isight);
  570. return 0;
  571. err_unit:
  572. fw_unit_put(isight->unit);
  573. fw_device_put(isight->device);
  574. mutex_destroy(&isight->mutex);
  575. error:
  576. snd_card_free(card);
  577. return err;
  578. }
  579. static int isight_remove(struct device *dev)
  580. {
  581. struct isight *isight = dev_get_drvdata(dev);
  582. isight_pcm_abort(isight);
  583. snd_card_disconnect(isight->card);
  584. mutex_lock(&isight->mutex);
  585. isight_stop_streaming(isight);
  586. mutex_unlock(&isight->mutex);
  587. snd_card_free_when_closed(isight->card);
  588. return 0;
  589. }
  590. static void isight_bus_reset(struct fw_unit *unit)
  591. {
  592. struct isight *isight = dev_get_drvdata(&unit->device);
  593. if (fw_iso_resources_update(&isight->resources) < 0) {
  594. isight_pcm_abort(isight);
  595. mutex_lock(&isight->mutex);
  596. isight_stop_streaming(isight);
  597. mutex_unlock(&isight->mutex);
  598. }
  599. }
  600. static const struct ieee1394_device_id isight_id_table[] = {
  601. {
  602. .match_flags = IEEE1394_MATCH_SPECIFIER_ID |
  603. IEEE1394_MATCH_VERSION,
  604. .specifier_id = OUI_APPLE,
  605. .version = SW_ISIGHT_AUDIO,
  606. },
  607. { }
  608. };
  609. MODULE_DEVICE_TABLE(ieee1394, isight_id_table);
  610. static struct fw_driver isight_driver = {
  611. .driver = {
  612. .owner = THIS_MODULE,
  613. .name = KBUILD_MODNAME,
  614. .bus = &fw_bus_type,
  615. .probe = isight_probe,
  616. .remove = isight_remove,
  617. },
  618. .update = isight_bus_reset,
  619. .id_table = isight_id_table,
  620. };
  621. static int __init alsa_isight_init(void)
  622. {
  623. return driver_register(&isight_driver.driver);
  624. }
  625. static void __exit alsa_isight_exit(void)
  626. {
  627. driver_unregister(&isight_driver.driver);
  628. }
  629. module_init(alsa_isight_init);
  630. module_exit(alsa_isight_exit);