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