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