Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap2/devices.c |
| 3 | * |
| 4 | * OMAP2 platform device setup/initialization |
| 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 | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/platform_device.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 15 | #include <linux/io.h> |
Kevin Hilman | 917fa28 | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 16 | #include <linux/clk.h> |
Varadarajan, Charulatha | f2ce623 | 2010-09-23 20:02:42 +0530 | [diff] [blame] | 17 | #include <linux/err.h> |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 18 | #include <linux/slab.h> |
Benoit Cousson | ad8dfac | 2011-08-12 13:48:47 +0200 | [diff] [blame] | 19 | #include <linux/of.h> |
Matt Porter | 484202f | 2012-09-17 16:26:11 -0700 | [diff] [blame] | 20 | #include <linux/pinctrl/machine.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 21 | |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 22 | #include <asm/mach-types.h> |
| 23 | #include <asm/mach/map.h> |
| 24 | |
Tony Lindgren | 45c3eb7 | 2012-11-30 08:41:50 -0800 | [diff] [blame] | 25 | #include <linux/omap-dma.h> |
Tony Lindgren | 2a296c8 | 2012-10-02 17:41:35 -0700 | [diff] [blame] | 26 | |
Tony Lindgren | ee0839c | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 27 | #include "iomap.h" |
Tony Lindgren | 2a296c8 | 2012-10-02 17:41:35 -0700 | [diff] [blame] | 28 | #include "omap_hwmod.h" |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 29 | #include "omap_device.h" |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 30 | |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 31 | #include "soc.h" |
| 32 | #include "common.h" |
Tony Lindgren | 4896e39 | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 33 | #include "mux.h" |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 34 | #include "control.h" |
Archit Taneja | 576e5bd | 2013-09-16 12:48:31 +0530 | [diff] [blame] | 35 | #include "display.h" |
Tony Lindgren | 4896e39 | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 36 | |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 37 | #define L3_MODULES_MAX_LEN 12 |
sricharan | a4dc616 | 2011-03-09 16:00:29 +0530 | [diff] [blame] | 38 | #define L3_MODULES 3 |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 39 | |
| 40 | static int __init omap3_l3_init(void) |
| 41 | { |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 42 | struct omap_hwmod *oh; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 43 | struct platform_device *pdev; |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 44 | char oh_name[L3_MODULES_MAX_LEN]; |
| 45 | |
| 46 | /* |
| 47 | * To avoid code running on other OMAPs in |
| 48 | * multi-omap builds |
| 49 | */ |
Tony Lindgren | aa25729c | 2014-11-05 09:21:23 -0800 | [diff] [blame] | 50 | if (!(cpu_is_omap34xx()) || of_have_populated_dt()) |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 51 | return -ENODEV; |
| 52 | |
Paul Walmsley | eeb3711 | 2012-04-13 06:34:32 -0600 | [diff] [blame] | 53 | snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main"); |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 54 | |
| 55 | oh = omap_hwmod_lookup(oh_name); |
| 56 | |
| 57 | if (!oh) |
| 58 | pr_err("could not look up %s\n", oh_name); |
| 59 | |
Paul Walmsley | c1d1cd5 | 2013-01-26 00:48:53 -0700 | [diff] [blame] | 60 | pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0); |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 61 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 62 | WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name); |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 63 | |
Nicholas Krause | e44be50 | 2015-05-20 15:32:26 -0400 | [diff] [blame] | 64 | return PTR_ERR_OR_ZERO(pdev); |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 65 | } |
Tony Lindgren | b76c8b1 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 66 | omap_postcore_initcall(omap3_l3_init); |
sricharan | 0abcf61 | 2011-02-08 14:10:45 +0530 | [diff] [blame] | 67 | |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 68 | static inline void omap_init_sti(void) {} |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 69 | |
Tony Lindgren | 646e3ed | 2008-10-06 15:49:36 +0300 | [diff] [blame] | 70 | #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE) |
Juha Yrjola | ed7eb9d | 2006-06-26 16:16:10 -0700 | [diff] [blame] | 71 | |
Arnd Bergmann | 2203747 | 2012-08-24 15:21:06 +0200 | [diff] [blame] | 72 | #include <linux/platform_data/spi-omap2-mcspi.h> |
Juha Yrjola | ed7eb9d | 2006-06-26 16:16:10 -0700 | [diff] [blame] | 73 | |
Kevin Hilman | 9cf793f | 2012-02-20 09:43:30 -0800 | [diff] [blame] | 74 | static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused) |
Juha Yrjola | ed7eb9d | 2006-06-26 16:16:10 -0700 | [diff] [blame] | 75 | { |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 76 | struct platform_device *pdev; |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 77 | char *name = "omap2_mcspi"; |
| 78 | struct omap2_mcspi_platform_config *pdata; |
| 79 | static int spi_num; |
| 80 | struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr; |
Tony Lindgren | af41a12 | 2009-09-24 16:23:05 -0700 | [diff] [blame] | 81 | |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 82 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 83 | if (!pdata) { |
| 84 | pr_err("Memory allocation for McSPI device failed\n"); |
| 85 | return -ENOMEM; |
| 86 | } |
Tony Lindgren | af41a12 | 2009-09-24 16:23:05 -0700 | [diff] [blame] | 87 | |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 88 | pdata->num_cs = mcspi_attrib->num_chipselect; |
| 89 | switch (oh->class->rev) { |
| 90 | case OMAP2_MCSPI_REV: |
| 91 | case OMAP3_MCSPI_REV: |
| 92 | pdata->regs_offset = 0; |
| 93 | break; |
| 94 | case OMAP4_MCSPI_REV: |
| 95 | pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET; |
| 96 | break; |
| 97 | default: |
| 98 | pr_err("Invalid McSPI Revision value\n"); |
Julia Lawall | e0feca89 | 2011-12-23 18:39:31 +0100 | [diff] [blame] | 99 | kfree(pdata); |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 100 | return -EINVAL; |
| 101 | } |
| 102 | |
| 103 | spi_num++; |
Paul Walmsley | c1d1cd5 | 2013-01-26 00:48:53 -0700 | [diff] [blame] | 104 | pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata)); |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 105 | WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n", |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 106 | name, oh->name); |
| 107 | kfree(pdata); |
| 108 | return 0; |
Tony Lindgren | af41a12 | 2009-09-24 16:23:05 -0700 | [diff] [blame] | 109 | } |
Tony Lindgren | af41a12 | 2009-09-24 16:23:05 -0700 | [diff] [blame] | 110 | |
| 111 | static void omap_init_mcspi(void) |
| 112 | { |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 113 | omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL); |
Juha Yrjola | ed7eb9d | 2006-06-26 16:16:10 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #else |
| 117 | static inline void omap_init_mcspi(void) {} |
| 118 | #endif |
| 119 | |
Paul Walmsley | 4848d46 | 2012-09-23 17:28:27 -0600 | [diff] [blame] | 120 | /** |
| 121 | * omap_init_rng - bind the RNG hwmod to the RNG omap_device |
| 122 | * |
| 123 | * Bind the RNG hwmod to the RNG omap_device. No return value. |
| 124 | */ |
| 125 | static void omap_init_rng(void) |
| 126 | { |
| 127 | struct omap_hwmod *oh; |
| 128 | struct platform_device *pdev; |
| 129 | |
| 130 | oh = omap_hwmod_lookup("rng"); |
| 131 | if (!oh) |
| 132 | return; |
| 133 | |
Paul Walmsley | c1d1cd5 | 2013-01-26 00:48:53 -0700 | [diff] [blame] | 134 | pdev = omap_device_build("omap_rng", -1, oh, NULL, 0); |
Paul Walmsley | 4848d46 | 2012-09-23 17:28:27 -0600 | [diff] [blame] | 135 | WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n"); |
| 136 | } |
Will Deacon | 8834133 | 2010-04-09 13:54:43 +0100 | [diff] [blame] | 137 | |
Mark A. Greer | 26f88e6 | 2013-03-18 10:06:32 -0600 | [diff] [blame] | 138 | static void __init omap_init_sham(void) |
Tony Lindgren | 646e3ed | 2008-10-06 15:49:36 +0300 | [diff] [blame] | 139 | { |
Mark A. Greer | 8c7bb57 | 2013-03-18 10:06:33 -0600 | [diff] [blame] | 140 | struct omap_hwmod *oh; |
| 141 | struct platform_device *pdev; |
Mark A. Greer | e569e99 | 2013-03-30 15:49:19 -0600 | [diff] [blame] | 142 | |
Mark A. Greer | 8c7bb57 | 2013-03-18 10:06:33 -0600 | [diff] [blame] | 143 | oh = omap_hwmod_lookup("sham"); |
| 144 | if (!oh) |
| 145 | return; |
Mark A. Greer | e569e99 | 2013-03-30 15:49:19 -0600 | [diff] [blame] | 146 | |
Mark A. Greer | 8c7bb57 | 2013-03-18 10:06:33 -0600 | [diff] [blame] | 147 | pdev = omap_device_build("omap-sham", -1, oh, NULL, 0); |
| 148 | WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n"); |
Tony Lindgren | 646e3ed | 2008-10-06 15:49:36 +0300 | [diff] [blame] | 149 | } |
Tony Lindgren | 646e3ed | 2008-10-06 15:49:36 +0300 | [diff] [blame] | 150 | |
Mark A. Greer | 14ae556 | 2012-12-21 09:28:10 -0700 | [diff] [blame] | 151 | static void __init omap_init_aes(void) |
Dmitry Kasatkin | b744c67 | 2010-09-03 19:13:55 +0800 | [diff] [blame] | 152 | { |
Mark A. Greer | 77e2fd8 | 2012-12-21 09:28:11 -0700 | [diff] [blame] | 153 | struct omap_hwmod *oh; |
| 154 | struct platform_device *pdev; |
Mark A. Greer | 660ffd6 | 2012-12-21 09:28:09 -0700 | [diff] [blame] | 155 | |
Mark A. Greer | 77e2fd8 | 2012-12-21 09:28:11 -0700 | [diff] [blame] | 156 | oh = omap_hwmod_lookup("aes"); |
| 157 | if (!oh) |
| 158 | return; |
Mark A. Greer | 660ffd6 | 2012-12-21 09:28:09 -0700 | [diff] [blame] | 159 | |
Mark A. Greer | 77e2fd8 | 2012-12-21 09:28:11 -0700 | [diff] [blame] | 160 | pdev = omap_device_build("omap-aes", -1, oh, NULL, 0); |
| 161 | WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n"); |
Dmitry Kasatkin | b744c67 | 2010-09-03 19:13:55 +0800 | [diff] [blame] | 162 | } |
| 163 | |
Tony Lindgren | d887466 | 2008-12-10 17:37:16 -0800 | [diff] [blame] | 164 | /*-------------------------------------------------------------------------*/ |
| 165 | |
Vaibhav Hiremath | b227358 | 2010-05-10 14:29:14 -0700 | [diff] [blame] | 166 | #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \ |
| 167 | defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE) |
| 168 | #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE) |
| 169 | static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = { |
| 170 | }; |
| 171 | #else |
| 172 | static struct resource omap_vout_resource[2] = { |
| 173 | }; |
| 174 | #endif |
| 175 | |
| 176 | static struct platform_device omap_vout_device = { |
| 177 | .name = "omap_vout", |
| 178 | .num_resources = ARRAY_SIZE(omap_vout_resource), |
| 179 | .resource = &omap_vout_resource[0], |
| 180 | .id = -1, |
| 181 | }; |
Archit Taneja | 576e5bd | 2013-09-16 12:48:31 +0530 | [diff] [blame] | 182 | |
| 183 | int __init omap_init_vout(void) |
Vaibhav Hiremath | b227358 | 2010-05-10 14:29:14 -0700 | [diff] [blame] | 184 | { |
Archit Taneja | 576e5bd | 2013-09-16 12:48:31 +0530 | [diff] [blame] | 185 | return platform_device_register(&omap_vout_device); |
Vaibhav Hiremath | b227358 | 2010-05-10 14:29:14 -0700 | [diff] [blame] | 186 | } |
| 187 | #else |
Archit Taneja | 576e5bd | 2013-09-16 12:48:31 +0530 | [diff] [blame] | 188 | int __init omap_init_vout(void) { return 0; } |
Vaibhav Hiremath | b227358 | 2010-05-10 14:29:14 -0700 | [diff] [blame] | 189 | #endif |
| 190 | |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 191 | /*-------------------------------------------------------------------------*/ |
| 192 | |
| 193 | static int __init omap2_init_devices(void) |
| 194 | { |
Matt Porter | 484202f | 2012-09-17 16:26:11 -0700 | [diff] [blame] | 195 | /* Enable dummy states for those platforms without pinctrl support */ |
| 196 | if (!of_have_populated_dt()) |
| 197 | pinctrl_provide_dummies(); |
| 198 | |
Benoit Cousson | efcf1e5 | 2012-01-20 14:15:58 +0100 | [diff] [blame] | 199 | /* If dtb is there, the devices will be created dynamically */ |
Peter Ujfalusi | 259bd6c | 2012-05-02 15:23:18 +0300 | [diff] [blame] | 200 | if (!of_have_populated_dt()) { |
Peter Ujfalusi | f2e6a0a | 2015-12-11 14:50:20 +0200 | [diff] [blame] | 201 | /* |
| 202 | * please keep these calls, and their implementations above, |
| 203 | * in alphabetical order so they're easier to sort through. |
| 204 | */ |
Benoit Cousson | efcf1e5 | 2012-01-20 14:15:58 +0100 | [diff] [blame] | 205 | omap_init_mcspi(); |
Mark A. Greer | 114d7a8 | 2013-03-18 10:06:33 -0600 | [diff] [blame] | 206 | omap_init_sham(); |
Mark A. Greer | 53335ac | 2012-12-21 09:28:12 -0700 | [diff] [blame] | 207 | omap_init_aes(); |
Lokesh Vutla | 674ee08 | 2013-08-05 20:17:22 +0530 | [diff] [blame] | 208 | omap_init_rng(); |
Peter Ujfalusi | 259bd6c | 2012-05-02 15:23:18 +0300 | [diff] [blame] | 209 | } |
Tony Lindgren | 9b6553c | 2006-04-02 17:46:30 +0100 | [diff] [blame] | 210 | omap_init_sti(); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 211 | |
| 212 | return 0; |
| 213 | } |
Tony Lindgren | b76c8b1 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 214 | omap_arch_initcall(omap2_init_devices); |
Tony Lindgren | a861280 | 2014-11-20 12:45:43 -0800 | [diff] [blame] | 215 | |
| 216 | static int __init omap_gpmc_init(void) |
| 217 | { |
| 218 | struct omap_hwmod *oh; |
| 219 | struct platform_device *pdev; |
| 220 | char *oh_name = "gpmc"; |
| 221 | |
| 222 | /* |
| 223 | * if the board boots up with a populated DT, do not |
| 224 | * manually add the device from this initcall |
| 225 | */ |
| 226 | if (of_have_populated_dt()) |
| 227 | return -ENODEV; |
| 228 | |
| 229 | oh = omap_hwmod_lookup(oh_name); |
| 230 | if (!oh) { |
| 231 | pr_err("Could not look up %s\n", oh_name); |
| 232 | return -ENODEV; |
| 233 | } |
| 234 | |
| 235 | pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0); |
| 236 | WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name); |
| 237 | |
Nicholas Krause | e44be50 | 2015-05-20 15:32:26 -0400 | [diff] [blame] | 238 | return PTR_ERR_OR_ZERO(pdev); |
Tony Lindgren | a861280 | 2014-11-20 12:45:43 -0800 | [diff] [blame] | 239 | } |
| 240 | omap_postcore_initcall(omap_gpmc_init); |