Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Google, Inc. |
| 3 | * Author: Nick Pelly <npelly@google.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 | |
| 16 | /* Control bluetooth power for trout platform */ |
| 17 | |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/rfkill.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <asm/gpio.h> |
| 24 | |
| 25 | #include "board-trout.h" |
| 26 | |
| 27 | static struct rfkill *bt_rfk; |
| 28 | static const char bt_name[] = "brf6300"; |
| 29 | |
| 30 | static int bluetooth_set_power(void *data, bool blocked) |
| 31 | { |
| 32 | if (!blocked) { |
| 33 | gpio_set_value(TROUT_GPIO_BT_32K_EN, 1); |
| 34 | udelay(10); |
| 35 | gpio_direction_output(101, 1); |
| 36 | } else { |
| 37 | gpio_direction_output(101, 0); |
| 38 | gpio_set_value(TROUT_GPIO_BT_32K_EN, 0); |
| 39 | } |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static struct rfkill_ops trout_rfkill_ops = { |
| 44 | .set_block = bluetooth_set_power, |
| 45 | }; |
| 46 | |
| 47 | static int trout_rfkill_probe(struct platform_device *pdev) |
| 48 | { |
| 49 | int rc = 0; |
| 50 | bool default_state = true; /* off */ |
| 51 | |
| 52 | bluetooth_set_power(NULL, default_state); |
| 53 | |
| 54 | bt_rfk = rfkill_alloc(bt_name, &pdev->dev, RFKILL_TYPE_BLUETOOTH, |
| 55 | &trout_rfkill_ops, NULL); |
| 56 | if (!bt_rfk) |
| 57 | return -ENOMEM; |
| 58 | |
| 59 | rfkill_set_states(bt_rfk, default_state, false); |
| 60 | |
| 61 | /* userspace cannot take exclusive control */ |
| 62 | |
| 63 | rc = rfkill_register(bt_rfk); |
| 64 | |
| 65 | if (rc) |
| 66 | rfkill_destroy(bt_rfk); |
| 67 | return rc; |
| 68 | } |
| 69 | |
| 70 | static int trout_rfkill_remove(struct platform_device *dev) |
| 71 | { |
| 72 | rfkill_unregister(bt_rfk); |
| 73 | rfkill_destroy(bt_rfk); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct platform_driver trout_rfkill_driver = { |
| 79 | .probe = trout_rfkill_probe, |
| 80 | .remove = trout_rfkill_remove, |
| 81 | .driver = { |
| 82 | .name = "trout_rfkill", |
| 83 | .owner = THIS_MODULE, |
| 84 | }, |
| 85 | }; |
| 86 | |
| 87 | static int __init trout_rfkill_init(void) |
| 88 | { |
| 89 | return platform_driver_register(&trout_rfkill_driver); |
| 90 | } |
| 91 | |
| 92 | static void __exit trout_rfkill_exit(void) |
| 93 | { |
| 94 | platform_driver_unregister(&trout_rfkill_driver); |
| 95 | } |
| 96 | |
| 97 | module_init(trout_rfkill_init); |
| 98 | module_exit(trout_rfkill_exit); |
| 99 | MODULE_DESCRIPTION("trout rfkill"); |
| 100 | MODULE_AUTHOR("Nick Pelly <npelly@google.com>"); |
| 101 | MODULE_LICENSE("GPL"); |