OSDN Git Service

ARM: omap2plus_defconfig: Enable ARM_KERNMEM_PERMS and few loadable modules
[android-x86/kernel.git] / arch / arm / mach-omap2 / devices.c
1 /*
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  */
11 #include <linux/gpio.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/io.h>
16 #include <linux/clk.h>
17 #include <linux/err.h>
18 #include <linux/slab.h>
19 #include <linux/of.h>
20 #include <linux/pinctrl/machine.h>
21
22 #include <asm/mach-types.h>
23 #include <asm/mach/map.h>
24
25 #include <linux/omap-dma.h>
26
27 #include "iomap.h"
28 #include "omap_hwmod.h"
29 #include "omap_device.h"
30
31 #include "soc.h"
32 #include "common.h"
33 #include "mux.h"
34 #include "control.h"
35 #include "display.h"
36
37 #define L3_MODULES_MAX_LEN 12
38 #define L3_MODULES 3
39
40 static int __init omap3_l3_init(void)
41 {
42         struct omap_hwmod *oh;
43         struct platform_device *pdev;
44         char oh_name[L3_MODULES_MAX_LEN];
45
46         /*
47          * To avoid code running on other OMAPs in
48          * multi-omap builds
49          */
50         if (!(cpu_is_omap34xx()) || of_have_populated_dt())
51                 return -ENODEV;
52
53         snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
54
55         oh = omap_hwmod_lookup(oh_name);
56
57         if (!oh)
58                 pr_err("could not look up %s\n", oh_name);
59
60         pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
61
62         WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
63
64         return PTR_ERR_OR_ZERO(pdev);
65 }
66 omap_postcore_initcall(omap3_l3_init);
67
68 static inline void omap_init_sti(void) {}
69
70 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
71
72 static struct platform_device omap_pcm = {
73         .name   = "omap-pcm-audio",
74         .id     = -1,
75 };
76
77 static void omap_init_audio(void)
78 {
79         platform_device_register(&omap_pcm);
80 }
81
82 #else
83 static inline void omap_init_audio(void) {}
84 #endif
85
86 #if defined(CONFIG_SPI_OMAP24XX) || defined(CONFIG_SPI_OMAP24XX_MODULE)
87
88 #include <linux/platform_data/spi-omap2-mcspi.h>
89
90 static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
91 {
92         struct platform_device *pdev;
93         char *name = "omap2_mcspi";
94         struct omap2_mcspi_platform_config *pdata;
95         static int spi_num;
96         struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
97
98         pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
99         if (!pdata) {
100                 pr_err("Memory allocation for McSPI device failed\n");
101                 return -ENOMEM;
102         }
103
104         pdata->num_cs = mcspi_attrib->num_chipselect;
105         switch (oh->class->rev) {
106         case OMAP2_MCSPI_REV:
107         case OMAP3_MCSPI_REV:
108                         pdata->regs_offset = 0;
109                         break;
110         case OMAP4_MCSPI_REV:
111                         pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
112                         break;
113         default:
114                         pr_err("Invalid McSPI Revision value\n");
115                         kfree(pdata);
116                         return -EINVAL;
117         }
118
119         spi_num++;
120         pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
121         WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
122                                 name, oh->name);
123         kfree(pdata);
124         return 0;
125 }
126
127 static void omap_init_mcspi(void)
128 {
129         omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
130 }
131
132 #else
133 static inline void omap_init_mcspi(void) {}
134 #endif
135
136 /**
137  * omap_init_rng - bind the RNG hwmod to the RNG omap_device
138  *
139  * Bind the RNG hwmod to the RNG omap_device.  No return value.
140  */
141 static void omap_init_rng(void)
142 {
143         struct omap_hwmod *oh;
144         struct platform_device *pdev;
145
146         oh = omap_hwmod_lookup("rng");
147         if (!oh)
148                 return;
149
150         pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
151         WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
152 }
153
154 static void __init omap_init_sham(void)
155 {
156         struct omap_hwmod *oh;
157         struct platform_device *pdev;
158
159         oh = omap_hwmod_lookup("sham");
160         if (!oh)
161                 return;
162
163         pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
164         WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
165 }
166
167 static void __init omap_init_aes(void)
168 {
169         struct omap_hwmod *oh;
170         struct platform_device *pdev;
171
172         oh = omap_hwmod_lookup("aes");
173         if (!oh)
174                 return;
175
176         pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
177         WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
178 }
179
180 /*-------------------------------------------------------------------------*/
181
182 #if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
183         defined(CONFIG_VIDEO_OMAP2_VOUT_MODULE)
184 #if defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
185 static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
186 };
187 #else
188 static struct resource omap_vout_resource[2] = {
189 };
190 #endif
191
192 static struct platform_device omap_vout_device = {
193         .name           = "omap_vout",
194         .num_resources  = ARRAY_SIZE(omap_vout_resource),
195         .resource       = &omap_vout_resource[0],
196         .id             = -1,
197 };
198
199 int __init omap_init_vout(void)
200 {
201         return platform_device_register(&omap_vout_device);
202 }
203 #else
204 int __init omap_init_vout(void) { return 0; }
205 #endif
206
207 /*-------------------------------------------------------------------------*/
208
209 static int __init omap2_init_devices(void)
210 {
211         /* Enable dummy states for those platforms without pinctrl support */
212         if (!of_have_populated_dt())
213                 pinctrl_provide_dummies();
214
215         /*
216          * please keep these calls, and their implementations above,
217          * in alphabetical order so they're easier to sort through.
218          */
219         omap_init_audio();
220         /* If dtb is there, the devices will be created dynamically */
221         if (!of_have_populated_dt()) {
222                 omap_init_mcspi();
223                 omap_init_sham();
224                 omap_init_aes();
225                 omap_init_rng();
226         }
227         omap_init_sti();
228
229         return 0;
230 }
231 omap_arch_initcall(omap2_init_devices);
232
233 static int __init omap_gpmc_init(void)
234 {
235         struct omap_hwmod *oh;
236         struct platform_device *pdev;
237         char *oh_name = "gpmc";
238
239         /*
240          * if the board boots up with a populated DT, do not
241          * manually add the device from this initcall
242          */
243         if (of_have_populated_dt())
244                 return -ENODEV;
245
246         oh = omap_hwmod_lookup(oh_name);
247         if (!oh) {
248                 pr_err("Could not look up %s\n", oh_name);
249                 return -ENODEV;
250         }
251
252         pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
253         WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
254
255         return PTR_ERR_OR_ZERO(pdev);
256 }
257 omap_postcore_initcall(omap_gpmc_init);