FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Input: tps6507x-ts - convert to polled input device infrastructure · fabgithub/linux@5705b8a · GitHub

Repository navigation

Commit 5705b8a

Browse files
committed
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: Manish Badarkhe <badarkhe.manish@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 69e9aa9 commit 5705b8a

2 files changed

Lines changed: 48 additions & 79 deletions

File tree

‎drivers/input/touchscreen/tps6507x-ts.c‎

Lines changed: 48 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/workqueue.h>
1818
#include <linux/slab.h>
1919
#include <linux/input.h>
20+
#include <linux/input-polldev.h>
2021
#include <linux/platform_device.h>
2122
#include <linux/mfd/tps6507x.h>
2223
#include <linux/input/tps6507x-ts.h>
@@ -38,14 +39,12 @@ struct ts_event {
3839
};
3940

4041
struct tps6507x_ts {
41-
struct input_dev *input_dev;
4242
struct device *dev;
43+
struct input_polled_dev *poll_dev;
44+
struct tps6507x_dev *mfd;
4345
char phys[32];
44-
struct delayed_work work;
4546
struct ts_event tc;
46-
struct tps6507x_dev *mfd;
4747
u16 min_pressure;
48-
unsigned long poll_period; /* ms */
4948
bool pendown;
5049
};
5150

@@ -156,13 +155,11 @@ static s32 tps6507x_adc_standby(struct tps6507x_ts *tsc)
156155
return ret;
157156
}
158157

159-
static void tps6507x_ts_handler(struct work_struct *work)
158+
static void tps6507x_ts_poll(struct input_polled_dev *poll_dev)
160159
{
161-
struct tps6507x_ts *tsc = container_of(work,
162-
struct tps6507x_ts, work.work);
163-
struct input_dev *input_dev = tsc->input_dev;
160+
struct tps6507x_ts *tsc = poll_dev->private;
161+
struct input_dev *input_dev = poll_dev->input;
164162
bool pendown;
165-
int schd;
166163
s32 ret;
167164

168165
ret = tps6507x_adc_conversion(tsc, TPS6507X_TSCMODE_PRESSURE,
@@ -206,62 +203,65 @@ static void tps6507x_ts_handler(struct work_struct *work)
206203
}
207204

208205
done:
209-
/* always poll if not using interrupts */
210-
schd = schedule_delayed_work(&tsc->work,
211-
msecs_to_jiffies(tsc->poll_period));
212-
if (!schd)
213-
dev_err(tsc->dev, "re-schedule failed");
214-
215-
ret = tps6507x_adc_standby(tsc);
206+
tps6507x_adc_standby(tsc);
216207
}
217208

