blob: c5312a4b49f5487a229166de8c28acb3994d6c52 [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
Russell King46d4bb9b52011-12-18 11:16:59 +000030 dev = amba_device_alloc(name, base, SZ_4K);
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053031 if (!dev)
32 return ERR_PTR(-ENOMEM);
33
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053034 dev->dma_mask = DMA_BIT_MASK(32);
35 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
36
37 dev->irq[0] = irq;
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053038
39 dev->periphid = periphid;
40
41 dev->dev.platform_data = pdata;
42
Lee Jonesb024a0c2012-02-06 11:22:25 -080043 dev->dev.parent = parent;
44
Russell King46d4bb9b52011-12-18 11:16:59 +000045 ret = amba_device_add(dev, &iomem_resource);
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053046 if (ret) {
Russell King46d4bb9b52011-12-18 11:16:59 +000047 amba_device_put(dev);
Rabin Vincentfbf1eadf2010-09-29 19:46:32 +053048 return ERR_PTR(ret);
49 }
50
51 return dev;
52}
53
54static struct platform_device *
Lee Jones18403422012-02-06 11:22:21 -080055dbx500_add_gpio(struct device *parent, int id, resource_size_t addr, int irq,
Rabin Vincent01afdd12010-12-08 11:07:55 +053056 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
Lee Jonesb024a0c2012-02-06 11:22:25 -080071 return platform_device_register_resndata(
72 parent,
73 "gpio",
74 id,
75 resources,
76 ARRAY_SIZE(resources),
77 pdata,
78 sizeof(*pdata));
Rabin Vincent01afdd12010-12-08 11:07:55 +053079}
80
Lee Jones18403422012-02-06 11:22:21 -080081void dbx500_add_gpios(struct device *parent, resource_size_t *base, int num,
82 int irq, struct nmk_gpio_platform_data *pdata)
Rabin Vincent01afdd12010-12-08 11:07:55 +053083{
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);
Rabin Vincente493e062010-03-18 12:35:22 +053090 pdata->num_gpio = 32;
Rabin Vincent01afdd12010-12-08 11:07:55 +053091
Lee Jones18403422012-02-06 11:22:21 -080092 dbx500_add_gpio(parent, i, base[i], irq, pdata);
Rabin Vincent01afdd12010-12-08 11:07:55 +053093 }
94}