]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/dream/gpio_output.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ecryptfs...
[net-next-2.6.git] / drivers / staging / dream / gpio_output.c
CommitLineData
420818f9
AH
1/* drivers/input/misc/gpio_output.c
2 *
3 * Copyright (C) 2007 Google, Inc.
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#include <linux/kernel.h>
17#include <linux/gpio.h>
18#include <linux/gpio_event.h>
19
20int gpio_event_output_event(
21 struct input_dev *input_dev, struct gpio_event_info *info, void **data,
22 unsigned int type, unsigned int code, int value)
23{
24 int i;
25 struct gpio_event_output_info *oi;
26 oi = container_of(info, struct gpio_event_output_info, info);
27 if (type != oi->type)
28 return 0;
29 if (!(oi->flags & GPIOEDF_ACTIVE_HIGH))
30 value = !value;
31 for (i = 0; i < oi->keymap_size; i++)
32 if (code == oi->keymap[i].code)
33 gpio_set_value(oi->keymap[i].gpio, value);
34 return 0;
35}
36
37int gpio_event_output_func(
38 struct input_dev *input_dev, struct gpio_event_info *info, void **data,
39 int func)
40{
41 int ret;
42 int i;
43 struct gpio_event_output_info *oi;
44 oi = container_of(info, struct gpio_event_output_info, info);
45
46 if (func == GPIO_EVENT_FUNC_SUSPEND || func == GPIO_EVENT_FUNC_RESUME)
47 return 0;
48
49 if (func == GPIO_EVENT_FUNC_INIT) {
50 int output_level = !(oi->flags & GPIOEDF_ACTIVE_HIGH);
51 for (i = 0; i < oi->keymap_size; i++)
52 input_set_capability(input_dev, oi->type,
53 oi->keymap[i].code);
54
55 for (i = 0; i < oi->keymap_size; i++) {
56 ret = gpio_request(oi->keymap[i].gpio,
57 "gpio_event_output");
58 if (ret) {
59 pr_err("gpio_event_output_func: gpio_request "
60 "failed for %d\n", oi->keymap[i].gpio);
61 goto err_gpio_request_failed;
62 }
63 ret = gpio_direction_output(oi->keymap[i].gpio,
64 output_level);
65 if (ret) {
66 pr_err("gpio_event_output_func: "
67 "gpio_direction_output failed for %d\n",
68 oi->keymap[i].gpio);
69 goto err_gpio_direction_output_failed;
70 }
71 }
72 return 0;
73 }
74
75 ret = 0;
76 for (i = oi->keymap_size - 1; i >= 0; i--) {
77err_gpio_direction_output_failed:
78 gpio_free(oi->keymap[i].gpio);
79err_gpio_request_failed:
80 ;
81 }
82 return ret;
83}
84