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