From patchwork Wed Dec 16 07:51:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 344503 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp164128ejs; Tue, 15 Dec 2020 23:53:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQvmO9yzUdKz37woKhz9i+UzPuVotbeHIxH65m4wvtcAgk0DwRfD0GcqaZAfI/XCemOm05 X-Received: by 2002:a17:906:eb5b:: with SMTP id mc27mr7909190ejb.163.1608105204091; Tue, 15 Dec 2020 23:53:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608105204; cv=none; d=google.com; s=arc-20160816; b=P9UHXnNAas3z8eZBPW4aH4VQZAU4BU19C/FFwHpPkbswXun7Hz9GgTs9pykg7sXaYE zm53ifHaX/yBOSi7/PlY17dD3ij5DXS/wxdKHV8WVQPt/DwshXmjo9YIRjs3GaNrzZMq ZI0HcvJQqlAsqbVZGRd4cZFjFJtjmgVGPSYsk+4DdsU0gFjDmRUQAXu3k+LRrl31wK0i 4D4+EgHndNHFfkilTrwtq+/QJLChAY9ys1pc9aNoTMlVB7haJQ8P69yxL/v8/6Q6NfWz ZWpxL4+TR4Wv/a0232PKPf+M4UKw2He11yYH3Xng+/7qbbJOGUyMrk/H6n5JRCfh/cdl nxjg== 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=pHBtryC0Ld+lVOexE/L2KV+9JDID/+FVmOF7eZus5jw=; b=UMZfq1T1Z+jl5OZj2OXrBpSE4JiiECVzvLt1Ngb1MXD6aLxs/XSuxsYwJ0sR2fH211 kB4csFdSUBYzqUzPFU29PnMOjyXTaRb2px0OtxnDisbl3UlnJxb40z1l9Viz2pw3DU84 1QdsLlYioJOBCw7kUzx92PWY22ar3NHitRKJBX2p2u4pI9HaLCbBWN4QbIYUYjbb0sKX zXzQJZE9g6e+Mt+UypNeJWAjmf5yMoajtMfB/eVLfMN+TTh62mcF9fWaR+dBIVahQ6LA R03heLy7wxBy8Cu0c5qrs7QsjSszpX4a/GRrd6AtrKE1sQcYn3WUEHuS90C0yWpGAm3Q MDZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tgcuAUXq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id c3si2158850eds.266.2020.12.15.23.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 23:53:24 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tgcuAUXq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 8095D82A78; Wed, 16 Dec 2020 08:52:36 +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="tgcuAUXq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EEA5682A6E; Wed, 16 Dec 2020 08:52:28 +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 mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 74FF182A50 for ; Wed, 16 Dec 2020 08:52:23 +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 eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20201216075213euoutp014e750751e57c0dae4a79353d93520877~RIxk0RUZP2594025940euoutp01j for ; Wed, 16 Dec 2020 07:52:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20201216075213euoutp014e750751e57c0dae4a79353d93520877~RIxk0RUZP2594025940euoutp01j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1608105133; bh=pHBtryC0Ld+lVOexE/L2KV+9JDID/+FVmOF7eZus5jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tgcuAUXqksGxWPtK0S5j9bKu8cjVrJ6bykVrBu18lMhYGzjmzLdtCCrXC++CjFkOv S6hJ6deHk0mV1+nB3p4cUADOzwtx/43lU3BxyST2uOe9PINdNWFC3jmAWIQDkMbLQE GdhtrXcFPz3vL41ocn9zVN1F3NCw1jEx6c6taR3E= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201216075206eucas1p2a6c762f8cb2a16e8a8b476933a053f98~RIxezWdmb1128511285eucas1p2K; Wed, 16 Dec 2020 07:52:06 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 3A.BB.44805.6ACB9DF5; Wed, 16 Dec 2020 07:52:06 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20201216075206eucas1p18bb5415110b6f1dfcbf96728061d7eb9~RIxeZlPJY0401404014eucas1p1F; Wed, 16 Dec 2020 07:52:06 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201216075206eusmtrp2b2c4171df69bbb79b920595e4f3a0c58~RIxeY5hr60040100401eusmtrp26; Wed, 16 Dec 2020 07:52:06 +0000 (GMT) X-AuditID: cbfec7f4-b37ff7000000af05-8e-5fd9bca68404 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 13.5A.16282.6ACB9DF5; Wed, 16 Dec 2020 07:52:06 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20201216075205eusmtip2c2bb935c9668ca17ac906511593cb619~RIxd5BDDz1788017880eusmtip28; Wed, 16 Dec 2020 07:52:05 +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 v3 5/6] button: add a simple ADC-based button driver Date: Wed, 16 Dec 2020 08:51:57 +0100 Message-Id: <20201216075158.16458-6-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216075158.16458-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSe0hTYRztu/e63Y0mtxn5zQxhmvbyWdSNciT5x80gQyLByLnyYpLO2DSz sG6Wr2m1FLXMVAyd+MyaY5VK6Zo9VyrlbFsPpAxrPmoVrYc5r9V/55zf+X3n8OPDUWGxmxee LE+nFXJZipjDx3TG76bAhq4RaYjzli/ZcaHdjTQ789zIsYkhhGw12Lhk79k9ZEGfL/lVqwNk idrJIe3dhVyyr2wKbOFTk+ZcLnWJGcCo6sp7GDU1HU/VFH5DqMdWPaDOapsA1dFwG92Jx/E3 J9IpyYdpRbAkgX/goeMnekgtPvLkRhvCgOGlKsDDIbEOfipvRlSAjwuJRgBfWyvcWOIAUG9q 5LDkM4CGx/XY35W345b5gQZA8+uu/ysNFj3X5eIQoVBlV3FceDERBgdz9JjLhBJWBKpKmbmn PIhImN/MoCqA4xixHKo/bnbJAiIc1j0yc9g0H9h89TbqwjxCAvt0zFxZSBhwaDt3BmVNkVD3 zoSw2AOO92u5LPaGMzdq5hdOAfjG1MplSTGAQzkXAOvaBK0mJ8fVAiVWwvabwawcAUdv1WAu GRLu0Gxf5JLRWViiq0BZWQAL8oSs2x9W9rf9i73zdHC+GgXvV01g7IHOA6h+dh1TA5/K/2G1 ADQBTzpDmZpEK8PkdGaQUpaqzJAnBe1PS70GZj/Mw9/9Dj3QjE8H9QIEB70A4qh4seCn3SwV ChJlWUdpRZpUkZFCK3vBUhwTewr2aVukQiJJlk4fpOlDtOLvFMF5XgxSYkuoDjiOvVthTMhS TVoT8soGjjVFmtdsc4xdwp4cfFDbbfSO4WbGeKX0/JKjqFeyGB/ZEP1DZCvSPCv3raqq68xP u+zUWrZf7hQPBpQwhpbdkskdm3jhW/rzQ0IX5YxUTUf8+FSTGqjVdk4xfnu/RB9rfuX+PNpo el/oeX6h8XvZVPze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leEhUhC5SDPga8/Z32Xvkg76IAWyY5tjlhTdp5PJIN2x+x+GUKqW+W fF0560c044layyN5wecLVec+XnVTwLG1a7to3ILivVoHmre0HLWes1JBUuBS8mwlluKMREMt 5qLiRACOAigv/wIAAA== X-CMS-MailID: 20201216075206eucas1p18bb5415110b6f1dfcbf96728061d7eb9 X-Msg-Generator: CA X-RootMTR: 20201216075206eucas1p18bb5415110b6f1dfcbf96728061d7eb9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201216075206eucas1p18bb5415110b6f1dfcbf96728061d7eb9 References: <20201216075158.16458-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 Analog to Digital Converter device 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..6db3c5e93a 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 Analog to Digital + Converter device. 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, +};