From patchwork Tue Aug 22 10:09:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13360453 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 C4DD7EE49A3 for ; Tue, 22 Aug 2023 10:10:32 +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=tTyJb9soFrwbT1bTSYUsjLY8MiW/nmh4ZVh3R6G6o8A=; b=WdstndBeTcgQKo KqXO58ywo2id/c97+1HFNOym0w6VXg7/8CR/kSg7AtyDBXfwzjuo58w8cgPd0Wl1sCPwlzE+d0Y/F 0MeT3bRSyWHbgiDZTtqmBocZXZ3V/YQEZ2lCStfN9VxNWC4HocQJYjkBnxSXQ4/OPI2+Qd4gkAv3K /GuubpIVAIJpLigLywgTae5+lBh5SKMXK93ybfOzKnyEzpXzhVPXSmADaZkHyYvQxHZbSX5W90Z96 MgK5pPr330xy4oOHQEj4QrwtEhFAF6EvMrcJwACIL8NplRbV+7bN1yLv52Kn4+8ELD4iA3RsWNfqY 7qhzZzSD36EZahEyS99g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYOKr-00FbQA-0x; Tue, 22 Aug 2023 10:10:05 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYOKm-00FbNd-0X for linux-arm-kernel@lists.infradead.org; Tue, 22 Aug 2023 10:10:01 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-563f8e8a53dso2454725a12.3 for ; Tue, 22 Aug 2023 03:09:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692698997; x=1693303797; 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=fpAcRisUyrskcWS9AV1ql1Z9KFMGwKdSa1ZIJWKbDtE=; b=di/waxyU1RwzQOGCQUjWPIcmGm7nMxFb+Crsiw0HiH7uQg6JdWYPXH/zipzX2ufxYA xgCh6OBoTadk39EKFNSbkLCXyg8RAaue/3nMYWljlciGnw6FKpvloIJWdkk8CYNnECuh 8VfIKCNBCyd+BaVN2kF634O289R3duwAU72vo5u/mO1RVN0UljuufG34VFcBaYoxGSOM umdVCGzy1R4jejs7DX6LNhdyz8vZJzV4I4io4O6eB+N9LJzecNWOrlfTFvOr8/ayMDVS mHbSIqc9tOWPqkW7mwhnAYyftFuVMdnTREu+KSv3BLU1E9vWMB2H7ytzARsPhkvVm9Il zsEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692698997; x=1693303797; 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=fpAcRisUyrskcWS9AV1ql1Z9KFMGwKdSa1ZIJWKbDtE=; b=B47V4iQ0r6zy5TLvzjYhE18nvzYpdd8jnrBJRr0MNjkMquJ8k4QeK2sahFZGEHpVTS 0r25p9hzpt6/hOVyOinL+WvnEVQz7/H6LQhpq0Rhg3okVLUEkKBUFXlaeOG3xy48U0Dz iONyAplMhy45aMl+WYstjwrDoJGwUg65g4pt+7giif+pN1h3WuVLhI/ZmIh+1NLl1Q/s bqIaUl9E5uzvt2KXCIFhYA11QeRyaBoJ/dorZESqNtcnnAZVUFSLu89tjTJeWiQ/0DoZ n/ZNfAoIqGFnS8NGW56jhRuqWT2BuuBVaULAahtp0Y4gEUXld9xFYcEnxLIApgiJej+G kaTg== X-Gm-Message-State: AOJu0Yx8suku6M/JS/TeTYaqap9iG6/YWHfXKGPoHBhskoAeULGmkr3u DlHkdf2VQiCzOIeG864tT+w= X-Google-Smtp-Source: AGHT+IF4shcelW6ONoQrgnmBOad91csKV+H7SubrAKxl9uy8OFFTv+GX3CRlybnzf5XbrvR+aJfwxw== X-Received: by 2002:a17:90a:3ec1:b0:26d:4642:1bd7 with SMTP id k59-20020a17090a3ec100b0026d46421bd7mr6180562pjc.34.1692698996974; Tue, 22 Aug 2023 03:09:56 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id s10-20020a17090a948a00b00263cca08d95sm9278975pjo.55.2023.08.22.03.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 03:09:56 -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, mjchen@nuvoton.com, schung@nuvoton.com, Jacky Huang , Krzysztof Kozlowski Subject: [PATCH v3 1/3] dt-bindings: rtc: Add Nuvoton ma35d1 rtc Date: Tue, 22 Aug 2023 10:09:46 +0000 Message-Id: <20230822100948.1366487-2-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230822100948.1366487-1-ychuang570808@gmail.com> References: <20230822100948.1366487-1-ychuang570808@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_031000_200922_745449A4 X-CRM114-Status: GOOD ( 12.97 ) 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 describing the Nuvoton ma35d1 rtc controller. Signed-off-by: Jacky Huang Reviewed-by: Krzysztof Kozlowski --- .../bindings/rtc/nuvoton,ma35d1-rtc.yaml | 48 +++++++++++++++++++ 1 file changed, 48 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..5e4ade803eed --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/nuvoton,ma35d1-rtc.yaml @@ -0,0 +1,48 @@ +# 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 Real Time Clock + +maintainers: + - Min-Jen Chen + +allOf: + - $ref: rtc.yaml# + +properties: + compatible: + enum: + - nuvoton,ma35d1-rtc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + +unevaluatedProperties: false + +examples: + - | + #include + #include + rtc@40410000 { + compatible = "nuvoton,ma35d1-rtc"; + reg = <0x40410000 0x200>; + interrupts = ; + clocks = <&clk RTC_GATE>; + }; + +... From patchwork Tue Aug 22 10:09:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13360454 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 13702EE4996 for ; Tue, 22 Aug 2023 10:10:46 +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=1lT4/iwYFe++ZJ xTBfbs+7GGXIn4FjBBv+Dq8BJYNPLmEv6pP4qsOVEp9o6fywqZW5KzD8cfowDtIdrbvgulQt2jAwz 9PIXxTqa2emldJkwIGL2kba/bgYll9A3RH01GuoZlU+YZg5Xa6OuNUmggocx5j24RzSuQTsc1vzeI I1ZaKnp+FKH0v3tfXnygGRVztnwmL5rfPlNZPTEMCnXKHp6+hdPbl8jYRGu0v2eRYYRSsMrjvfuhW aYqEoA2F7NbUH8qOj22u2nHNjiieANKeS9xjdMKfoZjg05JlhpGLBr3XOvv/gU03bP5pjVejtwB4q m/nXrxwEWDZkLeLOY0Zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYOL4-00FbT6-0k; Tue, 22 Aug 2023 10:10:18 +0000 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYOKn-00FbOJ-1b for linux-arm-kernel@lists.infradead.org; Tue, 22 Aug 2023 10:10:02 +0000 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6bd0425ad4fso3084532a34.2 for ; Tue, 22 Aug 2023 03:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692698999; x=1693303799; 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=LG4MRSC7npmqM5v4ypEN2DwtIDGV9Ah4DOUM6MEVZUMKX9OK5uOLIj/PDYxLIPGVjd GTvzBbr8pp5v3vEJ38Q7gcAROE1ZW67QxdkltOtD0EBgqz/alqB06NKas/nzdN025zcf FIjH7z7RZbNfUZXTndqURJVV8j+kLD8HI6WrSreP5D7mUaQJffWZi+oNHo8j07WI8PXD SnxYAHHpptdO/k2Q+okKoKoEjA+79yDs3jWJGgxVqTqvYZ8f4kKSOAHn6fH2e+HbqWvO brzatVPWh9JRF6IxnY5y5oOwxV/ENlUcQyzTBqZBp70K2aOugnVo0u4iNgaTLpy47uFd O2Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692698999; x=1693303799; 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=LwDGfqOKa1nwgGI3/VgXKoOwYY3+rYbbLCn8aAL8XI594icrkykW7/QYmPMunvLYMg j8z02iAq8x+sgGAHM1ifNUCyPzyPLx4F75lazhaQ/wTO4tyDg/1XLWLbUBnl1FW4P+3T e7ux7TxjWFsFmMTPcZJUUphe8DJzUSqdFOnEaV7UcnWIDHRWFQOM4SPeF/EA6wTDRKx4 dNnfJlTMTuEoZfdOCyl92qleIABe9FsTz5deq89uVmAh02vZNG2prTpll3u21TGz8WUz xXmhIiYAwY8ihaTIJl0sr9e8hcq3PKEBBYYGop8swt/7CcEPmoZDHT/o8D5slg6p6tzI LRkw== X-Gm-Message-State: AOJu0YxtBQ/IBpDmxQe8N//zJ90UKO5NDAUmRQXFtIxDBYUWX19B+w3M A2VZlIaJp0w29/YketaNsGM= X-Google-Smtp-Source: AGHT+IFqJs+8P0h5g5uFmdxTSWtrDryAe+2Ys7rZBcG+dYooxilXoWmF0cXX8oPdCL+ghCLEOrnOHg== X-Received: by 2002:a05:6870:610a:b0:1bb:7f9f:2fc5 with SMTP id s10-20020a056870610a00b001bb7f9f2fc5mr11455924oae.17.1692698999223; Tue, 22 Aug 2023 03:09:59 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id s10-20020a17090a948a00b00263cca08d95sm9278975pjo.55.2023.08.22.03.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 03:09:59 -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, mjchen@nuvoton.com, schung@nuvoton.com, Jacky Huang Subject: [PATCH v3 2/3] arm64: dts: nuvoton: Add rtc for ma35d1 Date: Tue, 22 Aug 2023 10:09:47 +0000 Message-Id: <20230822100948.1366487-3-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230822100948.1366487-1-ychuang570808@gmail.com> References: <20230822100948.1366487-1-ychuang570808@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_031001_533090_8A5F158E 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 Tue Aug 22 10:09:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13360455 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 807E4EE49A3 for ; Tue, 22 Aug 2023 10:10:50 +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=m9YLhLawEaiYpU1tTlX9iw9E+0Qn9EAk9aOuCwHG6LY=; b=o4OX/nf0FzYpUA yle9HH09ekSHuGxoWHaL/mV8gdgMN1uGDJ9LV9TLW8uOhpCw1pL6PN2cNN3rXPAwNeSerplE6UT34 ZGKNfM2ewdeGNuoG/M55C6OVJvVT2TZFAdwW236JnNJkRXGW/cT+4yDhyAq2+2Zufv5tRzP+EM9s8 o5Ow0rjr4eQD+65AzvMiE3MzwZOSWSAolGTTIPU1y7Ogy3VrmA9sTX2gmG4yswNnJb5gf2wJfnVM1 hX0RUwEyd/21Sd85buyqmGP44HA+Tq6ZkLouvovMLqMdC8od1woOwV4G2ECVB5cn/sOR7piqLPmXv dzlC3mqcKwemcF+yQojg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYOL4-00FbTK-2Q; Tue, 22 Aug 2023 10:10:18 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYOKr-00FbPa-1X for linux-arm-kernel@lists.infradead.org; Tue, 22 Aug 2023 10:10:07 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-26b67b38b61so2594238a91.0 for ; Tue, 22 Aug 2023 03:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692699002; x=1693303802; 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=RsNuC0uf0L8mG71kavK6xjbz+UT4AWgHgQ8qAuimw+8=; b=dj7he3KT95xCDDKd7JvaVC+vWEZi1XeAJG0cTkIkHnUzM2r6rtYcm5lsGku4JzWxFA kWW4tSKmZbrNPPfsZZRsMPqBTrDEXYckMrclFozEwgqOdVZoEROGwGFHsTS3wsBGYRZw Zw+EA8w/MJlgkb7CubwlX5l6t9bZNh06V7ObwZx9HDDJcrWf0MLxzSfPSWvuxaUs5CLA lUkg3uu249rQ7L44LCdnTTDGTDxjGjNhiPxyLid8eTrWyuK90UMW5x49NLBVOZTx7Eeb cN4WXQppN3lkVPB+MW9mvEH6LDdBZ4y4r3/Gr55/F+Sgfxv7wRnBk111xT8YQ90jfi8U tIqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692699002; x=1693303802; 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=RsNuC0uf0L8mG71kavK6xjbz+UT4AWgHgQ8qAuimw+8=; b=C2fdXScBRQOSxpTiaLKnFb5DbcOzXSXG4ZjHyNlCqhzYtpB3EK00+cbGh5DO4VBQIN XTQQxTVe9YX0Ck058ofAQnYBId12v9BNI/PrfLfNwD2pfeEyyuXwRgbgBmecHDlDlmIA oJayOCDWkasytZCQy70n6jhT/A/SNvtROa1EpORtsD6VvtwMzy7QMueZG2njqgnwmfmd 77ciWBcelo7yypdcV+Mu1umT5kbbM24146GymjTqOzhgglpWybp245XThat60DAb551W wn/yOqQ7/JjcIuNCEip69Qo1rKt/v2HAOJk1BGmW0gjSd2dSKrl23VjNi2g5hzerxrJq Bt2A== X-Gm-Message-State: AOJu0YwKlIwTMLfdbsRYP1p5tNHAXAxWgYL2Oe8Y4PqhYQ0SVmqzfe0d hNbmec8VkNtCdmqsMjKqqzQ= X-Google-Smtp-Source: AGHT+IHWkmJpA7CbzOTDIT3FY+FK1T+HeWzaunx8/ihJ94e1/5J4n5tSRyWnNqovorp8W7CnD1ycug== X-Received: by 2002:a17:90a:fd14:b0:26d:ae3:f6a7 with SMTP id cv20-20020a17090afd1400b0026d0ae3f6a7mr6148246pjb.21.1692699001664; Tue, 22 Aug 2023 03:10:01 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id s10-20020a17090a948a00b00263cca08d95sm9278975pjo.55.2023.08.22.03.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 03:10:01 -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, mjchen@nuvoton.com, schung@nuvoton.com, Jacky Huang Subject: [PATCH v3 3/3] rtc: Add driver for Nuvoton ma35d1 rtc controller Date: Tue, 22 Aug 2023 10:09:48 +0000 Message-Id: <20230822100948.1366487-4-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230822100948.1366487-1-ychuang570808@gmail.com> References: <20230822100948.1366487-1-ychuang570808@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_031005_541429_AA3DEE8F X-CRM114-Status: GOOD ( 26.01 ) 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 | 324 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 336 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..07c9a083a9d5 --- /dev/null +++ b/drivers/rtc/rtc-ma35d1.c @@ -0,0 +1,324 @@ +// 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 + +/* 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_UIEN 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_UIF 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; +}; + +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_UIF) { + rtc_reg_write(rtc, MA35_REG_RTC_INTSTS, RTC_INTSTS_UIF); + events |= RTC_UF | RTC_IRQF; + } + + rtc_update_irq(rtc->rtcdev, 1, events); + + return IRQ_HANDLED; +} + +static int ma35d1_rtc_init(struct ma35_rtc *rtc, u32 ms_timeout) +{ + const unsigned long timeout = jiffies + msecs_to_jiffies(ms_timeout); + + do { + if (rtc_reg_read(rtc, MA35_REG_RTC_INIT) & RTC_INIT_ACTIVE) + return 0; + + rtc_reg_write(rtc, MA35_REG_RTC_INIT, RTC_INIT_MAGIC_CODE); + + mdelay(1); + + } while (time_before(jiffies, timeout)); + + return -ETIMEDOUT; +} + +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; + + do { + 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); + } while (time != rtc_reg_read(rtc, MA35_REG_RTC_TIME) || + cal != rtc_reg_read(rtc, MA35_REG_RTC_CAL)); + + tm->tm_mday = bcd2bin(cal >> 0); + tm->tm_wday = wday; + 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); + + return rtc_valid_tm(tm); +} + +static int ma35d1_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + u32 val; + + val = bin2bcd(tm->tm_mday) << 0 | bin2bcd(tm->tm_mon + 1) << 8 | + bin2bcd(tm->tm_year - 100) << 16; + rtc_reg_write(rtc, MA35_REG_RTC_CAL, val); + + val = bin2bcd(tm->tm_sec) << 0 | bin2bcd(tm->tm_min) << 8 | + bin2bcd(tm->tm_hour) << 16; + 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); + + alrm->time.tm_mday = bcd2bin(calm >> 0); + alrm->time.tm_mon = bcd2bin(calm >> 8); + alrm->time.tm_mon = alrm->time.tm_mon - 1; + + alrm->time.tm_year = bcd2bin(calm >> 16) + 100; + + alrm->time.tm_sec = bcd2bin(talm >> 0); + alrm->time.tm_min = bcd2bin(talm >> 8); + alrm->time.tm_hour = bcd2bin(talm >> 16); + + return rtc_valid_tm(&alrm->time); +} + +static int ma35d1_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) +{ + struct ma35_rtc *rtc = dev_get_drvdata(dev); + unsigned long val; + + val = bin2bcd(alrm->time.tm_mday) << 0 | bin2bcd(alrm->time.tm_mon + 1) << 8 | + bin2bcd(alrm->time.tm_year - 100) << 16; + rtc_reg_write(rtc, MA35_REG_RTC_CALM, val); + + val = bin2bcd(alrm->time.tm_sec) << 0 | bin2bcd(alrm->time.tm_min) << 8 | + bin2bcd(alrm->time.tm_hour) << 16; + rtc_reg_write(rtc, MA35_REG_RTC_TALM, val); + + ma35d1_alarm_irq_enable(dev, alrm->enabled); + + 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 *rtc; + struct clk *clk; + u32 regval; + int ret; + + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + if (!rtc) + return -ENOMEM; + + rtc->rtc_reg = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(rtc->rtc_reg)) + return PTR_ERR(rtc->rtc_reg); + + clk = of_clk_get(pdev->dev.of_node, 0); + if (IS_ERR(clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(clk), "failed to find rtc clock\n"); + + ret = clk_prepare_enable(clk); + if (ret) + return ret; + + if (!(rtc_reg_read(rtc, MA35_REG_RTC_INIT) & RTC_INIT_ACTIVE)) { + ret = ma35d1_rtc_init(rtc, RTC_INIT_TIMEOUT); + if (ret) + return dev_err_probe(&pdev->dev, ret, "rtc init failed\n"); + } + + rtc->irq_num = platform_get_irq(pdev, 0); + + ret = devm_request_irq(&pdev->dev, rtc->irq_num, ma35d1_rtc_interrupt, + IRQF_NO_SUSPEND, "ma35d1rtc", rtc); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Failed to request rtc irq\n"); + + platform_set_drvdata(pdev, rtc); + + device_init_wakeup(&pdev->dev, true); + + rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rtc->rtcdev)) + return PTR_ERR(rtc->rtcdev); + + rtc->rtcdev->ops = &ma35d1_rtc_ops; + rtc->rtcdev->range_min = RTC_TIMESTAMP_BEGIN_2000; + rtc->rtcdev->range_max = RTC_TIMESTAMP_END_2099; + + ret = devm_rtc_register_device(rtc->rtcdev); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Failed to register rtc device\n"); + + regval = rtc_reg_read(rtc, MA35_REG_RTC_INTEN); + regval |= RTC_INTEN_UIEN; + rtc_reg_write(rtc, MA35_REG_RTC_INTEN, regval); + + return 0; +} + +static int ma35d1_rtc_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct ma35_rtc *rtc = platform_get_drvdata(pdev); + u32 regval; + + if (device_may_wakeup(&pdev->dev)) + enable_irq_wake(rtc->irq_num); + + regval = rtc_reg_read(rtc, MA35_REG_RTC_INTEN); + regval &= ~RTC_INTEN_UIEN; + rtc_reg_write(rtc, MA35_REG_RTC_INTEN, regval); + + return 0; +} + +static int ma35d1_rtc_resume(struct platform_device *pdev) +{ + struct ma35_rtc *rtc = platform_get_drvdata(pdev); + u32 regval; + + if (device_may_wakeup(&pdev->dev)) + disable_irq_wake(rtc->irq_num); + + regval = rtc_reg_read(rtc, MA35_REG_RTC_INTEN); + regval |= RTC_INTEN_UIEN; + rtc_reg_write(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 = { + .suspend = ma35d1_rtc_suspend, + .resume = ma35d1_rtc_resume, + .probe = ma35d1_rtc_probe, + .driver = { + .name = "rtc-ma35d1", + .of_match_table = ma35d1_rtc_of_match, + }, +}; + +module_platform_driver(ma35d1_rtc_driver); + +MODULE_AUTHOR("Ming-Jen Chen "); +MODULE_DESCRIPTION("MA35D1 RTC driver"); +MODULE_LICENSE("GPL");