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 | static struct dev_pm_domain omap_device_pm_domain; |
| 318 | |
| 319 | /** |
| 320 | * omap_device_build_from_dt - build an omap_device with multiple hwmods |
| 321 | * @pdev_name: name of the platform_device driver to use |
| 322 | * @pdev_id: this platform_device's connection ID |
| 323 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 324 | * @pdata: platform_data ptr to associate with the platform_device |
| 325 | * @pdata_len: amount of memory pointed to by @pdata |
| 326 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 327 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
| 328 | * @is_early_device: should the device be registered as an early device or not |
| 329 | * |
| 330 | * Function for building an omap_device already registered from device-tree |
| 331 | * |
| 332 | * Returns 0 or PTR_ERR() on error. |
| 333 | */ |
| 334 | static int omap_device_build_from_dt(struct platform_device *pdev) |
| 335 | { |
| 336 | struct omap_hwmod **hwmods; |
| 337 | struct omap_device *od; |
| 338 | struct omap_hwmod *oh; |
| 339 | struct device_node *node = pdev->dev.of_node; |
| 340 | const char *oh_name; |
| 341 | int oh_cnt, i, ret = 0; |
| 342 | |
| 343 | oh_cnt = of_property_count_strings(node, "ti,hwmods"); |
| 344 | if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) { |
| 345 | dev_warn(&pdev->dev, "No 'hwmods' to build omap_device\n"); |
| 346 | return -ENODEV; |
| 347 | } |
| 348 | |
| 349 | hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); |
| 350 | if (!hwmods) { |
| 351 | ret = -ENOMEM; |
| 352 | goto odbfd_exit; |
| 353 | } |
| 354 | |
| 355 | for (i = 0; i < oh_cnt; i++) { |
| 356 | of_property_read_string_index(node, "ti,hwmods", i, &oh_name); |
| 357 | oh = omap_hwmod_lookup(oh_name); |
| 358 | if (!oh) { |
| 359 | dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n", |
| 360 | oh_name); |
| 361 | ret = -EINVAL; |
| 362 | goto odbfd_exit1; |
| 363 | } |
| 364 | hwmods[i] = oh; |
| 365 | } |
| 366 | |
| 367 | od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0); |
| 368 | if (!od) { |
| 369 | dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n", |
| 370 | oh_name); |
| 371 | ret = PTR_ERR(od); |
| 372 | goto odbfd_exit1; |
| 373 | } |
| 374 | |
| 375 | if (of_get_property(node, "ti,no_idle_on_suspend", NULL)) |
| 376 | omap_device_disable_idle_on_suspend(pdev); |
| 377 | |
| 378 | pdev->dev.pm_domain = &omap_device_pm_domain; |
| 379 | |
| 380 | odbfd_exit1: |
| 381 | kfree(hwmods); |
| 382 | odbfd_exit: |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | static int _omap_device_notifier_call(struct notifier_block *nb, |
| 387 | unsigned long event, void *dev) |
| 388 | { |
| 389 | struct platform_device *pdev = to_platform_device(dev); |
| 390 | |
| 391 | switch (event) { |
| 392 | case BUS_NOTIFY_ADD_DEVICE: |
| 393 | if (pdev->dev.of_node) |
| 394 | omap_device_build_from_dt(pdev); |
| 395 | break; |
| 396 | |
| 397 | case BUS_NOTIFY_DEL_DEVICE: |
| 398 | if (pdev->archdata.od) |
| 399 | omap_device_delete(pdev->archdata.od); |
| 400 | break; |
| 401 | } |
| 402 | |
| 403 | return NOTIFY_DONE; |
| 404 | } |
| 405 | |
| 406 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 407 | /* Public functions for use by core code */ |
| 408 | |
| 409 | /** |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 410 | * omap_device_get_context_loss_count - get lost context count |
| 411 | * @od: struct omap_device * |
| 412 | * |
| 413 | * Using the primary hwmod, query the context loss count for this |
| 414 | * device. |
| 415 | * |
| 416 | * Callers should consider context for this device lost any time this |
| 417 | * function returns a value different than the value the caller got |
| 418 | * the last time it called this function. |
| 419 | * |
| 420 | * If any hwmods exist for the omap_device assoiated with @pdev, |
| 421 | * return the context loss counter for that hwmod, otherwise return |
| 422 | * zero. |
| 423 | */ |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 424 | int omap_device_get_context_loss_count(struct platform_device *pdev) |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 425 | { |
| 426 | struct omap_device *od; |
| 427 | u32 ret = 0; |
| 428 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 429 | od = to_omap_device(pdev); |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 430 | |
| 431 | if (od->hwmods_cnt) |
| 432 | ret = omap_hwmod_get_context_loss_count(od->hwmods[0]); |
| 433 | |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 438 | * omap_device_count_resources - count number of struct resource entries needed |
| 439 | * @od: struct omap_device * |
| 440 | * |
| 441 | * Count the number of struct resource entries needed for this |
| 442 | * omap_device @od. Used by omap_device_build_ss() to determine how |
| 443 | * much memory to allocate before calling |
| 444 | * omap_device_fill_resources(). Returns the count. |
| 445 | */ |
Kevin Hilman | a2a28ad | 2011-07-21 14:14:35 -0700 | [diff] [blame] | 446 | static int omap_device_count_resources(struct omap_device *od) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 447 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 448 | int c = 0; |
| 449 | int i; |
| 450 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 451 | for (i = 0; i < od->hwmods_cnt; i++) |
| 452 | c += omap_hwmod_count_resources(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 453 | |
| 454 | pr_debug("omap_device: %s: counted %d total resources across %d " |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 455 | "hwmods\n", od->pdev->name, c, od->hwmods_cnt); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 456 | |
| 457 | return c; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * omap_device_fill_resources - fill in array of struct resource |
| 462 | * @od: struct omap_device * |
| 463 | * @res: pointer to an array of struct resource to be filled in |
| 464 | * |
| 465 | * Populate one or more empty struct resource pointed to by @res with |
| 466 | * the resource data for this omap_device @od. Used by |
| 467 | * omap_device_build_ss() after calling omap_device_count_resources(). |
| 468 | * Ideally this function would not be needed at all. If omap_device |
| 469 | * replaces platform_device, then we can specify our own |
| 470 | * get_resource()/ get_irq()/etc functions that use the underlying |
| 471 | * omap_hwmod information. Or if platform_device is extended to use |
| 472 | * subarchitecture-specific function pointers, the various |
| 473 | * platform_device functions can simply call omap_device internal |
| 474 | * functions to get device resources. Hacking around the existing |
| 475 | * platform_device code wastes memory. Returns 0. |
| 476 | */ |
Kevin Hilman | a2a28ad | 2011-07-21 14:14:35 -0700 | [diff] [blame] | 477 | static int omap_device_fill_resources(struct omap_device *od, |
| 478 | struct resource *res) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 479 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 480 | int c = 0; |
| 481 | int i, r; |
| 482 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 483 | for (i = 0; i < od->hwmods_cnt; i++) { |
| 484 | r = omap_hwmod_fill_resources(od->hwmods[i], res); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 485 | res += r; |
| 486 | c += r; |
| 487 | } |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | /** |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 493 | * omap_device_alloc - allocate an omap_device |
| 494 | * @pdev: platform_device that will be included in this omap_device |
| 495 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 496 | * @pdata: platform_data ptr to associate with the platform_device |
| 497 | * @pdata_len: amount of memory pointed to by @pdata |
| 498 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 499 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
| 500 | * |
| 501 | * Convenience function for allocating an omap_device structure and filling |
| 502 | * hwmods, resources and pm_latency attributes. |
| 503 | * |
| 504 | * Returns an struct omap_device pointer or ERR_PTR() on error; |
| 505 | */ |
Ohad Ben-Cohen | 993e4fb | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 506 | struct omap_device *omap_device_alloc(struct platform_device *pdev, |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 507 | struct omap_hwmod **ohs, int oh_cnt, |
| 508 | struct omap_device_pm_latency *pm_lats, |
| 509 | int pm_lats_cnt) |
| 510 | { |
| 511 | int ret = -ENOMEM; |
| 512 | struct omap_device *od; |
| 513 | struct resource *res = NULL; |
| 514 | int i, res_count; |
| 515 | struct omap_hwmod **hwmods; |
| 516 | |
| 517 | od = kzalloc(sizeof(struct omap_device), GFP_KERNEL); |
| 518 | if (!od) { |
| 519 | ret = -ENOMEM; |
| 520 | goto oda_exit1; |
| 521 | } |
| 522 | od->hwmods_cnt = oh_cnt; |
| 523 | |
| 524 | hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); |
| 525 | if (!hwmods) |
| 526 | goto oda_exit2; |
| 527 | |
| 528 | od->hwmods = hwmods; |
| 529 | od->pdev = pdev; |
| 530 | |
| 531 | /* |
| 532 | * HACK: Ideally the resources from DT should match, and hwmod |
| 533 | * should just add the missing ones. Since the name is not |
| 534 | * properly populated by DT, stick to hwmod resources only. |
| 535 | */ |
| 536 | if (pdev->num_resources && pdev->resource) |
| 537 | dev_warn(&pdev->dev, "%s(): resources already allocated %d\n", |
| 538 | __func__, pdev->num_resources); |
| 539 | |
| 540 | res_count = omap_device_count_resources(od); |
| 541 | if (res_count > 0) { |
| 542 | dev_dbg(&pdev->dev, "%s(): resources allocated from hwmod %d\n", |
| 543 | __func__, res_count); |
| 544 | res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL); |
| 545 | if (!res) |
| 546 | goto oda_exit3; |
| 547 | |
| 548 | omap_device_fill_resources(od, res); |
| 549 | |
| 550 | ret = platform_device_add_resources(pdev, res, res_count); |
| 551 | kfree(res); |
| 552 | |
| 553 | if (ret) |
| 554 | goto oda_exit3; |
| 555 | } |
| 556 | |
| 557 | if (!pm_lats) { |
| 558 | pm_lats = omap_default_latency; |
| 559 | pm_lats_cnt = ARRAY_SIZE(omap_default_latency); |
| 560 | } |
| 561 | |
| 562 | od->pm_lats_cnt = pm_lats_cnt; |
| 563 | od->pm_lats = kmemdup(pm_lats, |
| 564 | sizeof(struct omap_device_pm_latency) * pm_lats_cnt, |
| 565 | GFP_KERNEL); |
| 566 | if (!od->pm_lats) |
| 567 | goto oda_exit3; |
| 568 | |
| 569 | pdev->archdata.od = od; |
| 570 | |
| 571 | for (i = 0; i < oh_cnt; i++) { |
| 572 | hwmods[i]->od = od; |
| 573 | _add_hwmod_clocks_clkdev(od, hwmods[i]); |
| 574 | } |
| 575 | |
| 576 | return od; |
| 577 | |
| 578 | oda_exit3: |
| 579 | kfree(hwmods); |
| 580 | oda_exit2: |
| 581 | kfree(od); |
| 582 | oda_exit1: |
| 583 | dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret); |
| 584 | |
| 585 | return ERR_PTR(ret); |
| 586 | } |
| 587 | |
Ohad Ben-Cohen | 993e4fb | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 588 | void omap_device_delete(struct omap_device *od) |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 589 | { |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 590 | if (!od) |
| 591 | return; |
| 592 | |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 593 | od->pdev->archdata.od = NULL; |
| 594 | kfree(od->pm_lats); |
| 595 | kfree(od->hwmods); |
| 596 | kfree(od); |
| 597 | } |
| 598 | |
| 599 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 600 | * omap_device_build - build and register an omap_device with one omap_hwmod |
| 601 | * @pdev_name: name of the platform_device driver to use |
| 602 | * @pdev_id: this platform_device's connection ID |
| 603 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 604 | * @pdata: platform_data ptr to associate with the platform_device |
| 605 | * @pdata_len: amount of memory pointed to by @pdata |
| 606 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 607 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 608 | * @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] | 609 | * |
| 610 | * Convenience function for building and registering a single |
| 611 | * omap_device record, which in turn builds and registers a |
| 612 | * platform_device record. See omap_device_build_ss() for more |
| 613 | * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise, |
| 614 | * passes along the return value of omap_device_build_ss(). |
| 615 | */ |
Kevin Hilman | 9cf793f | 2012-02-20 09:43:30 -0800 | [diff] [blame^] | 616 | 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] | 617 | struct omap_hwmod *oh, void *pdata, |
| 618 | int pdata_len, |
| 619 | struct omap_device_pm_latency *pm_lats, |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 620 | int pm_lats_cnt, int is_early_device) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 621 | { |
| 622 | struct omap_hwmod *ohs[] = { oh }; |
| 623 | |
| 624 | if (!oh) |
| 625 | return ERR_PTR(-EINVAL); |
| 626 | |
| 627 | return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata, |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 628 | pdata_len, pm_lats, pm_lats_cnt, |
| 629 | is_early_device); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
| 633 | * omap_device_build_ss - build and register an omap_device with multiple hwmods |
| 634 | * @pdev_name: name of the platform_device driver to use |
| 635 | * @pdev_id: this platform_device's connection ID |
| 636 | * @oh: ptr to the single omap_hwmod that backs this omap_device |
| 637 | * @pdata: platform_data ptr to associate with the platform_device |
| 638 | * @pdata_len: amount of memory pointed to by @pdata |
| 639 | * @pm_lats: pointer to a omap_device_pm_latency array for this device |
| 640 | * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 641 | * @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] | 642 | * |
| 643 | * Convenience function for building and registering an omap_device |
| 644 | * subsystem record. Subsystem records consist of multiple |
| 645 | * omap_hwmods. This function in turn builds and registers a |
| 646 | * platform_device record. Returns an ERR_PTR() on error, or passes |
| 647 | * along the return value of omap_device_register(). |
| 648 | */ |
Kevin Hilman | 9cf793f | 2012-02-20 09:43:30 -0800 | [diff] [blame^] | 649 | 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] | 650 | struct omap_hwmod **ohs, int oh_cnt, |
| 651 | void *pdata, int pdata_len, |
| 652 | struct omap_device_pm_latency *pm_lats, |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 653 | int pm_lats_cnt, int is_early_device) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 654 | { |
| 655 | int ret = -ENOMEM; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 656 | struct platform_device *pdev; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 657 | struct omap_device *od; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 658 | |
| 659 | if (!ohs || oh_cnt == 0 || !pdev_name) |
| 660 | return ERR_PTR(-EINVAL); |
| 661 | |
| 662 | if (!pdata && pdata_len > 0) |
| 663 | return ERR_PTR(-EINVAL); |
| 664 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 665 | pdev = platform_device_alloc(pdev_name, pdev_id); |
| 666 | if (!pdev) { |
| 667 | ret = -ENOMEM; |
| 668 | goto odbs_exit; |
| 669 | } |
| 670 | |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 671 | /* Set the dev_name early to allow dev_xxx in omap_device_alloc */ |
| 672 | if (pdev->id != -1) |
| 673 | dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); |
| 674 | else |
| 675 | dev_set_name(&pdev->dev, "%s", pdev->name); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 676 | |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 677 | od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt); |
| 678 | if (!od) |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 679 | goto odbs_exit1; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 680 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 681 | ret = platform_device_add_data(pdev, pdata, pdata_len); |
Artem Bityutskiy | 49b368a | 2010-07-12 13:38:07 +0000 | [diff] [blame] | 682 | if (ret) |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 683 | goto odbs_exit2; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 684 | |
| 685 | if (is_early_device) |
| 686 | ret = omap_early_device_register(pdev); |
| 687 | else |
| 688 | ret = omap_device_register(pdev); |
| 689 | if (ret) |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 690 | goto odbs_exit2; |
Kevin Hilman | 0656358 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 691 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 692 | return pdev; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 693 | |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 694 | odbs_exit2: |
Benoit Cousson | a4f6cdb | 2011-08-09 16:47:01 +0200 | [diff] [blame] | 695 | omap_device_delete(od); |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 696 | odbs_exit1: |
| 697 | platform_device_put(pdev); |
| 698 | odbs_exit: |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 699 | |
| 700 | pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret); |
| 701 | |
| 702 | return ERR_PTR(ret); |
| 703 | } |
| 704 | |
| 705 | /** |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 706 | * omap_early_device_register - register an omap_device as an early platform |
| 707 | * device. |
| 708 | * @od: struct omap_device * to register |
| 709 | * |
| 710 | * Register the omap_device structure. This currently just calls |
| 711 | * platform_early_add_device() on the underlying platform_device. |
| 712 | * Returns 0 by default. |
| 713 | */ |
Kevin Hilman | 9cf793f | 2012-02-20 09:43:30 -0800 | [diff] [blame^] | 714 | static int __init omap_early_device_register(struct platform_device *pdev) |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 715 | { |
| 716 | struct platform_device *devices[1]; |
| 717 | |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 718 | devices[0] = pdev; |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 719 | early_platform_add_devices(devices, 1); |
| 720 | return 0; |
| 721 | } |
| 722 | |
Kevin Hilman | 256a543 | 2011-07-12 22:48:03 +0200 | [diff] [blame] | 723 | #ifdef CONFIG_PM_RUNTIME |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 724 | static int _od_runtime_suspend(struct device *dev) |
| 725 | { |
| 726 | struct platform_device *pdev = to_platform_device(dev); |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 727 | int ret; |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 728 | |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 729 | ret = pm_generic_runtime_suspend(dev); |
| 730 | |
| 731 | if (!ret) |
| 732 | omap_device_idle(pdev); |
| 733 | |
| 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | static int _od_runtime_idle(struct device *dev) |
| 738 | { |
| 739 | return pm_generic_runtime_idle(dev); |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static int _od_runtime_resume(struct device *dev) |
| 743 | { |
| 744 | struct platform_device *pdev = to_platform_device(dev); |
| 745 | |
Kevin Hilman | 345f79b | 2011-05-31 16:08:09 -0700 | [diff] [blame] | 746 | omap_device_enable(pdev); |
| 747 | |
| 748 | return pm_generic_runtime_resume(dev); |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 749 | } |
Kevin Hilman | 256a543 | 2011-07-12 22:48:03 +0200 | [diff] [blame] | 750 | #endif |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 751 | |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 752 | #ifdef CONFIG_SUSPEND |
| 753 | static int _od_suspend_noirq(struct device *dev) |
| 754 | { |
| 755 | struct platform_device *pdev = to_platform_device(dev); |
| 756 | struct omap_device *od = to_omap_device(pdev); |
| 757 | int ret; |
| 758 | |
Kevin Hilman | 80c6d1e | 2011-07-12 22:48:29 +0200 | [diff] [blame] | 759 | if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND) |
| 760 | return pm_generic_suspend_noirq(dev); |
| 761 | |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 762 | ret = pm_generic_suspend_noirq(dev); |
| 763 | |
| 764 | if (!ret && !pm_runtime_status_suspended(dev)) { |
| 765 | if (pm_generic_runtime_suspend(dev) == 0) { |
| 766 | omap_device_idle(pdev); |
| 767 | od->flags |= OMAP_DEVICE_SUSPENDED; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | static int _od_resume_noirq(struct device *dev) |
| 775 | { |
| 776 | struct platform_device *pdev = to_platform_device(dev); |
| 777 | struct omap_device *od = to_omap_device(pdev); |
| 778 | |
Kevin Hilman | 80c6d1e | 2011-07-12 22:48:29 +0200 | [diff] [blame] | 779 | if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND) |
| 780 | return pm_generic_resume_noirq(dev); |
| 781 | |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 782 | if ((od->flags & OMAP_DEVICE_SUSPENDED) && |
| 783 | !pm_runtime_status_suspended(dev)) { |
| 784 | od->flags &= ~OMAP_DEVICE_SUSPENDED; |
| 785 | omap_device_enable(pdev); |
| 786 | pm_generic_runtime_resume(dev); |
| 787 | } |
| 788 | |
| 789 | return pm_generic_resume_noirq(dev); |
| 790 | } |
Kevin Hilman | 126caf1 | 2011-09-01 10:59:36 -0700 | [diff] [blame] | 791 | #else |
| 792 | #define _od_suspend_noirq NULL |
| 793 | #define _od_resume_noirq NULL |
Kevin Hilman | c03f007 | 2011-07-12 22:48:19 +0200 | [diff] [blame] | 794 | #endif |
| 795 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 796 | static struct dev_pm_domain omap_device_pm_domain = { |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 797 | .ops = { |
Kevin Hilman | 256a543 | 2011-07-12 22:48:03 +0200 | [diff] [blame] | 798 | SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume, |
| 799 | _od_runtime_idle) |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 800 | USE_PLATFORM_PM_SLEEP_OPS |
Kevin Hilman | ff35336 | 2011-08-25 15:31:14 +0200 | [diff] [blame] | 801 | .suspend_noirq = _od_suspend_noirq, |
| 802 | .resume_noirq = _od_resume_noirq, |
Kevin Hilman | 638080c | 2011-04-29 00:36:42 +0200 | [diff] [blame] | 803 | } |
| 804 | }; |
| 805 | |
Thara Gopinath | c23a97d | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 806 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 807 | * omap_device_register - register an omap_device with one omap_hwmod |
| 808 | * @od: struct omap_device * to register |
| 809 | * |
| 810 | * Register the omap_device structure. This currently just calls |
| 811 | * platform_device_register() on the underlying platform_device. |
| 812 | * Returns the return value of platform_device_register(). |
| 813 | */ |
Ohad Ben-Cohen | 993e4fb | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 814 | int omap_device_register(struct platform_device *pdev) |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 815 | { |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 816 | pr_debug("omap_device: %s: registering\n", pdev->name); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 817 | |
Kevin Hilman | bfae4f8 | 2011-07-21 14:47:53 -0700 | [diff] [blame] | 818 | pdev->dev.parent = &omap_device_parent; |
| 819 | pdev->dev.pm_domain = &omap_device_pm_domain; |
Kevin Hilman | d66b3fe | 2011-07-21 13:58:51 -0700 | [diff] [blame] | 820 | return platform_device_add(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
| 824 | /* Public functions for use by device drivers through struct platform_data */ |
| 825 | |
| 826 | /** |
| 827 | * omap_device_enable - fully activate an omap_device |
| 828 | * @od: struct omap_device * to activate |
| 829 | * |
| 830 | * Do whatever is necessary for the hwmods underlying omap_device @od |
| 831 | * to be accessible and ready to operate. This generally involves |
| 832 | * enabling clocks, setting SYSCONFIG registers; and in the future may |
| 833 | * involve remuxing pins. Device drivers should call this function |
| 834 | * (through platform_data function pointers) where they would normally |
| 835 | * enable clocks, etc. Returns -EINVAL if called when the omap_device |
| 836 | * is already enabled, or passes along the return value of |
| 837 | * _omap_device_activate(). |
| 838 | */ |
| 839 | int omap_device_enable(struct platform_device *pdev) |
| 840 | { |
| 841 | int ret; |
| 842 | struct omap_device *od; |
| 843 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 844 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 845 | |
| 846 | if (od->_state == OMAP_DEVICE_STATE_ENABLED) { |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 847 | dev_warn(&pdev->dev, |
| 848 | "omap_device: %s() called from invalid state %d\n", |
| 849 | __func__, od->_state); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 850 | return -EINVAL; |
| 851 | } |
| 852 | |
| 853 | /* Enable everything if we're enabling this device from scratch */ |
| 854 | if (od->_state == OMAP_DEVICE_STATE_UNKNOWN) |
| 855 | od->pm_lat_level = od->pm_lats_cnt; |
| 856 | |
| 857 | ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT); |
| 858 | |
| 859 | od->dev_wakeup_lat = 0; |
Kevin Hilman | 5f1b6ef | 2009-12-08 16:34:22 -0700 | [diff] [blame] | 860 | od->_dev_wakeup_lat_limit = UINT_MAX; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 861 | od->_state = OMAP_DEVICE_STATE_ENABLED; |
| 862 | |
| 863 | return ret; |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * omap_device_idle - idle an omap_device |
| 868 | * @od: struct omap_device * to idle |
| 869 | * |
| 870 | * Idle omap_device @od by calling as many .deactivate_func() entries |
| 871 | * in the omap_device's pm_lats table as is possible without exceeding |
| 872 | * the device's maximum wakeup latency limit, pm_lat_limit. Device |
| 873 | * drivers should call this function (through platform_data function |
| 874 | * pointers) where they would normally disable clocks after operations |
| 875 | * complete, etc.. Returns -EINVAL if the omap_device is not |
| 876 | * currently enabled, or passes along the return value of |
| 877 | * _omap_device_deactivate(). |
| 878 | */ |
| 879 | int omap_device_idle(struct platform_device *pdev) |
| 880 | { |
| 881 | int ret; |
| 882 | struct omap_device *od; |
| 883 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 884 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 885 | |
| 886 | if (od->_state != OMAP_DEVICE_STATE_ENABLED) { |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 887 | dev_warn(&pdev->dev, |
| 888 | "omap_device: %s() called from invalid state %d\n", |
| 889 | __func__, od->_state); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 890 | return -EINVAL; |
| 891 | } |
| 892 | |
| 893 | ret = _omap_device_deactivate(od, USE_WAKEUP_LAT); |
| 894 | |
| 895 | od->_state = OMAP_DEVICE_STATE_IDLE; |
| 896 | |
| 897 | return ret; |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * omap_device_shutdown - shut down an omap_device |
| 902 | * @od: struct omap_device * to shut down |
| 903 | * |
| 904 | * Shut down omap_device @od by calling all .deactivate_func() entries |
| 905 | * in the omap_device's pm_lats table and then shutting down all of |
| 906 | * the underlying omap_hwmods. Used when a device is being "removed" |
| 907 | * or a device driver is being unloaded. Returns -EINVAL if the |
| 908 | * omap_device is not currently enabled or idle, or passes along the |
| 909 | * return value of _omap_device_deactivate(). |
| 910 | */ |
| 911 | int omap_device_shutdown(struct platform_device *pdev) |
| 912 | { |
| 913 | int ret, i; |
| 914 | struct omap_device *od; |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 915 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 916 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 917 | |
| 918 | if (od->_state != OMAP_DEVICE_STATE_ENABLED && |
| 919 | od->_state != OMAP_DEVICE_STATE_IDLE) { |
Kevin Hilman | 49882c9 | 2011-07-21 09:58:36 -0700 | [diff] [blame] | 920 | dev_warn(&pdev->dev, |
| 921 | "omap_device: %s() called from invalid state %d\n", |
| 922 | __func__, od->_state); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 923 | return -EINVAL; |
| 924 | } |
| 925 | |
| 926 | ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT); |
| 927 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 928 | for (i = 0; i < od->hwmods_cnt; i++) |
| 929 | omap_hwmod_shutdown(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 930 | |
| 931 | od->_state = OMAP_DEVICE_STATE_SHUTDOWN; |
| 932 | |
| 933 | return ret; |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim |
| 938 | * @od: struct omap_device * |
| 939 | * |
| 940 | * When a device's maximum wakeup latency limit changes, call some of |
| 941 | * the .activate_func or .deactivate_func function pointers in the |
| 942 | * omap_device's pm_lats array to ensure that the device's maximum |
| 943 | * wakeup latency is less than or equal to the new latency limit. |
| 944 | * Intended to be called by OMAP PM code whenever a device's maximum |
| 945 | * wakeup latency limit changes (e.g., via |
| 946 | * omap_pm_set_dev_wakeup_lat()). Returns 0 if nothing needs to be |
| 947 | * done (e.g., if the omap_device is not currently idle, or if the |
| 948 | * wakeup latency is already current with the new limit) or passes |
| 949 | * along the return value of _omap_device_deactivate() or |
| 950 | * _omap_device_activate(). |
| 951 | */ |
| 952 | int omap_device_align_pm_lat(struct platform_device *pdev, |
| 953 | u32 new_wakeup_lat_limit) |
| 954 | { |
| 955 | int ret = -EINVAL; |
| 956 | struct omap_device *od; |
| 957 | |
Kevin Hilman | 8f0d69d | 2011-07-09 19:15:20 -0600 | [diff] [blame] | 958 | od = to_omap_device(pdev); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 959 | |
| 960 | if (new_wakeup_lat_limit == od->dev_wakeup_lat) |
| 961 | return 0; |
| 962 | |
| 963 | od->_dev_wakeup_lat_limit = new_wakeup_lat_limit; |
| 964 | |
| 965 | if (od->_state != OMAP_DEVICE_STATE_IDLE) |
| 966 | return 0; |
| 967 | else if (new_wakeup_lat_limit > od->dev_wakeup_lat) |
| 968 | ret = _omap_device_deactivate(od, USE_WAKEUP_LAT); |
| 969 | else if (new_wakeup_lat_limit < od->dev_wakeup_lat) |
| 970 | ret = _omap_device_activate(od, USE_WAKEUP_LAT); |
| 971 | |
| 972 | return ret; |
| 973 | } |
| 974 | |
| 975 | /** |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 976 | * omap_device_get_pwrdm - return the powerdomain * associated with @od |
| 977 | * @od: struct omap_device * |
| 978 | * |
| 979 | * Return the powerdomain associated with the first underlying |
| 980 | * omap_hwmod for this omap_device. Intended for use by core OMAP PM |
| 981 | * code. Returns NULL on error or a struct powerdomain * upon |
| 982 | * success. |
| 983 | */ |
| 984 | struct powerdomain *omap_device_get_pwrdm(struct omap_device *od) |
| 985 | { |
| 986 | /* |
| 987 | * XXX Assumes that all omap_hwmod powerdomains are identical. |
| 988 | * This may not necessarily be true. There should be a sanity |
| 989 | * check in here to WARN() if any difference appears. |
| 990 | */ |
| 991 | if (!od->hwmods_cnt) |
| 992 | return NULL; |
| 993 | |
| 994 | return omap_hwmod_get_pwrdm(od->hwmods[0]); |
| 995 | } |
| 996 | |
Paul Walmsley | db2a60b | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 997 | /** |
| 998 | * omap_device_get_mpu_rt_va - return the MPU's virtual addr for the hwmod base |
| 999 | * @od: struct omap_device * |
| 1000 | * |
| 1001 | * Return the MPU's virtual address for the base of the hwmod, from |
| 1002 | * the ioremap() that the hwmod code does. Only valid if there is one |
| 1003 | * hwmod associated with this device. Returns NULL if there are zero |
| 1004 | * or more than one hwmods associated with this omap_device; |
| 1005 | * otherwise, passes along the return value from |
| 1006 | * omap_hwmod_get_mpu_rt_va(). |
| 1007 | */ |
| 1008 | void __iomem *omap_device_get_rt_va(struct omap_device *od) |
| 1009 | { |
| 1010 | if (od->hwmods_cnt != 1) |
| 1011 | return NULL; |
| 1012 | |
| 1013 | return omap_hwmod_get_mpu_rt_va(od->hwmods[0]); |
| 1014 | } |
| 1015 | |
Nishanth Menon | 1f8a7d5 | 2011-07-27 15:02:32 -0500 | [diff] [blame] | 1016 | /** |
| 1017 | * omap_device_get_by_hwmod_name() - convert a hwmod name to |
| 1018 | * device pointer. |
| 1019 | * @oh_name: name of the hwmod device |
| 1020 | * |
| 1021 | * Returns back a struct device * pointer associated with a hwmod |
| 1022 | * device represented by a hwmod_name |
| 1023 | */ |
| 1024 | struct device *omap_device_get_by_hwmod_name(const char *oh_name) |
| 1025 | { |
| 1026 | struct omap_hwmod *oh; |
| 1027 | |
| 1028 | if (!oh_name) { |
| 1029 | WARN(1, "%s: no hwmod name!\n", __func__); |
| 1030 | return ERR_PTR(-EINVAL); |
| 1031 | } |
| 1032 | |
| 1033 | oh = omap_hwmod_lookup(oh_name); |
| 1034 | if (IS_ERR_OR_NULL(oh)) { |
| 1035 | WARN(1, "%s: no hwmod for %s\n", __func__, |
| 1036 | oh_name); |
| 1037 | return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV); |
| 1038 | } |
| 1039 | if (IS_ERR_OR_NULL(oh->od)) { |
| 1040 | WARN(1, "%s: no omap_device for %s\n", __func__, |
| 1041 | oh_name); |
| 1042 | return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV); |
| 1043 | } |
| 1044 | |
| 1045 | if (IS_ERR_OR_NULL(oh->od->pdev)) |
| 1046 | return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV); |
| 1047 | |
| 1048 | return &oh->od->pdev->dev; |
| 1049 | } |
| 1050 | EXPORT_SYMBOL(omap_device_get_by_hwmod_name); |
| 1051 | |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1052 | /* |
| 1053 | * Public functions intended for use in omap_device_pm_latency |
| 1054 | * .activate_func and .deactivate_func function pointers |
| 1055 | */ |
| 1056 | |
| 1057 | /** |
| 1058 | * omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods |
| 1059 | * @od: struct omap_device *od |
| 1060 | * |
| 1061 | * Enable all underlying hwmods. Returns 0. |
| 1062 | */ |
| 1063 | int omap_device_enable_hwmods(struct omap_device *od) |
| 1064 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1065 | int i; |
| 1066 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1067 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1068 | omap_hwmod_enable(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1069 | |
| 1070 | /* XXX pass along return value here? */ |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods |
| 1076 | * @od: struct omap_device *od |
| 1077 | * |
| 1078 | * Idle all underlying hwmods. Returns 0. |
| 1079 | */ |
| 1080 | int omap_device_idle_hwmods(struct omap_device *od) |
| 1081 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1082 | int i; |
| 1083 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1084 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1085 | omap_hwmod_idle(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1086 | |
| 1087 | /* XXX pass along return value here? */ |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * omap_device_disable_clocks - disable all main and interface clocks |
| 1093 | * @od: struct omap_device *od |
| 1094 | * |
| 1095 | * Disable the main functional clock and interface clock for all of the |
| 1096 | * omap_hwmods associated with the omap_device. Returns 0. |
| 1097 | */ |
| 1098 | int omap_device_disable_clocks(struct omap_device *od) |
| 1099 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1100 | int i; |
| 1101 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1102 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1103 | omap_hwmod_disable_clocks(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1104 | |
| 1105 | /* XXX pass along return value here? */ |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * omap_device_enable_clocks - enable all main and interface clocks |
| 1111 | * @od: struct omap_device *od |
| 1112 | * |
| 1113 | * Enable the main functional clock and interface clock for all of the |
| 1114 | * omap_hwmods associated with the omap_device. Returns 0. |
| 1115 | */ |
| 1116 | int omap_device_enable_clocks(struct omap_device *od) |
| 1117 | { |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1118 | int i; |
| 1119 | |
Kishon Vijay Abraham I | f39f489 | 2010-09-24 10:23:18 -0600 | [diff] [blame] | 1120 | for (i = 0; i < od->hwmods_cnt; i++) |
| 1121 | omap_hwmod_enable_clocks(od->hwmods[i]); |
Paul Walmsley | b04b65a | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 1122 | |
| 1123 | /* XXX pass along return value here? */ |
| 1124 | return 0; |
| 1125 | } |
Kevin Hilman | 0d5e825 | 2010-08-23 08:10:55 -0700 | [diff] [blame] | 1126 | |
| 1127 | struct device omap_device_parent = { |
| 1128 | .init_name = "omap", |
| 1129 | .parent = &platform_bus, |
| 1130 | }; |
| 1131 | |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 1132 | static struct notifier_block platform_nb = { |
| 1133 | .notifier_call = _omap_device_notifier_call, |
| 1134 | }; |
| 1135 | |
Kevin Hilman | 0d5e825 | 2010-08-23 08:10:55 -0700 | [diff] [blame] | 1136 | static int __init omap_device_init(void) |
| 1137 | { |
Benoit Cousson | dc2d07e | 2011-08-10 13:32:08 +0200 | [diff] [blame] | 1138 | bus_register_notifier(&platform_bus_type, &platform_nb); |
Kevin Hilman | 0d5e825 | 2010-08-23 08:10:55 -0700 | [diff] [blame] | 1139 | return device_register(&omap_device_parent); |
| 1140 | } |
| 1141 | core_initcall(omap_device_init); |