diff options
author | John W. Linville <linville@tuxdriver.com> | 2011-06-08 13:44:21 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2011-06-08 13:44:21 -0400 |
commit | c0c33addcba2ce753b4e2746db99feaae2f82a85 (patch) | |
tree | dab480183ac0e64bfe9250e1f294705d1a424c78 /lib | |
parent | ffbc03bc75b39c7bd412e7cc6d2185c11b0ffedd (diff) | |
parent | 931749bf78b969c54de9bbc67cf29b13a40bb73b (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6 into for-davem
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 14 | ||||
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/cordic.c | 101 | ||||
-rw-r--r-- | lib/crc8.c | 86 |
4 files changed, 204 insertions, 0 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 830181cc7a83..32f3e5ae2be5 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -79,6 +79,13 @@ config LIBCRC32C | |||
79 | require M here. See Castagnoli93. | 79 | require M here. See Castagnoli93. |
80 | Module will be libcrc32c. | 80 | Module will be libcrc32c. |
81 | 81 | ||
82 | config CRC8 | ||
83 | tristate "CRC8 function" | ||
84 | help | ||
85 | This option provides CRC8 function. Drivers may select this | ||
86 | when they need to do cyclic redundancy check according CRC8 | ||
87 | algorithm. Module will be called crc8. | ||
88 | |||
82 | config AUDIT_GENERIC | 89 | config AUDIT_GENERIC |
83 | bool | 90 | bool |
84 | depends on AUDIT && !AUDIT_ARCH | 91 | depends on AUDIT && !AUDIT_ARCH |
@@ -262,4 +269,11 @@ config AVERAGE | |||
262 | 269 | ||
263 | If unsure, say N. | 270 | If unsure, say N. |
264 | 271 | ||
272 | config CORDIC | ||
273 | tristate "Cordic function" | ||
274 | help | ||
275 | The option provides arithmetic function using cordic algorithm | ||
276 | so its calculations are in fixed point. Modules can select this | ||
277 | when they require this function. Module will be called cordic. | ||
278 | |||
265 | endmenu | 279 | endmenu |
diff --git a/lib/Makefile b/lib/Makefile index 6b597fdb1898..892f4e282ea1 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -61,6 +61,7 @@ obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o | |||
61 | obj-$(CONFIG_CRC32) += crc32.o | 61 | obj-$(CONFIG_CRC32) += crc32.o |
62 | obj-$(CONFIG_CRC7) += crc7.o | 62 | obj-$(CONFIG_CRC7) += crc7.o |
63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o | 63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o |
64 | obj-$(CONFIG_CRC8) += crc8.o | ||
64 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o | 65 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o |
65 | 66 | ||
66 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ | 67 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ |
@@ -112,6 +113,8 @@ obj-$(CONFIG_AVERAGE) += average.o | |||
112 | 113 | ||
113 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | 114 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o |
114 | 115 | ||
116 | obj-$(CONFIG_CORDIC) += cordic.o | ||
117 | |||
115 | hostprogs-y := gen_crc32table | 118 | hostprogs-y := gen_crc32table |
116 | clean-files := crc32table.h | 119 | clean-files := crc32table.h |
117 | 120 | ||
diff --git a/lib/cordic.c b/lib/cordic.c new file mode 100644 index 000000000000..aa27a88d7e04 --- /dev/null +++ b/lib/cordic.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2011 Broadcom Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/cordic.h> | ||
18 | |||
19 | #define CORDIC_ANGLE_GEN 39797 | ||
20 | #define CORDIC_PRECISION_SHIFT 16 | ||
21 | #define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2) | ||
22 | |||
23 | #define FIXED(X) ((s32)((X) << CORDIC_PRECISION_SHIFT)) | ||
24 | #define FLOAT(X) (((X) >= 0) \ | ||
25 | ? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \ | ||
26 | : -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1)) | ||
27 | |||
28 | static const s32 arctan_table[] = { | ||
29 | 2949120, | ||
30 | 1740967, | ||
31 | 919879, | ||
32 | 466945, | ||
33 | 234379, | ||
34 | 117304, | ||
35 | 58666, | ||
36 | 29335, | ||
37 | 14668, | ||
38 | 7334, | ||
39 | 3667, | ||
40 | 1833, | ||
41 | 917, | ||
42 | 458, | ||
43 | 229, | ||
44 | 115, | ||
45 | 57, | ||
46 | 29 | ||
47 | }; | ||
48 | |||
49 | /* | ||
50 | * cordic_calc_iq() - calculates the i/q coordinate for given angle | ||
51 | * | ||
52 | * theta: angle in degrees for which i/q coordinate is to be calculated | ||
53 | * coord: function output parameter holding the i/q coordinate | ||
54 | */ | ||
55 | struct cordic_iq cordic_calc_iq(s32 theta) | ||
56 | { | ||
57 | struct cordic_iq coord; | ||
58 | s32 angle, valtmp; | ||
59 | unsigned iter; | ||
60 | int signx = 1; | ||
61 | int signtheta; | ||
62 | |||
63 | coord.i = CORDIC_ANGLE_GEN; | ||
64 | coord.q = 0; | ||
65 | angle = 0; | ||
66 | |||
67 | theta = FIXED(theta); | ||
68 | signtheta = (theta < 0) ? -1 : 1; | ||
69 | theta = ((theta + FIXED(180) * signtheta) % FIXED(360)) - | ||
70 | FIXED(180) * signtheta; | ||
71 | |||
72 | if (FLOAT(theta) > 90) { | ||
73 | theta -= FIXED(180); | ||
74 | signx = -1; | ||
75 | } else if (FLOAT(theta) < -90) { | ||
76 | theta += FIXED(180); | ||
77 | signx = -1; | ||
78 | } | ||
79 | |||
80 | for (iter = 0; iter < CORDIC_NUM_ITER; iter++) { | ||
81 | if (theta > angle) { | ||
82 | valtmp = coord.i - (coord.q >> iter); | ||
83 | coord.q += (coord.i >> iter); | ||
84 | angle += arctan_table[iter]; | ||
85 | } else { | ||
86 | valtmp = coord.i + (coord.q >> iter); | ||
87 | coord.q -= (coord.i >> iter); | ||
88 | angle -= arctan_table[iter]; | ||
89 | } | ||
90 | coord.i = valtmp; | ||
91 | } | ||
92 | |||
93 | coord.i *= signx; | ||
94 | coord.q *= signx; | ||
95 | return coord; | ||
96 | } | ||
97 | EXPORT_SYMBOL(cordic_calc_iq); | ||
98 | |||
99 | MODULE_DESCRIPTION("Cordic functions"); | ||
100 | MODULE_AUTHOR("Broadcom Corporation"); | ||
101 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/crc8.c b/lib/crc8.c new file mode 100644 index 000000000000..87b59cafdb83 --- /dev/null +++ b/lib/crc8.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2011 Broadcom Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/crc8.h> | ||
21 | #include <linux/printk.h> | ||
22 | |||
23 | /* | ||
24 | * crc8_populate_msb - fill crc table for given polynomial in reverse bit order. | ||
25 | * | ||
26 | * table: table to be filled. | ||
27 | * polynomial: polynomial for which table is to be filled. | ||
28 | */ | ||
29 | void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
30 | { | ||
31 | int i, j; | ||
32 | const u8 msbit = 0x80; | ||
33 | u8 t = msbit; | ||
34 | |||
35 | table[0] = 0; | ||
36 | |||
37 | for (i = 1; i < CRC8_TABLE_SIZE; i *= 2) { | ||
38 | t = (t << 1) ^ (t & msbit ? polynomial : 0); | ||
39 | for (j = 0; j < i; j++) | ||
40 | table[i+j] = table[j] ^ t; | ||
41 | } | ||
42 | } | ||
43 | EXPORT_SYMBOL(crc8_populate_msb); | ||
44 | |||
45 | /* | ||
46 | * crc8_populate_lsb - fill crc table for given polynomial in regular bit order. | ||
47 | * | ||
48 | * table: table to be filled. | ||
49 | * polynomial: polynomial for which table is to be filled. | ||
50 | */ | ||
51 | void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
52 | { | ||
53 | int i, j; | ||
54 | u8 t = 1; | ||
55 | |||
56 | table[0] = 0; | ||
57 | |||
58 | for (i = (CRC8_TABLE_SIZE >> 1); i; i >>= 1) { | ||
59 | t = (t >> 1) ^ (t & 1 ? polynomial : 0); | ||
60 | for (j = 0; j < CRC8_TABLE_SIZE; j += 2*i) | ||
61 | table[i+j] = table[j] ^ t; | ||
62 | } | ||
63 | } | ||
64 | EXPORT_SYMBOL(crc8_populate_lsb); | ||
65 | |||
66 | /* | ||
67 | * crc8 - calculate a crc8 over the given input data. | ||
68 | * | ||
69 | * table: crc table used for calculation. | ||
70 | * pdata: pointer to data buffer. | ||
71 | * nbytes: number of bytes in data buffer. | ||
72 | * crc: previous returned crc8 value. | ||
73 | */ | ||
74 | u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc) | ||
75 | { | ||
76 | /* loop over the buffer data */ | ||
77 | while (nbytes-- > 0) | ||
78 | crc = table[(crc ^ *pdata++) & 0xff]; | ||
79 | |||
80 | return crc; | ||
81 | } | ||
82 | EXPORT_SYMBOL(crc8); | ||
83 | |||
84 | MODULE_DESCRIPTION("CRC8 (by Williams, Ross N.) function"); | ||
85 | MODULE_AUTHOR("Broadcom Corporation"); | ||
86 | MODULE_LICENSE("Dual BSD/GPL"); | ||