From patchwork Wed Dec 19 16:27:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 207455 X-Patchwork-Delegate: vapier@gentoo.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 926D42C0089 for ; Thu, 20 Dec 2012 03:35:38 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C1A7B4A04F; Wed, 19 Dec 2012 17:35:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SXJldHyky+bl; Wed, 19 Dec 2012 17:35:36 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8AEB64A032; Wed, 19 Dec 2012 17:35:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 761274A032 for ; Wed, 19 Dec 2012 17:35:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NS574wBdeeKn for ; Wed, 19 Dec 2012 17:35:30 +0100 (CET) X-Greylist: delayed 433 seconds by postgrey-1.27 at theia; Wed, 19 Dec 2012 17:35:28 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by theia.denx.de (Postfix) with ESMTPS id 212464A027 for ; Wed, 19 Dec 2012 17:35:28 +0100 (CET) Received: by mail-pb0-f45.google.com with SMTP id mc8so1327585pbc.18 for ; Wed, 19 Dec 2012 08:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=5Yqnn7LFzGfPGBEFZoV9idnEw8RfjNy98uRIo0d+8vk=; b=Klr+L3HqC3Ai3PEZKc51H5rJBye0eS/PVP9f11ySLtezHOXVRaTwXmawGJSLf9hU7S x8aKmurYEm2cigRjK/fCzIt3Om0JyJ4NBY3MrJGvQNGl+lLqectlUYXtJ9FWWmCwPGHI Ax5cixOJpTb0PaXac56WYdIBNIXrc7+oyIZFYO1SIRfviH+Ty7bav1D97G7dXkWTCbeI WgkiLu6rzfP0Q/GlCcp6B870jjWYCnrRZrXznQfbgVxdbfs25v3kVTg17l0SWMlqgOuM Sy+o8DSkSi65xrvvoNVp8t6hbNzVlq7CbWUMCZw+N4oHaCh6AF64NfS+WQ4nBNaNYIQY a1Jw== X-Received: by 10.68.242.38 with SMTP id wn6mr20241560pbc.28.1355934497433; Wed, 19 Dec 2012 08:28:17 -0800 (PST) Received: from localhost.localdomain ([123.237.83.48]) by mx.google.com with ESMTPS id z5sm3683430pax.9.2012.12.19.08.28.15 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 19 Dec 2012 08:28:17 -0800 (PST) From: Jagannadha Sutradharudu Teki To: u-boot@lists.denx.de Date: Wed, 19 Dec 2012 21:57:41 +0530 Message-Id: <1355934463-24319-4-git-send-email-jagannadh.teki@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1355934463-24319-1-git-send-email-jagannadh.teki@gmail.com> References: <1355934463-24319-1-git-send-email-jagannadh.teki@gmail.com> Subject: [U-Boot] [U-Boot, v2 4/6] sf: Add configuration register writing support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@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.