Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: drivers/bluetooth/bt_rfkill.c

Issue 6295009: CHROMIUM: config: bluetooth: rfkill driver Base URL: http://git.chromium.org/git/kernel-next.git@chromeos-2.6.36
Patch Set: CHROMIUM: config: bluetooth: rfkill driver Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « drivers/bluetooth/Makefile ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010, NVIDIA Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include <linux/err.h>
20 #include <linux/types.h>
21 #include <linux/uaccess.h>
22 #include <linux/fs.h>
23 #include <linux/gpio.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/miscdevice.h>
27 #include <linux/module.h>
28 #include <linux/rfkill.h>
29 #include <linux/platform_device.h>
30 #include <linux/clk.h>
31 #include <linux/slab.h>
32
33 struct bt_rfkill_data {
34 int gpio_reset;
35 int gpio_shutdown;
36 int delay;
37 struct clk *bt_clk;
38 };
39
40 static struct bt_rfkill_data *bt_rfkill;
41
42 static int bt_rfkill_set_power(void *data, bool blocked)
43 {
44 if (blocked) {
45 if (bt_rfkill->gpio_shutdown)
46 gpio_direction_output(bt_rfkill->gpio_shutdown, 0);
47 if (bt_rfkill->gpio_reset)
48 gpio_direction_output(bt_rfkill->gpio_reset, 0);
49 if (bt_rfkill->bt_clk)
50 clk_disable(bt_rfkill->bt_clk);
51 } else {
52 if (bt_rfkill->bt_clk)
53 clk_enable(bt_rfkill->bt_clk);
54 if (bt_rfkill->gpio_shutdown)
55 gpio_direction_output(bt_rfkill->gpio_shutdown, 1);
56 if (bt_rfkill->gpio_reset)
57 gpio_direction_output(bt_rfkill->gpio_reset, 1);
58 }
59
60 return 0;
61 }
62
63 static const struct rfkill_ops bt_rfkill_ops = {
64 .set_block = bt_rfkill_set_power,
65 };
66
67 static int bt_rfkill_probe(struct platform_device *pdev)
68 {
69 struct rfkill *bt_rfkill_dev;
70 struct resource *res;
71 int ret;
72 bool enable = false; /* off */
73 bool default_sw_block_state;
74
75 bt_rfkill = kzalloc(sizeof(*bt_rfkill), GFP_KERNEL);
76 if (!bt_rfkill)
77 return -ENOMEM;
78
79 bt_rfkill->bt_clk = clk_get(&pdev->dev, "bt_clk");
80 if (IS_ERR(bt_rfkill->bt_clk)) {
81 pr_warn("%s: can't find bt_clk.\
82 assuming clock to chip\n", __func__);
83 bt_rfkill->bt_clk = NULL;
84 }
85
86 res = platform_get_resource_byname(pdev, IORESOURCE_IO,
87 "bt_nreset_gpio");
88 if (res) {
89 bt_rfkill->gpio_reset = res->start;
90 ret = gpio_request(bt_rfkill->gpio_reset,
91 "bt_nreset_gpio");
92 } else {
93 pr_warn("%s : can't find reset gpio.\n", __func__);
94 bt_rfkill->gpio_reset = 0;
95 }
96
97 res = platform_get_resource_byname(pdev, IORESOURCE_IO,
98 "bt_nshutdown_gpio");
99 if (res) {
100 bt_rfkill->gpio_shutdown = res->start;
101 ret = gpio_request(bt_rfkill->gpio_shutdown,
102 "bt_nshutdown_gpio");
103 } else {
104 pr_warn("%s : can't find shutdown gpio.\n", __func__);
105 bt_rfkill->gpio_shutdown = 0;
106 }
107
108 /* make sure at-least one of the GPIO is defined */
109 if (!bt_rfkill->gpio_reset && !bt_rfkill->gpio_shutdown)
110 goto free_bcm_res;
111
112 if (bt_rfkill->bt_clk && enable)
113 clk_enable(bt_rfkill->bt_clk);
114 if (bt_rfkill->gpio_shutdown)
115 gpio_direction_output(bt_rfkill->gpio_shutdown, enable);
116 if (bt_rfkill->gpio_reset)
117 gpio_direction_output(bt_rfkill->gpio_reset, enable);
118
119 bt_rfkill_dev = rfkill_alloc("bt dev rfkill", &pdev->dev,
120 RFKILL_TYPE_BLUETOOTH, &bt_rfkill_ops,
121 NULL);
122
123 if (unlikely(!bt_rfkill_dev))
124 goto free_bcm_res;
125
126 default_sw_block_state = !enable;
127 rfkill_set_states(bt_rfkill_dev, default_sw_block_state, false);
128
129 ret = rfkill_register(bt_rfkill_dev);
130
131 if (unlikely(ret)) {
132 rfkill_destroy(bt_rfkill_dev);
133 goto free_bcm_res;
134 }
135
136 return 0;
137
138 free_bcm_res:
139 if (bt_rfkill->gpio_shutdown)
140 gpio_free(bt_rfkill->gpio_shutdown);
141 if (bt_rfkill->gpio_reset)
142 gpio_free(bt_rfkill->gpio_reset);
143 if (bt_rfkill->bt_clk && enable)
144 clk_disable(bt_rfkill->bt_clk);
145 if (bt_rfkill->bt_clk)
146 clk_put(bt_rfkill->bt_clk);
147 kfree(bt_rfkill);
148 return -ENODEV;
149 }
150
151 static int bt_rfkill_remove(struct platform_device *pdev)
152 {
153 struct rfkill *bt_rfkill_dev = platform_get_drvdata(pdev);
154
155 rfkill_unregister(bt_rfkill_dev);
156 rfkill_destroy(bt_rfkill_dev);
157 if (bt_rfkill->bt_clk)
158 clk_put(bt_rfkill->bt_clk);
159 if (bt_rfkill->gpio_shutdown)
160 gpio_free(bt_rfkill->gpio_shutdown);
161 if (bt_rfkill->gpio_reset)
162 gpio_free(bt_rfkill->gpio_reset);
163 kfree(bt_rfkill);
164
165 return 0;
166 }
167
168 static struct platform_driver bt_rfkill_driver = {
169 .probe = bt_rfkill_probe,
170 .remove = bt_rfkill_remove,
171 .driver = {
172 .name = "bt_rfkill",
173 .owner = THIS_MODULE,
174 },
175 };
176
177 static int __init bt_rfkill_init(void)
178 {
179 return platform_driver_register(&bt_rfkill_driver);
180 }
181
182 static void __exit bt_rfkill_exit(void)
183 {
184 platform_driver_unregister(&bt_rfkill_driver);
185 }
186
187 module_init(bt_rfkill_init);
188 module_exit(bt_rfkill_exit);
189
190 MODULE_DESCRIPTION("bt rfkill");
191 MODULE_AUTHOR("NVIDIA");
192 MODULE_LICENSE("GPL");
OLDNEW
« no previous file with comments | « drivers/bluetooth/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698