Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp848194rdb; Fri, 23 Feb 2024 01:41:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVCYf+f95eKZpA5PvEjpb8SyVeYQS9AbMhGEEIFrZGxxLtM/ONlcO/IssttMWkhmE6ch11o9z50WHvf3gJoh6mNmkY9q3pseXeVegMCiw== X-Google-Smtp-Source: AGHT+IEXageCNSPrLXaE5pjHO9JMEfse6QfMTBulyXxgB209KQN+uajMoXHHVSaZxxo2+MBdILxU X-Received: by 2002:a17:906:c78f:b0:a3e:63bd:3ad8 with SMTP id cw15-20020a170906c78f00b00a3e63bd3ad8mr837236ejb.8.1708681266070; Fri, 23 Feb 2024 01:41:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708681266; cv=pass; d=google.com; s=arc-20160816; b=di57CUxun7NSd22BFTimMQR7lEj+fU5NyvTp3j7mqlgNwrZPwDvZbPYHjzUgUQPO45 GAIhDJ1YYkY5U6fJzjkcyiO2bkHgIR/dL2xN3lFqsYiiZUAMjzVEzMSh90uzB9hYZS0f 7ElxMobJiPZAfiU8iBe9sLtytkFLls7McmCP6X3iUraJwFnbQzWODGvbrR1zVjYR+qJm Bg19H/5GKyyDiCj5kgGiOkrCgz2Tc0GTCmR8473JzhmCWVU1nBzpd7lDqnD9QlU9u12c UfwQmUjGMGvCTxG1maeFbXxdBvJJyo9TJFu8nooE/V9GPZ+y0yzJlzMasyXnGQydfUtK lBGw== 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:ironport-sdr; bh=lSehpjhq72z67c0z+/9ngcQxILnCPUVHkZ700EWKK8s=; fh=PYFgvMsJkZr80o/LKy5s4XAuzlyGJLnldFQceezwP4w=; b=QlJehTr85VpEPtz/ZfNZDgGC+7Y8y7tTpiRQ3iCzK02/uhRX/oW/DkiJ/hHAfjfuJ5 J/TIjGCvBKXNWJmLc5ryIdqjEY4eOLhBsJzcKQCBm9quNPI4gTW5wWzAonx0BbYgSgSC joElG9RHx+HiAp3ewoyxIUbTvppIWVbAgNZ91GGEbeBX70L6azY+fbodmFrA9CK2yqk7 G5oBNFKZ7XEp4NBkvsFRk73AaMAE7GPJszzsPzc9JQekNP+wNitXSJJMrkNEDQT5OO+j MjZFz51Ie+8ugknc0KGbPu3HN2viVtwTbki/mSEM31GCKe3QfI/6T5dYpHlvoyXVwJa4 EvSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ltts.com dmarc=pass fromdomain=ltts.com); spf=pass (google.com: domain of linux-kernel+bounces-78040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78040-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ltts.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id go17-20020a1709070d9100b00a3f180e5da6si2842945ejc.273.2024.02.23.01.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 01:41:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ltts.com dmarc=pass fromdomain=ltts.com); spf=pass (google.com: domain of linux-kernel+bounces-78040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78040-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ltts.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id CE8D41F22817 for ; Fri, 23 Feb 2024 09:41:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D19465F470; Fri, 23 Feb 2024 09:38:40 +0000 (UTC) Received: from esa2.ltts.com (unknown [14.140.155.42]) (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 B2B7F5E23A for ; Fri, 23 Feb 2024 09:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.140.155.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681120; cv=none; b=G6J1GpuRNx0zHBfJ9EFJEfTYcc/C4+XCa09Skeeh+uBkhPzHPRNaNPLX2Oh6/Kthb9tToeTRMoM+x5UUlUbhyd2kVsqPQMMM8i0B5Gby+3Ll1P0/JojnEEgMlGs89GMerP6g1nGIErAlSP3WnN3vIhLQwrbgnrp3/CzhQsvC/Qw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681120; c=relaxed/simple; bh=ThP1e59BE2y0a+k0wmwXnnRV7uTwiiZ0I39TuYzmV0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vFcAHgXz8WhZibDQwb35RW8/eA+YsaUzimyy3tqxgis3pFzv6zfphy4KSdKOK29HNqA04t5LTPaMA1t8gbT9Q+iTFpTTHgQJSZPDqctjjZWHmLwMTIlDrGMwSmlnNAouEI8Vo3NQCC0bzqiYkJwmTcw1eehZvU/dMU4PzC273uY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ltts.com; spf=pass smtp.mailfrom=ltts.com; arc=none smtp.client-ip=14.140.155.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ltts.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ltts.com IronPort-SDR: RNlqvsbwZQUn3SXsRH7RrO5NiWao73Cty4roxzM2G5AU9Pw4OHO1MjnlawiRToHFnqKlcJ1k1s r4gn41iW7TUw== Received: from unknown (HELO localhost.localdomain) ([192.168.34.55]) by esa2.ltts.com with ESMTP; 23 Feb 2024 15:07:17 +0530 From: Bhargav Raviprakash To: linux-kernel@vger.kernel.org Cc: m.nirmaladevi@ltts.com, lee@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, jpanis@baylibre.com, devicetree@vger.kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org, lgirdwood@gmail.com, broonie@kernel.org, linus.walleij@linaro.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, nm@ti.com, vigneshr@ti.com, kristo@kernel.org, Bhargav Raviprakash Subject: [PATCH v2 10/14] misc: tps6594-esm: use regmap_field Date: Fri, 23 Feb 2024 15:06:57 +0530 Message-Id: <20240223093701.66034-11-bhargav.r@ltts.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240223093701.66034-1-bhargav.r@ltts.com> References: <20240223093701.66034-1-bhargav.r@ltts.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use regmap_field and associated APIs to update the ESM_MODE_CFG and ESM_START registers. This helps in adding support for TPS65224 PMIC. Signed-off-by: Bhargav Raviprakash --- drivers/misc/tps6594-esm.c | 60 ++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/drivers/misc/tps6594-esm.c b/drivers/misc/tps6594-esm.c index 8ec5af9dc..d0f86b0e9 100644 --- a/drivers/misc/tps6594-esm.c +++ b/drivers/misc/tps6594-esm.c @@ -15,6 +15,19 @@ #define TPS6594_DEV_REV_1 0x08 +#define ESM_MODE_CFG_SET 0xff +#define ESM_START_SET 0xff +#define ESM_MODE_CFG_CLR 0x0 +#define ESM_START_CLR 0x0 + +static struct reg_field tps6594_esm_mode_cfg = REG_FIELD(TPS6594_REG_ESM_SOC_MODE_CFG, 5, 6); +static struct reg_field tps6594_esm_start = REG_FIELD(TPS6594_REG_ESM_SOC_START_REG, 0, 0); + +struct tps6594_esm { + struct regmap_field *esm_mode_cfg; + struct regmap_field *esm_start; +}; + static irqreturn_t tps6594_esm_isr(int irq, void *dev_id) { struct platform_device *pdev = dev_id; @@ -34,6 +47,7 @@ static int tps6594_esm_probe(struct platform_device *pdev) { struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); struct device *dev = &pdev->dev; + struct tps6594_esm *esm; unsigned int rev; int irq; int ret; @@ -69,13 +83,30 @@ static int tps6594_esm_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "Failed to request irq\n"); } - ret = regmap_set_bits(tps->regmap, TPS6594_REG_ESM_SOC_MODE_CFG, - TPS6594_BIT_ESM_SOC_EN | TPS6594_BIT_ESM_SOC_ENDRV); + esm = devm_kzalloc(dev, sizeof(struct tps6594_esm), GFP_KERNEL); + if (!esm) + return -ENOMEM; + + esm->esm_mode_cfg = devm_regmap_field_alloc(dev, tps->regmap, tps6594_esm_mode_cfg); + esm->esm_start = devm_regmap_field_alloc(dev, tps->regmap, tps6594_esm_start); + + if (IS_ERR(esm->esm_mode_cfg)) { + dev_err(dev, "esm_mode_cfg reg field init failed\n"); + return PTR_ERR(esm->esm_mode_cfg); + } + + if (IS_ERR(esm->esm_start)) { + dev_err(dev, "esm_start reg field init failed\n"); + return PTR_ERR(esm->esm_start); + } + + platform_set_drvdata(pdev, esm); + + ret = regmap_field_write(esm->esm_mode_cfg, ESM_MODE_CFG_SET); if (ret) return dev_err_probe(dev, ret, "Failed to configure ESM\n"); - ret = regmap_set_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, - TPS6594_BIT_ESM_SOC_START); + ret = regmap_field_write(esm->esm_start, ESM_START_SET); if (ret) return dev_err_probe(dev, ret, "Failed to start ESM\n"); @@ -87,19 +118,17 @@ static int tps6594_esm_probe(struct platform_device *pdev) static void tps6594_esm_remove(struct platform_device *pdev) { - struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); struct device *dev = &pdev->dev; + struct tps6594_esm *esm = platform_get_drvdata(pdev); int ret; - ret = regmap_clear_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, - TPS6594_BIT_ESM_SOC_START); + ret = regmap_field_write(esm->esm_start, ESM_START_CLR); if (ret) { dev_err(dev, "Failed to stop ESM\n"); goto out; } - ret = regmap_clear_bits(tps->regmap, TPS6594_REG_ESM_SOC_MODE_CFG, - TPS6594_BIT_ESM_SOC_EN | TPS6594_BIT_ESM_SOC_ENDRV); + ret = regmap_field_write(esm->esm_mode_cfg, ESM_MODE_CFG_CLR); if (ret) dev_err(dev, "Failed to unconfigure ESM\n"); @@ -110,11 +139,12 @@ static void tps6594_esm_remove(struct platform_device *pdev) static int tps6594_esm_suspend(struct device *dev) { - struct tps6594 *tps = dev_get_drvdata(dev->parent); + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct tps6594_esm *esm = platform_get_drvdata(pdev); + int ret; - ret = regmap_clear_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, - TPS6594_BIT_ESM_SOC_START); + ret = regmap_field_write(esm->esm_start, ESM_START_CLR); pm_runtime_put_sync(dev); @@ -123,12 +153,12 @@ static int tps6594_esm_suspend(struct device *dev) static int tps6594_esm_resume(struct device *dev) { - struct tps6594 *tps = dev_get_drvdata(dev->parent); + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct tps6594_esm *esm = platform_get_drvdata(pdev); pm_runtime_get_sync(dev); - return regmap_set_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, - TPS6594_BIT_ESM_SOC_START); + return regmap_field_write(esm->esm_start, ESM_START_SET); } static DEFINE_SIMPLE_DEV_PM_OPS(tps6594_esm_pm_ops, tps6594_esm_suspend, tps6594_esm_resume); -- 2.25.1