Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp503305ybl; Wed, 21 Aug 2019 00:46:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjbm12U8c8FPngES5+1wLyIO/paZuogKpi2AtEF/iTonTUx8X4gQQc5fEdpq9COl8meaMO X-Received: by 2002:a62:107:: with SMTP id 7mr34562782pfb.4.1566373587291; Wed, 21 Aug 2019 00:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566373587; cv=none; d=google.com; s=arc-20160816; b=qmCPMJC1/Vee6dfzpgMpo/MuMCnTFYB6satk91D8jVGB2qY1oPf/AeZCxv3lw6Y1Nx KPvhI6E0mOBWzM+SP/UtNQBo1s6KKqcHjCfQfb8Li79UyQzIW66WOPiGlfJTsUhNvao0 Lww9LK/bSYu7lRD0ha+pQIyYl1cHNQngfHqmQRYOx4amMk6GRb0rgs/SxeLwYiGCgLk1 tu5bl7K30eDVTwYlU/5WXc1c8TsQ4iOXlU4q+JgNvGajcv+ugT7+E8UaSGwBwSlOAGdg 2u8rRng+z1tDQtpFcLuMHq9km2UbawltrxGMyFwHKnkawuX9yf+f0yWBiX1Qp/7rO/+1 cNiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:ironport-sdr; bh=3A5MFRbmH9DqQmiLXTy/AvWYirm8GXzUQFUR4lMsMb0=; b=syc7mydGps/USpiuwkgF1gESuhbYngxKnVfhJ6I+mX0pxLDajPAcYaOW6DPQIdcsKy DJSqjrQNnSRBFzBLejnWezAtvSN3G4VGdINUT3PJivfh94gxmA0Y2fZ8V/yDoLblEGax 0Sv7ABRyKKmGp5+g+coI1FFQaWVNPnFltX7aAbfrWPBSzn5G6UtGHBHPsht3YN2agd9e 5sheiy73u2wgyAXz7u2cFfDU0q222uiQBWGuHI7jHDzR7txCYqNAHRP/Fi3goGm1gz/K 5JVTp/8D9uV90AM7ksbEGNVCO4qIe/1QedRakpezZ2C22CWiDsHAwGlQ+6Hi0EimkvTt Na5g== 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 d25si13626669pge.301.2019.08.21.00.46.10; Wed, 21 Aug 2019 00:46:27 -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 S1727910AbfHUGUM (ORCPT + 99 others); Wed, 21 Aug 2019 02:20:12 -0400 Received: from hel-mailgw-01.vaisala.com ([193.143.230.17]:4644 "EHLO hel-mailgw-01.vaisala.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726484AbfHUGUL (ORCPT ); Wed, 21 Aug 2019 02:20:11 -0400 IronPort-SDR: 8V8EhrJCUuKyTElVrk+Etk8MRSkN3jFaTOcIXL2ySLd8T/kMnYbJLkp4/a8ZXluS2r5ezUsoIn pibmHCVYXvHmMawGPM2NQzs/dHbFEI8ifb0RsvzGfuPfSsMPVmJkV8u16ce9v9Zn5yCPQC/0a+ nJ+/azIRxQUt+8Y+piWZwPFJqeftIelZfP/+/8z1/zIjv5A8DQH8x1ctAzyj+90SvlKWb4xOx8 hckWud2MNG3/cWzrgIV1HaAWIgZp8ELvdgD9u6ArUaOTUp6Un1SisPWpV2bzjc47TRFT2052uN DhU= X-IronPort-AV: E=Sophos;i="5.64,411,1559509200"; d="scan'208";a="229121716" Subject: Re: [v2] rtc: pcf85363/pcf85263: fix error that failed to run hwclock -w To: Li Yang , Alexandre Belloni , Mark Brown Cc: Biwen Li , a.zummo@towertech.it, linux-rtc@vger.kernel.org, lkml References: <20190816024636.34738-1-biwen.li@nxp.com> <20190816080417.GB3545@piout.net> <20190816162825.GE3545@piout.net> From: Nandor Han Message-ID: Date: Wed, 21 Aug 2019 09:20:05 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 21 Aug 2019 06:20:05.0337 (UTC) FILETIME=[791E8490:01D557E8] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/16/19 10:40 PM, Li Yang wrote: > On Fri, Aug 16, 2019 at 11:30 AM Alexandre Belloni > wrote: >> >> On 16/08/2019 10:50:49-0500, Li Yang wrote: >>> On Fri, Aug 16, 2019 at 3:05 AM Alexandre Belloni >>> wrote: >>>> >>>> On 16/08/2019 10:46:36+0800, Biwen Li wrote: >>>>> Issue: >>>>> - # hwclock -w >>>>> hwclock: RTC_SET_TIME: Invalid argument >>>>> >>>>> Why: >>>>> - Relative patch: https://lkml.org/lkml/2019/4/3/55 , this patch >>>>> will always check for unwritable registers, it will compare reg >>>>> with max_register in regmap_writeable. >>>>> >>>>> - In drivers/rtc/rtc-pcf85363.c, CTRL_STOP_EN is 0x2e, but DT_100THS >>>>> is 0, max_regiter is 0x2f, then reg will be equal to 0x30, >>>>> '0x30 < 0x2f' is false,so regmap_writeable will return false. >>>>> >>>>> - Root cause: the buf[] was written to a wrong place in the file >>>>> drivers/rtc/rtc-pcf85363.c >>>>> >>>> >>>> This is not true, the RTC wraps the register accesses properly and this >>> >>> This performance hack probably deserve some explanation in the code comment. :) >>> >>>> is probably something that should be handled by regmap_writable. >>> >>> The address wrapping is specific to this RTC chip. Is it also >>> commonly used by other I2C devices? I'm not sure if regmap_writable >>> should handle the wrapping case if it is too special. >>> >> >> Most of the i2c RTCs do address wrapping which is sometimes the only way >> to properly set the time. > > Adding Mark and Nandor to the loop. > > Regards, > Leo > Hi, `regmap` provides couple of ways to validate the registers: max_register, callback function and write table. All of these are optional, so it gives you the freedom to customize it as needed. In this situation probably you could: 1. Avoid using the wrapping feature of pcf85363 (you can just provide separate calls for stop, reset and time confguration). In this way the `max_register` validation method will work fine. 2. Replace `max_register` method validation with `callback function` validation method, were you could make your own validation. Regards, Nandor