Tegra: pmc: fix defects flagged during MISRA analysis

Main fixes:

* Fixed if/while statement conditional to be essentially boolean [Rule 14.4]

* Added curly braces ({}) around if/for/while statements in order to
  make them compound [Rule 15.6]

* Added explicit casts (e.g. 0U) to integers in order for them to be
  compatible with whatever operation they're used in [Rule 10.1]

Change-Id: Ic72b248aeede6cf18bf85051188ea7b8fd8ae829
Signed-off-by: Anthony Zhou <anzhou@nvidia.com>
diff --git a/plat/nvidia/tegra/common/drivers/pmc/pmc.c b/plat/nvidia/tegra/common/drivers/pmc/pmc.c
index 09e4c4a..d8827e1 100644
--- a/plat/nvidia/tegra/common/drivers/pmc/pmc.c
+++ b/plat/nvidia/tegra/common/drivers/pmc/pmc.c
@@ -11,8 +11,10 @@
 #include <pmc.h>
 #include <tegra_def.h>
 
+#define RESET_ENABLE	0x10U
+
 /* Module IDs used during power ungate procedure */
-static const int pmc_cpu_powergate_id[4] = {
+static const uint32_t pmc_cpu_powergate_id[4] = {
 	0, /* CPU 0 */
 	9, /* CPU 1 */
 	10, /* CPU 2 */
@@ -23,7 +25,7 @@
  * Power ungate CPU to start the boot process. CPU reset vectors must be
  * populated before calling this function.
  ******************************************************************************/
-void tegra_pmc_cpu_on(int cpu)
+void tegra_pmc_cpu_on(int32_t cpu)
 {
 	uint32_t val;
 
@@ -31,35 +33,34 @@
 	 * Check if CPU is already power ungated
 	 */
 	val = tegra_pmc_read_32(PMC_PWRGATE_STATUS);
-	if (val & (1 << pmc_cpu_powergate_id[cpu]))
-		return;
-
-	/*
-	 * The PMC deasserts the START bit when it starts the power
-	 * ungate process. Loop till no power toggle is in progress.
-	 */
-	do {
-		val = tegra_pmc_read_32(PMC_PWRGATE_TOGGLE);
-	} while (val & PMC_TOGGLE_START);
+	if ((val & (1U << pmc_cpu_powergate_id[cpu])) == 0U) {
+		/*
+		 * The PMC deasserts the START bit when it starts the power
+		 * ungate process. Loop till no power toggle is in progress.
+		 */
+		do {
+			val = tegra_pmc_read_32(PMC_PWRGATE_TOGGLE);
+		} while ((val & PMC_TOGGLE_START) != 0U);
 
-	/*
-	 * Start the power ungate procedure
-	 */
-	val = pmc_cpu_powergate_id[cpu] | PMC_TOGGLE_START;
-	tegra_pmc_write_32(PMC_PWRGATE_TOGGLE, val);
+		/*
+		 * Start the power ungate procedure
+		 */
+		val = pmc_cpu_powergate_id[cpu] | PMC_TOGGLE_START;
+		tegra_pmc_write_32(PMC_PWRGATE_TOGGLE, val);
 
-	/*
-	 * The PMC deasserts the START bit when it starts the power
-	 * ungate process. Loop till powergate START bit is asserted.
-	 */
-	do {
-		val = tegra_pmc_read_32(PMC_PWRGATE_TOGGLE);
-	} while (val & (1 << 8));
+		/*
+		 * The PMC deasserts the START bit when it starts the power
+		 * ungate process. Loop till powergate START bit is asserted.
+		 */
+		do {
+			val = tegra_pmc_read_32(PMC_PWRGATE_TOGGLE);
+		} while ((val & (1U << 8)) != 0U);
 
-	/* loop till the CPU is power ungated */
-	do {
-		val = tegra_pmc_read_32(PMC_PWRGATE_STATUS);
-	} while ((val & (1 << pmc_cpu_powergate_id[cpu])) == 0);
+		/* loop till the CPU is power ungated */
+		do {
+			val = tegra_pmc_read_32(PMC_PWRGATE_STATUS);
+		} while ((val & (1U << pmc_cpu_powergate_id[cpu])) == 0U);
+	}
 }
 
 /*******************************************************************************
@@ -69,9 +70,10 @@
 {
 	uint32_t val;
 
-	tegra_pmc_write_32(PMC_SECURE_SCRATCH34, (reset_addr & 0xFFFFFFFF) | 1);
-	val = reset_addr >> 32;
-	tegra_pmc_write_32(PMC_SECURE_SCRATCH35, val & 0x7FF);
+	tegra_pmc_write_32(PMC_SECURE_SCRATCH34,
+			   ((uint32_t)reset_addr & 0xFFFFFFFFU) | 1U);
+	val = (uint32_t)(reset_addr >> 32U);
+	tegra_pmc_write_32(PMC_SECURE_SCRATCH35, val & 0x7FFU);
 }
 
 /*******************************************************************************
@@ -101,7 +103,7 @@
 	uint32_t reg;
 
 	reg = tegra_pmc_read_32(PMC_CONFIG);
-	reg |= 0x10;		/* restart */
+	reg |= RESET_ENABLE;		/* restart */
 	tegra_pmc_write_32(PMC_CONFIG, reg);
 	wfi();