Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp144298rdb; Thu, 8 Feb 2024 01:24:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWmZ/O7DCiwXjxO5a/GMpPBHBDp090ajWr1+GFfIG9hCYTfJ8p7iAAy79ruEHHM1mj5Ex0iAoZXcqQ3csbrEAxFlgu+0X0hIOMHaf97LA== X-Google-Smtp-Source: AGHT+IGDYFmA9R6qWvAAScvSzPndaMaepPuXWRhWqY1OB6dMwEByvRjoFWJ2qXJfIc4U5N3M6VXS X-Received: by 2002:aa7:d047:0:b0:560:c6a8:e7c8 with SMTP id n7-20020aa7d047000000b00560c6a8e7c8mr4297435edo.10.1707384253317; Thu, 08 Feb 2024 01:24:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707384253; cv=pass; d=google.com; s=arc-20160816; b=wqtQYH6lQYxP6AnF4uSV6x1RPSqRsFDo9n2EBX1uYAryeTBAxdQSxHj0aKkMhpNKIL ruyPxIV9ZXRKbfB8Zzs89sVr80Ogh8qjOj6iu9OyEUzU2nNeqjf0/QScyIz1EJ9OxWmB YK4Fel8kxYYm5HnXluy6z6FUb3XDu+/mO91H+98fiIIUz4IX5aokY5L6tqOfEQnpCHbC hBZiCLjMWxhqHNZ5/G5uAl/XUBEbwE+W0cFF+61LEvTaeOagJ2tEcZdUUQO7yKYyrQnh vkyI/UyLLks759vIUKyYu4BCBjvxwKGhrtBUaWIb3J+WQ9cO1XdVWM2VgvtJd1QvASVb DUCw== 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=yLxpGTViBmDOI7Ty3oEi03RyrhoSOEPP78Rmq8WUJkE=; b=T299Aw6QQAQM8Y0j82KqkPh0Ds6o0ni0YTtcD+UfTj6+S9vknij+Q8+J+0CqTClfNn FQiLylDXC6TFdDJ64ZT668kKspCFU6Z5rrjNB+X5dK0c7rG+70JOPo/XB220j2CeK709 YObl5uS/ckSADjYgQDlhlkJf5sEAQjOsZosSpH/pZBWJgbWkGcVbJALG7lm92yWNalho n0DyoPAc4g7jHyXEjntBRri74CuhI/WseAx0Wsbe0ANM4pG3gJTcKcG94ABlL1lgYMbq NyXJxyp7UoGrR323CEZWRZUihmR8BWQcCjLGDj3BvFMk333jjiqDVwp0+b4cHB9xRR/f BZIA==; 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-57725-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57725-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ltts.com X-Forwarded-Encrypted: i=2; AJvYcCXvZwiIbHmtNblFUMoPofOI8Zj2jFtaA/Gv1iju53vmSkFLLWpycqWLxmA1MeRVNPgNoJU8cti2JJTF2jXYuLBE6h4g+eKFjtjQrDIodQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m18-20020aa7c492000000b00560b530d441si728507edq.162.2024.02.08.01.24.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 01:24:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57725-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-57725-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57725-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) 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 121351F222BA for ; Thu, 8 Feb 2024 09:24:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E2A171B50; Thu, 8 Feb 2024 09:21:24 +0000 (UTC) Received: from esa1.ltts.com (unknown [118.185.121.105]) (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 A881671B24 for ; Thu, 8 Feb 2024 09:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.185.121.105 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707384083; cv=none; b=MYXUKLOVyAYGr5cHZFRv4pi1uqKZEQ3tzjCPym1654MTGkfb0LDhuTkqZdINFuiE1zF4XGHhfoIj5k896Ywd/R5vRixrVMsWFxTgydvduTNSbbfVlfQvZ9xGqR/bi09tldunuzOSMqEOVbp5OB67YyGEza5jTe69VRefmJxZ6Xo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707384083; c=relaxed/simple; bh=ThP1e59BE2y0a+k0wmwXnnRV7uTwiiZ0I39TuYzmV0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Shroq9K2wTpyPjsl0516kvn5CLlKMZ5vfJPnB/L5w3aWEa0ennEUxWnNEjedMzk78vjBZpF2bR34D6NJOh1TJSSWFx/QwdqJSN0DKr3pS/pSSawpr3iw68sUBeda0iB1aXdEmY4ZNFg9ZJ+o5tX3fV6xfm/fZKIElbjmO70ITHg= 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=118.185.121.105 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: f+BS/AvZcIkT+V+vVDnXBhlduYS8eoLLZsdpJ+TVClBYt3xLPcOhYcpyy3BFtzoaiBINjAof0K 82nVD8yU/m7w== Received: from unknown (HELO localhost.localdomain) ([192.168.34.55]) by esa1.ltts.com with ESMTP; 08 Feb 2024 14:51:14 +0530 From: Bhargav Raviprakash To: linux-kernel@vger.kernel.org Cc: m.nirmaladevi@ltts.com, arnd@arndb.de, gregkh@linuxfoundation.org, Bhargav Raviprakash Subject: [PATCH v1 09/13] misc: tps6594-esm: use regmap_field Date: Thu, 8 Feb 2024 14:50:58 +0530 Message-Id: <20240208092059.1207134-3-bhargav.r@ltts.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208092059.1207134-1-bhargav.r@ltts.com> References: <20240208092059.1207134-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