Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp130564lqp; Sat, 8 Jun 2024 08:59:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWgXYBn9M3DWtpukMKan6JGzyebpm7Iz9gyiHm7x+Qx5X1yP908pThDt8I672cl+Y3kj1qkJnuSusTBEx7AcEen2Dr06MgJ75JuqiEtDQ== X-Google-Smtp-Source: AGHT+IGOzMh6FHtRiLQAfaA/STYKJR4b3YhkzMweFg+pTGqmNwmaN3VNO6O8T4ii/0Su+NAwX66d X-Received: by 2002:a05:6a20:9146:b0:1b0:194a:82f5 with SMTP id adf61e73a8af0-1b2e77cf72dmr8038877637.21.1717862369844; Sat, 08 Jun 2024 08:59:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717862369; cv=pass; d=google.com; s=arc-20160816; b=w1Cflfk80BGjIBF4qa1XFLdxTOav2P+USIragJnk3KJS5URenf8fg1NS4QGC18Mdcu AXtRcHQimQ4QLh1eEGtBha1mriCw9NupNSHPvVMPTv1KrVg4JByA4z8HSy4KX9QHRqjV Iagwxa1waIvqK8XzifejCNCpFJHjq8bjC/XPCCWa+M4QhM5RxgC7W/OTOVZH8lc/O4Z9 EtuWfn+j3bggX/lgUxsKVLncQasFiUpldXz/lwNqczsS7baOeIrvsblJ/j1JjLGVCjGT zVEP/XCcehLfT494uGup4I0CTy0VhLU3TfwAxXHlGuBO23ZvIgQuXR2VKCQcMbtUOuta aTPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rkSWs/l0Mp9waYReLpVrcVMVX00zAsqQr30llUIe+Y4=; fh=QhgSg1Zbhg0k1Y3sexI0DeQQQskTWRSzxoSuuRe9W3s=; b=YFK3bfK51kBABt43X/+NnFE4emvNLIrB/hIBS2kpc3k1kwdFiacrJnU7lb6R+18EDP gpiouIPHLGQrvrgVIODB/nj4CWpN/hWJfRlsh9j+czUP2Qcu3opCIl78x/g9bbIZiRSb I6D8hityefAUBaelapFhK/7foYQFxPDBxlbHZiJIesUWDhFgK05nJrxubRGuzDKuPnbu 6CFBuh1Ze5vZM4REECSRMrGKnU6tvm7mgdUR1yLoygpq+R+Qo27EruG9lI0xAc/LlMWo SoZWtQYIjg3KdMsfWRWHn6MZSRLLeRBwqt2LtZ1L/LCynGpAZn3toxjSlKqUiGrCpfXy OHTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MFNDOOfK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-207118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-703fd390606si1090349b3a.46.2024.06.08.08.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 08:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MFNDOOfK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-207118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 234F3282DB1 for ; Sat, 8 Jun 2024 15:59:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B704117D8AB; Sat, 8 Jun 2024 15:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MFNDOOfK" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73DA417B501; Sat, 8 Jun 2024 15:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717862241; cv=none; b=ZuC0OJgrEEGBUfCAX17+mlimpKPk9uGA2BhAWs9+5bzeNpL6Gzr/gH8+yiWTfbhj8LFGdo0L/Nq3C6CRGxDdMvMuijECCFX5sX33/Ysk2tPV4b2yK9HUV1sWeIMqXp31OVkheFTJhleauLw6B0K4/93pb8I1MVnXeMOy4AgtV98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717862241; c=relaxed/simple; bh=xuLW186fea6lJzbfge+RPFqnKTg2k2paCC0ZLWkIo8M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lp+P1Aa8whwpT/Gy0sUVgl5NHn7rFZ1PJTZOt0yLlTtRxeeZsyKDlXDZdqamVHYIBfuDhKY5ckY+IiU0CoAmzbwJSYres3AFfp+BzIgv6NDvFLdQl7v/S8xYBJPkT3N3RkWa+NBl04Dpw/GFquRPuh7dRQo/bmfBzhgS2TmGaQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MFNDOOfK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFDD6C4AF1D; Sat, 8 Jun 2024 15:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717862241; bh=xuLW186fea6lJzbfge+RPFqnKTg2k2paCC0ZLWkIo8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MFNDOOfKmyk7wBhW7lAU2yXcx+5TU/EnYCQSr9hCGygcERkvrnmTJ3hhIY9Io3/dq MpCcWT9gAuwR2HbMDkPMu6sy4V/+vVOfneCAjLosB66N+zMRS14PXFME4zlko+Zrtj sC7+mgyyAy3KDwQjIJLylDjGM17WcesG7fZx5YBExuIUvkbDgnyZLC+6L0SNXowQad /FLWNhfyOSah64zdaBKgoj++E5z6ahktS8HLti7zwxLownp+emefx37kSLuctj8oNJ mt+wPca/11oixsUJsC8kQTVJaPg3cnrw28At1YH4rltwRvoTs2ommJLb21LJw7GQbb tTJ41yvIhhfng== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1sFyRU-000000003QF-1Ytt; Sat, 08 Jun 2024 17:57:20 +0200 From: Johan Hovold To: Lee Jones , Mark Brown , Bjorn Andersson Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Konrad Dybcio , Liam Girdwood , Das Srinagesh , Satya Priya Kakitapalli , Linus Walleij , Stephen Boyd , Bryan O'Donoghue , Andy Shevchenko , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v3 10/12] mfd: pm8008: Rework to match new DT binding Date: Sat, 8 Jun 2024 17:55:24 +0200 Message-ID: <20240608155526.12996-11-johan+linaro@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240608155526.12996-1-johan+linaro@kernel.org> References: <20240608155526.12996-1-johan+linaro@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Rework the pm8008 driver to match the new devicetree binding which no longer describes internal details like interrupts and register offsets (including which of the two consecutive I2C addresses the registers belong to). Instead make the interrupt controller implementation internal and pass interrupts to the subdrivers using MFD cell resources. Note that subdrivers may either get their resources, like register block offsets, from the parent MFD or this can be included in the subdrivers directly. In the current implementation, the temperature alarm driver is generic enough to just get its base address and alarm interrupt from the parent driver, which already uses this information to implement the interrupt controller. The regulator driver, however, needs additional information like parent supplies and regulator characteristics so in that case it is easier to just augment its table with the regulator register base addresses. Similarly, the current GPIO driver already holds the number of pins and that lookup table can therefore also be extended with register offsets. Note that subdrivers can now access the two regmaps by name, even if the primary regmap is registered last so that it is returned by default when no name is provided in lookups. Finally, note that the temperature alarm and GPIO subdrivers need some minor rework before they can be used with non-SPMI devices like the PM8008. The temperature alarm MFD cell name specifically uses a "qpnp" rather than "spmi" prefix to prevent binding until the driver has been updated. Tested-by: Bryan O'Donoghue Signed-off-by: Johan Hovold --- drivers/mfd/Kconfig | 1 + drivers/mfd/qcom-pm8008.c | 97 +++++++++++++++++++++++---- include/dt-bindings/mfd/qcom-pm8008.h | 19 ------ 3 files changed, 86 insertions(+), 31 deletions(-) delete mode 100644 include/dt-bindings/mfd/qcom-pm8008.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 266b4f54af60..6b220dfea0a4 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -2208,6 +2208,7 @@ config MFD_ACER_A500_EC config MFD_QCOM_PM8008 tristate "QCOM PM8008 Power Management IC" depends on I2C && OF + select MFD_CORE select REGMAP_I2C select REGMAP_IRQ help diff --git a/drivers/mfd/qcom-pm8008.c b/drivers/mfd/qcom-pm8008.c index 72199840231e..246b5fe9819d 100644 --- a/drivers/mfd/qcom-pm8008.c +++ b/drivers/mfd/qcom-pm8008.c @@ -7,8 +7,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -16,8 +18,6 @@ #include #include -#include - #define I2C_INTR_STATUS_BASE 0x0550 #define INT_RT_STS_OFFSET 0x10 #define INT_SET_TYPE_OFFSET 0x11 @@ -45,6 +45,16 @@ enum { #define PM8008_GPIO1_ADDR PM8008_PERIPH_2_BASE #define PM8008_GPIO2_ADDR PM8008_PERIPH_3_BASE +/* PM8008 IRQ numbers */ +#define PM8008_IRQ_MISC_UVLO 0 +#define PM8008_IRQ_MISC_OVLO 1 +#define PM8008_IRQ_MISC_OTST2 2 +#define PM8008_IRQ_MISC_OTST3 3 +#define PM8008_IRQ_MISC_LDO_OCP 4 +#define PM8008_IRQ_TEMP_ALARM 5 +#define PM8008_IRQ_GPIO1 6 +#define PM8008_IRQ_GPIO2 7 + enum { SET_TYPE_INDEX, POLARITY_HI_INDEX, @@ -148,21 +158,65 @@ static const struct regmap_irq_chip pm8008_irq_chip = { .get_irq_reg = pm8008_get_irq_reg, }; -static struct regmap_config qcom_mfd_regmap_cfg = { +static const struct regmap_config qcom_mfd_regmap_cfg = { + .name = "primary", + .reg_bits = 16, + .val_bits = 8, + .max_register = 0xffff, +}; + +static const struct regmap_config pm8008_regmap_cfg_2 = { + .name = "secondary", .reg_bits = 16, .val_bits = 8, .max_register = 0xffff, }; +static const struct resource pm8008_temp_res[] = { + DEFINE_RES_MEM(PM8008_TEMP_ALARM_ADDR, 0x100), + DEFINE_RES_IRQ(PM8008_IRQ_TEMP_ALARM), +}; + +static const struct mfd_cell pm8008_cells[] = { + MFD_CELL_NAME("pm8008-regulator"), + MFD_CELL_RES("qpnp-temp-alarm", pm8008_temp_res), + MFD_CELL_NAME("pm8008-gpio"), +}; + +static void devm_irq_domain_fwnode_release(void *data) +{ + struct fwnode_handle *fwnode = data; + + irq_domain_free_fwnode(fwnode); +} + static int pm8008_probe(struct i2c_client *client) { struct regmap_irq_chip_data *irq_data; + struct device *dev = &client->dev; + struct regmap *regmap, *regmap2; + struct fwnode_handle *fwnode; + struct i2c_client *dummy; struct gpio_desc *reset; - int rc; - struct device *dev; - struct regmap *regmap; + char *name; + int ret; + + dummy = devm_i2c_new_dummy_device(dev, client->adapter, client->addr + 1); + if (IS_ERR(dummy)) { + ret = PTR_ERR(dummy); + dev_err(dev, "failed to claim second address: %d\n", ret); + return ret; + } + + regmap2 = devm_regmap_init_i2c(dummy, &qcom_mfd_regmap_cfg); + if (IS_ERR(regmap2)) + return PTR_ERR(regmap2); - dev = &client->dev; + ret = regmap_attach_dev(dev, regmap2, &pm8008_regmap_cfg_2); + if (ret) + return ret; + + /* Default regmap must be attached last. */ regmap = devm_regmap_init_i2c(client, &qcom_mfd_regmap_cfg); if (IS_ERR(regmap)) return PTR_ERR(regmap); @@ -177,14 +231,33 @@ static int pm8008_probe(struct i2c_client *client) */ usleep_range(1000, 2000); - if (of_property_read_bool(dev->of_node, "interrupt-controller")) { - rc = devm_regmap_add_irq_chip(dev, regmap, client->irq, + name = devm_kasprintf(dev, GFP_KERNEL, "%pOF-internal", dev->of_node); + if (!name) + return -ENOMEM; + + name = strreplace(name, '/', ':'); + + fwnode = irq_domain_alloc_named_fwnode(name); + if (!fwnode) + return -ENOMEM; + + ret = devm_add_action_or_reset(dev, devm_irq_domain_fwnode_release, fwnode); + if (ret) + return ret; + + ret = devm_regmap_add_irq_chip_fwnode(dev, fwnode, regmap, client->irq, IRQF_SHARED, 0, &pm8008_irq_chip, &irq_data); - if (rc) - dev_err(dev, "failed to add IRQ chip: %d\n", rc); + if (ret) { + dev_err(dev, "failed to add IRQ chip: %d\n", ret); + return ret; } - return devm_of_platform_populate(dev); + /* Needed by GPIO driver. */ + dev_set_drvdata(dev, regmap_irq_get_domain(irq_data)); + + return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, pm8008_cells, + ARRAY_SIZE(pm8008_cells), NULL, 0, + regmap_irq_get_domain(irq_data)); } static const struct of_device_id pm8008_match[] = { diff --git a/include/dt-bindings/mfd/qcom-pm8008.h b/include/dt-bindings/mfd/qcom-pm8008.h deleted file mode 100644 index eca9448df228..000000000000 --- a/include/dt-bindings/mfd/qcom-pm8008.h +++ /dev/null @@ -1,19 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (c) 2021 The Linux Foundation. All rights reserved. - */ - -#ifndef __DT_BINDINGS_MFD_QCOM_PM8008_H -#define __DT_BINDINGS_MFD_QCOM_PM8008_H - -/* PM8008 IRQ numbers */ -#define PM8008_IRQ_MISC_UVLO 0 -#define PM8008_IRQ_MISC_OVLO 1 -#define PM8008_IRQ_MISC_OTST2 2 -#define PM8008_IRQ_MISC_OTST3 3 -#define PM8008_IRQ_MISC_LDO_OCP 4 -#define PM8008_IRQ_TEMP_ALARM 5 -#define PM8008_IRQ_GPIO1 6 -#define PM8008_IRQ_GPIO2 7 - -#endif -- 2.44.1