only support EABI on ARM targets
[openwrt.git] / package / lqtapi / src / mps / vmmc-coder.c
1 #include <linux/kernel.h>
2
3 #include "vmmc.h"
4 #include "vmmc-cmds.h"
5 #include "vmmc-coder.h"
6 #include "vmmc-module.h"
7 #include "mps.h"
8
9 enum vmmc_coder_encoding {
10 VMMC_CODER_ENCODING_ALAW = 2,
11 VMMC_CODER_ENCODING_MLAW = 3,
12 VMMC_CODER_ENCODING_G726_16 = 4,
13 VMMC_CODER_ENCODING_G726_24 = 5,
14 VMMC_CODER_ENCODING_G726_32 = 6,
15 VMMC_CODER_ENCODING_G726_40 = 7,
16 VMMC_CODER_ENCODING_AMR_4_75 = 8,
17 VMMC_CODER_ENCODING_AMR_5_15 = 9,
18 VMMC_CODER_ENCODING_AMR_5_9 = 10,
19 VMMC_CODER_ENCODING_AMR_6_7 = 11,
20 VMMC_CODER_ENCODING_AMR_7_4 = 12,
21 VMMC_CODER_ENCODING_AMR_7_95 = 13,
22 VMMC_CODER_ENCODING_AMR_10_2 = 14,
23 VMMC_CODER_ENCODING_AMR_12_2 = 15,
24 VMMC_CODER_ENCODING_G728_16 = 16,
25 VMMC_CODER_ENCODING_G729AB_8 = 18,
26 VMMC_CODER_ENCODING_G729E_11_8 = 19,
27 VMMC_CODER_ENCODING_G7221_24 = 20,
28 VMMC_CODER_ENCODING_G7221_32 = 21,
29 VMMC_CODER_ENCODING_G722_64 = 22,
30 VMMC_CODER_ENCODING_L16_8 = 24,
31 VMMC_CODER_ENCODING_L16_16 = 25,
32 VMMC_CODER_ENCODING_ILBC_15_2 = 26,
33 VMMC_CODER_ENCODING_ILBC_13_3 = 27,
34 VMMC_CODER_ENCODING_G7231_5_3 = 28,
35 VMMC_CODER_ENCODING_G7231_6_3 = 29,
36 VMMC_CODER_ENCODING_ALAW_VBD = 30,
37 VMMC_CODER_ENCODING_MLAW_VBD = 31,
38 };
39
40 static const uint8_t vmmc_coder_payload_mapping[] = {
41 [VMMC_CODER_ENCODING_ALAW] = 8,
42 [VMMC_CODER_ENCODING_MLAW] = 0,
43 [VMMC_CODER_ENCODING_G726_16] = 35,
44 [VMMC_CODER_ENCODING_G726_24] = 36,
45 [VMMC_CODER_ENCODING_G726_32] = 37,
46 [VMMC_CODER_ENCODING_G726_40] = 38,
47 [VMMC_CODER_ENCODING_AMR_4_75] = 39,
48 [VMMC_CODER_ENCODING_AMR_5_15] = 40,
49 [VMMC_CODER_ENCODING_AMR_5_9] = 41,
50 [VMMC_CODER_ENCODING_AMR_6_7] = 42,
51 [VMMC_CODER_ENCODING_AMR_7_4] = 43,
52 [VMMC_CODER_ENCODING_AMR_7_95] = 44,
53 [VMMC_CODER_ENCODING_AMR_10_2] = 45,
54 [VMMC_CODER_ENCODING_AMR_12_2] = 46,
55 [VMMC_CODER_ENCODING_G728_16] = 47,
56 [VMMC_CODER_ENCODING_G729AB_8] = 48,
57 [VMMC_CODER_ENCODING_G729E_11_8] = 49,
58 [VMMC_CODER_ENCODING_G7221_24] = 50,
59 [VMMC_CODER_ENCODING_G7221_32] = 51,
60 [VMMC_CODER_ENCODING_G722_64] = 52,
61 [VMMC_CODER_ENCODING_L16_8] = 11,
62 [VMMC_CODER_ENCODING_L16_16] = 10,
63 [VMMC_CODER_ENCODING_ILBC_15_2] = 53,
64 [VMMC_CODER_ENCODING_ILBC_13_3] = 54,
65 [VMMC_CODER_ENCODING_G7231_5_3] = 4,
66 [VMMC_CODER_ENCODING_G7231_6_3] = 4,
67 [VMMC_CODER_ENCODING_ALAW_VBD] = 55,
68 [VMMC_CODER_ENCODING_MLAW_VBD] = 56,
69 };
70
71 static uint32_t payload_enc[9];
72 static uint32_t payload_dec[8];
73
74 static inline struct vmmc_coder *vmmc_module_to_coder(struct vmmc_module *module)
75 {
76 return container_of(module, struct vmmc_coder, module);
77 }
78
79 static int vmmc_coder_enable(struct vmmc_module *module, bool enable)
80 {
81 struct vmmc_coder *coder = vmmc_module_to_coder(module);
82
83 coder->enabled = enable;
84
85 /* coder->cmd_cache[0] = VMMC_CMD_CODER_DATA1(coder->enabled, 0, 0, 0, coder->id,
86 module->pins[0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
87 return vmmc_command_write(coder->vmmc, VMMC_CMD_CODER(coder->id),
88 coder->cmd_cache);*/
89 return 0;
90 }
91
92 static int vmmc_coder_sync(struct vmmc_module *module)
93 {
94 struct vmmc_coder *coder = vmmc_module_to_coder(module);
95
96 coder->cmd_cache[0] = VMMC_CMD_CODER_DATA1(coder->enabled, 0, 1, 1, coder->id,
97 module->pins[0], 1, 1, 1, 1, 1, 1, 0, 0, 0, VMMC_CODER_ENCODING_MLAW);
98 coder->cmd_cache[1] = VMMC_CMD_CODER_DATA2(0x2000, 0x2000);
99 coder->cmd_cache[2] = VMMC_CMD_CODER_DATA3(0, 0, module->pins[1], 0,
100 module->pins[2], 0, module->pins[3], module->pins[4]);
101
102 return vmmc_command_write(coder->vmmc, VMMC_CMD_CODER(coder->id), coder->cmd_cache);
103 }
104
105 static const struct vmmc_module_ops vmmc_coder_module_ops = {
106 .sync = vmmc_coder_sync,
107 .enable = vmmc_coder_enable,
108 };
109
110 #define VMMC_CMD_CODER_JB(_chan) (_VMMC_MSG(6, 3, 18) | _VMMC_CHAN(_chan) | 8)
111 #define VMMC_CMD_CODER_JB_DATA1(_sf, _prp, _pje, _dvf, _nam, _rad, _adap, _init_pod) \
112 (((_sf) << 31) | ((_prp) << 23) | ((_pje) << 22) | ((_dvf) << 21) | \
113 ((_nam) << 20) | ((_rad) << 17) | ((_adap) << 16) | (_init_pod))
114 #define VMMC_CMD_CODER_JB_DATA2(_min_pod, _max_pod) \
115 (((_min_pod) << 16) | (_max_pod))
116 #define VMMC_CMD_CODER_JB_DATA3(_adap_factor, _min_margin, _mode) \
117 (((_adap_factor) << 24) | ((_min_margin) << 16) | (_mode))
118
119 int vmmc_coder_init(struct vmmc_coder *coder, struct vmmc *vmmc, unsigned int id)
120 {
121 int ret;
122
123 ret = vmmc_module_init(&coder->module, 5, &vmmc_coder_module_ops);
124 if (ret)
125 return ret;
126
127 coder->id = id;
128 coder->module.id = id + 0x18;
129 coder->vmmc = vmmc;
130 coder->enabled = 0;
131
132 coder->cmd_cache[0] = VMMC_CMD_CODER_DATA1(0, 0, 0, 0, id, 0,
133 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
134 coder->cmd_cache[1] = VMMC_CMD_CODER_DATA2(0, 0);
135 coder->cmd_cache[2] = VMMC_CMD_CODER_DATA3(0, 0, 0, 0, 0, 0, 0, 0);
136 coder->cmd_cache[3] = VMMC_CMD_CODER_DATA4(0);
137
138 coder->jitter_buffer_cache[0] = VMMC_CMD_CODER_JB_DATA1(0x16, 1, 0, 0, 1, 1,
139 1, 0x50);
140 coder->jitter_buffer_cache[1] = VMMC_CMD_CODER_JB_DATA2(0x50, 0x05a0);
141 coder->jitter_buffer_cache[2] = VMMC_CMD_CODER_JB_DATA3(0x0d, 0x28, 1);
142
143 vmmc_command_write(coder->vmmc, VMMC_CMD_RTP_CFG_US(coder->id), payload_enc);
144 vmmc_command_write(coder->vmmc, VMMC_CMD_RTP_CFG_DS(coder->id), payload_dec);
145 vmmc_command_write(coder->vmmc, VMMC_CMD_CODER_JB(coder->id),
146 coder->jitter_buffer_cache);
147 vmmc_command_write(coder->vmmc, VMMC_CMD_CODER(coder->id), coder->cmd_cache);
148
149 vmmc_register_module(vmmc, &coder->module);
150
151 return ret;
152 }
153
154 void vmmc_coder_event(struct vmmc *vmmc, unsigned int chan, unsigned int type)
155 {
156 }
157
158 /*
159 void vmmc_coder_event(struct vmmc_coder *coder, unsigned int len)
160 {
161 struct sk_buff *skb;
162 provide_mem_region(coder->vmmc, vmmc_coder_alloc_paket(coder)->head, 512);
163
164 skb = skb_dequeue(&coder->paket_queue);
165 skb_put(skb, len);
166
167 tapi_stream_recv(&coder->vmmc->tdev, skb);
168 }
169 */
170 /*
171 int vmmc_coder_set_codec(struct vmmc_coder *coder, enum vmmc_codec codec)
172 {
173 }*/
174
175 void vmmc_init_coders(struct vmmc *vmmc)
176 {
177 unsigned int i;
178
179 payload_enc[0] = 0;
180 payload_enc[1] = 0x0;
181 payload_enc[1] |= vmmc_coder_payload_mapping[2] << 8;
182 payload_enc[1] |= vmmc_coder_payload_mapping[3] << 8;
183 for (i = 2; i < 9; ++i) {
184 payload_enc[i] = vmmc_coder_payload_mapping[i*4 - 4] << 24;
185 payload_enc[i] |= vmmc_coder_payload_mapping[i*4 - 3] << 16;
186 payload_enc[i] |= vmmc_coder_payload_mapping[i*4 - 2] << 8;
187 payload_enc[i] |= vmmc_coder_payload_mapping[i*4 - 1];
188 payload_enc[i] |= 0x80808080;
189 }
190 for (i = 0; i < 7; ++i) {
191 payload_dec[i] = vmmc_coder_payload_mapping[i*4 + 2] << 24;
192 payload_dec[i] |= vmmc_coder_payload_mapping[i*4 + 3] << 16;
193 payload_dec[i] |= vmmc_coder_payload_mapping[i*4 + 4] << 8;
194 payload_dec[i] |= vmmc_coder_payload_mapping[i*4 + 5];
195 }
196 payload_dec[i] = vmmc_coder_payload_mapping[i*4 + 2] << 24;
197 payload_dec[i] |= vmmc_coder_payload_mapping[i*4 + 3] << 16;
198
199
200 vmmc->num_coders = 5;
201 vmmc->coder = kcalloc(sizeof(*vmmc->coder), vmmc->num_coders, GFP_KERNEL);
202
203 for (i = 0; i < vmmc->num_coders; ++i)
204 vmmc_coder_init(&vmmc->coder[i], vmmc, i);
205 }
206
207 struct vmmc_coder *vmmc_coder_get(struct vmmc *vmmc)
208 {
209 unsigned int i;
210 for (i = 0; i < vmmc->num_coders; ++i) {
211 if (!test_and_set_bit(i, &vmmc->coder_used))
212 return &vmmc->coder[i];
213 }
214
215 return NULL;
216 }
217
218 void vmmc_coder_put(struct vmmc *vmmc, struct vmmc_coder *coder)
219 {
220 clear_bit(coder->id, &vmmc->coder_used);
221 }
This page took 0.05385 seconds and 5 git commands to generate.