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 | */ |
| 11 | |
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> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/gpio.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 28 | #include <plat/menelaus.h> |
| 29 | #include <plat/mcbsp.h> |
Jorge Eduardo Candelaria | d6a2d9b | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 30 | #include <plat/omap44xx.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 31 | |
Tony Lindgren | c40fae95 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 32 | /*-------------------------------------------------------------------------*/ |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 33 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 34 | #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE) |
| 35 | |
| 36 | static struct platform_device **omap_mcbsp_devices; |
| 37 | |
| 38 | void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config, |
| 39 | int size) |
| 40 | { |
| 41 | int i; |
| 42 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 43 | omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *), |
| 44 | GFP_KERNEL); |
| 45 | if (!omap_mcbsp_devices) { |
| 46 | printk(KERN_ERR "Could not register McBSP devices\n"); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | for (i = 0; i < size; i++) { |
| 51 | struct platform_device *new_mcbsp; |
| 52 | int ret; |
| 53 | |
| 54 | new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1); |
| 55 | if (!new_mcbsp) |
| 56 | continue; |
| 57 | new_mcbsp->dev.platform_data = &config[i]; |
| 58 | ret = platform_device_add(new_mcbsp); |
| 59 | if (ret) { |
| 60 | platform_device_put(new_mcbsp); |
| 61 | continue; |
| 62 | } |
| 63 | omap_mcbsp_devices[i] = new_mcbsp; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | #else |
| 68 | void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config, |
| 69 | int size) |
| 70 | { } |
| 71 | #endif |
| 72 | |
| 73 | /*-------------------------------------------------------------------------*/ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 74 | |
Jorge Eduardo Candelaria | d6a2d9b | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 75 | #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \ |
| 76 | defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE) |
| 77 | |
| 78 | static struct resource mcpdm_resources[] = { |
| 79 | { |
| 80 | .name = "mcpdm_mem", |
| 81 | .start = OMAP44XX_MCPDM_BASE, |
| 82 | .end = OMAP44XX_MCPDM_BASE + SZ_4K, |
| 83 | .flags = IORESOURCE_MEM, |
| 84 | }, |
| 85 | { |
| 86 | .name = "mcpdm_irq", |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 87 | .start = OMAP44XX_IRQ_MCPDM, |
| 88 | .end = OMAP44XX_IRQ_MCPDM, |
Jorge Eduardo Candelaria | d6a2d9b | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 89 | .flags = IORESOURCE_IRQ, |
| 90 | }, |
| 91 | }; |
| 92 | |
| 93 | static struct platform_device omap_mcpdm_device = { |
| 94 | .name = "omap-mcpdm", |
| 95 | .id = -1, |
| 96 | .num_resources = ARRAY_SIZE(mcpdm_resources), |
| 97 | .resource = mcpdm_resources, |
| 98 | }; |
| 99 | |
| 100 | static void omap_init_mcpdm(void) |
| 101 | { |
| 102 | (void) platform_device_register(&omap_mcpdm_device); |
| 103 | } |
| 104 | #else |
| 105 | static inline void omap_init_mcpdm(void) {} |
| 106 | #endif |
| 107 | |
| 108 | /*-------------------------------------------------------------------------*/ |
| 109 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 110 | #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \ |
Russell King | 7736c09 | 2008-09-09 10:16:22 +0100 | [diff] [blame] | 111 | defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 112 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 113 | #define OMAP_MMC_NR_RES 2 |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 114 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 115 | /* |
| 116 | * Register MMC devices. Called from mach-omap1 and mach-omap2 device init. |
| 117 | */ |
Tony Lindgren | 0dffb5c | 2009-01-29 08:57:16 -0800 | [diff] [blame] | 118 | int __init omap_mmc_add(const char *name, int id, unsigned long base, |
| 119 | unsigned long size, unsigned int irq, |
| 120 | struct omap_mmc_platform_data *data) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 121 | { |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 122 | struct platform_device *pdev; |
| 123 | struct resource res[OMAP_MMC_NR_RES]; |
| 124 | int ret; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 125 | |
Tony Lindgren | 0dffb5c | 2009-01-29 08:57:16 -0800 | [diff] [blame] | 126 | pdev = platform_device_alloc(name, id); |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 127 | if (!pdev) |
| 128 | return -ENOMEM; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 129 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 130 | memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource)); |
| 131 | res[0].start = base; |
| 132 | res[0].end = base + size - 1; |
| 133 | res[0].flags = IORESOURCE_MEM; |
| 134 | res[1].start = res[1].end = irq; |
| 135 | res[1].flags = IORESOURCE_IRQ; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 136 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 137 | ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); |
| 138 | if (ret == 0) |
| 139 | ret = platform_device_add_data(pdev, data, sizeof(*data)); |
| 140 | if (ret) |
| 141 | goto fail; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 142 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 143 | ret = platform_device_add(pdev); |
| 144 | if (ret) |
| 145 | goto fail; |
David Brownell | 01971f6 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 146 | |
| 147 | /* return device handle to board setup code */ |
| 148 | data->dev = &pdev->dev; |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 149 | return 0; |
| 150 | |
| 151 | fail: |
| 152 | platform_device_put(pdev); |
| 153 | return ret; |
Russell King | 7736c09 | 2008-09-09 10:16:22 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 156 | #endif |
| 157 | |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 158 | /*-------------------------------------------------------------------------*/ |
| 159 | |
Ladislav Michl | 3bfe897 | 2009-12-11 16:16:36 -0800 | [diff] [blame] | 160 | #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE) |
| 161 | |
Tony Lindgren | 088ef95 | 2010-02-12 12:26:47 -0800 | [diff] [blame] | 162 | #ifdef CONFIG_ARCH_OMAP2 |
Ladislav Michl | 3bfe897 | 2009-12-11 16:16:36 -0800 | [diff] [blame] | 163 | #define OMAP_RNG_BASE 0x480A0000 |
| 164 | #else |
| 165 | #define OMAP_RNG_BASE 0xfffe5000 |
| 166 | #endif |
| 167 | |
| 168 | static struct resource rng_resources[] = { |
| 169 | { |
| 170 | .start = OMAP_RNG_BASE, |
| 171 | .end = OMAP_RNG_BASE + 0x4f, |
| 172 | .flags = IORESOURCE_MEM, |
| 173 | }, |
| 174 | }; |
| 175 | |
| 176 | static struct platform_device omap_rng_device = { |
| 177 | .name = "omap_rng", |
| 178 | .id = -1, |
| 179 | .num_resources = ARRAY_SIZE(rng_resources), |
| 180 | .resource = rng_resources, |
| 181 | }; |
| 182 | |
| 183 | static void omap_init_rng(void) |
| 184 | { |
| 185 | (void) platform_device_register(&omap_rng_device); |
| 186 | } |
| 187 | #else |
| 188 | static inline void omap_init_rng(void) {} |
| 189 | #endif |
| 190 | |
| 191 | /*-------------------------------------------------------------------------*/ |
| 192 | |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 193 | /* Numbering for the SPI-capable controllers when used for SPI: |
| 194 | * spi = 1 |
| 195 | * uwire = 2 |
| 196 | * mmc1..2 = 3..4 |
| 197 | * mcbsp1..3 = 5..7 |
| 198 | */ |
| 199 | |
| 200 | #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE) |
| 201 | |
| 202 | #define OMAP_UWIRE_BASE 0xfffb3000 |
| 203 | |
| 204 | static struct resource uwire_resources[] = { |
| 205 | { |
| 206 | .start = OMAP_UWIRE_BASE, |
| 207 | .end = OMAP_UWIRE_BASE + 0x20, |
| 208 | .flags = IORESOURCE_MEM, |
| 209 | }, |
| 210 | }; |
| 211 | |
| 212 | static struct platform_device omap_uwire_device = { |
| 213 | .name = "omap_uwire", |
| 214 | .id = -1, |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 215 | .num_resources = ARRAY_SIZE(uwire_resources), |
| 216 | .resource = uwire_resources, |
| 217 | }; |
| 218 | |
| 219 | static void omap_init_uwire(void) |
| 220 | { |
| 221 | /* FIXME define and use a boot tag; not all boards will be hooking |
| 222 | * up devices to the microwire controller, and multi-board configs |
| 223 | * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway... |
| 224 | */ |
| 225 | |
| 226 | /* board-specific code must configure chipselects (only a few |
| 227 | * are normally used) and SCLK/SDI/SDO (each has two choices). |
| 228 | */ |
| 229 | (void) platform_device_register(&omap_uwire_device); |
| 230 | } |
| 231 | #else |
| 232 | static inline void omap_init_uwire(void) {} |
| 233 | #endif |
| 234 | |
| 235 | /*-------------------------------------------------------------------------*/ |
| 236 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 237 | #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE) |
| 238 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 239 | static struct resource wdt_resources[] = { |
| 240 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 241 | .flags = IORESOURCE_MEM, |
| 242 | }, |
| 243 | }; |
| 244 | |
| 245 | static struct platform_device omap_wdt_device = { |
| 246 | .name = "omap_wdt", |
| 247 | .id = -1, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 248 | .num_resources = ARRAY_SIZE(wdt_resources), |
| 249 | .resource = wdt_resources, |
| 250 | }; |
| 251 | |
| 252 | static void omap_init_wdt(void) |
| 253 | { |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 254 | if (cpu_is_omap16xx()) |
| 255 | wdt_resources[0].start = 0xfffeb000; |
| 256 | else if (cpu_is_omap2420()) |
| 257 | wdt_resources[0].start = 0x48022000; /* WDT2 */ |
| 258 | else if (cpu_is_omap2430()) |
| 259 | wdt_resources[0].start = 0x49016000; /* WDT2 */ |
| 260 | else if (cpu_is_omap343x()) |
| 261 | wdt_resources[0].start = 0x48314000; /* WDT2 */ |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 262 | else if (cpu_is_omap44xx()) |
| 263 | wdt_resources[0].start = 0x4a314000; |
Felipe Balbi | 2817142 | 2008-09-20 04:14:01 +0300 | [diff] [blame] | 264 | else |
| 265 | return; |
| 266 | |
| 267 | wdt_resources[0].end = wdt_resources[0].start + 0x4f; |
| 268 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 269 | (void) platform_device_register(&omap_wdt_device); |
| 270 | } |
| 271 | #else |
| 272 | static inline void omap_init_wdt(void) {} |
| 273 | #endif |
| 274 | |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 275 | #if defined(CONFIG_TIDSPBRIDGE) || defined(CONFIG_TIDSPBRIDGE_MODULE) |
| 276 | |
| 277 | static phys_addr_t omap_dsp_phys_mempool_base; |
| 278 | |
| 279 | void __init omap_dsp_reserve_sdram_memblock(void) |
| 280 | { |
| 281 | phys_addr_t size = CONFIG_TIDSPBRIDGE_MEMPOOL_SIZE; |
| 282 | phys_addr_t paddr; |
| 283 | |
| 284 | if (!size) |
| 285 | return; |
| 286 | |
Felipe Contreras | 89346f9 | 2010-10-19 10:37:24 +0300 | [diff] [blame] | 287 | paddr = memblock_alloc(size, SZ_1M); |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 288 | if (!paddr) { |
| 289 | pr_err("%s: failed to reserve %x bytes\n", |
| 290 | __func__, size); |
| 291 | return; |
| 292 | } |
Felipe Contreras | 89346f9 | 2010-10-19 10:37:24 +0300 | [diff] [blame] | 293 | memblock_free(paddr, size); |
| 294 | memblock_remove(paddr, size); |
Felipe Contreras | 9017388 | 2010-10-04 19:09:14 +0300 | [diff] [blame] | 295 | |
| 296 | omap_dsp_phys_mempool_base = paddr; |
| 297 | } |
| 298 | |
| 299 | phys_addr_t omap_dsp_get_mempool_base(void) |
| 300 | { |
| 301 | return omap_dsp_phys_mempool_base; |
| 302 | } |
| 303 | EXPORT_SYMBOL(omap_dsp_get_mempool_base); |
| 304 | #endif |
| 305 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 306 | /* |
| 307 | * This gets called after board-specific INIT_MACHINE, and initializes most |
| 308 | * on-chip peripherals accessible on this board (except for few like USB): |
| 309 | * |
| 310 | * (a) Does any "standard config" pin muxing needed. Board-specific |
| 311 | * code will have muxed GPIO pins and done "nonstandard" setup; |
| 312 | * that code could live in the boot loader. |
| 313 | * (b) Populating board-specific platform_data with the data drivers |
| 314 | * rely on to handle wiring variations. |
| 315 | * (c) Creating platform devices as meaningful on this board and |
| 316 | * with this kernel configuration. |
| 317 | * |
| 318 | * Claiming GPIOs, and setting their direction and initial values, is the |
| 319 | * responsibility of the device drivers. So is responding to probe(). |
| 320 | * |
| 321 | * Board-specific knowlege like creating devices or pin setup is to be |
| 322 | * kept out of drivers as much as possible. In particular, pin setup |
| 323 | * may be handled by the boot loader, and drivers should expect it will |
| 324 | * normally have been done by the time they're probed. |
| 325 | */ |
| 326 | static int __init omap_init_devices(void) |
| 327 | { |
| 328 | /* please keep these calls, and their implementations above, |
| 329 | * in alphabetical order so they're easier to sort through. |
| 330 | */ |
Ladislav Michl | 3bfe897 | 2009-12-11 16:16:36 -0800 | [diff] [blame] | 331 | omap_init_rng(); |
Jorge Eduardo Candelaria | d6a2d9b | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 332 | omap_init_mcpdm(); |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 333 | omap_init_uwire(); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | arch_initcall(omap_init_devices); |