From: jino.cho Date: Fri, 7 Jul 2017 02:54:46 +0000 (+0900) Subject: Support various uart device name X-Git-Tag: submit/tizen/20170713.044725~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58ee9949f82ac836a9920a37892cd51e9b0aafa0;p=platform%2Fcore%2Fsystem%2Fperipheral-bus.git Support various uart device name - ttyS : hot fix for rp3 - ttyAMA: console on AMBA serial. - ttySAC: console on Samsung SoC serial. Change-Id: Iec73e23898e55230bbc8a1f0c71046d6f1d9f89d Signed-off-by: jino.cho --- diff --git a/src/interface/uart.c b/src/interface/uart.c index 2468c02..f070b8b 100644 --- a/src/interface/uart.c +++ b/src/interface/uart.c @@ -27,13 +27,21 @@ #include "uart.h" #include "peripheral_common.h" -#define SYSFS_UART_PATH "/dev/ttySAC" - #define PATH_BUF_MAX 64 #define UART_BUF_MAX 16 #define UART_BAUDRATE_SIZE 19 +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) +#endif + +char *sysfs_uart_path[] = { + "/dev/ttyS", + "/dev/ttyAMA", + "/dev/ttySAC", +}; + static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = { B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, @@ -45,14 +53,19 @@ static const int byteinfo[4] = {CS5, CS6, CS7, CS8}; int uart_open(int port, int *file_hndl) { - int fd; - char fName[PATH_BUF_MAX] = {0}; + int i, fd; + char uart_dev[PATH_BUF_MAX] = {0}; _D("port : %d", port); - snprintf(fName, PATH_BUF_MAX, SYSFS_UART_PATH "%d", port); - if ((fd = open(fName, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { - _E("Error[%d]: can't open %s, %s--[%d]\n", errno, fName, __FUNCTION__, __LINE__); + for (i = 0; i < ARRAY_SIZE(sysfs_uart_path); i++) { + snprintf(uart_dev, PATH_BUF_MAX, "%s%d", sysfs_uart_path[i], port); + if (access(uart_dev, F_OK) == 0) + break; + } + + if ((fd = open(uart_dev, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { + _E("Error[%d]: can't open %s, %s--[%d]\n", errno, uart_dev, __FUNCTION__, __LINE__); return -ENXIO; } *file_hndl = fd;