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