Sfoglia il codice sorgente

touchpad: Yoga 720 Synaptics I2C touchpad works

The Synaptics 06CB:7F8F on LPSS I2C0 NAKed its address because the EC
keeps the touchpad until an ACPI OS checks in.  Do the DSDT EC0._REG
handshake at boot (ECMM 0xA3: OSTY = 6, ECRD = 1) and retry the address
for up to a second.

Also follow Linux i2c-hid/hid-multitouch: read the HID descriptor from
register 0x20 (TPD1._DSM), select touchpad Input Mode (feature 4 = 3)
and the surface/button switches (feature 6), and use the tip bit for
contact state.  Change IC_TAR only with the DesignWare controller
disabled, and drop the speculative LPSS private 0x200 clock write.
Johannes Zellner 6 ore fa
parent
commit
e5644a4824
6 ha cambiato i file con 122 aggiunte e 50 eliminazioni
  1. 24 10
      AGENTS.md
  2. 21 12
      docs/drivers.html
  3. 12 15
      kernel/i2c.c
  4. 0 5
      kernel/i2c.h
  5. 20 0
      kernel/ideapad.c
  6. 45 8
      kernel/touchpad.c

+ 24 - 10
AGENTS.md

@@ -1525,22 +1525,33 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `intel-lpss 0000:00:15.0: enabling device (0000 -> 0002)`), clears the
   LPSS `PMECTRLSTATUS` at PCI config `0x84` (the DSDT `LPD0(SB10)` target;
   the PMC `PWRMBASE + 0x84` address is a different register and leaves the
-  I2C FSM power-gated), enables the LPSS functional clock at private
-  `0x200` (gate + M=6/N=5 for the 120 MHz I2C clock; the BIOS leaves
-  unused LPSS blocks gated, and the register file still answers while the
-  I2C FSM does not drive the bus), maps the BAR and probes the Synaptics
-  at `0x2c`; the HID descriptor vendor/product
+  I2C FSM power-gated), asserts/releases the LPSS reset at private
+  `0x204` (the I2C clock is a fixed 120 MHz with no divider, as in Linux's
+  `intel-lpss`, so private `0x200` is not written), maps the BAR and
+  probes the Synaptics at `0x2c`.  The touchpad only ACKs once the EC was
+  told an ACPI OS is running: the DSDT's `EC0._REG` writes `OSTY` (OS type)
+  and `ECRD` (EC driver ready) into the EC memory window, and before that
+  the EC keeps the touchpad (it NAKed its address under NebOS while the
+  same controller setup works in Linux).  `ideapad_init()` does that write
+  at boot (see the board-sensors bullet) and the I2C0 probe retries the
+  address for up to a second.  The HID descriptor vendor/product
   `0x06CB/0x7F8F` filters out the Wacom touchscreen on I2C1.  The BIOS
   already leaves GPP_C16/C17 in native function 1 (Linux's `pins` shows
   `mode 1 0x84000702 0x58`), so the kernel does not rewrite the pads.  The
   Synaptics probe follows Linux i2c-hid: address ACK, read the HID
