Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1174096imm; Tue, 15 May 2018 15:08:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoFvdo1DEAJ6tmYMC3igRpjBOmPLfb7nc3MzNNy53tcmy6iGx/TXuOdU1HIA5Yn71B/caVX X-Received: by 2002:a62:850f:: with SMTP id u15-v6mr16776458pfd.160.1526422088215; Tue, 15 May 2018 15:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526422088; cv=none; d=google.com; s=arc-20160816; b=ldVVyn2tjYdsFqkLdvVtaDnOXke94MAl95BtvbTklwUdvW01D1Yj8MjLZ5V2stRyXt uV1elar/uy/1DTa68/dN+/Bemor+PZaeDF570dYq4wXfycHqs90KaKYBXkhVDYOjcbv+ Rk6h1xHQF2/Hy3dMRsSTHAzp1FhJ2NM3DD5L99Y49NH6urv3ke/I9oJMwS6GFdWyHORd 2Vxua6tIh9YE9wEj6HQPFW8dKxvYG7sn3HhxfnDWsWE0prAlB1YNsBjqqnwOIitOQxw7 jE/tm1JruLrW853pbmOZ1iVfI6JjPQ1cf6IDo3UQJJOz2wiMRdBOvcEFzu06JpJeOvd6 zzAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=0LhtYs4skRucyZm1e8u+36dPVdR7+jvOyCs6ITfv7Ik=; b=a8YlFs2mwe7jmoEK1rDMB7s42y3pMj2G21tf2R1p6KKTZzVt4WvJpmMqw1rox0WHT9 sg2V+GRZCj1jc4kWBlnBQXXuZJqs+Sh0Q1uf7EnG2d2BNnPlgYjm503uTE5H7EC5qzg3 phxfxpbUgf+E4Ft0bXu9MWxjR++SW1uLOp/6tgnhA7vlAUv9SlIlf9UNVv+CkAKSzVS7 M1tqiaJSQ/RFgX92cs+leh3FY5goWCXZqS1u7yODcIKcpPbjIvGAVIUoQGFXOXvjONnD zT4a4T/nlDmRLVAxeOnCbRhCweut0AvWzY590FXitxKQ7ttSXuYB83KEQ2fDG98el/jl DGNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H6C45lEF; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m13-v6si804067pgp.542.2018.05.15.15.07.53; Tue, 15 May 2018 15:08:08 -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=@chromium.org header.s=google header.b=H6C45lEF; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752015AbeEOWHp (ORCPT + 99 others); Tue, 15 May 2018 18:07:45 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:42045 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751104AbeEOWHo (ORCPT ); Tue, 15 May 2018 18:07:44 -0400 Received: by mail-pf0-f193.google.com with SMTP id p14-v6so713679pfh.9 for ; Tue, 15 May 2018 15:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=0LhtYs4skRucyZm1e8u+36dPVdR7+jvOyCs6ITfv7Ik=; b=H6C45lEFPQl5weUNORsSVhRgsxwDMDiRJn82mp8bmUIPOGmmoo74/3tiQ/O9WDHYb+ t/K98xLLhcRemJyeU8C6kOZYfouoZk5xhIpU/QdKsKpfFo5j/FLtbm+yudGQwhEFdRfz XJevjMRv3bWZssmIdzuIFc5MJeSEI9r0UqSp0= 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; bh=0LhtYs4skRucyZm1e8u+36dPVdR7+jvOyCs6ITfv7Ik=; b=Zn7UhKPVe4Fs2SOnQe3xft2AJ4Lm94LHcmLgS3CqjXbjeXchGtKdbv02BDmMNy0z0E b0prjOUDJzwO56NSYmC6JJAStQ3JatNrN84z9v3PM/G8KL2UTh2JdXUCCaX1a0g3bPdv fvvGorPIvPhsCKQtgBcMy08OtaEq125piC/wr2PuX6ghzbNrmLymLy0PDU/aDVRF7Uk1 0qLnLMELAjW6WbbdXi8JMVMh7ohqV6mpCMOag6cxrv4Z+HJuPg0OCuXrBaG9QDftVims WWEJr7mWDrCqD3to4CEFzJ7a1cmAnbCD5ebOlauEoDHKTUO0Qx9Vyu4308LNsOYTfMfs 0Nyw== X-Gm-Message-State: ALKqPwcF89RwmRe5gGPZNI2YKqnoduObixIN+CPYpddRKK+fHBYvkCOJ /5SWhEQFx7B9jpeEYWEf6DREBg== X-Received: by 2002:a65:48c9:: with SMTP id o9-v6mr13950525pgs.106.1526422063949; Tue, 15 May 2018 15:07:43 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:0:1000:1511:bde7:107f:fd5:44c8]) by smtp.gmail.com with ESMTPSA id z15-v6sm949062pgr.55.2018.05.15.15.07.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 15:07:43 -0700 (PDT) From: Douglas Anderson To: broonie@kernel.org Cc: mka@chromium.org, collinsd@codeaurora.org, Douglas Anderson , Liam Girdwood , linux-kernel@vger.kernel.org Subject: [PATCH] regulator: core: Allow for regulators that can't be read at bootup Date: Tue, 15 May 2018 15:07:17 -0700 Message-Id: <20180515220717.254950-1-dianders@chromium.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Regulators attached via RPMh on Qualcomm sdm845 apparently are write-only. Specifically you can send a request for a certain voltage but you can't read back to see what voltage you've requested. What this means is that at bootup we have absolutely no idea what voltage we could be at. As discussed in the patches to try to support the RPMh regulators [1], the fact that regulators are write-only means that its driver's get_voltage_sel() should return an error code if it's called before any calls to set_voltage_sel(). This causes problems in machine_constraints_voltage() when trying to apply the constraints. A proposed fix was to come up with an error code that could be returned by get_voltage_sel() which would cause the regulator framework to simply try setting the voltage with the current constraints. In this patch I propose the error code -ENOTRECOVERABLE. In errno.h this error is described as "State not recoverable". Though the error code was originally intended "for robust mutexes", the description of the error code seems to apply here because we can't read the state of the regulator. Also note that the only existing user of this error code in the regulator framework is tps65090-regulator.c which returns this error code from the enable() call (not get_voltage() or get_voltage_sel()), so there should be no existing regulators that might accidentally get the new behavior. (Side note is that tps65090 seems to interpret this error code to mean an error that you can't recover from rather than some data that can't be recovered). [1] https://patchwork.kernel.org/patch/10340897/ Signed-off-by: Douglas Anderson --- If this patch is accepted then we'll need to update the latest RPMh regulator patch to return it. The current patch returns -EINVAL which means that the regulator always fails. drivers/regulator/core.c | 12 ++++++++++++ include/linux/regulator/driver.h | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d4803460a557..fe314ff56772 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -886,6 +886,18 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, rdev->constraints->min_uV && rdev->constraints->max_uV) { int target_min, target_max; int current_uV = _regulator_get_voltage(rdev); + + if (current_uV == -ENOTRECOVERABLE) { + /* This regulator can't be read and must be initted */ + rdev_info(rdev, "Setting %d-%duV\n", + rdev->constraints->min_uV, + rdev->constraints->max_uV); + _regulator_do_set_voltage(rdev, + rdev->constraints->min_uV, + rdev->constraints->max_uV); + current_uV = _regulator_get_voltage(rdev); + } + if (current_uV < 0) { rdev_err(rdev, "failed to get the current voltage(%d)\n", diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 4fc96cb8e5d7..14e512ad6d4f 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -81,9 +81,12 @@ struct regulator_linear_range { * @set_voltage_sel: Set the voltage for the regulator using the specified * selector. * @map_voltage: Convert a voltage into a selector - * @get_voltage: Return the currently configured voltage for the regulator. + * @get_voltage: Return the currently configured voltage for the regulator; + * return -ENOTRECOVERABLE if regulator can't be read at + * bootup and hasn't been set yet. * @get_voltage_sel: Return the currently configured voltage selector for the - * regulator. + * regulator; return -ENOTRECOVERABLE if regulator can't + * be read at bootup and hasn't been set yet. * @list_voltage: Return one of the supported voltages, in microvolts; zero * if the selector indicates a voltage that is unusable on this system; * or negative errno. Selectors range from zero to one less than -- 2.17.0.441.gb46fe60e1d-goog