diff options
Diffstat (limited to 'drivers/input/keyboard/omap-keypad.c')
| -rw-r--r-- | drivers/input/keyboard/omap-keypad.c | 89 |
1 files changed, 29 insertions, 60 deletions
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c index 146b26f665f6..9e13f3f70a81 100644 --- a/drivers/input/keyboard/omap-keypad.c +++ b/drivers/input/keyboard/omap-keypad.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * linux/drivers/input/keyboard/omap-keypad.c * @@ -8,20 +9,6 @@ * * Added support for H2 & H3 Keypad * Copyright (C) 2004 Texas Instruments - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/module.h> @@ -34,14 +21,14 @@ #include <linux/mutex.h> #include <linux/errno.h> #include <linux/slab.h> -#include <linux/gpio.h> #include <linux/platform_data/gpio-omap.h> #include <linux/platform_data/keypad-omap.h> +#include <linux/soc/ti/omap1-io.h> #undef NEW_BOARD_LEARNING_MODE static void omap_kp_tasklet(unsigned long); -static void omap_kp_timer(unsigned long); +static void omap_kp_timer(struct timer_list *); static unsigned char keypad_state[8]; static DEFINE_MUTEX(kp_enable_mutex); @@ -59,10 +46,7 @@ struct omap_kp { unsigned short keymap[]; }; -static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0); - -static unsigned int *row_gpios; -static unsigned int *col_gpios; +static DECLARE_TASKLET_DISABLED_OLD(kp_tasklet, omap_kp_tasklet); static irqreturn_t omap_kp_interrupt(int irq, void *dev_id) { @@ -74,7 +58,7 @@ static irqreturn_t omap_kp_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static void omap_kp_timer(unsigned long data) +static void omap_kp_timer(struct timer_list *unused) { tasklet_schedule(&kp_tasklet); } @@ -172,27 +156,33 @@ static ssize_t omap_kp_enable_store(struct device *dev, struct device_attribute if ((state != 1) && (state != 0)) return -EINVAL; - mutex_lock(&kp_enable_mutex); - if (state != kp_enable) { - if (state) - enable_irq(omap_kp->irq); - else - disable_irq(omap_kp->irq); - kp_enable = state; + scoped_guard(mutex, &kp_enable_mutex) { + if (state != kp_enable) { + if (state) + enable_irq(omap_kp->irq); + else + disable_irq(omap_kp->irq); + kp_enable = state; + } } - mutex_unlock(&kp_enable_mutex); return strnlen(buf, count); } static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, omap_kp_enable_show, omap_kp_enable_store); +static struct attribute *omap_kp_attrs[] = { + &dev_attr_enable.attr, + NULL +}; +ATTRIBUTE_GROUPS(omap_kp); + static int omap_kp_probe(struct platform_device *pdev) { struct omap_kp *omap_kp; struct input_dev *input_dev; struct omap_kp_platform_data *pdata = dev_get_platdata(&pdev->dev); - int i, col_idx, row_idx, ret; + int ret; unsigned int row_shift, keycodemax; if (!pdata->rows || !pdata->cols || !pdata->keymap_data) { @@ -203,8 +193,7 @@ static int omap_kp_probe(struct platform_device *pdev) row_shift = get_count_order(pdata->cols); keycodemax = pdata->rows << row_shift; - omap_kp = kzalloc(sizeof(struct omap_kp) + - keycodemax * sizeof(unsigned short), GFP_KERNEL); + omap_kp = kzalloc(struct_size(omap_kp, keymap, keycodemax), GFP_KERNEL); input_dev = input_allocate_device(); if (!omap_kp || !input_dev) { kfree(omap_kp); @@ -222,27 +211,15 @@ static int omap_kp_probe(struct platform_device *pdev) if (pdata->delay) omap_kp->delay = pdata->delay; - if (pdata->row_gpios && pdata->col_gpios) { - row_gpios = pdata->row_gpios; - col_gpios = pdata->col_gpios; - } - omap_kp->rows = pdata->rows; omap_kp->cols = pdata->cols; - col_idx = 0; - row_idx = 0; - - setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp); + timer_setup(&omap_kp->timer, omap_kp_timer, 0); /* get the irq and init timer*/ kp_tasklet.data = (unsigned long) omap_kp; tasklet_enable(&kp_tasklet); - ret = device_create_file(&pdev->dev, &dev_attr_enable); - if (ret < 0) - goto err2; - /* setup input device */ input_dev->name = "omap-keypad"; input_dev->phys = "omap-keypad/input0"; @@ -260,12 +237,12 @@ static int omap_kp_probe(struct platform_device *pdev) pdata->rows, pdata->cols, omap_kp->keymap, input_dev); if (ret < 0) - goto err3; + goto err2; ret = input_register_device(omap_kp->input); if (ret < 0) { printk(KERN_ERR "Unable to register omap-keypad input device\n"); - goto err3; + goto err2; } if (pdata->dbounce) @@ -277,30 +254,23 @@ static int omap_kp_probe(struct platform_device *pdev) if (omap_kp->irq >= 0) { if (request_irq(omap_kp->irq, omap_kp_interrupt, 0, "omap-keypad", omap_kp) < 0) - goto err4; + goto err3; } omap_writew(0, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); return 0; -err4: +err3: input_unregister_device(omap_kp->input); input_dev = NULL; -err3: - device_remove_file(&pdev->dev, &dev_attr_enable); err2: - for (i = row_idx - 1; i >= 0; i--) - gpio_free(row_gpios[i]); - for (i = col_idx - 1; i >= 0; i--) - gpio_free(col_gpios[i]); - kfree(omap_kp); input_free_device(input_dev); return -EINVAL; } -static int omap_kp_remove(struct platform_device *pdev) +static void omap_kp_remove(struct platform_device *pdev) { struct omap_kp *omap_kp = platform_get_drvdata(pdev); @@ -309,15 +279,13 @@ static int omap_kp_remove(struct platform_device *pdev) omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT); free_irq(omap_kp->irq, omap_kp); - del_timer_sync(&omap_kp->timer); + timer_shutdown_sync(&omap_kp->timer); tasklet_kill(&kp_tasklet); /* unregister everything */ input_unregister_device(omap_kp->input); kfree(omap_kp); - - return 0; } static struct platform_driver omap_kp_driver = { @@ -325,6 +293,7 @@ static struct platform_driver omap_kp_driver = { .remove = omap_kp_remove, .driver = { .name = "omap-keypad", + .dev_groups = omap_kp_groups, }, }; module_platform_driver(omap_kp_driver); |
