diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /sound/firewire | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'sound/firewire')
-rw-r--r-- | sound/firewire/Kconfig | 13 | ||||
-rw-r--r-- | sound/firewire/Makefile | 2 | ||||
-rw-r--r-- | sound/firewire/amdtp.c | 49 | ||||
-rw-r--r-- | sound/firewire/amdtp.h | 29 | ||||
-rw-r--r-- | sound/firewire/cmp.c | 4 | ||||
-rw-r--r-- | sound/firewire/isight.c | 5 | ||||
-rw-r--r-- | sound/firewire/iso-resources.c | 1 | ||||
-rw-r--r-- | sound/firewire/lib.c | 28 | ||||
-rw-r--r-- | sound/firewire/lib.h | 1 | ||||
-rw-r--r-- | sound/firewire/packets-buffer.c | 1 | ||||
-rw-r--r-- | sound/firewire/scs1x.c | 527 | ||||
-rw-r--r-- | sound/firewire/speakers.c | 17 |
12 files changed, 69 insertions, 608 deletions
diff --git a/sound/firewire/Kconfig b/sound/firewire/Kconfig index ea063e1f872..26071489970 100644 --- a/sound/firewire/Kconfig +++ b/sound/firewire/Kconfig | |||
@@ -33,17 +33,4 @@ config SND_ISIGHT | |||
33 | To compile this driver as a module, choose M here: the module | 33 | To compile this driver as a module, choose M here: the module |
34 | will be called snd-isight. | 34 | will be called snd-isight. |
35 | 35 | ||
36 | config SND_SCS1X | ||
37 | tristate "Stanton Control System 1 MIDI" | ||
38 | select SND_PCM | ||
39 | select SND_RAWMIDI | ||
40 | select SND_FIREWIRE_LIB | ||
41 | help | ||
42 | Say Y here to include support for the MIDI ports of the Stanton | ||
43 | SCS.1d/SCS.1m DJ controllers. (SCS.1m audio is still handled | ||
44 | by FFADO.) | ||
45 | |||
46 | To compile this driver as a module, choose M here: the module | ||
47 | will be called snd-scs1x. | ||
48 | |||
49 | endif # SND_FIREWIRE | 36 | endif # SND_FIREWIRE |
diff --git a/sound/firewire/Makefile b/sound/firewire/Makefile index 460179df5bb..d71ed8935f7 100644 --- a/sound/firewire/Makefile +++ b/sound/firewire/Makefile | |||
@@ -2,9 +2,7 @@ snd-firewire-lib-objs := lib.o iso-resources.o packets-buffer.o \ | |||
2 | fcp.o cmp.o amdtp.o | 2 | fcp.o cmp.o amdtp.o |
3 | snd-firewire-speakers-objs := speakers.o | 3 | snd-firewire-speakers-objs := speakers.o |
4 | snd-isight-objs := isight.o | 4 | snd-isight-objs := isight.o |
5 | snd-scs1x-objs := scs1x.o | ||
6 | 5 | ||
7 | obj-$(CONFIG_SND_FIREWIRE_LIB) += snd-firewire-lib.o | 6 | obj-$(CONFIG_SND_FIREWIRE_LIB) += snd-firewire-lib.o |
8 | obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o | 7 | obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o |
9 | obj-$(CONFIG_SND_ISIGHT) += snd-isight.o | 8 | obj-$(CONFIG_SND_ISIGHT) += snd-isight.o |
10 | obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o | ||
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c index ea995af6d04..87657dd7714 100644 --- a/sound/firewire/amdtp.c +++ b/sound/firewire/amdtp.c | |||
@@ -31,8 +31,6 @@ | |||
31 | #define INTERRUPT_INTERVAL 16 | 31 | #define INTERRUPT_INTERVAL 16 |
32 | #define QUEUE_LENGTH 48 | 32 | #define QUEUE_LENGTH 48 |
33 | 33 | ||
34 | static void pcm_period_tasklet(unsigned long data); | ||
35 | |||
36 | /** | 34 | /** |
37 | * amdtp_out_stream_init - initialize an AMDTP output stream structure | 35 | * amdtp_out_stream_init - initialize an AMDTP output stream structure |
38 | * @s: the AMDTP output stream to initialize | 36 | * @s: the AMDTP output stream to initialize |
@@ -49,7 +47,6 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, | |||
49 | s->flags = flags; | 47 | s->flags = flags; |
50 | s->context = ERR_PTR(-1); | 48 | s->context = ERR_PTR(-1); |
51 | mutex_init(&s->mutex); | 49 | mutex_init(&s->mutex); |
52 | tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s); | ||
53 | s->packet_index = 0; | 50 | s->packet_index = 0; |
54 | 51 | ||
55 | return 0; | 52 | return 0; |
@@ -167,21 +164,6 @@ void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, | |||
167 | } | 164 | } |
168 | EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); | 165 | EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); |
169 | 166 | ||
170 | /** | ||
171 | * amdtp_out_stream_pcm_prepare - prepare PCM device for running | ||
172 | * @s: the AMDTP output stream | ||
173 | * | ||
174 | * This function should be called from the PCM device's .prepare callback. | ||
175 | */ | ||
176 | void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) | ||
177 | { | ||
178 | tasklet_kill(&s->period_tasklet); | ||
179 | s->pcm_buffer_pointer = 0; | ||
180 | s->pcm_period_pointer = 0; | ||
181 | s->pointer_flush = true; | ||
182 | } | ||
183 | EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare); | ||
184 | |||
185 | static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) | 167 | static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) |
186 | { | 168 | { |
187 | unsigned int phase, data_blocks; | 169 | unsigned int phase, data_blocks; |
@@ -394,21 +376,11 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle) | |||
394 | s->pcm_period_pointer += data_blocks; | 376 | s->pcm_period_pointer += data_blocks; |
395 | if (s->pcm_period_pointer >= pcm->runtime->period_size) { | 377 | if (s->pcm_period_pointer >= pcm->runtime->period_size) { |
396 | s->pcm_period_pointer -= pcm->runtime->period_size; | 378 | s->pcm_period_pointer -= pcm->runtime->period_size; |
397 | s->pointer_flush = false; | 379 | snd_pcm_period_elapsed(pcm); |
398 | tasklet_hi_schedule(&s->period_tasklet); | ||
399 | } | 380 | } |
400 | } | 381 | } |
401 | } | 382 | } |
402 | 383 | ||
403 | static void pcm_period_tasklet(unsigned long data) | ||
404 | { | ||
405 | struct amdtp_out_stream *s = (void *)data; | ||
406 | struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm); | ||
407 | |||
408 | if (pcm) | ||
409 | snd_pcm_period_elapsed(pcm); | ||
410 | } | ||
411 | |||
412 | static void out_packet_callback(struct fw_iso_context *context, u32 cycle, | 384 | static void out_packet_callback(struct fw_iso_context *context, u32 cycle, |
413 | size_t header_length, void *header, void *data) | 385 | size_t header_length, void *header, void *data) |
414 | { | 386 | { |
@@ -534,24 +506,6 @@ err_unlock: | |||
534 | EXPORT_SYMBOL(amdtp_out_stream_start); | 506 | EXPORT_SYMBOL(amdtp_out_stream_start); |
535 | 507 | ||
536 | /** | 508 | /** |
537 | * amdtp_out_stream_pcm_pointer - get the PCM buffer position | ||
538 | * @s: the AMDTP output stream that transports the PCM data | ||
539 | * | ||
540 | * Returns the current buffer position, in frames. | ||
541 | */ | ||
542 | unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) | ||
543 | { | ||
544 | /* this optimization is allowed to be racy */ | ||
545 | if (s->pointer_flush) | ||
546 | fw_iso_context_flush_completions(s->context); | ||
547 | else | ||
548 | s->pointer_flush = true; | ||
549 | |||
550 | return ACCESS_ONCE(s->pcm_buffer_pointer); | ||
551 | } | ||
552 | EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer); | ||
553 | |||
554 | /** | ||
555 | * amdtp_out_stream_update - update the stream after a bus reset | 509 | * amdtp_out_stream_update - update the stream after a bus reset |
556 | * @s: the AMDTP output stream | 510 | * @s: the AMDTP output stream |
557 | */ | 511 | */ |
@@ -578,7 +532,6 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s) | |||
578 | return; | 532 | return; |
579 | } | 533 | } |
580 | 534 | ||
581 | tasklet_kill(&s->period_tasklet); | ||
582 | fw_iso_context_stop(s->context); | 535 | fw_iso_context_stop(s->context); |
583 | fw_iso_context_destroy(s->context); | 536 | fw_iso_context_destroy(s->context); |
584 | s->context = ERR_PTR(-1); | 537 | s->context = ERR_PTR(-1); |
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h index b680c5ef01d..537a9cb8358 100644 --- a/sound/firewire/amdtp.h +++ b/sound/firewire/amdtp.h | |||
@@ -1,7 +1,6 @@ | |||
1 | #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED | 1 | #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED |
2 | #define SOUND_FIREWIRE_AMDTP_H_INCLUDED | 2 | #define SOUND_FIREWIRE_AMDTP_H_INCLUDED |
3 | 3 | ||
4 | #include <linux/interrupt.h> | ||
5 | #include <linux/mutex.h> | 4 | #include <linux/mutex.h> |
6 | #include <linux/spinlock.h> | 5 | #include <linux/spinlock.h> |
7 | #include "packets-buffer.h" | 6 | #include "packets-buffer.h" |
@@ -56,7 +55,6 @@ struct amdtp_out_stream { | |||
56 | struct iso_packets_buffer buffer; | 55 | struct iso_packets_buffer buffer; |
57 | 56 | ||
58 | struct snd_pcm_substream *pcm; | 57 | struct snd_pcm_substream *pcm; |
59 | struct tasklet_struct period_tasklet; | ||
60 | 58 | ||
61 | int packet_index; | 59 | int packet_index; |
62 | unsigned int data_block_counter; | 60 | unsigned int data_block_counter; |
@@ -68,7 +66,6 @@ struct amdtp_out_stream { | |||
68 | 66 | ||
69 | unsigned int pcm_buffer_pointer; | 67 | unsigned int pcm_buffer_pointer; |
70 | unsigned int pcm_period_pointer; | 68 | unsigned int pcm_period_pointer; |
71 | bool pointer_flush; | ||
72 | }; | 69 | }; |
73 | 70 | ||
74 | int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, | 71 | int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, |
@@ -84,8 +81,6 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s); | |||
84 | 81 | ||
85 | void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, | 82 | void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, |
86 | snd_pcm_format_t format); | 83 | snd_pcm_format_t format); |
87 | void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s); | ||
88 | unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); | ||
89 | void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); | 84 | void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); |
90 | 85 | ||
91 | /** | 86 | /** |
@@ -128,6 +123,18 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s) | |||
128 | } | 123 | } |
129 | 124 | ||
130 | /** | 125 | /** |
126 | * amdtp_out_stream_pcm_prepare - prepare PCM device for running | ||
127 | * @s: the AMDTP output stream | ||
128 | * | ||
129 | * This function should be called from the PCM device's .prepare callback. | ||
130 | */ | ||
131 | static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) | ||
132 | { | ||
133 | s->pcm_buffer_pointer = 0; | ||
134 | s->pcm_period_pointer = 0; | ||
135 | } | ||
136 | |||
137 | /** | ||
131 | * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device | 138 | * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device |
132 | * @s: the AMDTP output stream | 139 | * @s: the AMDTP output stream |
133 | * @pcm: the PCM device to be started, or %NULL to stop the current device | 140 | * @pcm: the PCM device to be started, or %NULL to stop the current device |
@@ -142,6 +149,18 @@ static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s, | |||
142 | ACCESS_ONCE(s->pcm) = pcm; | 149 | ACCESS_ONCE(s->pcm) = pcm; |
143 | } | 150 | } |
144 | 151 | ||
152 | /** | ||
153 | * amdtp_out_stream_pcm_pointer - get the PCM buffer position | ||
154 | * @s: the AMDTP output stream that transports the PCM data | ||
155 | * | ||
156 | * Returns the current buffer position, in frames. | ||
157 | */ | ||
158 | static inline unsigned long | ||
159 | amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) | ||
160 | { | ||
161 | return ACCESS_ONCE(s->pcm_buffer_pointer); | ||
162 | } | ||
163 | |||
145 | static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) | 164 | static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) |
146 | { | 165 | { |
147 | return sfc & 1; | 166 | return sfc & 1; |
diff --git a/sound/firewire/cmp.c b/sound/firewire/cmp.c index 645cb0ba429..14cacbc655d 100644 --- a/sound/firewire/cmp.c +++ b/sound/firewire/cmp.c | |||
@@ -32,7 +32,7 @@ enum bus_reset_handling { | |||
32 | SUCCEED_ON_BUS_RESET, | 32 | SUCCEED_ON_BUS_RESET, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | static __printf(2, 3) | 35 | static __attribute__((format(printf, 2, 3))) |
36 | void cmp_error(struct cmp_connection *c, const char *fmt, ...) | 36 | void cmp_error(struct cmp_connection *c, const char *fmt, ...) |
37 | { | 37 | { |
38 | va_list va; | 38 | va_list va; |
@@ -84,7 +84,7 @@ static int pcr_modify(struct cmp_connection *c, | |||
84 | return 0; | 84 | return 0; |
85 | 85 | ||
86 | io_error: | 86 | io_error: |
87 | cmp_error(c, "transaction failed: %s\n", fw_rcode_string(rcode)); | 87 | cmp_error(c, "transaction failed: %s\n", rcode_string(rcode)); |
88 | return -EIO; | 88 | return -EIO; |
89 | 89 | ||
90 | bus_reset: | 90 | bus_reset: |
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c index d428ffede4f..440030818db 100644 --- a/sound/firewire/isight.c +++ b/sound/firewire/isight.c | |||
@@ -51,6 +51,7 @@ struct isight { | |||
51 | struct fw_unit *unit; | 51 | struct fw_unit *unit; |
52 | struct fw_device *device; | 52 | struct fw_device *device; |
53 | u64 audio_base; | 53 | u64 audio_base; |
54 | struct fw_address_handler iris_handler; | ||
54 | struct snd_pcm_substream *pcm; | 55 | struct snd_pcm_substream *pcm; |
55 | struct mutex mutex; | 56 | struct mutex mutex; |
56 | struct iso_packets_buffer buffer; | 57 | struct iso_packets_buffer buffer; |
@@ -611,6 +612,7 @@ static void isight_card_free(struct snd_card *card) | |||
611 | 612 | ||
612 | fw_iso_resources_destroy(&isight->resources); | 613 | fw_iso_resources_destroy(&isight->resources); |
613 | fw_unit_put(isight->unit); | 614 | fw_unit_put(isight->unit); |
615 | fw_device_put(isight->device); | ||
614 | mutex_destroy(&isight->mutex); | 616 | mutex_destroy(&isight->mutex); |
615 | } | 617 | } |
616 | 618 | ||
@@ -643,7 +645,7 @@ static int isight_probe(struct device *unit_dev) | |||
643 | isight->card = card; | 645 | isight->card = card; |
644 | mutex_init(&isight->mutex); | 646 | mutex_init(&isight->mutex); |
645 | isight->unit = fw_unit_get(unit); | 647 | isight->unit = fw_unit_get(unit); |
646 | isight->device = fw_dev; | 648 | isight->device = fw_device_get(fw_dev); |
647 | isight->audio_base = get_unit_base(unit); | 649 | isight->audio_base = get_unit_base(unit); |
648 | if (!isight->audio_base) { | 650 | if (!isight->audio_base) { |
649 | dev_err(&unit->device, "audio unit base not found\n"); | 651 | dev_err(&unit->device, "audio unit base not found\n"); |
@@ -680,6 +682,7 @@ static int isight_probe(struct device *unit_dev) | |||
680 | 682 | ||
681 | err_unit: | 683 | err_unit: |
682 | fw_unit_put(isight->unit); | 684 | fw_unit_put(isight->unit); |
685 | fw_device_put(isight->device); | ||
683 | mutex_destroy(&isight->mutex); | 686 | mutex_destroy(&isight->mutex); |
684 | error: | 687 | error: |
685 | snd_card_free(card); | 688 | snd_card_free(card); |
diff --git a/sound/firewire/iso-resources.c b/sound/firewire/iso-resources.c index 5f17b77ee15..ffe20b877e9 100644 --- a/sound/firewire/iso-resources.c +++ b/sound/firewire/iso-resources.c | |||
@@ -8,7 +8,6 @@ | |||
8 | #include <linux/device.h> | 8 | #include <linux/device.h> |
9 | #include <linux/firewire.h> | 9 | #include <linux/firewire.h> |
10 | #include <linux/firewire-constants.h> | 10 | #include <linux/firewire-constants.h> |
11 | #include <linux/export.h> | ||
12 | #include <linux/jiffies.h> | 11 | #include <linux/jiffies.h> |
13 | #include <linux/mutex.h> | 12 | #include <linux/mutex.h> |
14 | #include <linux/sched.h> | 13 | #include <linux/sched.h> |
diff --git a/sound/firewire/lib.c b/sound/firewire/lib.c index 14eb4149837..4750cea2210 100644 --- a/sound/firewire/lib.c +++ b/sound/firewire/lib.c | |||
@@ -14,6 +14,32 @@ | |||
14 | #define ERROR_RETRY_DELAY_MS 5 | 14 | #define ERROR_RETRY_DELAY_MS 5 |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * rcode_string - convert a firewire result code to a string | ||
18 | * @rcode: the result | ||
19 | */ | ||
20 | const char *rcode_string(unsigned int rcode) | ||
21 | { | ||
22 | static const char *const names[] = { | ||
23 | [RCODE_COMPLETE] = "complete", | ||
24 | [RCODE_CONFLICT_ERROR] = "conflict error", | ||
25 | [RCODE_DATA_ERROR] = "data error", | ||
26 | [RCODE_TYPE_ERROR] = "type error", | ||
27 | [RCODE_ADDRESS_ERROR] = "address error", | ||
28 | [RCODE_SEND_ERROR] = "send error", | ||
29 | [RCODE_CANCELLED] = "cancelled", | ||
30 | [RCODE_BUSY] = "busy", | ||
31 | [RCODE_GENERATION] = "generation", | ||
32 | [RCODE_NO_ACK] = "no ack", | ||
33 | }; | ||
34 | |||
35 | if (rcode < ARRAY_SIZE(names) && names[rcode]) | ||
36 | return names[rcode]; | ||
37 | else | ||
38 | return "unknown"; | ||
39 | } | ||
40 | EXPORT_SYMBOL(rcode_string); | ||
41 | |||
42 | /** | ||
17 | * snd_fw_transaction - send a request and wait for its completion | 43 | * snd_fw_transaction - send a request and wait for its completion |
18 | * @unit: the driver's unit on the target device | 44 | * @unit: the driver's unit on the target device |
19 | * @tcode: the transaction code | 45 | * @tcode: the transaction code |
@@ -45,7 +71,7 @@ int snd_fw_transaction(struct fw_unit *unit, int tcode, | |||
45 | 71 | ||
46 | if (rcode_is_permanent_error(rcode) || ++tries >= 3) { | 72 | if (rcode_is_permanent_error(rcode) || ++tries >= 3) { |
47 | dev_err(&unit->device, "transaction failed: %s\n", | 73 | dev_err(&unit->device, "transaction failed: %s\n", |
48 | fw_rcode_string(rcode)); | 74 | rcode_string(rcode)); |
49 | return -EIO; | 75 | return -EIO; |
50 | } | 76 | } |
51 | 77 | ||
diff --git a/sound/firewire/lib.h b/sound/firewire/lib.h index aef301476ea..064f3fd9ab0 100644 --- a/sound/firewire/lib.h +++ b/sound/firewire/lib.h | |||
@@ -8,6 +8,7 @@ struct fw_unit; | |||
8 | 8 | ||
9 | int snd_fw_transaction(struct fw_unit *unit, int tcode, | 9 | int snd_fw_transaction(struct fw_unit *unit, int tcode, |
10 | u64 offset, void *buffer, size_t length); | 10 | u64 offset, void *buffer, size_t length); |
11 | const char *rcode_string(unsigned int rcode); | ||
11 | 12 | ||
12 | /* returns true if retrying the transaction would not make sense */ | 13 | /* returns true if retrying the transaction would not make sense */ |
13 | static inline bool rcode_is_permanent_error(int rcode) | 14 | static inline bool rcode_is_permanent_error(int rcode) |
diff --git a/sound/firewire/packets-buffer.c b/sound/firewire/packets-buffer.c index ea1506679c6..3c61ca2e615 100644 --- a/sound/firewire/packets-buffer.c +++ b/sound/firewire/packets-buffer.c | |||
@@ -6,7 +6,6 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/firewire.h> | 8 | #include <linux/firewire.h> |
9 | #include <linux/export.h> | ||
10 | #include <linux/slab.h> | 9 | #include <linux/slab.h> |
11 | #include "packets-buffer.h" | 10 | #include "packets-buffer.h" |
12 | 11 | ||
diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c deleted file mode 100644 index 844a555c3b1..00000000000 --- a/sound/firewire/scs1x.c +++ /dev/null | |||
@@ -1,527 +0,0 @@ | |||
1 | /* | ||
2 | * Stanton Control System 1 MIDI 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 | |||
8 | #include <linux/device.h> | ||
9 | #include <linux/firewire.h> | ||
10 | #include <linux/firewire-constants.h> | ||
11 | #include <linux/interrupt.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/mod_devicetable.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/string.h> | ||
16 | #include <linux/wait.h> | ||
17 | #include <sound/core.h> | ||
18 | #include <sound/initval.h> | ||
19 | #include <sound/rawmidi.h> | ||
20 | #include "lib.h" | ||
21 | |||
22 | #define OUI_STANTON 0x001260 | ||
23 | #define MODEL_SCS_1M 0x001000 | ||
24 | #define MODEL_SCS_1D 0x002000 | ||
25 | |||
26 | #define HSS1394_ADDRESS 0xc007dedadadaULL | ||
27 | #define HSS1394_MAX_PACKET_SIZE 64 | ||
28 | |||
29 | #define HSS1394_TAG_USER_DATA 0x00 | ||
30 | #define HSS1394_TAG_CHANGE_ADDRESS 0xf1 | ||
31 | |||
32 | struct scs { | ||
33 | struct snd_card *card; | ||
34 | struct fw_unit *unit; | ||
35 | struct fw_address_handler hss_handler; | ||
36 | struct fw_transaction transaction; | ||
37 | bool transaction_running; | ||
38 | bool output_idle; | ||
39 | u8 output_status; | ||
40 | u8 output_bytes; | ||
41 | bool output_escaped; | ||
42 | bool output_escape_high_nibble; | ||
43 | u8 input_escape_count; | ||
44 | struct snd_rawmidi_substream *output; | ||
45 | struct snd_rawmidi_substream *input; | ||
46 | struct tasklet_struct tasklet; | ||
47 | wait_queue_head_t idle_wait; | ||
48 | u8 *buffer; | ||
49 | }; | ||
50 | |||
51 | static const u8 sysex_escape_prefix[] = { | ||
52 | 0xf0, /* SysEx begin */ | ||
53 | 0x00, 0x01, 0x60, /* Stanton DJ */ | ||
54 | 0x48, 0x53, 0x53, /* "HSS" */ | ||
55 | }; | ||
56 | |||
57 | static int scs_output_open(struct snd_rawmidi_substream *stream) | ||
58 | { | ||
59 | struct scs *scs = stream->rmidi->private_data; | ||
60 | |||
61 | scs->output_status = 0; | ||
62 | scs->output_bytes = 1; | ||
63 | scs->output_escaped = false; | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static int scs_output_close(struct snd_rawmidi_substream *stream) | ||
69 | { | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up) | ||
74 | { | ||
75 | struct scs *scs = stream->rmidi->private_data; | ||
76 | |||
77 | ACCESS_ONCE(scs->output) = up ? stream : NULL; | ||
78 | if (up) { | ||
79 | scs->output_idle = false; | ||
80 | tasklet_schedule(&scs->tasklet); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | static void scs_write_callback(struct fw_card *card, int rcode, | ||
85 | void *data, size_t length, void *callback_data) | ||
86 | { | ||
87 | struct scs *scs = callback_data; | ||
88 | |||
89 | if (rcode == RCODE_GENERATION) { | ||
90 | /* TODO: retry this packet */ | ||
91 | } | ||
92 | |||
93 | scs->transaction_running = false; | ||
94 | tasklet_schedule(&scs->tasklet); | ||
95 | } | ||
96 | |||
97 | static bool is_valid_running_status(u8 status) | ||
98 | { | ||
99 | return status >= 0x80 && status <= 0xef; | ||
100 | } | ||
101 | |||
102 | static bool is_one_byte_cmd(u8 status) | ||
103 | { | ||
104 | return status == 0xf6 || | ||
105 | status >= 0xf8; | ||
106 | } | ||
107 | |||
108 | static bool is_two_bytes_cmd(u8 status) | ||
109 | { | ||
110 | return (status >= 0xc0 && status <= 0xdf) || | ||
111 | status == 0xf1 || | ||
112 | status == 0xf3; | ||
113 | } | ||
114 | |||
115 | static bool is_three_bytes_cmd(u8 status) | ||
116 | { | ||
117 | return (status >= 0x80 && status <= 0xbf) || | ||
118 | (status >= 0xe0 && status <= 0xef) || | ||
119 | status == 0xf2; | ||
120 | } | ||
121 | |||
122 | static bool is_invalid_cmd(u8 status) | ||
123 | { | ||
124 | return status == 0xf4 || | ||
125 | status == 0xf5 || | ||
126 | status == 0xf9 || | ||
127 | status == 0xfd; | ||
128 | } | ||
129 | |||
130 | static void scs_output_tasklet(unsigned long data) | ||
131 | { | ||
132 | struct scs *scs = (void *)data; | ||
133 | struct snd_rawmidi_substream *stream; | ||
134 | unsigned int i; | ||
135 | u8 byte; | ||
136 | struct fw_device *dev; | ||
137 | int generation; | ||
138 | |||
139 | if (scs->transaction_running) | ||
140 | return; | ||
141 | |||
142 | stream = ACCESS_ONCE(scs->output); | ||
143 | if (!stream) { | ||
144 | scs->output_idle = true; | ||
145 | wake_up(&scs->idle_wait); | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | i = scs->output_bytes; | ||
150 | for (;;) { | ||
151 | if (snd_rawmidi_transmit(stream, &byte, 1) != 1) { | ||
152 | scs->output_bytes = i; | ||
153 | scs->output_idle = true; | ||
154 | wake_up(&scs->idle_wait); | ||
155 | return; | ||
156 | } | ||
157 | /* | ||
158 | * Convert from real MIDI to what I think the device expects (no | ||
159 | * running status, one command per packet, unescaped SysExs). | ||
160 | */ | ||
161 | if (scs->output_escaped && byte < 0x80) { | ||
162 | if (scs->output_escape_high_nibble) { | ||
163 | if (i < HSS1394_MAX_PACKET_SIZE) { | ||
164 | scs->buffer[i] = byte << 4; | ||
165 | scs->output_escape_high_nibble = false; | ||
166 | } | ||
167 | } else { | ||
168 | scs->buffer[i++] |= byte & 0x0f; | ||
169 | scs->output_escape_high_nibble = true; | ||
170 | } | ||
171 | } else if (byte < 0x80) { | ||
172 | if (i == 1) { | ||
173 | if (!is_valid_running_status(scs->output_status)) | ||
174 | continue; | ||
175 | scs->buffer[0] = HSS1394_TAG_USER_DATA; | ||
176 | scs->buffer[i++] = scs->output_status; | ||
177 | } | ||
178 | scs->buffer[i++] = byte; | ||
179 | if ((i == 3 && is_two_bytes_cmd(scs->output_status)) || | ||
180 | (i == 4 && is_three_bytes_cmd(scs->output_status))) | ||
181 | break; | ||
182 | if (i == 1 + ARRAY_SIZE(sysex_escape_prefix) && | ||
183 | !memcmp(scs->buffer + 1, sysex_escape_prefix, | ||
184 | ARRAY_SIZE(sysex_escape_prefix))) { | ||
185 | scs->output_escaped = true; | ||
186 | scs->output_escape_high_nibble = true; | ||
187 | i = 0; | ||
188 | } | ||
189 | if (i >= HSS1394_MAX_PACKET_SIZE) | ||
190 | i = 1; | ||
191 | } else if (byte == 0xf7) { | ||
192 | if (scs->output_escaped) { | ||
193 | if (i >= 1 && scs->output_escape_high_nibble && | ||
194 | scs->buffer[0] != HSS1394_TAG_CHANGE_ADDRESS) | ||
195 | break; | ||
196 | } else { | ||
197 | if (i > 1 && scs->output_status == 0xf0) { | ||
198 | scs->buffer[i++] = 0xf7; | ||
199 | break; | ||
200 | } | ||
201 | } | ||
202 | i = 1; | ||
203 | scs->output_escaped = false; | ||
204 | } else if (!is_invalid_cmd(byte) && | ||
205 | byte < 0xf8) { | ||
206 | i = 1; | ||
207 | scs->buffer[0] = HSS1394_TAG_USER_DATA; | ||
208 | scs->buffer[i++] = byte; | ||
209 | scs->output_status = byte; | ||
210 | scs->output_escaped = false; | ||
211 | if (is_one_byte_cmd(byte)) | ||
212 | break; | ||
213 | } | ||
214 | } | ||
215 | scs->output_bytes = 1; | ||
216 | scs->output_escaped = false; | ||
217 | |||
218 | scs->transaction_running = true; | ||
219 | dev = fw_parent_device(scs->unit); | ||
220 | generation = dev->generation; | ||
221 | smp_rmb(); /* node_id vs. generation */ | ||
222 | fw_send_request(dev->card, &scs->transaction, TCODE_WRITE_BLOCK_REQUEST, | ||
223 | dev->node_id, generation, dev->max_speed, | ||
224 | HSS1394_ADDRESS, scs->buffer, i, | ||
225 | scs_write_callback, scs); | ||
226 | } | ||
227 | |||
228 | static void scs_output_drain(struct snd_rawmidi_substream *stream) | ||
229 | { | ||
230 | struct scs *scs = stream->rmidi->private_data; | ||
231 | |||
232 | wait_event(scs->idle_wait, scs->output_idle); | ||
233 | } | ||
234 | |||
235 | static struct snd_rawmidi_ops output_ops = { | ||
236 | .open = scs_output_open, | ||
237 | .close = scs_output_close, | ||
238 | .trigger = scs_output_trigger, | ||
239 | .drain = scs_output_drain, | ||
240 | }; | ||
241 | |||
242 | static int scs_input_open(struct snd_rawmidi_substream *stream) | ||
243 | { | ||
244 | struct scs *scs = stream->rmidi->private_data; | ||
245 | |||
246 | scs->input_escape_count = 0; | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | static int scs_input_close(struct snd_rawmidi_substream *stream) | ||
252 | { | ||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up) | ||
257 | { | ||
258 | struct scs *scs = stream->rmidi->private_data; | ||
259 | |||
260 | ACCESS_ONCE(scs->input) = up ? stream : NULL; | ||
261 | } | ||
262 | |||
263 | static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream, | ||
264 | u8 byte) | ||
265 | { | ||
266 | u8 nibbles[2]; | ||
267 | |||
268 | nibbles[0] = byte >> 4; | ||
269 | nibbles[1] = byte & 0x0f; | ||
270 | snd_rawmidi_receive(stream, nibbles, 2); | ||
271 | } | ||
272 | |||
273 | static void scs_input_midi_byte(struct scs *scs, | ||
274 | struct snd_rawmidi_substream *stream, | ||
275 | u8 byte) | ||
276 | { | ||
277 | if (scs->input_escape_count > 0) { | ||
278 | scs_input_escaped_byte(stream, byte); | ||
279 | scs->input_escape_count--; | ||
280 | if (scs->input_escape_count == 0) | ||
281 | snd_rawmidi_receive(stream, (const u8[]) { 0xf7 }, 1); | ||
282 | } else if (byte == 0xf9) { | ||
283 | snd_rawmidi_receive(stream, sysex_escape_prefix, | ||
284 | ARRAY_SIZE(sysex_escape_prefix)); | ||
285 | scs_input_escaped_byte(stream, 0x00); | ||
286 | scs_input_escaped_byte(stream, 0xf9); | ||
287 | scs->input_escape_count = 3; | ||
288 | } else { | ||
289 | snd_rawmidi_receive(stream, &byte, 1); | ||
290 | } | ||
291 | } | ||
292 | |||
293 | static void scs_input_packet(struct scs *scs, | ||
294 | struct snd_rawmidi_substream *stream, | ||
295 | const u8 *data, unsigned int bytes) | ||
296 | { | ||
297 | unsigned int i; | ||
298 | |||
299 | if (data[0] == HSS1394_TAG_USER_DATA) { | ||
300 | for (i = 1; i < bytes; ++i) | ||
301 | scs_input_midi_byte(scs, stream, data[i]); | ||
302 | } else { | ||
303 | snd_rawmidi_receive(stream, sysex_escape_prefix, | ||
304 | ARRAY_SIZE(sysex_escape_prefix)); | ||
305 | for (i = 0; i < bytes; ++i) | ||
306 | scs_input_escaped_byte(stream, data[i]); | ||
307 | snd_rawmidi_receive(stream, (const u8[]) { 0xf7 }, 1); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | static struct snd_rawmidi_ops input_ops = { | ||
312 | .open = scs_input_open, | ||
313 | .close = scs_input_close, | ||
314 | .trigger = scs_input_trigger, | ||
315 | }; | ||
316 | |||
317 | static int scs_create_midi(struct scs *scs) | ||
318 | { | ||
319 | struct snd_rawmidi *rmidi; | ||
320 | int err; | ||
321 | |||
322 | err = snd_rawmidi_new(scs->card, "SCS.1x", 0, 1, 1, &rmidi); | ||
323 | if (err < 0) | ||
324 | return err; | ||
325 | snprintf(rmidi->name, sizeof(rmidi->name), | ||
326 | "%s MIDI", scs->card->shortname); | ||
327 | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | | ||
328 | SNDRV_RAWMIDI_INFO_INPUT | | ||
329 | SNDRV_RAWMIDI_INFO_DUPLEX; | ||
330 | rmidi->private_data = scs; | ||
331 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &output_ops); | ||
332 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &input_ops); | ||
333 | |||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | static void handle_hss(struct fw_card *card, struct fw_request *request, | ||
338 | int tcode, int destination, int source, int generation, | ||
339 | unsigned long long offset, void *data, size_t length, | ||
340 | void *callback_data) | ||
341 | { | ||
342 | struct scs *scs = callback_data; | ||
343 | struct snd_rawmidi_substream *stream; | ||
344 | |||
345 | if (offset != scs->hss_handler.offset) { | ||
346 | fw_send_response(card, request, RCODE_ADDRESS_ERROR); | ||
347 | return; | ||
348 | } | ||
349 | if (tcode != TCODE_WRITE_QUADLET_REQUEST && | ||
350 | tcode != TCODE_WRITE_BLOCK_REQUEST) { | ||
351 | fw_send_response(card, request, RCODE_TYPE_ERROR); | ||
352 | return; | ||
353 | } | ||
354 | |||
355 | if (length >= 1) { | ||
356 | stream = ACCESS_ONCE(scs->input); | ||
357 | if (stream) | ||
358 | scs_input_packet(scs, stream, data, length); | ||
359 | } | ||
360 | |||
361 | fw_send_response(card, request, RCODE_COMPLETE); | ||
362 | } | ||
363 | |||
364 | static int scs_init_hss_address(struct scs *scs) | ||
365 | { | ||
366 | __be64 data; | ||
367 | int err; | ||
368 | |||
369 | data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) | | ||
370 | scs->hss_handler.offset); | ||
371 | err = snd_fw_transaction(scs->unit, TCODE_WRITE_BLOCK_REQUEST, | ||
372 | HSS1394_ADDRESS, &data, 8); | ||
373 | if (err < 0) | ||
374 | dev_err(&scs->unit->device, "HSS1394 communication failed\n"); | ||
375 | |||
376 | return err; | ||
377 | } | ||
378 | |||
379 | static void scs_card_free(struct snd_card *card) | ||
380 | { | ||
381 | struct scs *scs = card->private_data; | ||
382 | |||
383 | fw_core_remove_address_handler(&scs->hss_handler); | ||
384 | kfree(scs->buffer); | ||
385 | } | ||
386 | |||
387 | static int scs_probe(struct device *unit_dev) | ||
388 | { | ||
389 | struct fw_unit *unit = fw_unit(unit_dev); | ||
390 | struct fw_device *fw_dev = fw_parent_device(unit); | ||
391 | struct snd_card *card; | ||
392 | struct scs *scs; | ||
393 | int err; | ||
394 | |||
395 | err = snd_card_create(-16, NULL, THIS_MODULE, sizeof(*scs), &card); | ||
396 | if (err < 0) | ||
397 | return err; | ||
398 | snd_card_set_dev(card, unit_dev); | ||
399 | |||
400 | scs = card->private_data; | ||
401 | scs->card = card; | ||
402 | scs->unit = unit; | ||
403 | tasklet_init(&scs->tasklet, scs_output_tasklet, (unsigned long)scs); | ||
404 | init_waitqueue_head(&scs->idle_wait); | ||
405 | scs->output_idle = true; | ||
406 | |||
407 | scs->buffer = kmalloc(HSS1394_MAX_PACKET_SIZE, GFP_KERNEL); | ||
408 | if (!scs->buffer) | ||
409 | goto err_card; | ||
410 | |||
411 | scs->hss_handler.length = HSS1394_MAX_PACKET_SIZE; | ||
412 | scs->hss_handler.address_callback = handle_hss; | ||
413 | scs->hss_handler.callback_data = scs; | ||
414 | err = fw_core_add_address_handler(&scs->hss_handler, | ||
415 | &fw_high_memory_region); | ||
416 | if (err < 0) | ||
417 | goto err_buffer; | ||
418 | |||
419 | card->private_free = scs_card_free; | ||
420 | |||
421 | strcpy(card->driver, "SCS.1x"); | ||
422 | strcpy(card->shortname, "SCS.1x"); | ||
423 | fw_csr_string(unit->directory, CSR_MODEL, | ||
424 | card->shortname, sizeof(card->shortname)); | ||
425 | snprintf(card->longname, sizeof(card->longname), | ||
426 | "Stanton DJ %s (GUID %08x%08x) at %s, S%d", | ||
427 | card->shortname, fw_dev->config_rom[3], fw_dev->config_rom[4], | ||
428 | dev_name(&unit->device), 100 << fw_dev->max_speed); | ||
429 | strcpy(card->mixername, card->shortname); | ||
430 | |||
431 | err = scs_init_hss_address(scs); | ||
432 | if (err < 0) | ||
433 | goto err_card; | ||
434 | |||
435 | err = scs_create_midi(scs); | ||
436 | if (err < 0) | ||
437 | goto err_card; | ||
438 | |||
439 | err = snd_card_register(card); | ||
440 | if (err < 0) | ||
441 | goto err_card; | ||
442 | |||
443 | dev_set_drvdata(unit_dev, scs); | ||
444 | |||
445 | return 0; | ||
446 | |||
447 | err_buffer: | ||
448 | kfree(scs->buffer); | ||
449 | err_card: | ||
450 | snd_card_free(card); | ||
451 | return err; | ||
452 | } | ||
453 | |||
454 | static int scs_remove(struct device *dev) | ||
455 | { | ||
456 | struct scs *scs = dev_get_drvdata(dev); | ||
457 | |||
458 | snd_card_disconnect(scs->card); | ||
459 | |||
460 | ACCESS_ONCE(scs->output) = NULL; | ||
461 | ACCESS_ONCE(scs->input) = NULL; | ||
462 | |||
463 | wait_event(scs->idle_wait, scs->output_idle); | ||
464 | |||
465 | tasklet_kill(&scs->tasklet); | ||
466 | |||
467 | snd_card_free_when_closed(scs->card); | ||
468 | |||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static void scs_update(struct fw_unit *unit) | ||
473 | { | ||
474 | struct scs *scs = dev_get_drvdata(&unit->device); | ||
475 | __be64 data; | ||
476 | |||
477 | data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) | | ||
478 | scs->hss_handler.offset); | ||
479 | snd_fw_transaction(scs->unit, TCODE_WRITE_BLOCK_REQUEST, | ||
480 | HSS1394_ADDRESS, &data, 8); | ||
481 | } | ||
482 | |||
483 | static const struct ieee1394_device_id scs_id_table[] = { | ||
484 | { | ||
485 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | ||
486 | IEEE1394_MATCH_MODEL_ID, | ||
487 | .vendor_id = OUI_STANTON, | ||
488 | .model_id = MODEL_SCS_1M, | ||
489 | }, | ||
490 | { | ||
491 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | ||
492 | IEEE1394_MATCH_MODEL_ID, | ||
493 | .vendor_id = OUI_STANTON, | ||
494 | .model_id = MODEL_SCS_1D, | ||
495 | }, | ||
496 | {} | ||
497 | }; | ||
498 | MODULE_DEVICE_TABLE(ieee1394, scs_id_table); | ||
499 | |||
500 | MODULE_DESCRIPTION("SCS.1x MIDI driver"); | ||
501 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); | ||
502 | MODULE_LICENSE("GPL v2"); | ||
503 | |||
504 | static struct fw_driver scs_driver = { | ||
505 | .driver = { | ||
506 | .owner = THIS_MODULE, | ||
507 | .name = KBUILD_MODNAME, | ||
508 | .bus = &fw_bus_type, | ||
509 | .probe = scs_probe, | ||
510 | .remove = scs_remove, | ||
511 | }, | ||
512 | .update = scs_update, | ||
513 | .id_table = scs_id_table, | ||
514 | }; | ||
515 | |||
516 | static int __init alsa_scs1x_init(void) | ||
517 | { | ||
518 | return driver_register(&scs_driver.driver); | ||
519 | } | ||
520 | |||
521 | static void __exit alsa_scs1x_exit(void) | ||
522 | { | ||
523 | driver_unregister(&scs_driver.driver); | ||
524 | } | ||
525 | |||
526 | module_init(alsa_scs1x_init); | ||
527 | module_exit(alsa_scs1x_exit); | ||
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c index d6846557f27..3fc257da180 100644 --- a/sound/firewire/speakers.c +++ b/sound/firewire/speakers.c | |||
@@ -656,14 +656,16 @@ static u32 fwspk_read_firmware_version(struct fw_unit *unit) | |||
656 | static void fwspk_card_free(struct snd_card *card) | 656 | static void fwspk_card_free(struct snd_card *card) |
657 | { | 657 | { |
658 | struct fwspk *fwspk = card->private_data; | 658 | struct fwspk *fwspk = card->private_data; |
659 | struct fw_device *dev = fw_parent_device(fwspk->unit); | ||
659 | 660 | ||
660 | amdtp_out_stream_destroy(&fwspk->stream); | 661 | amdtp_out_stream_destroy(&fwspk->stream); |
661 | cmp_connection_destroy(&fwspk->connection); | 662 | cmp_connection_destroy(&fwspk->connection); |
662 | fw_unit_put(fwspk->unit); | 663 | fw_unit_put(fwspk->unit); |
664 | fw_device_put(dev); | ||
663 | mutex_destroy(&fwspk->mutex); | 665 | mutex_destroy(&fwspk->mutex); |
664 | } | 666 | } |
665 | 667 | ||
666 | static const struct device_info *fwspk_detect(struct fw_device *dev) | 668 | static const struct device_info *__devinit fwspk_detect(struct fw_device *dev) |
667 | { | 669 | { |
668 | static const struct device_info griffin_firewave = { | 670 | static const struct device_info griffin_firewave = { |
669 | .driver_name = "FireWave", | 671 | .driver_name = "FireWave", |
@@ -699,7 +701,7 @@ static const struct device_info *fwspk_detect(struct fw_device *dev) | |||
699 | return NULL; | 701 | return NULL; |
700 | } | 702 | } |
701 | 703 | ||
702 | static int fwspk_probe(struct device *unit_dev) | 704 | static int __devinit fwspk_probe(struct device *unit_dev) |
703 | { | 705 | { |
704 | struct fw_unit *unit = fw_unit(unit_dev); | 706 | struct fw_unit *unit = fw_unit(unit_dev); |
705 | struct fw_device *fw_dev = fw_parent_device(unit); | 707 | struct fw_device *fw_dev = fw_parent_device(unit); |
@@ -716,6 +718,7 @@ static int fwspk_probe(struct device *unit_dev) | |||
716 | fwspk = card->private_data; | 718 | fwspk = card->private_data; |
717 | fwspk->card = card; | 719 | fwspk->card = card; |
718 | mutex_init(&fwspk->mutex); | 720 | mutex_init(&fwspk->mutex); |
721 | fw_device_get(fw_dev); | ||
719 | fwspk->unit = fw_unit_get(unit); | 722 | fwspk->unit = fw_unit_get(unit); |
720 | fwspk->device_info = fwspk_detect(fw_dev); | 723 | fwspk->device_info = fwspk_detect(fw_dev); |
721 | if (!fwspk->device_info) { | 724 | if (!fwspk->device_info) { |
@@ -764,20 +767,20 @@ err_connection: | |||
764 | cmp_connection_destroy(&fwspk->connection); | 767 | cmp_connection_destroy(&fwspk->connection); |
765 | err_unit: | 768 | err_unit: |
766 | fw_unit_put(fwspk->unit); | 769 | fw_unit_put(fwspk->unit); |
770 | fw_device_put(fw_dev); | ||
767 | mutex_destroy(&fwspk->mutex); | 771 | mutex_destroy(&fwspk->mutex); |
768 | error: | 772 | error: |
769 | snd_card_free(card); | 773 | snd_card_free(card); |
770 | return err; | 774 | return err; |
771 | } | 775 | } |
772 | 776 | ||
773 | static int fwspk_remove(struct device *dev) | 777 | static int __devexit fwspk_remove(struct device *dev) |
774 | { | 778 | { |
775 | struct fwspk *fwspk = dev_get_drvdata(dev); | 779 | struct fwspk *fwspk = dev_get_drvdata(dev); |
776 | 780 | ||
781 | mutex_lock(&fwspk->mutex); | ||
777 | amdtp_out_stream_pcm_abort(&fwspk->stream); | 782 | amdtp_out_stream_pcm_abort(&fwspk->stream); |
778 | snd_card_disconnect(fwspk->card); | 783 | snd_card_disconnect(fwspk->card); |
779 | |||
780 | mutex_lock(&fwspk->mutex); | ||
781 | fwspk_stop_stream(fwspk); | 784 | fwspk_stop_stream(fwspk); |
782 | mutex_unlock(&fwspk->mutex); | 785 | mutex_unlock(&fwspk->mutex); |
783 | 786 | ||
@@ -793,8 +796,8 @@ static void fwspk_bus_reset(struct fw_unit *unit) | |||
793 | fcp_bus_reset(fwspk->unit); | 796 | fcp_bus_reset(fwspk->unit); |
794 | 797 | ||
795 | if (cmp_connection_update(&fwspk->connection) < 0) { | 798 | if (cmp_connection_update(&fwspk->connection) < 0) { |
796 | amdtp_out_stream_pcm_abort(&fwspk->stream); | ||
797 | mutex_lock(&fwspk->mutex); | 799 | mutex_lock(&fwspk->mutex); |
800 | amdtp_out_stream_pcm_abort(&fwspk->stream); | ||
798 | fwspk_stop_stream(fwspk); | 801 | fwspk_stop_stream(fwspk); |
799 | mutex_unlock(&fwspk->mutex); | 802 | mutex_unlock(&fwspk->mutex); |
800 | return; | 803 | return; |
@@ -834,7 +837,7 @@ static struct fw_driver fwspk_driver = { | |||
834 | .name = KBUILD_MODNAME, | 837 | .name = KBUILD_MODNAME, |
835 | .bus = &fw_bus_type, | 838 | .bus = &fw_bus_type, |
836 | .probe = fwspk_probe, | 839 | .probe = fwspk_probe, |
837 | .remove = fwspk_remove, | 840 | .remove = __devexit_p(fwspk_remove), |
838 | }, | 841 | }, |
839 | .update = fwspk_bus_reset, | 842 | .update = fwspk_bus_reset, |
840 | .id_table = fwspk_id_table, | 843 | .id_table = fwspk_id_table, |