From patchwork Sun May 13 12:44:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 8573 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 8CD9F23EAB for ; Sun, 13 May 2012 12:44:12 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 46AF1A187DD for ; Sun, 13 May 2012 12:44:12 +0000 (UTC) Received: by ggnf1 with SMTP id f1so2675271ggn.11 for ; Sun, 13 May 2012 05:44:11 -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=3jVfJBv/IIV9HZc0Vs9ZsednFfzhZbbuwqUYLSCX49Y=; b=Eo3QlE0TFYPhIs/jvsUTOiJHOH80sf0Ccts3tBrDeiGYdvUiw/HXgG0I5AB8Kcx3S2 N/n9PGygBeNurHj2x8xRxvkAuyl3vGyj6IP7PZFxUof0B2AzCZ1WnUdS7KMhywN7yBxg gqFuWIkQviELj6tAxDrpotc/T0jyzxjwe03rzcTPN0UN/csblNe+mVoQ2cbAPh38Fnsh GXTP+yAYFTTlAb1LDIsG+O4VRUpoqrk3Rpppr9B5IQS+Wb84q2aeF0lQo6rE1VJmk7oI HGgZliV04D+BBiz7OPBXN6tvAq9f15CCfmeqnadzAy/79P8PYsWaQY/XNcPPbCEEZXzr 0gqw== Received: by 10.42.122.76 with SMTP id m12mr2048337icr.38.1336913051637; Sun, 13 May 2012 05:44:11 -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.73.147 with SMTP id q19csp286729ibj; Sun, 13 May 2012 05:44:10 -0700 (PDT) Received: by 10.14.198.8 with SMTP id u8mr75031een.58.1336913050240; Sun, 13 May 2012 05:44:10 -0700 (PDT) Received: from eu1sys200aog105.obsmtp.com (eu1sys200aog105.obsmtp.com. [207.126.144.119]) by mx.google.com with SMTP id g41si4580969eea.128.2012.05.13.05.44.07 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 13 May 2012 05:44:10 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.119 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.119; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.119 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 eu1sys200aob105.postini.com ([207.126.147.11]) with SMTP ID DSNKT6+slo2YFY2mayIjKD3QqrQmw5qw96W1@postini.com; Sun, 13 May 2012 12:44:09 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 2333E48; Sun, 13 May 2012 12:43:48 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id A6EB048; Sun, 13 May 2012 10:19:07 +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 relay2.stm.gmessaging.net (Postfix) with ESMTPS id F04C0A807B; Sun, 13 May 2012 14:43:58 +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, 13 May 2012 14:44:03 +0200 From: Linus Walleij To: Dmitry Torokhov Cc: , Naveen Kumar Gaddipati , Naga Radesh Y , Linus Walleij Subject: [PATCH 4/7] input/nomadik-ske: cleanup of probe and some more code style Date: Sun, 13 May 2012 14:44:01 +0200 Message-ID: <1336913041-10117-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: ALoCoQnPCjm0v8RZcV3BOvE4f51mCdmdw9OCoXDRJKgslHK+TaZRIfZ3O1upyRD7JN8i/aasw5tH 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 | 149 ++++++++++++++------------- 1 file changed, 80 insertions(+), 69 deletions(-) diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c index 83b0424..c69a149 100644 --- a/drivers/input/keyboard/nomadik-ske-keypad.c +++ b/drivers/input/keyboard/nomadik-ske-keypad.c @@ -52,14 +52,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; @@ -84,9 +87,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 - * + * @keypad: pointer to device structure * Enable Multi key press detection, auto scan mode */ static int __init ske_keypad_chip_init(struct ske_keypad *keypad) @@ -224,8 +227,10 @@ 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; if (!plat) { dev_err(&pdev->dev, "invalid keypad platform data\n"); @@ -241,40 +246,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; @@ -286,38 +293,42 @@ static int __init ske_keypad_probe(struct platform_device *pdev) input->keycodemax = ARRAY_SIZE(keypad->keymap); 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); matrix_keypad_build_keymap(plat->keymap_data, SKE_KEYPAD_ROW_SHIFT, - input->keycode, input->keybit); + input->keycode, input->keybit); - 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 +338,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 +360,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 +367,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 +385,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 +403,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); }