From patchwork Fri Jan 18 06:17:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dante X-Patchwork-Id: 213475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 30D7F2C0087 for ; Fri, 18 Jan 2013 17:18:05 +1100 (EST) Received: from localhost ([::1]:40767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw5H8-00018m-7z for incoming@patchwork.ozlabs.org; Fri, 18 Jan 2013 01:18:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw5Gz-00015F-R7 for qemu-devel@nongnu.org; Fri, 18 Jan 2013 01:17:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tw5Gw-0001WL-Us for qemu-devel@nongnu.org; Fri, 18 Jan 2013 01:17:53 -0500 Received: from ftcsun4.faraday-tech.com ([60.248.181.187]:56100 helo=ftcsun4.faraday.com.tw) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw5Gv-0001Uf-Tg for qemu-devel@nongnu.org; Fri, 18 Jan 2013 01:17:50 -0500 Received: from ftcpcs100.faraday.com.tw ([192.168.31.10]) by ftcsun4.faraday.com.tw (8.11.7p1+Sun/8.11.6) with ESMTP id r0I6Hhm06978 for ; Fri, 18 Jan 2013 14:17:43 +0800 (CST) Received: from FTCPCS63.faraday.com.tw (unverified [192.168.32.63]) by ftcpcs100.faraday.com.tw (Clearswift SMTPRS 5.2.9) with ESMTP id ; Fri, 18 Jan 2013 14:17:43 +0800 Received: from vmware.faraday.com.tw (192.168.65.96) by FTCPCS63.faraday.com.tw (192.168.32.65) with Microsoft SMTP Server (TLS) id 14.2.328.9; Fri, 18 Jan 2013 14:17:43 +0800 From: Dante To: Date: Fri, 18 Jan 2013 14:17:11 +0800 Message-ID: <1358489831-18005-1-git-send-email-dantesu@faraday-tech.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-Originating-IP: [192.168.65.96] X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 60.248.181.187 Cc: peter.crosthwaite@petalogix.com, Dante Subject: [Qemu-devel] [PATCH] hw/m25p80.c: add WRSR(0x01) support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Atmel, SST and Intel/Numonyx serial flash tend to power up with the software protection bits set. And thus the new m25p80.c in linux kernel would always tries to use WREN(0x06) + WRSR(0x01) to turn-off the protection. The WEL(0x02) of status register is supposed to be cleared after WRSR(0x01). There are some drivers (i.e my own tiny driver for RTOSes) would check the WEL(0x02) in status register to make sure the protection is correctly turned off, so this patch is mandatory to me. Signed-off-by: Kuo-Jung Su --- hw/m25p80.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/m25p80.c b/hw/m25p80.c index d392656..c8d0411 100644 --- a/hw/m25p80.c +++ b/hw/m25p80.c @@ -184,6 +184,7 @@ static const FlashPartInfo known_devices[] = { typedef enum { NOP = 0, + WRSR = 0x1, WRDI = 0x4, RDSR = 0x5, WREN = 0x6, @@ -377,6 +378,12 @@ static void complete_collecting_data(Flash *s) case ERASE_SECTOR: flash_erase(s, s->cur_addr, s->cmd_in_progress); break; + case WRSR: + if (s->write_enable) { + s->state = STATE_IDLE; + s->write_enable = false; + } + break; default: break; } @@ -440,6 +447,15 @@ static void decode_new_cmd(Flash *s, uint32_t value) s->len = 0; s->state = STATE_COLLECTING_DATA; break; + + case WRSR: + if (s->write_enable) { + s->needed_bytes = 1; + s->pos = 0; + s->len = 0; + s->state = STATE_COLLECTING_DATA; + } + break; case WRDI: s->write_enable = false;