Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d2719a5 authored by Mohan Pallaka's avatar Mohan Pallaka Committed by Alex Sarraf
Browse files

input: gen_vkeys: squash commit from 3.14-kernel



Squash and apply the following changes taken from the msm-3.14
kernel branch as of msm-3.14
commit 8139d0b4e7a6d ("ARM: dts: msm: Set flag to manage clks")

commit c24a3df92a457643cc0821eb9e8f392ae5a907ee
Author: Amy Maloche <amaloche@codeaurora.org>
Date:   Thu May 9 10:23:41 2013 -0700

    input: gen_vkeys: Make y_offset an optional property

    Not all targets will need the y coordinate shifted to
    function properly, so set this value as default 0.

    Change-Id: I1816433c3601fe099ffb8ee275637e573990e432
    Signed-off-by: default avatarAmy Maloche <amaloche@codeaurora.org>

 Documentation/devicetree/bindings/input/gen_vkeys.txt
 drivers/input/touchscreen/gen_vkeys.c
 2 files changed, 13 insertions(+), 5 deletions(-)
commit bb2ac18f8fab38fa12d8a7d8b7ee80d9c0049329
Author: Amy Maloche <amaloche@codeaurora.org>
Date:   Wed Apr 17 12:15:56 2013 -0700

    vkeys: gen_vkeys: Add key position offset

    Add virtual key position offset to match virtual key
	positions with front panel.

    Change-Id: Ibbf89e816d9654f202b75470df0c673aa42439c8
    Acked-by: default avatarChun Zhang <chunz@qti.qualcomm.com>
    Signed-off-by: default avatarAmy Maloche <amaloche@codeaurora.org>

 Documentation/devicetree/bindings/input/gen_vkeys.txt
 drivers/input/touchscreen/gen_vkeys.c
 include/linux/input/gen_vkeys.h
 3 files changed, 10 insertions(+), 2 deletions(-)
commit 1a6d213cf5a3e40d8b39507e2b010dc81de63630
Author: Mohan Pallaka <mpallaka@codeaurora.org>
Date:   Wed Aug 8 11:25:52 2012 +0530

    input: Add support for virtual key generation

    Virtual keys are used for navigation on Android.
    These are not specific to the controller used
    in the target but are specific to the target.
    Add a module to generate virtual keys independently
    of the controller.

    Change-Id: I0c86dc77f1bc53c283e990be419c2715edf4e1c0
    Signed-off-by: default avatarMohan Pallaka <mpallaka@codeaurora.org>
    Signed-off-by: default avatarAmy Maloche <amaloche@codeaurora.org>
    [stepanm@codeaurora.org: resolve Kconfig conflicts]
    Signed-off-by: default avatarStepan Moskovchenko <stepanm@codeaurora.org>

 .../devicetree/bindings/input/gen_vkeys.txt
 drivers/input/touchscreen/Kconfig
 drivers/input/touchscreen/Makefile
 drivers/input/touchscreen/gen_vkeys.c
 include/linux/input/gen_vkeys.h
 5 files changed, 278 insertions(+)

Change-Id: Ie0e14d201a42632af57ff23dc85cec8881125e5a
Signed-off-by: default avatarAlex Sarraf <asarraf@codeaurora.org>
parent 8e6fdb81
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
Touchscreen Virtual Keys Device

Generate virtual keys sysfs entry for Android

Required properties:

 - compatible	: should be "qcom,gen-vkeys"
 - label		: name of the touch controller
 - qcom,disp-maxx	: Maximum x-coordinate of display
 - qcom,disp-maxy	: Maximum y-coordinate of display
 - qcom,panel-maxx	: Maximum x-coordinate of touch panel
 - qcom,panel-maxy	: Maximum y-coordinate of touch panel
 - qcom,key-codes	: Array of key codes for virtual keys

Optional properties:
 - qcom,y-offset	: Offset of y-location for virtual keys, default 0

Example:
	gen-vkeys {
		compatible = "qcom,gen-vkeys";
		label = "atmel_mxt_ts";
		qcom,disp-maxx = <720>;
		qcom,disp-maxy = <1280>;
		qcom,panel-maxx = <760>;
		qcom,panel-maxy = <1424>;
		qcom,key-codes = <158 139 102 217>;
		qcom,y-offset = <35>;
	};
