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