blob: e945957c160400c92a814f34b0df3def5cd86fa0 [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
Thomas Meyer12616742013-06-01 11:44:44 +020066 return PTR_RET(pdev);
sricharan0abcf612011-02-08 14:10:45 +053067}
Tony Lindgrenb76c8b192013-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,
77 .end = OMAP3430_ISP_END,
78 .flags = IORESOURCE_MEM,
79 },
80 {
Tony Lindgren828c7072009-03-23 18:23:49 -070081 .start = OMAP3430_ISP_CCP2_BASE,
82 .end = OMAP3430_ISP_CCP2_END,
83 .flags = IORESOURCE_MEM,
84 },
85 {
86 .start = OMAP3430_ISP_CCDC_BASE,
87 .end = OMAP3430_ISP_CCDC_END,
88 .flags = IORESOURCE_MEM,
89 },
90 {
91 .start = OMAP3430_ISP_HIST_BASE,
92 .end = OMAP3430_ISP_HIST_END,
93 .flags = IORESOURCE_MEM,
94 },
95 {
96 .start = OMAP3430_ISP_H3A_BASE,
97 .end = OMAP3430_ISP_H3A_END,
98 .flags = IORESOURCE_MEM,
99 },
100 {
101 .start = OMAP3430_ISP_PREV_BASE,
102 .end = OMAP3430_ISP_PREV_END,
103 .flags = IORESOURCE_MEM,
104 },
105 {
106 .start = OMAP3430_ISP_RESZ_BASE,
107 .end = OMAP3430_ISP_RESZ_END,
108 .flags = IORESOURCE_MEM,
109 },
110 {
111 .start = OMAP3430_ISP_SBL_BASE,
112 .end = OMAP3430_ISP_SBL_END,
113 .flags = IORESOURCE_MEM,
114 },
115 {
Tuukka Toivonen6817a692010-02-02 11:17:33 -0300116 .start = OMAP3430_ISP_CSI2A_REGS1_BASE,
117 .end = OMAP3430_ISP_CSI2A_REGS1_END,
Tony Lindgren828c7072009-03-23 18:23:49 -0700118 .flags = IORESOURCE_MEM,
119 },
120 {
Tuukka Toivonen6817a692010-02-02 11:17:33 -0300121 .start = OMAP3430_ISP_CSIPHY2_BASE,
122 .end = OMAP3430_ISP_CSIPHY2_END,
123 .flags = IORESOURCE_MEM,
124 },
125 {
126 .start = OMAP3630_ISP_CSI2A_REGS2_BASE,
127 .end = OMAP3630_ISP_CSI2A_REGS2_END,
128 .flags = IORESOURCE_MEM,
129 },
130 {
131 .start = OMAP3630_ISP_CSI2C_REGS1_BASE,
132 .end = OMAP3630_ISP_CSI2C_REGS1_END,
133 .flags = IORESOURCE_MEM,
134 },
135 {
136 .start = OMAP3630_ISP_CSIPHY1_BASE,
137 .end = OMAP3630_ISP_CSIPHY1_END,
138 .flags = IORESOURCE_MEM,
139 },
140 {
141 .start = OMAP3630_ISP_CSI2C_REGS2_BASE,
142 .end = OMAP3630_ISP_CSI2C_REGS2_END,
Tony Lindgren828c7072009-03-23 18:23:49 -0700143 .flags = IORESOURCE_MEM,
144 },
145 {
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -0700146 .start = 24 + OMAP_INTC_START,
Tony Lindgren828c7072009-03-23 18:23:49 -0700147 .flags = IORESOURCE_IRQ,
148 }
149};
150
151static struct platform_device omap3isp_device = {
152 .name = "omap3isp",
153 .id = -1,
154 .num_resources = ARRAY_SIZE(omap3isp_resources),
155 .resource = omap3isp_resources,
156};
157
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300158static struct omap_iommu_arch_data omap3_isp_iommu = {
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600159 .name = "mmu_isp",
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300160};
161
Laurent Pincharta11f6702009-12-14 08:09:07 -0300162int omap3_init_camera(struct isp_platform_data *pdata)
Tony Lindgren828c7072009-03-23 18:23:49 -0700163{
Suman Anna0ac4f032014-03-05 18:24:12 -0600164 if (of_have_populated_dt())
165 omap3_isp_iommu.name = "480bd400.mmu";
166
Laurent Pincharta11f6702009-12-14 08:09:07 -0300167 omap3isp_device.dev.platform_data = pdata;
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300168 omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
169
Laurent Pincharta11f6702009-12-14 08:09:07 -0300170 return platform_device_register(&omap3isp_device);
Tony Lindgren828c7072009-03-23 18:23:49 -0700171}
Tony Lindgren828c7072009-03-23 18:23:49 -0700172
Ohad Ben-Cohen1a51a0c2012-01-11 15:28:11 +0200173#else /* !CONFIG_IOMMU_API */
174
175int omap3_init_camera(struct isp_platform_data *pdata)
176{
177 return 0;
178}
179
180#endif
181
Suman Annac869c752013-03-12 17:55:29 -0500182#if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
Kevin Hilman9cf793f2012-02-20 09:43:30 -0800183static inline void __init omap_init_mbox(void)
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800184{
Felipe Contreras69dbf852011-02-24 12:51:33 -0800185 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -0700186 struct platform_device *pdev;
Suman Annab8a7cf82013-01-28 17:21:58 -0600187 struct omap_mbox_pdata *pdata;
Felipe Contreras69dbf852011-02-24 12:51:33 -0800188
189 oh = omap_hwmod_lookup("mailbox");
190 if (!oh) {
191 pr_err("%s: unable to find hwmod\n", __func__);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700192 return;
193 }
Suman Annab8a7cf82013-01-28 17:21:58 -0600194 if (!oh->dev_attr) {
195 pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
196 return;
197 }
Felipe Contreras69dbf852011-02-24 12:51:33 -0800198
Suman Annab8a7cf82013-01-28 17:21:58 -0600199 pdata = (struct omap_mbox_pdata *)oh->dev_attr;
200 pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700201 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
202 __func__, PTR_ERR(pdev));
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800203}
204#else
205static inline void omap_init_mbox(void) { }
Suman Annac869c752013-03-12 17:55:29 -0500206#endif /* CONFIG_OMAP2PLUS_MBOX */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800207
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100208static inline void omap_init_sti(void) {}
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100209
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000210#if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
211
212static struct platform_device omap_pcm = {
213 .name = "omap-pcm-audio",
214 .id = -1,
215};
216
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000217static void omap_init_audio(void)
218{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000219 platform_device_register(&omap_pcm);
220}
221
222#else
223static inline void omap_init_audio(void) {}
224#endif
225
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300226#if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700227
Arnd Bergmann22037472012-08-24 15:21:06 +0200228#include <linux/platform_data/spi-omap2-mcspi.h>
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700229
Kevin Hilman9cf793f2012-02-20 09:43:30 -0800230static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700231{
Kevin Hilman3528c582011-07-21 13:48:45 -0700232 struct platform_device *pdev;
Charulatha V1a5d8192011-02-02 17:52:14 +0530233 char *name = "omap2_mcspi";
234 struct omap2_mcspi_platform_config *pdata;
235 static int spi_num;
236 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700237
Charulatha V1a5d8192011-02-02 17:52:14 +0530238 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
239 if (!pdata) {
240 pr_err("Memory allocation for McSPI device failed\n");
241 return -ENOMEM;
242 }
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700243
Charulatha V1a5d8192011-02-02 17:52:14 +0530244 pdata->num_cs = mcspi_attrib->num_chipselect;
245 switch (oh->class->rev) {
246 case OMAP2_MCSPI_REV:
247 case OMAP3_MCSPI_REV:
248 pdata->regs_offset = 0;
249 break;
250 case OMAP4_MCSPI_REV:
251 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
252 break;
253 default:
254 pr_err("Invalid McSPI Revision value\n");
Julia Lawalle0feca892011-12-23 18:39:31 +0100255 kfree(pdata);
Charulatha V1a5d8192011-02-02 17:52:14 +0530256 return -EINVAL;
257 }
258
259 spi_num++;
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700260 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700261 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
Charulatha V1a5d8192011-02-02 17:52:14 +0530262 name, oh->name);
263 kfree(pdata);
264 return 0;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700265}
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700266
267static void omap_init_mcspi(void)
268{
Charulatha V1a5d8192011-02-02 17:52:14 +0530269 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700270}
271
272#else
273static inline void omap_init_mcspi(void) {}
274#endif
275
Paul Walmsley4848d462012-09-23 17:28:27 -0600276/**
277 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
278 *
279 * Bind the RNG hwmod to the RNG omap_device. No return value.
280 */
281static void omap_init_rng(void)
282{
283 struct omap_hwmod *oh;
284 struct platform_device *pdev;
285
286 oh = omap_hwmod_lookup("rng");
287 if (!oh)
288 return;
289
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700290 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
Paul Walmsley4848d462012-09-23 17:28:27 -0600291 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
292}
Will Deacon88341332010-04-09 13:54:43 +0100293
Mark A. Greer26f88e62013-03-18 10:06:32 -0600294static void __init omap_init_sham(void)
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300295{
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600296 struct omap_hwmod *oh;
297 struct platform_device *pdev;
Mark A. Greere569e992013-03-30 15:49:19 -0600298
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600299 oh = omap_hwmod_lookup("sham");
300 if (!oh)
301 return;
Mark A. Greere569e992013-03-30 15:49:19 -0600302
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600303 pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
304 WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300305}
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300306
Mark A. Greer14ae5562012-12-21 09:28:10 -0700307static void __init omap_init_aes(void)
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800308{
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700309 struct omap_hwmod *oh;
310 struct platform_device *pdev;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700311
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700312 oh = omap_hwmod_lookup("aes");
313 if (!oh)
314 return;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700315
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700316 pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
317 WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800318}
319
Tony Lindgrend8874662008-12-10 17:37:16 -0800320/*-------------------------------------------------------------------------*/
321
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700322#if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
323 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
324#if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
325static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
326};
327#else
328static struct resource omap_vout_resource[2] = {
329};
330#endif
331
332static struct platform_device omap_vout_device = {
333 .name = "omap_vout",
334 .num_resources = ARRAY_SIZE(omap_vout_resource),
335 .resource = &omap_vout_resource[0],
336 .id = -1,
337};
Archit Taneja576e5bd2013-09-16 12:48:31 +0530338
339int __init omap_init_vout(void)
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700340{
Archit Taneja576e5bd2013-09-16 12:48:31 +0530341 return platform_device_register(&omap_vout_device);
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700342}
343#else
Archit Taneja576e5bd2013-09-16 12:48:31 +0530344int __init omap_init_vout(void) { return 0; }
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700345#endif
346
Tony Lindgren1dbae812005-11-10 14:26:51 +0000347/*-------------------------------------------------------------------------*/
348
349static int __init omap2_init_devices(void)
350{
Matt Porter484202f2012-09-17 16:26:11 -0700351 /* Enable dummy states for those platforms without pinctrl support */
352 if (!of_have_populated_dt())
353 pinctrl_provide_dummies();
354
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -0700355 /*
356 * please keep these calls, and their implementations above,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000357 * in alphabetical order so they're easier to sort through.
358 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000359 omap_init_audio();
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100360 /* If dtb is there, the devices will be created dynamically */
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300361 if (!of_have_populated_dt()) {
Suman Annadbd5f462014-07-11 16:44:40 -0500362 omap_init_mbox();
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100363 omap_init_mcspi();
Mark A. Greer114d7a82013-03-18 10:06:33 -0600364 omap_init_sham();
Mark A. Greer53335ac2012-12-21 09:28:12 -0700365 omap_init_aes();
Lokesh Vutla674ee082013-08-05 20:17:22 +0530366 omap_init_rng();
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300367 }
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100368 omap_init_sti();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000369
370 return 0;
371}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -0800372omap_arch_initcall(omap2_init_devices);
Tony Lindgrena8612802014-11-20 12:45:43 -0800373
374static int __init omap_gpmc_init(void)
375{
376 struct omap_hwmod *oh;
377 struct platform_device *pdev;
378 char *oh_name = "gpmc";
379
380 /*
381 * if the board boots up with a populated DT, do not
382 * manually add the device from this initcall
383 */
384 if (of_have_populated_dt())
385 return -ENODEV;
386
387 oh = omap_hwmod_lookup(oh_name);
388 if (!oh) {
389 pr_err("Could not look up %s\n", oh_name);
390 return -ENODEV;
391 }
392
393 pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
394 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
395
396 return PTR_RET(pdev);
397}
398omap_postcore_initcall(omap_gpmc_init);