Syniurge / i2c-amd-mp2

DKMS-ready driver for AMD PCI-E MP2 I2C controllers
22 stars 4 forks source link

modprobing i2c_amd_mp2 does nothing #11

Closed Gooberpatrol66 closed 5 years ago

Gooberpatrol66 commented 5 years ago
root@gentoolaptop / # lsmod | grep i2c
synaptics_i2c          16384  0
i2c_amd_mp2            20480  0
i2c_algo_bit           16384  1 amdgpu
i2c_piix4              24576  0
i2c_hid                20480  0
hid                   106496  3 i2c_hid,usbhid,hid_generic
i2c_core               53248  8 i2c_hid,drm_kms_helper,i2c_amd_mp2,synaptics_i2c,i2c_algo_bit,amdgpu,i2c_piix4,drm

I'm using a Synaptics TM3336-002 touchpad. How do I get it to work with this driver?

Syniurge commented 5 years ago

Could you post the output of lspci, cat /proc/bus/input/devices and ls /sys/bus/acpi/devices/?

Gooberpatrol66 commented 5 years ago
root@gentoolaptop /home/nathan/Downloads/i2c-amd-mp2 # lspci
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15d0
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Device 15d1
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge
00:01.6 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 15d3
00:01.7 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 15d3
00:08.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge
00:08.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 15db
00:08.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 15dc
00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller (rev 61)
00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge (rev 51)
00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15e8
00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15e9
00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15ea
00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15eb
00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15ec
00:18.5 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15ed
00:18.6 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15ee
00:18.7 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 15ef
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15)
02:00.0 Network controller: Qualcomm Atheros QCA9377 802.11ac Wireless Network Adapter (rev 31)
03:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Raven Ridge [Radeon Vega Series / Radeon Vega Mobile Series] (rev c5)
03:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Device 15de
03:00.2 Encryption controller: Advanced Micro Devices, Inc. [AMD] Device 15df
03:00.3 USB controller: Advanced Micro Devices, Inc. [AMD] Device 15e0
03:00.4 USB controller: Advanced Micro Devices, Inc. [AMD] Device 15e1
03:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Device 15e3
04:00.0 SATA controller: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] (rev 61)
root@gentoolaptop /home/nathan/Downloads/i2c-amd-mp2 # cat /proc/bus/input/devices
I: Bus=0003 Vendor=093a Product=2510 Version=0111
N: Name="PIXART USB OPTICAL MOUSE"
P: Phys=usb-0000:03:00.3-3/input0
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.3/usb1/1-3/1-3:1.0/0003:093A:2510.0001/input/input0
U: Uniq=
H: Handlers=mouse0 event0 
B: PROP=0
B: EV=17
B: KEY=70000 0 0 0 0
B: REL=103
B: MSC=10

I: Bus=0019 Vendor=0000 Product=0005 Version=0000
N: Name="Lid Switch"
P: Phys=PNP0C0D/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input1
U: Uniq=
H: Handlers=event1 
B: PROP=0
B: EV=21
B: SW=1

I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=PNP0C0C/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2
U: Uniq=
H: Handlers=kbd event2 
B: PROP=0
B: EV=3
B: KEY=10000000000000 0

I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=LNXPWRBN/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3
U: Uniq=
H: Handlers=kbd event3 
B: PROP=0
B: EV=3
B: KEY=10000000000000 0

I: Bus=0019 Vendor=0000 Product=0006 Version=0000
N: Name="Video Bus"
P: Phys=LNXVIDEO/video/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:0b/LNXVIDEO:02/input/input4
U: Uniq=
H: Handlers=kbd event4 
B: PROP=0
B: EV=3
B: KEY=3e000b00000000 0 0 0

I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="Ideapad extra buttons"
P: Phys=ideapad/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.3/PNP0C09:00/VPC2004:00/input/input5
U: Uniq=
H: Handlers=kbd rfkill event5 
B: PROP=0
B: EV=13
B: KEY=81000800100c03 4400000000300000 0 2
B: MSC=10

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="HD-Audio Generic HDMI/DP,pcm=3"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.1/sound/card1/input6
U: Uniq=
H: Handlers=event6 
B: PROP=0
B: EV=21
B: SW=140

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="HD-Audio Generic Mic"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.6/sound/card0/input7
U: Uniq=
H: Handlers=event7 
B: PROP=0
B: EV=21
B: SW=10

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="HD-Audio Generic Headphone"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:03:00.6/sound/card0/input8
U: Uniq=
H: Handlers=event8 
B: PROP=0
B: EV=21
B: SW=4

I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input9
U: Uniq=
H: Handlers=sysrq kbd event9 leds 
B: PROP=0
B: EV=120013
B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7

