From patchwork Thu Jan 23 12:43:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 23622 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AC754218CB for ; Thu, 23 Jan 2014 12:43:44 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id ii20sf2791327qab.9 for ; Thu, 23 Jan 2014 04:43:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=O8Fm6fCq7TajRylevqbAevmGlFU1UtKWk2r4Ih1QC5g=; b=bIgoWBF6RUWifroVGL32D8gnOAXViHdSbuxtWIzZh3yZm7ftSlZ9+IvcdG7MUC4aqn KZhLfeHoxSjZy+cLplV2BMRlGE42w3D2ZI5guBE5hiJPfUv5PmbWlx0Be/sZZJsf6zig ZUlLXWanclzSVX8tek8/eTAcXJ4/k1aTyLpx9xOZB/3pn0kfwsnD7ORpNWQo11cPMMrC HGZ6REV+1jXIEIzsajJIZvRaF5B+l0IpePxtNuOlH4Iz6t9hT2wjZqPI4jQk3rBIbcrF QkbcuMkcPFqbiWiJecZK0PWqLt3Q+TCwPupM+fHOYQpR9vx9pfjzOUoftTLxVPP3MpuZ 1gRg== X-Gm-Message-State: ALoCoQlm89C60DKou4XBF+kzGy9+IRipjha4d9hmEAnpZPvKpg20xvuewgeFC+HXwp1zH7yE97pS X-Received: by 10.59.11.65 with SMTP id eg1mr2736317ved.11.1390481023862; Thu, 23 Jan 2014 04:43:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.134 with SMTP id i6ls297166qge.2.gmail; Thu, 23 Jan 2014 04:43:43 -0800 (PST) X-Received: by 10.59.5.102 with SMTP id cl6mr14243ved.41.1390481023750; Thu, 23 Jan 2014 04:43:43 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id vi9si6591372vec.94.2014.01.23.04.43.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 04:43:43 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id oy12so1063467veb.37 for ; Thu, 23 Jan 2014 04:43:43 -0800 (PST) X-Received: by 10.58.37.67 with SMTP id w3mr4438384vej.22.1390481023634; Thu, 23 Jan 2014 04:43:43 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp23600vcz; Thu, 23 Jan 2014 04:43:43 -0800 (PST) X-Received: by 10.180.207.15 with SMTP id ls15mr6987522wic.50.1390481022605; Thu, 23 Jan 2014 04:43:42 -0800 (PST) Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48]) by mx.google.com with ESMTPS id cg6si9104969wib.28.2014.01.23.04.43.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 04:43:42 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.48 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=74.125.82.48; Received: by mail-wg0-f48.google.com with SMTP id x13so1415711wgg.27 for ; Thu, 23 Jan 2014 04:43:42 -0800 (PST) X-Received: by 10.194.133.135 with SMTP id pc7mr6387570wjb.51.1390481022176; Thu, 23 Jan 2014 04:43:42 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id f7sm22054008wjb.7.2014.01.23.04.43.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jan 2014 04:43:41 -0800 (PST) From: Linus Walleij To: devicetree@vger.kernel.org, Dmitry Torokhov , linux-input@vger.kernel.org, Samuel Ortiz , Lee Jones Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Rutland , Linus Walleij Subject: [PATCH 3/3 RESEND] input: tc3589x-keypad: support probing from device tree Date: Thu, 23 Jan 2014 13:43:36 +0100 Message-Id: <1390481016-23938-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.4.2 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implement device tree probing for the tc3589x keypad driver. This is modeled on the STMPE keypad driver and tested on the Ux500 TVK1281618 UIB. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Use two local u32 variables to avoid weirdness in u8 casting of the resulting values to the pointers. ChangeLog v1->v2: - Fix rows/columns binding to read two u32's insead of two u8 /bits/ as noted by Mark Rutland. --- drivers/input/keyboard/tc3589x-keypad.c | 66 ++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c index 208de7cbb7fa..7f36e7addb86 100644 --- a/drivers/input/keyboard/tc3589x-keypad.c +++ b/drivers/input/keyboard/tc3589x-keypad.c @@ -297,6 +297,65 @@ static void tc3589x_keypad_close(struct input_dev *input) tc3589x_keypad_disable(keypad); } +#ifdef CONFIG_OF +static const struct tc3589x_keypad_platform_data * +tc3589x_keypad_of_probe(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct tc3589x_keypad_platform_data *plat; + u32 cols, rows; + u32 debounce_ms; + int proplen; + + if (!np) + return ERR_PTR(-ENODEV); + + plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + if (!plat) + return ERR_PTR(-ENOMEM); + + of_property_read_u32(np, "keypad,num-columns", &cols); + of_property_read_u32(np, "keypad,num-rows", &rows); + plat->kcol = (u8) cols; + plat->krow = (u8) rows; + if (!plat->krow || !plat->kcol || + plat->krow > TC_KPD_ROWS || plat->kcol > TC_KPD_COLUMNS) { + dev_err(dev, + "keypad columns/rows not properly specified (%ux%u)\n", + plat->kcol, plat->krow); + return ERR_PTR(-EINVAL); + } + + if (!of_get_property(np, "linux,keymap", &proplen)) { + dev_err(dev, "property linux,keymap not found\n"); + return ERR_PTR(-ENOENT); + } + + plat->no_autorepeat = of_property_read_bool(np, "linux,no-autorepeat"); + plat->enable_wakeup = of_property_read_bool(np, "linux,wakeup"); + + /* The custom delay format is ms/16 */ + of_property_read_u32(np, "debounce-delay-ms", &debounce_ms); + if (debounce_ms) + plat->debounce_period = debounce_ms * 16; + else + plat->debounce_period = TC_KPD_DEBOUNCE_PERIOD; + + plat->settle_time = TC_KPD_SETTLE_TIME; + /* FIXME: should be property of the IRQ resource? */ + plat->irqtype = IRQF_TRIGGER_FALLING; + + return plat; +} +#else +static inline const struct tc3589x_keypad_platform_data * +tc3589x_keypad_of_probe(struct device *dev) +{ + return ERR_PTR(-ENODEV); +} +#endif + + static int tc3589x_keypad_probe(struct platform_device *pdev) { struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); @@ -307,8 +366,11 @@ static int tc3589x_keypad_probe(struct platform_device *pdev) plat = tc3589x->pdata->keypad; if (!plat) { - dev_err(&pdev->dev, "invalid keypad platform data\n"); - return -EINVAL; + plat = tc3589x_keypad_of_probe(&pdev->dev); + if (IS_ERR(plat)) { + dev_err(&pdev->dev, "invalid keypad platform data\n"); + return PTR_ERR(plat); + } } irq = platform_get_irq(pdev, 0);