From patchwork Tue Nov 1 08:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: glazveze@delta.nl X-Patchwork-Id: 13609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2858526wru; Tue, 1 Nov 2022 03:05:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM633yP5kyyrosUW0MLN4puNQifbVi4U2p4gGc0qg05ej9orZ3zW/Wo/8eVldTpQR1eieLNh X-Received: by 2002:a17:902:ea95:b0:186:a6b7:4410 with SMTP id x21-20020a170902ea9500b00186a6b74410mr19278566plb.109.1667297111479; Tue, 01 Nov 2022 03:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667297111; cv=none; d=google.com; s=arc-20160816; b=czkO4hZc201WGGcF41Xk+W7bE6nG8RdpctHTy9LgNqMCBlO8BaVAkxzd2vovgneGUk qqqNUmnwlxdEIalBwC2mV3cqhrxF51IEzCLdet/qFYvlYNv04Q4H65EyMx+nrOvvjRk9 1nemcw3Dd6napEWzZAliQaQFJy7suugIkF1jRF8z1C+nzcPcn5f3OBDefAP2FAocdv6c mN83idq9aeWT9FZXZD6C1VnTxccZwadpztgB3ZWkQ2iWQUKKfvV2cNAASqK13HikipPz B0b5ySEGqIxw207n7L4iu7+GW8i8TXatc8xFoYfywtL5Tgax9PQh+NIN5HiRv/QwxrGN AFyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=YpeX5AAakSziat0QYnJ+qE6hZYfv8H5yKFpRZ5TqVhg=; b=ugUPRIl57OptywSD1A+sRezqiz8TsVy83tpcIqByaRKsryayMqZ+kPgJXs7JxaHYkF NoeL14sNrXusxs32g6TLh69iSkVKwaiFTB3hS3mbCDthEvnRA963w26S8f5SUthFQGPm LyAJr93Y61Pww9vDjBLbzFDY6+eIyFjjsvfselrSeVv3rNPs/srHCl+LL+3d6k9r/+Fy A3rQ5JcSRkNwYO1nqLaArKTV+9i4tKdXdlwttjV5FNgERrC2fEe/gc7I1Ssd+2H1i5yY dvHQsmY/5NJdMgaocb3nj3a/bHGMHtSLK+rHPzxTz12uj0wqzpPqgVdX5CLY5Q7VQpXb qD1w== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a17090a734600b00208606154f7si11313916pjs.117.2022.11.01.03.04.58; Tue, 01 Nov 2022 03:05:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229970AbiKAJxd (ORCPT + 99 others); Tue, 1 Nov 2022 05:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbiKAJxc (ORCPT ); Tue, 1 Nov 2022 05:53:32 -0400 X-Greylist: delayed 1543 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 01 Nov 2022 02:53:29 PDT Received: from spamfilter04.delta.nl (spamfilter04.delta.nl [217.102.255.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9682613F79 for ; Tue, 1 Nov 2022 02:53:28 -0700 (PDT) Received: from host-ubmmyvj.static.zeelandnet.nl ([217.102.255.198] helo=mail.zeelandnet.nl) by spamfilter04.delta.nl with esmtp (Exim 4.92) (envelope-from ) id 1opmgD-00068o-Tg; Tue, 01 Nov 2022 09:31:44 +0100 X-Sender-IP: 204.168.188.16 Received: from phenom.domain_not_set.invalid (016-188-168-204.dynamic.caiway.nl [204.168.188.16]) (Authenticated sender: glasveze@delta.nl) by mail.zeelandnet.nl (Postfix) with ESMTPA; Tue, 1 Nov 2022 09:31:23 +0100 (CET) From: glazveze@delta.nl To: linux-rtc@vger.kernel.org Cc: Mike Looijmans , Alessandro Zummo , Alexandre Belloni , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] dt-bindings: rtc: ds1307: Add support for Epson RX8111 Date: Tue, 1 Nov 2022 09:31:21 +0100 Message-Id: <20221101083123.11695-1-glazveze@delta.nl> X-Mailer: git-send-email 2.17.1 X-Originating-IP: 217.102.255.198 X-DELTA-Domain: zeelandnet.nl X-DELTA-Username: 217.102.255.198 Authentication-Results: delta.nl; auth=pass smtp.auth=217.102.255.198@zeelandnet.nl X-DELTA-Outgoing-Class: ham X-DELTA-Outgoing-Evidence: SB/global_tokens (0.00150102412276) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT+fMveXxnfOZrgwa7/MvQYDPUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wqSBOxlRVmV45FJ8CYZCUIt8C9mOBdONdnsxgsk1D2pwpi 79/9lCWegUcH0YAeiESZu3hhVxUr+XbzYNuhZTyMN2jRpXv406oGDMCZBpfLj6tXYKbjfBt0vNkw cgcqpVi2EeDr8t3Z6zKdUQQxqR+SNjz3rkBrmCeUsHTfzqlbREQW59v6OzLaYvRKiPHtemyFp+Fb q4/dza6vunvz714/oUhDTJc8JF+XcA6Coahq6p9OU3mS/dDcjm11n8LBBaHmFYGlZcUx+feeIofU vaKO2wvHbfwld3xCwVQvwEuT74WwDyq/Nv4s81lckG+lIDvnx8yeplRO3sLIqUlSH7OGWzZxdxZO MNdUoc9FlEr2BnLwENyZMPyeFLnoLT8oU4J5ip9csxSp5vs/cqLV2uCxa1gbjNr6zuq/msj6Lhvp vjHGDmddzHap4I7VGqLLvI7oxlm7kP52ZxDqHbw/0OqAoLoOc/cuTx5izBB4vDJo75HWAoddgXQw hX0bgQM/NQzAznOAUImGZ//xcQKfbL7egPacf1SEo03G99/UIdTGSFjTsZRW5VqyvaeMWA2+RBXp D59QdM/f9KJhSSfjTAUyLIywuTEI0kISK7u1AZUYswOEpwFdG2jGwY6Bm9W/XNNE6vgDovKp0+yN qw90aRFIFnjEprciIL+rxAZ0QqLSHV9IlKha13El6tTzAeqsLP7TmwyWkFAKX6230SM4LCMeEY09 Bx7bp0O2j1hLeSx525zuuPE0M/XzHi7X8V/cu68gr/U0flMcy2Vi/IcBgY4amwfEOQVUNYnWQ300 Dp6cJDE37L8A/sfCSfmp70N6CAkTDnHxOK4BiYyvkz+/wZwwYqG/vijyG4aOcjbIor8orItFLNlw ZrFQlMFer4BtL1PbpJ3Vh8ibsqyxAqJtYGjzP6GMdt/ZiCCGoGagixCwW84NSDNfnkx0FX3OFUNq n1MpieaDJmOksitnbpZ9MQYjx/Om5AxPQGNBedVITG8AWxFjzL6tOKgqN6JvQh5n0fI612bG5S+Z Kxm29vhtcTbav+nPErDn/9w2ERKKH06cfjA78AQFw9bd8gj3LalWsUOocRk0/bWX1xH6FJm0Q3iP CmrxJ2+EokXE5CTwtF1RSNQwFbwWnhEwBi6hI73CcV6EcHXc0Zal25K9MsiopwSawNLQjZK6kKbb gNaJlD9A4g+m3nW06IBcbpAk9tBJy3OwmQm7DjpV7Sk6wVAJ6/XOJOG/iKSpBU+r0zgYp1Oa51OE Dgse489k7IVPaIjV8ZGYtKORiBOrYEFBQtHrezLP9jihx+Za/cV70jOJzN2r4A== X-Report-Abuse-To: spam@spamfilter03.delta.nl X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, T_SPF_PERMERROR autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748287735916577479?= X-GMAIL-MSGID: =?utf-8?q?1748287735916577479?= From: Mike Looijmans The rx_8111 is quite similar to the rx_8030. This adds support for this chip to the ds1307 driver. This adds the entry to the devicetree bindings. Signed-off-by: Mike Looijmans Acked-by: Krzysztof Kozlowski --- (no changes since v1) Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml b/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml index 98d10e680144..a9590da64b84 100644 --- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml +++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml @@ -30,6 +30,7 @@ properties: - pericom,pt7c4338 - epson,rx8025 - isil,isl12057 + - epson,rx8111 - epson,rx8130 - items: From patchwork Tue Nov 1 08:31:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: glazveze@delta.nl X-Patchwork-Id: 13611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2858995wru; Tue, 1 Nov 2022 03:05:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4FNBBd7eB3DRG97Dw5Gln4gCfYrRPwfvKq5qRnAr7lcUgMBeQ6bdATsEgj9oclY7zTSnxJ X-Received: by 2002:a17:903:41cf:b0:187:1a3c:517a with SMTP id u15-20020a17090341cf00b001871a3c517amr11452464ple.7.1667297157105; Tue, 01 Nov 2022 03:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667297157; cv=none; d=google.com; s=arc-20160816; b=ESdH0xnqTfp7QezKSl1f2henEK4JhxBbllae0iOEylWR6x7kVnBe66GSbeOFii2Jr4 jjOFShi3xZIzKQCvoNYbN43PQCmXTp9YtQqOa57+l+jimRZLodFEfiHt3316K2GfNGgE qZQA9/zUIp8r3HAJw6j5IPifrNg9M0RsBZv/g5wy6X32715bdX+1CMWO8yJi7RJPThZp qHzTR/iq3xNK3I5P8KESC4+kwPjQ6pABx54Q8Syf/CG1OokKqt9gkOjuchaQ8rQwsquI y34+D74pY/RDTD6NutIFoz1A2rDQrJgm9CKsEGOV5uZTQ1AGOXRPCv+IxyS0nlSnmFzD lzYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=E8ulJ9atGrbgmJeDGP/MCK9Yj98pFc1TDY25eaCTEQo=; b=VcVGqU36mBN28lSn/rdl/SHM1Be4yXxvdsg8/9/VgYbcv28nuCPoJ04tI+Q4MvGrl9 /QashqNaG+CTd+xYgNpTZRnaMrxyolFVyHC82NxJjImQ7qMt82tBtyVRrnRivgZSKeR9 /dNfhrMmGC04XuGrznVAfCtWyMUAs8xbOArg52QlBUR9B9qL8/QpjtQ+Y+O3KgVejX1G svFi1Odu27U42VwLzLrjCl15M0pT8trL3e8gT3USsZsDzCBRX4tTxgtpL8fF73kkGihb g8tdUgWQgdA3KH1xbYLKft/kXD+d5KBwr48Ta1PGI500FB90tjDIRuZQ06Z8XweFdQO5 3vqg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o17-20020a170903301100b001868827ed1esi9935690pla.131.2022.11.01.03.05.43; Tue, 01 Nov 2022 03:05:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbiKAJ7k (ORCPT + 99 others); Tue, 1 Nov 2022 05:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbiKAJ7h (ORCPT ); Tue, 1 Nov 2022 05:59:37 -0400 Received: from spamfilter04.delta.nl (spamfilter04.delta.nl [217.102.255.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C808A14087 for ; Tue, 1 Nov 2022 02:59:35 -0700 (PDT) Received: from host-ubmmyvj.static.zeelandnet.nl ([217.102.255.198] helo=mail.zeelandnet.nl) by spamfilter04.delta.nl with esmtp (Exim 4.92) (envelope-from ) id 1opmgT-0006Dr-4K; Tue, 01 Nov 2022 09:31:56 +0100 X-Sender-IP: 204.168.188.16 Received: from phenom.domain_not_set.invalid (016-188-168-204.dynamic.caiway.nl [204.168.188.16]) (Authenticated sender: glasveze@delta.nl) by mail.zeelandnet.nl (Postfix) with ESMTPA; Tue, 1 Nov 2022 09:31:39 +0100 (CET) From: glazveze@delta.nl To: linux-rtc@vger.kernel.org Cc: Mike Looijmans , Alessandro Zummo , Alexandre Belloni , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] rtc: ds1307: Add support for Epson RX8111 Date: Tue, 1 Nov 2022 09:31:22 +0100 Message-Id: <20221101083123.11695-2-glazveze@delta.nl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221101083123.11695-1-glazveze@delta.nl> References: <20221101083123.11695-1-glazveze@delta.nl> X-Originating-IP: 217.102.255.198 X-DELTA-Domain: zeelandnet.nl X-DELTA-Username: 217.102.255.198 Authentication-Results: delta.nl; auth=pass smtp.auth=217.102.255.198@zeelandnet.nl X-DELTA-Outgoing-Class: ham X-DELTA-Outgoing-Evidence: SB/global_tokens (2.89810905447e-05) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT+ZRGfk0At9Ike/xfAhHowcPUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wqSBOxlRVmV45FJ8CYZCUIt8C9mOBdONdnsxgsk1D2pwpi 79/9lCWegUcH0YAeiESZu3hhVxUr+XbzYNuhZTyMN2jRpXv406oGDMCZBpfLj6tXYKbjfBt0vNkw cgcqpVi2EeDr8t3Z6zKdUQQxqR+SarWVngVq5vG8OaFuy65RvR2mlP2W9u+agdcanH6cUDPhtIdB kUNQyNMiiqabnglhcXCN1jpoyjx2M7Im+CZAXFY+5adZvWXoGLcQcb78Eui+mtbuPAbQ+aWD8hhQ CZMTEEe1sLzznCY3CGPOzCfYYPbQTl/SJIDeIbJV6Zcf430jRGDmKiHQCBmbL4/kVA5ilfR3t3lk efZwj1OjoVRNk0OBtfs8eND145V556pRoeWoiZFW8yMEtAB+QqbWN455cayBalMzNiQi+IaP6Ip3 l1/Gfk/thginq2iQcOP+mMhCFzRIiEpzynty7G1sAhwpazrLOzVL2cm1v+nUTthXE4PZdr6INmo5 IO5sXBWBIKP+Xt1YVt34tXjgAnyScrZDbgZGFmIP8t6jENaJPnk2Q0EqJ2YhaHYKPX4HHcW4fmLf d77XZbPqWAY81T0FayDkAbOrs4FPMK+W+hB4jPTBjMy+REZzZZBkbyPIV/jp5XA84mAL2fYZt/ag 6cJYhE+JR1THjBWZFF00ALVWc/sntqhVr03UHlrscRrHorFm3BMamUdylUIKhf3z2GAHxH7Inwey uebMOAyd9KE1KnR6Q/uNUZtOoISscGZbnZWaYNZOLDTtebGvOVlNWIOgzjpYs6oM5c5v6nO6dxgr nLgL2IFyOv5cAKYGRAn40Vzq1+FjVbTBFy0HmZ7j54j5nbTw0F2VAitLyFstLTVGwdoo+nbOFKKz xACo90vCZrfvMYKWPHYo9X+hHrxPABGbYgYFQMAJdpT8SBGMx9Hio+WRxFDvx3zE1+CEGnCvOf5u H+WNO/AEWyHOtr9hiOqu6Gu3yB2oVjwpD0SDGnhQZ7XpT5syUIQR9jMhtWFgK0+Er7PJLlMHANA1 bs2R4iRcH3xv9Puiud/hROIkQBFx9BA5yh8iLgxxK8ttJOgE22ySLDlnuktNvxRB2uyScQ1h73J0 jHT9cO2eqPW6UlupkxNosx4GZ3jlszDBLqeHTFooTZCcSBYZDWQs5qlkvd6bQTUH3gkwE9mTsS/2 b1BN8Jw1rw== X-Report-Abuse-To: spam@spamfilter03.delta.nl X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, T_SPF_PERMERROR autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748287783572958841?= X-GMAIL-MSGID: =?utf-8?q?1748287783572958841?= From: Mike Looijmans The rx_8111 is quite similar to the rx_8030. This adds support for this chip to the ds1307 driver. Date/time and alarm registers are in the usual places. The nvmem is located at 0x40. Time stamping is not supported. Signed-off-by: Mike Looijmans --- Changes in v2: Add "_REG" in register names Add interrupt/alarm handling (different from rx8030) drivers/rtc/rtc-ds1307.c | 308 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 285 insertions(+), 23 deletions(-) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index d51565bcc189..2c5dff45a246 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -46,6 +46,7 @@ enum ds_type { m41t11, mcp794xx, rx_8025, + rx_8111, rx_8130, last_ds_type /* always last */ /* rs5c372 too? different address... */ @@ -113,6 +114,24 @@ enum ds_type { # define RX8025_BIT_VDET 0x40 # define RX8025_BIT_XST 0x20 +#define RX8111_REG_EXTENSION 0x1d +# define RX8111_REG_EXTENSION_WADA BIT(3) +#define RX8111_REG_FLAG 0x1e +# define RX8111_REG_FLAG_VLF BIT(1) +# define RX8111_REG_FLAG_EVF BIT(2) +# define RX8111_REG_FLAG_AF BIT(3) +# define RX8111_REG_FLAG_TF BIT(4) +# define RX8111_REG_FLAG_UF BIT(5) +#define RX8111_REG_CONTROL 0x1e +# define RX8111_REG_CONTROL_EIE BIT(2) +# define RX8111_REG_CONTROL_AIE BIT(3) +# define RX8111_REG_CONTROL_TIE BIT(4) +# define RX8111_REG_CONTROL_UIE BIT(5) +#define RX8111_REG_PWR_SWITCH_CTRL 0x32 +# define RX8111_PSC_SMP_INIEN BIT(6) +# define RX8111_PSC_SMP_CHGEN BIT(7) +#define RX8111_REG_TIME_STAMP_BUF_CTRL 0x34 + #define RX8130_REG_ALARM_MIN 0x17 #define RX8130_REG_ALARM_HOUR 0x18 #define RX8130_REG_ALARM_WEEK_OR_DAY 0x19 @@ -205,6 +224,68 @@ struct chip_desc { static const struct chip_desc chips[last_ds_type]; +static int ds1307_check_voltage_lost(struct ds1307 *ds1307) +{ + int ret; + unsigned int reg; + unsigned int mask; + unsigned int regflag; + + switch (ds1307->type) { + case rx_8111: + reg = RX8111_REG_FLAG; + mask = RX8111_REG_FLAG_VLF; + break; + case rx_8130: + reg = RX8130_REG_FLAG; + mask = RX8130_REG_FLAG_VLF; + break; + default: + return 0; + } + + ret = regmap_read(ds1307->regmap, reg, ®flag); + if (ret) { + dev_err(ds1307->dev, "%s error %d\n", "read", ret); + return ret; + } + + if (regflag & mask) { + dev_warn_once(ds1307->dev, "oscillator failed, set time!\n"); + return -EINVAL; + } + + return 0; +} + +static int ds1307_clear_voltage_lost(struct ds1307 *ds1307) +{ + int ret; + unsigned int reg; + unsigned int mask; + + switch (ds1307->type) { + case rx_8111: + reg = RX8111_REG_FLAG; + mask = (unsigned int)~RX8111_REG_FLAG_VLF; + break; + case rx_8130: + reg = RX8130_REG_FLAG; + mask = (unsigned int)~RX8130_REG_FLAG_VLF; + break; + default: + return 0; + } + + ret = regmap_write(ds1307->regmap, reg, mask); + if (ret) { + dev_err(ds1307->dev, "%s error %d\n", "write", ret); + return ret; + } + + return 0; +} + static int ds1307_get_time(struct device *dev, struct rtc_time *t) { struct ds1307 *ds1307 = dev_get_drvdata(dev); @@ -212,19 +293,9 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t) const struct chip_desc *chip = &chips[ds1307->type]; u8 regs[7]; - if (ds1307->type == rx_8130) { - unsigned int regflag; - ret = regmap_read(ds1307->regmap, RX8130_REG_FLAG, ®flag); - if (ret) { - dev_err(dev, "%s error %d\n", "read", ret); - return ret; - } - - if (regflag & RX8130_REG_FLAG_VLF) { - dev_warn_once(dev, "oscillator failed, set time!\n"); - return -EINVAL; - } - } + ret = ds1307_check_voltage_lost(ds1307); + if (ret) + return ret; /* read the RTC date and time registers all at once */ ret = regmap_bulk_read(ds1307->regmap, chip->offset, regs, @@ -397,15 +468,9 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t) return result; } - if (ds1307->type == rx_8130) { - /* clear Voltage Loss Flag as data is available now */ - result = regmap_write(ds1307->regmap, RX8130_REG_FLAG, - ~(u8)RX8130_REG_FLAG_VLF); - if (result) { - dev_err(dev, "%s error %d\n", "write", result); - return result; - } - } + result = ds1307_clear_voltage_lost(ds1307); + if (result) + return result; return 0; } @@ -541,6 +606,174 @@ static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, u32 ohms, bool diode) return setup; } +static u8 do_trickle_setup_rx8111(struct ds1307 *ds1307, u32 ohms, bool diode) +{ + /* make sure that the backup battery is enabled */ + u8 setup = RX8111_PSC_SMP_INIEN; + + if (diode) + setup |= RX8111_PSC_SMP_CHGEN; + + return setup; +} + +static irqreturn_t rx8111_irq(int irq, void *dev_id) +{ + struct ds1307 *ds1307 = dev_id; + irqreturn_t result = IRQ_NONE; + int ret; + u8 ctl[2]; + u8 flags = 0; + + rtc_lock(ds1307->rtc); + + /* Read flag and control registers. */ + ret = regmap_bulk_read(ds1307->regmap, RX8111_REG_FLAG, ctl, + sizeof(ctl)); + if (ret < 0) + goto out; + + if (ctl[0] & RX8111_REG_FLAG_AF) { + result = IRQ_HANDLED; + flags |= RTC_AF; /* Alarm */ + ctl[1] &= ~RX8111_REG_CONTROL_AIE; + } + /* + * If an interrupt occurred that we cannot process, we'll have to turn + * it off, otherwise we'd be called again and again. + */ + if (ctl[0] & RX8111_REG_FLAG_UF) { + result = IRQ_HANDLED; + ctl[1] &= ~RX8111_REG_CONTROL_UIE; + } + if (ctl[0] & RX8111_REG_FLAG_TF) { + result = IRQ_HANDLED; + ctl[1] &= ~RX8111_REG_CONTROL_TIE; + } + if (ctl[0] & RX8111_REG_FLAG_EVF) { + result = IRQ_HANDLED; + ctl[1] &= ~RX8111_REG_CONTROL_EIE; + } + /* Clear all flags */ + ctl[0] &= ~(RX8111_REG_FLAG_UF | RX8111_REG_FLAG_TF | + RX8111_REG_FLAG_AF | RX8111_REG_FLAG_EVF); + + ret = regmap_bulk_write(ds1307->regmap, RX8111_REG_FLAG, ctl, + sizeof(ctl)); + if (ret < 0) + goto out; + + rtc_update_irq(ds1307->rtc, 1, flags | RTC_IRQF); + +out: + rtc_unlock(ds1307->rtc); + + return result; +} + +static int rx8111_read_alarm(struct device *dev, struct rtc_wkalrm *t) +{ + struct ds1307 *ds1307 = dev_get_drvdata(dev); + u8 ald[3], ctl[2]; + int ret; + + /* Read alarm registers. */ + ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, + sizeof(ald)); + if (ret < 0) + return ret; + + /* Read flag and control registers. */ + ret = regmap_bulk_read(ds1307->regmap, RX8111_REG_FLAG, ctl, + sizeof(ctl)); + if (ret < 0) + return ret; + + t->enabled = !!(ctl[1] & RX8111_REG_CONTROL_AIE); + t->pending = !!(ctl[0] & RX8111_REG_FLAG_AF); + + /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ + t->time.tm_sec = -1; + t->time.tm_min = bcd2bin(ald[0] & 0x7f); + t->time.tm_hour = bcd2bin(ald[1] & 0x7f); + t->time.tm_wday = -1; + t->time.tm_mday = bcd2bin(ald[2] & 0x7f); + t->time.tm_mon = -1; + t->time.tm_year = -1; + t->time.tm_yday = -1; + t->time.tm_isdst = -1; + + dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d enabled=%d\n", + __func__, t->time.tm_sec, t->time.tm_min, t->time.tm_hour, + t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled); + + return 0; +} + +static int rx8111_set_alarm(struct device *dev, struct rtc_wkalrm *t) +{ + struct ds1307 *ds1307 = dev_get_drvdata(dev); + u8 ald[3], ctl[3]; + int ret; + + dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d " + "enabled=%d pending=%d\n", __func__, + t->time.tm_sec, t->time.tm_min, t->time.tm_hour, + t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, + t->enabled, t->pending); + + /* Read control registers. */ + ret = regmap_bulk_read(ds1307->regmap, RX8111_REG_EXTENSION, ctl, + sizeof(ctl)); + if (ret < 0) + return ret; + + ctl[0] &= RX8111_REG_EXTENSION_WADA; + ctl[1] &= ~RX8111_REG_FLAG_AF; + ctl[2] &= ~RX8111_REG_CONTROL_AIE; + + ret = regmap_bulk_write(ds1307->regmap, RX8111_REG_EXTENSION, ctl, + sizeof(ctl)); + if (ret < 0) + return ret; + + /* Hardware alarm precision is 1 minute! */ + ald[0] = bin2bcd(t->time.tm_min); + ald[1] = bin2bcd(t->time.tm_hour); + ald[2] = bin2bcd(t->time.tm_mday); + + ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, + sizeof(ald)); + if (ret < 0) + return ret; + + if (!t->enabled) + return 0; + + ctl[2] |= RX8111_REG_CONTROL_AIE; + + return regmap_write(ds1307->regmap, RX8111_REG_CONTROL, ctl[2]); +} + +static int rx8111_alarm_irq_enable(struct device *dev, unsigned int enabled) +{ + struct ds1307 *ds1307 = dev_get_drvdata(dev); + int ret, reg; + + ret = regmap_read(ds1307->regmap, RX8111_REG_CONTROL, ®); + if (ret < 0) + return ret; + + if (enabled) + reg |= RX8111_REG_CONTROL_AIE; + else + reg &= ~RX8111_REG_CONTROL_AIE; + + dev_dbg(dev, "%s, enable=%u, reg=0x%x\n", __func__, enabled, reg); + + return regmap_write(ds1307->regmap, RX8111_REG_CONTROL, reg); +} + static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode) { /* make sure that the backup battery is enabled */ @@ -943,6 +1176,14 @@ static const struct rtc_class_ops rx8130_rtc_ops = { .alarm_irq_enable = rx8130_alarm_irq_enable, }; +static const struct rtc_class_ops rx8111_rtc_ops = { + .read_time = ds1307_get_time, + .set_time = ds1307_set_time, + .read_alarm = rx8111_read_alarm, + .set_alarm = rx8111_set_alarm, + .alarm_irq_enable = rx8111_alarm_irq_enable, +}; + static const struct rtc_class_ops mcp794xx_rtc_ops = { .read_time = ds1307_get_time, .set_time = ds1307_set_time, @@ -1012,6 +1253,16 @@ static const struct chip_desc chips[last_ds_type] = { .century_bit = DS1337_BIT_CENTURY, .bbsqi_bit = DS3231_BIT_BBSQW, }, + [rx_8111] = { + .alarm = 1, + .nvram_offset = 0x40, + .nvram_size = 0x40, /* 0x40 .. 0x7F is user RAM */ + .offset = 0x10, + .irq_handler = rx8111_irq, + .rtc_ops = &rx8111_rtc_ops, + .trickle_charger_reg = RX8111_REG_PWR_SWITCH_CTRL, + .do_trickle_setup = &do_trickle_setup_rx8111, + }, [rx_8130] = { .alarm = 1, /* this is battery backed SRAM */ @@ -1063,6 +1314,7 @@ static const struct i2c_device_id ds1307_id[] = { { "pt7c4338", ds_1307 }, { "rx8025", rx_8025 }, { "isl12057", ds_1337 }, + { "rx8111", rx_8111 }, { "rx8130", rx_8130 }, { } }; @@ -1137,6 +1389,10 @@ static const struct of_device_id ds1307_of_match[] = { .compatible = "isil,isl12057", .data = (void *)ds_1337 }, + { + .compatible = "epson,rx8111", + .data = (void *)rx_8111 + }, { .compatible = "epson,rx8130", .data = (void *)rx_8130 @@ -1880,6 +2136,12 @@ static int ds1307_probe(struct i2c_client *client, DS1307_REG_HOUR << 4 | 0x08, hour); } break; + case rx_8111: + /* Use memory as user RAM */ + regmap_write(ds1307->regmap, RX8111_REG_TIME_STAMP_BUF_CTRL, 0); + /* Disable timer, events, frequency output */ + regmap_write(ds1307->regmap, RX8111_REG_EXTENSION, 0xc8); + break; case ds_1388: err = regmap_read(ds1307->regmap, DS1388_REG_CONTROL, &tmp); if (err) { @@ -1955,7 +2217,7 @@ static int ds1307_probe(struct i2c_client *client, dev_info(ds1307->dev, "'wakeup-source' is set, request for an IRQ is disabled!\n"); /* We cannot support UIE mode if we do not have an IRQ line */ - clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, ds1307->rtc->features); + ds1307->rtc->uie_unsupported = 1; } if (want_irq) {