-  descriptor, then power-on (`0x0800`), reset (`0x0100`) and the
-  zero-length reset-complete input report.  The report line is
+  descriptor from register `0x0020` (`TPD1._DSM`; the Elan's is `0x0001`),
+  then power-on (`0x0800`), reset (`0x0100`) and the zero-length
+  reset-complete input report, and finally selects touchpad mode like
+  hid-multitouch (`SET_REPORT` feature 4 Input Mode = 3, feature 6 surface
+  and button switches on): a Windows Precision Touchpad sends plain mouse
+  report 2 until then.  `i2c.c` changes `IC_TAR` only with the controller
+  disabled, as the DesignWare databook requires.  The report line is
   a GPIO with no driver, so `touchpad_poll()` reads the input register every
   25 ms (back-to-back reads stall the device).  The Elan `0x5D` vendor report
   carries a finger bitmask and five packed bytes per active finger; the
   Synaptics Windows-Precision report 3 carries five 5-byte finger records
-  (tip/confidence, contact id, 16-bit X/Y), then scan time, contact count
+  (bit 0 confidence, bit 1 tip, contact id, 16-bit X/Y; a contact counts
+  while its tip bit is set), then scan time, contact count
   and the clickpad bit.  Both decoders feed the device-independent
   `touchpad_gesture.c/h` engine.  The engine owns
   pointer scaling, taps, the physical-button latch and two-finger
@@ -1560,7 +1571,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `rightclick off|tap|corner|both`, `tapclick on|off`,
   `scroll on|off|natural|traditional` and `invert on|off`; `touchpad probe`
   reruns a failed boot probe and prints the LPSS PCI id/BAR/command, the
-  DesignWare component type, the 0x200 clock and 0x204 reset registers, and
+  DesignWare component type, the private 0x200 and 0x204 reset registers, and
   the PMECTRLSTATUS before/after clear on failure.
   `mouseinfo` lists the Elan/Synaptics VID/PID.
 - **USB**: `usb.c/h` — controller-agnostic core: device enumeration,
@@ -1739,7 +1750,10 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   capacity scale and the mA->mW rate conversion, and `BMF0` (0xC0 bits
   4..7, 6 = SIMPLO) the vendor string.  The probe validates design/full
   capacity, voltage and the status/vendor bits, so an address that is not
-  this EC reads as absent, and the backend only reads (no EC writes).
+  this EC reads as absent.  Its only EC write is `EC0._REG`'s OS handshake
+  at boot: byte `0xA3` gets `OSTY` = 6 (bits 0..3, OSYS `0x07DF` as Linux
+  and Windows 10 report it) and `ECRD` = 1 (bit 6), a read-modify-write that
+  keeps `ADPT`; the EC hands the I2C touchpad to the OS only after it.
   `SYS_POWER_INFO` reports source `SYS_POWER_SRC_IDEAPAD`; `powerinfo`
   prints `ideapad`, and the WM top bar and Settings use the same snapshot.
   `power_src.c` tries the ThinkPad backend first, then the IdeaPad EC, then

+ 21 - 12
docs/drivers.html

@@ -92,7 +92,7 @@
 					<tr><td>Touchpad</td><td><span class="file">i2c.c</span>, <span class="file">touchpad.c</span>, <span class="file">touchpad_gesture.c</span></td><td>LPSS DesignWare I2C; Elan <code>0x15</code>, Synaptics <code>0x2C</code></td><td>Polled input register every 25 ms; software tap and two-finger scroll gestures; no GPIO interrupt driver</td></tr>
 					<tr><td>Serial</td><td><span class="file">serial.c</span></td><td>16550 UART, COM1</td><td>COM1 presence probe; PIT-polled receive ring, polled transmitter</td></tr>
 					<tr><td>Thermal</td><td><span class="file">thermal.c</span></td><td>Intel DTS MSR</td><td>Sampled once a second from the scheduler tick</td></tr>
-					<tr><td>Board sensors / EC</td><td><span class="file">it87.c</span>, <span class="file">tpec.c</span>, <span class="file">ec.c</span>, <span class="file">cros_ec.c</span>, <span class="file">ideapad.c</span></td><td>Super I/O, ThinkPad H8 EC, Chrome OS EC, IdeaPad EC (temps, fans, battery, AC, switches)</td><td>Polled; EC battery-index/FIFO/page-selector writes only</td></tr>
+					<tr><td>Board sensors / EC</td><td><span class="file">it87.c</span>, <span class="file">tpec.c</span>, <span class="file">ec.c</span>, <span class="file">cros_ec.c</span>, <span class="file">ideapad.c</span></td><td>Super I/O, ThinkPad H8 EC, Chrome OS EC, IdeaPad EC (temps, fans, battery, AC, switches)</td><td>Polled; EC battery-index/FIFO/page-selector writes and the IdeaPad OS handshake only</td></tr>
 					<tr><td>Wall clock</td><td><span class="file">rtc.c</span></td><td>CMOS RTC ports <code>0x70/0x71</code></td><td>Read/write under the BKL; update-cycle retries and a 1970–2069 two-digit year window</td></tr>
 				</tbody>
 			</table>
@@ -581,11 +581,15 @@
 			clears the LPSS <code>PMECTRLSTATUS</code> at PCI config
 			<code>0x84</code> (the DSDT <code>LPD0(SB10)</code> target;
 			the PMC <code>PWRMBASE + 0x84</code> address is a different
-			register and leaves the I2C FSM power-gated), enables the
-			LPSS functional clock at private <code>0x200</code>
-			(gate + M=6/N=5 for the 120 MHz I2C clock; the BIOS leaves
-			unused LPSS blocks gated and the register file still answers
-			while the FSM does not drive the bus), maps their BARs.
+			register and leaves the I2C FSM power-gated), asserts and
+			releases the LPSS reset at private <code>0x204</code> (the
+			I2C clock is a fixed 120 MHz without a divider, so private
+			<code>0x200</code> is left alone, as in Linux's
+			<code>intel-lpss</code>), maps their BARs. On the Yoga the
+			touchpad answers only after the EC was told an ACPI OS is
+			running (<code>EC0._REG</code>'s <code>OSTY</code>/<code>ECRD</code>
+			write, done by <span class="file">ideapad.c</span> at boot), so
+			the I2C0 probe retries the address for up to a second.
 			The BIOS already leaves GPP_C16/C17 in native function 1
 			(Linux's <code>pins</code> output shows
 			<code>mode 1 0x84000702 0x58</code>), so the kernel does not
