blob: cd8d9778b14e8726c5552f14967c843c9767c162 [file] [log] [blame]
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03001/*
2 * omap_device implementation
3 *
Paul Walmsley887adea2010-07-26 16:34:33 -06004 * Copyright (C) 2009-2010 Nokia Corporation
Paul Walmsley4788da22010-05-18 20:24:05 -06005 * Paul Walmsley, Kevin Hilman
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03006 *
7 * Developed in collaboration with (alphabetical order): Benoit
Paul Walmsley4788da22010-05-18 20:24:05 -06008 * Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03009 * Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
10 * Woodruff
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * This code provides a consistent interface for OMAP device drivers
17 * to control power management and interconnect properties of their
18 * devices.
19 *
20 * In the medium- to long-term, this code should either be
21 * a) implemented via arch-specific pointers in platform_data
22 * or
23 * b) implemented as a proper omap_bus/omap_device in Linux, no more
24 * platform_data func pointers
25 *
26 *
27 * Guidelines for usage by driver authors:
28 *
29 * 1. These functions are intended to be used by device drivers via
30 * function pointers in struct platform_data. As an example,
31 * omap_device_enable() should be passed to the driver as
32 *
33 * struct foo_driver_platform_data {
34 * ...
35 * int (*device_enable)(struct platform_device *pdev);
36 * ...
37 * }
38 *
39 * Note that the generic "device_enable" name is used, rather than
40 * "omap_device_enable". This is so other architectures can pass in their
41 * own enable/disable functions here.
42 *
43 * This should be populated during device setup:
44 *
45 * ...
46 * pdata->device_enable = omap_device_enable;
47 * ...
48 *
49 * 2. Drivers should first check to ensure the function pointer is not null
50 * before calling it, as in:
51 *
52 * if (pdata->device_enable)
53 * pdata->device_enable(pdev);
54 *
55 * This allows other architectures that don't use similar device_enable()/
56 * device_shutdown() functions to execute normally.
57 *
58 * ...
59 *
60 * Suggested usage by device drivers:
61 *
62 * During device initialization:
63 * device_enable()
64 *
65 * During device idle:
66 * (save remaining device context if necessary)
67 * device_idle();
68 *
69 * During device resume:
70 * device_enable();
71 * (restore context if necessary)
72 *
73 * During device shutdown:
74 * device_shutdown()
75 * (device must be reinitialized at this point to use it again)
76 *
77 */
78#undef DEBUG
79
80#include <linux/kernel.h>
81#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090082#include <linux/slab.h>
Paul Walmsleyb04b65a2009-09-03 20:14:05 +030083#include <linux/err.h>
84#include <linux/io.h>
Partha Basak4ef7aca2010-09-21 19:23:04 +020085#include <linux/clk.h>
Rajendra Nayakda0653f2011-02-25 15:40:21 -070086#include <linux/clkdev.h>
Kevin Hilman345f79b2011-05-31 16:08:09 -070087#include <linux/pm_runtime.h>
Paul Walmsleyb04b65a2009-09-03 20:14:05 +030088
Tony Lindgrence491cf2009-10-20 09:40:47 -070089#include <plat/omap_device.h>
90#include <plat/omap_hwmod.h>
Rajendra Nayakda0653f2011-02-25 15:40:21 -070091#include <plat/clock.h>
Paul Walmsleyb04b65a2009-09-03 20:14:05 +030092
93/* These parameters are passed to _omap_device_{de,}activate() */
94#define USE_WAKEUP_LAT 0
95#define IGNORE_WAKEUP_LAT 1
96
Kevin Hilmanbfae4f82011-07-21 14:47:53 -070097static int omap_device_register(struct platform_device *pdev);
98static int omap_early_device_register(struct platform_device *pdev);
Kevin Hilmana2a28ad2011-07-21 14:14:35 -070099
Benoit Coussonb7b5bc92011-08-09 16:54:19 +0200100static struct omap_device_pm_latency omap_default_latency[] = {
101 {
102 .deactivate_func = omap_device_idle_hwmods,
103 .activate_func = omap_device_enable_hwmods,
104 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
105 }
106};
107
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300108/* Private functions */
109
110/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300111 * _omap_device_activate - increase device readiness
112 * @od: struct omap_device *
113 * @ignore_lat: increase to latency target (0) or full readiness (1)?
114 *
115 * Increase readiness of omap_device @od (thus decreasing device
116 * wakeup latency, but consuming more power). If @ignore_lat is
117 * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
118 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
119 * latency is greater than the requested maximum wakeup latency, step
120 * backwards in the omap_device_pm_latency table to ensure the
121 * device's maximum wakeup latency is less than or equal to the
122 * requested maximum wakeup latency. Returns 0.
123 */
124static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
125{
Tony Lindgrenf0594292009-10-19 15:25:24 -0700126 struct timespec a, b, c;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300127
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700128 dev_dbg(&od->pdev->dev, "omap_device: activating\n");
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300129
130 while (od->pm_lat_level > 0) {
131 struct omap_device_pm_latency *odpl;
Tony Lindgrenf0594292009-10-19 15:25:24 -0700132 unsigned long long act_lat = 0;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300133
134 od->pm_lat_level--;
135
136 odpl = od->pm_lats + od->pm_lat_level;
137
138 if (!ignore_lat &&
139 (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
140 break;
141
Kevin Hilmand2292662009-12-08 16:34:23 -0700142 read_persistent_clock(&a);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300143
144 /* XXX check return code */
145 odpl->activate_func(od);
146
Kevin Hilmand2292662009-12-08 16:34:23 -0700147 read_persistent_clock(&b);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300148
Tony Lindgrenf0594292009-10-19 15:25:24 -0700149 c = timespec_sub(b, a);
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700150 act_lat = timespec_to_ns(&c);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300151
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700152 dev_dbg(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700153 "omap_device: pm_lat %d: activate: elapsed time "
154 "%llu nsec\n", od->pm_lat_level, act_lat);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300155
Kevin Hilman9799aca2010-01-26 20:13:02 -0700156 if (act_lat > odpl->activate_lat) {
157 odpl->activate_lat_worst = act_lat;
158 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
159 odpl->activate_lat = act_lat;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700160 dev_dbg(&od->pdev->dev,
Grazvydas Ignotas47c3e5d2011-07-25 16:18:24 +0300161 "new worst case activate latency "
162 "%d: %llu\n",
163 od->pm_lat_level, act_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700164 } else
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700165 dev_warn(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700166 "activate latency %d "
167 "higher than exptected. (%llu > %d)\n",
168 od->pm_lat_level, act_lat,
169 odpl->activate_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700170 }
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300171
172 od->dev_wakeup_lat -= odpl->activate_lat;
173 }
174
175 return 0;
176}
177
178/**
179 * _omap_device_deactivate - decrease device readiness
180 * @od: struct omap_device *
181 * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
182 *
183 * Decrease readiness of omap_device @od (thus increasing device
184 * wakeup latency, but conserving power). If @ignore_lat is
185 * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
186 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
187 * latency is less than the requested maximum wakeup latency, step
188 * forwards in the omap_device_pm_latency table to ensure the device's
189 * maximum wakeup latency is less than or equal to the requested
190 * maximum wakeup latency. Returns 0.
191 */
192static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
193{
Tony Lindgrenf0594292009-10-19 15:25:24 -0700194 struct timespec a, b, c;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300195
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700196 dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300197
198 while (od->pm_lat_level < od->pm_lats_cnt) {
199 struct omap_device_pm_latency *odpl;
Tony Lindgrenf0594292009-10-19 15:25:24 -0700200 unsigned long long deact_lat = 0;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300201
202 odpl = od->pm_lats + od->pm_lat_level;
203
204 if (!ignore_lat &&
205 ((od->dev_wakeup_lat + odpl->activate_lat) >
206 od->_dev_wakeup_lat_limit))
207 break;
208
Kevin Hilmand2292662009-12-08 16:34:23 -0700209 read_persistent_clock(&a);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300210
211 /* XXX check return code */
212 odpl->deactivate_func(od);
213
Kevin Hilmand2292662009-12-08 16:34:23 -0700214 read_persistent_clock(&b);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300215
Tony Lindgrenf0594292009-10-19 15:25:24 -0700216 c = timespec_sub(b, a);
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700217 deact_lat = timespec_to_ns(&c);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300218
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700219 dev_dbg(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700220 "omap_device: pm_lat %d: deactivate: elapsed time "
221 "%llu nsec\n", od->pm_lat_level, deact_lat);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300222
Kevin Hilman9799aca2010-01-26 20:13:02 -0700223 if (deact_lat > odpl->deactivate_lat) {
224 odpl->deactivate_lat_worst = deact_lat;
225 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
226 odpl->deactivate_lat = deact_lat;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700227 dev_dbg(&od->pdev->dev,
Grazvydas Ignotas47c3e5d2011-07-25 16:18:24 +0300228 "new worst case deactivate latency "
229 "%d: %llu\n",
230 od->pm_lat_level, deact_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700231 } else
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700232 dev_warn(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700233 "deactivate latency %d "
234 "higher than exptected. (%llu > %d)\n",
235 od->pm_lat_level, deact_lat,
236 odpl->deactivate_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700237 }
238
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300239 od->dev_wakeup_lat += odpl->activate_lat;
240
241 od->pm_lat_level++;
242 }
243
244 return 0;
245}
246
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600247static void _add_clkdev(struct omap_device *od, const char *clk_alias,
248 const char *clk_name)
249{
250 struct clk *r;
251 struct clk_lookup *l;
252
253 if (!clk_alias || !clk_name)
254 return;
255
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700256 dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600257
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700258 r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600259 if (!IS_ERR(r)) {
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700260 dev_warn(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700261 "alias %s already exists\n", clk_alias);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600262 clk_put(r);
263 return;
264 }
265
266 r = omap_clk_get_by_name(clk_name);
267 if (IS_ERR(r)) {
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700268 dev_err(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700269 "omap_clk_get_by_name for %s failed\n", clk_name);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600270 return;
271 }
272
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700273 l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600274 if (!l) {
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700275 dev_err(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700276 "clkdev_alloc for %s failed\n", clk_alias);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600277 return;
278 }
279
280 clkdev_add(l);
281}
282
Partha Basak4ef7aca2010-09-21 19:23:04 +0200283/**
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600284 * _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
285 * and main clock
Partha Basak4ef7aca2010-09-21 19:23:04 +0200286 * @od: struct omap_device *od
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600287 * @oh: struct omap_hwmod *oh
Partha Basak4ef7aca2010-09-21 19:23:04 +0200288 *
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600289 * For the main clock and every optional clock present per hwmod per
290 * omap_device, this function adds an entry in the clkdev table of the
291 * form <dev-id=dev_name, con-id=role> if it does not exist already.
Partha Basak4ef7aca2010-09-21 19:23:04 +0200292 *
293 * The function is called from inside omap_device_build_ss(), after
294 * omap_device_register.
295 *
296 * This allows drivers to get a pointer to its optional clocks based on its role
297 * by calling clk_get(<dev*>, <role>).
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600298 * In the case of the main clock, a "fck" alias is used.
Partha Basak4ef7aca2010-09-21 19:23:04 +0200299 *
300 * No return value.
301 */
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600302static void _add_hwmod_clocks_clkdev(struct omap_device *od,
303 struct omap_hwmod *oh)
Partha Basak4ef7aca2010-09-21 19:23:04 +0200304{
305 int i;
306
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600307 _add_clkdev(od, "fck", oh->main_clk);
Partha Basak4ef7aca2010-09-21 19:23:04 +0200308
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600309 for (i = 0; i < oh->opt_clks_cnt; i++)
310 _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
Partha Basak4ef7aca2010-09-21 19:23:04 +0200311}
312
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300313
314/* Public functions for use by core code */
315
316/**
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700317 * omap_device_get_context_loss_count - get lost context count
318 * @od: struct omap_device *
319 *
320 * Using the primary hwmod, query the context loss count for this
321 * device.
322 *
323 * Callers should consider context for this device lost any time this
324 * function returns a value different than the value the caller got
325 * the last time it called this function.
326 *
327 * If any hwmods exist for the omap_device assoiated with @pdev,
328 * return the context loss counter for that hwmod, otherwise return
329 * zero.
330 */
331u32 omap_device_get_context_loss_count(struct platform_device *pdev)
332{
333 struct omap_device *od;
334 u32 ret = 0;
335
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600336 od = to_omap_device(pdev);
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700337
338 if (od->hwmods_cnt)
339 ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
340
341 return ret;
342}
343
344/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300345 * omap_device_count_resources - count number of struct resource entries needed
346 * @od: struct omap_device *
347 *
348 * Count the number of struct resource entries needed for this
349 * omap_device @od. Used by omap_device_build_ss() to determine how
350 * much memory to allocate before calling
351 * omap_device_fill_resources(). Returns the count.
352 */
Kevin Hilmana2a28ad2011-07-21 14:14:35 -0700353static int omap_device_count_resources(struct omap_device *od)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300354{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300355 int c = 0;
356 int i;
357
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600358 for (i = 0; i < od->hwmods_cnt; i++)
359 c += omap_hwmod_count_resources(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300360
361 pr_debug("omap_device: %s: counted %d total resources across %d "
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700362 "hwmods\n", od->pdev->name, c, od->hwmods_cnt);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300363
364 return c;
365}
366
367/**
368 * omap_device_fill_resources - fill in array of struct resource
369 * @od: struct omap_device *
370 * @res: pointer to an array of struct resource to be filled in
371 *
372 * Populate one or more empty struct resource pointed to by @res with
373 * the resource data for this omap_device @od. Used by
374 * omap_device_build_ss() after calling omap_device_count_resources().
375 * Ideally this function would not be needed at all. If omap_device
376 * replaces platform_device, then we can specify our own
377 * get_resource()/ get_irq()/etc functions that use the underlying
378 * omap_hwmod information. Or if platform_device is extended to use
379 * subarchitecture-specific function pointers, the various
380 * platform_device functions can simply call omap_device internal
381 * functions to get device resources. Hacking around the existing
382 * platform_device code wastes memory. Returns 0.
383 */
Kevin Hilmana2a28ad2011-07-21 14:14:35 -0700384static int omap_device_fill_resources(struct omap_device *od,
385 struct resource *res)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300386{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300387 int c = 0;
388 int i, r;
389
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600390 for (i = 0; i < od->hwmods_cnt; i++) {
391 r = omap_hwmod_fill_resources(od->hwmods[i], res);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300392 res += r;
393 c += r;
394 }
395
396 return 0;
397}
398
399/**
400 * omap_device_build - build and register an omap_device with one omap_hwmod
401 * @pdev_name: name of the platform_device driver to use
402 * @pdev_id: this platform_device's connection ID
403 * @oh: ptr to the single omap_hwmod that backs this omap_device
404 * @pdata: platform_data ptr to associate with the platform_device
405 * @pdata_len: amount of memory pointed to by @pdata
406 * @pm_lats: pointer to a omap_device_pm_latency array for this device
407 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700408 * @is_early_device: should the device be registered as an early device or not
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300409 *
410 * Convenience function for building and registering a single
411 * omap_device record, which in turn builds and registers a
412 * platform_device record. See omap_device_build_ss() for more
413 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
414 * passes along the return value of omap_device_build_ss().
415 */
Kevin Hilman3528c582011-07-21 13:48:45 -0700416struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300417 struct omap_hwmod *oh, void *pdata,
418 int pdata_len,
419 struct omap_device_pm_latency *pm_lats,
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700420 int pm_lats_cnt, int is_early_device)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300421{
422 struct omap_hwmod *ohs[] = { oh };
423
424 if (!oh)
425 return ERR_PTR(-EINVAL);
426
427 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700428 pdata_len, pm_lats, pm_lats_cnt,
429 is_early_device);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300430}
431
432/**
433 * omap_device_build_ss - build and register an omap_device with multiple hwmods
434 * @pdev_name: name of the platform_device driver to use
435 * @pdev_id: this platform_device's connection ID
436 * @oh: ptr to the single omap_hwmod that backs this omap_device
437 * @pdata: platform_data ptr to associate with the platform_device
438 * @pdata_len: amount of memory pointed to by @pdata
439 * @pm_lats: pointer to a omap_device_pm_latency array for this device
440 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700441 * @is_early_device: should the device be registered as an early device or not
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300442 *
443 * Convenience function for building and registering an omap_device
444 * subsystem record. Subsystem records consist of multiple
445 * omap_hwmods. This function in turn builds and registers a
446 * platform_device record. Returns an ERR_PTR() on error, or passes
447 * along the return value of omap_device_register().
448 */
Kevin Hilman3528c582011-07-21 13:48:45 -0700449struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300450 struct omap_hwmod **ohs, int oh_cnt,
451 void *pdata, int pdata_len,
452 struct omap_device_pm_latency *pm_lats,
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700453 int pm_lats_cnt, int is_early_device)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300454{
455 int ret = -ENOMEM;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700456 struct platform_device *pdev;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300457 struct omap_device *od;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300458 struct resource *res = NULL;
Kevin Hilman06563582010-07-26 16:34:30 -0600459 int i, res_count;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300460 struct omap_hwmod **hwmods;
461
462 if (!ohs || oh_cnt == 0 || !pdev_name)
463 return ERR_PTR(-EINVAL);
464
465 if (!pdata && pdata_len > 0)
466 return ERR_PTR(-EINVAL);
467
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700468 pdev = platform_device_alloc(pdev_name, pdev_id);
469 if (!pdev) {
470 ret = -ENOMEM;
471 goto odbs_exit;
472 }
473
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300474 pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name,
475 oh_cnt);
476
477 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700478 if (!od) {
479 ret = -ENOMEM;
480 goto odbs_exit1;
481 }
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300482 od->hwmods_cnt = oh_cnt;
483
484 hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt,
485 GFP_KERNEL);
486 if (!hwmods)
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700487 goto odbs_exit2;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300488
489 memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt);
490 od->hwmods = hwmods;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700491 od->pdev = pdev;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300492
493 res_count = omap_device_count_resources(od);
494 if (res_count > 0) {
495 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
496 if (!res)
497 goto odbs_exit3;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700498
499 omap_device_fill_resources(od, res);
500
501 ret = platform_device_add_resources(pdev, res, res_count);
502 kfree(res);
503
504 if (ret)
505 goto odbs_exit3;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300506 }
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300507
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700508 ret = platform_device_add_data(pdev, pdata, pdata_len);
Artem Bityutskiy49b368a2010-07-12 13:38:07 +0000509 if (ret)
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700510 goto odbs_exit3;
511
512 pdev->archdata.od = od;
513
514 if (is_early_device)
515 ret = omap_early_device_register(pdev);
516 else
517 ret = omap_device_register(pdev);
518 if (ret)
519 goto odbs_exit3;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300520
Benoit Coussonb7b5bc92011-08-09 16:54:19 +0200521 if (!pm_lats) {
522 pm_lats = omap_default_latency;
523 pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
524 }
525
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300526 od->pm_lats_cnt = pm_lats_cnt;
Benoit Coussonb7b5bc92011-08-09 16:54:19 +0200527 od->pm_lats = kmemdup(pm_lats,
528 sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
529 GFP_KERNEL);
530 if (!od->pm_lats)
531 goto odbs_exit3;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300532
Partha Basak4ef7aca2010-09-21 19:23:04 +0200533 for (i = 0; i < oh_cnt; i++) {
Kevin Hilman06563582010-07-26 16:34:30 -0600534 hwmods[i]->od = od;
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600535 _add_hwmod_clocks_clkdev(od, hwmods[i]);
Partha Basak4ef7aca2010-09-21 19:23:04 +0200536 }
Kevin Hilman06563582010-07-26 16:34:30 -0600537
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700538 return pdev;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300539
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300540odbs_exit3:
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300541 kfree(hwmods);
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700542odbs_exit2:
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300543 kfree(od);
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700544odbs_exit1:
545 platform_device_put(pdev);
546odbs_exit:
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300547
548 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
549
550 return ERR_PTR(ret);
551}
552
553/**
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700554 * omap_early_device_register - register an omap_device as an early platform
555 * device.
556 * @od: struct omap_device * to register
557 *
558 * Register the omap_device structure. This currently just calls
559 * platform_early_add_device() on the underlying platform_device.
560 * Returns 0 by default.
561 */
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700562static int omap_early_device_register(struct platform_device *pdev)
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700563{
564 struct platform_device *devices[1];
565
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700566 devices[0] = pdev;
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700567 early_platform_add_devices(devices, 1);
568 return 0;
569}
570
Kevin Hilman256a5432011-07-12 22:48:03 +0200571#ifdef CONFIG_PM_RUNTIME
Kevin Hilman638080c2011-04-29 00:36:42 +0200572static int _od_runtime_suspend(struct device *dev)
573{
574 struct platform_device *pdev = to_platform_device(dev);
Kevin Hilman345f79b2011-05-31 16:08:09 -0700575 int ret;
Kevin Hilman638080c2011-04-29 00:36:42 +0200576
Kevin Hilman345f79b2011-05-31 16:08:09 -0700577 ret = pm_generic_runtime_suspend(dev);
578
579 if (!ret)
580 omap_device_idle(pdev);
581
582 return ret;
583}
584
585static int _od_runtime_idle(struct device *dev)
586{
587 return pm_generic_runtime_idle(dev);
Kevin Hilman638080c2011-04-29 00:36:42 +0200588}
589
590static int _od_runtime_resume(struct device *dev)
591{
592 struct platform_device *pdev = to_platform_device(dev);
593
Kevin Hilman345f79b2011-05-31 16:08:09 -0700594 omap_device_enable(pdev);
595
596 return pm_generic_runtime_resume(dev);
Kevin Hilman638080c2011-04-29 00:36:42 +0200597}
Kevin Hilman256a5432011-07-12 22:48:03 +0200598#endif
Kevin Hilman638080c2011-04-29 00:36:42 +0200599
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200600#ifdef CONFIG_SUSPEND
601static int _od_suspend_noirq(struct device *dev)
602{
603 struct platform_device *pdev = to_platform_device(dev);
604 struct omap_device *od = to_omap_device(pdev);
605 int ret;
606
Kevin Hilman80c6d1e2011-07-12 22:48:29 +0200607 if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)
608 return pm_generic_suspend_noirq(dev);
609
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200610 ret = pm_generic_suspend_noirq(dev);
611
612 if (!ret && !pm_runtime_status_suspended(dev)) {
613 if (pm_generic_runtime_suspend(dev) == 0) {
614 omap_device_idle(pdev);
615 od->flags |= OMAP_DEVICE_SUSPENDED;
616 }
617 }
618
619 return ret;
620}
621
622static int _od_resume_noirq(struct device *dev)
623{
624 struct platform_device *pdev = to_platform_device(dev);
625 struct omap_device *od = to_omap_device(pdev);
626
Kevin Hilman80c6d1e2011-07-12 22:48:29 +0200627 if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)
628 return pm_generic_resume_noirq(dev);
629
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200630 if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
631 !pm_runtime_status_suspended(dev)) {
632 od->flags &= ~OMAP_DEVICE_SUSPENDED;
633 omap_device_enable(pdev);
634 pm_generic_runtime_resume(dev);
635 }
636
637 return pm_generic_resume_noirq(dev);
638}
Kevin Hilman126caf12011-09-01 10:59:36 -0700639#else
640#define _od_suspend_noirq NULL
641#define _od_resume_noirq NULL
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200642#endif
643
Rafael J. Wysocki564b9052011-06-23 01:52:55 +0200644static struct dev_pm_domain omap_device_pm_domain = {
Kevin Hilman638080c2011-04-29 00:36:42 +0200645 .ops = {
Kevin Hilman256a5432011-07-12 22:48:03 +0200646 SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
647 _od_runtime_idle)
Kevin Hilman638080c2011-04-29 00:36:42 +0200648 USE_PLATFORM_PM_SLEEP_OPS
Kevin Hilmanff353362011-08-25 15:31:14 +0200649 .suspend_noirq = _od_suspend_noirq,
650 .resume_noirq = _od_resume_noirq,
Kevin Hilman638080c2011-04-29 00:36:42 +0200651 }
652};
653
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700654/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300655 * omap_device_register - register an omap_device with one omap_hwmod
656 * @od: struct omap_device * to register
657 *
658 * Register the omap_device structure. This currently just calls
659 * platform_device_register() on the underlying platform_device.
660 * Returns the return value of platform_device_register().
661 */
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700662static int omap_device_register(struct platform_device *pdev)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300663{
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700664 pr_debug("omap_device: %s: registering\n", pdev->name);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300665
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700666 pdev->dev.parent = &omap_device_parent;
667 pdev->dev.pm_domain = &omap_device_pm_domain;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700668 return platform_device_add(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300669}
670
671
672/* Public functions for use by device drivers through struct platform_data */
673
674/**
675 * omap_device_enable - fully activate an omap_device
676 * @od: struct omap_device * to activate
677 *
678 * Do whatever is necessary for the hwmods underlying omap_device @od
679 * to be accessible and ready to operate. This generally involves
680 * enabling clocks, setting SYSCONFIG registers; and in the future may
681 * involve remuxing pins. Device drivers should call this function
682 * (through platform_data function pointers) where they would normally
683 * enable clocks, etc. Returns -EINVAL if called when the omap_device
684 * is already enabled, or passes along the return value of
685 * _omap_device_activate().
686 */
687int omap_device_enable(struct platform_device *pdev)
688{
689 int ret;
690 struct omap_device *od;
691
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600692 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300693
694 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
Kevin Hilman49882c92011-07-21 09:58:36 -0700695 dev_warn(&pdev->dev,
696 "omap_device: %s() called from invalid state %d\n",
697 __func__, od->_state);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300698 return -EINVAL;
699 }
700
701 /* Enable everything if we're enabling this device from scratch */
702 if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
703 od->pm_lat_level = od->pm_lats_cnt;
704
705 ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
706
707 od->dev_wakeup_lat = 0;
Kevin Hilman5f1b6ef2009-12-08 16:34:22 -0700708 od->_dev_wakeup_lat_limit = UINT_MAX;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300709 od->_state = OMAP_DEVICE_STATE_ENABLED;
710
711 return ret;
712}
713
714/**
715 * omap_device_idle - idle an omap_device
716 * @od: struct omap_device * to idle
717 *
718 * Idle omap_device @od by calling as many .deactivate_func() entries
719 * in the omap_device's pm_lats table as is possible without exceeding
720 * the device's maximum wakeup latency limit, pm_lat_limit. Device
721 * drivers should call this function (through platform_data function
722 * pointers) where they would normally disable clocks after operations
723 * complete, etc.. Returns -EINVAL if the omap_device is not
724 * currently enabled, or passes along the return value of
725 * _omap_device_deactivate().
726 */
727int omap_device_idle(struct platform_device *pdev)
728{
729 int ret;
730 struct omap_device *od;
731
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600732 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300733
734 if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
Kevin Hilman49882c92011-07-21 09:58:36 -0700735 dev_warn(&pdev->dev,
736 "omap_device: %s() called from invalid state %d\n",
737 __func__, od->_state);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300738 return -EINVAL;
739 }
740
741 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
742
743 od->_state = OMAP_DEVICE_STATE_IDLE;
744
745 return ret;
746}
747
748/**
749 * omap_device_shutdown - shut down an omap_device
750 * @od: struct omap_device * to shut down
751 *
752 * Shut down omap_device @od by calling all .deactivate_func() entries
753 * in the omap_device's pm_lats table and then shutting down all of
754 * the underlying omap_hwmods. Used when a device is being "removed"
755 * or a device driver is being unloaded. Returns -EINVAL if the
756 * omap_device is not currently enabled or idle, or passes along the
757 * return value of _omap_device_deactivate().
758 */
759int omap_device_shutdown(struct platform_device *pdev)
760{
761 int ret, i;
762 struct omap_device *od;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300763
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600764 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300765
766 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
767 od->_state != OMAP_DEVICE_STATE_IDLE) {
Kevin Hilman49882c92011-07-21 09:58:36 -0700768 dev_warn(&pdev->dev,
769 "omap_device: %s() called from invalid state %d\n",
770 __func__, od->_state);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300771 return -EINVAL;
772 }
773
774 ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
775
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600776 for (i = 0; i < od->hwmods_cnt; i++)
777 omap_hwmod_shutdown(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300778
779 od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
780
781 return ret;
782}
783
784/**
785 * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
786 * @od: struct omap_device *
787 *
788 * When a device's maximum wakeup latency limit changes, call some of
789 * the .activate_func or .deactivate_func function pointers in the
790 * omap_device's pm_lats array to ensure that the device's maximum
791 * wakeup latency is less than or equal to the new latency limit.
792 * Intended to be called by OMAP PM code whenever a device's maximum
793 * wakeup latency limit changes (e.g., via
794 * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
795 * done (e.g., if the omap_device is not currently idle, or if the
796 * wakeup latency is already current with the new limit) or passes
797 * along the return value of _omap_device_deactivate() or
798 * _omap_device_activate().
799 */
800int omap_device_align_pm_lat(struct platform_device *pdev,
801 u32 new_wakeup_lat_limit)
802{
803 int ret = -EINVAL;
804 struct omap_device *od;
805
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600806 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300807
808 if (new_wakeup_lat_limit == od->dev_wakeup_lat)
809 return 0;
810
811 od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
812
813 if (od->_state != OMAP_DEVICE_STATE_IDLE)
814 return 0;
815 else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
816 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
817 else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
818 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
819
820 return ret;
821}
822
823/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300824 * omap_device_get_pwrdm - return the powerdomain * associated with @od
825 * @od: struct omap_device *
826 *
827 * Return the powerdomain associated with the first underlying
828 * omap_hwmod for this omap_device. Intended for use by core OMAP PM
829 * code. Returns NULL on error or a struct powerdomain * upon
830 * success.
831 */
832struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
833{
834 /*
835 * XXX Assumes that all omap_hwmod powerdomains are identical.
836 * This may not necessarily be true. There should be a sanity
837 * check in here to WARN() if any difference appears.
838 */
839 if (!od->hwmods_cnt)
840 return NULL;
841
842 return omap_hwmod_get_pwrdm(od->hwmods[0]);
843}
844
Paul Walmsleydb2a60b2010-07-26 16:34:33 -0600845/**
846 * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
847 * @od: struct omap_device *
848 *
849 * Return the MPU's virtual address for the base of the hwmod, from
850 * the ioremap() that the hwmod code does. Only valid if there is one
851 * hwmod associated with this device. Returns NULL if there are zero
852 * or more than one hwmods associated with this omap_device;
853 * otherwise, passes along the return value from
854 * omap_hwmod_get_mpu_rt_va().
855 */
856void __iomem *omap_device_get_rt_va(struct omap_device *od)
857{
858 if (od->hwmods_cnt != 1)
859 return NULL;
860
861 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
862}
863
Nishanth Menon1f8a7d52011-07-27 15:02:32 -0500864/**
865 * omap_device_get_by_hwmod_name() - convert a hwmod name to
866 * device pointer.
867 * @oh_name: name of the hwmod device
868 *
869 * Returns back a struct device * pointer associated with a hwmod
870 * device represented by a hwmod_name
871 */
872struct device *omap_device_get_by_hwmod_name(const char *oh_name)
873{
874 struct omap_hwmod *oh;
875
876 if (!oh_name) {
877 WARN(1, "%s: no hwmod name!\n", __func__);
878 return ERR_PTR(-EINVAL);
879 }
880
881 oh = omap_hwmod_lookup(oh_name);
882 if (IS_ERR_OR_NULL(oh)) {
883 WARN(1, "%s: no hwmod for %s\n", __func__,
884 oh_name);
885 return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
886 }
887 if (IS_ERR_OR_NULL(oh->od)) {
888 WARN(1, "%s: no omap_device for %s\n", __func__,
889 oh_name);
890 return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
891 }
892
893 if (IS_ERR_OR_NULL(oh->od->pdev))
894 return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
895
896 return &oh->od->pdev->dev;
897}
898EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
899
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300900/*
901 * Public functions intended for use in omap_device_pm_latency
902 * .activate_func and .deactivate_func function pointers
903 */
904
905/**
906 * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
907 * @od: struct omap_device *od
908 *
909 * Enable all underlying hwmods. Returns 0.
910 */
911int omap_device_enable_hwmods(struct omap_device *od)
912{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300913 int i;
914
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600915 for (i = 0; i < od->hwmods_cnt; i++)
916 omap_hwmod_enable(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300917
918 /* XXX pass along return value here? */
919 return 0;
920}
921
922/**
923 * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
924 * @od: struct omap_device *od
925 *
926 * Idle all underlying hwmods. Returns 0.
927 */
928int omap_device_idle_hwmods(struct omap_device *od)
929{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300930 int i;
931
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600932 for (i = 0; i < od->hwmods_cnt; i++)
933 omap_hwmod_idle(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300934
935 /* XXX pass along return value here? */
936 return 0;
937}
938
939/**
940 * omap_device_disable_clocks - disable all main and interface clocks
941 * @od: struct omap_device *od
942 *
943 * Disable the main functional clock and interface clock for all of the
944 * omap_hwmods associated with the omap_device. Returns 0.
945 */
946int omap_device_disable_clocks(struct omap_device *od)
947{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300948 int i;
949
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600950 for (i = 0; i < od->hwmods_cnt; i++)
951 omap_hwmod_disable_clocks(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300952
953 /* XXX pass along return value here? */
954 return 0;
955}
956
957/**
958 * omap_device_enable_clocks - enable all main and interface clocks
959 * @od: struct omap_device *od
960 *
961 * Enable the main functional clock and interface clock for all of the
962 * omap_hwmods associated with the omap_device. Returns 0.
963 */
964int omap_device_enable_clocks(struct omap_device *od)
965{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300966 int i;
967
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600968 for (i = 0; i < od->hwmods_cnt; i++)
969 omap_hwmod_enable_clocks(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300970
971 /* XXX pass along return value here? */
972 return 0;
973}
Kevin Hilman0d5e8252010-08-23 08:10:55 -0700974
975struct device omap_device_parent = {
976 .init_name = "omap",
977 .parent = &platform_bus,
978};
979
980static int __init omap_device_init(void)
981{
982 return device_register(&omap_device_parent);
983}
984core_initcall(omap_device_init);