Skip to contentSkip to conversation

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

PATCH Superseded Elie Morisse 2 participants 2 messages Oct 23, 2018 – Oct 24, 2018 I2C subsystem host drivers

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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 call or 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

 MAINTAINERS                           |   6 +
 drivers/i2c/busses/Kconfig            |  25 +
 drivers/i2c/busses/Makefile           |   2 +
 drivers/i2c/busses/i2c-amd-pci-mp2.c  | 633 ++++++++++++++++++++++++++
 drivers/i2c/busses/i2c-amd-pci-mp2.h  | 219 +++++++++
 drivers/i2c/busses/i2c-amd-plat-mp2.c | 362 +++++++++++++++
 6 files changed, 1247 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 +25 -0
index 451d4ae50e66..c35a51fa01c5 100644
@@ -77,6 +77,31 @@ config I2C_AMD8111
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-amd8111.
 
+config I2C_AMD8111
+	tristate "AMD 8111"
+	depends on PCI
+	help
+	  If you say yes to this option, support will be included for the
+	  second (SMBus 2.0) AMD 8111 mainboard I2C interface.
+
+	  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 +633 -0

633 lines not on this page · raw message

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

219 lines not on this page · raw message

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

362 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
I love your patch! Perhaps something to improve:

Hi Elie,

I love your patch! Perhaps something to improve:

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on v4.19 next-20181019]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Elie-Morisse/i2c-Add-PCI-and-platform-drivers-for-the-AMD-MP2-I2C-controller/20181024-013625
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

drivers/i2c/busses/i2c-amd-pci-mp2.c: In function 'amd_mp2_debugfs_read':

>> drivers/i2c/busses/i2c-amd-pci-mp2.c:298:66: warning: comparison of distinct pointer types lacks a cast
     buf_size = min(count, 0x800ul);
                                                                     ^ 

vim +298 drivers/i2c/busses/i2c-amd-pci-mp2.c

285
286 static ssize_t amd_mp2_debugfs_read(struct file *filp, char __user *ubuf,
287 size_t count, loff_t *offp)
288 {
289 struct amd_mp2_dev *privdata;
290 void __iomem *mmio;
291 u8 *buf;
292 size_t buf_size;
293 ssize_t ret, off;
294 u32 v32;
295
296 privdata = filp->private_data;
297 mmio = privdata->mmio;

 > 298		buf_size = min(count, 0x800ul);

299 buf = kmalloc(buf_size, GFP_KERNEL);
300
301 if (!buf)
302 return -ENOMEM;
303
304 off = 0;
305 off += scnprintf(buf + off, buf_size - off,
306 "Mp2 Device Information:\n");
307
308 off += scnprintf(buf + off, buf_size - off,
309 "========================\n");
310 off += scnprintf(buf + off, buf_size - off,
311 "\tMP2 C2P Message Register Dump:\n\n");
312 v32 = readl(privdata->mmio + AMD_C2P_MSG0);
313 off += scnprintf(buf + off, buf_size - off,
314 "AMD_C2P_MSG0 -\t\t\t%#06x\n", v32);
315
316 v32 = readl(privdata->mmio + AMD_C2P_MSG1);
317 off += scnprintf(buf + off, buf_size - off,
318 "AMD_C2P_MSG1 -\t\t\t%#06x\n", v32);
319
320 v32 = readl(privdata->mmio + AMD_C2P_MSG2);
321 off += scnprintf(buf + off, buf_size - off,
322 "AMD_C2P_MSG2 -\t\t\t%#06x\n", v32);
323
324 v32 = readl(privdata->mmio + AMD_C2P_MSG3);
325 off += scnprintf(buf + off, buf_size - off,
326 "AMD_C2P_MSG3 -\t\t\t%#06x\n", v32);
327
328 v32 = readl(privdata->mmio + AMD_C2P_MSG4);
329 off += scnprintf(buf + off, buf_size - off,
330 "AMD_C2P_MSG4 -\t\t\t%#06x\n", v32);
331
332 v32 = readl(privdata->mmio + AMD_C2P_MSG5);
333 off += scnprintf(buf + off, buf_size - off,
334 "AMD_C2P_MSG5 -\t\t\t%#06x\n", v32);
335
336 v32 = readl(privdata->mmio + AMD_C2P_MSG6);
337 off += scnprintf(buf + off, buf_size - off,
338 "AMD_C2P_MSG6 -\t\t\t%#06x\n", v32);
339
340 v32 = readl(privdata->mmio + AMD_C2P_MSG7);
341 off += scnprintf(buf + off, buf_size - off,
342 "AMD_C2P_MSG7 -\t\t\t%#06x\n", v32);
343
344 v32 = readl(privdata->mmio + AMD_C2P_MSG8);
345 off += scnprintf(buf + off, buf_size - off,
346 "AMD_C2P_MSG8 -\t\t\t%#06x\n", v32);
347
348 v32 = readl(privdata->mmio + AMD_C2P_MSG9);
349 off += scnprintf(buf + off, buf_size - off,
350 "AMD_C2P_MSG9 -\t\t\t%#06x\n", v32);
351
352 off += scnprintf(buf + off, buf_size - off,
353 "\n\tMP2 P2C Message Register Dump:\n\n");
354
355 v32 = readl(privdata->mmio + AMD_P2C_MSG1);
356 off += scnprintf(buf + off, buf_size - off,
357 "AMD_P2C_MSG1 -\t\t\t%#06x\n", v32);
358
359 v32 = readl(privdata->mmio + AMD_P2C_MSG2);
360 off += scnprintf(buf + off, buf_size - off,
361 "AMD_P2C_MSG2 -\t\t\t%#06x\n", v32);
362
363 v32 = readl(privdata->mmio + AMD_P2C_MSG_INTEN);
364 off += scnprintf(buf + off, buf_size - off,
365 "AMD_P2C_MSG_INTEN -\t\t%#06x\n", v32);
366
367 v32 = readl(privdata->mmio + AMD_P2C_MSG_INTSTS);
368 off += scnprintf(buf + off, buf_size - off,
369 "AMD_P2C_MSG_INTSTS -\t\t%#06x\n", v32);
370
371 ret = simple_read_from_buffer(ubuf, count, offp, buf, off);
372 kfree(buf);
373 return ret;
374 }
375

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation