From patchwork Tue Aug 13 16:59:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 1146524 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="NQEuBY26"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467KcC4YFXz9sND for ; Wed, 14 Aug 2019 03:35:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5204DC22081; Tue, 13 Aug 2019 17:24:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 76C1DC21FED; Tue, 13 Aug 2019 17:24:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 20533C22079; Tue, 13 Aug 2019 16:59:54 +0000 (UTC) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by lists.denx.de (Postfix) with ESMTPS id 724A2C21FBC for ; Tue, 13 Aug 2019 16:59:51 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id bj8so2505476plb.4 for ; Tue, 13 Aug 2019 09:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wMP0Pui5VTS7emEwoghcSOIW/l7o50q4LOnKBEz4Heo=; b=NQEuBY26eRwu9xqW1ICkGZjx9TWuwD9hQm/jhny5Nz7Kw1YW+//QES/u82/H2HFyHo RWliwnLAzl3F3o3PW6JD2u5MbKpPamv18LmxFSb727xSM/El9I4+3ks2nvKveQjFHIXQ jKDf7CBK+H08wkK5OZirgF3LRxloh+DtQ7L3jEz2CSTD1Ezw3rRY4tEt2j9FSoXqcAES bjp6BfJwMndRytWLhhUsY8vZ1sFGvNTtxhOasMYK/BXK3Uhf9Kz/l8RTq00b62SbrY+M 4al4ifao13dNja0o52+twCEjwcoLLDm5bLx0BGwFI5qdubwfLrhHYr3Gbzco/Lf7WElA BDlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wMP0Pui5VTS7emEwoghcSOIW/l7o50q4LOnKBEz4Heo=; b=JSKmCCYcfxYGXM3avyQYClTC4nEk8Ypd9bG9/veFb0Kd1H2cxmXSpv3d+amRSLjeAW 3y74f5/7mX67y7whGimTcgBm7KVVZCsknHodj5nEPpNv3dvSmwCuuw3c5hxBljYNF5BG idmRVtOfPc039Wm8avIvyKjEu8blEXtQo6cbvsxHxJOcREJi14IsKd/iiUqy0G2e2idP vC2OsOG3GgSF4rR8zYMNDuCX/eTK01DKCG2ba+TiJPzLKzXK3AGpIPfps5IsFnXfTy5j mBaMqNbIce390gg4iiv4qTMuK/v58/kw+g4CGpyV1yz6D3pucPj0l4YkQL1NNWBj9Oc9 MfDA== X-Gm-Message-State: APjAAAWHc7UWEJ62KweboX/K4f4WNIt1nmdnzZ0+eYvqjHwsf5qfASik Gmc+U/cAIuyiHOYJqcbYZ1PlIB7yDuZLzA== X-Google-Smtp-Source: APXvYqxENUhct1Sua2Yo0d+8o4CyVgzHOqVZHSnhZKuXXxiMLKIM/reu+B5YiAxVPTTnFcwfTklBVg== X-Received: by 2002:a17:902:ba96:: with SMTP id k22mr39646563pls.44.1565715589527; Tue, 13 Aug 2019 09:59:49 -0700 (PDT) Received: from gamma07.internal.sifive.com ([64.62.193.194]) by smtp.googlemail.com with ESMTPSA id w11sm6040857pfi.105.2019.08.13.09.59.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Aug 2019 09:59:48 -0700 (PDT) From: Sagar Shrikant Kadam To: u-boot@lists.denx.de, paul.walmsley@sifive.com, palmer@sifive.com, anup.patel@wdc.com, atish.patra@wdc.com, jagan@amarulasolutions.com, vigneshr@ti.com Date: Tue, 13 Aug 2019 09:59:29 -0700 Message-Id: <1565715571-26558-2-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565715571-26558-1-git-send-email-sagar.kadam@sifive.com> References: <1565715571-26558-1-git-send-email-sagar.kadam@sifive.com> Subject: [U-Boot] [U-BOOT PATCH 1/3] spi: nor: add spi-nor-fixup handlers for nor devices X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add support for spi_nor_fixups similar to that done in linux. Flash vendor specific fixups can be registered in spi_nor_ids. and will be called after BFPT parsing to fix any wrong parameter read from SFDP. Signed-off-by: Sagar Shrikant Kadam --- drivers/mtd/spi/sf_internal.h | 5 +++++ drivers/mtd/spi/spi-nor-core.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index a6bf734..c5e68d8 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -65,6 +65,11 @@ 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 */ + +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT + /* Part specific fixup hooks */ + const struct spi_nor_fixups *fixups; +#endif }; extern const struct flash_info spi_nor_ids[]; diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 1acff74..4306d19 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -1623,6 +1623,33 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = { static int spi_nor_hwcaps_read2cmd(u32 hwcaps); /** + * struct spi_nor_fixups - SPI NOR fixup hooks + * @post_bfpt: called after the BFPT table has been parsed + * + * Those hooks can be used to tweak the SPI NOR configuration when the SFDP + * table is broken or not available. + */ +struct spi_nor_fixups { + int (*post_bfpt)(struct spi_nor *nor, + const struct sfdp_parameter_header *bfpt_header, + const struct sfdp_bfpt *bfpt, + struct spi_nor_flash_parameter *params); +}; + +static int +spi_nor_post_bfpt_fixups(struct spi_nor *nor, + const struct sfdp_parameter_header *bfpt_header, + const struct sfdp_bfpt *bfpt, + struct spi_nor_flash_parameter *params) +{ + if (nor->info->fixups && nor->info->fixups->post_bfpt) + return nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt, + params); + + return 0; +} + +/** * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table. * @nor: pointer to a 'struct spi_nor' * @bfpt_header: pointer to the 'struct sfdp_parameter_header' describing @@ -1760,7 +1787,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, /* Stop here if not JESD216 rev A or later. */ if (bfpt_header->length < BFPT_DWORD_MAX) - return 0; + return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt, + params); /* Page size: this field specifies 'N' so the page size = 2^N bytes. */ params->page_size = bfpt.dwords[BFPT_DWORD(11)]; @@ -1793,7 +1821,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, return -EINVAL; } - return 0; + return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt, + params); } /**