Commit 5705b8ac authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: tps6507x-ts - convert to polled input device infrastructure

There is no need to roll our own polling scheme when we already have
one implemented by the core.
Tested-by: default avatarManish Badarkhe <badarkhe.manish@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 69e9aa99
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/input-polldev.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/mfd/tps6507x.h> #include <linux/mfd/tps6507x.h>
#include <linux/input/tps6507x-ts.h> #include <linux/input/tps6507x-ts.h>
...@@ -38,14 +39,12 @@ struct ts_event { ...@@ -38,14 +39,12 @@ struct ts_event {
}; };
struct tps6507x_ts { struct tps6507x_ts {
struct input_dev *input_dev;
struct device *dev; struct device *dev;
struct input_polled_dev *poll_dev;
struct tps6507x_dev *mfd;
char phys[32]; char phys[32];
struct delayed_work work;
struct ts_event tc; struct ts_event tc;
struct tps6507x_dev *mfd;
u16 min_pressure; u16 min_pressure;
unsigned long poll_period; /* ms */
bool pendown; bool pendown;
}; };
...@@ -156,13 +155,11 @@ static s32 tps6507x_adc_standby(struct tps6507x_ts *tsc) ...@@ -156,13 +155,11 @@ static s32 tps6507x_adc_standby(struct tps6507x_ts *tsc)
return ret; return ret;
} }
static void tps6507x_ts_handler(struct work_struct *work) static void tps6507x_ts_poll(struct input_polled_dev *poll_dev)
{ {
struct tps6507x_ts *tsc = container_of(work, struct tps6507x_ts *tsc = poll_dev->private;
struct tps6507x_ts, work.work); struct input_dev *input_dev = poll_dev->input;
struct input_dev *input_dev = tsc->input_dev;
bool pendown; bool pendown;
int schd;
s32 ret; s32 ret;
ret = tps6507x_adc_conversion(tsc, TPS6507X_TSCMODE_PRESSURE, ret = tps6507x_adc_conversion(tsc, TPS6507X_TSCMODE_PRESSURE,
...@@ -206,62 +203,65 @@ static void tps6507x_ts_handler(struct work_struct *work) ...@@ -206,62 +203,65 @@ static void tps6507x_ts_handler(struct work_struct *work)
} }
done: done:
/* always poll if not using interrupts */ tps6507x_adc_standby(tsc);
schd = schedule_delayed_work(&tsc->work,
msecs_to_jiffies(tsc->poll_period));
if (!schd)
dev_err(tsc->dev, "re-schedule failed");
ret = tps6507x_adc_standby(tsc);
} }
static int tps6507x_ts_probe(struct platform_device *pdev) static int tps6507x_ts_probe(struct platform_device *pdev)
{ {
int error;
struct tps6507x_ts *tsc;
struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
struct touchscreen_init_data *init_data; const struct tps6507x_board *tps_board;
const struct touchscreen_init_data *init_data;
struct tps6507x_ts *tsc;
struct input_polled_dev *poll_dev;
struct input_dev *input_dev; struct input_dev *input_dev;
struct tps6507x_board *tps_board; int error;
int schd;
/** /*
* tps_board points to pmic related constants * tps_board points to pmic related constants
* coming from the board-evm file. * coming from the board-evm file.
*/ */
tps_board = dev_get_platdata(tps6507x_dev->dev);
tps_board = (struct tps6507x_board *)tps6507x_dev->dev->platform_data;
if (!tps_board) { if (!tps_board) {
dev_err(tps6507x_dev->dev, dev_err(tps6507x_dev->dev,
"Could not find tps6507x platform data\n"); "Could not find tps6507x platform data\n");
return -EIO; return -ENODEV;
} }
/** /*
* init_data points to array of regulator_init structures * init_data points to array of regulator_init structures
* coming from the board-evm file. * coming from the board-evm file.
*/ */
init_data = tps_board->tps6507x_ts_init_data; init_data = tps_board->tps6507x_ts_init_data;
tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL); tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL);
if (!tsc) { if (!tsc) {
dev_err(tps6507x_dev->dev, "failed to allocate driver data\n"); dev_err(tps6507x_dev->dev, "failed to allocate driver data\n");
error = -ENOMEM; return -ENOMEM;
goto err0;
} }
tps6507x_dev->ts = tsc;
tsc->mfd = tps6507x_dev; tsc->mfd = tps6507x_dev;
tsc->dev = tps6507x_dev->dev; tsc->dev = tps6507x_dev->dev;
input_dev = input_allocate_device(); tsc->min_pressure = init_data ?
if (!input_dev) { init_data->min_pressure : TPS_DEFAULT_MIN_PRESSURE;
dev_err(tsc->dev, "Failed to allocate input device.\n");
snprintf(tsc->phys, sizeof(tsc->phys),
"%s/input0", dev_name(tsc->dev));
poll_dev = input_allocate_polled_device();
if (!poll_dev) {
dev_err(tsc->dev, "Failed to allocate polled input device.\n");
error = -ENOMEM; error = -ENOMEM;
goto err1; goto err_free_mem;
} }
tsc->poll_dev = poll_dev;
poll_dev->private = tsc;
poll_dev->poll = tps6507x_ts_poll;
poll_dev->poll_interval = init_data ?
init_data->poll_period : TSC_DEFAULT_POLL_PERIOD;
input_dev = poll_dev->input;
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
...@@ -270,72 +270,42 @@ static int tps6507x_ts_probe(struct platform_device *pdev) ...@@ -270,72 +270,42 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_10BIT, 0, 0); input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_10BIT, 0, 0);
input_dev->name = "TPS6507x Touchscreen"; input_dev->name = "TPS6507x Touchscreen";
input_dev->id.bustype = BUS_I2C;
input_dev->dev.parent = tsc->dev;
snprintf(tsc->phys, sizeof(tsc->phys),
"%s/input0", dev_name(tsc->dev));
input_dev->phys = tsc->phys; input_dev->phys = tsc->phys;
input_dev->dev.parent = tsc->dev;
dev_dbg(tsc->dev, "device: %s\n", input_dev->phys); input_dev->id.bustype = BUS_I2C;
input_set_drvdata(input_dev, tsc);
tsc->input_dev = input_dev;
INIT_DELAYED_WORK(&tsc->work, tps6507x_ts_handler);
if (init_data) { if (init_data) {
tsc->poll_period = init_data->poll_period;
tsc->min_pressure = init_data->min_pressure;
input_dev->id.vendor = init_data->vendor; input_dev->id.vendor = init_data->vendor;
input_dev->id.product = init_data->product; input_dev->id.product = init_data->product;
input_dev->id.version = init_data->version; input_dev->id.version = init_data->version;
} else {
tsc->poll_period = TSC_DEFAULT_POLL_PERIOD;
tsc->min_pressure = TPS_DEFAULT_MIN_PRESSURE;
} }
error = tps6507x_adc_standby(tsc); error = tps6507x_adc_standby(tsc);
if (error) if (error)
goto err2; goto err_free_polled_dev;
error = input_register_device(input_dev); error = input_register_polled_device(poll_dev);
if (error) if (error)
goto err2; goto err_free_polled_dev;
schd = schedule_delayed_work(&tsc->work,
msecs_to_jiffies(tsc->poll_period));
if (!schd) { platform_set_drvdata(pdev, tsc);
dev_err(tsc->dev, "schedule failed");
goto err2;
}
platform_set_drvdata(pdev, tps6507x_dev);
return 0; return 0;
err2: err_free_polled_dev:
cancel_delayed_work_sync(&tsc->work); input_free_polled_device(poll_dev);
input_free_device(input_dev); err_free_mem:
err1:
kfree(tsc); kfree(tsc);
tps6507x_dev->ts = NULL;
err0:
return error; return error;
} }
static int tps6507x_ts_remove(struct platform_device *pdev) static int tps6507x_ts_remove(struct platform_device *pdev)
{ {
struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev); struct tps6507x_ts *tsc = platform_get_drvdata(pdev);
struct tps6507x_ts *tsc = tps6507x_dev->ts; struct input_polled_dev *poll_dev = tsc->poll_dev;
struct input_dev *input_dev = tsc->input_dev;
cancel_delayed_work_sync(&tsc->work);
input_unregister_device(input_dev); input_unregister_polled_device(poll_dev);
input_free_polled_device(poll_dev);
tps6507x_dev->ts = NULL;
kfree(tsc); kfree(tsc);
return 0; return 0;
......
...@@ -163,7 +163,6 @@ struct tps6507x_dev { ...@@ -163,7 +163,6 @@ struct tps6507x_dev {
/* Client devices */ /* Client devices */
struct tps6507x_pmic *pmic; struct tps6507x_pmic *pmic;
struct tps6507x_ts *ts;
}; };
#endif /* __LINUX_MFD_TPS6507X_H */ #endif /* __LINUX_MFD_TPS6507X_H */
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