rfkill: rewrite
[deliverable/linux.git] / drivers / net / wireless / iwmc3200wifi / rfkill.c
1 /*
2 * Intel Wireless Multicomm 3200 WiFi driver
3 *
4 * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
5 * Samuel Ortiz <samuel.ortiz@intel.com>
6 * Zhu Yi <yi.zhu@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *
22 */
23
24 #include <linux/rfkill.h>
25
26 #include "iwm.h"
27
28 static int iwm_rfkill_set_block(void *data, bool blocked)
29 {
30 struct iwm_priv *iwm = data;
31
32 if (!blocked) {
33 if (test_bit(IWM_RADIO_RFKILL_HW, &iwm->radio))
34 return -EBUSY;
35
36 if (test_and_clear_bit(IWM_RADIO_RFKILL_SW, &iwm->radio) &&
37 (iwm_to_ndev(iwm)->flags & IFF_UP))
38 return iwm_up(iwm);
39 } else {
40 if (!test_and_set_bit(IWM_RADIO_RFKILL_SW, &iwm->radio))
41 return iwm_down(iwm);
42 }
43
44 return 0;
45 }
46
47 static const struct rfkill_ops iwm_rfkill_ops = {
48 .set_block = iwm_rfkill_set_block,
49 };
50
51 int iwm_rfkill_init(struct iwm_priv *iwm)
52 {
53 int ret;
54
55 iwm->rfkill = rfkill_alloc(KBUILD_MODNAME,
56 iwm_to_dev(iwm),
57 RFKILL_TYPE_WLAN,
58 &iwm_rfkill_ops, iwm);
59 if (!iwm->rfkill) {
60 IWM_ERR(iwm, "Unable to allocate rfkill device\n");
61 return -ENOMEM;
62 }
63
64 ret = rfkill_register(iwm->rfkill);
65 if (ret) {
66 IWM_ERR(iwm, "Failed to register rfkill device\n");
67 goto fail;
68 }
69
70 return 0;
71 fail:
72 rfkill_destroy(iwm->rfkill);
73 return ret;
74 }
75
76 void iwm_rfkill_exit(struct iwm_priv *iwm)
77 {
78 if (iwm->rfkill) {
79 rfkill_unregister(iwm->rfkill);
80 rfkill_destroy(iwm->rfkill);
81 }
82 iwm->rfkill = NULL;
83 }
This page took 0.04043 seconds and 6 git commands to generate.