ARM: tegra: fix compilation error due to mach/hardware.h removal
[linux-btrfs-devel.git] / arch / arm / mach-ux500 / devices-common.c
blob13a4ce046ae55926961a22c08ba4820df5a54299
1 /*
2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5 * License terms: GNU General Public License (GPL), version 2.
6 */
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>
16 #include <plat/gpio.h>
18 #include <mach/hardware.h>
20 #include "devices-common.h"
22 struct amba_device *
23 dbx500_add_amba_device(const char *name, resource_size_t base,
24 int irq, void *pdata, unsigned int periphid)
26 struct amba_device *dev;
27 int ret;
29 dev = kzalloc(sizeof *dev, GFP_KERNEL);
30 if (!dev)
31 return ERR_PTR(-ENOMEM);
33 dev->dev.init_name = name;
35 dev->res.start = base;
36 dev->res.end = base + SZ_4K - 1;
37 dev->res.flags = IORESOURCE_MEM;
39 dev->dma_mask = DMA_BIT_MASK(32);
40 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
42 dev->irq[0] = irq;
43 dev->irq[1] = NO_IRQ;
45 dev->periphid = periphid;
47 dev->dev.platform_data = pdata;
49 ret = amba_device_register(dev, &iomem_resource);
50 if (ret) {
51 kfree(dev);
52 return ERR_PTR(ret);
55 return dev;
58 static struct platform_device *
59 dbx500_add_platform_device(const char *name, int id, void *pdata,
60 struct resource *res, int resnum)
62 struct platform_device *dev;
63 int ret;
65 dev = platform_device_alloc(name, id);
66 if (!dev)
67 return ERR_PTR(-ENOMEM);
69 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
70 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
72 ret = platform_device_add_resources(dev, res, resnum);
73 if (ret)
74 goto out_free;
76 dev->dev.platform_data = pdata;
78 ret = platform_device_add(dev);
79 if (ret)
80 goto out_free;
82 return dev;
84 out_free:
85 platform_device_put(dev);
86 return ERR_PTR(ret);
89 struct platform_device *
90 dbx500_add_platform_device_4k1irq(const char *name, int id,
91 resource_size_t base,
92 int irq, void *pdata)
94 struct resource resources[] = {
95 [0] = {
96 .start = base,
97 .end = base + SZ_4K - 1,
98 .flags = IORESOURCE_MEM,
100 [1] = {
101 .start = irq,
102 .end = irq,
103 .flags = IORESOURCE_IRQ,
107 return dbx500_add_platform_device(name, id, pdata, resources,
108 ARRAY_SIZE(resources));
111 static struct platform_device *
112 dbx500_add_gpio(int id, resource_size_t addr, int irq,
113 struct nmk_gpio_platform_data *pdata)
115 struct resource resources[] = {
117 .start = addr,
118 .end = addr + 127,
119 .flags = IORESOURCE_MEM,
122 .start = irq,
123 .end = irq,
124 .flags = IORESOURCE_IRQ,
128 return platform_device_register_resndata(NULL, "gpio", id,
129 resources, ARRAY_SIZE(resources),
130 pdata, sizeof(*pdata));
133 void dbx500_add_gpios(resource_size_t *base, int num, int irq,
134 struct nmk_gpio_platform_data *pdata)
136 int first = 0;
137 int i;
139 for (i = 0; i < num; i++, first += 32, irq++) {
140 pdata->first_gpio = first;
141 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
142 pdata->num_gpio = 32;
144 dbx500_add_gpio(i, base[i], irq, pdata);