Commit | Line | Data |
---|---|---|
4dbf5056 MG |
1 | /* |
2 | * Greybus Audio Device Class Protocol helpers | |
3 | * | |
4 | * Copyright 2015-2016 Google Inc. | |
5 | * | |
6 | * Released under the GPLv2 only. | |
7 | */ | |
8 | ||
9 | #include "greybus.h" | |
10 | #include "greybus_protocols.h" | |
11 | #include "audio_apbridgea.h" | |
1045451f | 12 | #include "audio_codec.h" |
4dbf5056 MG |
13 | |
14 | int gb_audio_apbridgea_set_config(struct gb_connection *connection, | |
15 | __u16 i2s_port, __u32 format, __u32 rate, | |
16 | __u32 mclk_freq) | |
17 | { | |
18 | struct audio_apbridgea_set_config_request req; | |
19 | ||
20 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_SET_CONFIG; | |
21 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
22 | req.format = cpu_to_le32(format); | |
23 | req.rate = cpu_to_le32(rate); | |
24 | req.mclk_freq = cpu_to_le32(mclk_freq); | |
25 | ||
26 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
27 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
28 | } | |
29 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_set_config); | |
30 | ||
31 | int gb_audio_apbridgea_register_cport(struct gb_connection *connection, | |
4a8e5199 MG |
32 | __u16 i2s_port, __u16 cportid, |
33 | __u8 direction) | |
4dbf5056 MG |
34 | { |
35 | struct audio_apbridgea_register_cport_request req; | |
6ba7fad4 | 36 | int ret; |
4dbf5056 MG |
37 | |
38 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_REGISTER_CPORT; | |
39 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
40 | req.cport = cpu_to_le16(cportid); | |
4a8e5199 | 41 | req.direction = direction; |
4dbf5056 | 42 | |
6ba7fad4 DL |
43 | ret = gb_pm_runtime_get_sync(connection->bundle); |
44 | if (ret) | |
45 | return ret; | |
46 | ||
4dbf5056 MG |
47 | return gb_hd_output(connection->hd, &req, sizeof(req), |
48 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
49 | } | |
50 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_register_cport); | |
51 | ||
52 | int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection, | |
4a8e5199 MG |
53 | __u16 i2s_port, __u16 cportid, |
54 | __u8 direction) | |
4dbf5056 MG |
55 | { |
56 | struct audio_apbridgea_unregister_cport_request req; | |
6ba7fad4 | 57 | int ret; |
4dbf5056 MG |
58 | |
59 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_UNREGISTER_CPORT; | |
60 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
61 | req.cport = cpu_to_le16(cportid); | |
4a8e5199 | 62 | req.direction = direction; |
4dbf5056 | 63 | |
6ba7fad4 DL |
64 | ret = gb_hd_output(connection->hd, &req, sizeof(req), |
65 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
66 | ||
67 | gb_pm_runtime_put_autosuspend(connection->bundle); | |
68 | ||
69 | return ret; | |
4dbf5056 MG |
70 | } |
71 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_unregister_cport); | |
72 | ||
73 | int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection, | |
74 | __u16 i2s_port, __u16 size) | |
75 | { | |
76 | struct audio_apbridgea_set_tx_data_size_request req; | |
77 | ||
78 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_SET_TX_DATA_SIZE; | |
79 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
80 | req.size = cpu_to_le16(size); | |
81 | ||
82 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
83 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
84 | } | |
85 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_set_tx_data_size); | |
86 | ||
5bbe14b7 MG |
87 | int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection, |
88 | __u16 i2s_port) | |
89 | { | |
90 | struct audio_apbridgea_prepare_tx_request req; | |
91 | ||
92 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_PREPARE_TX; | |
93 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
94 | ||
95 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
96 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
97 | } | |
98 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_prepare_tx); | |
99 | ||
4dbf5056 MG |
100 | int gb_audio_apbridgea_start_tx(struct gb_connection *connection, |
101 | __u16 i2s_port, __u64 timestamp) | |
102 | { | |
103 | struct audio_apbridgea_start_tx_request req; | |
104 | ||
105 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_START_TX; | |
106 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
107 | req.timestamp = cpu_to_le64(timestamp); | |
108 | ||
109 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
110 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
111 | } | |
112 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_start_tx); | |
113 | ||
114 | int gb_audio_apbridgea_stop_tx(struct gb_connection *connection, __u16 i2s_port) | |
115 | { | |
116 | struct audio_apbridgea_stop_tx_request req; | |
117 | ||
118 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_STOP_TX; | |
119 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
120 | ||
121 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
122 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
123 | } | |
124 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_stop_tx); | |
125 | ||
5bbe14b7 MG |
126 | int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection, |
127 | __u16 i2s_port) | |
128 | { | |
129 | struct audio_apbridgea_shutdown_tx_request req; | |
130 | ||
131 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_SHUTDOWN_TX; | |
132 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
133 | ||
134 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
135 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
136 | } | |
137 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_shutdown_tx); | |
138 | ||
4dbf5056 MG |
139 | int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection, |
140 | __u16 i2s_port, __u16 size) | |
141 | { | |
142 | struct audio_apbridgea_set_rx_data_size_request req; | |
143 | ||
144 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_SET_RX_DATA_SIZE; | |
145 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
146 | req.size = cpu_to_le16(size); | |
147 | ||
148 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
149 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
150 | } | |
151 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_set_rx_data_size); | |
152 | ||
5bbe14b7 MG |
153 | int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection, |
154 | __u16 i2s_port) | |
155 | { | |
156 | struct audio_apbridgea_prepare_rx_request req; | |
157 | ||
158 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_PREPARE_RX; | |
159 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
160 | ||
161 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
162 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
163 | } | |
164 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_prepare_rx); | |
165 | ||
4dbf5056 MG |
166 | int gb_audio_apbridgea_start_rx(struct gb_connection *connection, |
167 | __u16 i2s_port) | |
168 | { | |
169 | struct audio_apbridgea_start_rx_request req; | |
170 | ||
171 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_START_RX; | |
172 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
173 | ||
174 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
175 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
176 | } | |
177 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_start_rx); | |
178 | ||
179 | int gb_audio_apbridgea_stop_rx(struct gb_connection *connection, __u16 i2s_port) | |
180 | { | |
181 | struct audio_apbridgea_stop_rx_request req; | |
182 | ||
183 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_STOP_RX; | |
184 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
185 | ||
186 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
187 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
188 | } | |
189 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_stop_rx); | |
190 | ||
5bbe14b7 MG |
191 | int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection, |
192 | __u16 i2s_port) | |
193 | { | |
194 | struct audio_apbridgea_shutdown_rx_request req; | |
195 | ||
196 | req.hdr.type = AUDIO_APBRIDGEA_TYPE_SHUTDOWN_RX; | |
197 | req.hdr.i2s_port = cpu_to_le16(i2s_port); | |
198 | ||
199 | return gb_hd_output(connection->hd, &req, sizeof(req), | |
200 | GB_APB_REQUEST_AUDIO_CONTROL, true); | |
201 | } | |
202 | EXPORT_SYMBOL_GPL(gb_audio_apbridgea_shutdown_rx); | |
203 | ||
4dbf5056 MG |
204 | MODULE_LICENSE("GPL v2"); |
205 | MODULE_ALIAS("greybus:audio-apbridgea"); | |
206 | MODULE_DESCRIPTION("Greybus Special APBridgeA Audio Protocol library"); | |
207 | MODULE_AUTHOR("Mark Greer <mgreer@animalcreek.com>"); |