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