Skip to content

Commit

Permalink
ar1021_i2c.c: introduce offsets to manually re-calbrate screen
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
  • Loading branch information
RobertCNelson committed Aug 4, 2019
1 parent a6b819c commit d53b831
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions drivers/input/touchscreen/ar1021_i2c.c
Expand Up @@ -24,6 +24,10 @@

#define AR1021_CMD_ENABLE_TOUCH 0x12

#define AR1021_CMD 0x55

#define AR1021_CMD_ENABLE_TOUCH 0x12

struct ar1021_i2c {
struct i2c_client *client;
struct input_dev *input;
Expand All @@ -33,6 +37,24 @@ struct ar1021_i2c {
bool swap_xy;
};

static bool ar1021_get_prop_u32(struct device *dev,
const char *property,
unsigned int default_value,
unsigned int *value)
{
u32 val;
int error;

error = device_property_read_u32(dev, property, &val);
if (error) {
*value = default_value;
return false;
}

*value = val;
return true;
}

static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
{
struct ar1021_i2c *ar1021 = dev_id;
Expand Down Expand Up @@ -111,6 +133,8 @@ static int ar1021_i2c_probe(struct i2c_client *client,
struct ar1021_i2c *ar1021;
struct input_dev *input;
int error;
unsigned int offset_x, offset_y;
bool data_present;

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev, "i2c_check_functionality error\n");
Expand Down Expand Up @@ -138,6 +162,22 @@ static int ar1021_i2c_probe(struct i2c_client *client,
ar1021->invert_y = device_property_read_bool(&client->dev, "touchscreen-inverted-y");
ar1021->swap_xy = device_property_read_bool(&client->dev, "touchscreen-swapped-x-y");

data_present = ar1021_get_prop_u32(&client->dev,
"touchscreen-offset-x",
0,
&offset_x);

if (data_present)
dev_info(&client->dev, "touchscreen-offset-x: %d\n", offset_x);

data_present = ar1021_get_prop_u32(&client->dev,
"touchscreen-offset-y",
0,
&offset_y);

if (data_present)
dev_info(&client->dev, "touchscreen-offset-y: %d\n", offset_y);

__set_bit(INPUT_PROP_DIRECT, input->propbit);
//input_set_capability(input, EV_KEY, BTN_TOUCH);

Expand All @@ -151,8 +191,8 @@ static int ar1021_i2c_probe(struct i2c_client *client,
}
else
{
input_set_abs_params(input, ABS_X, 0, AR1021_MAX_X, 0, 0);
input_set_abs_params(input, ABS_Y, 0, AR1021_MAX_Y, 0, 0);
input_set_abs_params(input, ABS_X, offset_x, AR1021_MAX_X-offset_x, 0, 0);
input_set_abs_params(input, ABS_Y, offset_y, AR1021_MAX_Y-offset_y, 0, 0);
}

input_set_abs_params(input, ABS_PRESSURE, 0, AR1021_MAX_PRESSURE, 0, 0);
Expand Down

0 comments on commit d53b831

Please sign in to comment.