Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp208074ybi; Thu, 13 Jun 2019 14:27:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFK4VtlLXQlOMGsXOPK1Vu51dEln1kFHrLne8Fka6v4GDCdvPgYEuR0sSLQJrhr3G1kiQ1 X-Received: by 2002:a65:44cb:: with SMTP id g11mr32042431pgs.193.1560461250990; Thu, 13 Jun 2019 14:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560461250; cv=none; d=google.com; s=arc-20160816; b=ELVC/3x0//YdCtdeTxqS3k6rHLzStnxtPH04lBJ3zYLejJh86qGp5E5dG+DIZk96mD F7x6JkUj8rIRGxhYfJFYDWBOKoPGOwSvrteBU3sdVeE8vRV+x8EFgaZcxJB1O/G9AJJ0 kxm+aJLOwbifK2dYhr/I6XBO+kG6mAsihV5j91wIQninewX8aDibCkzzSEi+Srwo3fbN F6qCjrLlzxcwjio3hiDipeN8gVjVYyRLRWWuMmSQPuX3W/lDZNI5dx/UsGPDfLW6xttl GcwX1Ws6wD5uenrrpTHLD4s2y8QdQPhzYBohW/fF/Ilvofa9nNgDTRrLotXhxqtSiLL/ OMzw== 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=5+TFtA79aZ+IjNk4lXxAZtuIhR9lTbHQLneZLDhsOTI=; b=0mgFqpAWaor8fe6dfeYYsm9JkZ3YQRDYW2O0ooIEkM94uG18o0CkXFmuM5cJw5jp25 QeGz4ai14hoCshRSX5EMGso66Oi4HthZOrq7Fiwda+WkgfzKb2Oe/QIVLaY6PLcl/lDR kKSgrhf7lsA20+Uexo7QdcXBYeTJ8NF2Ukp6URDfjqX8HKBJg0MZyooZj2N2A7qp+Bm/ CR2N/1DhSOvVQT9266Gzxaz5hvfDQDrSwN5kDVsaeBZpbj/3kN/KyBQ0xBFjCkE65rCM 8iGCSln0osKyc3IjaPQ2Eba/gq3t2OeSRzufSC/jqsBstPChIh8mwgz6pOj8nAFXS/nZ 35gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uMIEjubq; 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 w12si644544pgl.310.2019.06.13.14.27.16; Thu, 13 Jun 2019 14:27:30 -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=uMIEjubq; 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 S1728630AbfFMVZp (ORCPT + 99 others); Thu, 13 Jun 2019 17:25:45 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35878 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfFMVZo (ORCPT ); Thu, 13 Jun 2019 17:25:44 -0400 Received: by mail-pf1-f195.google.com with SMTP id r7so59435pfl.3; Thu, 13 Jun 2019 14:25:44 -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=5+TFtA79aZ+IjNk4lXxAZtuIhR9lTbHQLneZLDhsOTI=; b=uMIEjubqF6WKPWVjK7XNOAySKJKkv5jSfxkvZ3/roI+8lQePsCvI2lCFstJqXAdZkN S+YIT+Fi6msM8J8ypbwHiyND64I2FVfr22MAlOuAA8i9ehTBNIVJM6DQXfdvvBL/qQKL 7QCGMCbmx+hvUmJxlV80JNaG3f2CmSbdwucYCy3cVvVLQwf7CAlcR0DS+vvVNJb8ami4 YKOeqVcKi0Ur0EQine6oclQTAKAv3GLamNd0eHZonC9SAVXP+r52aCRIW2pP4Rttahe5 xDFsDI1AbWqAuuGSBKSmblnGtn3xhEX0eOHE4AY76Ayhn66J3KFwBpFAf2KflTGGxqQS Fhfg== 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=5+TFtA79aZ+IjNk4lXxAZtuIhR9lTbHQLneZLDhsOTI=; b=XHsQySmwm8f0mgrokBaa1zPl8q1FauOhYCkboJG/yqtFBrgOEVFlZCGBylKqVj/8Dt CQ08em/8rd3kLSyeaLboooCrHvx5GPGVEk1UTPe+k3jLJeak7ZSYrVKpVOrFPN69e1ae Dpcdx94bWh9aOpi/UoTZIbxAbhMBi8guxxCndluH6d7yIF/dzFv0JnL4NF/jBl6nZJ0f jtjWVNy0U/HxL/CqsrrA/Gmb+5+gtSfMz0jkWFQgPdJpoB19cDdWAQEUohVoMH5oEVoG se8IomCwGL2/GgZ76L5pyuTgqC/Xlo1015qSK18Fwqx3yYCdIxT+4Xy0DTos6pj0ZOOK rESw== X-Gm-Message-State: APjAAAVM3M+SDHZ8EwvKh1mue1MEGfrEQF+MpKsK8hw7CeA/BSf9is0S JFMo4Ejczdf/Pvh4odylNrd7Eskg X-Received: by 2002:a65:624f:: with SMTP id q15mr32323372pgv.436.1560461143720; Thu, 13 Jun 2019 14:25:43 -0700 (PDT) Received: from aw-bldr-10.qualcomm.com (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id j22sm618471pfh.71.2019.06.13.14.25.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 14:25:43 -0700 (PDT) From: Jeffrey Hugo To: lgirdwood@gmail.com, broonie@kernel.org Cc: agross@kernel.org, bjorn.andersson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jeffrey Hugo Subject: [PATCH v4 2/7] regulator: qcom_spmi: Refactor get_mode/set_mode Date: Thu, 13 Jun 2019 14:25:31 -0700 Message-Id: <20190613212531.10452-2-jeffrey.l.hugo@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190613212531.10452-1-jeffrey.l.hugo@gmail.com> References: <20190613212436.6940-1-jeffrey.l.hugo@gmail.com> <20190613212531.10452-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 | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index 42c429d50743..1b3383a24c9d 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c @@ -911,13 +911,16 @@ 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) - return REGULATOR_MODE_NORMAL; + reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; - if (reg & SPMI_COMMON_MODE_AUTO_MASK) + switch (reg) { + case SPMI_COMMON_MODE_HPM_MASK: + return REGULATOR_MODE_NORMAL; + case SPMI_COMMON_MODE_AUTO_MASK: return REGULATOR_MODE_FAST; - - return REGULATOR_MODE_IDLE; + default: + return REGULATOR_MODE_IDLE; + } } static int @@ -925,12 +928,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); } -- 2.17.1