From patchwork Fri May 8 20:41:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 200867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0F90C38A2A for ; Fri, 8 May 2020 20:42:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 838EB218AC for ; Fri, 8 May 2020 20:42:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DpwtSGfU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgEHUmo (ORCPT ); Fri, 8 May 2020 16:42:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727819AbgEHUmo (ORCPT ); Fri, 8 May 2020 16:42:44 -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 24536C061A0C for ; Fri, 8 May 2020 13:42:44 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id m7so1248074plt.5 for ; Fri, 08 May 2020 13:42:44 -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=v/kJOzHQVNztoa88Zqa893txGdJr3NbK0Uy6cZ9N+p4=; b=DpwtSGfUSL9CaKsXqVEz6+TLkdcWRpU57TbJQD2eIMJuVeMUFx37rOlwnIXKjG0zg1 +T9J0pJVRIGiPFPXLEG2zpm4A7vsYF252Wlid8+YjZBVRvYfbOs2dz7Qpb/m5iRtWtlK VvZG3TgTNpJq7gSlWQlFU0fi8IsfhcBGaKSY0ikVodZYDbeUbOJinlO3Y+N2eR4u2ISv +SlnwR1RvQ+7JDhuoTMdWxwG2DJuiimRfvT8+B8F2ZnkmQKYNDLRpSXcAAWBJ5R5EMd5 z/M2wfmFJT4uyoxKQwU6JiCkKwCF0XQPOUaRuzoK+hO9E2951WDCcYkuMAbpCZrpyWQW devQ== 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=v/kJOzHQVNztoa88Zqa893txGdJr3NbK0Uy6cZ9N+p4=; b=sEZyuGYcacLXYEYJ2X6/ijaD4IWwDDdRCn3vbZO8LVXkAP63fWOjVJo0IjLau0ty+4 5bjAePfynt73A+obJp0n37/0wMJfTMVuaujLcXyjyTn1wuCnvq2t9ZFkI7Uqm3aDRPkx a+yRfNd8SgRUS7S9V/CxHabaj8UX6ZiyuSB0fDSwqUIUqrT+n8SjtusDM44DuA1hb7vN t+EMc5X6O01O87FSQEs0YeZnueWaeGzQGZ1mNVEhBbPX9KNvuUjA2r6z2ASR4Omr0XEZ S2S+RqXuUreQ3+c5knwKmcaZkb5rwFiDq8R/ICVcMH7Wy7g/V0bKMrCSmSsJAja5fJ/g mGZQ== X-Gm-Message-State: AGi0PubkRFJt/FAVhPa1PKR7cAMz6LOrsMB2++1bkZa9mHFwKin4D8Cn Ikce+1y1CxEmgQdkLqOFGse75A== X-Google-Smtp-Source: APiQypJAb3f+QC64YiN7o7OeDguzr0+81s7Vq9M944QMiAehMTcBe6OBqfD9/1Clsaudgtub5c7lTA== X-Received: by 2002:a17:90b:8c8:: with SMTP id ds8mr7896979pjb.164.1588970563609; Fri, 08 May 2020 13:42:43 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id h191sm2670720pfe.44.2020.05.08.13.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 13:42:43 -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: [v2 1/4] dt-bindings: regulator: Add labibb regulator Date: Sat, 9 May 2020 02:11:57 +0530 Message-Id: <20200508204200.13481-2-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508204200.13481-1-sumit.semwal@linaro.org> References: <20200508204200.13481-1-sumit.semwal@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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. --- .../regulator/qcom-labibb-regulator.txt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.txt diff --git a/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.txt b/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.txt new file mode 100644 index 000000000000..6e639d69f780 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.txt @@ -0,0 +1,47 @@ +Qualcomm's LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost) Regulator + +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. + +Main node required properties: + +- compatible: Must be: + "qcom,pmi8998-lab-ibb" +- #address-cells: Must be 1 +- #size-cells: Must be 0 + +LAB subnode required properties: + +- interrupts: Specify the interrupts as per the interrupt + encoding. +- interrupt-names: Interrupt names to match up 1-to-1 with + the interrupts specified in 'interrupts' + property. + +IBB subnode required properties: + +- interrupts: Specify the interrupts as per the interrupt + encoding. +- interrupt-names: Interrupt names to match up 1-to-1 with + the interrupts specified in 'interrupts' + property. + +Example: + pmi8998_lsid1: pmic@3 { + labibb { + compatible = "qcom,pmi8998-lab-ibb"; + #address-cells = <1>; + #size-cells = <0>; + + 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 Fri May 8 20:41:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 200866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A4B9C38A2A for ; Fri, 8 May 2020 20:42:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 618D1218AC for ; Fri, 8 May 2020 20:42:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nsg+fNO+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727869AbgEHUmw (ORCPT ); Fri, 8 May 2020 16:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727867AbgEHUmw (ORCPT ); Fri, 8 May 2020 16:42:52 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C04C05BD43 for ; Fri, 8 May 2020 13:42:52 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x77so1560641pfc.0 for ; Fri, 08 May 2020 13:42:52 -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=SVjbZlHrSVv9m2cwhBcBLc6LEjcvRx6+IGpIi6KYIyE=; b=nsg+fNO+AZ1XW5nJWEXP8JVFjWOy9vRiTFuxosPSb58u/uwHDH4Ep55V5j2iNPFVx/ CYEpALPa7q+EGRgoAobwFDNpj/Fk+RVaocf8579+b1dj3DOFbBixyfcZz7gdkpVq78RC DRZa79VoCPcsD3aYFNwfmCyvcvQlaXtIltFy03n5iKNhKhiCYPDorQXHjQ42ijROgCxR Qnfmy64wnaVUFTV9LhAyhWIM5UK9WHfExO6CogxJrNgavMerAcTYQXHEB9VJlZTsR3J1 CVCcNhnTApiOAk2yNb3TIfm4VNa+qScfC279+0SoF+sq/LqIaZPf+pS3EJRsQ6u7KfW+ 86Bw== 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=SVjbZlHrSVv9m2cwhBcBLc6LEjcvRx6+IGpIi6KYIyE=; b=fnIJN8R3FaXaWCsrk6vlB/eZ2v5yjZ2kOn9uMk4OSrWKOkTKM2LJkaQ3K108B/R1ED MDlLMXmTZZ1Wn6+3mwfx+IN81YwoVHwkSZf1sEy8lCOO7ycKJqG+il9UH4leXItnm7P+ PmcpPbKNvdidNVd5Twi3Pve4kJ1PchIk/S2K4uUv2bIRl8a0uTKZfr3Jmja0FH33rQS5 whbey9Xf/0H8onx0kDp/UX/Wh/JVfKFyNsWb9OsQh9JyhV8sK40z4YBhC0g1a0mPxrMy aRGdwYQejK1xlnUwrq1k1caMevK+O/pqTCibrrktJllz8Au2k6PyTsQBi1OMymXejNDM bvng== X-Gm-Message-State: AGi0PubT8FCBknxMjIEXC1OkkmL7XaGa+tEbr/InoAOnOFFU5Q0cfonX j4UpwKjE8Oe7OtC6ub4kZ0g55w== X-Google-Smtp-Source: APiQypKRiZiS4d2dDsEoLlGqOHsfzXEJEctb3Zb7RvUKglVOqO9hrCuwwLZAF3uJ6DOWLSOn5m/sfQ== X-Received: by 2002:a63:3c4b:: with SMTP id i11mr3548334pgn.179.1588970571453; Fri, 08 May 2020 13:42:51 -0700 (PDT) Received: from nagraj.local ([49.206.21.239]) by smtp.gmail.com with ESMTPSA id h191sm2670720pfe.44.2020.05.08.13.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 13:42:50 -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: [v2 3/4] regulator: qcom: Add labibb driver Date: Sat, 9 May 2020 02:11:59 +0530 Message-Id: <20200508204200.13481-4-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508204200.13481-1-sumit.semwal@linaro.org> References: <20200508204200.13481-1-sumit.semwal@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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. This includes merging regulator_ops into one, and allowing for future labibb variations. --- drivers/regulator/Kconfig | 10 + drivers/regulator/Makefile | 1 + drivers/regulator/qcom-labibb-regulator.c | 288 ++++++++++++++++++++++ 3 files changed, 299 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..a9dc7c060375 --- /dev/null +++ b/drivers/regulator/qcom-labibb-regulator.c @@ -0,0 +1,288 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2019, 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 POWER_DELAY 8000 + +struct labibb_regulator { + struct regulator_desc desc; + struct device *dev; + struct regmap *regmap; + struct regulator_dev *rdev; + u16 base; + u8 type; +}; + +struct qcom_labibb { + struct device *dev; + struct regmap *regmap; + struct labibb_regulator lab; + struct labibb_regulator ibb; +}; + +struct labibb_regulator_data { + u16 base; + const char *name; + const char *irq_name; + u8 type; +}; + +static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev) +{ + int ret; + u8 val; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regmap_bulk_read(reg->regmap, reg->base + + REG_LABIBB_STATUS1, &val, 1); + if (ret < 0) { + dev_err(reg->dev, "Read register failed ret = %d\n", ret); + return ret; + } + + if (val & LABIBB_STATUS1_VREG_OK_BIT) + return 1; + else + return 0; +} + +static int _check_enabled_with_retries(struct regulator_dev *rdev, + int retries, int enabled) +{ + int ret; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + while (retries--) { + /* Wait for a small period before checking REG_LABIBB_STATUS1 */ + usleep_range(POWER_DELAY, POWER_DELAY + 200); + + ret = qcom_labibb_regulator_is_enabled(rdev); + + if (ret < 0) { + dev_err(reg->dev, "Can't read %s regulator status\n", + reg->desc.name); + return ret; + } + + if (ret == enabled) + return ret; + + } + + return -EINVAL; +} + +static int qcom_labibb_regulator_enable(struct regulator_dev *rdev) +{ + int ret, retries = 10; + 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; + } + + ret = _check_enabled_with_retries(rdev, retries, 1); + if (ret < 0) { + dev_err(reg->dev, "retries exhausted: enable %s regulator\n", + reg->desc.name); + return ret; + } + + if (ret) + return 0; + + + dev_err(reg->dev, "Can't enable %s\n", reg->desc.name); + return -EINVAL; +} + +static int qcom_labibb_regulator_disable(struct regulator_dev *rdev) +{ + int ret, retries = 2; + struct labibb_regulator *reg = rdev_get_drvdata(rdev); + + ret = regulator_disable_regmap(rdev); + + if (ret < 0) { + dev_err(reg->dev, "Write failed: disable %s regulator\n", + reg->desc.name); + return ret; + } + + ret = _check_enabled_with_retries(rdev, retries, 0); + if (ret < 0) { + dev_err(reg->dev, "retries exhausted: disable %s regulator\n", + reg->desc.name); + return ret; + } + + if (!ret) + return 0; + + dev_err(reg->dev, "Can't disable %s\n", reg->desc.name); + return -EINVAL; +} + +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 qcom_labibb *labibb, + const struct labibb_regulator_data *reg_data, + struct device_node *of_node) +{ + int ret; + struct labibb_regulator *reg; + struct regulator_config cfg = {}; + + if (reg_data->type == QCOM_LAB_TYPE) { + reg = &labibb->lab; + reg->desc.enable_mask = LAB_ENABLE_CTL_MASK; + } else { + reg = &labibb->ibb; + reg->desc.enable_mask = IBB_ENABLE_CTL_MASK; + } + + reg->dev = labibb->dev; + reg->base = reg_data->base; + reg->type = reg_data->type; + reg->regmap = labibb->regmap; + 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; + + cfg.dev = labibb->dev; + cfg.driver_data = reg; + cfg.regmap = labibb->regmap; + cfg.of_node = of_node; + + reg->rdev = devm_regulator_register(labibb->dev, ®->desc, + &cfg); + if (IS_ERR(reg->rdev)) { + ret = PTR_ERR(reg->rdev); + dev_err(labibb->dev, + "unable to register %s regulator\n", reg_data->name); + return ret; + } + return 0; +} + +static const struct labibb_regulator_data pmi8998_labibb_data[] = { + {0xde00, "lab", "lab-sc-err", QCOM_LAB_TYPE}, + {0xdc00, "ibb", "ibb-sc-err", QCOM_IBB_TYPE}, + { }, +}; + +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 qcom_labibb *labibb; + struct device_node *child; + const struct of_device_id *match; + const struct labibb_regulator_data *reg; + u8 type; + int ret; + + labibb = devm_kzalloc(&pdev->dev, sizeof(*labibb), GFP_KERNEL); + if (!labibb) + return -ENOMEM; + + labibb->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!labibb->regmap) { + dev_err(&pdev->dev, "Couldn't get parent's regmap\n"); + return -ENODEV; + } + + labibb->dev = &pdev->dev; + + match = of_match_device(qcom_labibb_match, &pdev->dev); + if (!match) + return -ENODEV; + + for (reg = match->data; reg->name; reg++) { + child = of_get_child_by_name(pdev->dev.of_node, reg->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_bulk_read(labibb->regmap, + reg->base + REG_PERPH_TYPE, + &type, 1); + if (ret < 0) { + dev_err(labibb->dev, + "Peripheral type read failed ret=%d\n", + ret); + return -EINVAL; + } + + if ((type != QCOM_LAB_TYPE) && (type != QCOM_IBB_TYPE)) { + dev_err(labibb->dev, + "qcom_labibb: unknown peripheral type\n"); + return -EINVAL; + } else if (type != reg->type) { + dev_err(labibb->dev, + "qcom_labibb: type read %x doesn't match DT %x\n", + type, reg->type); + return -EINVAL; + } + + ret = register_labibb_regulator(labibb, reg, child); + if (ret < 0) { + dev_err(&pdev->dev, + "qcom_labibb: error registering %s regulator: %d\n", + child->full_name, ret); + return ret; + } + } + + dev_set_drvdata(&pdev->dev, labibb); + 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");