root@gentoolaptop /home/nathan/Downloads/i2c-amd-mp2 # ls /sys/bus/acpi/devices
ACPI0003:00  AUI165C:00  device:0c  device:19  device:26    LNXCPU:06    PNP0103:00  PNP0C02:03  PNP0C0F:00  STK0002:00
AMDI0010:00  device:00   device:0d  device:1a  device:27    LNXCPU:07    PNP0200:00  PNP0C02:04  PNP0C0F:01  STK0002:01
AMDI0010:01  device:01   device:0e  device:1b  device:28    LNXPOWER:00  PNP0501:00  PNP0C02:05  PNP0C0F:02  STK0003:00
AMDI0010:02  device:02   device:0f  device:1c  device:29    LNXPOWER:01  PNP0501:01  PNP0C02:06  PNP0C0F:03  STK0003:01
AMDI0010:03  device:03   device:10  device:1d  device:2a    LNXPWRBN:00  PNP0501:02  PNP0C02:07  PNP0C0F:04  STK0004:00
AMDI0011:00  device:04   device:11  device:1e  ELAN0616:00  LNXSYBUS:00  PNP0501:03  PNP0C02:08  PNP0C0F:05  STK0004:01
AMDI0011:01  device:05   device:12  device:1f  FUJ7401:00   LNXSYBUS:01  PNP0800:00  PNP0C02:09  PNP0C0F:06  STK0005:00
AMDI0020:00  device:06   device:13  device:20  LNXCPU:00    LNXSYSTM:00  PNP0A08:00  PNP0C04:00  PNP0C0F:07  SYNA2B3F:00
AMDI0020:01  device:07   device:14  device:21  LNXCPU:01    LNXVIDEO:00  PNP0B00:00  PNP0C09:00  PNP0C50:00  UTK0001:00
AMDI0020:02  device:08   device:15  device:22  LNXCPU:02    LNXVIDEO:01  PNP0C01:00  PNP0C0A:00  PNP0C50:01  UTK0001:01
AMDI0020:03  device:09   device:16  device:23  LNXCPU:03    LNXVIDEO:02  PNP0C02:00  PNP0C0A:01  PNP0C50:02  VPC2004:00
AMDI0030:00  device:0a   device:17  device:24  LNXCPU:04    PNP0000:00   PNP0C02:01  PNP0C0C:00  STK0001:00
AMDI0040:00  device:0b   device:18  device:25  LNXCPU:05    PNP0100:00   PNP0C02:02  PNP0C0D:00  STK0001:01
Syniurge commented 5 years ago

Which Lenovo laptop is this?

You don't have the PCI device this driver is currently meant for, i.e Non-VGA unclassified device: Advanced Micro Devices, Inc. [AMD] Device 15e6, but you do have the right ACPI devices AMDI0011:0x.

The original authors of the driver from AMD said that there were plans to expand the ACPI part of the driver for new AMD sensor/non-sensor fusion hub devices, which is what your laptop may have. Once you give me the model name I'll contact Nehal-bakulchandra.Shah@amd.com.

I'd offer to expand the driver myself but I don't even have access to the datasheets.

BTW the issue isn't with your Synaptics TM3336-002 I2C touchpad, but with missing support for your I2C controller.

Gooberpatrol66 commented 5 years ago

Which Lenovo laptop is this?

Ideapad V330. Weirdly, the touchpad works in systemrescuecd. So, the correct driver seems to already exist in some form.

Syniurge commented 5 years ago

Could you paste your DSDT somewhere? You can extract the DSDT for example with:

sudo cat /sys/firmware/acpi/tables/DSDT > DSDT.aml
iasl -d DSDT.aml

This should clarify which I2C controller the touchpad depends upon, and what else the AMDI0011 is used for.

Gooberpatrol66 commented 5 years ago

https://bpaste.net/show/2a51d563b3b2

Syniurge commented 5 years ago

Sorry I meant the DSDT.dsl file generated by iasl, I can't use this copy&paste from a binary file.

Gooberpatrol66 commented 5 years ago

https://drive.google.com/file/d/1Mt1KlL8WJ1jSiz-MisBkFiGqilD8sZk_/view?usp=sharing

Syniurge commented 5 years ago

