Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2548569imi; Mon, 25 Jul 2022 01:20:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uvKzimaTgV8tl06K21vCVHuu62HhcfN/wNVpS59QTll7OsIqQdr+ejgN/wWgGBrYrkGD5J X-Received: by 2002:a17:902:b694:b0:16c:29d9:7308 with SMTP id c20-20020a170902b69400b0016c29d97308mr11456725pls.110.1658737227140; Mon, 25 Jul 2022 01:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658737227; cv=none; d=google.com; s=arc-20160816; b=EeSfJ6dduWzhlacppGKDvNExORygefmV0LQ4qlQ/PTxS/NaI9kgN6JaSykvct9hsS2 M1R8Xo5S15xXA/o3hfuU9W7axCXFgwSNrdo8gqh7AOdnhtDwraCLrsnBpCivhJhXPHJR EGhECMmOSV/clbl7vsUun1t1a2WcPtSee6wRMht0xRKcVHGrQXz9K3NGdxnuTZmSko7Y yIlLMGElN+2kXFo9icJOsmsmHt7VgNRKWxRz1VGdzrhNqsATs2uiV6FWG5+YFxNgD+y1 y2QCrEEPobo/ds2BLlgLcv8xPnU/T8vWLXnFRQQwciNZqZAWyuHRklU+TmBBhuuYBj8L bxig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QXb71uFWhSg39Viv30HgP3y8LahJOu5TtvkjW1YFFmA=; b=PgSKkroe4ZzyMs65xNamT2/A2FA1A97VgD7flikV8oOtMfyvfGfqRz5m7FhMts3sd+ jaj72BUkiFOiVTJoNzCGVtmFNFurX9vOh3VJJhaF3+5WOrfam8qnLRPu1gPdYfsOuuGn u5CMCPbfCti19Amtkjppy4WvFzX3gmTGaTiGKIOrdUCPi8UkZrgXdlCIiPPsmJbGKTSK YUZjFY3C4Y+54zIMb9g8xIBDVjU1Bs+NTx++f55rJwlaimG9vN6VQxVeWTw3a/MKUXo8 yRJUE9airqVYkAVjLe1CpICJUOpzojlVtSdrJWMnB97iO6OYLkl3jZ0iI5umZm+P3EJB sIAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gcXWANYd; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a635205000000b004126f260640si13224831pgb.128.2022.07.25.01.20.11; Mon, 25 Jul 2022 01:20:27 -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=@gmail.com header.s=20210112 header.b=gcXWANYd; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233655AbiGYIKx (ORCPT + 99 others); Mon, 25 Jul 2022 04:10:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbiGYIKv (ORCPT ); Mon, 25 Jul 2022 04:10:51 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D810C12AEE; Mon, 25 Jul 2022 01:10:50 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id ss3so19046220ejc.11; Mon, 25 Jul 2022 01:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QXb71uFWhSg39Viv30HgP3y8LahJOu5TtvkjW1YFFmA=; b=gcXWANYd95QqpDZNjT80H5El43Dovr5S0wOb+dj41WF0UAkuUiJDW2NAi4iQ305XFQ lVVKY0C+iGL0p5tVBSniVcX6zLS8O0o42jiM3VHbf3P2PJwPJY9pNrOD5I3tyZyDgnJy d6DIH0u/YAoFuSujbvAgci/gyOOkxjcOa7FgLYcccmWOMRReiJpRQvj8oeNjtzasRz45 5wI5mC7zC/KC/unitlCB9w7h7MNbq7bWUvDLO3UqaeZF52Xc40wDLTHrTN6lnrUtKqrq 8MOcmmfgBfz1xp4MxADiih/qQe4qXT1ndVyvX9sozOvgmH8wWtATEk7QsOTuHRb8u2m9 CtKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QXb71uFWhSg39Viv30HgP3y8LahJOu5TtvkjW1YFFmA=; b=uWgH9ODpJl474r6KXjDEVNXMUIHKloUQesa+lpBvT9gfOrkrn0B+T3Q27vJlXtAp6n BPfGm52m+sV1famrqspkfZ7wrm4qb/4sKirOIRDddEA8QS/xQVQpYlGa89BlTHd1uKMD Ck59W7FY5dNqH6PdXqV3HwVF/PUZ3yzQQieTe49Qgp9zXGMdn9Sm66PCxdFxD3R/R/im JScxwgVaEUwGKIZSnhKJnKNP77YBL34/WNvYTpc9Gjpdy7MGJF+1rqWs5oaF6AARAIJg qZmXxWh8VOYsaA4GXxStws3zYP/Kup9GHQEuD0Og3t0rkF9Y+4wcrAJhv/a1Hnxf+n0Z rTJQ== X-Gm-Message-State: AJIora+PUM1iINCw3DM2vR7Zb7pJqaBygXJVElTCUVE8D8BtT0aI3K+k jJIFfO0a5yc/OUllci9531HytHQLoWAUEgtAr8Q= X-Received: by 2002:a17:906:9b09:b0:72b:9612:d373 with SMTP id eo9-20020a1709069b0900b0072b9612d373mr8927348ejc.606.1658736649264; Mon, 25 Jul 2022 01:10:49 -0700 (PDT) MIME-Version: 1.0 References: <20220722102407.2205-1-peterwu.pub@gmail.com> <20220722102407.2205-10-peterwu.pub@gmail.com> In-Reply-To: <20220722102407.2205-10-peterwu.pub@gmail.com> From: Andy Shevchenko Date: Mon, 25 Jul 2022 10:10:12 +0200 Message-ID: Subject: Re: [PATCH v6 09/13] iio: adc: mt6370: Add MediaTek MT6370 support To: ChiaEn Wu Cc: Lee Jones , Daniel Thompson , Jingoo Han , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Matthias Brugger , Sebastian Reichel , Chunfeng Yun , Greg Kroah-Hartman , Jonathan Cameron , Lars-Peter Clausen , Liam Girdwood , Mark Brown , Guenter Roeck , "Krogerus, Heikki" , Helge Deller , ChiaEn Wu , Alice Chen , cy_huang , dri-devel , Linux LED Subsystem , devicetree , linux-arm Mailing List , "moderated list:ARM/Mediatek SoC support" , Linux Kernel Mailing List , Linux PM , USB , linux-iio , "open list:FRAMEBUFFER LAYER" , szuni chen , AngeloGioacchino Del Regno Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Fri, Jul 22, 2022 at 12:25 PM ChiaEn Wu wrote: > > From: ChiaEn Wu > > MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger > with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight > driver, display bias voltage supply, one general purpose LDO, and the > USB Type-C & PD controller complies with the latest USB Type-C and PD > standards. > > Add a support the MT6370 ADC driver for system monitoring, including support for the > charger current, voltage, and temperature. ... > +#define MT6370_AICR_400_mA 0x6 > +#define MT6370_ICHG_500_mA 0x4 > +#define MT6370_ICHG_900_mA 0x8 ^^^^ (Note this and read below) ... > + reg_val = FIELD_GET(MT6370_AICR_ICHG_MASK, reg_val); > + if (reg_val < MT6370_AICR_400_mA) > + *val1 = 3350; > + else > + *val1 = 5000; Here... ... > + if (reg_val < MT6370_ICHG_500_mA) > + *val1 = 2375; > + else if (reg_val >= MT6370_ICHG_500_mA && > + reg_val < MT6370_ICHG_900_mA) > + *val1 = 2680; > + else > + *val1 = 5000; ...and especially here it is so counterintuitive to have an if-else chain because the values are not ordered by semantic meaning. What if the new standard/hardware decides to use 0x7 for 100mA (hypothetically)? So, please use switch cases or other robust methods. -- With Best Regards, Andy Shevchenko