tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / input / touchscreen / msg2138 / mstar_drv_platform_interface.c
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2006-2012 MStar Semiconductor, Inc.
4 // All rights reserved.
5 //
6 // Unless otherwise stipulated in writing, any and all information contained
7 // herein regardless in any format shall remain the sole proprietary of
8 // MStar Semiconductor Inc. and be kept in strict confidence
9 // (??MStar Confidential Information??) by the recipient.
10 // Any unauthorized act including without limitation unauthorized disclosure,
11 // copying, use, reproduction, sale, distribution, modification, disassembling,
12 // reverse engineering and compiling of the contents of MStar Confidential
13 // Information is unlawful and strictly prohibited. MStar hereby reserves the
14 // rights to any and all damages, losses, costs and expenses resulting therefrom.
15 //
16 ////////////////////////////////////////////////////////////////////////////////
17
18 /**
19  *
20  * @file    mstar_drv_platform_interface.c
21  *
22  * @brief   This file defines the interface of touch screen
23  *
24  * @version v2.2.0.0
25  *
26  */
27
28 /*=============================================================*/
29 // INCLUDE FILE
30 /*=============================================================*/
31
32 #include "mstar_drv_platform_interface.h"
33 #include "mstar_drv_main.h"
34 #include "mstar_drv_ic_fw_porting_layer.h"
35 #include "mstar_drv_platform_porting_layer.h"
36
37 /*=============================================================*/
38 // EXTERN VARIABLE DECLARATION
39 /*=============================================================*/
40
41 #ifdef CONFIG_ENABLE_GESTURE_WAKEUP
42 extern u16 g_GestureWakeupMode;
43 extern u8 g_GestureWakeupFlag;
44 #endif //CONFIG_ENABLE_GESTURE_WAKEUP
45
46 /*=============================================================*/
47 // GLOBAL VARIABLE DEFINITION
48 /*=============================================================*/
49
50 extern struct input_dev *g_InputDevice;
51
52 /*=============================================================*/
53 // GLOBAL FUNCTION DEFINITION
54 /*=============================================================*/
55
56 void MsDrvInterfaceTouchDeviceSuspend(struct early_suspend *pSuspend)
57 {
58     DBG("*** %s() ***\n", __func__);
59
60 #ifdef CONFIG_ENABLE_GESTURE_WAKEUP
61 //    g_GestureWakeupMode = 0x1FFF; // Enable all gesture wakeup mode for testing 
62
63     if (g_GestureWakeupMode != 0x0000)
64     {
65         DrvIcFwLyrOpenGestureWakeup(g_GestureWakeupMode);
66         return;
67     }
68 #endif //CONFIG_ENABLE_GESTURE_WAKEUP
69
70     DrvPlatformLyrFingerTouchReleased(0, 0); // Send touch end for clearing point touch
71     input_sync(g_InputDevice);
72
73     DrvPlatformLyrDisableFingerTouchReport();
74     DrvPlatformLyrTouchDevicePowerOff(); 
75 }
76
77 void MsDrvInterfaceTouchDeviceResume(struct early_suspend *pSuspend)
78 {
79     DBG("*** %s() ***\n", __func__);
80
81 #ifdef CONFIG_ENABLE_GESTURE_WAKEUP
82     if (g_GestureWakeupFlag == 1)
83     {
84         DrvIcFwLyrCloseGestureWakeup();
85     }
86     else
87     {
88         DrvPlatformLyrEnableFingerTouchReport(); 
89     }
90 #endif //CONFIG_ENABLE_GESTURE_WAKEUP
91     
92     DrvPlatformLyrTouchDevicePowerOn();
93 /*
94     DrvPlatformLyrFingerTouchReleased(0, 0);
95     input_sync(g_InputDevice);
96 */    
97 #ifdef CONFIG_ENABLE_FIRMWARE_DATA_LOG
98     DrvIcFwLyrRestoreFirmwareModeToLogDataMode();
99 #endif //CONFIG_ENABLE_FIRMWARE_DATA_LOG
100
101 #ifndef CONFIG_ENABLE_GESTURE_WAKEUP
102     DrvPlatformLyrEnableFingerTouchReport(); 
103 #endif //CONFIG_ENABLE_GESTURE_WAKEUP
104 }
105
106 #ifdef TOUCH_VIRTUAL_KEYS
107 /*static ssize_t virtual_keys_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
108 {
109         return sprintf(buf,
110                 __stringify(EV_KEY) ":" __stringify(KEY_HOMEPAGE) ":192:1000:64:60"
111                 ":" __stringify(EV_KEY) ":" __stringify(KEY_MENU) ":256:1000:64:60"
112                 ":" __stringify(EV_KEY) ":" __stringify(KEY_BACK) ":128:1000:64:60"
113                 ":" __stringify(EV_KEY) ":" __stringify(KEY_SEARCH) ":64:1000:64:60"
114                 "\n");
115 }*/
116 static ssize_t virtual_keys_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
117 {
118         struct msg2138_ts_platform_data *pdata = g_I2cClient->dev.platform_data;
119         return sprintf(buf,"%s:%s:%d:%d:%d:%d:%s:%s:%d:%d:%d:%d:%s:%s:%d:%d:%d:%d\n"
120                 ,__stringify(EV_KEY), __stringify(KEY_APPSELECT),pdata ->virtualkeys[0],pdata ->virtualkeys[1],pdata ->virtualkeys[2],pdata ->virtualkeys[3]
121                 ,__stringify(EV_KEY), __stringify(KEY_HOMEPAGE),pdata ->virtualkeys[4],pdata ->virtualkeys[5],pdata ->virtualkeys[6],pdata ->virtualkeys[7]
122                 ,__stringify(EV_KEY), __stringify(KEY_BACK),pdata ->virtualkeys[8],pdata ->virtualkeys[9],pdata ->virtualkeys[10],pdata ->virtualkeys[11]);
123 }
124
125 static struct kobj_attribute virtual_keys_attr = {
126     .attr = {
127         .name = "virtualkeys.msg2138_ts",
128         .mode = S_IRUGO,
129     },
130     .show = &virtual_keys_show,
131 };
132
133 static struct attribute *properties_attrs[] = {
134     &virtual_keys_attr.attr,
135     NULL
136 };
137
138 static struct attribute_group properties_attr_group = {
139     .attrs = properties_attrs,
140 };
141
142 static void pixcir_ts_virtual_keys_init(void)
143 {
144     int ret;
145     struct kobject *properties_kobj;
146
147     properties_kobj = kobject_create_and_add("board_properties", NULL);
148     if (properties_kobj)
149         ret = sysfs_create_group(properties_kobj,
150                      &properties_attr_group);
151     if (!properties_kobj || ret)
152         pr_err("failed to create board_properties\n");
153 }
154 #endif
155
156 /* probe function is used for matching and initializing input device */
157 s32 /*__devinit*/ MsDrvInterfaceTouchDeviceProbe(struct i2c_client *pClient, const struct i2c_device_id *pDeviceId)
158 {
159     s32 nRetVal = 0;
160
161     DBG("*** %s() ***\n", __func__);
162
163     DrvPlatformLyrInputDeviceInitialize(pClient);
164
165     nRetVal = DrvPlatformLyrTouchDeviceRequestGPIO();
166     if(nRetVal < 0) {
167         pr_err("[Mstar] DrvPlatformLyrTouchDeviceRequestGPIO failed %d\n",nRetVal);
168         return nRetVal;
169     }
170
171 #ifdef CONFIG_ENABLE_REGULATOR_POWER_ON
172     DrvPlatformLyrTouchDeviceRegulatorPowerOn();
173 #endif //CONFIG_ENABLE_REGULATOR_POWER_ON
174
175     DrvPlatformLyrTouchDevicePowerOn();
176
177     nRetVal = DrvMainTouchDeviceInitialize();
178     if(nRetVal < 0) {
179         pr_err("[Mstar] DrvMainTouchDeviceInitialize failed %d\n",nRetVal);
180         return nRetVal;
181     }
182
183 #ifdef TOUCH_VIRTUAL_KEYS
184     pixcir_ts_virtual_keys_init();
185 #endif
186
187     DrvPlatformLyrTouchDeviceRegisterFingerTouchInterruptHandler();
188
189     DrvPlatformLyrTouchDeviceRegisterEarlySuspend();
190
191     printk("*** MStar touch driver registered ***\n");
192
193     return nRetVal;
194 }
195
196 /* remove function is triggered when the input device is removed from input sub-system */
197 s32 /*__devexit*/ MsDrvInterfaceTouchDeviceRemove(struct i2c_client *pClient)
198 {
199     DBG("*** %s() ***\n", __func__);
200
201     return DrvPlatformLyrTouchDeviceRemove(pClient);
202 }
203
204 void MsDrvInterfaceTouchDeviceSetIicDataRate(struct i2c_client *pClient, u32 nIicDataRate)
205 {
206     DBG("*** %s() ***\n", __func__);
207
208     DrvPlatformLyrSetIicDataRate(pClient, nIicDataRate);
209 }