dev: pmic: Move the old-gen vibrator to the common pm8x41 file

QM215 uses the msm8952 platform configuration. The PMIC supported
on QM215 is PM8916 which uses the old-gen vibrator. To support
both the vibrators (PM8916 and PMI8950/37) add logic which
detects the PMIC type and calls into the right vibrator function.

Change-Id: I75999c0d7e16e831947e537fc54d538be376fd99
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
diff --git a/dev/pmic/pm8x41/include/pm8x41.h b/dev/pmic/pm8x41/include/pm8x41.h
index 014834a..3f0a83d 100644
--- a/dev/pmic/pm8x41/include/pm8x41.h
+++ b/dev/pmic/pm8x41/include/pm8x41.h
@@ -250,4 +250,6 @@
 int pm_pwm_config(unsigned int duty_us, unsigned int period_us);
 uint32_t spmi_reg_read(uint32_t slave_id, uint16_t addr, uint8_t *data, uint8_t priority);
 uint32_t spmi_reg_write(uint32_t slave_id, uint16_t addr, uint8_t *data, uint8_t priority);
+void pm8x41_vib_turn_on(void);
+void pm8x41_vib_turn_off(void);
 #endif
diff --git a/dev/pmic/pm8x41/pm8x41.c b/dev/pmic/pm8x41/pm8x41.c
index 4e0b85a..6575f95 100644
--- a/dev/pmic/pm8x41/pm8x41.c
+++ b/dev/pmic/pm8x41/pm8x41.c
@@ -36,6 +36,9 @@
 #include <rpm-ipc.h>
 #include <regulator.h>
 #include <platform/timer.h>
+#include <pm_vib.h>
+
+#define QPNP_VIB_EN    BIT(7)
 
 /* Enable LN BB CLK */
 static uint32_t ln_bb_clk[][8] = {
@@ -841,3 +844,27 @@
 
 	return batt_is_broken;
 }
+
+void pm8x41_vib_turn_on(void)
+{
+	uint8_t val;
+
+	val = pm8x41_reg_read(QPNP_VIB_VTG_CTL);
+	val &= ~QPNP_VIB_VTG_SET_MASK;
+	val |= (QPNP_VIB_DEFAULT_VTG_LVL & QPNP_VIB_VTG_SET_MASK);
+	pm8x41_reg_write(QPNP_VIB_VTG_CTL, val);
+
+	val = pm8x41_reg_read(QPNP_VIB_EN_CTL);
+	val |= QPNP_VIB_EN;
+	pm8x41_reg_write(QPNP_VIB_EN_CTL, val);
+}
+
+/* Turn off vibrator */
+void pm8x41_vib_turn_off(void)
+{
+	uint8_t val;
+
+	val = pm8x41_reg_read(QPNP_VIB_EN_CTL);
+	val &= ~QPNP_VIB_EN;
+	pm8x41_reg_write(QPNP_VIB_EN_CTL, val);
+}
diff --git a/dev/pmic/pm8x41/pm8x41_vib.c b/dev/pmic/pm8x41/pm8x41_vib.c
index 3246b9f..23f2246 100644
--- a/dev/pmic/pm8x41/pm8x41_vib.c
+++ b/dev/pmic/pm8x41/pm8x41_vib.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014-2015, 2018, 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
@@ -30,29 +30,14 @@
 #include <pm8x41_hw.h>
 #include <pm_vib.h>
 
-#define QPNP_VIB_EN    BIT(7)
-
 /* Turn on vibrator */
 void pm_vib_turn_on(void)
 {
-	uint8_t val;
-
-	val = pm8x41_reg_read(QPNP_VIB_VTG_CTL);
-	val &= ~QPNP_VIB_VTG_SET_MASK;
-	val |= (QPNP_VIB_DEFAULT_VTG_LVL & QPNP_VIB_VTG_SET_MASK);
-	pm8x41_reg_write(QPNP_VIB_VTG_CTL, val);
-
-	val = pm8x41_reg_read(QPNP_VIB_EN_CTL);
-	val |= QPNP_VIB_EN;
-	pm8x41_reg_write(QPNP_VIB_EN_CTL, val);
+	pm8x41_vib_turn_on();
 }
 
 /* Turn off vibrator */
 void pm_vib_turn_off(void)
 {
-	uint8_t val;
-
-	val = pm8x41_reg_read(QPNP_VIB_EN_CTL);
-	val &= ~QPNP_VIB_EN;
-	pm8x41_reg_write(QPNP_VIB_EN_CTL, val);
+	pm8x41_vib_turn_off();
 }
diff --git a/dev/vib/vibrator.c b/dev/vib/vibrator.c
index 8c7a031..4100c5e 100644
--- a/dev/vib/vibrator.c
+++ b/dev/vib/vibrator.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014-2016, 2018, 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
@@ -31,6 +31,10 @@
 #include <kernel/thread.h>
 #include <pm_vib.h>
 #include <vibrator.h>
+#include <pm8x41.h>
+#include <platform.h>
+#include <smem.h>
+#include <target.h>
 
 #define CHECK_VIB_TIMER_FREQUENCY    50
 
@@ -49,13 +53,23 @@
 /* Function to turn on vibrator */
 void vib_turn_on()
 {
-	pm_vib_turn_on();
+	uint32_t pmic = target_get_pmic();
+
+	if (pmic == PMIC_IS_PM8916)
+		pm8x41_vib_turn_on();
+	else
+		pm_vib_turn_on();
 }
 
 /* Function to turn off vibrator */
 void vib_turn_off()
 {
-	pm_vib_turn_off();
+	uint32_t pmic = target_get_pmic();
+
+	if (pmic == PMIC_IS_PM8916)
+		pm8x41_vib_turn_off();
+	else
+		pm_vib_turn_off();
 }
 
 #if !USE_VIB_THREAD