@@ -597,17 +601,22 @@
 			(<code>0x0100</code>), consume the 2-byte acknowledgement, read the
 			HID descriptor, select absolute mode (<code>0x0300 = 1</code>) and
 			wake the device (<code>0x0800</code>). Synaptics at <code>0x2C</code>:
-			check the address, read the HID descriptor, then power on
+			check the address, read the HID descriptor from register
+			<code>0x0020</code> (<code>TPD1._DSM</code>), then power on
 			(<code>0x0800</code>), reset (<code>0x0100</code>) and wait for
 			the zero-length reset-complete input report, as Linux i2c-hid
-			does; then use the Windows-Precision report 3. The descriptor's
+			does; then select touchpad mode as hid-multitouch does
+			(<code>SET_REPORT</code> feature 4 Input Mode = 3, feature 6
+			surface/button switches on; until then the device sends plain
+			mouse report 2) and use the Windows-Precision report 3, where a
+			contact counts while its tip bit (bit 1) is set. The descriptor's
 			vendor/product (<code>0x06CB:0x7F8F</code>) filters out the Wacom
 			touchscreen on I2C1. The Elan native max-X/Y commands
 			(<code>0x0106</code>/<code>0x0107</code>) give the corner zone a
 			physical coordinate frame; the Synaptics frame is 1219 x 799.
 			<code>touchpad probe</code> reruns the probe and prints the LPSS
-			PCI id/BAR/command, component type, the <code>0x200</code>
-			clock and <code>0x204</code> reset registers, and
+			PCI id/BAR/command, component type, the private <code>0x200</code>
+			and <code>0x204</code> reset registers, and
 			<code>PMECTRLSTATUS</code> before/after the clear when it
 			fails.</li>
 			<li><strong>Reports.</strong> The Elan vendor report <code>0x5D</code>
