msm8960: sglte baseband detect

Added support to detect sglte baseband.
Also moved the target specific detection code to target directory.

Change-Id: Iff8c8c538b14fc4d92091a28a62a9dcaec6b8e08
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 5a68a4b..9ca4bce 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -82,6 +82,7 @@
 static const char *baseband_csfb    = " androidboot.baseband=csfb";
 static const char *baseband_svlte2a = " androidboot.baseband=svlte2a";
 static const char *baseband_mdm     = " androidboot.baseband=mdm";
+static const char *baseband_sglte   = " androidboot.baseband=sglte";
 
 /* Assuming unauthorized kernel image by default */
 static int auth_kernel_img = 0;
@@ -205,6 +206,10 @@
 		case BASEBAND_MDM:
 			cmdline_len += strlen(baseband_mdm);
 			break;
+
+		case BASEBAND_SGLTE:
+			cmdline_len += strlen(baseband_sglte);
+			break;
 	}
 
 	if (cmdline_len > 0) {
@@ -281,6 +286,12 @@
 				if (have_cmdline) --dst;
 				while ((*dst++ = *src++));
 				break;
+
+			case BASEBAND_SGLTE:
+				src = baseband_sglte;
+				if (have_cmdline) --dst;
+				while ((*dst++ = *src++));
+				break;
 		}
 		ptr += (n / 4);
 	}
@@ -1096,7 +1107,7 @@
 		}
 	}
 
-	if (!strcmp(ptn->name, "system") 
+	if (!strcmp(ptn->name, "system")
 		|| !strcmp(ptn->name, "userdata")
 		|| !strcmp(ptn->name, "persist")
 		|| !strcmp(ptn->name, "recoveryfs")) {
diff --git a/platform/msm_shared/board.c b/platform/msm_shared/board.c
index 0748837..c9d48bf 100644
--- a/platform/msm_shared/board.c
+++ b/platform/msm_shared/board.c
@@ -31,11 +31,13 @@
 #include <board.h>
 #include <smem.h>
 #include <baseband.h>
+#include <board.h>
 
 static struct board_data board = {UNKNOWN,
 	HW_PLATFORM_UNKNOWN,
 	HW_PLATFORM_SUBTYPE_UNKNOWN,
-	LINUX_MACHTYPE_UNKNOWN,};
+	LINUX_MACHTYPE_UNKNOWN,
+	BASEBAND_MSM};
 
 static void platform_detect()
 {
@@ -69,138 +71,24 @@
 	}
 }
 
