2014-05-29 14:51:53 +08:00
|
|
|
/*
|
|
|
|
* Generic DT helper functions for touchscreen devices
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Sebastian Reichel <sre@kernel.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-07-07 06:18:24 +08:00
|
|
|
#include <linux/property.h>
|
2014-05-29 14:51:53 +08:00
|
|
|
#include <linux/input.h>
|
2015-03-22 11:17:57 +08:00
|
|
|
#include <linux/input/mt.h>
|
2014-05-29 14:51:53 +08:00
|
|
|
#include <linux/input/touchscreen.h>
|
|
|
|
|
2015-07-07 06:18:24 +08:00
|
|
|
static bool touchscreen_get_prop_u32(struct device *dev,
|
2015-06-02 01:35:16 +08:00
|
|
|
const char *property,
|
|
|
|
unsigned int default_value,
|
|
|
|
unsigned int *value)
|
2015-03-22 11:17:48 +08:00
|
|
|
{
|
2015-06-02 01:35:16 +08:00
|
|
|
u32 val;
|
|
|
|
int error;
|
2015-03-22 11:17:48 +08:00
|
|
|
|
2015-07-07 06:18:24 +08:00
|
|
|
error = device_property_read_u32(dev, property, &val);
|
2015-06-02 01:35:16 +08:00
|
|
|
if (error) {
|
|
|
|
*value = default_value;
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-22 11:17:48 +08:00
|
|
|
|
2015-06-02 01:35:16 +08:00
|
|
|
*value = val;
|
|
|
|
return true;
|
2015-03-22 11:17:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void touchscreen_set_params(struct input_dev *dev,
|
|
|
|
unsigned long axis,
|
|
|
|
int max, int fuzz)
|
|
|
|
{
|
|
|
|
struct input_absinfo *absinfo;
|
|
|
|
|
|
|
|
if (!test_bit(axis, dev->absbit)) {
|
2015-07-07 05:45:25 +08:00
|
|
|
dev_warn(&dev->dev,
|
|
|
|
"DT specifies parameters but the axis %lu is not set up\n",
|
|
|
|
axis);
|
2015-03-22 11:17:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
absinfo = &dev->absinfo[axis];
|
|
|
|
absinfo->maximum = max;
|
|
|
|
absinfo->fuzz = fuzz;
|
|
|
|
}
|
|
|
|
|
2014-05-29 14:51:53 +08:00
|
|
|
/**
|
2015-07-07 06:18:24 +08:00
|
|
|
* touchscreen_parse_properties - parse common touchscreen DT properties
|
|
|
|
* @input: input device that should be parsed
|
|
|
|
* @multitouch: specifies whether parsed properties should be applied to
|
|
|
|
* single-touch or multi-touch axes
|
2014-05-29 14:51:53 +08:00
|
|
|
*
|
|
|
|
* This function parses common DT properties for touchscreens and setups the
|
2015-07-07 06:18:24 +08:00
|
|
|
* input device accordingly. The function keeps previously set up default
|
2014-05-29 14:51:53 +08:00
|
|
|
* values if no value is specified via DT.
|
|
|
|
*/
|
2015-07-07 06:18:24 +08:00
|
|
|
void touchscreen_parse_properties(struct input_dev *input, bool multitouch)
|
2014-05-29 14:51:53 +08:00
|
|
|
{
|
2015-07-07 06:18:24 +08:00
|
|
|
struct device *dev = input->dev.parent;
|
2015-06-02 01:35:16 +08:00
|
|
|
unsigned int axis;
|
|
|
|
unsigned int maximum, fuzz;
|
|
|
|
bool data_present;
|
2014-05-29 14:51:53 +08:00
|
|
|
|
2015-07-07 06:18:24 +08:00
|
|
|
input_alloc_absinfo(input);
|
|
|
|
if (!input->absinfo)
|
2014-05-29 14:51:53 +08:00
|
|
|
return;
|
|
|
|
|
2015-06-02 01:35:16 +08:00
|
|
|
axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
|
2015-07-07 06:18:24 +08:00
|
|
|
data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-x",
|
|
|
|
input_abs_get_max(input,
|
2015-07-07 05:57:54 +08:00
|
|
|
axis) + 1,
|
2015-06-02 01:35:16 +08:00
|
|
|
&maximum) |
|
2015-07-07 06:18:24 +08:00
|
|
|
touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
|
|
|
|
input_abs_get_fuzz(input, axis),
|
2015-06-02 01:35:16 +08:00
|
|
|
&fuzz);
|
|
|
|
if (data_present)
|
2015-07-07 06:18:24 +08:00
|
|
|
touchscreen_set_params(input, axis, maximum - 1, fuzz);
|
2014-05-29 14:51:53 +08:00
|
|
|
|
2015-06-02 01:35:16 +08:00
|
|
|
axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
|
2015-07-07 06:18:24 +08:00
|
|
|
data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-y",
|
|
|
|
input_abs_get_max(input,
|
2015-07-07 05:57:54 +08:00
|
|
|
axis) + 1,
|
2015-06-02 01:35:16 +08:00
|
|
|
&maximum) |
|
2015-07-07 06:18:24 +08:00
|
|
|
touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
|
|
|
|
input_abs_get_fuzz(input, axis),
|
2015-06-02 01:35:16 +08:00
|
|
|
&fuzz);
|
|
|
|
if (data_present)
|
2015-07-07 06:18:24 +08:00
|
|
|
touchscreen_set_params(input, axis, maximum - 1, fuzz);
|
2014-05-29 14:51:53 +08:00
|
|
|
|
2015-06-02 01:35:16 +08:00
|
|
|
axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
|
2015-07-07 06:18:24 +08:00
|
|
|
data_present = touchscreen_get_prop_u32(dev,
|
|
|
|
"touchscreen-max-pressure",
|
|
|
|
input_abs_get_max(input, axis),
|
2015-06-02 01:35:16 +08:00
|
|
|
&maximum) |
|
2015-07-07 06:18:24 +08:00
|
|
|
touchscreen_get_prop_u32(dev,
|
|
|
|
"touchscreen-fuzz-pressure",
|
|
|
|
input_abs_get_fuzz(input, axis),
|
2015-06-02 01:35:16 +08:00
|
|
|
&fuzz);
|
|
|
|
if (data_present)
|
2015-07-07 06:18:24 +08:00
|
|
|
touchscreen_set_params(input, axis, maximum, fuzz);
|
2014-05-29 14:51:53 +08:00
|
|
|
}
|
2015-07-07 06:18:24 +08:00
|
|
|
EXPORT_SYMBOL(touchscreen_parse_properties);
|