From patchwork Tue Dec 22 08:56:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 346621 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp5151287jai; Tue, 22 Dec 2020 00:57:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzeiS3VuPjsae6LSK16Izih7hJz649lNP8LDv3fGK0E61ncwFceFIxrx4ZZIJnUWGVpFkn X-Received: by 2002:a50:8b66:: with SMTP id l93mr19034754edl.384.1608627435185; Tue, 22 Dec 2020 00:57:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608627435; cv=none; d=google.com; s=arc-20160816; b=ycP90FRkEaA0NMji95Cd4fTzm3Cs38FyUAcVaFGGmpzh00naEt7WPdfFVJFkZ5qYGC qR99wMsil3HMYSM6T7egKLkCqmK5Yl/o6rtbHqtOn4MigP7q+7cLrvU8QlOkD9hSNXVH 6jDJsvES7p1vYWbHpG1pSvkDCF7QChUAFJS7CLHAbvwmwt0QMXgE6c2ETL0t2/VXw9Eq O39+15QHpD/kkgygdOk2nj67ZrfNidwctMPhEVCdzeu9GVCgimx4KdoFHoWrMFKVuqX4 wbPTg8oCpP93tEsEu6g5hpy8xfHXmjRVXAhpLt3yrusaOIwCrMW31FoUEkL9sUlEk/IE 7CyA== 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=lOS4um473VZDTxF5b1DiXy4UNgSyVQmYqFnigws4pAg=; b=U73dniE8n12JcQtaGovVrQHy2+QTCwV1FUCQSE9EZ7CpFmKUy5fzvzRWcUsSElK+yd newUr3u22xyDKEytacovb2WTyGUFIwZ5606wvDqpYWr2tqwiqNVQ0anJYpAg9+tO2uqw w5X33/Yxi5ZGQjOs5ZJk2C1EW/RF1Hy/p3Jg1lh/J34oRJbydacLMM2IWXEKWK45IsSX xG1dDbrcdwy1Ftcm2d1yfATmFcKr8gOe527VMcRKKLKw/z4bubOU2lrnOtnnXkC/mQ56 BYSdV/uu1k0qF1QBC13dRymM9edLnYmnH2rnQuZy7bvWzfHoRwtynWLTLooNzCLGCTj/ phaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=SooVQAtQ; 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 a15si12355483edb.360.2020.12.22.00.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 00:57:15 -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=SooVQAtQ; 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 B517582A38; Tue, 22 Dec 2020 09:56:55 +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="SooVQAtQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B2DB982A2C; Tue, 22 Dec 2020 09:56:49 +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 0626282A27 for ; Tue, 22 Dec 2020 09:56:41 +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 20201222085640euoutp029b587ac49c7a9ec07e0bc357b245bf5e~S-hj5w7910258702587euoutp02H for ; Tue, 22 Dec 2020 08:56:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201222085640euoutp029b587ac49c7a9ec07e0bc357b245bf5e~S-hj5w7910258702587euoutp02H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1608627400; bh=lOS4um473VZDTxF5b1DiXy4UNgSyVQmYqFnigws4pAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SooVQAtQ9SlXibOkPSrH20dI70yMYcneOHneKMhM59vufg/sPGHZwNbdYdbL5D0Bl aDzV34QrE0ebhOKiWJpDkdr9DcN4uwGssc6urqm+L9TeShoY315zhKm5UiD9h8M6U8 jHfnOZ3t7ulc4d6W/+3GmuHBlMyhv4vR9XN6HGG8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201222085639eucas1p2ddcf42bbf52a073e15caf3c55dbacc7b~S-hja6pa22518825188eucas1p2a; Tue, 22 Dec 2020 08:56:39 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 78.9A.45488.7C4B1EF5; Tue, 22 Dec 2020 08:56:39 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20201222085639eucas1p1db16b6bc2ae790ed711a09bcc5f176e5~S-hjFPxE_2035220352eucas1p1J; Tue, 22 Dec 2020 08:56:39 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201222085639eusmtrp215ebeaf160d33404a7a1523ba44235aa~S-hjEmaZu3114831148eusmtrp2G; Tue, 22 Dec 2020 08:56:39 +0000 (GMT) X-AuditID: cbfec7f5-c5fff7000000b1b0-c9-5fe1b4c7f7a2 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 66.8A.21957.7C4B1EF5; Tue, 22 Dec 2020 08:56:39 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201222085638eusmtip18d920fa2ab23ef8674c964a88747c5bb~S-himj_hy2659926599eusmtip18; Tue, 22 Dec 2020 08:56:38 +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 v4 2/3] button: add a simple Analog to Digital Converter device based button driver Date: Tue, 22 Dec 2020 09:56:32 +0100 Message-Id: <20201222085633.10194-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222085633.10194-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSZ0wTYRj2u7u2R7F41sEnapQqJtYIIoonIDiIucTEEX9YJzRyjAAVO1DU HxUVaSNYiwxBAUeAgFgghRSiAQuhIFoZDiwraAwIVoaIFhGlHOq/Z73f8+bNh6P8JJYLHiGR 01KJOErA5mIV9TbzepO+N2iD6ZYrWZqhY5HtEwkssu9LG0IW13VxSGPyUTKxdhU5rq8ApFYz wSatT1QcsjZ1GGznUkPtVzhUlrIFo7IzGzBqeOQElaP6jlAvOg2AStYXAqo0rwbdjx/h+oXQ URGxtNTDP5gbXlo0hsQ8W3VWmVzMUoLBZWrggENiEywdzOOoARfnEwUATlrKAEPGANQVDqEM +QrgaLkW/TvyuSyJzRj5AH7UvEb+jfTXdiD2FJvwhGqrmm3HC4mNsDXegNlDKNGJQHWKErMb Cwga/uo2zGCMcIPVF80zFTxiGzRcn2QzdStgUUnNjO5A+MPmmwMs+0OQqMFhXWMPiwkFwlzN Gw6DF8ABk34WL4O/K3MQZuASgL3mYg5DrgHYFp8BmJQv7DRPTNfh0/uthboqD0beARNstzh2 GRJOsN063y6j01BbkY4yMg8mJvCZ9BqYaXr0r/Zpc+vsuSioUdsw5kI3ACxJScA0YEXm/7Jc AAqBM62QRYfRMi8JfcZdJo6WKSRh7idPRZeB6R/TNGX6ZgAFAyPuRoDgwAggjgoW8rxdeoL4 vBBx3DlaeipIqoiiZUawFMcEzryq8odBfCJMLKcjaTqGlv51EdzBRYkIr+406Szrxy90Cc+H zp+rskz4Ue4ta9ccelDfc+dAeUrEsZqYzi7bu0gz3YJanQL4edqpnLslkQ2Pd7h1VHqVOz8N SK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M7pzT4tAUv4fhp07snVePtwyQOHRO55xtvyuw+VH+PQfC3jkYvh1D1xar9zbaSJn8Vbr3Y Idz+olQq4tSazksuh/s4eDi1H5Tz6zLtrGiYZXesdaqt0fVTb9/pG2SLuYbzLnTQKVb7FfyM octg8cFOnhBDhUdx4ovXWwebHerYUZUp+2LajuWb3tuvfaR35JARx7Lp/FKPI5VYijMSDbWY i4oTAbHxTKAAAwAA X-CMS-MailID: 20201222085639eucas1p1db16b6bc2ae790ed711a09bcc5f176e5 X-Msg-Generator: CA X-RootMTR: 20201222085639eucas1p1db16b6bc2ae790ed711a09bcc5f176e5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201222085639eucas1p1db16b6bc2ae790ed711a09bcc5f176e5 References: <20201222085633.10194-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 | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 130 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..bf99dd8b43 --- /dev/null +++ b/drivers/button/button-adc.c @@ -0,0 +1,121 @@ +// 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 + +/** + * struct button_adc_priv - private data for button-adc driver. + * + * @adc: Analog to Digital Converter device to which button is connected. + * @channel: channel of the ADC device to probe the button state. + */ +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_ofnode(UCLASS_ADC, 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, +};