ARM: ux500: Provide local timer support for Device Tree
[linux-flexiantxendom0-3.2.10.git] / arch / arm / mach-ux500 / devices-common.c
1 /*
2  * Copyright (C) ST-Ericsson SA 2010
3  *
4  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5  * License terms: GNU General Public License (GPL), version 2.
6  */
7
8 #include <linux/kernel.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/err.h>
11 #include <linux/irq.h>
12 #include <linux/slab.h>
13 #include <linux/platform_device.h>
14 #include <linux/amba/bus.h>
15
16 #include <plat/gpio-nomadik.h>
17
18 #include <mach/hardware.h>
19
20 #include "devices-common.h"
21
22 struct amba_device *
23 dbx500_add_amba_device(struct device *parent, const char *name,
24                        resource_size_t base, int irq, void *pdata,
25                        unsigned int periphid)
26 {
27         struct amba_device *dev;
28         int ret;
29
30         dev = kzalloc(sizeof *dev, GFP_KERNEL);
31         if (!dev)
32                 return ERR_PTR(-ENOMEM);
33
34         dev->dev.init_name = name;
35
36         dev->res.start = base;
37         dev->res.end = base + SZ_4K - 1;
38         dev->res.flags = IORESOURCE_MEM;
39
40         dev->dma_mask = DMA_BIT_MASK(32);
41         dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
42
43         dev->irq[0] = irq;
44         dev->irq[1] = NO_IRQ;
45
46         dev->periphid = periphid;
47
48         dev->dev.platform_data = pdata;
49
50         dev->dev.parent = parent;
51
52         ret = amba_device_register(dev, &iomem_resource);
53         if (ret) {
54                 kfree(dev);
55                 return ERR_PTR(ret);
56         }
57
58         return dev;
59 }
60
61 static struct platform_device *
62 dbx500_add_gpio(struct device *parent, int id, resource_size_t addr, int irq,
63                 struct nmk_gpio_platform_data *pdata)
64 {
65         struct resource resources[] = {
66                 {
67                         .start  = addr,
68                         .end    = addr + 127,
69                         .flags  = IORESOURCE_MEM,
70                 },
71                 {
72                         .start  = irq,
73                         .end    = irq,
74                         .flags  = IORESOURCE_IRQ,
75                 }
76         };
77
78         return platform_device_register_resndata(
79                 parent,
80                 "gpio",
81                 id,
82                 resources,
83                 ARRAY_SIZE(resources),
84                 pdata,
85                 sizeof(*pdata));
86 }
87
88 void dbx500_add_gpios(struct device *parent, resource_size_t *base, int num,
89                       int irq, struct nmk_gpio_platform_data *pdata)
90 {
91         int first = 0;
92         int i;
93
94         for (i = 0; i < num; i++, first += 32, irq++) {
95                 pdata->first_gpio = first;
96                 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
97                 pdata->num_gpio = 32;
98
99                 dbx500_add_gpio(parent, i, base[i], irq, pdata);
100         }
101 }