2 * Versatile OF physmap driver add-on
4 * Copyright (c) 2016, Linaro Limited
5 * Author: Linus Walleij <linus.walleij@linaro.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #include <linux/export.h>
25 #include <linux/of_address.h>
26 #include <linux/of_device.h>
27 #include <linux/mtd/map.h>
28 #include <linux/mfd/syscon.h>
29 #include <linux/regmap.h>
30 #include <linux/bitops.h>
31 #include "physmap_of_versatile.h"
33 static struct regmap
*syscon_regmap
;
35 enum versatile_flashprot
{
36 INTEGRATOR_AP_FLASHPROT
,
37 INTEGRATOR_CP_FLASHPROT
,
42 static const struct of_device_id syscon_match
[] = {
44 .compatible
= "arm,integrator-ap-syscon",
45 .data
= (void *)INTEGRATOR_AP_FLASHPROT
,
48 .compatible
= "arm,integrator-cp-syscon",
49 .data
= (void *)INTEGRATOR_CP_FLASHPROT
,
52 .compatible
= "arm,core-module-versatile",
53 .data
= (void *)VERSATILE_FLASHPROT
,
56 .compatible
= "arm,realview-eb-syscon",
57 .data
= (void *)REALVIEW_FLASHPROT
,
60 .compatible
= "arm,realview-pb1176-syscon",
61 .data
= (void *)REALVIEW_FLASHPROT
,
64 .compatible
= "arm,realview-pb11mp-syscon",
65 .data
= (void *)REALVIEW_FLASHPROT
,
68 .compatible
= "arm,realview-pba8-syscon",
69 .data
= (void *)REALVIEW_FLASHPROT
,
72 .compatible
= "arm,realview-pbx-syscon",
73 .data
= (void *)REALVIEW_FLASHPROT
,
79 * Flash protection handling for the Integrator/AP
81 #define INTEGRATOR_SC_CTRLS_OFFSET 0x08
82 #define INTEGRATOR_SC_CTRLC_OFFSET 0x0C
83 #define INTEGRATOR_SC_CTRL_FLVPPEN BIT(1)
84 #define INTEGRATOR_SC_CTRL_FLWP BIT(2)
86 #define INTEGRATOR_EBI_CSR1_OFFSET 0x04
87 /* The manual says bit 2, the code says bit 3, trust the code */
88 #define INTEGRATOR_EBI_WRITE_ENABLE BIT(3)
89 #define INTEGRATOR_EBI_LOCK_OFFSET 0x20
90 #define INTEGRATOR_EBI_LOCK_VAL 0xA05F
92 static const struct of_device_id ebi_match
[] = {
93 { .compatible
= "arm,external-bus-interface"},
97 static int ap_flash_init(struct platform_device
*pdev
)
99 struct device_node
*ebi
;
100 static void __iomem
*ebi_base
;
104 /* Look up the EBI */
105 ebi
= of_find_matching_node(NULL
, ebi_match
);
109 ebi_base
= of_iomap(ebi
, 0);
113 /* Clear VPP and write protection bits */
114 ret
= regmap_write(syscon_regmap
,
115 INTEGRATOR_SC_CTRLC_OFFSET
,
116 INTEGRATOR_SC_CTRL_FLVPPEN
| INTEGRATOR_SC_CTRL_FLWP
);
118 dev_err(&pdev
->dev
, "error clearing Integrator VPP/WP\n");
121 writel(INTEGRATOR_EBI_LOCK_VAL
, ebi_base
+ INTEGRATOR_EBI_LOCK_OFFSET
);
123 /* Enable write cycles on the EBI, CSR1 (flash) */
124 val
= readl(ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
);
125 val
|= INTEGRATOR_EBI_WRITE_ENABLE
;
126 writel(val
, ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
);
128 /* Lock the EBI again */
129 writel(0, ebi_base
+ INTEGRATOR_EBI_LOCK_OFFSET
);
135 static void ap_flash_set_vpp(struct map_info
*map
, int on
)
140 ret
= regmap_write(syscon_regmap
,
141 INTEGRATOR_SC_CTRLS_OFFSET
,
142 INTEGRATOR_SC_CTRL_FLVPPEN
| INTEGRATOR_SC_CTRL_FLWP
);
144 pr_err("error enabling AP VPP\n");
146 ret
= regmap_write(syscon_regmap
,
147 INTEGRATOR_SC_CTRLC_OFFSET
,
148 INTEGRATOR_SC_CTRL_FLVPPEN
| INTEGRATOR_SC_CTRL_FLWP
);
150 pr_err("error disabling AP VPP\n");
155 * Flash protection handling for the Integrator/CP
158 #define INTCP_FLASHPROG_OFFSET 0x04
159 #define CINTEGRATOR_FLVPPEN BIT(0)
160 #define CINTEGRATOR_FLWREN BIT(1)
161 #define CINTEGRATOR_FLMASK BIT(0)|BIT(1)
163 static void cp_flash_set_vpp(struct map_info
*map
, int on
)
168 ret
= regmap_update_bits(syscon_regmap
,
169 INTCP_FLASHPROG_OFFSET
,
171 CINTEGRATOR_FLVPPEN
| CINTEGRATOR_FLWREN
);
173 pr_err("error setting CP VPP\n");
175 ret
= regmap_update_bits(syscon_regmap
,
176 INTCP_FLASHPROG_OFFSET
,
180 pr_err("error setting CP VPP\n");
185 * Flash protection handling for the Versatiles and RealViews
188 #define VERSATILE_SYS_FLASH_OFFSET 0x4C
190 static void versatile_flash_set_vpp(struct map_info
*map
, int on
)
194 ret
= regmap_update_bits(syscon_regmap
, VERSATILE_SYS_FLASH_OFFSET
,
197 pr_err("error setting Versatile VPP\n");
200 int of_flash_probe_versatile(struct platform_device
*pdev
,
201 struct device_node
*np
,
202 struct map_info
*map
)
204 struct device_node
*sysnp
;
205 const struct of_device_id
*devid
;
207 static enum versatile_flashprot versatile_flashprot
;
210 /* Not all flash chips use this protection line */
211 if (!of_device_is_compatible(np
, "arm,versatile-flash"))
214 /* For first chip probed, look up the syscon regmap */
215 if (!syscon_regmap
) {
216 sysnp
= of_find_matching_node_and_match(NULL
,
222 versatile_flashprot
= (enum versatile_flashprot
)devid
->data
;
223 rmap
= syscon_node_to_regmap(sysnp
);
225 return PTR_ERR(rmap
);
227 syscon_regmap
= rmap
;
230 switch (versatile_flashprot
) {
231 case INTEGRATOR_AP_FLASHPROT
:
232 ret
= ap_flash_init(pdev
);
235 map
->set_vpp
= ap_flash_set_vpp
;
236 dev_info(&pdev
->dev
, "Integrator/AP flash protection\n");
238 case INTEGRATOR_CP_FLASHPROT
:
239 map
->set_vpp
= cp_flash_set_vpp
;
240 dev_info(&pdev
->dev
, "Integrator/CP flash protection\n");
242 case VERSATILE_FLASHPROT
:
243 case REALVIEW_FLASHPROT
:
244 map
->set_vpp
= versatile_flash_set_vpp
;
245 dev_info(&pdev
->dev
, "versatile/realview flash protection\n");
248 dev_info(&pdev
->dev
, "device marked as Versatile flash "
249 "but no system controller was found\n");