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