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