blob: a69bd67e9028030372309ee6c80d2265493c4967 [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>
Suman Annab8a7cf82013-01-28 17:21:58 -060021#include <linux/platform_data/mailbox-omap.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000022
Tony Lindgren1dbae812005-11-10 14:26:51 +000023#include <asm/mach-types.h>
24#include <asm/mach/map.h>
25
Tony Lindgren45c3eb72012-11-30 08:41:50 -080026#include <linux/omap-dma.h>
Tony Lindgren2a296c82012-10-02 17:41:35 -070027
Tony Lindgrenee0839c2012-02-24 10:34:35 -080028#include "iomap.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -070029#include "omap_hwmod.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070030#include "omap_device.h"
Tony Lindgren1dbae812005-11-10 14:26:51 +000031
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070032#include "soc.h"
33#include "common.h"
Tony Lindgren4896e392009-12-11 16:16:32 -080034#include "mux.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060035#include "control.h"
Laurent Pincharta11f6702009-12-14 08:09:07 -030036#include "devices.h"
Archit Taneja576e5bd2013-09-16 12:48:31 +053037#include "display.h"
Tony Lindgren4896e392009-12-11 16:16:32 -080038
sricharan0abcf612011-02-08 14:10:45 +053039#define L3_MODULES_MAX_LEN 12
sricharana4dc6162011-03-09 16:00:29 +053040#define L3_MODULES 3
sricharan0abcf612011-02-08 14:10:45 +053041
42static int __init omap3_l3_init(void)
43{
sricharan0abcf612011-02-08 14:10:45 +053044 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -070045 struct platform_device *pdev;
sricharan0abcf612011-02-08 14:10:45 +053046 char oh_name[L3_MODULES_MAX_LEN];
47
48 /*
49 * To avoid code running on other OMAPs in
50 * multi-omap builds
51 */
Tony Lindgrenaa25729c2014-11-05 09:21:23 -080052 if (!(cpu_is_omap34xx()) || of_have_populated_dt())
sricharan0abcf612011-02-08 14:10:45 +053053 return -ENODEV;
54
Paul Walmsleyeeb37112012-04-13 06:34:32 -060055 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
sricharan0abcf612011-02-08 14:10:45 +053056
57 oh = omap_hwmod_lookup(oh_name);
58
59 if (!oh)
60 pr_err("could not look up %s\n", oh_name);
61
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -070062 pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
sricharan0abcf612011-02-08 14:10:45 +053063
Kevin Hilman3528c582011-07-21 13:48:45 -070064 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
sricharan0abcf612011-02-08 14:10:45 +053065
Nicholas Krausee44be502015-05-20 15:32:26 -040066 return PTR_ERR_OR_ZERO(pdev);
sricharan0abcf612011-02-08 14:10:45 +053067}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -080068omap_postcore_initcall(omap3_l3_init);
sricharan0abcf612011-02-08 14:10:45 +053069
Ohad Ben-Cohen1a51a0c2012-01-11 15:28:11 +020070#if defined(CONFIG_IOMMU_API)
71
Tony Lindgren2ab7c842012-11-02 12:24:14 -070072#include <linux/platform_data/iommu-omap.h>
Ohad Ben-Cohen1a51a0c2012-01-11 15:28:11 +020073
Tony Lindgren828c7072009-03-23 18:23:49 -070074static struct resource omap3isp_resources[] = {
75 {
76 .start = OMAP3430_ISP_BASE,
Sakari Ailus8644cdf2015-03-25 19:57:35 -030077 .end = OMAP3430_ISP_BASE + 0x12fc,
Tony Lindgren828c7072009-03-23 18:23:49 -070078 .flags = IORESOURCE_MEM,
79 },
80 {
Sakari Ailus8644cdf2015-03-25 19:57:35 -030081 .start = OMAP3430_ISP_BASE2,
82 .end = OMAP3430_ISP_BASE2 + 0x0600,
Tony Lindgren828c7072009-03-23 18:23:49 -070083 .flags = IORESOURCE_MEM,
84 },
85 {
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070086 .start = 24 + OMAP_INTC_START,
Tony Lindgren828c7072009-03-23 18:23:49 -070087 .flags = IORESOURCE_IRQ,
88 }
89};
90
91static struct platform_device omap3isp_device = {
92 .name = "omap3isp",
93 .id = -1,
94 .num_resources = ARRAY_SIZE(omap3isp_resources),
95 .resource = omap3isp_resources,
96};
97
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +030098static struct omap_iommu_arch_data omap3_isp_iommu = {
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -060099 .name = "mmu_isp",
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300100};
101
Laurent Pincharta11f6702009-12-14 08:09:07 -0300102int omap3_init_camera(struct isp_platform_data *pdata)
Tony Lindgren828c7072009-03-23 18:23:49 -0700103{
Suman Anna0ac4f032014-03-05 18:24:12 -0600104 if (of_have_populated_dt())
105 omap3_isp_iommu.name = "480bd400.mmu";
106
Laurent Pincharta11f6702009-12-14 08:09:07 -0300107 omap3isp_device.dev.platform_data = pdata;
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300108 omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
109
Laurent Pincharta11f6702009-12-14 08:09:07 -0300110 return platform_device_register(&omap3isp_device);
Tony Lindgren828c7072009-03-23 18:23:49 -0700111}
Tony Lindgren828c7072009-03-23 18:23:49 -0700112
Ohad Ben-Cohen1a51a0c2012-01-11 15:28:11 +0200113#else /* !CONFIG_IOMMU_API */
114
115int omap3_init_camera(struct isp_platform_data *pdata)
116{
117 return 0;
118}
119
120#endif
121
Suman Annac869c752013-03-12 17:55:29 -0500122#if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
Kevin Hilman9cf793f2012-02-20 09:43:30 -0800123static inline void __init omap_init_mbox(void)
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800124{
Felipe Contreras69dbf852011-02-24 12:51:33 -0800125 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -0700126 struct platform_device *pdev;
Suman Annab8a7cf82013-01-28 17:21:58 -0600127 struct omap_mbox_pdata *pdata;
Felipe Contreras69dbf852011-02-24 12:51:33 -0800128
129 oh = omap_hwmod_lookup("mailbox");
130 if (!oh) {
131 pr_err("%s: unable to find hwmod\n", __func__);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700132 return;
133 }
Suman Annab8a7cf82013-01-28 17:21:58 -0600134 if (!oh->dev_attr) {
135 pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
136 return;
137 }
Felipe Contreras69dbf852011-02-24 12:51:33 -0800138
Suman Annab8a7cf82013-01-28 17:21:58 -0600139 pdata = (struct omap_mbox_pdata *)oh->dev_attr;
140 pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700141 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
142 __func__, PTR_ERR(pdev));
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800143}
144#else
145static inline void omap_init_mbox(void) { }
Suman Annac869c752013-03-12 17:55:29 -0500146#endif /* CONFIG_OMAP2PLUS_MBOX */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800147
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100148static inline void omap_init_sti(void) {}
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100149
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000150#if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
151
152static struct platform_device omap_pcm = {
153 .name = "omap-pcm-audio",
154 .id = -1,
155};
156
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000157static void omap_init_audio(void)
158{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000159 platform_device_register(&omap_pcm);
160}
161
162#else
163static inline void omap_init_audio(void) {}
164#endif
165
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300166#if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700167
Arnd Bergmann22037472012-08-24 15:21:06 +0200168#include <linux/platform_data/spi-omap2-mcspi.h>
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700169
Kevin Hilman9cf793f2012-02-20 09:43:30 -0800170static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700171{
Kevin Hilman3528c582011-07-21 13:48:45 -0700172 struct platform_device *pdev;
Charulatha V1a5d8192011-02-02 17:52:14 +0530173 char *name = "omap2_mcspi";
174 struct omap2_mcspi_platform_config *pdata;
175 static int spi_num;
176 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700177
Charulatha V1a5d8192011-02-02 17:52:14 +0530178 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
179 if (!pdata) {
180 pr_err("Memory allocation for McSPI device failed\n");
181 return -ENOMEM;
182 }
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700183
Charulatha V1a5d8192011-02-02 17:52:14 +0530184 pdata->num_cs = mcspi_attrib->num_chipselect;
185 switch (oh->class->rev) {
186 case OMAP2_MCSPI_REV:
187 case OMAP3_MCSPI_REV:
188 pdata->regs_offset = 0;
189 break;
190 case OMAP4_MCSPI_REV:
191 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
192 break;
193 default:
194 pr_err("Invalid McSPI Revision value\n");
Julia Lawalle0feca892011-12-23 18:39:31 +0100195 kfree(pdata);
Charulatha V1a5d8192011-02-02 17:52:14 +0530196 return -EINVAL;
197 }
198
199 spi_num++;
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700200 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700201 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
Charulatha V1a5d8192011-02-02 17:52:14 +0530202 name, oh->name);
203 kfree(pdata);
204 return 0;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700205}
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700206
207static void omap_init_mcspi(void)
208{
Charulatha V1a5d8192011-02-02 17:52:14 +0530209 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700210}
211
212#else
213static inline void omap_init_mcspi(void) {}
214#endif
215
Paul Walmsley4848d462012-09-23 17:28:27 -0600216/**
217 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
218 *
219 * Bind the RNG hwmod to the RNG omap_device. No return value.
220 */
221static void omap_init_rng(void)
222{
223 struct omap_hwmod *oh;
224 struct platform_device *pdev;
225
226 oh = omap_hwmod_lookup("rng");
227 if (!oh)
228 return;
229
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700230 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
Paul Walmsley4848d462012-09-23 17:28:27 -0600231 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
232}
Will Deacon88341332010-04-09 13:54:43 +0100233
Mark A. Greer26f88e62013-03-18 10:06:32 -0600234static void __init omap_init_sham(void)
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300235{
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600236 struct omap_hwmod *oh;
237 struct platform_device *pdev;
Mark A. Greere569e992013-03-30 15:49:19 -0600238
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600239 oh = omap_hwmod_lookup("sham");
240 if (!oh)
241 return;
Mark A. Greere569e992013-03-30 15:49:19 -0600242
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600243 pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
244 WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300245}
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300246
Mark A. Greer14ae5562012-12-21 09:28:10 -0700247static void __init omap_init_aes(void)
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800248{
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700249 struct omap_hwmod *oh;
250 struct platform_device *pdev;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700251
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700252 oh = omap_hwmod_lookup("aes");
253 if (!oh)
254 return;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700255
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700256 pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
257 WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800258}
259
Tony Lindgrend8874662008-12-10 17:37:16 -0800260/*-------------------------------------------------------------------------*/
261
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700262#if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
263 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
264#if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
265static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
266};
267#else
268static struct resource omap_vout_resource[2] = {
269};
270#endif
271
272static struct platform_device omap_vout_device = {
273 .name = "omap_vout",
274 .num_resources = ARRAY_SIZE(omap_vout_resource),
275 .resource = &omap_vout_resource[0],
276 .id = -1,
277};
Archit Taneja576e5bd2013-09-16 12:48:31 +0530278
279int __init omap_init_vout(void)
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700280{
Archit Taneja576e5bd2013-09-16 12:48:31 +0530281 return platform_device_register(&omap_vout_device);
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700282}
283#else
Archit Taneja576e5bd2013-09-16 12:48:31 +0530284int __init omap_init_vout(void) { return 0; }
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700285#endif
286
Tony Lindgren1dbae812005-11-10 14:26:51 +0000287/*-------------------------------------------------------------------------*/
288
289static int __init omap2_init_devices(void)
290{
Matt Porter484202f2012-09-17 16:26:11 -0700291 /* Enable dummy states for those platforms without pinctrl support */
292 if (!of_have_populated_dt())
293 pinctrl_provide_dummies();
294
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -0700295 /*
296 * please keep these calls, and their implementations above,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000297 * in alphabetical order so they're easier to sort through.
298 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000299 omap_init_audio();
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100300 /* If dtb is there, the devices will be created dynamically */
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300301 if (!of_have_populated_dt()) {
Suman Annadbd5f462014-07-11 16:44:40 -0500302 omap_init_mbox();
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100303 omap_init_mcspi();
Mark A. Greer114d7a82013-03-18 10:06:33 -0600304 omap_init_sham();
Mark A. Greer53335ac2012-12-21 09:28:12 -0700305 omap_init_aes();
Lokesh Vutla674ee082013-08-05 20:17:22 +0530306 omap_init_rng();
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300307 }
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100308 omap_init_sti();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000309
310 return 0;
311}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -0800312omap_arch_initcall(omap2_init_devices);
Tony Lindgrena8612802014-11-20 12:45:43 -0800313
314static int __init omap_gpmc_init(void)
315{
316 struct omap_hwmod *oh;
317 struct platform_device *pdev;
318 char *oh_name = "gpmc";
319
320 /*
321 * if the board boots up with a populated DT, do not
322 * manually add the device from this initcall
323 */
324 if (of_have_populated_dt())
325 return -ENODEV;
326
327 oh = omap_hwmod_lookup(oh_name);
328 if (!oh) {
329 pr_err("Could not look up %s\n", oh_name);
330 return -ENODEV;
331 }
332
333 pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
334 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
335
Nicholas Krausee44be502015-05-20 15:32:26 -0400336 return PTR_ERR_OR_ZERO(pdev);
Tony Lindgrena8612802014-11-20 12:45:43 -0800337}
338omap_postcore_initcall(omap_gpmc_init);