@@ -691,7 +700,7 @@
 			<li><strong>IT87xx.</strong> <span class="file">it87.c</span> reads the Super I/O temperatures and fan tachometers on the ASUS AT3IONT-I and the Gigabyte 970A-DS3P (IT8728F). Nothing is written to fan control.</li>
 			<li><strong>ThinkPad EC.</strong> <span class="file">tpec.c</span> is gated on an SMBIOS Lenovo/IBM vendor and a <code>ThinkPad</code> product or version string; IdeaPads/Yogas share the vendor but have a different ACPI EC register map, so the ThinkPad probe leaves them alone (the IdeaPad backend below handles theirs). It reads temperatures and fan mode through the shared ACPI EC protocol in <span class="file">ec.c</span> (ports <code>0x62/0x66</code>, command <code>0x80</code> read / <code>0x81</code> write, OBF/IBF waits, stale-byte drain, bounded polls). Battery/AC state comes from <code>0x38/0x39</code> (present, charging, discharging), <code>0x46</code> bit 4 (AC online), and the page-selected 16-byte window at <code>0xA0..0xAF</code>; <code>0x81</code> selects the battery and page (0 dynamic, 1 mode, 2 design, 5 manufacturer, 6 model). That page selector is the only EC write, and it is restored when it changed.</li>
 			<li><strong>Chrome EC.</strong> <span class="file">cros_ec.c</span> probes the Chrome OS EC, gated on the ACPI memory version, the <code>'E','C'</code> memmap id and the device feature bits; it skips the probe when the ThinkPad EC is present. Its ACPI window <code>0x20..0xFF</code> mirrors memmap <code>0x00..0xDF</code>: temperature sensors <code>0x00..0x0f</code>/<code>0x18..0x1f</code> (raw − 73 °C), fans <code>0x10..0x17</code> (<code>0xffff</code> absent), switches <code>0x30</code> (lid/power button), and the battery block <code>0x40..0x7f</code> (AC/present/charging flags at <code>0x4c</code>, voltage/rate/remaining/design/last-full/cycle count, and the 8-byte strings). <code>EC_ACPI_MEM_BATTERY_INDEX</code> <code>0x12</code> selects the battery and waits for <code>BATT_INDEX</code> <code>0x4e</code>; <code>EC_ACPI_MEM_STRINGS_FIFO</code> <code>0x16</code> returns longer strings when supported. The Cyan full-charge workaround is applied, and the units are mAh/mA. <span class="file">power_src.c</span> picks the ThinkPad backend first, then the Chrome EC; <code>SYS_CROS_EC_SENSORS</code> (107) exposes the EC temperature/fan/switch snapshot.</li>
