aboutsummaryrefslogtreecommitdiffstats
path: root/ubuntu/omnibook/bluetooth.c
blob: 1095eecb9f7ce7330c4b421c295d87a058426a06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * wireless.c Bluetooth feature
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * Written by Mathieu Bérard <mathieu.berard@crans.org>, 2006
 *
 */

#include "omnibook.h"
#include "hardware.h"

static int omnibook_bt_read(char *buffer, struct omnibook_operation *io_op)
{
	int len = 0;
	int retval;
	unsigned int state;

	if ((retval = backend_aerial_get(io_op, &state)))
		return retval;

	len +=
	    sprintf(buffer + len, "Bluetooth adapter is %s",
		    (state & BT_EX) ? "present" : "absent");
	if (state & BT_EX)
		len += sprintf(buffer + len, " and %s", (state & BT_STA) ? "enabled" : "disabled");
	len += sprintf(buffer + len, ".\n");
	return len;

}

static int omnibook_bt_write(char *buffer, struct omnibook_operation *io_op)
{
	int retval = 0;
	unsigned int state;

	if(mutex_lock_interruptible(&io_op->backend->mutex))
		return -ERESTARTSYS;	

	if ((retval = __backend_aerial_get(io_op, &state)))
		goto out;

	if (*buffer == '0')
		state &= ~BT_STA;
	else if (*buffer == '1')
		state |= BT_STA;
	else {
		retval = -EINVAL;
		goto out;
	}

	retval = __backend_aerial_set(io_op, state);

	out:		
	mutex_unlock(&io_op->backend->mutex);
	return retval;
}

static struct omnibook_feature bt_driver;

static int __init omnibook_bt_init(struct omnibook_operation *io_op)
{
	int retval = 0;
	unsigned int state;

/*
 *  Refuse enabling/disabling a non-existent device
 */

	if ((retval = backend_aerial_get(io_op, &state)))
		return retval;

	if (!(state & BT_EX))
		bt_driver.write = NULL;

	return retval;
}

static struct omnibook_tbl wireless_table[] __initdata = {
	{TSM70 | TSA105 | TSX205, {ACPI,}},	/* stubs to select backend */
	{TSM40, {SMI,}},			/* stubs to select backend */
	{0,}
};

static struct omnibook_feature __declared_feature bt_driver = {
	.name = "bluetooth",
	.enabled = 1,
	.read = omnibook_bt_read,
	.write = omnibook_bt_write,
	.init = omnibook_bt_init,
	.ectypes = TSM70 | TSM40 | TSA105 | TSX205,
	.tbl = wireless_table,
};

module_param_named(bluetooth, bt_driver.enabled, int, S_IRUGO);
MODULE_PARM_DESC(bluetooth, "Use 0 to disable, 1 to enable bluetooth adapter control");