From patchwork Fri Nov 24 09:30:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 119560 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1952214qgn; Fri, 24 Nov 2017 01:30:53 -0800 (PST) X-Google-Smtp-Source: AGs4zMYe6alA/kcC8FvSfwyei2L52CydXf/u/jpkbr2f4epbSSsGroH32qZVW7Bxie/pzNqM9SAV X-Received: by 10.99.120.10 with SMTP id t10mr9097789pgc.393.1511515853814; Fri, 24 Nov 2017 01:30:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511515853; cv=none; d=google.com; s=arc-20160816; b=XI5eGOK21ueOywIv6oGFXEOXL4rgfRJ1KXATmX1cykEJCzEM4p8PdRc77TCAJmP/XL 0RvKed+3NSt12JLrL+LB6ICYXtK2y8Bo2CRTWNyke/iqtGxmh5jCPCdWXRZ9eJu2V7j7 jkKlp3LfFlPI/tsPD6p1pw3rPsuXMckAtafhC1sKx1rrft3Gu1UdQEcmvTIcI4I2DA4J 4/THGHsTHe4yQP1nDtuqS23GGMj2O9nKhNgc64j7u4tNQaCcVa4YAghZ+V1I1oJOkbLa 6KIUS7u+gL5F9CtlvqY+DDLXBu1R1cD1l9We517HjjPG7dEoByaSUB/jz5gw8+X6Mzhj MiGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=hTdQEwzkCHxZcvB5E1i3W0skU/iyhywyIghYvhYiYws=; b=AjeQ+0EwfiWH1gdIxAlSY9DBnRce2nn0KHz3+oYTcPxS+jChorL20auA1AzMbOntoK 9CdNew9FGCZUtLn+C5DTmlxkBOu3dHhnmgMi272w+pfPMnxclWl8ZLN7DdMp8eeNbt46 lGNOLHQh56cK9fgDwxN0KFaKUOWiKIFY+tviolfWVCKlO8ajXlIVMc3m4pzvKb6GLkmn UeDnMlJk1R9Nyg9UATk0jv5u2ukdmDTAjdHYPzgzvSxGHclc9/XuUGm/HTQE/OrNV22O w1NHTs2I9752Gay+0TklkLZGQs8mIqOWyRm2IjMYVjI0MW1AypeaiTeBKQxB7D3b81u5 pEsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZunHVpSi; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u86si19793425pfg.173.2017.11.24.01.30.53 for ; Fri, 24 Nov 2017 01:30:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZunHVpSi; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752322AbdKXJaw (ORCPT ); Fri, 24 Nov 2017 04:30:52 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36215 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752759AbdKXJav (ORCPT ); Fri, 24 Nov 2017 04:30:51 -0500 Received: by mail-lf0-f68.google.com with SMTP id k66so24748664lfg.3 for ; Fri, 24 Nov 2017 01:30:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xCnI7XSqOKfUZ6TJHPtNBJMofvgtA3o1rRrtGoZsc9M=; b=ZunHVpSiAKOLFDa9GqcYxaTfKN2CYeApcTUMm2gEmevT831ohYZbBxFKAjDNcFmIwR ohFigJQgytaMDkksOyqXPR/Kvy9DU0jrmlFP+x75ZgF133vx3GArPhzxM8gYoE/yikwi kn7H3ef9ERuzNlxfLdqUyGBZnLtEB8JFCbYBA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xCnI7XSqOKfUZ6TJHPtNBJMofvgtA3o1rRrtGoZsc9M=; b=axekf5ptFkPJiznQfncG7tvkjTNOp0n9Wydn/EaQw8YLeueCbXsMbNT6hHr6R4Ng45 ZHgfAevDChBUOqwM9YHv4uJqmJPdz/syKnfqnXNEKFEfxP877SdcMnGfjxzibsmPf2IW nH4/pok7vNQ1cvnYVVSWl7Ow/9GB+qYUd3pfjBgWe19vYjUDEhP8MZrWVzdrrGQB23mD CyVOQVlnB2X0OoAPTujBPvhmIK4y2/zLnGlx+hAMKuo24EMl3eRYnQ5SG6CxghTDgAlf WNINb88atv7badIlsVUKMOH+OXAPAsIkyo1hYTa2ZENpqKHSig7Q4TuiCEsEIPrxA/jM hwMw== X-Gm-Message-State: AJaThX52ZTRQbEBLpqxXtR5349ODIoQmWTnjBWRyr+NZBMXn+o6rmXVd Hx4wWo1paKADhmkF4ZufAXhYG5seN+Y= X-Received: by 10.46.27.131 with SMTP id c3mr9687238ljf.40.1511515850348; Fri, 24 Nov 2017 01:30:50 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 19sm4476608ljx.58.2017.11.24.01.30.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Nov 2017 01:30:49 -0800 (PST) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij Subject: [PATCH 1/5] Input: gpio-keys: Support getting descriptors from board Date: Fri, 24 Nov 2017 10:30:41 +0100 Message-Id: <20171124093045.5961-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171124093045.5961-1-linus.walleij@linaro.org> References: <20171124093045.5961-1-linus.walleij@linaro.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org There are any number of board files in the kernel providing keys/pushbuttons/switches using simple GPIO. In order to transfer these smoothly to use GPIO descriptors with descriptor tables in the board files and no static GPIO numbers, we need to accept that the board files provide named GPIOs associated with the GPIO chip device. Luckily gpio_keys of both polled and interrupt-enabled type will optionally pass a "desc" field which we can use as the name of the GPIO to look up and request a GPIO line for a certain key defined in a per-board descriptor lookup table. Signed-off-by: Linus Walleij --- drivers/input/keyboard/gpio_keys.c | 14 +++++++++++++- drivers/input/keyboard/gpio_keys_polled.c | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 87e613dc33b8..420262a4fd54 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -520,7 +520,9 @@ static int gpio_keys_setup_key(struct platform_device *pdev, } else if (gpio_is_valid(button->gpio)) { /* * Legacy GPIO number, so request the GPIO here and - * convert it to descriptor. + * convert it to descriptor. This code goes away once + * we convert all old board files to provide descriptor + * tables. */ unsigned flags = GPIOF_IN; @@ -537,6 +539,16 @@ static int gpio_keys_setup_key(struct platform_device *pdev, bdata->gpiod = gpio_to_desc(button->gpio); if (!bdata->gpiod) return -EINVAL; + } else { + /* + * Try to look up from the descriptor table, includes + * letting gpiolib handle inversion semantics. This is + * optional since we have interrupt-only keys as well. + */ + bdata->gpiod = devm_gpiod_get_optional(dev, desc, + GPIOD_IN); + if (IS_ERR(bdata->gpiod)) + return PTR_ERR(bdata->gpiod); } if (bdata->gpiod) { diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index edc7262103b9..1bc428a7edea 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -342,6 +342,16 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) button->gpio); return -EINVAL; } + } else { + /* + * Try to look up from the descriptor table, includes + * letting gpiolib handle inversion semantics. + */ + bdata->gpiod = devm_gpiod_get_optional(dev, + button->desc, + GPIOD_IN); + if (IS_ERR(bdata->gpiod)) + return PTR_ERR(bdata->gpiod); } bdata->last_state = -1;