From nobody Thu Jun 27 10:33:17 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W8vzd2SZcz5PQjF; Thu, 27 Jun 2024 10:33:17 +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 4W8vzd1xZmz4gLd; Thu, 27 Jun 2024 10:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719484397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=icfO/pSFzaCr0bYL5TQegoxvhUolGKXh02cELuKK7g4=; b=q5NSQBOaclCd25xWp5vs7KAcQiNtGjMHSXKKT4kWJfRuq3uiBbt+A15dLB8geljdccCxSM DkEofN7fMY6raI3z551ywrdk0lr9vxTF8vCIKeTBMESgMRQveOUyoneBBoiO81wwuelolc E87v57aBlvS+tAYnjkAIY9dqpkiS051IGkpJ9WR0vxxX9/NacejxzOyZY1s7YKUsqywnta c6o2W57FdMgwKDPNPafv1C+4TSs+I0/uYdqVv5hDmhtnbLfISw6RyM/DyXWFf8zWNCiOso B4gQd7p2GqREDe7gC/mb1tcXAwlTsTXMoKJcexU0zEYG34khjLTuGufK5smq2A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719484397; a=rsa-sha256; cv=none; b=PlWPG19MmXbehB95Y7/QuziHuLlKPBY4yGk+Sj9+6mJr7JR4TJi6+wMJL4/mp5nJ/GiHap xODcRKZVuoEEFahtGMCBgB0tAOB/6gMK74BSsXhG/bAh8kDEvjHcO+tBK6LwXGT1AGHrQc YqRarJd2vZ7S9Y5xzOIN/Rw9G4vDihYHEnBCL6oDjnLuznzbgUMdF/uVuAeaE9Tlf0FBvm wF5O6m6XbOvKN6aerxcls/zx8boAiZpItXLXwOsC5lngFzFvbpIV/uvqV1B8JEvR4OscZ7 mNf0FGqfPxWLdjtqLpNl8w8TqVqn7jO39yHhCOissZbAs06DHQbY/oxfwZlC2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719484397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=icfO/pSFzaCr0bYL5TQegoxvhUolGKXh02cELuKK7g4=; b=K+tLz4vqXfwG2FjbZxwi9q7SRpTYtdtgvRiBCXtOAFpPA8vcnRaXBIwCZ/7HylDS6I+OlS j/uRdN28haPR1wl+gbj4jFx1au7wqzdm+hEgPTg/jOv1w8dxrwwUpbUhHaW/UT3RDMxwGs t5dbjYzcNsGZ7rlSrbZXoVbtQkSlIeeNsnzCH/AIt4kc4ik9eyNtUXTyD2Gihcfu0cvSig WQ9dSjQ4HxJMO9fu9d7qbyyaWE7+Ub8xaIftt/336LKjx/f27PoLUUrQF5cNTg0lBnRAvq 5P3Om0/KWtoYEQwUsKbwhac0DKpTO5AZDxeKIT3tQHdeaPZyhsD7+8s7MLNPog== 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 4W8vzd1QR4z1Nvx; Thu, 27 Jun 2024 10:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45RAXHZX079149; Thu, 27 Jun 2024 10:33:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45RAXHqX079145; Thu, 27 Jun 2024 10:33:17 GMT (envelope-from git) Date: Thu, 27 Jun 2024 10:33:17 GMT Message-Id: <202406271033.45RAXHqX079145@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 0deaf4be346f - main - rk_i2c: emulate repeated start List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0deaf4be346f7f343bd2cf771bbf5d172d1c0d2a Auto-Submitted: auto-generated The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=0deaf4be346f7f343bd2cf771bbf5d172d1c0d2a commit 0deaf4be346f7f343bd2cf771bbf5d172d1c0d2a Author: Andriy Gapon AuthorDate: 2024-06-27 07:40:22 +0000 Commit: Andriy Gapon CommitDate: 2024-06-27 10:32:15 +0000 rk_i2c: emulate repeated start rk_i2c_send_stop is modified so that it sends a stop condition, like it always did, if there is no IIC_M_NOSTOP flag. But if the flag is set then the function completely resets the control register and sets the driver state to transfer completed. Something like this was previously done for a write with IIC_M_NOSTOP. Now it is done for a read with IIC_M_NOSTOP as well. Linux code says that the hardware does not support the repeated start condition and the documentation, indeed, does not mention it. But according to the Linux driver clearing the control register and then sending a start condition acts as if it were a repeated start. While here, add braces around a single-line 'if' branch to balance it with a multi-line 'else' branch. Tested with max44009(4). MFC after: 2 weeks --- sys/dev/iicbus/controller/rockchip/rk_i2c.c | 34 +++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/sys/dev/iicbus/controller/rockchip/rk_i2c.c b/sys/dev/iicbus/controller/rockchip/rk_i2c.c index 4a431649de49..9f2a98bcea12 100644 --- a/sys/dev/iicbus/controller/rockchip/rk_i2c.c +++ b/sys/dev/iicbus/controller/rockchip/rk_i2c.c @@ -281,13 +281,26 @@ rk_i2c_send_stop(struct rk_i2c_softc *sc) { uint32_t reg; - RK_I2C_WRITE(sc, RK_I2C_IEN, RK_I2C_IEN_STOPIEN); + if (!(sc->msg->flags & IIC_M_NOSTOP)) { + RK_I2C_WRITE(sc, RK_I2C_IEN, RK_I2C_IEN_STOPIEN); - sc->state = STATE_STOP; + sc->state = STATE_STOP; - reg = RK_I2C_READ(sc, RK_I2C_CON); - reg |= RK_I2C_CON_STOP; - RK_I2C_WRITE(sc, RK_I2C_CON, reg); + reg = RK_I2C_READ(sc, RK_I2C_CON); + reg |= RK_I2C_CON_STOP; + RK_I2C_WRITE(sc, RK_I2C_CON, reg); + } else { + /* + * Do not actually set stop bit, set up conditions to + * emulate repeated start by clearing all state. + */ + sc->state = STATE_IDLE; + sc->transfer_done = 1; + + reg = RK_I2C_READ(sc, RK_I2C_CON); + reg &= ~RK_I2C_CON_CTRL_MASK; + RK_I2C_WRITE(sc, RK_I2C_CON, reg); + } } static void @@ -350,9 +363,9 @@ rk_i2c_intr_locked(struct rk_i2c_softc *sc) case STATE_READ: rk_i2c_drain_rx(sc); - if (sc->cnt == sc->msg->len) + if (sc->cnt == sc->msg->len) { rk_i2c_send_stop(sc); - else { + } else { sc->mode = RK_I2C_CON_MODE_RX; reg = RK_I2C_READ(sc, RK_I2C_CON) & \ ~RK_I2C_CON_CTRL_MASK; @@ -369,7 +382,6 @@ rk_i2c_intr_locked(struct rk_i2c_softc *sc) RK_I2C_WRITE(sc, RK_I2C_CON, reg); RK_I2C_WRITE(sc, RK_I2C_MRXCNT, transfer_len); } - break; case STATE_WRITE: if (sc->cnt < sc->msg->len) { @@ -378,12 +390,10 @@ rk_i2c_intr_locked(struct rk_i2c_softc *sc) RK_I2C_IEN_NAKRCVIEN); transfer_len = rk_i2c_fill_tx(sc); RK_I2C_WRITE(sc, RK_I2C_MTXCNT, transfer_len); - break; - } else if (!(sc->msg->flags & IIC_M_NOSTOP)) { + } else { rk_i2c_send_stop(sc); - break; } - /* passthru */ + break; case STATE_STOP: /* Disable stop bit */ reg = RK_I2C_READ(sc, RK_I2C_CON);