2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5 * License terms: GNU General Public License (GPL), version 2.
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>
16 #include <plat/gpio-nomadik.h>
18 #include <mach/hardware.h>
20 #include "devices-common.h"
23 dbx500_add_amba_device(const char *name
, resource_size_t base
,
24 int irq
, void *pdata
, unsigned int periphid
)
26 struct amba_device
*dev
;
29 dev
= kzalloc(sizeof *dev
, GFP_KERNEL
);
31 return ERR_PTR(-ENOMEM
);
33 dev
->dev
.init_name
= name
;
35 dev
->res
.start
= base
;
36 dev
->res
.end
= base
+ SZ_4K
- 1;
37 dev
->res
.flags
= IORESOURCE_MEM
;
39 dev
->dma_mask
= DMA_BIT_MASK(32);
40 dev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
45 dev
->periphid
= periphid
;
47 dev
->dev
.platform_data
= pdata
;
49 ret
= amba_device_register(dev
, &iomem_resource
);
58 static struct platform_device
*
59 dbx500_add_platform_device(const char *name
, int id
, void *pdata
,
60 struct resource
*res
, int resnum
)
62 struct platform_device
*dev
;
65 dev
= platform_device_alloc(name
, id
);
67 return ERR_PTR(-ENOMEM
);
69 dev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
70 dev
->dev
.dma_mask
= &dev
->dev
.coherent_dma_mask
;
72 ret
= platform_device_add_resources(dev
, res
, resnum
);
76 dev
->dev
.platform_data
= pdata
;
78 ret
= platform_device_add(dev
);
85 platform_device_put(dev
);
89 struct platform_device
*
90 dbx500_add_platform_device_4k1irq(const char *name
, int id
,
94 struct resource resources
[] = {
97 .end
= base
+ SZ_4K
- 1,
98 .flags
= IORESOURCE_MEM
,
103 .flags
= IORESOURCE_IRQ
,
107 return dbx500_add_platform_device(name
, id
, pdata
, resources
,
108 ARRAY_SIZE(resources
));
111 static struct platform_device
*
112 dbx500_add_gpio(int id
, resource_size_t addr
, int irq
,
113 struct nmk_gpio_platform_data
*pdata
)
115 struct resource resources
[] = {
119 .flags
= IORESOURCE_MEM
,
124 .flags
= IORESOURCE_IRQ
,
128 return platform_device_register_resndata(NULL
, "gpio", id
,
129 resources
, ARRAY_SIZE(resources
),
130 pdata
, sizeof(*pdata
));
133 void dbx500_add_gpios(resource_size_t
*base
, int num
, int irq
,
134 struct nmk_gpio_platform_data
*pdata
)
139 for (i
= 0; i
< num
; i
++, first
+= 32, irq
++) {
140 pdata
->first_gpio
= first
;
141 pdata
->first_irq
= NOMADIK_GPIO_TO_IRQ(first
);
142 pdata
->num_gpio
= 32;
144 dbx500_add_gpio(i
, base
[i
], irq
, pdata
);