From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jagan Teki Date: Wed, 2 Sep 2015 11:39:52 +0530 Subject: [U-Boot] [PATCH v3 08/13] sf: Add flash_read_reg support In-Reply-To: <1441174197-5096-1-git-send-email-jteki@openedev.com> References: <1441174197-5096-1-git-send-email-jteki@openedev.com> Message-ID: <1441174197-5096-9-git-send-email-jteki@openedev.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Generic function for all spi-flash register reads. Signed-off-by: Jagan Teki --- Changes for v3: - none Changes for v2: - none drivers/mtd/spi/sf.c | 23 +++++++++++++++++++++++ drivers/mtd/spi/sf_internal.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/mtd/spi/sf.c b/drivers/mtd/spi/sf.c index 664e860..cb36946 100644 --- a/drivers/mtd/spi/sf.c +++ b/drivers/mtd/spi/sf.c @@ -9,6 +9,7 @@ #include #include +#include static int spi_flash_read_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, @@ -56,3 +57,25 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, { return spi_flash_read_write(spi, cmd, cmd_len, data, NULL, data_len); } + +int flash_read_reg(struct spi_flash *flash, u8 cmd, u8 *val, int len) +{ + struct spi_slave *spi = flash->spi; + int ret; + + ret = spi_claim_bus(spi); + if (ret < 0) { + debug("SF: unable to claim SPI bus\n"); + return ret; + } + + ret = spi_flash_read_write(spi, &cmd, 1, NULL, val, len); + if (ret < 0) { + debug("SF: error %d reading register %x\n", ret, cmd); + return ret; + } + + spi_release_bus(spi); + + return ret; +} diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index 8a3e5ec..14b8b55 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -156,6 +156,9 @@ int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len); int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, void *data, size_t data_len); +/* Read flash register - common call for all flash register reads */ +int flash_read_reg(struct spi_flash *flash, u8 cmd, u8 *val, int len); + /* * Send a multi-byte command to the device followed by (optional) * data. Used for programming the flash array, etc. -- 1.9.1