2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * Copyright (C) 2012 ARM Limited
14 #include <linux/basic_mmio_gpio.h>
15 #include <linux/err.h>
17 #include <linux/mfd/core.h>
18 #include <linux/of_address.h>
19 #include <linux/of_platform.h>
20 #include <linux/platform_data/syscon.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
23 #include <linux/stat.h>
24 #include <linux/vexpress.h>
29 #define SYS_100HZ 0x024
30 #define SYS_FLAGSSET 0x030
31 #define SYS_FLAGSCLR 0x034
32 #define SYS_NVFLAGS 0x038
33 #define SYS_NVFLAGSSET 0x038
34 #define SYS_NVFLAGSCLR 0x03c
36 #define SYS_FLASH 0x04c
37 #define SYS_CFGSW 0x058
38 #define SYS_24MHZ 0x05c
39 #define SYS_MISC 0x060
41 #define SYS_PROCID0 0x084
42 #define SYS_PROCID1 0x088
43 #define SYS_CFGDATA 0x0a0
44 #define SYS_CFGCTRL 0x0a4
45 #define SYS_CFGSTAT 0x0a8
47 #define SYS_HBI_MASK 0xfff
48 #define SYS_PROCIDx_HBI_SHIFT 0
50 #define SYS_MISC_MASTERSITE (1 << 14)
52 void vexpress_flags_set(u32 data)
54 static void __iomem *base;
57 struct device_node *node = of_find_compatible_node(NULL, NULL,
58 "arm,vexpress-sysreg");
60 base = of_iomap(node, 0);
66 writel(~0, base + SYS_FLAGSCLR);
67 writel(data, base + SYS_FLAGSSET);
70 /* The sysreg block is just a random collection of various functions... */
72 static struct syscon_platform_data vexpress_sysreg_sys_id_pdata = {
76 static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
82 static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
88 static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
94 static struct syscon_platform_data vexpress_sysreg_sys_misc_pdata = {
98 static struct syscon_platform_data vexpress_sysreg_sys_procid_pdata = {
99 .label = "sys_procid",
102 static struct mfd_cell vexpress_sysreg_cells[] = {
106 .resources = (struct resource []) {
107 DEFINE_RES_MEM(SYS_ID, 0x4),
109 .platform_data = &vexpress_sysreg_sys_id_pdata,
110 .pdata_size = sizeof(vexpress_sysreg_sys_id_pdata),
112 .name = "basic-mmio-gpio",
113 .of_compatible = "arm,vexpress-sysreg,sys_led",
115 .resources = (struct resource []) {
116 DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
118 .platform_data = &vexpress_sysreg_sys_led_pdata,
119 .pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
121 .name = "basic-mmio-gpio",
122 .of_compatible = "arm,vexpress-sysreg,sys_mci",
124 .resources = (struct resource []) {
125 DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
127 .platform_data = &vexpress_sysreg_sys_mci_pdata,
128 .pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
130 .name = "basic-mmio-gpio",
131 .of_compatible = "arm,vexpress-sysreg,sys_flash",
133 .resources = (struct resource []) {
134 DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
136 .platform_data = &vexpress_sysreg_sys_flash_pdata,
137 .pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
141 .resources = (struct resource []) {
142 DEFINE_RES_MEM(SYS_MISC, 0x4),
144 .platform_data = &vexpress_sysreg_sys_misc_pdata,
145 .pdata_size = sizeof(vexpress_sysreg_sys_misc_pdata),
149 .resources = (struct resource []) {
150 DEFINE_RES_MEM(SYS_PROCID0, 0x8),
152 .platform_data = &vexpress_sysreg_sys_procid_pdata,
153 .pdata_size = sizeof(vexpress_sysreg_sys_procid_pdata),
155 .name = "vexpress-syscfg",
157 .resources = (struct resource []) {
158 DEFINE_RES_MEM(SYS_CFGDATA, 0xc),
163 static int vexpress_sysreg_probe(struct platform_device *pdev)
165 struct resource *mem;
167 struct bgpio_chip *mmc_gpio_chip;
171 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
175 base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
179 master = readl(base + SYS_MISC) & SYS_MISC_MASTERSITE ?
180 VEXPRESS_SITE_DB2 : VEXPRESS_SITE_DB1;
181 vexpress_config_set_master(master);
183 /* Confirm board type against DT property, if available */
184 if (of_property_read_u32(of_root, "arm,hbi", &dt_hbi) == 0) {
185 u32 id = readl(base + (master == VEXPRESS_SITE_DB1 ?
186 SYS_PROCID0 : SYS_PROCID1));
187 u32 hbi = (id >> SYS_PROCIDx_HBI_SHIFT) & SYS_HBI_MASK;
189 if (WARN_ON(dt_hbi != hbi))
190 dev_warn(&pdev->dev, "DT HBI (%x) is not matching hardware (%x)!\n",
195 * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
196 * older trees using sysreg node for MMC control lines.
198 mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
202 bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI,
203 NULL, NULL, NULL, NULL, 0);
204 mmc_gpio_chip->gc.ngpio = 2;
205 gpiochip_add(&mmc_gpio_chip->gc);
207 return mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
208 vexpress_sysreg_cells,
209 ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
212 static const struct of_device_id vexpress_sysreg_match[] = {
213 { .compatible = "arm,vexpress-sysreg", },
217 static struct platform_driver vexpress_sysreg_driver = {
219 .name = "vexpress-sysreg",
220 .of_match_table = vexpress_sysreg_match,
222 .probe = vexpress_sysreg_probe,
225 static int __init vexpress_sysreg_init(void)
227 struct device_node *node;
229 /* Need the sysreg early, before any other device... */
230 for_each_matching_node(node, vexpress_sysreg_match)
231 of_platform_device_create(node, NULL, NULL);
233 return platform_driver_register(&vexpress_sysreg_driver);
235 core_initcall(vexpress_sysreg_init);