It looks like the Synaptics touchpad sits on top of a I2C controller with ID "AMDI0010" that should be supported by the i2c_designware driver:

    Scope (_SB
    {
        Device (I2CD)
        {
            Name (_HID, "AMDI0010")  // _HID: Hardware ID
            Name (_UID, 0x03)  // _UID: Unique ID
            ...

    Scope (_SB.I2CD)
    {
        Device (TPDA)
        {
            Name (_HID, "SYNA2B3F")  // _HID: Hardware ID
            Name (_CID, "PNP0C50" /* HID Protocol Device (I2C bus) */)  // _CID: Compatible ID
            ...

(AMDI0010 and AMDI0011 despite the similar ID are very different)

Could you check if you have the i2c_designware driver enabled in your Gentoo kernel? On Ubuntu I have the following options:

CONFIG_I2C_DESIGNWARE_CORE=y
CONFIG_I2C_DESIGNWARE_PLATFORM=y
# CONFIG_I2C_DESIGNWARE_SLAVE is not set
CONFIG_I2C_DESIGNWARE_PCI=m
CONFIG_I2C_DESIGNWARE_BAYTRAIL=y

(No idea why they made the i2c-designware-platform driver builtin though)

Gooberpatrol66 commented 5 years ago
root@gentoolaptop /home/nathan # lsmod | grep design
i2c_designware_platform    16384  0
i2c_designware_core    16384  1 i2c_designware_platform
i2c_core               53248  8 i2c_designware_platform,i2c_hid,i2c_designware_core,drm_kms_helper,i2c_algo_bit,amdgpu,i2c_piix4,drm
root@gentoolaptop /home/nathan # zcat /proc/config.gz | grep DESIGNWARE
CONFIG_I2C_DESIGNWARE_CORE=m
CONFIG_I2C_DESIGNWARE_PLATFORM=m
# CONFIG_I2C_DESIGNWARE_SLAVE is not set
CONFIG_I2C_DESIGNWARE_PCI=m
# CONFIG_I2C_DESIGNWARE_BAYTRAIL is not set
# CONFIG_SND_DESIGNWARE_I2S is not set
Syniurge commented 5 years ago

Sorry for the late reply. Actually the DSDT contains many more devices that could be touchpads, some as children of AMDI0010 and others as children of AMDI0011. Clearly there can be at most one of these touchpads that is real, but I don't really know why there are so many devices listed.

But if the touchpad worked properly in systemrescuecd, it may still be a matter of finding the relevant kernel options.

What you could do is boot systemresuecd again, and then find the touchpad entry in /proc/bus/input/devices:

I: Bus=0018 Vendor=06cb Product=7f27 Version=0100
N: Name="MSFT0001:00 06CB:7F27 Touchpad"
P: Phys=i2c-MSFT0001:00
S: Sysfs=/devices/platform/AMDI0011:01/i2c-9/i2c-MSFT0001:00/0018:06CB:7F27.0005/input/input25
U: Uniq=
H: Handlers=mouse1 event12 
B: PROP=5
B: EV=1b
B: KEY=e520 10000 0 0 0 0
B: ABS=2e0800000000003
B: MSC=20

The full sysfs path /devices/platform/AMDI0011:01/i2c-9/i2c-MSFT0001:00/0018:06CB:7F27.0005/input/input25 tells which I2C controller/ACPI device the touchpad is attached to (here it's AMDI0011:01), hence which I2C controller driver the touchpad depends upon.

i2cdetect -l can give you more infos on the I2C controllers as well, and you should compare the outputs between Gentoo and SystemRescueCD:

i2c-3   smbus           SMBus PIIX4 adapter port 3 at 0b00      SMBus adapter
i2c-1   smbus           SMBus PIIX4 adapter port 0 at 0b00      SMBus adapter
i2c-8   i2c             AMD MP2 i2c bus 0                       I2C adapter
i2c-6   i2c             dmdc                                    I2C adapter
i2c-4   smbus           SMBus PIIX4 adapter port 4 at 0b00      SMBus adapter
i2c-2   smbus           SMBus PIIX4 adapter port 2 at 0b00      SMBus adapter
i2c-0   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-9   i2c             AMD MP2 i2c bus 1                       I2C adapter
i2c-7   i2c             AMDGPU DM i2c hw bus 1                  I2C adapter
i2c-5   i2c             AMDGPU DM i2c hw bus 0                  I2C adapter

(Here i2c-9 is the second bus of my MP2 device).

Hoping that it helps.

Although your touchpad probably doesn't need the MP2 driver, I'm still curious as to why you have AMDI0011 entries in the DSDT without a corresponding MP2 PCI device.

Gooberpatrol66 commented 5 years ago

I should probably just link my forum thread: https://forums.gentoo.org/viewtopic-t-1096812-highlight-.html

Syniurge commented 5 years ago

Do you have CONFIG_ACPI_I2C_OPREGION=y and CONFIG_PINCTRL_AMD=y set in your kernel config? Not having them might be the reason.

According to the DSDT the touchpad actually depends on pinctrl gpio for interrupt and i2c ACPI operation region.

Gooberpatrol66 commented 5 years ago

I upgraded to kernel 5.1.6 to try to fix an unrelated freezing issue, then I enabled CONFIG_PINCTRL_AMD, and suddenly the touchpad works.

coiby commented 3 years ago

@Gooberpatrol66

When I am debugging another touchpad issue (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1887190), I find there is an bug in drivers/pinctrl/pinctrl-amd.c. According to the DSDT you shared, your touchpad is supposed by this bug too. Which version of kernel do you use now? Do you feel your touchpad is not sensitive enough? Could you install and run evhz (https://gitlab.com/iankelling/evhz) to find the report rate of your touchpad? Thank you!

Gooberpatrol66 commented 3 years ago

5.8.14, 136Hz

coiby commented 3 years ago

5.8.14, 136Hz

Thank you! It seems your touchpad is working fine. Can you show the register value of the GPIO used by the touchpad by patching drivers/pinctrl/pinctrl-amd.c,

$ git diff --no-index pinctrl-amd_latest.c pinctrl-amd.c 
diff --git a/pinctrl-amd_latest.c b/pinctrl-amd.c
index 9a760f5..3e6bb0a 100644
--- a/pinctrl-amd_latest.c
+++ b/pinctrl-amd.c
@@ -424,6 +424,7 @@ static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
        raw_spin_lock_irqsave(&gpio_dev->lock, flags);
        pin_reg = readl(gpio_dev->base + (d->hwirq)*4);

+       pr_alert("amd_gpio reg_val=%x, pin=%lu (before set_type)", pin_reg, d->hwirq);
        switch (type & IRQ_TYPE_SENSE_MASK) {
        case IRQ_TYPE_EDGE_RISING:
                pin_reg &= ~BIT(LEVEL_TRIG_OFF);
@@ -463,6 +464,7 @@ static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
                pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
                pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
                pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
+               pr_alert("amd_gpio reg_val=%x, pin=%lu (LEVEL_LOW)", pin_reg, d->hwirq);
                pin_reg |= DB_TYPE_PRESERVE_HIGH_GLITCH << DB_CNTRL_OFF;
                irq_set_handler_locked(d, handle_level_irq);
                break;

I've also create a repo to build a standalone pinctrl-amd for debugging https://github.com/coiby/standalone_pinctrl_amd. You can simply following the instructions in README.md.

After rebooting your system, you can filter the kernel message by matching "amd_gpio",

$ journalctl -k|grep amd_gpio
19:Oct 17 06:02:58 Rk kernel: amd_gpio reg_val=500e8, pin=130 (before set_type)
20:Oct 17 06:02:58 Rk kernel: amd_gpio reg_val=50388, pin=130 (LEVEL_LOW)
23:Oct 17 06:02:58 Rk kernel: amd_gpio reg_val=503c8, pin=130 (before set_type)
24:Oct 17 06:02:58 Rk kernel: amd_gpio reg_val=50388, pin=130 (LEVEL_LOW)
Gooberpatrol66 commented 3 years ago

I'm probably not going to be able to help. I'm using guix now, and modifying the kernel in guix is incomprehensible to me.

coiby commented 3 years ago

On Sat, Oct 17, 2020 at 01:14:31PM -0700, Gooberpatrol66 wrote:

I'm probably not going to be able to help. I'm using guix now, and modifying the kernel in guix is incomprehensible to me.

Thank you anyway:)

coiby commented 3 years ago

@Gooberpatrol66 Can you show me the result of sudo cat /sys/kernel/debug/gpio|grep -A1 "pin3\s"?

$ sudo cat /sys/kernel/debug/gpio|grep -A1 "pin3\s"
pin3      interrupt is disabled| interrupt is masked| disable wakeup in S0i3 state| disable wakeup in S3 state|
 disable wakeup in S4/S5 state| input is low|   pull-up is disabled| pull-down is enabled|   output is disabled|   0x240000

I'm going to submit a patch soon to fix this touchpad (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1887190) and I need to make sure it won't cause any regression.

Gooberpatrol66 commented 3 years ago
nathan@guixlaptop ~/guix $ sudo cat /sys/kernel/debug/gpio|grep -A1 "pin3\s"
Password: 
pin3    Level trigger| Active low| interrupt is enabled| interrupt is unmasked| disable wakeup in S0i3 state| disable wakeup in S3 state|
 disable wakeup in S4/S5 state| input is high|   pull-up is disabled| Pull-down is disabled|   output is disabled| 0x51b40
coiby commented 3 years ago
nathan@guixlaptop ~/guix $ sudo cat /sys/kernel/debug/gpio|grep -A1 "pin3\s"
Password: 
pin3  Level trigger| Active low| interrupt is enabled| interrupt is unmasked| disable wakeup in S0i3 state| disable wakeup in S3 state|
 disable wakeup in S4/S5 state| input is high|   pull-up is disabled| Pull-down is disabled|   output is disabled| 0x51b40

Thank you for the info! My submitted patch (https://lore.kernel.org/patchwork/patch/1333753/) won't cause any regression.