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