diff mbox series

[v3,07/12] i2c: wmt: create wmt_i2c_init for general init

Message ID c3035b20e11b8c44eff7e9c4d4d69875313d0697.1698889581.git.hanshu-oc@zhaoxin.com
State New
Headers show
Series i2c: add zhaoxin i2c controller driver | expand

Commit Message

Hans Hu Nov. 2, 2023, 2:53 a.m. UTC
Some common initialization actions are put in the function
wmt_i2c_init(), which is convenient to share with zhaoxin.

Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com>
---
 drivers/i2c/busses/i2c-wmt.c | 70 ++++++++++++++++++++++--------------
 1 file changed, 44 insertions(+), 26 deletions(-)

Comments

Wolfram Sang Dec. 22, 2023, 10:26 a.m. UTC | #1
> +		irq_flags = IRQF_SHARED;
> +		i2c_dev->irq = platform_get_irq(pdev, 0);
> +		if (i2c_dev->irq < 0)
> +			return i2c_dev->irq;

Doesn't this belong to patch 11 where you introduce the new platform?

Sadly, I can't apply this patch anymore because patch 6 needs to be
dropped.

Could you rebase this series on top of my for-next branch once I pushed
it out later today? This will have the first cleanups already applied.
Hans Hu Dec. 22, 2023, 10:55 a.m. UTC | #2
On 2023/12/22 18:26, Wolfram Sang wrote:
>> +		irq_flags = IRQF_SHARED;
>> +		i2c_dev->irq = platform_get_irq(pdev, 0);
>> +		if (i2c_dev->irq < 0)
>> +			return i2c_dev->irq;
> Doesn't this belong to patch 11 where you introduce the new platform?
>
> Sadly, I can't apply this patch anymore because patch 6 needs to be
> dropped.
>
> Could you rebase this series on top of my for-next branch once I pushed
> it out later today? This will have the first cleanups already applied.
>
Thanks for your review, I will rebase this series on your last for-next 
branch.
Wolfram Sang Dec. 22, 2023, 11 a.m. UTC | #3
> Thanks for your review, I will rebase this series on your last for-next
> branch.

Thanks, I pushed it now.
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c
index 406b6827c42d..b2fb2e7e4f0d 100644
--- a/drivers/i2c/busses/i2c-wmt.c
+++ b/drivers/i2c/busses/i2c-wmt.c
@@ -286,6 +286,47 @@  static irqreturn_t wmt_i2c_isr(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
+int wmt_i2c_init(struct platform_device *pdev, struct wmt_i2c_dev **pi2c_dev)
+{
+	int err;
+	int irq_flags;
+	struct wmt_i2c_dev *i2c_dev;
+	struct device_node *np = pdev->dev.of_node;
+
+	i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
+	if (!i2c_dev)
+		return -ENOMEM;
+
+	i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
+	if (IS_ERR(i2c_dev->base))
+		return PTR_ERR(i2c_dev->base);
+
+	if (np) {
+		irq_flags = 0;
+		i2c_dev->irq = irq_of_parse_and_map(np, 0);
+		if (!i2c_dev->irq)
+			return -EINVAL;
+	} else {
+		irq_flags = IRQF_SHARED;
+		i2c_dev->irq = platform_get_irq(pdev, 0);
+		if (i2c_dev->irq < 0)
+			return i2c_dev->irq;
+	}
+
+	err = devm_request_irq(&pdev->dev, i2c_dev->irq, wmt_i2c_isr,
+					irq_flags, pdev->name, i2c_dev);
+	if (err)
+		return dev_err_probe(&pdev->dev, err,
+				"failed to request irq %i\n", i2c_dev->irq);
+
+	i2c_dev->dev = &pdev->dev;
+	init_completion(&i2c_dev->complete);
+	platform_set_drvdata(pdev, i2c_dev);
+
+	*pi2c_dev = i2c_dev;
+	return 0;
+}
+
 static int wmt_i2c_reset_hardware(struct wmt_i2c_dev *i2c_dev)
 {
 	int err;
@@ -327,19 +368,9 @@  static int wmt_i2c_probe(struct platform_device *pdev)
 	int err;
 	u32 clk_rate;
 
-	i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
-	if (!i2c_dev)
-		return -ENOMEM;
-
-	i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
-	if (IS_ERR(i2c_dev->base))
-		return PTR_ERR(i2c_dev->base);
-
-	i2c_dev->irq = irq_of_parse_and_map(np, 0);
-	if (!i2c_dev->irq) {
-		dev_err(&pdev->dev, "irq missing or invalid\n");
-		return -EINVAL;
-	}
+	err = wmt_i2c_init(pdev, &i2c_dev);
+	if (err)
+		return err;
 
 	i2c_dev->clk = of_clk_get(np, 0);
 	if (IS_ERR(i2c_dev->clk)) {
@@ -351,15 +382,6 @@  static int wmt_i2c_probe(struct platform_device *pdev)
 	if (!err && (clk_rate == I2C_MAX_FAST_MODE_FREQ))
 		i2c_dev->tcr = TCR_FAST_MODE;
 
-	i2c_dev->dev = &pdev->dev;
-
-	err = devm_request_irq(&pdev->dev, i2c_dev->irq, wmt_i2c_isr, 0,
-							"i2c", i2c_dev);
-	if (err) {
-		dev_err(&pdev->dev, "failed to request irq %i\n", i2c_dev->irq);
-		return err;
-	}
-
 	adap = &i2c_dev->adapter;
 	i2c_set_adapdata(adap, i2c_dev);
 	strscpy(adap->name, "WMT I2C adapter", sizeof(adap->name));
@@ -368,16 +390,12 @@  static int wmt_i2c_probe(struct platform_device *pdev)
 	adap->dev.parent = &pdev->dev;
 	adap->dev.of_node = pdev->dev.of_node;
 
-	init_completion(&i2c_dev->complete);
-
 	err = wmt_i2c_reset_hardware(i2c_dev);
 	if (err) {
 		dev_err(&pdev->dev, "error initializing hardware\n");
 		return err;
 	}
 
-	platform_set_drvdata(pdev, i2c_dev);
-
 	return devm_i2c_add_adapter(&pdev->dev, &i2c_dev->adapter);
 }