diff options
author | Antti Palosaari <crope@iki.fi> | 2010-09-12 19:48:58 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-10-20 23:05:52 -0400 |
commit | 9b22edd4b0f3520bc1279338d52dc63e76852bef (patch) | |
tree | 09ff3b882f3bc07fb838570df1b4268f84266871 /drivers/media/dvb | |
parent | d3bb73de97a9685bb150f81017d7e184fdb18451 (diff) |
V4L/DVB: af9013: optimize code size
Optimize af9013_set_coeff(). Move configuration values to own table.
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r-- | drivers/media/dvb/frontends/af9013.c | 194 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/af9013_priv.h | 43 |
2 files changed, 79 insertions, 158 deletions
diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c index 59fe5450a53e..25c5124bfc59 100644 --- a/drivers/media/dvb/frontends/af9013.c +++ b/drivers/media/dvb/frontends/af9013.c | |||
@@ -220,173 +220,50 @@ static u32 af913_div(u32 a, u32 b, u32 x) | |||
220 | 220 | ||
221 | static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw) | 221 | static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw) |
222 | { | 222 | { |
223 | int ret = 0; | 223 | int ret, i, found; |
224 | u8 i = 0; | ||
225 | u8 buf[24]; | 224 | u8 buf[24]; |
226 | u32 uninitialized_var(ns_coeff1_2048nu); | ||
227 | u32 uninitialized_var(ns_coeff1_8191nu); | ||
228 | u32 uninitialized_var(ns_coeff1_8192nu); | ||
229 | u32 uninitialized_var(ns_coeff1_8193nu); | ||
230 | u32 uninitialized_var(ns_coeff2_2k); | ||
231 | u32 uninitialized_var(ns_coeff2_8k); | ||
232 | |||
233 | deb_info("%s: adc_clock:%d bw:%d\n", __func__, | 225 | deb_info("%s: adc_clock:%d bw:%d\n", __func__, |
234 | state->config.adc_clock, bw); | 226 | state->config.adc_clock, bw); |
235 | 227 | ||
236 | switch (state->config.adc_clock) { | 228 | /* lookup coeff from table */ |
237 | case 28800: /* 28.800 MHz */ | 229 | for (i = 0, found = 0; i < ARRAY_SIZE(coeff_table); i++) { |
238 | switch (bw) { | 230 | if (coeff_table[i].adc_clock == state->config.adc_clock && |
239 | case BANDWIDTH_6_MHZ: | 231 | coeff_table[i].bw == bw) { |
240 | ns_coeff1_2048nu = 0x01e79e7a; | 232 | found = 1; |
241 | ns_coeff1_8191nu = 0x0079eb6e; | ||
242 | ns_coeff1_8192nu = 0x0079e79e; | ||
243 | ns_coeff1_8193nu = 0x0079e3cf; | ||
244 | ns_coeff2_2k = 0x00f3cf3d; | ||
245 | ns_coeff2_8k = 0x003cf3cf; | ||
246 | break; | ||
247 | case BANDWIDTH_7_MHZ: | ||
248 | ns_coeff1_2048nu = 0x0238e38e; | ||
249 | ns_coeff1_8191nu = 0x008e3d55; | ||
250 | ns_coeff1_8192nu = 0x008e38e4; | ||
251 | ns_coeff1_8193nu = 0x008e3472; | ||
252 | ns_coeff2_2k = 0x011c71c7; | ||
253 | ns_coeff2_8k = 0x00471c72; | ||
254 | break; | ||
255 | case BANDWIDTH_8_MHZ: | ||
256 | ns_coeff1_2048nu = 0x028a28a3; | ||
257 | ns_coeff1_8191nu = 0x00a28f3d; | ||
258 | ns_coeff1_8192nu = 0x00a28a29; | ||
259 | ns_coeff1_8193nu = 0x00a28514; | ||
260 | ns_coeff2_2k = 0x01451451; | ||
261 | ns_coeff2_8k = 0x00514514; | ||
262 | break; | ||
263 | default: | ||
264 | ret = -EINVAL; | ||
265 | } | ||
266 | break; | ||
267 | case 20480: /* 20.480 MHz */ | ||
268 | switch (bw) { | ||
269 | case BANDWIDTH_6_MHZ: | ||
270 | ns_coeff1_2048nu = 0x02adb6dc; | ||
271 | ns_coeff1_8191nu = 0x00ab7313; | ||
272 | ns_coeff1_8192nu = 0x00ab6db7; | ||
273 | ns_coeff1_8193nu = 0x00ab685c; | ||
274 | ns_coeff2_2k = 0x0156db6e; | ||
275 | ns_coeff2_8k = 0x0055b6dc; | ||
276 | break; | ||
277 | case BANDWIDTH_7_MHZ: | ||
278 | ns_coeff1_2048nu = 0x03200001; | ||
279 | ns_coeff1_8191nu = 0x00c80640; | ||
280 | ns_coeff1_8192nu = 0x00c80000; | ||
281 | ns_coeff1_8193nu = 0x00c7f9c0; | ||
282 | ns_coeff2_2k = 0x01900000; | ||
283 | ns_coeff2_8k = 0x00640000; | ||
284 | break; | ||
285 | case BANDWIDTH_8_MHZ: | ||
286 | ns_coeff1_2048nu = 0x03924926; | ||
287 | ns_coeff1_8191nu = 0x00e4996e; | ||
288 | ns_coeff1_8192nu = 0x00e49249; | ||
289 | ns_coeff1_8193nu = 0x00e48b25; | ||
290 | ns_coeff2_2k = 0x01c92493; | ||
291 | ns_coeff2_8k = 0x00724925; | ||
292 | break; | ||
293 | default: | ||
294 | ret = -EINVAL; | ||
295 | } | ||
296 | break; | ||
297 | case 28000: /* 28.000 MHz */ | ||
298 | switch (bw) { | ||
299 | case BANDWIDTH_6_MHZ: | ||
300 | ns_coeff1_2048nu = 0x01f58d10; | ||
301 | ns_coeff1_8191nu = 0x007d672f; | ||
302 | ns_coeff1_8192nu = 0x007d6344; | ||
303 | ns_coeff1_8193nu = 0x007d5f59; | ||
304 | ns_coeff2_2k = 0x00fac688; | ||
305 | ns_coeff2_8k = 0x003eb1a2; | ||
306 | break; | ||
307 | case BANDWIDTH_7_MHZ: | ||
308 | ns_coeff1_2048nu = 0x02492492; | ||
309 | ns_coeff1_8191nu = 0x00924db7; | ||
310 | ns_coeff1_8192nu = 0x00924925; | ||
311 | ns_coeff1_8193nu = 0x00924492; | ||
312 | ns_coeff2_2k = 0x01249249; | ||
313 | ns_coeff2_8k = 0x00492492; | ||
314 | break; | 233 | break; |
315 | case BANDWIDTH_8_MHZ: | ||
316 | ns_coeff1_2048nu = 0x029cbc15; | ||
317 | ns_coeff1_8191nu = 0x00a7343f; | ||
318 | ns_coeff1_8192nu = 0x00a72f05; | ||
319 | ns_coeff1_8193nu = 0x00a729cc; | ||
320 | ns_coeff2_2k = 0x014e5e0a; | ||
321 | ns_coeff2_8k = 0x00539783; | ||
322 | break; | ||
323 | default: | ||
324 | ret = -EINVAL; | ||
325 | } | ||
326 | break; | ||
327 | case 25000: /* 25.000 MHz */ | ||
328 | switch (bw) { | ||
329 | case BANDWIDTH_6_MHZ: | ||
330 | ns_coeff1_2048nu = 0x0231bcb5; | ||
331 | ns_coeff1_8191nu = 0x008c7391; | ||
332 | ns_coeff1_8192nu = 0x008c6f2d; | ||
333 | ns_coeff1_8193nu = 0x008c6aca; | ||
334 | ns_coeff2_2k = 0x0118de5b; | ||
335 | ns_coeff2_8k = 0x00463797; | ||
336 | break; | ||
337 | case BANDWIDTH_7_MHZ: | ||
338 | ns_coeff1_2048nu = 0x028f5c29; | ||
339 | ns_coeff1_8191nu = 0x00a3dc29; | ||
340 | ns_coeff1_8192nu = 0x00a3d70a; | ||
341 | ns_coeff1_8193nu = 0x00a3d1ec; | ||
342 | ns_coeff2_2k = 0x0147ae14; | ||
343 | ns_coeff2_8k = 0x0051eb85; | ||
344 | break; | ||
345 | case BANDWIDTH_8_MHZ: | ||
346 | ns_coeff1_2048nu = 0x02ecfb9d; | ||
347 | ns_coeff1_8191nu = 0x00bb44c1; | ||
348 | ns_coeff1_8192nu = 0x00bb3ee7; | ||
349 | ns_coeff1_8193nu = 0x00bb390d; | ||
350 | ns_coeff2_2k = 0x01767dce; | ||
351 | ns_coeff2_8k = 0x005d9f74; | ||
352 | break; | ||
353 | default: | ||
354 | ret = -EINVAL; | ||
355 | } | 234 | } |
356 | break; | ||
357 | default: | ||
358 | err("invalid xtal"); | ||
359 | return -EINVAL; | ||
360 | } | 235 | } |
361 | if (ret) { | 236 | |
362 | err("invalid bandwidth"); | 237 | if (!found) { |
363 | return ret; | 238 | err("invalid bw or clock"); |
239 | ret = -EINVAL; | ||
240 | goto error; | ||
364 | } | 241 | } |
365 | 242 | ||
366 | buf[i++] = (u8) ((ns_coeff1_2048nu & 0x03000000) >> 24); | 243 | buf[0] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x03000000) >> 24); |
367 | buf[i++] = (u8) ((ns_coeff1_2048nu & 0x00ff0000) >> 16); | 244 | buf[1] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x00ff0000) >> 16); |
368 | buf[i++] = (u8) ((ns_coeff1_2048nu & 0x0000ff00) >> 8); | 245 | buf[2] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x0000ff00) >> 8); |
369 | buf[i++] = (u8) ((ns_coeff1_2048nu & 0x000000ff)); | 246 | buf[3] = (u8) ((coeff_table[i].ns_coeff1_2048nu & 0x000000ff)); |
370 | buf[i++] = (u8) ((ns_coeff2_2k & 0x01c00000) >> 22); | 247 | buf[4] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x01c00000) >> 22); |
371 | buf[i++] = (u8) ((ns_coeff2_2k & 0x003fc000) >> 14); | 248 | buf[5] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x003fc000) >> 14); |
372 | buf[i++] = (u8) ((ns_coeff2_2k & 0x00003fc0) >> 6); | 249 | buf[6] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x00003fc0) >> 6); |
373 | buf[i++] = (u8) ((ns_coeff2_2k & 0x0000003f)); | 250 | buf[7] = (u8) ((coeff_table[i].ns_coeff2_2k & 0x0000003f)); |
374 | buf[i++] = (u8) ((ns_coeff1_8191nu & 0x03000000) >> 24); | 251 | buf[8] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x03000000) >> 24); |
375 | buf[i++] = (u8) ((ns_coeff1_8191nu & 0x00ffc000) >> 16); | 252 | buf[9] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x00ffc000) >> 16); |
376 | buf[i++] = (u8) ((ns_coeff1_8191nu & 0x0000ff00) >> 8); | 253 | buf[10] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x0000ff00) >> 8); |
377 | buf[i++] = (u8) ((ns_coeff1_8191nu & 0x000000ff)); | 254 | buf[11] = (u8) ((coeff_table[i].ns_coeff1_8191nu & 0x000000ff)); |
378 | buf[i++] = (u8) ((ns_coeff1_8192nu & 0x03000000) >> 24); | 255 | buf[12] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x03000000) >> 24); |
379 | buf[i++] = (u8) ((ns_coeff1_8192nu & 0x00ffc000) >> 16); | 256 | buf[13] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x00ffc000) >> 16); |
380 | buf[i++] = (u8) ((ns_coeff1_8192nu & 0x0000ff00) >> 8); | 257 | buf[14] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x0000ff00) >> 8); |
381 | buf[i++] = (u8) ((ns_coeff1_8192nu & 0x000000ff)); | 258 | buf[15] = (u8) ((coeff_table[i].ns_coeff1_8192nu & 0x000000ff)); |
382 | buf[i++] = (u8) ((ns_coeff1_8193nu & 0x03000000) >> 24); | 259 | buf[16] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x03000000) >> 24); |
383 | buf[i++] = (u8) ((ns_coeff1_8193nu & 0x00ffc000) >> 16); | 260 | buf[17] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x00ffc000) >> 16); |
384 | buf[i++] = (u8) ((ns_coeff1_8193nu & 0x0000ff00) >> 8); | 261 | buf[18] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x0000ff00) >> 8); |
385 | buf[i++] = (u8) ((ns_coeff1_8193nu & 0x000000ff)); | 262 | buf[19] = (u8) ((coeff_table[i].ns_coeff1_8193nu & 0x000000ff)); |
386 | buf[i++] = (u8) ((ns_coeff2_8k & 0x01c00000) >> 22); | 263 | buf[20] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x01c00000) >> 22); |
387 | buf[i++] = (u8) ((ns_coeff2_8k & 0x003fc000) >> 14); | 264 | buf[21] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x003fc000) >> 14); |
388 | buf[i++] = (u8) ((ns_coeff2_8k & 0x00003fc0) >> 6); | 265 | buf[22] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x00003fc0) >> 6); |
389 | buf[i++] = (u8) ((ns_coeff2_8k & 0x0000003f)); | 266 | buf[23] = (u8) ((coeff_table[i].ns_coeff2_8k & 0x0000003f)); |
390 | 267 | ||
391 | deb_info("%s: coeff:", __func__); | 268 | deb_info("%s: coeff:", __func__); |
392 | debug_dump(buf, sizeof(buf), deb_info); | 269 | debug_dump(buf, sizeof(buf), deb_info); |
@@ -398,6 +275,7 @@ static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw) | |||
398 | break; | 275 | break; |
399 | } | 276 | } |
400 | 277 | ||
278 | error: | ||
401 | return ret; | 279 | return ret; |
402 | } | 280 | } |
403 | 281 | ||
diff --git a/drivers/media/dvb/frontends/af9013_priv.h b/drivers/media/dvb/frontends/af9013_priv.h index 54ebf87551a2..fc9a32d9e632 100644 --- a/drivers/media/dvb/frontends/af9013_priv.h +++ b/drivers/media/dvb/frontends/af9013_priv.h | |||
@@ -60,6 +60,49 @@ struct snr_table { | |||
60 | u8 snr; | 60 | u8 snr; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | struct coeff { | ||
64 | u32 adc_clock; | ||
65 | fe_bandwidth_t bw; | ||
66 | u32 ns_coeff1_2048nu; | ||
67 | u32 ns_coeff1_8191nu; | ||
68 | u32 ns_coeff1_8192nu; | ||
69 | u32 ns_coeff1_8193nu; | ||
70 | u32 ns_coeff2_2k; | ||
71 | u32 ns_coeff2_8k; | ||
72 | }; | ||
73 | |||
74 | /* coeff lookup table */ | ||
75 | static struct coeff coeff_table[] = { | ||
76 | /* 28.800 MHz */ | ||
77 | { 28800, BANDWIDTH_6_MHZ, 0x01e79e7a, 0x0079eb6e, 0x0079e79e, | ||
78 | 0x0079e3cf, 0x00f3cf3d, 0x003cf3cf }, | ||
79 | { 28800, BANDWIDTH_7_MHZ, 0x0238e38e, 0x008e3d55, 0x008e38e4, | ||
80 | 0x008e3472, 0x011c71c7, 0x00471c72 }, | ||
81 | { 28800, BANDWIDTH_8_MHZ, 0x028a28a3, 0x00a28f3d, 0x00a28a29, | ||
82 | 0x00a28514, 0x01451451, 0x00514514 }, | ||
83 | /* 20.480 MHz */ | ||
84 | { 20480, BANDWIDTH_6_MHZ, 0x02adb6dc, 0x00ab7313, 0x00ab6db7, | ||
85 | 0x00ab685c, 0x0156db6e, 0x0055b6dc }, | ||
86 | { 20480, BANDWIDTH_7_MHZ, 0x03200001, 0x00c80640, 0x00c80000, | ||
87 | 0x00c7f9c0, 0x01900000, 0x00640000 }, | ||
88 | { 20480, BANDWIDTH_8_MHZ, 0x03924926, 0x00e4996e, 0x00e49249, | ||
89 | 0x00e48b25, 0x01c92493, 0x00724925 }, | ||
90 | /* 28.000 MHz */ | ||
91 | { 28000, BANDWIDTH_6_MHZ, 0x01f58d10, 0x007d672f, 0x007d6344, | ||
92 | 0x007d5f59, 0x00fac688, 0x003eb1a2 }, | ||
93 | { 28000, BANDWIDTH_7_MHZ, 0x02492492, 0x00924db7, 0x00924925, | ||
94 | 0x00924492, 0x01249249, 0x00492492 }, | ||
95 | { 28000, BANDWIDTH_8_MHZ, 0x029cbc15, 0x00a7343f, 0x00a72f05, | ||
96 | 0x00a729cc, 0x014e5e0a, 0x00539783 }, | ||
97 | /* 25.000 MHz */ | ||
98 | { 25000, BANDWIDTH_6_MHZ, 0x0231bcb5, 0x008c7391, 0x008c6f2d, | ||
99 | 0x008c6aca, 0x0118de5b, 0x00463797 }, | ||
100 | { 25000, BANDWIDTH_7_MHZ, 0x028f5c29, 0x00a3dc29, 0x00a3d70a, | ||
101 | 0x00a3d1ec, 0x0147ae14, 0x0051eb85 }, | ||
102 | { 25000, BANDWIDTH_8_MHZ, 0x02ecfb9d, 0x00bb44c1, 0x00bb3ee7, | ||
103 | 0x00bb390d, 0x01767dce, 0x005d9f74 }, | ||
104 | }; | ||
105 | |||
63 | /* QPSK SNR lookup table */ | 106 | /* QPSK SNR lookup table */ |
64 | static struct snr_table qpsk_snr_table[] = { | 107 | static struct snr_table qpsk_snr_table[] = { |
65 | { 0x0b4771, 0 }, | 108 | { 0x0b4771, 0 }, |