From patchwork Fri Jul 10 05:29:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11655725 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57C2613B4 for ; Fri, 10 Jul 2020 05:30:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A6A92078C for ; Fri, 10 Jul 2020 05:30:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AzRvCMOb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727879AbgGJF3g (ORCPT ); Fri, 10 Jul 2020 01:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726965AbgGJF3f (ORCPT ); Fri, 10 Jul 2020 01:29:35 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B456CC08C5CE for ; Thu, 9 Jul 2020 22:29:34 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id k5so1769049plk.13 for ; Thu, 09 Jul 2020 22:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MSKivOm6p95vIF+xsCRXaxJ3RfMT5lkhjSXb8u6KQ/A=; b=AzRvCMObicHfAfSGOvZ/3ah30NFhC9vr98FBzkz4giER7xo0+6P8IUylJlSB5/iQOR 1VvOmSZfn07xLWzFBVbYNkXjFg5/hEO4mAIjtWCjDZKYF0WBcXc5x8h2sdfAKITqM93m LUfaYqFINu/y79ulwbcZypq3lkFVnBCWH1l8ygT14B3kZ9YGTiHyprIxFwmU0k1l+HHd 5RxkB4R1JoSG7iDSma0TeNvG6sLp9NzsoiJeSr+vlqkMS9EVRC0eRrWBRFv89p18uB+g nncHWKBmkoKK4W5ti6WZD3IBE+fVVtlKe4GcgJa2iBw6MKpBOP89QqIM4BZ/jnMg9dxq DdIg== 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=MSKivOm6p95vIF+xsCRXaxJ3RfMT5lkhjSXb8u6KQ/A=; b=UCQHjoU8qDkAQKEvNx9kW6fYti28inJN57oOUlAv5AGsnhTpf9ZkcOyMjX4i0bIfhi V9bDvBGxfvQkWbm1xF5hUS+ymaBxEhEXYLmdlkUlQkun4yR1AKVsU4/QwZGTKVTiwlc9 lrz3D9NCb1QgmgtWHoLSYM8Qe+dvMLUbLqlQOiVx7S2cKxWtRdCdTKlLXkApOJksXZbh 3dMk6kXm538oxw5//5f5rB1fHNCBQTM4CGzGA0hzK+XNwxHTTn8jn0cdrLtvUq8qYHJf CEfgHCPf3rIDKWHvRdoR79aayJ8/b8EsisDUA0wsdJa0kZ4AkJP5z6R1EO6k9dRqrvr2 Ryhw== X-Gm-Message-State: AOAM533GL+nqu3mCEeci278/TbGWQ7RmJWBsaV8Tc9GHQJZwMmqVOqW/ y38BPJWQOK6E0k4q6KXS0/TlxQ== X-Google-Smtp-Source: ABdhPJxBqKnOiFN5zT4yMxUULpbvDRje/8up4OMyF5ylvIfzUsV3GPVWeC5YvCbNeZXYWmyPOLd9Bw== X-Received: by 2002:a17:902:ab94:: with SMTP id f20mr15348562plr.232.1594358973974; Thu, 09 Jul 2020 22:29:33 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id j17sm4168320pgn.87.2020.07.09.22.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 22:29:33 -0700 (PDT) From: Sumit Semwal To: agross@kernel.org, bjorn.andersson@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org Cc: nishakumari@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kgunda@codeaurora.org, rnayak@codeaurora.org, Sumit Semwal Subject: [RESEND: PATCH v5 1/4] regulator: Allow regulators to verify enabled during enable() Date: Fri, 10 Jul 2020 10:59:16 +0530 Message-Id: <20200710052919.2611-2-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200710052919.2611-1-sumit.semwal@linaro.org> References: <20200710052919.2611-1-sumit.semwal@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Some regulators might need to verify that they have indeed been enabled after the enable() call is made and enable_time delay has passed. This is implemented by repeatedly checking is_enabled() upto poll_enabled_time, waiting for the already calculated enable delay in each iteration. Signed-off-by: Sumit Semwal --- v3: addressed minor review comments, improved kernel doc v2: Address review comments, including swapping enable_time and poll_enabled_time. --- drivers/regulator/core.c | 63 +++++++++++++++++++++++++++++++- include/linux/regulator/driver.h | 5 +++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 03154f5b939f..538a2779986a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2347,6 +2347,37 @@ static void _regulator_enable_delay(unsigned int delay) udelay(us); } +/** + * _regulator_check_status_enabled + * + * A helper function to check if the regulator status can be interpreted + * as 'regulator is enabled'. + * @rdev: the regulator device to check + * + * Return: + * * 1 - if status shows regulator is in enabled state + * * 0 - if not enabled state + * * Error Value - as received from ops->get_status() + */ +static inline int _regulator_check_status_enabled(struct regulator_dev *rdev) +{ + int ret = rdev->desc->ops->get_status(rdev); + + if (ret < 0) { + rdev_info(rdev, "get_status returned error: %d\n", ret); + return ret; + } + + switch (ret) { + case REGULATOR_STATUS_OFF: + case REGULATOR_STATUS_ERROR: + case REGULATOR_STATUS_UNDEFINED: + return 0; + default: + return 1; + } +} + static int _regulator_do_enable(struct regulator_dev *rdev) { int ret, delay; @@ -2407,7 +2438,37 @@ static int _regulator_do_enable(struct regulator_dev *rdev) * together. */ trace_regulator_enable_delay(rdev_get_name(rdev)); - _regulator_enable_delay(delay); + /* If poll_enabled_time is set, poll upto the delay calculated + * above, delaying poll_enabled_time uS to check if the regulator + * actually got enabled. + * If the regulator isn't enabled after enable_delay has + * expired, return -ETIMEDOUT. + */ + if (rdev->desc->poll_enabled_time) { + unsigned int time_remaining = delay; + + while (time_remaining > 0) { + _regulator_enable_delay(rdev->desc->poll_enabled_time); + + if (rdev->desc->ops->get_status) { + ret = _regulator_check_status_enabled(rdev); + if (ret < 0) + return ret; + else if (ret) + break; + } else if (rdev->desc->ops->is_enabled(rdev)) + break; + + time_remaining -= rdev->desc->poll_enabled_time; + } + + if (time_remaining <= 0) { + rdev_err(rdev, "Enabled check timed out\n"); + return -ETIMEDOUT; + } + } else { + _regulator_enable_delay(delay); + } trace_regulator_enable_complete(rdev_get_name(rdev)); diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 7eb9fea8e482..436df3ba0b2a 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -305,6 +305,9 @@ enum regulator_type { * @enable_time: Time taken for initial enable of regulator (in uS). * @off_on_delay: guard time (in uS), before re-enabling a regulator * + * @poll_enabled_time: The polling interval (in uS) to use while checking that + * the regulator was actually enabled. Max upto enable_time. + * * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode */ struct regulator_desc { @@ -372,6 +375,8 @@ struct regulator_desc { unsigned int off_on_delay; + unsigned int poll_enabled_time; + unsigned int (*of_map_mode)(unsigned int mode); }; From patchwork Fri Jul 10 05:29:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11655719 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 129C413BD for ; Fri, 10 Jul 2020 05:29:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE6E9207DF for ; Fri, 10 Jul 2020 05:29:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CxKCCTLO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbgGJF3k (ORCPT ); Fri, 10 Jul 2020 01:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727908AbgGJF3i (ORCPT ); Fri, 10 Jul 2020 01:29:38 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD44C08C5DD for ; Thu, 9 Jul 2020 22:29:38 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id g67so2006594pgc.8 for ; Thu, 09 Jul 2020 22:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LrEMg7fVwuiooc5MLW1OYb4mtJllfG4D6r8RWT/b3sw=; b=CxKCCTLOKqqO7JWvU/G5EMfnstNxEKb1dka1ZqN2gIG0tl7r6OoXteASnNM0OuOmCn uY37q2IhPbR0YnDfVYWZMQ/jZB0/KhlzbFs9uwB0acc6hJFqwNOqdw6YOGtzC88zBQ4R j7Ogf3SCL+KGm3OMvpbOyQsiQSGToa3Iid991VeWl0voTzjusSj6CrR3OnfIHdw2P+Kf mA4BVnwGiWJDxOuYGb6R9DGHBOiBORWpDl8UtnguLLpJrgVL+dYL5c31cYfhyc8wD2Dq B8TGiOMoNF4quqpHNPd5BmsoWRl6DyTlMYDNR+wKYlmdQE1CFBJuC7T+LMd9kWZCCQoX btgg== 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=LrEMg7fVwuiooc5MLW1OYb4mtJllfG4D6r8RWT/b3sw=; b=F9zPh0dKv2HHgRvkMHx8sR0TMhz2nNa0Hk8MWio0WbYr0MTtChlIe//1eQ6o0hpLqX +h2e57SFSt4tQ9eC8NtE5XxplXGTs4kHW9Rwa6K8eohP1FoYNXh/VgBhP5ux74E5KnAB F3INTr1VrQeghhcDzR7HJKc4YE9Cnljxmlc1DTv0Qxm26/GUE+vQR4F0AtqaPFj4va/v 5qW7YyFYfHHh3XlFgTYiYRpvBrDKq722eQnPf+Fpgrr/UxZ0s86GYAPsoWoIqioM2URo Ck4+VCErMUscAu/oYwCJ54BUKqi1H1zdeRRDouxQHlb4EBeYaHtRI1tTaUJHY2RR7B3z 8HMA== X-Gm-Message-State: AOAM532b6oRsXGM2aOa0BRxvgFDjbdaiMplJqCx31Q3i4GVZElMBW980 GTivnkKcMsCzyw76JlPZ289VOA== X-Google-Smtp-Source: ABdhPJwX7+CmXa7FuhunOH1xpkGPJKpy0u3E/VAJrdFNV4DOCgfMEFsbbZh56sxg2zimQmCSMTFMyA== X-Received: by 2002:a05:6a00:1510:: with SMTP id q16mr58657852pfu.164.1594358978017; Thu, 09 Jul 2020 22:29:38 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id j17sm4168320pgn.87.2020.07.09.22.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 22:29:37 -0700 (PDT) From: Sumit Semwal To: agross@kernel.org, bjorn.andersson@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org Cc: nishakumari@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kgunda@codeaurora.org, rnayak@codeaurora.org, Sumit Semwal Subject: [RESEND PATCH v5 2/4] dt-bindings: regulator: Add labibb regulator Date: Fri, 10 Jul 2020 10:59:17 +0530 Message-Id: <20200710052919.2611-3-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200710052919.2611-1-sumit.semwal@linaro.org> References: <20200710052919.2611-1-sumit.semwal@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Nisha Kumari Adding the devicetree binding for labibb regulator. Signed-off-by: Nisha Kumari Signed-off-by: Sumit Semwal [sumits: cleanup as per review comments and update to yaml] --- v5: Addressed review comments - removed interrupt-names, changed to dual license, added unevaluatedProperties: false v4: fixed dt_binding_check issues v3: moved to yaml v2: updated for better compatible string and names. --- .../regulator/qcom-labibb-regulator.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml diff --git a/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml b/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file mode 100644 index 000000000000..085cbd1ad8d0 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/qcom-labibb-regulator.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm's LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost) Regulator + +maintainers: + - Sumit Semwal + +description: + LAB can be used as a positive boost power supply and IBB can be used as a + negative boost power supply for display panels. Currently implemented for + pmi8998. + +properties: + compatible: + const: qcom,pmi8998-lab-ibb + + lab: + type: object + + properties: + + interrupts: + maxItems: 1 + description: + Short-circuit interrupt for lab. + + required: + - interrupts + + ibb: + type: object + + properties: + + interrupts: + maxItems: 1 + description: + Short-circuit interrupt for lab. + + required: + - interrupts + +required: + - compatible + +unevaluatedProperties: false + +examples: + - | + #include + + labibb { + compatible = "qcom,pmi8998-lab-ibb"; + + lab { + interrupts = <0x3 0x0 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "sc-err"; + }; + + ibb { + interrupts = <0x3 0x2 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "sc-err"; + }; + }; + +... From patchwork Fri Jul 10 05:29:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11655721 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6149D13BD for ; Fri, 10 Jul 2020 05:29:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47E45207DF for ; Fri, 10 Jul 2020 05:29:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="P/u5REte" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbgGJF3p (ORCPT ); Fri, 10 Jul 2020 01:29:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726725AbgGJF3m (ORCPT ); Fri, 10 Jul 2020 01:29:42 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BCCFC08C5DC for ; Thu, 9 Jul 2020 22:29:42 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id gc9so2123524pjb.2 for ; Thu, 09 Jul 2020 22:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gVIUeXQMCzWAcTP6WaAZI7/yPZyluiCjZUpguitY3Jw=; b=P/u5REteL/HeTai6cE+dPZwjiV9k45Y4NLnHY/lfDl47b/TH7IYwoItVnpyoWNzEwM 6JGv23tEcx6U4hePPsyw74Hfjs2Yz9Neipt4eposDrzASCdglgWRr34EkrHURio4/qBj Z3xvQf4yms3QgpM6rQLSnnbaDQKSrZhPBW33tEZtZutBTBjXkxuhYhB9m/jgYjc+losm lNkfdM8XoGwpuf53dV5pDb7JLFt2TgVPvvUJlz7iPpTEbrohj4aPWL9vSVMagftZLgvA n4PQN7OYSdeEdD2wNWJE48CX4FacFMVW5rUOPU4xi9fEh7zodbFDNJabUL9mNXtQabka wRjg== 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=gVIUeXQMCzWAcTP6WaAZI7/yPZyluiCjZUpguitY3Jw=; b=FFn2gctxfQ2yHNKx7QueWrd/TG3/TrPkX1akcRF0yNSYUa1QnX1gcgA+/8uDyUJkNb wKwEA1fruEvSldd2Oea8Z3STca1Yd2X0Bcqpv0upbKzjfYFO47E520Kh0GDIasyTWybe F1d+nqRXKbyJ2+o6l8JZMoYIpiRoXutyAc2V8ovluoxYa0pxNvzrKVYqVTg/zi1ex/T2 aKxQApxOCLlfu9GJ2ir6CDUbujMooxiVYmL8NIrGu54TLSjFSWjfWioo1fa6PXfMoJYG gr1fSAp1Tmvz5KXR6F+wTVijyc9ZhqdPsMRLEiKQyt+eJ7wXkFb2j3TdCcqb90ru7swn xToQ== X-Gm-Message-State: AOAM531jPUQ1n2whpqpwS2PU8jJ4jn6sOU98XuQSfBwXGjVyuyDBf2wH XUmCOcWY16UtN3xBpwiT1PP1/Q== X-Google-Smtp-Source: ABdhPJzIuQ0yZotGXpNCWaIQ1/eS9a2x8OHmZ8rZCozWUj5XQgvP6wsYMa3AmkDZBQsnw+5EmhUdww== X-Received: by 2002:a17:902:44:: with SMTP id 62mr57666397pla.104.1594358982126; Thu, 09 Jul 2020 22:29:42 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id j17sm4168320pgn.87.2020.07.09.22.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 22:29:41 -0700 (PDT) From: Sumit Semwal To: agross@kernel.org, bjorn.andersson@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org Cc: nishakumari@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kgunda@codeaurora.org, rnayak@codeaurora.org, Sumit Semwal Subject: [RESEND PATCH v5 3/4] arm64: dts: qcom: pmi8998: Add nodes for LAB and IBB regulators Date: Fri, 10 Jul 2020 10:59:18 +0530 Message-Id: <20200710052919.2611-4-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200710052919.2611-1-sumit.semwal@linaro.org> References: <20200710052919.2611-1-sumit.semwal@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Nisha Kumari This patch adds devicetree nodes for LAB and IBB regulators. Signed-off-by: Nisha Kumari Signed-off-by: Sumit Semwal [sumits: Updated for better compatible strings and names] --- v5: sumits: removed interrupt-names, since there is only one interrupt per node v4: sumits: removed labibb label which is not needed v3: sumits: updated interrupt-names as per review comments v2: sumits: updated for better compatible string and names --- arch/arm64/boot/dts/qcom/pmi8998.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/pmi8998.dtsi b/arch/arm64/boot/dts/qcom/pmi8998.dtsi index 23f9146a161e..d016b12967eb 100644 --- a/arch/arm64/boot/dts/qcom/pmi8998.dtsi +++ b/arch/arm64/boot/dts/qcom/pmi8998.dtsi @@ -25,5 +25,17 @@ pmi8998_lsid1: pmic@3 { reg = <0x3 SPMI_USID>; #address-cells = <1>; #size-cells = <0>; + + labibb { + compatible = "qcom,pmi8998-lab-ibb"; + + ibb: ibb { + interrupts = <0x3 0xdc 0x2 IRQ_TYPE_EDGE_RISING>; + }; + + lab: lab { + interrupts = <0x3 0xde 0x0 IRQ_TYPE_EDGE_RISING>; + }; + }; }; }; From patchwork Fri Jul 10 05:29:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11655723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 686F213BD for ; Fri, 10 Jul 2020 05:29:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 376AF2078C for ; Fri, 10 Jul 2020 05:29:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uUgADqnE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbgGJF3s (ORCPT ); Fri, 10 Jul 2020 01:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727925AbgGJF3q (ORCPT ); Fri, 10 Jul 2020 01:29:46 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76BB6C08C5CE for ; Thu, 9 Jul 2020 22:29:46 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id g67so2006736pgc.8 for ; Thu, 09 Jul 2020 22:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=doG+Qibpx9UFueyy0W0CrVNyS15JzsuLsQupBt9QvgE=; b=uUgADqnEcSThMAdW+hepQhnpUMquwdcTcQ3f5JzBGsoE4J0Hymi0cWovhmG27sDlu8 EeiMm5AhusAdsWgt+PMrkbhITH2foBHXISLlkrMkKz3TR9XZZRLiApPDs5ih/2UI/6k6 soAUKvzD0OFWVWykCH57O2sEAZxvAy28rZPaxl76YEXozJlSKwCeIC/iT2e7YdHY06pO Sx5S7ZVVwSDw0yPhfXEOCo6DML9DwTsPLjWwOmgK/qCXaM5Fzq66dUn2jlpxf05P9NQl iEmuRPXBvS00r6FgLWOB3UD7cB+OyeHx3p2TrLAL2tnKrAESTeBC6w0mhW+sd45sVxPl 6YiA== 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=doG+Qibpx9UFueyy0W0CrVNyS15JzsuLsQupBt9QvgE=; b=MoX57MK/FfhgMVjz4tN+v0/bjqDf645MmLfK/yrRGxwQsDjDQp/nF57ByF4qJeweia RfXuA7LL0ZaaK6CbVsPY+XKbe2+LXXaypyRm7dNaXdd3I+Os3fxhfWkp4TNR26HKQjz5 /YAb33q+MZ0it39onc7js4YXPyX8hOUKTuCzA7tPW22TZAa4NG9QyMYh6dKD6Ng9rB7h AVZN7iLFtan2tC5sEXzkj+fQDBPFOX4giqKo6rvTozxlMWTWWd73B1syJ6EEt8ky+TQq y8WD/YqIDNXRwHvtP7Ej9S8RCl2TCjn6htvUk5qOzKoTmpLDfz1FQQ02IAikRNEFlDu+ rpJA== X-Gm-Message-State: AOAM532SCtRDrCAreUPnsk0m6V01f78cMOiuBQm0Hs/SabsGP84EDSnx ggzJcb407MCmGe+rWNosvi28KQ== X-Google-Smtp-Source: ABdhPJwWbus2KrjUScuZWhhE12NHtX4uIZVVZpFUhmDSXlIQyXG4Z0tSNqEDxAzXnZ10VsKXRj8NdA== X-Received: by 2002:a62:7ccd:: with SMTP id x196mr58691244pfc.23.1594358985905; Thu, 09 Jul 2020 22:29:45 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id j17sm4168320pgn.87.2020.07.09.22.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 22:29:45 -0700 (PDT) From: Sumit Semwal To: agross@kernel.org, bjorn.andersson@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org Cc: nishakumari@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kgunda@codeaurora.org, rnayak@codeaurora.org, Sumit Semwal Subject: [RESEND PATCH v5 4/4] regulator: qcom: Add labibb driver Date: Fri, 10 Jul 2020 10:59:19 +0530 Message-Id: <20200710052919.2611-5-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200710052919.2611-1-sumit.semwal@linaro.org> References: <20200710052919.2611-1-sumit.semwal@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Nisha Kumari Qualcomm platforms have LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost) regulators, labibb for short, which are used as power supply for LCD Mode displays. This patch adds labibb regulator driver for pmi8998 PMIC, found on SDM845 platforms. Signed-off-by: Nisha Kumari [sumits: reworked the driver design as per upstream review] Signed-off-by: Sumit Semwal --- v5: sumits: review comments addressed - removed dev_info about registering - removed of_get_child_by_name() - changed from using STATUS1 register to using ENABLE_CTL; this allows us to use the regulator_*_regmap helpers and makes this code cleaner. (In limited testing, STATUS1 seemed to report the change faster than ENABLE_CTL, but in absence of mechanism to validate if the regulator has indeed fully ramped when STATUS1 starts flagging, broonie suggested to use the slower ENABLE_CTL path for safety). v4: sumits: address review comments from v3, including cleaning up register_labibb_regulator(), and adapted to updated meaning of poll_enabled_time. v3: sumits: addressed review comments from v2; moved to use core regulator features like enable_time, off_on_delay, and the newly added poll_enabled_time. Moved the check_enabled functionality to core framework via poll_enabled_time. v2: sumits: reworked the driver for more common code, and addressed review comments from v1 --- drivers/regulator/Kconfig | 10 ++ drivers/regulator/Makefile | 1 + drivers/regulator/qcom-labibb-regulator.c | 175 ++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 drivers/regulator/qcom-labibb-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 8f677f5d79b4..c6377df023bc 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1178,5 +1178,15 @@ config REGULATOR_WM8994 This driver provides support for the voltage regulators on the WM8994 CODEC. +config REGULATOR_QCOM_LABIBB + tristate "QCOM LAB/IBB regulator support" + depends on SPMI || COMPILE_TEST + help + This driver supports Qualcomm's LAB/IBB regulators present on the + Qualcomm's PMIC chip pmi8998. QCOM LAB and IBB are SPMI + based PMIC implementations. LAB can be used as positive + boost regulator and IBB can be used as a negative boost regulator + for LCD display panel. + endif diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index e8f163371071..2c2b0861df76 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -88,6 +88,7 @@ obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o obj-$(CONFIG_REGULATOR_MT6358) += mt6358-regulator.o obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o +obj-$(CONFIG_REGULATOR_QCOM_LABIBB) += qcom-labibb-regulator.o obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o obj-$(CONFIG_REGULATOR_QCOM_RPMH) += qcom-rpmh-regulator.o obj-$(CONFIG_REGULATOR_QCOM_SMD_RPM) += qcom_smd-regulator.o diff --git a/drivers/regulator/qcom-labibb-regulator.c b/drivers/regulator/qcom-labibb-regulator.c new file mode 100644 index 000000000000..8c7dd1928380 --- /dev/null +++ b/drivers/regulator/qcom-labibb-regulator.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2020, The Linux Foundation. All rights reserved. + +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_PERPH_TYPE 0x04 + +#define QCOM_LAB_TYPE 0x24 +#define QCOM_IBB_TYPE 0x20 + +#define PMI8998_LAB_REG_BASE 0xde00 +#define PMI8998_IBB_REG_BASE 0xdc00 + +#define REG_LABIBB_STATUS1 0x08 +#define REG_LABIBB_ENABLE_CTL 0x46 +#define LABIBB_STATUS1_VREG_OK_BIT BIT(7) +#define LABIBB_CONTROL_ENABLE BIT(7) + +#define LAB_ENABLE_CTL_MASK BIT(7) +#define IBB_ENABLE_CTL_MASK (BIT(7) | BIT(6)) + +#define LABIBB_OFF_ON_DELAY 1000 +#define LAB_ENABLE_TIME (LABIBB_OFF_ON_DELAY * 2) +#define IBB_ENABLE_TIME (LABIBB_OFF_ON_DELAY * 10) +#define LABIBB_POLL_ENABLED_TIME 1000 + +struct labibb_regulator { + struct regulator_desc desc; + struct device *dev; + struct regmap *regmap; + struct regulator_dev *rdev; + u16 base; + u8 type; +}; + +struct labibb_regulator_data { + const char *name; + u8 type; + u16 base; + struct regulator_desc *desc; +}; + +static struct regulator_ops qcom_labibb_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, +}; + +static struct regulator_desc pmi8998_lab_desc = { + .enable_mask = LAB_ENABLE_CTL_MASK, + .enable_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_ENABLE_CTL), + .enable_val = LABIBB_CONTROL_ENABLE, + .enable_time = LAB_ENABLE_TIME, + .poll_enabled_time = LABIBB_POLL_ENABLED_TIME, + .off_on_delay = LABIBB_OFF_ON_DELAY, + .owner = THIS_MODULE, + .type = REGULATOR_VOLTAGE, + .ops = &qcom_labibb_ops, +}; + +static struct regulator_desc pmi8998_ibb_desc = { + .enable_mask = IBB_ENABLE_CTL_MASK, + .enable_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_ENABLE_CTL), + .enable_val = LABIBB_CONTROL_ENABLE, + .enable_time = IBB_ENABLE_TIME, + .poll_enabled_time = LABIBB_POLL_ENABLED_TIME, + .off_on_delay = LABIBB_OFF_ON_DELAY, + .owner = THIS_MODULE, + .type = REGULATOR_VOLTAGE, + .ops = &qcom_labibb_ops, +}; + +static const struct labibb_regulator_data pmi8998_labibb_data[] = { + {"lab", QCOM_LAB_TYPE, PMI8998_LAB_REG_BASE, &pmi8998_lab_desc}, + {"ibb", QCOM_IBB_TYPE, PMI8998_IBB_REG_BASE, &pmi8998_ibb_desc}, + { }, +}; + +static const struct of_device_id qcom_labibb_match[] = { + { .compatible = "qcom,pmi8998-lab-ibb", .data = &pmi8998_labibb_data}, + { }, +}; +MODULE_DEVICE_TABLE(of, qcom_labibb_match); + +static int qcom_labibb_regulator_probe(struct platform_device *pdev) +{ + struct labibb_regulator *vreg; + struct device *dev = &pdev->dev; + struct regulator_config cfg = {}; + + const struct of_device_id *match; + const struct labibb_regulator_data *reg_data; + struct regmap *reg_regmap; + unsigned int type; + int ret; + + reg_regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!reg_regmap) { + dev_err(&pdev->dev, "Couldn't get parent's regmap\n"); + return -ENODEV; + } + + match = of_match_device(qcom_labibb_match, &pdev->dev); + if (!match) + return -ENODEV; + + for (reg_data = match->data; reg_data->name; reg_data++) { + + /* Validate if the type of regulator is indeed + * what's mentioned in DT. + */ + ret = regmap_read(reg_regmap, reg_data->base + REG_PERPH_TYPE, + &type); + if (ret < 0) { + dev_err(dev, + "Peripheral type read failed ret=%d\n", + ret); + return -EINVAL; + } + + if (WARN_ON((type != QCOM_LAB_TYPE) && (type != QCOM_IBB_TYPE)) || + WARN_ON(type != reg_data->type)) + return -EINVAL; + + vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), + GFP_KERNEL); + if (!vreg) + return -ENOMEM; + + vreg->regmap = reg_regmap; + vreg->dev = dev; + vreg->base = reg_data->base; + vreg->type = reg_data->type; + + memcpy(&vreg->desc, reg_data->desc, sizeof(vreg->desc)); + vreg->desc.of_match = reg_data->name; + vreg->desc.name = reg_data->name; + + cfg.dev = vreg->dev; + cfg.driver_data = vreg; + cfg.regmap = vreg->regmap; + + vreg->rdev = devm_regulator_register(vreg->dev, &vreg->desc, + &cfg); + + if (IS_ERR(vreg->rdev)) { + dev_err(dev, "qcom_labibb: error registering %s : %d\n", + reg_data->name, ret); + return PTR_ERR(vreg->rdev); + } + } + + return 0; +} + +static struct platform_driver qcom_labibb_regulator_driver = { + .driver = { + .name = "qcom-lab-ibb-regulator", + .of_match_table = qcom_labibb_match, + }, + .probe = qcom_labibb_regulator_probe, +}; +module_platform_driver(qcom_labibb_regulator_driver); + +MODULE_DESCRIPTION("Qualcomm labibb driver"); +MODULE_AUTHOR("Nisha Kumari "); +MODULE_AUTHOR("Sumit Semwal "); +MODULE_LICENSE("GPL v2");