From patchwork Mon Dec 14 11:24:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 343491 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp2911987jai; Mon, 14 Dec 2020 03:26:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5XCf0navJuvYxgBDL6PucuNHnsiOdH93pgL9E2b6q5Z0Grc9dG4bc7MAdbYMg3bH/Z8b8 X-Received: by 2002:a17:906:b096:: with SMTP id x22mr882882ejy.471.1607945168650; Mon, 14 Dec 2020 03:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607945168; cv=none; d=google.com; s=arc-20160816; b=a7F62Fil2bNFNDAnuBQ2tFT+ouyQK4O6W4fFj/DbhFmBxsk6EFjuglj8Ka0kQeXZkY kJyRmVTdRLV9djj2mRxHq/Z+JgoLOOTqAEjLSQgg4UVJPyBTaiVhJcIQzPiyftvud5ns FsFqBUHGP06vsLjAjQPrqZFHrH+467ice1WHt3st6/uYB3EeluPwnQs7tOUHP9GC9MqB SYN/83UxBWLB0Fdm4UxcFG/Bsis0eZdokWPwuGQaY62zAsNW2B1dkmZLeDneb6WeQRjb 2aygg3jfFWTQq9B1lr9UIZrILnGbMWLgvls7YO0MLvewn76nU+FJMajtYNiOgYSPZvsd a7fw== 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=tt9bTK9Dr3R0toeu3fq55aabU8D9eXACSsnCgn5G89Y=; b=eed4AOhCOyUKBPmR6JHQ1WEZ13RFnQd1hwOAxGxPfuVif6NmukbJczk3oZeBCnq5nc Q3FBqCJAnxNzVDVts1Jsavsq5XEUMEYF0HugnqwN1wIggPGZAoch+O9CP6a5V5s2PvgI zP1ElR5mQ+9F4tEH6gUDMBZp9FYHmhE69dhRyOgfPnJsJ4OLzOCo7C5pC3TuvRs+t+qE uXVHvGrJHe/JPIDAj6Qbwm3Kp7453NnExUO9nBrpxIvK1a+oTSiLdXgK83FF4GkHBV9r muy8dK0YzzVMiLlkkDIyN3PFeAESN8qM3fBegJvdeg8Yzaq3kNq9z4bgFnpym0SHfm5n 3eJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=DP2vB5AQ; 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 o10si9148416ejg.80.2020.12.14.03.26.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 03:26:08 -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=DP2vB5AQ; 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 B55438283D; Mon, 14 Dec 2020 12:25:20 +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="DP2vB5AQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3276D82820; Mon, 14 Dec 2020 12:25:13 +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 242018280C for ; Mon, 14 Dec 2020 12:25: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 eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20201214112456euoutp01454358bdd71dac987067301f14c1446b~QkYvXi3EE0131301313euoutp01b for ; Mon, 14 Dec 2020 11:24:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20201214112456euoutp01454358bdd71dac987067301f14c1446b~QkYvXi3EE0131301313euoutp01b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1607945096; bh=tt9bTK9Dr3R0toeu3fq55aabU8D9eXACSsnCgn5G89Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DP2vB5AQ2D70ee9lclZ+5D9BB5FxFV5nfo639Jgm+VMK/zSsLCN6EY8nEx2pNpup0 wqWsNruQGitk4ERmc+PCPEvOCV0nWshbrgg0uArYjKE6/Qug87PbpxjCuFc0ktZ3jb Cd/cnS2dfiKKmjacK9nuI14tJy9wtE1oJpRMIzv8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20201214112451eucas1p1d652e1231c6f62614fdd02f9366612e7~QkYqfAkEc3050030500eucas1p1z; Mon, 14 Dec 2020 11:24:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 7B.C0.45488.38B47DF5; Mon, 14 Dec 2020 11:24:51 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20201214112450eucas1p18b98479811b98d883196c72b0f6deebd~QkYp9ZsRn3050430504eucas1p1o; Mon, 14 Dec 2020 11:24:50 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201214112450eusmtrp2cff93c101f4b8e8fddefadb59a45c070~QkYp8tYwP0874808748eusmtrp24; Mon, 14 Dec 2020 11:24:50 +0000 (GMT) X-AuditID: cbfec7f5-c5fff7000000b1b0-33-5fd74b83593c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AF.E8.16282.28B47DF5; Mon, 14 Dec 2020 11:24:50 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201214112450eusmtip1f84a10a77b6b4e9dc8fb2135891a3290~QkYpbGZGO1812918129eusmtip1c; Mon, 14 Dec 2020 11:24:50 +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 4/6] button: add a simple ADC-based button driver Date: Mon, 14 Dec 2020 12:24:35 +0100 Message-Id: <20201214112437.18757-5-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201214112437.18757-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmleLIzCtJLcpLzFFi42LZduznOd1m7+vxBv0PpSw2zljPanHjVxur xfN3l5ks1h65y25xqC/aouOwssW3LdsYLSZN+MVm8XZvJ7vF4akfGB24PN7faGX3mN1wkcVj 3qwTLB4fPsZ5zO/8zuRx9s4ORo++LasYPTYuO8AcwBHFZZOSmpNZllqkb5fAlfF31TSWgilK Fe/ebmNtYHwg3cXIySEhYCKxYMsrti5GLg4hgRWMEhO7m9ghnC+MEnvWHmGBcD4zStxY28gK 03Kr/QELiC0ksJxRovlmOFzHjUPNTCAJNgFDia63XWwgtoiAkcSlph1gk5gF7jBJdE1uAOsW FnCUuPd3A1gRi4CqxIXPd8BsXgFbiTtP57NAbJOXWL3hADOIzSlgJ7Fx7lqwYyUEjnBI7Oi/ ywZR5CKx/vABqPOEJV4d38IOYctI/N85nwmioZlR4uG5tewQTg+jxOWmGYwQVdYSd879AprE AXSfpsT6XfogpgTQdRNmFEKYfBI33gqCFDMDmZO2TWeGCPNKdLQJQcxQk5h1fB3c1oMXLjFD 2B4SLf87oEE6kVFi99WZ7BMY5Wch7FrAyLiKUTy1tDg3PbXYOC+1XK84Mbe4NC9dLzk/dxMj ML2c/nf86w7GFa8+6h1iZOJgPMQowcGsJML7u/5yvBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHe XVvXxAsJpCeWpGanphakFsFkmTg4pRqYFldG+farztuiHd3xqdSPiVeaoZ+D0UnSv33limdN Z+QF3Pg+/b4TuZjx0cOpAs/8TmXtzth+W//ykV2JM5z95h/hbVrmFbF4ldzNW/Mn2C038sr9 2frx0bHkvZ99li2cc0b3z6dDy86nyEj9jDnle6XNbKtnpei7h4e2vmyImJm08Oj2P5m6svN+ 77iSvP+oTTBvzfb6vNbEw6frBTrzoj59ORx18OwdA8OylR8Pm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d/b0bOcnATOEEuxtvL6ee27BXM9m ZG77xHaS9pQ59pm8b971h7btTe9eYVxm8Oh3iWd0n0TM9pcSv9qes15cJyldqXtViaU4I9FQ i7moOBEA979LTwADAAA= X-CMS-MailID: 20201214112450eucas1p18b98479811b98d883196c72b0f6deebd X-Msg-Generator: CA X-RootMTR: 20201214112450eucas1p18b98479811b98d883196c72b0f6deebd X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201214112450eucas1p18b98479811b98d883196c72b0f6deebd References: <20201214112437.18757-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 Change-Id: I6da7101eff3ce53766d899f49f5839d728d52fb3 --- 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 6b3ec7e55de..283367f2bd3 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 fcc10ebe8db..bbd18af1494 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 00000000000..086c676c02a --- /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, +};