1 /* drivers/input/misc/gpio_output.c
3 * Copyright (C) 2007 Google, Inc.
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.
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.
16 #include <linux/kernel.h>
17 #include <linux/gpio.h>
18 #include <linux/gpio_event.h>
20 int 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)
25 struct gpio_event_output_info *oi;
26 oi = container_of(info, struct gpio_event_output_info, info);
29 if (!(oi->flags & GPIOEDF_ACTIVE_HIGH))
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);
37 int gpio_event_output_func(
38 struct input_dev *input_dev, struct gpio_event_info *info, void **data,
43 struct gpio_event_output_info *oi;
44 oi = container_of(info, struct gpio_event_output_info, info);
46 if (func == GPIO_EVENT_FUNC_SUSPEND || func == GPIO_EVENT_FUNC_RESUME)
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,
55 for (i = 0; i < oi->keymap_size; i++) {
56 ret = gpio_request(oi->keymap[i].gpio,
59 pr_err("gpio_event_output_func: gpio_request "
60 "failed for %d\n", oi->keymap[i].gpio);
61 goto err_gpio_request_failed;
63 ret = gpio_direction_output(oi->keymap[i].gpio,
66 pr_err("gpio_event_output_func: "
67 "gpio_direction_output failed for %d\n",
69 goto err_gpio_direction_output_failed;
76 for (i = oi->keymap_size - 1; i >= 0; i--) {
77 err_gpio_direction_output_failed:
78 gpio_free(oi->keymap[i].gpio);
79 err_gpio_request_failed: