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
= &DEFINE_RES_MEM_NAMED(SYS_LED
, 0x4, "dat"),
65 .platform_data
= &vexpress_sysreg_sys_led_pdata
,
66 .pdata_size
= sizeof(vexpress_sysreg_sys_led_pdata
),
68 .name
= "basic-mmio-gpio",
69 .of_compatible
= "arm,vexpress-sysreg,sys_mci",
71 .resources
= &DEFINE_RES_MEM_NAMED(SYS_MCI
, 0x4, "dat"),
72 .platform_data
= &vexpress_sysreg_sys_mci_pdata
,
73 .pdata_size
= sizeof(vexpress_sysreg_sys_mci_pdata
),
75 .name
= "basic-mmio-gpio",
76 .of_compatible
= "arm,vexpress-sysreg,sys_flash",
78 .resources
= &DEFINE_RES_MEM_NAMED(SYS_FLASH
, 0x4, "dat"),
79 .platform_data
= &vexpress_sysreg_sys_flash_pdata
,
80 .pdata_size
= sizeof(vexpress_sysreg_sys_flash_pdata
),
82 .name
= "vexpress-syscfg",
84 .resources
= &DEFINE_RES_MEM(SYS_MISC
, 0x4c),
88 static int vexpress_sysreg_probe(struct platform_device
*pdev
)
92 struct gpio_chip
*mmc_gpio_chip
;
94 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
98 base
= devm_ioremap(&pdev
->dev
, mem
->start
, resource_size(mem
));
103 * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
104 * older trees using sysreg node for MMC control lines.
106 mmc_gpio_chip
= devm_kzalloc(&pdev
->dev
, sizeof(*mmc_gpio_chip
),
110 bgpio_init(mmc_gpio_chip
, &pdev
->dev
, 0x4, base
+ SYS_MCI
,
111 NULL
, NULL
, NULL
, NULL
, 0);
112 mmc_gpio_chip
->ngpio
= 2;
113 devm_gpiochip_add_data(&pdev
->dev
, mmc_gpio_chip
, NULL
);
115 return devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_AUTO
,
116 vexpress_sysreg_cells
,
117 ARRAY_SIZE(vexpress_sysreg_cells
), mem
, 0, NULL
);
120 static const struct of_device_id vexpress_sysreg_match
[] = {
121 { .compatible
= "arm,vexpress-sysreg", },
124 MODULE_DEVICE_TABLE(of
, vexpress_sysreg_match
);
126 static struct platform_driver vexpress_sysreg_driver
= {
128 .name
= "vexpress-sysreg",
129 .of_match_table
= vexpress_sysreg_match
,
131 .probe
= vexpress_sysreg_probe
,
134 module_platform_driver(vexpress_sysreg_driver
);
135 MODULE_DESCRIPTION("Versatile Express system registers driver");
136 MODULE_LICENSE("GPL v2");