added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / uwb / radio.c
blobf0d55495f5e983190eac44bd95b2b08e4e9a38c7
1 /*
2 * UWB radio (channel) management.
4 * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/kernel.h>
19 #include <linux/uwb.h>
21 #include "uwb-internal.h"
24 static int uwb_radio_select_channel(struct uwb_rc *rc)
27 * Default to channel 9 (BG1, TFC1) unless the user has
28 * selected a specific channel or there are no active PALs.
30 if (rc->active_pals == 0)
31 return -1;
32 if (rc->beaconing_forced)
33 return rc->beaconing_forced;
34 return 9;
39 * Notify all active PALs that the channel has changed.
41 static void uwb_radio_channel_changed(struct uwb_rc *rc, int channel)
43 struct uwb_pal *pal;
45 list_for_each_entry(pal, &rc->pals, node) {
46 if (pal->channel && channel != pal->channel) {
47 pal->channel = channel;
48 if (pal->channel_changed)
49 pal->channel_changed(pal, pal->channel);
55 * Change to a new channel and notify any active PALs of the new
56 * channel.
58 * When stopping the radio, PALs need to be notified first so they can
59 * terminate any active reservations.
61 static int uwb_radio_change_channel(struct uwb_rc *rc, int channel)
63 int ret = 0;
65 if (channel == -1)
66 uwb_radio_channel_changed(rc, channel);
68 if (channel != rc->beaconing) {
69 if (rc->beaconing != -1 && channel != -1) {
71 * FIXME: should signal the channel change
72 * with a Channel Change IE.
74 ret = uwb_radio_change_channel(rc, -1);
75 if (ret < 0)
76 return ret;
78 ret = uwb_rc_beacon(rc, channel, 0);
81 if (channel != -1)
82 uwb_radio_channel_changed(rc, rc->beaconing);
84 return ret;
87 /**
88 * uwb_radio_start - request that the radio be started
89 * @pal: the PAL making the request.
91 * If the radio is not already active, aa suitable channel is selected
92 * and beacons are started.
94 int uwb_radio_start(struct uwb_pal *pal)
96 struct uwb_rc *rc = pal->rc;
97 int ret = 0;
99 mutex_lock(&rc->uwb_dev.mutex);
101 if (!pal->channel) {
102 pal->channel = -1;
103 rc->active_pals++;
104 ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc));
107 mutex_unlock(&rc->uwb_dev.mutex);
108 return ret;
110 EXPORT_SYMBOL_GPL(uwb_radio_start);
113 * uwb_radio_stop - request tha the radio be stopped.
114 * @pal: the PAL making the request.
116 * Stops the radio if no other PAL is making use of it.
118 void uwb_radio_stop(struct uwb_pal *pal)
120 struct uwb_rc *rc = pal->rc;
122 mutex_lock(&rc->uwb_dev.mutex);
124 if (pal->channel) {
125 rc->active_pals--;
126 uwb_radio_change_channel(rc, uwb_radio_select_channel(rc));
127 pal->channel = 0;
130 mutex_unlock(&rc->uwb_dev.mutex);
132 EXPORT_SYMBOL_GPL(uwb_radio_stop);
135 * uwb_radio_force_channel - force a specific channel to be used
136 * @rc: the radio controller.
137 * @channel: the channel to use; -1 to force the radio to stop; 0 to
138 * use the default channel selection algorithm.
140 int uwb_radio_force_channel(struct uwb_rc *rc, int channel)
142 int ret = 0;
144 mutex_lock(&rc->uwb_dev.mutex);
146 rc->beaconing_forced = channel;
147 ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc));
149 mutex_unlock(&rc->uwb_dev.mutex);
150 return ret;
154 * uwb_radio_setup - setup the radio manager
155 * @rc: the radio controller.
157 * The radio controller is reset to ensure it's in a known state
158 * before it's used.
160 int uwb_radio_setup(struct uwb_rc *rc)
162 return uwb_rc_reset(rc);
166 * uwb_radio_reset_state - reset any radio manager state
167 * @rc: the radio controller.
169 * All internal radio manager state is reset to values corresponding
170 * to a reset radio controller.
172 void uwb_radio_reset_state(struct uwb_rc *rc)
174 struct uwb_pal *pal;
176 mutex_lock(&rc->uwb_dev.mutex);
178 list_for_each_entry(pal, &rc->pals, node) {
179 if (pal->channel) {
180 pal->channel = -1;
181 if (pal->channel_changed)
182 pal->channel_changed(pal, -1);
186 rc->beaconing = -1;
187 rc->scanning = -1;
189 mutex_unlock(&rc->uwb_dev.mutex);
193 * uwb_radio_shutdown - shutdown the radio manager
194 * @rc: the radio controller.
196 * The radio controller is reset.
198 void uwb_radio_shutdown(struct uwb_rc *rc)
200 uwb_radio_reset_state(rc);
201 uwb_rc_reset(rc);