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