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/module.h>
12 #include <linux/of_platform.h>
13 #include <linux/platform_data/syscon.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
16 #include <linux/stat.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 /* The sysreg block is just a random collection of various functions... */
41 static struct bgpio_pdata vexpress_sysreg_sys_led_pdata
= {
47 static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata
= {
53 static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata
= {
59 static struct mfd_cell vexpress_sysreg_cells
[] = {
61 .name
= "basic-mmio-gpio",
62 .of_compatible
= "arm,vexpress-sysreg,sys_led",
64 .resources
= (struct resource
[]) {
65 DEFINE_RES_MEM_NAMED(SYS_LED
, 0x4, "dat"),
67 .platform_data
= &vexpress_sysreg_sys_led_pdata
,
68 .pdata_size
= sizeof(vexpress_sysreg_sys_led_pdata
),
70 .name
= "basic-mmio-gpio",
71 .of_compatible
= "arm,vexpress-sysreg,sys_mci",
73 .resources
= (struct resource
[]) {
74 DEFINE_RES_MEM_NAMED(SYS_MCI
, 0x4, "dat"),
76 .platform_data
= &vexpress_sysreg_sys_mci_pdata
,
77 .pdata_size
= sizeof(vexpress_sysreg_sys_mci_pdata
),
79 .name
= "basic-mmio-gpio",
80 .of_compatible
= "arm,vexpress-sysreg,sys_flash",
82 .resources
= (struct resource
[]) {
83 DEFINE_RES_MEM_NAMED(SYS_FLASH
, 0x4, "dat"),
85 .platform_data
= &vexpress_sysreg_sys_flash_pdata
,
86 .pdata_size
= sizeof(vexpress_sysreg_sys_flash_pdata
),
88 .name
= "vexpress-syscfg",
90 .resources
= (struct resource
[]) {
91 DEFINE_RES_MEM(SYS_MISC
, 0x4c),
96 static int vexpress_sysreg_probe(struct platform_device
*pdev
)
100 struct gpio_chip
*mmc_gpio_chip
;
102 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
106 base
= devm_ioremap(&pdev
->dev
, mem
->start
, resource_size(mem
));
111 * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
112 * older trees using sysreg node for MMC control lines.
114 mmc_gpio_chip
= devm_kzalloc(&pdev
->dev
, sizeof(*mmc_gpio_chip
),
118 bgpio_init(mmc_gpio_chip
, &pdev
->dev
, 0x4, base
+ SYS_MCI
,
119 NULL
, NULL
, NULL
, NULL
, 0);
120 mmc_gpio_chip
->ngpio
= 2;
121 devm_gpiochip_add_data(&pdev
->dev
, mmc_gpio_chip
, NULL
);
123 return devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_AUTO
,
124 vexpress_sysreg_cells
,
125 ARRAY_SIZE(vexpress_sysreg_cells
), mem
, 0, NULL
);
128 static const struct of_device_id vexpress_sysreg_match
[] = {
129 { .compatible
= "arm,vexpress-sysreg", },
132 MODULE_DEVICE_TABLE(of
, vexpress_sysreg_match
);
134 static struct platform_driver vexpress_sysreg_driver
= {
136 .name
= "vexpress-sysreg",
137 .of_match_table
= vexpress_sysreg_match
,
139 .probe
= vexpress_sysreg_probe
,
142 module_platform_driver(vexpress_sysreg_driver
);
143 MODULE_LICENSE("GPL v2");