Skip to contentSkip to conversation

i2c: microchip: pci1xxxx: Add driver for I2C host controller in multifunction endpoint of pci1xxxx switch

PATCH Superseded Tharun Kumar P 2 participants 5 messages Sep 1, 2022 – Sep 5, 2022

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: microchip: pci1xxxx: Add driver for I2C host controller in multifunction endpoint of pci1xxxx switch

Microchip pci1xxxx is an unmanaged PCIe3.1a Switch for Consumer, Industrial and Automotive applications. This switch has multiple downstream ports. In one of the Switch's Downstream port, there is a multifunction endpoint for peripherals which includes an I2C host controller. The I2C function in the endpoint operates at 100KHz, 400KHz and 1 MHz and has buffer depth of 128 bytes.
This patch provides the I2C controller driver for the I2C function of the switch.

---
RFC -> V2:
1. Removed pci_free_irq_vectors API in code since pcim_enable_device is used
2. Added pci1xxxx_i2c_shutdown API in failure case of pci_alloc_irq_vectors and devm_request_irq
3. Used devm variant of i2c_add_adapter
4. Resolved name collision and fixed styling issues in comments
---

 MAINTAINERS                            |    8 +
 drivers/i2c/busses/Kconfig             |   10 +
 drivers/i2c/busses/Makefile            |    1 +
 drivers/i2c/busses/i2c-mchp-pci1xxxx.c | 1255 ++++++++++++++++++++++++
 4 files changed, 1274 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-mchp-pci1xxxx.c
MAINTAINERS +8 -0
index 3cf9842d9233..204885ab5200 100644
@@ -13110,6 +13110,14 @@ S:	Supported
 F:	Documentation/devicetree/bindings/mtd/atmel-nand.txt
 F:	drivers/mtd/nand/raw/atmel/*
 
+MICROCHIP PCI1XXXX I2C DRIVER
+M:	Tharun Kumar P <[email protected]>
+M:	Kumaravel Thiagarajan <[email protected]>
+M:	Microchip Linux Driver Support <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/i2c/busses/i2c-mchp-pci1xxxx.c
+
 MICROCHIP PWM DRIVER
 M:	Claudiu Beznea <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
drivers/i2c/busses/Kconfig +10 -0
index a1bae59208e3..7e967d87dc04 100644
@@ -1244,6 +1244,16 @@ config I2C_PARPORT
 	  This support is also available as a module.  If so, the module
 	  will be called i2c-parport.
 
+config I2C_PCI1XXXX
+	tristate "PCI1XXXX I2C Host Adapter"
+	depends on PCI
+	help
+	  If you say yes to this option, support will be included for
+	  Microchip PCI1XXXX's I2C interface.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called i2c-mchp-pci1xxxx.
+
 config I2C_ROBOTFUZZ_OSIF
 	tristate "RobotFuzz Open Source InterFace USB adapter"
 	depends on USB
drivers/i2c/busses/Makefile +1 -0
index 479f60e4ee3d..2372ed91e7ad 100644
@@ -131,6 +131,7 @@ obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
 obj-$(CONFIG_I2C_DLN2)		+= i2c-dln2.o
 obj-$(CONFIG_I2C_CP2615) += i2c-cp2615.o
 obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
+obj-$(CONFIG_I2C_PCI1XXXX)	+= i2c-mchp-pci1xxxx.o
 obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF)	+= i2c-robotfuzz-osif.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
 obj-$(CONFIG_I2C_TINY_USB)	+= i2c-tiny-usb.o
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +1255 -0

1,255 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Tharun Kumar P

Microchip pci1xxxx is an unmanaged PCIe3.1a Switch for Consumer, Industrial and Automotive applications. This switch has multiple downstream ports. In one of the Switch's Downstream port, there is a multifunction endpoint for peripherals which includes an I2C host controller. The I2C function in the endpoint operates at 100KHz, 400KHz and 1 MHz and has buffer depth of 128 bytes.
This patch provides the I2C controller driver for the I2C function of the switch.

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 80

Quoted 2 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +2 -0
+#define SMB_IDLE_SCALING_100KHZ		((FAIR_IDLE_DELAY_100KHZ_TICKS << 16) | \
+					FAIR_BUS_IDLE_MIN_100KHZ_TICKS)

This kind of indentation harder to read than

#define SMB_IDLE_SCALING_100KHZ		\
	((FAIR_IDLE_DELAY_100KHZ_TICKS << 16) | FAIR_BUS_IDLE_MIN_100KHZ_TICKS)

Ditto for other similar cases.

...

Quoted 1 line

+/*

If it's a kernel doc, make it kernel doc.

Quoted 9 lines

+ * struct pci1xxxx_i2c - private structure for the I2C controller
+ * @i2c_xfer_done: used for synchronisation between foreground & isr
+ * @i2c_xfer_in_progress: boolean to indicate whether a transfer is in
+ * progress or not
+ * @adap: I2C adapter instance
+ * @i2c_base: pci base address of the I2C controller
+ * @freq: frequency of I2C transfer
+ * @flags: internal flags to store transfer conditions
+ */

