Skip to content

Commit 78713df

Browse files
committed
Input: kxtj9 - switch to using polled mode of input devices
We have added polled mode to the normal input devices with the intent of retiring input_polled_dev. This converts kxtj9 driver to use the polling mode of standard input devices and removes dependency on INPUT_POLLDEV. note that with regular input devices handling polling, there is no longer a benefit in having separate INPUT_KXTJ9_POLLED_MODE config option. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent e733911 commit 78713df

File tree

2 files changed

+37
-122
lines changed

2 files changed

+37
-122
lines changed

drivers/input/misc/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,6 @@ config INPUT_KXTJ9
404404
To compile this driver as a module, choose M here: the module will
405405
be called kxtj9.
406406

407-
config INPUT_KXTJ9_POLLED_MODE
408-
bool "Enable polling mode support"
409-
depends on INPUT_KXTJ9
410-
select INPUT_POLLDEV
411-
help
412-
Say Y here if you need accelerometer to work in polling mode.
413-
414407
config INPUT_POWERMATE
415408
tristate "Griffin PowerMate and Contour Jog support"
416409
depends on USB_ARCH_HAS_HCD

drivers/input/misc/kxtj9.c

Lines changed: 37 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/module.h>
1212
#include <linux/slab.h>
1313
#include <linux/input/kxtj9.h>
14-
#include <linux/input-polldev.h>
1514

1615
#define NAME "kxtj9"
1716
#define G_MAX 8000
@@ -71,9 +70,6 @@ struct kxtj9_data {
7170
struct i2c_client *client;
7271
struct kxtj9_platform_data pdata;
7372
struct input_dev *input_dev;
74-
#ifdef CONFIG_INPUT_KXTJ9_POLLED_MODE
75-
struct input_polled_dev *poll_dev;
76-
#endif
7773
unsigned int last_poll_interval;
7874
u8 shift;
7975
u8 ctrl_reg1;
@@ -282,48 +278,6 @@ static void kxtj9_input_close(struct input_dev *dev)
282278
kxtj9_disable(tj9);
283279
}
284280

