Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp238619yba; Wed, 3 Apr 2019 07:54:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaH/B2VP58Q8RzluipFsGkvMdrjNskog5mT0Hrm4UTCz0mjuR5cWgxSqYK3J8qkstjPOdI X-Received: by 2002:aa7:8284:: with SMTP id s4mr8991250pfm.235.1554303255496; Wed, 03 Apr 2019 07:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554303255; cv=none; d=google.com; s=arc-20160816; b=0JXJ4rOc5wGJvGJOCbNzL4crF2yn2ApC5tobV1e9BLuyJcsojI4AaWMqGG9f0Q/n7L d3KtKcV1bqrG6JC9xV+e0YLYJsyV1CD5MIUejh+7JACokhvymz5JFdJcur6pSse5I8q/ J4mAkY8Td3eJP8XIyM7JhCno0GFmbxHaFYKy+dBNJtTRyVmxxs0jBTgYZHCiuHGt8D/2 Mtqq8v1emu+8Gvgy1BFJfKo22plKuZjmAet6y4SMsaNahIkV0tDRiBC+NkwOXAak2nS6 wp11Fw0YayyU7wysZLQmjnDr2VCMsibyH9WqktKLnr/x+S9YnLLsK4iPXCK7tXbzcRm8 q81w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Milta4NozW/xt9w7CX85eFInuJZBr4h1FU4VT6UbAiw=; b=OtbcS5kDzlRXB39XozAhSF9M+OTUP2VJ4hWdnSACF8kGJpZm0O8RX4hD8VGD3y3rlR 8xqlsih57NClQ8jwGNluuHUrGE0sb/iWR5cgjyl1ex+MD6Nm99vyZ7AGFBDZTxJh4R4w sNRf6NeBSXCIJRWoMTvoWao8Q3BYH6I6se9BqCBhnj0i/ufg7TQ9iWK5X2t7BV/HGSFs oIOiYP9TybQpxhMZ0gLcKnj/HSZ7t81S2n3HOSD+A4sM60kvZOZLuun++ZmY0v9c8Ppp 3ET/ro/EHjHHsZIXTcuQaOoSwiEdJ6EWUXsToIq8LnjO7nnrN3uIwxK2sR4kkuHPH6lA BNbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si14584161pld.190.2019.04.03.07.53.59; Wed, 03 Apr 2019 07:54:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726535AbfDCOxW (ORCPT + 99 others); Wed, 3 Apr 2019 10:53:22 -0400 Received: from smtp.asem.it ([151.1.184.197]:61517 "EHLO smtp.asem.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbfDCOxT (ORCPT ); Wed, 3 Apr 2019 10:53:19 -0400 Received: from webmail.asem.it by asem.it (smtp.asem.it) (SecurityGateway 5.5.0) with ESMTP id SG003789494.MSG for ; Wed, 03 Apr 2019 16:53:09 +0200S Received: from ASAS044.asem.intra (172.16.16.44) by ASAS044.asem.intra (172.16.16.44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Wed, 3 Apr 2019 16:53:08 +0200 Received: from flavio-x.asem.intra (172.16.17.208) by ASAS044.asem.intra (172.16.16.44) with Microsoft SMTP Server id 15.1.1261.35 via Frontend Transport; Wed, 3 Apr 2019 16:53:07 +0200 From: Flavio Suligoi To: Alessandro Zummo , Alexandre Belloni , Rob Herring , Mark Rutland CC: , , , Flavio Suligoi Subject: [PATCH 2/2] rtc: pcf2127: add battery-low INTn generation Date: Wed, 3 Apr 2019 16:52:45 +0200 Message-ID: <1554303165-24813-2-git-send-email-f.suligoi@asem.it> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554303165-24813-1-git-send-email-f.suligoi@asem.it> References: <1554303165-24813-1-git-send-email-f.suligoi@asem.it> MIME-Version: 1.0 Content-Type: text/plain X-SGHeloLookup-Result: pass smtp.helo=webmail.asem.it (ip=172.16.16.44) X-SGSPF-Result: none (smtp.asem.it) X-SGOP-RefID: str=0001.0A0B0210.5CA4C8D4.0055,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 (_st=1 _vt=0 _iwf=0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pcf2127 has an automatic battery-low detection function. In case of battery-low event, an interrupt generation through the pin INTn (active low) can be enabled, setting the flag BLIE in the register Control_3. This function is activated by the "battery-low-hw-alarm" DT property. Example of use for an NXP i.MX7D board: &i2c3 { clock-frequency = <100000>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c3>; status = "okay"; pcf2127@51 { compatible = "nxp,pcf2127"; reg = <0x51>; battery-low-hw-alarm; status = "okay"; }; }; Signed-off-by: Flavio Suligoi --- drivers/rtc/rtc-pcf2127.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 7cb786d..e3805c8 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -228,6 +228,10 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, const char *name, bool has_nvmem) { struct pcf2127 *pcf2127; + struct device_node *np; + struct i2c_client *client = to_i2c_client(dev); + unsigned char buf[2]; + int err; int ret = 0; dev_dbg(dev, "%s\n", __func__); @@ -245,6 +249,35 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, if (IS_ERR(pcf2127->rtc)) return PTR_ERR(pcf2127->rtc); + /* + * The pcf2127 has an automatic battery-low detection function. + * + * In case of battery-low event, an interrupt generation through + * the pin INTn (active low) can be enabled, setting the flag BLIE + * in the register Control_3. + */ + np = of_node_get(dev->of_node); + if (!np) { + dev_err(dev, "failed to find the RTC pcf2127 node\n"); + return -ENOENT; + } + if (of_get_property(np, "battery-low-hw-alarm", NULL)) { + dev_info(dev, "enable battery-low hw alarm on INTn pin\n"); + + /* + * Set BLIE bit in register Control_3 (override is possible + * because this register is fully zero after reset) + */ + buf[0] = PCF2127_REG_CTRL3; + buf[1] = 0x01; + /* write register's data */ + err = i2c_master_send(client, buf, 2); + if (err != 2) { + dev_err(dev, "%s: err=%d", __func__, err); + return -EIO; + } + } + if (has_nvmem) { struct nvmem_config nvmem_cfg = { .priv = pcf2127, -- 2.7.4