1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2012 ARM Limited
7 #include <linux/gpio/driver.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>
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
28 #define SYS_FLASH 0x04c
29 #define SYS_CFGSW 0x058
30 #define SYS_24MHZ 0x05c
31 #define SYS_MISC 0x060
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
39 #define SYS_HBI_MASK 0xfff
40 #define SYS_PROCIDx_HBI_SHIFT 0
42 #define SYS_MISC_MASTERSITE (1 << 14)
44 /* The sysreg block is just a random collection of various functions... */
46 static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
52 static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
58 static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
64 static struct mfd_cell vexpress_sysreg_cells[] = {
66 .name = "basic-mmio-gpio",
67 .of_compatible = "arm,vexpress-sysreg,sys_led",
69 .resources = (struct resource []) {
70 DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
72 .platform_data = &vexpress_sysreg_sys_led_pdata,
73 .pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
75 .name = "basic-mmio-gpio",
76 .of_compatible = "arm,vexpress-sysreg,sys_mci",
78 .resources = (struct resource []) {
79 DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
81 .platform_data = &vexpress_sysreg_sys_mci_pdata,
82 .pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
84 .name = "basic-mmio-gpio",
85 .of_compatible = "arm,vexpress-sysreg,sys_flash",
87 .resources = (struct resource []) {
88 DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
90 .platform_data = &vexpress_sysreg_sys_flash_pdata,
91 .pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
93 .name = "vexpress-syscfg",
95 .resources = (struct resource []) {
96 DEFINE_RES_MEM(SYS_CFGDATA, 0xc),
101 static int vexpress_sysreg_probe(struct platform_device *pdev)
103 struct resource *mem;
105 struct gpio_chip *mmc_gpio_chip;
109 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
113 base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
117 master = readl(base + SYS_MISC) & SYS_MISC_MASTERSITE ?
118 VEXPRESS_SITE_DB2 : VEXPRESS_SITE_DB1;
119 vexpress_config_set_master(master);
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;
127 if (WARN_ON(dt_hbi != hbi))
128 dev_warn(&pdev->dev, "DT HBI (%x) is not matching hardware (%x)!\n",
133 * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
134 * older trees using sysreg node for MMC control lines.
136 mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
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);
145 return mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
146 vexpress_sysreg_cells,
147 ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
150 static const struct of_device_id vexpress_sysreg_match[] = {
151 { .compatible = "arm,vexpress-sysreg", },
155 static struct platform_driver vexpress_sysreg_driver = {
157 .name = "vexpress-sysreg",
158 .of_match_table = vexpress_sysreg_match,
160 .probe = vexpress_sysreg_probe,
163 static int __init vexpress_sysreg_init(void)
165 struct device_node *node;
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);
171 return platform_driver_register(&vexpress_sysreg_driver);
173 core_initcall(vexpress_sysreg_init);