David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * ti-sysc.c - Texas Instruments sysc interconnect target driver |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/io.h> |
| 7 | #include <linux/clk.h> |
| 8 | #include <linux/clkdev.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/pm_domain.h> |
| 13 | #include <linux/pm_runtime.h> |
| 14 | #include <linux/reset.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <linux/of_platform.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/iopoll.h> |
| 19 | |
| 20 | #include <linux/platform_data/ti-sysc.h> |
| 21 | |
| 22 | #include <dt-bindings/bus/ti-sysc.h> |
| 23 | |
| 24 | #define MAX_MODULE_SOFTRESET_WAIT 10000 |
| 25 | |
| 26 | static const char * const reg_names[] = { "rev", "sysc", "syss", }; |
| 27 | |
| 28 | enum sysc_clocks { |
| 29 | SYSC_FCK, |
| 30 | SYSC_ICK, |
| 31 | SYSC_OPTFCK0, |
| 32 | SYSC_OPTFCK1, |
| 33 | SYSC_OPTFCK2, |
| 34 | SYSC_OPTFCK3, |
| 35 | SYSC_OPTFCK4, |
| 36 | SYSC_OPTFCK5, |
| 37 | SYSC_OPTFCK6, |
| 38 | SYSC_OPTFCK7, |
| 39 | SYSC_MAX_CLOCKS, |
| 40 | }; |
| 41 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 42 | static const char * const clock_names[SYSC_MAX_CLOCKS] = { |
| 43 | "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4", |
| 44 | "opt5", "opt6", "opt7", |
| 45 | }; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 46 | |
| 47 | #define SYSC_IDLEMODE_MASK 3 |
| 48 | #define SYSC_CLOCKACTIVITY_MASK 3 |
| 49 | |
| 50 | /** |
| 51 | * struct sysc - TI sysc interconnect target module registers and capabilities |
| 52 | * @dev: struct device pointer |
| 53 | * @module_pa: physical address of the interconnect target module |
| 54 | * @module_size: size of the interconnect target module |
| 55 | * @module_va: virtual address of the interconnect target module |
| 56 | * @offsets: register offsets from module base |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 57 | * @mdata: ti-sysc to hwmod translation data for a module |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 58 | * @clocks: clocks used by the interconnect target module |
| 59 | * @clock_roles: clock role names for the found clocks |
| 60 | * @nr_clocks: number of clocks used by the interconnect target module |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 61 | * @rsts: resets used by the interconnect target module |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 62 | * @legacy_mode: configured for legacy mode if set |
| 63 | * @cap: interconnect target module capabilities |
| 64 | * @cfg: interconnect target module configuration |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 65 | * @cookie: data used by legacy platform callbacks |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 66 | * @name: name if available |
| 67 | * @revision: interconnect target module revision |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 68 | * @enabled: sysc runtime enabled status |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 69 | * @needs_resume: runtime resume needed on resume from suspend |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 70 | * @child_needs_resume: runtime resume needed for child on resume from suspend |
| 71 | * @disable_on_idle: status flag used for disabling modules with resets |
| 72 | * @idle_work: work structure used to perform delayed idle on a module |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 73 | * @pre_reset_quirk: module specific pre-reset quirk |
| 74 | * @post_reset_quirk: module specific post-reset quirk |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 75 | * @reset_done_quirk: module specific reset done quirk |
| 76 | * @module_enable_quirk: module specific enable quirk |
| 77 | * @module_disable_quirk: module specific disable quirk |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 78 | * @module_unlock_quirk: module specific sysconfig unlock quirk |
| 79 | * @module_lock_quirk: module specific sysconfig lock quirk |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 80 | */ |
| 81 | struct sysc { |
| 82 | struct device *dev; |
| 83 | u64 module_pa; |
| 84 | u32 module_size; |
| 85 | void __iomem *module_va; |
| 86 | int offsets[SYSC_MAX_REGS]; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 87 | struct ti_sysc_module_data *mdata; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 88 | struct clk **clocks; |
| 89 | const char **clock_roles; |
| 90 | int nr_clocks; |
| 91 | struct reset_control *rsts; |
| 92 | const char *legacy_mode; |
| 93 | const struct sysc_capabilities *cap; |
| 94 | struct sysc_config cfg; |
| 95 | struct ti_sysc_cookie cookie; |
| 96 | const char *name; |
| 97 | u32 revision; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 98 | unsigned int enabled:1; |
| 99 | unsigned int needs_resume:1; |
| 100 | unsigned int child_needs_resume:1; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 101 | struct delayed_work idle_work; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 102 | void (*pre_reset_quirk)(struct sysc *sysc); |
| 103 | void (*post_reset_quirk)(struct sysc *sysc); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 104 | void (*reset_done_quirk)(struct sysc *sysc); |
| 105 | void (*module_enable_quirk)(struct sysc *sysc); |
| 106 | void (*module_disable_quirk)(struct sysc *sysc); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 107 | void (*module_unlock_quirk)(struct sysc *sysc); |
| 108 | void (*module_lock_quirk)(struct sysc *sysc); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 111 | static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np, |
| 112 | bool is_child); |
| 113 | |
| 114 | static void sysc_write(struct sysc *ddata, int offset, u32 value) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 115 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 116 | if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) { |
| 117 | writew_relaxed(value & 0xffff, ddata->module_va + offset); |
| 118 | |
| 119 | /* Only i2c revision has LO and HI register with stride of 4 */ |
| 120 | if (ddata->offsets[SYSC_REVISION] >= 0 && |
| 121 | offset == ddata->offsets[SYSC_REVISION]) { |
| 122 | u16 hi = value >> 16; |
| 123 | |
| 124 | writew_relaxed(hi, ddata->module_va + offset + 4); |
| 125 | } |
| 126 | |
| 127 | return; |
| 128 | } |
| 129 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 130 | writel_relaxed(value, ddata->module_va + offset); |
| 131 | } |
| 132 | |
| 133 | static u32 sysc_read(struct sysc *ddata, int offset) |
| 134 | { |
| 135 | if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) { |
| 136 | u32 val; |
| 137 | |
| 138 | val = readw_relaxed(ddata->module_va + offset); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 139 | |
| 140 | /* Only i2c revision has LO and HI register with stride of 4 */ |
| 141 | if (ddata->offsets[SYSC_REVISION] >= 0 && |
| 142 | offset == ddata->offsets[SYSC_REVISION]) { |
| 143 | u16 tmp = readw_relaxed(ddata->module_va + offset + 4); |
| 144 | |
| 145 | val |= tmp << 16; |
| 146 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 147 | |
| 148 | return val; |
| 149 | } |
| 150 | |
| 151 | return readl_relaxed(ddata->module_va + offset); |
| 152 | } |
| 153 | |
| 154 | static bool sysc_opt_clks_needed(struct sysc *ddata) |
| 155 | { |
| 156 | return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED); |
| 157 | } |
| 158 | |
| 159 | static u32 sysc_read_revision(struct sysc *ddata) |
| 160 | { |
| 161 | int offset = ddata->offsets[SYSC_REVISION]; |
| 162 | |
| 163 | if (offset < 0) |
| 164 | return 0; |
| 165 | |
| 166 | return sysc_read(ddata, offset); |
| 167 | } |
| 168 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 169 | static u32 sysc_read_sysconfig(struct sysc *ddata) |
| 170 | { |
| 171 | int offset = ddata->offsets[SYSC_SYSCONFIG]; |
| 172 | |
| 173 | if (offset < 0) |
| 174 | return 0; |
| 175 | |
| 176 | return sysc_read(ddata, offset); |
| 177 | } |
| 178 | |
| 179 | static u32 sysc_read_sysstatus(struct sysc *ddata) |
| 180 | { |
| 181 | int offset = ddata->offsets[SYSC_SYSSTATUS]; |
| 182 | |
| 183 | if (offset < 0) |
| 184 | return 0; |
| 185 | |
| 186 | return sysc_read(ddata, offset); |
| 187 | } |
| 188 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 189 | /* Poll on reset status */ |
| 190 | static int sysc_wait_softreset(struct sysc *ddata) |
| 191 | { |
| 192 | u32 sysc_mask, syss_done, rstval; |
| 193 | int syss_offset, error = 0; |
| 194 | |
| 195 | if (ddata->cap->regbits->srst_shift < 0) |
| 196 | return 0; |
| 197 | |
| 198 | syss_offset = ddata->offsets[SYSC_SYSSTATUS]; |
| 199 | sysc_mask = BIT(ddata->cap->regbits->srst_shift); |
| 200 | |
| 201 | if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED) |
| 202 | syss_done = 0; |
| 203 | else |
| 204 | syss_done = ddata->cfg.syss_mask; |
| 205 | |
| 206 | if (syss_offset >= 0) { |
| 207 | error = readx_poll_timeout_atomic(sysc_read_sysstatus, ddata, |
| 208 | rstval, (rstval & ddata->cfg.syss_mask) == |
| 209 | syss_done, 100, MAX_MODULE_SOFTRESET_WAIT); |
| 210 | |
| 211 | } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) { |
| 212 | error = readx_poll_timeout_atomic(sysc_read_sysconfig, ddata, |
| 213 | rstval, !(rstval & sysc_mask), |
| 214 | 100, MAX_MODULE_SOFTRESET_WAIT); |
| 215 | } |
| 216 | |
| 217 | return error; |
| 218 | } |
| 219 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 220 | static int sysc_add_named_clock_from_child(struct sysc *ddata, |
| 221 | const char *name, |
| 222 | const char *optfck_name) |
| 223 | { |
| 224 | struct device_node *np = ddata->dev->of_node; |
| 225 | struct device_node *child; |
| 226 | struct clk_lookup *cl; |
| 227 | struct clk *clock; |
| 228 | const char *n; |
| 229 | |
| 230 | if (name) |
| 231 | n = name; |
| 232 | else |
| 233 | n = optfck_name; |
| 234 | |
| 235 | /* Does the clock alias already exist? */ |
| 236 | clock = of_clk_get_by_name(np, n); |
| 237 | if (!IS_ERR(clock)) { |
| 238 | clk_put(clock); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | child = of_get_next_available_child(np, NULL); |
| 244 | if (!child) |
| 245 | return -ENODEV; |
| 246 | |
| 247 | clock = devm_get_clk_from_child(ddata->dev, child, name); |
| 248 | if (IS_ERR(clock)) |
| 249 | return PTR_ERR(clock); |
| 250 | |
| 251 | /* |
| 252 | * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID |
| 253 | * limit for clk_get(). If cl ever needs to be freed, it should be done |
| 254 | * with clkdev_drop(). |
| 255 | */ |
| 256 | cl = kcalloc(1, sizeof(*cl), GFP_KERNEL); |
| 257 | if (!cl) |
| 258 | return -ENOMEM; |
| 259 | |
| 260 | cl->con_id = n; |
| 261 | cl->dev_id = dev_name(ddata->dev); |
| 262 | cl->clk = clock; |
| 263 | clkdev_add(cl); |
| 264 | |
| 265 | clk_put(clock); |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name) |
| 271 | { |
| 272 | const char *optfck_name; |
| 273 | int error, index; |
| 274 | |
| 275 | if (ddata->nr_clocks < SYSC_OPTFCK0) |
| 276 | index = SYSC_OPTFCK0; |
| 277 | else |
| 278 | index = ddata->nr_clocks; |
| 279 | |
| 280 | if (name) |
| 281 | optfck_name = name; |
| 282 | else |
| 283 | optfck_name = clock_names[index]; |
| 284 | |
| 285 | error = sysc_add_named_clock_from_child(ddata, name, optfck_name); |
| 286 | if (error) |
| 287 | return error; |
| 288 | |
| 289 | ddata->clock_roles[index] = optfck_name; |
| 290 | ddata->nr_clocks++; |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 295 | static int sysc_get_one_clock(struct sysc *ddata, const char *name) |
| 296 | { |
| 297 | int error, i, index = -ENODEV; |
| 298 | |
| 299 | if (!strncmp(clock_names[SYSC_FCK], name, 3)) |
| 300 | index = SYSC_FCK; |
| 301 | else if (!strncmp(clock_names[SYSC_ICK], name, 3)) |
| 302 | index = SYSC_ICK; |
| 303 | |
| 304 | if (index < 0) { |
| 305 | for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { |
| 306 | if (!ddata->clocks[i]) { |
| 307 | index = i; |
| 308 | break; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | if (index < 0) { |
| 314 | dev_err(ddata->dev, "clock %s not added\n", name); |
| 315 | return index; |
| 316 | } |
| 317 | |
| 318 | ddata->clocks[index] = devm_clk_get(ddata->dev, name); |
| 319 | if (IS_ERR(ddata->clocks[index])) { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 320 | dev_err(ddata->dev, "clock get error for %s: %li\n", |
| 321 | name, PTR_ERR(ddata->clocks[index])); |
| 322 | |
| 323 | return PTR_ERR(ddata->clocks[index]); |
| 324 | } |
| 325 | |
| 326 | error = clk_prepare(ddata->clocks[index]); |
| 327 | if (error) { |
| 328 | dev_err(ddata->dev, "clock prepare error for %s: %i\n", |
| 329 | name, error); |
| 330 | |
| 331 | return error; |
| 332 | } |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static int sysc_get_clocks(struct sysc *ddata) |
| 338 | { |
| 339 | struct device_node *np = ddata->dev->of_node; |
| 340 | struct property *prop; |
| 341 | const char *name; |
| 342 | int nr_fck = 0, nr_ick = 0, i, error = 0; |
| 343 | |
| 344 | ddata->clock_roles = devm_kcalloc(ddata->dev, |
| 345 | SYSC_MAX_CLOCKS, |
| 346 | sizeof(*ddata->clock_roles), |
| 347 | GFP_KERNEL); |
| 348 | if (!ddata->clock_roles) |
| 349 | return -ENOMEM; |
| 350 | |
| 351 | of_property_for_each_string(np, "clock-names", prop, name) { |
| 352 | if (!strncmp(clock_names[SYSC_FCK], name, 3)) |
| 353 | nr_fck++; |
| 354 | if (!strncmp(clock_names[SYSC_ICK], name, 3)) |
| 355 | nr_ick++; |
| 356 | ddata->clock_roles[ddata->nr_clocks] = name; |
| 357 | ddata->nr_clocks++; |
| 358 | } |
| 359 | |
| 360 | if (ddata->nr_clocks < 1) |
| 361 | return 0; |
| 362 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 363 | if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) { |
| 364 | error = sysc_init_ext_opt_clock(ddata, NULL); |
| 365 | if (error) |
| 366 | return error; |
| 367 | } |
| 368 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 369 | if (ddata->nr_clocks > SYSC_MAX_CLOCKS) { |
| 370 | dev_err(ddata->dev, "too many clocks for %pOF\n", np); |
| 371 | |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | if (nr_fck > 1 || nr_ick > 1) { |
| 376 | dev_err(ddata->dev, "max one fck and ick for %pOF\n", np); |
| 377 | |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 381 | /* Always add a slot for main clocks fck and ick even if unused */ |
| 382 | if (!nr_fck) |
| 383 | ddata->nr_clocks++; |
| 384 | if (!nr_ick) |
| 385 | ddata->nr_clocks++; |
| 386 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 387 | ddata->clocks = devm_kcalloc(ddata->dev, |
| 388 | ddata->nr_clocks, sizeof(*ddata->clocks), |
| 389 | GFP_KERNEL); |
| 390 | if (!ddata->clocks) |
| 391 | return -ENOMEM; |
| 392 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 393 | for (i = 0; i < SYSC_MAX_CLOCKS; i++) { |
| 394 | const char *name = ddata->clock_roles[i]; |
| 395 | |
| 396 | if (!name) |
| 397 | continue; |
| 398 | |
| 399 | error = sysc_get_one_clock(ddata, name); |
| 400 | if (error) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 401 | return error; |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 407 | static int sysc_enable_main_clocks(struct sysc *ddata) |
| 408 | { |
| 409 | struct clk *clock; |
| 410 | int i, error; |
| 411 | |
| 412 | if (!ddata->clocks) |
| 413 | return 0; |
| 414 | |
| 415 | for (i = 0; i < SYSC_OPTFCK0; i++) { |
| 416 | clock = ddata->clocks[i]; |
| 417 | |
| 418 | /* Main clocks may not have ick */ |
| 419 | if (IS_ERR_OR_NULL(clock)) |
| 420 | continue; |
| 421 | |
| 422 | error = clk_enable(clock); |
| 423 | if (error) |
| 424 | goto err_disable; |
| 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | |
| 429 | err_disable: |
| 430 | for (i--; i >= 0; i--) { |
| 431 | clock = ddata->clocks[i]; |
| 432 | |
| 433 | /* Main clocks may not have ick */ |
| 434 | if (IS_ERR_OR_NULL(clock)) |
| 435 | continue; |
| 436 | |
| 437 | clk_disable(clock); |
| 438 | } |
| 439 | |
| 440 | return error; |
| 441 | } |
| 442 | |
| 443 | static void sysc_disable_main_clocks(struct sysc *ddata) |
| 444 | { |
| 445 | struct clk *clock; |
| 446 | int i; |
| 447 | |
| 448 | if (!ddata->clocks) |
| 449 | return; |
| 450 | |
| 451 | for (i = 0; i < SYSC_OPTFCK0; i++) { |
| 452 | clock = ddata->clocks[i]; |
| 453 | if (IS_ERR_OR_NULL(clock)) |
| 454 | continue; |
| 455 | |
| 456 | clk_disable(clock); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | static int sysc_enable_opt_clocks(struct sysc *ddata) |
| 461 | { |
| 462 | struct clk *clock; |
| 463 | int i, error; |
| 464 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 465 | if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 466 | return 0; |
| 467 | |
| 468 | for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { |
| 469 | clock = ddata->clocks[i]; |
| 470 | |
| 471 | /* Assume no holes for opt clocks */ |
| 472 | if (IS_ERR_OR_NULL(clock)) |
| 473 | return 0; |
| 474 | |
| 475 | error = clk_enable(clock); |
| 476 | if (error) |
| 477 | goto err_disable; |
| 478 | } |
| 479 | |
| 480 | return 0; |
| 481 | |
| 482 | err_disable: |
| 483 | for (i--; i >= 0; i--) { |
| 484 | clock = ddata->clocks[i]; |
| 485 | if (IS_ERR_OR_NULL(clock)) |
| 486 | continue; |
| 487 | |
| 488 | clk_disable(clock); |
| 489 | } |
| 490 | |
| 491 | return error; |
| 492 | } |
| 493 | |
| 494 | static void sysc_disable_opt_clocks(struct sysc *ddata) |
| 495 | { |
| 496 | struct clk *clock; |
| 497 | int i; |
| 498 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 499 | if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 500 | return; |
| 501 | |
| 502 | for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) { |
| 503 | clock = ddata->clocks[i]; |
| 504 | |
| 505 | /* Assume no holes for opt clocks */ |
| 506 | if (IS_ERR_OR_NULL(clock)) |
| 507 | return; |
| 508 | |
| 509 | clk_disable(clock); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | static void sysc_clkdm_deny_idle(struct sysc *ddata) |
| 514 | { |
| 515 | struct ti_sysc_platform_data *pdata; |
| 516 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 517 | if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO)) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 518 | return; |
| 519 | |
| 520 | pdata = dev_get_platdata(ddata->dev); |
| 521 | if (pdata && pdata->clkdm_deny_idle) |
| 522 | pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie); |
| 523 | } |
| 524 | |
| 525 | static void sysc_clkdm_allow_idle(struct sysc *ddata) |
| 526 | { |
| 527 | struct ti_sysc_platform_data *pdata; |
| 528 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 529 | if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO)) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 530 | return; |
| 531 | |
| 532 | pdata = dev_get_platdata(ddata->dev); |
| 533 | if (pdata && pdata->clkdm_allow_idle) |
| 534 | pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie); |
| 535 | } |
| 536 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 537 | /** |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 538 | * sysc_init_resets - init rstctrl reset line if configured |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 539 | * @ddata: device driver data |
| 540 | * |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 541 | * See sysc_rstctrl_reset_deassert(). |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 542 | */ |
| 543 | static int sysc_init_resets(struct sysc *ddata) |
| 544 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 545 | ddata->rsts = |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 546 | devm_reset_control_get_optional_shared(ddata->dev, "rstctrl"); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 547 | if (IS_ERR(ddata->rsts)) |
| 548 | return PTR_ERR(ddata->rsts); |
| 549 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * sysc_parse_and_check_child_range - parses module IO region from ranges |
| 555 | * @ddata: device driver data |
| 556 | * |
| 557 | * In general we only need rev, syss, and sysc registers and not the whole |
| 558 | * module range. But we do want the offsets for these registers from the |
| 559 | * module base. This allows us to check them against the legacy hwmod |
| 560 | * platform data. Let's also check the ranges are configured properly. |
| 561 | */ |
| 562 | static int sysc_parse_and_check_child_range(struct sysc *ddata) |
| 563 | { |
| 564 | struct device_node *np = ddata->dev->of_node; |
| 565 | const __be32 *ranges; |
| 566 | u32 nr_addr, nr_size; |
| 567 | int len, error; |
| 568 | |
| 569 | ranges = of_get_property(np, "ranges", &len); |
| 570 | if (!ranges) { |
| 571 | dev_err(ddata->dev, "missing ranges for %pOF\n", np); |
| 572 | |
| 573 | return -ENOENT; |
| 574 | } |
| 575 | |
| 576 | len /= sizeof(*ranges); |
| 577 | |
| 578 | if (len < 3) { |
| 579 | dev_err(ddata->dev, "incomplete ranges for %pOF\n", np); |
| 580 | |
| 581 | return -EINVAL; |
| 582 | } |
| 583 | |
| 584 | error = of_property_read_u32(np, "#address-cells", &nr_addr); |
| 585 | if (error) |
| 586 | return -ENOENT; |
| 587 | |
| 588 | error = of_property_read_u32(np, "#size-cells", &nr_size); |
| 589 | if (error) |
| 590 | return -ENOENT; |
| 591 | |
| 592 | if (nr_addr != 1 || nr_size != 1) { |
| 593 | dev_err(ddata->dev, "invalid ranges for %pOF\n", np); |
| 594 | |
| 595 | return -EINVAL; |
| 596 | } |
| 597 | |
| 598 | ranges++; |
| 599 | ddata->module_pa = of_translate_address(np, ranges++); |
| 600 | ddata->module_size = be32_to_cpup(ranges); |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 605 | /* Interconnect instances to probe before l4_per instances */ |
| 606 | static struct resource early_bus_ranges[] = { |
| 607 | /* am3/4 l4_wkup */ |
| 608 | { .start = 0x44c00000, .end = 0x44c00000 + 0x300000, }, |
| 609 | /* omap4/5 and dra7 l4_cfg */ |
| 610 | { .start = 0x4a000000, .end = 0x4a000000 + 0x300000, }, |
| 611 | /* omap4 l4_wkup */ |
| 612 | { .start = 0x4a300000, .end = 0x4a300000 + 0x30000, }, |
| 613 | /* omap5 and dra7 l4_wkup without dra7 dcan segment */ |
| 614 | { .start = 0x4ae00000, .end = 0x4ae00000 + 0x30000, }, |
| 615 | }; |
| 616 | |
| 617 | static atomic_t sysc_defer = ATOMIC_INIT(10); |
| 618 | |
| 619 | /** |
| 620 | * sysc_defer_non_critical - defer non_critical interconnect probing |
| 621 | * @ddata: device driver data |
| 622 | * |
| 623 | * We want to probe l4_cfg and l4_wkup interconnect instances before any |
| 624 | * l4_per instances as l4_per instances depend on resources on l4_cfg and |
| 625 | * l4_wkup interconnects. |
| 626 | */ |
| 627 | static int sysc_defer_non_critical(struct sysc *ddata) |
| 628 | { |
| 629 | struct resource *res; |
| 630 | int i; |
| 631 | |
| 632 | if (!atomic_read(&sysc_defer)) |
| 633 | return 0; |
| 634 | |
| 635 | for (i = 0; i < ARRAY_SIZE(early_bus_ranges); i++) { |
| 636 | res = &early_bus_ranges[i]; |
| 637 | if (ddata->module_pa >= res->start && |
| 638 | ddata->module_pa <= res->end) { |
| 639 | atomic_set(&sysc_defer, 0); |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | atomic_dec_if_positive(&sysc_defer); |
| 646 | |
| 647 | return -EPROBE_DEFER; |
| 648 | } |
| 649 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 650 | static struct device_node *stdout_path; |
| 651 | |
| 652 | static void sysc_init_stdout_path(struct sysc *ddata) |
| 653 | { |
| 654 | struct device_node *np = NULL; |
| 655 | const char *uart; |
| 656 | |
| 657 | if (IS_ERR(stdout_path)) |
| 658 | return; |
| 659 | |
| 660 | if (stdout_path) |
| 661 | return; |
| 662 | |
| 663 | np = of_find_node_by_path("/chosen"); |
| 664 | if (!np) |
| 665 | goto err; |
| 666 | |
| 667 | uart = of_get_property(np, "stdout-path", NULL); |
| 668 | if (!uart) |
| 669 | goto err; |
| 670 | |
| 671 | np = of_find_node_by_path(uart); |
| 672 | if (!np) |
| 673 | goto err; |
| 674 | |
| 675 | stdout_path = np; |
| 676 | |
| 677 | return; |
| 678 | |
| 679 | err: |
| 680 | stdout_path = ERR_PTR(-ENODEV); |
| 681 | } |
| 682 | |
| 683 | static void sysc_check_quirk_stdout(struct sysc *ddata, |
| 684 | struct device_node *np) |
| 685 | { |
| 686 | sysc_init_stdout_path(ddata); |
| 687 | if (np != stdout_path) |
| 688 | return; |
| 689 | |
| 690 | ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT | |
| 691 | SYSC_QUIRK_NO_RESET_ON_INIT; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * sysc_check_one_child - check child configuration |
| 696 | * @ddata: device driver data |
| 697 | * @np: child device node |
| 698 | * |
| 699 | * Let's avoid messy situations where we have new interconnect target |
| 700 | * node but children have "ti,hwmods". These belong to the interconnect |
| 701 | * target node and are managed by this driver. |
| 702 | */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 703 | static void sysc_check_one_child(struct sysc *ddata, |
| 704 | struct device_node *np) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 705 | { |
| 706 | const char *name; |
| 707 | |
| 708 | name = of_get_property(np, "ti,hwmods", NULL); |
| 709 | if (name) |
| 710 | dev_warn(ddata->dev, "really a child ti,hwmods property?"); |
| 711 | |
| 712 | sysc_check_quirk_stdout(ddata, np); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 713 | sysc_parse_dts_quirks(ddata, np, true); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 714 | } |
| 715 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 716 | static void sysc_check_children(struct sysc *ddata) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 717 | { |
| 718 | struct device_node *child; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 719 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 720 | for_each_child_of_node(ddata->dev->of_node, child) |
| 721 | sysc_check_one_child(ddata, child); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /* |
| 725 | * So far only I2C uses 16-bit read access with clockactivity with revision |
| 726 | * in two registers with stride of 4. We can detect this based on the rev |
| 727 | * register size to configure things far enough to be able to properly read |
| 728 | * the revision register. |
| 729 | */ |
| 730 | static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res) |
| 731 | { |
| 732 | if (resource_size(res) == 8) |
| 733 | ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * sysc_parse_one - parses the interconnect target module registers |
| 738 | * @ddata: device driver data |
| 739 | * @reg: register to parse |
| 740 | */ |
| 741 | static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg) |
| 742 | { |
| 743 | struct resource *res; |
| 744 | const char *name; |
| 745 | |
| 746 | switch (reg) { |
| 747 | case SYSC_REVISION: |
| 748 | case SYSC_SYSCONFIG: |
| 749 | case SYSC_SYSSTATUS: |
| 750 | name = reg_names[reg]; |
| 751 | break; |
| 752 | default: |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
| 756 | res = platform_get_resource_byname(to_platform_device(ddata->dev), |
| 757 | IORESOURCE_MEM, name); |
| 758 | if (!res) { |
| 759 | ddata->offsets[reg] = -ENODEV; |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | ddata->offsets[reg] = res->start - ddata->module_pa; |
| 765 | if (reg == SYSC_REVISION) |
| 766 | sysc_check_quirk_16bit(ddata, res); |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static int sysc_parse_registers(struct sysc *ddata) |
| 772 | { |
| 773 | int i, error; |
| 774 | |
| 775 | for (i = 0; i < SYSC_MAX_REGS; i++) { |
| 776 | error = sysc_parse_one(ddata, i); |
| 777 | if (error) |
| 778 | return error; |
| 779 | } |
| 780 | |
| 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * sysc_check_registers - check for misconfigured register overlaps |
| 786 | * @ddata: device driver data |
| 787 | */ |
| 788 | static int sysc_check_registers(struct sysc *ddata) |
| 789 | { |
| 790 | int i, j, nr_regs = 0, nr_matches = 0; |
| 791 | |
| 792 | for (i = 0; i < SYSC_MAX_REGS; i++) { |
| 793 | if (ddata->offsets[i] < 0) |
| 794 | continue; |
| 795 | |
| 796 | if (ddata->offsets[i] > (ddata->module_size - 4)) { |
| 797 | dev_err(ddata->dev, "register outside module range"); |
| 798 | |
| 799 | return -EINVAL; |
| 800 | } |
| 801 | |
| 802 | for (j = 0; j < SYSC_MAX_REGS; j++) { |
| 803 | if (ddata->offsets[j] < 0) |
| 804 | continue; |
| 805 | |
| 806 | if (ddata->offsets[i] == ddata->offsets[j]) |
| 807 | nr_matches++; |
| 808 | } |
| 809 | nr_regs++; |
| 810 | } |
| 811 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 812 | if (nr_matches > nr_regs) { |
| 813 | dev_err(ddata->dev, "overlapping registers: (%i/%i)", |
| 814 | nr_regs, nr_matches); |
| 815 | |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | /** |
| 823 | * syc_ioremap - ioremap register space for the interconnect target module |
| 824 | * @ddata: device driver data |
| 825 | * |
| 826 | * Note that the interconnect target module registers can be anywhere |
| 827 | * within the interconnect target module range. For example, SGX has |
| 828 | * them at offset 0x1fc00 in the 32MB module address space. And cpsw |
| 829 | * has them at offset 0x1200 in the CPSW_WR child. Usually the |
| 830 | * the interconnect target module registers are at the beginning of |
| 831 | * the module range though. |
| 832 | */ |
| 833 | static int sysc_ioremap(struct sysc *ddata) |
| 834 | { |
| 835 | int size; |
| 836 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 837 | if (ddata->offsets[SYSC_REVISION] < 0 && |
| 838 | ddata->offsets[SYSC_SYSCONFIG] < 0 && |
| 839 | ddata->offsets[SYSC_SYSSTATUS] < 0) { |
| 840 | size = ddata->module_size; |
| 841 | } else { |
| 842 | size = max3(ddata->offsets[SYSC_REVISION], |
| 843 | ddata->offsets[SYSC_SYSCONFIG], |
| 844 | ddata->offsets[SYSC_SYSSTATUS]); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 845 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 846 | if (size < SZ_1K) |
| 847 | size = SZ_1K; |
| 848 | |
| 849 | if ((size + sizeof(u32)) > ddata->module_size) |
| 850 | size = ddata->module_size; |
| 851 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 852 | |
| 853 | ddata->module_va = devm_ioremap(ddata->dev, |
| 854 | ddata->module_pa, |
| 855 | size + sizeof(u32)); |
| 856 | if (!ddata->module_va) |
| 857 | return -EIO; |
| 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * sysc_map_and_check_registers - ioremap and check device registers |
| 864 | * @ddata: device driver data |
| 865 | */ |
| 866 | static int sysc_map_and_check_registers(struct sysc *ddata) |
| 867 | { |
| 868 | int error; |
| 869 | |
| 870 | error = sysc_parse_and_check_child_range(ddata); |
| 871 | if (error) |
| 872 | return error; |
| 873 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 874 | error = sysc_defer_non_critical(ddata); |
| 875 | if (error) |
| 876 | return error; |
| 877 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 878 | sysc_check_children(ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 879 | |
| 880 | error = sysc_parse_registers(ddata); |
| 881 | if (error) |
| 882 | return error; |
| 883 | |
| 884 | error = sysc_ioremap(ddata); |
| 885 | if (error) |
| 886 | return error; |
| 887 | |
| 888 | error = sysc_check_registers(ddata); |
| 889 | if (error) |
| 890 | return error; |
| 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | /** |
| 896 | * sysc_show_rev - read and show interconnect target module revision |
| 897 | * @bufp: buffer to print the information to |
| 898 | * @ddata: device driver data |
| 899 | */ |
| 900 | static int sysc_show_rev(char *bufp, struct sysc *ddata) |
| 901 | { |
| 902 | int len; |
| 903 | |
| 904 | if (ddata->offsets[SYSC_REVISION] < 0) |
| 905 | return sprintf(bufp, ":NA"); |
| 906 | |
| 907 | len = sprintf(bufp, ":%08x", ddata->revision); |
| 908 | |
| 909 | return len; |
| 910 | } |
| 911 | |
| 912 | static int sysc_show_reg(struct sysc *ddata, |
| 913 | char *bufp, enum sysc_registers reg) |
| 914 | { |
| 915 | if (ddata->offsets[reg] < 0) |
| 916 | return sprintf(bufp, ":NA"); |
| 917 | |
| 918 | return sprintf(bufp, ":%x", ddata->offsets[reg]); |
| 919 | } |
| 920 | |
| 921 | static int sysc_show_name(char *bufp, struct sysc *ddata) |
| 922 | { |
| 923 | if (!ddata->name) |
| 924 | return 0; |
| 925 | |
| 926 | return sprintf(bufp, ":%s", ddata->name); |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * sysc_show_registers - show information about interconnect target module |
| 931 | * @ddata: device driver data |
| 932 | */ |
| 933 | static void sysc_show_registers(struct sysc *ddata) |
| 934 | { |
| 935 | char buf[128]; |
| 936 | char *bufp = buf; |
| 937 | int i; |
| 938 | |
| 939 | for (i = 0; i < SYSC_MAX_REGS; i++) |
| 940 | bufp += sysc_show_reg(ddata, bufp, i); |
| 941 | |
| 942 | bufp += sysc_show_rev(bufp, ddata); |
| 943 | bufp += sysc_show_name(bufp, ddata); |
| 944 | |
| 945 | dev_dbg(ddata->dev, "%llx:%x%s\n", |
| 946 | ddata->module_pa, ddata->module_size, |
| 947 | buf); |
| 948 | } |
| 949 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 950 | /** |
| 951 | * sysc_write_sysconfig - handle sysconfig quirks for register write |
| 952 | * @ddata: device driver data |
| 953 | * @value: register value |
| 954 | */ |
| 955 | static void sysc_write_sysconfig(struct sysc *ddata, u32 value) |
| 956 | { |
| 957 | if (ddata->module_unlock_quirk) |
| 958 | ddata->module_unlock_quirk(ddata); |
| 959 | |
| 960 | sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value); |
| 961 | |
| 962 | if (ddata->module_lock_quirk) |
| 963 | ddata->module_lock_quirk(ddata); |
| 964 | } |
| 965 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 966 | #define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1) |
| 967 | #define SYSC_CLOCACT_ICK 2 |
| 968 | |
| 969 | /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */ |
| 970 | static int sysc_enable_module(struct device *dev) |
| 971 | { |
| 972 | struct sysc *ddata; |
| 973 | const struct sysc_regbits *regbits; |
| 974 | u32 reg, idlemodes, best_mode; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 975 | int error; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 976 | |
| 977 | ddata = dev_get_drvdata(dev); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 978 | |
| 979 | /* |
| 980 | * Some modules like DSS reset automatically on idle. Enable optional |
| 981 | * reset clocks and wait for OCP softreset to complete. |
| 982 | */ |
| 983 | if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) { |
| 984 | error = sysc_enable_opt_clocks(ddata); |
| 985 | if (error) { |
| 986 | dev_err(ddata->dev, |
| 987 | "Optional clocks failed for enable: %i\n", |
| 988 | error); |
| 989 | return error; |
| 990 | } |
| 991 | } |
| 992 | error = sysc_wait_softreset(ddata); |
| 993 | if (error) |
| 994 | dev_warn(ddata->dev, "OCP softreset timed out\n"); |
| 995 | if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) |
| 996 | sysc_disable_opt_clocks(ddata); |
| 997 | |
| 998 | /* |
| 999 | * Some subsystem private interconnects, like DSS top level module, |
| 1000 | * need only the automatic OCP softreset handling with no sysconfig |
| 1001 | * register bits to configure. |
| 1002 | */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1003 | if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV) |
| 1004 | return 0; |
| 1005 | |
| 1006 | regbits = ddata->cap->regbits; |
| 1007 | reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); |
| 1008 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1009 | /* |
| 1010 | * Set CLOCKACTIVITY, we only use it for ick. And we only configure it |
| 1011 | * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware |
| 1012 | * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag. |
| 1013 | */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1014 | if (regbits->clkact_shift >= 0 && |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1015 | (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT)) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1016 | reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift; |
| 1017 | |
| 1018 | /* Set SIDLE mode */ |
| 1019 | idlemodes = ddata->cfg.sidlemodes; |
| 1020 | if (!idlemodes || regbits->sidle_shift < 0) |
| 1021 | goto set_midle; |
| 1022 | |
| 1023 | if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE | |
| 1024 | SYSC_QUIRK_SWSUP_SIDLE_ACT)) { |
| 1025 | best_mode = SYSC_IDLE_NO; |
| 1026 | } else { |
| 1027 | best_mode = fls(ddata->cfg.sidlemodes) - 1; |
| 1028 | if (best_mode > SYSC_IDLE_MASK) { |
| 1029 | dev_err(dev, "%s: invalid sidlemode\n", __func__); |
| 1030 | return -EINVAL; |
| 1031 | } |
| 1032 | |
| 1033 | /* Set WAKEUP */ |
| 1034 | if (regbits->enwkup_shift >= 0 && |
| 1035 | ddata->cfg.sysc_val & BIT(regbits->enwkup_shift)) |
| 1036 | reg |= BIT(regbits->enwkup_shift); |
| 1037 | } |
| 1038 | |
| 1039 | reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift); |
| 1040 | reg |= best_mode << regbits->sidle_shift; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1041 | sysc_write_sysconfig(ddata, reg); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1042 | |
| 1043 | set_midle: |
| 1044 | /* Set MIDLE mode */ |
| 1045 | idlemodes = ddata->cfg.midlemodes; |
| 1046 | if (!idlemodes || regbits->midle_shift < 0) |
| 1047 | goto set_autoidle; |
| 1048 | |
| 1049 | best_mode = fls(ddata->cfg.midlemodes) - 1; |
| 1050 | if (best_mode > SYSC_IDLE_MASK) { |
| 1051 | dev_err(dev, "%s: invalid midlemode\n", __func__); |
| 1052 | return -EINVAL; |
| 1053 | } |
| 1054 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1055 | if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY) |
| 1056 | best_mode = SYSC_IDLE_NO; |
| 1057 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1058 | reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift); |
| 1059 | reg |= best_mode << regbits->midle_shift; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1060 | sysc_write_sysconfig(ddata, reg); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1061 | |
| 1062 | set_autoidle: |
| 1063 | /* Autoidle bit must enabled separately if available */ |
| 1064 | if (regbits->autoidle_shift >= 0 && |
| 1065 | ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) { |
| 1066 | reg |= 1 << regbits->autoidle_shift; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1067 | sysc_write_sysconfig(ddata, reg); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1070 | /* Flush posted write */ |
| 1071 | sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); |
| 1072 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1073 | if (ddata->module_enable_quirk) |
| 1074 | ddata->module_enable_quirk(ddata); |
| 1075 | |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
| 1079 | static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode) |
| 1080 | { |
| 1081 | if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP)) |
| 1082 | *best_mode = SYSC_IDLE_SMART_WKUP; |
| 1083 | else if (idlemodes & BIT(SYSC_IDLE_SMART)) |
| 1084 | *best_mode = SYSC_IDLE_SMART; |
| 1085 | else if (idlemodes & BIT(SYSC_IDLE_FORCE)) |
| 1086 | *best_mode = SYSC_IDLE_FORCE; |
| 1087 | else |
| 1088 | return -EINVAL; |
| 1089 | |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | /* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */ |
| 1094 | static int sysc_disable_module(struct device *dev) |
| 1095 | { |
| 1096 | struct sysc *ddata; |
| 1097 | const struct sysc_regbits *regbits; |
| 1098 | u32 reg, idlemodes, best_mode; |
| 1099 | int ret; |
| 1100 | |
| 1101 | ddata = dev_get_drvdata(dev); |
| 1102 | if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV) |
| 1103 | return 0; |
| 1104 | |
| 1105 | if (ddata->module_disable_quirk) |
| 1106 | ddata->module_disable_quirk(ddata); |
| 1107 | |
| 1108 | regbits = ddata->cap->regbits; |
| 1109 | reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); |
| 1110 | |
| 1111 | /* Set MIDLE mode */ |
| 1112 | idlemodes = ddata->cfg.midlemodes; |
| 1113 | if (!idlemodes || regbits->midle_shift < 0) |
| 1114 | goto set_sidle; |
| 1115 | |
| 1116 | ret = sysc_best_idle_mode(idlemodes, &best_mode); |
| 1117 | if (ret) { |
| 1118 | dev_err(dev, "%s: invalid midlemode\n", __func__); |
| 1119 | return ret; |
| 1120 | } |
| 1121 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1122 | if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) || |
| 1123 | ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY)) |
| 1124 | best_mode = SYSC_IDLE_FORCE; |
| 1125 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1126 | reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift); |
| 1127 | reg |= best_mode << regbits->midle_shift; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1128 | sysc_write_sysconfig(ddata, reg); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1129 | |
| 1130 | set_sidle: |
| 1131 | /* Set SIDLE mode */ |
| 1132 | idlemodes = ddata->cfg.sidlemodes; |
| 1133 | if (!idlemodes || regbits->sidle_shift < 0) |
| 1134 | return 0; |
| 1135 | |
| 1136 | if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) { |
| 1137 | best_mode = SYSC_IDLE_FORCE; |
| 1138 | } else { |
| 1139 | ret = sysc_best_idle_mode(idlemodes, &best_mode); |
| 1140 | if (ret) { |
| 1141 | dev_err(dev, "%s: invalid sidlemode\n", __func__); |
| 1142 | return ret; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift); |
| 1147 | reg |= best_mode << regbits->sidle_shift; |
| 1148 | if (regbits->autoidle_shift >= 0 && |
| 1149 | ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) |
| 1150 | reg |= 1 << regbits->autoidle_shift; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1151 | sysc_write_sysconfig(ddata, reg); |
| 1152 | |
| 1153 | /* Flush posted write */ |
| 1154 | sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev, |
| 1160 | struct sysc *ddata) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1161 | { |
| 1162 | struct ti_sysc_platform_data *pdata; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1163 | int error; |
| 1164 | |
| 1165 | pdata = dev_get_platdata(ddata->dev); |
| 1166 | if (!pdata) |
| 1167 | return 0; |
| 1168 | |
| 1169 | if (!pdata->idle_module) |
| 1170 | return -ENODEV; |
| 1171 | |
| 1172 | error = pdata->idle_module(dev, &ddata->cookie); |
| 1173 | if (error) |
| 1174 | dev_err(dev, "%s: could not idle: %i\n", |
| 1175 | __func__, error); |
| 1176 | |
| 1177 | reset_control_assert(ddata->rsts); |
| 1178 | |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev, |
| 1183 | struct sysc *ddata) |
| 1184 | { |
| 1185 | struct ti_sysc_platform_data *pdata; |
| 1186 | int error; |
| 1187 | |
| 1188 | reset_control_deassert(ddata->rsts); |
| 1189 | |
| 1190 | pdata = dev_get_platdata(ddata->dev); |
| 1191 | if (!pdata) |
| 1192 | return 0; |
| 1193 | |
| 1194 | if (!pdata->enable_module) |
| 1195 | return -ENODEV; |
| 1196 | |
| 1197 | error = pdata->enable_module(dev, &ddata->cookie); |
| 1198 | if (error) |
| 1199 | dev_err(dev, "%s: could not enable: %i\n", |
| 1200 | __func__, error); |
| 1201 | |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | static int __maybe_unused sysc_runtime_suspend(struct device *dev) |
| 1206 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1207 | struct sysc *ddata; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1208 | int error = 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1209 | |
| 1210 | ddata = dev_get_drvdata(dev); |
| 1211 | |
| 1212 | if (!ddata->enabled) |
| 1213 | return 0; |
| 1214 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1215 | sysc_clkdm_deny_idle(ddata); |
| 1216 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1217 | if (ddata->legacy_mode) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1218 | error = sysc_runtime_suspend_legacy(dev, ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1219 | if (error) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1220 | goto err_allow_idle; |
| 1221 | } else { |
| 1222 | error = sysc_disable_module(dev); |
| 1223 | if (error) |
| 1224 | goto err_allow_idle; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1227 | sysc_disable_main_clocks(ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1228 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1229 | if (sysc_opt_clks_needed(ddata)) |
| 1230 | sysc_disable_opt_clocks(ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1231 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1232 | ddata->enabled = false; |
| 1233 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1234 | err_allow_idle: |
| 1235 | reset_control_assert(ddata->rsts); |
| 1236 | |
| 1237 | sysc_clkdm_allow_idle(ddata); |
| 1238 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1239 | return error; |
| 1240 | } |
| 1241 | |
| 1242 | static int __maybe_unused sysc_runtime_resume(struct device *dev) |
| 1243 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1244 | struct sysc *ddata; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1245 | int error = 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1246 | |
| 1247 | ddata = dev_get_drvdata(dev); |
| 1248 | |
| 1249 | if (ddata->enabled) |
| 1250 | return 0; |
| 1251 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1252 | |
| 1253 | sysc_clkdm_deny_idle(ddata); |
| 1254 | |
| 1255 | reset_control_deassert(ddata->rsts); |
| 1256 | |
| 1257 | if (sysc_opt_clks_needed(ddata)) { |
| 1258 | error = sysc_enable_opt_clocks(ddata); |
| 1259 | if (error) |
| 1260 | goto err_allow_idle; |
| 1261 | } |
| 1262 | |
| 1263 | error = sysc_enable_main_clocks(ddata); |
| 1264 | if (error) |
| 1265 | goto err_opt_clocks; |
| 1266 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1267 | if (ddata->legacy_mode) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1268 | error = sysc_runtime_resume_legacy(dev, ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1269 | if (error) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1270 | goto err_main_clocks; |
| 1271 | } else { |
| 1272 | error = sysc_enable_module(dev); |
| 1273 | if (error) |
| 1274 | goto err_main_clocks; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1277 | ddata->enabled = true; |
| 1278 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1279 | sysc_clkdm_allow_idle(ddata); |
| 1280 | |
| 1281 | return 0; |
| 1282 | |
| 1283 | err_main_clocks: |
| 1284 | sysc_disable_main_clocks(ddata); |
| 1285 | err_opt_clocks: |
| 1286 | if (sysc_opt_clks_needed(ddata)) |
| 1287 | sysc_disable_opt_clocks(ddata); |
| 1288 | err_allow_idle: |
| 1289 | sysc_clkdm_allow_idle(ddata); |
| 1290 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1291 | return error; |
| 1292 | } |
| 1293 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1294 | static int __maybe_unused sysc_noirq_suspend(struct device *dev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1295 | { |
| 1296 | struct sysc *ddata; |
| 1297 | |
| 1298 | ddata = dev_get_drvdata(dev); |
| 1299 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1300 | if (ddata->cfg.quirks & |
| 1301 | (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1302 | return 0; |
| 1303 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1304 | return pm_runtime_force_suspend(dev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1307 | static int __maybe_unused sysc_noirq_resume(struct device *dev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1308 | { |
| 1309 | struct sysc *ddata; |
| 1310 | |
| 1311 | ddata = dev_get_drvdata(dev); |
| 1312 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1313 | if (ddata->cfg.quirks & |
| 1314 | (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1315 | return 0; |
| 1316 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1317 | return pm_runtime_force_resume(dev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1318 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1319 | |
| 1320 | static const struct dev_pm_ops sysc_pm_ops = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1321 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume) |
| 1322 | SET_RUNTIME_PM_OPS(sysc_runtime_suspend, |
| 1323 | sysc_runtime_resume, |
| 1324 | NULL) |
| 1325 | }; |
| 1326 | |
| 1327 | /* Module revision register based quirks */ |
| 1328 | struct sysc_revision_quirk { |
| 1329 | const char *name; |
| 1330 | u32 base; |
| 1331 | int rev_offset; |
| 1332 | int sysc_offset; |
| 1333 | int syss_offset; |
| 1334 | u32 revision; |
| 1335 | u32 revision_mask; |
| 1336 | u32 quirks; |
| 1337 | }; |
| 1338 | |
| 1339 | #define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \ |
| 1340 | optrev_val, optrevmask, optquirkmask) \ |
| 1341 | { \ |
| 1342 | .name = (optname), \ |
| 1343 | .base = (optbase), \ |
| 1344 | .rev_offset = (optrev), \ |
| 1345 | .sysc_offset = (optsysc), \ |
| 1346 | .syss_offset = (optsyss), \ |
| 1347 | .revision = (optrev_val), \ |
| 1348 | .revision_mask = (optrevmask), \ |
| 1349 | .quirks = (optquirkmask), \ |
| 1350 | } |
| 1351 | |
| 1352 | static const struct sysc_revision_quirk sysc_revision_quirks[] = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1353 | /* These drivers need to be fixed to not use pm_runtime_irq_safe() */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1354 | SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1355 | SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET), |
| 1356 | SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000020, 0xffffffff, |
| 1357 | SYSC_QUIRK_LEGACY_IDLE), |
| 1358 | SYSC_QUIRK("mmu", 0, 0, 0x10, 0x14, 0x00000030, 0xffffffff, |
| 1359 | SYSC_QUIRK_LEGACY_IDLE), |
| 1360 | SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff, |
| 1361 | SYSC_QUIRK_LEGACY_IDLE), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1362 | SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1363 | SYSC_QUIRK_LEGACY_IDLE), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1364 | SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1365 | SYSC_QUIRK_LEGACY_IDLE), |
| 1366 | SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1367 | 0), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1368 | /* Some timers on omap4 and later */ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1369 | SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1370 | 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1371 | SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1372 | 0), |
| 1373 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff, |
| 1374 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1375 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1376 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1377 | /* Uarts on omap4 and later */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1378 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff, |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1379 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1380 | SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff, |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1381 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1382 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1383 | /* Quirks that need to be set based on the module address */ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1384 | SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1385 | SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT | |
| 1386 | SYSC_QUIRK_SWSUP_SIDLE), |
| 1387 | |
| 1388 | /* Quirks that need to be set based on detected module */ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1389 | SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff, |
| 1390 | SYSC_MODULE_QUIRK_AESS), |
| 1391 | SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, |
| 1392 | SYSC_QUIRK_CLKDM_NOAUTO), |
| 1393 | SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, |
| 1394 | SYSC_QUIRK_OPT_CLKS_IN_RESET), |
| 1395 | SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff, |
| 1396 | SYSC_QUIRK_OPT_CLKS_IN_RESET), |
| 1397 | SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff, |
| 1398 | SYSC_QUIRK_OPT_CLKS_IN_RESET), |
| 1399 | SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, |
| 1400 | SYSC_QUIRK_CLKDM_NOAUTO), |
| 1401 | SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, |
| 1402 | SYSC_QUIRK_CLKDM_NOAUTO), |
| 1403 | SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff, |
| 1404 | SYSC_QUIRK_OPT_CLKS_NEEDED), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1405 | SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff, |
| 1406 | SYSC_MODULE_QUIRK_HDQ1W), |
| 1407 | SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff, |
| 1408 | SYSC_MODULE_QUIRK_HDQ1W), |
| 1409 | SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff, |
| 1410 | SYSC_MODULE_QUIRK_I2C), |
| 1411 | SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff, |
| 1412 | SYSC_MODULE_QUIRK_I2C), |
| 1413 | SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff, |
| 1414 | SYSC_MODULE_QUIRK_I2C), |
| 1415 | SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0, |
| 1416 | SYSC_MODULE_QUIRK_I2C), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1417 | SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0), |
| 1418 | SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1419 | SYSC_MODULE_QUIRK_SGX), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1420 | SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0, |
| 1421 | SYSC_MODULE_QUIRK_RTC_UNLOCK), |
| 1422 | SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff, |
| 1423 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY), |
| 1424 | SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff, |
| 1425 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY), |
| 1426 | SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff, |
| 1427 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY), |
| 1428 | SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff, |
| 1429 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY), |
| 1430 | SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050, |
| 1431 | 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY), |
| 1432 | SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff, |
| 1433 | SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1434 | SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0, |
| 1435 | SYSC_MODULE_QUIRK_WDT), |
| 1436 | /* Watchdog on am3 and am4 */ |
| 1437 | SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0, |
| 1438 | SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1439 | |
| 1440 | #ifdef DEBUG |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1441 | SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0), |
| 1442 | SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0), |
| 1443 | SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0), |
| 1444 | SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1445 | SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902, |
| 1446 | 0xffff00f0, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1447 | SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0), |
| 1448 | SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0), |
| 1449 | SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0), |
| 1450 | SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0), |
| 1451 | SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0), |
| 1452 | SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0), |
| 1453 | SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0), |
| 1454 | SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0), |
| 1455 | SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0), |
| 1456 | SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0), |
| 1457 | SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1458 | SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0), |
| 1459 | SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1460 | SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0), |
| 1461 | SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0), |
| 1462 | SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0), |
| 1463 | SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1464 | SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1465 | SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0), |
| 1466 | SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff, 0), |
| 1467 | SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff, 0), |
| 1468 | SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0), |
| 1469 | SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0), |
| 1470 | SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1471 | SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1472 | SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0), |
| 1473 | SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1474 | SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1475 | SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0), |
| 1476 | SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0), |
| 1477 | SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0), |
| 1478 | SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0), |
| 1479 | SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0), |
| 1480 | SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0), |
| 1481 | SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0), |
| 1482 | SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0), |
| 1483 | SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0), |
| 1484 | SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0), |
| 1485 | SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0), |
| 1486 | SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0), |
| 1487 | SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0), |
| 1488 | SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1489 | SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0), |
| 1490 | SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1491 | SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0), |
| 1492 | SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0), |
| 1493 | SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0), |
| 1494 | SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0), |
| 1495 | SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0), |
| 1496 | SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1497 | SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1498 | SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1499 | SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0), |
| 1500 | SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1501 | #endif |
| 1502 | }; |
| 1503 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1504 | /* |
| 1505 | * Early quirks based on module base and register offsets only that are |
| 1506 | * needed before the module revision can be read |
| 1507 | */ |
| 1508 | static void sysc_init_early_quirks(struct sysc *ddata) |
| 1509 | { |
| 1510 | const struct sysc_revision_quirk *q; |
| 1511 | int i; |
| 1512 | |
| 1513 | for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) { |
| 1514 | q = &sysc_revision_quirks[i]; |
| 1515 | |
| 1516 | if (!q->base) |
| 1517 | continue; |
| 1518 | |
| 1519 | if (q->base != ddata->module_pa) |
| 1520 | continue; |
| 1521 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1522 | if (q->rev_offset != ddata->offsets[SYSC_REVISION]) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1523 | continue; |
| 1524 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1525 | if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG]) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1526 | continue; |
| 1527 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1528 | if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS]) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1529 | continue; |
| 1530 | |
| 1531 | ddata->name = q->name; |
| 1532 | ddata->cfg.quirks |= q->quirks; |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | /* Quirks that also consider the revision register value */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1537 | static void sysc_init_revision_quirks(struct sysc *ddata) |
| 1538 | { |
| 1539 | const struct sysc_revision_quirk *q; |
| 1540 | int i; |
| 1541 | |
| 1542 | for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) { |
| 1543 | q = &sysc_revision_quirks[i]; |
| 1544 | |
| 1545 | if (q->base && q->base != ddata->module_pa) |
| 1546 | continue; |
| 1547 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1548 | if (q->rev_offset != ddata->offsets[SYSC_REVISION]) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1549 | continue; |
| 1550 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1551 | if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG]) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1552 | continue; |
| 1553 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1554 | if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS]) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1555 | continue; |
| 1556 | |
| 1557 | if (q->revision == ddata->revision || |
| 1558 | (q->revision & q->revision_mask) == |
| 1559 | (ddata->revision & q->revision_mask)) { |
| 1560 | ddata->name = q->name; |
| 1561 | ddata->cfg.quirks |= q->quirks; |
| 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1566 | /* 1-wire needs module's internal clocks enabled for reset */ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1567 | static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1568 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1569 | int offset = 0x0c; /* HDQ_CTRL_STATUS */ |
| 1570 | u16 val; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1571 | |
| 1572 | val = sysc_read(ddata, offset); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1573 | val |= BIT(5); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1574 | sysc_write(ddata, offset, val); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1577 | /* AESS (Audio Engine SubSystem) needs autogating set after enable */ |
| 1578 | static void sysc_module_enable_quirk_aess(struct sysc *ddata) |
| 1579 | { |
| 1580 | int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */ |
| 1581 | |
| 1582 | sysc_write(ddata, offset, 1); |
| 1583 | } |
| 1584 | |
| 1585 | /* I2C needs to be disabled for reset */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1586 | static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable) |
| 1587 | { |
| 1588 | int offset; |
| 1589 | u16 val; |
| 1590 | |
| 1591 | /* I2C_CON, omap2/3 is different from omap4 and later */ |
| 1592 | if ((ddata->revision & 0xffffff00) == 0x001f0000) |
| 1593 | offset = 0x24; |
| 1594 | else |
| 1595 | offset = 0xa4; |
| 1596 | |
| 1597 | /* I2C_EN */ |
| 1598 | val = sysc_read(ddata, offset); |
| 1599 | if (enable) |
| 1600 | val |= BIT(15); |
| 1601 | else |
| 1602 | val &= ~BIT(15); |
| 1603 | sysc_write(ddata, offset, val); |
| 1604 | } |
| 1605 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1606 | static void sysc_pre_reset_quirk_i2c(struct sysc *ddata) |
| 1607 | { |
| 1608 | sysc_clk_quirk_i2c(ddata, false); |
| 1609 | } |
| 1610 | |
| 1611 | static void sysc_post_reset_quirk_i2c(struct sysc *ddata) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1612 | { |
| 1613 | sysc_clk_quirk_i2c(ddata, true); |
| 1614 | } |
| 1615 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1616 | /* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */ |
| 1617 | static void sysc_quirk_rtc(struct sysc *ddata, bool lock) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1618 | { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1619 | u32 val, kick0_val = 0, kick1_val = 0; |
| 1620 | unsigned long flags; |
| 1621 | int error; |
| 1622 | |
| 1623 | if (!lock) { |
| 1624 | kick0_val = 0x83e70b13; |
| 1625 | kick1_val = 0x95a4f1e0; |
| 1626 | } |
| 1627 | |
| 1628 | local_irq_save(flags); |
| 1629 | /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */ |
| 1630 | error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val, |
| 1631 | !(val & BIT(0)), 100, 50); |
| 1632 | if (error) |
| 1633 | dev_warn(ddata->dev, "rtc busy timeout\n"); |
| 1634 | /* Now we have ~15 microseconds to read/write various registers */ |
| 1635 | sysc_write(ddata, 0x6c, kick0_val); |
| 1636 | sysc_write(ddata, 0x70, kick1_val); |
| 1637 | local_irq_restore(flags); |
| 1638 | } |
| 1639 | |
| 1640 | static void sysc_module_unlock_quirk_rtc(struct sysc *ddata) |
| 1641 | { |
| 1642 | sysc_quirk_rtc(ddata, false); |
| 1643 | } |
| 1644 | |
| 1645 | static void sysc_module_lock_quirk_rtc(struct sysc *ddata) |
| 1646 | { |
| 1647 | sysc_quirk_rtc(ddata, true); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */ |
| 1651 | static void sysc_module_enable_quirk_sgx(struct sysc *ddata) |
| 1652 | { |
| 1653 | int offset = 0xff08; /* OCP_DEBUG_CONFIG */ |
| 1654 | u32 val = BIT(31); /* THALIA_INT_BYPASS */ |
| 1655 | |
| 1656 | sysc_write(ddata, offset, val); |
| 1657 | } |
| 1658 | |
| 1659 | /* Watchdog timer needs a disable sequence after reset */ |
| 1660 | static void sysc_reset_done_quirk_wdt(struct sysc *ddata) |
| 1661 | { |
| 1662 | int wps, spr, error; |
| 1663 | u32 val; |
| 1664 | |
| 1665 | wps = 0x34; |
| 1666 | spr = 0x48; |
| 1667 | |
| 1668 | sysc_write(ddata, spr, 0xaaaa); |
| 1669 | error = readl_poll_timeout(ddata->module_va + wps, val, |
| 1670 | !(val & 0x10), 100, |
| 1671 | MAX_MODULE_SOFTRESET_WAIT); |
| 1672 | if (error) |
| 1673 | dev_warn(ddata->dev, "wdt disable step1 failed\n"); |
| 1674 | |
| 1675 | sysc_write(ddata, spr, 0x5555); |
| 1676 | error = readl_poll_timeout(ddata->module_va + wps, val, |
| 1677 | !(val & 0x10), 100, |
| 1678 | MAX_MODULE_SOFTRESET_WAIT); |
| 1679 | if (error) |
| 1680 | dev_warn(ddata->dev, "wdt disable step2 failed\n"); |
| 1681 | } |
| 1682 | |
| 1683 | static void sysc_init_module_quirks(struct sysc *ddata) |
| 1684 | { |
| 1685 | if (ddata->legacy_mode || !ddata->name) |
| 1686 | return; |
| 1687 | |
| 1688 | if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1689 | ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1690 | |
| 1691 | return; |
| 1692 | } |
| 1693 | |
| 1694 | if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1695 | ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c; |
| 1696 | ddata->post_reset_quirk = sysc_post_reset_quirk_i2c; |
| 1697 | |
| 1698 | return; |
| 1699 | } |
| 1700 | |
| 1701 | if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS) |
| 1702 | ddata->module_enable_quirk = sysc_module_enable_quirk_aess; |
| 1703 | |
| 1704 | if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) { |
| 1705 | ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc; |
| 1706 | ddata->module_lock_quirk = sysc_module_lock_quirk_rtc; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1707 | |
| 1708 | return; |
| 1709 | } |
| 1710 | |
| 1711 | if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX) |
| 1712 | ddata->module_enable_quirk = sysc_module_enable_quirk_sgx; |
| 1713 | |
| 1714 | if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) { |
| 1715 | ddata->reset_done_quirk = sysc_reset_done_quirk_wdt; |
| 1716 | ddata->module_disable_quirk = sysc_reset_done_quirk_wdt; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | static int sysc_clockdomain_init(struct sysc *ddata) |
| 1721 | { |
| 1722 | struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); |
| 1723 | struct clk *fck = NULL, *ick = NULL; |
| 1724 | int error; |
| 1725 | |
| 1726 | if (!pdata || !pdata->init_clockdomain) |
| 1727 | return 0; |
| 1728 | |
| 1729 | switch (ddata->nr_clocks) { |
| 1730 | case 2: |
| 1731 | ick = ddata->clocks[SYSC_ICK]; |
| 1732 | /* fallthrough */ |
| 1733 | case 1: |
| 1734 | fck = ddata->clocks[SYSC_FCK]; |
| 1735 | break; |
| 1736 | case 0: |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
| 1740 | error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie); |
| 1741 | if (!error || error == -ENODEV) |
| 1742 | return 0; |
| 1743 | |
| 1744 | return error; |
| 1745 | } |
| 1746 | |
| 1747 | /* |
| 1748 | * Note that pdata->init_module() typically does a reset first. After |
| 1749 | * pdata->init_module() is done, PM runtime can be used for the interconnect |
| 1750 | * target module. |
| 1751 | */ |
| 1752 | static int sysc_legacy_init(struct sysc *ddata) |
| 1753 | { |
| 1754 | struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); |
| 1755 | int error; |
| 1756 | |
| 1757 | if (!pdata || !pdata->init_module) |
| 1758 | return 0; |
| 1759 | |
| 1760 | error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie); |
| 1761 | if (error == -EEXIST) |
| 1762 | error = 0; |
| 1763 | |
| 1764 | return error; |
| 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * sysc_rstctrl_reset_deassert - deassert rstctrl reset |
| 1769 | * @ddata: device driver data |
| 1770 | * @reset: reset before deassert |
| 1771 | * |
| 1772 | * A module can have both OCP softreset control and external rstctrl. |
| 1773 | * If more complicated rstctrl resets are needed, please handle these |
| 1774 | * directly from the child device driver and map only the module reset |
| 1775 | * for the parent interconnect target module device. |
| 1776 | * |
| 1777 | * Automatic reset of the module on init can be skipped with the |
| 1778 | * "ti,no-reset-on-init" device tree property. |
| 1779 | */ |
| 1780 | static int sysc_rstctrl_reset_deassert(struct sysc *ddata, bool reset) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1781 | { |
| 1782 | int error; |
| 1783 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1784 | if (!ddata->rsts) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1785 | return 0; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1786 | |
| 1787 | if (reset) { |
| 1788 | error = reset_control_assert(ddata->rsts); |
| 1789 | if (error) |
| 1790 | return error; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1793 | reset_control_deassert(ddata->rsts); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1794 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | /* |
| 1799 | * Note that the caller must ensure the interconnect target module is enabled |
| 1800 | * before calling reset. Otherwise reset will not complete. |
| 1801 | */ |
| 1802 | static int sysc_reset(struct sysc *ddata) |
| 1803 | { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1804 | int sysc_offset, sysc_val, error; |
| 1805 | u32 sysc_mask; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1806 | |
| 1807 | sysc_offset = ddata->offsets[SYSC_SYSCONFIG]; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1808 | |
| 1809 | if (ddata->legacy_mode || sysc_offset < 0 || |
| 1810 | ddata->cap->regbits->srst_shift < 0 || |
| 1811 | ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) |
| 1812 | return 0; |
| 1813 | |
| 1814 | sysc_mask = BIT(ddata->cap->regbits->srst_shift); |
| 1815 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1816 | if (ddata->pre_reset_quirk) |
| 1817 | ddata->pre_reset_quirk(ddata); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1818 | |
| 1819 | sysc_val = sysc_read_sysconfig(ddata); |
| 1820 | sysc_val |= sysc_mask; |
| 1821 | sysc_write(ddata, sysc_offset, sysc_val); |
| 1822 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1823 | if (ddata->cfg.srst_udelay) |
| 1824 | usleep_range(ddata->cfg.srst_udelay, |
| 1825 | ddata->cfg.srst_udelay * 2); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1826 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1827 | if (ddata->post_reset_quirk) |
| 1828 | ddata->post_reset_quirk(ddata); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1829 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 1830 | error = sysc_wait_softreset(ddata); |
| 1831 | if (error) |
| 1832 | dev_warn(ddata->dev, "OCP softreset timed out\n"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1833 | |
| 1834 | if (ddata->reset_done_quirk) |
| 1835 | ddata->reset_done_quirk(ddata); |
| 1836 | |
| 1837 | return error; |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * At this point the module is configured enough to read the revision but |
| 1842 | * module may not be completely configured yet to use PM runtime. Enable |
| 1843 | * all clocks directly during init to configure the quirks needed for PM |
| 1844 | * runtime based on the revision register. |
| 1845 | */ |
| 1846 | static int sysc_init_module(struct sysc *ddata) |
| 1847 | { |
| 1848 | int error = 0; |
| 1849 | bool manage_clocks = true; |
| 1850 | |
| 1851 | error = sysc_rstctrl_reset_deassert(ddata, false); |
| 1852 | if (error) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1853 | return error; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1854 | |
| 1855 | if (ddata->cfg.quirks & |
| 1856 | (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT)) |
| 1857 | manage_clocks = false; |
| 1858 | |
| 1859 | error = sysc_clockdomain_init(ddata); |
| 1860 | if (error) |
| 1861 | return error; |
| 1862 | |
| 1863 | sysc_clkdm_deny_idle(ddata); |
| 1864 | |
| 1865 | /* |
| 1866 | * Always enable clocks. The bootloader may or may not have enabled |
| 1867 | * the related clocks. |
| 1868 | */ |
| 1869 | error = sysc_enable_opt_clocks(ddata); |
| 1870 | if (error) |
| 1871 | return error; |
| 1872 | |
| 1873 | error = sysc_enable_main_clocks(ddata); |
| 1874 | if (error) |
| 1875 | goto err_opt_clocks; |
| 1876 | |
| 1877 | if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) { |
| 1878 | error = sysc_rstctrl_reset_deassert(ddata, true); |
| 1879 | if (error) |
| 1880 | goto err_main_clocks; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | ddata->revision = sysc_read_revision(ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1884 | sysc_init_revision_quirks(ddata); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1885 | sysc_init_module_quirks(ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1886 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1887 | if (ddata->legacy_mode) { |
| 1888 | error = sysc_legacy_init(ddata); |
| 1889 | if (error) |
| 1890 | goto err_main_clocks; |
| 1891 | } |
| 1892 | |
| 1893 | if (!ddata->legacy_mode) { |
| 1894 | error = sysc_enable_module(ddata->dev); |
| 1895 | if (error) |
| 1896 | goto err_main_clocks; |
| 1897 | } |
| 1898 | |
| 1899 | error = sysc_reset(ddata); |
| 1900 | if (error) |
| 1901 | dev_err(ddata->dev, "Reset failed with %d\n", error); |
| 1902 | |
| 1903 | if (!ddata->legacy_mode && manage_clocks) |
| 1904 | sysc_disable_module(ddata->dev); |
| 1905 | |
| 1906 | err_main_clocks: |
| 1907 | if (manage_clocks) |
| 1908 | sysc_disable_main_clocks(ddata); |
| 1909 | err_opt_clocks: |
| 1910 | /* No re-enable of clockdomain autoidle to prevent module autoidle */ |
| 1911 | if (manage_clocks) { |
| 1912 | sysc_disable_opt_clocks(ddata); |
| 1913 | sysc_clkdm_allow_idle(ddata); |
| 1914 | } |
| 1915 | |
| 1916 | return error; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | static int sysc_init_sysc_mask(struct sysc *ddata) |
| 1920 | { |
| 1921 | struct device_node *np = ddata->dev->of_node; |
| 1922 | int error; |
| 1923 | u32 val; |
| 1924 | |
| 1925 | error = of_property_read_u32(np, "ti,sysc-mask", &val); |
| 1926 | if (error) |
| 1927 | return 0; |
| 1928 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1929 | ddata->cfg.sysc_val = val & ddata->cap->sysc_mask; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1930 | |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes, |
| 1935 | const char *name) |
| 1936 | { |
| 1937 | struct device_node *np = ddata->dev->of_node; |
| 1938 | struct property *prop; |
| 1939 | const __be32 *p; |
| 1940 | u32 val; |
| 1941 | |
| 1942 | of_property_for_each_u32(np, name, prop, p, val) { |
| 1943 | if (val >= SYSC_NR_IDLEMODES) { |
| 1944 | dev_err(ddata->dev, "invalid idlemode: %i\n", val); |
| 1945 | return -EINVAL; |
| 1946 | } |
| 1947 | *idlemodes |= (1 << val); |
| 1948 | } |
| 1949 | |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
| 1953 | static int sysc_init_idlemodes(struct sysc *ddata) |
| 1954 | { |
| 1955 | int error; |
| 1956 | |
| 1957 | error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes, |
| 1958 | "ti,sysc-midle"); |
| 1959 | if (error) |
| 1960 | return error; |
| 1961 | |
| 1962 | error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes, |
| 1963 | "ti,sysc-sidle"); |
| 1964 | if (error) |
| 1965 | return error; |
| 1966 | |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | /* |
| 1971 | * Only some devices on omap4 and later have SYSCONFIG reset done |
| 1972 | * bit. We can detect this if there is no SYSSTATUS at all, or the |
| 1973 | * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers |
| 1974 | * have multiple bits for the child devices like OHCI and EHCI. |
| 1975 | * Depends on SYSC being parsed first. |
| 1976 | */ |
| 1977 | static int sysc_init_syss_mask(struct sysc *ddata) |
| 1978 | { |
| 1979 | struct device_node *np = ddata->dev->of_node; |
| 1980 | int error; |
| 1981 | u32 val; |
| 1982 | |
| 1983 | error = of_property_read_u32(np, "ti,syss-mask", &val); |
| 1984 | if (error) { |
| 1985 | if ((ddata->cap->type == TI_SYSC_OMAP4 || |
| 1986 | ddata->cap->type == TI_SYSC_OMAP4_TIMER) && |
| 1987 | (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET)) |
| 1988 | ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS; |
| 1989 | |
| 1990 | return 0; |
| 1991 | } |
| 1992 | |
| 1993 | if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET)) |
| 1994 | ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS; |
| 1995 | |
| 1996 | ddata->cfg.syss_mask = val; |
| 1997 | |
| 1998 | return 0; |
| 1999 | } |
| 2000 | |
| 2001 | /* |
| 2002 | * Many child device drivers need to have fck and opt clocks available |
| 2003 | * to get the clock rate for device internal configuration etc. |
| 2004 | */ |
| 2005 | static int sysc_child_add_named_clock(struct sysc *ddata, |
| 2006 | struct device *child, |
| 2007 | const char *name) |
| 2008 | { |
| 2009 | struct clk *clk; |
| 2010 | struct clk_lookup *l; |
| 2011 | int error = 0; |
| 2012 | |
| 2013 | if (!name) |
| 2014 | return 0; |
| 2015 | |
| 2016 | clk = clk_get(child, name); |
| 2017 | if (!IS_ERR(clk)) { |
| 2018 | clk_put(clk); |
| 2019 | |
| 2020 | return -EEXIST; |
| 2021 | } |
| 2022 | |
| 2023 | clk = clk_get(ddata->dev, name); |
| 2024 | if (IS_ERR(clk)) |
| 2025 | return -ENODEV; |
| 2026 | |
| 2027 | l = clkdev_create(clk, name, dev_name(child)); |
| 2028 | if (!l) |
| 2029 | error = -ENOMEM; |
| 2030 | |
| 2031 | clk_put(clk); |
| 2032 | |
| 2033 | return error; |
| 2034 | } |
| 2035 | |
| 2036 | static int sysc_child_add_clocks(struct sysc *ddata, |
| 2037 | struct device *child) |
| 2038 | { |
| 2039 | int i, error; |
| 2040 | |
| 2041 | for (i = 0; i < ddata->nr_clocks; i++) { |
| 2042 | error = sysc_child_add_named_clock(ddata, |
| 2043 | child, |
| 2044 | ddata->clock_roles[i]); |
| 2045 | if (error && error != -EEXIST) { |
| 2046 | dev_err(ddata->dev, "could not add child clock %s: %i\n", |
| 2047 | ddata->clock_roles[i], error); |
| 2048 | |
| 2049 | return error; |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
| 2056 | static struct device_type sysc_device_type = { |
| 2057 | }; |
| 2058 | |
| 2059 | static struct sysc *sysc_child_to_parent(struct device *dev) |
| 2060 | { |
| 2061 | struct device *parent = dev->parent; |
| 2062 | |
| 2063 | if (!parent || parent->type != &sysc_device_type) |
| 2064 | return NULL; |
| 2065 | |
| 2066 | return dev_get_drvdata(parent); |
| 2067 | } |
| 2068 | |
| 2069 | static int __maybe_unused sysc_child_runtime_suspend(struct device *dev) |
| 2070 | { |
| 2071 | struct sysc *ddata; |
| 2072 | int error; |
| 2073 | |
| 2074 | ddata = sysc_child_to_parent(dev); |
| 2075 | |
| 2076 | error = pm_generic_runtime_suspend(dev); |
| 2077 | if (error) |
| 2078 | return error; |
| 2079 | |
| 2080 | if (!ddata->enabled) |
| 2081 | return 0; |
| 2082 | |
| 2083 | return sysc_runtime_suspend(ddata->dev); |
| 2084 | } |
| 2085 | |
| 2086 | static int __maybe_unused sysc_child_runtime_resume(struct device *dev) |
| 2087 | { |
| 2088 | struct sysc *ddata; |
| 2089 | int error; |
| 2090 | |
| 2091 | ddata = sysc_child_to_parent(dev); |
| 2092 | |
| 2093 | if (!ddata->enabled) { |
| 2094 | error = sysc_runtime_resume(ddata->dev); |
| 2095 | if (error < 0) |
| 2096 | dev_err(ddata->dev, |
| 2097 | "%s error: %i\n", __func__, error); |
| 2098 | } |
| 2099 | |
| 2100 | return pm_generic_runtime_resume(dev); |
| 2101 | } |
| 2102 | |
| 2103 | #ifdef CONFIG_PM_SLEEP |
| 2104 | static int sysc_child_suspend_noirq(struct device *dev) |
| 2105 | { |
| 2106 | struct sysc *ddata; |
| 2107 | int error; |
| 2108 | |
| 2109 | ddata = sysc_child_to_parent(dev); |
| 2110 | |
| 2111 | dev_dbg(ddata->dev, "%s %s\n", __func__, |
| 2112 | ddata->name ? ddata->name : ""); |
| 2113 | |
| 2114 | error = pm_generic_suspend_noirq(dev); |
| 2115 | if (error) { |
| 2116 | dev_err(dev, "%s error at %i: %i\n", |
| 2117 | __func__, __LINE__, error); |
| 2118 | |
| 2119 | return error; |
| 2120 | } |
| 2121 | |
| 2122 | if (!pm_runtime_status_suspended(dev)) { |
| 2123 | error = pm_generic_runtime_suspend(dev); |
| 2124 | if (error) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2125 | dev_dbg(dev, "%s busy at %i: %i\n", |
| 2126 | __func__, __LINE__, error); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2127 | |
| 2128 | return 0; |
| 2129 | } |
| 2130 | |
| 2131 | error = sysc_runtime_suspend(ddata->dev); |
| 2132 | if (error) { |
| 2133 | dev_err(dev, "%s error at %i: %i\n", |
| 2134 | __func__, __LINE__, error); |
| 2135 | |
| 2136 | return error; |
| 2137 | } |
| 2138 | |
| 2139 | ddata->child_needs_resume = true; |
| 2140 | } |
| 2141 | |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | static int sysc_child_resume_noirq(struct device *dev) |
| 2146 | { |
| 2147 | struct sysc *ddata; |
| 2148 | int error; |
| 2149 | |
| 2150 | ddata = sysc_child_to_parent(dev); |
| 2151 | |
| 2152 | dev_dbg(ddata->dev, "%s %s\n", __func__, |
| 2153 | ddata->name ? ddata->name : ""); |
| 2154 | |
| 2155 | if (ddata->child_needs_resume) { |
| 2156 | ddata->child_needs_resume = false; |
| 2157 | |
| 2158 | error = sysc_runtime_resume(ddata->dev); |
| 2159 | if (error) |
| 2160 | dev_err(ddata->dev, |
| 2161 | "%s runtime resume error: %i\n", |
| 2162 | __func__, error); |
| 2163 | |
| 2164 | error = pm_generic_runtime_resume(dev); |
| 2165 | if (error) |
| 2166 | dev_err(ddata->dev, |
| 2167 | "%s generic runtime resume: %i\n", |
| 2168 | __func__, error); |
| 2169 | } |
| 2170 | |
| 2171 | return pm_generic_resume_noirq(dev); |
| 2172 | } |
| 2173 | #endif |
| 2174 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2175 | static struct dev_pm_domain sysc_child_pm_domain = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2176 | .ops = { |
| 2177 | SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend, |
| 2178 | sysc_child_runtime_resume, |
| 2179 | NULL) |
| 2180 | USE_PLATFORM_PM_SLEEP_OPS |
| 2181 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq, |
| 2182 | sysc_child_resume_noirq) |
| 2183 | } |
| 2184 | }; |
| 2185 | |
| 2186 | /** |
| 2187 | * sysc_legacy_idle_quirk - handle children in omap_device compatible way |
| 2188 | * @ddata: device driver data |
| 2189 | * @child: child device driver |
| 2190 | * |
| 2191 | * Allow idle for child devices as done with _od_runtime_suspend(). |
| 2192 | * Otherwise many child devices will not idle because of the permanent |
| 2193 | * parent usecount set in pm_runtime_irq_safe(). |
| 2194 | * |
| 2195 | * Note that the long term solution is to just modify the child device |
| 2196 | * drivers to not set pm_runtime_irq_safe() and then this can be just |
| 2197 | * dropped. |
| 2198 | */ |
| 2199 | static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child) |
| 2200 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2201 | if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE) |
| 2202 | dev_pm_domain_set(child, &sysc_child_pm_domain); |
| 2203 | } |
| 2204 | |
| 2205 | static int sysc_notifier_call(struct notifier_block *nb, |
| 2206 | unsigned long event, void *device) |
| 2207 | { |
| 2208 | struct device *dev = device; |
| 2209 | struct sysc *ddata; |
| 2210 | int error; |
| 2211 | |
| 2212 | ddata = sysc_child_to_parent(dev); |
| 2213 | if (!ddata) |
| 2214 | return NOTIFY_DONE; |
| 2215 | |
| 2216 | switch (event) { |
| 2217 | case BUS_NOTIFY_ADD_DEVICE: |
| 2218 | error = sysc_child_add_clocks(ddata, dev); |
| 2219 | if (error) |
| 2220 | return error; |
| 2221 | sysc_legacy_idle_quirk(ddata, dev); |
| 2222 | break; |
| 2223 | default: |
| 2224 | break; |
| 2225 | } |
| 2226 | |
| 2227 | return NOTIFY_DONE; |
| 2228 | } |
| 2229 | |
| 2230 | static struct notifier_block sysc_nb = { |
| 2231 | .notifier_call = sysc_notifier_call, |
| 2232 | }; |
| 2233 | |
| 2234 | /* Device tree configured quirks */ |
| 2235 | struct sysc_dts_quirk { |
| 2236 | const char *name; |
| 2237 | u32 mask; |
| 2238 | }; |
| 2239 | |
| 2240 | static const struct sysc_dts_quirk sysc_dts_quirks[] = { |
| 2241 | { .name = "ti,no-idle-on-init", |
| 2242 | .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, }, |
| 2243 | { .name = "ti,no-reset-on-init", |
| 2244 | .mask = SYSC_QUIRK_NO_RESET_ON_INIT, }, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2245 | { .name = "ti,no-idle", |
| 2246 | .mask = SYSC_QUIRK_NO_IDLE, }, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2247 | }; |
| 2248 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2249 | static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np, |
| 2250 | bool is_child) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2251 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2252 | const struct property *prop; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2253 | int i, len; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2254 | |
| 2255 | for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2256 | const char *name = sysc_dts_quirks[i].name; |
| 2257 | |
| 2258 | prop = of_get_property(np, name, &len); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2259 | if (!prop) |
| 2260 | continue; |
| 2261 | |
| 2262 | ddata->cfg.quirks |= sysc_dts_quirks[i].mask; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2263 | if (is_child) { |
| 2264 | dev_warn(ddata->dev, |
| 2265 | "dts flag should be at module level for %s\n", |
| 2266 | name); |
| 2267 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2268 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2269 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2270 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2271 | static int sysc_init_dts_quirks(struct sysc *ddata) |
| 2272 | { |
| 2273 | struct device_node *np = ddata->dev->of_node; |
| 2274 | int error; |
| 2275 | u32 val; |
| 2276 | |
| 2277 | ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL); |
| 2278 | |
| 2279 | sysc_parse_dts_quirks(ddata, np, false); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2280 | error = of_property_read_u32(np, "ti,sysc-delay-us", &val); |
| 2281 | if (!error) { |
| 2282 | if (val > 255) { |
| 2283 | dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n", |
| 2284 | val); |
| 2285 | } |
| 2286 | |
| 2287 | ddata->cfg.srst_udelay = (u8)val; |
| 2288 | } |
| 2289 | |
| 2290 | return 0; |
| 2291 | } |
| 2292 | |
| 2293 | static void sysc_unprepare(struct sysc *ddata) |
| 2294 | { |
| 2295 | int i; |
| 2296 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2297 | if (!ddata->clocks) |
| 2298 | return; |
| 2299 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2300 | for (i = 0; i < SYSC_MAX_CLOCKS; i++) { |
| 2301 | if (!IS_ERR_OR_NULL(ddata->clocks[i])) |
| 2302 | clk_unprepare(ddata->clocks[i]); |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | /* |
| 2307 | * Common sysc register bits found on omap2, also known as type1 |
| 2308 | */ |
| 2309 | static const struct sysc_regbits sysc_regbits_omap2 = { |
| 2310 | .dmadisable_shift = -ENODEV, |
| 2311 | .midle_shift = 12, |
| 2312 | .sidle_shift = 3, |
| 2313 | .clkact_shift = 8, |
| 2314 | .emufree_shift = 5, |
| 2315 | .enwkup_shift = 2, |
| 2316 | .srst_shift = 1, |
| 2317 | .autoidle_shift = 0, |
| 2318 | }; |
| 2319 | |
| 2320 | static const struct sysc_capabilities sysc_omap2 = { |
| 2321 | .type = TI_SYSC_OMAP2, |
| 2322 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE | |
| 2323 | SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET | |
| 2324 | SYSC_OMAP2_AUTOIDLE, |
| 2325 | .regbits = &sysc_regbits_omap2, |
| 2326 | }; |
| 2327 | |
| 2328 | /* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */ |
| 2329 | static const struct sysc_capabilities sysc_omap2_timer = { |
| 2330 | .type = TI_SYSC_OMAP2_TIMER, |
| 2331 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE | |
| 2332 | SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET | |
| 2333 | SYSC_OMAP2_AUTOIDLE, |
| 2334 | .regbits = &sysc_regbits_omap2, |
| 2335 | .mod_quirks = SYSC_QUIRK_USE_CLOCKACT, |
| 2336 | }; |
| 2337 | |
| 2338 | /* |
| 2339 | * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2 |
| 2340 | * with different sidle position |
| 2341 | */ |
| 2342 | static const struct sysc_regbits sysc_regbits_omap3_sham = { |
| 2343 | .dmadisable_shift = -ENODEV, |
| 2344 | .midle_shift = -ENODEV, |
| 2345 | .sidle_shift = 4, |
| 2346 | .clkact_shift = -ENODEV, |
| 2347 | .enwkup_shift = -ENODEV, |
| 2348 | .srst_shift = 1, |
| 2349 | .autoidle_shift = 0, |
| 2350 | .emufree_shift = -ENODEV, |
| 2351 | }; |
| 2352 | |
| 2353 | static const struct sysc_capabilities sysc_omap3_sham = { |
| 2354 | .type = TI_SYSC_OMAP3_SHAM, |
| 2355 | .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE, |
| 2356 | .regbits = &sysc_regbits_omap3_sham, |
| 2357 | }; |
| 2358 | |
| 2359 | /* |
| 2360 | * AES register bits found on omap3 and later, a variant of |
| 2361 | * sysc_regbits_omap2 with different sidle position |
| 2362 | */ |
| 2363 | static const struct sysc_regbits sysc_regbits_omap3_aes = { |
| 2364 | .dmadisable_shift = -ENODEV, |
| 2365 | .midle_shift = -ENODEV, |
| 2366 | .sidle_shift = 6, |
| 2367 | .clkact_shift = -ENODEV, |
| 2368 | .enwkup_shift = -ENODEV, |
| 2369 | .srst_shift = 1, |
| 2370 | .autoidle_shift = 0, |
| 2371 | .emufree_shift = -ENODEV, |
| 2372 | }; |
| 2373 | |
| 2374 | static const struct sysc_capabilities sysc_omap3_aes = { |
| 2375 | .type = TI_SYSC_OMAP3_AES, |
| 2376 | .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE, |
| 2377 | .regbits = &sysc_regbits_omap3_aes, |
| 2378 | }; |
| 2379 | |
| 2380 | /* |
| 2381 | * Common sysc register bits found on omap4, also known as type2 |
| 2382 | */ |
| 2383 | static const struct sysc_regbits sysc_regbits_omap4 = { |
| 2384 | .dmadisable_shift = 16, |
| 2385 | .midle_shift = 4, |
| 2386 | .sidle_shift = 2, |
| 2387 | .clkact_shift = -ENODEV, |
| 2388 | .enwkup_shift = -ENODEV, |
| 2389 | .emufree_shift = 1, |
| 2390 | .srst_shift = 0, |
| 2391 | .autoidle_shift = -ENODEV, |
| 2392 | }; |
| 2393 | |
| 2394 | static const struct sysc_capabilities sysc_omap4 = { |
| 2395 | .type = TI_SYSC_OMAP4, |
| 2396 | .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU | |
| 2397 | SYSC_OMAP4_SOFTRESET, |
| 2398 | .regbits = &sysc_regbits_omap4, |
| 2399 | }; |
| 2400 | |
| 2401 | static const struct sysc_capabilities sysc_omap4_timer = { |
| 2402 | .type = TI_SYSC_OMAP4_TIMER, |
| 2403 | .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU | |
| 2404 | SYSC_OMAP4_SOFTRESET, |
| 2405 | .regbits = &sysc_regbits_omap4, |
| 2406 | }; |
| 2407 | |
| 2408 | /* |
| 2409 | * Common sysc register bits found on omap4, also known as type3 |
| 2410 | */ |
| 2411 | static const struct sysc_regbits sysc_regbits_omap4_simple = { |
| 2412 | .dmadisable_shift = -ENODEV, |
| 2413 | .midle_shift = 2, |
| 2414 | .sidle_shift = 0, |
| 2415 | .clkact_shift = -ENODEV, |
| 2416 | .enwkup_shift = -ENODEV, |
| 2417 | .srst_shift = -ENODEV, |
| 2418 | .emufree_shift = -ENODEV, |
| 2419 | .autoidle_shift = -ENODEV, |
| 2420 | }; |
| 2421 | |
| 2422 | static const struct sysc_capabilities sysc_omap4_simple = { |
| 2423 | .type = TI_SYSC_OMAP4_SIMPLE, |
| 2424 | .regbits = &sysc_regbits_omap4_simple, |
| 2425 | }; |
| 2426 | |
| 2427 | /* |
| 2428 | * SmartReflex sysc found on omap34xx |
| 2429 | */ |
| 2430 | static const struct sysc_regbits sysc_regbits_omap34xx_sr = { |
| 2431 | .dmadisable_shift = -ENODEV, |
| 2432 | .midle_shift = -ENODEV, |
| 2433 | .sidle_shift = -ENODEV, |
| 2434 | .clkact_shift = 20, |
| 2435 | .enwkup_shift = -ENODEV, |
| 2436 | .srst_shift = -ENODEV, |
| 2437 | .emufree_shift = -ENODEV, |
| 2438 | .autoidle_shift = -ENODEV, |
| 2439 | }; |
| 2440 | |
| 2441 | static const struct sysc_capabilities sysc_34xx_sr = { |
| 2442 | .type = TI_SYSC_OMAP34XX_SR, |
| 2443 | .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY, |
| 2444 | .regbits = &sysc_regbits_omap34xx_sr, |
| 2445 | .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED | |
| 2446 | SYSC_QUIRK_LEGACY_IDLE, |
| 2447 | }; |
| 2448 | |
| 2449 | /* |
| 2450 | * SmartReflex sysc found on omap36xx and later |
| 2451 | */ |
| 2452 | static const struct sysc_regbits sysc_regbits_omap36xx_sr = { |
| 2453 | .dmadisable_shift = -ENODEV, |
| 2454 | .midle_shift = -ENODEV, |
| 2455 | .sidle_shift = 24, |
| 2456 | .clkact_shift = -ENODEV, |
| 2457 | .enwkup_shift = 26, |
| 2458 | .srst_shift = -ENODEV, |
| 2459 | .emufree_shift = -ENODEV, |
| 2460 | .autoidle_shift = -ENODEV, |
| 2461 | }; |
| 2462 | |
| 2463 | static const struct sysc_capabilities sysc_36xx_sr = { |
| 2464 | .type = TI_SYSC_OMAP36XX_SR, |
| 2465 | .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP, |
| 2466 | .regbits = &sysc_regbits_omap36xx_sr, |
| 2467 | .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE, |
| 2468 | }; |
| 2469 | |
| 2470 | static const struct sysc_capabilities sysc_omap4_sr = { |
| 2471 | .type = TI_SYSC_OMAP4_SR, |
| 2472 | .regbits = &sysc_regbits_omap36xx_sr, |
| 2473 | .mod_quirks = SYSC_QUIRK_LEGACY_IDLE, |
| 2474 | }; |
| 2475 | |
| 2476 | /* |
| 2477 | * McASP register bits found on omap4 and later |
| 2478 | */ |
| 2479 | static const struct sysc_regbits sysc_regbits_omap4_mcasp = { |
| 2480 | .dmadisable_shift = -ENODEV, |
| 2481 | .midle_shift = -ENODEV, |
| 2482 | .sidle_shift = 0, |
| 2483 | .clkact_shift = -ENODEV, |
| 2484 | .enwkup_shift = -ENODEV, |
| 2485 | .srst_shift = -ENODEV, |
| 2486 | .emufree_shift = -ENODEV, |
| 2487 | .autoidle_shift = -ENODEV, |
| 2488 | }; |
| 2489 | |
| 2490 | static const struct sysc_capabilities sysc_omap4_mcasp = { |
| 2491 | .type = TI_SYSC_OMAP4_MCASP, |
| 2492 | .regbits = &sysc_regbits_omap4_mcasp, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2493 | .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED, |
| 2494 | }; |
| 2495 | |
| 2496 | /* |
| 2497 | * McASP found on dra7 and later |
| 2498 | */ |
| 2499 | static const struct sysc_capabilities sysc_dra7_mcasp = { |
| 2500 | .type = TI_SYSC_OMAP4_SIMPLE, |
| 2501 | .regbits = &sysc_regbits_omap4_simple, |
| 2502 | .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2503 | }; |
| 2504 | |
| 2505 | /* |
| 2506 | * FS USB host found on omap4 and later |
| 2507 | */ |
| 2508 | static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = { |
| 2509 | .dmadisable_shift = -ENODEV, |
| 2510 | .midle_shift = -ENODEV, |
| 2511 | .sidle_shift = 24, |
| 2512 | .clkact_shift = -ENODEV, |
| 2513 | .enwkup_shift = 26, |
| 2514 | .srst_shift = -ENODEV, |
| 2515 | .emufree_shift = -ENODEV, |
| 2516 | .autoidle_shift = -ENODEV, |
| 2517 | }; |
| 2518 | |
| 2519 | static const struct sysc_capabilities sysc_omap4_usb_host_fs = { |
| 2520 | .type = TI_SYSC_OMAP4_USB_HOST_FS, |
| 2521 | .sysc_mask = SYSC_OMAP2_ENAWAKEUP, |
| 2522 | .regbits = &sysc_regbits_omap4_usb_host_fs, |
| 2523 | }; |
| 2524 | |
| 2525 | static const struct sysc_regbits sysc_regbits_dra7_mcan = { |
| 2526 | .dmadisable_shift = -ENODEV, |
| 2527 | .midle_shift = -ENODEV, |
| 2528 | .sidle_shift = -ENODEV, |
| 2529 | .clkact_shift = -ENODEV, |
| 2530 | .enwkup_shift = 4, |
| 2531 | .srst_shift = 0, |
| 2532 | .emufree_shift = -ENODEV, |
| 2533 | .autoidle_shift = -ENODEV, |
| 2534 | }; |
| 2535 | |
| 2536 | static const struct sysc_capabilities sysc_dra7_mcan = { |
| 2537 | .type = TI_SYSC_DRA7_MCAN, |
| 2538 | .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET, |
| 2539 | .regbits = &sysc_regbits_dra7_mcan, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2540 | .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2541 | }; |
| 2542 | |
| 2543 | static int sysc_init_pdata(struct sysc *ddata) |
| 2544 | { |
| 2545 | struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2546 | struct ti_sysc_module_data *mdata; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2547 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2548 | if (!pdata) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2549 | return 0; |
| 2550 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2551 | mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL); |
| 2552 | if (!mdata) |
| 2553 | return -ENOMEM; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2554 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2555 | if (ddata->legacy_mode) { |
| 2556 | mdata->name = ddata->legacy_mode; |
| 2557 | mdata->module_pa = ddata->module_pa; |
| 2558 | mdata->module_size = ddata->module_size; |
| 2559 | mdata->offsets = ddata->offsets; |
| 2560 | mdata->nr_offsets = SYSC_MAX_REGS; |
| 2561 | mdata->cap = ddata->cap; |
| 2562 | mdata->cfg = &ddata->cfg; |
| 2563 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2564 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2565 | ddata->mdata = mdata; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2566 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2567 | return 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | static int sysc_init_match(struct sysc *ddata) |
| 2571 | { |
| 2572 | const struct sysc_capabilities *cap; |
| 2573 | |
| 2574 | cap = of_device_get_match_data(ddata->dev); |
| 2575 | if (!cap) |
| 2576 | return -EINVAL; |
| 2577 | |
| 2578 | ddata->cap = cap; |
| 2579 | if (ddata->cap) |
| 2580 | ddata->cfg.quirks |= ddata->cap->mod_quirks; |
| 2581 | |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | static void ti_sysc_idle(struct work_struct *work) |
| 2586 | { |
| 2587 | struct sysc *ddata; |
| 2588 | |
| 2589 | ddata = container_of(work, struct sysc, idle_work.work); |
| 2590 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2591 | /* |
| 2592 | * One time decrement of clock usage counts if left on from init. |
| 2593 | * Note that we disable opt clocks unconditionally in this case |
| 2594 | * as they are enabled unconditionally during init without |
| 2595 | * considering sysc_opt_clks_needed() at that point. |
| 2596 | */ |
| 2597 | if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE | |
| 2598 | SYSC_QUIRK_NO_IDLE_ON_INIT)) { |
| 2599 | sysc_disable_main_clocks(ddata); |
| 2600 | sysc_disable_opt_clocks(ddata); |
| 2601 | sysc_clkdm_allow_idle(ddata); |
| 2602 | } |
| 2603 | |
| 2604 | /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */ |
| 2605 | if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE) |
| 2606 | return; |
| 2607 | |
| 2608 | /* |
| 2609 | * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT |
| 2610 | * and SYSC_QUIRK_NO_RESET_ON_INIT |
| 2611 | */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2612 | if (pm_runtime_active(ddata->dev)) |
| 2613 | pm_runtime_put_sync(ddata->dev); |
| 2614 | } |
| 2615 | |
| 2616 | static const struct of_device_id sysc_match_table[] = { |
| 2617 | { .compatible = "simple-bus", }, |
| 2618 | { /* sentinel */ }, |
| 2619 | }; |
| 2620 | |
| 2621 | static int sysc_probe(struct platform_device *pdev) |
| 2622 | { |
| 2623 | struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
| 2624 | struct sysc *ddata; |
| 2625 | int error; |
| 2626 | |
| 2627 | ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); |
| 2628 | if (!ddata) |
| 2629 | return -ENOMEM; |
| 2630 | |
| 2631 | ddata->dev = &pdev->dev; |
| 2632 | platform_set_drvdata(pdev, ddata); |
| 2633 | |
| 2634 | error = sysc_init_match(ddata); |
| 2635 | if (error) |
| 2636 | return error; |
| 2637 | |
| 2638 | error = sysc_init_dts_quirks(ddata); |
| 2639 | if (error) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2640 | return error; |
| 2641 | |
| 2642 | error = sysc_map_and_check_registers(ddata); |
| 2643 | if (error) |
| 2644 | return error; |
| 2645 | |
| 2646 | error = sysc_init_sysc_mask(ddata); |
| 2647 | if (error) |
| 2648 | return error; |
| 2649 | |
| 2650 | error = sysc_init_idlemodes(ddata); |
| 2651 | if (error) |
| 2652 | return error; |
| 2653 | |
| 2654 | error = sysc_init_syss_mask(ddata); |
| 2655 | if (error) |
| 2656 | return error; |
| 2657 | |
| 2658 | error = sysc_init_pdata(ddata); |
| 2659 | if (error) |
| 2660 | return error; |
| 2661 | |
| 2662 | sysc_init_early_quirks(ddata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2663 | |
| 2664 | error = sysc_get_clocks(ddata); |
| 2665 | if (error) |
| 2666 | return error; |
| 2667 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2668 | error = sysc_init_resets(ddata); |
| 2669 | if (error) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2670 | goto unprepare; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2671 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2672 | error = sysc_init_module(ddata); |
| 2673 | if (error) |
| 2674 | goto unprepare; |
| 2675 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2676 | pm_runtime_enable(ddata->dev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2677 | error = pm_runtime_get_sync(ddata->dev); |
| 2678 | if (error < 0) { |
| 2679 | pm_runtime_put_noidle(ddata->dev); |
| 2680 | pm_runtime_disable(ddata->dev); |
| 2681 | goto unprepare; |
| 2682 | } |
| 2683 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2684 | /* Balance reset counts */ |
| 2685 | if (ddata->rsts) |
| 2686 | reset_control_assert(ddata->rsts); |
| 2687 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2688 | sysc_show_registers(ddata); |
| 2689 | |
| 2690 | ddata->dev->type = &sysc_device_type; |
| 2691 | error = of_platform_populate(ddata->dev->of_node, sysc_match_table, |
| 2692 | pdata ? pdata->auxdata : NULL, |
| 2693 | ddata->dev); |
| 2694 | if (error) |
| 2695 | goto err; |
| 2696 | |
| 2697 | INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle); |
| 2698 | |
| 2699 | /* At least earlycon won't survive without deferred idle */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2700 | if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE | |
| 2701 | SYSC_QUIRK_NO_IDLE_ON_INIT | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2702 | SYSC_QUIRK_NO_RESET_ON_INIT)) { |
| 2703 | schedule_delayed_work(&ddata->idle_work, 3000); |
| 2704 | } else { |
| 2705 | pm_runtime_put(&pdev->dev); |
| 2706 | } |
| 2707 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2708 | return 0; |
| 2709 | |
| 2710 | err: |
| 2711 | pm_runtime_put_sync(&pdev->dev); |
| 2712 | pm_runtime_disable(&pdev->dev); |
| 2713 | unprepare: |
| 2714 | sysc_unprepare(ddata); |
| 2715 | |
| 2716 | return error; |
| 2717 | } |
| 2718 | |
| 2719 | static int sysc_remove(struct platform_device *pdev) |
| 2720 | { |
| 2721 | struct sysc *ddata = platform_get_drvdata(pdev); |
| 2722 | int error; |
| 2723 | |
| 2724 | cancel_delayed_work_sync(&ddata->idle_work); |
| 2725 | |
| 2726 | error = pm_runtime_get_sync(ddata->dev); |
| 2727 | if (error < 0) { |
| 2728 | pm_runtime_put_noidle(ddata->dev); |
| 2729 | pm_runtime_disable(ddata->dev); |
| 2730 | goto unprepare; |
| 2731 | } |
| 2732 | |
| 2733 | of_platform_depopulate(&pdev->dev); |
| 2734 | |
| 2735 | pm_runtime_put_sync(&pdev->dev); |
| 2736 | pm_runtime_disable(&pdev->dev); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 2737 | |
| 2738 | if (!reset_control_status(ddata->rsts)) |
| 2739 | reset_control_assert(ddata->rsts); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2740 | |
| 2741 | unprepare: |
| 2742 | sysc_unprepare(ddata); |
| 2743 | |
| 2744 | return 0; |
| 2745 | } |
| 2746 | |
| 2747 | static const struct of_device_id sysc_match[] = { |
| 2748 | { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, }, |
| 2749 | { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, }, |
| 2750 | { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, }, |
| 2751 | { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, }, |
| 2752 | { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, }, |
| 2753 | { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, }, |
| 2754 | { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, }, |
| 2755 | { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, }, |
| 2756 | { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, }, |
| 2757 | { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, }, |
| 2758 | { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, }, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2759 | { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, }, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2760 | { .compatible = "ti,sysc-usb-host-fs", |
| 2761 | .data = &sysc_omap4_usb_host_fs, }, |
| 2762 | { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, }, |
| 2763 | { }, |
| 2764 | }; |
| 2765 | MODULE_DEVICE_TABLE(of, sysc_match); |
| 2766 | |
| 2767 | static struct platform_driver sysc_driver = { |
| 2768 | .probe = sysc_probe, |
| 2769 | .remove = sysc_remove, |
| 2770 | .driver = { |
| 2771 | .name = "ti-sysc", |
| 2772 | .of_match_table = sysc_match, |
| 2773 | .pm = &sysc_pm_ops, |
| 2774 | }, |
| 2775 | }; |
| 2776 | |
| 2777 | static int __init sysc_init(void) |
| 2778 | { |
| 2779 | bus_register_notifier(&platform_bus_type, &sysc_nb); |
| 2780 | |
| 2781 | return platform_driver_register(&sysc_driver); |
| 2782 | } |
| 2783 | module_init(sysc_init); |
| 2784 | |
| 2785 | static void __exit sysc_exit(void) |
| 2786 | { |
| 2787 | bus_unregister_notifier(&platform_bus_type, &sysc_nb); |
| 2788 | platform_driver_unregister(&sysc_driver); |
| 2789 | } |
| 2790 | module_exit(sysc_exit); |
| 2791 | |
| 2792 | MODULE_DESCRIPTION("TI sysc interconnect target driver"); |
| 2793 | MODULE_LICENSE("GPL v2"); |