Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/plat-omap/devices.c |
| 3 | * |
| 4 | * Common platform device setup/initialization for OMAP1 and OMAP2 |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 11 | #include <linux/gpio.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/platform_device.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 16 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 18 | #include <linux/memblock.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 19 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 20 | #include <mach/hardware.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 21 | #include <asm/mach-types.h> |
| 22 | #include <asm/mach/map.h> |
| 23 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 24 | #include <plat/tc.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 25 | #include <plat/board.h> |
| 26 | #include <plat/mmc.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 27 | #include <plat/menelaus.h> |
| 28 | #include <plat/mcbsp.h> |
Jorge Eduardo Candelaria | d6a2d9b | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 29 | #include <plat/omap44xx.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 30 | |
Tony Lindgren | c40fae9 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 31 | /*-------------------------------------------------------------------------*/ |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 32 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 33 | #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE) |
| 34 | |
| 35 | static struct platform_device **omap_mcbsp_devices; |
| 36 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 37 | void omap_mcbsp_register_board_cfg(struct resource *res, int res_count, |
| 38 | struct omap_mcbsp_platform_data *config, int size) |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 39 | { |
| 40 | int i; |
| 41 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 42 | omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *), |
| 43 | GFP_KERNEL); |
| 44 | if (!omap_mcbsp_devices) { |
| 45 | printk(KERN_ERR "Could not register McBSP devices\n"); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | for (i = 0; i < size; i++) { |
| 50 | struct platform_device *new_mcbsp; |
| 51 | int ret; |
| 52 | |
| 53 | new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1); |
| 54 | if (!new_mcbsp) |
| 55 | continue; |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 56 | platform_device_add_resources(new_mcbsp, &res[i * res_count], |
| 57 | res_count); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 58 | new_mcbsp->dev.platform_data = &config[i]; |
| 59 | ret = platform_device_add(new_mcbsp); |
| 60 | if (ret) { |
| 61 | platform_device_put(new_mcbsp); |
| 62 | continue; |
| 63 | } |
| 64 | omap_mcbsp_devices[i] = new_mcbsp; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | #else |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 69 | void omap_mcbsp_register_board_cfg(struct resource *res, int res_count, |
| 70 | struct omap_mcbsp_platform_data *config, int size) |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 71 | { } |
| 72 | #endif |
| 73 | |
| 74 | /*-------------------------------------------------------------------------*/ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 75 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 76 | #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \ |
Russell King | 7736c09 | 2008-09-09 10:16:22 +0100 | [diff] [blame] | 77 | defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 78 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 79 | #define OMAP_MMC_NR_RES 2 |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 80 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 81 | /* |
| 82 | * Register MMC devices. Called from mach-omap1 and mach-omap2 device init. |
| 83 | */ |
Tony Lindgren | 0dffb5c | 2009-01-29 08:57:16 -0800 | [diff] [blame] | 84 | int __init omap_mmc_add(const char *name, int id, unsigned long base, |
| 85 | unsigned long size, unsigned int irq, |
| 86 | struct omap_mmc_platform_data *data) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 87 | { |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 88 | struct platform_device *pdev; |
| 89 | struct resource res[OMAP_MMC_NR_RES]; |
| 90 | int ret; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 91 | |
Tony Lindgren | 0dffb5c | 2009-01-29 08:57:16 -0800 | [diff] [blame] | 92 | pdev = platform_device_alloc(name, id); |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 93 | if (!pdev) |
| 94 | return -ENOMEM; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 95 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 96 | memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource)); |
| 97 | res[0].start = base; |
| 98 | res[0].end = base + size - 1; |
| 99 | res[0].flags = IORESOURCE_MEM; |
| 100 | res[1].start = res[1].end = irq; |
| 101 | res[1].flags = IORESOURCE_IRQ; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 102 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 103 | ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); |
| 104 | if (ret == 0) |
| 105 | ret = platform_device_add_data(pdev, data, sizeof(*data)); |
| 106 | if (ret) |
| 107 | goto fail; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 108 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 109 | ret = platform_device_add(pdev); |
| 110 | if (ret) |
| 111 | goto fail; |
David Brownell | 01971f6 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 112 | |
| 113 | /* return device handle to board setup code */ |
| 114 | data->dev = &pdev->dev; |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 115 | return 0; |
| 116 | |
| 117 | fail: |
| 118 | platform_device_put(pdev); |
| 119 | return ret; |
Russell King | 7736c09 | 2008-09-09 10:16:22 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 122 | #endif |
| 123 | |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 124 | /*-------------------------------------------------------------------------*/ |
| 125 | |
Ladislav Michl | 3bfe897 | 2009-12-11 16:16:36 -0800 | [diff] [blame] | 126 | #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE) |
| 127 | |
Tony Lindgren | 088ef95 | 2010-02-12 12:26:47 -0800 | [diff] [blame] | 128 | #ifdef CONFIG_ARCH_OMAP2 |
Ladislav Michl | 3bfe897 | 2009-12-11 16:16:36 -0800 | [diff] [blame] | 129 | #define OMAP_RNG_BASE 0x480A0000 |
| 130 | #else |
| 131 | #define OMAP_RNG_BASE 0xfffe5000 |
| 132 | #endif |
| 133 | |
| 134 | static struct resource rng_resources[] = { |
| 135 | { |
| 136 | .start = OMAP_RNG_BASE, |
| 137 | .end = OMAP_RNG_BASE + 0x4f, |
| 138 | .flags = IORESOURCE_MEM, |
| 139 | }, |
| 140 | }; |
| 141 | |
| 142 | static struct platform_device omap_rng_device = { |
| 143 | .name = "omap_rng", |
| 144 | .id = -1, |
| 145 | .num_resources = ARRAY_SIZE(rng_resources), |
| 146 | .resource = rng_resources, |
| 147 | }; |
| 148 | |
| 149 | static void omap_init_rng(void) |
| 150 | { |
| 151 | (void) platform_device_register(&omap_rng_device); |
| 152 | } |
| 153 | #else |
| 154 | static inline void omap_init_rng(void) {} |
| 155 | #endif |
| 156 | |
| 157 | /*-------------------------------------------------------------------------*/ |
| 158 | |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 159 | /* Numbering for the SPI-capable controllers when used for SPI: |
| 160 | * spi = 1 |
| 161 | * uwire = 2 |
| 162 | * mmc1..2 = 3..4 |
| 163 | * mcbsp1..3 = 5..7 |
| 164 | */ |
| 165 | |
| 166 | #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE) |
| 167 | |
| 168 | #define OMAP_UWIRE_BASE 0xfffb3000 |
| 169 | |
| 170 | static struct resource uwire_resources[] = { |
| 171 | { |
| 172 | .start = OMAP_UWIRE_BASE, |
| 173 | .end = OMAP_UWIRE_BASE + 0x20, |
| 174 | .flags = IORESOURCE_MEM, |
| 175 | }, |
| 176 | }; |
| 177 | |
| 178 | static struct platform_device omap_uwire_device = { |
| 179 | .name = "omap_uwire", |
| 180 | .id = -1, |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 181 | .num_resources = ARRAY_SIZE(uwire_resources), |
| 182 | .resource = uwire_resources, |
| 183 | }; |
| 184 | |
| 185 | static void omap_init_uwire(void) |
| 186 | { |
| 187 | /* FIXME define and use a boot tag; not all boards will be hooking |
| 188 | * up devices to the microwire controller, and multi-board configs |
| 189 | * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway... |
| 190 | */ |
| 191 | |
| 192 | /* board-specific code must configure chipselects (only a few |
| 193 | * are normally used) and SCLK/SDI/SDO (each has two choices). |
| 194 | */ |
| 195 | (void) platform_device_register(&omap_uwire_device); |
| 196 | } |
| 197 | #else |
| 198 | static inline void omap_init_uwire(void) {} |
| 199 | #endif |
| 200 | |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 201 | #if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE) |
| 202 | |
| 203 | static phys_addr_t omap_dsp_phys_mempool_base; |
| 204 | |
| 205 | void __init omap_dsp_reserve_sdram_memblock(void) |
| 206 | { |
| 207 | phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE; |
| 208 | phys_addr_t paddr; |
| 209 | |
| 210 | if (!size) |
| 211 | return; |
| 212 | |
Felipe Contreras | 89346f9 | 2010-10-19 10:37:24 +0300 | [diff] [blame] | 213 | paddr = memblock_alloc(size, SZ_1M); |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 214 | if (!paddr) { |
| 215 | pr_err("%s: failed to reserve %x bytes\n", |
| 216 | __func__, size); |
| 217 | return; |
| 218 | } |
Felipe Contreras | 89346f9 | 2010-10-19 10:37:24 +0300 | [diff] [blame] | 219 | memblock_free(paddr, size); |
| 220 | memblock_remove(paddr, size); |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 221 | |
| 222 | omap_dsp_phys_mempool_base = paddr; |
| 223 | } |
| 224 | |
| 225 | phys_addr_t omap_dsp_get_mempool_base(void) |
| 226 | { |
| 227 | return omap_dsp_phys_mempool_base; |
| 228 | } |
| 229 | EXPORT_SYMBOL(omap_dsp_get_mempool_base); |
| 230 | #endif |
| 231 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 232 | /* |
| 233 | * This gets called after board-specific INIT_MACHINE, and initializes most |
| 234 | * on-chip peripherals accessible on this board (except for few like USB): |
| 235 | * |
| 236 | * (a) Does any "standard config" pin muxing needed. Board-specific |
| 237 | * code will have muxed GPIO pins and done "nonstandard" setup; |
| 238 | * that code could live in the boot loader. |
| 239 | * (b) Populating board-specific platform_data with the data drivers |
| 240 | * rely on to handle wiring variations. |
| 241 | * (c) Creating platform devices as meaningful on this board and |
| 242 | * with this kernel configuration. |
| 243 | * |
| 244 | * Claiming GPIOs, and setting their direction and initial values, is the |
| 245 | * responsibility of the device drivers. So is responding to probe(). |
| 246 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 247 | * Board-specific knowledge like creating devices or pin setup is to be |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 248 | * kept out of drivers as much as possible. In particular, pin setup |
| 249 | * may be handled by the boot loader, and drivers should expect it will |
| 250 | * normally have been done by the time they're probed. |
| 251 | */ |
| 252 | static int __init omap_init_devices(void) |
| 253 | { |
| 254 | /* please keep these calls, and their implementations above, |
| 255 | * in alphabetical order so they're easier to sort through. |
| 256 | */ |
Ladislav Michl | 3bfe897 | 2009-12-11 16:16:36 -0800 | [diff] [blame] | 257 | omap_init_rng(); |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 258 | omap_init_uwire(); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | arch_initcall(omap_init_devices); |