From patchwork Wed Apr 9 07:28:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 3952931 Return-Path: X-Original-To: patchwork-linux-input@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 35DED9F38C for ; Wed, 9 Apr 2014 07:28:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E49D2044C for ; Wed, 9 Apr 2014 07:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C6FA20204 for ; Wed, 9 Apr 2014 07:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932733AbaDIH2T (ORCPT ); Wed, 9 Apr 2014 03:28:19 -0400 Received: from mail-we0-f180.google.com ([74.125.82.180]:60577 "EHLO mail-we0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932729AbaDIH2R (ORCPT ); Wed, 9 Apr 2014 03:28:17 -0400 Received: by mail-we0-f180.google.com with SMTP id p61so1999947wes.25 for ; Wed, 09 Apr 2014 00:28:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=s5SHLIQTddHaQW5DSbdxQPuQRtXHgOx0Qceao1oflMQ=; b=Ez408huL+aIIJseET+maBsHxtNaGjvE/hGySk7f8hBTDGJr0H6MyUZ+61fyEadUBsD LOo9FbxKQyn0+vSP4hIntcLTRzFcWk5+conayJ8IsRbDhf4oBa9j/+5J1fTHmoP2I97d zBDNu4lHDjkCkMNNbNgYfoj96YnvlMstBHfmj0n3pPrGYwLwa/QRj34QHcHZsZ42KeeB kpaykULAx5Fj9gNJzdjVdXUlnW6SYECAUH95FGNqczoLcw7w8tAKsQkcNk1oEMef7Dhy R83dHgmXJ6LSbwFy9POK6TRDnA/McbNL84Uqx/NGnb8eE5FfTvT/gqkvH4PiiWLKWEzT Xjzw== X-Gm-Message-State: ALoCoQnDfPpQX/KgspoEIF26l+YDS4xkGVg0sY4RN2ej4jZC9CySPCPno0MEoZEBs53dXOEjLtcE X-Received: by 10.180.160.166 with SMTP id xl6mr8495475wib.42.1397028496074; Wed, 09 Apr 2014 00:28:16 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id l12sm258656wjr.35.2014.04.09.00.28.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Apr 2014 00:28:15 -0700 (PDT) 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: [RESEND: PATCH 2/2] input: tc3589x-keypad: support probing from device tree Date: Wed, 9 Apr 2014 09:28:11 +0200 Message-Id: <1397028491-15462-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 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 74494a357522..ad7abae69078 100644 --- a/drivers/input/keyboard/tc3589x-keypad.c +++ b/drivers/input/keyboard/tc3589x-keypad.c @@ -296,6 +296,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); @@ -306,8 +365,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);