Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3739448imm; Tue, 17 Jul 2018 09:29:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeFOFfXhqKzCeGt1cE352QEUCvMNzhBvMb6h1s8HYT/vPn6f/R59eq11p2qGf3IvNf0PqYh X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr2325588plb.24.1531844978747; Tue, 17 Jul 2018 09:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531844978; cv=none; d=google.com; s=arc-20160816; b=xIG32xKVKsf6IF5khGnw/m9On+C9CXEbU8WRRieRDzh5FnXnC2WKO5AfISfyHqp3VG CEYbnhpj6xuJaxYinu/2WY064hRrhfV5yutJdi12D5buWonL0NcdVi+JVx5CFCrYJ853 rJu/qQAKOwVrBO90Mp/YYOd84EAFD41+YwIJ3XfCuA6+qreiwOwXrFhGp8dez0Ag1g9A vRqJiYMw1yJDBL3yIYcgVGQsZcuYfQlInFWI2urB3xS+zbSa8c5JcWpYK6s82Wqc2g8L OsRxJMGtRN4aT8RpUvkuECQHF9Wpjm2kaoh8whgbzHH7+4CkxtWMfqLj4X3uzYcWhFFG Jfjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=iqtnOVdesYOYb8NOA38/aOGX6fDKFzsB823ph+jcEt4=; b=J0zvwNh/LE2M/zX4H4FHVrpJNtAnIgXZPM0jtzkoMTqGC3U4zp8bIF0OVj+rtXeDLh jWcyE3nikq9ELs3UTFaScPxWef8TH73nUilaG/VEvtH+i9yYvqJsD3FJkww+4T5ttOqv kp8s+omYWVkPVi7uk2Uhm2K7KMe3boz/8tBWm8+YLB1/IVOBwL1nczMSAAmvVWnNMPqS mmUbjCjA/q3ZegwBZg2lHWoPgxldPFUrW5n5odG/Zjmg9dC7WqT2BJLVsgaFwLm2roFJ bFVm4ogr2xBWkJtaKRR0FGtY551bCQlotZZE6nPdovIU1YgUODjZPmn7iqPUiVE9hNm8 yISA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r81-v6si1259457pfg.305.2018.07.17.09.29.23; Tue, 17 Jul 2018 09:29:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729976AbeGQRCJ (ORCPT + 99 others); Tue, 17 Jul 2018 13:02:09 -0400 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:60707 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729600AbeGQRCJ (ORCPT ); Tue, 17 Jul 2018 13:02:09 -0400 X-IronPort-AV: E=Sophos;i="5.51,366,1526367600"; d="scan'208";a="16346069" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jul 2018 09:28:41 -0700 Received: from localhost.localdomain.com (10.10.76.4) by chn-sv-exch02.mchp-main.com (10.10.76.38) with Microsoft SMTP Server id 14.3.352.0; Tue, 17 Jul 2018 09:28:40 -0700 From: Tudor Ambarus To: , , , , CC: , , , , , , Tudor Ambarus Subject: [PATCH 1/3] mtd: spi-nor: add Global Block Unlock support Date: Tue, 17 Jul 2018 19:28:29 +0300 Message-ID: <20180717162831.17947-1-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.9.4 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can't determine this purely by manufacturer type and it's not autodetectable by anything like SFDP, so make a new flag for it: UNLOCK_GLOBAL_BLOCK. Note that the Global Block Unlock command has different names depending on the manufacturer, but always the same command value: 0x98. Macronix's MX25U12835F names it Gang Block Unlock, Winbound's W25Q128FV names it Global Block Unlock and Microchip's SST26VF064B names it Global Block Protection Unlock. Based on initial work done by Anurag Kumar Vulisha: https://patchwork.kernel.org/patch/7611271/ Signed-off-by: Tudor Ambarus --- drivers/mtd/spi-nor/spi-nor.c | 21 +++++++++++++++++++++ include/linux/mtd/spi-nor.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d9c368c..6648251 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -89,6 +89,7 @@ struct flash_info { #define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */ #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */ #define USE_CLSR BIT(14) /* use CLSR command */ +#define UNLOCK_GLOBAL_BLOCK BIT(15) /* Unlock global block protection */ int (*quad_enable)(struct spi_nor *nor); }; @@ -2730,6 +2731,17 @@ static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info, return 0; } +static int spi_nor_unlock_global_block_protection(struct spi_nor *nor) +{ + int ret; + + write_enable(nor); + ret = nor->write_reg(nor, SPINOR_OP_GBULK, NULL, 0); + if (ret < 0) + return ret; + return spi_nor_wait_till_ready(nor); +} + static int spi_nor_init(struct spi_nor *nor) { int err; @@ -2747,6 +2759,15 @@ static int spi_nor_init(struct spi_nor *nor) spi_nor_wait_till_ready(nor); } + if (nor->info->flags & UNLOCK_GLOBAL_BLOCK) { + err = spi_nor_unlock_global_block_protection(nor); + if (err) { + dev_err(nor->dev, + "Cannot unlock the global block protection\n"); + return err; + } + } + if (nor->quad_enable) { err = nor->quad_enable(nor); if (err) { diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index e60da0d..e8dd11d 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -64,6 +64,7 @@ #define SPINOR_OP_CLFSR 0x50 /* Clear flag status register */ #define SPINOR_OP_RDEAR 0xc8 /* Read Extended Address Register */ #define SPINOR_OP_WREAR 0xc5 /* Write Extended Address Register */ +#define SPINOR_OP_GBULK 0x98 /* Global Block Unlock Protection */ /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */ #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */ -- 2.9.4