From patchwork Fri Feb 9 06:08:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 127765 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp302533ljc; Thu, 8 Feb 2018 22:09:05 -0800 (PST) X-Google-Smtp-Source: AH8x227jz+E2lLYkVhGtOUQbSfpJLKM2H4yb2wgSH3/jGv3yPvQh4hJuIhmyWHKu0Bt8P8JKWQJf X-Received: by 2002:a17:902:67:: with SMTP id 94-v6mr1495450pla.183.1518156545828; Thu, 08 Feb 2018 22:09:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518156545; cv=none; d=google.com; s=arc-20160816; b=iV/Qjhq6heJfWuHlL5CozMMfTKMv2vT9kaWwXHhA3uyEM8lKXEM12HiknrbgZ57QdP c46sl+7z7XAye92Rym+zzIsJdxXP5+PUw/gryxbJBJxbpqvbxMITf/EoCOJntwFiDBEI NydLNYbrUllHIQWwi/DOJRSF9D0pJ/gd/5dUcQqw2sJMHwZeJk1lMhGmkQwA827IA0qC NuWepmslQCA7O+p4KKapfwOoz3aZztdYfG6xbwsy0BI2dKDyrlhUpoeIpY8t2etDgDUx Bmr9O/R6JPF9UWJb9cX1EfrcIE7IIGCPCLm9yEsXEQWVBGfikPAcKFTugcylBnYhdbOP Ce0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=S+Kw6wbi4hrN+BFcrieck2XWoaHy/5G/pIk09tnqQvk=; b=h1+UCCaIAJE+0mHldut1C7xigmXAPtuzElW2ZGNUi+E1AyhAuiyYBiMTRB2D7dN4aA dbNInK7PS3pZCH+fVyGVao6uSn9eDkdjV/t+LFZqBG082Cn699L+X/hYBMHQwz6qifbe /ttt6cULDEFp7xHlaw+l5B+qWOPKLXiou/EunGxszlu3U7AMCzHJjBXpdGap3tl4AkBv ARD0u33muVWIgY79w7DHdeaCJGGesj6nvvOHdjx2+4071Bw8lrRiwcZWjdTuIn2sL1cH 2nsdv/6Vfqu+tuUSR9cvRK4T1HKDqkTAtvxTlGR+RL+RUv5PBSflvqzGmEoaaK/UZvGP UPQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WhEc8+uS; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 s196si962873pgc.650.2018.02.08.22.09.05; Thu, 08 Feb 2018 22:09:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=WhEc8+uS; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1750895AbeBIGJB (ORCPT + 6 others); Fri, 9 Feb 2018 01:09:01 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:40565 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750828AbeBIGI7 (ORCPT ); Fri, 9 Feb 2018 01:08:59 -0500 Received: by mail-pg0-f65.google.com with SMTP id g2so2968058pgn.7 for ; Thu, 08 Feb 2018 22:08:59 -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; bh=0Q3uPb8gySQcgsQtVQr2S/bAzu9nETicVrLVrKTSbf8=; b=WhEc8+uSGm1aegZ2Efr5F2dp8w4fgknn6B5KKl+uqsRMla+0RX3QghT/XnHGSpntqx 82+bDmTJjh1RM3cBCZ4UvgGNhmxgjeRVdRuBeptiJrtbxY81ZHMJM3YcjYYfLno1mNRC rD1ySu2j8+mFRQT3yzOoAT/67FYCHFFOyZQcw= 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; bh=0Q3uPb8gySQcgsQtVQr2S/bAzu9nETicVrLVrKTSbf8=; b=RVmBgp5S8HnPQttWOKOOZOkFmHL5lxLnv05Vhn2WTwamahuynXYgB8YHVRe+hPLQ7V q3LQ8ye0pSykGBz8HMJQsLvUmMDyFCJyXyx3tdjcwVAqUfbc8isJ7vfc67nYtYkHIinP 3WYb1YwEO2b4Fz0bdMK/qHTvsVax4NDhivfZMLpmYd5ekZ9lsxl+JOxTlB09rLRIrNbV ze5e0KVRL+iC+h3dborGueXfq3Aso/gfH0069qKfHjEICD0wdLaWggBPxvOQzOVBrtBk 9xir9n0YmU5kT+e7hK2Q8OokLs2YkdDOhnj86/Rdp6oroUrAOIu2drcTQk722WCF+HZe 29Ag== X-Gm-Message-State: APf1xPCdZotTdTV5+rBzJ5/CsFC8TDpW9do4NEGyx8fDbhJo6DH0/HpD VmniBQ6iqWNI1zMBTbxHUCOWdw== X-Received: by 10.99.97.7 with SMTP id v7mr1479053pgb.104.1518156539285; Thu, 08 Feb 2018 22:08:59 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t8sm3376800pgr.21.2018.02.08.22.08.55 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Feb 2018 22:08:58 -0800 (PST) From: Baolin Wang To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: gregkh@linuxfoundation.org, lumotuwe@gmail.com, arvind.yadav.cs@gmail.com, josephl@nvidia.com, kstewart@linuxfoundation.org, pombredanne@nexb.com, tglx@linutronix.de, linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, linus.walleij@linaro.org, baolin.wang@linaro.org Subject: [PATCH] Input: gpio_keys: Add level trigger support for GPIO keys Date: Fri, 9 Feb 2018 14:08:28 +0800 Message-Id: <6c53b9ccfd4a56fc1b00e243bb9e7cae9e124932.1518155780.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On some platforms (such as Spreadtrum platform), the GPIO keys can only be triggered by level type. So this patch introduces one property to indicate if the GPIO trigger type is level trigger or edge trigger. Signed-off-by: Baolin Wang --- .../devicetree/bindings/input/gpio-keys.txt | 2 ++ drivers/input/keyboard/gpio_keys.c | 22 +++++++++++++++++++- include/linux/gpio_keys.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" 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/Documentation/devicetree/bindings/input/gpio-keys.txt b/Documentation/devicetree/bindings/input/gpio-keys.txt index a949404..e3104bd 100644 --- a/Documentation/devicetree/bindings/input/gpio-keys.txt +++ b/Documentation/devicetree/bindings/input/gpio-keys.txt @@ -29,6 +29,8 @@ Optional subnode-properties: - linux,can-disable: Boolean, indicates that button is connected to dedicated (not shared) interrupt which can be disabled to suppress events from the button. + - gpio-key,level-trigger: Boolean, indicates that button's interrupt + type is level trigger. Otherwise it is edge trigger as default. Example nodes: diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 87e613d..d3b4bb6 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -385,6 +385,19 @@ static void gpio_keys_gpio_work_func(struct work_struct *work) struct gpio_button_data *bdata = container_of(work, struct gpio_button_data, work.work); + if (bdata->button->level_trigger) { + unsigned int trigger = + irq_get_trigger_type(bdata->irq) & ~IRQF_TRIGGER_MASK; + int state = gpiod_get_raw_value_cansleep(bdata->gpiod); + + if (state) + trigger |= IRQF_TRIGGER_LOW; + else + trigger |= IRQF_TRIGGER_HIGH; + + irq_set_irq_type(bdata->irq, trigger); + } + gpio_keys_gpio_report_event(bdata); if (bdata->button->wakeup) @@ -566,7 +579,11 @@ static int gpio_keys_setup_key(struct platform_device *pdev, INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func); isr = gpio_keys_gpio_isr; - irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; + if (button->level_trigger) + irqflags = gpiod_is_active_low(bdata->gpiod) ? + IRQF_TRIGGER_LOW : IRQF_TRIGGER_HIGH; + else + irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; } else { if (!button->irq) { @@ -721,6 +738,9 @@ static void gpio_keys_close(struct input_dev *input) button->can_disable = fwnode_property_read_bool(child, "linux,can-disable"); + button->level_trigger = + fwnode_property_read_bool(child, "gpio-key,level-trigger"); + if (fwnode_property_read_u32(child, "debounce-interval", &button->debounce_interval)) button->debounce_interval = 5; diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index d06bf77..5095645 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -28,6 +28,7 @@ struct gpio_keys_button { int wakeup; int debounce_interval; bool can_disable; + bool level_trigger; int value; unsigned int irq; };