Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp229388ybm; Thu, 28 May 2020 01:01:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpTMus9muV/d3ijjOF1R2vQnie+7EbQLbJf8pIccXv/PElmBkWbqwqAb4DiDJJ9LPeMNy8 X-Received: by 2002:a50:dac4:: with SMTP id s4mr1879914edj.84.1590652917767; Thu, 28 May 2020 01:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590652917; cv=none; d=google.com; s=arc-20160816; b=iCzosa2jwb9FbwgwNd6jCi+AYGC+r2SHYni5UvZNWljFQMBn7cL4b4/OwTEzTKaCxX J9WO6kV+fg9ofvfVbdbvK2eGc6RqrZvpkPfequ/yhlbkvOjoeU6VN0fmSalAVliRpZsI iXCA6gh1Z4vasw036TMV4cj1TK8IK8pMWuSBr3/3RYj7Eqv4imPxKyhKQf8a4RTCRTfM ZtAw99vOynphlINh+tEIuzOb48CaSJcsFxYLQU5t/5vV/N+Cyx5+g62wTe28BchttQXp w5BezNGEUZDQvauYCa+3E3IlID3iotF6R6igkhyi2yJIz7sY4kmfMl6gHt+qjvS+tn98 ZgVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=WPQ7FtZIHgynP/jgW2hiEsA74Zmed4vqo2nGrHU8CEw=; b=D1TFpBBmKawcKKeUrdrlh33+IionPVLt7WYo7RjAGq0RPnUh3NAJH+XGkQ24cxD9P+ rJBSmbylqNQO3Pl6ebUHfknLJx4Ce+iFrTCFxi+CD4V3f8AvZRP+L5BVZH1/SEYUUp4j oa3yYCoarShq4UqEbTKXaF2LhJCPLFiGKYTg/Nt6tNmQglWjEh90BYXwxLXBjTfTCPZC 4dlvrI3R01h8cKzSAYdEObQHuVtbTOjikXy2RZi0yu2xBsu0Zj0t0cxDWcQWy5BaLU8c bqKOPKVV5IqtcxFpIe6x0a/NxwWNlM1D9jmVraNuFI/aXyIdCgqfaWzk3FVamdvHhxYY aJaw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp7si4406823ejc.619.2020.05.28.01.01.34; Thu, 28 May 2020 01:01:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbgE1H7Q (ORCPT + 99 others); Thu, 28 May 2020 03:59:16 -0400 Received: from twhmllg4.macronix.com ([122.147.135.202]:31245 "EHLO TWHMLLG4.macronix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbgE1H7P (ORCPT ); Thu, 28 May 2020 03:59:15 -0400 Received: from localhost.localdomain ([172.17.195.96]) by TWHMLLG4.macronix.com with ESMTP id 04S7wMHi030973; Thu, 28 May 2020 15:58:30 +0800 (GMT-8) (envelope-from masonccyang@mxic.com.tw) From: Mason Yang To: broonie@kernel.org, tudor.ambarus@microchip.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, boris.brezillon@collabora.com, matthias.bgg@gmail.com Cc: p.yadav@ti.com, juliensu@mxic.com.tw, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, Mason Yang Subject: [PATCH v3 09/14] mtd: spi-nor: core: add configuration register 2 read & write support Date: Thu, 28 May 2020 15:58:11 +0800 Message-Id: <1590652696-8844-10-git-send-email-masonccyang@mxic.com.tw> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1590652696-8844-1-git-send-email-masonccyang@mxic.com.tw> References: <1590652696-8844-1-git-send-email-masonccyang@mxic.com.tw> X-MAIL: TWHMLLG4.macronix.com 04S7wMHi030973 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Configuration register 2 is to set the device operation condition like STR or DTR mode at address offset 0 and DQS mode at address offset 0x200. Each device has various address offset for it's specific operatoin setting. Signed-off-by: Mason Yang --- drivers/mtd/spi-nor/core.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/mtd/spi-nor/core.h | 2 ++ 2 files changed, 80 insertions(+) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 642e3c0..117d117 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -347,6 +347,84 @@ int spi_nor_write_disable(struct spi_nor *nor) } /** + * spi_nor_read_cr2() - Read the Configuration Register 2. + * @nor: pointer to 'struct spi_nor'. + * @addr: offset address to read. + * @cr2: pointer to a DMA-able buffer where the value of the + * Configuration Register 2 will be written. + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_read_cr2(struct spi_nor *nor, u32 addr, u8 *cr2) +{ + int ret; + u8 cmd = nor->params->rd_reg_cmd; + + if (nor->spimem) { + struct spi_mem_op op = + SPI_MEM_OP(SPI_MEM_OP_CMD(cmd, 1), + SPI_MEM_OP_ADDR(4, addr, 1), + SPI_MEM_OP_DUMMY(4, 1), + SPI_MEM_OP_DATA_IN(1, cr2, 1)); + + spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); + + ret = spi_mem_exec_op(nor->spimem, &op); + } else { + if (spi_nor_protocol_is_dtr(nor->reg_proto)) + ret = -ENOTSUPP; + else + ret = nor->controller_ops->read_reg(nor, cmd, cr2, 1); + } + + if (ret) + dev_dbg(nor->dev, "error %d reading CR2\n", ret); + + return ret; +} + +/** + * spi_nor_write_cr2() - Write the Configuration Register 2. + * @nor: pointer to 'struct spi_nor'. + * @addr: offset address to write. + * @cr2: pointer to a DMA-able buffer where the value of the + * Configuratin Register 2 will be read. + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_write_cr2(struct spi_nor *nor, u32 addr, u8 *cr2) +{ + int ret; + u8 cmd = nor->params->wr_reg_cmd; + + ret = spi_nor_write_enable(nor); + if (ret) + return ret; + + if (nor->spimem) { + struct spi_mem_op op = + SPI_MEM_OP(SPI_MEM_OP_CMD(cmd, 1), + SPI_MEM_OP_ADDR(4, addr, 1), + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_OUT(1, cr2, 1)); + + spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); + + ret = spi_mem_exec_op(nor->spimem, &op); + } else { + if (spi_nor_protocol_is_dtr(nor->reg_proto)) + ret = -ENOTSUPP; + else + ret = nor->controller_ops->write_reg(nor, cmd, cr2, 1); + } + + if (ret) + dev_dbg(nor->dev, "error %d write CFG Reg 2\n", ret); + + return ret; +} + +/** * spi_nor_read_sr() - Read the Status Register. * @nor: pointer to 'struct spi_nor'. * @sr: pointer to a DMA-able buffer where the value of the diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 101726c..91bc69a 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -438,6 +438,8 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor, const enum spi_nor_protocol proto); int spi_nor_write_enable(struct spi_nor *nor); int spi_nor_write_disable(struct spi_nor *nor); +int spi_nor_read_cr2(struct spi_nor *nor, u32 addr, u8 *cr2); +int spi_nor_write_cr2(struct spi_nor *nor, u32 addr, u8 *cr2); int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable); int spi_nor_write_ear(struct spi_nor *nor, u8 ear); int spi_nor_wait_till_ready(struct spi_nor *nor); -- 1.9.1