From patchwork Tue Nov 12 09:13:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nandor Han X-Patchwork-Id: 1193379 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="H48sgxXI"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47C2C44JGCz9s4Y for ; Tue, 12 Nov 2019 20:15:12 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id BB7A5C21EBE; Tue, 12 Nov 2019 09:14:12 +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 B46C1C21E44; Tue, 12 Nov 2019 09:13:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4CB03C21E7F; Tue, 12 Nov 2019 09:13:28 +0000 (UTC) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40086.outbound.protection.outlook.com [40.107.4.86]) by lists.denx.de (Postfix) with ESMTPS id 6D254C21DA2 for ; Tue, 12 Nov 2019 09:13:25 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nVrTbpxWym27rAMCKpA1sPVq4ffuoZQSJSTIrDu2/UhEpOveu1tgiiMLlfKaz8ANJjRXnOh6kPQo825SRXD1JFy4cqlf2lcxSglmJXyMoMMwnHGeJx5U9c70OMOXUtC+EuN6t/aZyZKCSzQd7tmNxa8f/DMPlffxLG+7+7nccTbm5ZBhkop64SQgaxx1EkQjpaNQnfpm2pg1EVNay7/Ai3F1ujECtIkptlrLQkS4v5inMKbKcKFlhxWcuDNZyIr3/ZRgoQj1lp/L/HAKcZk224U35NWDZGSnn5wZDnGZphaBdV/8A8Tr9hFWCy2YxGZ94aFu0cZp4RuoQZRDj7ASJg== 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=iGiy6xuBQZbxKP6+/rGEpHStSGmlrkSuWP8Wp8itabw=; b=Pp3Wprib6sJ5bogKJELH/9y/ha/uHwmmG1w4AJbd7R8V9B8JLHm8WRZM6liVw65EsBdyyuKkpvIePMOGZjjIDCbfL++oxqsOJ2JsDJF8GnFqGnNHBRhyMrVzsxe/UYGLPR4wvwzQZy2vefiDf+jBAGAuhbfNOGXIDON3N4Ep9YfRHv5TKvoxrZnod80ugi2yDfz1ZUMCUa4pALyv78ziCzbyWGv8uFiR7mVHiytrtuVovb2BaqSN+kCAU9HFeiXACuOh2OJFhLcjDSSKbMCMtV6c5Ggfeb/PY8/tvwzAGf7raBwGng1jS/2T/2AWEqyCMaGl6wjLF3+pZvDreyppIA== 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=iGiy6xuBQZbxKP6+/rGEpHStSGmlrkSuWP8Wp8itabw=; b=H48sgxXIpv5H6sZtfKzaswNhl0TSVP1PQTgqWmmSv0bBDQq2PBKTk4wW+r6SfS7OANtVI9aAxITL4m99ZhxLRl0Pnb813KZDhLg6RDUiQWKK7k6tfL1z9tphPfmyNOva3q8FkdM03R2m2qrt43WzDQYwuq3SJuYVd6JEoF5I+iQ= 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:24 +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:24 +0000 From: Han Nandor To: "u-boot@lists.denx.de" Thread-Topic: [PATCH 3/3] reboot-mode: read the boot mode from RTC memory Thread-Index: AQHVmTlv1oKh7neCKEWv9FjVBiub+w== Date: Tue, 12 Nov 2019 09:13:24 +0000 Message-ID: <20191112091255.28149-4-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: 1719ec0b-b8dc-49a8-32f9-08d76750920f 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:3276; 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)(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: +cLIEQ9ngmGnBagoDdaDI0N40Pr8O2TY4BhCuZ+jf1kz/AEAS8QxCHn9B7jKIvyWpfSk1J7Y5krZBpvn1cSE1CNyMArvShGKp8TFiQeNKwhDrvy3pw1+MF7m8Ph+uWkivt+4eZl2DWpy0mG7Mxb3Bhy7SjrdUE6nN4LMz80Klh//2u07KGxVkly0Of3AY4xlV4+Z0XtAu0xYu6z4wt9h700wcRZdb3eIPFl8IguRhTUU6GcnG/oFIjp5vBr+uwOTO82yS8w7yH8VbLtoaLfflhhQNGlC87vvr7o21JkyO09VWS59OnVAYqU6S+kn3jWE5w62nF72akDFy9oK2sofqP1iUAfbXD1Grle80LuLxN8jHLUYt8gZ+RUe3KFfP5/EUa5Qok5itpVguwgW1k+QZGZ7PIimH2frg7DCpr8X1gIL/NiktofSs2M4sM1M+NBN MIME-Version: 1.0 X-OriginatorOrg: vaisala.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1719ec0b-b8dc-49a8-32f9-08d76750920f X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Nov 2019 09:13:24.4407 (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: 7ZuESeCvkXKk1iPO3dSW6GH9aveaypOWeAmQU/9ip3Lk3V+R30HZOAoyNGEJWKaepaQE81S1q0YD9SihMlQHtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR06MB4182 Cc: "trini@konsulko.com" Subject: [U-Boot] [PATCH 3/3] reboot-mode: read the boot mode from RTC memory 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" RTC devices could provide battery-backed memory that can be used for storing the reboot mode magic value. Add a new reboot-mode back-end that uses RTC to store the reboot-mode magic value. The driver also supports both endianness modes. Signed-off-by: Nandor Han --- .../reboot-mode/reboot-mode-rtc.txt | 22 +++ drivers/reboot-mode/Kconfig | 9 ++ drivers/reboot-mode/Makefile | 1 + drivers/reboot-mode/reboot-mode-rtc.c | 132 ++++++++++++++++++ include/reboot-mode/reboot-mode-rtc.h | 16 +++ 5 files changed, 180 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt create mode 100644 drivers/reboot-mode/reboot-mode-rtc.c create mode 100644 include/reboot-mode/reboot-mode-rtc.h diff --git a/doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt b/doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt new file mode 100644 index 0000000000..23aa12c88c --- /dev/null +++ b/doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt @@ -0,0 +1,22 @@ +RTC Reboot Mode Configuration + +Required Properties: +- compatible: must be "reboot-mode-rtc". +- rtc: reference to the rtc device used. +- reg: start register and the number of bytes used. Maximum 4 bytes supported. +- 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). +- big-endian: if the magic value is stored in big-endian. (default: false). + +Example: + reboot-mode-rtc { + compatible = "reboot-mode-rtc"; + rtc = <&rtc_0>; + reg = <0x14 4>; + u-boot,env-variable = "bootstatus"; + big-endian; + modes-test = <0x21969147>; + modes-download = <0x51939147>; + }; diff --git a/drivers/reboot-mode/Kconfig b/drivers/reboot-mode/Kconfig index ff65e2031a..ac67bfcef6 100644 --- a/drivers/reboot-mode/Kconfig +++ b/drivers/reboot-mode/Kconfig @@ -24,4 +24,13 @@ config DM_REBOOT_MODE_GPIO a device in a specific mode by using a GPIO that can be controlled outside U-Boot. +config DM_REBOOT_MODE_RTC + bool "Use RTC as reboot mode backend" + depends on DM_REBOOT_MODE + default n + help + Use RTC non volatile memory to control the reboot mode. This will allow users to boot + a device in a specific mode by using a register(s) that can be controlled + outside U-Boot (e.g. Kernel). + endmenu diff --git a/drivers/reboot-mode/Makefile b/drivers/reboot-mode/Makefile index 04917be4f4..2c13780ced 100644 --- a/drivers/reboot-mode/Makefile +++ b/drivers/reboot-mode/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o +obj-$(CONFIG_DM_REBOOT_MODE_RTC) += reboot-mode-rtc.o diff --git a/drivers/reboot-mode/reboot-mode-rtc.c b/drivers/reboot-mode/reboot-mode-rtc.c new file mode 100644 index 0000000000..db11acc75a --- /dev/null +++ b/drivers/reboot-mode/reboot-mode-rtc.c @@ -0,0 +1,132 @@ +// 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) +{ + if (!buf) + return -EINVAL; + + int ret; + u8 *val = (u8 *)buf; + struct reboot_mode_rtc_platdata *plat_data; + + plat_data = dev_get_platdata(dev); + if (!plat_data) + return -EINVAL; + + for (int i = 0; i < plat_data->size; i++) { + ret = rtc_read8(plat_data->rtc, plat_data->addr + i); + if (ret < 0) + return ret; + + val[i] = ret; + } + + if (plat_data->is_big_endian) + *buf = __be32_to_cpu(*buf); + else + *buf = __le32_to_cpu(*buf); + + return 0; +} + +static int reboot_mode_set(struct udevice *dev, u32 buf) +{ + int ret; + u8 *val; + struct reboot_mode_rtc_platdata *plat_data; + + plat_data = dev_get_platdata(dev); + if (!plat_data) + return -EINVAL; + + if (plat_data->is_big_endian) + buf = __cpu_to_be32(buf); + else + buf = __cpu_to_le32(buf); + + val = (u8 *)&buf; + + for (int i = 0; i < plat_data->size; i++) { + ret = rtc_write8(plat_data->rtc, (plat_data->addr + i), val[i]); + if (ret < 0) + return ret; + } + + return 0; +} + +#if CONFIG_IS_ENABLED(OF_CONTROL) +static int reboot_mode_ofdata_to_platdata(struct udevice *dev) +{ + struct ofnode_phandle_args phandle_args; + struct reboot_mode_rtc_platdata *plat_data; + + plat_data = dev_get_platdata(dev); + if (!plat_data) + return -EINVAL; + + if (dev_read_phandle_with_args(dev, "rtc", NULL, 0, 0, &phandle_args)) { + dev_err(dev, "RTC device not specified\n"); + return -ENOENT; + } + + if (uclass_get_device_by_ofnode(UCLASS_RTC, + phandle_args.node, &plat_data->rtc)) { + dev_err(dev, "could not get the RTC device\n"); + return -ENODEV; + } + + plat_data->addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, + dev_of_offset(dev), + "reg", + 0, + (fdt_size_t *)&plat_data->size, + false); + if (plat_data->addr == FDT_ADDR_T_NONE) { + dev_err(dev, "Invalid RTC address\n"); + return -EINVAL; + } + + if (plat_data->size > sizeof(u32)) { + dev_err(dev, "Invalid reg size\n"); + return -EINVAL; + } + + plat_data->is_big_endian = ofnode_read_bool(dev->node, "big-endian"); + + return 0; +} + +static const struct udevice_id reboot_mode_ids[] = { + { .compatible = "reboot-mode-rtc", 0 }, + { } +}; +#endif + +static const struct reboot_mode_ops reboot_mode_rtc_ops = { + .get = reboot_mode_get, + .set = reboot_mode_set, +}; + +U_BOOT_DRIVER(reboot_mode_rtc) = { + .name = "reboot-mode-rtc", + .id = UCLASS_REBOOT_MODE, +#if CONFIG_IS_ENABLED(OF_CONTROL) + .of_match = reboot_mode_ids, + .ofdata_to_platdata = reboot_mode_ofdata_to_platdata, +#endif + .platdata_auto_alloc_size = sizeof(struct reboot_mode_rtc_platdata), + .ops = &reboot_mode_rtc_ops, +}; diff --git a/include/reboot-mode/reboot-mode-rtc.h b/include/reboot-mode/reboot-mode-rtc.h new file mode 100644 index 0000000000..3613678f63 --- /dev/null +++ b/include/reboot-mode/reboot-mode-rtc.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c), Vaisala Oyj + */ + +#ifndef REBOOT_MODE_REBOOT_MODE_RTC_H_ +#define REBOOT_MODE_REBOOT_MODE_RTC_H_ + +struct reboot_mode_rtc_platdata { + struct udevice *rtc; + bool is_big_endian; + int addr; + size_t size; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_RTC_H_ */