USB: ftdi_sio: fix status line change handling for TIOCMIWAIT and TIOCGICOUNT
[linux-flexiantxendom0.git] / ubuntu / omnibook / bluetooth.c
1 /*
2  * wireless.c Bluetooth feature
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2, or (at your option) any
7  * later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * Written by Mathieu BĂ©rard <mathieu.berard@crans.org>, 2006
15  *
16  */
17
18 #include "omnibook.h"
19 #include "hardware.h"
20
21 static int omnibook_bt_read(char *buffer, struct omnibook_operation *io_op)
22 {
23         int len = 0;
24         int retval;
25         unsigned int state;
26
27         if ((retval = backend_aerial_get(io_op, &state)))
28                 return retval;
29
30         len +=
31             sprintf(buffer + len, "Bluetooth adapter is %s",
32                     (state & BT_EX) ? "present" : "absent");
33         if (state & BT_EX)
34                 len += sprintf(buffer + len, " and %s", (state & BT_STA) ? "enabled" : "disabled");
35         len += sprintf(buffer + len, ".\n");
36         return len;
37
38 }
39
40 static int omnibook_bt_write(char *buffer, struct omnibook_operation *io_op)
41 {
42         int retval = 0;
43         unsigned int state;
44
45         if(mutex_lock_interruptible(&io_op->backend->mutex))
46                 return -ERESTARTSYS;    
47
48         if ((retval = __backend_aerial_get(io_op, &state)))
49                 goto out;
50
51         if (*buffer == '0')
52                 state &= ~BT_STA;
53         else if (*buffer == '1')
54                 state |= BT_STA;
55         else {
56                 retval = -EINVAL;
57                 goto out;
58         }
59
60         retval = __backend_aerial_set(io_op, state);
61
62         out:            
63         mutex_unlock(&io_op->backend->mutex);
64         return retval;
65 }
66
67 static struct omnibook_feature bt_driver;
68
69 static int __init omnibook_bt_init(struct omnibook_operation *io_op)
70 {
71         int retval = 0;
72         unsigned int state;
73
74 /*
75  *  Refuse enabling/disabling a non-existent device
76  */
77
78         if ((retval = backend_aerial_get(io_op, &state)))
79                 return retval;
80
81         if (!(state & BT_EX))
82                 bt_driver.write = NULL;
83
84         return retval;
85 }
86
87 static struct omnibook_tbl wireless_table[] __initdata = {
88         {TSM70 | TSA105 | TSX205, {ACPI,}},     /* stubs to select backend */
89         {TSM40, {SMI,}},                        /* stubs to select backend */
90         {0,}
91 };
92
93 static struct omnibook_feature __declared_feature bt_driver = {
94         .name = "bluetooth",
95         .enabled = 1,
96         .read = omnibook_bt_read,
97         .write = omnibook_bt_write,
98         .init = omnibook_bt_init,
99         .ectypes = TSM70 | TSM40 | TSA105 | TSX205,
100         .tbl = wireless_table,
101 };
102
103 module_param_named(bluetooth, bt_driver.enabled, int, S_IRUGO);
104 MODULE_PARM_DESC(bluetooth, "Use 0 to disable, 1 to enable bluetooth adapter control");