4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include "core/common.h"
29 #include "core/devices.h"
33 #define GPIO_CHECK_PATH "/sys/class/gpio/sim"
34 #define GPIO_CHECK_STATUS "/sys/class/gpio/sim/status"
36 static int sim_init(void)
38 static int type = GPIO_DEVICE_UNKNOWN;
41 if (type != GPIO_DEVICE_UNKNOWN)
44 fd = open(GPIO_CHECK_PATH, O_RDONLY);
46 _E("%s open error: %s", GPIO_CHECK_PATH, strerror(errno));
47 type = GPIO_DEVICE_NOT_EXIST;
51 type = GPIO_DEVICE_EXIST;
56 static int sim_status(void)
58 static int type = GPIO_DEVICE_UNKNOWN;
59 int val = GPIO_DEVICE_UNKNOWN;
65 if (type != GPIO_DEVICE_EXIST)
68 fd = open(GPIO_CHECK_STATUS, O_RDONLY);
70 _E("%s open error: %s", GPIO_CHECK_STATUS, strerror(errno));
74 ret = read(fd, buf, 1);
77 _E("fail to get status %d", ret);
82 _I("device is (%d)", val);
87 static const struct gpio_device sim_gpio = {
88 .type = GPIO_DEVICE_SIM,
94 static void __CONSTRUCTOR__ module_init(void)
96 register_gpio_device(&sim_gpio);