Skip to contentSkip to conversation

i2c: add support for microchip fpga i2c controllers

PATCH Superseded Conor Dooley 2 participants 8 messages Jun 21, 2022 – Jul 6, 2022

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/2 i2c: add support for microchip fpga i2c controllers

Add Microchip CoreI2C i2c controller support. This driver supports the "hard" i2c controller on the Microchip PolarFire SoC & the basic feature set for "soft" i2c controller implemtations in the FPGA fabric.

---
Changes from v5:
- add zero to the invalid irq check

Changes from v4:
- reset the controller on xfer timeout
- sort the headers alphabetically

Changes from v3:
- update members in struct doc comment
- move mchp_corei2c_transfer in its caller
- change msg_len to a u16
- remove unused variable msg_read
- use adapater.timeout for completion
- dont use last_byte goto
- remove block on zero length messages
(the hardware can do them, was a carryover from the baremetal driver)
- probe:
- drop unneeded initialisation
- use ret not val
- explain shared irq
- disallow 0 bus_clock_rate
- include base in device name
- dropped the duplicate "microchip" in the registered print (its in driver.name)

Changes from v2:
- Fixed whitespace in defines that I removed accidentally

Changes from v1:
- Use byte write and read functions
- Return IRQ_NONE and don't warn if not this drivers interrupt
- Add a clk_disable_unprepare to avoid leaking a clock in the probe

---
 drivers/i2c/busses/Kconfig              |  11 +
 drivers/i2c/busses/Makefile             |   1 +
 drivers/i2c/busses/i2c-microchip-core.c | 486 ++++++++++++++++++++++++
 3 files changed, 498 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-microchip-core.c
drivers/i2c/busses/Kconfig +11 -0
index a1bae59208e3..3d4d8e0e9de7 100644
@@ -781,6 +781,17 @@ config I2C_MESON
 	  If you say yes to this option, support will be included for the
 	  I2C interface on the Amlogic Meson family of SoCs.
 
+config I2C_MICROCHIP_CORE
+	tristate "Microchip FPGA I2C controller"
+	depends on SOC_MICROCHIP_POLARFIRE || COMPILE_TEST
+	depends on OF
+	help
+	  If you say yes to this option, support will be included for the
+	  I2C interface on Microchip FPGAs.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called i2c-microchip-core.
+
 config I2C_MPC
 	tristate "MPC107/824x/85xx/512x/52xx/83xx/86xx"
 	depends on PPC
drivers/i2c/busses/Makefile +1 -0
index 479f60e4ee3d..75869b189e43 100644
@@ -78,6 +78,7 @@ obj-$(CONFIG_I2C_JZ4780)	+= i2c-jz4780.o
 obj-$(CONFIG_I2C_KEMPLD)	+= i2c-kempld.o
 obj-$(CONFIG_I2C_LPC2K)		+= i2c-lpc2k.o
 obj-$(CONFIG_I2C_MESON)		+= i2c-meson.o
+obj-$(CONFIG_I2C_MICROCHIP_CORE)	+= i2c-microchip-core.o
 obj-$(CONFIG_I2C_MPC)		+= i2c-mpc.o
 obj-$(CONFIG_I2C_MT65XX)	+= i2c-mt65xx.o
 obj-$(CONFIG_I2C_MT7621)	+= i2c-mt7621.o
drivers/i2c/busses/i2c-microchip-core.c new file +486 -0

486 lines not on this page · raw message

base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56

Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

PATCH v6 2/2 MAINTAINERS: add the polarfire soc's i2c driver

Add the newly added i2c controller driver to the existing entry for PolarFire SoC.

---
New in v6.
FYI: I have several maintainers updates in flight - usb, pwm, spi of which some will be in 5.20 & clk/hwrng/pci that are likely to go into 5.19-rcN.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index a6d3bd9d2a8d..90de65041863 100644
@@ -17141,6 +17141,7 @@ M:	Conor Dooley <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	arch/riscv/boot/dts/microchip/
+F:	drivers/i2c/busses/i2c-microchip-core.c
 F:	drivers/mailbox/mailbox-mpfs.c
 F:	drivers/soc/microchip/
 F:	include/soc/microchip/mpfs.h
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Acked-by on v6 2/2
#2 lore raw

Re: [PATCH v6 2/2] MAINTAINERS: add the polarfire soc's i2c driver

Quoted 9 lines · Conor Dooley

Add the newly added i2c controller driver to the existing entry for PolarFire SoC.

---
New in v6.
FYI: I have several maintainers updates in flight - usb, pwm, spi of which some will be in 5.20 & clk/hwrng/pci that are likely to go into 5.19-rcN.

Then, I'd suggest you collect all of them and send them as one patch at the end of the next merge window?

For that case:

#3 lore raw

Re: [PATCH v6 2/2] MAINTAINERS: add the polarfire soc's i2c driver

