Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ti-sysc.c - Texas Instruments sysc interconnect target driver |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 9 | * kind, whether express or implied; without even the implied warranty |
| 10 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/clk.h> |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 16 | #include <linux/clkdev.h> |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 17 | #include <linux/delay.h> |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/platform_device.h> |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 20 | #include <linux/pm_domain.h> |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 22 | #include <linux/reset.h> |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 23 | #include <linux/of_address.h> |
| 24 | #include <linux/of_platform.h> |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 25 | #include <linux/slab.h> |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 26 | #include <linux/iopoll.h> |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 27 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 28 | #include <linux/platform_data/ti-sysc.h> |
| 29 | |
| 30 | #include <dt-bindings/bus/ti-sysc.h> |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 31 | |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 32 | #define MAX_MODULE_SOFTRESET_WAIT 10000 |
| 33 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 34 | static const char * const reg_names[] = { "rev", "sysc", "syss", }; |
| 35 | |
| 36 | enum sysc_clocks { |
| 37 | SYSC_FCK, |
| 38 | SYSC_ICK, |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 39 | SYSC_OPTFCK0, |
| 40 | SYSC_OPTFCK1, |
| 41 | SYSC_OPTFCK2, |
| 42 | SYSC_OPTFCK3, |
| 43 | SYSC_OPTFCK4, |
| 44 | SYSC_OPTFCK5, |
| 45 | SYSC_OPTFCK6, |
| 46 | SYSC_OPTFCK7, |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 47 | SYSC_MAX_CLOCKS, |
| 48 | }; |
| 49 | |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 50 | static const char * const clock_names[SYSC_ICK + 1] = { "fck", "ick", }; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 51 | |
Tony Lindgren | c5a2de9 | 2017-12-15 09:41:23 -0800 | [diff] [blame] | 52 | #define SYSC_IDLEMODE_MASK 3 |
| 53 | #define SYSC_CLOCKACTIVITY_MASK 3 |
| 54 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 55 | /** |
| 56 | * struct sysc - TI sysc interconnect target module registers and capabilities |
| 57 | * @dev: struct device pointer |
| 58 | * @module_pa: physical address of the interconnect target module |
| 59 | * @module_size: size of the interconnect target module |
| 60 | * @module_va: virtual address of the interconnect target module |
| 61 | * @offsets: register offsets from module base |
| 62 | * @clocks: clocks used by the interconnect target module |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 63 | * @clock_roles: clock role names for the found clocks |
| 64 | * @nr_clocks: number of clocks used by the interconnect target module |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 65 | * @legacy_mode: configured for legacy mode if set |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 66 | * @cap: interconnect target module capabilities |
| 67 | * @cfg: interconnect target module configuration |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 68 | * @name: name if available |
| 69 | * @revision: interconnect target module revision |
Tony Lindgren | 62020f2 | 2018-02-22 13:59:44 -0800 | [diff] [blame] | 70 | * @needs_resume: runtime resume needed on resume from suspend |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 71 | */ |
| 72 | struct sysc { |
| 73 | struct device *dev; |
| 74 | u64 module_pa; |
| 75 | u32 module_size; |
| 76 | void __iomem *module_va; |
| 77 | int offsets[SYSC_MAX_REGS]; |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 78 | struct ti_sysc_module_data *mdata; |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 79 | struct clk **clocks; |
| 80 | const char **clock_roles; |
| 81 | int nr_clocks; |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 82 | struct reset_control *rsts; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 83 | const char *legacy_mode; |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 84 | const struct sysc_capabilities *cap; |
| 85 | struct sysc_config cfg; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 86 | struct ti_sysc_cookie cookie; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 87 | const char *name; |
| 88 | u32 revision; |
Tony Lindgren | 62020f2 | 2018-02-22 13:59:44 -0800 | [diff] [blame] | 89 | bool enabled; |
| 90 | bool needs_resume; |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 91 | bool child_needs_resume; |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 92 | struct delayed_work idle_work; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 95 | static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np, |
| 96 | bool is_child); |
| 97 | |
Tony Lindgren | b7182b4 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 98 | static void sysc_write(struct sysc *ddata, int offset, u32 value) |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 99 | { |
| 100 | writel_relaxed(value, ddata->module_va + offset); |
| 101 | } |
| 102 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 103 | static u32 sysc_read(struct sysc *ddata, int offset) |
| 104 | { |
| 105 | if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) { |
| 106 | u32 val; |
| 107 | |
| 108 | val = readw_relaxed(ddata->module_va + offset); |
| 109 | val |= (readw_relaxed(ddata->module_va + offset + 4) << 16); |
| 110 | |
| 111 | return val; |
| 112 | } |
| 113 | |
| 114 | return readl_relaxed(ddata->module_va + offset); |
| 115 | } |
| 116 | |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 117 | static bool sysc_opt_clks_needed(struct sysc *ddata) |
| 118 | { |
| 119 | return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED); |
| 120 | } |
| 121 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 122 | static u32 sysc_read_revision(struct sysc *ddata) |
| 123 | { |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 124 | int offset = ddata->offsets[SYSC_REVISION]; |
| 125 | |
| 126 | if (offset < 0) |
| 127 | return 0; |
| 128 | |
| 129 | return sysc_read(ddata, offset); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 132 | static int sysc_get_one_clock(struct sysc *ddata, const char *name) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 133 | { |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 134 | int error, i, index = -ENODEV; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 135 | |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 136 | if (!strncmp(clock_names[SYSC_FCK], name, 3)) |
| 137 | index = SYSC_FCK; |
| 138 | else if (!strncmp(clock_names[SYSC_ICK], name, 3)) |
| 139 | index = SYSC_ICK; |
| 140 | |
| 141 | if (index < 0) { |
| 142 | for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { |
Tony Lindgren | c97c862 | 2018-05-18 07:54:44 -0700 | [diff] [blame] | 143 | if (!ddata->clocks[i]) { |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 144 | index = i; |
| 145 | break; |
| 146 | } |
| 147 | } |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 148 | } |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 149 | |
| 150 | if (index < 0) { |
| 151 | dev_err(ddata->dev, "clock %s not added\n", name); |
| 152 | return index; |
| 153 | } |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 154 | |
| 155 | ddata->clocks[index] = devm_clk_get(ddata->dev, name); |
| 156 | if (IS_ERR(ddata->clocks[index])) { |
| 157 | if (PTR_ERR(ddata->clocks[index]) == -ENOENT) |
| 158 | return 0; |
| 159 | |
| 160 | dev_err(ddata->dev, "clock get error for %s: %li\n", |
| 161 | name, PTR_ERR(ddata->clocks[index])); |
| 162 | |
| 163 | return PTR_ERR(ddata->clocks[index]); |
| 164 | } |
| 165 | |
| 166 | error = clk_prepare(ddata->clocks[index]); |
| 167 | if (error) { |
| 168 | dev_err(ddata->dev, "clock prepare error for %s: %i\n", |
| 169 | name, error); |
| 170 | |
| 171 | return error; |
| 172 | } |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static int sysc_get_clocks(struct sysc *ddata) |
| 178 | { |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 179 | struct device_node *np = ddata->dev->of_node; |
| 180 | struct property *prop; |
| 181 | const char *name; |
| 182 | int nr_fck = 0, nr_ick = 0, i, error = 0; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 183 | |
Kees Cook | 2074905 | 2018-06-18 10:45:49 -0700 | [diff] [blame] | 184 | ddata->clock_roles = devm_kcalloc(ddata->dev, |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 185 | SYSC_MAX_CLOCKS, |
Kees Cook | 2074905 | 2018-06-18 10:45:49 -0700 | [diff] [blame] | 186 | sizeof(*ddata->clock_roles), |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 187 | GFP_KERNEL); |
| 188 | if (!ddata->clock_roles) |
| 189 | return -ENOMEM; |
| 190 | |
| 191 | of_property_for_each_string(np, "clock-names", prop, name) { |
| 192 | if (!strncmp(clock_names[SYSC_FCK], name, 3)) |
| 193 | nr_fck++; |
| 194 | if (!strncmp(clock_names[SYSC_ICK], name, 3)) |
| 195 | nr_ick++; |
| 196 | ddata->clock_roles[ddata->nr_clocks] = name; |
| 197 | ddata->nr_clocks++; |
| 198 | } |
| 199 | |
| 200 | if (ddata->nr_clocks < 1) |
| 201 | return 0; |
| 202 | |
| 203 | if (ddata->nr_clocks > SYSC_MAX_CLOCKS) { |
| 204 | dev_err(ddata->dev, "too many clocks for %pOF\n", np); |
| 205 | |
| 206 | return -EINVAL; |
| 207 | } |
| 208 | |
| 209 | if (nr_fck > 1 || nr_ick > 1) { |
| 210 | dev_err(ddata->dev, "max one fck and ick for %pOF\n", np); |
| 211 | |
| 212 | return -EINVAL; |
| 213 | } |
| 214 | |
Kees Cook | 2074905 | 2018-06-18 10:45:49 -0700 | [diff] [blame] | 215 | ddata->clocks = devm_kcalloc(ddata->dev, |
| 216 | ddata->nr_clocks, sizeof(*ddata->clocks), |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 217 | GFP_KERNEL); |
| 218 | if (!ddata->clocks) |
| 219 | return -ENOMEM; |
| 220 | |
Tony Lindgren | 7b4f8ac | 2018-11-15 14:46:52 -0800 | [diff] [blame] | 221 | for (i = 0; i < SYSC_MAX_CLOCKS; i++) { |
| 222 | const char *name = ddata->clock_roles[i]; |
| 223 | |
| 224 | if (!name) |
| 225 | continue; |
| 226 | |
| 227 | error = sysc_get_one_clock(ddata, name); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 228 | if (error && error != -ENOENT) |
| 229 | return error; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 235 | static int sysc_enable_main_clocks(struct sysc *ddata) |
| 236 | { |
| 237 | struct clk *clock; |
| 238 | int i, error; |
| 239 | |
| 240 | if (!ddata->clocks) |
| 241 | return 0; |
| 242 | |
| 243 | for (i = 0; i < SYSC_OPTFCK0; i++) { |
| 244 | clock = ddata->clocks[i]; |
| 245 | |
| 246 | /* Main clocks may not have ick */ |
| 247 | if (IS_ERR_OR_NULL(clock)) |
| 248 | continue; |
| 249 | |
| 250 | error = clk_enable(clock); |
| 251 | if (error) |
| 252 | goto err_disable; |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | |
| 257 | err_disable: |
| 258 | for (i--; i >= 0; i--) { |
| 259 | clock = ddata->clocks[i]; |
| 260 | |
| 261 | /* Main clocks may not have ick */ |
| 262 | if (IS_ERR_OR_NULL(clock)) |
| 263 | continue; |
| 264 | |
| 265 | clk_disable(clock); |
| 266 | } |
| 267 | |
| 268 | return error; |
| 269 | } |
| 270 | |
| 271 | static void sysc_disable_main_clocks(struct sysc *ddata) |
| 272 | { |
| 273 | struct clk *clock; |
| 274 | int i; |
| 275 | |
| 276 | if (!ddata->clocks) |
| 277 | return; |
| 278 | |
| 279 | for (i = 0; i < SYSC_OPTFCK0; i++) { |
| 280 | clock = ddata->clocks[i]; |
| 281 | if (IS_ERR_OR_NULL(clock)) |
| 282 | continue; |
| 283 | |
| 284 | clk_disable(clock); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | static int sysc_enable_opt_clocks(struct sysc *ddata) |
| 289 | { |
| 290 | struct clk *clock; |
| 291 | int i, error; |
| 292 | |
| 293 | if (!ddata->clocks) |
| 294 | return 0; |
| 295 | |
| 296 | for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { |
| 297 | clock = ddata->clocks[i]; |
| 298 | |
| 299 | /* Assume no holes for opt clocks */ |
| 300 | if (IS_ERR_OR_NULL(clock)) |
| 301 | return 0; |
| 302 | |
| 303 | error = clk_enable(clock); |
| 304 | if (error) |
| 305 | goto err_disable; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | |
| 310 | err_disable: |
| 311 | for (i--; i >= 0; i--) { |
| 312 | clock = ddata->clocks[i]; |
| 313 | if (IS_ERR_OR_NULL(clock)) |
| 314 | continue; |
| 315 | |
| 316 | clk_disable(clock); |
| 317 | } |
| 318 | |
| 319 | return error; |
| 320 | } |
| 321 | |
| 322 | static void sysc_disable_opt_clocks(struct sysc *ddata) |
| 323 | { |
| 324 | struct clk *clock; |
| 325 | int i; |
| 326 | |
| 327 | if (!ddata->clocks) |
| 328 | return; |
| 329 | |
| 330 | for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { |
| 331 | clock = ddata->clocks[i]; |
| 332 | |
| 333 | /* Assume no holes for opt clocks */ |
| 334 | if (IS_ERR_OR_NULL(clock)) |
| 335 | return; |
| 336 | |
| 337 | clk_disable(clock); |
| 338 | } |
| 339 | } |
| 340 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 341 | /** |
Tony Lindgren | b11c1ea | 2019-03-21 11:00:21 -0700 | [diff] [blame^] | 342 | * sysc_init_resets - init rstctrl reset line if configured |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 343 | * @ddata: device driver data |
| 344 | * |
Tony Lindgren | b11c1ea | 2019-03-21 11:00:21 -0700 | [diff] [blame^] | 345 | * See sysc_rstctrl_reset_deassert(). |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 346 | */ |
| 347 | static int sysc_init_resets(struct sysc *ddata) |
| 348 | { |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 349 | ddata->rsts = |
| 350 | devm_reset_control_array_get_optional_exclusive(ddata->dev); |
| 351 | if (IS_ERR(ddata->rsts)) |
| 352 | return PTR_ERR(ddata->rsts); |
| 353 | |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | /** |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 358 | * sysc_parse_and_check_child_range - parses module IO region from ranges |
| 359 | * @ddata: device driver data |
| 360 | * |
| 361 | * In general we only need rev, syss, and sysc registers and not the whole |
| 362 | * module range. But we do want the offsets for these registers from the |
| 363 | * module base. This allows us to check them against the legacy hwmod |
| 364 | * platform data. Let's also check the ranges are configured properly. |
| 365 | */ |
| 366 | static int sysc_parse_and_check_child_range(struct sysc *ddata) |
| 367 | { |
| 368 | struct device_node *np = ddata->dev->of_node; |
| 369 | const __be32 *ranges; |
| 370 | u32 nr_addr, nr_size; |
| 371 | int len, error; |
| 372 | |
| 373 | ranges = of_get_property(np, "ranges", &len); |
| 374 | if (!ranges) { |
| 375 | dev_err(ddata->dev, "missing ranges for %pOF\n", np); |
| 376 | |
| 377 | return -ENOENT; |
| 378 | } |
| 379 | |
| 380 | len /= sizeof(*ranges); |
| 381 | |
| 382 | if (len < 3) { |
| 383 | dev_err(ddata->dev, "incomplete ranges for %pOF\n", np); |
| 384 | |
| 385 | return -EINVAL; |
| 386 | } |
| 387 | |
| 388 | error = of_property_read_u32(np, "#address-cells", &nr_addr); |
| 389 | if (error) |
| 390 | return -ENOENT; |
| 391 | |
| 392 | error = of_property_read_u32(np, "#size-cells", &nr_size); |
| 393 | if (error) |
| 394 | return -ENOENT; |
| 395 | |
| 396 | if (nr_addr != 1 || nr_size != 1) { |
| 397 | dev_err(ddata->dev, "invalid ranges for %pOF\n", np); |
| 398 | |
| 399 | return -EINVAL; |
| 400 | } |
| 401 | |
| 402 | ranges++; |
| 403 | ddata->module_pa = of_translate_address(np, ranges++); |
| 404 | ddata->module_size = be32_to_cpup(ranges); |
| 405 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
Tony Lindgren | 3bb37c8 | 2018-02-22 14:05:14 -0800 | [diff] [blame] | 409 | static struct device_node *stdout_path; |
| 410 | |
| 411 | static void sysc_init_stdout_path(struct sysc *ddata) |
| 412 | { |
| 413 | struct device_node *np = NULL; |
| 414 | const char *uart; |
| 415 | |
| 416 | if (IS_ERR(stdout_path)) |
| 417 | return; |
| 418 | |
| 419 | if (stdout_path) |
| 420 | return; |
| 421 | |
| 422 | np = of_find_node_by_path("/chosen"); |
| 423 | if (!np) |
| 424 | goto err; |
| 425 | |
| 426 | uart = of_get_property(np, "stdout-path", NULL); |
| 427 | if (!uart) |
| 428 | goto err; |
| 429 | |
| 430 | np = of_find_node_by_path(uart); |
| 431 | if (!np) |
| 432 | goto err; |
| 433 | |
| 434 | stdout_path = np; |
| 435 | |
| 436 | return; |
| 437 | |
| 438 | err: |
| 439 | stdout_path = ERR_PTR(-ENODEV); |
| 440 | } |
| 441 | |
| 442 | static void sysc_check_quirk_stdout(struct sysc *ddata, |
| 443 | struct device_node *np) |
| 444 | { |
| 445 | sysc_init_stdout_path(ddata); |
| 446 | if (np != stdout_path) |
| 447 | return; |
| 448 | |
| 449 | ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT | |
| 450 | SYSC_QUIRK_NO_RESET_ON_INIT; |
| 451 | } |
| 452 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 453 | /** |
| 454 | * sysc_check_one_child - check child configuration |
| 455 | * @ddata: device driver data |
| 456 | * @np: child device node |
| 457 | * |
| 458 | * Let's avoid messy situations where we have new interconnect target |
| 459 | * node but children have "ti,hwmods". These belong to the interconnect |
| 460 | * target node and are managed by this driver. |
| 461 | */ |
| 462 | static int sysc_check_one_child(struct sysc *ddata, |
| 463 | struct device_node *np) |
| 464 | { |
| 465 | const char *name; |
| 466 | |
| 467 | name = of_get_property(np, "ti,hwmods", NULL); |
| 468 | if (name) |
| 469 | dev_warn(ddata->dev, "really a child ti,hwmods property?"); |
| 470 | |
Tony Lindgren | 3bb37c8 | 2018-02-22 14:05:14 -0800 | [diff] [blame] | 471 | sysc_check_quirk_stdout(ddata, np); |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 472 | sysc_parse_dts_quirks(ddata, np, true); |
Tony Lindgren | 3bb37c8 | 2018-02-22 14:05:14 -0800 | [diff] [blame] | 473 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | static int sysc_check_children(struct sysc *ddata) |
| 478 | { |
| 479 | struct device_node *child; |
| 480 | int error; |
| 481 | |
| 482 | for_each_child_of_node(ddata->dev->of_node, child) { |
| 483 | error = sysc_check_one_child(ddata, child); |
| 484 | if (error) |
| 485 | return error; |
| 486 | } |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
Tony Lindgren | a7199e2 | 2017-12-15 09:41:14 -0800 | [diff] [blame] | 491 | /* |
| 492 | * So far only I2C uses 16-bit read access with clockactivity with revision |
| 493 | * in two registers with stride of 4. We can detect this based on the rev |
| 494 | * register size to configure things far enough to be able to properly read |
| 495 | * the revision register. |
| 496 | */ |
| 497 | static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res) |
| 498 | { |
Tony Lindgren | dd57ac1 | 2018-02-22 14:09:57 -0800 | [diff] [blame] | 499 | if (resource_size(res) == 8) |
Tony Lindgren | a7199e2 | 2017-12-15 09:41:14 -0800 | [diff] [blame] | 500 | ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT; |
Tony Lindgren | a7199e2 | 2017-12-15 09:41:14 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 503 | /** |
| 504 | * sysc_parse_one - parses the interconnect target module registers |
| 505 | * @ddata: device driver data |
| 506 | * @reg: register to parse |
| 507 | */ |
| 508 | static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg) |
| 509 | { |
| 510 | struct resource *res; |
| 511 | const char *name; |
| 512 | |
| 513 | switch (reg) { |
| 514 | case SYSC_REVISION: |
| 515 | case SYSC_SYSCONFIG: |
| 516 | case SYSC_SYSSTATUS: |
| 517 | name = reg_names[reg]; |
| 518 | break; |
| 519 | default: |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | |
| 523 | res = platform_get_resource_byname(to_platform_device(ddata->dev), |
| 524 | IORESOURCE_MEM, name); |
| 525 | if (!res) { |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 526 | ddata->offsets[reg] = -ENODEV; |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | ddata->offsets[reg] = res->start - ddata->module_pa; |
Tony Lindgren | a7199e2 | 2017-12-15 09:41:14 -0800 | [diff] [blame] | 532 | if (reg == SYSC_REVISION) |
| 533 | sysc_check_quirk_16bit(ddata, res); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 534 | |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int sysc_parse_registers(struct sysc *ddata) |
| 539 | { |
| 540 | int i, error; |
| 541 | |
| 542 | for (i = 0; i < SYSC_MAX_REGS; i++) { |
| 543 | error = sysc_parse_one(ddata, i); |
| 544 | if (error) |
| 545 | return error; |
| 546 | } |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * sysc_check_registers - check for misconfigured register overlaps |
| 553 | * @ddata: device driver data |
| 554 | */ |
| 555 | static int sysc_check_registers(struct sysc *ddata) |
| 556 | { |
| 557 | int i, j, nr_regs = 0, nr_matches = 0; |
| 558 | |
| 559 | for (i = 0; i < SYSC_MAX_REGS; i++) { |
| 560 | if (ddata->offsets[i] < 0) |
| 561 | continue; |
| 562 | |
| 563 | if (ddata->offsets[i] > (ddata->module_size - 4)) { |
| 564 | dev_err(ddata->dev, "register outside module range"); |
| 565 | |
| 566 | return -EINVAL; |
| 567 | } |
| 568 | |
| 569 | for (j = 0; j < SYSC_MAX_REGS; j++) { |
| 570 | if (ddata->offsets[j] < 0) |
| 571 | continue; |
| 572 | |
| 573 | if (ddata->offsets[i] == ddata->offsets[j]) |
| 574 | nr_matches++; |
| 575 | } |
| 576 | nr_regs++; |
| 577 | } |
| 578 | |
| 579 | if (nr_regs < 1) { |
| 580 | dev_err(ddata->dev, "missing registers\n"); |
| 581 | |
| 582 | return -EINVAL; |
| 583 | } |
| 584 | |
| 585 | if (nr_matches > nr_regs) { |
| 586 | dev_err(ddata->dev, "overlapping registers: (%i/%i)", |
| 587 | nr_regs, nr_matches); |
| 588 | |
| 589 | return -EINVAL; |
| 590 | } |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * syc_ioremap - ioremap register space for the interconnect target module |
Tony Lindgren | 0ef8e3b | 2018-08-08 01:07:05 -0700 | [diff] [blame] | 597 | * @ddata: device driver data |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 598 | * |
| 599 | * Note that the interconnect target module registers can be anywhere |
Tony Lindgren | 0ef8e3b | 2018-08-08 01:07:05 -0700 | [diff] [blame] | 600 | * within the interconnect target module range. For example, SGX has |
| 601 | * them at offset 0x1fc00 in the 32MB module address space. And cpsw |
| 602 | * has them at offset 0x1200 in the CPSW_WR child. Usually the |
| 603 | * the interconnect target module registers are at the beginning of |
| 604 | * the module range though. |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 605 | */ |
| 606 | static int sysc_ioremap(struct sysc *ddata) |
| 607 | { |
Tony Lindgren | 0ef8e3b | 2018-08-08 01:07:05 -0700 | [diff] [blame] | 608 | int size; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 609 | |
Tony Lindgren | 0ef8e3b | 2018-08-08 01:07:05 -0700 | [diff] [blame] | 610 | size = max3(ddata->offsets[SYSC_REVISION], |
| 611 | ddata->offsets[SYSC_SYSCONFIG], |
| 612 | ddata->offsets[SYSC_SYSSTATUS]); |
| 613 | |
| 614 | if (size < 0 || (size + sizeof(u32)) > ddata->module_size) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 615 | return -EINVAL; |
| 616 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 617 | ddata->module_va = devm_ioremap(ddata->dev, |
| 618 | ddata->module_pa, |
Tony Lindgren | 0ef8e3b | 2018-08-08 01:07:05 -0700 | [diff] [blame] | 619 | size + sizeof(u32)); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 620 | if (!ddata->module_va) |
| 621 | return -EIO; |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * sysc_map_and_check_registers - ioremap and check device registers |
| 628 | * @ddata: device driver data |
| 629 | */ |
| 630 | static int sysc_map_and_check_registers(struct sysc *ddata) |
| 631 | { |
| 632 | int error; |
| 633 | |
| 634 | error = sysc_parse_and_check_child_range(ddata); |
| 635 | if (error) |
| 636 | return error; |
| 637 | |
| 638 | error = sysc_check_children(ddata); |
| 639 | if (error) |
| 640 | return error; |
| 641 | |
| 642 | error = sysc_parse_registers(ddata); |
| 643 | if (error) |
| 644 | return error; |
| 645 | |
| 646 | error = sysc_ioremap(ddata); |
| 647 | if (error) |
| 648 | return error; |
| 649 | |
| 650 | error = sysc_check_registers(ddata); |
| 651 | if (error) |
| 652 | return error; |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * sysc_show_rev - read and show interconnect target module revision |
| 659 | * @bufp: buffer to print the information to |
| 660 | * @ddata: device driver data |
| 661 | */ |
| 662 | static int sysc_show_rev(char *bufp, struct sysc *ddata) |
| 663 | { |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 664 | int len; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 665 | |
| 666 | if (ddata->offsets[SYSC_REVISION] < 0) |
| 667 | return sprintf(bufp, ":NA"); |
| 668 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 669 | len = sprintf(bufp, ":%08x", ddata->revision); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 670 | |
| 671 | return len; |
| 672 | } |
| 673 | |
| 674 | static int sysc_show_reg(struct sysc *ddata, |
| 675 | char *bufp, enum sysc_registers reg) |
| 676 | { |
| 677 | if (ddata->offsets[reg] < 0) |
| 678 | return sprintf(bufp, ":NA"); |
| 679 | |
| 680 | return sprintf(bufp, ":%x", ddata->offsets[reg]); |
| 681 | } |
| 682 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 683 | static int sysc_show_name(char *bufp, struct sysc *ddata) |
| 684 | { |
| 685 | if (!ddata->name) |
| 686 | return 0; |
| 687 | |
| 688 | return sprintf(bufp, ":%s", ddata->name); |
| 689 | } |
| 690 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 691 | /** |
| 692 | * sysc_show_registers - show information about interconnect target module |
| 693 | * @ddata: device driver data |
| 694 | */ |
| 695 | static void sysc_show_registers(struct sysc *ddata) |
| 696 | { |
| 697 | char buf[128]; |
| 698 | char *bufp = buf; |
| 699 | int i; |
| 700 | |
| 701 | for (i = 0; i < SYSC_MAX_REGS; i++) |
| 702 | bufp += sysc_show_reg(ddata, bufp, i); |
| 703 | |
| 704 | bufp += sysc_show_rev(bufp, ddata); |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 705 | bufp += sysc_show_name(bufp, ddata); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 706 | |
| 707 | dev_dbg(ddata->dev, "%llx:%x%s\n", |
| 708 | ddata->module_pa, ddata->module_size, |
| 709 | buf); |
| 710 | } |
| 711 | |
Tony Lindgren | ff43728 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 712 | static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev, |
| 713 | struct sysc *ddata) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 714 | { |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 715 | struct ti_sysc_platform_data *pdata; |
Tony Lindgren | ff43728 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 716 | int error; |
| 717 | |
| 718 | pdata = dev_get_platdata(ddata->dev); |
| 719 | if (!pdata) |
| 720 | return 0; |
| 721 | |
| 722 | if (!pdata->idle_module) |
| 723 | return -ENODEV; |
| 724 | |
| 725 | error = pdata->idle_module(dev, &ddata->cookie); |
| 726 | if (error) |
| 727 | dev_err(dev, "%s: could not idle: %i\n", |
| 728 | __func__, error); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev, |
| 734 | struct sysc *ddata) |
| 735 | { |
| 736 | struct ti_sysc_platform_data *pdata; |
| 737 | int error; |
| 738 | |
| 739 | pdata = dev_get_platdata(ddata->dev); |
| 740 | if (!pdata) |
| 741 | return 0; |
| 742 | |
| 743 | if (!pdata->enable_module) |
| 744 | return -ENODEV; |
| 745 | |
| 746 | error = pdata->enable_module(dev, &ddata->cookie); |
| 747 | if (error) |
| 748 | dev_err(dev, "%s: could not enable: %i\n", |
| 749 | __func__, error); |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static int __maybe_unused sysc_runtime_suspend(struct device *dev) |
| 755 | { |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 756 | struct sysc *ddata; |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 757 | int error = 0; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 758 | |
| 759 | ddata = dev_get_drvdata(dev); |
| 760 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 761 | if (!ddata->enabled) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 762 | return 0; |
| 763 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 764 | if (ddata->legacy_mode) { |
Tony Lindgren | ff43728 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 765 | error = sysc_runtime_suspend_legacy(dev, ddata); |
Tony Lindgren | 93de83a | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 766 | if (error) |
| 767 | return error; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 770 | sysc_disable_main_clocks(ddata); |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 771 | |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 772 | if (sysc_opt_clks_needed(ddata)) |
| 773 | sysc_disable_opt_clocks(ddata); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 774 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 775 | ddata->enabled = false; |
| 776 | |
| 777 | return error; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Arnd Bergmann | a4a5d49 | 2017-10-13 11:25:32 +0200 | [diff] [blame] | 780 | static int __maybe_unused sysc_runtime_resume(struct device *dev) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 781 | { |
| 782 | struct sysc *ddata; |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 783 | int error = 0; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 784 | |
| 785 | ddata = dev_get_drvdata(dev); |
| 786 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 787 | if (ddata->enabled) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 788 | return 0; |
| 789 | |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 790 | if (sysc_opt_clks_needed(ddata)) { |
| 791 | error = sysc_enable_opt_clocks(ddata); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 792 | if (error) |
| 793 | return error; |
| 794 | } |
| 795 | |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 796 | error = sysc_enable_main_clocks(ddata); |
| 797 | if (error) |
Tony Lindgren | 93de83a | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 798 | goto err_opt_clocks; |
| 799 | |
| 800 | if (ddata->legacy_mode) { |
| 801 | error = sysc_runtime_resume_legacy(dev, ddata); |
| 802 | if (error) |
| 803 | goto err_main_clocks; |
| 804 | } |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 805 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 806 | ddata->enabled = true; |
| 807 | |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 808 | return 0; |
| 809 | |
| 810 | err_main_clocks: |
Tony Lindgren | 93de83a | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 811 | sysc_disable_main_clocks(ddata); |
| 812 | err_opt_clocks: |
Tony Lindgren | d878970 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 813 | if (sysc_opt_clks_needed(ddata)) |
| 814 | sysc_disable_opt_clocks(ddata); |
| 815 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 816 | return error; |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Tony Lindgren | f5e80203 | 2018-10-01 09:33:28 -0700 | [diff] [blame] | 819 | static int __maybe_unused sysc_noirq_suspend(struct device *dev) |
Tony Lindgren | 62020f2 | 2018-02-22 13:59:44 -0800 | [diff] [blame] | 820 | { |
| 821 | struct sysc *ddata; |
| 822 | |
| 823 | ddata = dev_get_drvdata(dev); |
| 824 | |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 825 | if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE) |
Tony Lindgren | e7420c2 | 2018-04-16 10:26:46 -0700 | [diff] [blame] | 826 | return 0; |
| 827 | |
Tony Lindgren | f5e80203 | 2018-10-01 09:33:28 -0700 | [diff] [blame] | 828 | return pm_runtime_force_suspend(dev); |
Tony Lindgren | 62020f2 | 2018-02-22 13:59:44 -0800 | [diff] [blame] | 829 | } |
| 830 | |
Tony Lindgren | f5e80203 | 2018-10-01 09:33:28 -0700 | [diff] [blame] | 831 | static int __maybe_unused sysc_noirq_resume(struct device *dev) |
Tony Lindgren | 62020f2 | 2018-02-22 13:59:44 -0800 | [diff] [blame] | 832 | { |
| 833 | struct sysc *ddata; |
| 834 | |
| 835 | ddata = dev_get_drvdata(dev); |
Tony Lindgren | e7420c2 | 2018-04-16 10:26:46 -0700 | [diff] [blame] | 836 | |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 837 | if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE) |
Tony Lindgren | e7420c2 | 2018-04-16 10:26:46 -0700 | [diff] [blame] | 838 | return 0; |
| 839 | |
Tony Lindgren | f5e80203 | 2018-10-01 09:33:28 -0700 | [diff] [blame] | 840 | return pm_runtime_force_resume(dev); |
Tony Lindgren | e7420c2 | 2018-04-16 10:26:46 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 843 | static const struct dev_pm_ops sysc_pm_ops = { |
Tony Lindgren | e7420c2 | 2018-04-16 10:26:46 -0700 | [diff] [blame] | 844 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume) |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 845 | SET_RUNTIME_PM_OPS(sysc_runtime_suspend, |
| 846 | sysc_runtime_resume, |
| 847 | NULL) |
| 848 | }; |
| 849 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 850 | /* Module revision register based quirks */ |
| 851 | struct sysc_revision_quirk { |
| 852 | const char *name; |
| 853 | u32 base; |
| 854 | int rev_offset; |
| 855 | int sysc_offset; |
| 856 | int syss_offset; |
| 857 | u32 revision; |
| 858 | u32 revision_mask; |
| 859 | u32 quirks; |
| 860 | }; |
| 861 | |
| 862 | #define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \ |
| 863 | optrev_val, optrevmask, optquirkmask) \ |
| 864 | { \ |
| 865 | .name = (optname), \ |
| 866 | .base = (optbase), \ |
| 867 | .rev_offset = (optrev), \ |
| 868 | .sysc_offset = (optsysc), \ |
| 869 | .syss_offset = (optsyss), \ |
| 870 | .revision = (optrev_val), \ |
| 871 | .revision_mask = (optrevmask), \ |
| 872 | .quirks = (optquirkmask), \ |
| 873 | } |
| 874 | |
| 875 | static const struct sysc_revision_quirk sysc_revision_quirks[] = { |
| 876 | /* These drivers need to be fixed to not use pm_runtime_irq_safe() */ |
Tony Lindgren | 3a3d802 | 2018-09-27 13:33:58 -0700 | [diff] [blame] | 877 | SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff, |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 878 | SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET), |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 879 | SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff, |
| 880 | SYSC_QUIRK_LEGACY_IDLE), |
| 881 | SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff, |
| 882 | SYSC_QUIRK_LEGACY_IDLE), |
| 883 | SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff, |
| 884 | SYSC_QUIRK_LEGACY_IDLE), |
| 885 | SYSC_QUIRK("smartreflex", 0, -1, 0x24, -1, 0x00000000, 0xffffffff, |
| 886 | SYSC_QUIRK_LEGACY_IDLE), |
| 887 | SYSC_QUIRK("smartreflex", 0, -1, 0x38, -1, 0x00000000, 0xffffffff, |
| 888 | SYSC_QUIRK_LEGACY_IDLE), |
| 889 | SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, |
Tony Lindgren | 9bd34c6 | 2019-01-22 09:03:08 -0800 | [diff] [blame] | 890 | 0), |
Tony Lindgren | 8cde5d5 | 2018-04-16 10:25:15 -0700 | [diff] [blame] | 891 | /* Some timers on omap4 and later */ |
Tony Lindgren | 3a3d802 | 2018-09-27 13:33:58 -0700 | [diff] [blame] | 892 | SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x50002100, 0xffffffff, |
Tony Lindgren | 072167d | 2019-01-29 07:53:47 -0800 | [diff] [blame] | 893 | 0), |
Tony Lindgren | 3a3d802 | 2018-09-27 13:33:58 -0700 | [diff] [blame] | 894 | SYSC_QUIRK("timer", 0, 0, 0x10, -1, 0x4fff1301, 0xffff00ff, |
Tony Lindgren | 9bd34c6 | 2019-01-22 09:03:08 -0800 | [diff] [blame] | 895 | 0), |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 896 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff, |
| 897 | SYSC_QUIRK_LEGACY_IDLE), |
Tony Lindgren | d708bb1 | 2018-04-16 10:25:32 -0700 | [diff] [blame] | 898 | /* Uarts on omap4 and later */ |
Tony Lindgren | b82beef | 2018-09-24 12:16:59 -0700 | [diff] [blame] | 899 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff, |
| 900 | SYSC_QUIRK_LEGACY_IDLE), |
| 901 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff, |
Tony Lindgren | d708bb1 | 2018-04-16 10:25:32 -0700 | [diff] [blame] | 902 | SYSC_QUIRK_LEGACY_IDLE), |
Tony Lindgren | 7e27e5d | 2018-04-20 14:54:16 -0700 | [diff] [blame] | 903 | |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 904 | #ifdef DEBUG |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 905 | SYSC_QUIRK("adc", 0, 0, 0x10, -1, 0x47300001, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 906 | SYSC_QUIRK("atl", 0, 0, -1, -1, 0x0a070100, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 907 | SYSC_QUIRK("aess", 0, 0, 0x10, -1, 0x40000000, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 908 | SYSC_QUIRK("cm", 0, 0, -1, -1, 0x40000301, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 909 | SYSC_QUIRK("control", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 910 | SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902, |
Tony Lindgren | 23731ea | 2018-09-24 12:17:09 -0700 | [diff] [blame] | 911 | 0xffff00f0, 0), |
| 912 | SYSC_QUIRK("dcan", 0, 0, -1, -1, 0xffffffff, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 913 | SYSC_QUIRK("dcan", 0, 0, -1, -1, 0x00001401, 0xffffffff, 0), |
| 914 | SYSC_QUIRK("dwc3", 0, 0, 0x10, -1, 0x500a0200, 0xffffffff, 0), |
| 915 | SYSC_QUIRK("epwmss", 0, 0, 0x4, -1, 0x47400001, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 916 | SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -1, 0, 0, 0), |
| 917 | SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 918 | SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 919 | SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0), |
| 920 | SYSC_QUIRK("iss", 0, 0, 0x10, -1, 0x40000101, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 921 | SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0, 0), |
Tony Lindgren | 23731ea | 2018-09-24 12:17:09 -0700 | [diff] [blame] | 922 | SYSC_QUIRK("lcdc", 0, 0, 0x54, -1, 0x4f201000, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 923 | SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44306302, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 924 | SYSC_QUIRK("mcasp", 0, 0, 0x4, -1, 0x44307b02, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 925 | SYSC_QUIRK("mcbsp", 0, -1, 0x8c, -1, 0, 0, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 926 | SYSC_QUIRK("mcspi", 0, 0, 0x10, -1, 0x40300a0b, 0xffff00ff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 927 | SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 928 | SYSC_QUIRK("mailbox", 0, 0, 0x10, -1, 0x00000400, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 929 | SYSC_QUIRK("m3", 0, 0, -1, -1, 0x5f580105, 0x0fff0f00, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 930 | SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 931 | SYSC_QUIRK("ocp2scp", 0, 0, -1, -1, 0x50060007, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 932 | SYSC_QUIRK("padconf", 0, 0, 0x10, -1, 0x4fff0800, 0xffffffff, 0), |
Tony Lindgren | f010670 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 933 | SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 934 | SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0), |
Tony Lindgren | 23731ea | 2018-09-24 12:17:09 -0700 | [diff] [blame] | 935 | SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 936 | SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 937 | SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0), |
Tony Lindgren | 23731ea | 2018-09-24 12:17:09 -0700 | [diff] [blame] | 938 | SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 939 | SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 940 | SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 941 | SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 942 | SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 943 | SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 944 | SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 945 | SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0), |
| 946 | SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0), |
| 947 | SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 948 | SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 949 | SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 950 | SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 951 | SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0), |
Tony Lindgren | f010670 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 952 | SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 953 | SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0), |
Tony Lindgren | f010670 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 954 | SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 955 | SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050, |
| 956 | 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 957 | SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0, 0), |
| 958 | SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 959 | #endif |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 960 | }; |
| 961 | |
| 962 | static void sysc_init_revision_quirks(struct sysc *ddata) |
| 963 | { |
| 964 | const struct sysc_revision_quirk *q; |
| 965 | int i; |
| 966 | |
| 967 | for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) { |
| 968 | q = &sysc_revision_quirks[i]; |
| 969 | |
| 970 | if (q->base && q->base != ddata->module_pa) |
| 971 | continue; |
| 972 | |
| 973 | if (q->rev_offset >= 0 && |
| 974 | q->rev_offset != ddata->offsets[SYSC_REVISION]) |
| 975 | continue; |
| 976 | |
| 977 | if (q->sysc_offset >= 0 && |
| 978 | q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG]) |
| 979 | continue; |
| 980 | |
| 981 | if (q->syss_offset >= 0 && |
| 982 | q->syss_offset != ddata->offsets[SYSC_SYSSTATUS]) |
| 983 | continue; |
| 984 | |
| 985 | if (q->revision == ddata->revision || |
| 986 | (q->revision & q->revision_mask) == |
| 987 | (ddata->revision & q->revision_mask)) { |
| 988 | ddata->name = q->name; |
| 989 | ddata->cfg.quirks |= q->quirks; |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 994 | /* |
| 995 | * Note that pdata->init_module() typically does a reset first. After |
| 996 | * pdata->init_module() is done, PM runtime can be used for the interconnect |
| 997 | * target module. |
| 998 | */ |
| 999 | static int sysc_legacy_init(struct sysc *ddata) |
| 1000 | { |
| 1001 | struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); |
| 1002 | int error; |
| 1003 | |
| 1004 | if (!ddata->legacy_mode || !pdata || !pdata->init_module) |
| 1005 | return 0; |
| 1006 | |
| 1007 | error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie); |
| 1008 | if (error == -EEXIST) |
| 1009 | error = 0; |
| 1010 | |
| 1011 | return error; |
| 1012 | } |
| 1013 | |
Tony Lindgren | b11c1ea | 2019-03-21 11:00:21 -0700 | [diff] [blame^] | 1014 | /** |
| 1015 | * sysc_rstctrl_reset_deassert - deassert rstctrl reset |
| 1016 | * @ddata: device driver data |
| 1017 | * @reset: reset before deassert |
| 1018 | * |
| 1019 | * A module can have both OCP softreset control and external rstctrl. |
| 1020 | * If more complicated rstctrl resets are needed, please handle these |
| 1021 | * directly from the child device driver and map only the module reset |
| 1022 | * for the parent interconnect target module device. |
| 1023 | * |
| 1024 | * Automatic reset of the module on init can be skipped with the |
| 1025 | * "ti,no-reset-on-init" device tree property. |
| 1026 | */ |
| 1027 | static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset) |
| 1028 | { |
| 1029 | int error; |
| 1030 | |
| 1031 | if (!ddata->rsts) |
| 1032 | return 0; |
| 1033 | |
| 1034 | if (reset) { |
| 1035 | error = reset_control_assert(ddata->rsts); |
| 1036 | if (error) |
| 1037 | return error; |
| 1038 | } |
| 1039 | |
| 1040 | return reset_control_deassert(ddata->rsts); |
| 1041 | } |
| 1042 | |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 1043 | static int sysc_reset(struct sysc *ddata) |
| 1044 | { |
| 1045 | int offset = ddata->offsets[SYSC_SYSCONFIG]; |
| 1046 | int val; |
| 1047 | |
| 1048 | if (ddata->legacy_mode || offset < 0 || |
| 1049 | ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) |
| 1050 | return 0; |
| 1051 | |
| 1052 | /* |
| 1053 | * Currently only support reset status in sysstatus. |
| 1054 | * Warn and return error in all other cases |
| 1055 | */ |
| 1056 | if (!ddata->cfg.syss_mask) { |
| 1057 | dev_err(ddata->dev, "No ti,syss-mask. Reset failed\n"); |
| 1058 | return -EINVAL; |
| 1059 | } |
| 1060 | |
| 1061 | val = sysc_read(ddata, offset); |
| 1062 | val |= (0x1 << ddata->cap->regbits->srst_shift); |
| 1063 | sysc_write(ddata, offset, val); |
| 1064 | |
| 1065 | /* Poll on reset status */ |
| 1066 | offset = ddata->offsets[SYSC_SYSSTATUS]; |
| 1067 | |
| 1068 | return readl_poll_timeout(ddata->module_va + offset, val, |
| 1069 | (val & ddata->cfg.syss_mask) == 0x0, |
| 1070 | 100, MAX_MODULE_SOFTRESET_WAIT); |
| 1071 | } |
| 1072 | |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1073 | /* |
| 1074 | * At this point the module is configured enough to read the revision but |
| 1075 | * module may not be completely configured yet to use PM runtime. Enable |
| 1076 | * all clocks directly during init to configure the quirks needed for PM |
| 1077 | * runtime based on the revision register. |
| 1078 | */ |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1079 | static int sysc_init_module(struct sysc *ddata) |
| 1080 | { |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1081 | int error = 0; |
| 1082 | bool manage_clocks = true; |
Tony Lindgren | b11c1ea | 2019-03-21 11:00:21 -0700 | [diff] [blame^] | 1083 | bool reset = true; |
| 1084 | |
| 1085 | if (ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) |
| 1086 | reset = false; |
| 1087 | |
| 1088 | error = sysc_rstctrl_reset_deassert(ddata, reset); |
| 1089 | if (error) |
| 1090 | return error; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1091 | |
Tony Lindgren | 386cb76 | 2019-03-22 07:49:30 -0700 | [diff] [blame] | 1092 | if (ddata->cfg.quirks & |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1093 | (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT)) |
| 1094 | manage_clocks = false; |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1095 | |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1096 | if (manage_clocks) { |
| 1097 | error = sysc_enable_opt_clocks(ddata); |
| 1098 | if (error) |
| 1099 | return error; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1100 | |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1101 | error = sysc_enable_main_clocks(ddata); |
| 1102 | if (error) |
| 1103 | goto err_opt_clocks; |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 1104 | } |
| 1105 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1106 | ddata->revision = sysc_read_revision(ddata); |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1107 | sysc_init_revision_quirks(ddata); |
| 1108 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1109 | error = sysc_legacy_init(ddata); |
| 1110 | if (error) |
| 1111 | goto err_main_clocks; |
| 1112 | |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1113 | error = sysc_reset(ddata); |
| 1114 | if (error) |
| 1115 | dev_err(ddata->dev, "Reset failed with %d\n", error); |
| 1116 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1117 | err_main_clocks: |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1118 | if (manage_clocks) |
| 1119 | sysc_disable_main_clocks(ddata); |
| 1120 | err_opt_clocks: |
| 1121 | if (manage_clocks) |
| 1122 | sysc_disable_opt_clocks(ddata); |
| 1123 | |
| 1124 | return error; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1125 | } |
| 1126 | |
Tony Lindgren | c5a2de9 | 2017-12-15 09:41:23 -0800 | [diff] [blame] | 1127 | static int sysc_init_sysc_mask(struct sysc *ddata) |
| 1128 | { |
| 1129 | struct device_node *np = ddata->dev->of_node; |
| 1130 | int error; |
| 1131 | u32 val; |
| 1132 | |
| 1133 | error = of_property_read_u32(np, "ti,sysc-mask", &val); |
| 1134 | if (error) |
| 1135 | return 0; |
| 1136 | |
| 1137 | if (val) |
| 1138 | ddata->cfg.sysc_val = val & ddata->cap->sysc_mask; |
| 1139 | else |
| 1140 | ddata->cfg.sysc_val = ddata->cap->sysc_mask; |
| 1141 | |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes, |
| 1146 | const char *name) |
| 1147 | { |
| 1148 | struct device_node *np = ddata->dev->of_node; |
| 1149 | struct property *prop; |
| 1150 | const __be32 *p; |
| 1151 | u32 val; |
| 1152 | |
| 1153 | of_property_for_each_u32(np, name, prop, p, val) { |
| 1154 | if (val >= SYSC_NR_IDLEMODES) { |
| 1155 | dev_err(ddata->dev, "invalid idlemode: %i\n", val); |
| 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | *idlemodes |= (1 << val); |
| 1159 | } |
| 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | static int sysc_init_idlemodes(struct sysc *ddata) |
| 1165 | { |
| 1166 | int error; |
| 1167 | |
| 1168 | error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes, |
| 1169 | "ti,sysc-midle"); |
| 1170 | if (error) |
| 1171 | return error; |
| 1172 | |
| 1173 | error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes, |
| 1174 | "ti,sysc-sidle"); |
| 1175 | if (error) |
| 1176 | return error; |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | /* |
| 1182 | * Only some devices on omap4 and later have SYSCONFIG reset done |
| 1183 | * bit. We can detect this if there is no SYSSTATUS at all, or the |
| 1184 | * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers |
| 1185 | * have multiple bits for the child devices like OHCI and EHCI. |
| 1186 | * Depends on SYSC being parsed first. |
| 1187 | */ |
| 1188 | static int sysc_init_syss_mask(struct sysc *ddata) |
| 1189 | { |
| 1190 | struct device_node *np = ddata->dev->of_node; |
| 1191 | int error; |
| 1192 | u32 val; |
| 1193 | |
| 1194 | error = of_property_read_u32(np, "ti,syss-mask", &val); |
| 1195 | if (error) { |
| 1196 | if ((ddata->cap->type == TI_SYSC_OMAP4 || |
| 1197 | ddata->cap->type == TI_SYSC_OMAP4_TIMER) && |
| 1198 | (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET)) |
| 1199 | ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS; |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET)) |
| 1205 | ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS; |
| 1206 | |
| 1207 | ddata->cfg.syss_mask = val; |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1212 | /* |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1213 | * Many child device drivers need to have fck and opt clocks available |
| 1214 | * to get the clock rate for device internal configuration etc. |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1215 | */ |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1216 | static int sysc_child_add_named_clock(struct sysc *ddata, |
| 1217 | struct device *child, |
| 1218 | const char *name) |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1219 | { |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1220 | struct clk *clk; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1221 | struct clk_lookup *l; |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1222 | int error = 0; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1223 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1224 | if (!name) |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1225 | return 0; |
| 1226 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1227 | clk = clk_get(child, name); |
| 1228 | if (!IS_ERR(clk)) { |
| 1229 | clk_put(clk); |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1230 | |
| 1231 | return -EEXIST; |
| 1232 | } |
| 1233 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1234 | clk = clk_get(ddata->dev, name); |
| 1235 | if (IS_ERR(clk)) |
| 1236 | return -ENODEV; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1237 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1238 | l = clkdev_create(clk, name, dev_name(child)); |
| 1239 | if (!l) |
| 1240 | error = -ENOMEM; |
| 1241 | |
| 1242 | clk_put(clk); |
| 1243 | |
| 1244 | return error; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 1247 | static int sysc_child_add_clocks(struct sysc *ddata, |
| 1248 | struct device *child) |
| 1249 | { |
| 1250 | int i, error; |
| 1251 | |
| 1252 | for (i = 0; i < ddata->nr_clocks; i++) { |
| 1253 | error = sysc_child_add_named_clock(ddata, |
| 1254 | child, |
| 1255 | ddata->clock_roles[i]); |
| 1256 | if (error && error != -EEXIST) { |
| 1257 | dev_err(ddata->dev, "could not add child clock %s: %i\n", |
| 1258 | ddata->clock_roles[i], error); |
| 1259 | |
| 1260 | return error; |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1267 | static struct device_type sysc_device_type = { |
| 1268 | }; |
| 1269 | |
| 1270 | static struct sysc *sysc_child_to_parent(struct device *dev) |
| 1271 | { |
| 1272 | struct device *parent = dev->parent; |
| 1273 | |
| 1274 | if (!parent || parent->type != &sysc_device_type) |
| 1275 | return NULL; |
| 1276 | |
| 1277 | return dev_get_drvdata(parent); |
| 1278 | } |
| 1279 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1280 | static int __maybe_unused sysc_child_runtime_suspend(struct device *dev) |
| 1281 | { |
| 1282 | struct sysc *ddata; |
| 1283 | int error; |
| 1284 | |
| 1285 | ddata = sysc_child_to_parent(dev); |
| 1286 | |
| 1287 | error = pm_generic_runtime_suspend(dev); |
| 1288 | if (error) |
| 1289 | return error; |
| 1290 | |
| 1291 | if (!ddata->enabled) |
| 1292 | return 0; |
| 1293 | |
| 1294 | return sysc_runtime_suspend(ddata->dev); |
| 1295 | } |
| 1296 | |
| 1297 | static int __maybe_unused sysc_child_runtime_resume(struct device *dev) |
| 1298 | { |
| 1299 | struct sysc *ddata; |
| 1300 | int error; |
| 1301 | |
| 1302 | ddata = sysc_child_to_parent(dev); |
| 1303 | |
| 1304 | if (!ddata->enabled) { |
| 1305 | error = sysc_runtime_resume(ddata->dev); |
| 1306 | if (error < 0) |
| 1307 | dev_err(ddata->dev, |
| 1308 | "%s error: %i\n", __func__, error); |
| 1309 | } |
| 1310 | |
| 1311 | return pm_generic_runtime_resume(dev); |
| 1312 | } |
| 1313 | |
| 1314 | #ifdef CONFIG_PM_SLEEP |
| 1315 | static int sysc_child_suspend_noirq(struct device *dev) |
| 1316 | { |
| 1317 | struct sysc *ddata; |
| 1318 | int error; |
| 1319 | |
| 1320 | ddata = sysc_child_to_parent(dev); |
| 1321 | |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1322 | dev_dbg(ddata->dev, "%s %s\n", __func__, |
| 1323 | ddata->name ? ddata->name : ""); |
| 1324 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1325 | error = pm_generic_suspend_noirq(dev); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1326 | if (error) { |
| 1327 | dev_err(dev, "%s error at %i: %i\n", |
| 1328 | __func__, __LINE__, error); |
| 1329 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1330 | return error; |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1331 | } |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1332 | |
| 1333 | if (!pm_runtime_status_suspended(dev)) { |
| 1334 | error = pm_generic_runtime_suspend(dev); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1335 | if (error) { |
Tony Lindgren | f949078 | 2018-09-28 15:21:50 -0700 | [diff] [blame] | 1336 | dev_dbg(dev, "%s busy at %i: %i\n", |
| 1337 | __func__, __LINE__, error); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1338 | |
Tony Lindgren | 4f3530f | 2018-08-08 01:07:06 -0700 | [diff] [blame] | 1339 | return 0; |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1340 | } |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1341 | |
| 1342 | error = sysc_runtime_suspend(ddata->dev); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1343 | if (error) { |
| 1344 | dev_err(dev, "%s error at %i: %i\n", |
| 1345 | __func__, __LINE__, error); |
| 1346 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1347 | return error; |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1348 | } |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1349 | |
| 1350 | ddata->child_needs_resume = true; |
| 1351 | } |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | static int sysc_child_resume_noirq(struct device *dev) |
| 1357 | { |
| 1358 | struct sysc *ddata; |
| 1359 | int error; |
| 1360 | |
| 1361 | ddata = sysc_child_to_parent(dev); |
| 1362 | |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1363 | dev_dbg(ddata->dev, "%s %s\n", __func__, |
| 1364 | ddata->name ? ddata->name : ""); |
| 1365 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1366 | if (ddata->child_needs_resume) { |
| 1367 | ddata->child_needs_resume = false; |
| 1368 | |
| 1369 | error = sysc_runtime_resume(ddata->dev); |
| 1370 | if (error) |
| 1371 | dev_err(ddata->dev, |
| 1372 | "%s runtime resume error: %i\n", |
| 1373 | __func__, error); |
| 1374 | |
| 1375 | error = pm_generic_runtime_resume(dev); |
| 1376 | if (error) |
| 1377 | dev_err(ddata->dev, |
| 1378 | "%s generic runtime resume: %i\n", |
| 1379 | __func__, error); |
| 1380 | } |
| 1381 | |
| 1382 | return pm_generic_resume_noirq(dev); |
| 1383 | } |
| 1384 | #endif |
| 1385 | |
Tony Lindgren | b7182b4 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1386 | static struct dev_pm_domain sysc_child_pm_domain = { |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1387 | .ops = { |
| 1388 | SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend, |
| 1389 | sysc_child_runtime_resume, |
| 1390 | NULL) |
| 1391 | USE_PLATFORM_PM_SLEEP_OPS |
| 1392 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq, |
| 1393 | sysc_child_resume_noirq) |
| 1394 | } |
| 1395 | }; |
| 1396 | |
| 1397 | /** |
| 1398 | * sysc_legacy_idle_quirk - handle children in omap_device compatible way |
| 1399 | * @ddata: device driver data |
| 1400 | * @child: child device driver |
| 1401 | * |
| 1402 | * Allow idle for child devices as done with _od_runtime_suspend(). |
| 1403 | * Otherwise many child devices will not idle because of the permanent |
| 1404 | * parent usecount set in pm_runtime_irq_safe(). |
| 1405 | * |
| 1406 | * Note that the long term solution is to just modify the child device |
| 1407 | * drivers to not set pm_runtime_irq_safe() and then this can be just |
| 1408 | * dropped. |
| 1409 | */ |
| 1410 | static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child) |
| 1411 | { |
| 1412 | if (!ddata->legacy_mode) |
| 1413 | return; |
| 1414 | |
| 1415 | if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE) |
| 1416 | dev_pm_domain_set(child, &sysc_child_pm_domain); |
| 1417 | } |
| 1418 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1419 | static int sysc_notifier_call(struct notifier_block *nb, |
| 1420 | unsigned long event, void *device) |
| 1421 | { |
| 1422 | struct device *dev = device; |
| 1423 | struct sysc *ddata; |
| 1424 | int error; |
| 1425 | |
| 1426 | ddata = sysc_child_to_parent(dev); |
| 1427 | if (!ddata) |
| 1428 | return NOTIFY_DONE; |
| 1429 | |
| 1430 | switch (event) { |
| 1431 | case BUS_NOTIFY_ADD_DEVICE: |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 1432 | error = sysc_child_add_clocks(ddata, dev); |
| 1433 | if (error) |
| 1434 | return error; |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1435 | sysc_legacy_idle_quirk(ddata, dev); |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1436 | break; |
| 1437 | default: |
| 1438 | break; |
| 1439 | } |
| 1440 | |
| 1441 | return NOTIFY_DONE; |
| 1442 | } |
| 1443 | |
| 1444 | static struct notifier_block sysc_nb = { |
| 1445 | .notifier_call = sysc_notifier_call, |
| 1446 | }; |
| 1447 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1448 | /* Device tree configured quirks */ |
| 1449 | struct sysc_dts_quirk { |
| 1450 | const char *name; |
| 1451 | u32 mask; |
| 1452 | }; |
| 1453 | |
| 1454 | static const struct sysc_dts_quirk sysc_dts_quirks[] = { |
| 1455 | { .name = "ti,no-idle-on-init", |
| 1456 | .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, }, |
| 1457 | { .name = "ti,no-reset-on-init", |
| 1458 | .mask = SYSC_QUIRK_NO_RESET_ON_INIT, }, |
Tony Lindgren | 386cb76 | 2019-03-22 07:49:30 -0700 | [diff] [blame] | 1459 | { .name = "ti,no-idle", |
| 1460 | .mask = SYSC_QUIRK_NO_IDLE, }, |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1461 | }; |
| 1462 | |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 1463 | static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np, |
| 1464 | bool is_child) |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1465 | { |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1466 | const struct property *prop; |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 1467 | int i, len; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1468 | |
| 1469 | for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) { |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 1470 | const char *name = sysc_dts_quirks[i].name; |
| 1471 | |
| 1472 | prop = of_get_property(np, name, &len); |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1473 | if (!prop) |
Tony Lindgren | d39b6ea | 2018-02-15 09:18:55 -0800 | [diff] [blame] | 1474 | continue; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1475 | |
| 1476 | ddata->cfg.quirks |= sysc_dts_quirks[i].mask; |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 1477 | if (is_child) { |
| 1478 | dev_warn(ddata->dev, |
| 1479 | "dts flag should be at module level for %s\n", |
| 1480 | name); |
| 1481 | } |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1482 | } |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 1483 | } |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1484 | |
Tony Lindgren | 4014c08 | 2018-12-10 14:11:26 -0800 | [diff] [blame] | 1485 | static int sysc_init_dts_quirks(struct sysc *ddata) |
| 1486 | { |
| 1487 | struct device_node *np = ddata->dev->of_node; |
| 1488 | int error; |
| 1489 | u32 val; |
| 1490 | |
| 1491 | ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL); |
| 1492 | |
| 1493 | sysc_parse_dts_quirks(ddata, np, false); |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1494 | error = of_property_read_u32(np, "ti,sysc-delay-us", &val); |
| 1495 | if (!error) { |
| 1496 | if (val > 255) { |
| 1497 | dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n", |
| 1498 | val); |
| 1499 | } |
| 1500 | |
| 1501 | ddata->cfg.srst_udelay = (u8)val; |
| 1502 | } |
| 1503 | |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1507 | static void sysc_unprepare(struct sysc *ddata) |
| 1508 | { |
| 1509 | int i; |
| 1510 | |
Tony Lindgren | aaa29bb | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1511 | if (!ddata->clocks) |
| 1512 | return; |
| 1513 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1514 | for (i = 0; i < SYSC_MAX_CLOCKS; i++) { |
| 1515 | if (!IS_ERR_OR_NULL(ddata->clocks[i])) |
| 1516 | clk_unprepare(ddata->clocks[i]); |
| 1517 | } |
| 1518 | } |
| 1519 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1520 | /* |
| 1521 | * Common sysc register bits found on omap2, also known as type1 |
| 1522 | */ |
| 1523 | static const struct sysc_regbits sysc_regbits_omap2 = { |
| 1524 | .dmadisable_shift = -ENODEV, |
| 1525 | .midle_shift = 12, |
| 1526 | .sidle_shift = 3, |
| 1527 | .clkact_shift = 8, |
| 1528 | .emufree_shift = 5, |
| 1529 | .enwkup_shift = 2, |
| 1530 | .srst_shift = 1, |
| 1531 | .autoidle_shift = 0, |
| 1532 | }; |
| 1533 | |
| 1534 | static const struct sysc_capabilities sysc_omap2 = { |
| 1535 | .type = TI_SYSC_OMAP2, |
| 1536 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE | |
| 1537 | SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET | |
| 1538 | SYSC_OMAP2_AUTOIDLE, |
| 1539 | .regbits = &sysc_regbits_omap2, |
| 1540 | }; |
| 1541 | |
| 1542 | /* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */ |
| 1543 | static const struct sysc_capabilities sysc_omap2_timer = { |
| 1544 | .type = TI_SYSC_OMAP2_TIMER, |
| 1545 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE | |
| 1546 | SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET | |
| 1547 | SYSC_OMAP2_AUTOIDLE, |
| 1548 | .regbits = &sysc_regbits_omap2, |
| 1549 | .mod_quirks = SYSC_QUIRK_USE_CLOCKACT, |
| 1550 | }; |
| 1551 | |
| 1552 | /* |
| 1553 | * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2 |
| 1554 | * with different sidle position |
| 1555 | */ |
| 1556 | static const struct sysc_regbits sysc_regbits_omap3_sham = { |
| 1557 | .dmadisable_shift = -ENODEV, |
| 1558 | .midle_shift = -ENODEV, |
| 1559 | .sidle_shift = 4, |
| 1560 | .clkact_shift = -ENODEV, |
| 1561 | .enwkup_shift = -ENODEV, |
| 1562 | .srst_shift = 1, |
| 1563 | .autoidle_shift = 0, |
| 1564 | .emufree_shift = -ENODEV, |
| 1565 | }; |
| 1566 | |
| 1567 | static const struct sysc_capabilities sysc_omap3_sham = { |
| 1568 | .type = TI_SYSC_OMAP3_SHAM, |
| 1569 | .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE, |
| 1570 | .regbits = &sysc_regbits_omap3_sham, |
| 1571 | }; |
| 1572 | |
| 1573 | /* |
| 1574 | * AES register bits found on omap3 and later, a variant of |
| 1575 | * sysc_regbits_omap2 with different sidle position |
| 1576 | */ |
| 1577 | static const struct sysc_regbits sysc_regbits_omap3_aes = { |
| 1578 | .dmadisable_shift = -ENODEV, |
| 1579 | .midle_shift = -ENODEV, |
| 1580 | .sidle_shift = 6, |
| 1581 | .clkact_shift = -ENODEV, |
| 1582 | .enwkup_shift = -ENODEV, |
| 1583 | .srst_shift = 1, |
| 1584 | .autoidle_shift = 0, |
| 1585 | .emufree_shift = -ENODEV, |
| 1586 | }; |
| 1587 | |
| 1588 | static const struct sysc_capabilities sysc_omap3_aes = { |
| 1589 | .type = TI_SYSC_OMAP3_AES, |
| 1590 | .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE, |
| 1591 | .regbits = &sysc_regbits_omap3_aes, |
| 1592 | }; |
| 1593 | |
| 1594 | /* |
| 1595 | * Common sysc register bits found on omap4, also known as type2 |
| 1596 | */ |
| 1597 | static const struct sysc_regbits sysc_regbits_omap4 = { |
| 1598 | .dmadisable_shift = 16, |
| 1599 | .midle_shift = 4, |
| 1600 | .sidle_shift = 2, |
| 1601 | .clkact_shift = -ENODEV, |
| 1602 | .enwkup_shift = -ENODEV, |
| 1603 | .emufree_shift = 1, |
| 1604 | .srst_shift = 0, |
| 1605 | .autoidle_shift = -ENODEV, |
| 1606 | }; |
| 1607 | |
| 1608 | static const struct sysc_capabilities sysc_omap4 = { |
| 1609 | .type = TI_SYSC_OMAP4, |
| 1610 | .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU | |
| 1611 | SYSC_OMAP4_SOFTRESET, |
| 1612 | .regbits = &sysc_regbits_omap4, |
| 1613 | }; |
| 1614 | |
| 1615 | static const struct sysc_capabilities sysc_omap4_timer = { |
| 1616 | .type = TI_SYSC_OMAP4_TIMER, |
| 1617 | .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU | |
| 1618 | SYSC_OMAP4_SOFTRESET, |
| 1619 | .regbits = &sysc_regbits_omap4, |
| 1620 | }; |
| 1621 | |
| 1622 | /* |
| 1623 | * Common sysc register bits found on omap4, also known as type3 |
| 1624 | */ |
| 1625 | static const struct sysc_regbits sysc_regbits_omap4_simple = { |
| 1626 | .dmadisable_shift = -ENODEV, |
| 1627 | .midle_shift = 2, |
| 1628 | .sidle_shift = 0, |
| 1629 | .clkact_shift = -ENODEV, |
| 1630 | .enwkup_shift = -ENODEV, |
| 1631 | .srst_shift = -ENODEV, |
| 1632 | .emufree_shift = -ENODEV, |
| 1633 | .autoidle_shift = -ENODEV, |
| 1634 | }; |
| 1635 | |
| 1636 | static const struct sysc_capabilities sysc_omap4_simple = { |
| 1637 | .type = TI_SYSC_OMAP4_SIMPLE, |
| 1638 | .regbits = &sysc_regbits_omap4_simple, |
| 1639 | }; |
| 1640 | |
| 1641 | /* |
| 1642 | * SmartReflex sysc found on omap34xx |
| 1643 | */ |
| 1644 | static const struct sysc_regbits sysc_regbits_omap34xx_sr = { |
| 1645 | .dmadisable_shift = -ENODEV, |
| 1646 | .midle_shift = -ENODEV, |
| 1647 | .sidle_shift = -ENODEV, |
| 1648 | .clkact_shift = 20, |
| 1649 | .enwkup_shift = -ENODEV, |
| 1650 | .srst_shift = -ENODEV, |
| 1651 | .emufree_shift = -ENODEV, |
| 1652 | .autoidle_shift = -ENODEV, |
| 1653 | }; |
| 1654 | |
| 1655 | static const struct sysc_capabilities sysc_34xx_sr = { |
| 1656 | .type = TI_SYSC_OMAP34XX_SR, |
| 1657 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY, |
| 1658 | .regbits = &sysc_regbits_omap34xx_sr, |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1659 | .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED | |
| 1660 | SYSC_QUIRK_LEGACY_IDLE, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1661 | }; |
| 1662 | |
| 1663 | /* |
| 1664 | * SmartReflex sysc found on omap36xx and later |
| 1665 | */ |
| 1666 | static const struct sysc_regbits sysc_regbits_omap36xx_sr = { |
| 1667 | .dmadisable_shift = -ENODEV, |
| 1668 | .midle_shift = -ENODEV, |
| 1669 | .sidle_shift = 24, |
| 1670 | .clkact_shift = -ENODEV, |
| 1671 | .enwkup_shift = 26, |
| 1672 | .srst_shift = -ENODEV, |
| 1673 | .emufree_shift = -ENODEV, |
| 1674 | .autoidle_shift = -ENODEV, |
| 1675 | }; |
| 1676 | |
| 1677 | static const struct sysc_capabilities sysc_36xx_sr = { |
| 1678 | .type = TI_SYSC_OMAP36XX_SR, |
Tony Lindgren | 3267c08 | 2018-01-22 09:32:53 -0800 | [diff] [blame] | 1679 | .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1680 | .regbits = &sysc_regbits_omap36xx_sr, |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1681 | .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1682 | }; |
| 1683 | |
| 1684 | static const struct sysc_capabilities sysc_omap4_sr = { |
| 1685 | .type = TI_SYSC_OMAP4_SR, |
| 1686 | .regbits = &sysc_regbits_omap36xx_sr, |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1687 | .mod_quirks = SYSC_QUIRK_LEGACY_IDLE, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1688 | }; |
| 1689 | |
| 1690 | /* |
| 1691 | * McASP register bits found on omap4 and later |
| 1692 | */ |
| 1693 | static const struct sysc_regbits sysc_regbits_omap4_mcasp = { |
| 1694 | .dmadisable_shift = -ENODEV, |
| 1695 | .midle_shift = -ENODEV, |
| 1696 | .sidle_shift = 0, |
| 1697 | .clkact_shift = -ENODEV, |
| 1698 | .enwkup_shift = -ENODEV, |
| 1699 | .srst_shift = -ENODEV, |
| 1700 | .emufree_shift = -ENODEV, |
| 1701 | .autoidle_shift = -ENODEV, |
| 1702 | }; |
| 1703 | |
| 1704 | static const struct sysc_capabilities sysc_omap4_mcasp = { |
| 1705 | .type = TI_SYSC_OMAP4_MCASP, |
| 1706 | .regbits = &sysc_regbits_omap4_mcasp, |
Tony Lindgren | 2c63a83 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 1707 | .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED, |
| 1708 | }; |
| 1709 | |
| 1710 | /* |
| 1711 | * McASP found on dra7 and later |
| 1712 | */ |
| 1713 | static const struct sysc_capabilities sysc_dra7_mcasp = { |
| 1714 | .type = TI_SYSC_OMAP4_SIMPLE, |
| 1715 | .regbits = &sysc_regbits_omap4_simple, |
| 1716 | .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1717 | }; |
| 1718 | |
| 1719 | /* |
| 1720 | * FS USB host found on omap4 and later |
| 1721 | */ |
| 1722 | static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = { |
| 1723 | .dmadisable_shift = -ENODEV, |
| 1724 | .midle_shift = -ENODEV, |
| 1725 | .sidle_shift = 24, |
| 1726 | .clkact_shift = -ENODEV, |
| 1727 | .enwkup_shift = 26, |
| 1728 | .srst_shift = -ENODEV, |
| 1729 | .emufree_shift = -ENODEV, |
| 1730 | .autoidle_shift = -ENODEV, |
| 1731 | }; |
| 1732 | |
| 1733 | static const struct sysc_capabilities sysc_omap4_usb_host_fs = { |
| 1734 | .type = TI_SYSC_OMAP4_USB_HOST_FS, |
| 1735 | .sysc_mask = SYSC_OMAP2_ENAWAKEUP, |
| 1736 | .regbits = &sysc_regbits_omap4_usb_host_fs, |
| 1737 | }; |
| 1738 | |
Faiz Abbas | 7f35e63 | 2018-07-09 22:18:38 +0530 | [diff] [blame] | 1739 | static const struct sysc_regbits sysc_regbits_dra7_mcan = { |
| 1740 | .dmadisable_shift = -ENODEV, |
| 1741 | .midle_shift = -ENODEV, |
| 1742 | .sidle_shift = -ENODEV, |
| 1743 | .clkact_shift = -ENODEV, |
| 1744 | .enwkup_shift = 4, |
| 1745 | .srst_shift = 0, |
| 1746 | .emufree_shift = -ENODEV, |
| 1747 | .autoidle_shift = -ENODEV, |
| 1748 | }; |
| 1749 | |
| 1750 | static const struct sysc_capabilities sysc_dra7_mcan = { |
| 1751 | .type = TI_SYSC_DRA7_MCAN, |
| 1752 | .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET, |
| 1753 | .regbits = &sysc_regbits_dra7_mcan, |
| 1754 | }; |
| 1755 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1756 | static int sysc_init_pdata(struct sysc *ddata) |
| 1757 | { |
| 1758 | struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1759 | struct ti_sysc_module_data *mdata; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1760 | |
| 1761 | if (!pdata || !ddata->legacy_mode) |
| 1762 | return 0; |
| 1763 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1764 | mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL); |
| 1765 | if (!mdata) |
| 1766 | return -ENOMEM; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1767 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1768 | mdata->name = ddata->legacy_mode; |
| 1769 | mdata->module_pa = ddata->module_pa; |
| 1770 | mdata->module_size = ddata->module_size; |
| 1771 | mdata->offsets = ddata->offsets; |
| 1772 | mdata->nr_offsets = SYSC_MAX_REGS; |
| 1773 | mdata->cap = ddata->cap; |
| 1774 | mdata->cfg = &ddata->cfg; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1775 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1776 | ddata->mdata = mdata; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1777 | |
Tony Lindgren | a3e92e7 | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1778 | return 0; |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1779 | } |
| 1780 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1781 | static int sysc_init_match(struct sysc *ddata) |
| 1782 | { |
| 1783 | const struct sysc_capabilities *cap; |
| 1784 | |
| 1785 | cap = of_device_get_match_data(ddata->dev); |
| 1786 | if (!cap) |
| 1787 | return -EINVAL; |
| 1788 | |
| 1789 | ddata->cap = cap; |
| 1790 | if (ddata->cap) |
| 1791 | ddata->cfg.quirks |= ddata->cap->mod_quirks; |
| 1792 | |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 1796 | static void ti_sysc_idle(struct work_struct *work) |
| 1797 | { |
| 1798 | struct sysc *ddata; |
| 1799 | |
| 1800 | ddata = container_of(work, struct sysc, idle_work.work); |
| 1801 | |
| 1802 | if (pm_runtime_active(ddata->dev)) |
| 1803 | pm_runtime_put_sync(ddata->dev); |
| 1804 | } |
| 1805 | |
Tony Lindgren | c4bebea | 2018-04-16 10:24:54 -0700 | [diff] [blame] | 1806 | static const struct of_device_id sysc_match_table[] = { |
| 1807 | { .compatible = "simple-bus", }, |
| 1808 | { /* sentinel */ }, |
| 1809 | }; |
| 1810 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1811 | static int sysc_probe(struct platform_device *pdev) |
| 1812 | { |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1813 | struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1814 | struct sysc *ddata; |
| 1815 | int error; |
| 1816 | |
| 1817 | ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); |
| 1818 | if (!ddata) |
| 1819 | return -ENOMEM; |
| 1820 | |
| 1821 | ddata->dev = &pdev->dev; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1822 | platform_set_drvdata(pdev, ddata); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1823 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1824 | error = sysc_init_match(ddata); |
| 1825 | if (error) |
| 1826 | return error; |
| 1827 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1828 | error = sysc_init_dts_quirks(ddata); |
| 1829 | if (error) |
| 1830 | goto unprepare; |
| 1831 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1832 | error = sysc_get_clocks(ddata); |
| 1833 | if (error) |
| 1834 | return error; |
| 1835 | |
| 1836 | error = sysc_map_and_check_registers(ddata); |
| 1837 | if (error) |
| 1838 | goto unprepare; |
| 1839 | |
Tony Lindgren | c5a2de9 | 2017-12-15 09:41:23 -0800 | [diff] [blame] | 1840 | error = sysc_init_sysc_mask(ddata); |
| 1841 | if (error) |
| 1842 | goto unprepare; |
| 1843 | |
| 1844 | error = sysc_init_idlemodes(ddata); |
| 1845 | if (error) |
| 1846 | goto unprepare; |
| 1847 | |
| 1848 | error = sysc_init_syss_mask(ddata); |
| 1849 | if (error) |
| 1850 | goto unprepare; |
| 1851 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1852 | error = sysc_init_pdata(ddata); |
| 1853 | if (error) |
| 1854 | goto unprepare; |
| 1855 | |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1856 | error = sysc_init_resets(ddata); |
| 1857 | if (error) |
| 1858 | return error; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1859 | |
| 1860 | error = sysc_init_module(ddata); |
| 1861 | if (error) |
| 1862 | goto unprepare; |
| 1863 | |
Tony Lindgren | 1a5cd7c | 2019-03-21 11:00:21 -0700 | [diff] [blame] | 1864 | pm_runtime_enable(ddata->dev); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1865 | error = pm_runtime_get_sync(ddata->dev); |
| 1866 | if (error < 0) { |
| 1867 | pm_runtime_put_noidle(ddata->dev); |
| 1868 | pm_runtime_disable(ddata->dev); |
| 1869 | goto unprepare; |
| 1870 | } |
| 1871 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1872 | sysc_show_registers(ddata); |
| 1873 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1874 | ddata->dev->type = &sysc_device_type; |
Tony Lindgren | c4bebea | 2018-04-16 10:24:54 -0700 | [diff] [blame] | 1875 | error = of_platform_populate(ddata->dev->of_node, sysc_match_table, |
| 1876 | pdata ? pdata->auxdata : NULL, |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1877 | ddata->dev); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1878 | if (error) |
| 1879 | goto err; |
| 1880 | |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 1881 | INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle); |
| 1882 | |
| 1883 | /* At least earlycon won't survive without deferred idle */ |
| 1884 | if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE_ON_INIT | |
| 1885 | SYSC_QUIRK_NO_RESET_ON_INIT)) { |
| 1886 | schedule_delayed_work(&ddata->idle_work, 3000); |
| 1887 | } else { |
| 1888 | pm_runtime_put(&pdev->dev); |
| 1889 | } |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1890 | |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1891 | if (!of_get_available_child_count(ddata->dev->of_node)) |
| 1892 | reset_control_assert(ddata->rsts); |
| 1893 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1894 | return 0; |
| 1895 | |
| 1896 | err: |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1897 | pm_runtime_put_sync(&pdev->dev); |
| 1898 | pm_runtime_disable(&pdev->dev); |
| 1899 | unprepare: |
| 1900 | sysc_unprepare(ddata); |
| 1901 | |
| 1902 | return error; |
| 1903 | } |
| 1904 | |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1905 | static int sysc_remove(struct platform_device *pdev) |
| 1906 | { |
| 1907 | struct sysc *ddata = platform_get_drvdata(pdev); |
| 1908 | int error; |
| 1909 | |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 1910 | cancel_delayed_work_sync(&ddata->idle_work); |
| 1911 | |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1912 | error = pm_runtime_get_sync(ddata->dev); |
| 1913 | if (error < 0) { |
| 1914 | pm_runtime_put_noidle(ddata->dev); |
| 1915 | pm_runtime_disable(ddata->dev); |
| 1916 | goto unprepare; |
| 1917 | } |
| 1918 | |
| 1919 | of_platform_depopulate(&pdev->dev); |
| 1920 | |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1921 | pm_runtime_put_sync(&pdev->dev); |
| 1922 | pm_runtime_disable(&pdev->dev); |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1923 | reset_control_assert(ddata->rsts); |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1924 | |
| 1925 | unprepare: |
| 1926 | sysc_unprepare(ddata); |
| 1927 | |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1931 | static const struct of_device_id sysc_match[] = { |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1932 | { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, }, |
| 1933 | { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, }, |
| 1934 | { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, }, |
| 1935 | { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, }, |
| 1936 | { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, }, |
| 1937 | { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, }, |
| 1938 | { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, }, |
| 1939 | { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, }, |
| 1940 | { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, }, |
| 1941 | { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, }, |
| 1942 | { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, }, |
Tony Lindgren | 2c63a83 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 1943 | { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, }, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1944 | { .compatible = "ti,sysc-usb-host-fs", |
| 1945 | .data = &sysc_omap4_usb_host_fs, }, |
Faiz Abbas | 7f35e63 | 2018-07-09 22:18:38 +0530 | [diff] [blame] | 1946 | { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, }, |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1947 | { }, |
| 1948 | }; |
| 1949 | MODULE_DEVICE_TABLE(of, sysc_match); |
| 1950 | |
| 1951 | static struct platform_driver sysc_driver = { |
| 1952 | .probe = sysc_probe, |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1953 | .remove = sysc_remove, |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1954 | .driver = { |
| 1955 | .name = "ti-sysc", |
| 1956 | .of_match_table = sysc_match, |
| 1957 | .pm = &sysc_pm_ops, |
| 1958 | }, |
| 1959 | }; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1960 | |
| 1961 | static int __init sysc_init(void) |
| 1962 | { |
| 1963 | bus_register_notifier(&platform_bus_type, &sysc_nb); |
| 1964 | |
| 1965 | return platform_driver_register(&sysc_driver); |
| 1966 | } |
| 1967 | module_init(sysc_init); |
| 1968 | |
| 1969 | static void __exit sysc_exit(void) |
| 1970 | { |
| 1971 | bus_unregister_notifier(&platform_bus_type, &sysc_nb); |
| 1972 | platform_driver_unregister(&sysc_driver); |
| 1973 | } |
| 1974 | module_exit(sysc_exit); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1975 | |
| 1976 | MODULE_DESCRIPTION("TI sysc interconnect target driver"); |
| 1977 | MODULE_LICENSE("GPL v2"); |