From patchwork Fri Jun 12 22:35:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kevin P. Fleming" X-Patchwork-Id: 1308540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=km6g.us Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49kFv96VXcz9s1x for ; Sat, 13 Jun 2020 08:36:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726361AbgFLWgV (ORCPT ); Fri, 12 Jun 2020 18:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbgFLWgU (ORCPT ); Fri, 12 Jun 2020 18:36:20 -0400 Received: from mail.net18.km6g.us (mail.net18.km6g.us [IPv6:2607:5300:203:24b0:3::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9D1C03E96F; Fri, 12 Jun 2020 15:36:20 -0700 (PDT) Received: from [2001:470:8afe:60:716b:c9b9:d55a:f6f1] (helo=balrog20.km6g.us) by mail.net18.km6g.us with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jjsHV-0006C6-Hj; Fri, 12 Jun 2020 18:36:13 -0400 From: "Kevin P. Fleming" To: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org Cc: "Kevin P. Fleming" , Alessandro Zummo , Alexandre Belloni , Rob Herring Subject: [PATCH 1/3 v2] dt-bindings: abx80x: Add autocal-filter property Date: Fri, 12 Jun 2020 18:35:49 -0400 Message-Id: <20200612223551.282113-1-kevin+linux@km6g.us> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Add a property to allow control of the autocalibration filter capacitor. Signed-off-by: Kevin P. Fleming Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: Rob Herring To: linux-rtc@vger.kernel.org To: devicetree@vger.kernel.org --- v2: Change property to an integer value, and describe possible values Documentation/devicetree/bindings/rtc/abracon,abx80x.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt index 2405e35a1bc0f..18210627b8470 100644 --- a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt +++ b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt @@ -29,3 +29,11 @@ and valid to enable charging: - "abracon,tc-diode": should be "standard" (0.6V) or "schottky" (0.3V) - "abracon,tc-resistor": should be <0>, <3>, <6> or <11>. 0 disables the output resistor, the other values are in kOhm. + +All of the devices can have a 47pf capacitor attached to increase the +autocalibration accuracy of their RC oscillators. To enable or disable usage +of the capacitor the following property can be defined: + + - "abracon,autocal-filter": should be <0> or <1>. 0 indicates that there + is no capacitor attached, 1 indicates that there + is a capacitor attached. From patchwork Fri Jun 12 22:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kevin P. Fleming" X-Patchwork-Id: 1308542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=km6g.us Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49kFvg2WZKz9s1x for ; Sat, 13 Jun 2020 08:36:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726366AbgFLWgq (ORCPT ); Fri, 12 Jun 2020 18:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbgFLWgq (ORCPT ); Fri, 12 Jun 2020 18:36:46 -0400 Received: from mail.net18.km6g.us (mail.net18.km6g.us [IPv6:2607:5300:203:24b0:3::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4777CC03E96F; Fri, 12 Jun 2020 15:36:45 -0700 (PDT) Received: from [2001:470:8afe:60:716b:c9b9:d55a:f6f1] (helo=balrog20.km6g.us) by mail.net18.km6g.us with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jjsI0-0006C6-JI; Fri, 12 Jun 2020 18:36:44 -0400 From: "Kevin P. Fleming" To: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org Cc: "Kevin P. Fleming" , Alessandro Zummo , Alexandre Belloni , Rob Herring Subject: [PATCH 2/3] rtc: abx80x: Add utility function for writing configuration key Date: Fri, 12 Jun 2020 18:35:50 -0400 Message-Id: <20200612223551.282113-2-kevin+linux@km6g.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200612223551.282113-1-kevin+linux@km6g.us> References: <20200612223551.282113-1-kevin+linux@km6g.us> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Writing one of key two values into the configuration key register is a common operation, so a utility function has been added to provide consistent behavior and eliminate code duplication. Signed-off-by: Kevin P. Fleming Cc: Alessandro Zummo Cc: Alexandre Belloni To: linux-rtc@vger.kernel.org --- drivers/rtc/rtc-abx80x.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c index 803725b3a02c3..daa6f27040e61 100644 --- a/drivers/rtc/rtc-abx80x.c +++ b/drivers/rtc/rtc-abx80x.c @@ -117,6 +117,16 @@ struct abx80x_priv { struct watchdog_device wdog; }; +static int abx80x_write_config_key(struct i2c_client *client, u8 key) +{ + if (i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, key) < 0) { + dev_err(&client->dev, "Unable to write configuration key\n"); + return -EIO; + } + + return 0; +} + static int abx80x_is_rc_mode(struct i2c_client *client) { int flags = 0; @@ -140,12 +150,8 @@ static int abx80x_enable_trickle_charger(struct i2c_client *client, * Write the configuration key register to enable access to the Trickle * register */ - err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, - ABX8XX_CFG_KEY_MISC); - if (err < 0) { - dev_err(&client->dev, "Unable to write configuration key\n"); + if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0) return -EIO; - } err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE, ABX8XX_TRICKLE_CHARGE_ENABLE | @@ -358,12 +364,8 @@ static int abx80x_rtc_set_autocalibration(struct device *dev, } /* Unlock write access to Oscillator Control Register */ - retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, - ABX8XX_CFG_KEY_OSC); - if (retval < 0) { - dev_err(dev, "Failed to write CONFIG_KEY register\n"); - return retval; - } + if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_OSC) < 0) + return -EIO; retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags); @@ -450,12 +452,8 @@ static ssize_t oscillator_store(struct device *dev, flags |= (ABX8XX_OSC_OSEL); /* Unlock write access on Oscillator Control register */ - retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, - ABX8XX_CFG_KEY_OSC); - if (retval < 0) { - dev_err(dev, "Failed to write CONFIG_KEY register\n"); - return retval; - } + if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_OSC) < 0) + return -EIO; retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags); if (retval < 0) { @@ -762,13 +760,8 @@ static int abx80x_probe(struct i2c_client *client, * Write the configuration key register to enable access to * the config2 register */ - err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, - ABX8XX_CFG_KEY_MISC); - if (err < 0) { - dev_err(&client->dev, - "Unable to write configuration key\n"); + if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0) return -EIO; - } err = i2c_smbus_write_byte_data(client, ABX8XX_REG_OUT_CTRL, data | ABX8XX_OUT_CTRL_EXDS); From patchwork Fri Jun 12 22:35:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kevin P. Fleming" X-Patchwork-Id: 1308543 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=km6g.us Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49kFwb1VMKz9sRN for ; Sat, 13 Jun 2020 08:37:35 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbgFLWhd (ORCPT ); Fri, 12 Jun 2020 18:37:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgFLWhd (ORCPT ); Fri, 12 Jun 2020 18:37:33 -0400 Received: from mail.net18.km6g.us (mail.net18.km6g.us [IPv6:2607:5300:203:24b0:3::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A08E2C03E96F; Fri, 12 Jun 2020 15:37:33 -0700 (PDT) Received: from [2001:470:8afe:60:716b:c9b9:d55a:f6f1] (helo=balrog20.km6g.us) by mail.net18.km6g.us with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jjsIm-0006C6-Oh; Fri, 12 Jun 2020 18:37:32 -0400 From: "Kevin P. Fleming" To: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org Cc: "Kevin P. Fleming" , Alessandro Zummo , Alexandre Belloni , Rob Herring Subject: [PATCH 3/3 v2] rtc: abx80x: Add support for autocalibration filter capacitor Date: Fri, 12 Jun 2020 18:35:52 -0400 Message-Id: <20200612223551.282113-3-kevin+linux@km6g.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200612223551.282113-1-kevin+linux@km6g.us> References: <20200612223551.282113-1-kevin+linux@km6g.us> MIME-Version: 1.0 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org All of the parts supported by this driver can make use of a small capacitor to improve the accuracy of the autocalibration process for their RC oscillators. If a capacitor is connected, a configuration register must be set to enable its use, so a new Device Tree property has been added for that purpose. Signed-off-by: Kevin P. Fleming Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: Rob Herring To: linux-rtc@vger.kernel.org To: devicetree@vger.kernel.org Reported-by: kernel test robot Reported-by: Dan Carpenter --- v2: Change property to an integer value to allow user to enable or disable drivers/rtc/rtc-abx80x.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c index daa6f27040e61..8edfcefbd9058 100644 --- a/drivers/rtc/rtc-abx80x.c +++ b/drivers/rtc/rtc-abx80x.c @@ -77,6 +77,10 @@ #define ABX8XX_CFG_KEY_OSC 0xa1 #define ABX8XX_CFG_KEY_MISC 0x9d +#define ABX8XX_REG_AFCTRL 0x26 +#define ABX8XX_AUTOCAL_FILTER_DISABLE 0x00 +#define ABX8XX_AUTOCAL_FILTER_ENABLE 0xa0 + #define ABX8XX_REG_ID0 0x28 #define ABX8XX_REG_OUT_CTRL 0x30 @@ -141,6 +145,26 @@ static int abx80x_is_rc_mode(struct i2c_client *client) return (flags & ABX8XX_OSS_OMODE) ? 1 : 0; } +static int abx80x_set_autocal_filter(struct i2c_client *client, u8 filter_cfg) +{ + int err; + + /* + * Write the configuration key register to enable access to the AFCTRL + * register + */ + if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0) + return -EIO; + + err = i2c_smbus_write_byte_data(client, ABX8XX_REG_AFCTRL, filter_cfg); + if (err < 0) { + dev_warn(&client->dev, "Unable to write autocal filter register\n"); + return -EIO; + } + + return 0; +} + static int abx80x_enable_trickle_charger(struct i2c_client *client, u8 trickle_cfg) { @@ -678,7 +702,7 @@ static int abx80x_probe(struct i2c_client *client, { struct device_node *np = client->dev.of_node; struct abx80x_priv *priv; - int i, data, err, trickle_cfg = -EINVAL; + int i, data, err, trickle_cfg, filter_cfg = -EINVAL; char buf[7]; unsigned int part = id->driver_data; unsigned int partnumber; @@ -824,6 +848,15 @@ static int abx80x_probe(struct i2c_client *client, return err; } + if (of_property_read_u32(np, "abracon,autocal_filter", &filter_cfg) == 0) { + err = abx80x_set_autocal_filter(client, + filter_cfg ? + ABX8XX_AUTOCAL_FILTER_ENABLE : + ABX8XX_AUTOCAL_FILTER_DISABLE); + if (err) + return err; + } + if (client->irq > 0) { dev_info(&client->dev, "IRQ %d supplied\n", client->irq); err = devm_request_threaded_irq(&client->dev, client->irq, NULL,