From patchwork Wed Nov 14 13:47:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 12843 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 E19BC23E13 for ; Wed, 14 Nov 2012 13:47:56 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 95475A18F14 for ; Wed, 14 Nov 2012 13:47:56 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so561461iej.11 for ; Wed, 14 Nov 2012 05:47:56 -0800 (PST) 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:in-reply-to:references :x-gm-message-state; bh=ZFU8lN276jnh0X/oLB57Ske3bUjmuD0I6veDWI7WTuM=; b=P9J9/yigRJMfRtI1f9GKIkIhXYXKAWRrvNo0EeYK0riXfNXJlrOL81/JeHJePCZC5N cPsJNHPvQH/S4lOiPpk8dvsC2O0h+VQtJWLoY92n2rJUGBI6DjO9cEnUYp/Zob/UOF+V hKb/cO7M6d7Nimcgm2p+oEFrdffR6UkOQi2IvesDLgmWVf3Vdlz/YYx0b8O1YyPm0jqA 5w19/N7Ps1U3A9tMl5NOKRdsrlB585IpqNliDx5EbblCJFRqIjcFDq26Z0/oX+kGZZ9N pn1EMVJrqJ/qakOu3nmg6VHal9q6wfP+ecig4WPG14KHqx8HFNnYnZSTPr6ju87ZxkGV 7KuQ== Received: by 10.43.125.133 with SMTP id gs5mr6582790icc.54.1352900876366; Wed, 14 Nov 2012 05:47:56 -0800 (PST) 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.50.67.148 with SMTP id n20csp662911igt; Wed, 14 Nov 2012 05:47:55 -0800 (PST) Received: by 10.181.11.163 with SMTP id ej3mr26107753wid.11.1352900875198; Wed, 14 Nov 2012 05:47:55 -0800 (PST) Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com [74.125.82.46]) by mx.google.com with ESMTPS id i43si2330265wea.160.2012.11.14.05.47.54 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Nov 2012 05:47:55 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.46 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.46; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.46 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wg0-f46.google.com with SMTP id dt12so162604wgb.27 for ; Wed, 14 Nov 2012 05:47:54 -0800 (PST) Received: by 10.180.92.103 with SMTP id cl7mr26096625wib.16.1352900874384; Wed, 14 Nov 2012 05:47:54 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id b1sm2516537wix.11.2012.11.14.05.47.53 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Nov 2012 05:47:53 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: Lee Jones , Dmitry Torokhov , linux-input@vger.kernel.org Subject: [PATCH 4/5] Input: Enable STMPE keypad driver for Device Tree Date: Wed, 14 Nov 2012 13:47:16 +0000 Message-Id: <1352900837-20759-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352900837-20759-1-git-send-email-lee.jones@linaro.org> References: <1352900837-20759-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQn1RQunnGeUvqhhktVBrvf1vXkANW4JV035dXnxMqV2Pf4RRKu5dRaJ6U9OLmPjyaows+Za This patch allows the STMPE driver to be successfully probed and initialised when Device Tree support is enabled. Besides the usual platform data changes, we also separate the process of filling in the 'in use' pin bitmap, as we have to extract the information from Device Tree in the DT boot case. Cc: Dmitry Torokhov Cc: linux-input@vger.kernel.org Acked-by: Arnd Bergmann Acked-by: Linus Walleij Signed-off-by: Lee Jones --- drivers/input/keyboard/stmpe-keypad.c | 67 ++++++++++++++++++++++++++++----- drivers/mfd/stmpe.c | 1 + 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c index 470a877..4ae01d5 100644 --- a/drivers/input/keyboard/stmpe-keypad.c +++ b/drivers/input/keyboard/stmpe-keypad.c @@ -257,19 +257,73 @@ static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad) (plat->debounce_ms << 1)); } +static int stmpe_keypad_fill_used_pins(struct platform_device *pdev, + struct stmpe_keypad *keypad, + struct stmpe_keypad_platform_data *plat) +{ + struct device_node *np = pdev->dev.of_node; + unsigned int proplen; + const __be32 *prop; + int i; + + if (np) { + prop = of_get_property(np, "linux,keymap", &proplen); + if (!prop) { + dev_err(&pdev->dev, + "linux,keymap property not defined\n"); + return -EINVAL; + } + + for (i = 0; i < proplen / sizeof(u32); i++) { + unsigned int key = be32_to_cpup(prop + i); + + keypad->cols |= 1 << KEY_COL(key); + keypad->rows |= 1 << KEY_ROW(key); + } + } else { + for (i = 0; i < plat->keymap_data->keymap_size; i++) { + unsigned int key = plat->keymap_data->keymap[i]; + + keypad->cols |= 1 << KEY_COL(key); + keypad->rows |= 1 << KEY_ROW(key); + } + } + + return 0; +} + +static void __devinit stmpe_keypad_of_probe(struct device_node *np, + struct stmpe_keypad_platform_data *plat) +{ + of_property_read_u32(np, "debounce-interval", &plat->debounce_ms); + of_property_read_u32(np, "st,scan-count", &plat->scan_count); + + if (of_get_property(np, "st,no-autorepeat", NULL)) + plat->no_autorepeat = true; +} + static int __devinit stmpe_keypad_probe(struct platform_device *pdev) { struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); struct stmpe_keypad_platform_data *plat; + struct device_node *np = pdev->dev.of_node; struct stmpe_keypad *keypad; struct input_dev *input; int ret; int irq; - int i; plat = stmpe->pdata->keypad; - if (!plat) - return -ENODEV; + if (!plat) { + if (np) { + plat = devm_kzalloc(&pdev->dev, + sizeof(*plat), GFP_KERNEL); + if (!plat) + return -ENOMEM; + + stmpe_keypad_of_probe(np, plat); + } else + return -ENODEV; + } irq = platform_get_irq(pdev, 0); if (irq < 0) @@ -300,12 +354,7 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev) if (!plat->no_autorepeat) __set_bit(EV_REP, input->evbit); - for (i = 0; i < plat->keymap_data->keymap_size; i++) { - unsigned int key = plat->keymap_data->keymap[i]; - - keypad->cols |= 1 << KEY_COL(key); - keypad->rows |= 1 << KEY_ROW(key); - } + stmpe_keypad_fill_used_pins(pdev, keypad, plat); keypad->stmpe = stmpe; keypad->plat = plat; diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c index ba157d4..b03cc64 100644 --- a/drivers/mfd/stmpe.c +++ b/drivers/mfd/stmpe.c @@ -321,6 +321,7 @@ static struct resource stmpe_keypad_resources[] = { static struct mfd_cell stmpe_keypad_cell = { .name = "stmpe-keypad", + .of_compatible = "st,stmpe-keypad", .resources = stmpe_keypad_resources, .num_resources = ARRAY_SIZE(stmpe_keypad_resources), };