-			<li><strong>IdeaPad/Yoga EC.</strong> <span class="file">ideapad.c</span> reads <code>BAT1</code> and <code>ACAD</code> without an ACPI interpreter. The DSDT's <code>BAT1</code> methods take their fields from the PCH EC memory window at <code>0xFF000800</code> (a <code>SystemMemory</code> OperationRegion, not the <code>0x62/0x66</code> EC): <code>BST0</code> <code>0xC1</code>, <code>BRC0</code> <code>0xC2</code>, <code>BPV0</code> <code>0xC6</code>, <code>BDV0</code> <code>0xC8</code>, <code>BDC0</code> <code>0xCA</code>, <code>BFC0</code> <code>0xCC</code>, <code>CYC0</code> <code>0xCF</code>, <code>BAC0</code> <code>0xD2</code>, <code>BFCB</code> <code>0xED</code>, <code>ORRF</code> <code>0xF1</code> bit 6 and <code>ADPT</code> <code>0xA3</code> bit 7. <code>BAM0</code> (0xC0 bit 1) selects the 1/10 capacity scale and the mA-to-mW rate conversion, and <code>BMF0</code> (bits 4..7, 6 = SIMPLO) the pack vendor. The probe validates capacity, voltage and the status/vendor bits and only reads the window. Linux's <code>BAT1</code> on the Yoga reports 29.78/29.9 Wh, 8.657 V, 3.2 W, model <code>PABAS0241231</code> (SIMPLO), <code>ACAD</code> online; <span class="file">power_src.c</span> selects the ThinkPad EC first, then the IdeaPad EC, then the Chrome EC.</li>
+			<li><strong>IdeaPad/Yoga EC.</strong> <span class="file">ideapad.c</span> reads <code>BAT1</code> and <code>ACAD</code> without an ACPI interpreter. The DSDT's <code>BAT1</code> methods take their fields from the PCH EC memory window at <code>0xFF000800</code> (a <code>SystemMemory</code> OperationRegion, not the <code>0x62/0x66</code> EC): <code>BST0</code> <code>0xC1</code>, <code>BRC0</code> <code>0xC2</code>, <code>BPV0</code> <code>0xC6</code>, <code>BDV0</code> <code>0xC8</code>, <code>BDC0</code> <code>0xCA</code>, <code>BFC0</code> <code>0xCC</code>, <code>CYC0</code> <code>0xCF</code>, <code>BAC0</code> <code>0xD2</code>, <code>BFCB</code> <code>0xED</code>, <code>ORRF</code> <code>0xF1</code> bit 6 and <code>ADPT</code> <code>0xA3</code> bit 7. <code>BAM0</code> (0xC0 bit 1) selects the 1/10 capacity scale and the mA-to-mW rate conversion, and <code>BMF0</code> (bits 4..7, 6 = SIMPLO) the pack vendor. The probe validates capacity, voltage and the status/vendor bits. Its one write is the DSDT's <code>EC0._REG</code> OS handshake at boot: <code>0xA3</code> gets <code>OSTY</code> = 6 (bits 0..3) and <code>ECRD</code> = 1 (bit 6) in a read-modify-write that keeps <code>ADPT</code>; the EC hands the I2C touchpad to the OS only after it. Linux's <code>BAT1</code> on the Yoga reports 29.78/29.9 Wh, 8.657 V, 3.2 W, model <code>PABAS0241231</code> (SIMPLO), <code>ACAD</code> online; <span class="file">power_src.c</span> selects the ThinkPad EC first, then the IdeaPad EC, then the Chrome EC.</li>
 			<li><strong>MTRRs.</strong> <span class="file">mtrr.c</span> manages write-combining ranges for the framebuffer and reports the effective mapping.</li>
 		</ul>
 		<p>
@@ -771,7 +780,7 @@
 			<li><strong>AHCI.</strong> First controller only, no hotplug after boot, disks above 2 TB are clamped to 32-bit LBA.</li>
 			<li><strong>eMMC.</strong> Polled 1-bit/25 MHz PIO; no DMA, IRQ, CMD6 bus-width/high-speed/DDR switch or hotplug. Only the eMMC function is driven; the SDIO/SD functions and SD card reader are not.</li>
 			<li><strong>Storage serialization.</strong> A FAT/floppy operation sets <code>sys_fs_busy</code> and stalls process switching for its duration; the PIT keeps ticking.</li>
-			<li><strong>EC.</strong> The Chrome EC path uses the ACPI v2 memmap only: no MEC host-command interface, EC SCI events, charger current/voltage, charging limit or EC firmware version. The ThinkPad H8 path is limited to its page-selected battery window and has no SCI handler. The IdeaPad path maps the DSDT's EC memory window and only reads <code>BAT1</code>/<code>ACAD</code> (there is no ACPI interpreter, no EC SCI/notify handling, and the model/serial strings are the DSDT defaults). Battery/AC is polled by the WM once a second.</li>
+			<li><strong>EC.</strong> The Chrome EC path uses the ACPI v2 memmap only: no MEC host-command interface, EC SCI events, charger current/voltage, charging limit or EC firmware version. The ThinkPad H8 path is limited to its page-selected battery window and has no SCI handler. The IdeaPad path maps the DSDT's EC memory window, reads <code>BAT1</code>/<code>ACAD</code> and writes only the boot OS handshake (there is no ACPI interpreter, no EC SCI/notify handling, and the model/serial strings are the DSDT defaults). Battery/AC is polled by the WM once a second.</li>
 			<li><strong>WiFi.</strong> Intel 7265 rev D/3165 (7265D firmware), 8265 (8265-36 firmware, the 8000 loader is not yet hardware-validated) and 6200/6300 (6000 firmware, written without hardware in the loop); WPA2-PSK/CCMP and open networks, no WPA3/SAE, 802.1X, TKIP or WEP. No roaming, power save, background scan, HT/VHT, aggregation or rate scaling. Group rekeys need the background <code>wifi __keep</code> helper running. RX CCMP falls back to the byte-oriented software AES-CCM path when the firmware rejects the installed keys, so it has no replay window and is CPU-bound at high RX rates.</li>
 			<li><strong>RTL8821AU.</strong> High-speed EHCI/xHCI only (no UHCI/OHCI bulk). No IQ calibration, thermal power tracking, DIG, BT coexistence or by-rate/regulatory TX power tables (the eFuse base index is used for every rate); 20 MHz legacy rates only. Only one bulk device can stream on xHCI at a time (single bulk ring), so it does not mix with an ASIX dongle or a USB stick transfer.</li>
 			<li><strong>Suspend.</strong> There is no S0ix/suspend path; package C-states and the EC sleep handshake remain firmware-managed.</li>

