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