dnsmasq: move feature detection inside a shell func
[openwrt/staging/pepe2k.git] / target / linux / gemini / patches-4.19 / 0006-mtd-physmap_of_gemini-Handle-pin-control.patch
1 From 8e5e628a9de439d02914b85a48e1ac3e04ea486a Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Thu, 11 Oct 2018 20:03:49 +0200
4 Subject: [PATCH 06/18] mtd: physmap_of_gemini: Handle pin control
5
6 This enables the complex mapping for the Gemini and kicks in
7 custom read/write functions that will wrap the existing
8 simple functions in calls to enable/disable the parallel
9 flash pins using pin controls.
10
11 This is necessary on some hardware such as the D-Link
12 DIR-685 where all flash pins are patched in/out at the same
13 time, but some of the flash pins are in practice unused by
14 the flash and have anyway been reused as GPIO.
15
16 This concerns specifically CE1 on the Gemini. There is only
17 one flash chip, so only CE0 is used, and the line for CE1
18 has been reused as chip select for the emulated SPI port
19 connected to the display. If we try to use the same lines
20 for flash and GPIO at the same time, one of them will loose:
21 the GPIO line will disappear because it gets disconnected
22 from the pin when the flash group is muxed out.
23
24 Fix this by introducing two pin control states named simply
25 "enabled" and "disabled" and only enable the flash lines
26 when absolutely necessary (during read/write/copy). This
27 way, they are available for GPIO at all other times and
28 the display works.
29
30 Collect all the state variables in a struct named
31 struct gemini_flash and allocate this struct at probe
32 time.
33
34 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
35 ---
36 drivers/mtd/maps/Kconfig | 1 +
37 drivers/mtd/maps/physmap_of_gemini.c | 105 ++++++++++++++++++++++++++-
38 2 files changed, 105 insertions(+), 1 deletion(-)
39
40 --- a/drivers/mtd/maps/Kconfig
41 +++ b/drivers/mtd/maps/Kconfig
42 @@ -89,6 +89,7 @@ config MTD_PHYSMAP_OF_GEMINI
43 depends on MTD_PHYSMAP_OF
44 depends on MFD_SYSCON
45 default ARCH_GEMINI
46 + select MTD_COMPLEX_MAPPINGS
47 help
48 This provides some extra DT physmap parsing for the Gemini
49 platforms, some detection and setting up parallel mode on the
50 --- a/drivers/mtd/maps/physmap_of_gemini.c
51 +++ b/drivers/mtd/maps/physmap_of_gemini.c
52 @@ -10,9 +10,11 @@
53 #include <linux/of.h>
54 #include <linux/of_device.h>
55 #include <linux/mtd/map.h>
56 +#include <linux/mtd/xip.h>
57 #include <linux/mfd/syscon.h>
58 #include <linux/regmap.h>
59 #include <linux/bitops.h>
60 +#include <linux/pinctrl/consumer.h>
61 #include "physmap_of_gemini.h"
62
63 /*
64 @@ -49,6 +51,77 @@ static const struct of_device_id syscon_
65 { },
66 };
67
68 +struct gemini_flash {
69 + struct device *dev;
70 + struct pinctrl *p;
71 + struct pinctrl_state *enabled_state;
72 + struct pinctrl_state *disabled_state;
73 +};
74 +
75 +/* Static local state */
76 +static struct gemini_flash *gf;
77 +
78 +static void gemini_flash_enable_pins(void)
79 +{
80 + int ret;
81 +
82 + if (IS_ERR(gf->enabled_state))
83 + return;
84 + ret = pinctrl_select_state(gf->p, gf->enabled_state);
85 + if (ret)
86 + dev_err(gf->dev, "failed to enable pins\n");
87 +}
88 +
89 +static void gemini_flash_disable_pins(void)
90 +{
91 + int ret;
92 +
93 + if (IS_ERR(gf->disabled_state))
94 + return;
95 + ret = pinctrl_select_state(gf->p, gf->disabled_state);
96 + if (ret)
97 + dev_err(gf->dev, "failed to disable pins\n");
98 +}
99 +
100 +static map_word __xipram gemini_flash_map_read(struct map_info *map,
101 + unsigned long ofs)
102 +{
103 + map_word __xipram ret;
104 +
105 + gemini_flash_enable_pins();
106 + ret = inline_map_read(map, ofs);
107 + gemini_flash_disable_pins();
108 +
109 + return ret;
110 +}
111 +
112 +static void __xipram gemini_flash_map_write(struct map_info *map,
113 + const map_word datum,
114 + unsigned long ofs)
115 +{
116 + gemini_flash_enable_pins();
117 + inline_map_write(map, datum, ofs);
118 + gemini_flash_disable_pins();
119 +}
120 +
121 +static void __xipram gemini_flash_map_copy_from(struct map_info *map,
122 + void *to, unsigned long from,
123 + ssize_t len)
124 +{
125 + gemini_flash_enable_pins();
126 + inline_map_copy_from(map, to, from, len);
127 + gemini_flash_disable_pins();
128 +}
129 +
130 +static void __xipram gemini_flash_map_copy_to(struct map_info *map,
131 + unsigned long to,
132 + const void *from, ssize_t len)
133 +{
134 + gemini_flash_enable_pins();
135 + inline_map_copy_to(map, to, from, len);
136 + gemini_flash_disable_pins();
137 +}
138 +
139 int of_flash_probe_gemini(struct platform_device *pdev,
140 struct device_node *np,
141 struct map_info *map)
142 @@ -62,6 +135,11 @@ int of_flash_probe_gemini(struct platfor
143 if (!of_device_is_compatible(np, "cortina,gemini-flash"))
144 return 0;
145
146 + gf = devm_kzalloc(dev, sizeof(*gf), GFP_KERNEL);
147 + if (!gf)
148 + return -ENOMEM;
149 + gf->dev = dev;
150 +
151 rmap = syscon_regmap_lookup_by_phandle(np, "syscon");
152 if (IS_ERR(rmap)) {
153 dev_err(dev, "no syscon\n");
154 @@ -96,7 +174,32 @@ int of_flash_probe_gemini(struct platfor
155 map->bankwidth * 8);
156 }
157
158 - dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n");
159 + gf->p = devm_pinctrl_get(dev);
160 + if (IS_ERR(gf->p)) {
161 + dev_err(dev, "no pinctrl handle\n");
162 + ret = PTR_ERR(gf->p);
163 + return ret;
164 + }
165 +
166 + gf->enabled_state = pinctrl_lookup_state(gf->p, "enabled");
167 + if (IS_ERR(gf->enabled_state))
168 + dev_err(dev, "no enabled pin control state\n");
169 +
170 + gf->disabled_state = pinctrl_lookup_state(gf->p, "disabled");
171 + if (IS_ERR(gf->enabled_state)) {
172 + dev_err(dev, "no disabled pin control state\n");
173 + } else {
174 + ret = pinctrl_select_state(gf->p, gf->disabled_state);
175 + if (ret)
176 + dev_err(gf->dev, "failed to disable pins\n");
177 + }
178 +
179 + map->read = gemini_flash_map_read;
180 + map->write = gemini_flash_map_write;
181 + map->copy_from = gemini_flash_map_copy_from;
182 + map->copy_to = gemini_flash_map_copy_to;
183 +
184 + dev_info(dev, "initialized Gemini-specific physmap control\n");
185
186 return 0;
187 }