218209
static int tps6507x_ts_probe(struct platform_device *pdev)
219210
{
220-
int error;
221-
struct tps6507x_ts *tsc;
222211
struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
223-
struct touchscreen_init_data *init_data;
212+
const struct tps6507x_board *tps_board;
213+
const struct touchscreen_init_data *init_data;
214+
struct tps6507x_ts *tsc;
215+
struct input_polled_dev *poll_dev;
224216
struct input_dev *input_dev;
225-
struct tps6507x_board *tps_board;
226-
int schd;
217+
int error;
227218

228-
/**
219+
/*
229220
* tps_board points to pmic related constants
230221
* coming from the board-evm file.
231222
*/
232-
233-
tps_board = (struct tps6507x_board *)tps6507x_dev->dev->platform_data;
234-
223+
tps_board = dev_get_platdata(tps6507x_dev->dev);
235224
if (!tps_board) {
236225
dev_err(tps6507x_dev->dev,
237226
"Could not find tps6507x platform data\n");
238-
return -EIO;
227+
return -ENODEV;
239228
}
240229

241-
/**
230+
/*
242231
* init_data points to array of regulator_init structures
243232
* coming from the board-evm file.
244233
*/
245-
246234
init_data = tps_board->tps6507x_ts_init_data;
247235

248236
tsc = kzalloc(sizeof(struct tps6507x_ts), GFP_KERNEL);
249237
if (!tsc) {
250238
dev_err(tps6507x_dev->dev, "failed to allocate driver data\n");
251-
error = -ENOMEM;
252-
goto err0;
239+
return -ENOMEM;
253240
}
254241

255-
tps6507x_dev->ts = tsc;
256242
tsc->mfd = tps6507x_dev;
257243
tsc->dev = tps6507x_dev->dev;
258-
input_dev = input_allocate_device();
259-
if (!input_dev) {
260-
dev_err(tsc->dev, "Failed to allocate input device.\n");
244+
tsc->min_pressure = init_data ?
245+
init_data->min_pressure : TPS_DEFAULT_MIN_PRESSURE;
246+
247+
snprintf(tsc->phys, sizeof(tsc->phys),
248+
"%s/input0", dev_name(tsc->dev));
249+
250+
poll_dev = input_allocate_polled_device();
251+
if (!poll_dev) {
252+
dev_err(tsc->dev, "Failed to allocate polled input device.\n");
261253
error = -ENOMEM;
262-
goto err1;
254+
goto err_free_mem;
263255
}
264256

257+
tsc->poll_dev = poll_dev;
258+
259+
poll_dev->private = tsc;
260+
poll_dev->poll = tps6507x_ts_poll;
261+
poll_dev->poll_interval = init_data ?
262+
init_data->poll_period : TSC_DEFAULT_POLL_PERIOD;
263+
264+
input_dev = poll_dev->input;
265265
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
266266
input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
267267

@@ -270,72 +270,42 @@ static int tps6507x_ts_probe(struct platform_device *pdev)
270270
input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_10BIT, 0, 0);
271271

272272
input_dev->name = "TPS6507x Touchscreen";
273-
input_dev->id.bustype = BUS_I2C;
274-
input_dev->dev.parent = tsc->dev;
275-
276-
snprintf(tsc->phys, sizeof(tsc->phys),
277-
"%s/input0", dev_name(tsc->dev));
278273
input_dev->phys = tsc->phys;
279-
280-
dev_dbg(tsc->dev, "device: %s\n", input_dev->phys);
281-
282-
input_set_drvdata(input_dev, tsc);
283-
284-
tsc->input_dev = input_dev;
285-
286-
INIT_DELAYED_WORK(&tsc->work, tps6507x_ts_handler);
287-
274+
input_dev->dev.parent = tsc->dev;
275+
input_dev->id.bustype = BUS_I2C;
288276
if (init_data) {
289-
tsc->poll_period = init_data->poll_period;
290-
tsc->min_pressure = init_data->min_pressure;
291277
input_dev->id.vendor = init_data->vendor;
292278
input_dev->id.product = init_data->product;
293279
input_dev->id.version = init_data->version;
294-
} else {
295-
tsc->poll_period = TSC_DEFAULT_POLL_PERIOD;
296-
tsc->min_pressure = TPS_DEFAULT_MIN_PRESSURE;
297280
}
298281

299282
error = tps6507x_adc_standby(tsc);
300283
if (error)
301-
goto err2;
284+
goto err_free_polled_dev;
302285

303-
error = input_register_device(input_dev);
286+
error = input_register_polled_device(poll_dev);
304287
if (error)
305-
goto err2;
306-
307-
schd = schedule_delayed_work(&tsc->work,
308-
msecs_to_jiffies(tsc->poll_period));
288+
goto err_free_polled_dev;
309289

310-
if (!schd) {
311-
dev_err(tsc->dev, "schedule failed");
312-
goto err2;
313-
}
314-
platform_set_drvdata(pdev, tps6507x_dev);
290+
platform_set_drvdata(pdev, tsc);
315291

316292
return 0;
317293

318-
err2:
319-
cancel_delayed_work_sync(&tsc->work);
320-
input_free_device(input_dev);
321-
err1:
294+
err_free_polled_dev:
295+
input_free_polled_device(poll_dev);
296+
err_free_mem:
322297
kfree(tsc);
323-
tps6507x_dev->ts = NULL;
324-
err0:
325298
return error;
326299
}
327300

328301
static int tps6507x_ts_remove(struct platform_device *pdev)
329302
{
330-
struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
331-
struct tps6507x_ts *tsc = tps6507x_dev->ts;
332-
struct input_dev *input_dev = tsc->input_dev;
333-
334-
cancel_delayed_work_sync(&tsc->work);
303+
struct tps6507x_ts *tsc = platform_get_drvdata(pdev);
304+
struct input_polled_dev *poll_dev = tsc->poll_dev;
335305

336-
input_unregister_device(input_dev);
306+
input_unregister_polled_device(poll_dev);
307+
input_free_polled_device(poll_dev);
337308

338-
tps6507x_dev->ts = NULL;
339309
kfree(tsc);
340310

341311
return 0;

‎include/linux/mfd/tps6507x.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ struct tps6507x_dev {
163163

164164
/* Client devices */
165165
struct tps6507x_pmic *pmic;
166-
struct tps6507x_ts *ts;
167166
};
168167

169168
#endif /* __LINUX_MFD_TPS6507X_H */

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL