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