1 /*
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
16 #include <plat/gpio-nomadik.h>
17
18 #include <mach/hardware.h>
19
20 #include "devices-common.h"
21
22 struct amba_device *
dbx500_add_amba_device(struct device * parent,const char * name,resource_size_t base,int irq,void * pdata,unsigned int periphid)23 dbx500_add_amba_device(struct device *parent, const char *name,
24 resource_size_t base, int irq, void *pdata,
25 unsigned int periphid)
26 {
27 struct amba_device *dev;
28 int ret;
29
30 dev = amba_device_alloc(name, base, SZ_4K);
31 if (!dev)
32 return ERR_PTR(-ENOMEM);
33
34 dev->dma_mask = DMA_BIT_MASK(32);
35 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
36
37 dev->irq[0] = irq;
38
39 dev->periphid = periphid;
40
41 dev->dev.platform_data = pdata;
42
43 dev->dev.parent = parent;
44
45 ret = amba_device_add(dev, &iomem_resource);
46 if (ret) {
47 amba_device_put(dev);
48 return ERR_PTR(ret);
49 }
50
51 return dev;
52 }
53
54 static struct platform_device *
dbx500_add_gpio(struct device * parent,int id,resource_size_t addr,int irq,struct nmk_gpio_platform_data * pdata)55 dbx500_add_gpio(struct device *parent, int id, resource_size_t addr, int irq,
56 struct nmk_gpio_platform_data *pdata)
57 {
58 struct resource resources[] = {
59 {
60 .start = addr,
61 .end = addr + 127,
62 .flags = IORESOURCE_MEM,
63 },
64 {
65 .start = irq,
66 .end = irq,
67 .flags = IORESOURCE_IRQ,
68 }
69 };
70
71 return platform_device_register_resndata(
72 parent,
73 "gpio",
74 id,
75 resources,
76 ARRAY_SIZE(resources),
77 pdata,
78 sizeof(*pdata));
79 }
80
dbx500_add_gpios(struct device * parent,resource_size_t * base,int num,int irq,struct nmk_gpio_platform_data * pdata)81 void dbx500_add_gpios(struct device *parent, resource_size_t *base, int num,
82 int irq, struct nmk_gpio_platform_data *pdata)
83 {
84 int first = 0;
85 int i;
86
87 for (i = 0; i < num; i++, first += 32, irq++) {
88 pdata->first_gpio = first;
89 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
90 pdata->num_gpio = 32;
91
92 dbx500_add_gpio(parent, i, base[i], irq, pdata);
93 }
94 }
95