Skip to content

Commit 235300e

Browse files
Marek Vasutdtor
authored andcommitted
Input: ili210x - use resolution from ili251x firmware
The ili251x firmware protocol permits readout of panel resolution, implement this, but make it possible to override this value using DT bindings. This way, older DTs which contain touchscreen-size-x and touchscreen-size-y properties will behave just like before and new DTs may avoid specifying these for ILI251x. Note that the command format is different on other controllers, so this functionality is isolated to ILI251x. Signed-off-by: Marek Vasut <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 9e5afc8 commit 235300e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

drivers/input/touchscreen/ili210x.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct ili2xxx_chip {
3535
unsigned int max_touches;
3636
unsigned int resolution;
3737
bool has_calibrate_reg;
38+
bool has_firmware_proto;
3839
bool has_pressure_reg;
3940
};
4041

@@ -268,6 +269,7 @@ static const struct ili2xxx_chip ili251x_chip = {
268269
.continue_polling = ili251x_check_continue_polling,
269270
.max_touches = 10,
270271
.has_calibrate_reg = true,
272+
.has_firmware_proto = true,
271273
.has_pressure_reg = true,
272274
};
273275

@@ -323,6 +325,54 @@ static irqreturn_t ili210x_irq(int irq, void *irq_data)
323325
return IRQ_HANDLED;
324326
}
325327

328+
static int ili251x_firmware_update_resolution(struct device *dev)
329+
{
330+
struct i2c_client *client = to_i2c_client(dev);
331+
struct ili210x *priv = i2c_get_clientdata(client);
332+
u16 resx, resy;
333+
u8 rs[10];
334+
int error;
335+
336+
/* The firmware update blob might have changed the resolution. */
337+
error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs));
338+
if (error)
339+
return error;
340+
341+
resx = le16_to_cpup((__le16 *)rs);
342+
resy = le16_to_cpup((__le16 *)(rs + 2));
343+
344+
/* The value reported by the firmware is invalid. */
345+
if (!resx || resx == 0xffff || !resy || resy == 0xffff)
346+
return -EINVAL;
347+
348+
input_abs_set_max(priv->input, ABS_X, resx - 1);
349+
input_abs_set_max(priv->input, ABS_Y, resy - 1);
350+
input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1);
351+
input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1);
352+
353+
return 0;
354+
}
355+
356+
static int ili251x_firmware_update_cached_state(struct device *dev)
357+
{
358+
struct i2c_client *client = to_i2c_client(dev);
359+
struct ili210x *priv = i2c_get_clientdata(client);
360+
int error;
361+
362+
if (!priv->chip->has_firmware_proto)
363+
return 0;
364+
365+
/* Wait for firmware to boot and stabilize itself. */
366+
msleep(200);
367+
368+
/* Firmware does report valid information. */
369+
error = ili251x_firmware_update_resolution(dev);
370+
if (error)
371+
return error;
372+
373+
return 0;
374+
}
375+
326376
static ssize_t ili210x_calibrate(struct device *dev,
327377
struct device_attribute *attr,
328378
const char *buf, size_t count)
@@ -449,6 +499,12 @@ static int ili210x_i2c_probe(struct i2c_client *client,
449499
input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0);
450500
if (priv->chip->has_pressure_reg)
451501
input_set_abs_params(input, ABS_MT_PRESSURE, 0, 0xa, 0, 0);
502+
error = ili251x_firmware_update_cached_state(dev);
503+
if (error) {
504+
dev_err(dev, "Unable to cache firmware information, err: %d\n",
505+
error);
506+
return error;
507+
}
452508
touchscreen_parse_properties(input, true, &priv->prop);
453509

454510
error = input_mt_init_slots(input, priv->chip->max_touches,

0 commit comments

Comments
 (0)