-static void target_detect()
-{
-	unsigned platform_id;
-	unsigned platform_hw;
-	unsigned target_id;
-
-	platform_id = board.platform;
-	platform_hw = board.platform_hw;
-
-	/* Detect the board we are running on */
-	if ((platform_id == MSM8960) || (platform_id == MSM8660A)
-	    || (platform_id == MSM8260A) || (platform_id == APQ8060A)) {
-		switch (platform_hw) {
-		case HW_PLATFORM_SURF:
-			target_id = LINUX_MACHTYPE_8960_CDP;
-			break;
-		case HW_PLATFORM_MTP:
-			target_id = LINUX_MACHTYPE_8960_MTP;
-			break;
-		case HW_PLATFORM_FLUID:
-			target_id = LINUX_MACHTYPE_8960_FLUID;
-			break;
-		case HW_PLATFORM_LIQUID:
-			target_id = LINUX_MACHTYPE_8960_LIQUID;
-			break;
-		default:
-			target_id = LINUX_MACHTYPE_8960_CDP;
-		}
-	} else if ((platform_id == MSM8230) || (platform_id == MSM8630)
-		   || (platform_id == MSM8930) || (platform_id == APQ8030)) {
-		switch (platform_hw) {
-		case HW_PLATFORM_SURF:
-			target_id = LINUX_MACHTYPE_8930_CDP;
-			break;
-		case HW_PLATFORM_MTP:
-			target_id = LINUX_MACHTYPE_8930_MTP;
-			break;
-		case HW_PLATFORM_FLUID:
-			target_id = LINUX_MACHTYPE_8930_FLUID;
-			break;
-		default:
-			target_id = LINUX_MACHTYPE_8930_CDP;
-		}
-	} else if ((platform_id == MSM8227) || (platform_id == MSM8627)) {
-		switch (platform_hw) {
-		case HW_PLATFORM_SURF:
-			target_id = LINUX_MACHTYPE_8627_CDP;
-			break;
-		case HW_PLATFORM_MTP:
-			target_id = LINUX_MACHTYPE_8627_MTP;
-			break;
-		default:
-			target_id = LINUX_MACHTYPE_8627_CDP;
-		}
-	} else if (platform_id == MPQ8064) {
-		switch (platform_hw) {
-		case HW_PLATFORM_SURF:
-			target_id = LINUX_MACHTYPE_8064_MPQ_CDP;
-			break;
-		case HW_PLATFORM_HRD:
-			target_id = LINUX_MACHTYPE_8064_HRD;
-			break;
-		case HW_PLATFORM_DTV:
-			target_id = LINUX_MACHTYPE_8064_DTV;
-			break;
-		default:
-			target_id = LINUX_MACHTYPE_8064_MPQ_CDP;
-		}
-	} else if ((platform_id == APQ8064)) {
-		switch (platform_hw) {
-		case HW_PLATFORM_SURF:
-			target_id = LINUX_MACHTYPE_8064_CDP;
-			break;
-		case HW_PLATFORM_MTP:
-			target_id = LINUX_MACHTYPE_8064_MTP;
-			break;
-		case HW_PLATFORM_LIQUID:
-			target_id = LINUX_MACHTYPE_8064_LIQUID;
-			break;
-		default:
-			target_id = LINUX_MACHTYPE_8064_CDP;
-		}
-	} else {
-		dprintf(CRITICAL, "platform_id (%d) is not identified.\n",
-			platform_id);
-		ASSERT(0);
-	}
-	board.target = target_id;
-}
-
-static void baseband_detect()
-{
-	unsigned baseband = BASEBAND_MSM;
-	unsigned platform_subtype;
-	unsigned platform_id;
-
-	platform_id = board.platform;
-	platform_subtype = board.platform_subtype;
-
-	/* Check for MDM or APQ baseband variants.  Default to MSM */
-	if (platform_subtype == HW_PLATFORM_SUBTYPE_MDM)
-		baseband = BASEBAND_MDM;
-	else if (platform_id == APQ8060)
-		baseband = BASEBAND_APQ;
-	else if (platform_id == APQ8064)
-		baseband = BASEBAND_APQ;
-	else if (platform_id == MPQ8064)
-		baseband = BASEBAND_APQ;
-	else
-		baseband = BASEBAND_MSM;
-
-	board.baseband = baseband;
-}
-
 void board_init()
 {
 	platform_detect();
-	target_detect();
-	baseband_detect();
+	target_detect(&board);
+	target_baseband_detect(&board);
 }
 
-unsigned board_platform_id(void)
+uint32_t board_platform_id(void)
 {
 	return board.platform;
 }
 
-unsigned board_target_id()
+uint32_t board_target_id()
 {
 	return board.target;
 }
 
-unsigned board_baseband()
+uint32_t board_baseband()
 {
 	return board.baseband;
 }
diff --git a/platform/msm_shared/include/baseband.h b/platform/msm_shared/include/baseband.h
index 128da30..80f144a 100644
--- a/platform/msm_shared/include/baseband.h
+++ b/platform/msm_shared/include/baseband.h
@@ -36,6 +36,7 @@
 	BASEBAND_SVLTE1 = 3,
 	BASEBAND_SVLTE2A = 4,
 	BASEBAND_MDM = 5,
+	BASEBAND_SGLTE = 6,
 	BASEBAND_32BITS = 0x7FFFFFFF
 };
 
diff --git a/platform/msm_shared/include/board.h b/platform/msm_shared/include/board.h
index 59e19e3..40c0897 100644
--- a/platform/msm_shared/include/board.h
+++ b/platform/msm_shared/include/board.h
@@ -27,35 +27,10 @@
  *
  */
 
-#define LINUX_MACHTYPE_UNKNOWN      0
+#ifndef __BOARD_H
+#define __BOARD_H
 
