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), |
Tony Lindgren | f010670 | 2018-11-15 14:46:53 -0800 | [diff] [blame^] | 823 | SYSC_QUIRK("padconf", 0, 0, -1, -1, 0x40001100, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 824 | SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000100, 0xffffffff, 0), |
Tony Lindgren | 23731ea | 2018-09-24 12:17:09 -0700 | [diff] [blame] | 825 | SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x00004102, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 826 | SYSC_QUIRK("prcm", 0, 0, -1, -1, 0x40000400, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 827 | SYSC_QUIRK("scm", 0, 0, 0x10, -1, 0x40000900, 0xffffffff, 0), |
Tony Lindgren | 23731ea | 2018-09-24 12:17:09 -0700 | [diff] [blame] | 828 | SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4e8b0100, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 829 | SYSC_QUIRK("scm", 0, 0, -1, -1, 0x4f000100, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 830 | SYSC_QUIRK("scm", 0, 0, -1, -1, 0x40000900, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 831 | SYSC_QUIRK("scrm", 0, 0, -1, -1, 0x00000010, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 832 | SYSC_QUIRK("sdio", 0, 0, 0x10, -1, 0x40202301, 0xffff0ff0, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 833 | SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0), |
Tony Lindgren | 40d9f91 | 2018-09-24 12:16:54 -0700 | [diff] [blame] | 834 | SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 835 | SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40000902, 0xffffffff, 0), |
| 836 | SYSC_QUIRK("slimbus", 0, 0, 0x10, -1, 0x40002903, 0xffffffff, 0), |
| 837 | SYSC_QUIRK("spinlock", 0, 0, 0x10, -1, 0x50020000, 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 838 | SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -1, 0x00000020, 0xffffffff, 0), |
Tony Lindgren | c6eb4af | 2018-09-27 13:34:27 -0700 | [diff] [blame] | 839 | SYSC_QUIRK("rtc", 0, 0x74, 0x78, -1, 0x4eb01908, 0xffff00f0, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 840 | SYSC_QUIRK("timer32k", 0, 0, 0x4, -1, 0x00000060, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 841 | SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0), |
Tony Lindgren | f010670 | 2018-11-15 14:46:53 -0800 | [diff] [blame^] | 842 | SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 843 | SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, 0), |
Tony Lindgren | f010670 | 2018-11-15 14:46:53 -0800 | [diff] [blame^] | 844 | SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -1, 0x50700101, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 845 | SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050, |
| 846 | 0xffffffff, 0), |
Tony Lindgren | 1ba3069 | 2018-09-24 12:17:05 -0700 | [diff] [blame] | 847 | SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0, 0), |
| 848 | SYSC_QUIRK("vfpe", 0, 0, 0x104, -1, 0x4d001200, 0xffffffff, 0), |
Tony Lindgren | dc4c85e | 2018-04-16 10:26:25 -0700 | [diff] [blame] | 849 | #endif |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 850 | }; |
| 851 | |
| 852 | static void sysc_init_revision_quirks(struct sysc *ddata) |
| 853 | { |
| 854 | const struct sysc_revision_quirk *q; |
| 855 | int i; |
| 856 | |
| 857 | for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) { |
| 858 | q = &sysc_revision_quirks[i]; |
| 859 | |
| 860 | if (q->base && q->base != ddata->module_pa) |
| 861 | continue; |
| 862 | |
| 863 | if (q->rev_offset >= 0 && |
| 864 | q->rev_offset != ddata->offsets[SYSC_REVISION]) |
| 865 | continue; |
| 866 | |
| 867 | if (q->sysc_offset >= 0 && |
| 868 | q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG]) |
| 869 | continue; |
| 870 | |
| 871 | if (q->syss_offset >= 0 && |
| 872 | q->syss_offset != ddata->offsets[SYSC_SYSSTATUS]) |
| 873 | continue; |
| 874 | |
| 875 | if (q->revision == ddata->revision || |
| 876 | (q->revision & q->revision_mask) == |
| 877 | (ddata->revision & q->revision_mask)) { |
| 878 | ddata->name = q->name; |
| 879 | ddata->cfg.quirks |= q->quirks; |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 884 | static int sysc_reset(struct sysc *ddata) |
| 885 | { |
| 886 | int offset = ddata->offsets[SYSC_SYSCONFIG]; |
| 887 | int val; |
| 888 | |
| 889 | if (ddata->legacy_mode || offset < 0 || |
| 890 | ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) |
| 891 | return 0; |
| 892 | |
| 893 | /* |
| 894 | * Currently only support reset status in sysstatus. |
| 895 | * Warn and return error in all other cases |
| 896 | */ |
| 897 | if (!ddata->cfg.syss_mask) { |
| 898 | dev_err(ddata->dev, "No ti,syss-mask. Reset failed\n"); |
| 899 | return -EINVAL; |
| 900 | } |
| 901 | |
| 902 | val = sysc_read(ddata, offset); |
| 903 | val |= (0x1 << ddata->cap->regbits->srst_shift); |
| 904 | sysc_write(ddata, offset, val); |
| 905 | |
| 906 | /* Poll on reset status */ |
| 907 | offset = ddata->offsets[SYSC_SYSSTATUS]; |
| 908 | |
| 909 | return readl_poll_timeout(ddata->module_va + offset, val, |
| 910 | (val & ddata->cfg.syss_mask) == 0x0, |
| 911 | 100, MAX_MODULE_SOFTRESET_WAIT); |
| 912 | } |
| 913 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 914 | /* At this point the module is configured enough to read the revision */ |
| 915 | static int sysc_init_module(struct sysc *ddata) |
| 916 | { |
| 917 | int error; |
| 918 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 919 | if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE_ON_INIT) { |
| 920 | ddata->revision = sysc_read_revision(ddata); |
| 921 | goto rev_quirks; |
| 922 | } |
| 923 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 924 | error = pm_runtime_get_sync(ddata->dev); |
| 925 | if (error < 0) { |
| 926 | pm_runtime_put_noidle(ddata->dev); |
| 927 | |
| 928 | return 0; |
| 929 | } |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 930 | |
Faiz Abbas | 596e795 | 2018-07-09 22:18:39 +0530 | [diff] [blame] | 931 | error = sysc_reset(ddata); |
| 932 | if (error) { |
| 933 | dev_err(ddata->dev, "Reset failed with %d\n", error); |
| 934 | pm_runtime_put_sync(ddata->dev); |
| 935 | |
| 936 | return error; |
| 937 | } |
| 938 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 939 | ddata->revision = sysc_read_revision(ddata); |
| 940 | pm_runtime_put_sync(ddata->dev); |
| 941 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 942 | rev_quirks: |
| 943 | sysc_init_revision_quirks(ddata); |
| 944 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | |
Tony Lindgren | c5a2de9 | 2017-12-15 09:41:23 -0800 | [diff] [blame] | 948 | static int sysc_init_sysc_mask(struct sysc *ddata) |
| 949 | { |
| 950 | struct device_node *np = ddata->dev->of_node; |
| 951 | int error; |
| 952 | u32 val; |
| 953 | |
| 954 | error = of_property_read_u32(np, "ti,sysc-mask", &val); |
| 955 | if (error) |
| 956 | return 0; |
| 957 | |
| 958 | if (val) |
| 959 | ddata->cfg.sysc_val = val & ddata->cap->sysc_mask; |
| 960 | else |
| 961 | ddata->cfg.sysc_val = ddata->cap->sysc_mask; |
| 962 | |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes, |
| 967 | const char *name) |
| 968 | { |
| 969 | struct device_node *np = ddata->dev->of_node; |
| 970 | struct property *prop; |
| 971 | const __be32 *p; |
| 972 | u32 val; |
| 973 | |
| 974 | of_property_for_each_u32(np, name, prop, p, val) { |
| 975 | if (val >= SYSC_NR_IDLEMODES) { |
| 976 | dev_err(ddata->dev, "invalid idlemode: %i\n", val); |
| 977 | return -EINVAL; |
| 978 | } |
| 979 | *idlemodes |= (1 << val); |
| 980 | } |
| 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | static int sysc_init_idlemodes(struct sysc *ddata) |
| 986 | { |
| 987 | int error; |
| 988 | |
| 989 | error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes, |
| 990 | "ti,sysc-midle"); |
| 991 | if (error) |
| 992 | return error; |
| 993 | |
| 994 | error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes, |
| 995 | "ti,sysc-sidle"); |
| 996 | if (error) |
| 997 | return error; |
| 998 | |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | /* |
| 1003 | * Only some devices on omap4 and later have SYSCONFIG reset done |
| 1004 | * bit. We can detect this if there is no SYSSTATUS at all, or the |
| 1005 | * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers |
| 1006 | * have multiple bits for the child devices like OHCI and EHCI. |
| 1007 | * Depends on SYSC being parsed first. |
| 1008 | */ |
| 1009 | static int sysc_init_syss_mask(struct sysc *ddata) |
| 1010 | { |
| 1011 | struct device_node *np = ddata->dev->of_node; |
| 1012 | int error; |
| 1013 | u32 val; |
| 1014 | |
| 1015 | error = of_property_read_u32(np, "ti,syss-mask", &val); |
| 1016 | if (error) { |
| 1017 | if ((ddata->cap->type == TI_SYSC_OMAP4 || |
| 1018 | ddata->cap->type == TI_SYSC_OMAP4_TIMER) && |
| 1019 | (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET)) |
| 1020 | ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS; |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET)) |
| 1026 | ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS; |
| 1027 | |
| 1028 | ddata->cfg.syss_mask = val; |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
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 | * Many child device drivers need to have fck and opt clocks available |
| 1035 | * to get the clock rate for device internal configuration etc. |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1036 | */ |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1037 | static int sysc_child_add_named_clock(struct sysc *ddata, |
| 1038 | struct device *child, |
| 1039 | const char *name) |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1040 | { |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1041 | struct clk *clk; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1042 | struct clk_lookup *l; |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1043 | int error = 0; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1044 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1045 | if (!name) |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1046 | return 0; |
| 1047 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1048 | clk = clk_get(child, name); |
| 1049 | if (!IS_ERR(clk)) { |
| 1050 | clk_put(clk); |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1051 | |
| 1052 | return -EEXIST; |
| 1053 | } |
| 1054 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1055 | clk = clk_get(ddata->dev, name); |
| 1056 | if (IS_ERR(clk)) |
| 1057 | return -ENODEV; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1058 | |
Tony Lindgren | 8b2830ba | 2018-04-16 10:26:09 -0700 | [diff] [blame] | 1059 | l = clkdev_create(clk, name, dev_name(child)); |
| 1060 | if (!l) |
| 1061 | error = -ENOMEM; |
| 1062 | |
| 1063 | clk_put(clk); |
| 1064 | |
| 1065 | return error; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 1068 | static int sysc_child_add_clocks(struct sysc *ddata, |
| 1069 | struct device *child) |
| 1070 | { |
| 1071 | int i, error; |
| 1072 | |
| 1073 | for (i = 0; i < ddata->nr_clocks; i++) { |
| 1074 | error = sysc_child_add_named_clock(ddata, |
| 1075 | child, |
| 1076 | ddata->clock_roles[i]); |
| 1077 | if (error && error != -EEXIST) { |
| 1078 | dev_err(ddata->dev, "could not add child clock %s: %i\n", |
| 1079 | ddata->clock_roles[i], error); |
| 1080 | |
| 1081 | return error; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1088 | static struct device_type sysc_device_type = { |
| 1089 | }; |
| 1090 | |
| 1091 | static struct sysc *sysc_child_to_parent(struct device *dev) |
| 1092 | { |
| 1093 | struct device *parent = dev->parent; |
| 1094 | |
| 1095 | if (!parent || parent->type != &sysc_device_type) |
| 1096 | return NULL; |
| 1097 | |
| 1098 | return dev_get_drvdata(parent); |
| 1099 | } |
| 1100 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1101 | static int __maybe_unused sysc_child_runtime_suspend(struct device *dev) |
| 1102 | { |
| 1103 | struct sysc *ddata; |
| 1104 | int error; |
| 1105 | |
| 1106 | ddata = sysc_child_to_parent(dev); |
| 1107 | |
| 1108 | error = pm_generic_runtime_suspend(dev); |
| 1109 | if (error) |
| 1110 | return error; |
| 1111 | |
| 1112 | if (!ddata->enabled) |
| 1113 | return 0; |
| 1114 | |
| 1115 | return sysc_runtime_suspend(ddata->dev); |
| 1116 | } |
| 1117 | |
| 1118 | static int __maybe_unused sysc_child_runtime_resume(struct device *dev) |
| 1119 | { |
| 1120 | struct sysc *ddata; |
| 1121 | int error; |
| 1122 | |
| 1123 | ddata = sysc_child_to_parent(dev); |
| 1124 | |
| 1125 | if (!ddata->enabled) { |
| 1126 | error = sysc_runtime_resume(ddata->dev); |
| 1127 | if (error < 0) |
| 1128 | dev_err(ddata->dev, |
| 1129 | "%s error: %i\n", __func__, error); |
| 1130 | } |
| 1131 | |
| 1132 | return pm_generic_runtime_resume(dev); |
| 1133 | } |
| 1134 | |
| 1135 | #ifdef CONFIG_PM_SLEEP |
| 1136 | static int sysc_child_suspend_noirq(struct device *dev) |
| 1137 | { |
| 1138 | struct sysc *ddata; |
| 1139 | int error; |
| 1140 | |
| 1141 | ddata = sysc_child_to_parent(dev); |
| 1142 | |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1143 | dev_dbg(ddata->dev, "%s %s\n", __func__, |
| 1144 | ddata->name ? ddata->name : ""); |
| 1145 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1146 | error = pm_generic_suspend_noirq(dev); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1147 | if (error) { |
| 1148 | dev_err(dev, "%s error at %i: %i\n", |
| 1149 | __func__, __LINE__, error); |
| 1150 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1151 | return error; |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1152 | } |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1153 | |
| 1154 | if (!pm_runtime_status_suspended(dev)) { |
| 1155 | error = pm_generic_runtime_suspend(dev); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1156 | if (error) { |
Tony Lindgren | f949078 | 2018-09-28 15:21:50 -0700 | [diff] [blame] | 1157 | dev_dbg(dev, "%s busy at %i: %i\n", |
| 1158 | __func__, __LINE__, error); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1159 | |
Tony Lindgren | 4f3530f | 2018-08-08 01:07:06 -0700 | [diff] [blame] | 1160 | return 0; |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1161 | } |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1162 | |
| 1163 | error = sysc_runtime_suspend(ddata->dev); |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1164 | if (error) { |
| 1165 | dev_err(dev, "%s error at %i: %i\n", |
| 1166 | __func__, __LINE__, error); |
| 1167 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1168 | return error; |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1169 | } |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1170 | |
| 1171 | ddata->child_needs_resume = true; |
| 1172 | } |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | static int sysc_child_resume_noirq(struct device *dev) |
| 1178 | { |
| 1179 | struct sysc *ddata; |
| 1180 | int error; |
| 1181 | |
| 1182 | ddata = sysc_child_to_parent(dev); |
| 1183 | |
Tony Lindgren | ef55f82 | 2018-04-16 10:27:15 -0700 | [diff] [blame] | 1184 | dev_dbg(ddata->dev, "%s %s\n", __func__, |
| 1185 | ddata->name ? ddata->name : ""); |
| 1186 | |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1187 | if (ddata->child_needs_resume) { |
| 1188 | ddata->child_needs_resume = false; |
| 1189 | |
| 1190 | error = sysc_runtime_resume(ddata->dev); |
| 1191 | if (error) |
| 1192 | dev_err(ddata->dev, |
| 1193 | "%s runtime resume error: %i\n", |
| 1194 | __func__, error); |
| 1195 | |
| 1196 | error = pm_generic_runtime_resume(dev); |
| 1197 | if (error) |
| 1198 | dev_err(ddata->dev, |
| 1199 | "%s generic runtime resume: %i\n", |
| 1200 | __func__, error); |
| 1201 | } |
| 1202 | |
| 1203 | return pm_generic_resume_noirq(dev); |
| 1204 | } |
| 1205 | #endif |
| 1206 | |
| 1207 | struct dev_pm_domain sysc_child_pm_domain = { |
| 1208 | .ops = { |
| 1209 | SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend, |
| 1210 | sysc_child_runtime_resume, |
| 1211 | NULL) |
| 1212 | USE_PLATFORM_PM_SLEEP_OPS |
| 1213 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq, |
| 1214 | sysc_child_resume_noirq) |
| 1215 | } |
| 1216 | }; |
| 1217 | |
| 1218 | /** |
| 1219 | * sysc_legacy_idle_quirk - handle children in omap_device compatible way |
| 1220 | * @ddata: device driver data |
| 1221 | * @child: child device driver |
| 1222 | * |
| 1223 | * Allow idle for child devices as done with _od_runtime_suspend(). |
| 1224 | * Otherwise many child devices will not idle because of the permanent |
| 1225 | * parent usecount set in pm_runtime_irq_safe(). |
| 1226 | * |
| 1227 | * Note that the long term solution is to just modify the child device |
| 1228 | * drivers to not set pm_runtime_irq_safe() and then this can be just |
| 1229 | * dropped. |
| 1230 | */ |
| 1231 | static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child) |
| 1232 | { |
| 1233 | if (!ddata->legacy_mode) |
| 1234 | return; |
| 1235 | |
| 1236 | if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE) |
| 1237 | dev_pm_domain_set(child, &sysc_child_pm_domain); |
| 1238 | } |
| 1239 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1240 | static int sysc_notifier_call(struct notifier_block *nb, |
| 1241 | unsigned long event, void *device) |
| 1242 | { |
| 1243 | struct device *dev = device; |
| 1244 | struct sysc *ddata; |
| 1245 | int error; |
| 1246 | |
| 1247 | ddata = sysc_child_to_parent(dev); |
| 1248 | if (!ddata) |
| 1249 | return NOTIFY_DONE; |
| 1250 | |
| 1251 | switch (event) { |
| 1252 | case BUS_NOTIFY_ADD_DEVICE: |
Tony Lindgren | 09dfe58 | 2018-04-16 10:25:52 -0700 | [diff] [blame] | 1253 | error = sysc_child_add_clocks(ddata, dev); |
| 1254 | if (error) |
| 1255 | return error; |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1256 | sysc_legacy_idle_quirk(ddata, dev); |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1257 | break; |
| 1258 | default: |
| 1259 | break; |
| 1260 | } |
| 1261 | |
| 1262 | return NOTIFY_DONE; |
| 1263 | } |
| 1264 | |
| 1265 | static struct notifier_block sysc_nb = { |
| 1266 | .notifier_call = sysc_notifier_call, |
| 1267 | }; |
| 1268 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1269 | /* Device tree configured quirks */ |
| 1270 | struct sysc_dts_quirk { |
| 1271 | const char *name; |
| 1272 | u32 mask; |
| 1273 | }; |
| 1274 | |
| 1275 | static const struct sysc_dts_quirk sysc_dts_quirks[] = { |
| 1276 | { .name = "ti,no-idle-on-init", |
| 1277 | .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, }, |
| 1278 | { .name = "ti,no-reset-on-init", |
| 1279 | .mask = SYSC_QUIRK_NO_RESET_ON_INIT, }, |
| 1280 | }; |
| 1281 | |
| 1282 | static int sysc_init_dts_quirks(struct sysc *ddata) |
| 1283 | { |
| 1284 | struct device_node *np = ddata->dev->of_node; |
| 1285 | const struct property *prop; |
| 1286 | int i, len, error; |
| 1287 | u32 val; |
| 1288 | |
| 1289 | ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL); |
| 1290 | |
| 1291 | for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) { |
| 1292 | prop = of_get_property(np, sysc_dts_quirks[i].name, &len); |
| 1293 | if (!prop) |
Tony Lindgren | d39b6ea | 2018-02-15 09:18:55 -0800 | [diff] [blame] | 1294 | continue; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1295 | |
| 1296 | ddata->cfg.quirks |= sysc_dts_quirks[i].mask; |
| 1297 | } |
| 1298 | |
| 1299 | error = of_property_read_u32(np, "ti,sysc-delay-us", &val); |
| 1300 | if (!error) { |
| 1301 | if (val > 255) { |
| 1302 | dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n", |
| 1303 | val); |
| 1304 | } |
| 1305 | |
| 1306 | ddata->cfg.srst_udelay = (u8)val; |
| 1307 | } |
| 1308 | |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1312 | static void sysc_unprepare(struct sysc *ddata) |
| 1313 | { |
| 1314 | int i; |
| 1315 | |
| 1316 | for (i = 0; i < SYSC_MAX_CLOCKS; i++) { |
| 1317 | if (!IS_ERR_OR_NULL(ddata->clocks[i])) |
| 1318 | clk_unprepare(ddata->clocks[i]); |
| 1319 | } |
| 1320 | } |
| 1321 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1322 | /* |
| 1323 | * Common sysc register bits found on omap2, also known as type1 |
| 1324 | */ |
| 1325 | static const struct sysc_regbits sysc_regbits_omap2 = { |
| 1326 | .dmadisable_shift = -ENODEV, |
| 1327 | .midle_shift = 12, |
| 1328 | .sidle_shift = 3, |
| 1329 | .clkact_shift = 8, |
| 1330 | .emufree_shift = 5, |
| 1331 | .enwkup_shift = 2, |
| 1332 | .srst_shift = 1, |
| 1333 | .autoidle_shift = 0, |
| 1334 | }; |
| 1335 | |
| 1336 | static const struct sysc_capabilities sysc_omap2 = { |
| 1337 | .type = TI_SYSC_OMAP2, |
| 1338 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE | |
| 1339 | SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET | |
| 1340 | SYSC_OMAP2_AUTOIDLE, |
| 1341 | .regbits = &sysc_regbits_omap2, |
| 1342 | }; |
| 1343 | |
| 1344 | /* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */ |
| 1345 | static const struct sysc_capabilities sysc_omap2_timer = { |
| 1346 | .type = TI_SYSC_OMAP2_TIMER, |
| 1347 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE | |
| 1348 | SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET | |
| 1349 | SYSC_OMAP2_AUTOIDLE, |
| 1350 | .regbits = &sysc_regbits_omap2, |
| 1351 | .mod_quirks = SYSC_QUIRK_USE_CLOCKACT, |
| 1352 | }; |
| 1353 | |
| 1354 | /* |
| 1355 | * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2 |
| 1356 | * with different sidle position |
| 1357 | */ |
| 1358 | static const struct sysc_regbits sysc_regbits_omap3_sham = { |
| 1359 | .dmadisable_shift = -ENODEV, |
| 1360 | .midle_shift = -ENODEV, |
| 1361 | .sidle_shift = 4, |
| 1362 | .clkact_shift = -ENODEV, |
| 1363 | .enwkup_shift = -ENODEV, |
| 1364 | .srst_shift = 1, |
| 1365 | .autoidle_shift = 0, |
| 1366 | .emufree_shift = -ENODEV, |
| 1367 | }; |
| 1368 | |
| 1369 | static const struct sysc_capabilities sysc_omap3_sham = { |
| 1370 | .type = TI_SYSC_OMAP3_SHAM, |
| 1371 | .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE, |
| 1372 | .regbits = &sysc_regbits_omap3_sham, |
| 1373 | }; |
| 1374 | |
| 1375 | /* |
| 1376 | * AES register bits found on omap3 and later, a variant of |
| 1377 | * sysc_regbits_omap2 with different sidle position |
| 1378 | */ |
| 1379 | static const struct sysc_regbits sysc_regbits_omap3_aes = { |
| 1380 | .dmadisable_shift = -ENODEV, |
| 1381 | .midle_shift = -ENODEV, |
| 1382 | .sidle_shift = 6, |
| 1383 | .clkact_shift = -ENODEV, |
| 1384 | .enwkup_shift = -ENODEV, |
| 1385 | .srst_shift = 1, |
| 1386 | .autoidle_shift = 0, |
| 1387 | .emufree_shift = -ENODEV, |
| 1388 | }; |
| 1389 | |
| 1390 | static const struct sysc_capabilities sysc_omap3_aes = { |
| 1391 | .type = TI_SYSC_OMAP3_AES, |
| 1392 | .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE, |
| 1393 | .regbits = &sysc_regbits_omap3_aes, |
| 1394 | }; |
| 1395 | |
| 1396 | /* |
| 1397 | * Common sysc register bits found on omap4, also known as type2 |
| 1398 | */ |
| 1399 | static const struct sysc_regbits sysc_regbits_omap4 = { |
| 1400 | .dmadisable_shift = 16, |
| 1401 | .midle_shift = 4, |
| 1402 | .sidle_shift = 2, |
| 1403 | .clkact_shift = -ENODEV, |
| 1404 | .enwkup_shift = -ENODEV, |
| 1405 | .emufree_shift = 1, |
| 1406 | .srst_shift = 0, |
| 1407 | .autoidle_shift = -ENODEV, |
| 1408 | }; |
| 1409 | |
| 1410 | static const struct sysc_capabilities sysc_omap4 = { |
| 1411 | .type = TI_SYSC_OMAP4, |
| 1412 | .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU | |
| 1413 | SYSC_OMAP4_SOFTRESET, |
| 1414 | .regbits = &sysc_regbits_omap4, |
| 1415 | }; |
| 1416 | |
| 1417 | static const struct sysc_capabilities sysc_omap4_timer = { |
| 1418 | .type = TI_SYSC_OMAP4_TIMER, |
| 1419 | .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU | |
| 1420 | SYSC_OMAP4_SOFTRESET, |
| 1421 | .regbits = &sysc_regbits_omap4, |
| 1422 | }; |
| 1423 | |
| 1424 | /* |
| 1425 | * Common sysc register bits found on omap4, also known as type3 |
| 1426 | */ |
| 1427 | static const struct sysc_regbits sysc_regbits_omap4_simple = { |
| 1428 | .dmadisable_shift = -ENODEV, |
| 1429 | .midle_shift = 2, |
| 1430 | .sidle_shift = 0, |
| 1431 | .clkact_shift = -ENODEV, |
| 1432 | .enwkup_shift = -ENODEV, |
| 1433 | .srst_shift = -ENODEV, |
| 1434 | .emufree_shift = -ENODEV, |
| 1435 | .autoidle_shift = -ENODEV, |
| 1436 | }; |
| 1437 | |
| 1438 | static const struct sysc_capabilities sysc_omap4_simple = { |
| 1439 | .type = TI_SYSC_OMAP4_SIMPLE, |
| 1440 | .regbits = &sysc_regbits_omap4_simple, |
| 1441 | }; |
| 1442 | |
| 1443 | /* |
| 1444 | * SmartReflex sysc found on omap34xx |
| 1445 | */ |
| 1446 | static const struct sysc_regbits sysc_regbits_omap34xx_sr = { |
| 1447 | .dmadisable_shift = -ENODEV, |
| 1448 | .midle_shift = -ENODEV, |
| 1449 | .sidle_shift = -ENODEV, |
| 1450 | .clkact_shift = 20, |
| 1451 | .enwkup_shift = -ENODEV, |
| 1452 | .srst_shift = -ENODEV, |
| 1453 | .emufree_shift = -ENODEV, |
| 1454 | .autoidle_shift = -ENODEV, |
| 1455 | }; |
| 1456 | |
| 1457 | static const struct sysc_capabilities sysc_34xx_sr = { |
| 1458 | .type = TI_SYSC_OMAP34XX_SR, |
| 1459 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY, |
| 1460 | .regbits = &sysc_regbits_omap34xx_sr, |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1461 | .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED | |
| 1462 | SYSC_QUIRK_LEGACY_IDLE, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1463 | }; |
| 1464 | |
| 1465 | /* |
| 1466 | * SmartReflex sysc found on omap36xx and later |
| 1467 | */ |
| 1468 | static const struct sysc_regbits sysc_regbits_omap36xx_sr = { |
| 1469 | .dmadisable_shift = -ENODEV, |
| 1470 | .midle_shift = -ENODEV, |
| 1471 | .sidle_shift = 24, |
| 1472 | .clkact_shift = -ENODEV, |
| 1473 | .enwkup_shift = 26, |
| 1474 | .srst_shift = -ENODEV, |
| 1475 | .emufree_shift = -ENODEV, |
| 1476 | .autoidle_shift = -ENODEV, |
| 1477 | }; |
| 1478 | |
| 1479 | static const struct sysc_capabilities sysc_36xx_sr = { |
| 1480 | .type = TI_SYSC_OMAP36XX_SR, |
Tony Lindgren | 3267c08 | 2018-01-22 09:32:53 -0800 | [diff] [blame] | 1481 | .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1482 | .regbits = &sysc_regbits_omap36xx_sr, |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1483 | .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1484 | }; |
| 1485 | |
| 1486 | static const struct sysc_capabilities sysc_omap4_sr = { |
| 1487 | .type = TI_SYSC_OMAP4_SR, |
| 1488 | .regbits = &sysc_regbits_omap36xx_sr, |
Tony Lindgren | a885f0f | 2018-02-22 14:03:48 -0800 | [diff] [blame] | 1489 | .mod_quirks = SYSC_QUIRK_LEGACY_IDLE, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1490 | }; |
| 1491 | |
| 1492 | /* |
| 1493 | * McASP register bits found on omap4 and later |
| 1494 | */ |
| 1495 | static const struct sysc_regbits sysc_regbits_omap4_mcasp = { |
| 1496 | .dmadisable_shift = -ENODEV, |
| 1497 | .midle_shift = -ENODEV, |
| 1498 | .sidle_shift = 0, |
| 1499 | .clkact_shift = -ENODEV, |
| 1500 | .enwkup_shift = -ENODEV, |
| 1501 | .srst_shift = -ENODEV, |
| 1502 | .emufree_shift = -ENODEV, |
| 1503 | .autoidle_shift = -ENODEV, |
| 1504 | }; |
| 1505 | |
| 1506 | static const struct sysc_capabilities sysc_omap4_mcasp = { |
| 1507 | .type = TI_SYSC_OMAP4_MCASP, |
| 1508 | .regbits = &sysc_regbits_omap4_mcasp, |
Tony Lindgren | 2c63a83 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 1509 | .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED, |
| 1510 | }; |
| 1511 | |
| 1512 | /* |
| 1513 | * McASP found on dra7 and later |
| 1514 | */ |
| 1515 | static const struct sysc_capabilities sysc_dra7_mcasp = { |
| 1516 | .type = TI_SYSC_OMAP4_SIMPLE, |
| 1517 | .regbits = &sysc_regbits_omap4_simple, |
| 1518 | .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1519 | }; |
| 1520 | |
| 1521 | /* |
| 1522 | * FS USB host found on omap4 and later |
| 1523 | */ |
| 1524 | static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = { |
| 1525 | .dmadisable_shift = -ENODEV, |
| 1526 | .midle_shift = -ENODEV, |
| 1527 | .sidle_shift = 24, |
| 1528 | .clkact_shift = -ENODEV, |
| 1529 | .enwkup_shift = 26, |
| 1530 | .srst_shift = -ENODEV, |
| 1531 | .emufree_shift = -ENODEV, |
| 1532 | .autoidle_shift = -ENODEV, |
| 1533 | }; |
| 1534 | |
| 1535 | static const struct sysc_capabilities sysc_omap4_usb_host_fs = { |
| 1536 | .type = TI_SYSC_OMAP4_USB_HOST_FS, |
| 1537 | .sysc_mask = SYSC_OMAP2_ENAWAKEUP, |
| 1538 | .regbits = &sysc_regbits_omap4_usb_host_fs, |
| 1539 | }; |
| 1540 | |
Faiz Abbas | 7f35e63 | 2018-07-09 22:18:38 +0530 | [diff] [blame] | 1541 | static const struct sysc_regbits sysc_regbits_dra7_mcan = { |
| 1542 | .dmadisable_shift = -ENODEV, |
| 1543 | .midle_shift = -ENODEV, |
| 1544 | .sidle_shift = -ENODEV, |
| 1545 | .clkact_shift = -ENODEV, |
| 1546 | .enwkup_shift = 4, |
| 1547 | .srst_shift = 0, |
| 1548 | .emufree_shift = -ENODEV, |
| 1549 | .autoidle_shift = -ENODEV, |
| 1550 | }; |
| 1551 | |
| 1552 | static const struct sysc_capabilities sysc_dra7_mcan = { |
| 1553 | .type = TI_SYSC_DRA7_MCAN, |
| 1554 | .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET, |
| 1555 | .regbits = &sysc_regbits_dra7_mcan, |
| 1556 | }; |
| 1557 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1558 | static int sysc_init_pdata(struct sysc *ddata) |
| 1559 | { |
| 1560 | struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); |
| 1561 | struct ti_sysc_module_data mdata; |
| 1562 | int error = 0; |
| 1563 | |
| 1564 | if (!pdata || !ddata->legacy_mode) |
| 1565 | return 0; |
| 1566 | |
| 1567 | mdata.name = ddata->legacy_mode; |
| 1568 | mdata.module_pa = ddata->module_pa; |
| 1569 | mdata.module_size = ddata->module_size; |
| 1570 | mdata.offsets = ddata->offsets; |
| 1571 | mdata.nr_offsets = SYSC_MAX_REGS; |
| 1572 | mdata.cap = ddata->cap; |
| 1573 | mdata.cfg = &ddata->cfg; |
| 1574 | |
| 1575 | if (!pdata->init_module) |
| 1576 | return -ENODEV; |
| 1577 | |
| 1578 | error = pdata->init_module(ddata->dev, &mdata, &ddata->cookie); |
| 1579 | if (error == -EEXIST) |
| 1580 | error = 0; |
| 1581 | |
| 1582 | return error; |
| 1583 | } |
| 1584 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1585 | static int sysc_init_match(struct sysc *ddata) |
| 1586 | { |
| 1587 | const struct sysc_capabilities *cap; |
| 1588 | |
| 1589 | cap = of_device_get_match_data(ddata->dev); |
| 1590 | if (!cap) |
| 1591 | return -EINVAL; |
| 1592 | |
| 1593 | ddata->cap = cap; |
| 1594 | if (ddata->cap) |
| 1595 | ddata->cfg.quirks |= ddata->cap->mod_quirks; |
| 1596 | |
| 1597 | return 0; |
| 1598 | } |
| 1599 | |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 1600 | static void ti_sysc_idle(struct work_struct *work) |
| 1601 | { |
| 1602 | struct sysc *ddata; |
| 1603 | |
| 1604 | ddata = container_of(work, struct sysc, idle_work.work); |
| 1605 | |
| 1606 | if (pm_runtime_active(ddata->dev)) |
| 1607 | pm_runtime_put_sync(ddata->dev); |
| 1608 | } |
| 1609 | |
Tony Lindgren | c4bebea | 2018-04-16 10:24:54 -0700 | [diff] [blame] | 1610 | static const struct of_device_id sysc_match_table[] = { |
| 1611 | { .compatible = "simple-bus", }, |
| 1612 | { /* sentinel */ }, |
| 1613 | }; |
| 1614 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1615 | static int sysc_probe(struct platform_device *pdev) |
| 1616 | { |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1617 | struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1618 | struct sysc *ddata; |
| 1619 | int error; |
| 1620 | |
| 1621 | ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); |
| 1622 | if (!ddata) |
| 1623 | return -ENOMEM; |
| 1624 | |
| 1625 | ddata->dev = &pdev->dev; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1626 | platform_set_drvdata(pdev, ddata); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1627 | |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1628 | error = sysc_init_match(ddata); |
| 1629 | if (error) |
| 1630 | return error; |
| 1631 | |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1632 | error = sysc_init_dts_quirks(ddata); |
| 1633 | if (error) |
| 1634 | goto unprepare; |
| 1635 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1636 | error = sysc_get_clocks(ddata); |
| 1637 | if (error) |
| 1638 | return error; |
| 1639 | |
| 1640 | error = sysc_map_and_check_registers(ddata); |
| 1641 | if (error) |
| 1642 | goto unprepare; |
| 1643 | |
Tony Lindgren | c5a2de9 | 2017-12-15 09:41:23 -0800 | [diff] [blame] | 1644 | error = sysc_init_sysc_mask(ddata); |
| 1645 | if (error) |
| 1646 | goto unprepare; |
| 1647 | |
| 1648 | error = sysc_init_idlemodes(ddata); |
| 1649 | if (error) |
| 1650 | goto unprepare; |
| 1651 | |
| 1652 | error = sysc_init_syss_mask(ddata); |
| 1653 | if (error) |
| 1654 | goto unprepare; |
| 1655 | |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1656 | error = sysc_init_pdata(ddata); |
| 1657 | if (error) |
| 1658 | goto unprepare; |
| 1659 | |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1660 | error = sysc_init_resets(ddata); |
| 1661 | if (error) |
| 1662 | return error; |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1663 | |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1664 | pm_runtime_enable(ddata->dev); |
Tony Lindgren | 566a9b05 | 2017-12-15 09:41:19 -0800 | [diff] [blame] | 1665 | error = sysc_init_module(ddata); |
| 1666 | if (error) |
| 1667 | goto unprepare; |
| 1668 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1669 | error = pm_runtime_get_sync(ddata->dev); |
| 1670 | if (error < 0) { |
| 1671 | pm_runtime_put_noidle(ddata->dev); |
| 1672 | pm_runtime_disable(ddata->dev); |
| 1673 | goto unprepare; |
| 1674 | } |
| 1675 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1676 | sysc_show_registers(ddata); |
| 1677 | |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1678 | ddata->dev->type = &sysc_device_type; |
Tony Lindgren | c4bebea | 2018-04-16 10:24:54 -0700 | [diff] [blame] | 1679 | error = of_platform_populate(ddata->dev->of_node, sysc_match_table, |
| 1680 | pdata ? pdata->auxdata : NULL, |
Tony Lindgren | ef70b0b | 2018-02-22 14:00:25 -0800 | [diff] [blame] | 1681 | ddata->dev); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1682 | if (error) |
| 1683 | goto err; |
| 1684 | |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 1685 | INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle); |
| 1686 | |
| 1687 | /* At least earlycon won't survive without deferred idle */ |
| 1688 | if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE_ON_INIT | |
| 1689 | SYSC_QUIRK_NO_RESET_ON_INIT)) { |
| 1690 | schedule_delayed_work(&ddata->idle_work, 3000); |
| 1691 | } else { |
| 1692 | pm_runtime_put(&pdev->dev); |
| 1693 | } |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1694 | |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1695 | if (!of_get_available_child_count(ddata->dev->of_node)) |
| 1696 | reset_control_assert(ddata->rsts); |
| 1697 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1698 | return 0; |
| 1699 | |
| 1700 | err: |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1701 | pm_runtime_put_sync(&pdev->dev); |
| 1702 | pm_runtime_disable(&pdev->dev); |
| 1703 | unprepare: |
| 1704 | sysc_unprepare(ddata); |
| 1705 | |
| 1706 | return error; |
| 1707 | } |
| 1708 | |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1709 | static int sysc_remove(struct platform_device *pdev) |
| 1710 | { |
| 1711 | struct sysc *ddata = platform_get_drvdata(pdev); |
| 1712 | int error; |
| 1713 | |
Tony Lindgren | 76f0f77 | 2018-02-23 08:28:45 -0800 | [diff] [blame] | 1714 | cancel_delayed_work_sync(&ddata->idle_work); |
| 1715 | |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1716 | error = pm_runtime_get_sync(ddata->dev); |
| 1717 | if (error < 0) { |
| 1718 | pm_runtime_put_noidle(ddata->dev); |
| 1719 | pm_runtime_disable(ddata->dev); |
| 1720 | goto unprepare; |
| 1721 | } |
| 1722 | |
| 1723 | of_platform_depopulate(&pdev->dev); |
| 1724 | |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1725 | pm_runtime_put_sync(&pdev->dev); |
| 1726 | pm_runtime_disable(&pdev->dev); |
Tony Lindgren | 5062236 | 2018-04-16 10:20:27 -0700 | [diff] [blame] | 1727 | reset_control_assert(ddata->rsts); |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1728 | |
| 1729 | unprepare: |
| 1730 | sysc_unprepare(ddata); |
| 1731 | |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1735 | static const struct of_device_id sysc_match[] = { |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1736 | { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, }, |
| 1737 | { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, }, |
| 1738 | { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, }, |
| 1739 | { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, }, |
| 1740 | { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, }, |
| 1741 | { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, }, |
| 1742 | { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, }, |
| 1743 | { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, }, |
| 1744 | { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, }, |
| 1745 | { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, }, |
| 1746 | { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, }, |
Tony Lindgren | 2c63a83 | 2018-11-15 14:46:53 -0800 | [diff] [blame] | 1747 | { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, }, |
Tony Lindgren | 70a6524 | 2017-12-15 09:41:09 -0800 | [diff] [blame] | 1748 | { .compatible = "ti,sysc-usb-host-fs", |
| 1749 | .data = &sysc_omap4_usb_host_fs, }, |
Faiz Abbas | 7f35e63 | 2018-07-09 22:18:38 +0530 | [diff] [blame] | 1750 | { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, }, |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1751 | { }, |
| 1752 | }; |
| 1753 | MODULE_DEVICE_TABLE(of, sysc_match); |
| 1754 | |
| 1755 | static struct platform_driver sysc_driver = { |
| 1756 | .probe = sysc_probe, |
Tony Lindgren | 684be5a | 2017-10-13 10:48:40 -0700 | [diff] [blame] | 1757 | .remove = sysc_remove, |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1758 | .driver = { |
| 1759 | .name = "ti-sysc", |
| 1760 | .of_match_table = sysc_match, |
| 1761 | .pm = &sysc_pm_ops, |
| 1762 | }, |
| 1763 | }; |
Tony Lindgren | 2c355ff | 2018-02-22 13:58:03 -0800 | [diff] [blame] | 1764 | |
| 1765 | static int __init sysc_init(void) |
| 1766 | { |
| 1767 | bus_register_notifier(&platform_bus_type, &sysc_nb); |
| 1768 | |
| 1769 | return platform_driver_register(&sysc_driver); |
| 1770 | } |
| 1771 | module_init(sysc_init); |
| 1772 | |
| 1773 | static void __exit sysc_exit(void) |
| 1774 | { |
| 1775 | bus_unregister_notifier(&platform_bus_type, &sysc_nb); |
| 1776 | platform_driver_unregister(&sysc_driver); |
| 1777 | } |
| 1778 | module_exit(sysc_exit); |
Tony Lindgren | 0eecc63 | 2017-10-10 14:23:43 -0700 | [diff] [blame] | 1779 | |
| 1780 | MODULE_DESCRIPTION("TI sysc interconnect target driver"); |
| 1781 | MODULE_LICENSE("GPL v2"); |