Skip to contentSkip to conversation

i2c: Add PCI and platform drivers for the AMD MP2 I2C controller

PATCH Superseded Elie Morisse 1 participant 1 message Oct 26, 2018 I2C subsystem host drivers

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 i2c: Add PCI and platform drivers for the AMD MP2 I2C controller

This contains two drivers:
* i2c-amd-plat-mp2: platform driver managing an i2c adapter (one of
the two busses of the MP2) and routing any i2c read/write command to the PCI driver.
* i2c-amd-pci-mp2: PCI driver communicating through the C2P/P2C
mailbox registers, or through DMA for more than 32 bytes transfers.

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 v2/v3 was rewritten since it couldn't work if more than one bus was enabled, and contains many more fixes listed in the patch changelog.

With those changes both the touchpad and the touchscreen of the Ryzen-based Lenovo Yoga 530 which lie in separate busses work beautifully.

---
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 (https://marc.info/?l=linux-kernel&m=154031133019835) 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 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)

 MAINTAINERS                           |   6 +
 drivers/i2c/busses/Kconfig            |  15 +
 drivers/i2c/busses/Makefile           |   2 +
 drivers/i2c/busses/i2c-amd-pci-mp2.c  | 705 ++++++++++++++++++++++++++
 drivers/i2c/busses/i2c-amd-pci-mp2.h  | 224 ++++++++
 drivers/i2c/busses/i2c-amd-plat-mp2.c | 384 ++++++++++++++
 6 files changed, 1336 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-amd-pci-mp2.c
 create mode 100644 drivers/i2c/busses/i2c-amd-pci-mp2.h
 create mode 100644 drivers/i2c/busses/i2c-amd-plat-mp2.c
MAINTAINERS +6 -0
index 6ac000cc006d..8ff2bddc1ac2 100644
@@ -791,6 +791,12 @@ 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]>
+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 +15 -0
index 451d4ae50e66..e20f2d1ce381 100644
@@ -77,6 +77,21 @@ 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
+	depends on PCI
+
+config I2C_AMD_MP2_PLATFORM
+	tristate "AMD MP2 Platform"
+	select I2C_AMD_MP2_PCI
+	depends on ACPI
+	help
+	  If you say yes to this option, support will be included for the AMD MP2
+	  PCI I2C adapter.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-amd-plat-mp2.
+
 config I2C_HIX5HD2
 	tristate "Hix5hd2 high-speed I2C driver"
 	depends on ARCH_HISI || ARCH_HIX5HD2 || COMPILE_TEST
drivers/i2c/busses/Makefile +2 -0
index 18b26af82b1c..16ef646d7ef5 100644
@@ -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-pci-mp2.o
+obj-$(CONFIG_I2C_AMD_MP2_PLATFORM)	+= i2c-amd-plat-mp2.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-pci-mp2.c new file +705 -0

705 lines not on this page · raw message

drivers/i2c/busses/i2c-amd-pci-mp2.h new file +224 -0

224 lines not on this page · raw message

drivers/i2c/busses/i2c-amd-plat-mp2.c new file +384 -0

384 lines not on this page · raw message

Signature · 1 line
2.17.1