1 #include <linux/module.h>
4 #include <linux/slab.h>
5 #include <linux/input.h>
12 #define DEFAULT_POLL_PERIOD 20
15 #define REG_TOUCHDATA 0x10
16 #define REG_PANEL_INFO 0x20
17 #define REG_FIRMWARE_VERSION 0x40
18 #define REG_CALIBRATE 0xcc
71 dev_err(&client->
dev,
"i2c transfer failed\n");
78 static void ili210x_report_events(
struct input_dev *
input,
91 touch = touchdata->
status & (1 <<
i);
106 static bool get_pendown_state(
const struct ili210x *
priv)
121 struct touchdata touchdata;
125 &touchdata,
sizeof(touchdata));
128 "Unable to get touchdata, err = %d\n", error);
132 ili210x_report_events(priv->
input, &touchdata);
134 if ((touchdata.
status & 0xf3) || get_pendown_state(priv))
141 struct ili210x *priv = irq_data;
150 const char *buf,
size_t count)
153 struct ili210x *priv = i2c_get_clientdata(client);
158 if (kstrtoul(buf, 10, &calibrate))
166 if (rc !=
sizeof(cmd))
174 static struct attribute *ili210x_attributes[] = {
175 &dev_attr_calibrate.attr,
180 .attrs = ili210x_attributes,
189 struct input_dev *
input;
195 dev_dbg(dev,
"Probing for ILI210X I2C Touschreen driver");
198 dev_err(dev,
"No platform data!\n");
202 if (client->
irq <= 0) {
211 dev_err(dev,
"Failed to get firmware version, err: %d\n",
217 error = ili210x_read_reg(client,
REG_PANEL_INFO, &panel,
sizeof(panel));
219 dev_err(dev,
"Failed to get panel informations, err: %d\n",
224 xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8);
225 ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
228 input = input_allocate_device();
229 if (!priv || !input) {
241 input->name =
"ILI210x Touchscreen";
243 input->dev.parent =
dev;
251 input_set_abs_params(input,
ABS_X, 0, xmax, 0, 0);
252 input_set_abs_params(input,
ABS_Y, 0, ymax, 0, 0);
259 input_set_drvdata(input, priv);
260 i2c_set_clientdata(client, priv);
265 dev_err(dev,
"Unable to request touchscreen IRQ, err: %d\n",
272 dev_err(dev,
"Unable to create sysfs attributes, err: %d\n",
277 error = input_register_device(priv->
input);
279 dev_err(dev,
"Cannot regiser input device, err: %d\n", error);
280 goto err_remove_sysfs;
286 "ILI210x initialized (IRQ: %d), firmware version %d.%d.%d",
296 input_free_device(input);
303 struct ili210x *priv = i2c_get_clientdata(client);
308 input_unregister_device(priv->
input);
314 #ifdef CONFIG_PM_SLEEP
315 static int ili210x_i2c_suspend(
struct device *dev)
319 if (device_may_wakeup(&client->
dev))
320 enable_irq_wake(client->
irq);
325 static int ili210x_i2c_resume(
struct device *dev)
329 if (device_may_wakeup(&client->
dev))
330 disable_irq_wake(client->
irq);
337 ili210x_i2c_suspend, ili210x_i2c_resume);
345 static struct i2c_driver ili210x_ts_driver = {
347 .name =
"ili210x_i2c",
349 .pm = &ili210x_i2c_pm,
351 .id_table = ili210x_i2c_id,
352 .probe = ili210x_i2c_probe,