+++ /dev/null
-/*
- * device-node
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless requcpued by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <linux/types.h>
-#include <linux/un.h>
-
-#include <hw/cpu.h>
-#include <hw/shared.h>
-
-#define CPU_BOOST_SOCKET_FOR_SCENARIO "/dev/socket/scenario_info"
-#define BUF_MAX 128
-
-static int cpu_boost_send_socket(char *write_buf)
-{
- int socket_fd = 0;
- int ret = 0;
- struct sockaddr_un addr;
-
- if (access(CPU_BOOST_SOCKET_FOR_SCENARIO, F_OK) != 0) {
- _E("CPU boot socket does not exist");
- return -ENOTSUP;
- }
-
- socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (socket_fd < 0) {
- _E("Failed to get socket fd");
- return -ENOMEM;
- }
-
- memset(&addr, 0, sizeof(addr));
- snprintf(addr.sun_path, UNIX_PATH_MAX, "%s", CPU_BOOST_SOCKET_FOR_SCENARIO);
- addr.sun_family = AF_LOCAL;
-
- ret = connect(socket_fd, (struct sockaddr *)&addr,
- sizeof(sa_family_t) + sizeof(CPU_BOOST_SOCKET_FOR_SCENARIO) );
- if (ret != 0) {
- ret = -errno;
- _E("Failed to connect to socket(%d)", ret);
- close(socket_fd);
- return ret;
- }
-
- ret = send(socket_fd, write_buf, strlen(write_buf), MSG_NOSIGNAL);
- close(socket_fd);
- if (ret < 0) {
- ret = -errno;
- _E("Failed to send scenario (%s) (%d)", write_buf, ret);
- return ret;
- }
-
- return 0;
-}
-
-static int cpu_start_boost(void *data)
-{
- char *scenario = data;
- char buf[BUF_MAX];
-
- snprintf(buf, sizeof(buf), "%sLock", scenario);
- return cpu_boost_send_socket(buf);
-}
-
-static int cpu_stop_boost(void *data)
-{
- char *scenario = data;
- char buf[BUF_MAX];
-
- snprintf(buf, sizeof(buf), "%sUnlock", scenario);
- return cpu_boost_send_socket(buf);
-}
-
-static int cpu_open(struct hw_info *info,
- const char *id, struct hw_common **common)
-{
- struct cpu_device *cpu_dev;
-
- if (!info || !common)
- return -EINVAL;
-
- cpu_dev = calloc(1, sizeof(struct cpu_device));
- if (!cpu_dev)
- return -ENOMEM;
-
- cpu_dev->common.info = info;
- cpu_dev->start_boost = cpu_start_boost;
- cpu_dev->stop_boost = cpu_stop_boost;
-
- *common = (struct hw_common *)cpu_dev;
- return 0;
-}
-
-static int cpu_close(struct hw_common *common)
-{
- if (!common)
- return -EINVAL;
-
- free(common);
- return 0;
-}
-
-HARDWARE_MODULE_STRUCTURE = {
- .magic = HARDWARE_INFO_TAG,
- .hal_version = HARDWARE_INFO_VERSION,
- .device_version = CPU_HARDWARE_DEVICE_VERSION,
- .id = CPU_HARDWARE_DEVICE_ID,
- .name = "cpu",
- .open = cpu_open,
- .close = cpu_close,
-};