2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 rfkill routines.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include "rt2x00lib.h"
32 static void rt2x00rfkill_poll(struct input_polled_dev *poll_dev)
34 struct rt2x00_dev *rt2x00dev = poll_dev->private;
37 if (!test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state) ||
38 !test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
42 * Poll latest state, if the state is different then the previous state,
43 * we should generate an input event.
45 state = !!rt2x00dev->ops->lib->rfkill_poll(rt2x00dev);
46 old_state = !!test_bit(RFKILL_STATE_BLOCKED, &rt2x00dev->rfkill_state);
48 if (old_state != state) {
49 input_report_switch(poll_dev->input, SW_RFKILL_ALL, state);
50 change_bit(RFKILL_STATE_BLOCKED, &rt2x00dev->rfkill_state);
54 void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
56 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
57 test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
60 if (input_register_polled_device(rt2x00dev->rfkill_poll_dev)) {
61 ERROR(rt2x00dev, "Failed to register polled device.\n");
65 __set_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
68 * Force initial poll which will detect the initial device state,
69 * and correctly sends the signal to the input layer about this
72 rt2x00rfkill_poll(rt2x00dev->rfkill_poll_dev);
75 void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
77 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
78 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
81 input_unregister_polled_device(rt2x00dev->rfkill_poll_dev);
83 __clear_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
86 void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
88 struct input_polled_dev *poll_dev;
90 if (test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
91 !test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
94 poll_dev = input_allocate_polled_device();
96 ERROR(rt2x00dev, "Failed to allocate polled device.\n");
100 poll_dev->private = rt2x00dev;
101 poll_dev->poll = rt2x00rfkill_poll;
102 poll_dev->poll_interval = RFKILL_POLL_INTERVAL;
104 poll_dev->input->name = rt2x00dev->ops->name;
105 poll_dev->input->phys = wiphy_name(rt2x00dev->hw->wiphy);
106 poll_dev->input->id.bustype = BUS_HOST;
107 poll_dev->input->id.vendor = 0x1814;
108 poll_dev->input->id.product = rt2x00dev->chip.rt;
109 poll_dev->input->id.version = rt2x00dev->chip.rev;
110 poll_dev->input->dev.parent = wiphy_dev(rt2x00dev->hw->wiphy);
111 poll_dev->input->evbit[0] = BIT(EV_SW);
112 poll_dev->input->swbit[0] = BIT(SW_RFKILL_ALL);
114 rt2x00dev->rfkill_poll_dev = poll_dev;
116 __set_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state);
119 void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
121 if (!__test_and_clear_bit(RFKILL_STATE_ALLOCATED,
122 &rt2x00dev->rfkill_state))
125 input_free_polled_device(rt2x00dev->rfkill_poll_dev);
126 rt2x00dev->rfkill_poll_dev = NULL;