blob: e8c34fabc3c75cb68eb4485d943c17b60ff0b13a [file] [log] [blame]
Rabin Vincentfbf1ead2010-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 Vincentfbf1ead2010-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 King46d4bb92011-12-18 11:16:59 +000029 dev = amba_device_alloc(name, base, SZ_4K);
Rabin Vincentfbf1ead2010-09-29 19:46:32 +053030 if (!dev)
31 return ERR_PTR(-ENOMEM);
32
Rabin Vincentfbf1ead2010-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;
37 dev->irq[1] = NO_IRQ;
38
39 dev->periphid = periphid;
40
41 dev->dev.platform_data = pdata;
42
Russell King46d4bb92011-12-18 11:16:59 +000043 ret = amba_device_add(dev, &iomem_resource);
Rabin Vincentfbf1ead2010-09-29 19:46:32 +053044 if (ret) {
Russell King46d4bb92011-12-18 11:16:59 +000045 amba_device_put(dev);
Rabin Vincentfbf1ead2010-09-29 19:46:32 +053046 return ERR_PTR(ret);
47 }
48
49 return dev;
50}
51
52static struct platform_device *
53dbx500_add_platform_device(const char *name, int id, void *pdata,
54 struct resource *res, int resnum)
55{
56 struct platform_device *dev;
57 int ret;
58
59 dev = platform_device_alloc(name, id);
60 if (!dev)
61 return ERR_PTR(-ENOMEM);
62
63 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
64 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
65
66 ret = platform_device_add_resources(dev, res, resnum);
67 if (ret)
68 goto out_free;
69
70 dev->dev.platform_data = pdata;
71
72 ret = platform_device_add(dev);
73 if (ret)
74 goto out_free;
75
76 return dev;
77
78out_free:
79 platform_device_put(dev);
80 return ERR_PTR(ret);
81}
82
83struct platform_device *
84dbx500_add_platform_device_4k1irq(const char *name, int id,
85 resource_size_t base,
86 int irq, void *pdata)
87{
88 struct resource resources[] = {
89 [0] = {
90 .start = base,
91 .end = base + SZ_4K - 1,
92 .flags = IORESOURCE_MEM,
93 },
94 [1] = {
95 .start = irq,
96 .end = irq,
97 .flags = IORESOURCE_IRQ,
98 }
99 };
100
101 return dbx500_add_platform_device(name, id, pdata, resources,
102 ARRAY_SIZE(resources));
103}
Rabin Vincent01afdd12010-12-08 11:07:55 +0530104
105static struct platform_device *
106dbx500_add_gpio(int id, resource_size_t addr, int irq,
107 struct nmk_gpio_platform_data *pdata)
108{
109 struct resource resources[] = {
110 {
111 .start = addr,
112 .end = addr + 127,
113 .flags = IORESOURCE_MEM,
114 },
115 {
116 .start = irq,
117 .end = irq,
118 .flags = IORESOURCE_IRQ,
119 }
120 };
121
122 return platform_device_register_resndata(NULL, "gpio", id,
123 resources, ARRAY_SIZE(resources),
124 pdata, sizeof(*pdata));
125}
126
127void dbx500_add_gpios(resource_size_t *base, int num, int irq,
128 struct nmk_gpio_platform_data *pdata)
129{
130 int first = 0;
131 int i;
132
133 for (i = 0; i < num; i++, first += 32, irq++) {
134 pdata->first_gpio = first;
135 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
Rabin Vincente493e062010-03-18 12:35:22 +0530136 pdata->num_gpio = 32;
Rabin Vincent01afdd12010-12-08 11:07:55 +0530137
138 dbx500_add_gpio(i, base[i], irq, pdata);
139 }
140}