blob: 2fd6ea198e3df614455b00782914d19e0463fa4f [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* linux/arch/arm/mach-msm/board-sapphire-rfkill.c
2 * Copyright (C) 2007-2009 HTC Corporation.
3 * Author: Thomas Tsai <thomas_tsai@htc.com>
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13*/
14
15/* Control bluetooth power for sapphire platform */
16
17#include <linux/platform_device.h>
18#include <linux/module.h>
19#include <linux/device.h>
20#include <linux/rfkill.h>
21#include <linux/delay.h>
22#include <linux/gpio.h>
23#include <asm/mach-types.h>
24#include "gpio_chip.h"
25#include "board-sapphire.h"
26
27static struct rfkill *bt_rfk;
28static const char bt_name[] = "brf6300";
29
30extern int sapphire_bt_fastclock_power(int on);
31
32static int bluetooth_set_power(void *data, bool blocked)
33{
34 if (!blocked) {
35 sapphire_bt_fastclock_power(1);
36 gpio_set_value(SAPPHIRE_GPIO_BT_32K_EN, 1);
37 udelay(10);
38 gpio_direction_output(101, 1);
39 } else {
40 gpio_direction_output(101, 0);
41 gpio_set_value(SAPPHIRE_GPIO_BT_32K_EN, 0);
42 sapphire_bt_fastclock_power(0);
43 }
44 return 0;
45}
46
47static struct rfkill_ops sapphire_rfkill_ops = {
48 .set_block = bluetooth_set_power,
49};
50
51static int sapphire_rfkill_probe(struct platform_device *pdev)
52{
53 int rc = 0;
54 bool default_state = true; /* off */
55
56 bluetooth_set_power(NULL, default_state);
57
58 bt_rfk = rfkill_alloc(bt_name, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
59 &sapphire_rfkill_ops, NULL);
60 if (!bt_rfk)
61 return -ENOMEM;
62
63 /* userspace cannot take exclusive control */
64
65 rfkill_set_states(bt_rfk, default_state, false);
66
67 rc = rfkill_register(bt_rfk);
68
69 if (rc)
70 rfkill_destroy(bt_rfk);
71 return rc;
72}
73
74static int sapphire_rfkill_remove(struct platform_device *dev)
75{
76 rfkill_unregister(bt_rfk);
77 rfkill_destroy(bt_rfk);
78
79 return 0;
80}
81
82static struct platform_driver sapphire_rfkill_driver = {
83 .probe = sapphire_rfkill_probe,
84 .remove = sapphire_rfkill_remove,
85 .driver = {
86 .name = "sapphire_rfkill",
87 .owner = THIS_MODULE,
88 },
89};
90
91static int __init sapphire_rfkill_init(void)
92{
93 return platform_driver_register(&sapphire_rfkill_driver);
94}
95
96static void __exit sapphire_rfkill_exit(void)
97{
98 platform_driver_unregister(&sapphire_rfkill_driver);
99}
100
101module_init(sapphire_rfkill_init);
102module_exit(sapphire_rfkill_exit);
103MODULE_DESCRIPTION("sapphire rfkill");
104MODULE_AUTHOR("Nick Pelly <npelly@google.com>");
105MODULE_LICENSE("GPL");