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