Rabin Vincent | fbf1ead | 2010-09-29 19:46:32 +0530 | [diff] [blame] | 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 | |
Linus Walleij | 0f33286 | 2011-08-22 08:33:30 +0100 | [diff] [blame] | 16 | #include <plat/gpio-nomadik.h> |
Rabin Vincent | 01afdd1 | 2010-12-08 11:07:55 +0530 | [diff] [blame] | 17 | |
Rabin Vincent | fbf1ead | 2010-09-29 19:46:32 +0530 | [diff] [blame] | 18 | #include <mach/hardware.h> |
| 19 | |
| 20 | #include "devices-common.h" |
| 21 | |
| 22 | struct amba_device * |
| 23 | dbx500_add_amba_device(const char *name, resource_size_t base, |
| 24 | int irq, void *pdata, unsigned int periphid) |
| 25 | { |
| 26 | struct amba_device *dev; |
| 27 | int ret; |
| 28 | |
Russell King | 46d4bb9 | 2011-12-18 11:16:59 +0000 | [diff] [blame^] | 29 | dev = amba_device_alloc(name, base, SZ_4K); |
Rabin Vincent | fbf1ead | 2010-09-29 19:46:32 +0530 | [diff] [blame] | 30 | if (!dev) |
| 31 | return ERR_PTR(-ENOMEM); |
| 32 | |
Rabin Vincent | fbf1ead | 2010-09-29 19:46:32 +0530 | [diff] [blame] | 33 | dev->dma_mask = DMA_BIT_MASK(32); |
| 34 | dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 35 | |
| 36 | dev->irq[0] = irq; |
| 37 | dev->irq[1] = NO_IRQ; |
| 38 | |
| 39 | dev->periphid = periphid; |
| 40 | |
| 41 | dev->dev.platform_data = pdata; |
| 42 | |
Russell King | 46d4bb9 | 2011-12-18 11:16:59 +0000 | [diff] [blame^] | 43 | ret = amba_device_add(dev, &iomem_resource); |
Rabin Vincent | fbf1ead | 2010-09-29 19:46:32 +0530 | [diff] [blame] | 44 | if (ret) { |
Russell King | 46d4bb9 | 2011-12-18 11:16:59 +0000 | [diff] [blame^] | 45 | amba_device_put(dev); |
Rabin Vincent | fbf1ead | 2010-09-29 19:46:32 +0530 | [diff] [blame] | 46 | return ERR_PTR(ret); |
| 47 | } |
| 48 | |
| 49 | return dev; |
| 50 | } |
| 51 | |
| 52 | static struct platform_device * |
| 53 | dbx500_add_platform_device(const char *name, int id, void *pdata, |
| 54 | struct resource *res, int resnum) |
| 55 | { |
| 56 | struct platform_device *dev; |
| 57 | int ret; |
| 58 | |
| 59 | dev = platform_device_alloc(name, id); |
| 60 | if (!dev) |
| 61 | return ERR_PTR(-ENOMEM); |
| 62 | |
| 63 | dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 64 | dev->dev.dma_mask = &dev->dev.coherent_dma_mask; |
| 65 | |
| 66 | ret = platform_device_add_resources(dev, res, resnum); |
| 67 | if (ret) |
| 68 | goto out_free; |
| 69 | |
| 70 | dev->dev.platform_data = pdata; |
| 71 | |
| 72 | ret = platform_device_add(dev); |
| 73 | if (ret) |
| 74 | goto out_free; |
| 75 | |
| 76 | return dev; |
| 77 | |
| 78 | out_free: |
| 79 | platform_device_put(dev); |
| 80 | return ERR_PTR(ret); |
| 81 | } |
| 82 | |
| 83 | struct platform_device * |
| 84 | dbx500_add_platform_device_4k1irq(const char *name, int id, |
| 85 | resource_size_t base, |
| 86 | int irq, void *pdata) |
| 87 | { |
| 88 | struct resource resources[] = { |
| 89 | [0] = { |
| 90 | .start = base, |
| 91 | .end = base + SZ_4K - 1, |
| 92 | .flags = IORESOURCE_MEM, |
| 93 | }, |
| 94 | [1] = { |
| 95 | .start = irq, |
| 96 | .end = irq, |
| 97 | .flags = IORESOURCE_IRQ, |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | return dbx500_add_platform_device(name, id, pdata, resources, |
| 102 | ARRAY_SIZE(resources)); |
| 103 | } |
Rabin Vincent | 01afdd1 | 2010-12-08 11:07:55 +0530 | [diff] [blame] | 104 | |
| 105 | static struct platform_device * |
| 106 | dbx500_add_gpio(int id, resource_size_t addr, int irq, |
| 107 | struct nmk_gpio_platform_data *pdata) |
| 108 | { |
| 109 | struct resource resources[] = { |
| 110 | { |
| 111 | .start = addr, |
| 112 | .end = addr + 127, |
| 113 | .flags = IORESOURCE_MEM, |
| 114 | }, |
| 115 | { |
| 116 | .start = irq, |
| 117 | .end = irq, |
| 118 | .flags = IORESOURCE_IRQ, |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | return platform_device_register_resndata(NULL, "gpio", id, |
| 123 | resources, ARRAY_SIZE(resources), |
| 124 | pdata, sizeof(*pdata)); |
| 125 | } |
| 126 | |
| 127 | void dbx500_add_gpios(resource_size_t *base, int num, int irq, |
| 128 | struct nmk_gpio_platform_data *pdata) |
| 129 | { |
| 130 | int first = 0; |
| 131 | int i; |
| 132 | |
| 133 | for (i = 0; i < num; i++, first += 32, irq++) { |
| 134 | pdata->first_gpio = first; |
| 135 | pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first); |
Rabin Vincent | e493e06 | 2010-03-18 12:35:22 +0530 | [diff] [blame] | 136 | pdata->num_gpio = 32; |
Rabin Vincent | 01afdd1 | 2010-12-08 11:07:55 +0530 | [diff] [blame] | 137 | |
| 138 | dbx500_add_gpio(i, base[i], irq, pdata); |
| 139 | } |
| 140 | } |