Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8556156ybi; Thu, 6 Jun 2019 14:39:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTVZHpOnUuFshY2E4dXABEoZcHxrnGN+d2NFITMcXz0xwAdqBwR4xgKJUHMYYqXT0+/MN9 X-Received: by 2002:a62:7995:: with SMTP id u143mr55566445pfc.61.1559857171060; Thu, 06 Jun 2019 14:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559857171; cv=none; d=google.com; s=arc-20160816; b=wSqxEqiU2cOp86X0IdZf/5mOyKX4b+ajMoo0oB5lw8SPe8NIW9AWTxqRP6TBVsYCeT QC4dbzBFxssCJ+VI5E9SjB+R7UxVvt4WvMsB8UfmHk8p/VP8cnrBYybsLT4QJNNd1Tnv PnbLl24G25PcdsmC0Bh7L2rxcfJfyI6BiWinGA2eIiuuYH0WV4FjAVgOQNSN25BcUBFP 7erwsHRv3SlAAipGvMBCZ422KndmMHyQ7OBgdc+k7effCzHnMr+uWrh2eztYHHNFiXiR lL3xRN+eeL0Dwi204epoVsVN1/WLWYm5INz1n5fUVGziCDr1sOU6ojnhIJAvI+own+Kk l1wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=TDt7h/v0kd9jyNnEaaG9yodaGNQqPQNCl5xz0t2eFwA=; b=LofWA3yAlJW6BXCsVEIBvZJIl/wgecWFK/QU1inoJqp37HTTzRN/DF81R91oK0m/oa Yx8SpQIivQE8ZNJC6Kk39oDt6bBDBB0/PDIDQgBkUnXlSFdtbiXrWs5Nj8h/jNz0cL9L gG14D5Ms7a8Imv1M+8aksBRtoBc/grURN3w5CEMWBFYOHgjSvrVfJg4Le8zo/IEsDUjR FOTjjhSy9vKayocTcMTIDKH/7LYCfDdNnKbAVqxdLSxm/pzIqWyxFEDEBTxj0vxyi/BA gk/ju4ifZoz/0qm2bOfEcmPIEG3DEAMOd73+pwZj7I5Tm84NxTg36KJfjgpQaE1IO85h 6/2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cXshAzMR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si184709plf.382.2019.06.06.14.39.14; Thu, 06 Jun 2019 14:39:31 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cXshAzMR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729785AbfFFSu5 (ORCPT + 99 others); Thu, 6 Jun 2019 14:50:57 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40877 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727238AbfFFSu5 (ORCPT ); Thu, 6 Jun 2019 14:50:57 -0400 Received: by mail-pl1-f195.google.com with SMTP id a93so1274429pla.7; Thu, 06 Jun 2019 11:50:57 -0700 (PDT) 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; bh=TDt7h/v0kd9jyNnEaaG9yodaGNQqPQNCl5xz0t2eFwA=; b=cXshAzMROVZ+Er4MDxibdDbVf0pUnIWeBPc6CP5Zn5SJyMnjdu1GFA40sCjGeIbiYW hfJPmUlu+Sz8SKh+xG94yH21fbFGNL3Ip2ycoiNAhFOUTIjVxKFru1UDT8HRbIo/UCdm o4gB1B9C8lp1ux+uGEPsc7apA/Skx/BtP2o4G9dXH2hU9aL/yRkoqVYC6Pzgk/h/oBFN aJwrEBkpiMTxXHSifLQMO4pXPufqPgCrTMAZ/2EeGveYwEal26E2Z7aMvMpbqbmXDpni dcd5ug1YHHFas2FIp6OZ7g0kFdjHqkLh6vq+rT5EdhCMGqrlAgZHNwY1IA5zJvG3TrOr ySKw== 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; bh=TDt7h/v0kd9jyNnEaaG9yodaGNQqPQNCl5xz0t2eFwA=; b=OdsyFpAKkNn0M2lF40Bl1/QzG8/CpuTSJxuV/3PdYbPv0Sd4H08DYnwqDXCqn3oggw yB1+087pFvBJeEOdtJiBOOVwQYWovXUm0oYyJcBUveUER7v7cyh1VWdFgzFfEM4xuGfi ude5JKSdKOTSYXDoawz+HCpZCSeXDfhktzfgoxL8qNTST5Xe0jKKBB0mOnYERN7XHQ+z FTywvygTO7RdlVN/xhTQBJikiMMeXTFmd8k/EUoxF97w0NqvWfrIP2/EVYHnF6cX+7y/ 7VmLPAFe4k+xWCW9vujsZ3hpKKWdKWhpIDq7OB9x+rv3tQJnObnz3aYef8SUAMtThA1z uNrQ== X-Gm-Message-State: APjAAAXSIgmLMr9lBw/dnATWAdszJOXnMNr4NP6PSuS2ujZqAVhgptwr BLevDxIfPGu10le5DkejWb0= X-Received: by 2002:a17:902:b202:: with SMTP id t2mr50291592plr.69.1559847056796; Thu, 06 Jun 2019 11:50:56 -0700 (PDT) Received: from aw-bldr-10.qualcomm.com (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 139sm3184582pfw.152.2019.06.06.11.50.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 11:50:56 -0700 (PDT) From: Jeffrey Hugo To: lgirdwood@gmail.com, broonie@kernel.org Cc: agross@kernel.org, david.brown@linaro.org, bjorn.andersson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, jorge.ramirez-ortiz@linaro.org, niklas.cassel@linaro.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jeffrey Hugo Subject: [PATCH v2 2/7] drivers: regulator: qcom_spmi: Refactor get_mode/set_mode Date: Thu, 6 Jun 2019 11:49:31 -0700 Message-Id: <20190606184931.39588-1-jeffrey.l.hugo@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190606184842.39484-1-jeffrey.l.hugo@gmail.com> References: <20190606184842.39484-1-jeffrey.l.hugo@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org spmi_regulator_common_get_mode and spmi_regulator_common_set_mode use multi-level ifs which mirror a switch statement. Refactor to use a switch statement to make the code flow more clear. Signed-off-by: Jeffrey Hugo --- drivers/regulator/qcom_spmi-regulator.c | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index fd55438c25d6..1c18fe5969b5 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c @@ -911,13 +911,14 @@ static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev) spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); - if (reg & SPMI_COMMON_MODE_HPM_MASK) + switch (reg) { + case SPMI_COMMON_MODE_HPM_MASK: return REGULATOR_MODE_NORMAL; - - if (reg & SPMI_COMMON_MODE_AUTO_MASK) + case SPMI_COMMON_MODE_AUTO_MASK: return REGULATOR_MODE_FAST; - - return REGULATOR_MODE_IDLE; + default: + return REGULATOR_MODE_IDLE; + } } static int @@ -925,12 +926,19 @@ spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct spmi_regulator *vreg = rdev_get_drvdata(rdev); u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; - u8 val = 0; + u8 val; - if (mode == REGULATOR_MODE_NORMAL) + switch (mode) { + case REGULATOR_MODE_NORMAL: val = SPMI_COMMON_MODE_HPM_MASK; - else if (mode == REGULATOR_MODE_FAST) + break; + case REGULATOR_MODE_FAST: val = SPMI_COMMON_MODE_AUTO_MASK; + break; + default: + val = 0; + break; + } return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); } @@ -1834,9 +1842,9 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) } } - if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_HFS430) { + if (vreg->set_points->count == 1) { /* since there is only one range */ - range = spmi_regulator_find_range(vreg); + range = vreg->set_points->range; vreg->desc.uV_step = range->step_uV; } -- 2.17.1