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: 122947 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2825042vqt; Wed, 19 Jul 2023 18:55:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEBgt9uMYUs+ra9ZsPUPzPXxFjVlgdX4i3fpairrT/jYpTLgIHE5n/d1GSBK56Ocaqi3g7 X-Received: by 2002:a17:906:7798:b0:974:183a:54b6 with SMTP id s24-20020a170906779800b00974183a54b6mr3866180ejm.33.1689818134303; Wed, 19 Jul 2023 18:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689818134; cv=none; d=google.com; s=arc-20160816; b=ztnJuMOyVP7gISvTtIUVzn2GjYib/u8R6uBOsFDNf6d7xL4S5usvlfRtkb09wjT17K gsb8Eq9knzqkjgR1YZqh1wpwQU7+B+wxasC7h9wDelYWOgBqyyloxg67ZOQKz8nnUUHm mQ4lLLSpU+2mB/7o02cM471EKnXQAOqYeUZ+Vzo7mvc/k2huuLV0DxnjW29A252kv6+Z dz/MgibH4bDteazBh1NMvPCIsqr/1aCJnAQZeUOJrpW6ywnoaVCQNSTwT2luOc/hD8pL u6TJH6n1r+rvYTgzi1RkQ3bmMvkZN4aSvKE6lw7Ye1SEioBAlU1lVB8fvi+kwPOYSc7P HkEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PknmXnQirEOnubVOauabc0cJvIl8m6tNpWyxQZCD0N0=; fh=CuOU2zHMRvKBIxU3VBdQp/xZQgB1IU6H7AgQjHd0CZ4=; b=GBCwO23OzY9J8ovGYCo+PeMHf0kcNq02Nbs1ZtWiAqgxOnKXn9RwcCBNtYgPaPJyJi bwkH4tf1xu1NgvQd0LU4Q3rjpeRPrxYRA92OThRiqxaARzMOO1s3BY9Z9PoIv7Q0R2sV J604p0S39uJ12vv4Xo05KOocamCY1WWC2MgqL1QimY35fKzly9rjY2lTgy9wITeJ4Nqo EJI2Ke0S3Ru2HE/GcWTQxgW/Jw5eCDnLfpy4jhtdz/zgYPUe2YAZu/u4Ghgb8qKfr+0c t1yVywCHgQzjczqCnn7QZ+Xb9K7lw4YZTqsAKqranugcnCPJ9bQ4cKD7c0fYNACCnwKv ioYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=HlYK066k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z23-20020a1709063ad700b0098df03ffa69si3404780ejd.421.2023.07.19.18.55.02; Wed, 19 Jul 2023 18:55:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=HlYK066k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbjGTB3A (ORCPT + 99 others); Wed, 19 Jul 2023 21:29:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjGTB25 (ORCPT ); Wed, 19 Jul 2023 21:28:57 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 436FF2686; Wed, 19 Jul 2023 18:28:36 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b89114266dso2004995ad.0; 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=WkJSdyWosqbKiywAxNW8D+Um/hXQbrdoi2Et4ZyI2JCGNeY3TkGZ3Gfq3Qf9LyzyRl 7dbf3/mv5ERjoXwUjXvJOvumDVYT8KyziqzQGThSqOcTBhNgD2ZbuDx8jUDjKeCdtnXl xFRtsFy0I0FoDqOian6fxdaOPC5r39wv+et0j3ZosWjIGliAIRzerHSnsK7GRIyap+44 sveOO4eMLAmTJFmlqzzcgQXqIxaWTrcWGIPqoqm9IRTW+CDOWSVzvFqubgndt7Fr0NKf Rlxa6TE36se2lnXY01G4y/XNkBNL/QSYr+RL3TEdlDNHYkBK19b96p7S6zO48v5MTPMU 2ntw== X-Gm-Message-State: ABy/qLYK3u1EDOCMuVvX385zx2TDmQTgBvX+s6OL1cnrlwXD2vp9ZvHG FqpwRViaC+dc06B9sqkQ8xTS4tikTfA= 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771902739746505076 X-GMAIL-MSGID: 1771902739746505076 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: 122945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2818266vqt; Wed, 19 Jul 2023 18:35:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlEL4bcmjiBt5z6MUTW2spcGwN5eoLbUOGMWRXxlM7i9jeVql/0VQrck8Iem9kaOS2eBnkEL X-Received: by 2002:a05:6a20:9147:b0:131:f504:a631 with SMTP id x7-20020a056a20914700b00131f504a631mr3879705pzc.51.1689816930687; Wed, 19 Jul 2023 18:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689816930; cv=none; d=google.com; s=arc-20160816; b=a8Qk+ARHRWO7U418OG49500Ove40lUuPm+V0U39vS9w53g8nH6uMfJfCgpFTsyPIkB 2jgTMi4QhK4VStca+LnJnNTqCpqwoYdMR6uwV9FTOUlOcjkwGeqqzFRScNSxRiJGjFPP PvFIJrqQ6cB3hHGwOMbQzuCebel0nxA7HW6CffnGLxScNzzraLmGWkQNJYp26KU4ePsA TjZcEFpb5SSWqmwTeWa9mdi4topyyFBftu0W8pUzayQSLZtlo01ERkJChs+Hp0xrS5gn rBc2IFMnC+cnXLLxpoMH3siwyt/Spsari7AAuxrGkN5C1KIFh4OxodrVlaJW0tjqQMfg Tb2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WDGT67Q+ic1nejZuLGS46+I/MVwpubEr1pR0ugjy0IU=; fh=CuOU2zHMRvKBIxU3VBdQp/xZQgB1IU6H7AgQjHd0CZ4=; b=jemYwDKHBYorB/J/ucUhlC5hTSC122mk0hICXW11ZENToMPgRy0w7Nd13aMKm7xz0e f8uk8aErwR3aGlYQNb+GHYt/BdnVNkDSk9nC4TzKN/fFUJcREp25aAeFXkh1+kaHzTZK 0xsL4hNWgQEi7NFqNniGAD9ua8qYgjwCHCbOycLTM6L9q1HNTVe2kwnLKfxaonC6mA16 HaimNSSzn4KaN9kOw1YKHs/vvESqOwD8NW6mRRsHd01/oWNmmFsxzb/HLAfKWQw75lPt /wbjGNeJ32eeYby2LnuOZ9XGBkLiW1LFP6IOBBzDSv09SqlJ1AM7re2Zjx0XvjNbDewL kUaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=eqUPBahj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a170903230700b001b8af930e3dsi4763069plh.487.2023.07.19.18.35.17; Wed, 19 Jul 2023 18:35:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=eqUPBahj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbjGTB3C (ORCPT + 99 others); Wed, 19 Jul 2023 21:29:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjGTB25 (ORCPT ); Wed, 19 Jul 2023 21:28:57 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B894726B2; Wed, 19 Jul 2023 18:28:38 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b9ecf0cb4cso1593975ad.2; 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=MXDg/hJWZnwcTUWWfWmgnioSAe1GOpbq814Ibseq39Gdxi5zTcAbRUIR+OXCfripLP +ESiiXkG7k6nAKLAsuBiQ7gyZ16nnOcEZiKJ1i0iWaEIuR+YZfew8ilmon/iziiCcfnj kyesEz+rrpcvRnfiZd2zDglbwFjbzcPF/nCjuxc2TE+b8wltqMT/3GIp3TZ2V1Faq2IA 1iORiimRxaZMK3T1s5GwU0Q5Hy/BFlCjzkuzN8JZ4fBnbIa1kPDxPkdTQXgZ6CM51uTK 8xtwBBsIiRat/Vox9NQ6EX0uxfoLjo1qScj5ulY7H7FNuG9nu3GFFbEH5WtPnQZJGc86 gNtQ== X-Gm-Message-State: ABy/qLYY7Mqx3X0SDfiYNr3iXct6DEMtFmcp/6S1TBh+bMISlxf+ucT1 eNc4GptR5UX2J7n9DPsoMOI= 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771901477933628496 X-GMAIL-MSGID: 1771901477933628496 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: 122949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2825151vqt; Wed, 19 Jul 2023 18:55:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJmgGT7po4H+rLF0+L8z2al3bk2jNj/d1FQXmePKvNjR/zyYE2jbzxLJa+VFUbXxNQl71z X-Received: by 2002:a17:907:7f90:b0:99b:56d4:82bb with SMTP id qk16-20020a1709077f9000b0099b56d482bbmr38548ejc.6.1689818155828; Wed, 19 Jul 2023 18:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689818155; cv=none; d=google.com; s=arc-20160816; b=pdQ58isbv3k+z+1r8Q7DCrP0paqRf2kNzer/TYBCxHIVV9eCZPCBF58yOPdeZNNczE TQKIv8Xh8X/6HefhgK5DyJYFNdDw6ho2ueaHj9nss44tchJdYYzEhphZQivuOJ8Br5sT yj8cFp8ZssH8K3koG/ScaIsYcIuzZzKODybZk0CpBQ4QusXbyEhzNEOsv0Lyj10wYNub 3xt17f7tT7rR+Bs2lh1A4YTs6g8HwxYNsXyelUiu8EQeQwQ5SNFg9qSHUQBYz0cF/Rvs zxXIabpjM73SxQ2qMXzcFVNqIpH3kbYmmgv9wLIdlXPwpiEHZopswYMZiQegC+5XupI7 4awA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vF98fHpwax0Zc0/s3DhXChVek/qggsLafsYLHscMqpE=; fh=CuOU2zHMRvKBIxU3VBdQp/xZQgB1IU6H7AgQjHd0CZ4=; b=A5t41wwJU+IwOe+bZplouTz+v1DKtjR1F77u/hi8V/nYlAy+Dvi4PooWXqIFzWM78x lvyqQs3Av+xZtOA30e5gAsxEtnhMmxDXJ9iqIH6cLs4uQehlG/1MwEdV+lI0QAf3XGaW FZhmxRudnpQNc3JQMQrKiMmaLnoGaGzxrsa01s/An31nJ2j/Kw5t4Bpg7/4gWqLjgekV vdWvCuQVrvViAjb4MNRy7fMSz0OnGxY6iLbH58nbxAyYY2sInF10oLhZEIVrxPdgTUjO bVWaKemf+o2aFqAVZxa4+fx6oQKoMbAvYSctswJ1gzJ4HT0HwjzBai5XlgWDRgkZVVmF mcHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="JJ/ZQm5m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a170906541600b009928c9d9971si3741911ejo.875.2023.07.19.18.55.32; Wed, 19 Jul 2023 18:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="JJ/ZQm5m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjGTB3F (ORCPT + 99 others); Wed, 19 Jul 2023 21:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjGTB27 (ORCPT ); Wed, 19 Jul 2023 21:28:59 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75EA62123; Wed, 19 Jul 2023 18:28:41 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b89114266dso2005465ad.0; 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=OQfSpEnxgwGNhclNx/lTzwk3C4atgTcCPpMhEVLSc6tZgwuiDgSOYfxEZEJuZ5imej a3OS5FLkL+bNSUa3s+pLCHUHU+IWBxaNY7jTB82Q2AbTbZdRYkwrCmiM4vYODQdJAYyW D3NDZbw945pTdhzBTWAEKFv7w15cWXoRJwTYKYFtixqyTVUGnCL6BgW884c4rZrPSqAb 0DQTfF2rVRrmtmaj2w2hupUfVKnQRHwILDLfrtXO6dTwyZbHLyeJpWEqgJw5Yt+AQPdJ bJ4eGHPt66tfT+qk8iWf7muNzeSs840HWklCYT/KF8uqzFbA/QN80A2kIvB+5hSwRXfa eJVg== X-Gm-Message-State: ABy/qLaOWi1uFaR9AcbTbI4QTaVQAJAhs26ZlABpw1M9CVtDteYxG7Rg ly6txkBxu3wfJ/KlkTM1Kl8= 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771902762640178743 X-GMAIL-MSGID: 1771902762640178743 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");