From patchwork Wed Feb 13 13:43:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10809911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E12DA1390 for ; Wed, 13 Feb 2019 13:44:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD20021FAD for ; Wed, 13 Feb 2019 13:44:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0FA02852B; Wed, 13 Feb 2019 13:44:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3317821FAD for ; Wed, 13 Feb 2019 13:44:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391269AbfBMNoI (ORCPT ); Wed, 13 Feb 2019 08:44:08 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33809 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391250AbfBMNoF (ORCPT ); Wed, 13 Feb 2019 08:44:05 -0500 Received: by mail-wr1-f65.google.com with SMTP id f14so2577350wrg.1 for ; Wed, 13 Feb 2019 05:44:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+vwDcYDMNaEM9X+6Hq4e58zhVSF+acGNIMoeTvXQQHM=; b=WRJp4292P8ftHO1weosDSB+sYorAXl2Wgc6t1La/R9i/mCwbY7lpq8fB+fHpLCBAmc cvz4LaTaU8XqJQh5CLb0HxRsuAAd+mTr9+LjzDxnopjNFVP0gmTMdinyT72BN0HNzH3t uOivS/ubSiJh/JFsKGEt+22XiiqvjiPng0mbwnrr+ViT/5YN/fH9rwpKS2RSjtOVU74r oS+LYIb5WzWxzT8poowAkCewGaznU9NlXCu9RBTe/X7ZEd92lfRXDBu/CPxz1oHgk+hh zBRk9AEqjlQ2OnhyU4G6ZTsDVQtynqCJP86tCLfS3yCSpeKwGaq/h7oifueyZBITJn/6 PrNA== 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:mime-version:content-transfer-encoding; bh=+vwDcYDMNaEM9X+6Hq4e58zhVSF+acGNIMoeTvXQQHM=; b=S1qz/VnsSsQVzvatQ2397+XhCioImJsY71znCHO7KEUqnBZhwuJRe/CNpm6SmeLOUY Y8LA/Q3mGK0Jws3o/4H1QCFsKQFEvcp5g1RFtaM4ZP6XNE+XmTj5UOVL44Saacq0QtOb j1tHd/GI6abW1LaOng3oWzOkse1+S2V94awsUgeEhbQBQ4WRpEBoFh3jjlkauuKGDn4m ZhjAcp/iCA0+AlR0Kzgu2TlMogL36WEtOLVhdTQ+QvrDNVIZfgqzrz6RUDFfLyuC7VoB BK3MPl5bfB0Ey1LS88VASObxcHgfeNIOtQihq7DA8cmCNocr84uk8G4rwTYvmgxi4mOm mYHQ== X-Gm-Message-State: AHQUAuYrm8/zNJt7inwiHFTEZIoTcva4r8mrY++BOLC/OT1nazxQEtc0 ubfSlOB4X/0NAIHoV2Cy9j5CcA== X-Google-Smtp-Source: AHgI3Iadx6QBxMVtVKD+zy9LA9362p0pGm4eMszZ1/mlEjbEcVqguxZ0aW46jRwzS1KlifkNj7jBQw== X-Received: by 2002:adf:f8c1:: with SMTP id f1mr464254wrq.31.1550065443139; Wed, 13 Feb 2019 05:44:03 -0800 (PST) Received: from debian-brgl.home (amontpellier-652-1-54-116.w109-210.abo.wanadoo.fr. [109.210.45.116]) by smtp.gmail.com with ESMTPSA id e7sm2046720wrw.35.2019.02.13.05.44.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 05:44:02 -0800 (PST) From: Bartosz Golaszewski To: Rob Herring , Mark Rutland , Linus Walleij , Dmitry Torokhov , Jacek Anaszewski , Pavel Machek , Lee Jones , Sebastian Reichel , Liam Girdwood , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 10/11] input: max77650: add onkey support Date: Wed, 13 Feb 2019 14:43:34 +0100 Message-Id: <20190213134335.10838-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190213134335.10838-1-brgl@bgdev.pl> References: <20190213134335.10838-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bartosz Golaszewski Add support for the push- and slide-button events for max77650. Signed-off-by: Bartosz Golaszewski Acked-by: Dmitry Torokhov --- drivers/input/misc/Kconfig | 9 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max77650-onkey.c | 131 ++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/input/misc/max77650-onkey.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index ca59a2be9bc5..bb9c45c1269e 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -180,6 +180,15 @@ config INPUT_M68K_BEEP tristate "M68k Beeper support" depends on M68K +config INPUT_MAX77650_ONKEY + tristate "Maxim MAX77650 ONKEY support" + depends on MFD_MAX77650 + help + Support the ONKEY of the MAX77650 PMIC as an input device. + + To compile this driver as a module, choose M here: the module + will be called max77650-onkey. + config INPUT_MAX77693_HAPTIC tristate "MAXIM MAX77693/MAX77843 haptic controller support" depends on (MFD_MAX77693 || MFD_MAX77843) && PWM diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 9d0f9d1ff68f..5bd53590ce60 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -43,6 +43,7 @@ obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o +obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o diff --git a/drivers/input/misc/max77650-onkey.c b/drivers/input/misc/max77650-onkey.c new file mode 100644 index 000000000000..4605c18b37ca --- /dev/null +++ b/drivers/input/misc/max77650-onkey.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 BayLibre SAS +// Author: Bartosz Golaszewski +// +// ONKEY driver for MAXIM 77650/77651 charger/power-supply. + +#include +#include +#include +#include +#include +#include +#include + +#define MAX77650_ONKEY_MODE_MASK BIT(3) +#define MAX77650_ONKEY_MODE_PUSH 0x00 +#define MAX77650_ONKEY_MODE_SLIDE BIT(3) + +struct max77650_onkey { + struct input_dev *input; + unsigned int code; +}; + +static irqreturn_t max77650_onkey_falling(int irq, void *data) +{ + struct max77650_onkey *onkey = data; + + input_report_key(onkey->input, onkey->code, 0); + input_sync(onkey->input); + + return IRQ_HANDLED; +} + +static irqreturn_t max77650_onkey_rising(int irq, void *data) +{ + struct max77650_onkey *onkey = data; + + input_report_key(onkey->input, onkey->code, 1); + input_sync(onkey->input); + + return IRQ_HANDLED; +} + +static int max77650_onkey_probe(struct platform_device *pdev) +{ + int irq_r, irq_f, error, mode; + struct max77650_onkey *onkey; + struct device *dev, *parent; + const char *mode_prop; + struct regmap *map; + unsigned int type; + + dev = &pdev->dev; + parent = dev->parent; + + map = dev_get_regmap(parent, NULL); + if (!map) + return -ENODEV; + + onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL); + if (!onkey) + return -ENOMEM; + + error = device_property_read_u32(dev, "linux,code", &onkey->code); + if (error) + onkey->code = KEY_POWER; + + error = device_property_read_string(dev, + "maxim,onkey-mode", &mode_prop); + if (error) { + mode_prop = "push"; + type = EV_KEY; + } + + if (strcmp(mode_prop, "push") == 0) { + mode = MAX77650_ONKEY_MODE_PUSH; + type = EV_KEY; + } else if (strcmp(mode_prop, "slide") == 0) { + mode = MAX77650_ONKEY_MODE_SLIDE; + type = EV_SW; + } else { + return -EINVAL; + } + + error = regmap_update_bits(map, MAX77650_REG_CNFG_GLBL, + MAX77650_ONKEY_MODE_MASK, mode); + if (error) + return error; + + irq_f = platform_get_irq_byname(pdev, "nEN_F"); + if (irq_f < 0) + return irq_f; + + irq_r = platform_get_irq_byname(pdev, "nEN_R"); + if (irq_r < 0) + return irq_r; + + onkey->input = devm_input_allocate_device(dev); + if (!onkey->input) + return -ENOMEM; + + onkey->input->name = "max77650_onkey"; + onkey->input->phys = "max77650_onkey/input0"; + onkey->input->id.bustype = BUS_I2C; + input_set_capability(onkey->input, type, onkey->code); + + error = devm_request_any_context_irq(dev, irq_f, max77650_onkey_falling, + IRQF_ONESHOT, "onkey-down", onkey); + if (error < 0) + return error; + + error = devm_request_any_context_irq(dev, irq_r, max77650_onkey_rising, + IRQF_ONESHOT, "onkey-up", onkey); + if (error < 0) + return error; + + return input_register_device(onkey->input); +} + +static struct platform_driver max77650_onkey_driver = { + .driver = { + .name = "max77650-onkey", + }, + .probe = max77650_onkey_probe, +}; +module_platform_driver(max77650_onkey_driver); + +MODULE_DESCRIPTION("MAXIM 77650/77651 ONKEY driver"); +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_LICENSE("GPL v2");