mfd: vexpress-sysreg: Drop unused syscon child devices
[linux-2.6-microblaze.git] / drivers / mfd / vexpress-sysreg.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *
4  * Copyright (C) 2012 ARM Limited
5  */
6
7 #include <linux/gpio/driver.h>
8 #include <linux/err.h>
9 #include <linux/io.h>
10 #include <linux/mfd/core.h>
11 #include <linux/of_platform.h>
12 #include <linux/platform_data/syscon.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
15 #include <linux/stat.h>
16 #include <linux/vexpress.h>
17
18 #define SYS_ID                  0x000
19 #define SYS_SW                  0x004
20 #define SYS_LED                 0x008
21 #define SYS_100HZ               0x024
22 #define SYS_FLAGSSET            0x030
23 #define SYS_FLAGSCLR            0x034
24 #define SYS_NVFLAGS             0x038
25 #define SYS_NVFLAGSSET          0x038
26 #define SYS_NVFLAGSCLR          0x03c
27 #define SYS_MCI                 0x048
28 #define SYS_FLASH               0x04c
29 #define SYS_CFGSW               0x058
30 #define SYS_24MHZ               0x05c
31 #define SYS_MISC                0x060
32 #define SYS_DMA                 0x064
33 #define SYS_PROCID0             0x084
34 #define SYS_PROCID1             0x088
35 #define SYS_CFGDATA             0x0a0
36 #define SYS_CFGCTRL             0x0a4
37 #define SYS_CFGSTAT             0x0a8
38
39 #define SYS_HBI_MASK            0xfff
40 #define SYS_PROCIDx_HBI_SHIFT   0
41
42 #define SYS_MISC_MASTERSITE     (1 << 14)
43
44 /* The sysreg block is just a random collection of various functions... */
45
46 static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
47         .label = "sys_led",
48         .base = -1,
49         .ngpio = 8,
50 };
51
52 static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
53         .label = "sys_mci",
54         .base = -1,
55         .ngpio = 2,
56 };
57
58 static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
59         .label = "sys_flash",
60         .base = -1,
61         .ngpio = 1,
62 };
63
64 static struct mfd_cell vexpress_sysreg_cells[] = {
65         {
66                 .name = "basic-mmio-gpio",
67                 .of_compatible = "arm,vexpress-sysreg,sys_led",
68                 .num_resources = 1,
69                 .resources = (struct resource []) {
70                         DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
71                 },
72                 .platform_data = &vexpress_sysreg_sys_led_pdata,
73                 .pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
74         }, {
75                 .name = "basic-mmio-gpio",
76                 .of_compatible = "arm,vexpress-sysreg,sys_mci",
77                 .num_resources = 1,
78                 .resources = (struct resource []) {
79                         DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
80                 },
81                 .platform_data = &vexpress_sysreg_sys_mci_pdata,
82                 .pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
83         }, {
84                 .name = "basic-mmio-gpio",
85                 .of_compatible = "arm,vexpress-sysreg,sys_flash",
86                 .num_resources = 1,
87                 .resources = (struct resource []) {
88                         DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
89                 },
90                 .platform_data = &vexpress_sysreg_sys_flash_pdata,
91                 .pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
92         }, {
93                 .name = "vexpress-syscfg",
94                 .num_resources = 1,
95                 .resources = (struct resource []) {
96                         DEFINE_RES_MEM(SYS_CFGDATA, 0xc),
97                 },
98         }
99 };
100
101 static int vexpress_sysreg_probe(struct platform_device *pdev)
102 {
103         struct resource *mem;
104         void __iomem *base;
105         struct gpio_chip *mmc_gpio_chip;
106         int master;
107         u32 dt_hbi;
108
109         mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
110         if (!mem)
111                 return -EINVAL;
112
113         base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
114         if (!base)
115                 return -ENOMEM;
116
117         master = readl(base + SYS_MISC) & SYS_MISC_MASTERSITE ?
118                         VEXPRESS_SITE_DB2 : VEXPRESS_SITE_DB1;
119         vexpress_config_set_master(master);
120
121         /* Confirm board type against DT property, if available */
122         if (of_property_read_u32(of_root, "arm,hbi", &dt_hbi) == 0) {
123                 u32 id = readl(base + (master == VEXPRESS_SITE_DB1 ?
124                                  SYS_PROCID0 : SYS_PROCID1));
125                 u32 hbi = (id >> SYS_PROCIDx_HBI_SHIFT) & SYS_HBI_MASK;
126
127                 if (WARN_ON(dt_hbi != hbi))
128                         dev_warn(&pdev->dev, "DT HBI (%x) is not matching hardware (%x)!\n",
129                                         dt_hbi, hbi);
130         }
131
132         /*
133          * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
134          * older trees using sysreg node for MMC control lines.
135          */
136         mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
137                         GFP_KERNEL);
138         if (!mmc_gpio_chip)
139                 return -ENOMEM;
140         bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI,
141                         NULL, NULL, NULL, NULL, 0);
142         mmc_gpio_chip->ngpio = 2;
143         gpiochip_add_data(mmc_gpio_chip, NULL);
144
145         return mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
146                         vexpress_sysreg_cells,
147                         ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
148 }
149
150 static const struct of_device_id vexpress_sysreg_match[] = {
151         { .compatible = "arm,vexpress-sysreg", },
152         {},
153 };
154
155 static struct platform_driver vexpress_sysreg_driver = {
156         .driver = {
157                 .name = "vexpress-sysreg",
158                 .of_match_table = vexpress_sysreg_match,
159         },
160         .probe = vexpress_sysreg_probe,
161 };
162
163 static int __init vexpress_sysreg_init(void)
164 {
165         struct device_node *node;
166
167         /* Need the sysreg early, before any other device... */
168         for_each_matching_node(node, vexpress_sysreg_match)
169                 of_platform_device_create(node, NULL, NULL);
170
171         return platform_driver_register(&vexpress_sysreg_driver);
172 }
173 core_initcall(vexpress_sysreg_init);