4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongGi Jang <dg0402.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <sys/types.h>
34 #include "device_engine.h"
36 struct device *dev_head = NULL;
39 void add_dev(struct device *dev)
51 DBG("%s - %d", dev->devname, dev->devtype);
67 struct device *find_device(struct device *root_dev, devtype_t devtype)
80 DBG("devname = %s %d %d", dev->devname, dev->devtype, devtype);
81 if (dev->devtype == devtype)
89 int find_sysfs_node(char *path, char *node_name)
96 DBG("path is not existed : %s", path);
100 while ((entry = readdir(dp)) != NULL) {
101 if (strncmp(entry->d_name, ".", 1) == 0 ||
102 strncmp(entry->d_name, "..", 2) == 0)
110 if (node_name != NULL)
111 strncpy(node_name, entry->d_name,PATH_MAX);
114 DBG("sysfs node not existed");
115 if (closedir(dp) != 0)
116 DBG("Unable to close directory");
120 if (closedir(dp) != 0)
121 DBG("Unable to close directory");
125 int set_devtype(char *devname, devtype_t devtype)
132 if (strstr(dev->devname, devname)) {
133 if ((strstr(dev->devname, "auto") != NULL) &&
134 (dev->probe != NULL)) {
137 DBG("auto probe failed");
142 dev->devtype = devtype;
151 static int sys_read_buf(char *file, char *buf)
156 fd = open(file, O_RDONLY);
158 ERR("%s open error: %s", file, strerror(errno));
162 r = read(fd, buf, BUFF_MAX);
163 if ((r >= 0) && (r <= BUFF_MAX))
166 ERR("%s read error: %s", file, strerror(errno));
171 INFO("read %s, value= %s", file, buf);
175 static int sys_write_buf(char *file, char *buf)
180 fd = open(file, O_WRONLY);
182 ERR("%s open error: %s", file, strerror(errno));
186 r = write(fd, buf, strlen(buf));
189 ERR("%s write error: %s", file, strerror(errno));
192 INFO("write %s, value= %s", file, buf);
193 DBG("write[%s], value[%s], line[%d]", file, buf, __LINE__);
197 int sys_get_int(char *fname, int *val)
199 char buf[BUFF_MAX+1];
201 if (sys_read_buf(fname, buf) == 0) {
210 char *sys_get_str(char *fname)
212 char buf[BUFF_MAX+1];
215 if (sys_read_buf(fname, buf) == 0)
216 r = strdup((char *)buf);
221 int sys_set_int(char *fname, int val)
223 char buf[BUFF_MAX+1];
225 snprintf(buf, sizeof(buf), "%d", val);
227 if (sys_write_buf(fname, buf) == 0)
233 int sys_set_str(char *fname, char *val)
238 if (sys_write_buf(fname, val) == 0)