+11 −0
Original line number Diff line number Diff line
@@ -998,4 +998,15 @@ config TOUCHSCREEN_IT7260_I2C
	  To compile this driver as a module, choose M here: the
	  module will be called it7258_ts_i2c.

config TOUCHSCREEN_GEN_VKEYS
       tristate "Touchscreen Virtual Keys Driver"
       help
         Say Y here if you want to generate a sysfs entry for virtual
	 keys on Android.

         If unsure, say N.

         To compile this driver as a module, choose M here: the
         module will be called gen_vkeys.

endif
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o
obj-$(CONFIG_TOUCHSCREEN_ELO)		+= elo.o
obj-$(CONFIG_TOUCHSCREEN_EGALAX)	+= egalax_ts.o
obj-$(CONFIG_TOUCHSCREEN_FUJITSU)	+= fujitsu_ts.o
obj-$(CONFIG_TOUCHSCREEN_GEN_VKEYS)	+= gen_vkeys.o
obj-$(CONFIG_TOUCHSCREEN_ILI210X)	+= ili210x.o
obj-$(CONFIG_TOUCHSCREEN_INEXIO)	+= inexio.o
obj-$(CONFIG_TOUCHSCREEN_INTEL_MID)	+= intel-mid-touch.o
+230 −0
Original line number Diff line number Diff line
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/input.h>
#include <linux/input/gen_vkeys.h>

#define MAX_BUF_SIZE	256
#define VKEY_VER_CODE	"0x01"

#define HEIGHT_SCALE_NUM 8
#define HEIGHT_SCALE_DENOM 10

#define VKEY_Y_OFFSET_DEFAULT 0

/* numerator and denomenator for border equations */
#define BORDER_ADJUST_NUM 3
#define BORDER_ADJUST_DENOM 4

static struct kobject *vkey_obj;
static char *vkey_buf;

static ssize_t vkey_show(struct kobject  *obj,
		struct kobj_attribute *attr, char *buf)
{
	strlcpy(buf, vkey_buf, MAX_BUF_SIZE);
	return strnlen(buf, MAX_BUF_SIZE);
}

static struct kobj_attribute vkey_obj_attr = {
	.attr = {
		.mode = S_IRUGO,
	},
	.show = vkey_show,
};

static struct attribute *vkey_attr[] = {
	&vkey_obj_attr.attr,
	NULL,
};

static struct attribute_group vkey_grp = {
	.attrs = vkey_attr,
};

static int vkey_parse_dt(struct device *dev,
			struct vkeys_platform_data *pdata)
{
	struct device_node *np = dev->of_node;
	struct property *prop;
	int rc, val;

	rc = of_property_read_string(np, "label", &pdata->name);
	if (rc) {
		dev_err(dev, "Failed to read label\n");
		return -EINVAL;
	}

	rc = of_property_read_u32(np, "qcom,disp-maxx", &pdata->disp_maxx);
	if (rc) {
		dev_err(dev, "Failed to read display max x\n");
		return -EINVAL;
	}

	rc = of_property_read_u32(np, "qcom,disp-maxy", &pdata->disp_maxy);
	if (rc) {
		dev_err(dev, "Failed to read display max y\n");
		return -EINVAL;
	}

	rc = of_property_read_u32(np, "qcom,panel-maxx", &pdata->panel_maxx);
	if (rc) {
		dev_err(dev, "Failed to read panel max x\n");
		return -EINVAL;
	}

	rc = of_property_read_u32(np, "qcom,panel-maxy", &pdata->panel_maxy);
	if (rc) {
		dev_err(dev, "Failed to read panel max y\n");
		return -EINVAL;
	}

	prop = of_find_property(np, "qcom,key-codes", NULL);
	if (prop) {
		pdata->num_keys = prop->length / sizeof(u32);
		pdata->keycodes = devm_kzalloc(dev,
			sizeof(u32) * pdata->num_keys, GFP_KERNEL);
		if (!pdata->keycodes)
			return -ENOMEM;
		rc = of_property_read_u32_array(np, "qcom,key-codes",
				pdata->keycodes, pdata->num_keys);
		if (rc) {
			dev_err(dev, "Failed to read key codes\n");
			return -EINVAL;
		}
	}

