aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00rfkill.c
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-07-04 08:51:39 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-07-08 14:16:03 -0400
commit50db7875d9dcd89f7624b13535738612faf8db0c (patch)
tree40533fe7fc13cad3a343754644757b5809a213c4 /drivers/net/wireless/rt2x00/rt2x00rfkill.c
parentf2cae6c5e41a979f85463aff60877b31fa3a383d (diff)
rt2x00: Remove input_polldev requirements for rfkill
With the new rfkill interface there is no longer a need for the input_polldev. Create a delayed_work structure which we can put on the mac80211 workqueue and poll the hardware every 1000ms. v2: Decrease poll frequency from 100ms to 1000ms Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2x00rfkill.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00rfkill.c107
1 files changed, 33 insertions, 74 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00rfkill.c b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
index 207281cfa8b7..04b29716d356 100644
--- a/drivers/net/wireless/rt2x00/rt2x00rfkill.c
+++ b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
@@ -23,7 +23,6 @@
23 Abstract: rt2x00 rfkill routines. 23 Abstract: rt2x00 rfkill routines.
24 */ 24 */
25 25
26#include <linux/input-polldev.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/module.h> 27#include <linux/module.h>
29#include <linux/rfkill.h> 28#include <linux/rfkill.h>
@@ -61,15 +60,35 @@ static int rt2x00rfkill_toggle_radio(void *data, enum rfkill_state state)
61 return retval; 60 return retval;
62} 61}
63 62
64static void rt2x00rfkill_poll(struct input_polled_dev *poll_dev) 63static int rt2x00rfkill_get_state(void *data, enum rfkill_state *state)
65{ 64{
66 struct rt2x00_dev *rt2x00dev = poll_dev->private; 65 struct rt2x00_dev *rt2x00dev = data;
67 int state = rt2x00dev->ops->lib->rfkill_poll(rt2x00dev);
68 66
69 if (rt2x00dev->rfkill->state != state) { 67 *state = rt2x00dev->rfkill->state;
70 input_report_key(poll_dev->input, KEY_WLAN, 1); 68
71 input_report_key(poll_dev->input, KEY_WLAN, 0); 69 return 0;
72 } 70}
71
72static void rt2x00rfkill_poll(struct work_struct *work)
73{
74 struct rt2x00_dev *rt2x00dev =
75 container_of(work, struct rt2x00_dev, rfkill_work.work);
76 int state;
77
78 if (!test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
79 return;
80
81 /*
82 * rfkill_poll reports 1 when the key has been pressed and the
83 * radio should be blocked.
84 */
85 state = !rt2x00dev->ops->lib->rfkill_poll(rt2x00dev) ?
86 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
87
88 rfkill_force_state(rt2x00dev->rfkill, state);
89
90 queue_delayed_work(rt2x00dev->hw->workqueue,
91 &rt2x00dev->rfkill_work, RFKILL_POLL_INTERVAL);
73} 92}
74 93
75void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev) 94void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
@@ -83,12 +102,6 @@ void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
83 return; 102 return;
84 } 103 }
85 104
86 if (input_register_polled_device(rt2x00dev->poll_dev)) {
87 ERROR(rt2x00dev, "Failed to register polled device.\n");
88 rfkill_unregister(rt2x00dev->rfkill);
89 return;
90 }
91
92 __set_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state); 105 __set_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
93 106
94 /* 107 /*
@@ -96,7 +109,7 @@ void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
96 * and correctly sends the signal to the rfkill layer about this 109 * and correctly sends the signal to the rfkill layer about this
97 * state. 110 * state.
98 */ 111 */
99 rt2x00rfkill_poll(rt2x00dev->poll_dev); 112 rt2x00rfkill_poll(&rt2x00dev->rfkill_work.work);
100} 113}
101 114
102void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev) 115void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
@@ -105,38 +118,13 @@ void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
105 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state)) 118 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
106 return; 119 return;
107 120
108 input_unregister_polled_device(rt2x00dev->poll_dev); 121 cancel_delayed_work_sync(&rt2x00dev->rfkill_work);
122
109 rfkill_unregister(rt2x00dev->rfkill); 123 rfkill_unregister(rt2x00dev->rfkill);
110 124
111 __clear_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state); 125 __clear_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
112} 126}
113 127
114static struct input_polled_dev *
115rt2x00rfkill_allocate_polldev(struct rt2x00_dev *rt2x00dev)
116{
117 struct input_polled_dev *poll_dev;
118
119 poll_dev = input_allocate_polled_device();
120 if (!poll_dev)
121 return NULL;
122
123 poll_dev->private = rt2x00dev;
124 poll_dev->poll = rt2x00rfkill_poll;
125 poll_dev->poll_interval = RFKILL_POLL_INTERVAL;
126
127 poll_dev->input->name = rt2x00dev->ops->name;
128 poll_dev->input->phys = wiphy_name(rt2x00dev->hw->wiphy);
129 poll_dev->input->id.bustype = BUS_HOST;
130 poll_dev->input->id.vendor = 0x1814;
131 poll_dev->input->id.product = rt2x00dev->chip.rt;
132 poll_dev->input->id.version = rt2x00dev->chip.rev;
133 poll_dev->input->dev.parent = wiphy_dev(rt2x00dev->hw->wiphy);
134 poll_dev->input->evbit[0] = BIT(EV_KEY);
135 set_bit(KEY_WLAN, poll_dev->input->keybit);
136
137 return poll_dev;
138}
139
140void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev) 128void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
141{ 129{
142 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) 130 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
@@ -153,14 +141,9 @@ void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
153 rt2x00dev->rfkill->data = rt2x00dev; 141 rt2x00dev->rfkill->data = rt2x00dev;
154 rt2x00dev->rfkill->state = -1; 142 rt2x00dev->rfkill->state = -1;
155 rt2x00dev->rfkill->toggle_radio = rt2x00rfkill_toggle_radio; 143 rt2x00dev->rfkill->toggle_radio = rt2x00rfkill_toggle_radio;
144 rt2x00dev->rfkill->get_state = rt2x00rfkill_get_state;
156 145
157 rt2x00dev->poll_dev = rt2x00rfkill_allocate_polldev(rt2x00dev); 146 INIT_DELAYED_WORK(&rt2x00dev->rfkill_work, rt2x00rfkill_poll);
158 if (!rt2x00dev->poll_dev) {
159 ERROR(rt2x00dev, "Failed to allocate polled device.\n");
160 rfkill_free(rt2x00dev->rfkill);
161 rt2x00dev->rfkill = NULL;
162 return;
163 }
164 147
165 return; 148 return;
166} 149}
@@ -171,32 +154,8 @@ void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
171 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state)) 154 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
172 return; 155 return;
173 156
174 input_free_polled_device(rt2x00dev->poll_dev); 157 cancel_delayed_work_sync(&rt2x00dev->rfkill_work);
175 rt2x00dev->poll_dev = NULL;
176 158
177 rfkill_free(rt2x00dev->rfkill); 159 rfkill_free(rt2x00dev->rfkill);
178 rt2x00dev->rfkill = NULL; 160 rt2x00dev->rfkill = NULL;
179} 161}
180
181void rt2x00rfkill_suspend(struct rt2x00_dev *rt2x00dev)
182{
183 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
184 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
185 return;
186
187 input_free_polled_device(rt2x00dev->poll_dev);
188 rt2x00dev->poll_dev = NULL;
189}
190
191void rt2x00rfkill_resume(struct rt2x00_dev *rt2x00dev)
192{
193 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
194 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
195 return;
196
197 rt2x00dev->poll_dev = rt2x00rfkill_allocate_polldev(rt2x00dev);
198 if (!rt2x00dev->poll_dev) {
199 ERROR(rt2x00dev, "Failed to allocate polled device.\n");
200 return;
201 }
202}