Skip to content

Commit d33c1f3

Browse files
eng33popcornmix
authored andcommitted
input: Add support for no irq to ili210x driver
Signed-off-by: eng33 <eng33@waveshare.com>
1 parent 61e00de commit d33c1f3

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

drivers/input/touchscreen/ili210x.c

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct ili210x {
6767
u8 version_proto[2];
6868
u8 ic_mode[2];
6969
bool stop;
70+
struct timer_list poll_timer;
71+
struct work_struct poll_work;
7072
};
7173

7274
static int ili210x_read_reg(struct i2c_client *client,
@@ -360,6 +362,34 @@ static irqreturn_t ili210x_irq(int irq, void *irq_data)
360362
return IRQ_HANDLED;
361363
}
362364

365+
static void ili210x_poll_work(struct work_struct *work)
366+
{
367+
struct ili210x *priv = container_of(work, struct ili210x, poll_work);
368+
struct i2c_client *client = priv->client;
369+
const struct ili2xxx_chip *chip = priv->chip;
370+
u8 touchdata[ILI210X_DATA_SIZE] = { 0 };
371+
bool touch;
372+
int error;
373+
374+
error = chip->get_touch_data(client, touchdata);
375+
if (error) {
376+
dev_err(&client->dev, "Unable to get touch data: %d\n", error);
377+
return;
378+
}
379+
380+
touch = ili210x_report_events(priv, touchdata);
381+
}
382+
383+
static void ili210x_poll_timer_callback(struct timer_list *t)
384+
{
385+
struct ili210x *priv = from_timer(priv, t, poll_timer);
386+
387+
schedule_work(&priv->poll_work);
388+
389+
if (!priv->stop)
390+
mod_timer(&priv->poll_timer, jiffies + msecs_to_jiffies(ILI2XXX_POLL_PERIOD));
391+
}
392+
363393
static int ili251x_firmware_update_resolution(struct device *dev)
364394
{
365395
struct i2c_client *client = to_i2c_client(dev);
@@ -947,11 +977,6 @@ static int ili210x_i2c_probe(struct i2c_client *client)
947977
return -ENODEV;
948978
}
949979

950-
if (client->irq <= 0) {
951-
dev_err(dev, "No IRQ!\n");
952-
return -EINVAL;
953-
}
954-
955980
reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
956981
if (IS_ERR(reset_gpio))
957982
return PTR_ERR(reset_gpio);
@@ -1003,12 +1028,17 @@ static int ili210x_i2c_probe(struct i2c_client *client)
10031028
return error;
10041029
}
10051030

1006-
error = devm_request_threaded_irq(dev, client->irq, NULL, ili210x_irq,
1007-
IRQF_ONESHOT, client->name, priv);
1008-
if (error) {
1009-
dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
1010-
error);
1011-
return error;
1031+
if (client->irq) {
1032+
error = devm_request_threaded_irq(dev, client->irq, NULL, ili210x_irq,
1033+
IRQF_ONESHOT, client->name, priv);
1034+
if (error) {
1035+
dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n", error);
1036+
return error;
1037+
}
1038+
} else {
1039+
timer_setup(&priv->poll_timer, ili210x_poll_timer_callback, 0);
1040+
mod_timer(&priv->poll_timer, jiffies + msecs_to_jiffies(ILI2XXX_POLL_PERIOD));
1041+
INIT_WORK(&priv->poll_work, ili210x_poll_work);
10121042
}
10131043

10141044
error = devm_add_action_or_reset(dev, ili210x_stop, priv);
@@ -1024,6 +1054,16 @@ static int ili210x_i2c_probe(struct i2c_client *client)
10241054
return 0;
10251055
}
10261056

1057+
static void ili210x_i2c_remove(struct i2c_client *client)
1058+
{
1059+
struct ili210x *tsdata = i2c_get_clientdata(client);
1060+
1061+
if (!client->irq) {
1062+
del_timer(&tsdata->poll_timer);
1063+
cancel_work_sync(&tsdata->poll_work);
1064+
}
1065+
}
1066+
10271067
static const struct i2c_device_id ili210x_i2c_id[] = {
10281068
{ "ili210x", (long)&ili210x_chip },
10291069
{ "ili2117", (long)&ili211x_chip },
@@ -1050,6 +1090,7 @@ static struct i2c_driver ili210x_ts_driver = {
10501090
},
10511091
.id_table = ili210x_i2c_id,
10521092
.probe = ili210x_i2c_probe,
1093+
.remove = ili210x_i2c_remove,
10531094
};
10541095

10551096
module_i2c_driver(ili210x_ts_driver);

0 commit comments

Comments
 (0)