Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1 | /* |
| 2 | * omap_device implementation |
| 3 | * |
Paul Walmsley | 887adea | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Nokia Corporation |
Paul Walmsley | 4788da2 | 2010-05-18 20:24:05 -0600 | [diff] [blame] | 5 | * Paul Walmsley, Kevin Hilman |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 6 | * |
| 7 | * Developed in collaboration with (alphabetical order): Benoit |
Paul Walmsley | 4788da2 | 2010-05-18 20:24:05 -0600 | [diff] [blame] | 8 | * Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 9 | * 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 82 | #include <linux/slab.h> |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 83 | #include <linux/err.h> |
| 84 | #include <linux/io.h> |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 85 | #include <linux/clk.h> |
Rajendra Nayak | da0653f | 2011-02-25 15:40:21 -0700 | [diff] [blame] | 86 | #include <linux/clkdev.h> |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 87 | #include <linux/pm_runtime.h> |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 88 | #include <linux/of.h> |
| 89 | #include <linux/notifier.h> |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 90 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 91 | #include <plat/omap_device.h> |
| 92 | #include <plat/omap_hwmod.h> |
Rajendra Nayak | da0653f | 2011-02-25 15:40:21 -0700 | [diff] [blame] | 93 | #include <plat/clock.h> |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 94 | |
| 95 | /* These parameters are passed to _omap_device_{de,}activate() */ |
| 96 | #define USE_WAKEUP_LAT 0 |
| 97 | #define IGNORE_WAKEUP_LAT 1 |
| 98 | |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 99 | static int omap_device_register(struct platform_device *pdev); |
| 100 | static int omap_early_device_register(struct platform_device *pdev); |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 101 | static struct omap_device *omap_device_alloc(struct platform_device *pdev, |
| 102 | struct omap_hwmod **ohs, int oh_cnt, |
| 103 | struct omap_device_pm_latency *pm_lats, |
| 104 | int pm_lats_cnt); |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 105 | static void omap_device_delete(struct omap_device *od); |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 106 | |
Kevin Hilman | a2a28ad | 2011-07-21 14:14:35 -0700 | [diff] [blame] | 107 | |
Benoit Cousson | b7b5bc9 | 2011-08-09 16:54:19 +0200 | [diff] [blame] | 108 | static struct omap_device_pm_latency omap_default_latency[] = { |
| 109 | { |
| 110 | .deactivate_func = omap_device_idle_hwmods, |
| 111 | .activate_func = omap_device_enable_hwmods, |
| 112 | .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST, |
| 113 | } |
| 114 | }; |
| 115 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 116 | /* Private functions */ |
| 117 | |
| 118 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 119 | * _omap_device_activate - increase device readiness |
| 120 | * @od: struct omap_device * |
| 121 | * @ignore_lat: increase to latency target (0) or full readiness (1)? |
| 122 | * |
| 123 | * Increase readiness of omap_device @od (thus decreasing device |
| 124 | * wakeup latency, but consuming more power). If @ignore_lat is |
| 125 | * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise, |
| 126 | * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup |
| 127 | * latency is greater than the requested maximum wakeup latency, step |
| 128 | * backwards in the omap_device_pm_latency table to ensure the |
| 129 | * device's maximum wakeup latency is less than or equal to the |
| 130 | * requested maximum wakeup latency. Returns 0. |
| 131 | */ |
| 132 | static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) |
| 133 | { |
Tony Lindgren | f059429 | 2009-10-19 15:25:24 -0700 | [diff] [blame] | 134 | struct timespec a, b, c; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 135 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 136 | dev_dbg(&od->pdev->dev, "omap_device: activating\n"); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 137 | |
| 138 | while (od->pm_lat_level > 0) { |
| 139 | struct omap_device_pm_latency *odpl; |
Tony Lindgren | f059429 | 2009-10-19 15:25:24 -0700 | [diff] [blame] | 140 | unsigned long long act_lat = 0; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 141 | |
| 142 | od->pm_lat_level--; |
| 143 | |
| 144 | odpl = od->pm_lats + od->pm_lat_level; |
| 145 | |
| 146 | if (!ignore_lat && |
| 147 | (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit)) |
| 148 | break; |
| 149 | |
Kevin Hilman | d229266 | 2009-12-08 16:34:23 -0700 | [diff] [blame] | 150 | read_persistent_clock(&a); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 151 | |
| 152 | /* XXX check return code */ |
| 153 | odpl->activate_func(od); |
| 154 | |
Kevin Hilman | d229266 | 2009-12-08 16:34:23 -0700 | [diff] [blame] | 155 | read_persistent_clock(&b); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 156 | |
Tony Lindgren | f059429 | 2009-10-19 15:25:24 -0700 | [diff] [blame] | 157 | c = timespec_sub(b, a); |
Kevin Hilman | 0d93d8b | 2009-12-08 16:34:26 -0700 | [diff] [blame] | 158 | act_lat = timespec_to_ns(&c); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 159 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 160 | dev_dbg(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 161 | "omap_device: pm_lat %d: activate: elapsed time " |
| 162 | "%llu nsec\n", od->pm_lat_level, act_lat); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 163 | |
Kevin Hilman | 9799aca | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 164 | if (act_lat > odpl->activate_lat) { |
| 165 | odpl->activate_lat_worst = act_lat; |
| 166 | if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { |
| 167 | odpl->activate_lat = act_lat; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 168 | dev_dbg(&od->pdev->dev, |
Grazvydas Ignotas | 47c3e5d | 2011-07-25 16:18:24 +0300 | [diff] [blame] | 169 | "new worst case activate latency " |
| 170 | "%d: %llu\n", |
| 171 | od->pm_lat_level, act_lat); |
Kevin Hilman | 9799aca | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 172 | } else |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 173 | dev_warn(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 174 | "activate latency %d " |
| 175 | "higher than exptected. (%llu > %d)\n", |
| 176 | od->pm_lat_level, act_lat, |
| 177 | odpl->activate_lat); |
Kevin Hilman | 9799aca | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 178 | } |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 179 | |
| 180 | od->dev_wakeup_lat -= odpl->activate_lat; |
| 181 | } |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * _omap_device_deactivate - decrease device readiness |
| 188 | * @od: struct omap_device * |
| 189 | * @ignore_lat: decrease to latency target (0) or full inactivity (1)? |
| 190 | * |
| 191 | * Decrease readiness of omap_device @od (thus increasing device |
| 192 | * wakeup latency, but conserving power). If @ignore_lat is |
| 193 | * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise, |
| 194 | * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup |
| 195 | * latency is less than the requested maximum wakeup latency, step |
| 196 | * forwards in the omap_device_pm_latency table to ensure the device's |
| 197 | * maximum wakeup latency is less than or equal to the requested |
| 198 | * maximum wakeup latency. Returns 0. |
| 199 | */ |
| 200 | static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) |
| 201 | { |
Tony Lindgren | f059429 | 2009-10-19 15:25:24 -0700 | [diff] [blame] | 202 | struct timespec a, b, c; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 203 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 204 | dev_dbg(&od->pdev->dev, "omap_device: deactivating\n"); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 205 | |
| 206 | while (od->pm_lat_level < od->pm_lats_cnt) { |
| 207 | struct omap_device_pm_latency *odpl; |
Tony Lindgren | f059429 | 2009-10-19 15:25:24 -0700 | [diff] [blame] | 208 | unsigned long long deact_lat = 0; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 209 | |
| 210 | odpl = od->pm_lats + od->pm_lat_level; |
| 211 | |
| 212 | if (!ignore_lat && |
| 213 | ((od->dev_wakeup_lat + odpl->activate_lat) > |
| 214 | od->_dev_wakeup_lat_limit)) |
| 215 | break; |
| 216 | |
Kevin Hilman | d229266 | 2009-12-08 16:34:23 -0700 | [diff] [blame] | 217 | read_persistent_clock(&a); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 218 | |
| 219 | /* XXX check return code */ |
| 220 | odpl->deactivate_func(od); |
| 221 | |
Kevin Hilman | d229266 | 2009-12-08 16:34:23 -0700 | [diff] [blame] | 222 | read_persistent_clock(&b); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 223 | |
Tony Lindgren | f059429 | 2009-10-19 15:25:24 -0700 | [diff] [blame] | 224 | c = timespec_sub(b, a); |
Kevin Hilman | 0d93d8b | 2009-12-08 16:34:26 -0700 | [diff] [blame] | 225 | deact_lat = timespec_to_ns(&c); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 226 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 227 | dev_dbg(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 228 | "omap_device: pm_lat %d: deactivate: elapsed time " |
| 229 | "%llu nsec\n", od->pm_lat_level, deact_lat); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 230 | |
Kevin Hilman | 9799aca | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 231 | if (deact_lat > odpl->deactivate_lat) { |
| 232 | odpl->deactivate_lat_worst = deact_lat; |
| 233 | if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { |
| 234 | odpl->deactivate_lat = deact_lat; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 235 | dev_dbg(&od->pdev->dev, |
Grazvydas Ignotas | 47c3e5d | 2011-07-25 16:18:24 +0300 | [diff] [blame] | 236 | "new worst case deactivate latency " |
| 237 | "%d: %llu\n", |
| 238 | od->pm_lat_level, deact_lat); |
Kevin Hilman | 9799aca | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 239 | } else |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 240 | dev_warn(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 241 | "deactivate latency %d " |
| 242 | "higher than exptected. (%llu > %d)\n", |
| 243 | od->pm_lat_level, deact_lat, |
| 244 | odpl->deactivate_lat); |
Kevin Hilman | 9799aca | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 247 | od->dev_wakeup_lat += odpl->activate_lat; |
| 248 | |
| 249 | od->pm_lat_level++; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 255 | static void _add_clkdev(struct omap_device *od, const char *clk_alias, |
| 256 | const char *clk_name) |
| 257 | { |
| 258 | struct clk *r; |
| 259 | struct clk_lookup *l; |
| 260 | |
| 261 | if (!clk_alias || !clk_name) |
| 262 | return; |
| 263 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 264 | dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name); |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 265 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 266 | r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias); |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 267 | if (!IS_ERR(r)) { |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 268 | dev_warn(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 269 | "alias %s already exists\n", clk_alias); |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 270 | clk_put(r); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | r = omap_clk_get_by_name(clk_name); |
| 275 | if (IS_ERR(r)) { |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 276 | dev_err(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 277 | "omap_clk_get_by_name for %s failed\n", clk_name); |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 281 | l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev)); |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 282 | if (!l) { |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 283 | dev_err(&od->pdev->dev, |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 284 | "clkdev_alloc for %s failed\n", clk_alias); |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 285 | return; |
| 286 | } |
| 287 | |
| 288 | clkdev_add(l); |
| 289 | } |
| 290 | |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 291 | /** |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 292 | * _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks |
| 293 | * and main clock |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 294 | * @od: struct omap_device *od |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 295 | * @oh: struct omap_hwmod *oh |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 296 | * |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 297 | * For the main clock and every optional clock present per hwmod per |
| 298 | * omap_device, this function adds an entry in the clkdev table of the |
| 299 | * form <dev-id=dev_name, con-id=role> if it does not exist already. |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 300 | * |
| 301 | * The function is called from inside omap_device_build_ss(), after |
| 302 | * omap_device_register. |
| 303 | * |
| 304 | * This allows drivers to get a pointer to its optional clocks based on its role |
| 305 | * by calling clk_get(<dev*>, <role>). |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 306 | * In the case of the main clock, a "fck" alias is used. |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 307 | * |
| 308 | * No return value. |
| 309 | */ |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 310 | static void _add_hwmod_clocks_clkdev(struct omap_device *od, |
| 311 | struct omap_hwmod *oh) |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 312 | { |
| 313 | int i; |
| 314 | |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 315 | _add_clkdev(od, "fck", oh->main_clk); |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 316 | |
Benoit Cousson | bf1e077 | 2011-07-10 05:54:12 -0600 | [diff] [blame] | 317 | for (i = 0; i < oh->opt_clks_cnt; i++) |
| 318 | _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk); |
Partha Basak | 4ef7aca | 2010-09-21 19:23:04 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 321 | |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 322 | static struct dev_pm_domain omap_device_pm_domain; |
| 323 | |
| 324 | /** |
| 325 | * omap_device_build_from_dt - build an omap_device with multiple hwmods |
| 326 | * @pdev_name: name of the platform_device driver to use |
| 327 | * @pdev_id: this platform_device's connection ID |
| 328 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 329 | * @pdata: platform_data ptr to associate with the platform_device |
| 330 | * @pdata_len: amount of memory pointed to by @pdata |
| 331 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 332 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
| 333 | * @is_early_device: should the device be registered as an early device or not |
| 334 | * |
| 335 | * Function for building an omap_device already registered from device-tree |
| 336 | * |
| 337 | * Returns 0 or PTR_ERR() on error. |
| 338 | */ |
| 339 | static int omap_device_build_from_dt(struct platform_device *pdev) |
| 340 | { |
| 341 | struct omap_hwmod **hwmods; |
| 342 | struct omap_device *od; |
| 343 | struct omap_hwmod *oh; |
| 344 | struct device_node *node = pdev->dev.of_node; |
| 345 | const char *oh_name; |
| 346 | int oh_cnt, i, ret = 0; |
| 347 | |
| 348 | oh_cnt = of_property_count_strings(node, "ti,hwmods"); |
| 349 | if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) { |
| 350 | dev_warn(&pdev->dev, "No 'hwmods' to build omap_device\n"); |
| 351 | return -ENODEV; |
| 352 | } |
| 353 | |
| 354 | hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); |
| 355 | if (!hwmods) { |
| 356 | ret = -ENOMEM; |
| 357 | goto odbfd_exit; |
| 358 | } |
| 359 | |
| 360 | for (i = 0; i < oh_cnt; i++) { |
| 361 | of_property_read_string_index(node, "ti,hwmods", i, &oh_name); |
| 362 | oh = omap_hwmod_lookup(oh_name); |
| 363 | if (!oh) { |
| 364 | dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n", |
| 365 | oh_name); |
| 366 | ret = -EINVAL; |
| 367 | goto odbfd_exit1; |
| 368 | } |
| 369 | hwmods[i] = oh; |
| 370 | } |
| 371 | |
| 372 | od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0); |
| 373 | if (!od) { |
| 374 | dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n", |
| 375 | oh_name); |
| 376 | ret = PTR_ERR(od); |
| 377 | goto odbfd_exit1; |
| 378 | } |
| 379 | |
| 380 | if (of_get_property(node, "ti,no_idle_on_suspend", NULL)) |
| 381 | omap_device_disable_idle_on_suspend(pdev); |
| 382 | |
| 383 | pdev->dev.pm_domain = &omap_device_pm_domain; |
| 384 | |
| 385 | odbfd_exit1: |
| 386 | kfree(hwmods); |
| 387 | odbfd_exit: |
| 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | static int _omap_device_notifier_call(struct notifier_block *nb, |
| 392 | unsigned long event, void *dev) |
| 393 | { |
| 394 | struct platform_device *pdev = to_platform_device(dev); |
| 395 | |
| 396 | switch (event) { |
| 397 | case BUS_NOTIFY_ADD_DEVICE: |
| 398 | if (pdev->dev.of_node) |
| 399 | omap_device_build_from_dt(pdev); |
| 400 | break; |
| 401 | |
| 402 | case BUS_NOTIFY_DEL_DEVICE: |
| 403 | if (pdev->archdata.od) |
| 404 | omap_device_delete(pdev->archdata.od); |
| 405 | break; |
| 406 | } |
| 407 | |
| 408 | return NOTIFY_DONE; |
| 409 | } |
| 410 | |
| 411 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 412 | /* Public functions for use by core code */ |
| 413 | |
| 414 | /** |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 415 | * omap_device_get_context_loss_count - get lost context count |
| 416 | * @od: struct omap_device * |
| 417 | * |
| 418 | * Using the primary hwmod, query the context loss count for this |
| 419 | * device. |
| 420 | * |
| 421 | * Callers should consider context for this device lost any time this |
| 422 | * function returns a value different than the value the caller got |
| 423 | * the last time it called this function. |
| 424 | * |
| 425 | * If any hwmods exist for the omap_device assoiated with @pdev, |
| 426 | * return the context loss counter for that hwmod, otherwise return |
| 427 | * zero. |
| 428 | */ |
| 429 | u32 omap_device_get_context_loss_count(struct platform_device *pdev) |
| 430 | { |
| 431 | struct omap_device *od; |
| 432 | u32 ret = 0; |
| 433 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 434 | od = to_omap_device(pdev); |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 435 | |
| 436 | if (od->hwmods_cnt) |
| 437 | ret = omap_hwmod_get_context_loss_count(od->hwmods[0]); |
| 438 | |
| 439 | return ret; |
| 440 | } |
| 441 | |
| 442 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 443 | * omap_device_count_resources - count number of struct resource entries needed |
| 444 | * @od: struct omap_device * |
| 445 | * |
| 446 | * Count the number of struct resource entries needed for this |
| 447 | * omap_device @od. Used by omap_device_build_ss() to determine how |
| 448 | * much memory to allocate before calling |
| 449 | * omap_device_fill_resources(). Returns the count. |
| 450 | */ |
Kevin Hilman | a2a28ad | 2011-07-21 14:14:35 -0700 | [diff] [blame] | 451 | static int omap_device_count_resources(struct omap_device *od) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 452 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 453 | int c = 0; |
| 454 | int i; |
| 455 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 456 | for (i = 0; i < od->hwmods_cnt; i++) |
| 457 | c += omap_hwmod_count_resources(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 458 | |
| 459 | pr_debug("omap_device: %s: counted %d total resources across %d " |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 460 | "hwmods\n", od->pdev->name, c, od->hwmods_cnt); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 461 | |
| 462 | return c; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * omap_device_fill_resources - fill in array of struct resource |
| 467 | * @od: struct omap_device * |
| 468 | * @res: pointer to an array of struct resource to be filled in |
| 469 | * |
| 470 | * Populate one or more empty struct resource pointed to by @res with |
| 471 | * the resource data for this omap_device @od. Used by |
| 472 | * omap_device_build_ss() after calling omap_device_count_resources(). |
| 473 | * Ideally this function would not be needed at all. If omap_device |
| 474 | * replaces platform_device, then we can specify our own |
| 475 | * get_resource()/ get_irq()/etc functions that use the underlying |
| 476 | * omap_hwmod information. Or if platform_device is extended to use |
| 477 | * subarchitecture-specific function pointers, the various |
| 478 | * platform_device functions can simply call omap_device internal |
| 479 | * functions to get device resources. Hacking around the existing |
| 480 | * platform_device code wastes memory. Returns 0. |
| 481 | */ |
Kevin Hilman | a2a28ad | 2011-07-21 14:14:35 -0700 | [diff] [blame] | 482 | static int omap_device_fill_resources(struct omap_device *od, |
| 483 | struct resource *res) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 484 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 485 | int c = 0; |
| 486 | int i, r; |
| 487 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 488 | for (i = 0; i < od->hwmods_cnt; i++) { |
| 489 | r = omap_hwmod_fill_resources(od->hwmods[i], res); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 490 | res += r; |
| 491 | c += r; |
| 492 | } |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | /** |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 498 | * omap_device_alloc - allocate an omap_device |
| 499 | * @pdev: platform_device that will be included in this omap_device |
| 500 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 501 | * @pdata: platform_data ptr to associate with the platform_device |
| 502 | * @pdata_len: amount of memory pointed to by @pdata |
| 503 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 504 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
| 505 | * |
| 506 | * Convenience function for allocating an omap_device structure and filling |
| 507 | * hwmods, resources and pm_latency attributes. |
| 508 | * |
| 509 | * Returns an struct omap_device pointer or ERR_PTR() on error; |
| 510 | */ |
| 511 | static struct omap_device *omap_device_alloc(struct platform_device *pdev, |
| 512 | struct omap_hwmod **ohs, int oh_cnt, |
| 513 | struct omap_device_pm_latency *pm_lats, |
| 514 | int pm_lats_cnt) |
| 515 | { |
| 516 | int ret = -ENOMEM; |
| 517 | struct omap_device *od; |
| 518 | struct resource *res = NULL; |
| 519 | int i, res_count; |
| 520 | struct omap_hwmod **hwmods; |
| 521 | |
| 522 | od = kzalloc(sizeof(struct omap_device), GFP_KERNEL); |
| 523 | if (!od) { |
| 524 | ret = -ENOMEM; |
| 525 | goto oda_exit1; |
| 526 | } |
| 527 | od->hwmods_cnt = oh_cnt; |
| 528 | |
| 529 | hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); |
| 530 | if (!hwmods) |
| 531 | goto oda_exit2; |
| 532 | |
| 533 | od->hwmods = hwmods; |
| 534 | od->pdev = pdev; |
| 535 | |
| 536 | /* |
| 537 | * HACK: Ideally the resources from DT should match, and hwmod |
| 538 | * should just add the missing ones. Since the name is not |
| 539 | * properly populated by DT, stick to hwmod resources only. |
| 540 | */ |
| 541 | if (pdev->num_resources && pdev->resource) |
| 542 | dev_warn(&pdev->dev, "%s(): resources already allocated %d\n", |
| 543 | __func__, pdev->num_resources); |
| 544 | |
| 545 | res_count = omap_device_count_resources(od); |
| 546 | if (res_count > 0) { |
| 547 | dev_dbg(&pdev->dev, "%s(): resources allocated from hwmod %d\n", |
| 548 | __func__, res_count); |
| 549 | res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL); |
| 550 | if (!res) |
| 551 | goto oda_exit3; |
| 552 | |
| 553 | omap_device_fill_resources(od, res); |
| 554 | |
| 555 | ret = platform_device_add_resources(pdev, res, res_count); |
| 556 | kfree(res); |
| 557 | |
| 558 | if (ret) |
| 559 | goto oda_exit3; |
| 560 | } |
| 561 | |
| 562 | if (!pm_lats) { |
| 563 | pm_lats = omap_default_latency; |
| 564 | pm_lats_cnt = ARRAY_SIZE(omap_default_latency); |
| 565 | } |
| 566 | |
| 567 | od->pm_lats_cnt = pm_lats_cnt; |
| 568 | od->pm_lats = kmemdup(pm_lats, |
| 569 | sizeof(struct omap_device_pm_latency) * pm_lats_cnt, |
| 570 | GFP_KERNEL); |
| 571 | if (!od->pm_lats) |
| 572 | goto oda_exit3; |
| 573 | |
| 574 | pdev->archdata.od = od; |
| 575 | |
| 576 | for (i = 0; i < oh_cnt; i++) { |
| 577 | hwmods[i]->od = od; |
| 578 | _add_hwmod_clocks_clkdev(od, hwmods[i]); |
| 579 | } |
| 580 | |
| 581 | return od; |
| 582 | |
| 583 | oda_exit3: |
| 584 | kfree(hwmods); |
| 585 | oda_exit2: |
| 586 | kfree(od); |
| 587 | oda_exit1: |
| 588 | dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret); |
| 589 | |
| 590 | return ERR_PTR(ret); |
| 591 | } |
| 592 | |
| 593 | static void omap_device_delete(struct omap_device *od) |
| 594 | { |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 595 | if (!od) |
| 596 | return; |
| 597 | |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 598 | od->pdev->archdata.od = NULL; |
| 599 | kfree(od->pm_lats); |
| 600 | kfree(od->hwmods); |
| 601 | kfree(od); |
| 602 | } |
| 603 | |
| 604 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 605 | * omap_device_build - build and register an omap_device with one omap_hwmod |
| 606 | * @pdev_name: name of the platform_device driver to use |
| 607 | * @pdev_id: this platform_device's connection ID |
| 608 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 609 | * @pdata: platform_data ptr to associate with the platform_device |
| 610 | * @pdata_len: amount of memory pointed to by @pdata |
| 611 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 612 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 613 | * @is_early_device: should the device be registered as an early device or not |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 614 | * |
| 615 | * Convenience function for building and registering a single |
| 616 | * omap_device record, which in turn builds and registers a |
| 617 | * platform_device record. See omap_device_build_ss() for more |
| 618 | * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise, |
| 619 | * passes along the return value of omap_device_build_ss(). |
| 620 | */ |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 621 | struct platform_device *omap_device_build(const char *pdev_name, int pdev_id, |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 622 | struct omap_hwmod *oh, void *pdata, |
| 623 | int pdata_len, |
| 624 | struct omap_device_pm_latency *pm_lats, |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 625 | int pm_lats_cnt, int is_early_device) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 626 | { |
| 627 | struct omap_hwmod *ohs[] = { oh }; |
| 628 | |
| 629 | if (!oh) |
| 630 | return ERR_PTR(-EINVAL); |
| 631 | |
| 632 | return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata, |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 633 | pdata_len, pm_lats, pm_lats_cnt, |
| 634 | is_early_device); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /** |
| 638 | * omap_device_build_ss - build and register an omap_device with multiple hwmods |
| 639 | * @pdev_name: name of the platform_device driver to use |
| 640 | * @pdev_id: this platform_device's connection ID |
| 641 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 642 | * @pdata: platform_data ptr to associate with the platform_device |
| 643 | * @pdata_len: amount of memory pointed to by @pdata |
| 644 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 645 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 646 | * @is_early_device: should the device be registered as an early device or not |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 647 | * |
| 648 | * Convenience function for building and registering an omap_device |
| 649 | * subsystem record. Subsystem records consist of multiple |
| 650 | * omap_hwmods. This function in turn builds and registers a |
| 651 | * platform_device record. Returns an ERR_PTR() on error, or passes |
| 652 | * along the return value of omap_device_register(). |
| 653 | */ |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 654 | struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id, |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 655 | struct omap_hwmod **ohs, int oh_cnt, |
| 656 | void *pdata, int pdata_len, |
| 657 | struct omap_device_pm_latency *pm_lats, |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 658 | int pm_lats_cnt, int is_early_device) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 659 | { |
| 660 | int ret = -ENOMEM; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 661 | struct platform_device *pdev; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 662 | struct omap_device *od; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 663 | |
| 664 | if (!ohs || oh_cnt == 0 || !pdev_name) |
| 665 | return ERR_PTR(-EINVAL); |
| 666 | |
| 667 | if (!pdata && pdata_len > 0) |
| 668 | return ERR_PTR(-EINVAL); |
| 669 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 670 | pdev = platform_device_alloc(pdev_name, pdev_id); |
| 671 | if (!pdev) { |
| 672 | ret = -ENOMEM; |
| 673 | goto odbs_exit; |
| 674 | } |
| 675 | |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 676 | /* Set the dev_name early to allow dev_xxx in omap_device_alloc */ |
| 677 | if (pdev->id != -1) |
| 678 | dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); |
| 679 | else |
| 680 | dev_set_name(&pdev->dev, "%s", pdev->name); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 681 | |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 682 | od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt); |
| 683 | if (!od) |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 684 | goto odbs_exit1; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 685 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 686 | ret = platform_device_add_data(pdev, pdata, pdata_len); |
Artem Bityutskiy | 49b368a | 2010-07-12 13:38:07 +0000 | [diff] [blame] | 687 | if (ret) |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 688 | goto odbs_exit2; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 689 | |
| 690 | if (is_early_device) |
| 691 | ret = omap_early_device_register(pdev); |
| 692 | else |
| 693 | ret = omap_device_register(pdev); |
| 694 | if (ret) |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 695 | goto odbs_exit2; |
Kevin Hilman | 0656358 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 696 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 697 | return pdev; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 698 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 699 | odbs_exit2: |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 700 | omap_device_delete(od); |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 701 | odbs_exit1: |
| 702 | platform_device_put(pdev); |
| 703 | odbs_exit: |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 704 | |
| 705 | pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret); |
| 706 | |
| 707 | return ERR_PTR(ret); |
| 708 | } |
| 709 | |
| 710 | /** |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 711 | * omap_early_device_register - register an omap_device as an early platform |
| 712 | * device. |
| 713 | * @od: struct omap_device * to register |
| 714 | * |
| 715 | * Register the omap_device structure. This currently just calls |
| 716 | * platform_early_add_device() on the underlying platform_device. |
| 717 | * Returns 0 by default. |
| 718 | */ |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 719 | static int omap_early_device_register(struct platform_device *pdev) |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 720 | { |
| 721 | struct platform_device *devices[1]; |
| 722 | |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 723 | devices[0] = pdev; |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 724 | early_platform_add_devices(devices, 1); |
| 725 | return 0; |
| 726 | } |
| 727 | |
Kevin Hilman | 256a543 | 2011-07-12 22:48:03 +0200 | [diff] [blame] | 728 | #ifdef CONFIG_PM_RUNTIME |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 729 | static int _od_runtime_suspend(struct device *dev) |
| 730 | { |
| 731 | struct platform_device *pdev = to_platform_device(dev); |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 732 | int ret; |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 733 | |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 734 | ret = pm_generic_runtime_suspend(dev); |
| 735 | |
| 736 | if (!ret) |
| 737 | omap_device_idle(pdev); |
| 738 | |
| 739 | return ret; |
| 740 | } |
| 741 | |
| 742 | static int _od_runtime_idle(struct device *dev) |
| 743 | { |
| 744 | return pm_generic_runtime_idle(dev); |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static int _od_runtime_resume(struct device *dev) |
| 748 | { |
| 749 | struct platform_device *pdev = to_platform_device(dev); |
| 750 | |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 751 | omap_device_enable(pdev); |
| 752 | |
| 753 | return pm_generic_runtime_resume(dev); |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 754 | } |
Kevin Hilman | 256a543 | 2011-07-12 22:48:03 +0200 | [diff] [blame] | 755 | #endif |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 756 | |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 757 | #ifdef CONFIG_SUSPEND |
| 758 | static int _od_suspend_noirq(struct device *dev) |
| 759 | { |
| 760 | struct platform_device *pdev = to_platform_device(dev); |
| 761 | struct omap_device *od = to_omap_device(pdev); |
| 762 | int ret; |
| 763 | |
Kevin Hilman | 80c6d1e | 2011-07-12 22:48:29 +0200 | [diff] [blame] | 764 | if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND) |
| 765 | return pm_generic_suspend_noirq(dev); |
| 766 | |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 767 | ret = pm_generic_suspend_noirq(dev); |
| 768 | |
| 769 | if (!ret && !pm_runtime_status_suspended(dev)) { |
| 770 | if (pm_generic_runtime_suspend(dev) == 0) { |
| 771 | omap_device_idle(pdev); |
| 772 | od->flags |= OMAP_DEVICE_SUSPENDED; |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | return ret; |
| 777 | } |
| 778 | |
| 779 | static int _od_resume_noirq(struct device *dev) |
| 780 | { |
| 781 | struct platform_device *pdev = to_platform_device(dev); |
| 782 | struct omap_device *od = to_omap_device(pdev); |
| 783 | |
Kevin Hilman | 80c6d1e | 2011-07-12 22:48:29 +0200 | [diff] [blame] | 784 | if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND) |
| 785 | return pm_generic_resume_noirq(dev); |
| 786 | |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 787 | if ((od->flags & OMAP_DEVICE_SUSPENDED) && |
| 788 | !pm_runtime_status_suspended(dev)) { |
| 789 | od->flags &= ~OMAP_DEVICE_SUSPENDED; |
| 790 | omap_device_enable(pdev); |
| 791 | pm_generic_runtime_resume(dev); |
| 792 | } |
| 793 | |
| 794 | return pm_generic_resume_noirq(dev); |
| 795 | } |
Kevin Hilman | 126caf1 | 2011-09-01 10:59:36 -0700 | [diff] [blame] | 796 | #else |
| 797 | #define _od_suspend_noirq NULL |
| 798 | #define _od_resume_noirq NULL |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 799 | #endif |
| 800 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 801 | static struct dev_pm_domain omap_device_pm_domain = { |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 802 | .ops = { |
Kevin Hilman | 256a543 | 2011-07-12 22:48:03 +0200 | [diff] [blame] | 803 | SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume, |
| 804 | _od_runtime_idle) |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 805 | USE_PLATFORM_PM_SLEEP_OPS |
Kevin Hilman | ff35336 | 2011-08-25 15:31:14 +0200 | [diff] [blame] | 806 | .suspend_noirq = _od_suspend_noirq, |
| 807 | .resume_noirq = _od_resume_noirq, |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 808 | } |
| 809 | }; |
| 810 | |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 811 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 812 | * omap_device_register - register an omap_device with one omap_hwmod |
| 813 | * @od: struct omap_device * to register |
| 814 | * |
| 815 | * Register the omap_device structure. This currently just calls |
| 816 | * platform_device_register() on the underlying platform_device. |
| 817 | * Returns the return value of platform_device_register(). |
| 818 | */ |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 819 | static int omap_device_register(struct platform_device *pdev) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 820 | { |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 821 | pr_debug("omap_device: %s: registering\n", pdev->name); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 822 | |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 823 | pdev->dev.parent = &omap_device_parent; |
| 824 | pdev->dev.pm_domain = &omap_device_pm_domain; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 825 | return platform_device_add(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | |
| 829 | /* Public functions for use by device drivers through struct platform_data */ |
| 830 | |
| 831 | /** |
| 832 | * omap_device_enable - fully activate an omap_device |
| 833 | * @od: struct omap_device * to activate |
| 834 | * |
| 835 | * Do whatever is necessary for the hwmods underlying omap_device @od |
| 836 | * to be accessible and ready to operate. This generally involves |
| 837 | * enabling clocks, setting SYSCONFIG registers; and in the future may |
| 838 | * involve remuxing pins. Device drivers should call this function |
| 839 | * (through platform_data function pointers) where they would normally |
| 840 | * enable clocks, etc. Returns -EINVAL if called when the omap_device |
| 841 | * is already enabled, or passes along the return value of |
| 842 | * _omap_device_activate(). |
| 843 | */ |
| 844 | int omap_device_enable(struct platform_device *pdev) |
| 845 | { |
| 846 | int ret; |
| 847 | struct omap_device *od; |
| 848 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 849 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 850 | |
| 851 | if (od->_state == OMAP_DEVICE_STATE_ENABLED) { |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 852 | dev_warn(&pdev->dev, |
| 853 | "omap_device: %s() called from invalid state %d\n", |
| 854 | __func__, od->_state); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 855 | return -EINVAL; |
| 856 | } |
| 857 | |
| 858 | /* Enable everything if we're enabling this device from scratch */ |
| 859 | if (od->_state == OMAP_DEVICE_STATE_UNKNOWN) |
| 860 | od->pm_lat_level = od->pm_lats_cnt; |
| 861 | |
| 862 | ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT); |
| 863 | |
| 864 | od->dev_wakeup_lat = 0; |
Kevin Hilman | 5f1b6ef | 2009-12-08 16:34:22 -0700 | [diff] [blame] | 865 | od->_dev_wakeup_lat_limit = UINT_MAX; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 866 | od->_state = OMAP_DEVICE_STATE_ENABLED; |
| 867 | |
| 868 | return ret; |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * omap_device_idle - idle an omap_device |
| 873 | * @od: struct omap_device * to idle |
| 874 | * |
| 875 | * Idle omap_device @od by calling as many .deactivate_func() entries |
| 876 | * in the omap_device's pm_lats table as is possible without exceeding |
| 877 | * the device's maximum wakeup latency limit, pm_lat_limit. Device |
| 878 | * drivers should call this function (through platform_data function |
| 879 | * pointers) where they would normally disable clocks after operations |
| 880 | * complete, etc.. Returns -EINVAL if the omap_device is not |
| 881 | * currently enabled, or passes along the return value of |
| 882 | * _omap_device_deactivate(). |
| 883 | */ |
| 884 | int omap_device_idle(struct platform_device *pdev) |
| 885 | { |
| 886 | int ret; |
| 887 | struct omap_device *od; |
| 888 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 889 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 890 | |
| 891 | if (od->_state != OMAP_DEVICE_STATE_ENABLED) { |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 892 | dev_warn(&pdev->dev, |
| 893 | "omap_device: %s() called from invalid state %d\n", |
| 894 | __func__, od->_state); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 895 | return -EINVAL; |
| 896 | } |
| 897 | |
| 898 | ret = _omap_device_deactivate(od, USE_WAKEUP_LAT); |
| 899 | |
| 900 | od->_state = OMAP_DEVICE_STATE_IDLE; |
| 901 | |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * omap_device_shutdown - shut down an omap_device |
| 907 | * @od: struct omap_device * to shut down |
| 908 | * |
| 909 | * Shut down omap_device @od by calling all .deactivate_func() entries |
| 910 | * in the omap_device's pm_lats table and then shutting down all of |
| 911 | * the underlying omap_hwmods. Used when a device is being "removed" |
| 912 | * or a device driver is being unloaded. Returns -EINVAL if the |
| 913 | * omap_device is not currently enabled or idle, or passes along the |
| 914 | * return value of _omap_device_deactivate(). |
| 915 | */ |
| 916 | int omap_device_shutdown(struct platform_device *pdev) |
| 917 | { |
| 918 | int ret, i; |
| 919 | struct omap_device *od; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 920 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 921 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 922 | |
| 923 | if (od->_state != OMAP_DEVICE_STATE_ENABLED && |
| 924 | od->_state != OMAP_DEVICE_STATE_IDLE) { |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 925 | dev_warn(&pdev->dev, |
| 926 | "omap_device: %s() called from invalid state %d\n", |
| 927 | __func__, od->_state); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 928 | return -EINVAL; |
| 929 | } |
| 930 | |
| 931 | ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT); |
| 932 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 933 | for (i = 0; i < od->hwmods_cnt; i++) |
| 934 | omap_hwmod_shutdown(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 935 | |
| 936 | od->_state = OMAP_DEVICE_STATE_SHUTDOWN; |
| 937 | |
| 938 | return ret; |
| 939 | } |
| 940 | |
| 941 | /** |
| 942 | * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim |
| 943 | * @od: struct omap_device * |
| 944 | * |
| 945 | * When a device's maximum wakeup latency limit changes, call some of |
| 946 | * the .activate_func or .deactivate_func function pointers in the |
| 947 | * omap_device's pm_lats array to ensure that the device's maximum |
| 948 | * wakeup latency is less than or equal to the new latency limit. |
| 949 | * Intended to be called by OMAP PM code whenever a device's maximum |
| 950 | * wakeup latency limit changes (e.g., via |
| 951 | * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be |
| 952 | * done (e.g., if the omap_device is not currently idle, or if the |
| 953 | * wakeup latency is already current with the new limit) or passes |
| 954 | * along the return value of _omap_device_deactivate() or |
| 955 | * _omap_device_activate(). |
| 956 | */ |
| 957 | int omap_device_align_pm_lat(struct platform_device *pdev, |
| 958 | u32 new_wakeup_lat_limit) |
| 959 | { |
| 960 | int ret = -EINVAL; |
| 961 | struct omap_device *od; |
| 962 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 963 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 964 | |
| 965 | if (new_wakeup_lat_limit == od->dev_wakeup_lat) |
| 966 | return 0; |
| 967 | |
| 968 | od->_dev_wakeup_lat_limit = new_wakeup_lat_limit; |
| 969 | |
| 970 | if (od->_state != OMAP_DEVICE_STATE_IDLE) |
| 971 | return 0; |
| 972 | else if (new_wakeup_lat_limit > od->dev_wakeup_lat) |
| 973 | ret = _omap_device_deactivate(od, USE_WAKEUP_LAT); |
| 974 | else if (new_wakeup_lat_limit < od->dev_wakeup_lat) |
| 975 | ret = _omap_device_activate(od, USE_WAKEUP_LAT); |
| 976 | |
| 977 | return ret; |
| 978 | } |
| 979 | |
| 980 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 981 | * omap_device_get_pwrdm - return the powerdomain * associated with @od |
| 982 | * @od: struct omap_device * |
| 983 | * |
| 984 | * Return the powerdomain associated with the first underlying |
| 985 | * omap_hwmod for this omap_device. Intended for use by core OMAP PM |
| 986 | * code. Returns NULL on error or a struct powerdomain * upon |
| 987 | * success. |
| 988 | */ |
| 989 | struct powerdomain *omap_device_get_pwrdm(struct omap_device *od) |
| 990 | { |
| 991 | /* |
| 992 | * XXX Assumes that all omap_hwmod powerdomains are identical. |
| 993 | * This may not necessarily be true. There should be a sanity |
| 994 | * check in here to WARN() if any difference appears. |
| 995 | */ |
| 996 | if (!od->hwmods_cnt) |
| 997 | return NULL; |
| 998 | |
| 999 | return omap_hwmod_get_pwrdm(od->hwmods[0]); |
| 1000 | } |
| 1001 | |
Paul Walmsley | db2a60b | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 1002 | /** |
| 1003 | * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base |
| 1004 | * @od: struct omap_device * |
| 1005 | * |
| 1006 | * Return the MPU's virtual address for the base of the hwmod, from |
| 1007 | * the ioremap() that the hwmod code does. Only valid if there is one |
| 1008 | * hwmod associated with this device. Returns NULL if there are zero |
| 1009 | * or more than one hwmods associated with this omap_device; |
| 1010 | * otherwise, passes along the return value from |
| 1011 | * omap_hwmod_get_mpu_rt_va(). |
| 1012 | */ |
| 1013 | void __iomem *omap_device_get_rt_va(struct omap_device *od) |
| 1014 | { |
| 1015 | if (od->hwmods_cnt != 1) |
| 1016 | return NULL; |
| 1017 | |
| 1018 | return omap_hwmod_get_mpu_rt_va(od->hwmods[0]); |
| 1019 | } |
| 1020 | |
Nishanth Menon | 1f8a7d5 | 2011-07-27 15:02:32 -0500 | [diff] [blame] | 1021 | /** |
| 1022 | * omap_device_get_by_hwmod_name() - convert a hwmod name to |
| 1023 | * device pointer. |
| 1024 | * @oh_name: name of the hwmod device |
| 1025 | * |
| 1026 | * Returns back a struct device * pointer associated with a hwmod |
| 1027 | * device represented by a hwmod_name |
| 1028 | */ |
| 1029 | struct device *omap_device_get_by_hwmod_name(const char *oh_name) |
| 1030 | { |
| 1031 | struct omap_hwmod *oh; |
| 1032 | |
| 1033 | if (!oh_name) { |
| 1034 | WARN(1, "%s: no hwmod name!\n", __func__); |
| 1035 | return ERR_PTR(-EINVAL); |
| 1036 | } |
| 1037 | |
| 1038 | oh = omap_hwmod_lookup(oh_name); |
| 1039 | if (IS_ERR_OR_NULL(oh)) { |
| 1040 | WARN(1, "%s: no hwmod for %s\n", __func__, |
| 1041 | oh_name); |
| 1042 | return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV); |
| 1043 | } |
| 1044 | if (IS_ERR_OR_NULL(oh->od)) { |
| 1045 | WARN(1, "%s: no omap_device for %s\n", __func__, |
| 1046 | oh_name); |
| 1047 | return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV); |
| 1048 | } |
| 1049 | |
| 1050 | if (IS_ERR_OR_NULL(oh->od->pdev)) |
| 1051 | return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV); |
| 1052 | |
| 1053 | return &oh->od->pdev->dev; |
| 1054 | } |
| 1055 | EXPORT_SYMBOL(omap_device_get_by_hwmod_name); |
| 1056 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1057 | /* |
| 1058 | * Public functions intended for use in omap_device_pm_latency |
| 1059 | * .activate_func and .deactivate_func function pointers |
| 1060 | */ |
| 1061 | |
| 1062 | /** |
| 1063 | * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods |
| 1064 | * @od: struct omap_device *od |
| 1065 | * |
| 1066 | * Enable all underlying hwmods. Returns 0. |
| 1067 | */ |
| 1068 | int omap_device_enable_hwmods(struct omap_device *od) |
| 1069 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1070 | int i; |
| 1071 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1072 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1073 | omap_hwmod_enable(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1074 | |
| 1075 | /* XXX pass along return value here? */ |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods |
| 1081 | * @od: struct omap_device *od |
| 1082 | * |
| 1083 | * Idle all underlying hwmods. Returns 0. |
| 1084 | */ |
| 1085 | int omap_device_idle_hwmods(struct omap_device *od) |
| 1086 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1087 | int i; |
| 1088 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1089 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1090 | omap_hwmod_idle(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1091 | |
| 1092 | /* XXX pass along return value here? */ |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
| 1096 | /** |
| 1097 | * omap_device_disable_clocks - disable all main and interface clocks |
| 1098 | * @od: struct omap_device *od |
| 1099 | * |
| 1100 | * Disable the main functional clock and interface clock for all of the |
| 1101 | * omap_hwmods associated with the omap_device. Returns 0. |
| 1102 | */ |
| 1103 | int omap_device_disable_clocks(struct omap_device *od) |
| 1104 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1105 | int i; |
| 1106 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1107 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1108 | omap_hwmod_disable_clocks(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1109 | |
| 1110 | /* XXX pass along return value here? */ |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * omap_device_enable_clocks - enable all main and interface clocks |
| 1116 | * @od: struct omap_device *od |
| 1117 | * |
| 1118 | * Enable the main functional clock and interface clock for all of the |
| 1119 | * omap_hwmods associated with the omap_device. Returns 0. |
| 1120 | */ |
| 1121 | int omap_device_enable_clocks(struct omap_device *od) |
| 1122 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1123 | int i; |
| 1124 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1125 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1126 | omap_hwmod_enable_clocks(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1127 | |
| 1128 | /* XXX pass along return value here? */ |
| 1129 | return 0; |
| 1130 | } |
Kevin Hilman | 0d5e825 | 2010-08-23 08:10:55 -0700 | [diff] [blame] | 1131 | |
| 1132 | struct device omap_device_parent = { |
| 1133 | .init_name = "omap", |
| 1134 | .parent = &platform_bus, |
| 1135 | }; |
| 1136 | |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 1137 | static struct notifier_block platform_nb = { |
| 1138 | .notifier_call = _omap_device_notifier_call, |
| 1139 | }; |
| 1140 | |
Kevin Hilman | 0d5e825 | 2010-08-23 08:10:55 -0700 | [diff] [blame] | 1141 | static int __init omap_device_init(void) |
| 1142 | { |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 1143 | bus_register_notifier(&platform_bus_type, &platform_nb); |
Kevin Hilman | 0d5e825 | 2010-08-23 08:10:55 -0700 | [diff] [blame] | 1144 | return device_register(&omap_device_parent); |
| 1145 | } |
| 1146 | core_initcall(omap_device_init); |