From patchwork Wed Dec 19 16:27:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot, U-Boot, v2, 4/6] sf: Add configuration register writing support Date: Wed, 19 Dec 2012 06:27:41 -0000 From: Jagannadha Sutradharudu Teki X-Patchwork-Id: 207455 Message-Id: <1355934463-24319-4-git-send-email-jagannadh.teki@gmail.com> To: u-boot@lists.denx.de This patch provides support to program a flash config register. Configuration register contains the control bits used to configure the different configurations and security features of a device. User need to set these bits through spi_flash_cmd_write_config() based on their usage. Signed-off-by: Jagannadha Sutradharudu Teki Tested-by: Jagannadha Sutradharudu Teki --- Changes in v2: Improved code logic drivers/mtd/spi/spi_flash.c | 35 ++++++++++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 3 ++ 2 files changed, 38 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index bf5ec4a..cad6c40 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -279,6 +279,41 @@ int spi_flash_cmd_read_status(struct spi_flash *flash, void *data) return 0; } +int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr) +{ + u8 data[2]; + u8 cmd; + int ret; + + ret = spi_flash_cmd_read_status(flash, (void *)&data[0]); + if (ret < 0) { + debug("SF: fail to read status register\n"); + return ret; + } + + ret = spi_flash_cmd_write_enable(flash); + if (ret < 0) { + debug("SF: enabling write failed\n"); + return ret; + } + + cmd = CMD_WRITE_STATUS; + data[1] = cr; + ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &data, 2); + if (ret) { + debug("SF: fail to write config register\n"); + return ret; + } + + ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT); + if (ret < 0) { + debug("SF: write config register timed out\n"); + return ret; + } + + return 0; +} + /* * The following table holds all device probe functions * diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 8232595..825b398 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -80,6 +80,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr); /* Read the status register */ int spi_flash_cmd_read_status(struct spi_flash *flash, void *data); +/* Program the config register. */ +int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr); + /* * Same as spi_flash_cmd_read() except it also claims/releases the SPI * bus. Used as common part of the ->read() operation.