-/* 8960 */
-#define LINUX_MACHTYPE_8960_SIM     3230
-#define LINUX_MACHTYPE_8960_RUMI3   3231
-#define LINUX_MACHTYPE_8960_CDP     3396
-#define LINUX_MACHTYPE_8960_MTP     3397
-#define LINUX_MACHTYPE_8960_FLUID   3398
-#define LINUX_MACHTYPE_8960_APQ     3399
-#define LINUX_MACHTYPE_8960_LIQUID  3535
-
-/* 8627 */
-#define LINUX_MACHTYPE_8627_CDP     3861
-#define LINUX_MACHTYPE_8627_MTP     3862
-
-/* 8930 */
-#define LINUX_MACHTYPE_8930_CDP     3727
-#define LINUX_MACHTYPE_8930_MTP     3728
-#define LINUX_MACHTYPE_8930_FLUID   3729
-
-/* 8064 */
-#define LINUX_MACHTYPE_8064_SIM     3572
-#define LINUX_MACHTYPE_8064_RUMI3   3679
-#define LINUX_MACHTYPE_8064_CDP     3948
-#define LINUX_MACHTYPE_8064_MTP     3949
-#define LINUX_MACHTYPE_8064_LIQUID  3951
-#define LINUX_MACHTYPE_8064_MPQ_CDP 3993
-#define LINUX_MACHTYPE_8064_HRD     3994
-#define LINUX_MACHTYPE_8064_DTV     3995
+#include <target/board.h>
 
 struct board_data {
 	uint32_t platform;
@@ -66,6 +41,10 @@
 };
 
 void board_init();
-unsigned board_platform_id();
-unsigned board_target_id();
-unsigned board_baseband();
+void target_detect(struct board_data *);
+void target_baseband_detect(struct board_data *);
+uint32_t board_platform_id();
+uint32_t board_target_id();
+uint32_t board_baseband();
+
+#endif
diff --git a/platform/msm_shared/smem.h b/platform/msm_shared/smem.h
index 269ae9f..1144d12 100644
--- a/platform/msm_shared/smem.h
+++ b/platform/msm_shared/smem.h
@@ -11,7 +11,7 @@
  *    notice, this list of conditions and the following disclaimer.
  *  * Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the 
+ *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@@ -21,7 +21,7 @@
  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
@@ -204,6 +204,7 @@
 	HW_PLATFORM_SUBTYPE_CSFB = 1,
 	HW_PLATFORM_SUBTYPE_SVLTE1 = 2,
 	HW_PLATFORM_SUBTYPE_SVLTE2A = 3,
+	HW_PLATFORM_SUBTYPE_SGLTE = 6,
 	HW_PLATFORM_SUBTYPE_32BITS = 0x7FFFFFFF
 };
 
diff --git a/target/msm8960/include/target/board.h b/target/msm8960/include/target/board.h
new file mode 100644
index 0000000..a47f16a
--- /dev/null
+++ b/target/msm8960/include/target/board.h
@@ -0,0 +1,63 @@
+/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __TARGET_BOARD_H
+#define __TARGET_BOARD_H
+
+#define LINUX_MACHTYPE_UNKNOWN     0
+
+/* 8960 */
+#define LINUX_MACHTYPE_8960_SIM     3230
+#define LINUX_MACHTYPE_8960_RUMI3   3231
+#define LINUX_MACHTYPE_8960_CDP     3396
+#define LINUX_MACHTYPE_8960_MTP     3397
+#define LINUX_MACHTYPE_8960_FLUID   3398
+#define LINUX_MACHTYPE_8960_APQ     3399
+#define LINUX_MACHTYPE_8960_LIQUID  3535
+
+/* 8627 */
+#define LINUX_MACHTYPE_8627_CDP     3861
+#define LINUX_MACHTYPE_8627_MTP     3862
+
+/* 8930 */
+#define LINUX_MACHTYPE_8930_CDP     3727
+#define LINUX_MACHTYPE_8930_MTP     3728
+#define LINUX_MACHTYPE_8930_FLUID   3729
+
+/* 8064 */
+#define LINUX_MACHTYPE_8064_SIM     3572
+#define LINUX_MACHTYPE_8064_RUMI3   3679
+#define LINUX_MACHTYPE_8064_CDP     3948
+#define LINUX_MACHTYPE_8064_MTP     3949
+#define LINUX_MACHTYPE_8064_LIQUID  3951
+#define LINUX_MACHTYPE_8064_MPQ_CDP 3993
+#define LINUX_MACHTYPE_8064_HRD     3994
+#define LINUX_MACHTYPE_8064_DTV     3995
+
+#endif
diff --git a/target/msm8960/init.c b/target/msm8960/init.c
index f397153..24f70a4 100644
--- a/target/msm8960/init.c
+++ b/target/msm8960/init.c
@@ -288,3 +288,121 @@
 	}
 }
 
