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