dice.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. /*
  2. * TC Applied Technologies Digital Interface Communications Engine 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 <linux/compat.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/slab.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/wait.h>
  18. #include <sound/control.h>
  19. #include <sound/core.h>
  20. #include <sound/firewire.h>
  21. #include <sound/hwdep.h>
  22. #include <sound/initval.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include "amdtp.h"
  26. #include "iso-resources.h"
  27. #include "lib.h"
  28. #define DICE_PRIVATE_SPACE 0xffffe0000000uLL
  29. /* offset from DICE_PRIVATE_SPACE; offsets and sizes in quadlets */
  30. #define DICE_GLOBAL_OFFSET 0x00
  31. #define DICE_GLOBAL_SIZE 0x04
  32. #define DICE_TX_OFFSET 0x08
  33. #define DICE_TX_SIZE 0x0c
  34. #define DICE_RX_OFFSET 0x10
  35. #define DICE_RX_SIZE 0x14
  36. /* pointed to by DICE_GLOBAL_OFFSET */
  37. #define GLOBAL_OWNER 0x000
  38. #define OWNER_NO_OWNER 0xffff000000000000uLL
  39. #define OWNER_NODE_SHIFT 48
  40. #define GLOBAL_NOTIFICATION 0x008
  41. #define NOTIFY_RX_CFG_CHG 0x00000001
  42. #define NOTIFY_TX_CFG_CHG 0x00000002
  43. #define NOTIFY_DUP_ISOC 0x00000004
  44. #define NOTIFY_BW_ERR 0x00000008
  45. #define NOTIFY_LOCK_CHG 0x00000010
  46. #define NOTIFY_CLOCK_ACCEPTED 0x00000020
  47. #define NOTIFY_INTERFACE_CHG 0x00000040
  48. #define NOTIFY_MESSAGE 0x00100000
  49. #define GLOBAL_NICK_NAME 0x00c
  50. #define NICK_NAME_SIZE 64
  51. #define GLOBAL_CLOCK_SELECT 0x04c
  52. #define CLOCK_SOURCE_MASK 0x000000ff
  53. #define CLOCK_SOURCE_AES1 0x00000000
  54. #define CLOCK_SOURCE_AES2 0x00000001
  55. #define CLOCK_SOURCE_AES3 0x00000002
  56. #define CLOCK_SOURCE_AES4 0x00000003
  57. #define CLOCK_SOURCE_AES_ANY 0x00000004
  58. #define CLOCK_SOURCE_ADAT 0x00000005
  59. #define CLOCK_SOURCE_TDIF 0x00000006
  60. #define CLOCK_SOURCE_WC 0x00000007
  61. #define CLOCK_SOURCE_ARX1 0x00000008
  62. #define CLOCK_SOURCE_ARX2 0x00000009
  63. #define CLOCK_SOURCE_ARX3 0x0000000a
  64. #define CLOCK_SOURCE_ARX4 0x0000000b
  65. #define CLOCK_SOURCE_INTERNAL 0x0000000c
  66. #define CLOCK_RATE_MASK 0x0000ff00
  67. #define CLOCK_RATE_32000 0x00000000
  68. #define CLOCK_RATE_44100 0x00000100
  69. #define CLOCK_RATE_48000 0x00000200
  70. #define CLOCK_RATE_88200 0x00000300
  71. #define CLOCK_RATE_96000 0x00000400
  72. #define CLOCK_RATE_176400 0x00000500
  73. #define CLOCK_RATE_192000 0x00000600
  74. #define CLOCK_RATE_ANY_LOW 0x00000700
  75. #define CLOCK_RATE_ANY_MID 0x00000800
  76. #define CLOCK_RATE_ANY_HIGH 0x00000900
  77. #define CLOCK_RATE_NONE 0x00000a00
  78. #define CLOCK_RATE_SHIFT 8
  79. #define GLOBAL_ENABLE 0x050
  80. #define ENABLE 0x00000001
  81. #define GLOBAL_STATUS 0x054
  82. #define STATUS_SOURCE_LOCKED 0x00000001
  83. #define STATUS_RATE_CONFLICT 0x00000002
  84. #define STATUS_NOMINAL_RATE_MASK 0x0000ff00
  85. #define GLOBAL_EXTENDED_STATUS 0x058
  86. #define EXT_STATUS_AES1_LOCKED 0x00000001
  87. #define EXT_STATUS_AES2_LOCKED 0x00000002
  88. #define EXT_STATUS_AES3_LOCKED 0x00000004
  89. #define EXT_STATUS_AES4_LOCKED 0x00000008
  90. #define EXT_STATUS_ADAT_LOCKED 0x00000010
  91. #define EXT_STATUS_TDIF_LOCKED 0x00000020
  92. #define EXT_STATUS_ARX1_LOCKED 0x00000040
  93. #define EXT_STATUS_ARX2_LOCKED 0x00000080
  94. #define EXT_STATUS_ARX3_LOCKED 0x00000100
  95. #define EXT_STATUS_ARX4_LOCKED 0x00000200
  96. #define EXT_STATUS_WC_LOCKED 0x00000400
  97. #define EXT_STATUS_AES1_SLIP 0x00010000
  98. #define EXT_STATUS_AES2_SLIP 0x00020000
  99. #define EXT_STATUS_AES3_SLIP 0x00040000
  100. #define EXT_STATUS_AES4_SLIP 0x00080000
  101. #define EXT_STATUS_ADAT_SLIP 0x00100000
  102. #define EXT_STATUS_TDIF_SLIP 0x00200000
  103. #define EXT_STATUS_ARX1_SLIP 0x00400000
  104. #define EXT_STATUS_ARX2_SLIP 0x00800000
  105. #define EXT_STATUS_ARX3_SLIP 0x01000000
  106. #define EXT_STATUS_ARX4_SLIP 0x02000000
  107. #define EXT_STATUS_WC_SLIP 0x04000000
  108. #define GLOBAL_SAMPLE_RATE 0x05c
  109. #define GLOBAL_VERSION 0x060
  110. #define GLOBAL_CLOCK_CAPABILITIES 0x064
  111. #define CLOCK_CAP_RATE_32000 0x00000001
  112. #define CLOCK_CAP_RATE_44100 0x00000002
  113. #define CLOCK_CAP_RATE_48000 0x00000004
  114. #define CLOCK_CAP_RATE_88200 0x00000008
  115. #define CLOCK_CAP_RATE_96000 0x00000010
  116. #define CLOCK_CAP_RATE_176400 0x00000020
  117. #define CLOCK_CAP_RATE_192000 0x00000040
  118. #define CLOCK_CAP_SOURCE_AES1 0x00010000
  119. #define CLOCK_CAP_SOURCE_AES2 0x00020000
  120. #define CLOCK_CAP_SOURCE_AES3 0x00040000
  121. #define CLOCK_CAP_SOURCE_AES4 0x00080000
  122. #define CLOCK_CAP_SOURCE_AES_ANY 0x00100000
  123. #define CLOCK_CAP_SOURCE_ADAT 0x00200000
  124. #define CLOCK_CAP_SOURCE_TDIF 0x00400000
  125. #define CLOCK_CAP_SOURCE_WC 0x00800000
  126. #define CLOCK_CAP_SOURCE_ARX1 0x01000000
  127. #define CLOCK_CAP_SOURCE_ARX2 0x02000000
  128. #define CLOCK_CAP_SOURCE_ARX3 0x04000000
  129. #define CLOCK_CAP_SOURCE_ARX4 0x08000000
  130. #define CLOCK_CAP_SOURCE_INTERNAL 0x10000000
  131. #define GLOBAL_CLOCK_SOURCE_NAMES 0x068
  132. #define CLOCK_SOURCE_NAMES_SIZE 256
  133. /* pointed to by DICE_TX_OFFSET */
  134. #define TX_NUMBER 0x000
  135. #define TX_SIZE 0x004
  136. /* repeated TX_NUMBER times, offset by TX_SIZE quadlets */
  137. #define TX_ISOCHRONOUS 0x008
  138. #define TX_NUMBER_AUDIO 0x00c
  139. #define TX_NUMBER_MIDI 0x010
  140. #define TX_SPEED 0x014
  141. #define TX_NAMES 0x018
  142. #define TX_NAMES_SIZE 256
  143. #define TX_AC3_CAPABILITIES 0x118
  144. #define TX_AC3_ENABLE 0x11c
  145. /* pointed to by DICE_RX_OFFSET */
  146. #define RX_NUMBER 0x000
  147. #define RX_SIZE 0x004
  148. /* repeated RX_NUMBER times, offset by RX_SIZE quadlets */
  149. #define RX_ISOCHRONOUS 0x008
  150. #define RX_SEQ_START 0x00c
  151. #define RX_NUMBER_AUDIO 0x010
  152. #define RX_NUMBER_MIDI 0x014
  153. #define RX_NAMES 0x018
  154. #define RX_NAMES_SIZE 256
  155. #define RX_AC3_CAPABILITIES 0x118
  156. #define RX_AC3_ENABLE 0x11c
  157. #define FIRMWARE_LOAD_SPACE 0xffffe0100000uLL
  158. /* offset from FIRMWARE_LOAD_SPACE */
  159. #define FIRMWARE_VERSION 0x000
  160. #define FIRMWARE_OPCODE 0x004
  161. #define OPCODE_MASK 0x00000fff
  162. #define OPCODE_GET_IMAGE_DESC 0x00000000
  163. #define OPCODE_DELETE_IMAGE 0x00000001
  164. #define OPCODE_CREATE_IMAGE 0x00000002
  165. #define OPCODE_UPLOAD 0x00000003
  166. #define OPCODE_UPLOAD_STAT 0x00000004
  167. #define OPCODE_RESET_IMAGE 0x00000005
  168. #define OPCODE_TEST_ACTION 0x00000006
  169. #define OPCODE_GET_RUNNING_IMAGE_VINFO 0x0000000a
  170. #define OPCODE_EXECUTE 0x80000000
  171. #define FIRMWARE_RETURN_STATUS 0x008
  172. #define FIRMWARE_PROGRESS 0x00c
  173. #define PROGRESS_CURR_MASK 0x00000fff
  174. #define PROGRESS_MAX_MASK 0x00fff000
  175. #define PROGRESS_TOUT_MASK 0x0f000000
  176. #define PROGRESS_FLAG 0x80000000
  177. #define FIRMWARE_CAPABILITIES 0x010
  178. #define FL_CAP_AUTOERASE 0x00000001
  179. #define FL_CAP_PROGRESS 0x00000002
  180. #define FIRMWARE_DATA 0x02c
  181. #define TEST_CMD_POKE 0x00000001
  182. #define TEST_CMD_PEEK 0x00000002
  183. #define CMD_GET_AVS_CNT 0x00000003
  184. #define CMD_CLR_AVS_CNT 0x00000004
  185. #define CMD_SET_MODE 0x00000005
  186. #define CMD_SET_MIDIBP 0x00000006
  187. #define CMD_GET_AVSPHASE 0x00000007
  188. #define CMD_ENABLE_BNC_SYNC 0x00000008
  189. #define CMD_PULSE_BNC_SYNC 0x00000009
  190. #define CMD_EMUL_SLOW_CMD 0x0000000a
  191. #define FIRMWARE_TEST_DELAY 0xfd8
  192. #define FIRMWARE_TEST_BUF 0xfdc
  193. /* EAP */
  194. #define EAP_PRIVATE_SPACE 0xffffe0200000uLL
  195. #define EAP_CAPABILITY_OFFSET 0x000
  196. #define EAP_CAPABILITY_SIZE 0x004
  197. /* ... */
  198. #define EAP_ROUTER_CAPS 0x000
  199. #define ROUTER_EXPOSED 0x00000001
  200. #define ROUTER_READ_ONLY 0x00000002
  201. #define ROUTER_FLASH 0x00000004
  202. #define MAX_ROUTES_MASK 0xffff0000
  203. #define EAP_MIXER_CAPS 0x004
  204. #define MIXER_EXPOSED 0x00000001
  205. #define MIXER_READ_ONLY 0x00000002
  206. #define MIXER_FLASH 0x00000004
  207. #define MIXER_IN_DEV_MASK 0x000000f0
  208. #define MIXER_OUT_DEV_MASK 0x00000f00
  209. #define MIXER_INPUTS_MASK 0x00ff0000
  210. #define MIXER_OUTPUTS_MASK 0xff000000
  211. #define EAP_GENERAL_CAPS 0x008
  212. #define GENERAL_STREAM_CONFIG 0x00000001
  213. #define GENERAL_FLASH 0x00000002
  214. #define GENERAL_PEAK 0x00000004
  215. #define GENERAL_MAX_TX_STREAMS_MASK 0x000000f0
  216. #define GENERAL_MAX_RX_STREAMS_MASK 0x00000f00
  217. #define GENERAL_STREAM_CONFIG_FLASH 0x00001000
  218. #define GENERAL_CHIP_MASK 0x00ff0000
  219. #define GENERAL_CHIP_DICE_II 0x00000000
  220. #define GENERAL_CHIP_DICE_MINI 0x00010000
  221. #define GENERAL_CHIP_DICE_JR 0x00020000
  222. struct dice {
  223. struct snd_card *card;
  224. struct fw_unit *unit;
  225. spinlock_t lock;
  226. struct mutex mutex;
  227. unsigned int global_offset;
  228. unsigned int rx_offset;
  229. struct fw_address_handler notification_handler;
  230. int owner_generation;
  231. int dev_lock_count; /* > 0 driver, < 0 userspace */
  232. bool dev_lock_changed;
  233. bool global_enabled;
  234. wait_queue_head_t hwdep_wait;
  235. u32 notification_bits;
  236. struct snd_pcm_substream *pcm;
  237. struct fw_iso_resources resources;
  238. struct amdtp_out_stream stream;
  239. };
  240. MODULE_DESCRIPTION("DICE driver");
  241. MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  242. MODULE_LICENSE("GPL v2");
  243. static const unsigned int dice_rates[] = {
  244. [0] = 32000,
  245. [1] = 44100,
  246. [2] = 48000,
  247. [3] = 88200,
  248. [4] = 96000,
  249. [5] = 176400,
  250. [6] = 192000,
  251. };
  252. static void dice_lock_changed(struct dice *dice)
  253. {
  254. dice->dev_lock_changed = true;
  255. wake_up(&dice->hwdep_wait);
  256. }
  257. static int dice_try_lock(struct dice *dice)
  258. {
  259. int err;
  260. spin_lock_irq(&dice->lock);
  261. if (dice->dev_lock_count < 0) {
  262. err = -EBUSY;
  263. goto out;
  264. }
  265. if (dice->dev_lock_count++ == 0)
  266. dice_lock_changed(dice);
  267. err = 0;
  268. out:
  269. spin_unlock_irq(&dice->lock);
  270. return err;
  271. }
  272. static void dice_unlock(struct dice *dice)
  273. {
  274. spin_lock_irq(&dice->lock);
  275. if (WARN_ON(dice->dev_lock_count <= 0))
  276. goto out;
  277. if (--dice->dev_lock_count == 0)
  278. dice_lock_changed(dice);
  279. out:
  280. spin_unlock_irq(&dice->lock);
  281. }
  282. static inline u64 global_address(struct dice *dice, unsigned int offset)
  283. {
  284. return DICE_PRIVATE_SPACE + dice->global_offset + offset;
  285. }
  286. // TODO: rx index
  287. static inline u64 rx_address(struct dice *dice, unsigned int offset)
  288. {
  289. return DICE_PRIVATE_SPACE + dice->rx_offset + offset;
  290. }
  291. static int dice_owner_set(struct dice *dice)
  292. {
  293. struct fw_device *device = fw_parent_device(dice->unit);
  294. __be64 *buffer;
  295. int rcode, err, errors = 0;
  296. buffer = kmalloc(2 * 8, GFP_KERNEL);
  297. if (!buffer)
  298. return -ENOMEM;
  299. for (;;) {
  300. buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
  301. buffer[1] = cpu_to_be64(
  302. ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
  303. dice->notification_handler.offset);
  304. dice->owner_generation = device->generation;
  305. smp_rmb(); /* node_id vs. generation */
  306. rcode = fw_run_transaction(device->card,
  307. TCODE_LOCK_COMPARE_SWAP,
  308. device->node_id,
  309. dice->owner_generation,
  310. device->max_speed,
  311. global_address(dice, GLOBAL_OWNER),
  312. buffer, 2 * 8);
  313. if (rcode == RCODE_COMPLETE) {
  314. if (buffer[0] == cpu_to_be64(OWNER_NO_OWNER)) {
  315. err = 0;
  316. } else {
  317. dev_err(&dice->unit->device,
  318. "device is already in use\n");
  319. err = -EBUSY;
  320. }
  321. break;
  322. }
  323. if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
  324. dev_err(&dice->unit->device,
  325. "setting device owner failed: %s\n",
  326. fw_rcode_string(rcode));
  327. err = -EIO;
  328. break;
  329. }
  330. msleep(20);
  331. }
  332. kfree(buffer);
  333. return err;
  334. }
  335. static int dice_owner_update(struct dice *dice)
  336. {
  337. struct fw_device *device = fw_parent_device(dice->unit);
  338. __be64 *buffer;
  339. int rcode, err, errors = 0;
  340. if (dice->owner_generation == -1)
  341. return 0;
  342. buffer = kmalloc(2 * 8, GFP_KERNEL);
  343. if (!buffer)
  344. return -ENOMEM;
  345. for (;;) {
  346. buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
  347. buffer[1] = cpu_to_be64(
  348. ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
  349. dice->notification_handler.offset);
  350. dice->owner_generation = device->generation;
  351. smp_rmb(); /* node_id vs. generation */
  352. rcode = fw_run_transaction(device->card,
  353. TCODE_LOCK_COMPARE_SWAP,
  354. device->node_id,
  355. dice->owner_generation,
  356. device->max_speed,
  357. global_address(dice, GLOBAL_OWNER),
  358. buffer, 2 * 8);
  359. if (rcode == RCODE_COMPLETE) {
  360. if (buffer[0] == cpu_to_be64(OWNER_NO_OWNER)) {
  361. err = 0;
  362. } else {
  363. dev_err(&dice->unit->device,
  364. "device is already in use\n");
  365. err = -EBUSY;
  366. }
  367. break;
  368. }
  369. if (rcode == RCODE_GENERATION) {
  370. err = 0; /* try again later */
  371. break;
  372. }
  373. if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
  374. dev_err(&dice->unit->device,
  375. "setting device owner failed: %s\n",
  376. fw_rcode_string(rcode));
  377. err = -EIO;
  378. break;
  379. }
  380. msleep(20);
  381. }
  382. kfree(buffer);
  383. if (err < 0)
  384. dice->owner_generation = -1;
  385. return err;
  386. }
  387. static void dice_owner_clear(struct dice *dice)
  388. {
  389. struct fw_device *device = fw_parent_device(dice->unit);
  390. __be64 *buffer;
  391. int rcode, errors = 0;
  392. buffer = kmalloc(2 * 8, GFP_KERNEL);
  393. if (!buffer)
  394. return;
  395. for (;;) {
  396. buffer[0] = cpu_to_be64(
  397. ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
  398. dice->notification_handler.offset);
  399. buffer[1] = cpu_to_be64(OWNER_NO_OWNER);
  400. rcode = fw_run_transaction(device->card,
  401. TCODE_LOCK_COMPARE_SWAP,
  402. device->node_id,
  403. dice->owner_generation,
  404. device->max_speed,
  405. global_address(dice, GLOBAL_OWNER),
  406. buffer, 2 * 8);
  407. if (rcode == RCODE_COMPLETE)
  408. break;
  409. if (rcode == RCODE_GENERATION)
  410. break;
  411. if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
  412. dev_err(&dice->unit->device,
  413. "clearing device owner failed: %s\n",
  414. fw_rcode_string(rcode));
  415. break;
  416. }
  417. msleep(20);
  418. }
  419. kfree(buffer);
  420. dice->owner_generation = -1;
  421. }
  422. static int dice_enable_set(struct dice *dice)
  423. {
  424. struct fw_device *device = fw_parent_device(dice->unit);
  425. __be32 value;
  426. int rcode, err, errors = 0;
  427. value = cpu_to_be32(ENABLE);
  428. for (;;) {
  429. rcode = fw_run_transaction(device->card,
  430. TCODE_WRITE_QUADLET_REQUEST,
  431. device->node_id,
  432. dice->owner_generation,
  433. device->max_speed,
  434. global_address(dice, GLOBAL_ENABLE),
  435. &value, 4);
  436. if (rcode == RCODE_COMPLETE) {
  437. dice->global_enabled = true;
  438. err = 0;
  439. break;
  440. }
  441. if (rcode == RCODE_GENERATION) {
  442. err = -EAGAIN;
  443. break;
  444. }
  445. if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
  446. dev_err(&dice->unit->device,
  447. "device enabling failed: %s\n",
  448. fw_rcode_string(rcode));
  449. err = -EIO;
  450. break;
  451. }
  452. msleep(20);
  453. }
  454. return err;
  455. }
  456. static void dice_enable_clear(struct dice *dice)
  457. {
  458. struct fw_device *device = fw_parent_device(dice->unit);
  459. __be32 value;
  460. int rcode, errors = 0;
  461. value = 0;
  462. for (;;) {
  463. rcode = fw_run_transaction(device->card,
  464. TCODE_WRITE_QUADLET_REQUEST,
  465. device->node_id,
  466. dice->owner_generation,
  467. device->max_speed,
  468. global_address(dice, GLOBAL_ENABLE),
  469. &value, 4);
  470. if (rcode == RCODE_COMPLETE ||
  471. rcode == RCODE_GENERATION)
  472. break;
  473. if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
  474. dev_err(&dice->unit->device,
  475. "device disabling failed: %s\n",
  476. fw_rcode_string(rcode));
  477. break;
  478. }
  479. msleep(20);
  480. }
  481. dice->global_enabled = false;
  482. }
  483. static void dice_notification(struct fw_card *card, struct fw_request *request,
  484. int tcode, int destination, int source,
  485. int generation, unsigned long long offset,
  486. void *data, size_t length, void *callback_data)
  487. {
  488. struct dice *dice = callback_data;
  489. unsigned long flags;
  490. if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
  491. fw_send_response(card, request, RCODE_TYPE_ERROR);
  492. return;
  493. }
  494. if ((offset & 3) != 0) {
  495. fw_send_response(card, request, RCODE_ADDRESS_ERROR);
  496. return;
  497. }
  498. spin_lock_irqsave(&dice->lock, flags);
  499. dice->notification_bits |= be32_to_cpup(data);
  500. spin_unlock_irqrestore(&dice->lock, flags);
  501. fw_send_response(card, request, RCODE_COMPLETE);
  502. wake_up(&dice->hwdep_wait);
  503. }
  504. static int dice_open(struct snd_pcm_substream *substream)
  505. {
  506. static const struct snd_pcm_hardware hardware = {
  507. .info = SNDRV_PCM_INFO_MMAP |
  508. SNDRV_PCM_INFO_MMAP_VALID |
  509. SNDRV_PCM_INFO_BATCH |
  510. SNDRV_PCM_INFO_INTERLEAVED |
  511. SNDRV_PCM_INFO_BLOCK_TRANSFER,
  512. .formats = AMDTP_OUT_PCM_FORMAT_BITS,
  513. .buffer_bytes_max = 16 * 1024 * 1024,
  514. .period_bytes_min = 1,
  515. .period_bytes_max = UINT_MAX,
  516. .periods_min = 1,
  517. .periods_max = UINT_MAX,
  518. };
  519. struct dice *dice = substream->private_data;
  520. struct snd_pcm_runtime *runtime = substream->runtime;
  521. __be32 clock_sel, number_audio, number_midi;
  522. unsigned int rate;
  523. int err;
  524. err = dice_try_lock(dice);
  525. if (err < 0)
  526. goto error;
  527. err = snd_fw_transaction(dice->unit, TCODE_READ_QUADLET_REQUEST,
  528. global_address(dice, GLOBAL_CLOCK_SELECT),
  529. &clock_sel, 4);
  530. if (err < 0)
  531. goto err_lock;
  532. rate = (be32_to_cpu(clock_sel) & CLOCK_RATE_MASK) >> CLOCK_RATE_SHIFT;
  533. if (rate >= ARRAY_SIZE(dice_rates)) {
  534. err = -ENXIO;
  535. goto err_lock;
  536. }
  537. rate = dice_rates[rate];
  538. err = snd_fw_transaction(dice->unit, TCODE_READ_QUADLET_REQUEST,
  539. rx_address(dice, RX_NUMBER_AUDIO),
  540. &number_audio, 4);
  541. if (err < 0)
  542. goto err_lock;
  543. err = snd_fw_transaction(dice->unit, TCODE_READ_QUADLET_REQUEST,
  544. rx_address(dice, RX_NUMBER_MIDI),
  545. &number_midi, 4);
  546. if (err < 0)
  547. goto err_lock;
  548. runtime->hw = hardware;
  549. runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
  550. snd_pcm_limit_hw_rates(runtime);
  551. runtime->hw.channels_min = be32_to_cpu(number_audio);
  552. runtime->hw.channels_max = be32_to_cpu(number_audio);
  553. amdtp_out_stream_set_rate(&dice->stream, rate);
  554. amdtp_out_stream_set_pcm(&dice->stream, be32_to_cpu(number_audio));
  555. amdtp_out_stream_set_midi(&dice->stream, be32_to_cpu(number_midi));
  556. err = snd_pcm_hw_constraint_minmax(runtime,
  557. SNDRV_PCM_HW_PARAM_PERIOD_TIME,
  558. 5000, 8192000);
  559. if (err < 0)
  560. goto err_lock;
  561. err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  562. if (err < 0)
  563. goto err_lock;
  564. return 0;
  565. err_lock:
  566. dice_unlock(dice);
  567. error:
  568. return err;
  569. }
  570. static int dice_close(struct snd_pcm_substream *substream)
  571. {
  572. struct dice *dice = substream->private_data;
  573. dice_unlock(dice);
  574. return 0;
  575. }
  576. static int dice_stream_start_packets(struct dice *dice)
  577. {
  578. int err;
  579. if (amdtp_out_stream_running(&dice->stream))
  580. return 0;
  581. err = amdtp_out_stream_start(&dice->stream, dice->resources.channel,
  582. fw_parent_device(dice->unit)->max_speed);
  583. if (err < 0)
  584. return err;
  585. err = dice_enable_set(dice);
  586. if (err < 0) {
  587. amdtp_out_stream_stop(&dice->stream);
  588. return err;
  589. }
  590. return 0;
  591. }
  592. static int dice_stream_start(struct dice *dice)
  593. {
  594. __be32 channel;
  595. int err;
  596. if (!dice->resources.allocated) {
  597. err = fw_iso_resources_allocate(&dice->resources,
  598. amdtp_out_stream_get_max_payload(&dice->stream),
  599. fw_parent_device(dice->unit)->max_speed);
  600. if (err < 0)
  601. goto error;
  602. channel = cpu_to_be32(dice->resources.channel);
  603. err = snd_fw_transaction(dice->unit,
  604. TCODE_WRITE_QUADLET_REQUEST,
  605. rx_address(dice, RX_ISOCHRONOUS),
  606. &channel, 4);
  607. if (err < 0)
  608. goto err_resources;
  609. }
  610. err = dice_stream_start_packets(dice);
  611. if (err < 0)
  612. goto err_rx_channel;
  613. return 0;
  614. err_rx_channel:
  615. channel = cpu_to_be32((u32)-1);
  616. snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
  617. rx_address(dice, RX_ISOCHRONOUS), &channel, 4);
  618. err_resources:
  619. fw_iso_resources_free(&dice->resources);
  620. error:
  621. return err;
  622. }
  623. static void dice_stream_stop_packets(struct dice *dice)
  624. {
  625. if (amdtp_out_stream_running(&dice->stream)) {
  626. dice_enable_clear(dice);
  627. amdtp_out_stream_stop(&dice->stream);
  628. }
  629. }
  630. static void dice_stream_stop(struct dice *dice)
  631. {
  632. __be32 channel;
  633. dice_stream_stop_packets(dice);
  634. if (!dice->resources.allocated)
  635. return;
  636. channel = cpu_to_be32((u32)-1);
  637. snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
  638. rx_address(dice, RX_ISOCHRONOUS), &channel, 4);
  639. fw_iso_resources_free(&dice->resources);
  640. }
  641. static int dice_hw_params(struct snd_pcm_substream *substream,
  642. struct snd_pcm_hw_params *hw_params)
  643. {
  644. struct dice *dice = substream->private_data;
  645. int err;
  646. mutex_lock(&dice->mutex);
  647. dice_stream_stop(dice);
  648. mutex_unlock(&dice->mutex);
  649. err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
  650. params_buffer_bytes(hw_params));
  651. if (err < 0)
  652. goto error;
  653. amdtp_out_stream_set_pcm_format(&dice->stream,
  654. params_format(hw_params));
  655. return 0;
  656. error:
  657. return err;
  658. }
  659. static int dice_hw_free(struct snd_pcm_substream *substream)
  660. {
  661. struct dice *dice = substream->private_data;
  662. mutex_lock(&dice->mutex);
  663. dice_stream_stop(dice);
  664. mutex_unlock(&dice->mutex);
  665. return snd_pcm_lib_free_vmalloc_buffer(substream);
  666. }
  667. static int dice_prepare(struct snd_pcm_substream *substream)
  668. {
  669. struct dice *dice = substream->private_data;
  670. int err;
  671. mutex_lock(&dice->mutex);
  672. if (amdtp_out_streaming_error(&dice->stream))
  673. dice_stream_stop_packets(dice);
  674. err = dice_stream_start(dice);
  675. if (err < 0) {
  676. mutex_unlock(&dice->mutex);
  677. return err;
  678. }
  679. mutex_unlock(&dice->mutex);
  680. amdtp_out_stream_pcm_prepare(&dice->stream);
  681. return 0;
  682. }
  683. static int dice_trigger(struct snd_pcm_substream *substream, int cmd)
  684. {
  685. struct dice *dice = substream->private_data;
  686. struct snd_pcm_substream *pcm;
  687. switch (cmd) {
  688. case SNDRV_PCM_TRIGGER_START:
  689. pcm = substream;
  690. break;
  691. case SNDRV_PCM_TRIGGER_STOP:
  692. pcm = NULL;
  693. break;
  694. default:
  695. return -EINVAL;
  696. }
  697. amdtp_out_stream_pcm_trigger(&dice->stream, pcm);
  698. return 0;
  699. }
  700. static snd_pcm_uframes_t dice_pointer(struct snd_pcm_substream *substream)
  701. {
  702. struct dice *dice = substream->private_data;
  703. return amdtp_out_stream_pcm_pointer(&dice->stream);
  704. }
  705. static int dice_create_pcm(struct dice *dice)
  706. {
  707. static struct snd_pcm_ops ops = {
  708. .open = dice_open,
  709. .close = dice_close,
  710. .ioctl = snd_pcm_lib_ioctl,
  711. .hw_params = dice_hw_params,
  712. .hw_free = dice_hw_free,
  713. .prepare = dice_prepare,
  714. .trigger = dice_trigger,
  715. .pointer = dice_pointer,
  716. .page = snd_pcm_lib_get_vmalloc_page,
  717. .mmap = snd_pcm_lib_mmap_vmalloc,
  718. };
  719. struct snd_pcm *pcm;
  720. int err;
  721. err = snd_pcm_new(dice->card, "DICE", 0, 1, 0, &pcm);
  722. if (err < 0)
  723. return err;
  724. pcm->private_data = dice;
  725. strcpy(pcm->name, dice->card->shortname);
  726. dice->pcm = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  727. dice->pcm->ops = &ops;
  728. return 0;
  729. }
  730. static long dice_hwdep_read(struct snd_hwdep *hwdep, char __user *buf,
  731. long count, loff_t *offset)
  732. {
  733. struct dice *dice = hwdep->private_data;
  734. DEFINE_WAIT(wait);
  735. union snd_firewire_event event;
  736. spin_lock_irq(&dice->lock);
  737. while (!dice->dev_lock_changed && dice->notification_bits == 0) {
  738. prepare_to_wait(&dice->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
  739. spin_unlock_irq(&dice->lock);
  740. schedule();
  741. finish_wait(&dice->hwdep_wait, &wait);
  742. if (signal_pending(current))
  743. return -ERESTARTSYS;
  744. spin_lock_irq(&dice->lock);
  745. }
  746. memset(&event, 0, sizeof(event));
  747. if (dice->dev_lock_changed) {
  748. event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
  749. event.lock_status.status = dice->dev_lock_count > 0;
  750. dice->dev_lock_changed = false;
  751. count = min(count, (long)sizeof(event.lock_status));
  752. } else {
  753. event.dice_notification.type = SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION;
  754. event.dice_notification.notification = dice->notification_bits;
  755. dice->notification_bits = 0;
  756. count = min(count, (long)sizeof(event.dice_notification));
  757. }
  758. spin_unlock_irq(&dice->lock);
  759. if (copy_to_user(buf, &event, count))
  760. return -EFAULT;
  761. return count;
  762. }
  763. static unsigned int dice_hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
  764. poll_table *wait)
  765. {
  766. struct dice *dice = hwdep->private_data;
  767. unsigned int events;
  768. poll_wait(file, &dice->hwdep_wait, wait);
  769. spin_lock_irq(&dice->lock);
  770. if (dice->dev_lock_changed || dice->notification_bits != 0)
  771. events = POLLIN | POLLRDNORM;
  772. else
  773. events = 0;
  774. spin_unlock_irq(&dice->lock);
  775. return events;
  776. }
  777. static int dice_hwdep_get_info(struct dice *dice, void __user *arg)
  778. {
  779. struct fw_device *dev = fw_parent_device(dice->unit);
  780. struct snd_firewire_get_info info;
  781. memset(&info, 0, sizeof(info));
  782. info.type = SNDRV_FIREWIRE_TYPE_DICE;
  783. info.card = dev->card->index;
  784. *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
  785. *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
  786. strlcpy(info.device_name, dev_name(&dev->device),
  787. sizeof(info.device_name));
  788. if (copy_to_user(arg, &info, sizeof(info)))
  789. return -EFAULT;
  790. return 0;
  791. }
  792. static int dice_hwdep_lock(struct dice *dice)
  793. {
  794. int err;
  795. spin_lock_irq(&dice->lock);
  796. if (dice->dev_lock_count == 0) {
  797. dice->dev_lock_count = -1;
  798. err = 0;
  799. } else {
  800. err = -EBUSY;
  801. }
  802. spin_unlock_irq(&dice->lock);
  803. return err;
  804. }
  805. static int dice_hwdep_unlock(struct dice *dice)
  806. {
  807. int err;
  808. spin_lock_irq(&dice->lock);
  809. if (dice->dev_lock_count == -1) {
  810. dice->dev_lock_count = 0;
  811. err = 0;
  812. } else {
  813. err = -EBADFD;
  814. }
  815. spin_unlock_irq(&dice->lock);
  816. return err;
  817. }
  818. static int dice_hwdep_release(struct snd_hwdep *hwdep, struct file *file)
  819. {
  820. struct dice *dice = hwdep->private_data;
  821. spin_lock_irq(&dice->lock);
  822. if (dice->dev_lock_count == -1)
  823. dice->dev_lock_count = 0;
  824. spin_unlock_irq(&dice->lock);
  825. return 0;
  826. }
  827. static int dice_hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
  828. unsigned int cmd, unsigned long arg)
  829. {
  830. struct dice *dice = hwdep->private_data;
  831. switch (cmd) {
  832. case SNDRV_FIREWIRE_IOCTL_GET_INFO:
  833. return dice_hwdep_get_info(dice, (void __user *)arg);
  834. case SNDRV_FIREWIRE_IOCTL_LOCK:
  835. return dice_hwdep_lock(dice);
  836. case SNDRV_FIREWIRE_IOCTL_UNLOCK:
  837. return dice_hwdep_unlock(dice);
  838. default:
  839. return -ENOIOCTLCMD;
  840. }
  841. }
  842. #ifdef CONFIG_COMPAT
  843. static int dice_hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
  844. unsigned int cmd, unsigned long arg)
  845. {
  846. return dice_hwdep_ioctl(hwdep, file, cmd,
  847. (unsigned long)compat_ptr(arg));
  848. }
  849. #else
  850. #define dice_hwdep_compat_ioctl NULL
  851. #endif
  852. static int dice_create_hwdep(struct dice *dice)
  853. {
  854. static const struct snd_hwdep_ops ops = {
  855. .read = dice_hwdep_read,
  856. .release = dice_hwdep_release,
  857. .poll = dice_hwdep_poll,
  858. .ioctl = dice_hwdep_ioctl,
  859. .ioctl_compat = dice_hwdep_compat_ioctl,
  860. };
  861. struct snd_hwdep *hwdep;
  862. int err;
  863. err = snd_hwdep_new(dice->card, "DICE", 0, &hwdep);
  864. if (err < 0)
  865. return err;
  866. strcpy(hwdep->name, "DICE");
  867. hwdep->iface = SNDRV_HWDEP_IFACE_FW_DICE;
  868. hwdep->ops = ops;
  869. hwdep->private_data = dice;
  870. hwdep->exclusive = true;
  871. return 0;
  872. }
  873. static void dice_card_free(struct snd_card *card)
  874. {
  875. struct dice *dice = card->private_data;
  876. amdtp_out_stream_destroy(&dice->stream);
  877. fw_core_remove_address_handler(&dice->notification_handler);
  878. mutex_destroy(&dice->mutex);
  879. }
  880. static int dice_init_offsets(struct dice *dice)
  881. {
  882. __be32 pointers[6];
  883. unsigned int global_size, rx_size;
  884. int err;
  885. err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
  886. DICE_PRIVATE_SPACE, &pointers, 6 * 4);
  887. if (err < 0)
  888. return err;
  889. dice->global_offset = be32_to_cpu(pointers[0]) * 4;
  890. global_size = be32_to_cpu(pointers[1]);
  891. dice->rx_offset = be32_to_cpu(pointers[4]) * 4;
  892. rx_size = be32_to_cpu(pointers[5]);
  893. /* some sanity checks to ensure that we actually have a DICE */
  894. if (dice->global_offset < 10 * 4 || global_size < 0x168 / 4 ||
  895. dice->rx_offset < 10 * 4 || rx_size < 0x120 / 4) {
  896. dev_err(&dice->unit->device, "invalid register pointers\n");
  897. return -ENXIO;
  898. }
  899. return 0;
  900. }
  901. static void dice_card_strings(struct dice *dice)
  902. {
  903. struct snd_card *card = dice->card;
  904. struct fw_device *dev = fw_parent_device(dice->unit);
  905. char vendor[32], model[32];
  906. unsigned int i;
  907. int err;
  908. strcpy(card->driver, "DICE");
  909. strcpy(card->shortname, "DICE");
  910. BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
  911. err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
  912. global_address(dice, GLOBAL_NICK_NAME),
  913. card->shortname, sizeof(card->shortname));
  914. if (err >= 0) {
  915. /* DICE strings are returned in "always-wrong" endianness */
  916. BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
  917. for (i = 0; i < sizeof(card->shortname); i += 4)
  918. swab32s((u32 *)&card->shortname[i]);
  919. card->shortname[sizeof(card->shortname) - 1] = '\0';
  920. }
  921. strcpy(vendor, "?");
  922. fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
  923. strcpy(model, "?");
  924. fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
  925. snprintf(card->longname, sizeof(card->longname),
  926. "%s %s, GUID %08x%08x at %s, S%d",
  927. vendor, model, dev->config_rom[3], dev->config_rom[4],
  928. dev_name(&dice->unit->device), 100 << dev->max_speed);
  929. strcpy(card->mixername, "DICE");
  930. }
  931. static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
  932. {
  933. struct snd_card *card;
  934. struct dice *dice;
  935. __be32 clock_sel;
  936. int err;
  937. err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*dice), &card);
  938. if (err < 0)
  939. return err;
  940. snd_card_set_dev(card, &unit->device);
  941. dice = card->private_data;
  942. dice->card = card;
  943. spin_lock_init(&dice->lock);
  944. mutex_init(&dice->mutex);
  945. dice->unit = unit;
  946. init_waitqueue_head(&dice->hwdep_wait);
  947. err = dice_init_offsets(dice);
  948. if (err < 0)
  949. goto err_mutex;
  950. dice->notification_handler.length = 4;
  951. dice->notification_handler.address_callback = dice_notification;
  952. dice->notification_handler.callback_data = dice;
  953. err = fw_core_add_address_handler(&dice->notification_handler,
  954. &fw_high_memory_region);
  955. if (err < 0)
  956. goto err_mutex;
  957. err = fw_iso_resources_init(&dice->resources, unit);
  958. if (err < 0)
  959. goto err_notification_handler;
  960. dice->resources.channels_mask = 0x00000000ffffffffuLL;
  961. err = amdtp_out_stream_init(&dice->stream, unit, CIP_BLOCKING);
  962. if (err < 0)
  963. goto err_resources;
  964. err = dice_owner_set(dice);
  965. if (err < 0)
  966. goto err_stream;
  967. card->private_free = dice_card_free;
  968. dice_card_strings(dice);
  969. err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
  970. global_address(dice, GLOBAL_CLOCK_SELECT),
  971. &clock_sel, 4);
  972. if (err < 0)
  973. goto error;
  974. clock_sel &= cpu_to_be32(~CLOCK_SOURCE_MASK);
  975. clock_sel |= cpu_to_be32(CLOCK_SOURCE_ARX1);
  976. err = snd_fw_transaction(unit, TCODE_WRITE_QUADLET_REQUEST,
  977. global_address(dice, GLOBAL_CLOCK_SELECT),
  978. &clock_sel, 4);
  979. if (err < 0)
  980. goto error;
  981. err = dice_create_pcm(dice);
  982. if (err < 0)
  983. goto error;
  984. err = dice_create_hwdep(dice);
  985. if (err < 0)
  986. goto error;
  987. err = snd_card_register(card);
  988. if (err < 0)
  989. goto error;
  990. dev_set_drvdata(&unit->device, dice);
  991. return 0;
  992. err_stream:
  993. amdtp_out_stream_destroy(&dice->stream);
  994. err_resources:
  995. fw_iso_resources_destroy(&dice->resources);
  996. err_notification_handler:
  997. fw_core_remove_address_handler(&dice->notification_handler);
  998. err_mutex:
  999. mutex_destroy(&dice->mutex);
  1000. error:
  1001. snd_card_free(card);
  1002. return err;
  1003. }
  1004. static void dice_remove(struct fw_unit *unit)
  1005. {
  1006. struct dice *dice = dev_get_drvdata(&unit->device);
  1007. mutex_lock(&dice->mutex);
  1008. amdtp_out_stream_pcm_abort(&dice->stream);
  1009. snd_card_disconnect(dice->card);
  1010. dice_stream_stop(dice);
  1011. dice_owner_clear(dice);
  1012. mutex_unlock(&dice->mutex);
  1013. snd_card_free_when_closed(dice->card);
  1014. }
  1015. static void dice_bus_reset(struct fw_unit *unit)
  1016. {
  1017. struct dice *dice = dev_get_drvdata(&unit->device);
  1018. mutex_lock(&dice->mutex);
  1019. /*
  1020. * On a bus reset, the DICE firmware disables streaming and then goes
  1021. * off contemplating its own navel for hundreds of milliseconds before
  1022. * it can react to any of our attempts to reenable streaming. This
  1023. * means that we lose synchronization anyway, so we force our streams
  1024. * to stop so that the application can restart them in an orderly
  1025. * manner.
  1026. */
  1027. amdtp_out_stream_pcm_abort(&dice->stream);
  1028. dice_stream_stop_packets(dice);
  1029. dice_owner_update(dice);
  1030. fw_iso_resources_update(&dice->resources);
  1031. mutex_unlock(&dice->mutex);
  1032. }
  1033. #define TC_OUI 0x000166
  1034. #define DICE_INTERFACE 0x000001
  1035. static const struct ieee1394_device_id dice_id_table[] = {
  1036. {
  1037. .match_flags = IEEE1394_MATCH_SPECIFIER_ID |
  1038. IEEE1394_MATCH_VERSION,
  1039. .specifier_id = TC_OUI,
  1040. .version = DICE_INTERFACE,
  1041. },
  1042. { }
  1043. };
  1044. MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
  1045. static struct fw_driver dice_driver = {
  1046. .driver = {
  1047. .owner = THIS_MODULE,
  1048. .name = KBUILD_MODNAME,
  1049. .bus = &fw_bus_type,
  1050. },
  1051. .probe = dice_probe,
  1052. .update = dice_bus_reset,
  1053. .remove = dice_remove,
  1054. .id_table = dice_id_table,
  1055. };
  1056. static int __init alsa_dice_init(void)
  1057. {
  1058. return driver_register(&dice_driver.driver);
  1059. }
  1060. static void __exit alsa_dice_exit(void)
  1061. {
  1062. driver_unregister(&dice_driver.driver);
  1063. }
  1064. module_init(alsa_dice_init);
  1065. module_exit(alsa_dice_exit);