Merge "platform: msm_shared: remove unused code from DSI config"
diff --git a/platform/msm8916/include/platform/irqs.h b/platform/msm8916/include/platform/irqs.h
index c3f6f8f..4211c77 100644
--- a/platform/msm8916/include/platform/irqs.h
+++ b/platform/msm8916/include/platform/irqs.h
@@ -35,6 +35,7 @@
  * 16-31: PPI (private peripheral interrupts)
  * 32+:   SPI (shared peripheral interrupts)
  */
+int qtmr_irq();
 
 #define GIC_PPI_START                          16
 #define GIC_SPI_START                          32
@@ -42,7 +43,9 @@
 #define INT_QTMR_NON_SECURE_PHY_TIMER_EXP      (GIC_PPI_START + 3)
 #define INT_QTMR_VIRTUAL_TIMER_EXP             (GIC_PPI_START + 4)
 
-#define INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP      (GIC_SPI_START + 8)
+#define INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP      qtmr_irq()
+#define INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16 (GIC_SPI_START + 8)
+#define INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39 (GIC_SPI_START + 257)
 #define SDCC1_PWRCTL_IRQ                       (GIC_SPI_START + 138)
 #define SDCC2_PWRCTL_IRQ                       (GIC_SPI_START + 221)
 
diff --git a/platform/msm8916/platform.c b/platform/msm8916/platform.c
index 25d45a7..1b60c18 100644
--- a/platform/msm8916/platform.c
+++ b/platform/msm8916/platform.c
@@ -29,6 +29,7 @@
 #include <debug.h>
 #include <reg.h>
 #include <platform/iomap.h>
+#include <platform/irqs.h>
 #include <qgic.h>
 #include <qtimer.h>
 #include <mmu.h>
@@ -64,6 +65,8 @@
 
 static struct smem_ram_ptable ram_ptable;
 
+static int platform_is_msm8939();
+
 void platform_early_init(void)
 {
 	board_init();
@@ -72,6 +75,14 @@
 	qtimer_init();
 }
 
+int qtmr_irq()
+{
+	if (platform_is_msm8939())
+		return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
+	else
+		return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
+}
+
 void platform_init(void)
 {
 	dprintf(INFO, "platform_init()\n");
@@ -165,3 +176,24 @@
 	/* Using 1-1 mapping on this platform. */
 	return phys_addr;
 }
+
+static int platform_is_msm8939()
+{
+	uint32_t platform = board_platform_id();
+	uint32_t ret = 0;
+
+	switch(platform)
+	{
+		case MSM8939:
+		case APQ8036:
+		case APQ8039:
+		case MSM8236:
+		case MSM8636:
+			ret = 1;
+			break;
+		default:
+			ret = 0;
+	};
+
+	return ret;
+}
diff --git a/platform/msm_shared/include/qgic.h b/platform/msm_shared/include/qgic.h
index 45607ff..ce5db4c 100644
--- a/platform/msm_shared/include/qgic.h
+++ b/platform/msm_shared/include/qgic.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -55,6 +55,10 @@
 #define GIC_DIST_TARGET             GIC_DIST_REG(0x800)
 #define GIC_DIST_CONFIG             GIC_DIST_REG(0xc00)
 #define GIC_DIST_SOFTINT            GIC_DIST_REG(0xf00)
+#define MAX_CPUS_PER_CLUSTER        0x4
+
+/* Bits [15:8] of the mpidr contain the cluster ID*/
+#define CLUSTER_ID_OFFSET           0x8
 
 struct ihandler {
 	int_handler func;
diff --git a/platform/msm_shared/qgic.c b/platform/msm_shared/qgic.c
index e7888d1..8eab7b5 100644
--- a/platform/msm_shared/qgic.c
+++ b/platform/msm_shared/qgic.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2008, Google Inc.
  * All rights reserved.
  *
- * Copyright (c) 2009-2011, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2011,2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -46,6 +46,25 @@
 	uint32_t i;
 	uint32_t num_irq = 0;
 	uint32_t cpumask = 1;
+	uint32_t mpidr;
+	uint32_t core = 0;
+	uint32_t cluster;
+	uint32_t cpu_id;
+
+	/* Read the mpidr register to find out the boot up cluster */
+	__asm__ volatile("mrc p15, 0, %0, c0, c0, 5" : "=r" (mpidr));
+
+	/* Bits [15:8] of the mpidr contain the cluster ID*/
+	cluster = (mpidr & 0xff00) >> CLUSTER_ID_OFFSET;
+
+	/* Bits [7:0] of the mpidr gives the CPU id*/
+	cpu_id = mpidr & 0xff;
+
+	/* According to the cluster and CPU id, select the core currently running */
+	core = (cpu_id + cluster * MAX_CPUS_PER_CLUSTER);
+
+	/* Based on the core,shift the bit to adjust the cpumask */
+	cpumask = cpumask << core;
 
 	cpumask |= cpumask << 8;
 	cpumask |= cpumask << 16;