Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp994794rwl; Wed, 5 Apr 2023 10:20:02 -0700 (PDT) X-Google-Smtp-Source: AKy350bGjN5YuMug6DWW1I91IjglVi5ufeJdqI9OidWs96RmncPMbdijKLXg7zZjiP08mTo1De+8 X-Received: by 2002:a17:90b:4f83:b0:23f:9445:318e with SMTP id qe3-20020a17090b4f8300b0023f9445318emr3233477pjb.3.1680715202511; Wed, 05 Apr 2023 10:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680715202; cv=none; d=google.com; s=arc-20160816; b=QcyfNOz4tgMEr0xZMcbnEcDUAt4Sl/UlKa6Emuav0ScjNNix2u0tZLe3dtfvs/In55 inMs6azA8NmbUBO41pY5vHGP564tOmkoH4jBpnoe25tX60mvyxd3AE23RJQgtAmmGcGq Jh18f7PpxwT8MMQPSaZdV70Qx4UPtWaXQgpZvk3jQ7Xp4g0zf9dO+bhWeqO0bZn/y6J9 MhNWIttV4HpHY5nTjvlGEH168WuHJuYVbR1AgbJ154tnUf7k7+nHwrZtYde2mSQtkzAj RezpUORiigKvnudIvEMKU4JugIxLny6KCGM1Hz2JSUqERSJV/0tMDXQSeImfZLSqK4ob ahHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=t1MNaffuvyVWLXyLQ6lRNzfTJfcAUGjlFHNhQFdXp8E=; b=exNCBFvD2y4soXzlgpC+c1Pba/M4FrIOXcgpDeh7dwhI8dP0j6ira2GLCcbx3fpHu7 Rt5sgdIORpDhB0FiL9qB/FeRUZmYVzt8OL9dAGuDzte+iWKFbSsVbJYTsbZyHClogA41 j34UWjV/b3H2qFMXyPkc3wC4TO930Q8QhJycOiUPKKHe5cNb4gIO04LS/tVLtmB0Co7o F8pajUinyU+D0bgPCljrdP6FKe6Ir0W5Fi1AQ2syScF7MsmcuXe8V/GtXNvxw5YZBeVw Q9Nwi8HVrZP/1lZoPkTrVBFaRxDCCBvlCq7+05PIjRKsA9P+FUJMTEyVXrmBuDDLMRsQ u7qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=necvQ0RU; 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 x22-20020a17090a0bd600b0023d3f169c1csi1742682pjd.2.2023.04.05.10.19.50; Wed, 05 Apr 2023 10:20:02 -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=necvQ0RU; 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 S233074AbjDERPR (ORCPT + 99 others); Wed, 5 Apr 2023 13:15:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbjDERPI (ORCPT ); Wed, 5 Apr 2023 13:15:08 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2BED5B81; Wed, 5 Apr 2023 10:15:06 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id ev7so7622773qvb.5; Wed, 05 Apr 2023 10:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680714906; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=t1MNaffuvyVWLXyLQ6lRNzfTJfcAUGjlFHNhQFdXp8E=; b=necvQ0RUkjIYKGcUKjnlMsbAs/R7KTYbS1sbZjsMBWTmc3Cdfs9FdRAJJSpnS0SR1Q uXlN/daZrSLE77aAF9x4bRtegwHo7n0Gs5fzxuXzk6Gs7cn8SNLI4z6HLXXaGGgCXL+S n8gyLeyOqitneWHgm7Qlk7GnGcEJnL2JpcJAHqkHu0kbrM6D/mGGgnfF3Zj89t0BWw0S KCs172JHRuSg5zv68dt9Yo1a8ZqK4SdLH3HAy6wGej64TIzWZw9JeV5KH+rJ92QbKLWB E+1ixS8JWRtJpIPK+tJ1TdJECMXpq6UYYmKIidPzD4yNWM56UFwuB6LLRLreWAgdlh7r EW4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680714906; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t1MNaffuvyVWLXyLQ6lRNzfTJfcAUGjlFHNhQFdXp8E=; b=OmvncK3lbHAycK1xQyi169byNWie7zXa4sH2iA2PQFPLuh2ZZ04rksqiVmqEtdFSvL A8Cfg4MuNCOCsYbmwsfXuF2WhRJuKXDYOwzxp2uw2AIpuC4r18bp0vJKPn/rjBbqT4S4 gqcQBw78J4J0bznt2bwuBKQAHzH373CB0XWEGSS6EZYo7ePI5c5RPUQm2cqBYwZ0pXGP yEZEKxaOZ0s74S+vTmljNm8Vq8aIBnnpr3UA+UhzrirxRW7Rgs+YlapspTaE9szhqCOO s6okKm3+U/nLcZgFk/hoNLcmile+Ua4qYBtCp+Vd0Pj/q16xzOuCuqOUvV4Lci83EsCm zwjw== X-Gm-Message-State: AAQBX9fwgt0tTWfbOj1J1LhuuRjf2I2hcOok737fSMQmTylfZZYVv4Jz J/xB0ahvhzPWXlmYzqGF0WQ= X-Received: by 2002:a05:6214:2401:b0:5db:4e49:b2bd with SMTP id fv1-20020a056214240100b005db4e49b2bdmr6544289qvb.18.1680714905746; Wed, 05 Apr 2023 10:15:05 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id ct9-20020a056214178900b005dd8b934571sm4403209qvb.9.2023.04.05.10.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 10:15:05 -0700 (PDT) From: Benjamin Bara Date: Wed, 05 Apr 2023 19:14:35 +0200 Subject: [PATCH v3 2/3] regulator: da9063: implement setter for voltage monitoring MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230403-da9063-disable-unused-v3-2-cc4dc698864c@skidata.com> References: <20230403-da9063-disable-unused-v3-0-cc4dc698864c@skidata.com> In-Reply-To: <20230403-da9063-disable-unused-v3-0-cc4dc698864c@skidata.com> To: Support Opensource , Liam Girdwood , Mark Brown , Lee Jones , Rob Herring , Krzysztof Kozlowski , Steve Twiss Cc: DLG-Adam.Thomson.Opensource@dm.renesas.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Matti Vaittinen , Benjamin Bara X-Mailer: b4 0.12.2 X-Spam-Status: No, score=0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 From: Benjamin Bara Allow to en- and disable voltage monitoring from the device tree. Consider that the da9063 only monitors under- *and* over-voltage together, so both must be set to the same severity and value. Signed-off-by: Benjamin Bara --- drivers/regulator/da9063-regulator.c | 118 ++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 28 deletions(-) diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c index 1c720fc595b3..6f1d77e486fc 100644 --- a/drivers/regulator/da9063-regulator.c +++ b/drivers/regulator/da9063-regulator.c @@ -207,6 +207,24 @@ static const unsigned int da9063_bmem_bio_merged_limits[] = { 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000 }; +static int da9063_set_xvp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable) +{ + struct da9063_regulator *regl = rdev_get_drvdata(rdev); + struct device *dev = regl->hw->dev; + + dev_dbg(dev, "%s: lim: %d, sev: %d, en: %d\n", regl->desc.name, lim_uV, severity, enable); + + /* + * only support enable and disable. + * the da9063 offers a GPIO (GP_FB2) which is unasserted if an XV happens. + * therefore ignore severity here, as there might be handlers in hardware. + */ + if (lim_uV) + return -EINVAL; + + return regmap_field_write(regl->vmon, enable ? 1 : 0); +} + static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct da9063_regulator *regl = rdev_get_drvdata(rdev); @@ -545,37 +563,41 @@ static int da9063_buck_get_current_limit(struct regulator_dev *rdev) } static const struct regulator_ops da9063_buck_ops = { - .enable = regulator_enable_regmap, - .disable = regulator_disable_regmap, - .is_enabled = regulator_is_enabled_regmap, - .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = regulator_set_voltage_sel_regmap, - .list_voltage = regulator_list_voltage_linear, - .set_current_limit = da9063_buck_set_current_limit, - .get_current_limit = da9063_buck_get_current_limit, - .set_mode = da9063_buck_set_mode, - .get_mode = da9063_buck_get_mode, - .get_status = da9063_buck_get_status, - .set_suspend_voltage = da9063_set_suspend_voltage, - .set_suspend_enable = da9063_suspend_enable, - .set_suspend_disable = da9063_suspend_disable, - .set_suspend_mode = da9063_buck_set_suspend_mode, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear, + .set_current_limit = da9063_buck_set_current_limit, + .get_current_limit = da9063_buck_get_current_limit, + .set_mode = da9063_buck_set_mode, + .get_mode = da9063_buck_get_mode, + .get_status = da9063_buck_get_status, + .set_suspend_voltage = da9063_set_suspend_voltage, + .set_suspend_enable = da9063_suspend_enable, + .set_suspend_disable = da9063_suspend_disable, + .set_suspend_mode = da9063_buck_set_suspend_mode, + .set_over_voltage_protection = da9063_set_xvp, + .set_under_voltage_protection = da9063_set_xvp, }; static const struct regulator_ops da9063_ldo_ops = { - .enable = regulator_enable_regmap, - .disable = regulator_disable_regmap, - .is_enabled = regulator_is_enabled_regmap, - .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = regulator_set_voltage_sel_regmap, - .list_voltage = regulator_list_voltage_linear, - .set_mode = da9063_ldo_set_mode, - .get_mode = da9063_ldo_get_mode, - .get_status = da9063_ldo_get_status, - .set_suspend_voltage = da9063_set_suspend_voltage, - .set_suspend_enable = da9063_suspend_enable, - .set_suspend_disable = da9063_suspend_disable, - .set_suspend_mode = da9063_ldo_set_suspend_mode, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear, + .set_mode = da9063_ldo_set_mode, + .get_mode = da9063_ldo_get_mode, + .get_status = da9063_ldo_get_status, + .set_suspend_voltage = da9063_set_suspend_voltage, + .set_suspend_enable = da9063_suspend_enable, + .set_suspend_disable = da9063_suspend_disable, + .set_suspend_mode = da9063_ldo_set_suspend_mode, + .set_over_voltage_protection = da9063_set_xvp, + .set_under_voltage_protection = da9063_set_xvp, }; /* Info of regulators for DA9063 */ @@ -749,6 +771,41 @@ static const struct regulator_init_data *da9063_get_regulator_initdata( return NULL; } +static int da9063_check_xvp_constraints(struct regulator_config *config) +{ + struct da9063_regulator *regl = config->driver_data; + const struct regulation_constraints *constr = &config->init_data->constraints; + const struct notification_limit *uv_l = &constr->under_voltage_limits; + const struct notification_limit *ov_l = &constr->over_voltage_limits; + + /* make sure that only one severity is used to clarify if unchanged, enabled or disabled */ + if ((!!uv_l->prot + !!uv_l->err + !!uv_l->warn) > 1) { + dev_err(config->dev, "%s: at most one voltage monitoring severity allowed!\n", + regl->desc.name); + return -EINVAL; + } + + /* make sure that UV and OV monitoring is set to the same severity and value */ + if (uv_l->prot != ov_l->prot) { + dev_err(config->dev, + "%s: protection-microvolt: value must be equal for uv and ov!\n", + regl->desc.name); + return -EINVAL; + } + if (uv_l->err != ov_l->err) { + dev_err(config->dev, "%s: error-microvolt: value must be equal for uv and ov!\n", + regl->desc.name); + return -EINVAL; + } + if (uv_l->warn != ov_l->warn) { + dev_err(config->dev, "%s: warn-microvolt: value must be equal for uv and ov!\n", + regl->desc.name); + return -EINVAL; + } + + return 0; +} + static struct of_regulator_match da9063_matches[] = { [DA9063_ID_BCORE1] = { .name = "bcore1" }, [DA9063_ID_BCORE2] = { .name = "bcore2" }, @@ -970,6 +1027,11 @@ static int da9063_regulator_probe(struct platform_device *pdev) if (da9063_reg_matches) config.of_node = da9063_reg_matches[id].of_node; config.regmap = da9063->regmap; + + ret = da9063_check_xvp_constraints(&config); + if (ret) + return ret; + regl->rdev = devm_regulator_register(&pdev->dev, ®l->desc, &config); if (IS_ERR(regl->rdev)) { -- 2.34.1