i2c: Add drivers for the AMD PCIe MP2 I2C controller
Subsystems (2)
Elie Morisse
maintainerPATCH v9 1/1 i2c: Add drivers for the AMD PCIe MP2 I2C controller
I2C communication takes place through iomapped registers, or through DMA for more than 32 bytes transfers.
MP2 controllers have two separate buses, so may accommodate up to two I2C adapters. Those adapters are listed in the ACPI namespace with the "AMDI0011" HID, and probed by a platform driver.
This is major rework of the patch submitted by Nehal-bakulchandra Shah from AMD (https://patchwork.kernel.org/patch/10597369/).
Most of the event handling of v3 was rewritten to make it work with more than one bus (e.g on Ryzen-based Lenovo Yoga 530), and this version contains many more improvements.
---
Changes since v1:(https://www.spinics.net/lists/linux-i2c/msg34650.html) -> Add fix for IOMMU
-> Add depedency of ACPI
-> Add locks to avoid the crash
Changes since v2:(https://patchwork.ozlabs.org/patch/961270/)
-> fix for review comments
-> fix for more than 32 bytes write issue
Changes since v3 (https://patchwork.kernel.org/patch/10597369/) by Elie M.:
-> support more than one bus/adapter
-> support more than one slave per bus
-> use the bus speed specified by the slaves declared in the DSDT instead of
assuming speed == 400kbits/s
-> instead of kzalloc'ing a buffer for every less than 32 bytes reads, simply
use i2c_msg.buf
-> fix buffer overreads/overflows when (<=32 bytes) message lengths aren't a
multiple of 4 by using memcpy_fromio and memcpy_toio
-> use streaming DMA mappings instead of allocating a coherent DMA buffer for
every >32 bytes read/write
-> properly check for timeouts during i2c_amd_xfer and increase it from 50
jiffies to 250 msecs (which is more in line with other drivers)
-> complete amd_i2c_dev.msg even if the device doesn't return a xxx_success
event, instead of stalling i2c_amd_xfer
-> removed the spinlock and mdelay during i2c_amd_pci_configure, I didn't see
the point since it's already waiting for a i2c_busenable_complete event
-> add an adapter-specific mutex lock for i2c_amd_xfer, since we don't want
parallel calls writing to AMD_C2P_MSG0 (or AMD_C2P_MSG1)
-> add a global mutex lock for registers AMD_C2P_MSG2 to AMD_C2P_MSG9, which
are shared across the two busses/adapters
-> add MODULE_DEVICE_TABLE to automatically load i2c-amd-platdrv if the DSDT
enumerates devices with the "AMDI0011" HID
-> set maximum length of reads/writes to 4095 (event's length field is 12 bits) -> basic PM support
-> style corrections to match the kernel code style, and tried to reduce code
duplication whenever possible
Changes since v4 by Elie M.:
-> fix missing typecast warning
-> removed the duplicated entry in Kconfig
Changes since v5 by Elie M.:
-> move DMA mapping from the platform driver to the PCI driver
-> attempt to find the platform device's PCI parent through the _DEP ACPI method
(if not found take the first MP2 device registred in the i2c-amd-pci-mp2 driver, like before)
-> do not assume anymore that the PCI device is owned by the i2c-amd-pci-mp2
driver
-> address other review comments by Bjorn Helgaas (meant for v3)
Changes since v6 by Elie M.:
-> remove unnecessary memcpy from the DMA buffer during i2c_amd_read_completion
Changes since v7 by Elie M.:
-> merge the two modules into one named i2c-amd-mp2, delete now useless exports -> unlock the C2P mutex if i2c_amd_xfer_msg timeouts, to prevent stalling the
MP2 controller if a slave doesn't respond to a read or write request
-> unmap the DMA buffer before read/write_complete
-> fix bus_disable commands handling (no more errors during module exit) -> prefer managed versions of pci_ and dev_ functions whenever possible -> increase adapter retries from 0 to 3
-> reduce code duplication in debugfs functions
-> address other review points by Bjorn Helgaas (except regarding the _DEP
hint)
Changes since v8 by Elie M.:
-> remove mostly redundant amd_i2c_rw_config, refer to i2c_msg whenever possible
-> use i2c_get_dma_safe_msg_buf and i2c_put_dma_safe_msg_buf
-> defer probe() by the platform driver if no MP2 device has been probed yet by the PCI driver (which should address Bjorn Helgaas' concern while preserving the platform driver)
-> if the interrupt following a command doesn't get handled after 250ms, zero AMD_P2C_MSG_INTEN to prevent the MP2 from stalling for a few more seconds (there seems to be an interrupt issue with older Zen microcodes, upgrade your amd microcode package if you experience timeouts) -> include AMD_P2C_MSG3 and fix typo in debugfs output
-> cosmetic fixes, code reduction, and better comments
-> add Nehal Shah and Shyam Sundar S K from AMD to the list of maintainers
MAINTAINERS | 8 + drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 2 + drivers/i2c/busses/i2c-amd-mp2-pci.c | 671 ++++++++++++++++++++++++++ drivers/i2c/busses/i2c-amd-mp2-plat.c | 332 +++++++++++++ drivers/i2c/busses/i2c-amd-mp2.h | 212 ++++++++ 6 files changed, 1235 insertions(+) create mode 100644 drivers/i2c/busses/i2c-amd-mp2-pci.c create mode 100644 drivers/i2c/busses/i2c-amd-mp2-plat.c create mode 100644 drivers/i2c/busses/i2c-amd-mp2.h
MAINTAINERS +8 -0
@@ -791,6 +791,14 @@ F: drivers/gpu/drm/amd/include/vi_structs.h F: drivers/gpu/drm/amd/include/v9_structs.h F: include/uapi/linux/kfd_ioctl.h +AMD MP2 I2C DRIVER +M: Elie Morisse <[email protected]> +M: Nehal Shah <[email protected]> +M: Shyam Sundar S K <[email protected]> +L: [email protected] +S: Maintained +F: drivers/i2c/busses/i2c-amd-mp2* + AMD POWERPLAY M: Rex Zhu <[email protected]> M: Evan Quan <[email protected]>
drivers/i2c/busses/Kconfig +10 -0
@@ -77,6 +77,16 @@ config I2C_AMD8111 This driver can also be built as a module. If so, the module will be called i2c-amd8111. +config I2C_AMD_MP2_PCI + tristate "AMD MP2 PCIe I2C adapter" + depends on PCI && ACPI + help + If you say yes to this option, support will be included for the AMD + MP2 PCIe I2C adapter. + + This driver can also be built as a module. If so, the module + will be called i2c-amd-mp2. + config I2C_HIX5HD2 tristate "Hix5hd2 high-speed I2C driver" depends on ARCH_HISI || ARCH_HIX5HD2 || COMPILE_TEST
drivers/i2c/busses/Makefile +2 -0
@@ -32,6 +32,8 @@ obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o # Embedded system I2C/SMBus host controller drivers obj-$(CONFIG_I2C_ALTERA) += i2c-altera.o +obj-$(CONFIG_I2C_AMD_MP2_PCI) += i2c-amd-mp2.o +i2c-amd-mp2-objs := i2c-amd-mp2-pci.o i2c-amd-mp2-plat.o obj-$(CONFIG_I2C_ASPEED) += i2c-aspeed.o obj-$(CONFIG_I2C_AT91) += i2c-at91.o obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
drivers/i2c/busses/i2c-amd-mp2-pci.c new file +671 -0
671 lines not on this page · raw message
drivers/i2c/busses/i2c-amd-mp2-plat.c new file +332 -0
332 lines not on this page · raw message
drivers/i2c/busses/i2c-amd-mp2.h new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.17.1