1. 11 Nov, 2022 13 commits
    • Michael Zaidman's avatar
      HID: ft260: fix 'cast to restricted' kernel CI bot warnings · fb5d783b
      Michael Zaidman authored
      Fix 'cast to restricted' sparse warnings reported by kernel test robot
      in https://lore.kernel.org/all/202211021607.ssjymlKi-lkp@intel.com/Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      fb5d783b
    • Michael Zaidman's avatar
      HID: ft260: missed NACK from busy device · 5afac727
      Michael Zaidman authored
      When writing into a slow device like an EEPROM chip, the
      controller may exit the busy state before the device releases
      the bus. In this case, the ft260_xfer_status returns success
      before the data transfer completion.
      
      The patch fixes it by returning from the ft260_xfer_status()
      with the "-EAGAIN" on both controller and bus busy status when
      appropriate.
      
      It does not apply to the i2c combined transactions when after
      the write IO, the controller keeps the bus busy until the read
      IO and then between reading IOs to ensure an atomic operation.
      Co-developed-by: default avatarGermain Hebert <germain.hebert@ca.abb.com>
      Signed-off-by: default avatarGermain Hebert <germain.hebert@ca.abb.com>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      5afac727
    • Michael Zaidman's avatar
      HID: ft260: fix a NULL pointer dereference in ft260_i2c_write · c2500bdf
      Michael Zaidman authored
      The zero-length passed into the ft260_i2c_write() triggered the
      NULL pointer dereference in the debug message on data[0] access.
      Since the controller does not support a write of zero length,
      let's not allow it.
      
      Before:
      
      $ sudo i2ctransfer -y 13 w0@0x51
      Killed
      
      After:
      
      $ sudo i2ctransfer -y 13 w0@0x51
      Error: Sending messages failed: Invalid argument
      Reported-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      c2500bdf
    • Michael Zaidman's avatar
      HID: ft260: wake up device from power saving mode · 4b3da685
      Michael Zaidman authored
      The FT260 can enter a power saving mode after being idle for longer
      than 5 seconds.
      
      When being woken up from power saving mode by an I2C write request,
      a possible NACK is not correctly reported by the controller. As a
      workaround, the driver will issue an I2C status report two times in
      ft260_xfer_status() after the chip has been idle for more than 5s.
      Co-developed-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      4b3da685
    • Michael Zaidman's avatar
      HID: ft260: missed NACK from big i2c read · 728b117e
      Michael Zaidman authored
      The FT260 controller does not return NACK when performing a big
      read (of multiple hid reports size) from a non-existing device
      or from the device responding with NACK when it is not ready
      to serve the request. However, it responds correctly with NACK
      to a read of up to a single hid report size.
      
      To overcome this issue, we split the muli-report read request
      into a read of a single HID report of 60 bytes size and a
      multi-report read.
      
      Big read of 256 bytes with first read of 60 bytes:
      
      $ sudo ./i2cperf -d 2 -o 2 -s 256 -r 0-0xff 1 0x50 -S
      
      [  +5.633280] ft260_i2c_write_read: off 0x0 rlen 255 wlen 2
      [  +0.000006] ft260_i2c_write: rep 0xd0 addr 0x50 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0
      [  +0.013205] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.000007] ft260_i2c_read: rep 0xc2 addr 0x50 len 255 rlen 60 flag 0x3
      [  +0.010932] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.004733] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000006] ft260_i2c_read: rep 0xc2 addr 0x50 len 195 rlen 128 flag 0x0
      [  +0.012572] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.005789] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.003189] ft260_raw_event: i2c resp: rep 0xd1 len 8
      [  +0.004092] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000010] ft260_i2c_read: rep 0xc2 addr 0x50 len 67 rlen 67 flag 0x4
      [  +0.011688] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.004700] ft260_raw_event: i2c resp: rep 0xd1 len 7
      [  +0.004858] ft260_xfer_status: bus_status 0x20, clock 100
      
      Read from non-existing device at address 8. The first 60 read responded
      with NACK.
      
      $ sudo ./i2cperf -d 2 -o 2 -s 256 -r 0-0xff 1 0x8 -S
      [Oct19 15:37] ft260_i2c_write_read: off 0x0 rlen 255 wlen 2
      [  +0.000007] ft260_i2c_write: rep 0xd0 addr 0x8 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0
      [  +0.022820] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.000007] ft260_i2c_read: rep 0xc2 addr 0x8 len 255 rlen 60 flag 0x3
      [  +0.010658] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.005965] ft260_xfer_status: bus_status 0x46, clock 100  <-- NACK
      [  +0.000009] ft260 0003:0403:6030.0004: i2c bus error: 0x46
      [  +0.007784] ft260_i2c_reset: done
      Co-developed-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      728b117e
    • Michael Zaidman's avatar
      HID: ft260: remove SMBus Quick command support · 3b56ff48
      Michael Zaidman authored
      The i2cdetect uses the SMBus Quick command by default to scan devices
      on the I2C bus. The FT260 implements an I2C bus controller. The SMBus
      is derived from I2C, but there are several differences between the
      specifications of the two buses in the areas of timing, protocols,
      operation modes, and electrical characteristics.
      
      One of the differences is that the I2C devices allow the slave not
      to ACK its slave address, but SMBus requires it to always ACK it as
      a mechanism to detect a detachable device’s presence on the bus.
      Since FT260 is the I2C bus controller, it does not acknowledge the
      SMBus Quick write command, which sends a single bit to the device at
      the place of the RD/WR bit.
      
      The ft260 driver attempted to mimic the SMBus Quick Write functionality
      by writing a single byte as the SMBus Byte Write command does.
      
      Usually, one byte in the SMBus Quick Write will be fine. However, it may
      cause problems with devices with a control register at offset 0, like
      i2c muxes, for example, when scanned with the i2cdetect utility.
      
      The i2cdetect with the "-r" option uses the SMBus Read Byte command,
      which is a reasonable workaround. To prevent the I2C bus from locking
      at write-only devices (most notably clock chips at address 0x69), use
      the "-r" option in conjunction with scanning range parameters.
      
      This patch removes the SMBus Quick command support.
      
      $ sudo i2cdetect -y 13
      Warning: Can't use SMBus Quick Write command, will skip some addresses
           0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
      00:
      10:
      20:
      30: -- -- -- -- -- -- -- --
      40:
      50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
      60:
      70:
      
      $ sudo i2cdetect -y -r 13
           0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
      00:                         -- -- -- -- -- -- -- --
      10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
      60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      70: -- -- -- -- -- -- -- --
      Reported-by: default avatarVince Asbridge <VAsbridge@sanblaze.com>
      Reported-by: default avatarStephen Shirron <SShirron@sanblaze.com>
      Reported-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      3b56ff48
    • Michael Zaidman's avatar
      HID: ft260: skip unexpected HID input reports · b7121e3c
      Michael Zaidman authored
      The FT260 is not supposed to generate unexpected HID reports. However,
      in theory, the unsolicited HID Input reports can be issued by a specially
      crafted malicious USB device masquerading as FT260 when the attacker has
      physical access to the USB port. In this case, the read_buf pointer points
      to the final data portion of the previous I2C Read transfer, and the memcpy
      invoked in the ft260_raw_event() will try copying the content of the
      unexpected report into the wrong location.
      
      This commit sets the Read buffer pointer to NULL on the I2C Read
      transaction completion and checks it in the ft260_raw_event() to detect
      and skip the unsolicited Input report.
      Reported-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      b7121e3c
    • Michael Zaidman's avatar
      HID: ft260: do not populate /dev/hidraw device · 76e76e79
      Michael Zaidman authored
      Do not populate the /dev/hidraw on ft260 interfaces when the hid-ft260
      driver is loaded.
      
      $ sudo insmod hid-ft260.ko
      $ ls /dev/hidraw*
      /dev/hidraw0
      
      $ sudo rmmod hid-ft260.ko
      $ ls /dev/hidraw*
      /dev/hidraw0  /dev/hidraw1  /dev/hidraw2
      Reported-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      76e76e79
    • Michael Zaidman's avatar
      HID: ft260: improve i2c large reads performance · 54410c14
      Michael Zaidman authored
      The patch increases the read buffer size to 180 bytes. It reduces
      the number of ft260_i2c_read() calls by three, improving the big
      reads performance.
      
      $ sudo i2ctransfer -y -f 13 w2@0x51 0x0 0x0 r180
      
      Before:
      
      [  +4.071878] ft260_i2c_write_read: off 0x0 rlen 180 wlen 2
      [  +0.000005] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0
      [  +0.001097] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000175] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000004] ft260_i2c_read: rep 0xc2 addr 0x51 len 180 rlen 60 flag 0x3
      [  +0.008579] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000208] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 120 rlen 60 flag 0x0
      [  +0.008794] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000181] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 60 rlen 60 flag 0x4
      [  +0.008817] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000223] ft260_xfer_status: bus_status 0x20, clock 100
      
      After:
      
      [ +11.611642] ft260_i2c_write_read: off 0x0 rlen 180 wlen 2
      [  +0.000005] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0
      [  +0.008001] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 180 rlen 180 flag 0x7
      [  +0.008994] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.007987] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.007992] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000206] ft260_xfer_status: bus_status 0x20, clock 100
      Suggested-by: default avatarEnrik Berkhan <Enrik.Berkhan@inka.de>
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      54410c14
    • Michael Zaidman's avatar
      HID: ft260: support i2c reads greater than HID report size · 0acb869f
      Michael Zaidman authored
      A random i2c read operation in EEPROM devices is implemented as a dummy
      write operation, followed by a current address read operation. The dummy
      write operation is used to load the target byte or word address (a.k.a
      offset) into the offset counter, from which the subsequent read operation
      then reads.
      
      To support longer than one HID report size random read, the ft260 driver
      issues multiple pairs of i2c write offset + read data transactions of HID
      report size so that the EEPROM device sees many i2c random read requests
      from different offsets.
      
      Two issues with the current implementation:
      - This approach suffers from extra overhead caused by writing offset
        requests.
      - Necessity to handle offset per HID report in big-endian representation
        as EEPROM devices expect. The current implementation does not do it and
        correctly handles the reads up to 60 bytes only.
      
      This patch addresses both issues by implementing more efficient approach.
      It issues a single i2c read request of up to the EEPROM page size and then
      waits for the data to arrive in multiple HID reports. For example, to read
      the 256 bytes from a 24LC512 chip, which has 128 bytes page size, the old
      method performs six ft260_i2c_write_read transactions while the new - two
      only.
      
      Before:
      
      $ sudo ./i2cperf -d 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S
      
        Read block via i2ctransfer by chunks
        -------------------------------------------------------------------
        data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
        -------------------------------------------------------------------
        40803           85             256           2           128
      
      Kernel log of a single 128 bytes read request:
      
      [  +2.376308] ft260_i2c_write_read: read_off 0x0 left_len 128 len 60
      [  +0.000002] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0
      [  +0.000707] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000173] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 60
      [  +0.008660] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000156] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.000001] ft260_i2c_write_read: read_off 0x3c left_len 68 len 60
      [  +0.000001] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x3c
      [  +0.001034] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000191] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 60
      [  +0.008614] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000203] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.000001] ft260_i2c_write_read: read_off 0x78 left_len 8 len 8
      [  +0.000001] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x78
      [  +0.000987] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000192] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000001] ft260_i2c_read: rep 0xc2 addr 0x51 len 8
      [  +0.002614] ft260_raw_event: i2c resp: rep 0xd1 len 8
      [  +0.000200] ft260_xfer_status: bus_status 0x20, clock 100
      
      After:
      
      $ sudo ./i2cperf -d 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S
      
        Read block via i2ctransfer by chunks
        -------------------------------------------------------------------
        data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
        -------------------------------------------------------------------
        43990           85             256           2           128
      
      Kernel log of a single 128 bytes read request:
      
      [  +1.464346] ft260_i2c_write_read: off 0x0 rlen 128 wlen 2
      [  +0.000002] ft260_i2c_write: rep 0xd0 addr 0x51 off 0 len 2 wlen 2 flag 0x2 d[0] 0x0
      [  +0.001653] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000188] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 128 rlen 60 flag 0x3
      [  +0.008609] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000157] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 68 rlen 60 flag 0x0
      [  +0.008840] ft260_raw_event: i2c resp: rep 0xde len 60
      [  +0.000203] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000002] ft260_i2c_read: rep 0xc2 addr 0x51 len 8 rlen 8 flag 0x4
      [  +0.002794] ft260_raw_event: i2c resp: rep 0xd1 len 8
      [  +0.000201] ft260_xfer_status: bus_status 0x20, clock 100
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Tested-by: default avatarGuillaume Champagne <champagne.guillaume.c@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      0acb869f
    • Michael Zaidman's avatar
      HID: ft260: support i2c writes larger than HID report size · 1edfae51
      Michael Zaidman authored
      To support longer than one HID report size write, the driver splits a
      single i2c message data payload into multiple i2c messages of HID report
      size. However, it does not replicate the offset bytes within the EEPROM
      chip in every consequent HID report because it is not and should not be
      aware of the EEPROM type. It breaks the i2c write message integrity and
      causes the EEPROM device not to acknowledge the second HID report keeping
      the i2c bus busy until the ft260 controller reports failure.
      
      This patch preserves the i2c write message integrity by manipulating the
      i2c flag bits across multiple HID reports to be seen by the EEPROM device
      as a single i2c write transfer.
      
      Before:
      
      $ sudo ./i2cperf -f 2 -o 2 -s 64 -r 0-0xff 13 0x51 -S
      Error: Sending messages failed: Input/output error
      
      [  +3.667741] ft260_i2c_write: rep 0xde addr 0x51 off 0 len 60 d[0] 0x0
      [  +0.007330] ft260_hid_output_report_check_status: wait 6400 usec, len 64
      [  +0.000203] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.000001] ft260_i2c_write: rep 0xd1 addr 0x51 off 60 len 6 d[0] 0x0
      [  +0.002337] ft260_hid_output_report_check_status: wait 1000 usec, len 10
      [  +0.000157] ft260_xfer_status: bus_status 0x2e, clock 100
      [  +0.000241] ft260_i2c_reset: done
      [  +0.000003] ft260_i2c_write: failed to start transfer, ret -5
      
      After:
      
      $ sudo ./i2cperf -f 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S
      
        Fill block with increment via i2ctransfer by chunks
        -------------------------------------------------------------------
        data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
        -------------------------------------------------------------------
        71260           86             256           2           128
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Tested-by: default avatarGuillaume Champagne <champagne.guillaume.c@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      1edfae51
    • Michael Zaidman's avatar
      HID: ft260: improve i2c write performance · 6fca5e3f
      Michael Zaidman authored
      The patch improves the I2C write performance by 20 - 30 percent by
      revising the sleep time in the ft260_hid_output_report_check_status()
      in the following ways:
      
      1. Reduce the wait time and start to poll earlier.
      
      Sending a large amount of data at a low I2C clock rate saturates the
      internal FT260 buffer and causes hiccups in status readiness, as shown
      below in the log fragment. Aligning the status check wait time to the
      worst case significantly reduces the write performance.
      
      [Oct22 10:28] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      [  +0.005296] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.013460] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      [  +0.003244] ft260_hid_output_report_check_status: wait 1920 usec, len 38
      [  +0.000190] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.015324] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      [  +0.003491] ft260_hid_output_report_check_status: wait 1920 usec, len 38
      [  +0.000202] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.016047] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      [  +0.002768] ft260_hid_output_report_check_status: wait 1920 usec, len 38
      [  +0.000150] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.011389] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      [  +0.003467] ft260_hid_output_report_check_status: wait 1920 usec, len 38
      [  +0.000191] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000172] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000131] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000241] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000233] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000190] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000196] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.011314] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      [  +0.003334] ft260_hid_output_report_check_status: wait 1920 usec, len 38
      [  +0.000227] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000204] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000198] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000147] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.011060] ft260_i2c_write: rep 0xd8 addr 0x51 off 0 len 34 d[0] 0x0
      
        Before:
          $ sudo ./i2cperf -f 2 -o 2 -s 32 -r 0-0xff 13 0x51 -S
      
            Fill block with increment via i2ctransfer by chunks
            -------------------------------------------------------------------
            data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
            -------------------------------------------------------------------
            40510           80             256           8           32
      
        After:
          $ sudo ./i2cperf -f 2 -o 2 -s 32 -r 0-0xff 13 0x51 -S
      
            Fill block with increment via i2ctransfer by chunks
            -------------------------------------------------------------------
            data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
            -------------------------------------------------------------------
            52584           80             256           8           32
      
      2. Do not sleep if the estimated I2C transfer time is below 2 ms since
         the first xfer status query frequently takes around 1.5 ms, and the
         following status queries take about 200us on average. So we usually
         return from the routine after the first 1 - 3 status checks.
      
      [Oct22 11:14] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0
      [  +0.004270] ft260_xfer_status: bus_status 0x20, clock 100
      [  +0.013889] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0
      [  +0.000856] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000138] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.013352] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0
      [  +0.001501] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000177] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.014477] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0
      [  +0.001377] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000233] ft260_xfer_status: bus_status 0x41, clock 100
      [  +0.000191] ft260_xfer_status: bus_status 0x40, clock 100
      [  +0.013197] ft260_i2c_write: rep 0xd4 addr 0x51 off 0 len 18 d[0] 0x0
      
        Before:
          $ sudo ./i2cperf -f 2 -o 2 -s 16 -r 0-0xff 13 0x51 -S
      
            Fill block with increment via i2ctransfer by chunks
            -------------------------------------------------------------------
            data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
            -------------------------------------------------------------------
            28826           73             256           16          16
      
        After:
          $ sudo ./i2cperf -f 2 -o 2 -s 16 -r 0-0xff 13 0x51 -S
      
            Fill block with increment via i2ctransfer by chunks
            -------------------------------------------------------------------
            data rate(bps)  efficiency(%)  data size(B)  total IOs   IO size(B)
            -------------------------------------------------------------------
            45138           73             256           16          16
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Tested-by: default avatarGuillaume Champagne <champagne.guillaume.c@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      6fca5e3f
    • Michael Zaidman's avatar
      HID: ft260: ft260_xfer_status routine cleanup · f45d50ed
      Michael Zaidman authored
      After clarifying with FTDI's support, it turned out that the error
      condition (bit 1) in byte 1 of the i2c status HID report is a status
      bit reflecting all error conditions. When bits 2, 3, or 4 are raised
      to 1, bit 1 is set to 1 also. Since the ft260_xfer_status routine tests
      the error condition bit and exits in the case of an error, the program
      flow never reaches the conditional expressions for 2, 3, and 4 bits when
      any of them indicates an error state. Though these expressions are never
      evaluated to true, they are checked several times per IO, increasing the
      ft260_xfer_status polling cycle duration.
      
      The patch removes the conditional expressions for 2, 3, and 4 bits in
      byte 1 of the i2c status HID report.
      Signed-off-by: default avatarMichael Zaidman <michael.zaidman@gmail.com>
      Tested-by: default avatarGuillaume Champagne <champagne.guillaume.c@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      f45d50ed
  2. 22 Oct, 2022 1 commit
    • Linus Torvalds's avatar
      Merge tag 'for-linus-2022102101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid · 334fe5d3
      Linus Torvalds authored
      Pull HID fixes from Benjamin Tissoires:
      
       - a 12 year old bug fix for the Apple Magic Trackpad v1 (José Expósito)
      
       - a fix for a potential crash on removal of the Playstation controllers
         (Roderick Colenbrander)
      
       - a few new device IDs and device-specific quirks, most notably support
         of the new Playstation DualSense Edge controller
      
      * tag 'for-linus-2022102101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
        HID: lenovo: Make array tp10ubkbd_led static const
        HID: saitek: add madcatz variant of MMO7 mouse device ID
        HID: playstation: support updated DualSense rumble mode.
        HID: playstation: add initial DualSense Edge controller support
        HID: playstation: stop DualSense output work on remove.
        HID: magicmouse: Do not set BTN_MOUSE on double report
      334fe5d3
  3. 21 Oct, 2022 26 commits