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