From patchwork Tue Oct 28 00:01:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 5167491 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 305159F349 for ; Tue, 28 Oct 2014 00:06:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EDCBB201C8 for ; Tue, 28 Oct 2014 00:06:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CA4152017A for ; Tue, 28 Oct 2014 00:06:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XiuGi-0004po-El; Tue, 28 Oct 2014 00:04:12 +0000 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XiuFU-000498-Fh for linux-arm-kernel@lists.infradead.org; Tue, 28 Oct 2014 00:02:58 +0000 Received: by mail-wi0-f171.google.com with SMTP id hi2so4282905wib.10 for ; Mon, 27 Oct 2014 17:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ni/s16e3XrGQq2rlFBlUr9BJwMfFqNiOubdKfj3NvsQ=; b=zNfE9dYxwpl3oT8XNu2DRwmIGcjHjh0Ry6Yv2+lsxu4NUFPRbf+J3mcOgIe2v8/n2I /Cq2f6dh68dabgY2EUX3tG4UoSwAOZKERCnwiWtgPJILIlSQEqCej2wjGbX73zy+JYSa 7wIbCxdF3X665QPb53d+d9kEqDXLrFSIXD+B/IT42JZiu5bZmtYpYmlRFmeWxSAZVEZe k7R5kCubLoYWpgTPCQNm7VJCXMMJdah/nsiEgsfw74Y563wfZqAh9h1oUoSF6E0qWRRK va69RIW4kO6Zz4L3lUXTS0Gg8W218Bal0vn/iG+HMg7hJ80dhGrY1P79TaXsydxMZfVH ECdg== X-Received: by 10.180.82.7 with SMTP id e7mr527240wiy.27.1414454554095; Mon, 27 Oct 2014 17:02:34 -0700 (PDT) Received: from fangorn.rup.mentorg.com (nat-min.mentorg.com. [139.181.32.34]) by mx.google.com with ESMTPSA id fq1sm13495340wib.12.2014.10.27.17.02.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Oct 2014 17:02:33 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-spi@vger.kernel.org, linux-fbdev@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH 04/15] input: convert LoCoMo keyboard driver to use new locomo core Date: Tue, 28 Oct 2014 03:01:57 +0300 Message-Id: <1414454528-24240-5-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1414454528-24240-1-git-send-email-dbaryshkov@gmail.com> References: <1414454528-24240-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141027_170256_883297_BF7A5FB6 X-CRM114-Status: GOOD ( 22.44 ) X-Spam-Score: -0.8 (/) Cc: Alexandre Courbot , Bryan Wu , Russell King , Samuel Ortiz , Lee Jones , Linus Walleij , Dmitry Torokhov , Liam Girdwood , Haojian Zhuang , Mark Brown , Andrea Adami , Jingoo Han , Richard Purdie , Robert Jarzmik , Daniel Mack X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As LoCoMo is switching to new device model, adapt keyboard driver to support new locomo core driver. Signed-off-by: Dmitry Eremin-Solenikov --- drivers/input/keyboard/Kconfig | 1 - drivers/input/keyboard/locomokbd.c | 165 ++++++++++++++++++++----------------- 2 files changed, 91 insertions(+), 75 deletions(-) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index a3958c6..b660516 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -337,7 +337,6 @@ config KEYBOARD_LM8333 config KEYBOARD_LOCOMO tristate "LoCoMo Keyboard Support" - depends on SHARP_LOCOMO help Say Y here if you are running Linux on a Sharp Zaurus Collie or Poodle based PDA diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c index c94d610..c2fabf3 100644 --- a/drivers/input/keyboard/locomokbd.c +++ b/drivers/input/keyboard/locomokbd.c @@ -28,16 +28,10 @@ #include #include #include -#include +#include #include -#include - -#include -#include - -MODULE_AUTHOR("John Lenz "); -MODULE_DESCRIPTION("LoCoMo keyboard driver"); -MODULE_LICENSE("GPL"); +#include +#include #define LOCOMOKBD_NUMKEYS 128 @@ -75,7 +69,8 @@ struct locomokbd { struct input_dev *input; char phys[32]; - unsigned long base; + void __iomem *base; + int irq; spinlock_t lock; struct timer_list timer; @@ -84,37 +79,37 @@ struct locomokbd { }; /* helper functions for reading the keyboard matrix */ -static inline void locomokbd_charge_all(unsigned long membase) +static inline void locomokbd_charge_all(void __iomem *membase) { - locomo_writel(0x00FF, membase + LOCOMO_KSC); + writew(0x00FF, membase + LOCOMO_KSC); } -static inline void locomokbd_activate_all(unsigned long membase) +static inline void locomokbd_activate_all(void __iomem *membase) { unsigned long r; - locomo_writel(0, membase + LOCOMO_KSC); - r = locomo_readl(membase + LOCOMO_KIC); + writew(0, membase + LOCOMO_KSC); + r = readw(membase + LOCOMO_KIC); r &= 0xFEFF; - locomo_writel(r, membase + LOCOMO_KIC); + writew(r, membase + LOCOMO_KIC); } -static inline void locomokbd_activate_col(unsigned long membase, int col) +static inline void locomokbd_activate_col(void __iomem *membase, int col) { unsigned short nset; unsigned short nbset; nset = 0xFF & ~(1 << col); nbset = (nset << 8) + nset; - locomo_writel(nbset, membase + LOCOMO_KSC); + writew(nbset, membase + LOCOMO_KSC); } -static inline void locomokbd_reset_col(unsigned long membase, int col) +static inline void locomokbd_reset_col(void __iomem *membase, int col) { unsigned short nbset; nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF; - locomo_writel(nbset, membase + LOCOMO_KSC); + writew(nbset, membase + LOCOMO_KSC); } /* @@ -129,7 +124,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd) unsigned int row, col, rowd; unsigned long flags; unsigned int num_pressed; - unsigned long membase = locomokbd->base; + void __iomem *membase = locomokbd->base; spin_lock_irqsave(&locomokbd->lock, flags); @@ -141,7 +136,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd) locomokbd_activate_col(membase, col); udelay(KB_DELAY); - rowd = ~locomo_readl(membase + LOCOMO_KIB); + rowd = ~readw(membase + LOCOMO_KIB); for (row = 0; row < KB_ROWS; row++) { unsigned int scancode, pressed, key; @@ -194,11 +189,11 @@ static irqreturn_t locomokbd_interrupt(int irq, void *dev_id) struct locomokbd *locomokbd = dev_id; u16 r; - r = locomo_readl(locomokbd->base + LOCOMO_KIC); + r = readw(locomokbd->base + LOCOMO_KIC); if ((r & 0x0001) == 0) return IRQ_HANDLED; - locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */ + writew(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */ /** wait chattering delay **/ udelay(100); @@ -222,8 +217,8 @@ static int locomokbd_open(struct input_dev *dev) struct locomokbd *locomokbd = input_get_drvdata(dev); u16 r; - r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010; - locomo_writel(r, locomokbd->base + LOCOMO_KIC); + r = readw(locomokbd->base + LOCOMO_KIC) | 0x0010; + writew(r, locomokbd->base + LOCOMO_KIC); return 0; } @@ -232,35 +227,39 @@ static void locomokbd_close(struct input_dev *dev) struct locomokbd *locomokbd = input_get_drvdata(dev); u16 r; - r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010; - locomo_writel(r, locomokbd->base + LOCOMO_KIC); + r = readw(locomokbd->base + LOCOMO_KIC) & ~0x0010; + writew(r, locomokbd->base + LOCOMO_KIC); } -static int locomokbd_probe(struct locomo_dev *dev) +static int locomokbd_probe(struct platform_device *dev) { struct locomokbd *locomokbd; struct input_dev *input_dev; int i, err; + struct resource *res; + + locomokbd = devm_kzalloc(&dev->dev, sizeof(struct locomokbd), + GFP_KERNEL); + if (!locomokbd) + return -ENOMEM; - locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL); input_dev = input_allocate_device(); - if (!locomokbd || !input_dev) { - err = -ENOMEM; - goto err_free_mem; - } + if (!input_dev) + return -ENOMEM; - /* try and claim memory region */ - if (!request_mem_region((unsigned long) dev->mapbase, - dev->length, - LOCOMO_DRIVER_NAME(dev))) { - err = -EBUSY; - printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); - goto err_free_mem; - } + res = platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; - locomo_set_drvdata(dev, locomokbd); + locomokbd->irq = platform_get_irq(dev, 0); + if (locomokbd->irq < 0) + return -ENXIO; - locomokbd->base = (unsigned long) dev->mapbase; + platform_set_drvdata(dev, locomokbd); + + locomokbd->base = devm_ioremap_resource(&dev->dev, res); + if (IS_ERR(locomokbd->base)) + return PTR_ERR(locomokbd->base); spin_lock_init(&locomokbd->lock); @@ -296,11 +295,15 @@ static int locomokbd_probe(struct locomo_dev *dev) set_bit(locomokbd->keycode[i], input_dev->keybit); clear_bit(0, input_dev->keybit); + writew(0, locomokbd->base + LOCOMO_KEYBOARD + LOCOMO_KIC); + writew(0, locomokbd->base + LOCOMO_KEYBOARD + LOCOMO_KIC); + /* attempt to get the interrupt */ - err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); + err = request_irq(locomokbd->irq, locomokbd_interrupt, 0, + "locomokbd", locomokbd); if (err) { printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n"); - goto err_release_region; + goto err_free_mem; } err = input_register_device(locomokbd->input); @@ -309,54 +312,68 @@ static int locomokbd_probe(struct locomo_dev *dev) return 0; - err_free_irq: - free_irq(dev->irq[0], locomokbd); - err_release_region: - release_mem_region((unsigned long) dev->mapbase, dev->length); - locomo_set_drvdata(dev, NULL); - err_free_mem: +err_free_irq: + free_irq(locomokbd->irq, locomokbd); +err_free_mem: + platform_set_drvdata(dev, NULL); input_free_device(input_dev); - kfree(locomokbd); return err; } -static int locomokbd_remove(struct locomo_dev *dev) +static int locomokbd_remove(struct platform_device *dev) { - struct locomokbd *locomokbd = locomo_get_drvdata(dev); + struct locomokbd *locomokbd = platform_get_drvdata(dev); - free_irq(dev->irq[0], locomokbd); + free_irq(locomokbd->irq, locomokbd); del_timer_sync(&locomokbd->timer); input_unregister_device(locomokbd->input); - locomo_set_drvdata(dev, NULL); + platform_set_drvdata(dev, NULL); + + return 0; +} - release_mem_region((unsigned long) dev->mapbase, dev->length); +#ifdef CONFIG_PM_SLEEP +static int locomokbd_resume(struct device *dev) +{ + struct locomokbd *locomokbd = dev_get_drvdata(dev); + unsigned long flags; + u16 r; + + spin_lock_irqsave(&locomokbd->lock, flags); + + writew(0, locomokbd->base + LOCOMO_KSC); + r = readw(locomokbd->base + LOCOMO_KIC); + r &= 0xFEFF; + writew(r, locomokbd->base + LOCOMO_KIC); + writew(0x1, locomokbd->base + LOCOMO_KCMD); - kfree(locomokbd); + spin_unlock_irqrestore(&locomokbd->lock, flags); return 0; } -static struct locomo_driver keyboard_driver = { - .drv = { - .name = "locomokbd" +static SIMPLE_DEV_PM_OPS(locomo_kbd_pm, NULL, locomokbd_resume); +#define LOCOMO_KBD_PM (&locomo_kbd_pm) +#else +#define LOCOMO_KBD_PM NULL +#endif + +static struct platform_driver locomokbd_driver = { + .driver = { + .name = "locomo-kbd", + .owner = THIS_MODULE, + .pm = LOCOMO_KBD_PM, }, - .devid = LOCOMO_DEVID_KEYBOARD, .probe = locomokbd_probe, .remove = locomokbd_remove, }; -static int __init locomokbd_init(void) -{ - return locomo_driver_register(&keyboard_driver); -} - -static void __exit locomokbd_exit(void) -{ - locomo_driver_unregister(&keyboard_driver); -} +module_platform_driver(locomokbd_driver); -module_init(locomokbd_init); -module_exit(locomokbd_exit); +MODULE_AUTHOR("John Lenz "); +MODULE_DESCRIPTION("LoCoMo keyboard driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:locomo-kbd");