Commit | Line | Data |
---|---|---|
88e0abcd PM |
1 | /* |
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. | |
5 | * | |
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. | |
10 | * | |
11 | * Copyright (C) 2012 ARM Limited | |
12 | */ | |
13 | ||
974cc7b9 | 14 | #include <linux/basic_mmio_gpio.h> |
88e0abcd | 15 | #include <linux/err.h> |
88e0abcd | 16 | #include <linux/io.h> |
974cc7b9 | 17 | #include <linux/mfd/core.h> |
88e0abcd | 18 | #include <linux/of_address.h> |
3b9334ac | 19 | #include <linux/of_platform.h> |
974cc7b9 | 20 | #include <linux/platform_data/syscon.h> |
88e0abcd | 21 | #include <linux/platform_device.h> |
88e0abcd PM |
22 | #include <linux/slab.h> |
23 | #include <linux/stat.h> | |
88e0abcd PM |
24 | #include <linux/vexpress.h> |
25 | ||
26 | #define SYS_ID 0x000 | |
27 | #define SYS_SW 0x004 | |
28 | #define SYS_LED 0x008 | |
29 | #define SYS_100HZ 0x024 | |
88e0abcd PM |
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 | |
35 | #define SYS_MCI 0x048 | |
36 | #define SYS_FLASH 0x04c | |
37 | #define SYS_CFGSW 0x058 | |
38 | #define SYS_24MHZ 0x05c | |
39 | #define SYS_MISC 0x060 | |
40 | #define SYS_DMA 0x064 | |
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 | |
46 | ||
47 | #define SYS_HBI_MASK 0xfff | |
88e0abcd PM |
48 | #define SYS_PROCIDx_HBI_SHIFT 0 |
49 | ||
88e0abcd PM |
50 | #define SYS_MISC_MASTERSITE (1 << 14) |
51 | ||
f0bd7ccc | 52 | void vexpress_flags_set(u32 data) |
974cc7b9 | 53 | { |
f0bd7ccc PM |
54 | static void __iomem *base; |
55 | ||
56 | if (!base) { | |
974cc7b9 PM |
57 | struct device_node *node = of_find_compatible_node(NULL, NULL, |
58 | "arm,vexpress-sysreg"); | |
88e0abcd | 59 | |
f0bd7ccc | 60 | base = of_iomap(node, 0); |
974cc7b9 PM |
61 | } |
62 | ||
f0bd7ccc PM |
63 | if (WARN_ON(!base)) |
64 | return; | |
88e0abcd | 65 | |
f0bd7ccc PM |
66 | writel(~0, base + SYS_FLAGSCLR); |
67 | writel(data, base + SYS_FLAGSSET); | |
88e0abcd PM |
68 | } |
69 | ||
974cc7b9 | 70 | /* The sysreg block is just a random collection of various functions... */ |
8ea402f5 | 71 | |
974cc7b9 PM |
72 | static struct syscon_platform_data vexpress_sysreg_sys_id_pdata = { |
73 | .label = "sys_id", | |
88e0abcd PM |
74 | }; |
75 | ||
974cc7b9 PM |
76 | static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = { |
77 | .label = "sys_led", | |
78 | .base = -1, | |
79 | .ngpio = 8, | |
88e0abcd PM |
80 | }; |
81 | ||
974cc7b9 PM |
82 | static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = { |
83 | .label = "sys_mci", | |
84 | .base = -1, | |
85 | .ngpio = 2, | |
8ea402f5 PM |
86 | }; |
87 | ||
974cc7b9 PM |
88 | static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = { |
89 | .label = "sys_flash", | |
90 | .base = -1, | |
91 | .ngpio = 1, | |
8ea402f5 PM |
92 | }; |
93 | ||
974cc7b9 PM |
94 | static struct syscon_platform_data vexpress_sysreg_sys_misc_pdata = { |
95 | .label = "sys_misc", | |
96 | }; | |
8ea402f5 | 97 | |
974cc7b9 PM |
98 | static struct syscon_platform_data vexpress_sysreg_sys_procid_pdata = { |
99 | .label = "sys_procid", | |
100 | }; | |
88e0abcd | 101 | |
974cc7b9 PM |
102 | static struct mfd_cell vexpress_sysreg_cells[] = { |
103 | { | |
104 | .name = "syscon", | |
105 | .num_resources = 1, | |
106 | .resources = (struct resource []) { | |
107 | DEFINE_RES_MEM(SYS_ID, 0x4), | |
108 | }, | |
109 | .platform_data = &vexpress_sysreg_sys_id_pdata, | |
110 | .pdata_size = sizeof(vexpress_sysreg_sys_id_pdata), | |
111 | }, { | |
112 | .name = "basic-mmio-gpio", | |
113 | .of_compatible = "arm,vexpress-sysreg,sys_led", | |
114 | .num_resources = 1, | |
115 | .resources = (struct resource []) { | |
116 | DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"), | |
117 | }, | |
118 | .platform_data = &vexpress_sysreg_sys_led_pdata, | |
119 | .pdata_size = sizeof(vexpress_sysreg_sys_led_pdata), | |
120 | }, { | |
121 | .name = "basic-mmio-gpio", | |
122 | .of_compatible = "arm,vexpress-sysreg,sys_mci", | |
123 | .num_resources = 1, | |
124 | .resources = (struct resource []) { | |
125 | DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"), | |
126 | }, | |
127 | .platform_data = &vexpress_sysreg_sys_mci_pdata, | |
128 | .pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata), | |
129 | }, { | |
130 | .name = "basic-mmio-gpio", | |
131 | .of_compatible = "arm,vexpress-sysreg,sys_flash", | |
132 | .num_resources = 1, | |
133 | .resources = (struct resource []) { | |
134 | DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"), | |
135 | }, | |
136 | .platform_data = &vexpress_sysreg_sys_flash_pdata, | |
137 | .pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata), | |
138 | }, { | |
139 | .name = "syscon", | |
140 | .num_resources = 1, | |
141 | .resources = (struct resource []) { | |
142 | DEFINE_RES_MEM(SYS_MISC, 0x4), | |
143 | }, | |
144 | .platform_data = &vexpress_sysreg_sys_misc_pdata, | |
145 | .pdata_size = sizeof(vexpress_sysreg_sys_misc_pdata), | |
146 | }, { | |
147 | .name = "syscon", | |
148 | .num_resources = 1, | |
149 | .resources = (struct resource []) { | |
150 | DEFINE_RES_MEM(SYS_PROCID0, 0x8), | |
151 | }, | |
152 | .platform_data = &vexpress_sysreg_sys_procid_pdata, | |
153 | .pdata_size = sizeof(vexpress_sysreg_sys_procid_pdata), | |
154 | }, { | |
155 | .name = "vexpress-syscfg", | |
156 | .num_resources = 1, | |
157 | .resources = (struct resource []) { | |
158 | DEFINE_RES_MEM(SYS_CFGDATA, 0xc), | |
159 | }, | |
160 | } | |
161 | }; | |
88e0abcd | 162 | |
612b95cd | 163 | static int vexpress_sysreg_probe(struct platform_device *pdev) |
88e0abcd | 164 | { |
974cc7b9 PM |
165 | struct resource *mem; |
166 | void __iomem *base; | |
167 | struct bgpio_chip *mmc_gpio_chip; | |
f0bd7ccc | 168 | int master; |
6b2c31c7 | 169 | u32 dt_hbi; |
88e0abcd | 170 | |
974cc7b9 PM |
171 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
172 | if (!mem) | |
173 | return -EINVAL; | |
88e0abcd | 174 | |
974cc7b9 PM |
175 | base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
176 | if (!base) | |
177 | return -ENOMEM; | |
88e0abcd | 178 | |
f0bd7ccc PM |
179 | master = readl(base + SYS_MISC) & SYS_MISC_MASTERSITE ? |
180 | VEXPRESS_SITE_DB2 : VEXPRESS_SITE_DB1; | |
181 | vexpress_config_set_master(master); | |
88e0abcd | 182 | |
6b2c31c7 | 183 | /* Confirm board type against DT property, if available */ |
5063e25a | 184 | if (of_property_read_u32(of_root, "arm,hbi", &dt_hbi) == 0) { |
f0bd7ccc PM |
185 | u32 id = readl(base + (master == VEXPRESS_SITE_DB1 ? |
186 | SYS_PROCID0 : SYS_PROCID1)); | |
6b2c31c7 PM |
187 | u32 hbi = (id >> SYS_PROCIDx_HBI_SHIFT) & SYS_HBI_MASK; |
188 | ||
189 | if (WARN_ON(dt_hbi != hbi)) | |
190 | dev_warn(&pdev->dev, "DT HBI (%x) is not matching hardware (%x)!\n", | |
191 | dt_hbi, hbi); | |
192 | } | |
193 | ||
974cc7b9 PM |
194 | /* |
195 | * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with | |
196 | * older trees using sysreg node for MMC control lines. | |
197 | */ | |
198 | mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip), | |
199 | GFP_KERNEL); | |
200 | if (!mmc_gpio_chip) | |
201 | return -ENOMEM; | |
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); | |
206 | ||
207 | return mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, | |
208 | vexpress_sysreg_cells, | |
209 | ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL); | |
88e0abcd PM |
210 | } |
211 | ||
212 | static const struct of_device_id vexpress_sysreg_match[] = { | |
213 | { .compatible = "arm,vexpress-sysreg", }, | |
214 | {}, | |
215 | }; | |
216 | ||
217 | static struct platform_driver vexpress_sysreg_driver = { | |
218 | .driver = { | |
219 | .name = "vexpress-sysreg", | |
220 | .of_match_table = vexpress_sysreg_match, | |
221 | }, | |
222 | .probe = vexpress_sysreg_probe, | |
223 | }; | |
224 | ||
225 | static int __init vexpress_sysreg_init(void) | |
226 | { | |
3b9334ac PM |
227 | struct device_node *node; |
228 | ||
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); | |
232 | ||
88e0abcd PM |
233 | return platform_driver_register(&vexpress_sysreg_driver); |
234 | } | |
235 | core_initcall(vexpress_sysreg_init); |