blob: 96be2482ea453a65a35d6736d55082b5013b4741 [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 *
Lee Jones18403422012-02-06 11:22:21 -080023dbx500_add_amba_device(struct device *parent, const char *name,
24 resource_size_t base, int irq, void *pdata,
25 unsigned int periphid)
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053026{
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 ret = amba_device_register(dev, &iomem_resource);
51 if (ret) {
52 kfree(dev);
53 return ERR_PTR(ret);
54 }
55
56 return dev;
57}
58
59static struct platform_device *
60dbx500_add_platform_device(const char *name, int id, void *pdata,
61 struct resource *res, int resnum)
62{
63 struct platform_device *dev;
64 int ret;
65
66 dev = platform_device_alloc(name, id);
67 if (!dev)
68 return ERR_PTR(-ENOMEM);
69
70 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
71 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
72
73 ret = platform_device_add_resources(dev, res, resnum);
74 if (ret)
75 goto out_free;
76
77 dev->dev.platform_data = pdata;
78
79 ret = platform_device_add(dev);
80 if (ret)
81 goto out_free;
82
83 return dev;
84
85out_free:
86 platform_device_put(dev);
87 return ERR_PTR(ret);
88}
89
90struct platform_device *
91dbx500_add_platform_device_4k1irq(const char *name, int id,
92 resource_size_t base,
93 int irq, void *pdata)
94{
95 struct resource resources[] = {
96 [0] = {
97 .start = base,
98 .end = base + SZ_4K - 1,
99 .flags = IORESOURCE_MEM,
100 },
101 [1] = {
102 .start = irq,
103 .end = irq,
104 .flags = IORESOURCE_IRQ,
105 }
106 };
107
108 return dbx500_add_platform_device(name, id, pdata, resources,
109 ARRAY_SIZE(resources));
110}
Rabin Vincent01afdd12010-12-08 11:07:55 +0530111
112static struct platform_device *
Lee Jones18403422012-02-06 11:22:21 -0800113dbx500_add_gpio(struct device *parent, int id, resource_size_t addr, int irq,
Rabin Vincent01afdd12010-12-08 11:07:55 +0530114 struct nmk_gpio_platform_data *pdata)
115{
116 struct resource resources[] = {
117 {
118 .start = addr,
119 .end = addr + 127,
120 .flags = IORESOURCE_MEM,
121 },
122 {
123 .start = irq,
124 .end = irq,
125 .flags = IORESOURCE_IRQ,
126 }
127 };
128
129 return platform_device_register_resndata(NULL, "gpio", id,
130 resources, ARRAY_SIZE(resources),
131 pdata, sizeof(*pdata));
132}
133
Lee Jones18403422012-02-06 11:22:21 -0800134void dbx500_add_gpios(struct device *parent, resource_size_t *base, int num,
135 int irq, struct nmk_gpio_platform_data *pdata)
Rabin Vincent01afdd12010-12-08 11:07:55 +0530136{
137 int first = 0;
138 int i;
139
140 for (i = 0; i < num; i++, first += 32, irq++) {
141 pdata->first_gpio = first;
142 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
Rabin Vincente493e062010-03-18 12:35:22 +0530143 pdata->num_gpio = 32;
Rabin Vincent01afdd12010-12-08 11:07:55 +0530144
Lee Jones18403422012-02-06 11:22:21 -0800145 dbx500_add_gpio(parent, i, base[i], irq, pdata);
Rabin Vincent01afdd12010-12-08 11:07:55 +0530146 }
147}