From patchwork Fri Dec 20 11:44:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1214028 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.b="nz0+e41G"; dkim-atps=neutral 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47fRkf4gzVz9sPc for ; Fri, 20 Dec 2019 22:45:13 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B52E6815DC; Fri, 20 Dec 2019 12:45:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1576842307; bh=+2MshTzZne5hMkrPPi7KsVdD8gROWH71vfGLqrJYshE=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Cc:From; b=nz0+e41GoisHQdsSUOuFz6fNMTeanUSDtvtyqkjClLesLViDLFqm5cUcSzF/74cAH u6PkVKEbCj3Jk1InCBS3LAAS6FigGiObJ56hfDB/DdMbsWYtspx8dTItBRGUp4DsWJ hhre31Z6bgeORg2x8UZmf+Sjkl5qWW2S2iWXegqgtajqV+bHnRyuJtHc8t4mcH1reC 50L+PD2y8eGW86st5cmRpQCcDs0lPl7OF5w1slTRdRQLMWP0JerowBePlXy0ummsss opyBGZCqGT7UHZfdmlkNhJutYxk/8OvbEqVBKyBw6obJQ0IdPnuN4Iq8uEISCR1mLs 1VetSzapN2Ffw== Received: by phobos.denx.de (Postfix, from userid 109) id C2577814DE; Fri, 20 Dec 2019 12:45:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 56CCD814DE for ; Fri, 20 Dec 2019 12:45:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=marex@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 47fRkN6qvyz1rQBt; Fri, 20 Dec 2019 12:45:00 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 47fRkN6ZCFz1rYZR; Fri, 20 Dec 2019 12:45:00 +0100 (CET) Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id nllA3DB1BhZD; Fri, 20 Dec 2019 12:44:59 +0100 (CET) X-Auth-Info: dLK6YiGILlcwTWfuIK/f/JUpskEdI6pW0t2Hcj1Abcw= Received: from desktop.lan (ip-86-49-35-8.net.upcbroadband.cz [86.49.35.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 20 Dec 2019 12:44:59 +0100 (CET) From: Marek Vasut To: u-boot@lists.denx.de Subject: [PATCH] cmd: spi: Permit setting bus frequency Date: Fri, 20 Dec 2019 12:44:57 +0100 Message-Id: <20191220114457.3235630-1-marex@denx.de> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Tom Rini Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean The 'sspi' command hard-coded 1 MHz bus frequency for all transmissions. Allow changing that at runtime by specifying '@freq' bus frequency in Hz. Signed-off-by: Marek Vasut Cc: Tom Rini Reviewed-by: Lukasz Majewski --- cmd/spi.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/spi.c b/cmd/spi.c index 75226fd368..bfa185b6ae 100644 --- a/cmd/spi.c +++ b/cmd/spi.c @@ -28,6 +28,7 @@ static unsigned int bus; static unsigned int cs; static unsigned int mode; +static unsigned int freq; static int bitlen; static uchar dout[MAX_SPI_BYTES]; static uchar din[MAX_SPI_BYTES]; @@ -45,12 +46,12 @@ static int do_spi_xfer(int bus, int cs) str = strdup(name); if (!str) return -ENOMEM; - ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv", + ret = spi_get_bus_and_cs(bus, cs, freq, mode, "spi_generic_drv", str, &dev, &slave); if (ret) return ret; #else - slave = spi_setup_slave(bus, cs, 1000000, mode); + slave = spi_setup_slave(bus, cs, freq, mode); if (!slave) { printf("Invalid device %d:%d\n", bus, cs); return -EINVAL; @@ -106,6 +107,8 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * We use the last specified parameters, unless new ones are * entered. */ + if (freq == 0) + freq = 1000000; if ((flag & CMD_FLAG_REPEAT) == 0) { @@ -119,7 +122,9 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) bus = CONFIG_DEFAULT_SPI_BUS; } if (*cp == '.') - mode = simple_strtoul(cp+1, NULL, 10); + mode = simple_strtoul(cp+1, &cp, 10); + if (*cp == '@') + freq = simple_strtoul(cp+1, &cp, 10); } if (argc >= 3) bitlen = simple_strtoul(argv[2], NULL, 10); @@ -159,10 +164,11 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) U_BOOT_CMD( sspi, 5, 1, do_spi, "SPI utility command", - "[:][.] - Send and receive bits\n" + "[:][.][@] - Send and receive bits\n" " - Identifies the SPI bus\n" " - Identifies the chip select\n" " - Identifies the SPI mode to use\n" + " - Identifies the SPI bus frequency in Hz\n" " - Number of bits to send (base 10)\n" " - Hexadecimal string that gets sent" );