From owner-dev-commits-src-main@freebsd.org Mon May 31 19:35:39 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 821A364DBD9; Mon, 31 May 2021 19:35:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fv59l3KpCz4lFv; Mon, 31 May 2021 19:35:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5B37D15D60; Mon, 31 May 2021 19:35:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14VJZdwd058496; Mon, 31 May 2021 19:35:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14VJZdjk058495; Mon, 31 May 2021 19:35:39 GMT (envelope-from git) Date: Mon, 31 May 2021 19:35:39 GMT Message-Id: <202105311935.14VJZdjk058495@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 5236888db771 - main - iichid(4): disable interrupt on suspend MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5236888db77194c194706b122675af7355fe7ceb Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2021 19:35:39 -0000 The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=5236888db77194c194706b122675af7355fe7ceb commit 5236888db77194c194706b122675af7355fe7ceb Author: J.R. Oldroyd AuthorDate: 2021-05-31 19:33:07 +0000 Commit: Vladimir Kondratyev CommitDate: 2021-05-31 19:33:07 +0000 iichid(4): disable interrupt on suspend Commit message of the identical change in Linux driver says: "When an I2C HID device is powered off during system sleep, as a result of removing its power resources (by the ACPI core) the interrupt line might go low as well. This results inadvertent interrupts." This change fixes suspend/resume on Asus S510UQ laptops. While here add a couple of typo fixes as well as a slight change to the iichid_attach() code to have the power_on flag set properly. Submitted by: J.R. Oldroyd Reviewed by: wulf MFC after: 1 week --- sys/dev/iicbus/iichid.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c index 7c51a697c4c7..68d7cfd9090f 100644 --- a/sys/dev/iicbus/iichid.c +++ b/sys/dev/iicbus/iichid.c @@ -573,7 +573,7 @@ iichid_intr(void *context) * not allowed and often returns a garbage. If a HOST needs to * communicate with the DEVICE it MUST issue a SET POWER command * (to ON) before any other command. As some hardware requires reads to - * acknoledge interrupts we fetch only length header and discard it. + * acknowledge interrupts we fetch only length header and discard it. */ maxlen = sc->power_on ? sc->intr_bufsize : 0; error = iichid_cmd_read(sc, sc->intr_buf, maxlen, &actual); @@ -1069,14 +1069,16 @@ iichid_attach(device_t dev) error = iichid_reset(sc); if (error) { device_printf(dev, "failed to reset hardware: %d\n", error); - return (ENXIO); + error = ENXIO; + goto done; } - sc->power_on = false; + sc->power_on = true; + #ifdef IICHID_SAMPLING TASK_INIT(&sc->event_task, 0, iichid_event_task, sc); /* taskqueue_create can't fail with M_WAITOK mflag passed. */ - sc->taskqueue = taskqueue_create("hmt_tq", M_WAITOK | M_ZERO, + sc->taskqueue = taskqueue_create("iichid_tq", M_WAITOK | M_ZERO, taskqueue_thread_enqueue, &sc->taskqueue); TIMEOUT_TASK_INIT(sc->taskqueue, &sc->periodic_task, 0, iichid_event_task, sc); @@ -1144,8 +1146,10 @@ iichid_attach(device_t dev) device_printf(dev, "failed to attach child: error %d\n", error); iichid_detach(dev); } + done: (void)iichid_set_power(sc, I2C_HID_POWER_OFF); + sc->power_on = false; return (error); } @@ -1178,21 +1182,27 @@ iichid_suspend(device_t dev) int error; sc = device_get_softc(dev); - DPRINTF(sc, "Suspend called, setting device to power_state 1\n"); (void)bus_generic_suspend(dev); +#ifdef IICHID_SAMPLING + if (sc->sampling_rate_slow < 0) +#endif + (void)bus_generic_suspend_intr(device_get_parent(dev), dev, + sc->irq_res); + /* * 8.2 - The HOST is going into a deep power optimized state and wishes * to put all the devices into a low power state also. The HOST * is recommended to issue a HIPO command to the DEVICE to force * the DEVICE in to a lower power state. */ + DPRINTF(sc, "Suspend called, setting device to power_state 1\n"); error = iichid_set_power_state(sc, IICHID_PS_NULL, IICHID_PS_OFF); if (error != 0) DPRINTF(sc, "Could not set power_state, error: %d\n", error); else DPRINTF(sc, "Successfully set power_state\n"); - return (0); + return (0); } static int @@ -1209,6 +1219,11 @@ iichid_resume(device_t dev) else DPRINTF(sc, "Successfully set power_state\n"); (void)bus_generic_resume(dev); +#ifdef IICHID_SAMPLING + if (sc->sampling_rate_slow < 0) +#endif + (void)bus_generic_resume_intr(device_get_parent(dev), dev, + sc->irq_res); return (0); }