Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6850599rwn; Tue, 13 Sep 2022 09:50:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4SnLRwdifRaAEtEXJj6H39mSyPV+RlVWVULr6bDvPUbp/XY8e9QYXzJO8I8HberGJzIu/y X-Received: by 2002:a17:902:8ec6:b0:172:dc2c:306d with SMTP id x6-20020a1709028ec600b00172dc2c306dmr32657679plo.104.1663087804384; Tue, 13 Sep 2022 09:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663087804; cv=none; d=google.com; s=arc-20160816; b=PomfVdsRXPRVmbS6xvNtBplilXGcd57kNvjyOiqSOyxufHF9H0gcxPINzuGywSpmsm bnNXzciH1Oa0YmEAH5lC9fXqy8ahM3dDSrjQLR1o755Lnq3KN8R6pIu7wGS7vUpeVLo9 HB3qjhnF55AcFPvF3xrrvku0RbxiXnjYGXWUz3o1ncqAcBb9n9PDftrjqpuBv5OUbyPa ciTrmoofvufn84uWjpnU1B24xCQUnTt0vurnf+91/1M47G29LXJ+QQxYtJbsV0L3gmAU f1HdejwX2YByGtWUpVPhUxfucG/TtS0oFt/XbKI0Lkk9qa35KvlFZvKTS3QGvkCVXOvX 8+DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:subject:dkim-signature; bh=+0bJLl7XXBn2mnQPoCDEw9fJxIAC5EOVcVVMuJTzH6k=; b=C1OAvDVCMvcVA8UnKp4myqV8QLInwTcdPdNqdFxnTlR3/Q95KF44yhN4Ndl0l5qF9/ CtlHQLvH/tx1XaxdhtOgQxhJrtwLAW533WtI1f0cuMyAuwxcuRim9OlMAtGwZKf04Psm reRhCPEe163M3ZIeN9WAl6pZjlw0GGR8+299l+vEm3OpRr11uuVwMxhPExmkEq68Ucgw +49zDpZ1cLGGo9o3NdiJwLy/uVzNykf/DSCa5awLAA2JSy/QemHOtg7YKbPF8SPY3sMb nJIlRnv3qDdDFCIpxjrl6pLEeXebgcuN0+2xaUOyRao79/Vx3/NdPNCuTw14o1PvX3i6 1COw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=tTBYVQWo; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v32-20020a634660000000b0043496cbbb81si988860pgk.386.2022.09.13.09.49.45; Tue, 13 Sep 2022 09:50:04 -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=@amazon.com header.s=amazon201209 header.b=tTBYVQWo; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236580AbiIMPfH (ORCPT + 99 others); Tue, 13 Sep 2022 11:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236716AbiIMPdr (ORCPT ); Tue, 13 Sep 2022 11:33:47 -0400 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B85677FE43; Tue, 13 Sep 2022 07:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1663080061; x=1694616061; h=message-id:date:mime-version:to:cc:references:from: in-reply-to:content-transfer-encoding:subject; bh=+0bJLl7XXBn2mnQPoCDEw9fJxIAC5EOVcVVMuJTzH6k=; b=tTBYVQWoqfDe6VIPnKCaVmTjQdJWGd5dppqTK2olilOqfKka9LjVcPpz xbpXsH61PUyqnAQ3mU4O2ckxX3OENhZ9o9gFr4j185+H03PlqJsR8CX5G Cf4EgetDUtGJMZoC+uKvY7YPBRHsE2QfFOBoan6NgCfHTn6ezoYLo7Zl7 o=; X-IronPort-AV: E=Sophos;i="5.93,313,1654560000"; d="scan'208";a="225465858" Subject: Re: [PATCH v5 20/21] hwmon: (mr75203) add debugfs to read and write temperature coefficients Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-28a78e3f.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2022 14:40:23 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2b-28a78e3f.us-west-2.amazon.com (Postfix) with ESMTPS id 0C13CA0EC0; Tue, 13 Sep 2022 14:40:21 +0000 (UTC) Received: from EX19D013UWA002.ant.amazon.com (10.13.138.210) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 13 Sep 2022 14:40:20 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX19D013UWA002.ant.amazon.com (10.13.138.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 13 Sep 2022 14:40:20 +0000 Received: from [192.168.151.102] (10.85.143.178) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 13 Sep 2022 14:40:16 +0000 Message-ID: <3b121ab4-dd64-68b3-ee89-8571b5d3651e@amazon.com> Date: Tue, 13 Sep 2022 17:40:16 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 To: Andy Shevchenko CC: , , , , , , , , , , "Farber, Eliav" References: <20220908152449.35457-1-farbere@amazon.com> <20220908152449.35457-21-farbere@amazon.com> <581a4a0b-8e0e-b7a2-f873-77ed74b54e96@amazon.com> Content-Language: en-US From: "Farber, Eliav" In-Reply-To: <581a4a0b-8e0e-b7a2-f873-77ed74b54e96@amazon.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_SPF_WL 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 On 9/13/2022 4:06 PM, Farber, Eliav wrote: > On 9/8/2022 9:11 PM, Andy Shevchenko wrote: >> On Thu, Sep 08, 2022 at 03:24:48PM +0000, Eliav Farber wrote: >>> This change adds debugfs to read and write temperature sensor >>> coefficients >>> - g, h, j and cal5. >>> >>> The coefficients can vary between product and product, so it can be >>> very >>> useful to be able to modify them on the fly during the calibration >>> process. >>> >>> e.g.: >>> >>> cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_cal5 >>> 4096 >>> >>> echo 83000 > sys/kernel/debug/940f23d0000.pvt/ts_coeff_g >> >> ... >> >>> - Return j coefficient to use debugfs_create_file() instead of >>>   debugfs_create_u32() because j is signed. >> >> You can use >> >> DEFINE_DEBUGFS_ATTRIBUTE(ts_coeff_j, ts_coeff_j_get, ts_coeff_j_set, >> "%lld\n"); >> >> which still makes code compact. > > > I tried your suggestion to use DEFINE_DEBUGFS_ATTRIBUTE but I can't set > j to be a negative value: > > root@alpine:~# cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > 0 > root@alpine:~# echo 100 > /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > root@alpine:~# cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > 100 > root@alpine:~# echo -100 > /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > sh: write error: Invalid argument > > This is the code I added: > > static int ts_coeff_j_set(void *data, u64 val) > { >     struct pvt_device *pvt = data; > >     pvt->ts_coeff.j = val; >     return 0; > } > > static int ts_coeff_j_get(void *data, u64 *val) > { >     struct pvt_device *pvt = data; > >     *val = pvt->ts_coeff.j; >     return 0; > } > > DEFINE_DEBUGFS_ATTRIBUTE(ts_coeff_j_fops, ts_coeff_j_get, >              ts_coeff_j_set, "%lld\n"); > > static void devm_pvt_ts_dbgfs_remove(void *data) > { >     struct pvt_device *pvt = (struct pvt_device *)data; > >     debugfs_remove_recursive(pvt->dbgfs_dir); >     pvt->dbgfs_dir = NULL; > } > > static int pvt_ts_dbgfs_create(struct pvt_device *pvt, struct device > *dev) > { >     ... >     debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt, >                 &ts_coeff_j_fops); >     ... > > I'm using kernel 5.10.112. > Can you please see if I'm did anything wrong? It seems like debugfs_attr_write() calls simple_attr_write() and it uses kstrtoull(), which is why it fails when setting a negative value. This is the same also in v6.0-rc5. debugfs_attr_read() on the other hand does show the correct value also when j is negative. -- Regards, Eliav