	pdata->y_offset = VKEY_Y_OFFSET_DEFAULT;
	rc = of_property_read_u32(np, "qcom,y-offset", &val);
	if (!rc)
		pdata->y_offset = val;
	else if (rc != -EINVAL) {
		dev_err(dev, "Failed to read y position offset\n");
		return rc;
	}
	return 0;
}

static int vkeys_probe(struct platform_device *pdev)
{
	struct vkeys_platform_data *pdata;
	int width, height, center_x, center_y;
	int x1 = 0, x2 = 0, i, c = 0, ret, border;
	char *name;

	vkey_buf = devm_kzalloc(&pdev->dev, MAX_BUF_SIZE, GFP_KERNEL);
	if (!vkey_buf) {
		dev_err(&pdev->dev, "Failed to allocate memory\n");
		return -ENOMEM;
	}

	if (pdev->dev.of_node) {
		pdata = devm_kzalloc(&pdev->dev,
			sizeof(struct vkeys_platform_data), GFP_KERNEL);
		if (!pdata) {
			dev_err(&pdev->dev, "Failed to allocate memory\n");
			return -ENOMEM;
		}

		ret = vkey_parse_dt(&pdev->dev, pdata);
		if (ret) {
			dev_err(&pdev->dev, "Parsing DT failed(%d)", ret);
			return ret;
		}
	} else
		pdata = pdev->dev.platform_data;

	if (!pdata || !pdata->name || !pdata->keycodes || !pdata->num_keys ||
		!pdata->disp_maxx || !pdata->disp_maxy || !pdata->panel_maxy) {
		dev_err(&pdev->dev, "pdata is invalid\n");
		return -EINVAL;
	}

	border = (pdata->panel_maxx - pdata->disp_maxx) * 2;
	width = ((pdata->disp_maxx - (border * (pdata->num_keys - 1)))
			/ pdata->num_keys);
	height = (pdata->panel_maxy - pdata->disp_maxy);
	center_y = pdata->disp_maxy + (height / 2) + pdata->y_offset;
	height = height * HEIGHT_SCALE_NUM / HEIGHT_SCALE_DENOM;

	x2 -= border * BORDER_ADJUST_NUM / BORDER_ADJUST_DENOM;

	for (i = 0; i < pdata->num_keys; i++) {
		x1 = x2 + border;
		x2 = x2 + border + width;
		center_x = x1 + (x2 - x1) / 2;
		c += snprintf(vkey_buf + c, MAX_BUF_SIZE - c,
				"%s:%d:%d:%d:%d:%d\n",
				VKEY_VER_CODE, pdata->keycodes[i],
				center_x, center_y, width, height);
	}

	vkey_buf[c] = '\0';

	name = devm_kzalloc(&pdev->dev, sizeof(*name) * MAX_BUF_SIZE,
					GFP_KERNEL);
	if (!name)
		return -ENOMEM;

	snprintf(name, MAX_BUF_SIZE,
				"virtualkeys.%s", pdata->name);
	vkey_obj_attr.attr.name = name;

	vkey_obj = kobject_create_and_add("board_properties", NULL);
	if (!vkey_obj) {
		dev_err(&pdev->dev, "unable to create kobject\n");
		return -ENOMEM;
	}

	ret = sysfs_create_group(vkey_obj, &vkey_grp);
	if (ret) {
		dev_err(&pdev->dev, "failed to create attributes\n");
		goto destroy_kobj;
	}
	return 0;

destroy_kobj:
	kobject_put(vkey_obj);

	return ret;
}

static int vkeys_remove(struct platform_device *pdev)
{
	sysfs_remove_group(vkey_obj, &vkey_grp);
	kobject_put(vkey_obj);

	return 0;
}

static struct of_device_id vkey_match_table[] = {
	{ .compatible = "qcom,gen-vkeys",},
	{ },
};

static struct platform_driver vkeys_driver = {
	.probe = vkeys_probe,
	.remove = vkeys_remove,
	.driver = {
		.owner = THIS_MODULE,
		.name = "gen_vkeys",
		.of_match_table = vkey_match_table,
	},
};

module_platform_driver(vkeys_driver);
MODULE_LICENSE("GPL v2");
+24 −0
Original line number Diff line number Diff line
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __GEN_VKEYS_
struct vkeys_platform_data {
	const char *name;
	int disp_maxx;
	int disp_maxy;
	int panel_maxx;
	int panel_maxy;
	int *keycodes;
	int num_keys;
	int y_offset;
};
#endif