From patchwork Tue Jun 2 10:09:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 11583521 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 83D29739 for ; Tue, 2 Jun 2020 10:09:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BF63206A4 for ; Tue, 2 Jun 2020 10:09:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bXg2bBWl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726904AbgFBKJo (ORCPT ); Tue, 2 Jun 2020 06:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726831AbgFBKJm (ORCPT ); Tue, 2 Jun 2020 06:09:42 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95CC1C061A0E for ; Tue, 2 Jun 2020 03:09:42 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id x207so2946995pfc.5 for ; Tue, 02 Jun 2020 03:09: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=ndmZINi8/nRwu7d+LAYbr+txyzlIO7v5ED11d9EW/5I=; b=bXg2bBWlRV/VWepPPKfUL4toFrac1pPv181g4AL+Z/4jvmKEoLiLV3a5TpS69Vhd7P SKvhE2QvgNyLVsfiu9dGHIwJNl7pgam0LrNGvv6n6gxUbVmVkNRs47rlUxTFL4IdUlzz /QAc7stsfcTiuRScjBBKFO1f8A+oOhK21xXbKiBK1eedA5Ca1PBNYgu6+9dNiHCjVZsu Bjm5NvTEsouS0VIss9B43BxK7ywxTAXPe1xEGQKD9FBRftSgykI7WE+kS9i2cAp65Vqi aEjbzs89tATVOyO6wZnJXiWM538d6Gu588wFJkgGUF/qNhCjPNN6l/fEqRNa632+zykf msXg== 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=ndmZINi8/nRwu7d+LAYbr+txyzlIO7v5ED11d9EW/5I=; b=MdolA5qOH04Q6y++/GguNS54iblqSU1ZeIsIwYs0HQYoXFn26RXbTCbm1DQjJG2iYa jJgl7sxqn2U42EpQM2MBqqai6BDrXfcDSRZRLz9nJxkeMaMeo75SG0ahIktXVe0S9DV/ w82wmMyDnvBLojT7ariyz6S/iGuRAx1+Px5lS9sx5f1M4kV1wsnYdgOkCaaNUGf9igO9 lLj/xIufwN0xLK+yoisbX3H3o7QJhEEyKX4fRECs8cwI1UK8BD35rP3slQfCkqcpOji1 A8QHp7E1XPdVQg8luALN4LzL8Wga4BVQ8lwp56aCWbSKjxlF8UICbZfUJ9pDfsngggSK 77Dg== X-Gm-Message-State: AOAM531U8IyNl40tLN0kkRX4GYHmWfx87/dt8Fzik1Xk3dxxucuwrRiy saaSH1OlXWxgips488Fd0PjChA== X-Google-Smtp-Source: ABdhPJzLb9+p6Kfdr2Mjf3AENxX8NVujOQmqmyksXLrgLUu63ML3k4MQnHadxEaOa+SqRKDPi9C5IA== X-Received: by 2002:a63:cd0d:: with SMTP id i13mr23582221pgg.292.1591092582021; Tue, 02 Jun 2020 03:09:42 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id d8sm1931276pgb.42.2020.06.02.03.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 03:09: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: [PATCH v4 1/5] regulator: Allow regulators to verify enabled during enable() Date: Tue, 2 Jun 2020 15:39:20 +0530 Message-Id: <20200602100924.26256-2-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100924.26256-1-sumit.semwal@linaro.org> References: <20200602100924.26256-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 --- v2: Address review comments, including swapping enable_time and poll_enabled_time. --- drivers/regulator/core.c | 58 +++++++++++++++++++++++++++++++- include/linux/regulator/driver.h | 5 +++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 7486f6e4e613..d9ab888da95f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2347,6 +2347,32 @@ static void _regulator_enable_delay(unsigned int delay) udelay(us); } +/* _regulator_check_status_enabled + * + * returns: + * 1 if status shows regulator is in enabled state + * 0 if not enabled state + * else, 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 +2433,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 failed.\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 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 Tue Jun 2 10:09: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: 11583537 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 C0D9B1392 for ; Tue, 2 Jun 2020 10:10:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A89ED2072F for ; Tue, 2 Jun 2020 10:10:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MGUa5+DQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728289AbgFBKKa (ORCPT ); Tue, 2 Jun 2020 06:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727032AbgFBKJq (ORCPT ); Tue, 2 Jun 2020 06:09:46 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C7DC08C5C1 for ; Tue, 2 Jun 2020 03:09:46 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id x207so2947086pfc.5 for ; Tue, 02 Jun 2020 03:09: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=vautb822ZfqbgT9H1qhF7C4M74PWhQzgpsc/iQMPhyE=; b=MGUa5+DQjvlhtfr049c1/fZTWBfJSEvMFonHlxrFq/sQnDeuGeJcc19rbD1i2IUYFW wLdRgfi5usAEHgvKX+OpQiU8rU7Wukf4IBm7E1vRavICIGExstq2YzYucy2VItWJKOa+ jeZPXSqL+224vtF1Uhg376HaG0Q77QkIazFNHY1K5ndrpRfNcOAE+wcbJszpvM3VA8b3 yt4sy+m/l7mzThlR4/45Oxmf0iIzi3ZG4xs6tKIq/66HY8NrivhPSydQrhMaMdnSVgd5 DZGaTpACkz+3blFLW4phCxLZByRK4jdSNCSvI1owaTzER2JWfPUn1eKbji0Gt/bMBP+7 ZaGg== 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=vautb822ZfqbgT9H1qhF7C4M74PWhQzgpsc/iQMPhyE=; b=Sjvv3mIxILvjxRXCczHoGsj/repwBLhNhnpsM6CSCe6kaAsuj2iM086NQ3sDuzSGLn erWYrvL+lcwSToirKy+YqLm7VHfdjn4Jq3r44jyF3WoJ40JVPVlsxGPH+mt2+WT6zIsr aQwzNhwg8I2Kx4RmsJZkynuIOS9dtN4znL4VsX9qR7sa8fnbNNIjfV8rCwO6gRW3H7Ww 06y7ZG1Z5aP9JbV0A02Uguix5+SOuBz3zMhr79V/GE1eclD4/EdzFKBwVE3pJMvanPBa cXdf9zNKOArfUOCwi2UtFn4+M7aGbaL4apPOiXY+DULgeTfv64UxJa+LUp64zFBSPMBu wGlw== X-Gm-Message-State: AOAM5332o+hNb2uqQ2Lr3iKSkazSs58P96tv+ARHgf6do+MtMDfSYpzM bOMp2a8CwAMq35wh6O448pNbmg== X-Google-Smtp-Source: ABdhPJyvrxxge7r1kiYD3PJFB7Ec7P66SkuqUcn7jCBYLTysyG8pMddjI4b3PuPNg2NaNhrHragmnw== X-Received: by 2002:a62:9242:: with SMTP id o63mr24360759pfd.310.1591092585950; Tue, 02 Jun 2020 03:09:45 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id d8sm1931276pgb.42.2020.06.02.03.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 03:09: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: [PATCH v4 2/5] dt-bindings: regulator: Add labibb regulator Date: Tue, 2 Jun 2020 15:39:21 +0530 Message-Id: <20200602100924.26256-3-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100924.26256-1-sumit.semwal@linaro.org> References: <20200602100924.26256-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] --- v2: updated for better compatible string and names. v3: moved to yaml v4: fixed dt_binding_check issues --- .../regulator/qcom-labibb-regulator.yaml | 79 +++++++++++++++++++ 1 file changed, 79 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..178820ec04c7 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml @@ -0,0 +1,79 @@ +# 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 + + properties: + + interrupts: + maxItems: 1 + description: + Short-circuit interrupt for lab. + + interrupt-names: + const: sc-err + + required: + - interrupts + - interrupt-names + + ibb: + type: object + + properties: + + interrupts: + maxItems: 1 + description: + Short-circuit interrupt for lab. + + interrupt-names: + const: sc-err + + required: + - interrupts + - interrupt-names + +required: + - compatible + +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 Tue Jun 2 10:09: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: 11583533 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 75740739 for ; Tue, 2 Jun 2020 10:10:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CE40206A4 for ; Tue, 2 Jun 2020 10:10:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JPrls4ET" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728232AbgFBKKX (ORCPT ); Tue, 2 Jun 2020 06:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727782AbgFBKJu (ORCPT ); Tue, 2 Jun 2020 06:09:50 -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 60D98C08C5C0 for ; Tue, 2 Jun 2020 03:09:50 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id b7so956375pju.0 for ; Tue, 02 Jun 2020 03:09:50 -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=VDUg6z9g8U9M6fAkFW44jT1VB/1+ZQ8nnChdFdTrw0o=; b=JPrls4ETeYgIMJX8QWPVQUeGPDIFB+vzbpaSR5smt+GsXM2c2z7wR9aheT0MN045P2 MNn4xigoWj3B+e/Mlkhx8leM+ryWRSyDkv2jCuMpjMoMbsu6AveAhfgJUHQ04LLWxZmN Mgejx+A7Nfvupn6zYsWwCzGymftS0KpiDMYxnUrGc8Z7h4wVwSJgqHJSqQ8KVtifV0X7 rlEB+oWDujkm/iwFE0RsCoTI8us/FmQfaZNaYZGaCf6JwP+V5n7ZiL9XU/eRKA9H7Sb3 hQZABN9U4kKHxk5DR00FZFVn1TbaoJ9Ge7zovM/YwR3zCbmAbsNpG5n5/W57XxXCdpd4 S+hA== 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=VDUg6z9g8U9M6fAkFW44jT1VB/1+ZQ8nnChdFdTrw0o=; b=KCa4jE93avf6WLeD2cm9JIv2gtrKMyhf2x0EyOssLQ1H7hpzkVX3zglcm2nSTGoI82 JKLdW9/eRtbsPK02tETnn7XVOQfJOYkUu91GCf8QUV0jy1IMO2R2t82yCXvvGUoNvROy pGCV4GlF5Gl9YgjjvaFhoO6P3xJjPda5+uhGKUVAUIKpG/j933gLv7OR2XWFmlugQVbe 1XJTl6fb8Nh4/7lKLmzgG2AS6/0RM/DYSkO9U4hjPArdrgPD6+3V987STj54Tkdt1lxY fbsHt/EIqDPi2Qmj3QEu1HZq+IdBiQglVXdFUwPF71pvqD/RUSr3VFx1Dd5nVbrAcc2K EpwA== X-Gm-Message-State: AOAM531CD3a/oHluuNPl0Q5sjZqnTC3G4WBvnvSMM0A2qErAuNryRLKv OZ0HRcXIt/UUImQ9eqcv6gHR1g== X-Google-Smtp-Source: ABdhPJwnO+GOOLL0Y48EeL/vzlAQa5VHkhlhDZThUPUSKKqU0v9nmNf30V1MnTAaDnlATpYdfSTLog== X-Received: by 2002:a17:90b:3614:: with SMTP id ml20mr4435051pjb.41.1591092589904; Tue, 02 Jun 2020 03:09:49 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id d8sm1931276pgb.42.2020.06.02.03.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 03:09:49 -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 v4 3/5] arm64: dts: qcom: pmi8998: Add nodes for LAB and IBB regulators Date: Tue, 2 Jun 2020 15:39:22 +0530 Message-Id: <20200602100924.26256-4-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100924.26256-1-sumit.semwal@linaro.org> References: <20200602100924.26256-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] --- v2: sumits: updated for better compatible string and names v3: sumits: updated interrupt-names as per review comments v4: sumits: removed labibb label --- 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..3230b78b8048 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 { + 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 Tue Jun 2 10:09: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: 11583523 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 DF8451392 for ; Tue, 2 Jun 2020 10:10:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9C4A206A4 for ; Tue, 2 Jun 2020 10:10:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ORS0mq6U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbgFBKKB (ORCPT ); Tue, 2 Jun 2020 06:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727921AbgFBKJz (ORCPT ); Tue, 2 Jun 2020 06:09:55 -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 7A7BBC08C5C0 for ; Tue, 2 Jun 2020 03:09:54 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id nm22so1142295pjb.4 for ; Tue, 02 Jun 2020 03:09:54 -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=WQ8tlQ9M2KNVUknmTLJ9Ovy1EUyM0LdAsA5zBG5CPW8=; b=ORS0mq6UB6c17FJD3ZPVsoh2rQkYrnxC2efGcLAmVgm9JxOM0HLvsm7j/sOwyROJ1c vnHyABy/OWd0dngrfZZAZHJOUrKVHIpKIaGWXt4fQJpPA7eSUdhBWwtuSJ/WNgDZiTR2 q+73a7K56YfV+d464vmMAIhnaw0kQ1XzUtwbnHJt8bntyPB8/TjQyNpV8OZcVFLsN+xA XuWN7H82J/x8TeAcP9O/CX4kEojQS2ePs0lLscli7iplkq+xwOooLL744F9lIHrdVYbk OWgEUL+cw4RLGF7Mxc1iW69EIsPbLhgOXQSBmTFxBKuYnWo5dT1OHptHuRwCZfDd4MHG LIaQ== 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=WQ8tlQ9M2KNVUknmTLJ9Ovy1EUyM0LdAsA5zBG5CPW8=; b=cpDERhMka6cvDMtKWoMSGG4IAJckQd4H4dw1KoD+23QAa2wCc3ZE0X1suCCsesFnlg 5Q+3ohMOXwS601SEMeLD7aGbYzsan6aMBm7Uxx4CHjv23yFaZw4RHY2MLtvosmovdagx BVQSzXHCrkNWOV7UP163WomhEu8so5rHtIfYkXAcRaAMW7wU2jaSCsVPx+onPb+u3kS2 dVKR5L63zl+06bO/wqimk4GANk7EdyA2aWQDHeMhRZGFGAsqMoY4n82TU5nKxr/8kMpw dfxf/ry4YWscyHihNNMsyi5ii3W/A0Oo2R3MPKUXDLRsAL09/4vkE40tGk4fDrOa3ejt dzkA== X-Gm-Message-State: AOAM532ykHWewysEyg7JLd3M6klf3mtBpfe9vzVdZ7ywFvGBDVTc2PLS tpEFX0m7z1iJJ3Z9CkVHlunWMg== X-Google-Smtp-Source: ABdhPJzGq/twjlCqJvLiQfkF2b+jVjyBBBs4RdirCbWWigTJMsW87iF0xggNE/eM7YoulQsC4b298A== X-Received: by 2002:a17:90b:4c91:: with SMTP id my17mr4244853pjb.81.1591092593913; Tue, 02 Jun 2020 03:09:53 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id d8sm1931276pgb.42.2020.06.02.03.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 03:09:53 -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 v4 4/5] regulator: qcom: Add labibb driver Date: Tue, 2 Jun 2020 15:39:23 +0530 Message-Id: <20200602100924.26256-5-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100924.26256-1-sumit.semwal@linaro.org> References: <20200602100924.26256-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 [sumits: reworked to driver for more common code, using core regulator features, and using newly-added poll_enabled_time functionality from core] --- 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. v4: sumits: address review comments from v3, including cleaning up register_labibb_regulator(), and adapted to updated meaning of poll_enabled_time. --- drivers/regulator/Kconfig | 10 ++ drivers/regulator/Makefile | 1 + drivers/regulator/qcom-labibb-regulator.c | 193 ++++++++++++++++++++++ 3 files changed, 204 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..33b764ac69d1 --- /dev/null +++ b/drivers/regulator/qcom-labibb-regulator.c @@ -0,0 +1,194 @@ +// 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_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 { + u16 base; + const char *name; + u8 type; + unsigned int enable_time; + unsigned int enable_mask; +}; + +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) +{ + return regulator_enable_regmap(rdev); +} + +static int qcom_labibb_regulator_disable(struct regulator_dev *rdev) +{ + return regulator_disable_regmap(rdev); +} + +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 struct regulator_dev *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; + reg->desc.enable_mask = reg_data->enable_mask; + 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 = reg_data->enable_time; + reg->desc.poll_enabled_time = LABIBB_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; + + return devm_regulator_register(reg->dev, ®->desc, &cfg); +} + +static const struct labibb_regulator_data pmi8998_labibb_data[] = { + {0xde00, "lab", QCOM_LAB_TYPE, LAB_ENABLE_TIME, LAB_ENABLE_CTL_MASK}, + {0xdc00, "ibb", QCOM_IBB_TYPE, IBB_ENABLE_TIME, IBB_ENABLE_CTL_MASK}, + { }, +}; + +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 = &pdev->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; + } + + 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); + + if (WARN_ON(child == NULL)) + return -EINVAL; + + /* 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; + + 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; + + dev_info(dev, "Registering %s regulator\n", child->full_name); + + labibb_reg->rdev = register_labibb_regulator(labibb_reg, reg_data, child); + if (IS_ERR(labibb_reg->rdev)) { + dev_err(dev, + "qcom_labibb: error registering %s : %d\n", + child->full_name, ret); + return PTR_ERR(labibb_reg->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_LICENSE("GPL v2"); From patchwork Tue Jun 2 10:09: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: 11583525 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 EB29D739 for ; Tue, 2 Jun 2020 10:10:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFB0920738 for ; Tue, 2 Jun 2020 10:10:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lSddc/Av" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728066AbgFBKKD (ORCPT ); Tue, 2 Jun 2020 06:10:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728050AbgFBKJ7 (ORCPT ); Tue, 2 Jun 2020 06:09:59 -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 563CAC05BD43 for ; Tue, 2 Jun 2020 03:09:58 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id m2so1218445pjv.2 for ; Tue, 02 Jun 2020 03:09:58 -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=wsqa0aiNnjxSKSxZ07dY/8X+UeLS5BJ6SaHqCOj/zLM=; b=lSddc/AvN4z9zX0shlWtxeHp4IJFJCOtqh4MGjrINjiStIZWUQKc3yOAQuFdZJI06k Vgy0UakBX9xert0KE1UF87P6NBRdcXPOptUNsYNpDvrAnNp1csMaFaG6DaxQeLZTBFt1 +HoTwMoBRqgd7Kx6DaTJKw9XgING9jXQsWc3DtKEdhn2tKdTbZEB2kkGmk2VBgyPjTh6 e9wj6eyF2irxqoUdh51pQk+J/3XrBBgkHPFn5f+2m0+sjSP4g2cq9nT3RbJymdxn+gOv bydoevKbA+rxapu0nSr+tOr1TEEJPW01CMxZe7OMGPr9/LAMY2MvEQy6dcJxQRhCg4AW aGdQ== 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=wsqa0aiNnjxSKSxZ07dY/8X+UeLS5BJ6SaHqCOj/zLM=; b=otH0ntewH53RXcfajcIsanf54e9ui6MWGhjHlKu31ilZuqPn8lF1tbmFAs0v5/9O8X uRQ4jFFIE2IFn3OG8cKgKLEq96jcbqpeKNc/f4jM0QRVBxGe7Ei6oEpPHT9A2u3i+pgK 1RbqDD45Mn9g/bXQPKcRFAIKbTbDZi2Ox7UUxDHZZ4NihPRSe7ouzpY3isp8MXbjbWue iAKAINsg+tU8lM07h+j4o21gtCpeXxOWH3EQYgNjaBfnMQAp6wKpF0HEx7izl2BbzzYX qUWnrIP6oLJGhEkIrS9HMeI6bg4a3+2uQdwa5N0Ukk6HdUhLK831dtrYwc72SqniDBVc VyjQ== X-Gm-Message-State: AOAM530eMMdGbrPm8cr8Rk+sU3dD7ai9muwaLTBPIzpWclr8m2xNZ0RC q963XfpGeZMQhyevZ3vSNVTLJw== X-Google-Smtp-Source: ABdhPJxBYq+KqFnjJ1UQ+HHg3VFRhBmTfHQTgVlsT9+2hmQTf2hYbGj9JKW5daP2oYzepPi6Pw4uMg== X-Received: by 2002:a17:90a:3669:: with SMTP id s96mr4644955pjb.149.1591092597818; Tue, 02 Jun 2020 03:09:57 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id d8sm1931276pgb.42.2020.06.02.03.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 03:09:57 -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 v4 5/5] regulator: qcom: labibb: Add SC interrupt handling Date: Tue, 2 Jun 2020 15:39:24 +0530 Message-Id: <20200602100924.26256-6-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100924.26256-1-sumit.semwal@linaro.org> References: <20200602100924.26256-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 [sumits: updated to rework to use regmap_read_poll_timeout, handle it per regulator, add REGULATOR_EVENT_OVER_CURRENT handling and notification to clients and other cleanup] --- 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. v4: sumits: updated 'int vreg_enabled' to 'boot enabled', made sc_irq a local var and other review comments from v3. --- drivers/regulator/qcom-labibb-regulator.c | 102 +++++++++++++++++++++- 1 file changed, 99 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/qcom-labibb-regulator.c b/drivers/regulator/qcom-labibb-regulator.c index 33b764ac69d1..bca0308b26dd 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,16 @@ #define IBB_ENABLE_TIME (LABIBB_OFF_ON_DELAY * 10) #define LABIBB_POLL_ENABLED_TIME 1000 +#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; + bool enabled; u8 type; }; @@ -59,12 +65,26 @@ static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev) static int qcom_labibb_regulator_enable(struct regulator_dev *rdev) { - return regulator_enable_regmap(rdev); + int ret; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regulator_enable_regmap(rdev); + if (ret >= 0) + reg->enabled = true; + + return ret; } static int qcom_labibb_regulator_disable(struct regulator_dev *rdev) { - return regulator_disable_regmap(rdev); + int ret = 0; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regulator_disable_regmap(rdev); + if (ret >= 0) + reg->enabled = false; + + return ret; } static struct regulator_ops qcom_labibb_ops = { @@ -73,12 +93,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->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 struct regulator_dev *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; + int ret, sc_irq; reg->base = reg_data->base; reg->type = reg_data->type; @@ -95,6 +173,24 @@ static struct regulator_dev *register_labibb_regulator(struct labibb_regulator * reg->desc.poll_enabled_time = LABIBB_POLL_ENABLED_TIME; reg->desc.off_on_delay = LABIBB_OFF_ON_DELAY; + sc_irq = of_irq_get_byname(of_node, "sc-err"); + if (sc_irq < 0) { + dev_err(reg->dev, "Unable to get sc-err, ret = %d\n", + sc_irq); + return ERR_PTR(sc_irq); + } else { + ret = devm_request_threaded_irq(reg->dev, + 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 ERR_PTR(ret); + } + } + cfg.dev = reg->dev; cfg.driver_data = reg; cfg.regmap = reg->regmap;