]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - drivers/mtd/maps/physmap_of_gemini.c
Merge branch 'for-4.14-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[mirror_ubuntu-focal-kernel.git] / drivers / mtd / maps / physmap_of_gemini.c
1 /*
2 * Cortina Systems Gemini OF physmap add-on
3 * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
4 *
5 * This SoC has an elaborate flash control register, so we need to
6 * detect and set it up when booting on this platform.
7 */
8 #include <linux/export.h>
9 #include <linux/of.h>
10 #include <linux/of_device.h>
11 #include <linux/mtd/map.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/regmap.h>
14 #include <linux/bitops.h>
15 #include "physmap_of_gemini.h"
16
17 /*
18 * The Flash-relevant parts of the global status register
19 * These would also be relevant for a NAND driver.
20 */
21 #define GLOBAL_STATUS 0x04
22 #define FLASH_TYPE_MASK (0x3 << 24)
23 #define FLASH_TYPE_NAND_2K (0x3 << 24)
24 #define FLASH_TYPE_NAND_512 (0x2 << 24)
25 #define FLASH_TYPE_PARALLEL (0x1 << 24)
26 #define FLASH_TYPE_SERIAL (0x0 << 24)
27 /* if parallel */
28 #define FLASH_WIDTH_16BIT (1 << 23) /* else 8 bit */
29 /* if serial */
30 #define FLASH_ATMEL (1 << 23) /* else STM */
31
32 #define FLASH_SIZE_MASK (0x3 << 21)
33 #define NAND_256M (0x3 << 21) /* and more */
34 #define NAND_128M (0x2 << 21)
35 #define NAND_64M (0x1 << 21)
36 #define NAND_32M (0x0 << 21)
37 #define ATMEL_16M (0x3 << 21) /* and more */
38 #define ATMEL_8M (0x2 << 21)
39 #define ATMEL_4M_2M (0x1 << 21)
40 #define ATMEL_1M (0x0 << 21) /* and less */
41 #define STM_32M (1 << 22) /* and more */
42 #define STM_16M (0 << 22) /* and less */
43
44 #define FLASH_PARALLEL_HIGH_PIN_CNT (1 << 20) /* else low pin cnt */
45
46 static const struct of_device_id syscon_match[] = {
47 { .compatible = "cortina,gemini-syscon" },
48 { },
49 };
50
51 int of_flash_probe_gemini(struct platform_device *pdev,
52 struct device_node *np,
53 struct map_info *map)
54 {
55 struct regmap *rmap;
56 struct device *dev = &pdev->dev;
57 u32 val;
58 int ret;
59
60 /* Multiplatform guard */
61 if (!of_device_is_compatible(np, "cortina,gemini-flash"))
62 return 0;
63
64 rmap = syscon_regmap_lookup_by_phandle(np, "syscon");
65 if (IS_ERR(rmap)) {
66 dev_err(dev, "no syscon\n");
67 return PTR_ERR(rmap);
68 }
69
70 ret = regmap_read(rmap, GLOBAL_STATUS, &val);
71 if (ret) {
72 dev_err(dev, "failed to read global status register\n");
73 return -ENODEV;
74 }
75 dev_dbg(dev, "global status reg: %08x\n", val);
76
77 /*
78 * It would be contradictory if a physmap flash was NOT parallel.
79 */
80 if ((val & FLASH_TYPE_MASK) != FLASH_TYPE_PARALLEL) {
81 dev_err(dev, "flash is not parallel\n");
82 return -ENODEV;
83 }
84
85 /*
86 * Complain if DT data and hardware definition is different.
87 */
88 if (val & FLASH_WIDTH_16BIT) {
89 if (map->bankwidth != 2)
90 dev_warn(dev, "flash hardware say flash is 16 bit wide but DT says it is %d bits wide\n",
91 map->bankwidth * 8);
92 } else {
93 if (map->bankwidth != 1)
94 dev_warn(dev, "flash hardware say flash is 8 bit wide but DT says it is %d bits wide\n",
95 map->bankwidth * 8);
96 }
97
98 dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n");
99
100 return 0;
101 }