blob: 6725c72b0cd010427f204b1ea30c9f6dbcdf9870 [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);
Benoit Coussona4f6cdb2011-08-09 16:47:01 +020099static struct omap_device *omap_device_alloc(struct platform_device *pdev,
100 struct omap_hwmod **ohs, int oh_cnt,
101 struct omap_device_pm_latency *pm_lats,
102 int pm_lats_cnt);
103
Kevin Hilmana2a28ad2011-07-21 14:14:35 -0700104
Benoit Coussonb7b5bc92011-08-09 16:54:19 +0200105static struct omap_device_pm_latency omap_default_latency[] = {
106 {
107 .deactivate_func = omap_device_idle_hwmods,
108 .activate_func = omap_device_enable_hwmods,
109 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
110 }
111};
112
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300113/* Private functions */
114
115/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300116 * _omap_device_activate - increase device readiness
117 * @od: struct omap_device *
118 * @ignore_lat: increase to latency target (0) or full readiness (1)?
119 *
120 * Increase readiness of omap_device @od (thus decreasing device
121 * wakeup latency, but consuming more power). If @ignore_lat is
122 * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise,
123 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
124 * latency is greater than the requested maximum wakeup latency, step
125 * backwards in the omap_device_pm_latency table to ensure the
126 * device's maximum wakeup latency is less than or equal to the
127 * requested maximum wakeup latency. Returns 0.
128 */
129static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
130{
Tony Lindgrenf0594292009-10-19 15:25:24 -0700131 struct timespec a, b, c;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300132
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700133 dev_dbg(&od->pdev->dev, "omap_device: activating\n");
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300134
135 while (od->pm_lat_level > 0) {
136 struct omap_device_pm_latency *odpl;
Tony Lindgrenf0594292009-10-19 15:25:24 -0700137 unsigned long long act_lat = 0;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300138
139 od->pm_lat_level--;
140
141 odpl = od->pm_lats + od->pm_lat_level;
142
143 if (!ignore_lat &&
144 (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
145 break;
146
Kevin Hilmand2292662009-12-08 16:34:23 -0700147 read_persistent_clock(&a);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300148
149 /* XXX check return code */
150 odpl->activate_func(od);
151
Kevin Hilmand2292662009-12-08 16:34:23 -0700152 read_persistent_clock(&b);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300153
Tony Lindgrenf0594292009-10-19 15:25:24 -0700154 c = timespec_sub(b, a);
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700155 act_lat = timespec_to_ns(&c);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300156
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700157 dev_dbg(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700158 "omap_device: pm_lat %d: activate: elapsed time "
159 "%llu nsec\n", od->pm_lat_level, act_lat);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300160
Kevin Hilman9799aca2010-01-26 20:13:02 -0700161 if (act_lat > odpl->activate_lat) {
162 odpl->activate_lat_worst = act_lat;
163 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
164 odpl->activate_lat = act_lat;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700165 dev_dbg(&od->pdev->dev,
Grazvydas Ignotas47c3e5d2011-07-25 16:18:24 +0300166 "new worst case activate latency "
167 "%d: %llu\n",
168 od->pm_lat_level, act_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700169 } else
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700170 dev_warn(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700171 "activate latency %d "
172 "higher than exptected. (%llu > %d)\n",
173 od->pm_lat_level, act_lat,
174 odpl->activate_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700175 }
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300176
177 od->dev_wakeup_lat -= odpl->activate_lat;
178 }
179
180 return 0;
181}
182
183/**
184 * _omap_device_deactivate - decrease device readiness
185 * @od: struct omap_device *
186 * @ignore_lat: decrease to latency target (0) or full inactivity (1)?
187 *
188 * Decrease readiness of omap_device @od (thus increasing device
189 * wakeup latency, but conserving power). If @ignore_lat is
190 * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise,
191 * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup
192 * latency is less than the requested maximum wakeup latency, step
193 * forwards in the omap_device_pm_latency table to ensure the device's
194 * maximum wakeup latency is less than or equal to the requested
195 * maximum wakeup latency. Returns 0.
196 */
197static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
198{
Tony Lindgrenf0594292009-10-19 15:25:24 -0700199 struct timespec a, b, c;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300200
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700201 dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300202
203 while (od->pm_lat_level < od->pm_lats_cnt) {
204 struct omap_device_pm_latency *odpl;
Tony Lindgrenf0594292009-10-19 15:25:24 -0700205 unsigned long long deact_lat = 0;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300206
207 odpl = od->pm_lats + od->pm_lat_level;
208
209 if (!ignore_lat &&
210 ((od->dev_wakeup_lat + odpl->activate_lat) >
211 od->_dev_wakeup_lat_limit))
212 break;
213
Kevin Hilmand2292662009-12-08 16:34:23 -0700214 read_persistent_clock(&a);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300215
216 /* XXX check return code */
217 odpl->deactivate_func(od);
218
Kevin Hilmand2292662009-12-08 16:34:23 -0700219 read_persistent_clock(&b);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300220
Tony Lindgrenf0594292009-10-19 15:25:24 -0700221 c = timespec_sub(b, a);
Kevin Hilman0d93d8b2009-12-08 16:34:26 -0700222 deact_lat = timespec_to_ns(&c);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300223
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700224 dev_dbg(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700225 "omap_device: pm_lat %d: deactivate: elapsed time "
226 "%llu nsec\n", od->pm_lat_level, deact_lat);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300227
Kevin Hilman9799aca2010-01-26 20:13:02 -0700228 if (deact_lat > odpl->deactivate_lat) {
229 odpl->deactivate_lat_worst = deact_lat;
230 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
231 odpl->deactivate_lat = deact_lat;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700232 dev_dbg(&od->pdev->dev,
Grazvydas Ignotas47c3e5d2011-07-25 16:18:24 +0300233 "new worst case deactivate latency "
234 "%d: %llu\n",
235 od->pm_lat_level, deact_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700236 } else
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700237 dev_warn(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700238 "deactivate latency %d "
239 "higher than exptected. (%llu > %d)\n",
240 od->pm_lat_level, deact_lat,
241 odpl->deactivate_lat);
Kevin Hilman9799aca2010-01-26 20:13:02 -0700242 }
243
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300244 od->dev_wakeup_lat += odpl->activate_lat;
245
246 od->pm_lat_level++;
247 }
248
249 return 0;
250}
251
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600252static void _add_clkdev(struct omap_device *od, const char *clk_alias,
253 const char *clk_name)
254{
255 struct clk *r;
256 struct clk_lookup *l;
257
258 if (!clk_alias || !clk_name)
259 return;
260
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700261 dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600262
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700263 r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600264 if (!IS_ERR(r)) {
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700265 dev_warn(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700266 "alias %s already exists\n", clk_alias);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600267 clk_put(r);
268 return;
269 }
270
271 r = omap_clk_get_by_name(clk_name);
272 if (IS_ERR(r)) {
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700273 dev_err(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700274 "omap_clk_get_by_name for %s failed\n", clk_name);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600275 return;
276 }
277
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700278 l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600279 if (!l) {
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700280 dev_err(&od->pdev->dev,
Kevin Hilman49882c92011-07-21 09:58:36 -0700281 "clkdev_alloc for %s failed\n", clk_alias);
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600282 return;
283 }
284
285 clkdev_add(l);
286}
287
Partha Basak4ef7aca2010-09-21 19:23:04 +0200288/**
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600289 * _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
290 * and main clock
Partha Basak4ef7aca2010-09-21 19:23:04 +0200291 * @od: struct omap_device *od
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600292 * @oh: struct omap_hwmod *oh
Partha Basak4ef7aca2010-09-21 19:23:04 +0200293 *
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600294 * For the main clock and every optional clock present per hwmod per
295 * omap_device, this function adds an entry in the clkdev table of the
296 * form <dev-id=dev_name, con-id=role> if it does not exist already.
Partha Basak4ef7aca2010-09-21 19:23:04 +0200297 *
298 * The function is called from inside omap_device_build_ss(), after
299 * omap_device_register.
300 *
301 * This allows drivers to get a pointer to its optional clocks based on its role
302 * by calling clk_get(<dev*>, <role>).
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600303 * In the case of the main clock, a "fck" alias is used.
Partha Basak4ef7aca2010-09-21 19:23:04 +0200304 *
305 * No return value.
306 */
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600307static void _add_hwmod_clocks_clkdev(struct omap_device *od,
308 struct omap_hwmod *oh)
Partha Basak4ef7aca2010-09-21 19:23:04 +0200309{
310 int i;
311
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600312 _add_clkdev(od, "fck", oh->main_clk);
Partha Basak4ef7aca2010-09-21 19:23:04 +0200313
Benoit Coussonbf1e0772011-07-10 05:54:12 -0600314 for (i = 0; i < oh->opt_clks_cnt; i++)
315 _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
Partha Basak4ef7aca2010-09-21 19:23:04 +0200316}
317
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300318
319/* Public functions for use by core code */
320
321/**
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700322 * omap_device_get_context_loss_count - get lost context count
323 * @od: struct omap_device *
324 *
325 * Using the primary hwmod, query the context loss count for this
326 * device.
327 *
328 * Callers should consider context for this device lost any time this
329 * function returns a value different than the value the caller got
330 * the last time it called this function.
331 *
332 * If any hwmods exist for the omap_device assoiated with @pdev,
333 * return the context loss counter for that hwmod, otherwise return
334 * zero.
335 */
336u32 omap_device_get_context_loss_count(struct platform_device *pdev)
337{
338 struct omap_device *od;
339 u32 ret = 0;
340
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600341 od = to_omap_device(pdev);
Kevin Hilmanc80705a2010-12-21 21:31:55 -0700342
343 if (od->hwmods_cnt)
344 ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
345
346 return ret;
347}
348
349/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300350 * omap_device_count_resources - count number of struct resource entries needed
351 * @od: struct omap_device *
352 *
353 * Count the number of struct resource entries needed for this
354 * omap_device @od. Used by omap_device_build_ss() to determine how
355 * much memory to allocate before calling
356 * omap_device_fill_resources(). Returns the count.
357 */
Kevin Hilmana2a28ad2011-07-21 14:14:35 -0700358static int omap_device_count_resources(struct omap_device *od)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300359{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300360 int c = 0;
361 int i;
362
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600363 for (i = 0; i < od->hwmods_cnt; i++)
364 c += omap_hwmod_count_resources(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300365
366 pr_debug("omap_device: %s: counted %d total resources across %d "
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700367 "hwmods\n", od->pdev->name, c, od->hwmods_cnt);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300368
369 return c;
370}
371
372/**
373 * omap_device_fill_resources - fill in array of struct resource
374 * @od: struct omap_device *
375 * @res: pointer to an array of struct resource to be filled in
376 *
377 * Populate one or more empty struct resource pointed to by @res with
378 * the resource data for this omap_device @od. Used by
379 * omap_device_build_ss() after calling omap_device_count_resources().
380 * Ideally this function would not be needed at all. If omap_device
381 * replaces platform_device, then we can specify our own
382 * get_resource()/ get_irq()/etc functions that use the underlying
383 * omap_hwmod information. Or if platform_device is extended to use
384 * subarchitecture-specific function pointers, the various
385 * platform_device functions can simply call omap_device internal
386 * functions to get device resources. Hacking around the existing
387 * platform_device code wastes memory. Returns 0.
388 */
Kevin Hilmana2a28ad2011-07-21 14:14:35 -0700389static int omap_device_fill_resources(struct omap_device *od,
390 struct resource *res)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300391{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300392 int c = 0;
393 int i, r;
394
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600395 for (i = 0; i < od->hwmods_cnt; i++) {
396 r = omap_hwmod_fill_resources(od->hwmods[i], res);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300397 res += r;
398 c += r;
399 }
400
401 return 0;
402}
403
404/**
Benoit Coussona4f6cdb2011-08-09 16:47:01 +0200405 * omap_device_alloc - allocate an omap_device
406 * @pdev: platform_device that will be included in this omap_device
407 * @oh: ptr to the single omap_hwmod that backs this omap_device
408 * @pdata: platform_data ptr to associate with the platform_device
409 * @pdata_len: amount of memory pointed to by @pdata
410 * @pm_lats: pointer to a omap_device_pm_latency array for this device
411 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
412 *
413 * Convenience function for allocating an omap_device structure and filling
414 * hwmods, resources and pm_latency attributes.
415 *
416 * Returns an struct omap_device pointer or ERR_PTR() on error;
417 */
418static struct omap_device *omap_device_alloc(struct platform_device *pdev,
419 struct omap_hwmod **ohs, int oh_cnt,
420 struct omap_device_pm_latency *pm_lats,
421 int pm_lats_cnt)
422{
423 int ret = -ENOMEM;
424 struct omap_device *od;
425 struct resource *res = NULL;
426 int i, res_count;
427 struct omap_hwmod **hwmods;
428
429 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
430 if (!od) {
431 ret = -ENOMEM;
432 goto oda_exit1;
433 }
434 od->hwmods_cnt = oh_cnt;
435
436 hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
437 if (!hwmods)
438 goto oda_exit2;
439
440 od->hwmods = hwmods;
441 od->pdev = pdev;
442
443 /*
444 * HACK: Ideally the resources from DT should match, and hwmod
445 * should just add the missing ones. Since the name is not
446 * properly populated by DT, stick to hwmod resources only.
447 */
448 if (pdev->num_resources && pdev->resource)
449 dev_warn(&pdev->dev, "%s(): resources already allocated %d\n",
450 __func__, pdev->num_resources);
451
452 res_count = omap_device_count_resources(od);
453 if (res_count > 0) {
454 dev_dbg(&pdev->dev, "%s(): resources allocated from hwmod %d\n",
455 __func__, res_count);
456 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
457 if (!res)
458 goto oda_exit3;
459
460 omap_device_fill_resources(od, res);
461
462 ret = platform_device_add_resources(pdev, res, res_count);
463 kfree(res);
464
465 if (ret)
466 goto oda_exit3;
467 }
468
469 if (!pm_lats) {
470 pm_lats = omap_default_latency;
471 pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
472 }
473
474 od->pm_lats_cnt = pm_lats_cnt;
475 od->pm_lats = kmemdup(pm_lats,
476 sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
477 GFP_KERNEL);
478 if (!od->pm_lats)
479 goto oda_exit3;
480
481 pdev->archdata.od = od;
482
483 for (i = 0; i < oh_cnt; i++) {
484 hwmods[i]->od = od;
485 _add_hwmod_clocks_clkdev(od, hwmods[i]);
486 }
487
488 return od;
489
490oda_exit3:
491 kfree(hwmods);
492oda_exit2:
493 kfree(od);
494oda_exit1:
495 dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
496
497 return ERR_PTR(ret);
498}
499
500static void omap_device_delete(struct omap_device *od)
501{
502 od->pdev->archdata.od = NULL;
503 kfree(od->pm_lats);
504 kfree(od->hwmods);
505 kfree(od);
506}
507
508/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300509 * omap_device_build - build and register an omap_device with one omap_hwmod
510 * @pdev_name: name of the platform_device driver to use
511 * @pdev_id: this platform_device's connection ID
512 * @oh: ptr to the single omap_hwmod that backs this omap_device
513 * @pdata: platform_data ptr to associate with the platform_device
514 * @pdata_len: amount of memory pointed to by @pdata
515 * @pm_lats: pointer to a omap_device_pm_latency array for this device
516 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700517 * @is_early_device: should the device be registered as an early device or not
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300518 *
519 * Convenience function for building and registering a single
520 * omap_device record, which in turn builds and registers a
521 * platform_device record. See omap_device_build_ss() for more
522 * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
523 * passes along the return value of omap_device_build_ss().
524 */
Kevin Hilman3528c582011-07-21 13:48:45 -0700525struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300526 struct omap_hwmod *oh, void *pdata,
527 int pdata_len,
528 struct omap_device_pm_latency *pm_lats,
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700529 int pm_lats_cnt, int is_early_device)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300530{
531 struct omap_hwmod *ohs[] = { oh };
532
533 if (!oh)
534 return ERR_PTR(-EINVAL);
535
536 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700537 pdata_len, pm_lats, pm_lats_cnt,
538 is_early_device);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300539}
540
541/**
542 * omap_device_build_ss - build and register an omap_device with multiple hwmods
543 * @pdev_name: name of the platform_device driver to use
544 * @pdev_id: this platform_device's connection ID
545 * @oh: ptr to the single omap_hwmod that backs this omap_device
546 * @pdata: platform_data ptr to associate with the platform_device
547 * @pdata_len: amount of memory pointed to by @pdata
548 * @pm_lats: pointer to a omap_device_pm_latency array for this device
549 * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700550 * @is_early_device: should the device be registered as an early device or not
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300551 *
552 * Convenience function for building and registering an omap_device
553 * subsystem record. Subsystem records consist of multiple
554 * omap_hwmods. This function in turn builds and registers a
555 * platform_device record. Returns an ERR_PTR() on error, or passes
556 * along the return value of omap_device_register().
557 */
Kevin Hilman3528c582011-07-21 13:48:45 -0700558struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300559 struct omap_hwmod **ohs, int oh_cnt,
560 void *pdata, int pdata_len,
561 struct omap_device_pm_latency *pm_lats,
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700562 int pm_lats_cnt, int is_early_device)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300563{
564 int ret = -ENOMEM;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700565 struct platform_device *pdev;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300566 struct omap_device *od;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300567
568 if (!ohs || oh_cnt == 0 || !pdev_name)
569 return ERR_PTR(-EINVAL);
570
571 if (!pdata && pdata_len > 0)
572 return ERR_PTR(-EINVAL);
573
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700574 pdev = platform_device_alloc(pdev_name, pdev_id);
575 if (!pdev) {
576 ret = -ENOMEM;
577 goto odbs_exit;
578 }
579
Benoit Coussona4f6cdb2011-08-09 16:47:01 +0200580 /* Set the dev_name early to allow dev_xxx in omap_device_alloc */
581 if (pdev->id != -1)
582 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
583 else
584 dev_set_name(&pdev->dev, "%s", pdev->name);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300585
Benoit Coussona4f6cdb2011-08-09 16:47:01 +0200586 od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
587 if (!od)
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700588 goto odbs_exit1;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300589
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700590 ret = platform_device_add_data(pdev, pdata, pdata_len);
Artem Bityutskiy49b368a2010-07-12 13:38:07 +0000591 if (ret)
Benoit Coussona4f6cdb2011-08-09 16:47:01 +0200592 goto odbs_exit2;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700593
594 if (is_early_device)
595 ret = omap_early_device_register(pdev);
596 else
597 ret = omap_device_register(pdev);
598 if (ret)
Benoit Coussona4f6cdb2011-08-09 16:47:01 +0200599 goto odbs_exit2;
Kevin Hilman06563582010-07-26 16:34:30 -0600600
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700601 return pdev;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300602
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700603odbs_exit2:
Benoit Coussona4f6cdb2011-08-09 16:47:01 +0200604 omap_device_delete(od);
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700605odbs_exit1:
606 platform_device_put(pdev);
607odbs_exit:
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300608
609 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
610
611 return ERR_PTR(ret);
612}
613
614/**
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700615 * omap_early_device_register - register an omap_device as an early platform
616 * device.
617 * @od: struct omap_device * to register
618 *
619 * Register the omap_device structure. This currently just calls
620 * platform_early_add_device() on the underlying platform_device.
621 * Returns 0 by default.
622 */
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700623static int omap_early_device_register(struct platform_device *pdev)
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700624{
625 struct platform_device *devices[1];
626
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700627 devices[0] = pdev;
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700628 early_platform_add_devices(devices, 1);
629 return 0;
630}
631
Kevin Hilman256a5432011-07-12 22:48:03 +0200632#ifdef CONFIG_PM_RUNTIME
Kevin Hilman638080c2011-04-29 00:36:42 +0200633static int _od_runtime_suspend(struct device *dev)
634{
635 struct platform_device *pdev = to_platform_device(dev);
Kevin Hilman345f79b2011-05-31 16:08:09 -0700636 int ret;
Kevin Hilman638080c2011-04-29 00:36:42 +0200637
Kevin Hilman345f79b2011-05-31 16:08:09 -0700638 ret = pm_generic_runtime_suspend(dev);
639
640 if (!ret)
641 omap_device_idle(pdev);
642
643 return ret;
644}
645
646static int _od_runtime_idle(struct device *dev)
647{
648 return pm_generic_runtime_idle(dev);
Kevin Hilman638080c2011-04-29 00:36:42 +0200649}
650
651static int _od_runtime_resume(struct device *dev)
652{
653 struct platform_device *pdev = to_platform_device(dev);
654
Kevin Hilman345f79b2011-05-31 16:08:09 -0700655 omap_device_enable(pdev);
656
657 return pm_generic_runtime_resume(dev);
Kevin Hilman638080c2011-04-29 00:36:42 +0200658}
Kevin Hilman256a5432011-07-12 22:48:03 +0200659#endif
Kevin Hilman638080c2011-04-29 00:36:42 +0200660
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200661#ifdef CONFIG_SUSPEND
662static int _od_suspend_noirq(struct device *dev)
663{
664 struct platform_device *pdev = to_platform_device(dev);
665 struct omap_device *od = to_omap_device(pdev);
666 int ret;
667
Kevin Hilman80c6d1e2011-07-12 22:48:29 +0200668 if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)
669 return pm_generic_suspend_noirq(dev);
670
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200671 ret = pm_generic_suspend_noirq(dev);
672
673 if (!ret && !pm_runtime_status_suspended(dev)) {
674 if (pm_generic_runtime_suspend(dev) == 0) {
675 omap_device_idle(pdev);
676 od->flags |= OMAP_DEVICE_SUSPENDED;
677 }
678 }
679
680 return ret;
681}
682
683static int _od_resume_noirq(struct device *dev)
684{
685 struct platform_device *pdev = to_platform_device(dev);
686 struct omap_device *od = to_omap_device(pdev);
687
Kevin Hilman80c6d1e2011-07-12 22:48:29 +0200688 if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)
689 return pm_generic_resume_noirq(dev);
690
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200691 if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
692 !pm_runtime_status_suspended(dev)) {
693 od->flags &= ~OMAP_DEVICE_SUSPENDED;
694 omap_device_enable(pdev);
695 pm_generic_runtime_resume(dev);
696 }
697
698 return pm_generic_resume_noirq(dev);
699}
Kevin Hilman126caf12011-09-01 10:59:36 -0700700#else
701#define _od_suspend_noirq NULL
702#define _od_resume_noirq NULL
Kevin Hilmanc03f0072011-07-12 22:48:19 +0200703#endif
704
Rafael J. Wysocki564b9052011-06-23 01:52:55 +0200705static struct dev_pm_domain omap_device_pm_domain = {
Kevin Hilman638080c2011-04-29 00:36:42 +0200706 .ops = {
Kevin Hilman256a5432011-07-12 22:48:03 +0200707 SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
708 _od_runtime_idle)
Kevin Hilman638080c2011-04-29 00:36:42 +0200709 USE_PLATFORM_PM_SLEEP_OPS
Kevin Hilmanff353362011-08-25 15:31:14 +0200710 .suspend_noirq = _od_suspend_noirq,
711 .resume_noirq = _od_resume_noirq,
Kevin Hilman638080c2011-04-29 00:36:42 +0200712 }
713};
714
Thara Gopinathc23a97d2010-02-24 12:05:58 -0700715/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300716 * omap_device_register - register an omap_device with one omap_hwmod
717 * @od: struct omap_device * to register
718 *
719 * Register the omap_device structure. This currently just calls
720 * platform_device_register() on the underlying platform_device.
721 * Returns the return value of platform_device_register().
722 */
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700723static int omap_device_register(struct platform_device *pdev)
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300724{
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700725 pr_debug("omap_device: %s: registering\n", pdev->name);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300726
Kevin Hilmanbfae4f82011-07-21 14:47:53 -0700727 pdev->dev.parent = &omap_device_parent;
728 pdev->dev.pm_domain = &omap_device_pm_domain;
Kevin Hilmand66b3fe2011-07-21 13:58:51 -0700729 return platform_device_add(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300730}
731
732
733/* Public functions for use by device drivers through struct platform_data */
734
735/**
736 * omap_device_enable - fully activate an omap_device
737 * @od: struct omap_device * to activate
738 *
739 * Do whatever is necessary for the hwmods underlying omap_device @od
740 * to be accessible and ready to operate. This generally involves
741 * enabling clocks, setting SYSCONFIG registers; and in the future may
742 * involve remuxing pins. Device drivers should call this function
743 * (through platform_data function pointers) where they would normally
744 * enable clocks, etc. Returns -EINVAL if called when the omap_device
745 * is already enabled, or passes along the return value of
746 * _omap_device_activate().
747 */
748int omap_device_enable(struct platform_device *pdev)
749{
750 int ret;
751 struct omap_device *od;
752
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600753 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300754
755 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
Kevin Hilman49882c92011-07-21 09:58:36 -0700756 dev_warn(&pdev->dev,
757 "omap_device: %s() called from invalid state %d\n",
758 __func__, od->_state);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300759 return -EINVAL;
760 }
761
762 /* Enable everything if we're enabling this device from scratch */
763 if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
764 od->pm_lat_level = od->pm_lats_cnt;
765
766 ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
767
768 od->dev_wakeup_lat = 0;
Kevin Hilman5f1b6ef2009-12-08 16:34:22 -0700769 od->_dev_wakeup_lat_limit = UINT_MAX;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300770 od->_state = OMAP_DEVICE_STATE_ENABLED;
771
772 return ret;
773}
774
775/**
776 * omap_device_idle - idle an omap_device
777 * @od: struct omap_device * to idle
778 *
779 * Idle omap_device @od by calling as many .deactivate_func() entries
780 * in the omap_device's pm_lats table as is possible without exceeding
781 * the device's maximum wakeup latency limit, pm_lat_limit. Device
782 * drivers should call this function (through platform_data function
783 * pointers) where they would normally disable clocks after operations
784 * complete, etc.. Returns -EINVAL if the omap_device is not
785 * currently enabled, or passes along the return value of
786 * _omap_device_deactivate().
787 */
788int omap_device_idle(struct platform_device *pdev)
789{
790 int ret;
791 struct omap_device *od;
792
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600793 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300794
795 if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
Kevin Hilman49882c92011-07-21 09:58:36 -0700796 dev_warn(&pdev->dev,
797 "omap_device: %s() called from invalid state %d\n",
798 __func__, od->_state);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300799 return -EINVAL;
800 }
801
802 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
803
804 od->_state = OMAP_DEVICE_STATE_IDLE;
805
806 return ret;
807}
808
809/**
810 * omap_device_shutdown - shut down an omap_device
811 * @od: struct omap_device * to shut down
812 *
813 * Shut down omap_device @od by calling all .deactivate_func() entries
814 * in the omap_device's pm_lats table and then shutting down all of
815 * the underlying omap_hwmods. Used when a device is being "removed"
816 * or a device driver is being unloaded. Returns -EINVAL if the
817 * omap_device is not currently enabled or idle, or passes along the
818 * return value of _omap_device_deactivate().
819 */
820int omap_device_shutdown(struct platform_device *pdev)
821{
822 int ret, i;
823 struct omap_device *od;
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300824
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600825 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300826
827 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
828 od->_state != OMAP_DEVICE_STATE_IDLE) {
Kevin Hilman49882c92011-07-21 09:58:36 -0700829 dev_warn(&pdev->dev,
830 "omap_device: %s() called from invalid state %d\n",
831 __func__, od->_state);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300832 return -EINVAL;
833 }
834
835 ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
836
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600837 for (i = 0; i < od->hwmods_cnt; i++)
838 omap_hwmod_shutdown(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300839
840 od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
841
842 return ret;
843}
844
845/**
846 * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim
847 * @od: struct omap_device *
848 *
849 * When a device's maximum wakeup latency limit changes, call some of
850 * the .activate_func or .deactivate_func function pointers in the
851 * omap_device's pm_lats array to ensure that the device's maximum
852 * wakeup latency is less than or equal to the new latency limit.
853 * Intended to be called by OMAP PM code whenever a device's maximum
854 * wakeup latency limit changes (e.g., via
855 * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be
856 * done (e.g., if the omap_device is not currently idle, or if the
857 * wakeup latency is already current with the new limit) or passes
858 * along the return value of _omap_device_deactivate() or
859 * _omap_device_activate().
860 */
861int omap_device_align_pm_lat(struct platform_device *pdev,
862 u32 new_wakeup_lat_limit)
863{
864 int ret = -EINVAL;
865 struct omap_device *od;
866
Kevin Hilman8f0d69d2011-07-09 19:15:20 -0600867 od = to_omap_device(pdev);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300868
869 if (new_wakeup_lat_limit == od->dev_wakeup_lat)
870 return 0;
871
872 od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
873
874 if (od->_state != OMAP_DEVICE_STATE_IDLE)
875 return 0;
876 else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
877 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
878 else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
879 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
880
881 return ret;
882}
883
884/**
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300885 * omap_device_get_pwrdm - return the powerdomain * associated with @od
886 * @od: struct omap_device *
887 *
888 * Return the powerdomain associated with the first underlying
889 * omap_hwmod for this omap_device. Intended for use by core OMAP PM
890 * code. Returns NULL on error or a struct powerdomain * upon
891 * success.
892 */
893struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
894{
895 /*
896 * XXX Assumes that all omap_hwmod powerdomains are identical.
897 * This may not necessarily be true. There should be a sanity
898 * check in here to WARN() if any difference appears.
899 */
900 if (!od->hwmods_cnt)
901 return NULL;
902
903 return omap_hwmod_get_pwrdm(od->hwmods[0]);
904}
905
Paul Walmsleydb2a60b2010-07-26 16:34:33 -0600906/**
907 * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base
908 * @od: struct omap_device *
909 *
910 * Return the MPU's virtual address for the base of the hwmod, from
911 * the ioremap() that the hwmod code does. Only valid if there is one
912 * hwmod associated with this device. Returns NULL if there are zero
913 * or more than one hwmods associated with this omap_device;
914 * otherwise, passes along the return value from
915 * omap_hwmod_get_mpu_rt_va().
916 */
917void __iomem *omap_device_get_rt_va(struct omap_device *od)
918{
919 if (od->hwmods_cnt != 1)
920 return NULL;
921
922 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
923}
924
Nishanth Menon1f8a7d52011-07-27 15:02:32 -0500925/**
926 * omap_device_get_by_hwmod_name() - convert a hwmod name to
927 * device pointer.
928 * @oh_name: name of the hwmod device
929 *
930 * Returns back a struct device * pointer associated with a hwmod
931 * device represented by a hwmod_name
932 */
933struct device *omap_device_get_by_hwmod_name(const char *oh_name)
934{
935 struct omap_hwmod *oh;
936
937 if (!oh_name) {
938 WARN(1, "%s: no hwmod name!\n", __func__);
939 return ERR_PTR(-EINVAL);
940 }
941
942 oh = omap_hwmod_lookup(oh_name);
943 if (IS_ERR_OR_NULL(oh)) {
944 WARN(1, "%s: no hwmod for %s\n", __func__,
945 oh_name);
946 return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
947 }
948 if (IS_ERR_OR_NULL(oh->od)) {
949 WARN(1, "%s: no omap_device for %s\n", __func__,
950 oh_name);
951 return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
952 }
953
954 if (IS_ERR_OR_NULL(oh->od->pdev))
955 return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
956
957 return &oh->od->pdev->dev;
958}
959EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
960
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300961/*
962 * Public functions intended for use in omap_device_pm_latency
963 * .activate_func and .deactivate_func function pointers
964 */
965
966/**
967 * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
968 * @od: struct omap_device *od
969 *
970 * Enable all underlying hwmods. Returns 0.
971 */
972int omap_device_enable_hwmods(struct omap_device *od)
973{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300974 int i;
975
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600976 for (i = 0; i < od->hwmods_cnt; i++)
977 omap_hwmod_enable(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300978
979 /* XXX pass along return value here? */
980 return 0;
981}
982
983/**
984 * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
985 * @od: struct omap_device *od
986 *
987 * Idle all underlying hwmods. Returns 0.
988 */
989int omap_device_idle_hwmods(struct omap_device *od)
990{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300991 int i;
992
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -0600993 for (i = 0; i < od->hwmods_cnt; i++)
994 omap_hwmod_idle(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +0300995
996 /* XXX pass along return value here? */
997 return 0;
998}
999
1000/**
1001 * omap_device_disable_clocks - disable all main and interface clocks
1002 * @od: struct omap_device *od
1003 *
1004 * Disable the main functional clock and interface clock for all of the
1005 * omap_hwmods associated with the omap_device. Returns 0.
1006 */
1007int omap_device_disable_clocks(struct omap_device *od)
1008{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03001009 int i;
1010
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -06001011 for (i = 0; i < od->hwmods_cnt; i++)
1012 omap_hwmod_disable_clocks(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03001013
1014 /* XXX pass along return value here? */
1015 return 0;
1016}
1017
1018/**
1019 * omap_device_enable_clocks - enable all main and interface clocks
1020 * @od: struct omap_device *od
1021 *
1022 * Enable the main functional clock and interface clock for all of the
1023 * omap_hwmods associated with the omap_device. Returns 0.
1024 */
1025int omap_device_enable_clocks(struct omap_device *od)
1026{
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03001027 int i;
1028
Kishon Vijay Abraham If39f4892010-09-24 10:23:18 -06001029 for (i = 0; i < od->hwmods_cnt; i++)
1030 omap_hwmod_enable_clocks(od->hwmods[i]);
Paul Walmsleyb04b65a2009-09-03 20:14:05 +03001031
1032 /* XXX pass along return value here? */
1033 return 0;
1034}
Kevin Hilman0d5e8252010-08-23 08:10:55 -07001035
1036struct device omap_device_parent = {
1037 .init_name = "omap",
1038 .parent = &platform_bus,
1039};
1040
1041static int __init omap_device_init(void)
1042{
1043 return device_register(&omap_device_parent);
1044}
1045core_initcall(omap_device_init);