...

Quoted 1 line

+static int set_sys_lock(void __iomem *addr)

Why not to take pointer to your private structure and offset instead of address and calc the address here?

...

Quoted 1 line

+static int release_sys_lock(void __iomem *addr)

Ditto.

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 436

Quoted 11 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +11 -0
+static void pci1xxxx_i2c_buffer_write(struct pci1xxxx_i2c *i2c, u8 slaveaddr,
+				      u8 transferlen, unsigned char *buf)
+{
+	if (slaveaddr) {
+		writeb(slaveaddr, i2c->i2c_base + SMBUS_MST_BUF);
+		if (buf)
+			memcpy_toio((i2c->i2c_base + SMBUS_MST_BUF + 1), buf, transferlen);
+	} else {
+		if (buf)
+			memcpy_toio((i2c->i2c_base + SMBUS_MST_BUF), buf, transferlen);
+	}

Why do you need buf checks? Is your code can shoot itself in the foot?

Quoted 1 line

+}

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 610

Quoted 5 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +3 -0
+		regval &= ~(intr_msk);
 
+		regval |= (I2C_INPUT_EN | I2C_OUTPUT_EN);
 
+		regval |= (I2C_INPUT_EN | I2C_OUTPUT_EN);

And in a plenty places you add extra parentheses. Reread your code and drop them and in some cases (I will show below an example) move code to shorter amount of LoCs.

...

Review

Quoted 1 line
(quoted diff) +1 -0
+		regval &=  ~(I2C_INPUT_EN | I2C_OUTPUT_EN);

Extra space.

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+	pci1xxxx_i2c_config_high_level_intr(i2c, (I2C_BUF_MSTR_INTR_MASK),
+					    true);

Why parentheses? Why it can't be one line?
There are more examples like this. Fix them all.

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 864

Quoted 4 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +3 -0
+			if (i2c->flags & I2C_FLAGS_SMB_BLK_READ)
+				pci1xxxx_i2c_set_readm(i2c, true);
 
+

We don't need useless blank lines.

Quoted 9 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +9 -0
+		} else {
+			pci1xxxx_i2c_set_count(i2c, 0, 0, transferlen);
+
+			pci1xxxx_i2c_config_asr(i2c, false);
+
+			pci1xxxx_i2c_clear_flags(i2c);
+
+			pci1xxxx_i2c_set_transfer_dir(i2c, I2C_DIRN_READ);
+		}

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 901

Quoted 4 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +3 -0
+		if (i2c->flags & I2C_FLAGS_SMB_BLK_READ) {
 
+			buf[0] = readb(i2c->i2c_base +
+				      SMBUS_MST_BUF);

Why not on one line?

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 909

Quoted 8 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +8 -0
+			read_count = buf[0];
+			memcpy_fromio(&buf[1], (i2c->i2c_base +
+						SMBUS_MST_BUF + 1),
+						read_count);
+		} else {
+			memcpy_fromio(&buf[count], (i2c->i2c_base +
+						SMBUS_MST_BUF), transferlen);
+		}

These accessors may copy from 1 to 4 bytes at a time. Does your hardware supports this kind of accesses?

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1106

