From patchwork Mon Dec 10 14:42:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 204932 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 E253A2C023D for ; Tue, 11 Dec 2012 01:54:52 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 544CB4A04A; Mon, 10 Dec 2012 15:54:39 +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 GekCT9kxp33d; Mon, 10 Dec 2012 15:54:39 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 19F834A08B; Mon, 10 Dec 2012 15:54:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7C59C4A03C for ; Mon, 10 Dec 2012 15:44:55 +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 ZahLjh-0hfXi for ; Mon, 10 Dec 2012 15:44:55 +0100 (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-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by theia.denx.de (Postfix) with ESMTPS id 11B284A03F for ; Mon, 10 Dec 2012 15:44:54 +0100 (CET) Received: by mail-pb0-f44.google.com with SMTP id uo1so1906084pbc.3 for ; Mon, 10 Dec 2012 06:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=tZsygGlQiYWf0RzY5biOmWblG1HhsBT55OLj9OmLRxI=; b=yL+jFHjvYxSe8ITsAtahXgEVSMVJSNaY2oFTFpwbbiMglb0zgyFwawwNFnr0qiv0f0 RBtAR+gDEkD26iBpjE/cThz+hMJd4haIL0Myr3br6Uhwm9ymwaa/o+BfUi/9G6WRnuNI k9FOnDBDf5aff1KisH6UTVfkW0VCbTYztHWUhauwuglLMt82emd3BB9fPYEJEfWbB5rQ jTlyU6ljHMkcX8Hx3xXuMD285u0RpLcSsL4nU/b+CPjoQrQSuR14yKDLdNreTo+AQ/Zn t/5Eo9lq5s+pmUfFwbsRxk5JKHz0VQhFQIkiygQ0CEQdJchVsuHHxJLRI0pdskJ1OarN kGwA== Received: by 10.68.189.65 with SMTP id gg1mr39342169pbc.57.1355150693412; Mon, 10 Dec 2012 06:44:53 -0800 (PST) Received: from localhost.localdomain ([49.204.14.3]) by mx.google.com with ESMTPS id ty4sm11952285pbc.57.2012.12.10.06.44.51 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 10 Dec 2012 06:44:52 -0800 (PST) From: Jagannadha Sutradharudu Teki To: u-boot@lists.denx.de Date: Mon, 10 Dec 2012 20:12:00 +0530 Message-Id: <1355150521-3339-4-git-send-email-jagannadh.teki@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1355150521-3339-1-git-send-email-jagannadh.teki@gmail.com> References: <1355150521-3339-1-git-send-email-jagannadh.teki@gmail.com> X-Mailman-Approved-At: Mon, 10 Dec 2012 15:54:16 +0100 Subject: [U-Boot] [PATCH 3/4] sf: Add configuration register writing 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 --- drivers/mtd/spi/spi_flash.c | 27 +++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 3 +++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 800ed8b..a8f0af0 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -274,6 +274,33 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr) return 0; } +int spi_flash_cmd_write_config(struct spi_flash *flash, u16 cr) +{ + u8 cmd; + int ret; + + ret = spi_flash_cmd_write_enable(flash); + if (ret < 0) { + debug("SF: enabling write failed\n"); + return ret; + } + + cmd = CMD_WRITE_STATUS; + ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &cr, 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 141cfa8..9287778 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -77,6 +77,9 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash) /* Program the status register. */ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr); +/* Program the config register. */ +int spi_flash_cmd_write_config(struct spi_flash *flash, u16 cr); + /* * Same as spi_flash_cmd_read() except it also claims/releases the SPI * bus. Used as common part of the ->read() operation.