From patchwork Tue Nov 12 09:13:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nandor Han X-Patchwork-Id: 1193378 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vaisala.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=vaisala.com header.i=@vaisala.com header.b="QPu0lFkj"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47C2Bf4Ftsz9sNH for ; Tue, 12 Nov 2019 20:14:50 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 1D7F7C21EBA; Tue, 12 Nov 2019 09:13:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2F328C21E74; Tue, 12 Nov 2019 09:13:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BD449C21CB1; Tue, 12 Nov 2019 09:13:24 +0000 (UTC) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40077.outbound.protection.outlook.com [40.107.4.77]) by lists.denx.de (Postfix) with ESMTPS id 633BBC21C8B for ; Tue, 12 Nov 2019 09:13:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kSNxPgjaNv0sp8idx5Fvlt6SXWgDqECkskJ4SB1Gto0i1xUG+/bXXUVUD93+eokCrAjbQMGEd4cp5+srlDyFLKg9uafHcb8MySLzo+a6LTW0uLKpDpbLihuxJeAk9BFDhSj3J/hqd0AA9s486tuys+uKlFjzYwrMW6KJrVhPosSs5pDldoUs/aBvLacQxKtx8amfxJtLN9y4cp8GpuHkwhJij3qSxEPjBgPWXyF6UXKx60jNOw8Wq8z3s/brcV0GcHYVVmlycxlINSl8ML+jIleQqo2ExnSzlbBzzOJyWBLEYHWV5mSkw1Bd6pCs0ofoKS3+jrSkqyweuZ5A4Qfo9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/23IqtYixeKutgDMq3MOEYkYOAyhsGbBuCc4imLRVLk=; b=ao41kj1As+T8cRZll0IHwgYKuFJ8uJbFeabCn2HmYHjIRs97vz0WpmaCYtqZzdpjnhErA1e9igCzgwVfKCNzwRjTon5frdeOYyJejh+5i+6ntR3+cscCHSmIn3m0HuZyAqej7bTONpFB8FAJLSdTDvTUyFLZjhBppzYHHKUmbhFzcSobP1KFzChKAiHiO3beGazS/GQzp+5tiqau75c9duYyPRUBoMy10q3YbL4yDatFLpN5dfiNFrXlY5X0QkaWKfKWa/U4JRzrUTqMhwP6WKewfTvZVJtB1sAdzc/BnhFv/hhfLIbID47f2L8L3iVOZ3LO6QfCXxRZZ4fhJjOgdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vaisala.com; dmarc=pass action=none header.from=vaisala.com; dkim=pass header.d=vaisala.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vaisala.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/23IqtYixeKutgDMq3MOEYkYOAyhsGbBuCc4imLRVLk=; b=QPu0lFkjSDSuBA52GRLYGHwGPL7kjzesiJhnmdLhLPMGwdZv/DTJ3u+t2qAdfjm3VZkcetmYhT3531mMSGYukd0PHOs0AzeZwhzSq0dpfZnSTUbCKdu3AqaiZvansaocVu9cxkBirXWjDFLqSjj2Mqb3NnOGAGhTDsGrEuOdNkU= Received: from AM6PR06MB6263.eurprd06.prod.outlook.com (20.179.247.144) by AM6PR06MB4182.eurprd06.prod.outlook.com (20.177.39.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.24; Tue, 12 Nov 2019 09:13:23 +0000 Received: from AM6PR06MB6263.eurprd06.prod.outlook.com ([fe80::b027:3f98:12c7:613a]) by AM6PR06MB6263.eurprd06.prod.outlook.com ([fe80::b027:3f98:12c7:613a%2]) with mapi id 15.20.2430.027; Tue, 12 Nov 2019 09:13:23 +0000 From: Han Nandor To: "u-boot@lists.denx.de" Thread-Topic: [PATCH 2/3] reboot-mode: read the boot mode from GPIOs status Thread-Index: AQHVmTlvl9T4DqTbHk+9vqyhtaZwkA== Date: Tue, 12 Nov 2019 09:13:23 +0000 Message-ID: <20191112091255.28149-3-nandor.han@vaisala.com> References: <20191112091255.28149-1-nandor.han@vaisala.com> In-Reply-To: <20191112091255.28149-1-nandor.han@vaisala.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MR2P264CA0116.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::32) To AM6PR06MB6263.eurprd06.prod.outlook.com (2603:10a6:20b:ff::16) authentication-results: spf=none (sender IP is ) smtp.mailfrom=nandor.han@vaisala.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [193.143.230.131] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1b88ddb4-d902-4eb5-0013-08d767509180 x-ms-traffictypediagnostic: AM6PR06MB4182: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-tenant-id: 6d7393e0-41f5-4c2e-9b12-4c2be5da5c57 x-ms-oob-tlc-oobclassifiers: OLM:3044; x-forefront-prvs: 021975AE46 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39850400004)(396003)(346002)(376002)(366004)(189003)(199004)(2906002)(36756003)(2616005)(76176011)(7736002)(14454004)(305945005)(5640700003)(6486002)(25786009)(486006)(81156014)(50226002)(8676002)(81166006)(86362001)(52116002)(476003)(446003)(11346002)(8936002)(4326008)(2351001)(386003)(316002)(66476007)(6916009)(6506007)(26005)(6512007)(1076003)(66446008)(66556008)(54906003)(66946007)(64756008)(99286004)(71190400001)(71200400001)(66066001)(6436002)(2501003)(6116002)(3846002)(478600001)(186003)(14444005)(5660300002)(102836004)(256004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR06MB4182; H:AM6PR06MB6263.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: vaisala.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: MRrsD1kV0gtWo0pE9Ypxl4c52jUaeUee9vvYP2IdEIEE4PECNF6HcdFQRAKLKaW3Q0pJxV+3vlRNKBnMKc8IAhv5JudP/xfIyAofPQ5lVECLar6ZCVPJOZYBKAwFAUhg+sHYpPucoHuxOVclTNwtYhR+doW3Y/ADGEe0wNZjHLm8UoRxiN1/oS+hGNYJiyJdbAO9Pvb3zK5Tz6nz+T+uEtlNy4IHz5PlUZwc7xL2WQmiQhTNIazSogs4IPjfBosCXzqk+p934X7gcnkIeDWRXSJ+hKzX8lIK3EiJFbOUZj31V2HPICy3JjlXtp3XpWL7S30qNssDXWHFwBgMGFVBcK1vhvTVwD6ty550QsODG8uqxpugyNZMjvuoVZe3aPRb/l24khCTTFWz5M7Dt172jULEYvphy5hOM9trWvOYasQI8SCqxp7qcTXPurjDlCHz MIME-Version: 1.0 X-OriginatorOrg: vaisala.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b88ddb4-d902-4eb5-0013-08d767509180 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Nov 2019 09:13:23.4372 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 6d7393e0-41f5-4c2e-9b12-4c2be5da5c57 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uaK2ng+dVrT2/ZOvpHRRomxTbvO6GH4I7bIkslO+BPFh3AA4YLe7RcbwYb21WPomgNk31LAd1wxJflrlahytIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR06MB4182 Cc: "trini@konsulko.com" Subject: [U-Boot] [PATCH 2/3] reboot-mode: read the boot mode from GPIOs status X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" A use case for controlling the boot mode is when the user wants to control the device boot by pushing a button without needing to go in user-space. Add a new backed for reboot mode where GPIOs are used to control the reboot-mode. The driver is able to scan a predefined list of GPIOs and return the magic value. Having the modes associated with the magic value generated based on the GPIO values, allows the reboot mode uclass to select the proper mode. Signed-off-by: Nandor Han --- .../reboot-mode/reboot-mode-gpio.txt | 20 +++ drivers/reboot-mode/Kconfig | 9 ++ drivers/reboot-mode/Makefile | 1 + drivers/reboot-mode/reboot-mode-gpio.c | 125 ++++++++++++++++++ include/reboot-mode/reboot-mode-gpio.h | 32 +++++ 5 files changed, 187 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt create mode 100644 drivers/reboot-mode/reboot-mode-gpio.c create mode 100644 include/reboot-mode/reboot-mode-gpio.h diff --git a/doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt b/doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt new file mode 100644 index 0000000000..bb209d2742 --- /dev/null +++ b/doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt @@ -0,0 +1,20 @@ +GPIO Reboot Mode Configuration + +Required Properties: +- compatible: must be "reboot-mode-gpio". +- gpios: list of gpios that are used to calculate the reboot-mode magic value. + Every gpio represents a bit in the magic value in the same order + as defined in device tree. +- modes: list of properties that define the modes and associated unique ids. + +Optional Properties: +- u-boot,env-variable: used to save the reboot mode (default: reboot-mode). + +Example: + reboot-mode { + compatible = "reboot-mode-gpio"; + gpios = <&gpio1 2 GPIO_ACTIVE_LOW>, <&gpio2 6 GPIO_ACTIVE_HIGH>; + u-boot,env-variable = "bootstatus"; + mode-test = <0x00000001>; + mode-download = <0x00000002>; + }; diff --git a/drivers/reboot-mode/Kconfig b/drivers/reboot-mode/Kconfig index 0edc3209d7..ff65e2031a 100644 --- a/drivers/reboot-mode/Kconfig +++ b/drivers/reboot-mode/Kconfig @@ -15,4 +15,13 @@ config DM_REBOOT_MODE adjust the boot process based on reboot mode parameter passed to U-Boot. +config DM_REBOOT_MODE_GPIO + bool "Use GPIOs as reboot mode backend" + depends on DM_REBOOT_MODE + default n + help + Use GPIOs to control the reboot mode. This will allow users to boot + a device in a specific mode by using a GPIO that can be controlled + outside U-Boot. + endmenu diff --git a/drivers/reboot-mode/Makefile b/drivers/reboot-mode/Makefile index 2ab0fddac9..04917be4f4 100644 --- a/drivers/reboot-mode/Makefile +++ b/drivers/reboot-mode/Makefile @@ -5,3 +5,4 @@ # obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o +obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o diff --git a/drivers/reboot-mode/reboot-mode-gpio.c b/drivers/reboot-mode/reboot-mode-gpio.c new file mode 100644 index 0000000000..7d8d483cff --- /dev/null +++ b/drivers/reboot-mode/reboot-mode-gpio.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c), Vaisala Oyj + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static int reboot_mode_get(struct udevice *dev, u32 *buf) +{ + int ret; + struct reboot_mode_gpio_platdata *plat_data; + + if (!buf) + return -EINVAL; + + plat_data = dev_get_platdata(dev); + if (!plat_data) + return -EINVAL; + + ret = dm_gpio_get_values_as_int(plat_data->gpio_desc, + plat_data->gpio_count); + if (ret < 0) + return ret; + + *buf = ret; + + return 0; +} + +static int reboot_mode_probe(struct udevice *dev) +{ + struct reboot_mode_gpio_platdata *plat_data; + + plat_data = dev_get_platdata(dev); + if (!plat_data) + return -EINVAL; + + int ret; + +#if CONFIG_IS_ENABLED(OF_CONTROL) + ret = gpio_get_list_count(dev, "gpios"); + if (ret < 0) + return ret; + + plat_data->gpio_count = ret; +#endif + + if (plat_data->gpio_count <= 0) + return -EINVAL; + + plat_data->gpio_desc = devm_kcalloc(dev, plat_data->gpio_count, + sizeof(struct gpio_desc), 0); + +#if CONFIG_IS_ENABLED(OF_CONTROL) + ret = gpio_request_list_by_name(dev, "gpios", plat_data->gpio_desc, + plat_data->gpio_count, GPIOD_IS_IN); + if (ret < 0) + return ret; +#else + for (int i = 0; i < plat_data->gpio_count; i++) { + struct reboot_mode_gpio_config *gpio = + plat_data->gpios_config + i; + struct gpio_desc *desc = plat_data->gpio_desc + i; + + ret = uclass_get_device_by_seq(UCLASS_GPIO, + gpio->gpio_dev_offset, + &desc->dev); + if (ret < 0) + return ret; + + desc->flags = gpio->flags; + desc->offset = gpio->gpio_offset; + + ret = dm_gpio_request(desc, ""); + if (ret < 0) + return ret; + + ret = dm_gpio_set_dir(desc); + if (ret < 0) + return ret; + } +#endif + return 0; +} + +static int reboot_mode_remove(struct udevice *dev) +{ + struct reboot_mode_gpio_platdata *plat_data; + + plat_data = dev_get_platdata(dev); + if (!plat_data) + return -EINVAL; + + return gpio_free_list(dev, plat_data->gpio_desc, plat_data->gpio_count); +} + +#if CONFIG_IS_ENABLED(OF_CONTROL) +static const struct udevice_id reboot_mode_ids[] = { + { .compatible = "reboot-mode-gpio", 0 }, + { } +}; +#endif + +static const struct reboot_mode_ops reboot_mode_gpio_ops = { + .get = reboot_mode_get, +}; + +U_BOOT_DRIVER(reboot_mode_gpio) = { + .name = "reboot-mode-gpio", + .id = UCLASS_REBOOT_MODE, + .probe = reboot_mode_probe, + .remove = reboot_mode_remove, +#if CONFIG_IS_ENABLED(OF_CONTROL) + .of_match = reboot_mode_ids, +#endif + .platdata_auto_alloc_size = sizeof(struct reboot_mode_gpio_platdata), + .ops = &reboot_mode_gpio_ops, +}; diff --git a/include/reboot-mode/reboot-mode-gpio.h b/include/reboot-mode/reboot-mode-gpio.h new file mode 100644 index 0000000000..16b1185c69 --- /dev/null +++ b/include/reboot-mode/reboot-mode-gpio.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) Vaisala Oyj. + */ + +#ifndef REBOOT_MODE_REBOOT_MODE_GPIO_H_ +#define REBOOT_MODE_REBOOT_MODE_GPIO_H_ + +#include + +/* + * In case of initializing the driver statically (using U_BOOT_DEVICE macro), + * we can use this struct to declare the pins used. + */ + +#if !CONFIG_IS_ENABLED(OF_CONTROL) +struct reboot_mode_gpio_config { + int gpio_dev_offset; + int gpio_offset; + int flags; +}; +#endif + +struct reboot_mode_gpio_platdata { + struct gpio_desc *gpio_desc; +#if !CONFIG_IS_ENABLED(OF_CONTROL) + struct reboot_mode_gpio_config *gpios_config; +#endif + int gpio_count; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_GPIO_H_ */