From 6ca15cfa0788ebef365ce31d1e01ea30a389a895 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 19 Oct 2018 09:49:05 +0200 Subject: mtd: maps: Rename physmap_of_{versatile, gemini} into physmap-{versatile, gemini} Now that the physmap_of driver is gone, the gemini and versative extensions are part of the physmap driver. Rename the source files and the config option to reflect this. Signed-off-by: Boris Brezillon Reviewed-by: Ricardo Ribalda Delgado Acked-by: Linus Walleij --- drivers/mtd/maps/Kconfig | 4 +- drivers/mtd/maps/Makefile | 4 +- drivers/mtd/maps/physmap-core.c | 4 +- drivers/mtd/maps/physmap-gemini.c | 97 ++++++++++++ drivers/mtd/maps/physmap-gemini.h | 17 +++ drivers/mtd/maps/physmap-versatile.c | 254 ++++++++++++++++++++++++++++++++ drivers/mtd/maps/physmap-versatile.h | 17 +++ drivers/mtd/maps/physmap_of_gemini.c | 97 ------------ drivers/mtd/maps/physmap_of_gemini.h | 17 --- drivers/mtd/maps/physmap_of_versatile.c | 254 -------------------------------- drivers/mtd/maps/physmap_of_versatile.h | 17 --- 11 files changed, 391 insertions(+), 391 deletions(-) create mode 100644 drivers/mtd/maps/physmap-gemini.c create mode 100644 drivers/mtd/maps/physmap-gemini.h create mode 100644 drivers/mtd/maps/physmap-versatile.c create mode 100644 drivers/mtd/maps/physmap-versatile.h delete mode 100644 drivers/mtd/maps/physmap_of_gemini.c delete mode 100644 drivers/mtd/maps/physmap_of_gemini.h delete mode 100644 drivers/mtd/maps/physmap_of_versatile.c delete mode 100644 drivers/mtd/maps/physmap_of_versatile.h (limited to 'drivers/mtd/maps') diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 5bffebacce86..bb0d64e3fcd6 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig @@ -74,7 +74,7 @@ config MTD_PHYSMAP_OF physically into the CPU's memory. The mapping description here is taken from OF device tree. -config MTD_PHYSMAP_OF_VERSATILE +config MTD_PHYSMAP_VERSATILE bool "ARM Versatile OF-based physical memory map handling" depends on MTD_PHYSMAP_OF depends on MFD_SYSCON @@ -84,7 +84,7 @@ 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 +config MTD_PHYSMAP_GEMINI bool "Cortina Gemini OF-based physical memory map handling" depends on MTD_PHYSMAP_OF depends on MFD_SYSCON diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index ad32b185a120..ce737e15b7cf 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile @@ -18,8 +18,8 @@ obj-$(CONFIG_MTD_CK804XROM) += ck804xrom.o obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o obj-$(CONFIG_MTD_PXA2XX) += pxa2xx-flash.o physmap-objs-y += physmap-core.o -physmap-objs-$(CONFIG_MTD_PHYSMAP_OF_VERSATILE) += physmap_of_versatile.o -physmap-objs-$(CONFIG_MTD_PHYSMAP_OF_GEMINI) += physmap_of_gemini.o +physmap-objs-$(CONFIG_MTD_PHYSMAP_VERSATILE) += physmap-versatile.o +physmap-objs-$(CONFIG_MTD_PHYSMAP_GEMINI) += physmap-gemini.o physmap-objs := $(physmap-objs-y) obj-$(CONFIG_MTD_PHYSMAP) += physmap.o obj-$(CONFIG_MTD_PISMO) += pismo.o diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-core.c index 07af8368d173..8a8af37576ff 100644 --- a/drivers/mtd/maps/physmap-core.c +++ b/drivers/mtd/maps/physmap-core.c @@ -31,8 +31,8 @@ #include #include -#include "physmap_of_gemini.h" -#include "physmap_of_versatile.h" +#include "physmap-gemini.h" +#include "physmap-versatile.h" struct physmap_flash_info { unsigned int nmaps; diff --git a/drivers/mtd/maps/physmap-gemini.c b/drivers/mtd/maps/physmap-gemini.c new file mode 100644 index 000000000000..1cf128a0526d --- /dev/null +++ b/drivers/mtd/maps/physmap-gemini.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * 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-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 */ + +int of_flash_probe_gemini(struct platform_device *pdev, + struct device_node *np, + struct map_info *map) +{ + 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_dbg(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); + } + + dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n"); + + return 0; +} diff --git a/drivers/mtd/maps/physmap-gemini.h b/drivers/mtd/maps/physmap-gemini.h new file mode 100644 index 000000000000..72bd04ce3fdb --- /dev/null +++ b/drivers/mtd/maps/physmap-gemini.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include + +#ifdef CONFIG_MTD_PHYSMAP_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 diff --git a/drivers/mtd/maps/physmap-versatile.c b/drivers/mtd/maps/physmap-versatile.c new file mode 100644 index 000000000000..0179d710bb3f --- /dev/null +++ b/drivers/mtd/maps/physmap-versatile.c @@ -0,0 +1,254 @@ +/* + * Versatile OF physmap driver add-on + * + * Copyright (c) 2016, Linaro Limited + * Author: Linus Walleij + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "physmap-versatile.h" + +static struct regmap *syscon_regmap; + +enum versatile_flashprot { + INTEGRATOR_AP_FLASHPROT, + INTEGRATOR_CP_FLASHPROT, + VERSATILE_FLASHPROT, + REALVIEW_FLASHPROT, +}; + +static const struct of_device_id syscon_match[] = { + { + .compatible = "arm,integrator-ap-syscon", + .data = (void *)INTEGRATOR_AP_FLASHPROT, + }, + { + .compatible = "arm,integrator-cp-syscon", + .data = (void *)INTEGRATOR_CP_FLASHPROT, + }, + { + .compatible = "arm,core-module-versatile", + .data = (void *)VERSATILE_FLASHPROT, + }, + { + .compatible = "arm,realview-eb-syscon", + .data = (void *)REALVIEW_FLASHPROT, + }, + { + .compatible = "arm,realview-pb1176-syscon", + .data = (void *)REALVIEW_FLASHPROT, + }, + { + .compatible = "arm,realview-pb11mp-syscon", + .data = (void *)REALVIEW_FLASHPROT, + }, + { + .compatible = "arm,realview-pba8-syscon", + .data = (void *)REALVIEW_FLASHPROT, + }, + { + .compatible = "arm,realview-pbx-syscon", + .data = (void *)REALVIEW_FLASHPROT, + }, + {}, +}; + +/* + * Flash protection handling for the Integrator/AP + */ +#define INTEGRATOR_SC_CTRLS_OFFSET 0x08 +#define INTEGRATOR_SC_CTRLC_OFFSET 0x0C +#define INTEGRATOR_SC_CTRL_FLVPPEN BIT(1) +#define INTEGRATOR_SC_CTRL_FLWP BIT(2) + +#define INTEGRATOR_EBI_CSR1_OFFSET 0x04 +/* The manual says bit 2, the code says bit 3, trust the code */ +#define INTEGRATOR_EBI_WRITE_ENABLE BIT(3) +#define INTEGRATOR_EBI_LOCK_OFFSET 0x20 +#define INTEGRATOR_EBI_LOCK_VAL 0xA05F + +static const struct of_device_id ebi_match[] = { + { .compatible = "arm,external-bus-interface"}, + { }, +}; + +static int ap_flash_init(struct platform_device *pdev) +{ + struct device_node *ebi; + void __iomem *ebi_base; + u32 val; + int ret; + + /* Look up the EBI */ + ebi = of_find_matching_node(NULL, ebi_match); + if (!ebi) { + return -ENODEV; + } + ebi_base = of_iomap(ebi, 0); + if (!ebi_base) + return -ENODEV; + + /* Clear VPP and write protection bits */ + ret = regmap_write(syscon_regmap, + INTEGRATOR_SC_CTRLC_OFFSET, + INTEGRATOR_SC_CTRL_FLVPPEN | INTEGRATOR_SC_CTRL_FLWP); + if (ret) + dev_err(&pdev->dev, "error clearing Integrator VPP/WP\n"); + + /* Unlock the EBI */ + writel(INTEGRATOR_EBI_LOCK_VAL, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET); + + /* Enable write cycles on the EBI, CSR1 (flash) */ + val = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET); + val |= INTEGRATOR_EBI_WRITE_ENABLE; + writel(val, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET); + + /* Lock the EBI again */ + writel(0, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET); + iounmap(ebi_base); + + return 0; +} + +static void ap_flash_set_vpp(struct map_info *map, int on) +{ + int ret; + + if (on) { + ret = regmap_write(syscon_regmap, + INTEGRATOR_SC_CTRLS_OFFSET, + INTEGRATOR_SC_CTRL_FLVPPEN | INTEGRATOR_SC_CTRL_FLWP); + if (ret) + pr_err("error enabling AP VPP\n"); + } else { + ret = regmap_write(syscon_regmap, + INTEGRATOR_SC_CTRLC_OFFSET, + INTEGRATOR_SC_CTRL_FLVPPEN | INTEGRATOR_SC_CTRL_FLWP); + if (ret) + pr_err("error disabling AP VPP\n"); + } +} + +/* + * Flash protection handling for the Integrator/CP + */ + +#define INTCP_FLASHPROG_OFFSET 0x04 +#define CINTEGRATOR_FLVPPEN BIT(0) +#define CINTEGRATOR_FLWREN BIT(1) +#define CINTEGRATOR_FLMASK BIT(0)|BIT(1) + +static void cp_flash_set_vpp(struct map_info *map, int on) +{ + int ret; + + if (on) { + ret = regmap_update_bits(syscon_regmap, + INTCP_FLASHPROG_OFFSET, + CINTEGRATOR_FLMASK, + CINTEGRATOR_FLVPPEN | CINTEGRATOR_FLWREN); + if (ret) + pr_err("error setting CP VPP\n"); + } else { + ret = regmap_update_bits(syscon_regmap, + INTCP_FLASHPROG_OFFSET, + CINTEGRATOR_FLMASK, + 0); + if (ret) + pr_err("error setting CP VPP\n"); + } +} + +/* + * Flash protection handling for the Versatiles and RealViews + */ + +#define VERSATILE_SYS_FLASH_OFFSET 0x4C + +static void versatile_flash_set_vpp(struct map_info *map, int on) +{ + int ret; + + ret = regmap_update_bits(syscon_regmap, VERSATILE_SYS_FLASH_OFFSET, + 0x01, !!on); + if (ret) + pr_err("error setting Versatile VPP\n"); +} + +int of_flash_probe_versatile(struct platform_device *pdev, + struct device_node *np, + struct map_info *map) +{ + struct device_node *sysnp; + const struct of_device_id *devid; + struct regmap *rmap; + static enum versatile_flashprot versatile_flashprot; + int ret; + + /* Not all flash chips use this protection line */ + if (!of_device_is_compatible(np, "arm,versatile-flash")) + return 0; + + /* For first chip probed, look up the syscon regmap */ + if (!syscon_regmap) { + sysnp = of_find_matching_node_and_match(NULL, + syscon_match, + &devid); + if (!sysnp) + return -ENODEV; + + versatile_flashprot = (enum versatile_flashprot)devid->data; + rmap = syscon_node_to_regmap(sysnp); + if (IS_ERR(rmap)) + return PTR_ERR(rmap); + + syscon_regmap = rmap; + } + + switch (versatile_flashprot) { + case INTEGRATOR_AP_FLASHPROT: + ret = ap_flash_init(pdev); + if (ret) + return ret; + map->set_vpp = ap_flash_set_vpp; + dev_info(&pdev->dev, "Integrator/AP flash protection\n"); + break; + case INTEGRATOR_CP_FLASHPROT: + map->set_vpp = cp_flash_set_vpp; + dev_info(&pdev->dev, "Integrator/CP flash protection\n"); + break; + case VERSATILE_FLASHPROT: + case REALVIEW_FLASHPROT: + map->set_vpp = versatile_flash_set_vpp; + dev_info(&pdev->dev, "versatile/realview flash protection\n"); + break; + default: + dev_info(&pdev->dev, "device marked as Versatile flash " + "but no system controller was found\n"); + break; + } + + return 0; +} diff --git a/drivers/mtd/maps/physmap-versatile.h b/drivers/mtd/maps/physmap-versatile.h new file mode 100644 index 000000000000..9cf39d031f5a --- /dev/null +++ b/drivers/mtd/maps/physmap-versatile.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include + +#ifdef CONFIG_MTD_PHYSMAP_VERSATILE +int of_flash_probe_versatile(struct platform_device *pdev, + struct device_node *np, + struct map_info *map); +#else +static inline +int of_flash_probe_versatile(struct platform_device *pdev, + struct device_node *np, + struct map_info *map) +{ + return 0; +} +#endif diff --git a/drivers/mtd/maps/physmap_of_gemini.c b/drivers/mtd/maps/physmap_of_gemini.c deleted file mode 100644 index 9df62ca721d5..000000000000 --- a/drivers/mtd/maps/physmap_of_gemini.c +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * 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 */ - -int of_flash_probe_gemini(struct platform_device *pdev, - struct device_node *np, - struct map_info *map) -{ - 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_dbg(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); - } - - dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n"); - - return 0; -} diff --git a/drivers/mtd/maps/physmap_of_gemini.h b/drivers/mtd/maps/physmap_of_gemini.h deleted file mode 100644 index 60e13a689d6a..000000000000 --- a/drivers/mtd/maps/physmap_of_gemini.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#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 diff --git a/drivers/mtd/maps/physmap_of_versatile.c b/drivers/mtd/maps/physmap_of_versatile.c deleted file mode 100644 index 03f2b6e7bc7e..000000000000 --- a/drivers/mtd/maps/physmap_of_versatile.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Versatile OF physmap driver add-on - * - * Copyright (c) 2016, Linaro Limited - * Author: Linus Walleij - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "physmap_of_versatile.h" - -static struct regmap *syscon_regmap; - -enum versatile_flashprot { - INTEGRATOR_AP_FLASHPROT, - INTEGRATOR_CP_FLASHPROT, - VERSATILE_FLASHPROT, - REALVIEW_FLASHPROT, -}; - -static const struct of_device_id syscon_match[] = { - { - .compatible = "arm,integrator-ap-syscon", - .data = (void *)INTEGRATOR_AP_FLASHPROT, - }, - { - .compatible = "arm,integrator-cp-syscon", - .data = (void *)INTEGRATOR_CP_FLASHPROT, - }, - { - .compatible = "arm,core-module-versatile", - .data = (void *)VERSATILE_FLASHPROT, - }, - { - .compatible = "arm,realview-eb-syscon", - .data = (void *)REALVIEW_FLASHPROT, - }, - { - .compatible = "arm,realview-pb1176-syscon", - .data = (void *)REALVIEW_FLASHPROT, - }, - { - .compatible = "arm,realview-pb11mp-syscon", - .data = (void *)REALVIEW_FLASHPROT, - }, - { - .compatible = "arm,realview-pba8-syscon", - .data = (void *)REALVIEW_FLASHPROT, - }, - { - .compatible = "arm,realview-pbx-syscon", - .data = (void *)REALVIEW_FLASHPROT, - }, - {}, -}; - -/* - * Flash protection handling for the Integrator/AP - */ -#define INTEGRATOR_SC_CTRLS_OFFSET 0x08 -#define INTEGRATOR_SC_CTRLC_OFFSET 0x0C -#define INTEGRATOR_SC_CTRL_FLVPPEN BIT(1) -#define INTEGRATOR_SC_CTRL_FLWP BIT(2) - -#define INTEGRATOR_EBI_CSR1_OFFSET 0x04 -/* The manual says bit 2, the code says bit 3, trust the code */ -#define INTEGRATOR_EBI_WRITE_ENABLE BIT(3) -#define INTEGRATOR_EBI_LOCK_OFFSET 0x20 -#define INTEGRATOR_EBI_LOCK_VAL 0xA05F - -static const struct of_device_id ebi_match[] = { - { .compatible = "arm,external-bus-interface"}, - { }, -}; - -static int ap_flash_init(struct platform_device *pdev) -{ - struct device_node *ebi; - void __iomem *ebi_base; - u32 val; - int ret; - - /* Look up the EBI */ - ebi = of_find_matching_node(NULL, ebi_match); - if (!ebi) { - return -ENODEV; - } - ebi_base = of_iomap(ebi, 0); - if (!ebi_base) - return -ENODEV; - - /* Clear VPP and write protection bits */ - ret = regmap_write(syscon_regmap, - INTEGRATOR_SC_CTRLC_OFFSET, - INTEGRATOR_SC_CTRL_FLVPPEN | INTEGRATOR_SC_CTRL_FLWP); - if (ret) - dev_err(&pdev->dev, "error clearing Integrator VPP/WP\n"); - - /* Unlock the EBI */ - writel(INTEGRATOR_EBI_LOCK_VAL, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET); - - /* Enable write cycles on the EBI, CSR1 (flash) */ - val = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET); - val |= INTEGRATOR_EBI_WRITE_ENABLE; - writel(val, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET); - - /* Lock the EBI again */ - writel(0, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET); - iounmap(ebi_base); - - return 0; -} - -static void ap_flash_set_vpp(struct map_info *map, int on) -{ - int ret; - - if (on) { - ret = regmap_write(syscon_regmap, - INTEGRATOR_SC_CTRLS_OFFSET, - INTEGRATOR_SC_CTRL_FLVPPEN | INTEGRATOR_SC_CTRL_FLWP); - if (ret) - pr_err("error enabling AP VPP\n"); - } else { - ret = regmap_write(syscon_regmap, - INTEGRATOR_SC_CTRLC_OFFSET, - INTEGRATOR_SC_CTRL_FLVPPEN | INTEGRATOR_SC_CTRL_FLWP); - if (ret) - pr_err("error disabling AP VPP\n"); - } -} - -/* - * Flash protection handling for the Integrator/CP - */ - -#define INTCP_FLASHPROG_OFFSET 0x04 -#define CINTEGRATOR_FLVPPEN BIT(0) -#define CINTEGRATOR_FLWREN BIT(1) -#define CINTEGRATOR_FLMASK BIT(0)|BIT(1) - -static void cp_flash_set_vpp(struct map_info *map, int on) -{ - int ret; - - if (on) { - ret = regmap_update_bits(syscon_regmap, - INTCP_FLASHPROG_OFFSET, - CINTEGRATOR_FLMASK, - CINTEGRATOR_FLVPPEN | CINTEGRATOR_FLWREN); - if (ret) - pr_err("error setting CP VPP\n"); - } else { - ret = regmap_update_bits(syscon_regmap, - INTCP_FLASHPROG_OFFSET, - CINTEGRATOR_FLMASK, - 0); - if (ret) - pr_err("error setting CP VPP\n"); - } -} - -/* - * Flash protection handling for the Versatiles and RealViews - */ - -#define VERSATILE_SYS_FLASH_OFFSET 0x4C - -static void versatile_flash_set_vpp(struct map_info *map, int on) -{ - int ret; - - ret = regmap_update_bits(syscon_regmap, VERSATILE_SYS_FLASH_OFFSET, - 0x01, !!on); - if (ret) - pr_err("error setting Versatile VPP\n"); -} - -int of_flash_probe_versatile(struct platform_device *pdev, - struct device_node *np, - struct map_info *map) -{ - struct device_node *sysnp; - const struct of_device_id *devid; - struct regmap *rmap; - static enum versatile_flashprot versatile_flashprot; - int ret; - - /* Not all flash chips use this protection line */ - if (!of_device_is_compatible(np, "arm,versatile-flash")) - return 0; - - /* For first chip probed, look up the syscon regmap */ - if (!syscon_regmap) { - sysnp = of_find_matching_node_and_match(NULL, - syscon_match, - &devid); - if (!sysnp) - return -ENODEV; - - versatile_flashprot = (enum versatile_flashprot)devid->data; - rmap = syscon_node_to_regmap(sysnp); - if (IS_ERR(rmap)) - return PTR_ERR(rmap); - - syscon_regmap = rmap; - } - - switch (versatile_flashprot) { - case INTEGRATOR_AP_FLASHPROT: - ret = ap_flash_init(pdev); - if (ret) - return ret; - map->set_vpp = ap_flash_set_vpp; - dev_info(&pdev->dev, "Integrator/AP flash protection\n"); - break; - case INTEGRATOR_CP_FLASHPROT: - map->set_vpp = cp_flash_set_vpp; - dev_info(&pdev->dev, "Integrator/CP flash protection\n"); - break; - case VERSATILE_FLASHPROT: - case REALVIEW_FLASHPROT: - map->set_vpp = versatile_flash_set_vpp; - dev_info(&pdev->dev, "versatile/realview flash protection\n"); - break; - default: - dev_info(&pdev->dev, "device marked as Versatile flash " - "but no system controller was found\n"); - break; - } - - return 0; -} diff --git a/drivers/mtd/maps/physmap_of_versatile.h b/drivers/mtd/maps/physmap_of_versatile.h deleted file mode 100644 index 0302502c9462..000000000000 --- a/drivers/mtd/maps/physmap_of_versatile.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include - -#ifdef CONFIG_MTD_PHYSMAP_OF_VERSATILE -int of_flash_probe_versatile(struct platform_device *pdev, - struct device_node *np, - struct map_info *map); -#else -static inline -int of_flash_probe_versatile(struct platform_device *pdev, - struct device_node *np, - struct map_info *map) -{ - return 0; -} -#endif -- cgit v1.2.3