1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * ARM Integrator Logical Module bus driver
4*4882a593Smuzhiyun * Copyright (C) 2020 Linaro Ltd.
5*4882a593Smuzhiyun * Author: Linus Walleij <linus.walleij@linaro.org>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * See the device tree bindings for this block for more details on the
8*4882a593Smuzhiyun * hardware.
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/module.h>
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include <linux/io.h>
14*4882a593Smuzhiyun #include <linux/of.h>
15*4882a593Smuzhiyun #include <linux/of_address.h>
16*4882a593Smuzhiyun #include <linux/of_platform.h>
17*4882a593Smuzhiyun #include <linux/init.h>
18*4882a593Smuzhiyun #include <linux/slab.h>
19*4882a593Smuzhiyun #include <linux/platform_device.h>
20*4882a593Smuzhiyun #include <linux/bitops.h>
21*4882a593Smuzhiyun #include <linux/mfd/syscon.h>
22*4882a593Smuzhiyun #include <linux/regmap.h>
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /* All information about the connected logic modules are in here */
25*4882a593Smuzhiyun #define INTEGRATOR_SC_DEC_OFFSET 0x10
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /* Base address for the expansion modules */
28*4882a593Smuzhiyun #define INTEGRATOR_AP_EXP_BASE 0xc0000000
29*4882a593Smuzhiyun #define INTEGRATOR_AP_EXP_STRIDE 0x10000000
30*4882a593Smuzhiyun
integrator_lm_populate(int num,struct device * dev)31*4882a593Smuzhiyun static int integrator_lm_populate(int num, struct device *dev)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun struct device_node *np = dev->of_node;
34*4882a593Smuzhiyun struct device_node *child;
35*4882a593Smuzhiyun u32 base;
36*4882a593Smuzhiyun int ret;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun base = INTEGRATOR_AP_EXP_BASE + (num * INTEGRATOR_AP_EXP_STRIDE);
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun /* Walk over the child nodes and see what chipselects we use */
41*4882a593Smuzhiyun for_each_available_child_of_node(np, child) {
42*4882a593Smuzhiyun struct resource res;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun ret = of_address_to_resource(child, 0, &res);
45*4882a593Smuzhiyun if (ret) {
46*4882a593Smuzhiyun dev_info(dev, "no valid address on child\n");
47*4882a593Smuzhiyun continue;
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun /* First populate the syscon then any devices */
51*4882a593Smuzhiyun if (res.start == base) {
52*4882a593Smuzhiyun dev_info(dev, "populate module @0x%08x from DT\n",
53*4882a593Smuzhiyun base);
54*4882a593Smuzhiyun ret = of_platform_default_populate(child, NULL, dev);
55*4882a593Smuzhiyun if (ret) {
56*4882a593Smuzhiyun dev_err(dev, "failed to populate module\n");
57*4882a593Smuzhiyun return ret;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun return 0;
63*4882a593Smuzhiyun }
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun static const struct of_device_id integrator_ap_syscon_match[] = {
66*4882a593Smuzhiyun { .compatible = "arm,integrator-ap-syscon"},
67*4882a593Smuzhiyun { },
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun
integrator_ap_lm_probe(struct platform_device * pdev)70*4882a593Smuzhiyun static int integrator_ap_lm_probe(struct platform_device *pdev)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun struct device *dev = &pdev->dev;
73*4882a593Smuzhiyun struct device_node *syscon;
74*4882a593Smuzhiyun static struct regmap *map;
75*4882a593Smuzhiyun u32 val;
76*4882a593Smuzhiyun int ret;
77*4882a593Smuzhiyun int i;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /* Look up the system controller */
80*4882a593Smuzhiyun syscon = of_find_matching_node(NULL, integrator_ap_syscon_match);
81*4882a593Smuzhiyun if (!syscon) {
82*4882a593Smuzhiyun dev_err(dev,
83*4882a593Smuzhiyun "could not find Integrator/AP system controller\n");
84*4882a593Smuzhiyun return -ENODEV;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun map = syscon_node_to_regmap(syscon);
87*4882a593Smuzhiyun if (IS_ERR(map)) {
88*4882a593Smuzhiyun dev_err(dev,
89*4882a593Smuzhiyun "could not find Integrator/AP system controller\n");
90*4882a593Smuzhiyun return PTR_ERR(map);
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun ret = regmap_read(map, INTEGRATOR_SC_DEC_OFFSET, &val);
94*4882a593Smuzhiyun if (ret) {
95*4882a593Smuzhiyun dev_err(dev, "could not read from Integrator/AP syscon\n");
96*4882a593Smuzhiyun return ret;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /* Loop over the connected modules */
100*4882a593Smuzhiyun for (i = 0; i < 4; i++) {
101*4882a593Smuzhiyun if (!(val & BIT(4 + i)))
102*4882a593Smuzhiyun continue;
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun dev_info(dev, "detected module in slot %d\n", i);
105*4882a593Smuzhiyun ret = integrator_lm_populate(i, dev);
106*4882a593Smuzhiyun if (ret)
107*4882a593Smuzhiyun return ret;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun return 0;
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun static const struct of_device_id integrator_ap_lm_match[] = {
114*4882a593Smuzhiyun { .compatible = "arm,integrator-ap-lm"},
115*4882a593Smuzhiyun { },
116*4882a593Smuzhiyun };
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun static struct platform_driver integrator_ap_lm_driver = {
119*4882a593Smuzhiyun .probe = integrator_ap_lm_probe,
120*4882a593Smuzhiyun .driver = {
121*4882a593Smuzhiyun .name = "integratorap-lm",
122*4882a593Smuzhiyun .of_match_table = integrator_ap_lm_match,
123*4882a593Smuzhiyun },
124*4882a593Smuzhiyun };
125*4882a593Smuzhiyun module_platform_driver(integrator_ap_lm_driver);
126*4882a593Smuzhiyun MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
127*4882a593Smuzhiyun MODULE_DESCRIPTION("Integrator AP Logical Module driver");
128*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
129