[U-Boot] [U-Boot, v2 4/6] sf: Add configuration register writing support
Jagan Teki
jagannadh.teki at gmail.com
Sun Dec 23 18:52:26 CET 2012
Tested on real hardware, works fine.
Tested-by: Jagannadha Sutradharudu Teki <jagannadh.teki at gmail.com>
Thanks,
Jagan.
On Wed, Dec 19, 2012 at 9:57 PM, Jagannadha Sutradharudu Teki
<jagannadh.teki at gmail.com> wrote:
> 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 <jagannadh.teki at gmail.com>
> ---
> 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.
> --
> 1.7.0.4
>
More information about the U-Boot
mailing list