From patchwork Tue Dec 15 14:42:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 344016 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp3975376jai; Tue, 15 Dec 2020 06:44:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwZ8Zz41CbmHkUtsnquvs2KYbCC6o3yoVuC7wmzco4szAwmES88DGv8hNnYvWV7rJwOeUG X-Received: by 2002:a50:9f4a:: with SMTP id b68mr29664017edf.296.1608043469195; Tue, 15 Dec 2020 06:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608043469; cv=none; d=google.com; s=arc-20160816; b=TLwKa0rvsBI/6/41TSrArbEX1fWdBvUwjbJGsQ9VoljpMRGXtmSYCv2Qaz1jvd7dwL Sly5SE9p/1HuwTrnv/vqqpUIlIWXcjhJQMeI2pwATXKdeG2HWoWaNKUo/PQaOBc4OldR o0xelWs6krh4rw3RtUnNYObcZlpQI5et0nqoY9n0wT5oxMM5ColM0btakR2aV/vMk6bT /y5Tk13UErVOeVZNkiP4+/wkCMSouJQ8s171q/dWBswV4MJB4MPVaxcBH9wpsv1d5ETh smwxGhPpBq0HuCH0/0k5n6ye+oFSz0rl5gWfM9Qwpp4xTz3WJmkVBsBo6lY8NVEjvdlq lWaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=0Xav+A+9dQCe2IQu9jP7gRV/iH3XCUGWANAZ0kxLTCI=; b=OjeGvX6+w1STtcJZ5uXs5xwxb0dFtaphCx0tyGO3supmtXPZUyGp1qoWHZCI924tg1 nT2oVsr3+dKqPkJUe8k7aMgjXW+U9e+p1ckpp3FX8/SZldI+nlOQeYPA9LNpIjYKKDrL 6TXSCWgnImTI0LMjCfo9aBv/MIXGyDPZCbgi+BgCFc2nKTOWOHEih57P7p9afSE59RLM s7G4TcfTfUdNpSl+ZzZCQaUxeWuSv94vXiVH9lkCO9WbcRMB5wVwLFfGkHpQbihfqyVc gtbc69y3vbeTAmPwapQF7m9Eao1+UZGUt8uwNU8Dtom1UYbIkYTJAq1hi+PqsI+6bmoh sm+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=hZXe+PSr; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id j13si963330edt.512.2020.12.15.06.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 06:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=hZXe+PSr; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 30A01829D5; Tue, 15 Dec 2020 15:43:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="hZXe+PSr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 89634829BB; Tue, 15 Dec 2020 15:43:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7BB51829A8 for ; Tue, 15 Dec 2020 15:43:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=m.szyprowski@samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20201215144250euoutp02165313b9a5d137f2d6736ae3b00d4f49~Q6uzpf1qR1439514395euoutp02Y for ; Tue, 15 Dec 2020 14:42:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201215144250euoutp02165313b9a5d137f2d6736ae3b00d4f49~Q6uzpf1qR1439514395euoutp02Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1608043370; bh=0Xav+A+9dQCe2IQu9jP7gRV/iH3XCUGWANAZ0kxLTCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hZXe+PSrM2Hb1NGD00NPbub5asu+wSRvzxz5mKnQaJ1KGEEhVm1y9gzIE76oXbbpR oD7JhXi44QWyUYlqhSFJTsCnjANjp7mHydavOAg675WxX5KMLkEFfLvp/kE51IN01I 5pm3zFBtFQWdPk5dDCVr4RpZPkhklxyR1GNj2t4M= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201215144244eucas1p2f5e3a8c465f0a6a720bc6f3462e41c55~Q6uumW1Az0232202322eucas1p28; Tue, 15 Dec 2020 14:42:44 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 32.51.44805.46BC8DF5; Tue, 15 Dec 2020 14:42:44 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20201215144244eucas1p12404d7047f032e03ebcad27b88f23a25~Q6uuR4auL0484804848eucas1p1X; Tue, 15 Dec 2020 14:42:44 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201215144244eusmtrp29dfc45cdf1bb5e2a2f56451282e785b8~Q6uuRNywI2514325143eusmtrp2e; Tue, 15 Dec 2020 14:42:44 +0000 (GMT) X-AuditID: cbfec7f4-b4fff7000000af05-06-5fd8cb649563 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 43.A0.21957.46BC8DF5; Tue, 15 Dec 2020 14:42:44 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20201215144243eusmtip2baa6727add6ead2fcc3cad65ec517268~Q6utxSJAI0137801378eusmtip2D; Tue, 15 Dec 2020 14:42:43 +0000 (GMT) From: Marek Szyprowski To: u-boot@lists.denx.de, u-boot-amlogic@groups.io Cc: Marek Szyprowski , Neil Armstrong , Lukasz Majewski , Philippe Reynes , Simon Glass , Heinrich Schuchardt , Jaehoon Chung , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 5/7] button: add a simple ADC-based button driver Date: Tue, 15 Dec 2020 15:42:28 +0100 Message-Id: <20201215144230.9235-6-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201215144230.9235-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphleLIzCtJLcpLzFFi42LZduzned2U0zfiDS6e07HYOGM9q8WNX22s Fs/fXWayWHvkLrvFob5oi47DyhbftmxjtJg04Rebxdu9newWh6d+YHTg8nh/o5XdY3bDRRaP ebNOsHh8+BjnMb/zO5PH2Ts7GD36tqxi9Ni47ABzAEcUl01Kak5mWWqRvl0CV8an/tcsBTcU Kz6e2M3SwLhcuouRk0NCwERiy5SrrCC2kMAKRomfTXJdjFxA9hdGiVttJ5khnM+MEkcun2GE 6di7biITRGI5o8TvY//Y4Fo2XWhnA6liEzCU6HrbBWaLCBhJXGrawQJSxCxwh0mia3IDC0hC WMBF4u7nC8wgNouAqsSnm7vZQWxeARuJ3X3n2SHWyUus3nAArIZTwFbiz8RV7CCDJAQOcEgs 3fINqshFYufXPawQtrDEq+NboOIyEv93zmeCaGhmlHh4bi1Udw+jxOWmGVAfWUvcOfcL6FYO oPs0Jdbv0ocIO0p8eNPACBKWEOCTuPFWECTMDGRO2jadGSLMK9HRJgRRrSYx6/g6uLUHL1xi hrA9JJq+HoeG4wRGiTOHH7JNYJSfhbBsASPjKkbx1NLi3PTUYqO81HK94sTc4tK8dL3k/NxN jMAEc/rf8S87GJe/+qh3iJGJg/EQowQHs5IIb2/p9Xgh3pTEyqrUovz4otKc1OJDjNIcLEri vElb1sQLCaQnlqRmp6YWpBbBZJk4OKUamMpKlh16bPW3+Mn0m39yu5v7RA9OZdO8v8HmVeGT lr6iaqddUgUpx768K7iv5d02wTJYWuNvSPDL865GL5M0377bPGd3Z/NB19c+G1zWrul1XW61 pIlDa5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Gqb wRz166DHXNdZ85pEXLZXzZffI17400nla1A0p9rrJRxuqg+z4/cc3uIYE6rmGF9Vma+a5eh+ 6xJHcjOP751EwTl7lzN+L3060cVbRsm9yOUhY4WyuVPd3DvRL/w/33SOT53+UpjhZ5r68U62 dJXcnRNtbWUWJGVvsfPeXp7ILGGyv3XjkZpVi6a7JrEqy/LJX3zHp3NqZ1+SEktxRqKhFnNR cSIAhMO8WAADAAA= X-CMS-MailID: 20201215144244eucas1p12404d7047f032e03ebcad27b88f23a25 X-Msg-Generator: CA X-RootMTR: 20201215144244eucas1p12404d7047f032e03ebcad27b88f23a25 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201215144244eucas1p12404d7047f032e03ebcad27b88f23a25 References: <20201215144230.9235-1-m.szyprowski@samsung.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Add a simple ADC-based button driver. This driver binds to the 'adc-keys' device tree node. Signed-off-by: Marek Szyprowski --- drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 117 ++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 drivers/button/button-adc.c -- 2.17.1 diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig index 6b3ec7e55d..283367f2bd 100644 --- a/drivers/button/Kconfig +++ b/drivers/button/Kconfig @@ -9,6 +9,14 @@ config BUTTON can provide access to board-specific buttons. Use of the device tree for configuration is encouraged. +config BUTTON_ADC + bool "Button adc" + depends on BUTTON + help + Enable support for buttons which are connected to ADC lines. The ADC + driver must use driver model. Buttons are configured using the device + tree. + config BUTTON_GPIO bool "Button gpio" depends on BUTTON diff --git a/drivers/button/Makefile b/drivers/button/Makefile index fcc10ebe8d..bbd18af149 100644 --- a/drivers/button/Makefile +++ b/drivers/button/Makefile @@ -3,4 +3,5 @@ # Copyright (C) 2020 Philippe Reynes obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_ADC) += button-adc.o obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o diff --git a/drivers/button/button-adc.c b/drivers/button/button-adc.c new file mode 100644 index 0000000000..086c676c02 --- /dev/null +++ b/drivers/button/button-adc.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * Author: Marek Szyprowski + */ + +#include +#include +#include +#include +#include +#include +#include + +struct button_adc_priv { + struct udevice *adc; + int channel; +}; + +static enum button_state_t button_adc_get_state(struct udevice *dev) +{ + struct button_adc_priv *priv = dev_get_priv(dev); + unsigned int val, mask; + int ret; + + ret = adc_start_channel(priv->adc, priv->channel); + if (ret) + return ret; + + ret = adc_channel_data(priv->adc, priv->channel, &val); + if (ret) + return ret; + + ret = adc_data_mask(priv->adc, &mask); + if (ret) + return ret; + + /* getting state is simplified a bit */ + if (ret == 0) + return (val < mask / 2) ? BUTTON_ON : BUTTON_OFF; + + return ret; +} + +static int button_adc_probe(struct udevice *dev) +{ + struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev); + struct button_adc_priv *priv = dev_get_priv(dev); + struct ofnode_phandle_args args; + int ret; + + /* Ignore the top-level button node */ + if (!uc_plat->label) + return 0; + + ret = dev_read_phandle_with_args(dev->parent, "io-channels", + "#io-channel-cells", 0, 0, &args); + if (ret) + return ret; + + ret = uclass_get_device_by_name(UCLASS_ADC, ofnode_get_name(args.node), + &priv->adc); + if (ret) + return ret; + + priv->channel = args.args[0]; + + return ret; +} + +static int button_adc_bind(struct udevice *parent) +{ + struct udevice *dev; + ofnode node; + int ret; + + dev_for_each_subnode(node, parent) { + struct button_uc_plat *uc_plat; + const char *label; + + label = ofnode_read_string(node, "label"); + if (!label) { + debug("%s: node %s has no label\n", __func__, + ofnode_get_name(node)); + return -EINVAL; + } + ret = device_bind_driver_to_node(parent, "button_adc", + ofnode_get_name(node), + node, &dev); + if (ret) + return ret; + uc_plat = dev_get_uclass_platdata(dev); + uc_plat->label = label; + } + + return 0; +} + +static const struct button_ops button_adc_ops = { + .get_state = button_adc_get_state, +}; + +static const struct udevice_id button_adc_ids[] = { + { .compatible = "adc-keys" }, + { } +}; + +U_BOOT_DRIVER(button_adc) = { + .name = "button_adc", + .id = UCLASS_BUTTON, + .of_match = button_adc_ids, + .ops = &button_adc_ops, + .priv_auto_alloc_size = sizeof(struct button_adc_priv), + .bind = button_adc_bind, + .probe = button_adc_probe, +};