lge_touch_core: Allow disabling the nav keys

picked from https://github.com/CyanogenMod/lge-kernel-gproj/commit/cd7ad350d6c37d7d12b32bf08cc527ee8dd6e355

Change-Id: Ibd640bfff4862b1c35120419b672a51623181d0f
diff --git a/drivers/input/touchscreen/lge_touch_core.c b/drivers/input/touchscreen/lge_touch_core.c
index 72f221c..1dd21ae 100644
--- a/drivers/input/touchscreen/lge_touch_core.c
+++ b/drivers/input/touchscreen/lge_touch_core.c
@@ -65,6 +65,7 @@
 	void*			h_touch;
 	atomic_t		next_work;
 	atomic_t		device_init;
+	atomic_t        keypad_enable;
 	u8				work_sync_err_cnt;
 	u8				ic_init_err_cnt;
 	volatile int	curr_pwr_state;
@@ -1844,6 +1845,7 @@
 	}
 
 	/* Button handle */
+	if (atomic_read(&ts->keypad_enable))
 	if (ts->ts_data.state != TOUCH_BUTTON_LOCK) {
 		/* do not check when there is no pressed button at error case
 		 * 	- if you check it, sometimes touch is locked becuase button pressed via IC error.
@@ -1933,19 +1935,24 @@
 	return x >= rt.left && x <= rt.right && y >= rt.top && y <= rt.bottom;
 }
 
-static u16 find_button(const struct t_data data, const struct section_info sc)
+static u16 find_button(struct lge_touch_data *ts)
 {
-	int i;
+    int i;
+    const struct t_data data = ts->ts_data.curr_data[0];
+    const struct section_info sc = ts->st_info;
 
-	if (is_in_section(sc.panel, data.x_position, data.y_position))
-		return KEY_PANEL;
+    if (is_in_section(sc.panel, data.x_position, data.y_position))
+	    return KEY_PANEL;
 
-	for(i=0; i<sc.b_num; i++){
-		if (is_in_section(sc.button[i], data.x_position, data.y_position))
-			return sc.b_name[i];
-	}
+	if (!atomic_read(&ts->keypad_enable))
+	    return KEY_BOUNDARY;
 
-	return KEY_BOUNDARY;
+    for(i=0; i<sc.b_num; i++){
+        if (is_in_section(sc.button[i], data.x_position, data.y_position))
+            return sc.b_name[i];
+    }
+
+    return KEY_BOUNDARY;
 }
 
 static bool check_cancel(u16 button, u16 x, u16 y, const struct section_info sc)
@@ -2014,7 +2021,7 @@
 			}
 		}
 
-		tmp_button = find_button(ts->ts_data.curr_data[id], ts->st_info);
+		tmp_button = find_button(ts);
 		if (unlikely(touch_debug_mask & DEBUG_BUTTON))
 			TOUCH_INFO_MSG("button_now [%d]\n", tmp_button);
 
@@ -3269,6 +3276,33 @@
 	return ret;
 }
 #endif
+
+static ssize_t keypad_enable_read(struct lge_touch_data *ts, char *buf)
+{
+    return sprintf(buf, "%d\n", atomic_read(&ts->keypad_enable));
+}
+
+static int keypad_enable_store(struct lge_touch_data *ts, const char *buf, size_t count)
+{
+    unsigned int val = 0;
+    sscanf(buf, "%d", &val);
+    val = (val == 0 ? 0:1);
+    atomic_set(&ts->keypad_enable, val);
+    if (val) {
+        set_bit(KEY_BACK, ts->input_dev->keybit);
+        set_bit(KEY_MENU, ts->input_dev->keybit);
+        set_bit(KEY_HOME, ts->input_dev->keybit);
+        set_bit(KEY_SEARCH, ts->input_dev->keybit);
+    } else {
+        clear_bit(KEY_BACK, ts->input_dev->keybit);
+        clear_bit(KEY_MENU, ts->input_dev->keybit);
+        clear_bit(KEY_HOME, ts->input_dev->keybit);
+        clear_bit(KEY_SEARCH, ts->input_dev->keybit);
+    }
+    input_sync(ts->input_dev);
+    return count;
+}
+
 static LGE_TOUCH_ATTR(platform_data, S_IRUGO | S_IWUSR, show_platform_data, NULL);
 static LGE_TOUCH_ATTR(firmware, S_IRUGO | S_IWUSR, show_fw_info, store_fw_upgrade);
 static LGE_TOUCH_ATTR(fw_ver, S_IRUGO | S_IWUSR, show_fw_ver, NULL);
@@ -3291,6 +3325,7 @@
 static LGE_TOUCH_ATTR(pen_enable, S_IRUGO | S_IWUSR, show_pen_enable, NULL);
 static LGE_TOUCH_ATTR(ts_noise, S_IRUGO | S_IWUSR, show_ts_noise, NULL);
 #endif
+static LGE_TOUCH_ATTR(keypad_enable, S_IRUGO | S_IWUSR, keypad_enable_read, keypad_enable_store);
 
 static struct attribute *lge_touch_attribute_list[] = {
 	&lge_touch_attr_platform_data.attr,
@@ -3315,6 +3350,7 @@
 	&lge_touch_attr_pen_enable.attr,
 	&lge_touch_attr_ts_noise.attr,
 #endif
+    &lge_touch_attr_keypad_enable.attr,
 	NULL,
 };
 
@@ -3600,6 +3636,8 @@
 	register_early_suspend(&ts->early_suspend);
 #endif
 
+    atomic_set(&ts->keypad_enable, 1);
+
 	/* Register sysfs for making fixed communication path to framework layer */
 	ret = sysdev_class_register(&lge_touch_sys_class);
 	if (ret < 0) {