blob: 898a64517b09ecc1386bd1e2e23d938cc4b6e72c [file] [log] [blame]
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +05301/*
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
Linus Walleij0f332862011-08-22 08:33:30 +010016#include <plat/gpio-nomadik.h>
Rabin Vincent01afdd12010-12-08 11:07:55 +053017
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053018#include <mach/hardware.h>
19
20#include "devices-common.h"
21
22struct amba_device *
23dbx500_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
Russell King46d4bb9b52011-12-18 11:16:59 +000029 dev = amba_device_alloc(name, base, SZ_4K);
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053030 if (!dev)
31 return ERR_PTR(-ENOMEM);
32
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053033 dev->dma_mask = DMA_BIT_MASK(32);
34 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
35
36 dev->irq[0] = irq;
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053037
38 dev->periphid = periphid;
39
40 dev->dev.platform_data = pdata;
41
Russell King46d4bb9b52011-12-18 11:16:59 +000042 ret = amba_device_add(dev, &iomem_resource);
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053043 if (ret) {
Russell King46d4bb9b52011-12-18 11:16:59 +000044 amba_device_put(dev);
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053045 return ERR_PTR(ret);
46 }
47
48 return dev;
49}
50
51static struct platform_device *
52dbx500_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
77out_free:
78 platform_device_put(dev);
79 return ERR_PTR(ret);
80}
81
82struct platform_device *
83dbx500_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}
Rabin Vincent01afdd12010-12-08 11:07:55 +0530103
104static struct platform_device *
105dbx500_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
126void 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);
Rabin Vincente493e062010-03-18 12:35:22 +0530135 pdata->num_gpio = 32;
Rabin Vincent01afdd12010-12-08 11:07:55 +0530136
137 dbx500_add_gpio(i, base[i], irq, pdata);
138 }
139}