+ 12 - 15
kernel/i2c.c

@@ -165,20 +165,6 @@ void i2c_dw_dump(unsigned int base)
 	serial_putc(SERIAL_COM1, '\n');
 }
 
-void i2c_dw_clock_spt(unsigned int base)
-{
-	/* LPSS private 0x200: bit 0 gates the functional clock, bits 1..15
-	 * are the M divider, bits 16..30 the N divider, bit 31 updates the
-	 * divider.  With the gate off the DesignWare register file still
-	 * answers (the component type reads) but the I2C FSM never drives
-	 * the bus.  Linux's intel-lpss enables it before the device probe;
-	 * the BIOS leaves unused LPSS blocks gated.  SPT-LP runs the LPSS
-	 * clock at 120 MHz with the unity divider (the clk_summary shows
-	 * 120000000 for i2c_designware.0 pclk), so M=N=1. */
-	dw_wr(base, 0x200, 0x80010003u);
-	dw_delay_ms(1);
-}
-
 int i2c_dw_init(unsigned int base)
 {
 	unsigned int t0;
@@ -234,7 +220,18 @@ int i2c_dw_transfer(unsigned int base, unsigned int addr,
 	 * short: a failed poll must not block the housekeeping loop. */
 	deadline = 10 + (wrlen + rdlen);
 
-	dw_wr(base, DW_IC_TAR, addr & 0x7f);
+	/* IC_TAR may only change while the controller is disabled (unless
+	 * the IP was built with IC_DYNAMIC_TAR_UPDATE); Linux's
+	 * i2c_dw_xfer_init() disables it around the write as well. */
+	if ((dw_rd(base, DW_IC_TAR) & 0x3ff) != (addr & 0x7f)) {
+		dw_wr(base, DW_IC_ENABLE, 0);
+		t0 = get_ticks_ms();
+		while ((dw_rd(base, DW_IC_ENABLE_STATUS) & 1) &&
+		       get_ticks_ms() - t0 < 5)
+			;
+		dw_wr(base, DW_IC_TAR, addr & 0x7f);
+		dw_wr(base, DW_IC_ENABLE, IC_ENABLE_EN);
+	}
 	dw_clear_irq(base);
 	i2c_last_abort = 0;
 

+ 0 - 5
kernel/i2c.h

@@ -16,11 +16,6 @@ extern unsigned int i2c_last_abort;
 /* Raw component-type / reset-release access for the LPSS scan. */
 unsigned int i2c_dw_comp_type(unsigned int base);
 void i2c_dw_reset_release(unsigned int base);
-/* Sunrise Point-LP only: enable the LPSS functional clock gate and set
- * the fractional divider (0x200).  The BIOS leaves it off for unused
- * LPSS blocks; the register file still answers, but the I2C FSM does not
- * drive the bus. */
-void i2c_dw_clock_spt(unsigned int base);
 /* One-line controller register dump for the seriallog. */
 void i2c_dw_dump(unsigned int base);
 

+ 20 - 0
kernel/ideapad.c

@@ -17,6 +17,7 @@
  *   0xED  BFCB   alternate last-full capacity (16-bit)
  *   0xF1  bit 6  ORRF (use BFCB when set)
  *   0xA3  bit 7  ADPT (AC adapter online)
+ *   0xA3  bits 0..3 OSTY, bit 6 ECRD (written once, see ideapad_os_ready)
  *
  * The DSDT scales capacities by BASC = 10 when BAM0 == 0 (the pack reports
  * in 10 mWh units) and converts BAC0 from mA to mW with BPV0.  The _BST rate
@@ -93,12 +94,31 @@ int ideapad_present(void)
 	return 1;
 }
 
+/* EC0._REG(3, 1) in the DSDT: OSTP() reports the OS type (OSTY, 0xA3 bits
+ * 0..3; Linux and Windows 10 make OSYS 0x07DF, OSTY 6), then ECFG(1) sets
+ * ECRD (0xA3 bit 6), "the OS EC driver is ready".  Until the OS does this
+ * the EC keeps the I2C touchpad to itself (the Synaptics NAKs its address
+ * on the LPSS I2C0 bus), the way an ACPI-less OS finds it.  Both fields are
+ * Preserve, so this is the same byte read-modify-write the AML does. */
+static void ideapad_os_ready(unsigned char *p)
+{
+	unsigned int v = p[0xA3];
+
+	p[0xA3] = (unsigned char)((v & ~0x4Fu) | 0x06u | 0x40u);
+	serial_puts(SERIAL_COM1, "touchpad: ideapad EC os ready a3 ");
+	serial_puthex(SERIAL_COM1, v);
+	serial_puts(SERIAL_COM1, " -> ");
+	serial_puthex(SERIAL_COM1, p[0xA3]);
+	serial_putc(SERIAL_COM1, '\n');
+}
+
 void ideapad_init(void)
 {
 	if (!ideapad_present())
 		return;
 	serial_puts(SERIAL_COM1,
 		    "ideapad: EC battery/AC at 0xFF000800\n");
+	ideapad_os_ready(ecmm);
 }
 
 void ideapad_power_read(struct power_info *out, int detail)

+ 45 - 8
kernel/touchpad.c

@@ -27,6 +27,7 @@
 #include "touchpad.h"
 #include "touchpad_gesture.h"
 #include "i2c.h"
+#include "ideapad.h"
 #include "io.h"
 #include "paging.h"
 #include "pci.h"
@@ -40,6 +41,8 @@
 
 #define TP_HID_DESC_REG		0x0001
 #define TP_HID_DESC_LEN		30
+/* TPD1._DSM(HID-I2C UUID, 1) in the Yoga DSDT: the descriptor register. */
+#define TP_SYN_DESC_REG		0x0020
 
 #define TP_CMD_REG		0x0005
 #define TP_CMD_RESET		0x0100
@@ -364,12 +367,34 @@ static int probe_controller(unsigned int base)
 	return 1;
 }
 