Quoted 13 lines · Wolfram Sang

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines · Conor Dooley

Add the newly added i2c controller driver to the existing entry for PolarFire SoC.

---
New in v6.
FYI: I have several maintainers updates in flight - usb, pwm, spi of which some will be in 5.20 & clk/hwrng/pci that are likely to go into 5.19-rcN.

Quoted 2 lines

Then, I'd suggest you collect all of them and send them as one patch at the end of the next merge window?

Hmm, couple of them have actually already gone in. I doubt the pwm will make it but the others have. If this driver is cleaned up in time for 5.20, I'll rebase this patch after the first week of the mw & resubmit with your Ack.
Thanks.

Quoted 10 lines

For that case:

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw
In reply to Conor Dooley

Hi Conor,

thank you for sending this driver.

Quoted 7 lines · Conor Dooley

Add Microchip CoreI2C i2c controller support. This driver supports the "hard" i2c controller on the Microchip PolarFire SoC & the basic feature set for "soft" i2c controller implemtations in the FPGA fabric.

Where are the bindings? Are they already on the way upstream?

Quoted 1 line
 drivers/i2c/busses/i2c-microchip-core.c | 486 ++++++++++++++++++++++++

The biggest remark I have is to rename the driver a little. Usually a "-core" suffix means that there are other drivers like "-platform" or "-pci" use this core. Would "i2c-microchip-fpga" or "i2c-microchip-corei2c" work for you?

drivers/i2c/busses/i2c-microchip-core.c line 14

Quoted 5 lines
drivers/i2c/busses/i2c-microchip-core.c new file +5 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/iopoll.h>

Do you really need that?

...

Quoted 8 lines
drivers/i2c/busses/i2c-microchip-core.c new file +8 -0
+static irqreturn_t mchp_corei2c_handle_isr(struct mchp_corei2c_dev *idev)
+{
+	u32 status = idev->isr_status;
+	u8 ctrl;
+	bool last_byte = false, finished = false;
+
+	if (!idev->buf)
+		return IRQ_NONE;

drivers/i2c/busses/i2c-microchip-core.c line 247

Quoted 10 lines
drivers/i2c/busses/i2c-microchip-core.c new file +10 -0
+
+	switch (status) {
+	case STATUS_M_START_SENT:
+	case STATUS_M_REPEATED_START_SENT:
+		ctrl = readb(idev->base + CORE_I2C_CTRL);
+		ctrl &= ~CTRL_STA;
+		writeb(idev->addr, idev->base + CORE_I2C_DATA);
+		writeb(ctrl, idev->base + CORE_I2C_CTRL);
+		if (idev->msg_len <= 0)
+			finished = true;

How can it happen that len is < 0? Wouldn't that be an error case?

...

drivers/i2c/busses/i2c-microchip-core.c line 363

Quoted 3 lines
drivers/i2c/busses/i2c-microchip-core.c new file +3 -0
+static u32 mchp_corei2c_func(struct i2c_adapter *adap)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;

Have you testes SMBUS_QUICK as well?

...

drivers/i2c/busses/i2c-microchip-core.c line 397

Quoted 3 lines
drivers/i2c/busses/i2c-microchip-core.c new file +3 -0
+	idev->dev = &pdev->dev;
+	init_completion(&idev->msg_complete);
+	spin_lock_init(&idev->lock);

You never use this lock.

...

drivers/i2c/busses/i2c-microchip-core.c line 440

Quoted 5 lines
drivers/i2c/busses/i2c-microchip-core.c new file +5 -0
+	idev->adapter.owner = THIS_MODULE;
+	idev->adapter.algo = &mchp_corei2c_algo;
+	idev->adapter.dev.parent = &pdev->dev;
+	idev->adapter.dev.of_node = pdev->dev.of_node;
+	idev->adapter.timeout = MICROCHIP_I2C_TIMEOUT;

Simply use HZ here?

All in all, only minor stuff. Driver looks really good in general.

Thanks and happy hacking,

Wolfram

#5 lore raw
Quoted 13 lines · Wolfram Sang

Hi Conor,

thank you for sending this driver.

Quoted 7 lines · Conor Dooley

Add Microchip CoreI2C i2c controller support. This driver supports the "hard" i2c controller on the Microchip PolarFire SoC & the basic feature set for "soft" i2c controller implemtations in the FPGA fabric.

Quoted 8 lines

Where are the bindings? Are they already on the way upstream?

Quoted 1 line
  drivers/i2c/busses/i2c-microchip-core.c | 486 ++++++++++++++++++++++++

The biggest remark I have is to rename the driver a little. Usually a "-core" suffix means that there are other drivers like "-platform" or "-pci" use this core. Would "i2c-microchip-fpga" or "i2c-microchip-corei2c" work for you?

I'd prefer the latter. Being called "core" is unfortunate and I did think about that. i2c-microchip-corei2c would have been my first choice but I thought the double usage of i2c would've been disapproved of haha

Quoted 8 lines

drivers/i2c/busses/i2c-microchip-core.c line 14

Quoted 6 lines
drivers/i2c/busses/i2c-microchip-core.c new file +5 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/iopoll.h>

Do you really need that?

Nope!

Quoted 24 lines

...

Quoted 8 lines
drivers/i2c/busses/i2c-microchip-core.c new file +8 -0
+static irqreturn_t mchp_corei2c_handle_isr(struct mchp_corei2c_dev *idev)
+{
+	u32 status = idev->isr_status;
+	u8 ctrl;
+	bool last_byte = false, finished = false;
+
+	if (!idev->buf)
+		return IRQ_NONE;

drivers/i2c/busses/i2c-microchip-core.c line 247

Quoted 10 lines
drivers/i2c/busses/i2c-microchip-core.c new file +10 -0
+
+	switch (status) {
+	case STATUS_M_START_SENT:
+	case STATUS_M_REPEATED_START_SENT:
+		ctrl = readb(idev->base + CORE_I2C_CTRL);
+		ctrl &= ~CTRL_STA;
+		writeb(idev->addr, idev->base + CORE_I2C_DATA);
+		writeb(ctrl, idev->base + CORE_I2C_CTRL);
+		if (idev->msg_len <= 0)
+			finished = true;

How can it happen that len is < 0? Wouldn't that be an error case?

Quoted 7 lines

...

drivers/i2c/busses/i2c-microchip-core.c line 363

Quoted 3 lines
drivers/i2c/busses/i2c-microchip-core.c new file +3 -0
+static u32 mchp_corei2c_func(struct i2c_adapter *adap)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;

Have you testes SMBUS_QUICK as well?

Not specifically SMBUS_QUICK, but I did test with hardware that uses "zero-length" messages.

Quoted 8 lines

...

drivers/i2c/busses/i2c-microchip-core.c line 397

Quoted 3 lines
drivers/i2c/busses/i2c-microchip-core.c new file +3 -0
+	idev->dev = &pdev->dev;
+	init_completion(&idev->msg_complete);
+	spin_lock_init(&idev->lock);

You never use this lock.

And nor did we in any prior version (pre-list).
I am just going to remove it.

Quoted 10 lines

...

drivers/i2c/busses/i2c-microchip-core.c line 440

Quoted 5 lines
drivers/i2c/busses/i2c-microchip-core.c new file +5 -0
+	idev->adapter.owner = THIS_MODULE;
+	idev->adapter.algo = &mchp_corei2c_algo;
+	idev->adapter.dev.parent = &pdev->dev;
+	idev->adapter.dev.of_node = pdev->dev.of_node;
+	idev->adapter.timeout = MICROCHIP_I2C_TIMEOUT;

Simply use HZ here?

Sure.

Thanks for the review :)

#6 lore raw
Quoted 5 lines

I'd prefer the latter. Being called "core" is unfortunate and I did think about that. i2c-microchip-corei2c would have been my first choice but I thought the double usage of i2c would've been disapproved of haha

:) Well, double "i2c" is not exactly pretty but since it is the name of that IP core...

Quoted 4 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (idev->msg_len <= 0)
+			finished = true;

How can it happen that len is < 0? Wouldn't that be an error case?

Is it to be on the safe side?

Quoted 4 lines
Quoted 1 line

Have you testes SMBUS_QUICK as well?

Not specifically SMBUS_QUICK, but I did test with hardware that uses "zero-length" messages.

Good!

Quoted 1 line

Thanks for the review :)

You are welcome.

#7 lore raw
Quoted 1 line · Wolfram Sang

Where are the bindings? Are they already on the way upstream?

Already upstream. Documentation/devicetree/bindings/i2c/microchip,corei2c.yaml

Quoted 8 lines
Quoted 5 lines

I'd prefer the latter. Being called "core" is unfortunate and I did think about that. i2c-microchip-corei2c would have been my first choice but I thought the double usage of i2c would've been disapproved of haha

:) Well, double "i2c" is not exactly pretty but since it is the name of that IP core...

Yeah, and it is the name of /all/ the IP cores we have (:

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+		if (idev->msg_len <= 0)
+			finished = true;

How can it happen that len is < 0? Wouldn't that be an error case?

Is it to be on the safe side?

Ahh sorry, I missed that. msg_len is a u16 so cannot be <0 I'll change it.

Quoted 12 lines
Quoted 5 lines
Quoted 2 lines

Have you testes SMBUS_QUICK as well?

Not specifically SMBUS_QUICK, but I did test with hardware that uses "zero-length" messages.

Good!

Quoted 1 line

Thanks for the review :)

You are welcome.