From patchwork Thu Jul 20 01:28:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13319691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A159C001E0 for ; Thu, 20 Jul 2023 01:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IlZmGN5rJUL5mCYw6NpjmpXGKwNwmhzd54TKDZPqQWY=; b=MvvOVTe+/1Tkkk Tl/o+mWWUGLxn2caNCCTaNrHnhUfRyjckj1Os1HkxszlXwZ1gpV2nKdRctOnuiTQ6pgkWyWeQfwwV XP56Kz9QsycFNpT474X9mMK2og9oP4Mqk7BZi9o/hzQIVZllQyVlpC2K6XXGPThXobY5qa6uCnpwh S25JrfRqbKpnL9EEL9sPrweXJqqjwMVuNpsRY9HNzrbdNTPUHntcnA1YVjKFljitzBvUiRi7qNw9I 8oUvF55X5a4OwEq5H/Q637FaaX8DHbkeuat6m2calvKCeEcPs1BIZzV7Mw+YxVs1k2cY0Lb8/dL+O 7unnuRhNKWO2MCbvcbKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qMITF-009SOP-2d; Thu, 20 Jul 2023 01:28:45 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMIT7-009SLf-2P for linux-arm-kernel@lists.infradead.org; Thu, 20 Jul 2023 01:28:39 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1b8bd586086so1869185ad.2 for ; Wed, 19 Jul 2023 18:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689816516; x=1690421316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PknmXnQirEOnubVOauabc0cJvIl8m6tNpWyxQZCD0N0=; b=HlYK066kywXFDcqXfpN2MS//uTAgfYqt5W28/6QC2VM5BWYvB9bkuxwbgRlpf1fMew Tm/pCbdMEnTe3tOBySqaUMHvkByNcNOlFFGdNmLrhU4bFI4TOTJGS2knR7XmWOHKbpoW /I+38ci00HljLjTLHrsLSNgjGqduuZlVU25broSFKNElvothWFoMJ0GGG4N9GDbZa/Zl nZGOHUmJPM8x9+tnsBOBKYEu8HcGaSGhp/4V5d/wjxEjYWzo8jZMH04YE/zRlgl3UbQc vLFf+m/2YS5qKN7Nf8ri2iyYAeRf+BcDIcQidasUU4L9RVBAyNJoZIwQUS7dcD5JOiAr rtWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689816516; x=1690421316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PknmXnQirEOnubVOauabc0cJvIl8m6tNpWyxQZCD0N0=; b=XWIx55emge1COapjtUwWT64AxSQ8eLp3B6ze6PaK/xSoCjTEVKuqNGblHgAypSwCPC yI8vJFyi3u3FK2cp2V1IyPm9/eaQEwdB9RpTQ1M+ItBJUZFPPpHtgsKyNIvAMfjSm+5z YtxMd4mj6+vOqAjLQrC34z3L3nSTzGy3xTwo47zFzjvaWNzhocsI3AwPfmb57CKEtyFP Q2U0OntBmG2YjJEbl10kR8O4k276sQ/8b6MhUL56QwP0ZiY1qKBupblu5JImm9dwo84q G1CApwOfHV4DXkMqMjUjyBnKEVIA4/NSTs+acDAOiS+wngmoaUjNUZfVUxqbVh0t1pmw DNeA== X-Gm-Message-State: ABy/qLYTqQYmmM9x+1pWLEOMYXdoVOO7zb0Wlzp7LzsQi3shqI6FAfBv 1McBEVgtkDrcStLOlsp3pp0= X-Google-Smtp-Source: APBJJlGSks9Rg5tIlI14bZPE81Pyz9Tcv/KMpi5HUYJgRIUzBSJhe/UXuN78EoamwuQ5FKB1bcIDJw== X-Received: by 2002:a17:902:e548:b0:1b8:b29e:b47b with SMTP id n8-20020a170902e54800b001b8b29eb47bmr5402474plf.44.1689816515718; Wed, 19 Jul 2023 18:28:35 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id jc18-20020a17090325d200b001b1a2c14a4asm4673998plb.38.2023.07.19.18.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 18:28:35 -0700 (PDT) From: Jacky Huang To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, soc@kernel.org, mjchen@nuvoton.com, schung@nuvoton.com, Jacky Huang Subject: [PATCH 1/3] dt-bindings: rtc: Document nuvoton ma35d1 rtc driver Date: Thu, 20 Jul 2023 01:28:24 +0000 Message-Id: <20230720012826.430026-2-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230720012826.430026-1-ychuang570808@gmail.com> References: <20230720012826.430026-1-ychuang570808@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230719_182837_785750_7852B335 X-CRM114-Status: GOOD ( 12.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jacky Huang Add documentation to describe nuvoton ma35d1 rtc driver. Signed-off-by: Jacky Huang --- .../bindings/rtc/nuvoton,ma35d1-rtc.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/nuvoton,ma35d1-rtc.yaml diff --git a/Documentation/devicetree/bindings/rtc/nuvoton,ma35d1-rtc.yaml b/Documentation/devicetree/bindings/rtc/nuvoton,ma35d1-rtc.yaml new file mode 100644 index 000000000000..08c30f3018fb --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/nuvoton,ma35d1-rtc.yaml @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/rtc/nuvoton,ma35d1-rtc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 Read Time Clock + +maintainers: + - Min-Jen Chen + +properties: + compatible: + enum: + - nuvoton,ma35d1-rtc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + +additionalProperties: false + +examples: + - | + #include + #include + rtc@40410000 { + compatible = "nuvoton,ma35d1-rtc"; + reg = <0x40410000 0x200>; + interrupts = ; + clocks = <&clk RTC_GATE>; + }; + +... From patchwork Thu Jul 20 01:28:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13319692 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A5D2C001B0 for ; Thu, 20 Jul 2023 01:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r0LVOsX2UixPURBIudozXN5MaHACcV3V6OGntys9KRo=; b=n5RbP43E/ooFjc yhl1+H1pK5R7iSXCxIkF8IEUsmyVho1QaXWOrtOmq7T2PMrsfTN2LPurc7pGbvpsZMWaqr62XIZad IknBC5te+ksKD872C5g7b2z8QhEx0rkXYLgG2tExiHiYBIlj2NC6eV+ft19abDDaWW95m/q6Sa5xc 0mO4gOgBvJ0ZCSB1YniAHue+EUl3gi9HwsR6sOwzi0im6sPpBvUEzGjGn7V4iGCcsD0p7j3x7KVnI 4O+qVoNgdgvIC3jlxJMZlc29bcJ78kwe5PDO+Q0Dnvm7I/R7mlBMH8f7xon22PGdVSwPnGh0lZ2m7 6z2yOXAcctr0Vabyk7YA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qMITG-009SOs-13; Thu, 20 Jul 2023 01:28:46 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMITB-009SMO-0M for linux-arm-kernel@lists.infradead.org; Thu, 20 Jul 2023 01:28:42 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b9ecf0cb4cso1593965ad.2 for ; Wed, 19 Jul 2023 18:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689816518; x=1690421318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WDGT67Q+ic1nejZuLGS46+I/MVwpubEr1pR0ugjy0IU=; b=eqUPBahja8GTfVR6T6fFNkk2833efQusNbZx+/WiUnuJ4kY/GBoQIUsDwZ/MP3Lusy F/ZMLqgaEQ9OL4AOnwKeWYtcAfbDHs5M195JDiqgIlbeyJe7ps3obAo2OPZCAtQGtIUl y+mfY0MDjUmB1+7V/1DuBg5bJYAsKbms9z0SCDU/N3vMohYXzS6D6RCyev1T/K+HnVVI E036YQ3eCNDNCGP+Z6JBnea7Nx9ZlSZNQhJYr7shN/AcUPTcdeWA+4+FnM6mvzHwHv2K lWNXwHnd3PrMc0g/jjNZrA86u58+hOYGuZfrCs1l1EOxU2lRshLeCVZLfe4k3zmivwNM zvbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689816518; x=1690421318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WDGT67Q+ic1nejZuLGS46+I/MVwpubEr1pR0ugjy0IU=; b=d21oNxqF3441LJvknHKc0vteBpEvFSYv1+wg7JXDT+uatf3xXqZNCWLfLKKIIgWN84 FYXRjR4ixwv9pdNmAsshLeUUtyfBN8ArAeQ2r5n8Xdq8UYFAYeovllBdRASluwYQHh+e 9r92gAqLqcP/ewEk1LTFa9nAprAqv9SMo+FYp72itWphaPhn1niwFh4dRm4wP4QGGW8V HF+25+H2vLHVIkhl3rsCiZrD5KNRJqlzD20fjzjZWZspMIkq4MaK0z3F5Y44qwlFhTK5 RNTslNru4pVfAS5RSp541yRhUIE5W3Iax148GtQK0gJreVU4l4Z4/LUQZ10FYdSAFgHJ U3Ww== X-Gm-Message-State: ABy/qLZbB0RFamdL4eWHw3gMz+G71x6hc/D0/h11XbFP/H5GnEHDolkG xd1BK/mBBNCZJ74EqJbjXP1TrJNsEYw= X-Google-Smtp-Source: APBJJlEhuwr7n6DNGJ88bgpAmDcrLbybNZ+8zRVk9zTgXhTN0mbnD3ADnzhKzc0aNPcLpdskJYyXyw== X-Received: by 2002:a17:902:9689:b0:1b8:8dab:64e8 with SMTP id n9-20020a170902968900b001b88dab64e8mr3762203plp.36.1689816518213; Wed, 19 Jul 2023 18:28:38 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id jc18-20020a17090325d200b001b1a2c14a4asm4673998plb.38.2023.07.19.18.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 18:28:37 -0700 (PDT) From: Jacky Huang To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, soc@kernel.org, mjchen@nuvoton.com, schung@nuvoton.com, Jacky Huang Subject: [PATCH 2/3] arm64: dts: nuvoton: Add rtc for ma35d1 Date: Thu, 20 Jul 2023 01:28:25 +0000 Message-Id: <20230720012826.430026-3-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230720012826.430026-1-ychuang570808@gmail.com> References: <20230720012826.430026-1-ychuang570808@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230719_182841_151377_8DA0D160 X-CRM114-Status: GOOD ( 11.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jacky Huang Add rtc controller support to the dtsi of ma35d1 SoC and enable rtc on SOM and IoT boards. Signed-off-by: Jacky Huang --- arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts | 4 ++++ arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts | 4 ++++ arch/arm64/boot/dts/nuvoton/ma35d1.dtsi | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts b/arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts index b89e2be6abae..b3be4331abcf 100644 --- a/arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts +++ b/arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts @@ -54,3 +54,7 @@ &clk { "integer", "integer"; }; + +&rtc { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts b/arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts index a1ebddecb7f8..9858788a589c 100644 --- a/arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +++ b/arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts @@ -54,3 +54,7 @@ &clk { "integer", "integer"; }; + +&rtc { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/nuvoton/ma35d1.dtsi b/arch/arm64/boot/dts/nuvoton/ma35d1.dtsi index 781cdae566a0..394395bfd3ae 100644 --- a/arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +++ b/arch/arm64/boot/dts/nuvoton/ma35d1.dtsi @@ -95,6 +95,14 @@ clk: clock-controller@40460200 { clocks = <&clk_hxt>; }; + rtc: rtc@40410000 { + compatible = "nuvoton,ma35d1-rtc"; + reg = <0x0 0x40410000 0x0 0x200>; + interrupts = ; + clocks = <&clk RTC_GATE>; + status = "disabled"; + }; + uart0: serial@40700000 { compatible = "nuvoton,ma35d1-uart"; reg = <0x0 0x40700000 0x0 0x100>; From patchwork Thu Jul 20 01:28:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13319693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82C84C001B0 for ; Thu, 20 Jul 2023 01:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ALK8mk4ZmW1gJnhrcXkQy76+hvasNpA3l3XZHYokl3k=; b=NCp+agXLoCrnsa Sbd03Yg869dtENzbCwA/tic4lDL8+r1ZFr16rXFTM3AahsPniYCYRSpCsReIKH/S85XqcmdQZ1HQW IAWKJsdttaUzPRY1mDBbfcccuNVkOPklZoq/m9CX7z6fw466IoSvZjam+9DOUycWEOYct1kOhSC5S lrng99+0TP4pUX+CgMsXImPOEPfTvhC2P7OsykwIaeMLouP9zMFnGIrxUzZdemg4r8lmMLX2oPTh+ FidHsqeTf9+2X4sXVmKAAliQp5wFLA0tOr8PGYLPEU4ehZpA+0eyWChD4k0befcZw0GdTTm/d92af Xy3bqALRX0niNvpU7qcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qMITR-009SRC-09; Thu, 20 Jul 2023 01:28:57 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMITD-009SN7-2j for linux-arm-kernel@lists.infradead.org; Thu, 20 Jul 2023 01:28:45 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b8bd586086so1869665ad.2 for ; Wed, 19 Jul 2023 18:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689816521; x=1690421321; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vF98fHpwax0Zc0/s3DhXChVek/qggsLafsYLHscMqpE=; b=JJ/ZQm5mNhv/s6ghFu0gO4ZT0Fs4A6LcMJ635qvnnghcNt6qAsAkzz9bNoIlOryydJ CA7QidGqUe+bDS3C5fYLvbLF+eaHVBKTH9p5X9fU98dAyQQ3UASZRxZWdtJWGEnHkWAo /w0ZMy9RRsAORJHI2iAvPuvMXb7SulnnkuT/rA3glN03CtpB5Q6LhR5igW41wOk0lbJI Qc+6O1v7SrFHNdPAgrW6vmjWzjf6oS72vMZ0qOxERCA0+xFUHO28afslEQcW8LAXGWYw zupB2LJdgro8swbYMBRi7dZmERBQwQq7Bj8WrUH4m0vvYXwo1UDufLQxmNEL4QGZscCf j6XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689816521; x=1690421321; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vF98fHpwax0Zc0/s3DhXChVek/qggsLafsYLHscMqpE=; b=jfO7iDKynLHtIs6eagyGxUkXrIgrbpikShYq1qz7P+gaBHvavMe2a/M9hHYUxEiXOi qsgX0+W334NoOrmNUy9MYxXl+NA5OAa+aHP7S4B7oYFU2mahEvgbbW6ot4gh8JSDuS/H L+KyqQTc9duE6PsYzX4RywAqzqKODWT2hwxfm5j7afLhxfOKJitdbZQBmSWZRRa100lv sOAaELgz0An62A+0Trl8Jbq8HlP0tyLw8ilZjZYv9c5MOU5P2/v6in28fSffOOWDB+5I /L91hgF0ZLim3IPQVj2q8YcRU2Iu9pkdtGcXSetGl8sA8cRyFg5Do2jqk9olBTun2ogj J6qw== X-Gm-Message-State: ABy/qLYYbh+cJObeC7WOykaokmse7oUocv/F6JNojG5CX+vFDzC7FDzS mEdnFCMlYORqiuSifAjDtzI= X-Google-Smtp-Source: APBJJlGv2NNq1pJpkuA+XM/BsZ15tBeCSl5UdI8m9KcIIjgkfVJpPAVrqgxpQJ4d7JVa62oTRaMI2A== X-Received: by 2002:a17:902:ba8f:b0:1b8:5bd0:fe12 with SMTP id k15-20020a170902ba8f00b001b85bd0fe12mr3979821pls.16.1689816520861; Wed, 19 Jul 2023 18:28:40 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id jc18-20020a17090325d200b001b1a2c14a4asm4673998plb.38.2023.07.19.18.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 18:28:40 -0700 (PDT) From: Jacky Huang To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, soc@kernel.org, mjchen@nuvoton.com, schung@nuvoton.com, Jacky Huang Subject: [PATCH 3/3] rtc: Add driver for nuvoton ma35d1 rtc controller Date: Thu, 20 Jul 2023 01:28:26 +0000 Message-Id: <20230720012826.430026-4-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230720012826.430026-1-ychuang570808@gmail.com> References: <20230720012826.430026-1-ychuang570808@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230719_182843_884122_CE399E02 X-CRM114-Status: GOOD ( 26.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jacky Huang The ma35d1 rtc controller provides real-time and calendar messaging capabilities. It supports programmable time tick and alarm match interrupts. The time and calendar messages are expressed in BCD format. This driver supports the built-in rtc controller of the ma35d1. It enables setting and reading the rtc time and configuring and reading the rtc alarm. Signed-off-by: Jacky Huang --- drivers/rtc/Kconfig | 11 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-ma35d1.c | 371 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 383 insertions(+) create mode 100644 drivers/rtc/rtc-ma35d1.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 05f4b2d66290..95ddd8f616f4 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1929,6 +1929,17 @@ config RTC_DRV_TI_K3 This driver can also be built as a module, if so, the module will be called "rtc-ti-k3". +config RTC_DRV_MA35D1 + tristate "Nuvoton MA35D1 RTC" + depends on ARCH_MA35 || COMPILE_TEST + select REGMAP_MMIO + help + If you say yes here you get support for the Nuvoton MA35D1 + On-Chip Real Time Clock. + + This driver can also be built as a module, if so, the module + will be called "rtc-ma35d1". + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index fd209883ee2e..763c9cb5dde1 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -88,6 +88,7 @@ obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o +obj-$(CONFIG_RTC_DRV_MA35D1) += rtc-ma35d1.o obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o obj-$(CONFIG_RTC_DRV_MAX6916) += rtc-max6916.o diff --git a/drivers/rtc/rtc-ma35d1.c b/drivers/rtc/rtc-ma35d1.c new file mode 100644 index 000000000000..48c991a8f669 --- /dev/null +++ b/drivers/rtc/rtc-ma35d1.c @@ -0,0 +1,371 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * RTC driver for Nuvoton MA35D1 + * + * Copyright (C) 2023 Nuvoton Technology Corp. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* MA35D1 RTC Control Registers */ +#define MA35_REG_RTC_INIT 0x00 +#define MA35_REG_RTC_SINFASTS 0x04 +#define MA35_REG_RTC_FREQADJ 0x08 +#define MA35_REG_RTC_TIME 0x0c +#define MA35_REG_RTC_CAL 0x10 +#define MA35_REG_RTC_CLKFMT 0x14 +#define MA35_REG_RTC_WEEKDAY 0x18 +#define MA35_REG_RTC_TALM 0x1c +#define MA35_REG_RTC_CALM 0x20 +#define MA35_REG_RTC_LEAPYEAR 0x24 +#define MA35_REG_RTC_INTEN 0x28 +#define MA35_REG_RTC_INTSTS 0x2c +#define MA35_REG_RTC_TICK 0x30 + +/* register MA35_REG_RTC_INIT */ +#define RTC_INIT_ACTIVE BIT(0) +#define RTC_INIT_MAGIC_CODE 0xa5eb1357 + +/* register MA35_REG_RTC_CLKFMT */ +#define RTC_CLKFMT_24HEN BIT(0) +#define RTC_CLKFMT_DCOMPEN BIT(16) + +/* register MA35_REG_RTC_INTEN */ +#define RTC_INTEN_ALMIEN BIT(0) +#define RTC_INTEN_TICKIEN BIT(1) +#define RTC_INTEN_CLKFIEN BIT(24) +#define RTC_INTEN_CLKSTIEN BIT(25) + +/* register MA35_REG_RTC_INTSTS */ +#define RTC_INTSTS_ALMIF BIT(0) +#define RTC_INTSTS_TICKIF BIT(1) +#define RTC_INTSTS_CLKFIF BIT(24) +#define RTC_INTSTS_CLKSTIF BIT(25) + +#define RTC_INIT_TIMEOUT 250 + +struct ma35_rtc { + int irq_num; + void __iomem *rtc_reg; + struct rtc_device *rtcdev; +}; + +struct ma35_bcd_time { + int bcd_sec; + int bcd_min; + int bcd_hour; + int bcd_mday; + int bcd_mon; + int bcd_year; +}; + +static u32 rtc_reg_read(struct ma35_rtc *p, u32 offset) +{ + return __raw_readl(p->rtc_reg + offset); +} + +static inline void rtc_reg_write(struct ma35_rtc *p, u32 offset, u32 value) +{ + __raw_writel(value, p->rtc_reg + offset); +} + +static irqreturn_t ma35d1_rtc_interrupt(int irq, void *data) +{ + struct ma35_rtc *rtc = (struct ma35_rtc *)data; + unsigned long events = 0, rtc_irq; + + rtc_irq = rtc_reg_read(rtc, MA35_REG_RTC_INTSTS); + + if (rtc_irq & RTC_INTSTS_ALMIF) { + rtc_reg_write(rtc, MA35_REG_RTC_INTSTS, RTC_INTSTS_ALMIF); + events |= RTC_AF | RTC_IRQF; + } + + if (rtc_irq & RTC_INTSTS_TICKIF) { + rtc_reg_write(rtc, MA35_REG_RTC_INTSTS, RTC_INTSTS_TICKIF); + events |= RTC_UF | RTC_IRQF; + } + + rtc_update_irq(rtc->rtcdev, 1, events); + + return IRQ_HANDLED; +} + +static int ma35d1_rtc_init(struct ma35_rtc *ma35_rtc, u32 ms_timeout) +{ + const unsigned long timeout = jiffies + msecs_to_jiffies(ms_timeout); + + do { + if (rtc_reg_read(ma35_rtc, MA35_REG_RTC_INIT) & RTC_INIT_ACTIVE) + return 0; + + rtc_reg_write(ma35_rtc, MA35_REG_RTC_INIT, RTC_INIT_MAGIC_CODE); + + mdelay(1); + + } while (time_before(jiffies, timeout)); + + return -ETIMEDOUT; +} + +static int ma35d1_rtc_bcd2bin(u32 time, u32 cal, u32 wday, struct rtc_time *tm) +{ + tm->tm_mday = bcd2bin(cal >> 0); + tm->tm_mon = bcd2bin(cal >> 8); + tm->tm_mon = tm->tm_mon - 1; + tm->tm_year = bcd2bin(cal >> 16) + 100; + + tm->tm_sec = bcd2bin(time >> 0); + tm->tm_min = bcd2bin(time >> 8); + tm->tm_hour = bcd2bin(time >> 16); + + tm->tm_wday = wday; + + return rtc_valid_tm(tm); +} + +static int ma35d1_rtc_alarm_bcd2bin(u32 talm, u32 calm, struct rtc_time *tm) +{ + tm->tm_mday = bcd2bin(calm >> 0); + tm->tm_mon = bcd2bin(calm >> 8); + tm->tm_mon = tm->tm_mon - 1; + tm->tm_year = bcd2bin(calm >> 16) + 100; + + tm->tm_sec = bcd2bin(talm >> 0); + tm->tm_min = bcd2bin(talm >> 8); + tm->tm_hour = bcd2bin(talm >> 16); + + return rtc_valid_tm(tm); +} + +static void ma35d1_rtc_bin2bcd(struct device *dev, struct rtc_time *settm, + struct ma35_bcd_time *gettm) +{ + gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0; + gettm->bcd_mon = bin2bcd((settm->tm_mon + 1)) << 8; + + if (settm->tm_year < 100) { + dev_warn(dev, "The year will be between 1970-1999, right?\n"); + gettm->bcd_year = bin2bcd(settm->tm_year) << 16; + } else { + gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; + } + + gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0; + gettm->bcd_min = bin2bcd(settm->tm_min) << 8; + gettm->bcd_hour = bin2bcd(settm->tm_hour) << 16; +} + +static int ma35d1_alarm_irq_enable(struct device *dev, u32 enabled) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + u32 reg_ien; + + reg_ien = rtc_reg_read(rtc, MA35_REG_RTC_INTEN); + + if (enabled) + rtc_reg_write(rtc, MA35_REG_RTC_INTEN, reg_ien | RTC_INTEN_ALMIEN); + else + rtc_reg_write(rtc, MA35_REG_RTC_INTEN, reg_ien & ~RTC_INTEN_ALMIEN); + + return 0; +} + +static int ma35d1_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + u32 time, cal, wday; + + time = rtc_reg_read(rtc, MA35_REG_RTC_TIME); + cal = rtc_reg_read(rtc, MA35_REG_RTC_CAL); + wday = rtc_reg_read(rtc, MA35_REG_RTC_WEEKDAY); + + return ma35d1_rtc_bcd2bin(time, cal, wday, tm); +} + +static int ma35d1_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + struct ma35_bcd_time gettm; + u32 val; + + ma35d1_rtc_bin2bcd(dev, tm, &gettm); + + val = gettm.bcd_mday | gettm.bcd_mon | gettm.bcd_year; + rtc_reg_write(rtc, MA35_REG_RTC_CAL, val); + + val = gettm.bcd_sec | gettm.bcd_min | gettm.bcd_hour; + rtc_reg_write(rtc, MA35_REG_RTC_TIME, val); + + val = tm->tm_wday; + rtc_reg_write(rtc, MA35_REG_RTC_WEEKDAY, val); + + return 0; +} + +static int ma35d1_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + u32 talm, calm; + + talm = rtc_reg_read(rtc, MA35_REG_RTC_TALM); + calm = rtc_reg_read(rtc, MA35_REG_RTC_CALM); + + return ma35d1_rtc_alarm_bcd2bin(talm, calm, &alrm->time); +} + +static int ma35d1_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + struct ma35_bcd_time tm; + unsigned long val; + + ma35d1_rtc_bin2bcd(dev, &alrm->time, &tm); + + val = tm.bcd_mday | tm.bcd_mon | tm.bcd_year; + rtc_reg_write(rtc, MA35_REG_RTC_CALM, val); + + val = tm.bcd_sec | tm.bcd_min | tm.bcd_hour; + rtc_reg_write(rtc, MA35_REG_RTC_TALM, val); + + return 0; +} + +static const struct rtc_class_ops ma35d1_rtc_ops = { + .read_time = ma35d1_rtc_read_time, + .set_time = ma35d1_rtc_set_time, + .read_alarm = ma35d1_rtc_read_alarm, + .set_alarm = ma35d1_rtc_set_alarm, + .alarm_irq_enable = ma35d1_alarm_irq_enable, +}; + +static int ma35d1_rtc_probe(struct platform_device *pdev) +{ + struct ma35_rtc *ma35_rtc; + struct clk *clk; + u32 regval; + int err; + + ma35_rtc = devm_kzalloc(&pdev->dev, sizeof(struct ma35_rtc), + GFP_KERNEL); + if (!ma35_rtc) + return -ENOMEM; + + ma35_rtc->rtc_reg = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(ma35_rtc->rtc_reg)) + return PTR_ERR(ma35_rtc->rtc_reg); + + clk = of_clk_get(pdev->dev.of_node, 0); + if (IS_ERR(clk)) { + err = PTR_ERR(clk); + dev_err(&pdev->dev, "failed to get core clk: %d\n", err); + return -ENOENT; + } + err = clk_prepare_enable(clk); + if (err) + return -ENOENT; + + platform_set_drvdata(pdev, ma35_rtc); + + ma35_rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, + &ma35d1_rtc_ops, THIS_MODULE); + if (IS_ERR(ma35_rtc->rtcdev)) { + dev_err(&pdev->dev, "rtc device register failed\n"); + return PTR_ERR(ma35_rtc->rtcdev); + } + + err = ma35d1_rtc_init(ma35_rtc, RTC_INIT_TIMEOUT); + if (err) + return err; + + regval = rtc_reg_read(ma35_rtc, MA35_REG_RTC_CLKFMT); + regval |= RTC_CLKFMT_24HEN; + rtc_reg_write(ma35_rtc, MA35_REG_RTC_CLKFMT, regval); + + ma35_rtc->irq_num = platform_get_irq(pdev, 0); + + if (devm_request_irq(&pdev->dev, ma35_rtc->irq_num, ma35d1_rtc_interrupt, + IRQF_NO_SUSPEND, "ma35d1rtc", ma35_rtc)) { + dev_err(&pdev->dev, "ma35d1 RTC request irq failed\n"); + return -EBUSY; + } + + regval = rtc_reg_read(ma35_rtc, MA35_REG_RTC_INTEN); + regval |= RTC_INTEN_TICKIEN; + rtc_reg_write(ma35_rtc, MA35_REG_RTC_INTEN, regval); + + device_init_wakeup(&pdev->dev, true); + + return 0; +} + +static int __exit ma35d1_rtc_remove(struct platform_device *pdev) +{ + device_init_wakeup(&pdev->dev, false); + + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static int ma35d1_rtc_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct ma35_rtc *ma35_rtc = platform_get_drvdata(pdev); + u32 regval; + + if (device_may_wakeup(&pdev->dev)) + enable_irq_wake(ma35_rtc->irq_num); + + regval = rtc_reg_read(ma35_rtc, MA35_REG_RTC_INTEN); + regval &= ~RTC_INTEN_TICKIEN; + rtc_reg_write(ma35_rtc, MA35_REG_RTC_INTEN, regval); + + return 0; +} + +static int ma35d1_rtc_resume(struct platform_device *pdev) +{ + struct ma35_rtc *ma35_rtc = platform_get_drvdata(pdev); + u32 regval; + + if (device_may_wakeup(&pdev->dev)) + disable_irq_wake(ma35_rtc->irq_num); + + regval = rtc_reg_read(ma35_rtc, MA35_REG_RTC_INTEN); + regval |= RTC_INTEN_TICKIEN; + rtc_reg_write(ma35_rtc, MA35_REG_RTC_INTEN, regval); + + return 0; +} + +static const struct of_device_id ma35d1_rtc_of_match[] = { + { .compatible = "nuvoton,ma35d1-rtc", }, + {}, +}; +MODULE_DEVICE_TABLE(of, ma35d1_rtc_of_match); + +static struct platform_driver ma35d1_rtc_driver = { + .remove = __exit_p(ma35d1_rtc_remove), + .suspend = ma35d1_rtc_suspend, + .resume = ma35d1_rtc_resume, + .probe = ma35d1_rtc_probe, + .driver = { + .name = "rtc-ma35d1", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(ma35d1_rtc_of_match), + }, +}; + +module_platform_driver(ma35d1_rtc_driver); + +MODULE_AUTHOR("Min-Jen Chen "); +MODULE_DESCRIPTION("MA35D1 RTC driver"); +MODULE_LICENSE("GPL");