Merge branch 'master' into radar
[carl9170fw.git] / carlfw / include / radar.h
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * Radar pulse definitions
5  *
6  * Copyright 2012 Christian Lamparter <chunkeey@googlemail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __CARL9170FW_RADAR_H
24 #define __CARL9170FW_RADAR_H
25
26 #include "generated/autoconf.h"
27 #include "types.h"
28 #include "compiler.h"
29 #include "fwdesc.h"
30
31 enum RADAR_TYPE {
32         NO_RADAR = 0,
33         ONE_KHZ,
34         TEN_KHZ,
35
36         ONE_TWO_KHZ,
37
38         FCC1,
39         FCC4,
40
41         ETSIFIXED,
42
43         /* keep last */
44         __CARL9170FW_NUM_RADARS
45 };
46
47 struct radar_info {
48         unsigned int pulses;
49         const struct radar_info_pattern *pattern;
50 };
51
52 struct radar_info_pattern {
53         unsigned int pulse_width;
54         unsigned int pulse_interval;
55         uint32_t     pulse_pattern;
56         uint32_t     pulse_mode;
57 };
58
59 static const struct radar_info_pattern radar_NO_RADAR[0] = {  };
60 static const struct radar_info_pattern radar_ONE_KHZ[] = {
61         {
62                 .pulse_width = 1,
63                 .pulse_interval = 1000,
64                 .pulse_pattern = 0xa7438080,
65                 .pulse_mode    = 0x5f01,
66         },
67 };
68
69 static const struct radar_info_pattern radar_TEN_KHZ[] = {
70         {
71                 .pulse_width = 1,
72                 .pulse_interval = 100,
73                 .pulse_pattern = 0x436f0001,
74                 .pulse_mode    = 0x5f01,
75         },
76 };
77
78 static const struct radar_info_pattern radar_ONE_TWO_KHZ[] = {
79         {
80                 .pulse_width = 1,
81                 .pulse_interval = 1000,
82                 .pulse_pattern = 0xa7438080,
83                 .pulse_mode    = 0x5f01,
84         },
85
86         {
87                 .pulse_width = 10,
88                 .pulse_interval = 500,
89                 .pulse_pattern = 0xa7431001,
90                 .pulse_mode    = 0x5f01,
91         },
92 };
93
94 /*
95  * Data taken from:
96  * <http://linuxwireless.org/en/developers/DFS>
97  */
98
99 /* FCC Test Signal 1 - 1us pulse, 1428 us interval */
100 static const struct radar_info_pattern radar_FCC1[] = {
101         {
102                 .pulse_width = 1,
103                 .pulse_interval = 1428,
104                 .pulse_pattern = 0xa7438080,
105                 .pulse_mode    = 0x5f01,
106         },
107 };
108
109 /* FCC Test Signal 4 - 11-20us pulse, 200-500 us interval */
110 static const struct radar_info_pattern radar_FCC4[] = {
111         {
112                 .pulse_width = 11,
113                 .pulse_interval = 200,
114                 .pulse_pattern = 0xf3128008,
115                 .pulse_mode    = 0x5f01,
116         },
117 };
118
119 /* ETSI Test Signal 1 (Fixed) - 1us Pulse, 750 us interval */
120 static const struct radar_info_pattern radar_ETSIFIXED[] = {
121         {
122                 .pulse_width = 1,
123                 .pulse_interval = 750,
124                 .pulse_pattern = 0x8a5f8080,
125                 .pulse_mode    = 0x5f01,
126         },
127 };
128
129
130 #define ADD_RADAR(name) [name] = { .pulses = ARRAY_SIZE(radar_## name), .pattern = radar_## name }
131
132 static const struct radar_info radars[__CARL9170FW_NUM_RADARS] = {
133         ADD_RADAR(NO_RADAR),
134         ADD_RADAR(ONE_KHZ),
135         ADD_RADAR(TEN_KHZ),
136         ADD_RADAR(ONE_TWO_KHZ),
137         ADD_RADAR(FCC1),
138         ADD_RADAR(FCC4),
139         ADD_RADAR(ETSIFIXED),
140 };
141
142 #define MAP_ENTRY(idx) [idx] = { .index = idx, .name = # idx , }
143 #define NAMED_MAP_ENTRY(idx, named) [idx] = {.index = idx, .name = named, }
144
145 static const struct carl9170fw_radar_map_entry radar_names[__CARL9170FW_NUM_RADARS] = {
146         MAP_ENTRY(NO_RADAR),
147         MAP_ENTRY(ONE_KHZ),
148         MAP_ENTRY(TEN_KHZ),
149         MAP_ENTRY(ONE_TWO_KHZ),
150
151         MAP_ENTRY(FCC1),
152         MAP_ENTRY(FCC4),
153
154         MAP_ENTRY(ETSIFIXED),
155 };
156
157 #endif /* __CARL9170FW_RADAR_H */