From patchwork Thu May 28 15:46:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11576225 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 109381667 for ; Thu, 28 May 2020 15:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED31A2089D for ; Thu, 28 May 2020 15:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="B6fZFOPX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404733AbgE1Pro (ORCPT ); Thu, 28 May 2020 11:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404676AbgE1PrE (ORCPT ); Thu, 28 May 2020 11:47:04 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E4CCC08C5C6 for ; Thu, 28 May 2020 08:47:04 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id t7so11694039plr.0 for ; Thu, 28 May 2020 08:47:04 -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=KyQEzGyzaYw5IWn5g/75UMLFSkhlAAtyUxzYzVWL1hI=; b=B6fZFOPXlINNumfwCvb4M1+Lbl67pHh2jE6GhmJTySjRkf+DhDhRtqbsCH3uHuPArI NNdypH3hqwOSn3+AgnW7EdJU6gonFzCjQQeoDNGHRN8Y5zL9d+bjfozfI83PBjSIEiFh wcKk/G9OyoVmTtdVNO25Uyn5Ve2jHzU65xddhYSZT/ctnl72a3e3/mEhasjWD9Uj4yWa aBxGFqdpDceEnDm4mCrxmEQ3a1j2St1E6gQGtbVNT+RlXnU97aWAlEl0DGVosRGrImiZ du8WVebIRNthoE/I9ytP4vciOfDB/VyXzom+emikQzgl5LIk2rO9RRLh6Gy9o3N7fCGC js8A== 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=KyQEzGyzaYw5IWn5g/75UMLFSkhlAAtyUxzYzVWL1hI=; b=CgLhnqbqhkQJ7ZdWmpwMg4rJ3jfW9WAMFpOBxLKstCMVEWQWGx5QmDxWLd4p7Qo5Jb Kl8xHa5a9MbbyUPrk9cdNFxX8MbfG9qywQ6/13khNfJ6KKAwZMeEiB+iMe3GPJeGva8n rrFt8XFEYlSay/AixwqejEMUuELT1rolZKUyRb774+F/uwddKOUi5pqu6OuVYNnB0Dcj D3Rnz27TElznB47J4HgUeEkdI3hQQIvb2wE20ibwQKStXpeuIl45pkC8eBoCBXlU/vKH P9+XaCybqFeEyZDXSU09D2cT/wwgDx2c24yXomWnJFPeBPgEKjMjjCr4fS1nAMz7O8tk Bqqw== X-Gm-Message-State: AOAM532yYzeszntNksib8F8Hht+GTf4LJxOtvXysAC5VBCIDT6efdX0Q /JyLytEZCA4t5En6xeJEJX0qtw== X-Google-Smtp-Source: ABdhPJwuG1bZv/tBfujMCsmSXvQMl1Vfa8akWgxhHGSKy4wVvRhdiY4eDH3JPL7Kki/GZrRRFeyvyQ== X-Received: by 2002:a17:90b:1482:: with SMTP id js2mr4611348pjb.54.1590680823540; Thu, 28 May 2020 08:47:03 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id y22sm5212551pfc.132.2020.05.28.08.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 08:47:02 -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: [PATCH v3 1/5] regulator: Allow regulators to verify enabled during enable() Date: Thu, 28 May 2020 21:16:21 +0530 Message-Id: <20200528154625.17742-2-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528154625.17742-1-sumit.semwal@linaro.org> References: <20200528154625.17742-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 --- drivers/regulator/core.c | 28 ++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 7486f6e4e613..06199f182114 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2409,6 +2409,34 @@ static int _regulator_do_enable(struct regulator_dev *rdev) _regulator_enable_delay(delay); + /* If set, poll upto poll_enabled_time uS to see if the regulator + * actually got enabled. + * For each iteration, wait for the enable_time delay calculated + * above already. + * If the regulator isn't enabled after poll_enabled_time has + * expired, return -ETIMEDOUT. + */ + if (rdev->desc->poll_enabled_time) { + unsigned int time_remaining = rdev->desc->poll_enabled_time; + + while (time_remaining > 0) { + /* We've already waited for enable_time above; + * so we can start with immediate check of the + * status of the regulator. + */ + if (rdev->desc->ops->is_enabled(rdev)) + break; + + _regulator_enable_delay(delay); + time_remaining -= delay; + } + + if (time_remaining <= 0) { + rdev_err(rdev, "Enabled check failed.\n"); + return -ETIMEDOUT; + } + } + trace_regulator_enable_complete(rdev_get_name(rdev)); return 0; diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 29d920516e0b..bb50e943010f 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -322,6 +322,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: Maximum time (in uS) to poll if the regulator is + * actually enabled, after enable() call + * * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode */ struct regulator_desc { @@ -389,6 +392,8 @@ struct regulator_desc { unsigned int off_on_delay; + unsigned int poll_enabled_time; + unsigned int (*of_map_mode)(unsigned int mode); }; From patchwork Thu May 28 15:46:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11576219 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 98D4E60D for ; Thu, 28 May 2020 15:47:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B5942089D for ; Thu, 28 May 2020 15:47:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CvqTv5pY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404692AbgE1PrS (ORCPT ); Thu, 28 May 2020 11:47:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404685AbgE1PrI (ORCPT ); Thu, 28 May 2020 11:47:08 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9573C08C5C6 for ; Thu, 28 May 2020 08:47:07 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id m7so11708934plt.5 for ; Thu, 28 May 2020 08:47:07 -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=KY8aQRYELLAf9/2I3C13n0AvLroYbmfmwpkCrL98Gv0=; b=CvqTv5pYPAdd6X3RyQls/VWekEcH11q0LJ7qJf5c56TvtFNlwd9Hq76OBcVcRIdXye frAGiLIfKX9m8sWcdgMq7BMReQbM4jtYCQwewrbSa92Sn8keEoNVTKGtLuRsw33UDbDS tJCxXprxz4EYFBGPBO/4WKEVpdayZ51g6BfqU5NyF8UsPWklu+YHZq7cFziV6zYX4NPR /NnvhskEu0rJBGH8hn1Z+edDNEWzjIE+zG70ZEu/N0Er1D1nKymsHoOZ6gOuwx1P6Ill D0Ilr1xNbViWFlkxkjXpevCn5+VswQ3S/gsvBpizyAfkOo6PHPPwvAI/+JLTQOAOtAPX Gj3A== 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=KY8aQRYELLAf9/2I3C13n0AvLroYbmfmwpkCrL98Gv0=; b=SvFAIQWy+8WtWqFGLHS6FYI2UPEo5J+k2lD1peg5E02r8b1kfrH4d55UcRXKhPmR0V DFmikv4vQGhvq+JBR+uKQSK+59oDdiLYrhFnvQB4H6kFfBRiq38TgEBe6OgDTqe9WwB8 O/KS7nwGF+5GsN6Slgj8kPk+lAGnaIo451nzxP97aG7t6Nh0F6MsHNuDMomuZNGlMaU7 Ay1hSTEPhagpAAY2tYwayJO/cMTjj5eVli7IB/rCG8+lP7W/sfs1ifHBHiXuUnsqOpli 9t6fb90U4bnFZMOr6ecnRxCxx1vzthZlRI7U4/lw5ozoea6o/FS90ZMgVPcECJZ5jDsw L6BA== X-Gm-Message-State: AOAM533Z8cv/ORUoDriGymx3WWe8p/K+35WJHrr5bYqBNFUDMiQbAlgf niSTv6Vub4cGAuQgFpSGYUm3+w== X-Google-Smtp-Source: ABdhPJy3Sol2FO0WDZNPj8c7jOKixvVKVciOZKOIyGeQHO4q9jqYHyeikxhpwzbAQlI2rsbc6NkQLg== X-Received: by 2002:a17:90a:e2cb:: with SMTP id fr11mr4678496pjb.72.1590680827443; Thu, 28 May 2020 08:47:07 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id y22sm5212551pfc.132.2020.05.28.08.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 08:47:06 -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: [PATCH v3 2/5] dt-bindings: regulator: Add labibb regulator Date: Thu, 28 May 2020 21:16:22 +0530 Message-Id: <20200528154625.17742-3-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528154625.17742-1-sumit.semwal@linaro.org> References: <20200528154625.17742-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 --- v2: updated for better compatible string and names. v3: moved to yaml --- .../regulator/qcom-labibb-regulator.yaml | 63 +++++++++++++++++++ 1 file changed, 63 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..5406601ecd65 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: GPL-2.0-only +%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. + +allOf: + - $ref: "regulator.yaml#" + +properties: + compatible: + const: qcom,pmi8998-lab-ibb + + lab: + type: object + interrupts: + items: + - description: Short-circuit interrupt for lab. + interrupt-names: + maxItems: 1 + items: + - const: sc-err + + ibb: + type: object + interrupts: + items: + - description: Short-circuit interrupt for lab. + interrupt-names: + maxItems: 1 + items: + - const: sc-err + +required: + - compatible + +examples: + pmi8998_lsid1: pmic@3 { + labibb { + compatible = "qcom,pmi8998-lab-ibb"; + + lab: lab { + interrupts = <0x3 0xde 0x0 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "lab-sc-err"; + }; + + ibb: ibb { + interrupts = <0x3 0xdc 0x2 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ibb-sc-err"; + }; + + }; + }; From patchwork Thu May 28 15:46:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11576221 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 BCBFF60D for ; Thu, 28 May 2020 15:47:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5074207BC for ; Thu, 28 May 2020 15:47:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IZc05fC2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404678AbgE1PrP (ORCPT ); Thu, 28 May 2020 11:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404691AbgE1PrL (ORCPT ); Thu, 28 May 2020 11:47:11 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6EBC08C5C8 for ; Thu, 28 May 2020 08:47:11 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id 131so5324377pfv.13 for ; Thu, 28 May 2020 08:47:11 -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=rABvwzpSHjK9Um87JqwSpNf8fC8athc+8D0QEbmnNrI=; b=IZc05fC2hVRUdUctuTSvYWOzikAy0ps/zfWm31qMoGvq8hMp11Ml1/B1izUv24mB/z qjx2bsJVmW1srtAT3T+hcQdqnAHP+f8TCZnv0y1UqVS7WbEAxeRk/WqixTbiB8RL0YY9 m8mWtnqA2MudUteutSztsLrsBGssFZyvS+onP1qztgMV+TgCpQxVFzTQkLZOzrGbkGc3 zPGdP8Fhnmfk91gHo3mKGpbZ2X+X46tO+8LcM0LCAdZCyS37HAvaUVoVl66RSVlIbIdY eV6hRazLof97B8v4DgFZjJMi5fpUP/cmI439a9eTChRUvH1T2d9c9BKt3dPvlm0Yrqxh 7j8g== 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=rABvwzpSHjK9Um87JqwSpNf8fC8athc+8D0QEbmnNrI=; b=DCkXhghUVWMnlW1yVFbY/67bEdjweXLbJ3BI6rGm7dcK2I5btNWuZweMYzVBkxkix3 aUxw4jfKsiqsDjwRoT4EF5CZwBF2xRtZGJ2JImee9EySehcF8iJS9jyXqpvYoG97taOF x18sgfOFsdK7bU+fn4gXCyy334L985FyYOSbS6DeMtAO91v0IrHLYcMgLXRKNCiQ9xDC yzlPaTERmc2q+ClO6gQm5wVBx16W0Z1wW+DwCIBwZaVaL1ori3s91bk2Ma1ICGANPizX WD4BYgbdWoqMGJGC3o4LSLCs4NkGcDFvECfPDkLcLV3YHuoaHDyOq66XYnRGZZrV3FEj wtJA== X-Gm-Message-State: AOAM530iv2NpXQZj1tP45kgWbO0kfFR52KT0w4HUkAV4SGWeG00ik4pP m5KPGZmy8xWyw4q9Zzy2tuyyDQ== X-Google-Smtp-Source: ABdhPJxdahc+f9DIB9SjORBE5j/wBNbjZIfowfCBK8fCGznSzu7kQcY5h/uN99JQRFhu2gKfrlSHyQ== X-Received: by 2002:a65:534d:: with SMTP id w13mr3471439pgr.18.1590680831305; Thu, 28 May 2020 08:47:11 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id y22sm5212551pfc.132.2020.05.28.08.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 08:47:10 -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: [PATCH v3 3/5] arm64: dts: qcom: pmi8998: Add nodes for LAB and IBB regulators Date: Thu, 28 May 2020 21:16:23 +0530 Message-Id: <20200528154625.17742-4-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528154625.17742-1-sumit.semwal@linaro.org> References: <20200528154625.17742-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 Reviewed-by: Bjorn Andersson --- v2: sumits: updated for better compatible string and names v3: sumits: updated interrupt-names as per review comments --- arch/arm64/boot/dts/qcom/pmi8998.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/pmi8998.dtsi b/arch/arm64/boot/dts/qcom/pmi8998.dtsi index 23f9146a161e..1a72fe92f1a6 100644 --- a/arch/arm64/boot/dts/qcom/pmi8998.dtsi +++ b/arch/arm64/boot/dts/qcom/pmi8998.dtsi @@ -25,5 +25,19 @@ pmi8998_lsid1: pmic@3 { reg = <0x3 SPMI_USID>; #address-cells = <1>; #size-cells = <0>; + + labibb: labibb { + compatible = "qcom,pmi8998-lab-ibb"; + + ibb: ibb { + interrupts = <0x3 0xdc 0x2 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "sc-err"; + }; + + lab: lab { + interrupts = <0x3 0xde 0x0 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "sc-err"; + }; + }; }; }; From patchwork Thu May 28 15:46:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11576223 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 A337D1391 for ; Thu, 28 May 2020 15:47:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 86189208DB for ; Thu, 28 May 2020 15:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Iajg5mUW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404732AbgE1Prn (ORCPT ); Thu, 28 May 2020 11:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404695AbgE1PrP (ORCPT ); Thu, 28 May 2020 11:47:15 -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 C26CCC08C5C6 for ; Thu, 28 May 2020 08:47:15 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ci23so3253168pjb.5 for ; Thu, 28 May 2020 08:47:15 -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=Wx5aZAA2kgOq4IleLhAQPeiiPlraf5A+rXTLPd1JNIw=; b=Iajg5mUWeIxX1zJJkELZJT/Zl2KfR9vwzR3UF9/3IEr1PB4nWrK9x5+aZdvYCf3GP2 Itw3yhcx38OyWurkVcM4w5ATZNtZPB3fOMgIZe7LUFZ7Bc/9al0kUV3+99pssDrp+AWa PcolB9Sf2IrT4GL9Y7m5xy6QvVCaSB9r/qCk8yGAr50KBokrDJx3UFWPbDndLr8Fiasx QHQQuzjIR3T+BrkKa/79g2RP80MOO/YZpEg2XA9JeSTP0PyEw9Su9UlrnU9rcmxPCvve fgjC+P7/emKojWRifaOHfHDW2ubilZ7oLyBDZrrQQ6ZkVoFfQD4U7Prm1MJ/iv6HmLSO uebg== 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=Wx5aZAA2kgOq4IleLhAQPeiiPlraf5A+rXTLPd1JNIw=; b=Lb6AXRFUw2N3PWpk8FpnIbxVsVj2thhDuLlsCZu2v07AEnDox+Z5KBKzWryoLhe4P9 YAKlaAR2DYKxWDT0LmuVAYw3FzDvBaSRHV5dmdrTpDKjIDHZ4L3lmH8OE2lKRZiBAdbY tliGpdPI09vQVyIKWqQn6XJQ9jLLzy8igao63rIA0EEMBFiv/fp5h9E/YAeslR8VnCxY aNBWHgSc3jQgkbPhdHz7ixky8rsyWIMmCNiPMAkEVjTNqhilzPO6HsV/8TRQJoN1MVmX fttT5a6vKL0JIapbYAQCKeEK8nLAnFRRbyzFqrcWvLrmGVRJ5sL6O3MLFk0dOsR5ZfCy mwYw== X-Gm-Message-State: AOAM531i9/t1yJsYaRh/OS04C9oiKXXn5mZzdWnG3ZKfR1a1B3CQaV2K buPF1c9YYzn9HzjWu0i9RkhVLw== X-Google-Smtp-Source: ABdhPJzpnu42SCdBn7Y6SErNPbPXGO6hYpLYNPmuXtb2Qv5qU0QdRex0sC0meUd5ni27cu/StKFINA== X-Received: by 2002:a17:902:bd07:: with SMTP id p7mr3946318pls.293.1590680835189; Thu, 28 May 2020 08:47:15 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id y22sm5212551pfc.132.2020.05.28.08.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 08:47:14 -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: [PATCH v3 4/5] regulator: qcom: Add labibb driver Date: Thu, 28 May 2020 21:16:24 +0530 Message-Id: <20200528154625.17742-5-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528154625.17742-1-sumit.semwal@linaro.org> References: <20200528154625.17742-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 Signed-off-by: Sumit Semwal --- v2: sumits: reworked the driver for more common code, and addressed review comments from v1 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. --- drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/qcom-labibb-regulator.c | 224 ++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/regulator/qcom-labibb-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index f4b72cb098ef..58704a9fd05d 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1167,5 +1167,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 6610ee001d9a..5b313786c0e8 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -87,6 +87,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..634d08461c6e --- /dev/null +++ b/drivers/regulator/qcom-labibb-regulator.c @@ -0,0 +1,225 @@ +// 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 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_ENABLE_TIME 1000 +#define LAB_POLL_ENABLED_TIME (LABIBB_ENABLE_TIME * 2) +#define IBB_POLL_ENABLED_TIME (LABIBB_ENABLE_TIME * 10) +#define LABIBB_OFF_ON_DELAY (8200) + +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 { + u16 base; + const char *name; + u8 type; + unsigned int poll_enabled_time; +}; + +static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev) +{ + int ret; + unsigned int val; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regmap_read(reg->regmap, reg->base + REG_LABIBB_STATUS1, &val); + if (ret < 0) { + dev_err(reg->dev, "Read register failed ret = %d\n", ret); + return ret; + } + return !!(val & LABIBB_STATUS1_VREG_OK_BIT); +} + +static int qcom_labibb_regulator_enable(struct regulator_dev *rdev) +{ + int ret; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regulator_enable_regmap(rdev); + if (ret < 0) + dev_err(reg->dev, "Write failed: enable %s regulator\n", + reg->desc.name); + + return ret; +} + +static int qcom_labibb_regulator_disable(struct regulator_dev *rdev) +{ + int ret = 0; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regulator_disable_regmap(rdev); + if (ret < 0) + dev_err(reg->dev, "Disable failed: disable %s\n", + reg->desc.name); + + return ret; +} + +static struct regulator_ops qcom_labibb_ops = { + .enable = qcom_labibb_regulator_enable, + .disable = qcom_labibb_regulator_disable, + .is_enabled = qcom_labibb_regulator_is_enabled, +}; + +static int register_labibb_regulator(struct labibb_regulator *reg, + const struct labibb_regulator_data *reg_data, + struct device_node *of_node) +{ + struct regulator_config cfg = {}; + + reg->base = reg_data->base; + reg->type = reg_data->type; + reg->desc.enable_reg = reg->base + REG_LABIBB_ENABLE_CTL; + reg->desc.enable_val = LABIBB_CONTROL_ENABLE; + reg->desc.of_match = reg_data->name; + reg->desc.name = reg_data->name; + reg->desc.owner = THIS_MODULE; + reg->desc.type = REGULATOR_VOLTAGE; + reg->desc.ops = &qcom_labibb_ops; + + reg->desc.enable_time = LABIBB_ENABLE_TIME; + reg->desc.poll_enabled_time = reg_data->poll_enabled_time; + reg->desc.off_on_delay = LABIBB_OFF_ON_DELAY; + + cfg.dev = reg->dev; + cfg.driver_data = reg; + cfg.regmap = reg->regmap; + cfg.of_node = of_node; + + reg->rdev = devm_regulator_register(reg->dev, ®->desc, &cfg); + return PTR_ERR_OR_ZERO(reg->rdev); +} + +static const struct labibb_regulator_data pmi8998_labibb_data[] = { + {0xde00, "lab", QCOM_LAB_TYPE, LAB_POLL_ENABLED_TIME}, + {0xdc00, "ibb", QCOM_IBB_TYPE, IBB_POLL_ENABLED_TIME}, + { }, +}; + +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 *labibb_reg; + struct device *dev; + struct device_node *child; + 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; + } + + dev = &pdev->dev; + + match = of_match_device(qcom_labibb_match, &pdev->dev); + if (!match) + return -ENODEV; + + for (reg_data = match->data; reg_data->name; reg_data++) { + child = of_get_child_by_name(pdev->dev.of_node, reg_data->name); + + /* TODO: This validates if the type of regulator is indeed + * what's mentioned in DT. + * I'm not sure if this is needed, but we'll keep it for now. + */ + 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 ((type != QCOM_LAB_TYPE) && (type != QCOM_IBB_TYPE)) { + dev_err(dev, + "qcom_labibb: unknown peripheral type\n"); + return -EINVAL; + } else if (type != reg_data->type) { + dev_err(dev, + "qcom_labibb: type %x doesn't match DT %x\n", + type, reg_data->type); + return -EINVAL; + } + + labibb_reg = devm_kzalloc(&pdev->dev, sizeof(*labibb_reg), + GFP_KERNEL); + if (!labibb_reg) + return -ENOMEM; + + labibb_reg->regmap = reg_regmap; + labibb_reg->dev = dev; + + switch (reg_data->type) { + case QCOM_LAB_TYPE: + labibb_reg->desc.enable_mask = LAB_ENABLE_CTL_MASK; + break; + + case QCOM_IBB_TYPE: + labibb_reg->desc.enable_mask = IBB_ENABLE_CTL_MASK; + break; + } + + dev_info(dev, "Registering %s regulator\n", child->full_name); + + ret = register_labibb_regulator(labibb_reg, reg_data, child); + if (ret < 0) { + dev_err(dev, + "qcom_labibb: error registering %s : %d\n", + child->full_name, ret); + return ret; + } + } + + 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_LICENSE("GPL v2"); From patchwork Thu May 28 15:46:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11576215 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 159EA60D for ; Thu, 28 May 2020 15:47:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E85F3207F5 for ; Thu, 28 May 2020 15:47:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UmyhKM4J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404710AbgE1PrV (ORCPT ); Thu, 28 May 2020 11:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404705AbgE1PrT (ORCPT ); Thu, 28 May 2020 11:47:19 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98718C08C5C7 for ; Thu, 28 May 2020 08:47:19 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id nu7so3346387pjb.0 for ; Thu, 28 May 2020 08:47:19 -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=LsQCDM2neDPMHnH/0t80dBq+lQkYA0nzb5LOU64sDRo=; b=UmyhKM4Jpks9J00t8FKaJjhwAp3CWXCfbjL0jeNN7H8h731llMvtFA/1uul7nDsSW2 r8lXAjZppv+TRe5sk5OVwRVS6NZpwNufyz7lViBxNmscU7XlWTvv/lpCQa1JA/1yofpT FJ+u7puB6jtYSEkZSTzF//xkcIvATOriQAypxMkieuU+topZgBCiB11v3kPtuO8XpZam 6DiqgMRySkj6CFgQJbEwT2VaI+MUYJv4HL9RQ5JcTsPn1z8ysZeOlNZXZorE/M6c8DgK 0nQv9rse0TS88b5U/AjkWMPuzVM0WTMRWkAqLP1rBt2Szu7f3FBLcBq4flH0YlSO2vj1 pphA== 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=LsQCDM2neDPMHnH/0t80dBq+lQkYA0nzb5LOU64sDRo=; b=Dg80FrSp+rK4NINCSemIpHZ46pGvGoEhpCbHmm2JoQDhzpzUKOAg0fLR0clpv/n/bj JaJG/JXBBGZPjmLIod1qKyglnRYuDnPpsST51P4b6lZT7hCmqD0+7jhO21V9omAhkbiE IJ5xvxVF+BMgSy8W7UnNZ778hyAj0KGeZBQpJqQ8JS4tt10HTX76FWgbBja9BaliEriT EHxxO7E9Ygsb885j/DQjplLDXxCbWm8upsdW3CGsum53nH8S8MYFajK2eug+L6NudlV6 RpCgCjt9sXwwLoYNLY2t0yLjJhEWZU5aDZVyJtton0lbGUHvH4hbGxD0vqFPi0M2jdxs 5qkw== X-Gm-Message-State: AOAM532Y/MUpAo4SxL+Kr+9VGs8FrH7qp+G6s8GPX7delpUHaqF6gcRu AV253RupFd9IW6nzjQstoLQ9DADZg8yH1Q== X-Google-Smtp-Source: ABdhPJwrGVxnRHPAj6hGG65lrdgZ7wwXriSr+ERPGBBU3/A2TNUzw23m8eel0A7JJcN7JnWbDwY3XA== X-Received: by 2002:a17:90a:c788:: with SMTP id gn8mr4431712pjb.230.1590680838985; Thu, 28 May 2020 08:47:18 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id y22sm5212551pfc.132.2020.05.28.08.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 08:47:18 -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: [PATCH v3 5/5] regulator: qcom: labibb: Add SC interrupt handling Date: Thu, 28 May 2020 21:16:25 +0530 Message-Id: <20200528154625.17742-6-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528154625.17742-1-sumit.semwal@linaro.org> References: <20200528154625.17742-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 Add Short circuit interrupt handling and recovery for the lab and ibb regulators on qcom platforms. The client panel drivers need to register for REGULATOR_EVENT_OVER_CURRENT notification which will be triggered on short circuit. They should try to enable the regulator once, and if it doesn't get enabled, handle shutting down the panel accordingly. Signed-off-by: Nisha Kumari Signed-off-by: Sumit Semwal --- v2: sumits: reworked handling to user regmap_read_poll_timeout, and handle it per-regulator instead of clearing both lab and ibb errors on either irq triggering. Also added REGULATOR_EVENT_OVER_CURRENT handling and notification to clients. v3: sumits: updated as per review comments of v2: removed spurious check for irq in handler and some unused variables; inlined some of the code, omitted IRQF_TRIGGER_RISING as it's coming from DT. --- drivers/regulator/qcom-labibb-regulator.c | 92 +++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/regulator/qcom-labibb-regulator.c b/drivers/regulator/qcom-labibb-regulator.c index 634d08461c6e..695ffac71e81 100644 --- a/drivers/regulator/qcom-labibb-regulator.c +++ b/drivers/regulator/qcom-labibb-regulator.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only // Copyright (c) 2020, The Linux Foundation. All rights reserved. +#include #include #include #include @@ -18,6 +19,7 @@ #define REG_LABIBB_ENABLE_CTL 0x46 #define LABIBB_STATUS1_VREG_OK_BIT BIT(7) #define LABIBB_CONTROL_ENABLE BIT(7) +#define LABIBB_STATUS1_SC_DETECT_BIT BIT(6) #define LAB_ENABLE_CTL_MASK BIT(7) #define IBB_ENABLE_CTL_MASK (BIT(7) | BIT(6)) @@ -27,12 +29,17 @@ #define IBB_POLL_ENABLED_TIME (LABIBB_ENABLE_TIME * 10) #define LABIBB_OFF_ON_DELAY (8200) +#define POLLING_SCP_DONE_INTERVAL_US 5000 +#define POLLING_SCP_TIMEOUT 16000 + struct labibb_regulator { struct regulator_desc desc; struct device *dev; struct regmap *regmap; struct regulator_dev *rdev; u16 base; + int sc_irq; + int vreg_enabled; u8 type; }; @@ -65,6 +72,8 @@ static int qcom_labibb_regulator_enable(struct regulator_dev *rdev) if (ret < 0) dev_err(reg->dev, "Write failed: enable %s regulator\n", reg->desc.name); + else + reg->vreg_enabled = 1; return ret; } @@ -78,6 +87,8 @@ static int qcom_labibb_regulator_disable(struct regulator_dev *rdev) if (ret < 0) dev_err(reg->dev, "Disable failed: disable %s\n", reg->desc.name); + else + reg->vreg_enabled = 0; return ret; } @@ -88,11 +99,70 @@ static struct regulator_ops qcom_labibb_ops = { .is_enabled = qcom_labibb_regulator_is_enabled, }; +static irqreturn_t labibb_sc_err_handler(int irq, void *_reg) +{ + int ret; + u16 reg; + unsigned int val; + struct labibb_regulator *labibb_reg = _reg; + bool in_sc_err, scp_done = false; + + ret = regmap_read(labibb_reg->regmap, + labibb_reg->base + REG_LABIBB_STATUS1, &val); + if (ret < 0) { + dev_err(labibb_reg->dev, "sc_err_irq: Read failed, ret=%d\n", + ret); + return IRQ_HANDLED; + } + + dev_dbg(labibb_reg->dev, "%s SC error triggered! STATUS1 = %d\n", + labibb_reg->desc.name, val); + + in_sc_err = !!(val & LABIBB_STATUS1_SC_DETECT_BIT); + + /* + * The SC(short circuit) fault would trigger PBS(Portable Batch + * System) to disable regulators for protection. This would + * cause the SC_DETECT status being cleared so that it's not + * able to get the SC fault status. + * Check if the regulator is enabled in the driver but + * disabled in hardware, this means a SC fault had happened + * and SCP handling is completed by PBS. + */ + if (!in_sc_err) { + + reg = labibb_reg->base + REG_LABIBB_ENABLE_CTL; + + ret = regmap_read_poll_timeout(labibb_reg->regmap, + reg, val, + !(val & LABIBB_CONTROL_ENABLE), + POLLING_SCP_DONE_INTERVAL_US, + POLLING_SCP_TIMEOUT); + + if (!ret && labibb_reg->vreg_enabled) { + dev_dbg(labibb_reg->dev, + "%s has been disabled by SCP\n", + labibb_reg->desc.name); + scp_done = true; + } + } + + if (in_sc_err || scp_done) { + regulator_lock(labibb_reg->rdev); + regulator_notifier_call_chain(labibb_reg->rdev, + REGULATOR_EVENT_OVER_CURRENT, + NULL); + regulator_unlock(labibb_reg->rdev); + } + return IRQ_HANDLED; +} + static int register_labibb_regulator(struct labibb_regulator *reg, const struct labibb_regulator_data *reg_data, struct device_node *of_node) { struct regulator_config cfg = {}; + int ret; reg->base = reg_data->base; reg->type = reg_data->type; @@ -108,6 +178,28 @@ static int register_labibb_regulator(struct labibb_regulator *reg, reg->desc.poll_enabled_time = reg_data->poll_enabled_time; reg->desc.off_on_delay = LABIBB_OFF_ON_DELAY; + reg->sc_irq = -EINVAL; + ret = of_irq_get_byname(of_node, "sc-err"); + if (ret < 0) { + dev_err(reg->dev, "Unable to get sc-err, ret = %d\n", + ret); + return ret; + } else + reg->sc_irq = ret; + + if (reg->sc_irq > 0) { + ret = devm_request_threaded_irq(reg->dev, + reg->sc_irq, + NULL, labibb_sc_err_handler, + IRQF_ONESHOT, + "sc-err", reg); + if (ret) { + dev_err(reg->dev, "Failed to register sc-err irq ret=%d\n", + ret); + return ret; + } + } + cfg.dev = reg->dev; cfg.driver_data = reg; cfg.regmap = reg->regmap;