Quoted 10 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +10 -0
+static int pci1xxxx_i2c_suspend(struct device *dev)
+{
+	struct pci1xxxx_i2c *i2c = dev_get_drvdata(dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
+	u32 regval;
+
+	i2c_mark_adapter_suspended(&i2c->adap);
+
+	while ((i2c->i2c_xfer_in_progress))
+		msleep(20);

Each long sleep (20 ms is quite long) has to be explained. But this entire loop looks like a band-aid of lack of IRQ or so. Why do you need to poll?

Quoted 17 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +17 -0
+	pci1xxxx_i2c_config_high_level_intr(i2c,
+					    SMBALERT_WAKE_INTR_MASK,
+					    true);
+
+	/*
+	 * Enable the PERST_DIS bit to mask the PERST from
+	 * resetting the core registers
+	 */
+	regval = readl(i2c->i2c_base + SMBUS_RESET_REG);
+	regval |= PERI_SMBUS_D3_RESET_DIS;
+	writel(regval, i2c->i2c_base + SMBUS_RESET_REG);
+	/* Enable PCI wake in the PMCSR register */
+	device_set_wakeup_enable(dev, TRUE);
+	pci_wake_from_d3(pdev, TRUE);
+
+	return 0;
+}

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1142

Quoted 1 line
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +1 -0
+	pci_wake_from_d3(pdev, FALSE);

What's FALSE and why false can't be used?

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1147

Quoted 2 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +2 -0
+static SIMPLE_DEV_PM_OPS(pci1xxxx_i2c_pm_ops, pci1xxxx_i2c_suspend,
+			 pci1xxxx_i2c_resume);

Use new macro which starts with DEFINE prefix.

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1177

Quoted 3 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +3 -0
+	/*
+	 * We are getting the base address of the SMB core. SMB core uses
+	 * BAR0 and size is 32K

Missed period.

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 11

Quoted 3 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +2 -0
+	 */
 
+

Useless blank line.

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1188

Quoted 9 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +8 -0
+	ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
+	if (ret < 0)
+		return -ENOMEM;
 
+	i2c->i2c_base =	pcim_iomap_table(pdev)[0];
+
+	init_completion(&i2c->i2c_xfer_done);
+
+	pci1xxxx_i2c_init(i2c);

Here you need to wrap pci1xxxx_i2c_shutdown() to be devm_. See below.

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1197

Quoted 8 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +8 -0
+	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
+	if (ret < 0) {
+		pci1xxxx_i2c_shutdown(i2c);
+		return ret;
+	}
+
+	/* Register the isr. We are not using any isr flags here. */
+	ret = devm_request_irq(&pdev->dev, pci_irq_vector(pdev, 0),

With

	struct device *dev = &pdev->dev;

you may have some lines of code neater and shorter.

Quoted 11 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +11 -0
+			       pci1xxxx_i2c_isr, PCI1XXXX_IRQ_FLAGS,
+			       pci_name(pdev), i2c);
+	if (ret) {
+		pci1xxxx_i2c_shutdown(i2c);
+		return ret;
+	}
+
+	i2c->adap = pci1xxxx_i2c_ops;
+	i2c->adap.class = I2C_CLASS_SPD;
+	i2c->adap.dev.parent = &pdev->dev;
+

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1217

Quoted 10 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +9 -0
+	snprintf(i2c->adap.name, sizeof(i2c->adap.name),
+		 "MCHP PCI1xxxx i2c adapter at %s", pci_name(pdev));
+
+	i2c_set_adapdata(&i2c->adap, i2c);
+
+	ret = devm_i2c_add_adapter(&pdev->dev, &i2c->adap);
+	if (ret) {
+		dev_err(&pdev->dev, "i2c add adapter failed = %d\n", ret);
 
+		pci1xxxx_i2c_shutdown(i2c);

You can't mix devm_ and non-devm_ in such manner. It's asking for troubles at ->remove() or unbind stages.

Review

Quoted 1 line
(quoted diff) +1 -0
+		return ret;

After fixing above, convert the error messages to use

	return dev_err_probe(...);

pattern.

Quoted 1 line
(quoted diff) +1 -0
+	}

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1229

Quoted 6 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +6 -0
+static void pci1xxxx_i2c_remove_pci(struct pci_dev *pdev)
+{
+	struct pci1xxxx_i2c *i2c = pci_get_drvdata(pdev);
+
+	pci1xxxx_i2c_shutdown(i2c);
+}

This will be gone.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 8 lines · Andy Shevchenko

This kind of indentation harder to read than

#define SMB_IDLE_SCALING_100KHZ         \
        ((FAIR_IDLE_DELAY_100KHZ_TICKS << 16) |
FAIR_BUS_IDLE_MIN_100KHZ_TICKS)

Ditto for other similar cases.

Okay. I will update in all the places.

Quoted 5 lines

...

Quoted 1 line

+/*

If it's a kernel doc, make it kernel doc.

This need not be kernel doc. I will add comments within structure.

Quoted 9 lines
Quoted 2 lines

+ * struct pci1xxxx_i2c - private structure for the I2C controller
+ * @i2c_xfer_done: used for synchronisation between foreground & isr

...

Quoted 1 line

+static int set_sys_lock(void __iomem *addr)

Why not to take pointer to your private structure and offset instead of address
and calc the address here?

Okay

Quoted 5 lines

...

Quoted 1 line

+static int release_sys_lock(void __iomem *addr)

Ditto.

Okay

Quoted 8 lines

...

Quoted 4 lines

+             if (buf)
+                     memcpy_toio((i2c->i2c_base + SMBUS_MST_BUF), buf, transferlen);
+     }

Why do you need buf checks? Is your code can shoot itself in the foot?

Yes, buf will be passed as NULL in some cases. So, this check is required.

Quoted 7 lines
Quoted 2 lines

+}
             regval |= (I2C_INPUT_EN | I2C_OUTPUT_EN);

And in a plenty places you add extra parentheses. Reread your code and drop them and in some cases (I will show below an example) move code to shorter amount of LoCs.

Okay. I will take care of this.

Quoted 6 lines

...

Quoted 1 line

+             regval &=  ~(I2C_INPUT_EN | I2C_OUTPUT_EN);

Extra space.

Okay. I will remove extra spaces.

Quoted 7 lines

...

Quoted 2 lines

+     pci1xxxx_i2c_config_high_level_intr(i2c, (I2C_BUF_MSTR_INTR_MASK), +                                         true);

Why parentheses? Why it can't be one line?
There are more examples like this. Fix them all.

Okay

Quoted 6 lines

...

Quoted 3 lines

+                             pci1xxxx_i2c_set_readm(i2c, true);

+

We don't need useless blank lines.

Okay. I will take care of this.

Quoted 5 lines
Quoted 3 lines

+                     buf[0] = readb(i2c->i2c_base + +                                   SMBUS_MST_BUF);

Why not on one line?

Okay. I will update.

Quoted 6 lines
Quoted 3 lines

+                     memcpy_fromio(&buf[count], (i2c->i2c_base + +                                             SMBUS_MST_BUF), transferlen); +             }

These accessors may copy from 1 to 4 bytes at a time. Does your hardware supports this kind of accesses?

Yes, Hardware supports this kind of access.

Quoted 8 lines

...

Quoted 2 lines

+     while ((i2c->i2c_xfer_in_progress))
+             msleep(20);

Each long sleep (20 ms is quite long) has to be explained. But this entire loop
looks like a band-aid of lack of IRQ or so. Why do you need to poll?

This handling takes care of special case when system is put to suspend when i2c transfer is progress in driver. We will wait until transfer completes.

Quoted 4 lines
Quoted 2 lines

+     pci_wake_from_d3(pdev, FALSE);

What's FALSE and why false can't be used?

Okay, I will use false.

Quoted 5 lines

...

Quoted 2 lines

+static SIMPLE_DEV_PM_OPS(pci1xxxx_i2c_pm_ops, pci1xxxx_i2c_suspend, +                      pci1xxxx_i2c_resume);

Use new macro which starts with DEFINE prefix.

Okay

Quoted 3 lines

...
Missed period.

Okay. I will take care of this.

Quoted 5 lines
Quoted 3 lines

+      */

+

Useless blank line.

Okay, I will take care of this.

Quoted 9 lines
Quoted 3 lines

+
+     pci1xxxx_i2c_init(i2c);

Here you need to wrap pci1xxxx_i2c_shutdown() to be devm_. See below.

Quoted 3 lines

+     ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); +     if (ret < 0) {
+             pci1xxxx_i2c_shutdown(i2c);

I am not getting. Are you suggesting to change API name to devm_pci1xxxx_i2c_shutdown?

Quoted 5 lines

With

        struct device *dev = &pdev->dev;

you may have some lines of code neater and shorter.

Okay. I will take care in all places.

Quoted 9 lines
Quoted 6 lines

+
+     ret = devm_i2c_add_adapter(&pdev->dev, &i2c->adap);
+     if (ret) {
+             dev_err(&pdev->dev, "i2c add adapter failed = %d\n", ret);

+             pci1xxxx_i2c_shutdown(i2c);

You can't mix devm_ and non-devm_ in such manner. It's asking for troubles at ->remove() or unbind stages.

I am not getting this comment. Can you kindly explain more.

Quoted 8 lines
Quoted 1 line

+             return ret;

After fixing above, convert the error messages to use

        return dev_err_probe(...);

pattern.

Okay.

Quoted 10 lines

...

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1229

Quoted 6 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +6 -0
+static void pci1xxxx_i2c_remove_pci(struct pci_dev *pdev)
+{
+     struct pci1xxxx_i2c *i2c = pci_get_drvdata(pdev);
+
+     pci1xxxx_i2c_shutdown(i2c);
+}

This will be gone.

I am not getting this comment also.

Thanks,
Tharun Kumar P

#3 lore raw
Quoted 1 line · On Fri, Sep 02, 2022 at 11:31:11AM +0000, [email protected]…

On Thu, 2022-09-01 at 21:47 +0300, Andy Shevchenko wrote:

...

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

+             if (buf)
+                     memcpy_toio((i2c->i2c_base + SMBUS_MST_BUF), buf, transferlen);

Why do you need buf checks? Is your code can shoot itself in the foot?

Yes, buf will be passed as NULL in some cases. So, this check is required.

Can you show an excerpt of the caller which passes NULL?

...

Quoted 6 lines
Quoted 3 lines

Each long sleep (20 ms is quite long) has to be explained. But this entire loop
looks like a band-aid of lack of IRQ or so. Why do you need to poll?

This handling takes care of special case when system is put to suspend when i2c transfer is progress in driver. We will wait until transfer completes.

This should be at least a comment in the code.

...

Quoted 16 lines
Quoted 7 lines
Quoted 1 line

+     pci1xxxx_i2c_init(i2c);

Here you need to wrap pci1xxxx_i2c_shutdown() to be devm_. See below.

Quoted 3 lines

+     ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); +     if (ret < 0) {
+             pci1xxxx_i2c_shutdown(i2c);

I am not getting. Are you suggesting to change API name to devm_pci1xxxx_i2c_shutdown?

Quoted 5 lines
Quoted 4 lines

+
+     ret = devm_i2c_add_adapter(&pdev->dev, &i2c->adap);
+     if (ret) {
+             dev_err(&pdev->dev, "i2c add adapter failed = %d\n", ret);

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

+             pci1xxxx_i2c_shutdown(i2c);

You can't mix devm_ and non-devm_ in such manner. It's asking for troubles at ->remove() or unbind stages.

I am not getting this comment. Can you kindly explain more.

Quoted 1 line
Quoted 1 line

+             return ret;

Explanations [1] & [2]. Example how to workaround [3].

[1]: https://www.mail-archive.com/[email protected]/msg1949091.html
[2]: https://lore.kernel.org/all/[email protected]/
[3]: https://www.spinics.net/lists/kernel/msg4433985.html

...

Quoted 7 lines
Quoted 5 lines

After fixing above, convert the error messages to use

        return dev_err_probe(...);

pattern.

Okay.

Will be result of above fix.

...

Quoted 10 lines
Quoted 8 lines

drivers/i2c/busses/i2c-mchp-pci1xxxx.c line 1229

Quoted 6 lines
drivers/i2c/busses/i2c-mchp-pci1xxxx.c new file +6 -0
+static void pci1xxxx_i2c_remove_pci(struct pci_dev *pdev)
+{
+     struct pci1xxxx_i2c *i2c = pci_get_drvdata(pdev);
+
+     pci1xxxx_i2c_shutdown(i2c);
+}

This will be gone.

I am not getting this comment also.

See above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

+             if (buf)
+                     memcpy_toio((i2c->i2c_base + SMBUS_MST_BUF), buf, transferlen);

Why do you need buf checks? Is your code can shoot itself in the foot?

Yes, buf will be passed as NULL in some cases. So, this check is required.

Can you show an excerpt of the caller which passes NULL?

During I2C read, for writing just the client address without passing any other data, the buf pointer is set as NULL in pci1xxxx_i2c_buffer_write API in the "pci1xxxx_i2c_read" function

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

Each long sleep (20 ms is quite long) has to be explained. But this entire loop
looks like a band-aid of lack of IRQ or so. Why do you need to poll?

This handling takes care of special case when system is put to suspend when i2c
transfer is progress in driver. We will wait until transfer completes.

This should be at least a comment in the code.

Okay, I will add comment.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

You can't mix devm_ and non-devm_ in such manner. It's asking for troubles at
->remove() or unbind stages.

I am not getting this comment. Can you kindly explain more.

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

+             return ret;

Explanations [1] & [2]. Example how to workaround [3].

[1]: https://www.mail-archive.com/[email protected]/msg1949091.html
[2]: https://lore.kernel.org/all/[email protected]/
[3]: https://www.spinics.net/lists/kernel/msg4433985.html

Okay. I will update code as per this logic in the upcoming version of the patch.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

After fixing above, convert the error messages to use

        return dev_err_probe(...);

pattern.

Okay.

Will be result of above fix.

Okay

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This will be gone.

I am not getting this comment also.

See above.

Okay

Thanks,
Tharun Kumar P