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