linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>
To: Lee Jones <lee.jones@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Nicolas Boichat <drinkcat@chromium.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Sean Wang <sean.wang@mediatek.com>,
	Sebastian Reichel <sre@kernel.org>,
	Eddie Huang <eddie.huang@mediatek.com>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	Richard Fontana <rfontana@redhat.com>,
	Frank Wunderlich <frank-w@public-files.de>,
	Josef Friedl <josef.friedl@speed.at>,
	Thomas Gleixner <tglx@linutronix.de>,
	Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>,
	Ran Bi <ran.bi@mediatek.com>, <devicetree@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-rtc@vger.kernel.org>, <srv_heupstream@mediatek.com>
Subject: [PATCH v12 2/6] mfd: mt6397: Trim probe function to support different chips more cleanly
Date: Wed, 8 Apr 2020 16:12:07 +0800	[thread overview]
Message-ID: <1586333531-21641-3-git-send-email-hsin-hsiung.wang@mediatek.com> (raw)
In-Reply-To: <1586333531-21641-1-git-send-email-hsin-hsiung.wang@mediatek.com>

Add new struct members for mfd-cells and irq initial function, so we can
call devm_mfd_add_devices() only once.

Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>
---
 drivers/mfd/mt6397-core.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index d2e70d8..a313a72 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -103,22 +103,31 @@ static const struct mfd_cell mt6397_devs[] = {
 struct chip_data {
 	u32 cid_addr;
 	u32 cid_shift;
+	const struct mfd_cell *cells;
+	int cell_size;
+	int (*irq_init)(struct mt6397_chip *chip);
 };
 
 static const struct chip_data mt6323_core = {
 	.cid_addr = MT6323_CID,
 	.cid_shift = 0,
+	.cells = mt6323_devs,
+	.cell_size = ARRAY_SIZE(mt6323_devs),
+	.irq_init = mt6397_irq_init,
 };
 
 static const struct chip_data mt6397_core = {
 	.cid_addr = MT6397_CID,
 	.cid_shift = 0,
+	.cells = mt6397_devs,
+	.cell_size = ARRAY_SIZE(mt6397_devs),
+	.irq_init = mt6397_irq_init,
 };
 
 static int mt6397_probe(struct platform_device *pdev)
 {
 	int ret;
-	unsigned int id;
+	unsigned int id = 0;
 	struct mt6397_chip *pmic;
 	const struct chip_data *pmic_core;
 
@@ -154,29 +163,13 @@ static int mt6397_probe(struct platform_device *pdev)
 	if (pmic->irq <= 0)
 		return pmic->irq;
 
-	ret = mt6397_irq_init(pmic);
+	ret = pmic_core->irq_init(pmic);
 	if (ret)
 		return ret;
 
-	switch (pmic->chip_id) {
-	case MT6323_CHIP_ID:
-		ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
-					   mt6323_devs, ARRAY_SIZE(mt6323_devs),
-					   NULL, 0, pmic->irq_domain);
-		break;
-
-	case MT6391_CHIP_ID:
-	case MT6397_CHIP_ID:
-		ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
-					   mt6397_devs, ARRAY_SIZE(mt6397_devs),
-					   NULL, 0, pmic->irq_domain);
-		break;
-
-	default:
-		dev_err(&pdev->dev, "unsupported chip: %d\n", pmic->chip_id);
-		return -ENODEV;
-	}
-
+	ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
+				   pmic_core->cells, pmic_core->cell_size,
+				   NULL, 0, pmic->irq_domain);
 	if (ret) {
 		irq_domain_remove(pmic->irq_domain);
 		dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
-- 
2.6.4

  parent reply	other threads:[~2020-04-08  8:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08  8:12 [PATCH v12 0/6] Add Support for MediaTek PMIC MT6358 Hsin-Hsiung Wang
2020-04-08  8:12 ` [PATCH v12 1/6] mfd: mt6397: Modify suspend/resume behavior Hsin-Hsiung Wang
2020-04-16  8:49   ` Lee Jones
2020-04-20 10:52     ` Hsin-hsiung Wang
2020-04-20 11:15       ` Lee Jones
2020-04-20 11:55         ` Hsin-hsiung Wang
2020-04-08  8:12 ` Hsin-Hsiung Wang [this message]
2020-04-16  8:52   ` [PATCH v12 2/6] mfd: mt6397: Trim probe function to support different chips more cleanly Lee Jones
2020-04-08  8:12 ` [PATCH v12 3/6] dt-bindings: mfd: Add compatible for the MediaTek MT6358 PMIC Hsin-Hsiung Wang
2020-04-08  8:12 ` [PATCH v12 4/6] mfd: Add support " Hsin-Hsiung Wang
2020-04-16  9:10   ` Lee Jones
2020-04-08  8:12 ` [PATCH v12 5/6] rtc: mt6397: Add support for the MediaTek MT6358 RTC Hsin-Hsiung Wang
2020-04-16  9:14   ` Lee Jones
2020-04-17  8:29     ` Ran Bi
2020-04-17  8:49       ` Ran Bi
2020-04-20  7:37         ` Lee Jones
2020-04-20  7:36       ` Lee Jones
2020-04-08  8:12 ` [PATCH v12 6/6] arm64: dts: mt6358: add PMIC MT6358 related nodes Hsin-Hsiung Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1586333531-21641-3-git-send-email-hsin-hsiung.wang@mediatek.com \
    --to=hsin-hsiung.wang@mediatek.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=eddie.huang@mediatek.com \
    --cc=frank-w@public-files.de \
    --cc=josef.friedl@speed.at \
    --cc=kstewart@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=ran.bi@mediatek.com \
    --cc=rfontana@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=sean.wang@mediatek.com \
    --cc=sre@kernel.org \
    --cc=srv_heupstream@mediatek.com \
    --cc=tglx@linutronix.de \
    --subject='Re: [PATCH v12 2/6] mfd: mt6397: Trim probe function to support different chips more cleanly' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).