blob: aaf24af287dd367bdd653dc908018ece17b16231 [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001// SPDX-License-Identifier: GPL-2.0-only
Pawel Moll88e0abc2012-09-18 12:24:57 +01002/*
Pawel Moll88e0abc2012-09-18 12:24:57 +01003 *
4 * Copyright (C) 2012 ARM Limited
5 */
6
Linus Walleij0f4630f2015-12-04 14:02:58 +01007#include <linux/gpio/driver.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +01008#include <linux/err.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +01009#include <linux/io.h>
Pawel Moll974cc7b2014-04-23 10:49:31 +010010#include <linux/mfd/core.h>
Rob Herring7b9d4282020-04-29 15:58:20 -050011#include <linux/module.h>
Pawel Moll3b9334a2014-04-30 16:46:29 +010012#include <linux/of_platform.h>
Pawel Moll974cc7b2014-04-23 10:49:31 +010013#include <linux/platform_data/syscon.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +010014#include <linux/platform_device.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +010015#include <linux/slab.h>
16#include <linux/stat.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +010017
18#define SYS_ID 0x000
19#define SYS_SW 0x004
20#define SYS_LED 0x008
21#define SYS_100HZ 0x024
Pawel Moll88e0abc2012-09-18 12:24:57 +010022#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
Pawel Moll974cc7b2014-04-23 10:49:31 +010039/* The sysreg block is just a random collection of various functions... */
Pawel Moll8eb12b92013-06-11 11:56:02 +010040
Pawel Moll974cc7b2014-04-23 10:49:31 +010041static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
42 .label = "sys_led",
43 .base = -1,
44 .ngpio = 8,
45};
46
47static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
48 .label = "sys_mci",
49 .base = -1,
50 .ngpio = 2,
51};
52
53static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
54 .label = "sys_flash",
55 .base = -1,
56 .ngpio = 1,
57};
58
Pawel Moll974cc7b2014-04-23 10:49:31 +010059static struct mfd_cell vexpress_sysreg_cells[] = {
60 {
Pawel Moll974cc7b2014-04-23 10:49:31 +010061 .name = "basic-mmio-gpio",
62 .of_compatible = "arm,vexpress-sysreg,sys_led",
63 .num_resources = 1,
64 .resources = (struct resource []) {
65 DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
66 },
67 .platform_data = &vexpress_sysreg_sys_led_pdata,
68 .pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
69 }, {
70 .name = "basic-mmio-gpio",
71 .of_compatible = "arm,vexpress-sysreg,sys_mci",
72 .num_resources = 1,
73 .resources = (struct resource []) {
74 DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
75 },
76 .platform_data = &vexpress_sysreg_sys_mci_pdata,
77 .pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
78 }, {
79 .name = "basic-mmio-gpio",
80 .of_compatible = "arm,vexpress-sysreg,sys_flash",
81 .num_resources = 1,
82 .resources = (struct resource []) {
83 DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
84 },
85 .platform_data = &vexpress_sysreg_sys_flash_pdata,
86 .pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
87 }, {
Pawel Moll974cc7b2014-04-23 10:49:31 +010088 .name = "vexpress-syscfg",
89 .num_resources = 1,
90 .resources = (struct resource []) {
Rob Herring310f80d2020-04-29 15:58:23 -050091 DEFINE_RES_MEM(SYS_MISC, 0x4c),
Pawel Moll974cc7b2014-04-23 10:49:31 +010092 },
Pawel Moll8ea402f2013-01-30 10:33:16 +000093 }
Pawel Moll88e0abc2012-09-18 12:24:57 +010094};
95
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -080096static int vexpress_sysreg_probe(struct platform_device *pdev)
Pawel Moll88e0abc2012-09-18 12:24:57 +010097{
Pawel Moll974cc7b2014-04-23 10:49:31 +010098 struct resource *mem;
99 void __iomem *base;
Linus Walleij0f4630f2015-12-04 14:02:58 +0100100 struct gpio_chip *mmc_gpio_chip;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100101
Pawel Moll974cc7b2014-04-23 10:49:31 +0100102 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
103 if (!mem)
104 return -EINVAL;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100105
Pawel Moll974cc7b2014-04-23 10:49:31 +0100106 base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
107 if (!base)
108 return -ENOMEM;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100109
Pawel Moll974cc7b2014-04-23 10:49:31 +0100110 /*
111 * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
112 * older trees using sysreg node for MMC control lines.
113 */
114 mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
115 GFP_KERNEL);
116 if (!mmc_gpio_chip)
117 return -ENOMEM;
118 bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI,
119 NULL, NULL, NULL, NULL, 0);
Linus Walleij0f4630f2015-12-04 14:02:58 +0100120 mmc_gpio_chip->ngpio = 2;
Rob Herring0ea355e2020-04-29 15:58:19 -0500121 devm_gpiochip_add_data(&pdev->dev, mmc_gpio_chip, NULL);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100122
Rob Herring0ea355e2020-04-29 15:58:19 -0500123 return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
Pawel Moll974cc7b2014-04-23 10:49:31 +0100124 vexpress_sysreg_cells,
125 ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100126}
127
128static const struct of_device_id vexpress_sysreg_match[] = {
129 { .compatible = "arm,vexpress-sysreg", },
130 {},
131};
Rob Herring7b9d4282020-04-29 15:58:20 -0500132MODULE_DEVICE_TABLE(of, vexpress_sysreg_match);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100133
134static struct platform_driver vexpress_sysreg_driver = {
135 .driver = {
136 .name = "vexpress-sysreg",
137 .of_match_table = vexpress_sysreg_match,
138 },
139 .probe = vexpress_sysreg_probe,
140};
141
Rob Herring7b9d4282020-04-29 15:58:20 -0500142module_platform_driver(vexpress_sysreg_driver);
143MODULE_LICENSE("GPL v2");