Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp737164imm; Wed, 25 Jul 2018 05:28:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe6td6TtichmztxjdC0PNOo7UlvMCIkljXdnkytjju8cKJYPTAMEr3F+qxFz4vA0NH2Kxtt X-Received: by 2002:a62:1b07:: with SMTP id b7-v6mr22024437pfb.70.1532521702069; Wed, 25 Jul 2018 05:28:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532521702; cv=none; d=google.com; s=arc-20160816; b=nX0oeGuVC7llcKxqLOKY0sZugF8abCMs0nVvFE1FH1osL4hI+lnFB06LZbXaWuFbFr Ai0IHUwSZzfzVKnHpYMdENTQ7lNW+e86acXkQdY2ZJsnXE7fYKUandvSWwNKNF8lgKnx xvFYCFnOExlTN3TB0WkXqhDymZ2HKFHTtYBakU4yy5d/TMecQkkeiKcwyyEIauTMgQ16 G7BMIqcl/YnuoPARbpcCHrIptSApug8pipFdtcoaZzPECY241Ad0ENMGDJGEtK5RBsbz ZED6HvlHjxTEVOyrHMhynhvq/FDftsNiewNMJpvmneCRBDBuP+3mvCay+tK7REGZuWy0 QmFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=DwMcXbjHpGP+4ZyZ7V7ROQgreHIH45+QqxUBMWxNS6k=; b=p8oP/S8z2G+kRl7/7E1d6zXCfVIZNVEeeVB3UQoAkvazejZtmJ5dRYyMSBrIN954ZS pder9Ct0HSGZFVIuVftN8p2OR20ZPRMBbO4X/4mo0pU6trdkIoHev79VeXNUssCQ5/00 DUpiHuDPBTTq7jADAxD6jxjzAUyod7rBMffcn6rRqpZ8OaacPZC/dSdBbQUe/gjHBM11 E/sSknkzVlFWSHVpwq4yfgTNcRYrmzmry376eBzdTVTD7S6guJDjNSAMWzEd1M4NS99j /LZjkqii51BE5hTEVYU65zR377aavKKD0UWQd7dyRMX6Sc2hsgEIoPHQgMQMxUf+GVcj Weqw== 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 m14-v6si13291942pfh.92.2018.07.25.05.28.07; Wed, 25 Jul 2018 05:28:22 -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 S1728985AbeGYNiJ (ORCPT + 99 others); Wed, 25 Jul 2018 09:38:09 -0400 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:36724 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728791AbeGYNiJ (ORCPT ); Wed, 25 Jul 2018 09:38:09 -0400 X-IronPort-AV: E=Sophos;i="5.51,401,1526367600"; d="scan'208";a="16771207" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 25 Jul 2018 05:26:41 -0700 Received: from [10.159.245.163] (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.352.0; Wed, 25 Jul 2018 05:26:40 -0700 Subject: Re: [PATCH 1/3] mtd: spi-nor: add Global Block Unlock support To: Tudor Ambarus , , , , , CC: , , , , References: <20180717162831.17947-1-tudor.ambarus@microchip.com> From: Cyrille Pitchen Message-ID: <8e0ff8be-34d1-7de9-6120-a067540a75d2@microchip.com> Date: Wed, 25 Jul 2018 14:26:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180717162831.17947-1-tudor.ambarus@microchip.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tudor, Le 17/07/2018 à 18:28, Tudor Ambarus a écrit : > 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 Reviewed-by: Cyrille Pitchen Best regards, Cyrille > --- > 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) */ >