285-
static void kxtj9_init_input_device(struct kxtj9_data *tj9,
286-
struct input_dev *input_dev)
287-
{
288-
__set_bit(EV_ABS, input_dev->evbit);
289-
input_set_abs_params(input_dev, ABS_X, -G_MAX, G_MAX, FUZZ, FLAT);
290-
input_set_abs_params(input_dev, ABS_Y, -G_MAX, G_MAX, FUZZ, FLAT);
291-
input_set_abs_params(input_dev, ABS_Z, -G_MAX, G_MAX, FUZZ, FLAT);
292-
293-
input_dev->name = "kxtj9_accel";
294-
input_dev->id.bustype = BUS_I2C;
295-
}
296-
297-
static int kxtj9_setup_input_device(struct kxtj9_data *tj9)
298-
{
299-
struct input_dev *input_dev;
300-
int err;
301-
302-
input_dev = devm_input_allocate_device(&tj9->client->dev);
303-
if (!input_dev) {
304-
dev_err(&tj9->client->dev, "input device allocate failed\n");
305-
return -ENOMEM;
306-
}
307-
308-
tj9->input_dev = input_dev;
309-
310-
input_dev->open = kxtj9_input_open;
311-
input_dev->close = kxtj9_input_close;
312-
input_set_drvdata(input_dev, tj9);
313-
314-
kxtj9_init_input_device(tj9, input_dev);
315-
316-
err = input_register_device(tj9->input_dev);
317-
if (err) {
318-
dev_err(&tj9->client->dev,
319-
"unable to register input polled device %s: %d\n",
320-
tj9->input_dev->name, err);
321-
return err;
322-
}
323-
324-
return 0;
325-
}
326-
327281
/*
328282
* When IRQ mode is selected, we need to provide an interface to allow the user
329283
* to change the output data rate of the part. For consistency, we are using
@@ -389,12 +343,10 @@ static struct attribute_group kxtj9_attribute_group = {
389343
.attrs = kxtj9_attributes
390344
};
391345

392-
393-
#ifdef CONFIG_INPUT_KXTJ9_POLLED_MODE
394-
static void kxtj9_poll(struct input_polled_dev *dev)
346+
static void kxtj9_poll(struct input_dev *input)
395347
{
396-
struct kxtj9_data *tj9 = dev->private;
397-
unsigned int poll_interval = dev->poll_interval;
348+
struct kxtj9_data *tj9 = input_get_drvdata(input);
349+
unsigned int poll_interval = input_get_poll_interval(input);
398350

399351
kxtj9_report_acceleration_data(tj9);
400352

@@ -404,61 +356,6 @@ static void kxtj9_poll(struct input_polled_dev *dev)
404356
}
405357
}
406358

407-
static void kxtj9_polled_input_open(struct input_polled_dev *dev)
408-
{
409-
struct kxtj9_data *tj9 = dev->private;
410-
411-
kxtj9_enable(tj9);
412-
}
413-
414-
static void kxtj9_polled_input_close(struct input_polled_dev *dev)
415-
{
416-
struct kxtj9_data *tj9 = dev->private;
417-
418-
kxtj9_disable(tj9);
419-
}
420-
421-
static int kxtj9_setup_polled_device(struct kxtj9_data *tj9)
422-
{
423-
int err;
424-
struct input_polled_dev *poll_dev;
425-
426-
poll_dev = devm_input_allocate_polled_device(&tj9->client->dev);
427-
if (!poll_dev) {
428-
dev_err(&tj9->client->dev,
429-
"Failed to allocate polled device\n");
430-
return -ENOMEM;
431-
}
432-
433-
tj9->poll_dev = poll_dev;
434-
tj9->input_dev = poll_dev->input;
435-
436-
poll_dev->private = tj9;
437-
poll_dev->poll = kxtj9_poll;
438-
poll_dev->open = kxtj9_polled_input_open;
439-
poll_dev->close = kxtj9_polled_input_close;
440-
441-
kxtj9_init_input_device(tj9, poll_dev->input);
442-
443-
err = input_register_polled_device(poll_dev);
444-
if (err) {
445-
dev_err(&tj9->client->dev,
446-
"Unable to register polled device, err=%d\n", err);
447-
return err;
448-
}
449-
450-
return 0;
451-
}
452-
453-
#else
454-
455-
static inline int kxtj9_setup_polled_device(struct kxtj9_data *tj9)
456-
{
457-
return -ENOSYS;
458-
}
459-
460-
#endif
461-
462359
static void kxtj9_platform_exit(void *data)
463360
{
464361
struct kxtj9_data *tj9 = data;
@@ -494,6 +391,7 @@ static int kxtj9_probe(struct i2c_client *client,
494391
const struct kxtj9_platform_data *pdata =
495392
dev_get_platdata(&client->dev);
496393
struct kxtj9_data *tj9;
394+
struct input_dev *input_dev;
497395
int err;
498396

499397
if (!i2c_check_functionality(client->adapter,
@@ -538,15 +436,44 @@ static int kxtj9_probe(struct i2c_client *client,
538436
tj9->ctrl_reg1 = tj9->pdata.res_12bit | tj9->pdata.g_range;
539437
tj9->last_poll_interval = tj9->pdata.init_interval;
540438

439+
input_dev = devm_input_allocate_device(&client->dev);
440+
if (!input_dev) {
441+
dev_err(&client->dev, "input device allocate failed\n");
442+
return -ENOMEM;
443+
}
444+
445+
input_set_drvdata(input_dev, tj9);
446+
tj9->input_dev = input_dev;
447+
448+
input_dev->name = "kxtj9_accel";
449+
input_dev->id.bustype = BUS_I2C;
450+
451+
input_dev->open = kxtj9_input_open;
452+
input_dev->close = kxtj9_input_close;
453+
454+
input_set_abs_params(input_dev, ABS_X, -G_MAX, G_MAX, FUZZ, FLAT);
455+
input_set_abs_params(input_dev, ABS_Y, -G_MAX, G_MAX, FUZZ, FLAT);
456+
input_set_abs_params(input_dev, ABS_Z, -G_MAX, G_MAX, FUZZ, FLAT);
457+
458+
if (client->irq <= 0) {
459+
err = input_setup_polling(input_dev, kxtj9_poll);
460+
if (err)
461+
return err;
462+
}
463+
464+
err = input_register_device(input_dev);
465+
if (err) {
466+
dev_err(&client->dev,
467+
"unable to register input polled device %s: %d\n",
468+
input_dev->name, err);
469+
return err;
470+
}
471+
541472
if (client->irq) {
542473
/* If in irq mode, populate INT_CTRL_REG1 and enable DRDY. */
543474
tj9->int_ctrl |= KXTJ9_IEN | KXTJ9_IEA | KXTJ9_IEL;
544475
tj9->ctrl_reg1 |= DRDYE;
545476

546-
err = kxtj9_setup_input_device(tj9);
547-
if (err)
548-
return err;
549-
550477
err = devm_request_threaded_irq(&client->dev, client->irq,
551478
NULL, kxtj9_isr,
552479
IRQF_TRIGGER_RISING |
@@ -563,11 +490,6 @@ static int kxtj9_probe(struct i2c_client *client,
563490
dev_err(&client->dev, "sysfs create failed: %d\n", err);
564491
return err;
565492
}
566-
567-
} else {
568-
err = kxtj9_setup_polled_device(tj9);
569-
if (err)
570-
return err;
571493
}
572494

573495
return 0;

0 commit comments

Comments
 (0)