blob: d7f1d69daf6d4d083005e15d11d556c412aacfbc [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
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 King2f8163b2011-07-26 10:53:52 +010011#include <linux/gpio.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000012#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010015#include <linux/io.h>
Kevin Hilman917fa282008-12-10 17:37:17 -080016#include <linux/clk.h>
Varadarajan, Charulathaf2ce6232010-09-23 20:02:42 +053017#include <linux/err.h>
Charulatha V1a5d8192011-02-02 17:52:14 +053018#include <linux/slab.h>
Benoit Coussonad8dfac2011-08-12 13:48:47 +020019#include <linux/of.h>
Matt Porter484202f2012-09-17 16:26:11 -070020#include <linux/pinctrl/machine.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000021
Tony Lindgren1dbae812005-11-10 14:26:51 +000022#include <asm/mach-types.h>
23#include <asm/mach/map.h>
24
Tony Lindgren45c3eb72012-11-30 08:41:50 -080025#include <linux/omap-dma.h>
Tony Lindgren2a296c82012-10-02 17:41:35 -070026
Tony Lindgrenee0839c2012-02-24 10:34:35 -080027#include "iomap.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -070028#include "omap_hwmod.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070029#include "omap_device.h"
Tony Lindgren1dbae812005-11-10 14:26:51 +000030
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070031#include "soc.h"
32#include "common.h"
Tony Lindgren4896e392009-12-11 16:16:32 -080033#include "mux.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060034#include "control.h"
Archit Taneja576e5bd2013-09-16 12:48:31 +053035#include "display.h"
Tony Lindgren4896e392009-12-11 16:16:32 -080036
sricharan0abcf612011-02-08 14:10:45 +053037#define L3_MODULES_MAX_LEN 12
sricharana4dc6162011-03-09 16:00:29 +053038#define L3_MODULES 3
sricharan0abcf612011-02-08 14:10:45 +053039
40static int __init omap3_l3_init(void)
41{
sricharan0abcf612011-02-08 14:10:45 +053042 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -070043 struct platform_device *pdev;
sricharan0abcf612011-02-08 14:10:45 +053044 char oh_name[L3_MODULES_MAX_LEN];
45
46 /*
47 * To avoid code running on other OMAPs in
48 * multi-omap builds
49 */
Tony Lindgrenaa25729c2014-11-05 09:21:23 -080050 if (!(cpu_is_omap34xx()) || of_have_populated_dt())
sricharan0abcf612011-02-08 14:10:45 +053051 return -ENODEV;
52
Paul Walmsleyeeb37112012-04-13 06:34:32 -060053 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
sricharan0abcf612011-02-08 14:10:45 +053054
55 oh = omap_hwmod_lookup(oh_name);
56
57 if (!oh)
58 pr_err("could not look up %s\n", oh_name);
59
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -070060 pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
sricharan0abcf612011-02-08 14:10:45 +053061
Kevin Hilman3528c582011-07-21 13:48:45 -070062 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
sricharan0abcf612011-02-08 14:10:45 +053063
Nicholas Krausee44be502015-05-20 15:32:26 -040064 return PTR_ERR_OR_ZERO(pdev);
sricharan0abcf612011-02-08 14:10:45 +053065}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -080066omap_postcore_initcall(omap3_l3_init);
sricharan0abcf612011-02-08 14:10:45 +053067
Tony Lindgren9b6553c2006-04-02 17:46:30 +010068static inline void omap_init_sti(void) {}
Tony Lindgren9b6553c2006-04-02 17:46:30 +010069
Tony Lindgren646e3ed2008-10-06 15:49:36 +030070#if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -070071
Arnd Bergmann22037472012-08-24 15:21:06 +020072#include <linux/platform_data/spi-omap2-mcspi.h>
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -070073
Kevin Hilman9cf793f2012-02-20 09:43:30 -080074static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -070075{
Kevin Hilman3528c582011-07-21 13:48:45 -070076 struct platform_device *pdev;
Charulatha V1a5d8192011-02-02 17:52:14 +053077 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 Lindgrenaf41a122009-09-24 16:23:05 -070081
Charulatha V1a5d8192011-02-02 17:52:14 +053082 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
83 if (!pdata) {
84 pr_err("Memory allocation for McSPI device failed\n");
85 return -ENOMEM;
86 }
Tony Lindgrenaf41a122009-09-24 16:23:05 -070087
Charulatha V1a5d8192011-02-02 17:52:14 +053088 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 Lawalle0feca892011-12-23 18:39:31 +010099 kfree(pdata);
Charulatha V1a5d8192011-02-02 17:52:14 +0530100 return -EINVAL;
101 }
102
103 spi_num++;
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700104 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700105 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
Charulatha V1a5d8192011-02-02 17:52:14 +0530106 name, oh->name);
107 kfree(pdata);
108 return 0;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700109}
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700110
111static void omap_init_mcspi(void)
112{
Charulatha V1a5d8192011-02-02 17:52:14 +0530113 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700114}
115
116#else
117static inline void omap_init_mcspi(void) {}
118#endif
119
Paul Walmsley4848d462012-09-23 17:28:27 -0600120/**
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 */
125static 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 Walmsleyc1d1cd52013-01-26 00:48:53 -0700134 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
Paul Walmsley4848d462012-09-23 17:28:27 -0600135 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
136}
Will Deacon88341332010-04-09 13:54:43 +0100137
Mark A. Greer26f88e62013-03-18 10:06:32 -0600138static void __init omap_init_sham(void)
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300139{
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600140 struct omap_hwmod *oh;
141 struct platform_device *pdev;
Mark A. Greere569e992013-03-30 15:49:19 -0600142
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600143 oh = omap_hwmod_lookup("sham");
144 if (!oh)
145 return;
Mark A. Greere569e992013-03-30 15:49:19 -0600146
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600147 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 Lindgren646e3ed2008-10-06 15:49:36 +0300149}
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300150
Mark A. Greer14ae5562012-12-21 09:28:10 -0700151static void __init omap_init_aes(void)
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800152{
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700153 struct omap_hwmod *oh;
154 struct platform_device *pdev;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700155
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700156 oh = omap_hwmod_lookup("aes");
157 if (!oh)
158 return;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700159
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700160 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 Kasatkinb744c672010-09-03 19:13:55 +0800162}
163
Tony Lindgrend8874662008-12-10 17:37:16 -0800164/*-------------------------------------------------------------------------*/
165
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700166#if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
167 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
168#if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
169static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
170};
171#else
172static struct resource omap_vout_resource[2] = {
173};
174#endif
175
176static 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 Taneja576e5bd2013-09-16 12:48:31 +0530182
183int __init omap_init_vout(void)
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700184{
Archit Taneja576e5bd2013-09-16 12:48:31 +0530185 return platform_device_register(&omap_vout_device);
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700186}
187#else
Archit Taneja576e5bd2013-09-16 12:48:31 +0530188int __init omap_init_vout(void) { return 0; }
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700189#endif
190
Tony Lindgren1dbae812005-11-10 14:26:51 +0000191/*-------------------------------------------------------------------------*/
192
193static int __init omap2_init_devices(void)
194{
Matt Porter484202f2012-09-17 16:26:11 -0700195 /* Enable dummy states for those platforms without pinctrl support */
196 if (!of_have_populated_dt())
197 pinctrl_provide_dummies();
198
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100199 /* If dtb is there, the devices will be created dynamically */
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300200 if (!of_have_populated_dt()) {
Peter Ujfalusif2e6a0a2015-12-11 14:50:20 +0200201 /*
202 * please keep these calls, and their implementations above,
203 * in alphabetical order so they're easier to sort through.
204 */
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100205 omap_init_mcspi();
Mark A. Greer114d7a82013-03-18 10:06:33 -0600206 omap_init_sham();
Mark A. Greer53335ac2012-12-21 09:28:12 -0700207 omap_init_aes();
Lokesh Vutla674ee082013-08-05 20:17:22 +0530208 omap_init_rng();
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300209 }
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100210 omap_init_sti();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000211
212 return 0;
213}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -0800214omap_arch_initcall(omap2_init_devices);
Tony Lindgrena8612802014-11-20 12:45:43 -0800215
216static 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 Krausee44be502015-05-20 15:32:26 -0400238 return PTR_ERR_OR_ZERO(pdev);
Tony Lindgrena8612802014-11-20 12:45:43 -0800239}
240omap_postcore_initcall(omap_gpmc_init);