Commit b1d2a3ec authored by Franklin S Cooper Jr's avatar Franklin S Cooper Jr Committed by Dmitry Torokhov

Input: edt-ft5x06 - add support for different max support points

Update the code so that the maximum supported points aren't hard coded but
can be changed.

Set the maximum support points based on the data passed along side the
compatible field.
Signed-off-by: default avatarFranklin S Cooper Jr <fcooper@ti.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c789f1fb
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/input/mt.h> #include <linux/input/mt.h>
#include <linux/input/touchscreen.h> #include <linux/input/touchscreen.h>
#include <linux/of_device.h>
#define MAX_SUPPORT_POINTS 5
#define WORK_REGISTER_THRESHOLD 0x00 #define WORK_REGISTER_THRESHOLD 0x00
#define WORK_REGISTER_REPORT_RATE 0x08 #define WORK_REGISTER_REPORT_RATE 0x08
...@@ -105,6 +104,7 @@ struct edt_ft5x06_ts_data { ...@@ -105,6 +104,7 @@ struct edt_ft5x06_ts_data {
int gain; int gain;
int offset; int offset;
int report_rate; int report_rate;
int max_support_points;
char name[EDT_NAME_LEN]; char name[EDT_NAME_LEN];
...@@ -112,6 +112,10 @@ struct edt_ft5x06_ts_data { ...@@ -112,6 +112,10 @@ struct edt_ft5x06_ts_data {
enum edt_ver version; enum edt_ver version;
}; };
struct edt_i2c_chip_data {
int max_support_points;
};
static int edt_ft5x06_ts_readwrite(struct i2c_client *client, static int edt_ft5x06_ts_readwrite(struct i2c_client *client,
u16 wr_len, u8 *wr_buf, u16 wr_len, u8 *wr_buf,
u16 rd_len, u8 *rd_buf) u16 rd_len, u8 *rd_buf)
...@@ -193,7 +197,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id) ...@@ -193,7 +197,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
} }
memset(rdbuf, 0, sizeof(rdbuf)); memset(rdbuf, 0, sizeof(rdbuf));
datalen = tplen * MAX_SUPPORT_POINTS + offset + crclen; datalen = tplen * tsdata->max_support_points + offset + crclen;
error = edt_ft5x06_ts_readwrite(tsdata->client, error = edt_ft5x06_ts_readwrite(tsdata->client,
sizeof(cmd), &cmd, sizeof(cmd), &cmd,
...@@ -218,7 +222,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id) ...@@ -218,7 +222,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
goto out; goto out;
} }
for (i = 0; i < MAX_SUPPORT_POINTS; i++) { for (i = 0; i < tsdata->max_support_points; i++) {
u8 *buf = &rdbuf[i * tplen + offset]; u8 *buf = &rdbuf[i * tplen + offset];
bool down; bool down;
...@@ -874,6 +878,7 @@ edt_ft5x06_ts_set_regs(struct edt_ft5x06_ts_data *tsdata) ...@@ -874,6 +878,7 @@ edt_ft5x06_ts_set_regs(struct edt_ft5x06_ts_data *tsdata)
static int edt_ft5x06_ts_probe(struct i2c_client *client, static int edt_ft5x06_ts_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
const struct edt_i2c_chip_data *chip_data;
struct edt_ft5x06_ts_data *tsdata; struct edt_ft5x06_ts_data *tsdata;
struct input_dev *input; struct input_dev *input;
unsigned long irq_flags; unsigned long irq_flags;
...@@ -888,6 +893,16 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, ...@@ -888,6 +893,16 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
} }
chip_data = of_device_get_match_data(&client->dev);
if (!chip_data)
chip_data = (const struct edt_i2c_chip_data *)id->driver_data;
if (!chip_data || !chip_data->max_support_points) {
dev_err(&client->dev, "invalid or missing chip data\n");
return -EINVAL;
}
tsdata->max_support_points = chip_data->max_support_points;
tsdata->reset_gpio = devm_gpiod_get_optional(&client->dev, tsdata->reset_gpio = devm_gpiod_get_optional(&client->dev,
"reset", GPIOD_OUT_HIGH); "reset", GPIOD_OUT_HIGH);
if (IS_ERR(tsdata->reset_gpio)) { if (IS_ERR(tsdata->reset_gpio)) {
...@@ -953,7 +968,8 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, ...@@ -953,7 +968,8 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
touchscreen_parse_properties(input, true); touchscreen_parse_properties(input, true);
error = input_mt_init_slots(input, MAX_SUPPORT_POINTS, INPUT_MT_DIRECT); error = input_mt_init_slots(input, tsdata->max_support_points,
INPUT_MT_DIRECT);
if (error) { if (error) {
dev_err(&client->dev, "Unable to init MT slots.\n"); dev_err(&client->dev, "Unable to init MT slots.\n");
return error; return error;
...@@ -1032,17 +1048,21 @@ static int __maybe_unused edt_ft5x06_ts_resume(struct device *dev) ...@@ -1032,17 +1048,21 @@ static int __maybe_unused edt_ft5x06_ts_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(edt_ft5x06_ts_pm_ops, static SIMPLE_DEV_PM_OPS(edt_ft5x06_ts_pm_ops,
edt_ft5x06_ts_suspend, edt_ft5x06_ts_resume); edt_ft5x06_ts_suspend, edt_ft5x06_ts_resume);
static const struct edt_i2c_chip_data edt_ft5x06_data = {
.max_support_points = 5,
};
static const struct i2c_device_id edt_ft5x06_ts_id[] = { static const struct i2c_device_id edt_ft5x06_ts_id[] = {
{ "edt-ft5x06", 0, }, { .name = "edt-ft5x06", .driver_data = (long)&edt_ft5x06_data },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(i2c, edt_ft5x06_ts_id); MODULE_DEVICE_TABLE(i2c, edt_ft5x06_ts_id);
#ifdef CONFIG_OF #ifdef CONFIG_OF
static const struct of_device_id edt_ft5x06_of_match[] = { static const struct of_device_id edt_ft5x06_of_match[] = {
{ .compatible = "edt,edt-ft5206", }, { .compatible = "edt,edt-ft5206", .data = &edt_ft5x06_data },
{ .compatible = "edt,edt-ft5306", }, { .compatible = "edt,edt-ft5306", .data = &edt_ft5x06_data },
{ .compatible = "edt,edt-ft5406", }, { .compatible = "edt,edt-ft5406", .data = &edt_ft5x06_data },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, edt_ft5x06_of_match); MODULE_DEVICE_TABLE(of, edt_ft5x06_of_match);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment