i2c: add support for microchip fpga i2c controllers
Subsystems (2)
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
@@ -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
@@ -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
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
@@ -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
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.
Signed-off-by Conor Dooley <[email protected]>---
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:
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.
Signed-off-by Conor Dooley <[email protected]>---
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:
Acked-by Wolfram Sang <[email protected]>_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
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.
Co-developed-by Daire McNamara <[email protected]>Signed-off-by Daire McNamara <[email protected]>Signed-off-by Conor Dooley <[email protected]>
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
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.
Co-developed-by Daire McNamara <[email protected]>Signed-off-by Daire McNamara <[email protected]>Signed-off-by Conor Dooley <[email protected]>
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_QUICKas 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 :)
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_QUICKas 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.
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_QUICKas 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.