From patchwork Fri Jun 14 12:18:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 1947888 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=M0TjBvu1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0yyR0D6zz20X9 for ; Fri, 14 Jun 2024 22:19:43 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DDECB889CF; Fri, 14 Jun 2024 14:19:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.b="M0TjBvu1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9965C889DC; Fri, 14 Jun 2024 14:19:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CF041889D2 for ; Fri, 14 Jun 2024 14:19:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=contact@jookia.org X-Envelope-To: jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1718367573; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HpXA2aS2NTssOXnHNMdzy7H/mieGuZZtMDIntKc1hz0=; b=M0TjBvu1n+g8rDisY8AoZp40jxTP+hECCE7/1z+WJH5EfmCT0ji2dHPwH9ZcZPTrw0x9Ml dZpuyuvgtX+BPQil/JuUrHhbOVAXKpbVuKtOIPeHT/CnNdzwakmPulyLt5Chjad4++uYEN p3G/ZcQ7DMr9ovcqQbGJi5ZHAnTccw10fTUMqEZFVW4K5QPaa8Xe+su/oNIcB1XG54mdoy AvrgJWrkfrAMB86X1xBo4tkVzJUOdLb7JH0dS/sRlmAc5TKy8xDN1EuEXnGw/BKL3RHaNj +qXIHkWA1ArSnTxRheXrXhgfb9oNKeDvpTx1sNHLE70diDwMoLkt7eUIXGhPJw== X-Envelope-To: agust@denx.de X-Envelope-To: u-boot@lists.denx.de X-Envelope-To: trini@konsulko.com X-Envelope-To: contact@jookia.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: John Watts Date: Fri, 14 Jun 2024 22:18:41 +1000 Subject: [PATCH 1/5] spi: Return old wordlen in spit_set_wordlen MIME-Version: 1.0 Message-Id: <20240614-mipi_dbi-v1-1-946eb82f8533@jookia.org> References: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> In-Reply-To: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> To: Jagan Teki , Tom Rini , Anatolij Gustschin Cc: u-boot@lists.denx.de, John Watts X-Developer-Signature: v=1; a=openssh-sha256; t=1718367536; l=1370; i=contact@jookia.org; h=from:subject:message-id; bh=IUmROq0U3IEa42gVai3F6LYhozMwfML6Dn97dCcmEvA=; b=U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgPs7MDd2XR g2uRE9caV1lPPPeu0VzIG9fPrrVmYyAhLcAAAAEc3NoOgAAAAZwYXRhdHQAAAAAAAAABnNoYTUx MgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAuogheZcotvyeyfEGtUEBZyP 0tLBadb07yXD7fGuaWXS81DOJm4OcbN51nlpSyuyLDbc6X+9iNNRmNVJd1pDiCQUAAP+P X-Developer-Key: i=contact@jookia.org; a=openssh; fpr=SHA256:/gEvgms/9HpbgpcH+K7O4GYXmqkP7siJx9zHeEWRZTg X-Migadu-Flow: FLOW_OUT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Return the current wordlen to the caller so they can restore it back when done. This is required to avoid clobbering the bus state. Signed-off-by: John Watts --- drivers/spi/spi.c | 4 +++- include/spi.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 22910de0dd..3649c9c25b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -10,6 +10,8 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) { + int oldwordlen = slave->wordlen; + if (wordlen == 0 || wordlen > 32) { printf("spi: invalid wordlen %u\n", wordlen); return -1; @@ -17,7 +19,7 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) slave->wordlen = wordlen; - return 0; + return oldwordlen; } void *spi_do_alloc_slave(int offset, int size, unsigned int bus, diff --git a/include/spi.h b/include/spi.h index 7e38cc2a2a..d5acf4f9e9 100644 --- a/include/spi.h +++ b/include/spi.h @@ -259,7 +259,7 @@ void spi_release_bus(struct spi_slave *slave); * @slave: The SPI slave * @wordlen: The number of bits in a word * - * Returns: 0 on success, -1 on failure. + * Returns: The old word length on success, -1 on failure. */ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen); From patchwork Fri Jun 14 12:18:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 1947889 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=o6y+qxjm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0yyc5vNDz20X9 for ; Fri, 14 Jun 2024 22:19:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 54C0A889D2; Fri, 14 Jun 2024 14:19:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.b="o6y+qxjm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD884889D8; Fri, 14 Jun 2024 14:19:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F1FC1889D2 for ; Fri, 14 Jun 2024 14:19:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=contact@jookia.org X-Envelope-To: jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1718367581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=emWWhDx0/VeL+rLlM4ue4RA7bpk2wRFBXDZ05MQiqwA=; b=o6y+qxjmsMsmtQ134AtamCh5RorsZftkF8Un2z/ijt5HZdbUScqnOpHPdGLgroWsfmmsOn h58idnD/Z/RDHdAAD6sTUAIYMjpPzHOC5ZKHk7CwaukLssbhyc+7iibGGLBHQhIh39kTn6 MQp8AoUelUJRBvbafvkq6lmHBe+Yy0CtgcSSinCKV5KfKviCO/iGjZIQ5VKt5OPJD1bmC0 0yUvm4YUW8rf42larMOCKHpGlOK5nfX62+llIsVcLuoLbghBpL/bUGZ3fUf5v0SgunqZKy 6vb/58Zdty/gczjGvwgPzrieC93qmigwYmT39Bk4XXCLOKnuAYojKukYO8ZJaA== X-Envelope-To: agust@denx.de X-Envelope-To: u-boot@lists.denx.de X-Envelope-To: trini@konsulko.com X-Envelope-To: contact@jookia.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: John Watts Date: Fri, 14 Jun 2024 22:18:42 +1000 Subject: [PATCH 2/5] spi: Limit spi_set_wordlen to SPI_DEFAULT_WORDLEN MIME-Version: 1.0 Message-Id: <20240614-mipi_dbi-v1-2-946eb82f8533@jookia.org> References: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> In-Reply-To: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> To: Jagan Teki , Tom Rini , Anatolij Gustschin Cc: u-boot@lists.denx.de, John Watts X-Developer-Signature: v=1; a=openssh-sha256; t=1718367539; l=692; i=contact@jookia.org; h=from:subject:message-id; bh=IjR2SlyUYvSw+pzu3vrAhstMW7aXu4RnvA2p8lD7ZS8=; b=U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgPs7MDd2XR g2uRE9caV1lPPPeu0VzIG9fPrrVmYyAhLcAAAAEc3NoOgAAAAZwYXRhdHQAAAAAAAAABnNoYTUx MgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAiRiBz30jfMOLdY4irMLi4rB KF3cJom5I5C7AGbFZdJ9KqU3JW7kqk7Xte3HoIYnMnkBj1s12sNb8WdPzBCv6AQUAAP+f X-Developer-Key: i=contact@jookia.org; a=openssh; fpr=SHA256:/gEvgms/9HpbgpcH+K7O4GYXmqkP7siJx9zHeEWRZTg X-Migadu-Flow: FLOW_OUT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean We have no way to tell if we can actually set the wordlen in non-DM code, so limit it to the default wordlen already in use. Signed-off-by: John Watts --- drivers/spi/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 3649c9c25b..7be9bf9b17 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -12,7 +12,7 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) { int oldwordlen = slave->wordlen; - if (wordlen == 0 || wordlen > 32) { + if (wordlen != SPI_DEFAULT_WORDLEN) { printf("spi: invalid wordlen %u\n", wordlen); return -1; } From patchwork Fri Jun 14 12:18:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 1947890 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=y0guYoHx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0yyq4hvcz20X9 for ; Fri, 14 Jun 2024 22:20:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B616B889D7; Fri, 14 Jun 2024 14:19:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.b="y0guYoHx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D968F889E3; Fri, 14 Jun 2024 14:19:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E5D7E889C5 for ; Fri, 14 Jun 2024 14:19:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=contact@jookia.org X-Envelope-To: jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1718367592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PdjQ/sNEYkqXz5nUiDB6l7pnOHwLgYY20k5O3F6c/1I=; b=y0guYoHxq0E28/b/BsaGXtMtxf/al4tF6Ld1GPENkclhRYMCLQkmfC2wpd2g+9IUVDYWN2 ILTyQnl/1PG4ipBymD+1Psj+vOAXgimeRRxDoSO3aE9kQ0GPK7f+pSS3jVEFJz3Jvr94/u IWu8AbtRjG14Z13+inzPwAK8mCkmLN2IQ7qX9QkBKfWNax00ZuV8GA3a9UmGBKr2s6khde zZSuT5cMTjZ8/wL7jTgY2Ab8Toa5vT0KVmvESK1+hdTDZKlmDAFFI5Ra/vcy8pQUcd5vYc Evc9l6BKc8IIjGyNDikb5t+oekVBT6A2q1CP9+KvW+wCHON7H/90EWmvQGRasA== X-Envelope-To: agust@denx.de X-Envelope-To: u-boot@lists.denx.de X-Envelope-To: trini@konsulko.com X-Envelope-To: contact@jookia.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: John Watts Date: Fri, 14 Jun 2024 22:18:43 +1000 Subject: [PATCH 3/5] spi: Implement spi_set_wordlen for driver model MIME-Version: 1.0 Message-Id: <20240614-mipi_dbi-v1-3-946eb82f8533@jookia.org> References: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> In-Reply-To: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> To: Jagan Teki , Tom Rini , Anatolij Gustschin Cc: u-boot@lists.denx.de, John Watts X-Developer-Signature: v=1; a=openssh-sha256; t=1718367546; l=1382; i=contact@jookia.org; h=from:subject:message-id; bh=I8RuEJ8g/cBh8hAckeVnNnUKcdafw1PPjrDVQFThuUk=; b=U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgPs7MDd2XR g2uRE9caV1lPPPeu0VzIG9fPrrVmYyAhLcAAAAEc3NoOgAAAAZwYXRhdHQAAAAAAAAABnNoYTUx MgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAYpUwJ3KhyWHIu5BglUcvyo9 46fPfU76riOOMp/j/EmDPCJ560X0GCEyNtGNWd1mBJr4vmgXTaOfCz9DX8eYACgUAAP+l X-Developer-Key: i=contact@jookia.org; a=openssh; fpr=SHA256:/gEvgms/9HpbgpcH+K7O4GYXmqkP7siJx9zHeEWRZTg X-Migadu-Flow: FLOW_OUT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement spi_set_wordlen for driver model devices. Not all drivers support this interface, so we will assume the default wordlen is safe and allow setting that unconditionally. Signed-off-by: John Watts --- drivers/spi/spi-uclass.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index f4795e6867..c2baf9a262 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -130,6 +130,35 @@ void spi_release_bus(struct spi_slave *slave) dm_spi_release_bus(slave->dev); } +static int spi_try_set_wordlen(struct spi_slave *slave, unsigned int wordlen) +{ + struct dm_spi_ops *ops; + + ops = spi_get_ops(slave->dev->parent); + if (ops->set_wordlen) + return ops->set_wordlen(slave->dev->parent, wordlen); + else if (wordlen == SPI_DEFAULT_WORDLEN) + return 0; + else + return -EINVAL; +} + +int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) +{ + int oldwordlen = slave->wordlen; + int ret; + + ret = spi_try_set_wordlen(slave, wordlen); + if (ret < 0) { + dev_err(slave->dev, "Cannot set wordlen (err=%d)\n", ret); + return ret; + } + + slave->wordlen = wordlen; + + return oldwordlen; +} + int spi_set_speed(struct spi_slave *slave, uint hz) { struct dm_spi_ops *ops; From patchwork Fri Jun 14 12:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 1947891 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=C6/pZtHB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0yz24hC4z20Pb for ; Fri, 14 Jun 2024 22:20:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41ADC889C5; Fri, 14 Jun 2024 14:20:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.b="C6/pZtHB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A975D86784; Fri, 14 Jun 2024 14:20:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C26F6889CD for ; Fri, 14 Jun 2024 14:19:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=contact@jookia.org X-Envelope-To: jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1718367599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nh98bDQEFpoNVCkl1wGgAwa0yRgYBuJCHqpg+Q097q0=; b=C6/pZtHBMDEJO1zu8regQPxynmrV6ecsV9jBq5ShpDJKT1+yf+8NfIwrja3n0D9ReUzofA 3IWeCD8U2nxgsKqLtZLSEIQFa7wnCvP/DJ6k9g6GakvO2nMXbPQ67ZOgsX8tnwrdoTWo20 JO6dXJxvqZRuxsfWwSZa9va+vf9mBJ0MWefgVe/5HOsSOg+mBh4Jx6R+yqjtZ2moRLLGq3 qGO1akIFoCKUHN6H7p7dd1XH1pobs6efMLVfL0Ol0YoJ7TLdCzcRfSNc03gtE1QKvPYqxw sljL6eHtADKjh02DWChIT9A9leHT8gKHUoMQPlh3nxYb8qfhtLkpp6bJvUA31g== X-Envelope-To: agust@denx.de X-Envelope-To: u-boot@lists.denx.de X-Envelope-To: trini@konsulko.com X-Envelope-To: contact@jookia.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: John Watts Date: Fri, 14 Jun 2024 22:18:44 +1000 Subject: [PATCH 4/5] spi: softspi: Support setting wordlen MIME-Version: 1.0 Message-Id: <20240614-mipi_dbi-v1-4-946eb82f8533@jookia.org> References: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> In-Reply-To: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> To: Jagan Teki , Tom Rini , Anatolij Gustschin Cc: u-boot@lists.denx.de, John Watts X-Developer-Signature: v=1; a=openssh-sha256; t=1718367549; l=1136; i=contact@jookia.org; h=from:subject:message-id; bh=LlOMILhhtJXcTwEWP8peUufBWk2IZMPYBZb1Mqq11vw=; b=U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgPs7MDd2XR g2uRE9caV1lPPPeu0VzIG9fPrrVmYyAhLcAAAAEc3NoOgAAAAZwYXRhdHQAAAAAAAAABnNoYTUx MgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAiW4fj06Q5RqThDYIdO9PN5a KDFOflPOgAv2dTGdY88nlfFRzff1rwa2FleA/MFiCdatcgXrfZYD6hhZXr68XCgUAAP+n X-Developer-Key: i=contact@jookia.org; a=openssh; fpr=SHA256:/gEvgms/9HpbgpcH+K7O4GYXmqkP7siJx9zHeEWRZTg X-Migadu-Flow: FLOW_OUT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The bit-banging soft SPI driver supports any word length, so just blindly return support for all of them. Signed-off-by: John Watts --- drivers/spi/soft_spi.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index 0fa14339bd..4f2161f0bf 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -204,6 +204,12 @@ static int soft_spi_xfer(struct udevice *dev, unsigned int bitlen, return 0; } +static int soft_spi_set_wordlen(struct udevice *dev, unsigned int wordlen) +{ + /* Support any wordlen as this driver clock out bits individually. */ + return 0; +} + static int soft_spi_set_speed(struct udevice *dev, unsigned int speed) { /* Ignore any speed settings. Speed is implemented via "spi-delay-us" */ @@ -223,6 +229,7 @@ static const struct dm_spi_ops soft_spi_ops = { .claim_bus = soft_spi_claim_bus, .release_bus = soft_spi_release_bus, .xfer = soft_spi_xfer, + .set_wordlen = soft_spi_set_wordlen, .set_speed = soft_spi_set_speed, .set_mode = soft_spi_set_mode, }; From patchwork Fri Jun 14 12:18:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 1947892 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=DGQVjknL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0yzD4zDdz20Pb for ; Fri, 14 Jun 2024 22:20:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E6B39889CD; Fri, 14 Jun 2024 14:20:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=jookia.org header.i=@jookia.org header.b="DGQVjknL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BDB1386784; Fri, 14 Jun 2024 14:20:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E56CB889FB for ; Fri, 14 Jun 2024 14:20:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=jookia.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=contact@jookia.org X-Envelope-To: jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1718367606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3nceZEU6XG+W2vq8G+kvamKDSmxkG76T7GJPifojXw4=; b=DGQVjknL7FGKR2hKY8QqTRePxl6a+NWfCMfMM5hjwuT2W5SscStnjOPCjIgkjUczEHFmdP 6V/nxdEbNtkr52IPDXTTSYGoj0F4o5oPk4/iqDihnlhf95zS/AvPuSSGwAk2uKyJoxBUnx x7Z9RqPjPQDQkQcUbjYvAlLbUglDxFmFxbBu9WtcwjxHpsHrms+Xwx7Ayc+pkd6yeVUwhz Acw7K7qpeDsjTHRDSdP91iAQk1g9dYMGmOY0N73I3YkH6qFbifNeWs0SVAOp0NyW11Xwje GwuqCSMu0PO1bBBqNLkrWVK7a0UGSdkmxkFzMHD8AhfsNl/69dX+PO2muE++QQ== X-Envelope-To: agust@denx.de X-Envelope-To: u-boot@lists.denx.de X-Envelope-To: trini@konsulko.com X-Envelope-To: contact@jookia.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: John Watts Date: Fri, 14 Jun 2024 22:18:45 +1000 Subject: [PATCH 5/5] video: add support for MIPI DBI interface MIME-Version: 1.0 Message-Id: <20240614-mipi_dbi-v1-5-946eb82f8533@jookia.org> References: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> In-Reply-To: <20240614-mipi_dbi-v1-0-946eb82f8533@jookia.org> To: Jagan Teki , Tom Rini , Anatolij Gustschin Cc: u-boot@lists.denx.de, John Watts X-Developer-Signature: v=1; a=openssh-sha256; t=1718367553; l=5303; i=contact@jookia.org; h=from:subject:message-id; bh=rsfDi51M3wXU8ZdhxUYVk/XVGRQ21hIPBjIrpZ+jSV4=; b=U1NIU0lHAAAAAQAAAEoAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAAAgPs7MDd2XR g2uRE9caV1lPPPeu0VzIG9fPrrVmYyAhLcAAAAEc3NoOgAAAAZwYXRhdHQAAAAAAAAABnNoYTUx MgAAAGcAAAAac2stc3NoLWVkMjU1MTlAb3BlbnNzaC5jb20AAABAXXy2POTYTWIfHkCoOKnCUn9 u2xWDpF5d7M6u0u4UWSURBdDMxI5hcrH6CfRGILYvpkxG1psTCZfCpDgmvadlDgUAAP+1 X-Developer-Key: i=contact@jookia.org; a=openssh; fpr=SHA256:/gEvgms/9HpbgpcH+K7O4GYXmqkP7siJx9zHeEWRZTg X-Migadu-Flow: FLOW_OUT X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This interface supports sending MIPI commands over an SPI bus. This driver only implements the Type C1 protocol for now. Signed-off-by: John Watts --- drivers/video/Kconfig | 6 ++++ drivers/video/Makefile | 1 + drivers/video/mipi_dbi.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ include/mipi_dbi.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+) diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 7808ae7919..e9d069d440 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -157,6 +157,12 @@ config VIDEO_MIPI_DSI The MIPI Display Serial Interface (MIPI DSI) defines a high-speed serial interface between a host processor and a display module. +config VIDEO_MIPI_DBI + bool "Support MIPI DBI interface" + help + Support MIPI DBI interface for driving a MIPI compatible device + over a SPI interface. + config CONSOLE_NORMAL bool "Support a simple text console" default y diff --git a/drivers/video/Makefile b/drivers/video/Makefile index f3f70cd04a..ad77c60973 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -69,6 +69,7 @@ obj-$(CONFIG_VIDEO_LCD_TDO_TL070WSH30) += tdo-tl070wsh30.o obj-$(CONFIG_VIDEO_MCDE_SIMPLE) += mcde_simple.o obj-${CONFIG_VIDEO_MESON} += meson/ obj-${CONFIG_VIDEO_MIPI_DSI} += mipi_dsi.o +obj-${CONFIG_VIDEO_MIPI_DBI} += mipi_dbi.o obj-$(CONFIG_VIDEO_MVEBU) += mvebu_lcd.o obj-$(CONFIG_VIDEO_MXS) += mxsfb.o videomodes.o obj-$(CONFIG_VIDEO_NX) += nexell_display.o videomodes.o nexell/ diff --git a/drivers/video/mipi_dbi.c b/drivers/video/mipi_dbi.c new file mode 100644 index 0000000000..d7457bb6e2 --- /dev/null +++ b/drivers/video/mipi_dbi.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * MIPI DBI Bus support + * + * Copyright 2024 John Watts + */ + +#include + +int mipi_dbi_spi_init(struct spi_slave *slave, struct mipi_dbi *dbi, + struct gpio_desc *dc) +{ + /* D/C GPIO isn't supported yet */ + if (dc) + return -1; + + dbi->spi = slave; + + return 0; +} + +int mipi_dbi_xfer(struct mipi_dbi *dbi, u8 data, int pos, int len) +{ + struct spi_slave *spi = dbi->spi; + bool is_data = (pos != 0); + int flags = 0; + u8 buf[2]; + + /* Mimic Linux's behaviour of pulling CS active each word */ + flags |= SPI_XFER_ONCE; + + buf[0] = (is_data ? 0x80 : 0x00) | (data >> 1); + buf[1] = ((data & 0x1) << 7); + + return spi_xfer(spi, 9, &buf, NULL, flags); +} + +int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, const u8 *data, size_t len) +{ + struct spi_slave *spi = dbi->spi; + int wordlen; + int retval = -1; + + if (spi_claim_bus(spi)) + return -1; + + wordlen = spi_set_wordlen(spi, 9); + if (wordlen == -1) + goto done; + + if (mipi_dbi_xfer(dbi, cmd, 0, len) != 0) + goto done; + + for (int i = 1; i <= len; ++i) { + u8 dat = data[i - 1]; + + if (mipi_dbi_xfer(dbi, dat, i, len) != 0) + goto done; + } + + retval = 0; + +done: + if (wordlen != -1) + spi_set_wordlen(spi, wordlen); + + spi_release_bus(spi); + + return retval; +} diff --git a/include/mipi_dbi.h b/include/mipi_dbi.h new file mode 100644 index 0000000000..1c0c21ba81 --- /dev/null +++ b/include/mipi_dbi.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * MIPI DBI Bus support + * + * Copyright 2024 John Watts + */ +#ifndef MIPI_DBI_H +#define MIPI_DBI_H + +#include +#include +#include + +/** + * struct mipi_dbi - MIPI DBI bus info + * + * This contains information about a MIPI DBI bus. + * Use mipi_dbi_spi_init to create and initialize this structure. + * + * @spi: SPI slave this bus operates on. + */ +struct mipi_dbi { + struct spi_slave *spi; +}; + +/** + * mipi_dbi_spi_init - Creates a new MIPI DBI bus + * + * Creates and sets up a 'struct mipi_dbi' using the provided SPI slave + * and optional D/C GPIO. + * + * @slave: SPI slave the bus is on + * @dbi: Destination mipi_dbi structure to initialize + * @dc: D/C GPIO (NULL if unused) + * + * Returns: 0 on success, -1 on failure. + */ +int mipi_dbi_spi_init(struct spi_slave *slave, struct mipi_dbi *dbi, + struct gpio_desc *dc); + +/** + * mipi_dbi_command_buf - Sends a command and data over the bus + * + * Sends a command and any optional data over a bus. + * + * @dbi: MIPI DBI bus to use + * @cmd: MIPI DBI command + * @data: Command data (NULL if len is 0) + * @len: Length of data in bytes + * + * Returns: 0 on success, -1 on failure. + */ +int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, const u8 *data, size_t len); + +/** + * mipi_dbi_command - Sends a command and data sequence over the bus + * + * Sends a command and any optional data over a bus. + * The data is a variadic sequence. + * + * @dbi: MIPI DBI bus to use + * @cmd: MIPI DBI command + * @seq: Command data bytes + * + * Returns: 0 on success, -1 on failure. + */ +#define mipi_dbi_command(dbi, cmd, seq...) \ +({ \ + const u8 data[] = { seq }; \ + mipi_dbi_command_buf(dbi, cmd, data, ARRAY_SIZE(data)); \ +}) + +#endif /* MIPI_DBI_H */