]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-ux500/devices-common.c
Merge branch 'next/fixes-non-critical' into next/drivers
[karo-tx-linux.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(const char *name, resource_size_t base,
24                        int irq, void *pdata, unsigned int periphid)
25 {
26         struct amba_device *dev;
27         int ret;
28
29         dev = amba_device_alloc(name, base, SZ_4K);
30         if (!dev)
31                 return ERR_PTR(-ENOMEM);
32
33         dev->dma_mask = DMA_BIT_MASK(32);
34         dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
35
36         dev->irq[0] = irq;
37
38         dev->periphid = periphid;
39
40         dev->dev.platform_data = pdata;
41
42         ret = amba_device_add(dev, &iomem_resource);
43         if (ret) {
44                 amba_device_put(dev);
45                 return ERR_PTR(ret);
46         }
47
48         return dev;
49 }
50
51 static struct platform_device *
52 dbx500_add_platform_device(const char *name, int id, void *pdata,
53                            struct resource *res, int resnum)
54 {
55         struct platform_device *dev;
56         int ret;
57
58         dev = platform_device_alloc(name, id);
59         if (!dev)
60                 return ERR_PTR(-ENOMEM);
61
62         dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
63         dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
64
65         ret = platform_device_add_resources(dev, res, resnum);
66         if (ret)
67                 goto out_free;
68
69         dev->dev.platform_data = pdata;
70
71         ret = platform_device_add(dev);
72         if (ret)
73                 goto out_free;
74
75         return dev;
76
77 out_free:
78         platform_device_put(dev);
79         return ERR_PTR(ret);
80 }
81
82 struct platform_device *
83 dbx500_add_platform_device_4k1irq(const char *name, int id,
84                                   resource_size_t base,
85                                   int irq, void *pdata)
86 {
87         struct resource resources[] = {
88                 [0] = {
89                         .start  = base,
90                         .end    = base + SZ_4K - 1,
91                         .flags  = IORESOURCE_MEM,
92                 },
93                 [1] = {
94                         .start  = irq,
95                         .end    = irq,
96                         .flags  = IORESOURCE_IRQ,
97                 }
98         };
99
100         return dbx500_add_platform_device(name, id, pdata, resources,
101                                           ARRAY_SIZE(resources));
102 }
103
104 static struct platform_device *
105 dbx500_add_gpio(int id, resource_size_t addr, int irq,
106                 struct nmk_gpio_platform_data *pdata)
107 {
108         struct resource resources[] = {
109                 {
110                         .start  = addr,
111                         .end    = addr + 127,
112                         .flags  = IORESOURCE_MEM,
113                 },
114                 {
115                         .start  = irq,
116                         .end    = irq,
117                         .flags  = IORESOURCE_IRQ,
118                 }
119         };
120
121         return platform_device_register_resndata(NULL, "gpio", id,
122                                 resources, ARRAY_SIZE(resources),
123                                 pdata, sizeof(*pdata));
124 }
125
126 void dbx500_add_gpios(resource_size_t *base, int num, int irq,
127                       struct nmk_gpio_platform_data *pdata)
128 {
129         int first = 0;
130         int i;
131
132         for (i = 0; i < num; i++, first += 32, irq++) {
133                 pdata->first_gpio = first;
134                 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
135                 pdata->num_gpio = 32;
136
137                 dbx500_add_gpio(i, base[i], irq, pdata);
138         }
139 }