Received: by 2002:a25:1104:0:0:0:0:0 with SMTP id 4csp147535ybr; Fri, 22 May 2020 03:15:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0lSQJYXdI1LI8Dbh6/sC7WWti0N/nKNN+VdGYEZIvY04rMSLpvt0/L8ZwVS+yZb94MMkH X-Received: by 2002:a17:906:7c59:: with SMTP id g25mr7678728ejp.393.1590142548914; Fri, 22 May 2020 03:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590142548; cv=none; d=google.com; s=arc-20160816; b=RjHStVpdQP0iDORhOiDH00HeAW4LKIBwiNOVXtSE/A+4ewINAnd6WsOOHLgMutpJwn cl3Bho6M9A70ulALzBJ2pVjRLlTOjmaPk7dbj/PLntqiTN+NAF8MneCP3+L+z+CCl+ER YCL3Tvq1k3d/Yr3F03PpuV1rnkKZMkID8lXYeOPgYfU9Lzfr0MbiB+SBuHL6HBU9N5mT TkFTmNED/i0+88Y4XdtwgsXEAqUYGEsPjJODKWwxEag0ZfndTAoZSHAYfOJqokpiTJn/ Fl6yI8tvTtYwvYw7VQ+Dsj5SP5qd0krQBU/1nEiH8QL+vrWzcGe9hjyjfXvxvthpj4kX JCgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oT/wzRt5tcDLs2tHXZFon7HN6JCAyNcgvVf1sZG+Lus=; b=Lqu/pkuiU2mHjQzkMGl5mTxpysjNDF6FiO2CWiINUeRqLoX34Y2db3CLK6w1ZB0mLX KSCKdnqGu61thKSj5/AaHoX4N68G05Q6ZfnOHGLWStm4GTTkQcQk90sH9MpZXgTU60Ru bwxOv/Ber8Cn+aTPWbgQ0yJRu5kYuyxHjea1zZ3ZVUhOlu7leKcx921/K9bUG2t3Kr0q JqCTGvOeIK8gMhJ4dWoii3IlkmYjgyhB3RJzirYpgELnelda1vAJtpkKlI/OPV/OxPRE JqiJPBsLIJJ1P2ixUraicf0n5iSo26b7X6+UfbUkXhOGc7RY71ZuQOlIO2zoYffaEuls +YLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=b+HtBS9v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si4551896edi.43.2020.05.22.03.15.25; Fri, 22 May 2020 03:15:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=b+HtBS9v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728698AbgEVKNj (ORCPT + 99 others); Fri, 22 May 2020 06:13:39 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:58906 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728592AbgEVKNi (ORCPT ); Fri, 22 May 2020 06:13:38 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04MADIKv008976; Fri, 22 May 2020 05:13:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1590142398; bh=oT/wzRt5tcDLs2tHXZFon7HN6JCAyNcgvVf1sZG+Lus=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=b+HtBS9vWLINtp5CvanMgZAQtDci3udipuzCdtrjOwgSe06CSj4EJar+2rV1lJT48 06LgFtUkQrGy/p1TNrPXtShxP77rTnIlK0WjBZsJukC2QsQ8SwOkDkHPEvsKTM5nUb pFlIjZ4qWPJbeTmcKL5qibsqkJLC0gtuc2xyYNwM= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04MADIOp048226; Fri, 22 May 2020 05:13:18 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 22 May 2020 05:13:17 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Fri, 22 May 2020 05:13:17 -0500 Received: from pratyush-OptiPlex-790.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04MAD1a3041179; Fri, 22 May 2020 05:13:13 -0500 From: Pratyush Yadav To: Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mark Brown , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , Matthias Brugger , , , , , CC: Pratyush Yadav , Sekhar Nori , Boris Brezillon , Mason Yang Subject: [PATCH v7 02/20] spi: spi-mem: allow specifying a command's extension Date: Fri, 22 May 2020 15:42:43 +0530 Message-ID: <20200522101301.26909-3-p.yadav@ti.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200522101301.26909-1-p.yadav@ti.com> References: <20200522101301.26909-1-p.yadav@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In xSPI mode, flashes expect 2-byte opcodes. The second byte is called the "command extension". There can be 3 types of extensions in xSPI: repeat, invert, and hex. When the extension type is "repeat", the same opcode is sent twice. When it is "invert", the second byte is the inverse of the opcode. When it is "hex" an additional opcode byte based is sent with the command whose value can be anything. So, make opcode a 16-bit value and add a 'nbytes', similar to how multiple address widths are handled. Signed-off-by: Pratyush Yadav --- drivers/spi/spi-mem.c | 5 ++++- include/linux/spi/spi-mem.h | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index 93e255287ab9..29dcd1d62710 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -159,6 +159,9 @@ bool spi_mem_default_supports_op(struct spi_mem *mem, if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr) return false; + if (op->cmd.nbytes != 1) + return false; + return true; } EXPORT_SYMBOL_GPL(spi_mem_default_supports_op); @@ -173,7 +176,7 @@ static bool spi_mem_buswidth_is_valid(u8 buswidth) static int spi_mem_check_op(const struct spi_mem_op *op) { - if (!op->cmd.buswidth) + if (!op->cmd.buswidth || !op->cmd.nbytes) return -EINVAL; if ((op->addr.nbytes && !op->addr.buswidth) || diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h index e3dcb956bf61..159463cc659c 100644 --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h @@ -17,6 +17,7 @@ { \ .buswidth = __buswidth, \ .opcode = __opcode, \ + .nbytes = 1, \ } #define SPI_MEM_OP_ADDR(__nbytes, __val, __buswidth) \ @@ -69,6 +70,8 @@ enum spi_mem_data_dir { /** * struct spi_mem_op - describes a SPI memory operation + * @cmd.nbytes: number of opcode bytes (only 1 or 2 are valid). The opcode is + * sent MSB-first. * @cmd.buswidth: number of IO lines used to transmit the command * @cmd.opcode: operation opcode * @cmd.dtr: whether the command opcode should be sent in DTR mode or not @@ -94,9 +97,10 @@ enum spi_mem_data_dir { */ struct spi_mem_op { struct { + u8 nbytes; u8 buswidth; u8 dtr : 1; - u8 opcode; + u16 opcode; } cmd; struct { -- 2.26.2