tizen 2.3 release
[framework/system/deviced.git] / src / gpio / gpio.h
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef __GPIO_HANDLER_H__
20 #define __GPIO_HANDLER_H__
21
22 #include <errno.h>
23 #include "core/common.h"
24
25 #define GPIO_DEVICE_CLOSED      0
26 #define GPIO_DEVICE_OPENED      1
27
28 enum gpio_device_check_type {
29         GPIO_DEVICE_UNKNOWN = -1,
30         GPIO_DEVICE_NOT_EXIST = 0,
31         GPIO_DEVICE_EXIST = 1,
32 };
33 enum gpio_device_type {
34         GPIO_DEVICE_HALL = 0,
35         GPIO_DEVICE_BUZZER,
36         GPIO_DEVICE_SIM,
37 };
38
39 struct gpio_device {
40         enum gpio_device_type type;
41         const char *name;
42         int (*init) (void);
43         int (*status) (void);
44 };
45
46 void register_gpio_device(const struct gpio_device *gpio);
47 void unregister_gpio_device(const struct gpio_device *gpio);
48 const struct gpio_device *find_gpio_device(const char *name);
49 int check_default_gpio_device(const struct gpio_device *dev);
50
51 #define NOT_SUPPORT_GPIO(gpio) \
52         ((check_default_gpio_device(gpio))? 1 : 0)
53
54 #define FIND_GPIO_INT(gpio, name) do { \
55         if (!gpio) gpio = find_gpio_device(name); if(check_default_gpio_device(gpio)) return -ENODEV; \
56 } while(0)
57
58 #define FIND_GPIO_VOID(gpio, name) do { \
59         if (!gpio) gpio = find_gpio_device(name); if(check_default_gpio_device(gpio)) return; \
60 } while(0)
61
62
63 #endif /* __GPIO_HANDLER_H__ */