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