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 DBG("!@#read[%s], value[%s], line[%d]", file, buf, __LINE__);
164 if ((r >= 0) && (r <= BUFF_MAX))
167 ERR("%s read error: %s", file, strerror(errno));
172 INFO("read %s, value= %s", file, buf);
173 DBG("read[%s], value[%s], line[%d]", file, buf, __LINE__);
177 static int sys_write_buf(char *file, char *buf)
182 fd = open(file, O_WRONLY);
184 ERR("%s open error: %s", file, strerror(errno));
188 r = write(fd, buf, strlen(buf));
191 ERR("%s write error: %s", file, strerror(errno));
194 INFO("write %s, value= %s", file, buf);
195 DBG("write[%s], value[%s], line[%d]", file, buf, __LINE__);
199 int sys_get_int(char *fname, int *val)
203 if (sys_read_buf(fname, buf) == 0) {
212 char *sys_get_str(char *fname)
217 if (sys_read_buf(fname, buf) == 0)
218 r = strdup((char *)buf);
223 int sys_set_int(char *fname, int val)
227 snprintf(buf, sizeof(buf), "%d", val);
229 if (sys_write_buf(fname, buf) == 0)
235 int sys_set_str(char *fname, char *val)
240 if (sys_write_buf(fname, val) == 0)