+/* HID-over-I2C SET_REPORT (opcode 3) of a one-byte feature report: the
+ * command word carries type 3 (feature) and the report id, the data register
+ * gets a 2-byte length (including itself), the id and the value. */
+static void syn_set_feature(unsigned int data_reg, unsigned int id,
+			    unsigned int val)
+{
+	unsigned char b[10];
+
+	b[0] = (unsigned char)(tp_cmd_reg & 0xff);
+	b[1] = (unsigned char)(tp_cmd_reg >> 8);
+	b[2] = (unsigned char)(0x30 | id);
+	b[3] = 0x03;
+	b[4] = (unsigned char)(data_reg & 0xff);
+	b[5] = (unsigned char)(data_reg >> 8);
+	b[6] = 4;
+	b[7] = 0;
+	b[8] = (unsigned char)id;
+	b[9] = (unsigned char)val;
+	(void)i2c_dw_transfer(tp_base, tp_addr, b, 10, 0, 0);
+	msleep(10);
+}
+
 /* Synaptics 06CB:7F8F Windows-Precision touchpad (Yoga 720-13IKB) on the
  * Sunrise Point-LP LPSS I2C0.  The HID descriptor is the standard 30-byte
  * HID-over-I2C block; report 3 is five 5-byte finger records (tip/confidence,
  * contact id, 16-bit X, 16-bit Y), then scan time, contact count and the
  * clickpad button. */
