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