From patchwork Thu Jul 29 11:36:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1511185 X-Patchwork-Delegate: monstr@monstr.eu 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=X54d2FIB; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gb7mY6Dg8z9sSs for ; Thu, 29 Jul 2021 21:37:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA99A82EA8; Thu, 29 Jul 2021 13:36:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="X54d2FIB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0FAAF82E83; Thu, 29 Jul 2021 13:36: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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D5BA182E2B for ; Thu, 29 Jul 2021 13:36:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x532.google.com with SMTP id p21so7719623edi.9 for ; Thu, 29 Jul 2021 04:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZGSrXjX6OTuwkGO0/NkU+3DHm+UoI49cLHDbAOE0p+E=; b=X54d2FIBOWTnNNndcBdYUeBPYbAvomDBExK4Zzf6fOH3k+kAA/QgOw0w5ULTFUAS3v RxSSf8NG7KfQEQHFq6z2mMFRo9sib50TP4Ndbo/3/9tzFKk1GEaZYNOzQ1TrpIiWG/N/ Fj+20FseFvAQ3iyo+gki+QH3ICcxYR6VUpHzxpFOIYA1xdu66ih+j5UYLvW/hF9dE/ui jUXscXkz+ivP441KOVNgGuWbXHiakBcahtG/nLG5e8PiFjmTSZPuOHVQCULD2P+2RcbF ulEwOOrsAsfOW6GHtzj2E+12ah7NWVg3r6mgPZDfes34306hPOsDtlfDfHC5/4mpctk1 2JPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ZGSrXjX6OTuwkGO0/NkU+3DHm+UoI49cLHDbAOE0p+E=; b=baBI6gsEz0qIg398Xwfn4veQirAVEf9AvEq9MvykMq725REoZowyT+SobCC9s1/Iz3 YUjzXMJObuvSuBmp2h8OjO5ehuNH/ilLdAOdzC8rg/hVUWxvY6CAhin7HMK8xvP9Yp/5 nEQwjhn+uePpnyKXgOyi8zezYFoS7qjNnz3ce1qtQXEopQrWz1cZw9vXuYvpZawIJ4ea PrUCNgpJrRX1ReQL0AxHwSP7rgEOjl47DVvb/aPcnpuThaAMDO7dXASz2iCyjitRf2j4 9alIn2jg3RF3Sq+GYIKxEFrZ3eSSvnpOM/THLL58WdT+YASBjr3poPWc8mLKF/hGrRhh NEKQ== X-Gm-Message-State: AOAM530TW62rTUKlRAYcwszbK0ItGAN38e7tv70nGcQAu0W8fxLvWcZC 9eaa9/Y4Vc4t6ZgkI7Pf2xJbkgMRAVdK5H7A X-Google-Smtp-Source: ABdhPJzFReABxRwTp8xLQHkXFdXiloYz3CtG26PNLxUNG1oHmTV+p+dJnWqUIrxDZxy0SIKrtAHhlw== X-Received: by 2002:a05:6402:424e:: with SMTP id g14mr5586668edb.364.1627558588315; Thu, 29 Jul 2021 04:36:28 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6:f666:9af6:3fed:e53b]) by smtp.gmail.com with ESMTPSA id de19sm1096599edb.6.2021.07.29.04.36.27 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jul 2021 04:36:28 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Patrick Delaunay , Simon Glass Subject: [PATCH 1/4] dm: rtc: uclass: Add flag to control sequence numbering Date: Thu, 29 Jul 2021 13:36:22 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 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.103.2 at phobos.denx.de X-Virus-Status: Clean RTCs are using aliases for sequences. That's why enable DM_UC_FLAG_SEQ_ALIAS for exact RTC indentification. The same flag is used by a lot of other uclasses like mmc, pci, serial, spi, timer, tpm, etc. Signed-off-by: Michal Simek --- drivers/rtc/rtc-uclass.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c index be6a2ddb6671..321b8732ed9a 100644 --- a/drivers/rtc/rtc-uclass.c +++ b/drivers/rtc/rtc-uclass.c @@ -176,6 +176,7 @@ int rtc_write32(struct udevice *dev, unsigned int reg, u32 value) UCLASS_DRIVER(rtc) = { .name = "rtc", .id = UCLASS_RTC, + .flags = DM_UC_FLAG_SEQ_ALIAS, #if !CONFIG_IS_ENABLED(OF_PLATDATA) .post_bind = dm_scan_fdt_dev, #endif From patchwork Thu Jul 29 11:36:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1511182 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=EP/u8LWq; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gb7mC59Jxz9sSs for ; Thu, 29 Jul 2021 21:36:57 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4CAF682E0A; Thu, 29 Jul 2021 13:36:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="EP/u8LWq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 07D1F82E9E; Thu, 29 Jul 2021 13:36:35 +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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4777882E7A for ; Thu, 29 Jul 2021 13:36:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x632.google.com with SMTP id ga41so10102864ejc.10 for ; Thu, 29 Jul 2021 04:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9YSL03Z+1JJxmuXPJPJEbrFt+a528VDwhjfX9cNQaX4=; b=EP/u8LWqTMdVdReWIND09JsIZaDvqi5O2Ng5am/O6k54BPGuGjuw0cQ0c1YT7JWm9m 2YmxKIQ8AmVlWj21I2pqPWpeIahrHcgMlOyn/jjfndodkGUskKtisX0WOTiv6p978laJ uRdiRSbegwDCJLgInPrIRVYozZeP0rGQRPmgy6G/AZY5nmliseHfjj/UdB0XVCAiiosr NYFvWVU9oT6E0UUSkbLK+FQUkH4H+aWarU1jnt9JvBsmco6AjLocAVgwnMb2x1O38VVk I8duD6uGlyG6yFASYGmWDh8YXbhLkCSo/HF9PYTyxRrNATL4/Hjt1B5QO87lOZeAL8+T EKbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9YSL03Z+1JJxmuXPJPJEbrFt+a528VDwhjfX9cNQaX4=; b=CeTtN4fzLZUS3MiydIOnKCwoQxukmMBjENFxTgXe8o0UNn+O9cplCecldXbNvDTXIF Z/oL1UDQ+yQGR0w0w63LdsJhwX3PWK6uDPUiBWb1sHPWd5fOWWlEMVv9QWILbvf0dBEV Bbnfu3AGdJnN8oSz6KRq8I3TMgeCgoFRK37Zst/Cv8r/ulF6qs9kHnvihGaWGT1YUXF2 1LkVHwYjpFjvOkc8u7oqQ5APWTrpOu5UynDvFWMgHEl3ZvVUDd5Jc/c9tkYggP0Sns+5 aOyuzGqnlT9mA5tyIw/nOSnKmzQOjZZVdODa8XJEfrZHXUM8KdQZNBAbWAp+2w1xY5dJ KkNQ== X-Gm-Message-State: AOAM531OwUtYJuhKEHm3OghlxHLA50U5JLXPaJbL2ViAhakZ8lz7yIvp Hd4D7X7+nr9GbFdvY8EFfP5wY+iRcXsIHVPj X-Google-Smtp-Source: ABdhPJxLs2NwHTxNmed1hDEgIoIIYUUc0yby4Zu7B68LqQhZQ9GpPalOgZQTkzBKtPMZ0m5bMr7wTQ== X-Received: by 2002:a17:906:1ccf:: with SMTP id i15mr4201135ejh.120.1627558589757; Thu, 29 Jul 2021 04:36:29 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6:f666:9af6:3fed:e53b]) by smtp.gmail.com with ESMTPSA id n17sm1064229edr.84.2021.07.29.04.36.29 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jul 2021 04:36:29 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Simon Glass Subject: [PATCH 2/4] cmd: date: rtc: Update command to read the first RTC with seq 0 Date: Thu, 29 Jul 2021 13:36:23 +0200 Message-Id: <90b3582388ce5438f9cadc259f26c07c35616b89.1627558582.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 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.103.2 at phobos.denx.de X-Virus-Status: Clean RTCs are using sequence number defined in aliases node. Date command with DM_RTC enabled is looking for the first RTC with index 0. But when RTC_EMULATION is enabled it gets likely most of the time index 0 even when system has rtc0 device via aliases node and gets sequence number 0. That's why extend the code to look for sequence 0 number first. If this fails continue to use existing device with index 0. Signed-off-by: Michal Simek --- cmd/date.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/date.c b/cmd/date.c index 0e1189475313..5d5c20a59af9 100644 --- a/cmd/date.c +++ b/cmd/date.c @@ -41,10 +41,13 @@ static int do_date(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_DM_RTC struct udevice *dev; - rcode = uclass_get_device(UCLASS_RTC, 0, &dev); + rcode = uclass_get_device_by_seq(UCLASS_RTC, 0, &dev); if (rcode) { - printf("Cannot find RTC: err=%d\n", rcode); - return CMD_RET_FAILURE; + rcode = uclass_get_device(UCLASS_RTC, 0, &dev); + if (rcode) { + printf("Cannot find RTC: err=%d\n", rcode); + return CMD_RET_FAILURE; + } } #elif defined(CONFIG_SYS_I2C) old_bus = i2c_get_bus_num(); From patchwork Thu Jul 29 11:36:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1511186 X-Patchwork-Delegate: monstr@monstr.eu 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=u9ZlAtGc; 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 4Gb7mj664jz9sSs for ; Thu, 29 Jul 2021 21:37:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2C0B582EBD; Thu, 29 Jul 2021 13:36:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="u9ZlAtGc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB40582E6A; Thu, 29 Jul 2021 13:36: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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C2E4682EB5 for ; Thu, 29 Jul 2021 13:36:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52b.google.com with SMTP id h8so7764833ede.4 for ; Thu, 29 Jul 2021 04:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y0J7tbiOQ7M8C2BvHn3G9YLGMJN3L4XswpM04b9AXGc=; b=u9ZlAtGcwnOwua3TjUZ8nx88/TytptDUucmywnUzQuolhdGbW0Mj40VVH4NyosUXxO UIjOfxNxkvjIGY79JHNGntNlXRd0mB1hCfWr0p3BseJhfX8l8hTsdMsmDox7Miqu9nW+ Iu+xokXZsPzLJgBCqx6TYi/EPZfZHFbxFk+uefSgwuXqMltOWX5CG44rhTCySy8xFQMs zrUYPDwr0U08YM0GSOd2zH22DNbpiIl9RqWVKtc+H5T7kj3YMz3HIfkLnwaTS57I4QlQ azRvLum8YKm0N45aFRhhvL0d24RS3T3RthonwaR5Ar4PaQd9eoBekMy+1d0lDTn/BKtF XhWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Y0J7tbiOQ7M8C2BvHn3G9YLGMJN3L4XswpM04b9AXGc=; b=P7VAM/za9yEpdUrVR9A3B18t3K+nzMH9v2t9R7toBxGJ9CazBwayn8Gz3dMOcnYnFK yk6/ONRslnmfHvtDlO1lfO+iBqeqaGHhWECU1UmunqxJCLeHaRkOV96B/haVAsAP4zp3 KgasxhBWaWfknyK5HFviOyl9RRPdP2FVNIcpMWL3wuih6n+vRWbMA8Y1AGSlr7LM6+ko 7XiV5pfjq9YzmQKoHh7v910F1OFI8f0pt9anUIXU70becK4TtaPD0cjdGAtlLY/Q7rYH qb5k5XgD8X7/tkPmD0reu2hFK1xczi4G5tvfijxBotTR48vc9RRO3R75MR2QdFg/FF1y 5gcQ== X-Gm-Message-State: AOAM531mjOPu9hU1KhO1o4BMAxfQIJootY+gNGsOd95pI2Ye9HovoekO syBq69TuhPKB+TWoB15674zso+W4cLD+G6IR X-Google-Smtp-Source: ABdhPJzXOZf0ygacrN7hFCyt+m1/GeSEf5bpxFqfabhj74AsfBhvlB0sg93I4J0AoefjYlXaevTCzg== X-Received: by 2002:a05:6402:d2:: with SMTP id i18mr5516305edu.17.1627558591187; Thu, 29 Jul 2021 04:36:31 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6:f666:9af6:3fed:e53b]) by smtp.gmail.com with ESMTPSA id t25sm1091500edq.29.2021.07.29.04.36.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jul 2021 04:36:30 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Bin Meng , Dario Binacchi , Heiko Schocher , Heinrich Schuchardt , =?utf-8?q?Marek_Beh=C3=BAn?= , Michal Simek , Stefan Roese , "Ying-Chun Liu (PaulLiu)" Subject: [PATCH 3/4] rtc: zynqmp: Add support for ZynqMP RTC Date: Thu, 29 Jul 2021 13:36:24 +0200 Message-Id: <7fb0337f46fd574588f23bfc59ebbc7d9c2770ce.1627558582.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 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.103.2 at phobos.denx.de X-Virus-Status: Clean The whole driver logic is taken from Linux kernel but only set/get/reset functions are implemented. When device is power off RTC is power out of battery. Signed-off-by: Michal Simek --- MAINTAINERS | 1 + drivers/rtc/Kconfig | 7 ++ drivers/rtc/Makefile | 1 + drivers/rtc/zynqmp_rtc.c | 158 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 drivers/rtc/zynqmp_rtc.c diff --git a/MAINTAINERS b/MAINTAINERS index 8a18b3b6d939..5734ebb80363 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -600,6 +600,7 @@ F: drivers/mtd/nand/raw/zynq_nand.c F: drivers/net/phy/xilinx_phy.c F: drivers/net/zynq_gem.c F: drivers/serial/serial_zynq.c +F: drivers/rtc/zynqmp_rtc.c F: drivers/spi/zynq_qspi.c F: drivers/spi/zynq_spi.c F: drivers/timer/cadence-ttc.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index cbdfddb80f66..b6692e62df1c 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -195,4 +195,11 @@ config RTC_DAVINCI Say "yes" here to support the on chip real time clock present on TI OMAP1, AM33xx, DA8xx/OMAP-L13x, AM43xx and DRA7xx. +config RTC_ZYNQMP + bool "Enable ZynqMP RTC driver" + depends on ARCH_ZYNQMP + help + Say "yes" here to support the on chip real time clock + present on Xilinx ZynqMP SoC. + endmenu diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 331a49ab599a..d621be622848 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -57,3 +57,4 @@ obj-$(CONFIG_RTC_STM32) += stm32_rtc.o obj-$(CONFIG_SANDBOX) += sandbox_rtc.o obj-$(CONFIG_RTC_X1205) += x1205.o obj-$(CONFIG_RTC_ABX80X) += abx80x.o +obj-$(CONFIG_RTC_ZYNQMP) += zynqmp_rtc.o diff --git a/drivers/rtc/zynqmp_rtc.c b/drivers/rtc/zynqmp_rtc.c new file mode 100644 index 000000000000..ab9b93ca9793 --- /dev/null +++ b/drivers/rtc/zynqmp_rtc.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021, Xilinx, Inc. + */ + +#define LOG_CATEGORY UCLASS_RTC + +#include +#include +#include +#include + +/* RTC Registers */ +#define RTC_SET_TM_WR 0x00 +#define RTC_SET_TM_RD 0x04 +#define RTC_CALIB_WR 0x08 +#define RTC_CUR_TM 0x10 +#define RTC_INT_STS 0x20 +#define RTC_CTRL 0x40 + +#define RTC_INT_SEC BIT(0) +#define RTC_BATT_EN BIT(31) +#define RTC_CALIB_DEF 0x198233 +#define RTC_CALIB_MASK 0x1FFFFF + +struct zynqmp_rtc_priv { + fdt_addr_t base; + unsigned int calibval; +}; + +static int zynqmp_rtc_get(struct udevice *dev, struct rtc_time *tm) +{ + struct zynqmp_rtc_priv *priv = dev_get_priv(dev); + u32 status; + unsigned long read_time; + + status = readl(priv->base + RTC_INT_STS); + + if (status & RTC_INT_SEC) { + /* + * RTC has updated the CURRENT_TIME with the time written into + * SET_TIME_WRITE register. + */ + read_time = readl(priv->base + RTC_CUR_TM); + } else { + /* + * Time written in SET_TIME_WRITE has not yet updated into + * the seconds read register, so read the time from the + * SET_TIME_WRITE instead of CURRENT_TIME register. + * Since we add +1 sec while writing, we need to -1 sec while + * reading. + */ + read_time = readl(priv->base + RTC_SET_TM_RD) - 1; + } + + rtc_to_tm(read_time, tm); + + return 0; +} + +static int zynqmp_rtc_set(struct udevice *dev, const struct rtc_time *tm) +{ + struct zynqmp_rtc_priv *priv = dev_get_priv(dev); + unsigned long new_time = 0; + + if (tm) + /* + * The value written will be updated after 1 sec into the + * seconds read register, so we need to program time +1 sec + * to get the correct time on read. + */ + new_time = rtc_mktime(tm) + 1; + + /* + * Writing into calibration register will clear the Tick Counter and + * force the next second to be signaled exactly in 1 second period + */ + priv->calibval &= RTC_CALIB_MASK; + writel(priv->calibval, (priv->base + RTC_CALIB_WR)); + + writel(new_time, priv->base + RTC_SET_TM_WR); + + /* + * Clear the rtc interrupt status register after setting the + * time. During a read_time function, the code should read the + * RTC_INT_STATUS register and if bit 0 is still 0, it means + * that one second has not elapsed yet since RTC was set and + * the current time should be read from SET_TIME_READ register; + * otherwise, CURRENT_TIME register is read to report the time + */ + writel(RTC_INT_SEC, priv->base + RTC_INT_STS); + + return 0; +} + +static int zynqmp_rtc_reset(struct udevice *dev) +{ + return zynqmp_rtc_set(dev, NULL); +} + +static int zynqmp_rtc_init(struct udevice *dev) +{ + struct zynqmp_rtc_priv *priv = dev_get_priv(dev); + u32 rtc_ctrl; + + /* Enable RTC switch to battery when VCC_PSAUX is not available */ + rtc_ctrl = readl(priv->base + RTC_CTRL); + rtc_ctrl |= RTC_BATT_EN; + writel(rtc_ctrl, priv->base + RTC_CTRL); + + /* + * Based on crystal freq of 33.330 KHz + * set the seconds counter and enable, set fractions counter + * to default value suggested as per design spec + * to correct RTC delay in frequency over period of time. + */ + priv->calibval &= RTC_CALIB_MASK; + writel(priv->calibval, (priv->base + RTC_CALIB_WR)); + + return 0; +} + +static int zynqmp_rtc_probe(struct udevice *dev) +{ + struct zynqmp_rtc_priv *priv = dev_get_priv(dev); + int ret; + + priv->base = dev_read_addr(dev); + if (priv->base == FDT_ADDR_T_NONE) + return -EINVAL; + + priv->calibval = dev_read_u32_default(dev, "calibration", + RTC_CALIB_DEF); + + ret = zynqmp_rtc_init(dev); + + return ret; +} + +static const struct rtc_ops zynqmp_rtc_ops = { + .get = zynqmp_rtc_get, + .set = zynqmp_rtc_set, + .reset = zynqmp_rtc_reset, +}; + +static const struct udevice_id zynqmp_rtc_ids[] = { + { .compatible = "xlnx,zynqmp-rtc" }, + { } +}; + +U_BOOT_DRIVER(rtc_zynqmp) = { + .name = "rtc-zynqmp", + .id = UCLASS_RTC, + .probe = zynqmp_rtc_probe, + .of_match = zynqmp_rtc_ids, + .ops = &zynqmp_rtc_ops, + .priv_auto = sizeof(struct zynqmp_rtc_priv), +}; From patchwork Thu Jul 29 11:36:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1511187 X-Patchwork-Delegate: monstr@monstr.eu 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=H1D06F8m; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Gb7mw1hjPz9sSs for ; Thu, 29 Jul 2021 21:37:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2EA0F82EE0; Thu, 29 Jul 2021 13:37:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="H1D06F8m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2ED3982E2B; Thu, 29 Jul 2021 13:36:39 +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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2DBBF82E10 for ; Thu, 29 Jul 2021 13:36:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62f.google.com with SMTP id oz16so10136569ejc.7 for ; Thu, 29 Jul 2021 04:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3B+qqZaTD6EaVatTieQWxWrrHB5l3nICFBj0LOGsPxY=; b=H1D06F8mq7TdiMZPKD2zZfUb2bi1Eys+WyGmNKabIXDcmQtgPj0qbtO/ZxbVhfkHAy vo0ckqGNt/xM1cz8/uVb4GK5MztWMG5TF8r9pk9+FItxwLBwDjZ2HwEoxNRGOWXzh8Dt pj6zdYfeeY1Fu5IDuighL0hMf1ryApKUOJkVUOA5eec/hKzPM6pOtxRkY7AteJYI3CVA TKYQQnj66sext/Wxwd4UP4S+tCcVTCgenJXQuGstGk147k3WApnqP6Y6lIcGf/th0FHs LaWhFl7agNgcVu1GPE7E7iAx8YDLhuXqt9PZoMvJYThgceI1WjIZwkhEiEHt8d/g8aKO fxKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=3B+qqZaTD6EaVatTieQWxWrrHB5l3nICFBj0LOGsPxY=; b=lEDnU8RsCEItsPpbfUPb+NRiLyrlBgdKL266LOBUO8+fRrPXR1iHUHxBw/+tiCt3xi Xv5A2M5AcQHesOKyzzg2kgv5cRkuxrBhh2FC8apAw+opo80upqm8EJbwFeF6YWlv/4oo +ELMs+ZPekmOoFfic9MEpKR0fnTZhUO51/i5K0rO1Qyg3zXCSJhnQeZ0vQ/XokRp9Y1j xD3kkG67vOKrMS4zDUs1koniGtsTFmPoOoECc9LYLFlykGIYMajEOX1xozrdI6BGdkr7 7sSTJAAhegpHwGZwXFCmDh8r8zeTxfRKtji/lMqMRwJnsRhUCpGvQAtC3Vqod7YSbl9X mn7A== X-Gm-Message-State: AOAM533Q6EFIEsF54i0ySBA0X/Iy0ENB6fsRrfHmfM8qJ2n4NHrDvMf0 DfSrJWbbh/iy5U7CyH44770FE0bABqzSDx9M X-Google-Smtp-Source: ABdhPJxdbN8tW8vZ3eijpDTPj/+MZWMQ7k/YG70xKbB977HsbzR+Md7I6YjzbyPTdExRk6L552oSWA== X-Received: by 2002:a17:906:c304:: with SMTP id s4mr4134574ejz.346.1627558592648; Thu, 29 Jul 2021 04:36:32 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6:f666:9af6:3fed:e53b]) by smtp.gmail.com with ESMTPSA id r27sm1079549edb.66.2021.07.29.04.36.32 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jul 2021 04:36:32 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Ashok Reddy Soma , Ilias Apalodimas , Michal Simek , T Karthik Reddy Subject: [PATCH 4/4] xilinx: zynqmp: Enable CMD_RTC command with Zynqmp RTC driver Date: Thu, 29 Jul 2021 13:36:25 +0200 Message-Id: <615f7ba11467ebb4b9f27f8bc4b05fbd78cda1f6.1627558582.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 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.103.2 at phobos.denx.de X-Virus-Status: Clean Enable RTC command to be able to check available. And also enable ZynqMP RTC driver to be possible to use by default. Here is the list when both drivers are enabled: ZynqMP> rtc list RTC #0 - rtc_emul RTC #1 - rtc@ffa60000 Signed-off-by: Michal Simek --- configs/xilinx_zynqmp_virt_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/xilinx_zynqmp_virt_defconfig b/configs/xilinx_zynqmp_virt_defconfig index a1a3526f3c5f..9a45ccb5287c 100644 --- a/configs/xilinx_zynqmp_virt_defconfig +++ b/configs/xilinx_zynqmp_virt_defconfig @@ -62,6 +62,7 @@ CONFIG_CMD_TFTPPUT=y CONFIG_CMD_BMP=y CONFIG_CMD_CACHE=y CONFIG_CMD_EFIDEBUG=y +CONFIG_CMD_RTC=y CONFIG_CMD_TIME=y CONFIG_CMD_GETTIME=y CONFIG_CMD_TIMER=y @@ -153,6 +154,7 @@ CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_RTC=y CONFIG_RTC_EMULATION=y +CONFIG_RTC_ZYNQMP=y CONFIG_SCSI=y CONFIG_DM_SCSI=y CONFIG_ARM_DCC=y