blob: 3fdb945991848c5f969e8061448f0ace56399465 [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"
Paul Walmsley4814ced2010-10-08 11:40:20 -060033#include "control.h"
Archit Taneja576e5bd2013-09-16 12:48:31 +053034#include "display.h"
Tony Lindgren4896e392009-12-11 16:16:32 -080035
sricharan0abcf612011-02-08 14:10:45 +053036#define L3_MODULES_MAX_LEN 12
sricharana4dc6162011-03-09 16:00:29 +053037#define L3_MODULES 3
sricharan0abcf612011-02-08 14:10:45 +053038
39static int __init omap3_l3_init(void)
40{
sricharan0abcf612011-02-08 14:10:45 +053041 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -070042 struct platform_device *pdev;
sricharan0abcf612011-02-08 14:10:45 +053043 char oh_name[L3_MODULES_MAX_LEN];
44
45 /*
46 * To avoid code running on other OMAPs in
47 * multi-omap builds
48 */
Tony Lindgrenaa25729c2014-11-05 09:21:23 -080049 if (!(cpu_is_omap34xx()) || of_have_populated_dt())
sricharan0abcf612011-02-08 14:10:45 +053050 return -ENODEV;
51
Paul Walmsleyeeb37112012-04-13 06:34:32 -060052 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
sricharan0abcf612011-02-08 14:10:45 +053053
54 oh = omap_hwmod_lookup(oh_name);
55
56 if (!oh)
57 pr_err("could not look up %s\n", oh_name);
58
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -070059 pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
sricharan0abcf612011-02-08 14:10:45 +053060
Kevin Hilman3528c582011-07-21 13:48:45 -070061 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
sricharan0abcf612011-02-08 14:10:45 +053062
Nicholas Krausee44be502015-05-20 15:32:26 -040063 return PTR_ERR_OR_ZERO(pdev);
sricharan0abcf612011-02-08 14:10:45 +053064}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -080065omap_postcore_initcall(omap3_l3_init);
sricharan0abcf612011-02-08 14:10:45 +053066
Tony Lindgren9b6553c2006-04-02 17:46:30 +010067static inline void omap_init_sti(void) {}
Tony Lindgren9b6553c2006-04-02 17:46:30 +010068
Javier Martinez Canillas502ad2a2016-08-11 15:29:45 -040069#if IS_ENABLED(CONFIG_SPI_OMAP24XX)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -070070
Arnd Bergmann22037472012-08-24 15:21:06 +020071#include <linux/platform_data/spi-omap2-mcspi.h>
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -070072
Kevin Hilman9cf793f2012-02-20 09:43:30 -080073static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -070074{
Kevin Hilman3528c582011-07-21 13:48:45 -070075 struct platform_device *pdev;
Charulatha V1a5d8192011-02-02 17:52:14 +053076 char *name = "omap2_mcspi";
77 struct omap2_mcspi_platform_config *pdata;
78 static int spi_num;
79 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
Tony Lindgrenaf41a122009-09-24 16:23:05 -070080
Charulatha V1a5d8192011-02-02 17:52:14 +053081 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
82 if (!pdata) {
83 pr_err("Memory allocation for McSPI device failed\n");
84 return -ENOMEM;
85 }
Tony Lindgrenaf41a122009-09-24 16:23:05 -070086
Charulatha V1a5d8192011-02-02 17:52:14 +053087 pdata->num_cs = mcspi_attrib->num_chipselect;
88 switch (oh->class->rev) {
89 case OMAP2_MCSPI_REV:
90 case OMAP3_MCSPI_REV:
91 pdata->regs_offset = 0;
92 break;
93 case OMAP4_MCSPI_REV:
94 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
95 break;
96 default:
97 pr_err("Invalid McSPI Revision value\n");
Julia Lawalle0feca892011-12-23 18:39:31 +010098 kfree(pdata);
Charulatha V1a5d8192011-02-02 17:52:14 +053099 return -EINVAL;
100 }
101
102 spi_num++;
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700103 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700104 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
Charulatha V1a5d8192011-02-02 17:52:14 +0530105 name, oh->name);
106 kfree(pdata);
107 return 0;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700108}
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700109
110static void omap_init_mcspi(void)
111{
Charulatha V1a5d8192011-02-02 17:52:14 +0530112 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700113}
114
115#else
116static inline void omap_init_mcspi(void) {}
117#endif
118
Paul Walmsley4848d462012-09-23 17:28:27 -0600119/**
120 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
121 *
122 * Bind the RNG hwmod to the RNG omap_device. No return value.
123 */
124static void omap_init_rng(void)
125{
126 struct omap_hwmod *oh;
127 struct platform_device *pdev;
128
129 oh = omap_hwmod_lookup("rng");
130 if (!oh)
131 return;
132
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700133 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
Paul Walmsley4848d462012-09-23 17:28:27 -0600134 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
135}
Will Deacon88341332010-04-09 13:54:43 +0100136
Mark A. Greer26f88e62013-03-18 10:06:32 -0600137static void __init omap_init_sham(void)
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300138{
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600139 struct omap_hwmod *oh;
140 struct platform_device *pdev;
Mark A. Greere569e992013-03-30 15:49:19 -0600141
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600142 oh = omap_hwmod_lookup("sham");
143 if (!oh)
144 return;
Mark A. Greere569e992013-03-30 15:49:19 -0600145
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600146 pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
147 WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300148}
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300149
Mark A. Greer14ae5562012-12-21 09:28:10 -0700150static void __init omap_init_aes(void)
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800151{
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700152 struct omap_hwmod *oh;
153 struct platform_device *pdev;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700154
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700155 oh = omap_hwmod_lookup("aes");
156 if (!oh)
157 return;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700158
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700159 pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
160 WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800161}
162
Tony Lindgrend8874662008-12-10 17:37:16 -0800163/*-------------------------------------------------------------------------*/
164
Javier Martinez Canillas502ad2a2016-08-11 15:29:45 -0400165#if IS_ENABLED(CONFIG_VIDEO_OMAP2_VOUT)
166#if IS_ENABLED(CONFIG_FB_OMAP2)
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700167static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
168};
169#else
170static struct resource omap_vout_resource[2] = {
171};
172#endif
173
174static struct platform_device omap_vout_device = {
175 .name = "omap_vout",
176 .num_resources = ARRAY_SIZE(omap_vout_resource),
177 .resource = &omap_vout_resource[0],
178 .id = -1,
179};
Archit Taneja576e5bd2013-09-16 12:48:31 +0530180
181int __init omap_init_vout(void)
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700182{
Archit Taneja576e5bd2013-09-16 12:48:31 +0530183 return platform_device_register(&omap_vout_device);
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700184}
185#else
Archit Taneja576e5bd2013-09-16 12:48:31 +0530186int __init omap_init_vout(void) { return 0; }
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700187#endif
188
Tony Lindgren1dbae812005-11-10 14:26:51 +0000189/*-------------------------------------------------------------------------*/
190
191static int __init omap2_init_devices(void)
192{
Matt Porter484202f2012-09-17 16:26:11 -0700193 /* Enable dummy states for those platforms without pinctrl support */
194 if (!of_have_populated_dt())
195 pinctrl_provide_dummies();
196
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100197 /* If dtb is there, the devices will be created dynamically */
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300198 if (!of_have_populated_dt()) {
Peter Ujfalusif2e6a0a2015-12-11 14:50:20 +0200199 /*
200 * please keep these calls, and their implementations above,
201 * in alphabetical order so they're easier to sort through.
202 */
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100203 omap_init_mcspi();
Mark A. Greer114d7a82013-03-18 10:06:33 -0600204 omap_init_sham();
Mark A. Greer53335ac2012-12-21 09:28:12 -0700205 omap_init_aes();
Lokesh Vutla674ee082013-08-05 20:17:22 +0530206 omap_init_rng();
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300207 }
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100208 omap_init_sti();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000209
210 return 0;
211}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -0800212omap_arch_initcall(omap2_init_devices);
Tony Lindgrena8612802014-11-20 12:45:43 -0800213
214static int __init omap_gpmc_init(void)
215{
216 struct omap_hwmod *oh;
217 struct platform_device *pdev;
218 char *oh_name = "gpmc";
219
220 /*
221 * if the board boots up with a populated DT, do not
222 * manually add the device from this initcall
223 */
224 if (of_have_populated_dt())
225 return -ENODEV;
226
227 oh = omap_hwmod_lookup(oh_name);
228 if (!oh) {
229 pr_err("Could not look up %s\n", oh_name);
230 return -ENODEV;
231 }
232
233 pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
234 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
235
Nicholas Krausee44be502015-05-20 15:32:26 -0400236 return PTR_ERR_OR_ZERO(pdev);
Tony Lindgrena8612802014-11-20 12:45:43 -0800237}
238omap_postcore_initcall(omap_gpmc_init);