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