+/* Detect the target type */
+void target_detect(struct board_data *board)
+{
+	uint32_t platform;
+	uint32_t platform_hw;
+	uint32_t target_id;
+
+	platform = board->platform;
+	platform_hw = board->platform_hw;
+
+	/* Detect the board we are running on */
+	if ((platform == MSM8960) || (platform == MSM8660A)
+	    || (platform == MSM8260A) || (platform == APQ8060A)) {
+		switch (platform_hw) {
+		case HW_PLATFORM_SURF:
+			target_id = LINUX_MACHTYPE_8960_CDP;
+			break;
+		case HW_PLATFORM_MTP:
+			target_id = LINUX_MACHTYPE_8960_MTP;
+			break;
+		case HW_PLATFORM_FLUID:
+			target_id = LINUX_MACHTYPE_8960_FLUID;
+			break;
+		case HW_PLATFORM_LIQUID:
+			target_id = LINUX_MACHTYPE_8960_LIQUID;
+			break;
+		default:
+			target_id = LINUX_MACHTYPE_8960_CDP;
+		}
+	} else if ((platform == MSM8230) || (platform == MSM8630)
+		   || (platform == MSM8930) || (platform == APQ8030)) {
+		switch (platform_hw) {
+		case HW_PLATFORM_SURF:
+			target_id = LINUX_MACHTYPE_8930_CDP;
+			break;
+		case HW_PLATFORM_MTP:
+			target_id = LINUX_MACHTYPE_8930_MTP;
+			break;
+		case HW_PLATFORM_FLUID:
+			target_id = LINUX_MACHTYPE_8930_FLUID;
+			break;
+		default:
+			target_id = LINUX_MACHTYPE_8930_CDP;
+		}
+	} else if ((platform == MSM8227) || (platform == MSM8627)) {
+		switch (platform_hw) {
+		case HW_PLATFORM_SURF:
+			target_id = LINUX_MACHTYPE_8627_CDP;
+			break;
+		case HW_PLATFORM_MTP:
+			target_id = LINUX_MACHTYPE_8627_MTP;
+			break;
+		default:
+			target_id = LINUX_MACHTYPE_8627_CDP;
+		}
+	} else if (platform == MPQ8064) {
+		switch (platform_hw) {
+		case HW_PLATFORM_SURF:
+			target_id = LINUX_MACHTYPE_8064_MPQ_CDP;
+			break;
+		case HW_PLATFORM_HRD:
+			target_id = LINUX_MACHTYPE_8064_HRD;
+			break;
+		case HW_PLATFORM_DTV:
+			target_id = LINUX_MACHTYPE_8064_DTV;
+			break;
+		default:
+			target_id = LINUX_MACHTYPE_8064_MPQ_CDP;
+		}
+	} else if ((platform == APQ8064)) {
+		switch (platform_hw) {
+		case HW_PLATFORM_SURF:
+			target_id = LINUX_MACHTYPE_8064_CDP;
+			break;
+		case HW_PLATFORM_MTP:
+			target_id = LINUX_MACHTYPE_8064_MTP;
+			break;
+		case HW_PLATFORM_LIQUID:
+			target_id = LINUX_MACHTYPE_8064_LIQUID;
+			break;
+		default:
+			target_id = LINUX_MACHTYPE_8064_CDP;
+		}
+	} else {
+		dprintf(CRITICAL, "platform (%d) is not identified.\n",
+			platform);
+		ASSERT(0);
+	}
+	board->target = target_id;
+}
+
+/* Detect the modem type */
+void target_baseband_detect(struct board_data *board)
+{
+	uint32_t baseband;
+	uint32_t platform;
+	uint32_t platform_subtype;
+
+	platform         = board->platform;
+	platform_subtype = board->platform_subtype;
+
+	/* Check for baseband variants. Default to MSM */
+	if (platform_subtype == HW_PLATFORM_SUBTYPE_MDM)
+		baseband = BASEBAND_MDM;
+	else if (platform_subtype == HW_PLATFORM_SUBTYPE_SGLTE)
+		baseband = BASEBAND_SGLTE;
+	else if (platform == APQ8060)
+		baseband = BASEBAND_APQ;
+	else if (platform == APQ8064)
+		baseband = BASEBAND_APQ;
+	else if (platform == MPQ8064)
+		baseband = BASEBAND_APQ;
+	else
+		baseband = BASEBAND_MSM;
+
+	board->baseband = baseband;
+}
+