diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2018-12-11 05:17:30 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2018-12-11 08:56:20 -0500 |
commit | 3c3b892b3735edcc9e0be0aa129c72613e3f156e (patch) | |
tree | 1cec4e0a5d49534d57c30f3d9788125966e75228 | |
parent | 72f10f08b6e95cfeb7cad9ebd165d5cca771e0e7 (diff) |
ALSA: fireface: share helper function to get current sampling rate and clock source
As long as investigating packet dumps from Fireface 400/800, bits on
status registers for clock synchronization are the same.
This commit moves a parser for a register of clock configuration to
obsolete model-specific operations.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/firewire/fireface/ff-pcm.c | 2 | ||||
-rw-r--r-- | sound/firewire/fireface/ff-protocol-ff400.c | 60 | ||||
-rw-r--r-- | sound/firewire/fireface/ff-stream.c | 2 | ||||
-rw-r--r-- | sound/firewire/fireface/ff-transaction.c | 59 | ||||
-rw-r--r-- | sound/firewire/fireface/ff.h | 4 |
5 files changed, 63 insertions, 64 deletions
diff --git a/sound/firewire/fireface/ff-pcm.c b/sound/firewire/fireface/ff-pcm.c index bf47f9ec8703..63b0be6f05e8 100644 --- a/sound/firewire/fireface/ff-pcm.c +++ b/sound/firewire/fireface/ff-pcm.c | |||
@@ -141,7 +141,7 @@ static int pcm_open(struct snd_pcm_substream *substream) | |||
141 | if (err < 0) | 141 | if (err < 0) |
142 | goto release_lock; | 142 | goto release_lock; |
143 | 143 | ||
144 | err = ff->spec->protocol->get_clock(ff, &rate, &src); | 144 | err = snd_ff_transaction_get_clock(ff, &rate, &src); |
145 | if (err < 0) | 145 | if (err < 0) |
146 | goto release_lock; | 146 | goto release_lock; |
147 | 147 | ||
diff --git a/sound/firewire/fireface/ff-protocol-ff400.c b/sound/firewire/fireface/ff-protocol-ff400.c index 31c381dcb452..d2fbb0382223 100644 --- a/sound/firewire/fireface/ff-protocol-ff400.c +++ b/sound/firewire/fireface/ff-protocol-ff400.c | |||
@@ -19,65 +19,6 @@ | |||
19 | #define FF400_MIDI_RX_PORT_0 0x000080180000ull | 19 | #define FF400_MIDI_RX_PORT_0 0x000080180000ull |
20 | #define FF400_MIDI_RX_PORT_1 0x000080190000ull | 20 | #define FF400_MIDI_RX_PORT_1 0x000080190000ull |
21 | 21 | ||
22 | static int ff400_get_clock(struct snd_ff *ff, unsigned int *rate, | ||
23 | enum snd_ff_clock_src *src) | ||
24 | { | ||
25 | __le32 reg; | ||
26 | u32 data; | ||
27 | int err; | ||
28 | |||
29 | err = snd_fw_transaction(ff->unit, TCODE_READ_QUADLET_REQUEST, | ||
30 | SND_FF_REG_CLOCK_CONFIG, ®, sizeof(reg), 0); | ||
31 | if (err < 0) | ||
32 | return err; | ||
33 | data = le32_to_cpu(reg); | ||
34 | |||
35 | /* Calculate sampling rate. */ | ||
36 | switch ((data >> 1) & 0x03) { | ||
37 | case 0x01: | ||
38 | *rate = 32000; | ||
39 | break; | ||
40 | case 0x00: | ||
41 | *rate = 44100; | ||
42 | break; | ||
43 | case 0x03: | ||
44 | *rate = 48000; | ||
45 | break; | ||
46 | case 0x02: | ||
47 | default: | ||
48 | return -EIO; | ||
49 | } | ||
50 | |||
51 | if (data & 0x08) | ||
52 | *rate *= 2; | ||
53 | else if (data & 0x10) | ||
54 | *rate *= 4; | ||
55 | |||
56 | /* Calculate source of clock. */ | ||
57 | if (data & 0x01) { | ||
58 | *src = SND_FF_CLOCK_SRC_INTERNAL; | ||
59 | } else { | ||
60 | /* TODO: 0x00, 0x01, 0x02, 0x06, 0x07? */ | ||
61 | switch ((data >> 10) & 0x07) { | ||
62 | case 0x03: | ||
63 | *src = SND_FF_CLOCK_SRC_SPDIF; | ||
64 | break; | ||
65 | case 0x04: | ||
66 | *src = SND_FF_CLOCK_SRC_WORD; | ||
67 | break; | ||
68 | case 0x05: | ||
69 | *src = SND_FF_CLOCK_SRC_LTC; | ||
70 | break; | ||
71 | case 0x00: | ||
72 | default: | ||
73 | *src = SND_FF_CLOCK_SRC_ADAT; | ||
74 | break; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | static int ff400_begin_session(struct snd_ff *ff, unsigned int rate) | 22 | static int ff400_begin_session(struct snd_ff *ff, unsigned int rate) |
82 | { | 23 | { |
83 | __le32 reg; | 24 | __le32 reg; |
@@ -169,7 +110,6 @@ static int ff400_switch_fetching_mode(struct snd_ff *ff, bool enable) | |||
169 | } | 110 | } |
170 | 111 | ||
171 | const struct snd_ff_protocol snd_ff_protocol_ff400 = { | 112 | const struct snd_ff_protocol snd_ff_protocol_ff400 = { |
172 | .get_clock = ff400_get_clock, | ||
173 | .begin_session = ff400_begin_session, | 113 | .begin_session = ff400_begin_session, |
174 | .finish_session = ff400_finish_session, | 114 | .finish_session = ff400_finish_session, |
175 | .switch_fetching_mode = ff400_switch_fetching_mode, | 115 | .switch_fetching_mode = ff400_switch_fetching_mode, |
diff --git a/sound/firewire/fireface/ff-stream.c b/sound/firewire/fireface/ff-stream.c index 78880922120e..59ca2e84d41c 100644 --- a/sound/firewire/fireface/ff-stream.c +++ b/sound/firewire/fireface/ff-stream.c | |||
@@ -149,7 +149,7 @@ int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate) | |||
149 | if (ff->substreams_counter == 0) | 149 | if (ff->substreams_counter == 0) |
150 | return 0; | 150 | return 0; |
151 | 151 | ||
152 | err = ff->spec->protocol->get_clock(ff, &curr_rate, &src); | 152 | err = snd_ff_transaction_get_clock(ff, &curr_rate, &src); |
153 | if (err < 0) | 153 | if (err < 0) |
154 | return err; | 154 | return err; |
155 | if (curr_rate != rate || | 155 | if (curr_rate != rate || |
diff --git a/sound/firewire/fireface/ff-transaction.c b/sound/firewire/fireface/ff-transaction.c index 332b29f8ed75..1dad51da13e0 100644 --- a/sound/firewire/fireface/ff-transaction.c +++ b/sound/firewire/fireface/ff-transaction.c | |||
@@ -8,6 +8,65 @@ | |||
8 | 8 | ||
9 | #include "ff.h" | 9 | #include "ff.h" |
10 | 10 | ||
11 | int snd_ff_transaction_get_clock(struct snd_ff *ff, unsigned int *rate, | ||
12 | enum snd_ff_clock_src *src) | ||
13 | { | ||
14 | __le32 reg; | ||
15 | u32 data; | ||
16 | int err; | ||
17 | |||
18 | err = snd_fw_transaction(ff->unit, TCODE_READ_QUADLET_REQUEST, | ||
19 | SND_FF_REG_CLOCK_CONFIG, ®, sizeof(reg), 0); | ||
20 | if (err < 0) | ||
21 | return err; | ||
22 | data = le32_to_cpu(reg); | ||
23 | |||
24 | /* Calculate sampling rate. */ | ||
25 | switch ((data >> 1) & 0x03) { | ||
26 | case 0x01: | ||
27 | *rate = 32000; | ||
28 | break; | ||
29 | case 0x00: | ||
30 | *rate = 44100; | ||
31 | break; | ||
32 | case 0x03: | ||
33 | *rate = 48000; | ||
34 | break; | ||
35 | case 0x02: | ||
36 | default: | ||
37 | return -EIO; | ||
38 | } | ||
39 | |||
40 | if (data & 0x08) | ||
41 | *rate *= 2; | ||
42 | else if (data & 0x10) | ||
43 | *rate *= 4; | ||
44 | |||
45 | /* Calculate source of clock. */ | ||
46 | if (data & 0x01) { | ||
47 | *src = SND_FF_CLOCK_SRC_INTERNAL; | ||
48 | } else { | ||
49 | /* TODO: 0x00, 0x01, 0x02, 0x06, 0x07? */ | ||
50 | switch ((data >> 10) & 0x07) { | ||
51 | case 0x03: | ||
52 | *src = SND_FF_CLOCK_SRC_SPDIF; | ||
53 | break; | ||
54 | case 0x04: | ||
55 | *src = SND_FF_CLOCK_SRC_WORD; | ||
56 | break; | ||
57 | case 0x05: | ||
58 | *src = SND_FF_CLOCK_SRC_LTC; | ||
59 | break; | ||
60 | case 0x00: | ||
61 | default: | ||
62 | *src = SND_FF_CLOCK_SRC_ADAT; | ||
63 | break; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
11 | static void finish_transmit_midi_msg(struct snd_ff *ff, unsigned int port, | 70 | static void finish_transmit_midi_msg(struct snd_ff *ff, unsigned int port, |
12 | int rcode) | 71 | int rcode) |
13 | { | 72 | { |
diff --git a/sound/firewire/fireface/ff.h b/sound/firewire/fireface/ff.h index 6dc36a2623b3..cdb1326f65b7 100644 --- a/sound/firewire/fireface/ff.h +++ b/sound/firewire/fireface/ff.h | |||
@@ -101,8 +101,6 @@ enum snd_ff_clock_src { | |||
101 | }; | 101 | }; |
102 | 102 | ||
103 | struct snd_ff_protocol { | 103 | struct snd_ff_protocol { |
104 | int (*get_clock)(struct snd_ff *ff, unsigned int *rate, | ||
105 | enum snd_ff_clock_src *src); | ||
106 | int (*begin_session)(struct snd_ff *ff, unsigned int rate); | 104 | int (*begin_session)(struct snd_ff *ff, unsigned int rate); |
107 | void (*finish_session)(struct snd_ff *ff); | 105 | void (*finish_session)(struct snd_ff *ff); |
108 | int (*switch_fetching_mode)(struct snd_ff *ff, bool enable); | 106 | int (*switch_fetching_mode)(struct snd_ff *ff, bool enable); |
@@ -114,6 +112,8 @@ struct snd_ff_protocol { | |||
114 | 112 | ||
115 | extern const struct snd_ff_protocol snd_ff_protocol_ff400; | 113 | extern const struct snd_ff_protocol snd_ff_protocol_ff400; |
116 | 114 | ||
115 | int snd_ff_transaction_get_clock(struct snd_ff *ff, unsigned int *rate, | ||
116 | enum snd_ff_clock_src *src); | ||
117 | int snd_ff_transaction_register(struct snd_ff *ff); | 117 | int snd_ff_transaction_register(struct snd_ff *ff); |
118 | int snd_ff_transaction_reregister(struct snd_ff *ff); | 118 | int snd_ff_transaction_reregister(struct snd_ff *ff); |
119 | void snd_ff_transaction_unregister(struct snd_ff *ff); | 119 | void snd_ff_transaction_unregister(struct snd_ff *ff); |