blob: 1afb50d6d63672887805d4ae3d29962593b14ddb [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 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,
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 {
Sakari Ailusc19d19e2012-10-14 07:31:48 -0300146 .start = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE,
147 .end = OMAP343X_CTRL_BASE + OMAP343X_CONTROL_CSIRXFE + 3,
148 .flags = IORESOURCE_MEM,
149 },
150 {
151 .start = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL,
152 .end = OMAP343X_CTRL_BASE + OMAP3630_CONTROL_CAMERA_PHY_CTRL + 3,
153 .flags = IORESOURCE_MEM,
154 },
155 {
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -0700156 .start = 24 + OMAP_INTC_START,
Tony Lindgren828c7072009-03-23 18:23:49 -0700157 .flags = IORESOURCE_IRQ,
158 }
159};
160
161static struct platform_device omap3isp_device = {
162 .name = "omap3isp",
163 .id = -1,
164 .num_resources = ARRAY_SIZE(omap3isp_resources),
165 .resource = omap3isp_resources,
166};
167
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300168static struct omap_iommu_arch_data omap3_isp_iommu = {
Omar Ramirez Luna72b15b62012-11-19 19:05:50 -0600169 .name = "mmu_isp",
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300170};
171
Laurent Pincharta11f6702009-12-14 08:09:07 -0300172int omap3_init_camera(struct isp_platform_data *pdata)
Tony Lindgren828c7072009-03-23 18:23:49 -0700173{
Suman Anna0ac4f032014-03-05 18:24:12 -0600174 if (of_have_populated_dt())
175 omap3_isp_iommu.name = "480bd400.mmu";
176
Laurent Pincharta11f6702009-12-14 08:09:07 -0300177 omap3isp_device.dev.platform_data = pdata;
Ohad Ben-Cohenc8eaab32011-09-23 16:44:57 +0300178 omap3isp_device.dev.archdata.iommu = &omap3_isp_iommu;
179
Laurent Pincharta11f6702009-12-14 08:09:07 -0300180 return platform_device_register(&omap3isp_device);
Tony Lindgren828c7072009-03-23 18:23:49 -0700181}
Tony Lindgren828c7072009-03-23 18:23:49 -0700182
Ohad Ben-Cohen1a51a0c2012-01-11 15:28:11 +0200183#else /* !CONFIG_IOMMU_API */
184
185int omap3_init_camera(struct isp_platform_data *pdata)
186{
187 return 0;
188}
189
190#endif
191
Suman Annac869c752013-03-12 17:55:29 -0500192#if defined(CONFIG_OMAP2PLUS_MBOX) || defined(CONFIG_OMAP2PLUS_MBOX_MODULE)
Kevin Hilman9cf793f2012-02-20 09:43:30 -0800193static inline void __init omap_init_mbox(void)
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800194{
Felipe Contreras69dbf852011-02-24 12:51:33 -0800195 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -0700196 struct platform_device *pdev;
Suman Annab8a7cf82013-01-28 17:21:58 -0600197 struct omap_mbox_pdata *pdata;
Felipe Contreras69dbf852011-02-24 12:51:33 -0800198
199 oh = omap_hwmod_lookup("mailbox");
200 if (!oh) {
201 pr_err("%s: unable to find hwmod\n", __func__);
Hiroshi DOYU6c20a682009-03-23 18:07:23 -0700202 return;
203 }
Suman Annab8a7cf82013-01-28 17:21:58 -0600204 if (!oh->dev_attr) {
205 pr_err("%s: hwmod doesn't have valid attrs\n", __func__);
206 return;
207 }
Felipe Contreras69dbf852011-02-24 12:51:33 -0800208
Suman Annab8a7cf82013-01-28 17:21:58 -0600209 pdata = (struct omap_mbox_pdata *)oh->dev_attr;
210 pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700211 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n",
212 __func__, PTR_ERR(pdev));
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800213}
214#else
215static inline void omap_init_mbox(void) { }
Suman Annac869c752013-03-12 17:55:29 -0500216#endif /* CONFIG_OMAP2PLUS_MBOX */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800217
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100218static inline void omap_init_sti(void) {}
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100219
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000220#if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
221
222static struct platform_device omap_pcm = {
223 .name = "omap-pcm-audio",
224 .id = -1,
225};
226
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000227static void omap_init_audio(void)
228{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000229 platform_device_register(&omap_pcm);
230}
231
232#else
233static inline void omap_init_audio(void) {}
234#endif
235
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300236#if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700237
Arnd Bergmann22037472012-08-24 15:21:06 +0200238#include <linux/platform_data/spi-omap2-mcspi.h>
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700239
Kevin Hilman9cf793f2012-02-20 09:43:30 -0800240static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700241{
Kevin Hilman3528c582011-07-21 13:48:45 -0700242 struct platform_device *pdev;
Charulatha V1a5d8192011-02-02 17:52:14 +0530243 char *name = "omap2_mcspi";
244 struct omap2_mcspi_platform_config *pdata;
245 static int spi_num;
246 struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700247
Charulatha V1a5d8192011-02-02 17:52:14 +0530248 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
249 if (!pdata) {
250 pr_err("Memory allocation for McSPI device failed\n");
251 return -ENOMEM;
252 }
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700253
Charulatha V1a5d8192011-02-02 17:52:14 +0530254 pdata->num_cs = mcspi_attrib->num_chipselect;
255 switch (oh->class->rev) {
256 case OMAP2_MCSPI_REV:
257 case OMAP3_MCSPI_REV:
258 pdata->regs_offset = 0;
259 break;
260 case OMAP4_MCSPI_REV:
261 pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
262 break;
263 default:
264 pr_err("Invalid McSPI Revision value\n");
Julia Lawalle0feca892011-12-23 18:39:31 +0100265 kfree(pdata);
Charulatha V1a5d8192011-02-02 17:52:14 +0530266 return -EINVAL;
267 }
268
269 spi_num++;
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700270 pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
Kevin Hilman3528c582011-07-21 13:48:45 -0700271 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
Charulatha V1a5d8192011-02-02 17:52:14 +0530272 name, oh->name);
273 kfree(pdata);
274 return 0;
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700275}
Tony Lindgrenaf41a122009-09-24 16:23:05 -0700276
277static void omap_init_mcspi(void)
278{
Charulatha V1a5d8192011-02-02 17:52:14 +0530279 omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
Juha Yrjolaed7eb9d2006-06-26 16:16:10 -0700280}
281
282#else
283static inline void omap_init_mcspi(void) {}
284#endif
285
Paul Walmsley4848d462012-09-23 17:28:27 -0600286/**
287 * omap_init_rng - bind the RNG hwmod to the RNG omap_device
288 *
289 * Bind the RNG hwmod to the RNG omap_device. No return value.
290 */
291static void omap_init_rng(void)
292{
293 struct omap_hwmod *oh;
294 struct platform_device *pdev;
295
296 oh = omap_hwmod_lookup("rng");
297 if (!oh)
298 return;
299
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700300 pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
Paul Walmsley4848d462012-09-23 17:28:27 -0600301 WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
302}
Will Deacon88341332010-04-09 13:54:43 +0100303
Mark A. Greer26f88e62013-03-18 10:06:32 -0600304static void __init omap_init_sham(void)
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300305{
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600306 struct omap_hwmod *oh;
307 struct platform_device *pdev;
Mark A. Greere569e992013-03-30 15:49:19 -0600308
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600309 oh = omap_hwmod_lookup("sham");
310 if (!oh)
311 return;
Mark A. Greere569e992013-03-30 15:49:19 -0600312
Mark A. Greer8c7bb572013-03-18 10:06:33 -0600313 pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
314 WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300315}
Tony Lindgren646e3ed2008-10-06 15:49:36 +0300316
Mark A. Greer14ae5562012-12-21 09:28:10 -0700317static void __init omap_init_aes(void)
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800318{
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700319 struct omap_hwmod *oh;
320 struct platform_device *pdev;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700321
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700322 oh = omap_hwmod_lookup("aes");
323 if (!oh)
324 return;
Mark A. Greer660ffd62012-12-21 09:28:09 -0700325
Mark A. Greer77e2fd82012-12-21 09:28:11 -0700326 pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
327 WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
Dmitry Kasatkinb744c672010-09-03 19:13:55 +0800328}
329
Tony Lindgrend8874662008-12-10 17:37:16 -0800330/*-------------------------------------------------------------------------*/
331
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700332#if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
333 defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
334#if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
335static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
336};
337#else
338static struct resource omap_vout_resource[2] = {
339};
340#endif
341
342static struct platform_device omap_vout_device = {
343 .name = "omap_vout",
344 .num_resources = ARRAY_SIZE(omap_vout_resource),
345 .resource = &omap_vout_resource[0],
346 .id = -1,
347};
Archit Taneja576e5bd2013-09-16 12:48:31 +0530348
349int __init omap_init_vout(void)
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700350{
Archit Taneja576e5bd2013-09-16 12:48:31 +0530351 return platform_device_register(&omap_vout_device);
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700352}
353#else
Archit Taneja576e5bd2013-09-16 12:48:31 +0530354int __init omap_init_vout(void) { return 0; }
Vaibhav Hiremathb2273582010-05-10 14:29:14 -0700355#endif
356
Tony Lindgren1dbae812005-11-10 14:26:51 +0000357/*-------------------------------------------------------------------------*/
358
359static int __init omap2_init_devices(void)
360{
Matt Porter484202f2012-09-17 16:26:11 -0700361 /* Enable dummy states for those platforms without pinctrl support */
362 if (!of_have_populated_dt())
363 pinctrl_provide_dummies();
364
Paul Walmsley81fbc5ef2010-12-21 19:56:17 -0700365 /*
366 * please keep these calls, and their implementations above,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000367 * in alphabetical order so they're easier to sort through.
368 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000369 omap_init_audio();
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100370 /* If dtb is there, the devices will be created dynamically */
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300371 if (!of_have_populated_dt()) {
Suman Annadbd5f462014-07-11 16:44:40 -0500372 omap_init_mbox();
Benoit Coussonefcf1e52012-01-20 14:15:58 +0100373 omap_init_mcspi();
Mark A. Greer114d7a82013-03-18 10:06:33 -0600374 omap_init_sham();
Mark A. Greer53335ac2012-12-21 09:28:12 -0700375 omap_init_aes();
Lokesh Vutla674ee082013-08-05 20:17:22 +0530376 omap_init_rng();
Peter Ujfalusi259bd6c2012-05-02 15:23:18 +0300377 }
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100378 omap_init_sti();
Tony Lindgren1dbae812005-11-10 14:26:51 +0000379
380 return 0;
381}
Tony Lindgrenb76c8b12013-01-11 11:24:18 -0800382omap_arch_initcall(omap2_init_devices);
Tony Lindgrena8612802014-11-20 12:45:43 -0800383
384static int __init omap_gpmc_init(void)
385{
386 struct omap_hwmod *oh;
387 struct platform_device *pdev;
388 char *oh_name = "gpmc";
389
390 /*
391 * if the board boots up with a populated DT, do not
392 * manually add the device from this initcall
393 */
394 if (of_have_populated_dt())
395 return -ENODEV;
396
397 oh = omap_hwmod_lookup(oh_name);
398 if (!oh) {
399 pr_err("Could not look up %s\n", oh_name);
400 return -ENODEV;
401 }
402
403 pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
404 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
405
406 return PTR_RET(pdev);
407}
408omap_postcore_initcall(omap_gpmc_init);