1 // SPDX-License-Identifier: GPL-2.0-only
3 * ARM Integrator Logical Module bus driver
4 * Copyright (C) 2020 Linaro Ltd.
5 * Author: Linus Walleij <linus.walleij@linaro.org>
7 * See the device tree bindings for this block for more details on the
11 #include <linux/module.h>
12 #include <linux/err.h>
15 #include <linux/of_address.h>
16 #include <linux/of_platform.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/platform_device.h>
20 #include <linux/bitops.h>
21 #include <linux/mfd/syscon.h>
22 #include <linux/regmap.h>
24 /* All information about the connected logic modules are in here */
25 #define INTEGRATOR_SC_DEC_OFFSET 0x10
27 /* Base address for the expansion modules */
28 #define INTEGRATOR_AP_EXP_BASE 0xc0000000
29 #define INTEGRATOR_AP_EXP_STRIDE 0x10000000
31 static int integrator_lm_populate(int num
, struct device
*dev
)
33 struct device_node
*np
= dev
->of_node
;
34 struct device_node
*child
;
38 base
= INTEGRATOR_AP_EXP_BASE
+ (num
* INTEGRATOR_AP_EXP_STRIDE
);
40 /* Walk over the child nodes and see what chipselects we use */
41 for_each_available_child_of_node(np
, child
) {
44 ret
= of_address_to_resource(child
, 0, &res
);
46 dev_info(dev
, "no valid address on child\n");
50 /* First populate the syscon then any devices */
51 if (res
.start
== base
) {
52 dev_info(dev
, "populate module @0x%08x from DT\n",
54 ret
= of_platform_default_populate(child
, NULL
, dev
);
56 dev_err(dev
, "failed to populate module\n");
66 static const struct of_device_id integrator_ap_syscon_match
[] = {
67 { .compatible
= "arm,integrator-ap-syscon"},
71 static int integrator_ap_lm_probe(struct platform_device
*pdev
)
73 struct device
*dev
= &pdev
->dev
;
74 struct device_node
*syscon
;
75 static struct regmap
*map
;
80 /* Look up the system controller */
81 syscon
= of_find_matching_node(NULL
, integrator_ap_syscon_match
);
84 "could not find Integrator/AP system controller\n");
87 map
= syscon_node_to_regmap(syscon
);
91 "could not find Integrator/AP system controller\n");
95 ret
= regmap_read(map
, INTEGRATOR_SC_DEC_OFFSET
, &val
);
97 dev_err(dev
, "could not read from Integrator/AP syscon\n");
101 /* Loop over the connected modules */
102 for (i
= 0; i
< 4; i
++) {
103 if (!(val
& BIT(4 + i
)))
106 dev_info(dev
, "detected module in slot %d\n", i
);
107 ret
= integrator_lm_populate(i
, dev
);
115 static const struct of_device_id integrator_ap_lm_match
[] = {
116 { .compatible
= "arm,integrator-ap-lm"},
120 static struct platform_driver integrator_ap_lm_driver
= {
121 .probe
= integrator_ap_lm_probe
,
123 .name
= "integratorap-lm",
124 .of_match_table
= integrator_ap_lm_match
,
127 module_platform_driver(integrator_ap_lm_driver
);
128 MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
129 MODULE_DESCRIPTION("Integrator AP Logical Module driver");