From patchwork Sun Jan 22 12:21:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 718157 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v5tqL0HVNz9s2Q for ; Sun, 22 Jan 2017 23:22:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TtBn1rG9"; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CDADDB9116E; Sun, 22 Jan 2017 13:22:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Sun, 22 Jan 2017 13:22:00 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 93346B8010C for ; Sun, 22 Jan 2017 13:21:58 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .linaro. - helo: .mail-lf0-f54.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -7 Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 22 Jan 2017 13:21:57 +0100 (CET) Received: by mail-lf0-f54.google.com with SMTP id v186so80703740lfa.1 for ; Sun, 22 Jan 2017 04:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=atrIN35Lk8d+JuxbD2nFo4Qy3GIqJFgwb8/6g5PAKyI=; b=TtBn1rG9f86OIvx4inoa4wL0oQtYtdHHkyB5kaO0KZU6O/zfjpmHvasAEwOy2JKuYI vAYCgsUJlRQ8QoN60C8g9Ps2spMsyg62Oz3rUqGkVrthsEyjlB4vAidnMg5kevT0IqjM HUlfedKZr0ucJnnCDEGy3h5FivyPu8Zv8UaG4= 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; bh=atrIN35Lk8d+JuxbD2nFo4Qy3GIqJFgwb8/6g5PAKyI=; b=QIzZ12Lcs3ftpH30KEcVPrkO1gKbu3u51oUOCXjePXnnwTnlw9bvuwPjid0tl7ACv5 lppCOeYFaC8fiqDVbSkwFhP8Kb69+x6X7SzWhA7aadgfRIPSkrtGic4l6BqfCjbTATYb lFiD7v3jAIPzUhfEz92yVvttok3yofVqZVRPYrEitmZsbUzu1XBYb0jfG2M2oD0nWdrW YQRPwGkCUMdIKRoFlOTLnPJp6UdfFAs2SuRG/x3k6F2T97tb21IfQUg9I+Eeb4cCiWAB tOOujPHyEv49N+quYlchIhEKXnV7gUF/hoXFY+NNTwI7huuPNwQyjL9n2Z+XMa7mgGQ6 wpoQ== X-Gm-Message-State: AIkVDXIouEdPN9x2+w+sjThXhqfC8mPN0Mv9olL53K/y2iW7iSbkbHP+169aPATb2Ey15gYT X-Received: by 10.46.14.26 with SMTP id 26mr6008869ljo.59.1485087717378; Sun, 22 Jan 2017 04:21:57 -0800 (PST) Received: from localhost.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id b62sm5414467lfb.24.2017.01.22.04.21.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jan 2017 04:21:56 -0800 (PST) From: Linus Walleij To: linux-arm-kernel@lists.infradead.org, Hans Ulli Kroll , Florian Fainelli , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen Date: Sun, 22 Jan 2017 13:21:54 +0100 Message-Id: <20170122122154.10561-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 Subject: [OpenWrt-Devel] [PATCH 10/22] mtd: physmap_of: add a hook for Gemini flash probing X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openwrt-devel@openwrt.org, Paulius Zaleckas , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Janos Laube MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" In order to support device tree probing of Gemini NOR flash chips, a certain register in the syscon needs to be poked to enable parallel flash mode. Such things used to happen in "necessarily different" board file code, and this indeed was also done for the Gemini, so the MTD driver could treat it as any memory-mapped NOR flash, but this is not the way in the future: board files need to go, and hardware concerns distributed down to the applicable drivers. This adds a hook in the same way that the Versatile did: if the Kconfig symbol is not selected the net total of supporting Gemini should be zero bytes of added code. To live up to this promise, also the return value error print from the Versatile extra probe call get to be removed in this patch, all printing need to happen in the add-ons. Cc: Janos Laube Cc: Paulius Zaleckas Cc: Hans Ulli Kroll Cc: Florian Fainelli Signed-off-by: Linus Walleij --- MTD maintainers: please just apply this to the MTD tree when you are happy with it. It is functionally orthogonal to the rest of the series and is just in the series for context. --- drivers/mtd/maps/Kconfig | 10 +++ drivers/mtd/maps/Makefile | 3 + drivers/mtd/maps/physmap_of.c | 9 ++- drivers/mtd/maps/physmap_of_gemini.c | 120 +++++++++++++++++++++++++++++++++++ drivers/mtd/maps/physmap_of_gemini.h | 16 +++++ 5 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 drivers/mtd/maps/physmap_of_gemini.c create mode 100644 drivers/mtd/maps/physmap_of_gemini.h diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 5bcc896a48c3..e9206060c598 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig @@ -84,6 +84,16 @@ config MTD_PHYSMAP_OF_VERSATILE platforms, basically to add a VPP (write protection) callback so the flash can be taken out of write protection. +config MTD_PHYSMAP_OF_GEMINI + bool "Support Gemini physmap OF" + depends on MTD_PHYSMAP_OF + depends on MFD_SYSCON + default ARCH_GEMINI + help + This provides some extra DT physmap parsing for the Gemini + platforms, some detection and setting up parallel mode on the + external interface. + config MTD_PMC_MSP_EVM tristate "CFI Flash device mapped on PMC-Sierra MSP" depends on PMC_MSP && MTD_CFI diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 644f7d36d35d..36fe05ec9fab 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile @@ -21,6 +21,9 @@ obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o ifdef CONFIG_MTD_PHYSMAP_OF_VERSATILE obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of_versatile.o endif +ifdef CONFIG_MTD_PHYSMAP_OF_GEMINI +obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of_gemini.o +endif obj-$(CONFIG_MTD_PISMO) += pismo.o obj-$(CONFIG_MTD_PMC_MSP_EVM) += pmcmsp-flash.o obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 3fad35942895..14e8909c9955 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c @@ -24,6 +24,7 @@ #include #include #include +#include "physmap_of_gemini.h" #include "physmap_of_versatile.h" struct of_flash_list { @@ -241,11 +242,13 @@ static int of_flash_probe(struct platform_device *dev) info->list[i].map.size = res_size; info->list[i].map.bankwidth = be32_to_cpup(width); info->list[i].map.device_node = dp; + + err = of_flash_probe_gemini(dev, dp, &info->list[i].map); + if (err) + return err; err = of_flash_probe_versatile(dev, dp, &info->list[i].map); - if (err) { - dev_err(&dev->dev, "Can't probe Versatile VPP\n"); + if (err) return err; - } err = -ENOMEM; info->list[i].map.virt = ioremap(info->list[i].map.phys, diff --git a/drivers/mtd/maps/physmap_of_gemini.c b/drivers/mtd/maps/physmap_of_gemini.c new file mode 100644 index 000000000000..1d60ef779b99 --- /dev/null +++ b/drivers/mtd/maps/physmap_of_gemini.c @@ -0,0 +1,120 @@ +/* + * Cortina Systems Gemini OF physmap add-on + * Copyright (C) 2017 Linus Walleij + * + * This SoC has an elaborate flash control register, so we need to + * detect and set it up when booting on this platform. + */ +#include +#include +#include +#include +#include +#include +#include +#include "physmap_of_gemini.h" + +/* + * The Flash-relevant parts of the global status register + * These would also be relevant for a NAND driver. + */ +#define GLOBAL_STATUS 0x04 +#define FLASH_TYPE_MASK (0x3 << 24) +#define FLASH_TYPE_NAND_2K (0x3 << 24) +#define FLASH_TYPE_NAND_512 (0x2 << 24) +#define FLASH_TYPE_PARALLEL (0x1 << 24) +#define FLASH_TYPE_SERIAL (0x0 << 24) +/* if parallel */ +#define FLASH_WIDTH_16BIT (1 << 23) /* else 8 bit */ +/* if serial */ +#define FLASH_ATMEL (1 << 23) /* else STM */ + +#define FLASH_SIZE_MASK (0x3 << 21) +#define NAND_256M (0x3 << 21) /* and more */ +#define NAND_128M (0x2 << 21) +#define NAND_64M (0x1 << 21) +#define NAND_32M (0x0 << 21) +#define ATMEL_16M (0x3 << 21) /* and more */ +#define ATMEL_8M (0x2 << 21) +#define ATMEL_4M_2M (0x1 << 21) +#define ATMEL_1M (0x0 << 21) /* and less */ +#define STM_32M (1 << 22) /* and more */ +#define STM_16M (0 << 22) /* and less */ + +#define FLASH_PARALLEL_HIGH_PIN_CNT (1 << 20) /* else low pin cnt */ + +/* Miscellaneous Control Register */ +#define GLOBAL_MISC_CTRL 0x30 +#define FLASH_PADS_MASK 0x07 +#define NAND_PADS_DISABLE BIT(2) +#define PFLASH_PADS_DISABLE BIT(1) +#define SFLASH_PADS_DISABLE BIT(0) + +static const struct of_device_id syscon_match[] = { + { .compatible = "cortina,gemini-syscon" }, + { }, +}; + +int of_flash_probe_gemini(struct platform_device *pdev, + struct device_node *np, + struct map_info *map) +{ + static struct regmap *rmap; + struct device *dev = &pdev->dev; + u32 val; + int ret; + + /* Multiplatform guard */ + if (!of_device_is_compatible(np, "cortina,gemini-flash")) + return 0; + + rmap = syscon_regmap_lookup_by_phandle(np, "syscon"); + if (IS_ERR(rmap)) { + dev_err(dev, "no syscon\n"); + return PTR_ERR(rmap); + } + + ret = regmap_read(rmap, GLOBAL_STATUS, &val); + if (ret) { + dev_err(dev, "failed to read global status register\n"); + return -ENODEV; + } + dev_info(dev, "global status reg: %08x\n", val); + + /* + * It would be contradictory if a physmap flash was NOT parallel. + */ + if ((val & FLASH_TYPE_MASK) != FLASH_TYPE_PARALLEL) { + dev_err(dev, "flash is not parallel\n"); + return -ENODEV; + } + + /* + * Complain if DT data and hardware definition is different. + */ + if (val & FLASH_WIDTH_16BIT) { + if (map->bankwidth != 2) + dev_warn(dev, "flash hardware say flash is 16 bit wide " + "but DT says it is %d bits wide\n", + map->bankwidth * 8); + } else { + if (map->bankwidth != 1) + dev_warn(dev, "flash hardware say flash is 8 bit wide " + "but DT says it is %d bits wide\n", + map->bankwidth * 8); + } + + /* Activate parallel (NOR flash) mode */ + ret = regmap_update_bits(rmap, GLOBAL_MISC_CTRL, + FLASH_PADS_MASK, + SFLASH_PADS_DISABLE | NAND_PADS_DISABLE); + if (ret) { + dev_err(dev, "unable to set up physmap pads\n"); + return -ENODEV; + } + + dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n"); + + return 0; +} +EXPORT_SYMBOL_GPL(of_flash_probe_gemini); diff --git a/drivers/mtd/maps/physmap_of_gemini.h b/drivers/mtd/maps/physmap_of_gemini.h new file mode 100644 index 000000000000..c675025288dd --- /dev/null +++ b/drivers/mtd/maps/physmap_of_gemini.h @@ -0,0 +1,16 @@ +#include +#include + +#ifdef CONFIG_MTD_PHYSMAP_OF_GEMINI +int of_flash_probe_gemini(struct platform_device *pdev, + struct device_node *np, + struct map_info *map); +#else +static inline +int of_flash_probe_gemini(struct platform_device *pdev, + struct device_node *np, + struct map_info *map) +{ + return 0; +} +#endif