From patchwork Sun Jun 17 14:18:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9370 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B2C4F23E55 for ; Sun, 17 Jun 2012 14:18:23 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5DBC2A18054 for ; Sun, 17 Jun 2012 14:18:23 +0000 (UTC) Received: by mail-ob0-f180.google.com with SMTP id un3so7892186obb.11 for ; Sun, 17 Jun 2012 07:18:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:mime-version:content-type :x-gm-message-state; bh=e10tKT7Y+NM88Jkr7D/f9/Ubk+8tfvqhChEcEqIjNfA=; b=izMr6+pnUnaVeD3LiiaRhXOpbd+ueCn+YAe+50lAg6a3iHNF/Qr8HaA/cy3ZzLCeBD 2QCyFxVBClLkbXudH/iRI7glP84FAzhMzghMYkmB/xIVUtBmNQRFqoBtz97t2kbVqZV/ njlzwo259aaooFGUsfm5gLLHzyAUDYgO0Gz7H9OGHCF/HMvbsy46icJHkG8UUZtGOyh1 jIlqetNXNg2CkArguSgGkqMEJhm0C3Oj5KqVKL78WarxNYfa1+ojjopmFIO2DJcL4aXl 4bBhT1UJvesPVZ0CmO8Cp2P9UTElBG30hlNCeRwcDh087N2Hh4pUAS/Tm3oii+dKBpxY 1Tpg== Received: by 10.50.193.196 with SMTP id hq4mr6144231igc.57.1339942702599; Sun, 17 Jun 2012 07:18:22 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp23827ibb; Sun, 17 Jun 2012 07:18:21 -0700 (PDT) Received: by 10.14.100.193 with SMTP id z41mr2780811eef.112.1339942701075; Sun, 17 Jun 2012 07:18:21 -0700 (PDT) Received: from eu1sys200aog102.obsmtp.com (eu1sys200aog102.obsmtp.com. [207.126.144.113]) by mx.google.com with SMTP id v8si7127577eem.12.2012.06.17.07.18.18 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jun 2012 07:18:21 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.113 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.113; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.113 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob102.postini.com ([207.126.147.11]) with SMTP ID DSNKT93nKouy2Gf+SV55ZdVtK5fgYvUrLaEW@postini.com; Sun, 17 Jun 2012 14:18:20 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id A0F7840; Sun, 17 Jun 2012 14:17:46 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 5AEFB48; Sun, 17 Jun 2012 11:26:00 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id E509824C07D; Sun, 17 Jun 2012 16:17:59 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Sun, 17 Jun 2012 16:18:07 +0200 From: Linus Walleij To: Dmitry Torokhov Cc: , Naveen Kumar Gaddipati , Naga Radesh Y , Linus Walleij Subject: [PATCH 4/4] input/nomadik-ske: cleanup of probe and some more code style Date: Sun, 17 Jun 2012 16:18:05 +0200 Message-ID: <1339942685-20194-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.9.2 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm0BS4fWB5C7Lar61i16er9n6eNgRpdUNIOGFVRNJCI2tPKCCbmjUVWuBalmllMzg3TjWBZ From: Naveen Kumar Gaddipati This fixes some kerneldoc, and clean up the probe function so we split it in two parts: first allocate all resources and then start the clock and begin initializing the hardware. We exit quickly with negative error if the probe is unsucessful when getting resources. We add a pointer to the device's struct device to be used for dev_* prints and similar. Signed-off-by: Naveen Kumar Gaddipati Signed-off-by: Naga Radesh Y Signed-off-by: Linus Walleij --- drivers/input/keyboard/nomadik-ske-keypad.c | 152 +++++++++++++++------------ 1 file changed, 83 insertions(+), 69 deletions(-) diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c index ca802fe..a2f2479 100644 --- a/drivers/input/keyboard/nomadik-ske-keypad.c +++ b/drivers/input/keyboard/nomadik-ske-keypad.c @@ -53,14 +53,17 @@ /** * struct ske_keypad - data structure used by keypad driver - * @irq: irq no - * @reg_base: ske regsiters base address - * @input: pointer to input device object - * @board: keypad platform device - * @keymap: matrix scan code table for keycodes - * @clk: clock structure pointer + * @dev: Pointer to the structure device + * @irq: irq no + * @reg_base: ske regsiters base address + * @input: pointer to input device object + * @board: keypad platform device + * @keymap: matrix scan code table for keycodes + * @clk: clock structure pointer + * @ske_keypad_lock: lock used while writting into registers */ struct ske_keypad { + struct device *dev; int irq; void __iomem *reg_base; struct input_dev *input; @@ -85,9 +88,9 @@ static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr, spin_unlock(&keypad->ske_keypad_lock); } -/* - * ske_keypad_chip_init: init keypad controller configuration - * +/** + * ske_keypad_chip_init() - init keypad controller configuration + * @keypad: pointer to device structure * Enable Multi key press detection, auto scan mode */ static int __init ske_keypad_chip_init(struct ske_keypad *keypad) @@ -225,6 +228,9 @@ static int __init ske_keypad_probe(struct platform_device *pdev) struct ske_keypad *keypad; struct input_dev *input; struct resource *res; + struct clk *clk; + void __iomem *reg_base; + int ret = 0; int irq; int error; @@ -242,40 +248,42 @@ static int __init ske_keypad_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "missing platform resources\n"); - return -EINVAL; + return -ENXIO; } - keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL); - input = input_allocate_device(); - if (!keypad || !input) { - dev_err(&pdev->dev, "failed to allocate keypad memory\n"); - error = -ENOMEM; - goto err_free_mem; + res = request_mem_region(res->start, resource_size(res), pdev->name); + if (!res) { + dev_err(&pdev->dev, "failed to request I/O memory\n"); + return -EBUSY; } - keypad->irq = irq; - keypad->board = plat; - keypad->input = input; - spin_lock_init(&keypad->ske_keypad_lock); + reg_base = ioremap(res->start, resource_size(res)); + if (!reg_base) { + dev_err(&pdev->dev, "failed to remap I/O memory\n"); + ret = -ENXIO; + goto out_freerequest_memregions; + } - if (!request_mem_region(res->start, resource_size(res), pdev->name)) { - dev_err(&pdev->dev, "failed to request I/O memory\n"); - error = -EBUSY; - goto err_free_mem; + clk = clk_get(&pdev->dev, NULL); + if (IS_ERR(clk)) { + dev_err(&pdev->dev, "failed to clk_get\n"); + ret = PTR_ERR(clk); + goto out_freeioremap; } - keypad->reg_base = ioremap(res->start, resource_size(res)); - if (!keypad->reg_base) { - dev_err(&pdev->dev, "failed to remap I/O memory\n"); - error = -ENXIO; - goto err_free_mem_region; + /* resources are sane; we begin allocation */ + keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL); + if (!keypad) { + dev_err(&pdev->dev, "failed to allocate keypad memory\n"); + goto out_freeclk; } + keypad->dev = &pdev->dev; - keypad->clk = clk_get(&pdev->dev, NULL); - if (IS_ERR(keypad->clk)) { - dev_err(&pdev->dev, "failed to get clk\n"); - error = PTR_ERR(keypad->clk); - goto err_iounmap; + input = input_allocate_device(); + if (!input) { + dev_err(&pdev->dev, "failed to input_allocate_device\n"); + ret = -ENOMEM; + goto out_freekeypad; } input->id.bustype = BUS_HOST; @@ -287,37 +295,43 @@ static int __init ske_keypad_probe(struct platform_device *pdev) keypad->keymap, input); if (error) { dev_err(&pdev->dev, "Failed to build keymap\n"); - goto err_iounmap; + goto out_freekeypad; } input_set_capability(input, EV_MSC, MSC_SCAN); + input_set_drvdata(input, keypad); + + __set_bit(EV_KEY, input->evbit); if (!plat->no_autorepeat) __set_bit(EV_REP, input->evbit); - clk_enable(keypad->clk); + ret = input_register_device(input); + if (ret) { + dev_err(&pdev->dev, + "unable to register input device: %d\n", ret); + goto out_freeinput; + } - /* go through board initialization helpers */ - if (keypad->board->init) - keypad->board->init(); + keypad->irq = irq; + keypad->board = plat; + keypad->input = input; + keypad->reg_base = reg_base; + keypad->clk = clk; - error = ske_keypad_chip_init(keypad); - if (error) { - dev_err(&pdev->dev, "unable to init keypad hardware\n"); - goto err_clk_disable; - } + /* allocations are sane, we begin HW initialization */ + clk_enable(keypad->clk); - error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq, - IRQF_ONESHOT, "ske-keypad", keypad); - if (error) { - dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq); - goto err_clk_disable; + if (keypad->board->init && keypad->board->init() < 0) { + dev_err(&pdev->dev, "keyboard init config failed\n"); + ret = -EINVAL; + goto out_unregisterinput; } - error = input_register_device(input); - if (error) { - dev_err(&pdev->dev, - "unable to register input device: %d\n", error); - goto err_free_irq; + ret = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq, + IRQF_ONESHOT, "ske-keypad", keypad); + if (ret) { + dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq); + goto out_unregisterinput; } if (plat->wakeup_enable) @@ -327,19 +341,21 @@ static int __init ske_keypad_probe(struct platform_device *pdev) return 0; -err_free_irq: - free_irq(keypad->irq, keypad); -err_clk_disable: +out_unregisterinput: + input_unregister_device(input); + input = NULL; clk_disable(keypad->clk); - clk_put(keypad->clk); -err_iounmap: - iounmap(keypad->reg_base); -err_free_mem_region: - release_mem_region(res->start, resource_size(res)); -err_free_mem: +out_freeinput: input_free_device(input); +out_freekeypad: kfree(keypad); - return error; +out_freeclk: + clk_put(clk); +out_freeioremap: + iounmap(reg_base); +out_freerequest_memregions: + release_mem_region(res->start, resource_size(res)); + return ret; } static int __devexit ske_keypad_remove(struct platform_device *pdev) @@ -347,8 +363,6 @@ static int __devexit ske_keypad_remove(struct platform_device *pdev) struct ske_keypad *keypad = platform_get_drvdata(pdev); struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - free_irq(keypad->irq, keypad); - input_unregister_device(keypad->input); clk_disable(keypad->clk); @@ -356,7 +370,7 @@ static int __devexit ske_keypad_remove(struct platform_device *pdev) if (keypad->board->exit) keypad->board->exit(); - + free_irq(keypad->irq, keypad); iounmap(keypad->reg_base); release_mem_region(res->start, resource_size(res)); kfree(keypad); @@ -374,7 +388,7 @@ static int ske_keypad_suspend(struct device *dev) if (device_may_wakeup(dev)) enable_irq_wake(irq); else { - disable_irq(keypad->irq); + disable_irq(irq); ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); clk_disable(keypad->clk); } @@ -392,7 +406,7 @@ static int ske_keypad_resume(struct device *dev) disable_irq_wake(irq); else { clk_enable(keypad->clk); - enable_irq(keypad->irq); + enable_irq(irq); ske_keypad_chip_init(keypad); }