import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / vibrator / mt8127 / vibrator.c
1 /******************************************************************************
2 * mt6575_vibrator.c - MT6575 Android Linux Vibrator Device Driver
3 *
4 * Copyright 2009-2010 MediaTek Co.,Ltd.
5 *
6 * DESCRIPTION:
7 * This file provid the other drivers vibrator relative functions
8 *
9 ******************************************************************************/
10
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/device.h>
16 #include <mach/mt_typedefs.h>
17 #include <cust_vibrator.h>
18 #include <mach/upmu_common_sw.h>
19 #include <mach/upmu_hw.h>
20 #include <linux/delay.h>
21
22 #ifdef CONFIG_MTK_PMIC_MT6397
23 static int vibe_mode = 0;
24 #endif
25 extern S32 pwrap_read( U32 adr, U32 *rdata );
26 extern S32 pwrap_write( U32 adr, U32 wdata );
27 #if 0
28 // pmic wrap read and write func
29 static unsigned int vibr_pmic_pwrap_read(U32 addr)
30 {
31
32 U32 val =0;
33 pwrap_read(addr, &val);
34 return val;
35
36 }
37
38 static void vibr_pmic_pwrap_write(unsigned int addr, unsigned int wdata)
39
40 {
41 //unsigned int val =0;
42 pwrap_write(addr, wdata);
43 }
44 #endif
45 extern void dct_pmic_VIBR_enable(kal_bool dctEnable);
46
47 void vibr_Enable_HW(void)
48 {
49
50
51 printk("[vibrator]vibr_Enable \n");
52
53 #ifdef CONFIG_MTK_PMIC_MT6397
54
55 /*
56 if(hwPowerOn(MT65XX_POWER_LDO_VIBR, VOL_2800, "VIBR")) {
57 ldo_state=1;
58 }
59 */
60 //dct_pmic_VIBR_enable(1);
61
62 upmu_set_rg_vibr_sw_mode(1);// [bit 5]: VIBR_SW_MODE 0=HW, 1=SW
63 upmu_set_rg_vibr_vosel(7); // [bit 11-9]: VIBR_SEL, 101=2.8V, 110=3.0V, 111=3.3V
64 upmu_set_rg_vibr_fr_ori(1); //[bit 4-3]: VIBR_FR_ORI, 00=float, 01=forward, 10=braking, 11=backward
65 //upmu_set_rg_vibr_mst_time(); //[bit 7-6]: VIBR_MST_TIME, 00=1us, 01=2us, 10=4us, 11=8us
66
67 upmu_set_rg_vibr_en(1); //[bit 15]: VIBR_EN, 1=enable
68 upmu_set_rg_vibr_pwdb(1); //[bit 6]: VIBR_PWDB, 1=enable
69
70 #else
71 dct_pmic_VIBR_enable(1);
72 #endif
73
74 return;
75
76 }
77
78 void vibr_Disable_HW(void)
79 {
80 printk("[vibrator]vibr_Disable \n");
81
82 #ifdef CONFIG_MTK_PMIC_MT6397
83
84 /*
85 if(hwPowerDown(MT65XX_POWER_LDO_VIBR, "VIBR")) {
86 ldo_state=0;
87 }
88 */
89 //dct_pmic_VIBR_enable(0);
90 switch(vibe_mode)
91 {
92 case 1:
93 upmu_set_rg_vibr_fr_ori(2); //[bit 4-3]: VIBR_FR_ORI, 00=float, 01=forward, 10=braking, 11=backward
94 upmu_set_rg_vibr_fr_ori(3); //[bit 4-3]: VIBR_FR_ORI, 00=float, 01=forward, 10=braking, 11=backward
95
96 msleep(30); //delay 30ms
97 upmu_set_rg_vibr_fr_ori(2); //[bit 4-3]: VIBR_FR_ORI, 00=float, 01=forward, 10=braking, 11=backward
98 upmu_set_rg_vibr_en(0); //[bit 15]: VIBR_EN, 1=enable
99 upmu_set_rg_vibr_pwdb(0); //[bit 6]: VIBR_PWDB, 1=enable
100 case 0:
101 default:
102 upmu_set_rg_vibr_en(0); //[bit 15]: VIBR_EN, 1=enable
103 upmu_set_rg_vibr_pwdb(0); //[bit 6]: VIBR_PWDB, 1=enable
104 break;
105 }
106 vibe_mode = 0;
107 #else
108 dct_pmic_VIBR_enable(0);
109 #endif
110
111 return;
112 }
113
114 void vibr_power_set(void)
115 {
116 #ifdef CUST_VIBR_VOL
117 struct vibrator_hw* hw = get_cust_vibrator_hw();
118 printk("[vibrator]vibr_init: vibrator set voltage = %d\n", hw->vib_vol);
119 upmu_set_rg_vibr_vosel(hw->vib_vol);
120 #endif
121 }
122
123 struct vibrator_hw* mt_get_cust_vibrator_hw(void)
124 {
125 return get_cust_vibrator_hw();
126 }