From nobody Sat May 10 11:33:39 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1610146349; cv=none; d=zohomail.com; s=zohoarc; b=kBXq87TticGKKRD/OSgKjo3FX+smbmbKHjin/e+RXcHCbig8MaoXs0npt1BLsI9PE6+t7+3F8JoIKzl1u7Aa9Sk1jHLQsxB17wH2dsZ7o80j6JmzjUfPVnSYSURsuCHFUG0b3N9fKPHAt8xcWW5L7klbgXVbY5pnp5PDqAtICIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610146349; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Subject:To; bh=MTn9/sf2WP+vAcNsRG2ZW/CUAbf2TQCT32NuGuwVptE=; b=WrYqEAw0GXocAvVV+pAsQCikLl5UN5gsppskZL7Iq7/dAepZtPUrB2R4+wwNPXBOkzfeneMJCF2hpECIZuxV0OeGOU9Ob0HtdL2XZsPuK+fxt/9QSLBauQHCZAasEewoIaeBBUrmBMihnTPVsaLzYSQzWfD9Gf4Hxd8stQji+ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1610146349491829.1497925040737; Fri, 8 Jan 2021 14:52:29 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbhAHWwO (ORCPT ); Fri, 8 Jan 2021 17:52:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbhAHWwN (ORCPT ); Fri, 8 Jan 2021 17:52:13 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4C73C061799; Fri, 8 Jan 2021 14:50:57 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id g185so9689859wmf.3; Fri, 08 Jan 2021 14:50:57 -0800 (PST) Received: from adgra-XPS-15-9570.home (2a01cb0008bd270094076597458eade1.ipv6.abo.wanadoo.fr. [2a01:cb00:8bd:2700:9407:6597:458e:ade1]) by smtp.gmail.com with ESMTPSA id o23sm15900644wro.57.2021.01.08.14.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 14:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MTn9/sf2WP+vAcNsRG2ZW/CUAbf2TQCT32NuGuwVptE=; b=h8Y06fXUNifmcBRDKjduA9iraYXESamRmjF9O235AD9AswsWcWShCxDpT183OGuf66 pbbLpr0pmoH0pr6Bua6CsjBdcMNyY4Q/V0Ldl1vfHmKuyIRWNb02mql/W1OEIWoPoN88 1G8JaHmJc6y8YuhtyxfLCUsCL3R9P24yxIoyd3Mv35nyDZ5BmN0fwXIXpJlQklB1Z4+Z 7SsaJ8dnyaF3u7Fr8Qf4o42xvomA16Bzueyfyaw61TCJcCYGNBsKNpEd3E2hpjVzIPCp HuZ1ftqWQ1xj8qj7qD10hUdzwf7viSTbZbNBcwxHqETbQEOeEbS49p0Hgd7sYXrVKsGn BhGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MTn9/sf2WP+vAcNsRG2ZW/CUAbf2TQCT32NuGuwVptE=; b=EBuVXjY42Cy+xNtQ/aChJWht8b5HkzHz8BVYUu1I0ZJhIm5eSxrndoDkRvEYbtdBf5 PUMoJe3VaZdsfHpsW8aYhGxqIW4wsUSCX4sECWkaBzmimfs7ADGNv8sv3nkbN0aXYZoD QmIsLgOM9hTJoVdzZXtJAhuRyVKVLNZiDVARyCSe+VBHaSCRZZHU4HZuvyiHABmsaeDV E69ngL0Ye9FF1lWy7qwbPIBReB7ALeK19x2rBhOdGdA+klNS7Uhf0MwOkgvar35zBl6+ 0ScQjHgms87j1iUkFL8ibBWuSphcUCSrwgESmhzdqAswzrSO1tDTCNzxjqbqQA2mdDjx jx4Q== X-Gm-Message-State: AOAM533P+Yl7xL7BFpwHOSVqAHr3+mPbybgf9TOgCcSZmhNSjynL60MY xhQV7ueh1Zn5P65Wmb2ToFc= X-Google-Smtp-Source: ABdhPJwNJvGE+k5cr857pWNImY3bh1V0Yl3EQMVcQoOrQy7yyvNxR0aEaZ9zCWC/rs3aTBZgCsvqpw== X-Received: by 2002:a1c:3cd5:: with SMTP id j204mr4801107wma.53.1610146256506; Fri, 08 Jan 2021 14:50:56 -0800 (PST) From: Adrien Grassein Cc: broonie@kernel.org, jagan@amarulasolutions.com, lgirdwood@gmail.com, robh+dt@kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Adrien Grassein Subject: [PATCH v3 6/6] regulator: pf8x00: fix nxp,phase-shift Date: Fri, 8 Jan 2021 23:50:06 +0100 Message-Id: <20210108225006.153700-7-adrien.grassein@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108225006.153700-1-adrien.grassein@gmail.com> References: <20210108225006.153700-1-adrien.grassein@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fix the ternary condition which is a bad coding style in the kernel I also remove the defering configuration of the nxp,phase-shift. The configuration is now done at parsing time. It save some memory and it's better for comprehension. I also use the OTP default configuration when the parameter is wrong or not specified. I think that it's better to use the default configuration from the chip than an arbitrary value. Signed-off-by: Adrien Grassein --- drivers/regulator/pf8x00-regulator.c | 45 +++++++++++++--------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/regulator/pf8x00-regulator.c b/drivers/regulator/pf8x0= 0-regulator.c index 4b57f74e7326..9932a580619c 100644 --- a/drivers/regulator/pf8x00-regulator.c +++ b/drivers/regulator/pf8x00-regulator.c @@ -107,7 +107,6 @@ enum pf8x00_ldo_states { =20 #define PF8X00_SWXILIM_MASK GENMASK(4, 3) #define PF8X00_SWXPHASE_MASK GENMASK(2, 0) -#define PF8X00_SWXPHASE_DEFAULT 0 #define PF8X00_SWXPHASE_SHIFT 7 =20 enum pf8x00_devid { @@ -121,7 +120,6 @@ enum pf8x00_devid { =20 struct pf8x00_regulator { struct regulator_desc desc; - u8 phase_shift; }; =20 struct pf8x00_chip { @@ -167,17 +165,13 @@ static const int pf8x00_vsnvs_voltages[] =3D { 0, 1800000, 3000000, 3300000, }; =20 -static struct pf8x00_regulator *desc_to_regulator(const struct regulator_d= esc *desc) -{ - return container_of(desc, struct pf8x00_regulator, desc); -} - static int pf8x00_of_parse_cb(struct device_node *np, const struct regulator_desc *desc, struct regulator_config *config) { - struct pf8x00_regulator *data =3D desc_to_regulator(desc); struct pf8x00_chip *chip =3D config->driver_data; + unsigned char id =3D desc->id - PF8X00_LDO4; + unsigned char reg =3D PF8X00_SW_BASE(id) + SW_CONFIG2; int phase; int val; int ret; @@ -185,21 +179,30 @@ static int pf8x00_of_parse_cb(struct device_node *np, ret =3D of_property_read_u32(np, "nxp,phase-shift", &val); if (ret) { dev_dbg(chip->dev, - "unspecified phase-shift for BUCK%d, use 0 degrees\n", - desc->id - PF8X00_LDO4); - val =3D PF8X00_SWXPHASE_DEFAULT; + "unspecified phase-shift for BUCK%d, using OTP configuration\n", + id); + goto end; } =20 - phase =3D val / 45; - if ((phase * 45) !=3D val) { + if (val < 0 || val > 315 || val % 45 !=3D 0) { dev_warn(config->dev, - "invalid phase_shift %d for BUCK%d, use 0 degrees\n", - (phase * 45), desc->id - PF8X00_LDO4); - phase =3D PF8X00_SWXPHASE_SHIFT; + "invalid phase_shift %d for BUCK%d, using OTP configuration\n", + val, id); + goto end; } =20 - data->phase_shift =3D (phase >=3D 1) ? phase - 1 : PF8X00_SWXPHASE_SHIFT; + phase =3D val / 45; + + if (phase >=3D 1) + phase -=3D 1; + else + phase =3D PF8X00_SWXPHASE_SHIFT; + + regmap_update_bits(chip->regmap, reg, + PF8X00_SWXPHASE_MASK, + phase); =20 +end: return 0; } =20 @@ -432,14 +435,6 @@ static int pf8x00_i2c_probe(struct i2c_client *client) "failed to register %s regulator\n", data->desc.name); return PTR_ERR(rdev); } - - if ((id >=3D PF8X00_BUCK1) && (id <=3D PF8X00_BUCK7)) { - u8 reg =3D PF8X00_SW_BASE(id) + SW_CONFIG2; - - regmap_update_bits(chip->regmap, reg, - PF8X00_SWXPHASE_MASK, - data->phase_shift); - } } =20 return 0; --=20 2.25.1