blob: b4138a7168db7fac5f72eb57bd1e74ef791bb6d1 [file] [log] [blame]
Pawel Moll88e0abc2012-09-18 12:24:57 +01001/*
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
14#include <linux/err.h>
15#include <linux/gpio.h>
16#include <linux/io.h>
17#include <linux/leds.h>
18#include <linux/of_address.h>
Pawel Moll3b9334a2014-04-30 16:46:29 +010019#include <linux/of_platform.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +010020#include <linux/platform_device.h>
21#include <linux/regulator/driver.h>
Pawel Moll3b9334a2014-04-30 16:46:29 +010022#include <linux/sched.h>
Pawel Moll88e0abc2012-09-18 12:24:57 +010023#include <linux/slab.h>
24#include <linux/stat.h>
25#include <linux/timer.h>
26#include <linux/vexpress.h>
27
28#define SYS_ID 0x000
29#define SYS_SW 0x004
30#define SYS_LED 0x008
31#define SYS_100HZ 0x024
32#define SYS_FLAGS 0x030
33#define SYS_FLAGSSET 0x030
34#define SYS_FLAGSCLR 0x034
35#define SYS_NVFLAGS 0x038
36#define SYS_NVFLAGSSET 0x038
37#define SYS_NVFLAGSCLR 0x03c
38#define SYS_MCI 0x048
39#define SYS_FLASH 0x04c
40#define SYS_CFGSW 0x058
41#define SYS_24MHZ 0x05c
42#define SYS_MISC 0x060
43#define SYS_DMA 0x064
44#define SYS_PROCID0 0x084
45#define SYS_PROCID1 0x088
46#define SYS_CFGDATA 0x0a0
47#define SYS_CFGCTRL 0x0a4
48#define SYS_CFGSTAT 0x0a8
49
50#define SYS_HBI_MASK 0xfff
51#define SYS_ID_HBI_SHIFT 16
52#define SYS_PROCIDx_HBI_SHIFT 0
53
Pawel Moll8ea402f2013-01-30 10:33:16 +000054#define SYS_LED_LED(n) (1 << (n))
55
Pawel Moll88e0abc2012-09-18 12:24:57 +010056#define SYS_MCI_CARDIN (1 << 0)
57#define SYS_MCI_WPROT (1 << 1)
58
59#define SYS_FLASH_WPn (1 << 0)
60
61#define SYS_MISC_MASTERSITE (1 << 14)
62
63#define SYS_CFGCTRL_START (1 << 31)
64#define SYS_CFGCTRL_WRITE (1 << 30)
65#define SYS_CFGCTRL_DCC(n) (((n) & 0xf) << 26)
66#define SYS_CFGCTRL_FUNC(n) (((n) & 0x3f) << 20)
67#define SYS_CFGCTRL_SITE(n) (((n) & 0x3) << 16)
68#define SYS_CFGCTRL_POSITION(n) (((n) & 0xf) << 12)
69#define SYS_CFGCTRL_DEVICE(n) (((n) & 0xfff) << 0)
70
71#define SYS_CFGSTAT_ERR (1 << 1)
72#define SYS_CFGSTAT_COMPLETE (1 << 0)
73
74
75static void __iomem *vexpress_sysreg_base;
76static struct device *vexpress_sysreg_dev;
Pawel Moll3b9334a2014-04-30 16:46:29 +010077static LIST_HEAD(vexpress_sysreg_config_funcs);
78static struct device *vexpress_sysreg_config_bridge;
Pawel Moll88e0abc2012-09-18 12:24:57 +010079
80
Pawel Moll3b9334a2014-04-30 16:46:29 +010081static int vexpress_sysreg_get_master(void)
82{
83 if (readl(vexpress_sysreg_base + SYS_MISC) & SYS_MISC_MASTERSITE)
84 return VEXPRESS_SITE_DB2;
85
86 return VEXPRESS_SITE_DB1;
87}
88
Pawel Moll88e0abc2012-09-18 12:24:57 +010089void vexpress_flags_set(u32 data)
90{
91 writel(~0, vexpress_sysreg_base + SYS_FLAGSCLR);
92 writel(data, vexpress_sysreg_base + SYS_FLAGSSET);
93}
94
95u32 vexpress_get_procid(int site)
96{
97 if (site == VEXPRESS_SITE_MASTER)
Pawel Moll3b9334a2014-04-30 16:46:29 +010098 site = vexpress_sysreg_get_master();
Pawel Moll88e0abc2012-09-18 12:24:57 +010099
100 return readl(vexpress_sysreg_base + (site == VEXPRESS_SITE_DB1 ?
101 SYS_PROCID0 : SYS_PROCID1));
102}
103
104u32 vexpress_get_hbi(int site)
105{
106 u32 id;
107
108 switch (site) {
109 case VEXPRESS_SITE_MB:
110 id = readl(vexpress_sysreg_base + SYS_ID);
111 return (id >> SYS_ID_HBI_SHIFT) & SYS_HBI_MASK;
112 case VEXPRESS_SITE_MASTER:
113 case VEXPRESS_SITE_DB1:
114 case VEXPRESS_SITE_DB2:
115 id = vexpress_get_procid(site);
116 return (id >> SYS_PROCIDx_HBI_SHIFT) & SYS_HBI_MASK;
117 }
118
119 return ~0;
120}
121
122void __iomem *vexpress_get_24mhz_clock_base(void)
123{
124 return vexpress_sysreg_base + SYS_24MHZ;
125}
126
127
Pawel Moll88e0abc2012-09-18 12:24:57 +0100128struct vexpress_sysreg_config_func {
Pawel Moll3b9334a2014-04-30 16:46:29 +0100129 struct list_head list;
130 struct regmap *regmap;
131 int num_templates;
132 u32 template[0]; /* Keep this last */
Pawel Moll88e0abc2012-09-18 12:24:57 +0100133};
134
Pawel Moll3b9334a2014-04-30 16:46:29 +0100135static int vexpress_sysreg_config_exec(struct vexpress_sysreg_config_func *func,
136 int index, bool write, u32 *data)
Pawel Moll88e0abc2012-09-18 12:24:57 +0100137{
Pawel Moll3b9334a2014-04-30 16:46:29 +0100138 u32 command, status;
139 int tries;
140 long timeout;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100141
142 if (WARN_ON(!vexpress_sysreg_base))
143 return -ENOENT;
144
Pawel Moll3b9334a2014-04-30 16:46:29 +0100145 if (WARN_ON(index > func->num_templates))
146 return -EINVAL;
147
Pawel Moll88e0abc2012-09-18 12:24:57 +0100148 command = readl(vexpress_sysreg_base + SYS_CFGCTRL);
149 if (WARN_ON(command & SYS_CFGCTRL_START))
150 return -EBUSY;
151
Pawel Moll3b9334a2014-04-30 16:46:29 +0100152 command = func->template[index];
153 command |= SYS_CFGCTRL_START;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100154 command |= write ? SYS_CFGCTRL_WRITE : 0;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100155
156 /* Use a canary for reads */
157 if (!write)
158 *data = 0xdeadbeef;
159
160 dev_dbg(vexpress_sysreg_dev, "command %x, data %x\n",
161 command, *data);
162 writel(*data, vexpress_sysreg_base + SYS_CFGDATA);
163 writel(0, vexpress_sysreg_base + SYS_CFGSTAT);
164 writel(command, vexpress_sysreg_base + SYS_CFGCTRL);
165 mb();
166
Pawel Moll3b9334a2014-04-30 16:46:29 +0100167 /* The operation can take ages... Go to sleep, 100us initially */
168 tries = 100;
169 timeout = 100;
170 do {
171 set_current_state(TASK_INTERRUPTIBLE);
172 schedule_timeout(usecs_to_jiffies(timeout));
173 if (signal_pending(current))
174 return -EINTR;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100175
Pawel Moll3b9334a2014-04-30 16:46:29 +0100176 status = readl(vexpress_sysreg_base + SYS_CFGSTAT);
177 if (status & SYS_CFGSTAT_ERR)
178 return -EFAULT;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100179
Pawel Moll3b9334a2014-04-30 16:46:29 +0100180 if (timeout > 20)
181 timeout -= 20;
182 } while (--tries && !(status & SYS_CFGSTAT_COMPLETE));
183 if (WARN_ON_ONCE(!tries))
184 return -ETIMEDOUT;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100185
Pawel Moll3b9334a2014-04-30 16:46:29 +0100186 if (!write) {
187 *data = readl(vexpress_sysreg_base + SYS_CFGDATA);
188 dev_dbg(vexpress_sysreg_dev, "func %p, read data %x\n",
189 func, *data);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100190 }
191
Pawel Moll3b9334a2014-04-30 16:46:29 +0100192 return 0;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100193}
194
Pawel Moll3b9334a2014-04-30 16:46:29 +0100195static int vexpress_sysreg_config_read(void *context, unsigned int index,
196 unsigned int *val)
197{
198 struct vexpress_sysreg_config_func *func = context;
199
200 return vexpress_sysreg_config_exec(func, index, false, val);
201}
202
203static int vexpress_sysreg_config_write(void *context, unsigned int index,
204 unsigned int val)
205{
206 struct vexpress_sysreg_config_func *func = context;
207
208 return vexpress_sysreg_config_exec(func, index, true, &val);
209}
210
211struct regmap_config vexpress_sysreg_regmap_config = {
212 .lock = vexpress_config_lock,
213 .unlock = vexpress_config_unlock,
214 .reg_bits = 32,
215 .val_bits = 32,
216 .reg_read = vexpress_sysreg_config_read,
217 .reg_write = vexpress_sysreg_config_write,
218 .reg_format_endian = REGMAP_ENDIAN_LITTLE,
219 .val_format_endian = REGMAP_ENDIAN_LITTLE,
Pawel Moll88e0abc2012-09-18 12:24:57 +0100220};
221
Pawel Moll3b9334a2014-04-30 16:46:29 +0100222static struct regmap *vexpress_sysreg_config_regmap_init(struct device *dev,
223 void *context)
Pawel Moll88e0abc2012-09-18 12:24:57 +0100224{
Pawel Moll3b9334a2014-04-30 16:46:29 +0100225 struct platform_device *pdev = to_platform_device(dev);
226 struct vexpress_sysreg_config_func *func;
227 struct property *prop;
228 const __be32 *val = NULL;
229 __be32 energy_quirk[4];
230 int num;
231 u32 site, position, dcc;
232 int err;
233 int i;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100234
Pawel Moll3b9334a2014-04-30 16:46:29 +0100235 if (dev->of_node) {
236 err = vexpress_config_get_topo(dev->of_node, &site, &position,
237 &dcc);
238 if (err)
239 return ERR_PTR(err);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100240
Pawel Moll3b9334a2014-04-30 16:46:29 +0100241 prop = of_find_property(dev->of_node,
242 "arm,vexpress-sysreg,func", NULL);
243 if (!prop)
244 return ERR_PTR(-EINVAL);
245
246 num = prop->length / sizeof(u32) / 2;
247 val = prop->value;
248 } else {
249 if (pdev->num_resources != 1 ||
250 pdev->resource[0].flags != IORESOURCE_BUS)
251 return ERR_PTR(-EFAULT);
252
253 site = pdev->resource[0].start;
254 if (site == VEXPRESS_SITE_MASTER)
255 site = vexpress_sysreg_get_master();
256 position = 0;
257 dcc = 0;
258 num = 1;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100259 }
260
Pawel Moll3b9334a2014-04-30 16:46:29 +0100261 /*
262 * "arm,vexpress-energy" function used to be described
263 * by its first device only, now it requires both
264 */
265 if (num == 1 && of_device_is_compatible(dev->of_node,
266 "arm,vexpress-energy")) {
267 num = 2;
268 energy_quirk[0] = *val;
269 energy_quirk[2] = *val++;
270 energy_quirk[1] = *val;
271 energy_quirk[3] = cpu_to_be32(be32_to_cpup(val) + 1);
272 val = energy_quirk;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100273 }
274
Pawel Moll3b9334a2014-04-30 16:46:29 +0100275 func = kzalloc(sizeof(*func) + sizeof(*func->template) * num,
276 GFP_KERNEL);
277 if (!func)
278 return NULL;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100279
Pawel Moll3b9334a2014-04-30 16:46:29 +0100280 func->num_templates = num;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100281
Pawel Moll3b9334a2014-04-30 16:46:29 +0100282 for (i = 0; i < num; i++) {
283 u32 function, device;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100284
Pawel Moll3b9334a2014-04-30 16:46:29 +0100285 if (dev->of_node) {
286 function = be32_to_cpup(val++);
287 device = be32_to_cpup(val++);
288 } else {
289 function = pdev->resource[0].end;
290 device = pdev->id;
291 }
292
293 dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n",
294 func, site, position, dcc,
295 function, device);
296
297 func->template[i] = SYS_CFGCTRL_DCC(dcc);
298 func->template[i] |= SYS_CFGCTRL_SITE(site);
299 func->template[i] |= SYS_CFGCTRL_POSITION(position);
300 func->template[i] |= SYS_CFGCTRL_FUNC(function);
301 func->template[i] |= SYS_CFGCTRL_DEVICE(device);
302 }
303
304 vexpress_sysreg_regmap_config.max_register = num - 1;
305
306 func->regmap = regmap_init(dev, NULL, func,
307 &vexpress_sysreg_regmap_config);
308
309 if (IS_ERR(func->regmap))
310 kfree(func);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100311 else
Pawel Moll3b9334a2014-04-30 16:46:29 +0100312 list_add(&func->list, &vexpress_sysreg_config_funcs);
Pawel Moll88e0abc2012-09-18 12:24:57 +0100313
Pawel Moll3b9334a2014-04-30 16:46:29 +0100314 return func->regmap;
Pawel Moll88e0abc2012-09-18 12:24:57 +0100315}
316
Pawel Moll3b9334a2014-04-30 16:46:29 +0100317static void vexpress_sysreg_config_regmap_exit(struct regmap *regmap,
318 void *context)
319{
320 struct vexpress_sysreg_config_func *func, *tmp;
321
322 regmap_exit(regmap);
323
324 list_for_each_entry_safe(func, tmp, &vexpress_sysreg_config_funcs,
325 list) {
326 if (func->regmap == regmap) {
327 list_del(&vexpress_sysreg_config_funcs);
328 kfree(func);
329 break;
330 }
331 }
332}
333
334static struct vexpress_config_bridge_ops vexpress_sysreg_config_bridge_ops = {
335 .regmap_init = vexpress_sysreg_config_regmap_init,
336 .regmap_exit = vexpress_sysreg_config_regmap_exit,
337};
338
339int vexpress_sysreg_config_device_register(struct platform_device *pdev)
340{
341 pdev->dev.parent = vexpress_sysreg_config_bridge;
342
343 return platform_device_register(pdev);
344}
345
346
Pawel Moll52666292012-11-27 16:48:50 +0000347void __init vexpress_sysreg_early_init(void __iomem *base)
348{
349 vexpress_sysreg_base = base;
Pawel Moll3b9334a2014-04-30 16:46:29 +0100350 vexpress_config_set_master(vexpress_sysreg_get_master());
Pawel Moll52666292012-11-27 16:48:50 +0000351}
352
Pawel Moll88e0abc2012-09-18 12:24:57 +0100353void __init vexpress_sysreg_of_early_init(void)
354{
Catalin Marinasdcd560c2013-02-04 18:08:02 +0000355 struct device_node *node;
Pawel Moll52666292012-11-27 16:48:50 +0000356
Catalin Marinasdcd560c2013-02-04 18:08:02 +0000357 if (vexpress_sysreg_base)
358 return;
359
360 node = of_find_compatible_node(NULL, NULL, "arm,vexpress-sysreg");
Pawel Moll3b9334a2014-04-30 16:46:29 +0100361 if (WARN_ON(!node))
362 return;
363
364 vexpress_sysreg_base = of_iomap(node, 0);
365 if (WARN_ON(!vexpress_sysreg_base))
366 return;
367
368 vexpress_config_set_master(vexpress_sysreg_get_master());
Pawel Moll88e0abc2012-09-18 12:24:57 +0100369}
370
371
Pawel Moll8eb12b92013-06-11 11:56:02 +0100372#ifdef CONFIG_GPIOLIB
373
Pawel Moll8ea402f2013-01-30 10:33:16 +0000374#define VEXPRESS_SYSREG_GPIO(_name, _reg, _value) \
375 [VEXPRESS_GPIO_##_name] = { \
376 .reg = _reg, \
377 .value = _reg##_##_value, \
378 }
379
Pawel Moll88e0abc2012-09-18 12:24:57 +0100380static struct vexpress_sysreg_gpio {
381 unsigned long reg;
382 u32 value;
383} vexpress_sysreg_gpios[] = {
Pawel Moll8ea402f2013-01-30 10:33:16 +0000384 VEXPRESS_SYSREG_GPIO(MMC_CARDIN, SYS_MCI, CARDIN),
385 VEXPRESS_SYSREG_GPIO(MMC_WPROT, SYS_MCI, WPROT),
386 VEXPRESS_SYSREG_GPIO(FLASH_WPn, SYS_FLASH, WPn),
387 VEXPRESS_SYSREG_GPIO(LED0, SYS_LED, LED(0)),
388 VEXPRESS_SYSREG_GPIO(LED1, SYS_LED, LED(1)),
389 VEXPRESS_SYSREG_GPIO(LED2, SYS_LED, LED(2)),
390 VEXPRESS_SYSREG_GPIO(LED3, SYS_LED, LED(3)),
391 VEXPRESS_SYSREG_GPIO(LED4, SYS_LED, LED(4)),
392 VEXPRESS_SYSREG_GPIO(LED5, SYS_LED, LED(5)),
393 VEXPRESS_SYSREG_GPIO(LED6, SYS_LED, LED(6)),
394 VEXPRESS_SYSREG_GPIO(LED7, SYS_LED, LED(7)),
Pawel Moll88e0abc2012-09-18 12:24:57 +0100395};
396
397static int vexpress_sysreg_gpio_direction_input(struct gpio_chip *chip,
398 unsigned offset)
399{
400 return 0;
401}
402
Pawel Moll88e0abc2012-09-18 12:24:57 +0100403static int vexpress_sysreg_gpio_get(struct gpio_chip *chip,
404 unsigned offset)
405{
406 struct vexpress_sysreg_gpio *gpio = &vexpress_sysreg_gpios[offset];
407 u32 reg_value = readl(vexpress_sysreg_base + gpio->reg);
408
409 return !!(reg_value & gpio->value);
410}
411
412static void vexpress_sysreg_gpio_set(struct gpio_chip *chip,
413 unsigned offset, int value)
414{
415 struct vexpress_sysreg_gpio *gpio = &vexpress_sysreg_gpios[offset];
416 u32 reg_value = readl(vexpress_sysreg_base + gpio->reg);
417
418 if (value)
419 reg_value |= gpio->value;
420 else
421 reg_value &= ~gpio->value;
422
423 writel(reg_value, vexpress_sysreg_base + gpio->reg);
424}
425
Pawel Moll8ea402f2013-01-30 10:33:16 +0000426static int vexpress_sysreg_gpio_direction_output(struct gpio_chip *chip,
427 unsigned offset, int value)
428{
429 vexpress_sysreg_gpio_set(chip, offset, value);
430
431 return 0;
432}
433
Pawel Moll88e0abc2012-09-18 12:24:57 +0100434static struct gpio_chip vexpress_sysreg_gpio_chip = {
435 .label = "vexpress-sysreg",
436 .direction_input = vexpress_sysreg_gpio_direction_input,
437 .direction_output = vexpress_sysreg_gpio_direction_output,
438 .get = vexpress_sysreg_gpio_get,
439 .set = vexpress_sysreg_gpio_set,
440 .ngpio = ARRAY_SIZE(vexpress_sysreg_gpios),
441 .base = 0,
442};
443
444
Pawel Moll8ea402f2013-01-30 10:33:16 +0000445#define VEXPRESS_SYSREG_GREEN_LED(_name, _default_trigger, _gpio) \
446 { \
447 .name = "v2m:green:"_name, \
448 .default_trigger = _default_trigger, \
449 .gpio = VEXPRESS_GPIO_##_gpio, \
450 }
451
452struct gpio_led vexpress_sysreg_leds[] = {
453 VEXPRESS_SYSREG_GREEN_LED("user1", "heartbeat", LED0),
454 VEXPRESS_SYSREG_GREEN_LED("user2", "mmc0", LED1),
455 VEXPRESS_SYSREG_GREEN_LED("user3", "cpu0", LED2),
456 VEXPRESS_SYSREG_GREEN_LED("user4", "cpu1", LED3),
457 VEXPRESS_SYSREG_GREEN_LED("user5", "cpu2", LED4),
458 VEXPRESS_SYSREG_GREEN_LED("user6", "cpu3", LED5),
459 VEXPRESS_SYSREG_GREEN_LED("user7", "cpu4", LED6),
460 VEXPRESS_SYSREG_GREEN_LED("user8", "cpu5", LED7),
461};
462
463struct gpio_led_platform_data vexpress_sysreg_leds_pdata = {
464 .num_leds = ARRAY_SIZE(vexpress_sysreg_leds),
465 .leds = vexpress_sysreg_leds,
466};
467
Pawel Moll8eb12b92013-06-11 11:56:02 +0100468#endif
469
Pawel Moll8ea402f2013-01-30 10:33:16 +0000470
Pawel Moll88e0abc2012-09-18 12:24:57 +0100471static ssize_t vexpress_sysreg_sys_id_show(struct device *dev,
472 struct device_attribute *attr, char *buf)
473{
474 return sprintf(buf, "0x%08x\n", readl(vexpress_sysreg_base + SYS_ID));
475}
476
477DEVICE_ATTR(sys_id, S_IRUGO, vexpress_sysreg_sys_id_show, NULL);
478
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800479static int vexpress_sysreg_probe(struct platform_device *pdev)
Pawel Moll88e0abc2012-09-18 12:24:57 +0100480{
481 int err;
482 struct resource *res = platform_get_resource(pdev,
483 IORESOURCE_MEM, 0);
484
485 if (!devm_request_mem_region(&pdev->dev, res->start,
486 resource_size(res), pdev->name)) {
487 dev_err(&pdev->dev, "Failed to request memory region!\n");
488 return -EBUSY;
489 }
490
Pawel Moll3b9334a2014-04-30 16:46:29 +0100491 if (!vexpress_sysreg_base)
Pawel Moll88e0abc2012-09-18 12:24:57 +0100492 vexpress_sysreg_base = devm_ioremap(&pdev->dev, res->start,
493 resource_size(res));
494
495 if (!vexpress_sysreg_base) {
496 dev_err(&pdev->dev, "Failed to obtain base address!\n");
497 return -EFAULT;
498 }
499
Pawel Moll3b9334a2014-04-30 16:46:29 +0100500 vexpress_config_set_master(vexpress_sysreg_get_master());
Pawel Moll8eb12b92013-06-11 11:56:02 +0100501 vexpress_sysreg_dev = &pdev->dev;
502
503#ifdef CONFIG_GPIOLIB
Pawel Moll88e0abc2012-09-18 12:24:57 +0100504 vexpress_sysreg_gpio_chip.dev = &pdev->dev;
505 err = gpiochip_add(&vexpress_sysreg_gpio_chip);
506 if (err) {
Pawel Moll88e0abc2012-09-18 12:24:57 +0100507 dev_err(&pdev->dev, "Failed to register GPIO chip! (%d)\n",
508 err);
509 return err;
510 }
511
Pawel Moll8ea402f2013-01-30 10:33:16 +0000512 platform_device_register_data(vexpress_sysreg_dev, "leds-gpio",
513 PLATFORM_DEVID_AUTO, &vexpress_sysreg_leds_pdata,
514 sizeof(vexpress_sysreg_leds_pdata));
Pawel Moll8eb12b92013-06-11 11:56:02 +0100515#endif
Pawel Moll8ea402f2013-01-30 10:33:16 +0000516
Pawel Moll3b9334a2014-04-30 16:46:29 +0100517 vexpress_sysreg_config_bridge = vexpress_config_bridge_register(
518 &pdev->dev, &vexpress_sysreg_config_bridge_ops, NULL);
519 WARN_ON(!vexpress_sysreg_config_bridge);
520
Pawel Moll88e0abc2012-09-18 12:24:57 +0100521 device_create_file(vexpress_sysreg_dev, &dev_attr_sys_id);
522
523 return 0;
524}
525
526static const struct of_device_id vexpress_sysreg_match[] = {
527 { .compatible = "arm,vexpress-sysreg", },
528 {},
529};
530
531static struct platform_driver vexpress_sysreg_driver = {
532 .driver = {
533 .name = "vexpress-sysreg",
534 .of_match_table = vexpress_sysreg_match,
535 },
536 .probe = vexpress_sysreg_probe,
537};
538
539static int __init vexpress_sysreg_init(void)
540{
Pawel Moll3b9334a2014-04-30 16:46:29 +0100541 struct device_node *node;
542
543 /* Need the sysreg early, before any other device... */
544 for_each_matching_node(node, vexpress_sysreg_match)
545 of_platform_device_create(node, NULL, NULL);
546
Pawel Moll88e0abc2012-09-18 12:24:57 +0100547 return platform_driver_register(&vexpress_sysreg_driver);
548}
549core_initcall(vexpress_sysreg_init);