hikey: Adopt uim to handle old kernel path am: 6cb91460ad am: bebca4acff
am: 6fd10124b9

Change-Id: Ic352a1a8abafe9a01da31aa7cfa9695f8beb7555
diff --git a/wpan/uim/uim.c b/wpan/uim/uim.c
index a9dde00..7f78f0c 100644
--- a/wpan/uim/uim.c
+++ b/wpan/uim/uim.c
@@ -42,6 +42,12 @@
 char uim_bd_address[BD_ADDR_LEN];
 bdaddr_t *bd_addr;
 
+/* kim Sysfs path */
+static char *sysfs_install_entry = INSTALL_SYSFS_ENTRY;
+static char *sysfs_dev_name = DEV_NAME_SYSFS;
+static char *sysfs_baud_rate = BAUD_RATE_SYSFS;
+static char *sysfs_flow_ctrl = FLOW_CTRL_SYSFS;
+
 /*****************************************************************************/
 #ifdef UIM_DEBUG
 /*  Function to Read the firmware version
@@ -65,6 +71,14 @@
 }
 #endif
 
+void sysfs_entry_fallback(void)
+{
+	sysfs_install_entry = INSTALL_SYSFS_ENTRY_OLD;
+	sysfs_dev_name = DEV_NAME_SYSFS_OLD;
+	sysfs_baud_rate = BAUD_RATE_SYSFS_OLD;
+	sysfs_flow_ctrl = FLOW_CTRL_SYSFS_OLD;
+}
+
 /*****************************************************************************/
 /* Function to read the HCI event from the given file descriptor
  *
@@ -283,9 +297,9 @@
 
 	if (install == '1') {
 		memset(buf, 0, UART_DEV_NAME_LEN);
-		fd = open(DEV_NAME_SYSFS, O_RDONLY);
+		fd = open(sysfs_dev_name, O_RDONLY);
 		if (fd < 0) {
-			UIM_ERR("Can't open %s", DEV_NAME_SYSFS);
+			UIM_ERR("Can't open %s", sysfs_dev_name);
 			return -1;
 		}
 		len = read(fd, buf, UART_DEV_NAME_LEN);
@@ -298,9 +312,9 @@
 		close(fd);
 
 		memset(buf, 0, UART_DEV_NAME_LEN);
-		fd = open(BAUD_RATE_SYSFS, O_RDONLY);
+		fd = open(sysfs_baud_rate, O_RDONLY);
 		if (fd < 0) {
-			UIM_ERR("Can't open %s", BAUD_RATE_SYSFS);
+			UIM_ERR("Can't open %s", sysfs_baud_rate);
 			return -1;
 		}
 		len = read(fd, buf, UART_DEV_NAME_LEN);
@@ -313,9 +327,9 @@
 		sscanf((const char*)buf, "%d", &cust_baud_rate);
 
 		memset(buf, 0, UART_DEV_NAME_LEN);
-		fd = open(FLOW_CTRL_SYSFS, O_RDONLY);
+		fd = open(sysfs_flow_ctrl, O_RDONLY);
 		if (fd < 0) {
-			UIM_ERR("Can't open %s", FLOW_CTRL_SYSFS);
+			UIM_ERR("Can't open %s", sysfs_flow_ctrl);
 			close(fd);
 			return -1;
 		}
@@ -486,14 +500,17 @@
 
 	/* sysfs entry may get populated after service is started so we retry if it fails*/
 	while (trials > 0) {
-		st_fd = open(INSTALL_SYSFS_ENTRY, O_RDONLY);
+		st_fd = open(sysfs_install_entry, O_RDONLY);
 		if(st_fd > 0)
 			break;
-		usleep(500000);
+		if (trials == 3)
+			sysfs_entry_fallback();
+		else
+			usleep(500000);
 		--trials;
 		}
 	if (st_fd < 0) {
-		UIM_DBG("unable to open %s(%s)", INSTALL_SYSFS_ENTRY, strerror(errno));
+		UIM_DBG("unable to open %s(%s)", sysfs_install_entry, strerror(errno));
 		return -1;
 	}
 
@@ -525,9 +542,9 @@
 	}
 
 	close(st_fd);
-	st_fd = open(INSTALL_SYSFS_ENTRY, O_RDONLY);
+	st_fd = open(sysfs_install_entry, O_RDONLY);
 	if (st_fd < 0) {
-		UIM_DBG("unable to open %s (%s)", INSTALL_SYSFS_ENTRY, strerror(errno));
+		UIM_DBG("unable to open %s (%s)", sysfs_install_entry, strerror(errno));
 		return -1;
 	}
 
diff --git a/wpan/uim/uim.h b/wpan/uim/uim.h
index c88d9cc..dc9c5b1 100644
--- a/wpan/uim/uim.h
+++ b/wpan/uim/uim.h
@@ -69,6 +69,10 @@
 #define BAUD_RATE_SYSFS "/sys/devices/platform/kim/baud_rate"
 #define FLOW_CTRL_SYSFS "/sys/devices/platform/kim/flow_cntrl"
 
+#define INSTALL_SYSFS_ENTRY_OLD "/sys/devices/kim/install"
+#define DEV_NAME_SYSFS_OLD "/sys/devices/kim/dev_name"
+#define BAUD_RATE_SYSFS_OLD "/sys/devices/kim/baud_rate"
+#define FLOW_CTRL_SYSFS_OLD "/sys/devices/kim/flow_cntrl"
 
 #define VERBOSE
 /*Debug logs*/