-static int probe_synaptics(unsigned int base)
+static int probe_synaptics(unsigned int base, unsigned int tries)
 {
 	unsigned char desc[TP_HID_DESC_LEN + 2];
 	unsigned char ack[2];
@@ -380,9 +405,6 @@ static int probe_synaptics(unsigned int base)
 		tp_err = "i2c init failed";
 		return 0;
 	}
-	/* The LPSS reset release at 0x204 clears the 0x200 clock gate, so
-	 * enable the functional clock after it. */
-	i2c_dw_clock_spt(base);
 	tp_base = base;
 	tp_addr = TP_SYN_ADDR;
 	if (!tp_dbg_seen) {
@@ -394,14 +416,20 @@ static int probe_synaptics(unsigned int base)
 	 * descriptor; only the report-descriptor stage powers the device on
 	 * and resets it.  Do the same, with a power-on/retry fallback for a
 	 * device left asleep by a previous OS. */
-	if (i2c_dw_transfer(base, tp_addr, 0, 0, ack, 1) != 0) {
+	/* The EC releases the touchpad once ideapad_os_ready() told it an
+	 * ACPI OS is running; give it up to a second on I2C0. */
+	while (i2c_dw_transfer(base, tp_addr, 0, 0, ack, 1) != 0) {
+		if (--tries) {
+			msleep(50);
+			continue;
+		}
 		tp_err = "no device at 0x2c";
 		tp_err_val = i2c_last_abort;
 		i2c_dw_dump(base);
 		return 0;
 	}
 	for (i = 0; i < 4; i++) {
-		if (hid_read_reg(tp_addr, TP_HID_DESC_REG, desc,
+		if (hid_read_reg(tp_addr, TP_SYN_DESC_REG, desc,
 				 sizeof(desc)) == 0)
 			break;
 		if (!tried_power) {
@@ -461,6 +489,12 @@ static int probe_synaptics(unsigned int base)
 	}
 	hid_write_reg(tp_addr, tp_cmd_reg, TP_CMD_WAKE);
 	msleep(60);
+	/* A Windows Precision Touchpad reports as a plain mouse (report 2)
+	 * until the host selects touchpad mode, like hid-multitouch's
+	 * mt_set_modes(): feature 4 Input Mode = 3, then feature 6 surface
+	 * and button switches on. */
+	syn_set_feature(get16(desc + off + 18), 4, 3);
+	syn_set_feature(get16(desc + off + 18), 6, 3);
 
 	tp_kind = TP_KIND_SYNAPTICS;
 	/* The Windows-Precision report uses the logical frame from its
@@ -578,7 +612,8 @@ int touchpad_init(void)
 			tp_dbg_seen = 1;
 			continue;
 		}
-		if (probe_synaptics(base))
+		if (probe_synaptics(base, k == 0 && ideapad_present() ?
+				    20 : 1))
 			return 1;
 		tp_dbg_seen = 1;
 	}
@@ -669,7 +704,9 @@ static int synaptics_decode(const unsigned char *buf, struct tpg_frame *f,
 		unsigned int f0 = buf[p];
 		int x, y;
 
-		if (!(f0 & 0x01))
+		/* Bit 0 is Confidence, bit 1 Tip Switch (usages 0x47, 0x42
+		 * in that order); a lift-off report keeps confidence set. */
+		if (!(f0 & 0x02))
 			continue;
 		x = (int)get16(buf + p + 1);
 		y = (int)get16(buf + p + 3);