From patchwork Mon Jul 6 20:01:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1323914 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=fV5zg05M; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B0xMD3j8Nz9sR4 for ; Tue, 7 Jul 2020 06:03:04 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 22B3B81BB8; Mon, 6 Jul 2020 22:01:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk 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=prevas.dk header.i=@prevas.dk header.b="fV5zg05M"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3883D81B93; Mon, 6 Jul 2020 22:01:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20704.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::704]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B8CE481B65 for ; Mon, 6 Jul 2020 22:01:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UwulQ+7cqh6BSsa6miCnp9ce2J+Ie6vOsnTmgTkYnBm3SY6/aMDqA76gCDiKlblNmgU5KVUd32L2gxZRi5Cr3Wonzj3CbLhKEsibOqPaX4OyFu+erjX7mq2OwE2Bd6/XBE38jfzuS8gnTLYdKOPhefxHUchaQWK7saOUp7sgD9FDQnJb/0Th5IRw4/bnPVyfCbk3EbI0Cv/2greDsw+iOjYk/oehewMBJ4LManCIAxLe1A1Zto+96YFoxHfWMMLEY4VwTcZ6HlrO+3Fpv2PyBbD+67+xMHYkCIurVcAXb9NDYksEi+nYXpm37u6w53WUhlOtIYo21k20rpG7J0MtjA== 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=G8WSQjkrcPaMvoR+HOHHhKQZswzYA+AtWRVWUC3/9Eo=; b=dRPtCGIa3qkYkFrJqT7teH11rNDWGlD2XcxpECdBj/XMuNFpKvfLQjFP7EArDU8o/gu4AzqV4e8+dOtQ1NP9j84shUoTRS45JQKlRjbfDJhNCsUSQVMMaKXK3sYMVPB9cZzyu3gpMRGl498pK0Oaoa3ToudE80xY20HedAxv4WX4Kr9HJ/rAEqsKkIMdtTCsXK/6aWcj3Q3cyBE1k0ML1LdRAYLxxhfAntjqbl8fWtdRMhX7ms5gGu4gI9m03nB7XYkaTUqFhzX74AWi7AftSpOesS1ObyM2z22IhGw35Q7mUD1+Um8i0smPHVdB35GHqTesQ//0RMMI88B5f6TgIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G8WSQjkrcPaMvoR+HOHHhKQZswzYA+AtWRVWUC3/9Eo=; b=fV5zg05MpfXIVGlDXriC2CJUHyhIMxkkAzvY/YAedlkXyjYUHYMp409edjimEGzqbgOfri8ZNBLrNmAiOdfioXur7Lt6rLLQfp7oqLn8TD4t3pt3pdzeCgLD0Iv+tm/j3w2y7LxqkV65sHIAOdUp1BA3En/kVKW02DOoThzmZNg= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM0PR10MB3587.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:144::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20; Mon, 6 Jul 2020 20:01:31 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::91fd:aebc:e8cb:a663]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::91fd:aebc:e8cb:a663%7]) with mapi id 15.20.3153.029; Mon, 6 Jul 2020 20:01:31 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Schocher , Biwen Li , Rasmus Villemoes Subject: [PATCH v4 06/11] rtc: add rtc command Date: Mon, 6 Jul 2020 22:01:15 +0200 Message-Id: <20200706200120.23093-7-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200706200120.23093-1-rasmus.villemoes@prevas.dk> References: <20200706200120.23093-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM6PR0502CA0046.eurprd05.prod.outlook.com (2603:10a6:20b:56::23) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.112.31) by AM6PR0502CA0046.eurprd05.prod.outlook.com (2603:10a6:20b:56::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20 via Frontend Transport; Mon, 6 Jul 2020 20:01:30 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.112.31] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77da8467-6727-43c3-ec8d-08d821e76030 X-MS-TrafficTypeDiagnostic: AM0PR10MB3587: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:651; X-Forefront-PRVS: 04569283F9 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6wOxoKqX45aMGIkz5zf1SkZSaSoQjpbUIqRywZpAZFNInBztw1pTXYb42+3Pqz3NIKOy6bZkoz1yfLUMuI8uIuKZiOvtDMHNPjYQtrq1kDQwUbPb5nh0AIqHF7giy+KwBZoJdIoRAkoQYGaVUk5+xQ6+3ARbz7NL6JqM6rcNDzjMtZk9aEhJmHhA/J6qHH3XwDY3Zo7DX+HeDiuhHOX8KCz6qrBNG5/q+jonAKtt/zdqIOByGn/OIvZNLt6CxjbBLB7aGKeOY/QwIb5PvRYRCzbtT39jFWP4rgMrOPCEN4+z8xt0e4QpY9r5QQzS76J6daMlmMsrzFP5H97EayHnog== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFTY:; SFS:(39850400004)(346002)(136003)(396003)(376002)(366004)(5660300002)(6506007)(6666004)(26005)(54906003)(66476007)(36756003)(8976002)(8936002)(6512007)(66556008)(66946007)(52116002)(478600001)(44832011)(86362001)(1076003)(107886003)(2906002)(186003)(6486002)(8676002)(16526019)(956004)(4326008)(83380400001)(316002)(2616005)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: hQymbSQ5zFzWHOGYwLMQAWMZrOWoGHYP7YxPaQEbakzGxHZXhBd96sVcb85MigXzsnOpKi8KgDHHvoADe51bOzZqWEBHI0XQ9Rd0/8G7hwCH7T+W+PYXpbBQMMHV/s/uuEav4MeUsrwpjw9XfWPVCW2i26GKkikz5ZKCbGzJFTb1aCM/vgT1caAhdRZnx0QAjlzxWifwLA7GWyGCRGIe/Tq73HzM4M0vC7q6J+d/gsM2jpyEGOQ0W3ppbBaONJHQ9QcAeSttu1CB5KCRyOLG3T66BjKjbImAQWe8puPAhyNFildYlRi/g3fG5Wc/5kOoRaRTZ0mwWS3Qj/dP+ybh/D0dXafRW4Xg2YgGBvUbiEMfgCLcFhEGnoUs9aPOz9zJgiPH4T6bAo+FNR9ABXLy/K9FOIARCvtaVGrQB1fINvhmJuLjusCexL/odqZwrHySKXEAherIZCmWYBEnKiFi1EQQ8Kl28Yjtqh0JGsDbVrs= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 77da8467-6727-43c3-ec8d-08d821e76030 X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2020 20:01:30.9125 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 28j5G2FtNCeetkCo1ShypnoTgmnm+pWPSecaNIonp07Ok7lAMecg0xtkaTgB5RsnKyTPvzDrNE6vrvvizSdjPw3tfcrUuIaCgaWPcsEfHxk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB3587 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 Mostly as an aid for debugging RTC drivers, provide a command that can be used to read/write arbitrary registers (assuming the driver provides the read/write methods or their single-register-at-a-time variants). Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher Signed-off-by: Rasmus Villemoes --- cmd/Kconfig | 6 ++ cmd/Makefile | 1 + cmd/rtc.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 cmd/rtc.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 192b3b262f..c4d40cbce6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1718,6 +1718,12 @@ config CMD_DATE Enable the 'date' command for getting/setting the time/date in RTC devices. +config CMD_RTC + bool "rtc" + depends on DM_RTC + help + Enable the 'rtc' command for low-level access to RTC devices. + config CMD_TIME bool "time" help diff --git a/cmd/Makefile b/cmd/Makefile index 974ad48b0a..c7992113e4 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -120,6 +120,7 @@ obj-$(CONFIG_CMD_REISER) += reiser.o obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o obj-$(CONFIG_CMD_RNG) += rng.o obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o +obj-$(CONFIG_CMD_RTC) += rtc.o obj-$(CONFIG_SANDBOX) += host.o obj-$(CONFIG_CMD_SATA) += sata.o obj-$(CONFIG_CMD_NVME) += nvme.o diff --git a/cmd/rtc.c b/cmd/rtc.c new file mode 100644 index 0000000000..b4f61b2e83 --- /dev/null +++ b/cmd/rtc.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include +#include +#include + +#define MAX_RTC_BYTES 32 + +static int do_rtc_read(struct udevice *dev, int argc, char * const argv[]) +{ + u8 buf[MAX_RTC_BYTES]; + int reg, len, ret, r; + + if (argc < 2 || argc > 3) + return CMD_RET_USAGE; + + reg = simple_strtoul(argv[0], NULL, 16); + len = simple_strtoul(argv[1], NULL, 16); + + if (argc == 3) { + u8 *addr; + + addr = map_sysmem(simple_strtoul(argv[2], NULL, 16), len); + ret = dm_rtc_read(dev, reg, addr, len); + unmap_sysmem(addr); + if (ret) { + printf("dm_rtc_read() failed: %d\n", ret); + return CMD_RET_FAILURE; + } + return CMD_RET_SUCCESS; + } + + while (len) { + r = min_t(int, len, sizeof(buf)); + ret = dm_rtc_read(dev, reg, buf, r); + if (ret) { + printf("dm_rtc_read() failed: %d\n", ret); + return CMD_RET_FAILURE; + } + print_buffer(reg, buf, 1, r, 0); + len -= r; + reg += r; + } + + return CMD_RET_SUCCESS; +} + +static int do_rtc_write(struct udevice *dev, int argc, char * const argv[]) +{ + u8 buf[MAX_RTC_BYTES]; + int reg, len, ret; + const char *s; + int slen; + + if (argc < 2 || argc > 3) + return CMD_RET_USAGE; + + reg = simple_strtoul(argv[0], NULL, 16); + + if (argc == 3) { + u8 *addr; + + len = simple_strtoul(argv[1], NULL, 16); + addr = map_sysmem(simple_strtoul(argv[2], NULL, 16), len); + ret = dm_rtc_write(dev, reg, addr, len); + unmap_sysmem(addr); + if (ret) { + printf("dm_rtc_write() failed: %d\n", ret); + return CMD_RET_FAILURE; + } + return CMD_RET_SUCCESS; + } + + s = argv[1]; + slen = strlen(s); + + if (slen % 2) { + printf("invalid hex string\n"); + return CMD_RET_FAILURE; + } + + while (slen) { + len = min_t(int, slen / 2, sizeof(buf)); + if (hex2bin(buf, s, len)) { + printf("invalid hex string\n"); + return CMD_RET_FAILURE; + } + + ret = dm_rtc_write(dev, reg, buf, len); + if (ret) { + printf("dm_rtc_write() failed: %d\n", ret); + return CMD_RET_FAILURE; + } + s += 2 * len; + slen -= 2 * len; + } + + return CMD_RET_SUCCESS; +} + +int do_rtc(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + static int curr_rtc; + struct udevice *dev; + int ret, idx; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; + argv++; + + if (!strcmp(argv[0], "list")) { + struct uclass *uc; + + idx = 0; + uclass_id_foreach_dev(UCLASS_RTC, dev, uc) { + printf("RTC #%d - %s\n", idx++, dev->name); + } + if (!idx) { + printf("*** no RTC devices available ***\n"); + return CMD_RET_FAILURE; + } + return CMD_RET_SUCCESS; + } + + idx = curr_rtc; + if (!strcmp(argv[0], "dev") && argc >= 2) + idx = simple_strtoul(argv[1], NULL, 10); + + ret = uclass_get_device(UCLASS_RTC, idx, &dev); + if (ret) { + printf("Cannot find RTC #%d: err=%d\n", idx, ret); + return CMD_RET_FAILURE; + } + + if (!strcmp(argv[0], "dev")) { + /* Show the existing or newly selected RTC */ + if (argc >= 2) + curr_rtc = idx; + printf("RTC #%d - %s\n", idx, dev->name); + return CMD_RET_SUCCESS; + } + + if (!strcmp(argv[0], "read")) + return do_rtc_read(dev, argc - 1, argv + 1); + + if (!strcmp(argv[0], "write")) + return do_rtc_write(dev, argc - 1, argv + 1); + + return CMD_RET_USAGE; +} + +U_BOOT_CMD( + rtc, 5, 0, do_rtc, + "RTC subsystem", + "list - show available rtc devices\n" + "rtc dev [n] - show or set current rtc device\n" + "rtc read - read and display 8-bit registers starting at \n" + "rtc read - read 8-bit registers starting at to memory \n" + "rtc write - write 8-bit registers starting at \n" + "rtc write - write from memory to 8-bit registers starting at \n" +);