From 219edc71784ff8a3537ffbe64baded61ce4048b9 Mon Sep 17 00:00:00 2001 From: Alexandre Pereira da Silva Date: Sun, 29 Jul 2012 22:18:47 -0700 Subject: Input: gpio_keys - clean up device tree parser - fix sizeof in memset; - clean up dt properties extraction; - use for_each_chil_of_node macro; - use of_get_child_count(); - use of_match_ptr macro. Signed-off-by: Alexandre Pereira da Silva Acked-by: Rob Herring [Fabio Estevam : fix fix NULL pointer dereference for dt case - pdata->buttons wasn't initialized] Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys.c | 161 ++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 81 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index cbb1add43d5..b890231debd 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -43,11 +43,9 @@ struct gpio_button_data { }; struct gpio_keys_drvdata { + const struct gpio_keys_platform_data *pdata; struct input_dev *input; struct mutex disable_lock; - unsigned int n_buttons; - int (*enable)(struct device *dev); - void (*disable)(struct device *dev); struct gpio_button_data data[0]; }; @@ -171,7 +169,7 @@ static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata, if (!bits) return -ENOMEM; - for (i = 0; i < ddata->n_buttons; i++) { + for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; if (bdata->button->type != type) @@ -219,7 +217,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, goto out; /* First validate */ - for (i = 0; i < ddata->n_buttons; i++) { + for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; if (bdata->button->type != type) @@ -234,7 +232,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, mutex_lock(&ddata->disable_lock); - for (i = 0; i < ddata->n_buttons; i++) { + for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; if (bdata->button->type != type) @@ -523,56 +521,64 @@ fail: static int gpio_keys_open(struct input_dev *input) { struct gpio_keys_drvdata *ddata = input_get_drvdata(input); + const struct gpio_keys_platform_data *pdata = ddata->pdata; - return ddata->enable ? ddata->enable(input->dev.parent) : 0; + return pdata->enable ? pdata->enable(input->dev.parent) : 0; } static void gpio_keys_close(struct input_dev *input) { struct gpio_keys_drvdata *ddata = input_get_drvdata(input); + const struct gpio_keys_platform_data *pdata = ddata->pdata; - if (ddata->disable) - ddata->disable(input->dev.parent); + if (pdata->disable) + pdata->disable(input->dev.parent); } /* * Handlers for alternative sources of platform_data */ + #ifdef CONFIG_OF /* * Translate OpenFirmware node properties into platform_data */ -static int gpio_keys_get_devtree_pdata(struct device *dev, - struct gpio_keys_platform_data *pdata) +static struct gpio_keys_platform_data * __devinit +gpio_keys_get_devtree_pdata(struct device *dev) { struct device_node *node, *pp; + struct gpio_keys_platform_data *pdata; + struct gpio_keys_button *button; + int error; + int nbuttons; int i; - struct gpio_keys_button *buttons; - u32 reg; node = dev->of_node; - if (node == NULL) - return -ENODEV; - - memset(pdata, 0, sizeof *pdata); + if (!node) { + error = -ENODEV; + goto err_out; + } - pdata->rep = !!of_get_property(node, "autorepeat", NULL); + nbuttons = of_get_child_count(node); + if (nbuttons == 0) { + error = -ENODEV; + goto err_out; + } - /* First count the subnodes */ - pp = NULL; - while ((pp = of_get_next_child(node, pp))) - pdata->nbuttons++; + pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), + GFP_KERNEL); + if (!pdata) { + error = -ENOMEM; + goto err_out; + } - if (pdata->nbuttons == 0) - return -ENODEV; + pdata->buttons = (struct gpio_keys_button *)(pdata + 1); + pdata->nbuttons = nbuttons; - buttons = kzalloc(pdata->nbuttons * (sizeof *buttons), GFP_KERNEL); - if (!buttons) - return -ENOMEM; + pdata->rep = !!of_get_property(node, "autorepeat", NULL); - pp = NULL; i = 0; - while ((pp = of_get_next_child(node, pp))) { + for_each_child_of_node(node, pp) { enum of_gpio_flags flags; if (!of_find_property(pp, "gpios", NULL)) { @@ -580,39 +586,42 @@ static int gpio_keys_get_devtree_pdata(struct device *dev, dev_warn(dev, "Found button without gpios\n"); continue; } - buttons[i].gpio = of_get_gpio_flags(pp, 0, &flags); - buttons[i].active_low = flags & OF_GPIO_ACTIVE_LOW; - if (of_property_read_u32(pp, "linux,code", ®)) { - dev_err(dev, "Button without keycode: 0x%x\n", buttons[i].gpio); - goto out_fail; - } - buttons[i].code = reg; + button = &pdata->buttons[i++]; - buttons[i].desc = of_get_property(pp, "label", NULL); + button->gpio = of_get_gpio_flags(pp, 0, &flags); + button->active_low = flags & OF_GPIO_ACTIVE_LOW; - if (of_property_read_u32(pp, "linux,input-type", ®) == 0) - buttons[i].type = reg; - else - buttons[i].type = EV_KEY; + if (of_property_read_u32(pp, "linux,code", &button->code)) { + dev_err(dev, "Button without keycode: 0x%x\n", + button->gpio); + error = -EINVAL; + goto err_free_pdata; + } - buttons[i].wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); + button->desc = of_get_property(pp, "label", NULL); - if (of_property_read_u32(pp, "debounce-interval", ®) == 0) - buttons[i].debounce_interval = reg; - else - buttons[i].debounce_interval = 5; + if (of_property_read_u32(pp, "linux,input-type", &button->type)) + button->type = EV_KEY; + + button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); - i++; + if (of_property_read_u32(pp, "debounce-interval", + &button->debounce_interval)) + button->debounce_interval = 5; } - pdata->buttons = buttons; + if (pdata->nbuttons == 0) { + error = -EINVAL; + goto err_free_pdata; + } - return 0; + return pdata; -out_fail: - kfree(buttons); - return -ENODEV; +err_free_pdata: + kfree(pdata); +err_out: + return ERR_PTR(error); } static struct of_device_id gpio_keys_of_match[] = { @@ -623,14 +632,12 @@ MODULE_DEVICE_TABLE(of, gpio_keys_of_match); #else -static int gpio_keys_get_devtree_pdata(struct device *dev, - struct gpio_keys_platform_data *altp) +static inline struct gpio_keys_platform_data * +gpio_keys_get_devtree_pdata(struct device *dev) { - return -ENODEV; + return ERR_PTR(-ENODEV); } -#define gpio_keys_of_match NULL - #endif static void gpio_remove_key(struct gpio_button_data *bdata) @@ -645,19 +652,17 @@ static void gpio_remove_key(struct gpio_button_data *bdata) static int __devinit gpio_keys_probe(struct platform_device *pdev) { - const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; - struct gpio_keys_drvdata *ddata; struct device *dev = &pdev->dev; - struct gpio_keys_platform_data alt_pdata; + const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); + struct gpio_keys_drvdata *ddata; struct input_dev *input; int i, error; int wakeup = 0; if (!pdata) { - error = gpio_keys_get_devtree_pdata(dev, &alt_pdata); - if (error) - return error; - pdata = &alt_pdata; + pdata = gpio_keys_get_devtree_pdata(dev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); } ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + @@ -670,10 +675,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev) goto fail1; } + ddata->pdata = pdata; ddata->input = input; - ddata->n_buttons = pdata->nbuttons; - ddata->enable = pdata->enable; - ddata->disable = pdata->disable; mutex_init(&ddata->disable_lock); platform_set_drvdata(pdev, ddata); @@ -742,9 +745,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev) fail1: input_free_device(input); kfree(ddata); - /* If we have no platform_data, we allocated buttons dynamically. */ - if (!pdev->dev.platform_data) - kfree(pdata->buttons); + /* If we have no platform data, we allocated pdata dynamically. */ + if (!dev_get_platdata(&pdev->dev)) + kfree(pdata); return error; } @@ -759,18 +762,14 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 0); - for (i = 0; i < ddata->n_buttons; i++) + for (i = 0; i < ddata->pdata->nbuttons; i++) gpio_remove_key(&ddata->data[i]); input_unregister_device(input); - /* - * If we had no platform_data, we allocated buttons dynamically, and - * must free them here. ddata->data[0].button is the pointer to the - * beginning of the allocated array. - */ - if (!pdev->dev.platform_data) - kfree(ddata->data[0].button); + /* If we have no platform data, we allocated pdata dynamically. */ + if (!dev_get_platdata(&pdev->dev)) + kfree(ddata->pdata); kfree(ddata); @@ -784,7 +783,7 @@ static int gpio_keys_suspend(struct device *dev) int i; if (device_may_wakeup(dev)) { - for (i = 0; i < ddata->n_buttons; i++) { + for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; if (bdata->button->wakeup) enable_irq_wake(bdata->irq); @@ -799,7 +798,7 @@ static int gpio_keys_resume(struct device *dev) struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); int i; - for (i = 0; i < ddata->n_buttons; i++) { + for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; if (bdata->button->wakeup && device_may_wakeup(dev)) disable_irq_wake(bdata->irq); @@ -822,7 +821,7 @@ static struct platform_driver gpio_keys_device_driver = { .name = "gpio-keys", .owner = THIS_MODULE, .pm = &gpio_keys_pm_ops, - .of_match_table = gpio_keys_of_match, + .of_match_table = of_match_ptr(gpio_keys_of_match), } }; -- cgit v1.2.3-18-g5258 From 2fba26c6595e4c1c64a74dad30f71c09708ff59a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 29 Jul 2012 22:18:47 -0700 Subject: Input: gpio_keys - report a wakeup_event for a button press In order to avoid races with suspend, a wakeup event must register as such by calling pm_wakeup_event() or pm_stay_awake(). This will ensure that the current suspend cycle aborts. When the user-space visible event is created in the interrupt handler (gpio_keys_irq_isr), a simple pm_wakeup_event() with no delay is sufficient as suspend will synchronise with all interrupt delivery. When the user-space visible event is created later (gpio_keys_gpio_isr), we need to bracket the event with pm_stay_awake() and pm_relax(). Signed-off-by: NeilBrown Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index b890231debd..6a68041c261 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -344,6 +344,9 @@ static void gpio_keys_gpio_work_func(struct work_struct *work) container_of(work, struct gpio_button_data, work); gpio_keys_gpio_report_event(bdata); + + if (bdata->button->wakeup) + pm_relax(bdata->input->dev.parent); } static void gpio_keys_gpio_timer(unsigned long _data) @@ -359,6 +362,8 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) BUG_ON(irq != bdata->irq); + if (bdata->button->wakeup) + pm_stay_awake(bdata->input->dev.parent); if (bdata->timer_debounce) mod_timer(&bdata->timer, jiffies + msecs_to_jiffies(bdata->timer_debounce)); @@ -395,6 +400,9 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) spin_lock_irqsave(&bdata->lock, flags); if (!bdata->key_pressed) { + if (bdata->button->wakeup) + pm_wakeup_event(bdata->input->dev.parent, 0); + input_event(input, EV_KEY, button->code, 1); input_sync(input); -- cgit v1.2.3-18-g5258 From 112b51cfa21714d001e5b3e3f7c1f13146906a5d Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 29 Jul 2012 22:25:51 -0700 Subject: Input: twl4030-pwrbutton - report a wakeup_event on button press As the power button causes a wake from suspend, we need to register the event with the pm sustem to avoid racing with suspend. As the input event is reported in the interrupt handler, as simple pm_wakeup_event() is sufficient. Signed-off-by: NeilBrown Signed-off-by: Dmitry Torokhov --- drivers/input/misc/twl4030-pwrbutton.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/input') diff --git a/drivers/input/misc/twl4030-pwrbutton.c b/drivers/input/misc/twl4030-pwrbutton.c index 38e4b507b94..b3dd96d6448 100644 --- a/drivers/input/misc/twl4030-pwrbutton.c +++ b/drivers/input/misc/twl4030-pwrbutton.c @@ -42,6 +42,7 @@ static irqreturn_t powerbutton_irq(int irq, void *_pwr) err = twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value, STS_HW_CONDITIONS); if (!err) { + pm_wakeup_event(pwr->dev.parent, 0); input_report_key(pwr, KEY_POWER, value & PWR_PWRON_IRQ); input_sync(pwr); } else { -- cgit v1.2.3-18-g5258 From 41091ad0b8f843d36390058362c8f3c52a26a333 Mon Sep 17 00:00:00 2001 From: Baodong Chen Date: Sun, 29 Jul 2012 22:33:03 -0700 Subject: Input: random formatting fixes Fixes for some coding style issues reported by scripts/checkpatch.pl utility. Signed-off-by: Baodong Chen Signed-off-by: Dmitry Torokhov --- drivers/input/apm-power.c | 2 +- drivers/input/ff-core.c | 4 ++-- drivers/input/ff-memless.c | 14 ++++++++------ drivers/input/joydev.c | 2 +- drivers/input/mousedev.c | 9 ++++----- drivers/input/sparse-keymap.c | 4 ++-- 6 files changed, 18 insertions(+), 17 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/apm-power.c b/drivers/input/apm-power.c index e90ee3d3061..650177a3c85 100644 --- a/drivers/input/apm-power.c +++ b/drivers/input/apm-power.c @@ -33,7 +33,7 @@ static void system_power_event(unsigned int keycode) } static void apmpower_event(struct input_handle *handle, unsigned int type, - unsigned int code, int value) + unsigned int code, int value) { /* only react on key down events */ if (value != 1) diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c index 480eb9d9876..f50f6dd9227 100644 --- a/drivers/input/ff-core.c +++ b/drivers/input/ff-core.c @@ -138,8 +138,8 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, if (effect->id == -1) { for (id = 0; id < ff->max_effects; id++) - if (!ff->effect_owners[id]) - break; + if (!ff->effect_owners[id]) + break; if (id >= ff->max_effects) { ret = -ENOSPC; diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c index b107922514f..74c0d8c6002 100644 --- a/drivers/input/ff-memless.c +++ b/drivers/input/ff-memless.c @@ -72,12 +72,14 @@ static const struct ff_envelope *get_envelope(const struct ff_effect *effect) static const struct ff_envelope empty_envelope; switch (effect->type) { - case FF_PERIODIC: - return &effect->u.periodic.envelope; - case FF_CONSTANT: - return &effect->u.constant.envelope; - default: - return &empty_envelope; + case FF_PERIODIC: + return &effect->u.periodic.envelope; + + case FF_CONSTANT: + return &effect->u.constant.envelope; + + default: + return &empty_envelope; } } diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index 26043cc6a01..78f323ea1e4 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -711,7 +711,7 @@ static long joydev_ioctl(struct file *file, case JS_SET_ALL: retval = copy_from_user(&joydev->glue, argp, - sizeof(joydev->glue)) ? -EFAULT: 0; + sizeof(joydev->glue)) ? -EFAULT : 0; break; case JS_GET_ALL: diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c index 0110b5a3a16..964e43d81e2 100644 --- a/drivers/input/mousedev.c +++ b/drivers/input/mousedev.c @@ -551,17 +551,16 @@ static int mousedev_open(struct inode *inode, struct file *file) return -ENODEV; error = mutex_lock_interruptible(&mousedev_table_mutex); - if (error) { + if (error) return error; - } + mousedev = mousedev_table[i]; if (mousedev) get_device(&mousedev->dev); mutex_unlock(&mousedev_table_mutex); - if (!mousedev) { + if (!mousedev) return -ENODEV; - } client = kzalloc(sizeof(struct mousedev_client), GFP_KERNEL); if (!client) { @@ -1088,7 +1087,7 @@ static int __init mousedev_init(void) #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX error = misc_register(&psaux_mouse); if (error) - pr_warning("could not register psaux device, error: %d\n", + pr_warn("could not register psaux device, error: %d\n", error); else psaux_registered = 1; diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c index 75fb040a343..a70aa555bbf 100644 --- a/drivers/input/sparse-keymap.c +++ b/drivers/input/sparse-keymap.c @@ -180,11 +180,11 @@ int sparse_keymap_setup(struct input_dev *dev, for (e = keymap; e->type != KE_END; e++) map_size++; - map = kcalloc(map_size, sizeof (struct key_entry), GFP_KERNEL); + map = kcalloc(map_size, sizeof(struct key_entry), GFP_KERNEL); if (!map) return -ENOMEM; - memcpy(map, keymap, map_size * sizeof (struct key_entry)); + memcpy(map, keymap, map_size * sizeof(struct key_entry)); for (i = 0; i < map_size; i++) { entry = &map[i]; -- cgit v1.2.3-18-g5258 From 2976f247989cbff1019fa3740938b0b086de5659 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Jul 2012 22:48:33 -0700 Subject: Input: gpio-keys-polled - constify pointers to platform data Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys_polled.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 20c8ab17221..2619297f384 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -38,7 +38,7 @@ struct gpio_keys_button_data { struct gpio_keys_polled_dev { struct input_polled_dev *poll_dev; struct device *dev; - struct gpio_keys_platform_data *pdata; + const struct gpio_keys_platform_data *pdata; struct gpio_keys_button_data data[0]; }; @@ -67,11 +67,11 @@ static void gpio_keys_polled_check_state(struct input_dev *input, static void gpio_keys_polled_poll(struct input_polled_dev *dev) { struct gpio_keys_polled_dev *bdev = dev->private; - struct gpio_keys_platform_data *pdata = bdev->pdata; + const struct gpio_keys_platform_data *pdata = bdev->pdata; struct input_dev *input = dev->input; int i; - for (i = 0; i < bdev->pdata->nbuttons; i++) { + for (i = 0; i < pdata->nbuttons; i++) { struct gpio_keys_button_data *bdata = &bdev->data[i]; if (bdata->count < bdata->threshold) @@ -85,7 +85,7 @@ static void gpio_keys_polled_poll(struct input_polled_dev *dev) static void gpio_keys_polled_open(struct input_polled_dev *dev) { struct gpio_keys_polled_dev *bdev = dev->private; - struct gpio_keys_platform_data *pdata = bdev->pdata; + const struct gpio_keys_platform_data *pdata = bdev->pdata; if (pdata->enable) pdata->enable(bdev->dev); @@ -94,7 +94,7 @@ static void gpio_keys_polled_open(struct input_polled_dev *dev) static void gpio_keys_polled_close(struct input_polled_dev *dev) { struct gpio_keys_polled_dev *bdev = dev->private; - struct gpio_keys_platform_data *pdata = bdev->pdata; + const struct gpio_keys_platform_data *pdata = bdev->pdata; if (pdata->disable) pdata->disable(bdev->dev); @@ -102,8 +102,8 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev) static int __devinit gpio_keys_polled_probe(struct platform_device *pdev) { - struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; struct device *dev = &pdev->dev; + const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); struct gpio_keys_polled_dev *bdev; struct input_polled_dev *poll_dev; struct input_dev *input; @@ -217,7 +217,7 @@ err_free_bdev: static int __devexit gpio_keys_polled_remove(struct platform_device *pdev) { struct gpio_keys_polled_dev *bdev = platform_get_drvdata(pdev); - struct gpio_keys_platform_data *pdata = bdev->pdata; + const struct gpio_keys_platform_data *pdata = bdev->pdata; int i; input_unregister_polled_device(bdev->poll_dev); -- cgit v1.2.3-18-g5258 From a2f25245269d754a9fd687a15db975271a58c5e0 Mon Sep 17 00:00:00 2001 From: Alexandre Pereira da Silva Date: Tue, 31 Jul 2012 22:08:45 -0700 Subject: Input: gpio_keys_polled - convert to dt Signed-off-by: Alexandre Pereira da Silva Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys_polled.c | 132 ++++++++++++++++++++++++++++-- 1 file changed, 127 insertions(+), 5 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 2619297f384..79089520621 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #define DRV_NAME "gpio-keys-polled" @@ -100,6 +102,99 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev) pdata->disable(bdev->dev); } +#ifdef CONFIG_OF +static struct gpio_keys_platform_data * __devinit +gpio_keys_polled_get_devtree_pdata(struct device *dev) +{ + struct device_node *node, *pp; + struct gpio_keys_platform_data *pdata; + struct gpio_keys_button *button; + int error; + int nbuttons; + int i; + + node = dev->of_node; + if (!node) + return NULL; + + nbuttons = of_get_child_count(node); + if (nbuttons == 0) + return NULL; + + pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), + GFP_KERNEL); + if (!pdata) { + error = -ENOMEM; + goto err_out; + } + + pdata->buttons = (struct gpio_keys_button *)(pdata + 1); + + pdata->rep = !!of_get_property(node, "autorepeat", NULL); + of_property_read_u32(node, "poll-interval", &pdata->poll_interval); + + i = 0; + for_each_child_of_node(node, pp) { + enum of_gpio_flags flags; + + if (!of_find_property(pp, "gpios", NULL)) { + pdata->nbuttons--; + dev_warn(dev, "Found button without gpios\n"); + continue; + } + + button = &pdata->buttons[i++]; + + button->gpio = of_get_gpio_flags(pp, 0, &flags); + button->active_low = flags & OF_GPIO_ACTIVE_LOW; + + if (of_property_read_u32(pp, "linux,code", &button->code)) { + dev_err(dev, "Button without keycode: 0x%x\n", + button->gpio); + error = -EINVAL; + goto err_free_pdata; + } + + button->desc = of_get_property(pp, "label", NULL); + + if (of_property_read_u32(pp, "linux,input-type", &button->type)) + button->type = EV_KEY; + + button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); + + if (of_property_read_u32(pp, "debounce-interval", + &button->debounce_interval)) + button->debounce_interval = 5; + } + + if (pdata->nbuttons == 0) { + error = -EINVAL; + goto err_free_pdata; + } + + return pdata; + +err_free_pdata: + kfree(pdata); +err_out: + return ERR_PTR(error); +} + +static struct of_device_id gpio_keys_polled_of_match[] = { + { .compatible = "gpio-keys-polled", }, + { }, +}; +MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); + +#else + +static inline struct gpio_keys_platform_data * +gpio_keys_polled_get_devtree_pdata(struct device *dev) +{ + return NULL; +} +#endif + static int __devinit gpio_keys_polled_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -110,15 +205,29 @@ static int __devinit gpio_keys_polled_probe(struct platform_device *pdev) int error; int i; - if (!pdata || !pdata->poll_interval) - return -EINVAL; + if (!pdata) { + pdata = gpio_keys_polled_get_devtree_pdata(dev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + if (!pdata) { + dev_err(dev, "missing platform data\n"); + return -EINVAL; + } + } + + if (!pdata->poll_interval) { + dev_err(dev, "missing poll_interval value\n"); + error = -EINVAL; + goto err_free_pdata; + } bdev = kzalloc(sizeof(struct gpio_keys_polled_dev) + pdata->nbuttons * sizeof(struct gpio_keys_button_data), GFP_KERNEL); if (!bdev) { dev_err(dev, "no memory for private data\n"); - return -ENOMEM; + error = -ENOMEM; + goto err_free_pdata; } poll_dev = input_allocate_polled_device(); @@ -197,7 +306,7 @@ static int __devinit gpio_keys_polled_probe(struct platform_device *pdev) /* report initial state of the buttons */ for (i = 0; i < pdata->nbuttons; i++) gpio_keys_polled_check_state(input, &pdata->buttons[i], - &bdev->data[i]); + &bdev->data[i]); return 0; @@ -209,8 +318,13 @@ err_free_gpio: err_free_bdev: kfree(bdev); - platform_set_drvdata(pdev, NULL); + +err_free_pdata: + /* If we have no platform_data, we allocated pdata dynamically. */ + if (!dev_get_platdata(&pdev->dev)) + kfree(pdata); + return error; } @@ -227,6 +341,13 @@ static int __devexit gpio_keys_polled_remove(struct platform_device *pdev) input_free_polled_device(bdev->poll_dev); + /* + * If we had no platform_data, we allocated pdata dynamically and + * must free it here. + */ + if (!dev_get_platdata(&pdev->dev)) + kfree(pdata); + kfree(bdev); platform_set_drvdata(pdev, NULL); @@ -239,6 +360,7 @@ static struct platform_driver gpio_keys_polled_driver = { .driver = { .name = DRV_NAME, .owner = THIS_MODULE, + .of_match_table = of_match_ptr(gpio_keys_polled_of_match), }, }; module_platform_driver(gpio_keys_polled_driver); -- cgit v1.2.3-18-g5258 From a78769b80d73468d53d0ad70c5a9e3fd9ff9dc54 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Tue, 31 Jul 2012 22:08:47 -0700 Subject: Input: rotary-encoder - defer calls gpio_to_irq() Don't call gpio_to_irq() on GPIOs before gpio_request() succeeded on them. This avoids Ooopses with incorrect DT bindings. Signed-off-by: Daniel Mack Signed-off-by: Dmitry Torokhov --- drivers/input/misc/rotary_encoder.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index f07f784198b..00a7bdabb0b 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -163,8 +163,6 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) encoder->input = input; encoder->pdata = pdata; - encoder->irq_a = gpio_to_irq(pdata->gpio_a); - encoder->irq_b = gpio_to_irq(pdata->gpio_b); /* create and register the input driver */ input->name = pdev->name; @@ -215,6 +213,9 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) goto exit_free_gpio_a; } + encoder->irq_a = gpio_to_irq(pdata->gpio_a); + encoder->irq_b = gpio_to_irq(pdata->gpio_b); + /* request the IRQs */ if (pdata->half_period) { handler = &rotary_encoder_half_period_irq; -- cgit v1.2.3-18-g5258 From 429a34d7477bb7071d37dd98b89f000ee6f0193b Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Tue, 31 Jul 2012 22:08:48 -0700 Subject: Input: rotary-encoder - use gpio_request_one() Use gpio_request_one() instead of separate calls to gpio_request() and gpio_direction_input() to simplify the code. Signed-off-by: Daniel Mack Signed-off-by: Dmitry Torokhov --- drivers/input/misc/rotary_encoder.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 00a7bdabb0b..e261ad4e6c6 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -145,6 +145,7 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data; struct rotary_encoder *encoder; struct input_dev *input; + struct device *dev = &pdev->dev; irq_handler_t handler; int err; @@ -180,36 +181,20 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) err = input_register_device(input); if (err) { - dev_err(&pdev->dev, "failed to register input device\n"); + dev_err(dev, "failed to register input device\n"); goto exit_free_mem; } /* request the GPIOs */ - err = gpio_request(pdata->gpio_a, DRV_NAME); + err = gpio_request_one(pdata->gpio_a, GPIOF_IN, dev_name(dev)); if (err) { - dev_err(&pdev->dev, "unable to request GPIO %d\n", - pdata->gpio_a); + dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_a); goto exit_unregister_input; } - err = gpio_direction_input(pdata->gpio_a); + err = gpio_request_one(pdata->gpio_b, GPIOF_IN, dev_name(dev)); if (err) { - dev_err(&pdev->dev, "unable to set GPIO %d for input\n", - pdata->gpio_a); - goto exit_unregister_input; - } - - err = gpio_request(pdata->gpio_b, DRV_NAME); - if (err) { - dev_err(&pdev->dev, "unable to request GPIO %d\n", - pdata->gpio_b); - goto exit_free_gpio_a; - } - - err = gpio_direction_input(pdata->gpio_b); - if (err) { - dev_err(&pdev->dev, "unable to set GPIO %d for input\n", - pdata->gpio_b); + dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_b); goto exit_free_gpio_a; } @@ -228,8 +213,7 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, DRV_NAME, encoder); if (err) { - dev_err(&pdev->dev, "unable to request IRQ %d\n", - encoder->irq_a); + dev_err(dev, "unable to request IRQ %d\n", encoder->irq_a); goto exit_free_gpio_b; } @@ -237,8 +221,7 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, DRV_NAME, encoder); if (err) { - dev_err(&pdev->dev, "unable to request IRQ %d\n", - encoder->irq_b); + dev_err(dev, "unable to request IRQ %d\n", encoder->irq_b); goto exit_free_irq_a; } -- cgit v1.2.3-18-g5258 From ce9195378299ff2f3d703937de46bdd338e780eb Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 31 Jul 2012 22:08:49 -0700 Subject: Input: rotary-encoder - constify platform data pointers Drivers should not be changing platform data attached to the device because they do not own it. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/rotary_encoder.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index e261ad4e6c6..ea51265d4e0 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -29,7 +29,7 @@ struct rotary_encoder { struct input_dev *input; - struct rotary_encoder_platform_data *pdata; + const struct rotary_encoder_platform_data *pdata; unsigned int axis; unsigned int pos; @@ -43,7 +43,7 @@ struct rotary_encoder { char last_stable; }; -static int rotary_encoder_get_state(struct rotary_encoder_platform_data *pdata) +static int rotary_encoder_get_state(const struct rotary_encoder_platform_data *pdata) { int a = !!gpio_get_value(pdata->gpio_a); int b = !!gpio_get_value(pdata->gpio_b); @@ -56,7 +56,7 @@ static int rotary_encoder_get_state(struct rotary_encoder_platform_data *pdata) static void rotary_encoder_report_event(struct rotary_encoder *encoder) { - struct rotary_encoder_platform_data *pdata = encoder->pdata; + const struct rotary_encoder_platform_data *pdata = encoder->pdata; if (pdata->relative_axis) { input_report_rel(encoder->input, @@ -142,10 +142,10 @@ static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) static int __devinit rotary_encoder_probe(struct platform_device *pdev) { - struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data; + struct device *dev = &pdev->dev; + const struct rotary_encoder_platform_data *pdata = dev_get_platdata(dev); struct rotary_encoder *encoder; struct input_dev *input; - struct device *dev = &pdev->dev; irq_handler_t handler; int err; @@ -247,7 +247,7 @@ exit_free_mem: static int __devexit rotary_encoder_remove(struct platform_device *pdev) { struct rotary_encoder *encoder = platform_get_drvdata(pdev); - struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data; + const struct rotary_encoder_platform_data *pdata = encoder->pdata; free_irq(encoder->irq_a, encoder); free_irq(encoder->irq_b, encoder); -- cgit v1.2.3-18-g5258 From 80c99bcd28617bd534b6f9489857235ee613c797 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Tue, 31 Jul 2012 22:08:50 -0700 Subject: Input: rotary-encoder - add DT bindings This adds devicetree bindings to the rotary encoder driver and some documentation about how to use them. Tested on a PXA3xx platform. Signed-off-by: Daniel Mack Signed-off-by: Dmitry Torokhov --- drivers/input/misc/rotary_encoder.c | 96 ++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 16 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index ea51265d4e0..99a49e4968d 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #define DRV_NAME "rotary-encoder" @@ -140,6 +142,56 @@ static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) return IRQ_HANDLED; } +#ifdef CONFIG_OF +static struct of_device_id rotary_encoder_of_match[] = { + { .compatible = "rotary-encoder", }, + { }, +}; +MODULE_DEVICE_TABLE(of, rotary_encoder_of_match); + +static struct rotary_encoder_platform_data * __devinit +rotary_encoder_parse_dt(struct device *dev) +{ + const struct of_device_id *of_id = + of_match_device(rotary_encoder_of_match, dev); + struct device_node *np = dev->of_node; + struct rotary_encoder_platform_data *pdata; + enum of_gpio_flags flags; + + if (!of_id || !np) + return NULL; + + pdata = kzalloc(sizeof(struct rotary_encoder_platform_data), + GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + of_property_read_u32(np, "rotary-encoder,steps", &pdata->steps); + of_property_read_u32(np, "linux,axis", &pdata->axis); + + pdata->gpio_a = of_get_gpio_flags(np, 0, &flags); + pdata->inverted_a = flags & OF_GPIO_ACTIVE_LOW; + + pdata->gpio_b = of_get_gpio_flags(np, 1, &flags); + pdata->inverted_b = flags & OF_GPIO_ACTIVE_LOW; + + pdata->relative_axis = !!of_get_property(np, + "rotary-encoder,relative-axis", NULL); + pdata->rollover = !!of_get_property(np, + "rotary-encoder,rollover", NULL); + pdata->half_period = !!of_get_property(np, + "rotary-encoder,half-period", NULL); + + return pdata; +} +#else +static inline struct rotary_encoder_platform_data * +rotary_encoder_parse_dt(struct device *dev) +{ + return NULL; +} +#endif + static int __devinit rotary_encoder_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -150,14 +202,19 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) int err; if (!pdata) { - dev_err(&pdev->dev, "missing platform data\n"); - return -ENOENT; + pdata = rotary_encoder_parse_dt(dev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + + if (!pdata) { + dev_err(dev, "missing platform data\n"); + return -EINVAL; + } } encoder = kzalloc(sizeof(struct rotary_encoder), GFP_KERNEL); input = input_allocate_device(); if (!encoder || !input) { - dev_err(&pdev->dev, "failed to allocate memory for device\n"); err = -ENOMEM; goto exit_free_mem; } @@ -165,10 +222,9 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) encoder->input = input; encoder->pdata = pdata; - /* create and register the input driver */ input->name = pdev->name; input->id.bustype = BUS_HOST; - input->dev.parent = &pdev->dev; + input->dev.parent = dev; if (pdata->relative_axis) { input->evbit[0] = BIT_MASK(EV_REL); @@ -179,17 +235,11 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) pdata->axis, 0, pdata->steps, 0, 1); } - err = input_register_device(input); - if (err) { - dev_err(dev, "failed to register input device\n"); - goto exit_free_mem; - } - /* request the GPIOs */ err = gpio_request_one(pdata->gpio_a, GPIOF_IN, dev_name(dev)); if (err) { dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_a); - goto exit_unregister_input; + goto exit_free_mem; } err = gpio_request_one(pdata->gpio_b, GPIOF_IN, dev_name(dev)); @@ -225,22 +275,30 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev) goto exit_free_irq_a; } + err = input_register_device(input); + if (err) { + dev_err(dev, "failed to register input device\n"); + goto exit_free_irq_b; + } + platform_set_drvdata(pdev, encoder); return 0; +exit_free_irq_b: + free_irq(encoder->irq_b, encoder); exit_free_irq_a: free_irq(encoder->irq_a, encoder); exit_free_gpio_b: gpio_free(pdata->gpio_b); exit_free_gpio_a: gpio_free(pdata->gpio_a); -exit_unregister_input: - input_unregister_device(input); - input = NULL; /* so we don't try to free it */ exit_free_mem: input_free_device(input); kfree(encoder); + if (!dev_get_platdata(&pdev->dev)) + kfree(pdata); + return err; } @@ -253,10 +311,15 @@ static int __devexit rotary_encoder_remove(struct platform_device *pdev) free_irq(encoder->irq_b, encoder); gpio_free(pdata->gpio_a); gpio_free(pdata->gpio_b); + input_unregister_device(encoder->input); - platform_set_drvdata(pdev, NULL); kfree(encoder); + if (!dev_get_platdata(&pdev->dev)) + kfree(pdata); + + platform_set_drvdata(pdev, NULL); + return 0; } @@ -266,6 +329,7 @@ static struct platform_driver rotary_encoder_driver = { .driver = { .name = DRV_NAME, .owner = THIS_MODULE, + .of_match_table = of_match_ptr(rotary_encoder_of_match), } }; module_platform_driver(rotary_encoder_driver); -- cgit v1.2.3-18-g5258 From c0bb1f975ca06b17d595937c5e91578b36047039 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 31 Jul 2012 22:08:55 -0700 Subject: Input: get rid of MATCH_BIT() macro MATCH_BIT() is ugly and stupid, we have much nicer bitmap_subset() which does the same and does not hide control flow. Reported-by: Baodong Chen Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/input.c b/drivers/input/input.c index 8921c6180c5..768e46b05ef 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -844,18 +844,10 @@ int input_set_keycode(struct input_dev *dev, } EXPORT_SYMBOL(input_set_keycode); -#define MATCH_BIT(bit, max) \ - for (i = 0; i < BITS_TO_LONGS(max); i++) \ - if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \ - break; \ - if (i != BITS_TO_LONGS(max)) \ - continue; - static const struct input_device_id *input_match_device(struct input_handler *handler, struct input_dev *dev) { const struct input_device_id *id; - int i; for (id = handler->id_table; id->flags || id->driver_info; id++) { @@ -875,15 +867,32 @@ static const struct input_device_id *input_match_device(struct input_handler *ha if (id->version != dev->id.version) continue; - MATCH_BIT(evbit, EV_MAX); - MATCH_BIT(keybit, KEY_MAX); - MATCH_BIT(relbit, REL_MAX); - MATCH_BIT(absbit, ABS_MAX); - MATCH_BIT(mscbit, MSC_MAX); - MATCH_BIT(ledbit, LED_MAX); - MATCH_BIT(sndbit, SND_MAX); - MATCH_BIT(ffbit, FF_MAX); - MATCH_BIT(swbit, SW_MAX); + if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX)) + continue; + + if (!bitmap_subset(id->keybit, dev->keybit, KEY_MAX)) + continue; + + if (!bitmap_subset(id->relbit, dev->relbit, REL_MAX)) + continue; + + if (!bitmap_subset(id->absbit, dev->absbit, ABS_MAX)) + continue; + + if (!bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX)) + continue; + + if (!bitmap_subset(id->ledbit, dev->ledbit, LED_MAX)) + continue; + + if (!bitmap_subset(id->sndbit, dev->sndbit, SND_MAX)) + continue; + + if (!bitmap_subset(id->ffbit, dev->ffbit, FF_MAX)) + continue; + + if (!bitmap_subset(id->swbit, dev->swbit, SW_MAX)) + continue; if (!handler->match || handler->match(handler, dev)) return id; -- cgit v1.2.3-18-g5258 From 929d1af5478dec82903e05aa9662a4ec12ad655b Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Jul 2012 22:48:31 -0700 Subject: Input: uinput - take event lock when fetching events from buffer When fetching events form device's buffer in uinput_read() we need to take input device's event_lock to avoid racing with new event delivery. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 736056897e5..1b4ee4a5c49 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -452,9 +452,28 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t return retval; } +static bool uinput_fetch_next_event(struct uinput_device *udev, + struct input_event *event) +{ + bool have_event; + + spin_lock_irq(&udev->dev->event_lock); + + have_event = udev->head != udev->tail; + if (have_event) { + *event = udev->buff[udev->tail]; + udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE; + } + + spin_unlock_irq(&udev->dev->event_lock); + + return have_event; +} + static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { struct uinput_device *udev = file->private_data; + struct input_event event; int retval = 0; if (udev->state != UIST_CREATED) @@ -477,12 +496,14 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, goto out; } - while (udev->head != udev->tail && retval + input_event_size() <= count) { - if (input_event_to_user(buffer + retval, &udev->buff[udev->tail])) { + while (retval + input_event_size() <= count && + uinput_fetch_next_event(udev, &event)) { + + if (input_event_to_user(buffer + retval, &event)) { retval = -EFAULT; goto out; } - udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE; + retval += input_event_size(); } -- cgit v1.2.3-18-g5258 From f40033acc2d14acecd1b27a79dc8a0ad437e619a Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 29 Jul 2012 22:48:31 -0700 Subject: Input: uinput - return -EINVAL when read buffer size is too small Let's check whether the user-supplied buffer is actually big enough and return -EINVAL if it is not. This differs from current behavior, which caused 0 to be returned and actually does not make any sense, as broken application will simply repeat the read getting into endless loop. Note that we treat 0 as a special case, according to the standard: "Before any action described below is taken, and if nbyte is zero, the read() function may detect and return errors as described below. In the absence of errors, or if error detection is not performed, the read() function shall return zero and have no other results." Signed-off-by: David Herrmann Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/input') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 1b4ee4a5c49..e74ed9cc637 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -476,6 +476,9 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, struct input_event event; int retval = 0; + if (count != 0 && count < input_event_size()) + return -EINVAL; + if (udev->state != UIST_CREATED) return -ENODEV; -- cgit v1.2.3-18-g5258 From 22ae19c6e3c22b390952e90f452f26adad9b8687 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Jul 2012 22:48:31 -0700 Subject: Input: uinput - fix race that can block nonblocking read Consider two threads calling read() on the same uinput-fd, both non-blocking. Assume there is data-available so both will simultaneously pass: udev->head == udev->tail Then the first thread goes to sleep and the second one pops the message from the queue. Now assume udev->head == udev->tail. If the first thread wakes up it will call wait_event_*() and sleep in the waitq. This effectively turns the non-blocking FD into a blocking one. We fix this by attempting to fetch events from the queue first and only if we fail to retrieve any events we either return -EAGAIN (in case of non-blocing read) or wait until there are more events. This also fixes incorrect return code (we were returning 0 instead of -EAGAIN for non-blocking reads) when an event is "stolen" by another thread. Blocking reads will now continue to wait instead of returning 0 in this scenario. Count of 0 continues to be a special case, as per spec: we will check for device existence and whether there are events in the queue, but no events will be actually retrieved. Reported-by: David Herrmann Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 74 +++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index e74ed9cc637..1719554fe19 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -439,6 +439,9 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t struct uinput_device *udev = file->private_data; int retval; + if (count == 0) + return 0; + retval = mutex_lock_interruptible(&udev->mutex); if (retval) return retval; @@ -470,48 +473,59 @@ static bool uinput_fetch_next_event(struct uinput_device *udev, return have_event; } -static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) +static ssize_t uinput_events_to_user(struct uinput_device *udev, + char __user *buffer, size_t count) { - struct uinput_device *udev = file->private_data; struct input_event event; - int retval = 0; + size_t read = 0; + int error = 0; - if (count != 0 && count < input_event_size()) - return -EINVAL; + while (read + input_event_size() <= count && + uinput_fetch_next_event(udev, &event)) { - if (udev->state != UIST_CREATED) - return -ENODEV; + if (input_event_to_user(buffer + read, &event)) { + error = -EFAULT; + break; + } - if (udev->head == udev->tail && (file->f_flags & O_NONBLOCK)) - return -EAGAIN; + read += input_event_size(); + } - retval = wait_event_interruptible(udev->waitq, - udev->head != udev->tail || udev->state != UIST_CREATED); - if (retval) - return retval; + return read ?: error; +} - retval = mutex_lock_interruptible(&udev->mutex); - if (retval) - return retval; +static ssize_t uinput_read(struct file *file, char __user *buffer, + size_t count, loff_t *ppos) +{ + struct uinput_device *udev = file->private_data; + ssize_t retval; - if (udev->state != UIST_CREATED) { - retval = -ENODEV; - goto out; - } + if (count != 0 && count < input_event_size()) + return -EINVAL; - while (retval + input_event_size() <= count && - uinput_fetch_next_event(udev, &event)) { + do { + retval = mutex_lock_interruptible(&udev->mutex); + if (retval) + return retval; - if (input_event_to_user(buffer + retval, &event)) { - retval = -EFAULT; - goto out; - } + if (udev->state != UIST_CREATED) + retval = -ENODEV; + else if (udev->head == udev->tail && + (file->f_flags & O_NONBLOCK)) + retval = -EAGAIN; + else + retval = uinput_events_to_user(udev, buffer, count); - retval += input_event_size(); - } + mutex_unlock(&udev->mutex); - out: - mutex_unlock(&udev->mutex); + if (retval || count == 0) + break; + + if (!(file->f_flags & O_NONBLOCK)) + retval = wait_event_interruptible(udev->waitq, + udev->head != udev->tail || + udev->state != UIST_CREATED); + } while (retval == 0); return retval; } -- cgit v1.2.3-18-g5258 From 00ce756ce53acdb82d408346e6a7b734ca9e5bad Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Jul 2012 22:48:32 -0700 Subject: Input: uinput - mark failed submission requests as free If uinput_request_submit() fails after new request ID was allocated we need to mark that request ID as free, otherwise it will always stay occupied and we may run out of available IDs. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 78 +++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 38 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 1719554fe19..6099365102d 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -56,10 +56,11 @@ static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned i } /* Atomically allocate an ID for the given request. Returns 0 on success. */ -static int uinput_request_alloc_id(struct uinput_device *udev, struct uinput_request *request) +static bool uinput_request_alloc_id(struct uinput_device *udev, + struct uinput_request *request) { int id; - int err = -1; + bool reserved = false; spin_lock(&udev->requests_lock); @@ -67,13 +68,13 @@ static int uinput_request_alloc_id(struct uinput_device *udev, struct uinput_req if (!udev->requests[id]) { request->id = id; udev->requests[id] = request; - err = 0; + reserved = true; break; } } spin_unlock(&udev->requests_lock); - return err; + return reserved; } static struct uinput_request *uinput_request_find(struct uinput_device *udev, int id) @@ -85,11 +86,12 @@ static struct uinput_request *uinput_request_find(struct uinput_device *udev, in return udev->requests[id]; } -static inline int uinput_request_reserve_slot(struct uinput_device *udev, struct uinput_request *request) +static int uinput_request_reserve_slot(struct uinput_device *udev, + struct uinput_request *request) { /* Allocate slot. If none are available right away, wait. */ return wait_event_interruptible(udev->requests_waitq, - !uinput_request_alloc_id(udev, request)); + uinput_request_alloc_id(udev, request)); } static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request) @@ -101,14 +103,11 @@ static void uinput_request_done(struct uinput_device *udev, struct uinput_reques complete(&request->done); } -static int uinput_request_submit(struct uinput_device *udev, struct uinput_request *request) +static int uinput_request_send(struct uinput_device *udev, + struct uinput_request *request) { int retval; - retval = uinput_request_reserve_slot(udev, request); - if (retval) - return retval; - retval = mutex_lock_interruptible(&udev->mutex); if (retval) return retval; @@ -118,7 +117,12 @@ static int uinput_request_submit(struct uinput_device *udev, struct uinput_reque goto out; } - /* Tell our userspace app about this new request by queueing an input event */ + init_completion(&request->done); + + /* + * Tell our userspace application about this new request + * by queueing an input event. + */ uinput_dev_event(udev->dev, EV_UINPUT, request->code, request->id); out: @@ -126,6 +130,25 @@ static int uinput_request_submit(struct uinput_device *udev, struct uinput_reque return retval; } +static int uinput_request_submit(struct uinput_device *udev, + struct uinput_request *request) +{ + int error; + + error = uinput_request_reserve_slot(udev, request); + if (error) + return error; + + error = uinput_request_send(udev, request); + if (error) { + uinput_request_done(udev, request); + return error; + } + + wait_for_completion(&request->done); + return request->retval; +} + /* * Fail all ouitstanding requests so handlers don't wait for the userspace * to finish processing them. @@ -167,7 +190,6 @@ static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *eff { struct uinput_device *udev = input_get_drvdata(dev); struct uinput_request request; - int retval; /* * uinput driver does not currently support periodic effects with @@ -180,42 +202,25 @@ static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *eff effect->u.periodic.waveform == FF_CUSTOM) return -EINVAL; - request.id = -1; - init_completion(&request.done); request.code = UI_FF_UPLOAD; request.u.upload.effect = effect; request.u.upload.old = old; - retval = uinput_request_submit(udev, &request); - if (!retval) { - wait_for_completion(&request.done); - retval = request.retval; - } - - return retval; + return uinput_request_submit(udev, &request); } static int uinput_dev_erase_effect(struct input_dev *dev, int effect_id) { struct uinput_device *udev = input_get_drvdata(dev); struct uinput_request request; - int retval; if (!test_bit(EV_FF, dev->evbit)) return -ENOSYS; - request.id = -1; - init_completion(&request.done); request.code = UI_FF_ERASE; request.u.effect_id = effect_id; - retval = uinput_request_submit(udev, &request); - if (!retval) { - wait_for_completion(&request.done); - retval = request.retval; - } - - return retval; + return uinput_request_submit(udev, &request); } static void uinput_destroy_device(struct uinput_device *udev) @@ -478,20 +483,17 @@ static ssize_t uinput_events_to_user(struct uinput_device *udev, { struct input_event event; size_t read = 0; - int error = 0; while (read + input_event_size() <= count && uinput_fetch_next_event(udev, &event)) { - if (input_event_to_user(buffer + read, &event)) { - error = -EFAULT; - break; - } + if (input_event_to_user(buffer + read, &event)) + return -EFAULT; read += input_event_size(); } - return read ?: error; + return read; } static ssize_t uinput_read(struct file *file, char __user *buffer, -- cgit v1.2.3-18-g5258 From c5b3533a82ef4b6ceae81b7675f8d6dadcc6f3ab Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Jul 2012 22:48:32 -0700 Subject: Input: uinput - specify exact bit sizes on userspace APIs Switch to using __u32/__s32 instead of ordinary 'int' in structures forming userspace API. Also internally make request_id unsigned int. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 6099365102d..b247e1c8e8f 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -59,7 +59,7 @@ static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned i static bool uinput_request_alloc_id(struct uinput_device *udev, struct uinput_request *request) { - int id; + unsigned int id; bool reserved = false; spin_lock(&udev->requests_lock); @@ -77,10 +77,11 @@ static bool uinput_request_alloc_id(struct uinput_device *udev, return reserved; } -static struct uinput_request *uinput_request_find(struct uinput_device *udev, int id) +static struct uinput_request *uinput_request_find(struct uinput_device *udev, + unsigned int id) { /* Find an input request, by ID. Returns NULL if the ID isn't valid. */ - if (id >= UINPUT_NUM_REQUESTS || id < 0) + if (id >= UINPUT_NUM_REQUESTS) return NULL; return udev->requests[id]; @@ -556,8 +557,8 @@ static int uinput_release(struct inode *inode, struct file *file) #ifdef CONFIG_COMPAT struct uinput_ff_upload_compat { - int request_id; - int retval; + __u32 request_id; + __s32 retval; struct ff_effect_compat effect; struct ff_effect_compat old; }; -- cgit v1.2.3-18-g5258 From 54ce165ebd9d9494b64149e0d1ab4ddbf5ea908b Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Jul 2012 22:48:32 -0700 Subject: Input: uinput - fix formatting Reformat the code to keep it within 80 columns. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index b247e1c8e8f..86328e9c984 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -40,7 +40,8 @@ #include #include "../input-compat.h" -static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) +static int uinput_dev_event(struct input_dev *dev, + unsigned int type, unsigned int code, int value) { struct uinput_device *udev = input_get_drvdata(dev); @@ -95,7 +96,8 @@ static int uinput_request_reserve_slot(struct uinput_device *udev, uinput_request_alloc_id(udev, request)); } -static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request) +static void uinput_request_done(struct uinput_device *udev, + struct uinput_request *request) { /* Mark slot as available */ udev->requests[request->id] = NULL; @@ -151,7 +153,7 @@ static int uinput_request_submit(struct uinput_device *udev, } /* - * Fail all ouitstanding requests so handlers don't wait for the userspace + * Fail all outstanding requests so handlers don't wait for the userspace * to finish processing them. */ static void uinput_flush_requests(struct uinput_device *udev) @@ -187,7 +189,9 @@ static int uinput_dev_playback(struct input_dev *dev, int effect_id, int value) return uinput_dev_event(dev, EV_FF, effect_id, value); } -static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old) +static int uinput_dev_upload_effect(struct input_dev *dev, + struct ff_effect *effect, + struct ff_effect *old) { struct uinput_device *udev = input_get_drvdata(dev); struct uinput_request request; @@ -353,7 +357,8 @@ static int uinput_allocate_device(struct uinput_device *udev) return 0; } -static int uinput_setup_device(struct uinput_device *udev, const char __user *buffer, size_t count) +static int uinput_setup_device(struct uinput_device *udev, + const char __user *buffer, size_t count) { struct uinput_user_dev *user_dev; struct input_dev *dev; @@ -425,7 +430,8 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu return retval; } -static inline ssize_t uinput_inject_event(struct uinput_device *udev, const char __user *buffer, size_t count) +static ssize_t uinput_inject_event(struct uinput_device *udev, + const char __user *buffer, size_t count) { struct input_event ev; @@ -440,7 +446,8 @@ static inline ssize_t uinput_inject_event(struct uinput_device *udev, const char return input_event_size(); } -static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) +static ssize_t uinput_write(struct file *file, const char __user *buffer, + size_t count, loff_t *ppos) { struct uinput_device *udev = file->private_data; int retval; @@ -744,7 +751,8 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, break; req = uinput_request_find(udev, ff_up.request_id); - if (!req || req->code != UI_FF_UPLOAD || !req->u.upload.effect) { + if (!req || req->code != UI_FF_UPLOAD || + !req->u.upload.effect) { retval = -EINVAL; break; } @@ -827,7 +835,8 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } #ifdef CONFIG_COMPAT -static long uinput_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +static long uinput_compat_ioctl(struct file *file, + unsigned int cmd, unsigned long arg) { return uinput_ioctl_handler(file, cmd, arg, compat_ptr(arg)); } @@ -872,4 +881,3 @@ MODULE_VERSION("0.3"); module_init(uinput_init); module_exit(uinput_exit); - -- cgit v1.2.3-18-g5258 From f4d4661bee0f54410ac65571b50df5d9fe091d03 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Aug 2012 22:04:32 -0700 Subject: Input: samsung-keypad - use of_match_ptr() Instead of having to define the match table to NULL if CONFIG_OF isn't set, use the of_match_ptr() macro which will do this for us. Signed-off-by: Tobias Klauser Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/samsung-keypad.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index a061ba603a2..e2f31c8489f 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -662,8 +662,6 @@ static const struct of_device_id samsung_keypad_dt_match[] = { {}, }; MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match); -#else -#define samsung_keypad_dt_match NULL #endif static struct platform_device_id samsung_keypad_driver_ids[] = { @@ -684,7 +682,7 @@ static struct platform_driver samsung_keypad_driver = { .driver = { .name = "samsung-keypad", .owner = THIS_MODULE, - .of_match_table = samsung_keypad_dt_match, + .of_match_table = of_match_ptr(samsung_keypad_dt_match), .pm = &samsung_keypad_pm_ops, }, .id_table = samsung_keypad_driver_ids, -- cgit v1.2.3-18-g5258 From 31b95bfb79e8d7637ba0d399eb152f9b0d548340 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Aug 2012 22:04:46 -0700 Subject: Input: samsung-keypad - use of_get_child_count() helper Use of_get_child_count() instead of custom implementation. Signed-off-by: Tobias Klauser Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/samsung-keypad.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index e2f31c8489f..277e26dc910 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -256,7 +256,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt( struct matrix_keymap_data *keymap_data; uint32_t *keymap, num_rows = 0, num_cols = 0; struct device_node *np = dev->of_node, *key_np; - unsigned int key_count = 0; + unsigned int key_count; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { @@ -280,9 +280,7 @@ static struct samsung_keypad_platdata *samsung_keypad_parse_dt( } pdata->keymap_data = keymap_data; - for_each_child_of_node(np, key_np) - key_count++; - + key_count = of_get_child_count(np); keymap_data->keymap_size = key_count; keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL); if (!keymap) { -- cgit v1.2.3-18-g5258 From bd68dfe0071b50bc69416a92ee22b63d1cc33a3b Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Fri, 31 Aug 2012 07:50:21 -0700 Subject: Input: s3c2410_ts - make s3c_ts_pmops const Fixes the following warning: WARNING: struct dev_pm_ops should normally be const Signed-off-by: Sachin Kamat Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/s3c2410_ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/input') diff --git a/drivers/input/touchscreen/s3c2410_ts.c b/drivers/input/touchscreen/s3c2410_ts.c index bf1a0640006..b3c66d4d02f 100644 --- a/drivers/input/touchscreen/s3c2410_ts.c +++ b/drivers/input/touchscreen/s3c2410_ts.c @@ -406,7 +406,7 @@ static int s3c2410ts_resume(struct device *dev) return 0; } -static struct dev_pm_ops s3c_ts_pmops = { +static const struct dev_pm_ops s3c_ts_pmops = { .suspend = s3c2410ts_suspend, .resume = s3c2410ts_resume, }; -- cgit v1.2.3-18-g5258 From 77626ebc0cb540c39f03e988484ee650a99c355b Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Tue, 21 Aug 2012 22:11:59 -0700 Subject: Input: wacom - add support for EMR on Cintiq 24HD touch Adds support for the EMR digitizer on the Cintiq 24HD touch. The EMR digitizer should work identically to that found on the Cintiq 24HD. The touch digitizer is a separate USB device similar to how we split apart some other devices. Signed-off-by: Jason Gerecke Signed-off-by: Dmitry Torokhov --- drivers/input/tablet/wacom_wac.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/input') diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c index 002041975de..532d067a9e0 100644 --- a/drivers/input/tablet/wacom_wac.c +++ b/drivers/input/tablet/wacom_wac.c @@ -1848,7 +1848,10 @@ static const struct wacom_features wacom_features_0x2A = { "Wacom Intuos5 M", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047, 63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES }; static const struct wacom_features wacom_features_0xF4 = - { "Wacom Cintiq 24HD", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047, + { "Wacom Cintiq 24HD", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047, + 63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES }; +static const struct wacom_features wacom_features_0xF8 = + { "Wacom Cintiq 24HD touch", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047, 63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES }; static const struct wacom_features wacom_features_0x3F = { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023, @@ -2091,6 +2094,7 @@ const struct usb_device_id wacom_ids[] = { { USB_DEVICE_WACOM(0xEF) }, { USB_DEVICE_WACOM(0x47) }, { USB_DEVICE_WACOM(0xF4) }, + { USB_DEVICE_WACOM(0xF8) }, { USB_DEVICE_WACOM(0xFA) }, { USB_DEVICE_LENOVO(0x6004) }, { } -- cgit v1.2.3-18-g5258 From a85442ade272121927a56e02f7dfde1127482df2 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Tue, 4 Sep 2012 20:27:38 -0700 Subject: Input: tegra - move platform data header Move the Tegra KBC platform data header out of arch/arm/mach-tegra, as a pre-requisite of single zImage. Signed-off-by: Stephen Warren Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tegra-kbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c index 4ffe64d5310..c7ae23ead57 100644 --- a/drivers/input/keyboard/tegra-kbc.c +++ b/drivers/input/keyboard/tegra-kbc.c @@ -29,8 +29,8 @@ #include #include #include +#include #include -#include #define KBC_MAX_DEBOUNCE_CNT 0x3ffu -- cgit v1.2.3-18-g5258 From 9e14f36bb577bd2828db5797303ca7bf6c87d50a Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 4 Sep 2012 23:10:50 -0700 Subject: Input: omap-keypad - fixed formatting Fixed spacing error on if statements and fixed tab error. Signed-off-by: Josh Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/omap-keypad.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c index a0222db4dc8..b03c5b95486 100644 --- a/drivers/input/keyboard/omap-keypad.c +++ b/drivers/input/keyboard/omap-keypad.c @@ -214,7 +214,7 @@ static void omap_kp_tasklet(unsigned long data) memcpy(keypad_state, new_state, sizeof(keypad_state)); if (key_down) { - int delay = HZ / 20; + int delay = HZ / 20; /* some key is pressed - keep irq disabled and use timer * to poll the keypad */ if (spurious) @@ -413,7 +413,7 @@ static int __devinit omap_kp_probe(struct platform_device *pdev) } return 0; err5: - for (i = irq_idx - 1; i >=0; i--) + for (i = irq_idx - 1; i >= 0; i--) free_irq(row_gpios[i], omap_kp); err4: input_unregister_device(omap_kp->input); @@ -421,10 +421,10 @@ err4: err3: device_remove_file(&pdev->dev, &dev_attr_enable); err2: - for (i = row_idx - 1; i >=0; i--) + for (i = row_idx - 1; i >= 0; i--) gpio_free(row_gpios[i]); err1: - for (i = col_idx - 1; i >=0; i--) + for (i = col_idx - 1; i >= 0; i--) gpio_free(col_gpios[i]); kfree(omap_kp); -- cgit v1.2.3-18-g5258 From 8757145af0cc7d51dc4d491c9a2248ece50b9932 Mon Sep 17 00:00:00 2001 From: Alexandre Pereira da Silva Date: Wed, 12 Sep 2012 21:49:26 -0700 Subject: Input: gpio_keys_polled - fix dt pdata->nbuttons pdata->nbuttons should be updated by the dt code. Signed-off-by: Alexandre Pereira da Silva Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys_polled.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/input') diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 79089520621..f2142de789e 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -129,6 +129,7 @@ gpio_keys_polled_get_devtree_pdata(struct device *dev) } pdata->buttons = (struct gpio_keys_button *)(pdata + 1); + pdata->nbuttons = nbuttons; pdata->rep = !!of_get_property(node, "autorepeat", NULL); of_property_read_u32(node, "poll-interval", &pdata->poll_interval); -- cgit v1.2.3-18-g5258 From fb4f552e895cec29934d94a99cbd1f1f00448a88 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 12 Sep 2012 21:49:26 -0700 Subject: Input: hgpk - use %*ph to dump small buffer Signed-off-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/hgpk.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c index 575f880727f..62be888e83d 100644 --- a/drivers/input/mouse/hgpk.c +++ b/drivers/input/mouse/hgpk.c @@ -334,11 +334,8 @@ static bool hgpk_is_byte_valid(struct psmouse *psmouse, unsigned char *packet) if (!valid) psmouse_dbg(psmouse, - "bad data, mode %d (%d) %02x %02x %02x %02x %02x %02x\n", - priv->mode, pktcnt, - psmouse->packet[0], psmouse->packet[1], - psmouse->packet[2], psmouse->packet[3], - psmouse->packet[4], psmouse->packet[5]); + "bad data, mode %d (%d) %*ph\n", + priv->mode, pktcnt, 6, psmouse->packet); return valid; } @@ -1030,7 +1027,7 @@ static enum hgpk_model_t hgpk_get_model(struct psmouse *psmouse) return -EIO; } - psmouse_dbg(psmouse, "ID: %02x %02x %02x\n", param[0], param[1], param[2]); + psmouse_dbg(psmouse, "ID: %*ph\n", 3, param); /* HGPK signature: 0x67, 0x00, 0x */ if (param[0] != 0x67 || param[1] != 0x00) -- cgit v1.2.3-18-g5258 From 824efd37415961d38821ecbd9694e213fb2e8b32 Mon Sep 17 00:00:00 2001 From: Seth Forshee Date: Fri, 28 Sep 2012 10:29:21 -0700 Subject: Input: synaptics - adjust threshold for treating position values as negative Commit c039450 (Input: synaptics - handle out of bounds values from the hardware) caused any hardware reported values over 7167 to be treated as a wrapped-around negative value. It turns out that some firmware uses the value 8176 to indicate a finger near the edge of the touchpad whose actual position cannot be determined. This value now gets treated as negative, which can cause pointer jumps and broken edge scrolling on these machines. I only know of one touchpad which reports negative values, and this hardware never reports any value lower than -8 (i.e. 8184). Moving the threshold for treating a value as negative up to 8176 should work fine then for any hardware we currently know about, and since we're dealing with unspecified behavior it's probably the best we can do. The special 8176 value is also likely to result in sudden jumps in position, so let's also clamp this to the maximum specified value for the axis. BugLink: http://bugs.launchpad.net/bugs/1046512 https://bugzilla.kernel.org/show_bug.cgi?id=46371 Cc: stable@vger.kernel.org Signed-off-by: Seth Forshee Reviewed-by: Daniel Kurtz Tested-by: Alan Swanson Tested-by: Arteom Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/synaptics.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index 14eaecea2b7..0786919c15c 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -53,14 +53,19 @@ #define ABS_POS_BITS 13 /* - * Any position values from the hardware above the following limits are - * treated as "wrapped around negative" values that have been truncated to - * the 13-bit reporting range of the hardware. These are just reasonable - * guesses and can be adjusted if hardware is found that operates outside - * of these parameters. + * These values should represent the absolute maximum value that will + * be reported for a positive position value. Some Synaptics firmware + * uses this value to indicate a finger near the edge of the touchpad + * whose precise position cannot be determined. + * + * At least one touchpad is known to report positions in excess of this + * value which are actually negative values truncated to the 13-bit + * reporting range. These values have never been observed to be lower + * than 8184 (i.e. -8), so we treat all values greater than 8176 as + * negative and any other value as positive. */ -#define X_MAX_POSITIVE (((1 << ABS_POS_BITS) + XMAX) / 2) -#define Y_MAX_POSITIVE (((1 << ABS_POS_BITS) + YMAX) / 2) +#define X_MAX_POSITIVE 8176 +#define Y_MAX_POSITIVE 8176 /***************************************************************************** * Stuff we need even when we do not want native Synaptics support @@ -604,11 +609,21 @@ static int synaptics_parse_hw_state(const unsigned char buf[], hw->right = (buf[0] & 0x02) ? 1 : 0; } - /* Convert wrap-around values to negative */ + /* + * Convert wrap-around values to negative. (X|Y)_MAX_POSITIVE + * is used by some firmware to indicate a finger at the edge of + * the touchpad whose precise position cannot be determined, so + * convert these values to the maximum axis value. + */ if (hw->x > X_MAX_POSITIVE) hw->x -= 1 << ABS_POS_BITS; + else if (hw->x == X_MAX_POSITIVE) + hw->x = XMAX; + if (hw->y > Y_MAX_POSITIVE) hw->y -= 1 << ABS_POS_BITS; + else if (hw->y == Y_MAX_POSITIVE) + hw->y = YMAX; return 0; } -- cgit v1.2.3-18-g5258 From 5e056ef4ddeb6129f6bb170f2c26b8f370bbcda7 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 24 Sep 2012 09:21:31 -0700 Subject: Input: wacom - mark Intuos5 pad as in-prox when touching buttons If the ExpressKeys on the Intuos5 are touched, they currently result an out-of-prox packet being sent even if the pad is already out of prox. This can cause some confusion in the X driver. To restore the expected semantics, we make being touched a sufficient condition to signal proximity. https://bugs.freedesktop.org/show_bug.cgi?id=54250 Reported-by: Timo Aaltonen Signed-off-by: Jason Gerecke Reviewed-by: Chris Bagwell Signed-off-by: Dmitry Torokhov --- drivers/input/tablet/wacom_wac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/input') diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c index 532d067a9e0..93171098abb 100644 --- a/drivers/input/tablet/wacom_wac.c +++ b/drivers/input/tablet/wacom_wac.c @@ -606,7 +606,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) input_report_abs(input, ABS_WHEEL, 0); } - if (data[2] | (data[3] & 0x01) | data[4]) { + if (data[2] | (data[3] & 0x01) | data[4] | data[5]) { input_report_key(input, wacom->tool[1], 1); input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); } else { -- cgit v1.2.3-18-g5258