diff options
author | Monika Zielinska <m.zielinska3@samsung.com> | 2018-07-04 11:41:10 +0200 |
---|---|---|
committer | lokilee73 <changjoo.lee@samsung.com> | 2018-07-10 11:44:12 +0900 |
commit | 00487eada03fd43123c67f542a585734466dca2e (patch) | |
tree | e071defc7509a9c815d2c95e680d2908c8e596b2 | |
parent | aa02128230605ce08c03ba10ad3ba4953faa37a5 (diff) | |
download | device-tm1-00487eada03fd43123c67f542a585734466dca2e.tar.gz device-tm1-00487eada03fd43123c67f542a585734466dca2e.tar.bz2 device-tm1-00487eada03fd43123c67f542a585734466dca2e.zip |
Add board API
Change-Id: I4fb066365f42db11e72d74dd879e2969c45878a6
Signed-off-by: Monika Zielinska <m.zielinska3@samsung.com>
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rwxr-xr-x | hw/board/CMakeLists.txt | 19 | ||||
-rwxr-xr-x | hw/board/board.c | 110 |
3 files changed, 130 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bf1e68e..d5b5fee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,3 +15,4 @@ ADD_SUBDIRECTORY(hw/ir) ADD_SUBDIRECTORY(hw/thermal) ADD_SUBDIRECTORY(hw/usb_gadget) ADD_SUBDIRECTORY(hw/usb_client) +ADD_SUBDIRECTORY(hw/board) diff --git a/hw/board/CMakeLists.txt b/hw/board/CMakeLists.txt new file mode 100755 index 0000000..ef3052b --- /dev/null +++ b/hw/board/CMakeLists.txt @@ -0,0 +1,19 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(board C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(usb_gadget_pkgs REQUIRED hwcommon dlog) + +FOREACH(flag ${usb_gadget_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} MODULE board.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_gadget_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) diff --git a/hw/board/board.c b/hw/board/board.c new file mode 100755 index 0000000..175cb2e --- /dev/null +++ b/hw/board/board.c @@ -0,0 +1,110 @@ +/* + * libdevice-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 required 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. + */ + +#define _GNU_SOURCE +#include <hw/board.h> + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <hw/shared.h> + +#define CPUINFO_PATH "/proc/cpuinfo" +#define SERIAL_TAG "Serial" +#define LINE_LEN 64 + +static int get_device_serial(char **out) +{ + FILE *fp; + char line[LINE_LEN], *p, *q; + + fp = fopen(CPUINFO_PATH, "r"); + if (!fp) + return -1; + + while ((p = fgets(line, sizeof(line), fp)) != NULL) { + p = strchr(p, '\t'); + if (!p) + continue; + + *p = '\0'; + + if (strncmp(line, SERIAL_TAG, sizeof(line)) != 0) + continue; + + ++p; + p = strchr(p, ':'); + if (!p) + continue; + p += 2; + + q = strchrnul(p, '\n'); + *q = '\0'; + *out = strdup(p); + if (!out) + _E("Out of memory, strdup failed"); + fclose(fp); + return 0; + } + + fclose(fp); + return -1; +} + +static int board_open(struct hw_info *info, + const char *id, struct hw_common **common) +{ + struct hw_board *b; + + if (!info || !common) + return -EINVAL; + + b = calloc(1, sizeof(*b)); + if (!b) + return -ENOMEM; + + b->common.info = info; + b->get_device_serial = get_device_serial; + + *common = &b->common; + return 0; +} + +static int board_close(struct hw_common *common) +{ + struct hw_board *b; + + if (!common) + return -EINVAL; + + b = container_of(common, struct hw_board, common); + free(b); + + return 0; +} + +HARDWARE_MODULE_STRUCTURE = { + .magic = HARDWARE_INFO_TAG, + .hal_version = HARDWARE_INFO_VERSION, + .device_version = BOARD_HARDWARE_DEVICE_VERSION, + .id = BOARD_HARDWARE_DEVICE_ID, + .name = "device", + .open = board_open, + .close = board_close, +}; |