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