From patchwork Tue Nov 12 15:31:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 21466 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f71.google.com (mail-vb0-f71.google.com [209.85.212.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 306C323FBB for ; Tue, 12 Nov 2013 15:31:12 +0000 (UTC) Received: by mail-vb0-f71.google.com with SMTP id i3sf10037142vbh.6 for ; Tue, 12 Nov 2013 07:31:11 -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=botp+Y7qCKrjhog/U7Tuv4KsyWkGhzUs+UyQyrnrrwg=; b=g6PwDf/k2ELzRmWrGMZVjbDcILzXV9NGsRc+JUN9fe40IAdLEPz/blUImRceNz9R/G ohrzTzUVNnDGKBsC3/fUQjnqPp8UqCMLZ0A41DIhQ7FHHQV09wnv9qWq87FlRuiCjhCJ UszU16rFUzltJqASWYAPdWAm4ZwA2Qg4JQeBhNda82zYOZWYn2naeQwBA2pKz27KPAGO E+F4H3f47pBhja/erhksZRkPklUBC/NM3i+CrApgDfq8aniy8/PwR2/l+hPuUK06ZFsN udMCIz/g1cqVvTEhC0YrxAnHLwD4tvGDO72C6p+pG3R2VzeyBN1o9cVOb7z+HIkOYowu /D4Q== X-Gm-Message-State: ALoCoQlxH7RyUMCFaIa4VMrrpcTYmj3ihvbVicdsRdPjaT30N+yaomMsVU6cCIK3nzwRhpZDIyHX X-Received: by 10.52.108.166 with SMTP id hl6mr16257214vdb.0.1384270271615; Tue, 12 Nov 2013 07:31:11 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.110.5 with SMTP id hw5ls117704qeb.56.gmail; Tue, 12 Nov 2013 07:31:11 -0800 (PST) X-Received: by 10.58.232.228 with SMTP id tr4mr806984vec.34.1384270271513; Tue, 12 Nov 2013 07:31:11 -0800 (PST) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id ud10si12197115vcb.141.2013.11.12.07.31.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Nov 2013 07:31:11 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.179 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.179; Received: by mail-ve0-f179.google.com with SMTP id oz11so3343912veb.38 for ; Tue, 12 Nov 2013 07:31:11 -0800 (PST) X-Received: by 10.220.75.73 with SMTP id x9mr346526vcj.38.1384270271424; Tue, 12 Nov 2013 07:31:11 -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 u4csp170788vcz; Tue, 12 Nov 2013 07:31:10 -0800 (PST) X-Received: by 10.194.241.228 with SMTP id wl4mr27607579wjc.2.1384270270419; Tue, 12 Nov 2013 07:31:10 -0800 (PST) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by mx.google.com with ESMTPS id gm6si7936971wib.47.2013.11.12.07.31.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Nov 2013 07:31:10 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.174 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=209.85.212.174; Received: by mail-wi0-f174.google.com with SMTP id cb5so3849186wib.7 for ; Tue, 12 Nov 2013 07:31:09 -0800 (PST) X-Received: by 10.180.39.205 with SMTP id r13mr16665854wik.55.1384270268330; Tue, 12 Nov 2013 07:31:08 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id c10sm45775543wie.11.2013.11.12.07.31.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Nov 2013 07:31:07 -0800 (PST) From: Linus Walleij To: devicetree@vger.kernel.org, Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Rutland , Linus Walleij Subject: [PATCH 4/5 v3] input: tc3589x-keypad: support probing from device tree Date: Tue, 12 Nov 2013 16:31:01 +0100 Message-Id: <1384270261-15889-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.3.1 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.179 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);