blob: 78fc3da39088f5527212670ee3778654d9b9e728 [file] [log] [blame]
Suman Anna54d66222019-08-13 04:13:32 -07001// SPDX-License-Identifier: GPL-2.0
Tony Lindgren0eecc632017-10-10 14:23:43 -07002/*
3 * ti-sysc.c - Texas Instruments sysc interconnect target driver
Tony Lindgren0eecc632017-10-10 14:23:43 -07004 */
5
6#include <linux/io.h>
7#include <linux/clk.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -08008#include <linux/clkdev.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -08009#include <linux/delay.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080010#include <linux/list.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070011#include <linux/module.h>
12#include <linux/platform_device.h>
Tony Lindgrena885f0f2018-02-22 14:03:48 -080013#include <linux/pm_domain.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070014#include <linux/pm_runtime.h>
Tony Lindgren50622362018-04-16 10:20:27 -070015#include <linux/reset.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070016#include <linux/of_address.h>
17#include <linux/of_platform.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080018#include <linux/slab.h>
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080019#include <linux/sys_soc.h>
Faiz Abbas596e7952018-07-09 22:18:39 +053020#include <linux/iopoll.h>
Tony Lindgren2c355ff2018-02-22 13:58:03 -080021
Tony Lindgren70a65242017-12-15 09:41:09 -080022#include <linux/platform_data/ti-sysc.h>
23
24#include <dt-bindings/bus/ti-sysc.h>
Tony Lindgren0eecc632017-10-10 14:23:43 -070025
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080026#define DIS_ISP BIT(2)
27#define DIS_IVA BIT(1)
28#define DIS_SGX BIT(0)
29
30#define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), }
31
Faiz Abbas596e7952018-07-09 22:18:39 +053032#define MAX_MODULE_SOFTRESET_WAIT 10000
33
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080034enum sysc_soc {
35 SOC_UNKNOWN,
36 SOC_2420,
37 SOC_2430,
38 SOC_3430,
39 SOC_3630,
40 SOC_4430,
41 SOC_4460,
42 SOC_4470,
43 SOC_5430,
44 SOC_AM3,
45 SOC_AM4,
46 SOC_DRA7,
47};
48
49struct sysc_address {
50 unsigned long base;
51 struct list_head node;
52};
53
54struct sysc_soc_info {
55 unsigned long general_purpose:1;
56 enum sysc_soc soc;
57 struct mutex list_lock; /* disabled modules list lock */
58 struct list_head disabled_modules;
59};
Tony Lindgren0eecc632017-10-10 14:23:43 -070060
61enum sysc_clocks {
62 SYSC_FCK,
63 SYSC_ICK,
Tony Lindgren09dfe582018-04-16 10:25:52 -070064 SYSC_OPTFCK0,
65 SYSC_OPTFCK1,
66 SYSC_OPTFCK2,
67 SYSC_OPTFCK3,
68 SYSC_OPTFCK4,
69 SYSC_OPTFCK5,
70 SYSC_OPTFCK6,
71 SYSC_OPTFCK7,
Tony Lindgren0eecc632017-10-10 14:23:43 -070072 SYSC_MAX_CLOCKS,
73};
74
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -080075static struct sysc_soc_info *sysc_soc;
76static const char * const reg_names[] = { "rev", "sysc", "syss", };
Tony Lindgrena54275f2019-03-21 11:00:21 -070077static const char * const clock_names[SYSC_MAX_CLOCKS] = {
78 "fck", "ick", "opt0", "opt1", "opt2", "opt3", "opt4",
79 "opt5", "opt6", "opt7",
80};
Tony Lindgren0eecc632017-10-10 14:23:43 -070081
Tony Lindgrenc5a2de92017-12-15 09:41:23 -080082#define SYSC_IDLEMODE_MASK 3
83#define SYSC_CLOCKACTIVITY_MASK 3
84
Tony Lindgren0eecc632017-10-10 14:23:43 -070085/**
86 * struct sysc - TI sysc interconnect target module registers and capabilities
87 * @dev: struct device pointer
88 * @module_pa: physical address of the interconnect target module
89 * @module_size: size of the interconnect target module
90 * @module_va: virtual address of the interconnect target module
91 * @offsets: register offsets from module base
Suman Annab58056d2019-08-13 04:13:32 -070092 * @mdata: ti-sysc to hwmod translation data for a module
Tony Lindgren0eecc632017-10-10 14:23:43 -070093 * @clocks: clocks used by the interconnect target module
Tony Lindgren09dfe582018-04-16 10:25:52 -070094 * @clock_roles: clock role names for the found clocks
95 * @nr_clocks: number of clocks used by the interconnect target module
Suman Annab58056d2019-08-13 04:13:32 -070096 * @rsts: resets used by the interconnect target module
Tony Lindgren0eecc632017-10-10 14:23:43 -070097 * @legacy_mode: configured for legacy mode if set
Tony Lindgren70a65242017-12-15 09:41:09 -080098 * @cap: interconnect target module capabilities
99 * @cfg: interconnect target module configuration
Suman Annab58056d2019-08-13 04:13:32 -0700100 * @cookie: data used by legacy platform callbacks
Tony Lindgren566a9b052017-12-15 09:41:19 -0800101 * @name: name if available
102 * @revision: interconnect target module revision
Suman Annab58056d2019-08-13 04:13:32 -0700103 * @enabled: sysc runtime enabled status
Tony Lindgren62020f22018-02-22 13:59:44 -0800104 * @needs_resume: runtime resume needed on resume from suspend
Suman Annab58056d2019-08-13 04:13:32 -0700105 * @child_needs_resume: runtime resume needed for child on resume from suspend
106 * @disable_on_idle: status flag used for disabling modules with resets
107 * @idle_work: work structure used to perform delayed idle on a module
Tony Lindgrene64c0212020-02-24 12:58:03 -0800108 * @pre_reset_quirk: module specific pre-reset quirk
109 * @post_reset_quirk: module specific post-reset quirk
Tony Lindgren4e23be42019-06-10 04:48:05 -0700110 * @reset_done_quirk: module specific reset done quirk
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700111 * @module_enable_quirk: module specific enable quirk
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700112 * @module_disable_quirk: module specific disable quirk
Tony Lindgrene8639e12020-02-24 12:58:03 -0800113 * @module_unlock_quirk: module specific sysconfig unlock quirk
114 * @module_lock_quirk: module specific sysconfig lock quirk
Tony Lindgren0eecc632017-10-10 14:23:43 -0700115 */
116struct sysc {
117 struct device *dev;
118 u64 module_pa;
119 u32 module_size;
120 void __iomem *module_va;
121 int offsets[SYSC_MAX_REGS];
Tony Lindgrena3e92e72019-03-21 11:00:21 -0700122 struct ti_sysc_module_data *mdata;
Tony Lindgren09dfe582018-04-16 10:25:52 -0700123 struct clk **clocks;
124 const char **clock_roles;
125 int nr_clocks;
Tony Lindgren50622362018-04-16 10:20:27 -0700126 struct reset_control *rsts;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700127 const char *legacy_mode;
Tony Lindgren70a65242017-12-15 09:41:09 -0800128 const struct sysc_capabilities *cap;
129 struct sysc_config cfg;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -0800130 struct ti_sysc_cookie cookie;
Tony Lindgren566a9b052017-12-15 09:41:19 -0800131 const char *name;
132 u32 revision;
Tony Lindgren8383e252019-05-27 04:51:56 -0700133 unsigned int enabled:1;
134 unsigned int needs_resume:1;
135 unsigned int child_needs_resume:1;
Tony Lindgren76f0f772018-02-23 08:28:45 -0800136 struct delayed_work idle_work;
Tony Lindgrene64c0212020-02-24 12:58:03 -0800137 void (*pre_reset_quirk)(struct sysc *sysc);
138 void (*post_reset_quirk)(struct sysc *sysc);
Tony Lindgren4e23be42019-06-10 04:48:05 -0700139 void (*reset_done_quirk)(struct sysc *sysc);
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700140 void (*module_enable_quirk)(struct sysc *sysc);
Tony Lindgrenc7d86692019-10-17 11:21:44 -0700141 void (*module_disable_quirk)(struct sysc *sysc);
Tony Lindgrene8639e12020-02-24 12:58:03 -0800142 void (*module_unlock_quirk)(struct sysc *sysc);
143 void (*module_lock_quirk)(struct sysc *sysc);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700144};
145
Tony Lindgren4014c082018-12-10 14:11:26 -0800146static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
147 bool is_child);
148
Tony Lindgrenb7182b42019-03-21 11:00:21 -0700149static void sysc_write(struct sysc *ddata, int offset, u32 value)
Faiz Abbas596e7952018-07-09 22:18:39 +0530150{
Tony Lindgren5aa91292019-05-27 04:51:53 -0700151 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
152 writew_relaxed(value & 0xffff, ddata->module_va + offset);
153
154 /* Only i2c revision has LO and HI register with stride of 4 */
155 if (ddata->offsets[SYSC_REVISION] >= 0 &&
156 offset == ddata->offsets[SYSC_REVISION]) {
157 u16 hi = value >> 16;
158
159 writew_relaxed(hi, ddata->module_va + offset + 4);
160 }
161
162 return;
163 }
164
Faiz Abbas596e7952018-07-09 22:18:39 +0530165 writel_relaxed(value, ddata->module_va + offset);
166}
167
Tony Lindgren566a9b052017-12-15 09:41:19 -0800168static u32 sysc_read(struct sysc *ddata, int offset)
169{
170 if (ddata->cfg.quirks & SYSC_QUIRK_16BIT) {
171 u32 val;
172
173 val = readw_relaxed(ddata->module_va + offset);
Tony Lindgren5aa91292019-05-27 04:51:53 -0700174
175 /* Only i2c revision has LO and HI register with stride of 4 */
176 if (ddata->offsets[SYSC_REVISION] >= 0 &&
177 offset == ddata->offsets[SYSC_REVISION]) {
178 u16 tmp = readw_relaxed(ddata->module_va + offset + 4);
179
180 val |= tmp << 16;
181 }
Tony Lindgren566a9b052017-12-15 09:41:19 -0800182
183 return val;
184 }
185
186 return readl_relaxed(ddata->module_va + offset);
187}
188
Tony Lindgren09dfe582018-04-16 10:25:52 -0700189static bool sysc_opt_clks_needed(struct sysc *ddata)
190{
191 return !!(ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_NEEDED);
192}
193
Tony Lindgren0eecc632017-10-10 14:23:43 -0700194static u32 sysc_read_revision(struct sysc *ddata)
195{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800196 int offset = ddata->offsets[SYSC_REVISION];
197
198 if (offset < 0)
199 return 0;
200
201 return sysc_read(ddata, offset);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700202}
203
Tony Lindgrene0db94f2019-05-27 04:51:53 -0700204static u32 sysc_read_sysconfig(struct sysc *ddata)
205{
206 int offset = ddata->offsets[SYSC_SYSCONFIG];
207
208 if (offset < 0)
209 return 0;
210
211 return sysc_read(ddata, offset);
212}
213
214static u32 sysc_read_sysstatus(struct sysc *ddata)
215{
216 int offset = ddata->offsets[SYSC_SYSSTATUS];
217
218 if (offset < 0)
219 return 0;
220
221 return sysc_read(ddata, offset);
222}
223
Tony Lindgrena54275f2019-03-21 11:00:21 -0700224static int sysc_add_named_clock_from_child(struct sysc *ddata,
225 const char *name,
226 const char *optfck_name)
227{
228 struct device_node *np = ddata->dev->of_node;
229 struct device_node *child;
230 struct clk_lookup *cl;
231 struct clk *clock;
232 const char *n;
233
234 if (name)
235 n = name;
236 else
237 n = optfck_name;
238
239 /* Does the clock alias already exist? */
240 clock = of_clk_get_by_name(np, n);
241 if (!IS_ERR(clock)) {
242 clk_put(clock);
243
244 return 0;
245 }
246
247 child = of_get_next_available_child(np, NULL);
248 if (!child)
249 return -ENODEV;
250
251 clock = devm_get_clk_from_child(ddata->dev, child, name);
252 if (IS_ERR(clock))
253 return PTR_ERR(clock);
254
255 /*
256 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
257 * limit for clk_get(). If cl ever needs to be freed, it should be done
258 * with clkdev_drop().
259 */
260 cl = kcalloc(1, sizeof(*cl), GFP_KERNEL);
261 if (!cl)
262 return -ENOMEM;
263
264 cl->con_id = n;
265 cl->dev_id = dev_name(ddata->dev);
266 cl->clk = clock;
267 clkdev_add(cl);
268
269 clk_put(clock);
270
271 return 0;
272}
273
274static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
275{
276 const char *optfck_name;
277 int error, index;
278
279 if (ddata->nr_clocks < SYSC_OPTFCK0)
280 index = SYSC_OPTFCK0;
281 else
282 index = ddata->nr_clocks;
283
284 if (name)
285 optfck_name = name;
286 else
287 optfck_name = clock_names[index];
288
289 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
290 if (error)
291 return error;
292
293 ddata->clock_roles[index] = optfck_name;
294 ddata->nr_clocks++;
295
296 return 0;
297}
298
Tony Lindgren09dfe582018-04-16 10:25:52 -0700299static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700300{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700301 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700302
Tony Lindgren09dfe582018-04-16 10:25:52 -0700303 if (!strncmp(clock_names[SYSC_FCK], name, 3))
304 index = SYSC_FCK;
305 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
306 index = SYSC_ICK;
307
308 if (index < 0) {
309 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700310 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700311 index = i;
312 break;
313 }
314 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700315 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700316
317 if (index < 0) {
318 dev_err(ddata->dev, "clock %s not added\n", name);
319 return index;
320 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700321
322 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
323 if (IS_ERR(ddata->clocks[index])) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700324 dev_err(ddata->dev, "clock get error for %s: %li\n",
325 name, PTR_ERR(ddata->clocks[index]));
326
327 return PTR_ERR(ddata->clocks[index]);
328 }
329
330 error = clk_prepare(ddata->clocks[index]);
331 if (error) {
332 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
333 name, error);
334
335 return error;
336 }
337
338 return 0;
339}
340
341static int sysc_get_clocks(struct sysc *ddata)
342{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700343 struct device_node *np = ddata->dev->of_node;
344 struct property *prop;
345 const char *name;
346 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700347
Kees Cook20749052018-06-18 10:45:49 -0700348 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700349 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700350 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700351 GFP_KERNEL);
352 if (!ddata->clock_roles)
353 return -ENOMEM;
354
355 of_property_for_each_string(np, "clock-names", prop, name) {
356 if (!strncmp(clock_names[SYSC_FCK], name, 3))
357 nr_fck++;
358 if (!strncmp(clock_names[SYSC_ICK], name, 3))
359 nr_ick++;
360 ddata->clock_roles[ddata->nr_clocks] = name;
361 ddata->nr_clocks++;
362 }
363
364 if (ddata->nr_clocks < 1)
365 return 0;
366
Tony Lindgrena54275f2019-03-21 11:00:21 -0700367 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
368 error = sysc_init_ext_opt_clock(ddata, NULL);
369 if (error)
370 return error;
371 }
372
Tony Lindgren09dfe582018-04-16 10:25:52 -0700373 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
374 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
375
376 return -EINVAL;
377 }
378
379 if (nr_fck > 1 || nr_ick > 1) {
380 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
381
382 return -EINVAL;
383 }
384
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800385 /* Always add a slot for main clocks fck and ick even if unused */
386 if (!nr_fck)
387 ddata->nr_clocks++;
388 if (!nr_ick)
389 ddata->nr_clocks++;
390
Kees Cook20749052018-06-18 10:45:49 -0700391 ddata->clocks = devm_kcalloc(ddata->dev,
392 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700393 GFP_KERNEL);
394 if (!ddata->clocks)
395 return -ENOMEM;
396
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800397 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
398 const char *name = ddata->clock_roles[i];
399
400 if (!name)
401 continue;
402
403 error = sysc_get_one_clock(ddata, name);
Tony Lindgren2783d062019-09-05 13:01:29 -0700404 if (error)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700405 return error;
406 }
407
408 return 0;
409}
410
Tony Lindgrend8789702019-03-21 11:00:21 -0700411static int sysc_enable_main_clocks(struct sysc *ddata)
412{
413 struct clk *clock;
414 int i, error;
415
416 if (!ddata->clocks)
417 return 0;
418
419 for (i = 0; i < SYSC_OPTFCK0; i++) {
420 clock = ddata->clocks[i];
421
422 /* Main clocks may not have ick */
423 if (IS_ERR_OR_NULL(clock))
424 continue;
425
426 error = clk_enable(clock);
427 if (error)
428 goto err_disable;
429 }
430
431 return 0;
432
433err_disable:
434 for (i--; i >= 0; i--) {
435 clock = ddata->clocks[i];
436
437 /* Main clocks may not have ick */
438 if (IS_ERR_OR_NULL(clock))
439 continue;
440
441 clk_disable(clock);
442 }
443
444 return error;
445}
446
447static void sysc_disable_main_clocks(struct sysc *ddata)
448{
449 struct clk *clock;
450 int i;
451
452 if (!ddata->clocks)
453 return;
454
455 for (i = 0; i < SYSC_OPTFCK0; i++) {
456 clock = ddata->clocks[i];
457 if (IS_ERR_OR_NULL(clock))
458 continue;
459
460 clk_disable(clock);
461 }
462}
463
464static int sysc_enable_opt_clocks(struct sysc *ddata)
465{
466 struct clk *clock;
467 int i, error;
468
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800469 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700470 return 0;
471
472 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
473 clock = ddata->clocks[i];
474
475 /* Assume no holes for opt clocks */
476 if (IS_ERR_OR_NULL(clock))
477 return 0;
478
479 error = clk_enable(clock);
480 if (error)
481 goto err_disable;
482 }
483
484 return 0;
485
486err_disable:
487 for (i--; i >= 0; i--) {
488 clock = ddata->clocks[i];
489 if (IS_ERR_OR_NULL(clock))
490 continue;
491
492 clk_disable(clock);
493 }
494
495 return error;
496}
497
498static void sysc_disable_opt_clocks(struct sysc *ddata)
499{
500 struct clk *clock;
501 int i;
502
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800503 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700504 return;
505
506 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
507 clock = ddata->clocks[i];
508
509 /* Assume no holes for opt clocks */
510 if (IS_ERR_OR_NULL(clock))
511 return;
512
513 clk_disable(clock);
514 }
515}
516
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700517static void sysc_clkdm_deny_idle(struct sysc *ddata)
518{
519 struct ti_sysc_platform_data *pdata;
520
Tony Lindgren94f63452019-12-12 08:57:58 -0800521 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700522 return;
523
524 pdata = dev_get_platdata(ddata->dev);
525 if (pdata && pdata->clkdm_deny_idle)
526 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
527}
528
529static void sysc_clkdm_allow_idle(struct sysc *ddata)
530{
531 struct ti_sysc_platform_data *pdata;
532
Tony Lindgren94f63452019-12-12 08:57:58 -0800533 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700534 return;
535
536 pdata = dev_get_platdata(ddata->dev);
537 if (pdata && pdata->clkdm_allow_idle)
538 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
539}
540
Tony Lindgren0eecc632017-10-10 14:23:43 -0700541/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700542 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700543 * @ddata: device driver data
544 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700545 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700546 */
547static int sysc_init_resets(struct sysc *ddata)
548{
Tony Lindgren50622362018-04-16 10:20:27 -0700549 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300550 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700551
zhengbin3f2c4202019-11-18 18:37:32 +0800552 return PTR_ERR_OR_ZERO(ddata->rsts);
Tony Lindgren50622362018-04-16 10:20:27 -0700553}
554
555/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700556 * sysc_parse_and_check_child_range - parses module IO region from ranges
557 * @ddata: device driver data
558 *
559 * In general we only need rev, syss, and sysc registers and not the whole
560 * module range. But we do want the offsets for these registers from the
561 * module base. This allows us to check them against the legacy hwmod
562 * platform data. Let's also check the ranges are configured properly.
563 */
564static int sysc_parse_and_check_child_range(struct sysc *ddata)
565{
566 struct device_node *np = ddata->dev->of_node;
567 const __be32 *ranges;
568 u32 nr_addr, nr_size;
569 int len, error;
570
571 ranges = of_get_property(np, "ranges", &len);
572 if (!ranges) {
573 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
574
575 return -ENOENT;
576 }
577
578 len /= sizeof(*ranges);
579
580 if (len < 3) {
581 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
582
583 return -EINVAL;
584 }
585
586 error = of_property_read_u32(np, "#address-cells", &nr_addr);
587 if (error)
588 return -ENOENT;
589
590 error = of_property_read_u32(np, "#size-cells", &nr_size);
591 if (error)
592 return -ENOENT;
593
594 if (nr_addr != 1 || nr_size != 1) {
595 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
596
597 return -EINVAL;
598 }
599
600 ranges++;
601 ddata->module_pa = of_translate_address(np, ranges++);
602 ddata->module_size = be32_to_cpup(ranges);
603
Tony Lindgren0eecc632017-10-10 14:23:43 -0700604 return 0;
605}
606
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800607static struct device_node *stdout_path;
608
609static void sysc_init_stdout_path(struct sysc *ddata)
610{
611 struct device_node *np = NULL;
612 const char *uart;
613
614 if (IS_ERR(stdout_path))
615 return;
616
617 if (stdout_path)
618 return;
619
620 np = of_find_node_by_path("/chosen");
621 if (!np)
622 goto err;
623
624 uart = of_get_property(np, "stdout-path", NULL);
625 if (!uart)
626 goto err;
627
628 np = of_find_node_by_path(uart);
629 if (!np)
630 goto err;
631
632 stdout_path = np;
633
634 return;
635
636err:
637 stdout_path = ERR_PTR(-ENODEV);
638}
639
640static void sysc_check_quirk_stdout(struct sysc *ddata,
641 struct device_node *np)
642{
643 sysc_init_stdout_path(ddata);
644 if (np != stdout_path)
645 return;
646
647 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
648 SYSC_QUIRK_NO_RESET_ON_INIT;
649}
650
Tony Lindgren0eecc632017-10-10 14:23:43 -0700651/**
652 * sysc_check_one_child - check child configuration
653 * @ddata: device driver data
654 * @np: child device node
655 *
656 * Let's avoid messy situations where we have new interconnect target
657 * node but children have "ti,hwmods". These belong to the interconnect
658 * target node and are managed by this driver.
659 */
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530660static void sysc_check_one_child(struct sysc *ddata,
661 struct device_node *np)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700662{
663 const char *name;
664
665 name = of_get_property(np, "ti,hwmods", NULL);
Tony Lindgren7320fd32020-02-24 12:58:03 -0800666 if (name && !of_device_is_compatible(np, "ti,sysc"))
Tony Lindgren0eecc632017-10-10 14:23:43 -0700667 dev_warn(ddata->dev, "really a child ti,hwmods property?");
668
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800669 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800670 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700671}
672
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530673static void sysc_check_children(struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700674{
675 struct device_node *child;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700676
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530677 for_each_child_of_node(ddata->dev->of_node, child)
678 sysc_check_one_child(ddata, child);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700679}
680
Tony Lindgrena7199e22017-12-15 09:41:14 -0800681/*
682 * So far only I2C uses 16-bit read access with clockactivity with revision
683 * in two registers with stride of 4. We can detect this based on the rev
684 * register size to configure things far enough to be able to properly read
685 * the revision register.
686 */
687static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
688{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800689 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800690 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800691}
692
Tony Lindgren0eecc632017-10-10 14:23:43 -0700693/**
694 * sysc_parse_one - parses the interconnect target module registers
695 * @ddata: device driver data
696 * @reg: register to parse
697 */
698static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
699{
700 struct resource *res;
701 const char *name;
702
703 switch (reg) {
704 case SYSC_REVISION:
705 case SYSC_SYSCONFIG:
706 case SYSC_SYSSTATUS:
707 name = reg_names[reg];
708 break;
709 default:
710 return -EINVAL;
711 }
712
713 res = platform_get_resource_byname(to_platform_device(ddata->dev),
714 IORESOURCE_MEM, name);
715 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700716 ddata->offsets[reg] = -ENODEV;
717
718 return 0;
719 }
720
721 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800722 if (reg == SYSC_REVISION)
723 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700724
725 return 0;
726}
727
728static int sysc_parse_registers(struct sysc *ddata)
729{
730 int i, error;
731
732 for (i = 0; i < SYSC_MAX_REGS; i++) {
733 error = sysc_parse_one(ddata, i);
734 if (error)
735 return error;
736 }
737
738 return 0;
739}
740
741/**
742 * sysc_check_registers - check for misconfigured register overlaps
743 * @ddata: device driver data
744 */
745static int sysc_check_registers(struct sysc *ddata)
746{
747 int i, j, nr_regs = 0, nr_matches = 0;
748
749 for (i = 0; i < SYSC_MAX_REGS; i++) {
750 if (ddata->offsets[i] < 0)
751 continue;
752
753 if (ddata->offsets[i] > (ddata->module_size - 4)) {
754 dev_err(ddata->dev, "register outside module range");
755
756 return -EINVAL;
757 }
758
759 for (j = 0; j < SYSC_MAX_REGS; j++) {
760 if (ddata->offsets[j] < 0)
761 continue;
762
763 if (ddata->offsets[i] == ddata->offsets[j])
764 nr_matches++;
765 }
766 nr_regs++;
767 }
768
Tony Lindgren0eecc632017-10-10 14:23:43 -0700769 if (nr_matches > nr_regs) {
770 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
771 nr_regs, nr_matches);
772
773 return -EINVAL;
774 }
775
776 return 0;
777}
778
779/**
780 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700781 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700782 *
783 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700784 * within the interconnect target module range. For example, SGX has
785 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
786 * has them at offset 0x1200 in the CPSW_WR child. Usually the
787 * the interconnect target module registers are at the beginning of
788 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700789 */
790static int sysc_ioremap(struct sysc *ddata)
791{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700792 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700793
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700794 if (ddata->offsets[SYSC_REVISION] < 0 &&
795 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
796 ddata->offsets[SYSC_SYSSTATUS] < 0) {
797 size = ddata->module_size;
798 } else {
799 size = max3(ddata->offsets[SYSC_REVISION],
800 ddata->offsets[SYSC_SYSCONFIG],
801 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700802
Tony Lindgren4e23be42019-06-10 04:48:05 -0700803 if (size < SZ_1K)
804 size = SZ_1K;
805
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700806 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700807 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700808 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700809
Tony Lindgren0eecc632017-10-10 14:23:43 -0700810 ddata->module_va = devm_ioremap(ddata->dev,
811 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700812 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700813 if (!ddata->module_va)
814 return -EIO;
815
816 return 0;
817}
818
819/**
820 * sysc_map_and_check_registers - ioremap and check device registers
821 * @ddata: device driver data
822 */
823static int sysc_map_and_check_registers(struct sysc *ddata)
824{
825 int error;
826
827 error = sysc_parse_and_check_child_range(ddata);
828 if (error)
829 return error;
830
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530831 sysc_check_children(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700832
833 error = sysc_parse_registers(ddata);
834 if (error)
835 return error;
836
837 error = sysc_ioremap(ddata);
838 if (error)
839 return error;
840
841 error = sysc_check_registers(ddata);
842 if (error)
843 return error;
844
845 return 0;
846}
847
848/**
849 * sysc_show_rev - read and show interconnect target module revision
850 * @bufp: buffer to print the information to
851 * @ddata: device driver data
852 */
853static int sysc_show_rev(char *bufp, struct sysc *ddata)
854{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800855 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700856
857 if (ddata->offsets[SYSC_REVISION] < 0)
858 return sprintf(bufp, ":NA");
859
Tony Lindgren566a9b052017-12-15 09:41:19 -0800860 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700861
862 return len;
863}
864
865static int sysc_show_reg(struct sysc *ddata,
866 char *bufp, enum sysc_registers reg)
867{
868 if (ddata->offsets[reg] < 0)
869 return sprintf(bufp, ":NA");
870
871 return sprintf(bufp, ":%x", ddata->offsets[reg]);
872}
873
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800874static int sysc_show_name(char *bufp, struct sysc *ddata)
875{
876 if (!ddata->name)
877 return 0;
878
879 return sprintf(bufp, ":%s", ddata->name);
880}
881
Tony Lindgren0eecc632017-10-10 14:23:43 -0700882/**
883 * sysc_show_registers - show information about interconnect target module
884 * @ddata: device driver data
885 */
886static void sysc_show_registers(struct sysc *ddata)
887{
888 char buf[128];
889 char *bufp = buf;
890 int i;
891
892 for (i = 0; i < SYSC_MAX_REGS; i++)
893 bufp += sysc_show_reg(ddata, bufp, i);
894
895 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800896 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700897
898 dev_dbg(ddata->dev, "%llx:%x%s\n",
899 ddata->module_pa, ddata->module_size,
900 buf);
901}
902
Tony Lindgrene8639e12020-02-24 12:58:03 -0800903/**
904 * sysc_write_sysconfig - handle sysconfig quirks for register write
905 * @ddata: device driver data
906 * @value: register value
907 */
908static void sysc_write_sysconfig(struct sysc *ddata, u32 value)
909{
910 if (ddata->module_unlock_quirk)
911 ddata->module_unlock_quirk(ddata);
912
913 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value);
914
915 if (ddata->module_lock_quirk)
916 ddata->module_lock_quirk(ddata);
917}
918
Roger Quadrosd59b6052019-04-08 12:52:39 +0300919#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700920#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +0300921
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700922/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +0300923static int sysc_enable_module(struct device *dev)
924{
925 struct sysc *ddata;
926 const struct sysc_regbits *regbits;
927 u32 reg, idlemodes, best_mode;
928
929 ddata = dev_get_drvdata(dev);
930 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
931 return 0;
932
Roger Quadrosd59b6052019-04-08 12:52:39 +0300933 regbits = ddata->cap->regbits;
934 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
935
Tony Lindgrenae9ae122019-05-27 04:51:54 -0700936 /* Set CLOCKACTIVITY, we only use it for ick */
937 if (regbits->clkact_shift >= 0 &&
938 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT ||
939 ddata->cfg.sysc_val & BIT(regbits->clkact_shift)))
940 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
941
Roger Quadrosd59b6052019-04-08 12:52:39 +0300942 /* Set SIDLE mode */
943 idlemodes = ddata->cfg.sidlemodes;
944 if (!idlemodes || regbits->sidle_shift < 0)
945 goto set_midle;
946
Tony Lindgrenfb685f12019-05-27 04:51:55 -0700947 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
948 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
949 best_mode = SYSC_IDLE_NO;
950 } else {
951 best_mode = fls(ddata->cfg.sidlemodes) - 1;
952 if (best_mode > SYSC_IDLE_MASK) {
953 dev_err(dev, "%s: invalid sidlemode\n", __func__);
954 return -EINVAL;
955 }
Tony Lindgren6e09f492019-05-27 04:51:55 -0700956
957 /* Set WAKEUP */
958 if (regbits->enwkup_shift >= 0 &&
959 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
960 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300961 }
962
963 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
964 reg |= best_mode << regbits->sidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -0800965 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300966
967set_midle:
968 /* Set MIDLE mode */
969 idlemodes = ddata->cfg.midlemodes;
970 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -0700971 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +0300972
973 best_mode = fls(ddata->cfg.midlemodes) - 1;
974 if (best_mode > SYSC_IDLE_MASK) {
975 dev_err(dev, "%s: invalid midlemode\n", __func__);
976 return -EINVAL;
977 }
978
Tony Lindgren03856e92019-10-21 13:36:09 -0700979 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY)
980 best_mode = SYSC_IDLE_NO;
981
Roger Quadrosd59b6052019-04-08 12:52:39 +0300982 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
983 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -0800984 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +0300985
Tony Lindgreneec26552019-05-27 04:51:54 -0700986set_autoidle:
987 /* Autoidle bit must enabled separately if available */
988 if (regbits->autoidle_shift >= 0 &&
989 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
990 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -0800991 sysc_write_sysconfig(ddata, reg);
Tony Lindgreneec26552019-05-27 04:51:54 -0700992 }
993
Tony Lindgrend7f563d2019-08-14 05:18:16 -0700994 if (ddata->module_enable_quirk)
995 ddata->module_enable_quirk(ddata);
996
Roger Quadrosd59b6052019-04-08 12:52:39 +0300997 return 0;
998}
999
1000static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
1001{
1002 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
1003 *best_mode = SYSC_IDLE_SMART_WKUP;
1004 else if (idlemodes & BIT(SYSC_IDLE_SMART))
1005 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -07001006 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +03001007 *best_mode = SYSC_IDLE_FORCE;
1008 else
1009 return -EINVAL;
1010
1011 return 0;
1012}
1013
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001014/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001015static int sysc_disable_module(struct device *dev)
1016{
1017 struct sysc *ddata;
1018 const struct sysc_regbits *regbits;
1019 u32 reg, idlemodes, best_mode;
1020 int ret;
1021
1022 ddata = dev_get_drvdata(dev);
1023 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1024 return 0;
1025
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001026 if (ddata->module_disable_quirk)
1027 ddata->module_disable_quirk(ddata);
1028
Roger Quadrosd59b6052019-04-08 12:52:39 +03001029 regbits = ddata->cap->regbits;
1030 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1031
1032 /* Set MIDLE mode */
1033 idlemodes = ddata->cfg.midlemodes;
1034 if (!idlemodes || regbits->midle_shift < 0)
1035 goto set_sidle;
1036
1037 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1038 if (ret) {
1039 dev_err(dev, "%s: invalid midlemode\n", __func__);
1040 return ret;
1041 }
1042
Tony Lindgren93c60482019-12-09 13:55:15 -08001043 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) ||
1044 ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY))
Tony Lindgren03856e92019-10-21 13:36:09 -07001045 best_mode = SYSC_IDLE_FORCE;
1046
Roger Quadrosd59b6052019-04-08 12:52:39 +03001047 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1048 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001049 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001050
1051set_sidle:
1052 /* Set SIDLE mode */
1053 idlemodes = ddata->cfg.sidlemodes;
1054 if (!idlemodes || regbits->sidle_shift < 0)
1055 return 0;
1056
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001057 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
1058 best_mode = SYSC_IDLE_FORCE;
1059 } else {
1060 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1061 if (ret) {
1062 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1063 return ret;
1064 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001065 }
1066
1067 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1068 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001069 if (regbits->autoidle_shift >= 0 &&
1070 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1071 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001072 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001073
1074 return 0;
1075}
1076
Tony Lindgrenff437282019-03-21 11:00:21 -07001077static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1078 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001079{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001080 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001081 int error;
1082
1083 pdata = dev_get_platdata(ddata->dev);
1084 if (!pdata)
1085 return 0;
1086
1087 if (!pdata->idle_module)
1088 return -ENODEV;
1089
1090 error = pdata->idle_module(dev, &ddata->cookie);
1091 if (error)
1092 dev_err(dev, "%s: could not idle: %i\n",
1093 __func__, error);
1094
Tero Kristo4345f0d2019-08-07 15:46:04 +03001095 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001096
Tony Lindgrenff437282019-03-21 11:00:21 -07001097 return 0;
1098}
1099
1100static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1101 struct sysc *ddata)
1102{
1103 struct ti_sysc_platform_data *pdata;
1104 int error;
1105
1106 pdata = dev_get_platdata(ddata->dev);
1107 if (!pdata)
1108 return 0;
1109
1110 if (!pdata->enable_module)
1111 return -ENODEV;
1112
1113 error = pdata->enable_module(dev, &ddata->cookie);
1114 if (error)
1115 dev_err(dev, "%s: could not enable: %i\n",
1116 __func__, error);
1117
Tero Kristobf59ebb2019-10-07 15:29:29 +03001118 reset_control_deassert(ddata->rsts);
1119
Tony Lindgrenff437282019-03-21 11:00:21 -07001120 return 0;
1121}
1122
1123static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1124{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001125 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001126 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001127
1128 ddata = dev_get_drvdata(dev);
1129
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001130 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001131 return 0;
1132
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001133 sysc_clkdm_deny_idle(ddata);
1134
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001135 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001136 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001137 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001138 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001139 } else {
1140 error = sysc_disable_module(dev);
1141 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001142 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001143 }
1144
Tony Lindgrend8789702019-03-21 11:00:21 -07001145 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001146
Tony Lindgrend8789702019-03-21 11:00:21 -07001147 if (sysc_opt_clks_needed(ddata))
1148 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001149
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001150 ddata->enabled = false;
1151
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001152err_allow_idle:
Tero Kristo4345f0d2019-08-07 15:46:04 +03001153 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001154
Tero Kristob6036312019-08-07 15:46:03 +03001155 sysc_clkdm_allow_idle(ddata);
1156
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001157 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001158}
1159
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001160static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001161{
1162 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001163 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001164
1165 ddata = dev_get_drvdata(dev);
1166
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001167 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001168 return 0;
1169
Tony Lindgren8383e252019-05-27 04:51:56 -07001170
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001171 sysc_clkdm_deny_idle(ddata);
1172
Tony Lindgrend8789702019-03-21 11:00:21 -07001173 if (sysc_opt_clks_needed(ddata)) {
1174 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001175 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001176 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001177 }
1178
Tony Lindgrend8789702019-03-21 11:00:21 -07001179 error = sysc_enable_main_clocks(ddata);
1180 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001181 goto err_opt_clocks;
1182
Tero Kristobf59ebb2019-10-07 15:29:29 +03001183 reset_control_deassert(ddata->rsts);
1184
Tony Lindgren93de83a2019-03-21 11:00:21 -07001185 if (ddata->legacy_mode) {
1186 error = sysc_runtime_resume_legacy(dev, ddata);
1187 if (error)
1188 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001189 } else {
1190 error = sysc_enable_module(dev);
1191 if (error)
1192 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001193 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001194
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001195 ddata->enabled = true;
1196
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001197 sysc_clkdm_allow_idle(ddata);
1198
Tony Lindgrend8789702019-03-21 11:00:21 -07001199 return 0;
1200
1201err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001202 sysc_disable_main_clocks(ddata);
1203err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001204 if (sysc_opt_clks_needed(ddata))
1205 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001206err_allow_idle:
1207 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001208
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001209 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001210}
1211
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001212static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001213{
1214 struct sysc *ddata;
1215
1216 ddata = dev_get_drvdata(dev);
1217
Tony Lindgren40d9f912018-09-24 12:16:54 -07001218 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001219 return 0;
1220
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001221 return pm_runtime_force_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001222}
1223
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001224static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001225{
1226 struct sysc *ddata;
1227
1228 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001229
Tony Lindgren40d9f912018-09-24 12:16:54 -07001230 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
Tony Lindgrene7420c22018-04-16 10:26:46 -07001231 return 0;
1232
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001233 return pm_runtime_force_resume(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001234}
1235
Tony Lindgren0eecc632017-10-10 14:23:43 -07001236static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001237 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001238 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1239 sysc_runtime_resume,
1240 NULL)
1241};
1242
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001243/* Module revision register based quirks */
1244struct sysc_revision_quirk {
1245 const char *name;
1246 u32 base;
1247 int rev_offset;
1248 int sysc_offset;
1249 int syss_offset;
1250 u32 revision;
1251 u32 revision_mask;
1252 u32 quirks;
1253};
1254
1255#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1256 optrev_val, optrevmask, optquirkmask) \
1257 { \
1258 .name = (optname), \
1259 .base = (optbase), \
1260 .rev_offset = (optrev), \
1261 .sysc_offset = (optsysc), \
1262 .syss_offset = (optsyss), \
1263 .revision = (optrev_val), \
1264 .revision_mask = (optrevmask), \
1265 .quirks = (optquirkmask), \
1266 }
1267
1268static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1269 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001270 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001271 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001272 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1273 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001274 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001275 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001276 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001277 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001278 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1279 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001280 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001281 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001282 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001283 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001284 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001285 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenb4a9a7a2019-03-21 13:27:08 -07001286 SYSC_QUIRK_SWSUP_SIDLE_ACT | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001287
Tony Lindgrena54275f2019-03-21 11:00:21 -07001288 /* Quirks that need to be set based on the module address */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001289 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
Tony Lindgrena54275f2019-03-21 11:00:21 -07001290 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1291 SYSC_QUIRK_SWSUP_SIDLE),
1292
Tony Lindgren4e23be42019-06-10 04:48:05 -07001293 /* Quirks that need to be set based on detected module */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001294 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
Tony Lindgren020003f2019-11-14 08:25:28 -08001295 SYSC_MODULE_QUIRK_AESS),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001296 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001297 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001298 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001299 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001300 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001301 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001302 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001303 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001304 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001305 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001306 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001307 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001308 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1309 SYSC_QUIRK_OPT_CLKS_NEEDED),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001310 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
1311 SYSC_MODULE_QUIRK_HDQ1W),
1312 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
1313 SYSC_MODULE_QUIRK_HDQ1W),
1314 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
1315 SYSC_MODULE_QUIRK_I2C),
1316 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
1317 SYSC_MODULE_QUIRK_I2C),
1318 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
1319 SYSC_MODULE_QUIRK_I2C),
1320 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
1321 SYSC_MODULE_QUIRK_I2C),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001322 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1323 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001324 SYSC_MODULE_QUIRK_SGX),
Tony Lindgrenaef067e2020-03-10 09:06:02 -07001325 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1326 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrene8639e12020-02-24 12:58:03 -08001327 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1328 SYSC_MODULE_QUIRK_RTC_UNLOCK),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001329 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1330 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1331 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1332 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren42546322020-07-13 09:59:47 -07001333 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1334 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1335 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1336 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren03856e92019-10-21 13:36:09 -07001337 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1338 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001339 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
Tony Lindgren1819ef22019-10-21 14:15:55 -07001340 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001341 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1342 SYSC_MODULE_QUIRK_WDT),
Suman Annab2745d92020-02-27 16:28:34 -06001343 /* PRUSS on am3, am4 and am5 */
1344 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1345 SYSC_MODULE_QUIRK_PRUSS),
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001346 /* Watchdog on am3 and am4 */
1347 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1348 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001349
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001350#ifdef DEBUG
Tony Lindgren590e15c2020-02-24 12:58:03 -08001351 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1352 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1353 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1354 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001355 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001356 0xffff00f0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001357 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1358 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001359 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1360 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1361 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001362 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001363 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1364 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1365 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1366 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001367 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
Tony Lindgren7edd00f2019-08-14 05:18:16 -07001368 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1369 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001370 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1371 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1372 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001373 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001374 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001375 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001376 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff, 0),
1377 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1378 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1379 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001380 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001381 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1382 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001383 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001384 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1385 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1386 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
1387 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1388 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1389 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001390 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1391 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001392 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1393 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1394 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1395 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1396 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1397 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001398 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001399 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001400 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1401 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
1402 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1403 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
Tony Lindgren1a542812020-05-07 09:43:08 -07001404 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1405 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1406 /* Some timers on omap4 and later */
1407 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1408 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1409 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1410 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001411 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001412 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001413 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001414 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001415 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001416 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001417#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001418};
1419
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001420/*
1421 * Early quirks based on module base and register offsets only that are
1422 * needed before the module revision can be read
1423 */
1424static void sysc_init_early_quirks(struct sysc *ddata)
1425{
1426 const struct sysc_revision_quirk *q;
1427 int i;
1428
1429 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1430 q = &sysc_revision_quirks[i];
1431
1432 if (!q->base)
1433 continue;
1434
1435 if (q->base != ddata->module_pa)
1436 continue;
1437
Tony Lindgren590e15c2020-02-24 12:58:03 -08001438 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001439 continue;
1440
Tony Lindgren590e15c2020-02-24 12:58:03 -08001441 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001442 continue;
1443
Tony Lindgren590e15c2020-02-24 12:58:03 -08001444 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001445 continue;
1446
1447 ddata->name = q->name;
1448 ddata->cfg.quirks |= q->quirks;
1449 }
1450}
1451
1452/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001453static void sysc_init_revision_quirks(struct sysc *ddata)
1454{
1455 const struct sysc_revision_quirk *q;
1456 int i;
1457
1458 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1459 q = &sysc_revision_quirks[i];
1460
1461 if (q->base && q->base != ddata->module_pa)
1462 continue;
1463
Tony Lindgren590e15c2020-02-24 12:58:03 -08001464 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001465 continue;
1466
Tony Lindgren590e15c2020-02-24 12:58:03 -08001467 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001468 continue;
1469
Tony Lindgren590e15c2020-02-24 12:58:03 -08001470 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001471 continue;
1472
1473 if (q->revision == ddata->revision ||
1474 (q->revision & q->revision_mask) ==
1475 (ddata->revision & q->revision_mask)) {
1476 ddata->name = q->name;
1477 ddata->cfg.quirks |= q->quirks;
1478 }
1479 }
1480}
1481
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001482/*
1483 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1484 * enabled DSS interrupts. Eventually we may be able to do this on
1485 * dispc init rather than top-level DSS init.
1486 */
1487static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1488 bool disable)
1489{
1490 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1491 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1492 int manager_count;
1493 bool framedonetv_irq;
1494 u32 val, irq_mask = 0;
1495
1496 switch (sysc_soc->soc) {
1497 case SOC_2420 ... SOC_3630:
1498 manager_count = 2;
1499 framedonetv_irq = false;
1500 break;
1501 case SOC_4430 ... SOC_4470:
1502 manager_count = 3;
1503 break;
1504 case SOC_5430:
1505 case SOC_DRA7:
1506 manager_count = 4;
1507 break;
1508 case SOC_AM4:
1509 manager_count = 1;
1510 break;
1511 case SOC_UNKNOWN:
1512 default:
1513 return 0;
1514 };
1515
1516 /* Remap the whole module range to be able to reset dispc outputs */
1517 devm_iounmap(ddata->dev, ddata->module_va);
1518 ddata->module_va = devm_ioremap(ddata->dev,
1519 ddata->module_pa,
1520 ddata->module_size);
1521 if (!ddata->module_va)
1522 return -EIO;
1523
1524 /* DISP_CONTROL */
1525 val = sysc_read(ddata, dispc_offset + 0x40);
1526 lcd_en = val & lcd_en_mask;
1527 digit_en = val & digit_en_mask;
1528 if (lcd_en)
1529 irq_mask |= BIT(0); /* FRAMEDONE */
1530 if (digit_en) {
1531 if (framedonetv_irq)
1532 irq_mask |= BIT(24); /* FRAMEDONETV */
1533 else
1534 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1535 }
1536 if (disable & (lcd_en | digit_en))
1537 sysc_write(ddata, dispc_offset + 0x40,
1538 val & ~(lcd_en_mask | digit_en_mask));
1539
1540 if (manager_count <= 2)
1541 return irq_mask;
1542
1543 /* DISPC_CONTROL2 */
1544 val = sysc_read(ddata, dispc_offset + 0x238);
1545 lcd2_en = val & lcd_en_mask;
1546 if (lcd2_en)
1547 irq_mask |= BIT(22); /* FRAMEDONE2 */
1548 if (disable && lcd2_en)
1549 sysc_write(ddata, dispc_offset + 0x238,
1550 val & ~lcd_en_mask);
1551
1552 if (manager_count <= 3)
1553 return irq_mask;
1554
1555 /* DISPC_CONTROL3 */
1556 val = sysc_read(ddata, dispc_offset + 0x848);
1557 lcd3_en = val & lcd_en_mask;
1558 if (lcd3_en)
1559 irq_mask |= BIT(30); /* FRAMEDONE3 */
1560 if (disable && lcd3_en)
1561 sysc_write(ddata, dispc_offset + 0x848,
1562 val & ~lcd_en_mask);
1563
1564 return irq_mask;
1565}
1566
1567/* DSS needs child outputs disabled and SDI registers cleared for reset */
1568static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1569{
1570 const int dispc_offset = 0x1000;
1571 int error;
1572 u32 irq_mask, val;
1573
1574 /* Get enabled outputs */
1575 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1576 if (!irq_mask)
1577 return;
1578
1579 /* Clear IRQSTATUS */
Tony Lindgren69e60902020-03-03 07:17:43 -08001580 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001581
1582 /* Disable outputs */
1583 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1584
1585 /* Poll IRQSTATUS */
1586 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1587 val, val != irq_mask, 100, 50);
1588 if (error)
1589 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1590 __func__, val, irq_mask);
1591
1592 if (sysc_soc->soc == SOC_3430) {
1593 /* Clear DSS_SDI_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001594 sysc_write(ddata, 0x44, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001595
1596 /* Clear DSS_PLL_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001597 sysc_write(ddata, 0x48, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001598 }
1599
1600 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
Tony Lindgren69e60902020-03-03 07:17:43 -08001601 sysc_write(ddata, 0x40, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001602}
1603
Tony Lindgren4e23be42019-06-10 04:48:05 -07001604/* 1-wire needs module's internal clocks enabled for reset */
Tony Lindgrenaec551c2020-02-24 12:58:03 -08001605static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001606{
1607 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1608 u16 val;
1609
1610 val = sysc_read(ddata, offset);
1611 val |= BIT(5);
1612 sysc_write(ddata, offset, val);
1613}
1614
Tony Lindgren020003f2019-11-14 08:25:28 -08001615/* AESS (Audio Engine SubSystem) needs autogating set after enable */
1616static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1617{
1618 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1619
1620 sysc_write(ddata, offset, 1);
1621}
1622
Tony Lindgrene64c0212020-02-24 12:58:03 -08001623/* I2C needs to be disabled for reset */
Tony Lindgren4e23be42019-06-10 04:48:05 -07001624static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1625{
1626 int offset;
1627 u16 val;
1628
1629 /* I2C_CON, omap2/3 is different from omap4 and later */
1630 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1631 offset = 0x24;
1632 else
1633 offset = 0xa4;
1634
1635 /* I2C_EN */
1636 val = sysc_read(ddata, offset);
1637 if (enable)
1638 val |= BIT(15);
1639 else
1640 val &= ~BIT(15);
1641 sysc_write(ddata, offset, val);
1642}
1643
Tony Lindgrene64c0212020-02-24 12:58:03 -08001644static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001645{
1646 sysc_clk_quirk_i2c(ddata, false);
1647}
1648
Tony Lindgrene64c0212020-02-24 12:58:03 -08001649static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1650{
1651 sysc_clk_quirk_i2c(ddata, true);
1652}
1653
Tony Lindgrene8639e12020-02-24 12:58:03 -08001654/* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1655static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1656{
1657 u32 val, kick0_val = 0, kick1_val = 0;
1658 unsigned long flags;
1659 int error;
1660
1661 if (!lock) {
1662 kick0_val = 0x83e70b13;
1663 kick1_val = 0x95a4f1e0;
1664 }
1665
1666 local_irq_save(flags);
1667 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
1668 error = readl_poll_timeout(ddata->module_va + 0x44, val,
1669 !(val & BIT(0)), 100, 50);
1670 if (error)
1671 dev_warn(ddata->dev, "rtc busy timeout\n");
1672 /* Now we have ~15 microseconds to read/write various registers */
1673 sysc_write(ddata, 0x6c, kick0_val);
1674 sysc_write(ddata, 0x70, kick1_val);
1675 local_irq_restore(flags);
1676}
1677
1678static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1679{
1680 sysc_quirk_rtc(ddata, false);
1681}
1682
1683static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1684{
1685 sysc_quirk_rtc(ddata, true);
1686}
1687
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001688/* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1689static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1690{
1691 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1692 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1693
1694 sysc_write(ddata, offset, val);
1695}
1696
Tony Lindgren4e23be42019-06-10 04:48:05 -07001697/* Watchdog timer needs a disable sequence after reset */
1698static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1699{
1700 int wps, spr, error;
1701 u32 val;
1702
1703 wps = 0x34;
1704 spr = 0x48;
1705
1706 sysc_write(ddata, spr, 0xaaaa);
1707 error = readl_poll_timeout(ddata->module_va + wps, val,
1708 !(val & 0x10), 100,
1709 MAX_MODULE_SOFTRESET_WAIT);
1710 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001711 dev_warn(ddata->dev, "wdt disable step1 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001712
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001713 sysc_write(ddata, spr, 0x5555);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001714 error = readl_poll_timeout(ddata->module_va + wps, val,
1715 !(val & 0x10), 100,
1716 MAX_MODULE_SOFTRESET_WAIT);
1717 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001718 dev_warn(ddata->dev, "wdt disable step2 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001719}
1720
Suman Annab2745d92020-02-27 16:28:34 -06001721/* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
1722static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
1723{
1724 u32 reg;
1725
1726 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1727 reg |= SYSC_PRUSS_STANDBY_INIT;
1728 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1729}
1730
Tony Lindgren4e23be42019-06-10 04:48:05 -07001731static void sysc_init_module_quirks(struct sysc *ddata)
1732{
1733 if (ddata->legacy_mode || !ddata->name)
1734 return;
1735
1736 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001737 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001738
1739 return;
1740 }
1741
1742 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001743 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
1744 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001745
1746 return;
1747 }
1748
Tony Lindgren020003f2019-11-14 08:25:28 -08001749 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
1750 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
1751
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001752 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
1753 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
1754
Tony Lindgrene8639e12020-02-24 12:58:03 -08001755 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
1756 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
1757 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
1758
1759 return;
1760 }
1761
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001762 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
1763 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
1764
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001765 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
Tony Lindgren4e23be42019-06-10 04:48:05 -07001766 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001767 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
1768 }
Suman Annab2745d92020-02-27 16:28:34 -06001769
1770 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
1771 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001772}
1773
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001774static int sysc_clockdomain_init(struct sysc *ddata)
1775{
1776 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1777 struct clk *fck = NULL, *ick = NULL;
1778 int error;
1779
1780 if (!pdata || !pdata->init_clockdomain)
1781 return 0;
1782
1783 switch (ddata->nr_clocks) {
1784 case 2:
1785 ick = ddata->clocks[SYSC_ICK];
1786 /* fallthrough */
1787 case 1:
1788 fck = ddata->clocks[SYSC_FCK];
1789 break;
1790 case 0:
1791 return 0;
1792 }
1793
1794 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1795 if (!error || error == -ENODEV)
1796 return 0;
1797
1798 return error;
1799}
1800
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001801/*
1802 * Note that pdata->init_module() typically does a reset first. After
1803 * pdata->init_module() is done, PM runtime can be used for the interconnect
1804 * target module.
1805 */
1806static int sysc_legacy_init(struct sysc *ddata)
1807{
1808 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1809 int error;
1810
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001811 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001812 return 0;
1813
1814 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
1815 if (error == -EEXIST)
1816 error = 0;
1817
1818 return error;
1819}
1820
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001821/*
1822 * Note that the caller must ensure the interconnect target module is enabled
1823 * before calling reset. Otherwise reset will not complete.
1824 */
Faiz Abbas596e7952018-07-09 22:18:39 +05301825static int sysc_reset(struct sysc *ddata)
1826{
YueHaibingc8a738f2019-06-28 12:10:54 +08001827 int sysc_offset, syss_offset, sysc_val, rstval, error = 0;
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001828 u32 sysc_mask, syss_done;
Faiz Abbas596e7952018-07-09 22:18:39 +05301829
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001830 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
1831 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001832
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08001833 if (ddata->legacy_mode ||
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001834 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05301835 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
1836 return 0;
1837
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001838 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05301839
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001840 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
1841 syss_done = 0;
1842 else
1843 syss_done = ddata->cfg.syss_mask;
1844
Tony Lindgrene64c0212020-02-24 12:58:03 -08001845 if (ddata->pre_reset_quirk)
1846 ddata->pre_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001847
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08001848 if (sysc_offset >= 0) {
1849 sysc_val = sysc_read_sysconfig(ddata);
1850 sysc_val |= sysc_mask;
1851 sysc_write(ddata, sysc_offset, sysc_val);
1852 }
Faiz Abbas596e7952018-07-09 22:18:39 +05301853
Tony Lindgrene709ed72019-12-12 08:20:10 -08001854 if (ddata->cfg.srst_udelay)
1855 usleep_range(ddata->cfg.srst_udelay,
1856 ddata->cfg.srst_udelay * 2);
1857
Tony Lindgrene64c0212020-02-24 12:58:03 -08001858 if (ddata->post_reset_quirk)
1859 ddata->post_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001860
Faiz Abbas596e7952018-07-09 22:18:39 +05301861 /* Poll on reset status */
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001862 if (syss_offset >= 0) {
1863 error = readx_poll_timeout(sysc_read_sysstatus, ddata, rstval,
1864 (rstval & ddata->cfg.syss_mask) ==
1865 syss_done,
1866 100, MAX_MODULE_SOFTRESET_WAIT);
Faiz Abbas596e7952018-07-09 22:18:39 +05301867
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001868 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
1869 error = readx_poll_timeout(sysc_read_sysconfig, ddata, rstval,
1870 !(rstval & sysc_mask),
1871 100, MAX_MODULE_SOFTRESET_WAIT);
1872 }
1873
Tony Lindgren4e23be42019-06-10 04:48:05 -07001874 if (ddata->reset_done_quirk)
1875 ddata->reset_done_quirk(ddata);
1876
Tony Lindgrene0db94f2019-05-27 04:51:53 -07001877 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05301878}
1879
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001880/*
1881 * At this point the module is configured enough to read the revision but
1882 * module may not be completely configured yet to use PM runtime. Enable
1883 * all clocks directly during init to configure the quirks needed for PM
1884 * runtime based on the revision register.
1885 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08001886static int sysc_init_module(struct sysc *ddata)
1887{
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001888 int error = 0;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001889
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001890 error = sysc_clockdomain_init(ddata);
1891 if (error)
1892 return error;
1893
Tony Lindgrend0989132019-09-05 07:37:22 -07001894 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001895
Tony Lindgrend0989132019-09-05 07:37:22 -07001896 /*
1897 * Always enable clocks. The bootloader may or may not have enabled
1898 * the related clocks.
1899 */
1900 error = sysc_enable_opt_clocks(ddata);
1901 if (error)
1902 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001903
Tony Lindgrend0989132019-09-05 07:37:22 -07001904 error = sysc_enable_main_clocks(ddata);
1905 if (error)
1906 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05301907
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001908 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
Tero Kristodf4f3452019-10-07 15:29:30 +03001909 error = reset_control_deassert(ddata->rsts);
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07001910 if (error)
1911 goto err_main_clocks;
1912 }
1913
Tony Lindgren566a9b052017-12-15 09:41:19 -08001914 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001915 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001916 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001917
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001918 if (ddata->legacy_mode) {
1919 error = sysc_legacy_init(ddata);
1920 if (error)
Tero Kristocdc56c12019-10-07 15:29:31 +03001921 goto err_reset;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001922 }
1923
Tony Lindgrend0989132019-09-05 07:37:22 -07001924 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001925 error = sysc_enable_module(ddata->dev);
1926 if (error)
Tero Kristocdc56c12019-10-07 15:29:31 +03001927 goto err_reset;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001928 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001929
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001930 error = sysc_reset(ddata);
1931 if (error)
1932 dev_err(ddata->dev, "Reset failed with %d\n", error);
1933
Tero Kristocdc56c12019-10-07 15:29:31 +03001934 if (error && !ddata->legacy_mode)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001935 sysc_disable_module(ddata->dev);
1936
Tero Kristocdc56c12019-10-07 15:29:31 +03001937err_reset:
1938 if (error && !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
1939 reset_control_assert(ddata->rsts);
1940
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001941err_main_clocks:
Tero Kristocdc56c12019-10-07 15:29:31 +03001942 if (error)
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001943 sysc_disable_main_clocks(ddata);
1944err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07001945 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tero Kristocdc56c12019-10-07 15:29:31 +03001946 if (error) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001947 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001948 sysc_clkdm_allow_idle(ddata);
1949 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07001950
1951 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08001952}
1953
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001954static int sysc_init_sysc_mask(struct sysc *ddata)
1955{
1956 struct device_node *np = ddata->dev->of_node;
1957 int error;
1958 u32 val;
1959
1960 error = of_property_read_u32(np, "ti,sysc-mask", &val);
1961 if (error)
1962 return 0;
1963
Tony Lindgrene212abd2019-07-22 03:44:52 -07001964 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08001965
1966 return 0;
1967}
1968
1969static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
1970 const char *name)
1971{
1972 struct device_node *np = ddata->dev->of_node;
1973 struct property *prop;
1974 const __be32 *p;
1975 u32 val;
1976
1977 of_property_for_each_u32(np, name, prop, p, val) {
1978 if (val >= SYSC_NR_IDLEMODES) {
1979 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
1980 return -EINVAL;
1981 }
1982 *idlemodes |= (1 << val);
1983 }
1984
1985 return 0;
1986}
1987
1988static int sysc_init_idlemodes(struct sysc *ddata)
1989{
1990 int error;
1991
1992 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
1993 "ti,sysc-midle");
1994 if (error)
1995 return error;
1996
1997 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
1998 "ti,sysc-sidle");
1999 if (error)
2000 return error;
2001
2002 return 0;
2003}
2004
2005/*
2006 * Only some devices on omap4 and later have SYSCONFIG reset done
2007 * bit. We can detect this if there is no SYSSTATUS at all, or the
2008 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2009 * have multiple bits for the child devices like OHCI and EHCI.
2010 * Depends on SYSC being parsed first.
2011 */
2012static int sysc_init_syss_mask(struct sysc *ddata)
2013{
2014 struct device_node *np = ddata->dev->of_node;
2015 int error;
2016 u32 val;
2017
2018 error = of_property_read_u32(np, "ti,syss-mask", &val);
2019 if (error) {
2020 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2021 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2022 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2023 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2024
2025 return 0;
2026 }
2027
2028 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2029 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2030
2031 ddata->cfg.syss_mask = val;
2032
2033 return 0;
2034}
2035
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002036/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002037 * Many child device drivers need to have fck and opt clocks available
2038 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002039 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002040static int sysc_child_add_named_clock(struct sysc *ddata,
2041 struct device *child,
2042 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002043{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002044 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002045 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002046 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002047
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002048 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002049 return 0;
2050
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002051 clk = clk_get(child, name);
2052 if (!IS_ERR(clk)) {
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002053 error = -EEXIST;
2054 goto put_clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002055 }
2056
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002057 clk = clk_get(ddata->dev, name);
2058 if (IS_ERR(clk))
2059 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002060
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002061 l = clkdev_create(clk, name, dev_name(child));
2062 if (!l)
2063 error = -ENOMEM;
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002064put_clk:
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002065 clk_put(clk);
2066
2067 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002068}
2069
Tony Lindgren09dfe582018-04-16 10:25:52 -07002070static int sysc_child_add_clocks(struct sysc *ddata,
2071 struct device *child)
2072{
2073 int i, error;
2074
2075 for (i = 0; i < ddata->nr_clocks; i++) {
2076 error = sysc_child_add_named_clock(ddata,
2077 child,
2078 ddata->clock_roles[i]);
2079 if (error && error != -EEXIST) {
2080 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2081 ddata->clock_roles[i], error);
2082
2083 return error;
2084 }
2085 }
2086
2087 return 0;
2088}
2089
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002090static struct device_type sysc_device_type = {
2091};
2092
2093static struct sysc *sysc_child_to_parent(struct device *dev)
2094{
2095 struct device *parent = dev->parent;
2096
2097 if (!parent || parent->type != &sysc_device_type)
2098 return NULL;
2099
2100 return dev_get_drvdata(parent);
2101}
2102
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002103static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2104{
2105 struct sysc *ddata;
2106 int error;
2107
2108 ddata = sysc_child_to_parent(dev);
2109
2110 error = pm_generic_runtime_suspend(dev);
2111 if (error)
2112 return error;
2113
2114 if (!ddata->enabled)
2115 return 0;
2116
2117 return sysc_runtime_suspend(ddata->dev);
2118}
2119
2120static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2121{
2122 struct sysc *ddata;
2123 int error;
2124
2125 ddata = sysc_child_to_parent(dev);
2126
2127 if (!ddata->enabled) {
2128 error = sysc_runtime_resume(ddata->dev);
2129 if (error < 0)
2130 dev_err(ddata->dev,
2131 "%s error: %i\n", __func__, error);
2132 }
2133
2134 return pm_generic_runtime_resume(dev);
2135}
2136
2137#ifdef CONFIG_PM_SLEEP
2138static int sysc_child_suspend_noirq(struct device *dev)
2139{
2140 struct sysc *ddata;
2141 int error;
2142
2143 ddata = sysc_child_to_parent(dev);
2144
Tony Lindgrenef55f822018-04-16 10:27:15 -07002145 dev_dbg(ddata->dev, "%s %s\n", __func__,
2146 ddata->name ? ddata->name : "");
2147
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002148 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002149 if (error) {
2150 dev_err(dev, "%s error at %i: %i\n",
2151 __func__, __LINE__, error);
2152
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002153 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002154 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002155
2156 if (!pm_runtime_status_suspended(dev)) {
2157 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002158 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07002159 dev_dbg(dev, "%s busy at %i: %i\n",
2160 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002161
Tony Lindgren4f3530f2018-08-08 01:07:06 -07002162 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002163 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002164
2165 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002166 if (error) {
2167 dev_err(dev, "%s error at %i: %i\n",
2168 __func__, __LINE__, error);
2169
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002170 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002171 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002172
2173 ddata->child_needs_resume = true;
2174 }
2175
2176 return 0;
2177}
2178
2179static int sysc_child_resume_noirq(struct device *dev)
2180{
2181 struct sysc *ddata;
2182 int error;
2183
2184 ddata = sysc_child_to_parent(dev);
2185
Tony Lindgrenef55f822018-04-16 10:27:15 -07002186 dev_dbg(ddata->dev, "%s %s\n", __func__,
2187 ddata->name ? ddata->name : "");
2188
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002189 if (ddata->child_needs_resume) {
2190 ddata->child_needs_resume = false;
2191
2192 error = sysc_runtime_resume(ddata->dev);
2193 if (error)
2194 dev_err(ddata->dev,
2195 "%s runtime resume error: %i\n",
2196 __func__, error);
2197
2198 error = pm_generic_runtime_resume(dev);
2199 if (error)
2200 dev_err(ddata->dev,
2201 "%s generic runtime resume: %i\n",
2202 __func__, error);
2203 }
2204
2205 return pm_generic_resume_noirq(dev);
2206}
2207#endif
2208
Tony Lindgrenb7182b42019-03-21 11:00:21 -07002209static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002210 .ops = {
2211 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2212 sysc_child_runtime_resume,
2213 NULL)
2214 USE_PLATFORM_PM_SLEEP_OPS
2215 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2216 sysc_child_resume_noirq)
2217 }
2218};
2219
2220/**
2221 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2222 * @ddata: device driver data
2223 * @child: child device driver
2224 *
2225 * Allow idle for child devices as done with _od_runtime_suspend().
2226 * Otherwise many child devices will not idle because of the permanent
2227 * parent usecount set in pm_runtime_irq_safe().
2228 *
2229 * Note that the long term solution is to just modify the child device
2230 * drivers to not set pm_runtime_irq_safe() and then this can be just
2231 * dropped.
2232 */
2233static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2234{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002235 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2236 dev_pm_domain_set(child, &sysc_child_pm_domain);
2237}
2238
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002239static int sysc_notifier_call(struct notifier_block *nb,
2240 unsigned long event, void *device)
2241{
2242 struct device *dev = device;
2243 struct sysc *ddata;
2244 int error;
2245
2246 ddata = sysc_child_to_parent(dev);
2247 if (!ddata)
2248 return NOTIFY_DONE;
2249
2250 switch (event) {
2251 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07002252 error = sysc_child_add_clocks(ddata, dev);
2253 if (error)
2254 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002255 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002256 break;
2257 default:
2258 break;
2259 }
2260
2261 return NOTIFY_DONE;
2262}
2263
2264static struct notifier_block sysc_nb = {
2265 .notifier_call = sysc_notifier_call,
2266};
2267
Tony Lindgren566a9b052017-12-15 09:41:19 -08002268/* Device tree configured quirks */
2269struct sysc_dts_quirk {
2270 const char *name;
2271 u32 mask;
2272};
2273
2274static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2275 { .name = "ti,no-idle-on-init",
2276 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2277 { .name = "ti,no-reset-on-init",
2278 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002279 { .name = "ti,no-idle",
2280 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002281};
2282
Tony Lindgren4014c082018-12-10 14:11:26 -08002283static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2284 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002285{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002286 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002287 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002288
2289 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002290 const char *name = sysc_dts_quirks[i].name;
2291
2292 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002293 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002294 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002295
2296 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002297 if (is_child) {
2298 dev_warn(ddata->dev,
2299 "dts flag should be at module level for %s\n",
2300 name);
2301 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002302 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002303}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002304
Tony Lindgren4014c082018-12-10 14:11:26 -08002305static int sysc_init_dts_quirks(struct sysc *ddata)
2306{
2307 struct device_node *np = ddata->dev->of_node;
2308 int error;
2309 u32 val;
2310
2311 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2312
2313 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002314 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2315 if (!error) {
2316 if (val > 255) {
2317 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2318 val);
2319 }
2320
2321 ddata->cfg.srst_udelay = (u8)val;
2322 }
2323
2324 return 0;
2325}
2326
Tony Lindgren0eecc632017-10-10 14:23:43 -07002327static void sysc_unprepare(struct sysc *ddata)
2328{
2329 int i;
2330
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002331 if (!ddata->clocks)
2332 return;
2333
Tony Lindgren0eecc632017-10-10 14:23:43 -07002334 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2335 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2336 clk_unprepare(ddata->clocks[i]);
2337 }
2338}
2339
Tony Lindgren70a65242017-12-15 09:41:09 -08002340/*
2341 * Common sysc register bits found on omap2, also known as type1
2342 */
2343static const struct sysc_regbits sysc_regbits_omap2 = {
2344 .dmadisable_shift = -ENODEV,
2345 .midle_shift = 12,
2346 .sidle_shift = 3,
2347 .clkact_shift = 8,
2348 .emufree_shift = 5,
2349 .enwkup_shift = 2,
2350 .srst_shift = 1,
2351 .autoidle_shift = 0,
2352};
2353
2354static const struct sysc_capabilities sysc_omap2 = {
2355 .type = TI_SYSC_OMAP2,
2356 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2357 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2358 SYSC_OMAP2_AUTOIDLE,
2359 .regbits = &sysc_regbits_omap2,
2360};
2361
2362/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2363static const struct sysc_capabilities sysc_omap2_timer = {
2364 .type = TI_SYSC_OMAP2_TIMER,
2365 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2366 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2367 SYSC_OMAP2_AUTOIDLE,
2368 .regbits = &sysc_regbits_omap2,
2369 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2370};
2371
2372/*
2373 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2374 * with different sidle position
2375 */
2376static const struct sysc_regbits sysc_regbits_omap3_sham = {
2377 .dmadisable_shift = -ENODEV,
2378 .midle_shift = -ENODEV,
2379 .sidle_shift = 4,
2380 .clkact_shift = -ENODEV,
2381 .enwkup_shift = -ENODEV,
2382 .srst_shift = 1,
2383 .autoidle_shift = 0,
2384 .emufree_shift = -ENODEV,
2385};
2386
2387static const struct sysc_capabilities sysc_omap3_sham = {
2388 .type = TI_SYSC_OMAP3_SHAM,
2389 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2390 .regbits = &sysc_regbits_omap3_sham,
2391};
2392
2393/*
2394 * AES register bits found on omap3 and later, a variant of
2395 * sysc_regbits_omap2 with different sidle position
2396 */
2397static const struct sysc_regbits sysc_regbits_omap3_aes = {
2398 .dmadisable_shift = -ENODEV,
2399 .midle_shift = -ENODEV,
2400 .sidle_shift = 6,
2401 .clkact_shift = -ENODEV,
2402 .enwkup_shift = -ENODEV,
2403 .srst_shift = 1,
2404 .autoidle_shift = 0,
2405 .emufree_shift = -ENODEV,
2406};
2407
2408static const struct sysc_capabilities sysc_omap3_aes = {
2409 .type = TI_SYSC_OMAP3_AES,
2410 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2411 .regbits = &sysc_regbits_omap3_aes,
2412};
2413
2414/*
2415 * Common sysc register bits found on omap4, also known as type2
2416 */
2417static const struct sysc_regbits sysc_regbits_omap4 = {
2418 .dmadisable_shift = 16,
2419 .midle_shift = 4,
2420 .sidle_shift = 2,
2421 .clkact_shift = -ENODEV,
2422 .enwkup_shift = -ENODEV,
2423 .emufree_shift = 1,
2424 .srst_shift = 0,
2425 .autoidle_shift = -ENODEV,
2426};
2427
2428static const struct sysc_capabilities sysc_omap4 = {
2429 .type = TI_SYSC_OMAP4,
2430 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2431 SYSC_OMAP4_SOFTRESET,
2432 .regbits = &sysc_regbits_omap4,
2433};
2434
2435static const struct sysc_capabilities sysc_omap4_timer = {
2436 .type = TI_SYSC_OMAP4_TIMER,
2437 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2438 SYSC_OMAP4_SOFTRESET,
2439 .regbits = &sysc_regbits_omap4,
2440};
2441
2442/*
2443 * Common sysc register bits found on omap4, also known as type3
2444 */
2445static const struct sysc_regbits sysc_regbits_omap4_simple = {
2446 .dmadisable_shift = -ENODEV,
2447 .midle_shift = 2,
2448 .sidle_shift = 0,
2449 .clkact_shift = -ENODEV,
2450 .enwkup_shift = -ENODEV,
2451 .srst_shift = -ENODEV,
2452 .emufree_shift = -ENODEV,
2453 .autoidle_shift = -ENODEV,
2454};
2455
2456static const struct sysc_capabilities sysc_omap4_simple = {
2457 .type = TI_SYSC_OMAP4_SIMPLE,
2458 .regbits = &sysc_regbits_omap4_simple,
2459};
2460
2461/*
2462 * SmartReflex sysc found on omap34xx
2463 */
2464static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2465 .dmadisable_shift = -ENODEV,
2466 .midle_shift = -ENODEV,
2467 .sidle_shift = -ENODEV,
2468 .clkact_shift = 20,
2469 .enwkup_shift = -ENODEV,
2470 .srst_shift = -ENODEV,
2471 .emufree_shift = -ENODEV,
2472 .autoidle_shift = -ENODEV,
2473};
2474
2475static const struct sysc_capabilities sysc_34xx_sr = {
2476 .type = TI_SYSC_OMAP34XX_SR,
2477 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2478 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002479 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2480 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002481};
2482
2483/*
2484 * SmartReflex sysc found on omap36xx and later
2485 */
2486static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2487 .dmadisable_shift = -ENODEV,
2488 .midle_shift = -ENODEV,
2489 .sidle_shift = 24,
2490 .clkact_shift = -ENODEV,
2491 .enwkup_shift = 26,
2492 .srst_shift = -ENODEV,
2493 .emufree_shift = -ENODEV,
2494 .autoidle_shift = -ENODEV,
2495};
2496
2497static const struct sysc_capabilities sysc_36xx_sr = {
2498 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002499 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002500 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002501 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002502};
2503
2504static const struct sysc_capabilities sysc_omap4_sr = {
2505 .type = TI_SYSC_OMAP4_SR,
2506 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002507 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002508};
2509
2510/*
2511 * McASP register bits found on omap4 and later
2512 */
2513static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2514 .dmadisable_shift = -ENODEV,
2515 .midle_shift = -ENODEV,
2516 .sidle_shift = 0,
2517 .clkact_shift = -ENODEV,
2518 .enwkup_shift = -ENODEV,
2519 .srst_shift = -ENODEV,
2520 .emufree_shift = -ENODEV,
2521 .autoidle_shift = -ENODEV,
2522};
2523
2524static const struct sysc_capabilities sysc_omap4_mcasp = {
2525 .type = TI_SYSC_OMAP4_MCASP,
2526 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002527 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2528};
2529
2530/*
2531 * McASP found on dra7 and later
2532 */
2533static const struct sysc_capabilities sysc_dra7_mcasp = {
2534 .type = TI_SYSC_OMAP4_SIMPLE,
2535 .regbits = &sysc_regbits_omap4_simple,
2536 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002537};
2538
2539/*
2540 * FS USB host found on omap4 and later
2541 */
2542static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2543 .dmadisable_shift = -ENODEV,
2544 .midle_shift = -ENODEV,
2545 .sidle_shift = 24,
2546 .clkact_shift = -ENODEV,
2547 .enwkup_shift = 26,
2548 .srst_shift = -ENODEV,
2549 .emufree_shift = -ENODEV,
2550 .autoidle_shift = -ENODEV,
2551};
2552
2553static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2554 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2555 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2556 .regbits = &sysc_regbits_omap4_usb_host_fs,
2557};
2558
Faiz Abbas7f35e632018-07-09 22:18:38 +05302559static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2560 .dmadisable_shift = -ENODEV,
2561 .midle_shift = -ENODEV,
2562 .sidle_shift = -ENODEV,
2563 .clkact_shift = -ENODEV,
2564 .enwkup_shift = 4,
2565 .srst_shift = 0,
2566 .emufree_shift = -ENODEV,
2567 .autoidle_shift = -ENODEV,
2568};
2569
2570static const struct sysc_capabilities sysc_dra7_mcan = {
2571 .type = TI_SYSC_DRA7_MCAN,
2572 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2573 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002574 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302575};
2576
Suman Annab2745d92020-02-27 16:28:34 -06002577/*
2578 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2579 */
2580static const struct sysc_capabilities sysc_pruss = {
2581 .type = TI_SYSC_PRUSS,
2582 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2583 .regbits = &sysc_regbits_omap4_simple,
2584 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2585};
2586
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002587static int sysc_init_pdata(struct sysc *ddata)
2588{
2589 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002590 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002591
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002592 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002593 return 0;
2594
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002595 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2596 if (!mdata)
2597 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002598
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002599 if (ddata->legacy_mode) {
2600 mdata->name = ddata->legacy_mode;
2601 mdata->module_pa = ddata->module_pa;
2602 mdata->module_size = ddata->module_size;
2603 mdata->offsets = ddata->offsets;
2604 mdata->nr_offsets = SYSC_MAX_REGS;
2605 mdata->cap = ddata->cap;
2606 mdata->cfg = &ddata->cfg;
2607 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002608
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002609 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002610
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002611 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002612}
2613
Tony Lindgren70a65242017-12-15 09:41:09 -08002614static int sysc_init_match(struct sysc *ddata)
2615{
2616 const struct sysc_capabilities *cap;
2617
2618 cap = of_device_get_match_data(ddata->dev);
2619 if (!cap)
2620 return -EINVAL;
2621
2622 ddata->cap = cap;
2623 if (ddata->cap)
2624 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2625
2626 return 0;
2627}
2628
Tony Lindgren76f0f772018-02-23 08:28:45 -08002629static void ti_sysc_idle(struct work_struct *work)
2630{
2631 struct sysc *ddata;
2632
2633 ddata = container_of(work, struct sysc, idle_work.work);
2634
Tony Lindgrend0989132019-09-05 07:37:22 -07002635 /*
2636 * One time decrement of clock usage counts if left on from init.
2637 * Note that we disable opt clocks unconditionally in this case
2638 * as they are enabled unconditionally during init without
2639 * considering sysc_opt_clks_needed() at that point.
2640 */
2641 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2642 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
Tony Lindgrend0989132019-09-05 07:37:22 -07002643 sysc_disable_main_clocks(ddata);
2644 sysc_disable_opt_clocks(ddata);
2645 sysc_clkdm_allow_idle(ddata);
2646 }
2647
2648 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2649 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2650 return;
2651
2652 /*
2653 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2654 * and SYSC_QUIRK_NO_RESET_ON_INIT
2655 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002656 if (pm_runtime_active(ddata->dev))
2657 pm_runtime_put_sync(ddata->dev);
2658}
2659
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002660/*
2661 * SoC model and features detection. Only needed for SoCs that need
2662 * special handling for quirks, no need to list others.
2663 */
2664static const struct soc_device_attribute sysc_soc_match[] = {
2665 SOC_FLAG("OMAP242*", SOC_2420),
2666 SOC_FLAG("OMAP243*", SOC_2430),
2667 SOC_FLAG("OMAP3[45]*", SOC_3430),
2668 SOC_FLAG("OMAP3[67]*", SOC_3630),
2669 SOC_FLAG("OMAP443*", SOC_4430),
2670 SOC_FLAG("OMAP446*", SOC_4460),
2671 SOC_FLAG("OMAP447*", SOC_4470),
2672 SOC_FLAG("OMAP54*", SOC_5430),
2673 SOC_FLAG("AM433", SOC_AM3),
2674 SOC_FLAG("AM43*", SOC_AM4),
2675 SOC_FLAG("DRA7*", SOC_DRA7),
2676
2677 { /* sentinel */ },
2678};
2679
2680/*
2681 * List of SoCs variants with disabled features. By default we assume all
2682 * devices in the device tree are available so no need to list those SoCs.
2683 */
2684static const struct soc_device_attribute sysc_soc_feat_match[] = {
2685 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
2686 SOC_FLAG("AM3505", DIS_SGX),
2687 SOC_FLAG("OMAP3525", DIS_SGX),
2688 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
2689 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
2690
2691 /* OMAP3630/DM3730 variants with some accelerators disabled */
2692 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
2693 SOC_FLAG("DM3725", DIS_SGX),
2694 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
2695 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
2696 SOC_FLAG("OMAP3621", DIS_ISP),
2697
2698 { /* sentinel */ },
2699};
2700
2701static int sysc_add_disabled(unsigned long base)
2702{
2703 struct sysc_address *disabled_module;
2704
2705 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
2706 if (!disabled_module)
2707 return -ENOMEM;
2708
2709 disabled_module->base = base;
2710
2711 mutex_lock(&sysc_soc->list_lock);
2712 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
2713 mutex_unlock(&sysc_soc->list_lock);
2714
2715 return 0;
2716}
2717
2718/*
2719 * One time init to detect the booted SoC and disable unavailable features.
2720 * Note that we initialize static data shared across all ti-sysc instances
2721 * so ddata is only used for SoC type. This can be called from module_init
2722 * once we no longer need to rely on platform data.
2723 */
2724static int sysc_init_soc(struct sysc *ddata)
2725{
2726 const struct soc_device_attribute *match;
2727 struct ti_sysc_platform_data *pdata;
2728 unsigned long features = 0;
2729
2730 if (sysc_soc)
2731 return 0;
2732
2733 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
2734 if (!sysc_soc)
2735 return -ENOMEM;
2736
2737 mutex_init(&sysc_soc->list_lock);
2738 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
2739 sysc_soc->general_purpose = true;
2740
2741 pdata = dev_get_platdata(ddata->dev);
2742 if (pdata && pdata->soc_type_gp)
2743 sysc_soc->general_purpose = pdata->soc_type_gp();
2744
2745 match = soc_device_match(sysc_soc_match);
2746 if (match && match->data)
2747 sysc_soc->soc = (int)match->data;
2748
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002749 /* Ignore devices that are not available on HS and EMU SoCs */
2750 if (!sysc_soc->general_purpose) {
2751 switch (sysc_soc->soc) {
2752 case SOC_3430 ... SOC_3630:
2753 sysc_add_disabled(0x48304000); /* timer12 */
2754 break;
2755 default:
2756 break;
2757 };
2758 }
2759
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002760 match = soc_device_match(sysc_soc_feat_match);
2761 if (!match)
2762 return 0;
2763
2764 if (match->data)
2765 features = (unsigned long)match->data;
2766
2767 /*
2768 * Add disabled devices to the list based on the module base.
2769 * Note that this must be done before we attempt to access the
2770 * device and have module revision checks working.
2771 */
2772 if (features & DIS_ISP)
2773 sysc_add_disabled(0x480bd400);
2774 if (features & DIS_IVA)
2775 sysc_add_disabled(0x5d000000);
2776 if (features & DIS_SGX)
2777 sysc_add_disabled(0x50000000);
2778
2779 return 0;
2780}
2781
2782static void sysc_cleanup_soc(void)
2783{
2784 struct sysc_address *disabled_module;
2785 struct list_head *pos, *tmp;
2786
2787 if (!sysc_soc)
2788 return;
2789
2790 mutex_lock(&sysc_soc->list_lock);
2791 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
2792 disabled_module = list_entry(pos, struct sysc_address, node);
2793 list_del(pos);
2794 kfree(disabled_module);
2795 }
2796 mutex_unlock(&sysc_soc->list_lock);
2797}
2798
2799static int sysc_check_disabled_devices(struct sysc *ddata)
2800{
2801 struct sysc_address *disabled_module;
2802 struct list_head *pos;
2803 int error = 0;
2804
2805 mutex_lock(&sysc_soc->list_lock);
2806 list_for_each(pos, &sysc_soc->disabled_modules) {
2807 disabled_module = list_entry(pos, struct sysc_address, node);
2808 if (ddata->module_pa == disabled_module->base) {
2809 dev_dbg(ddata->dev, "module disabled for this SoC\n");
2810 error = -ENODEV;
2811 break;
2812 }
2813 }
2814 mutex_unlock(&sysc_soc->list_lock);
2815
2816 return error;
2817}
2818
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002819static const struct of_device_id sysc_match_table[] = {
2820 { .compatible = "simple-bus", },
2821 { /* sentinel */ },
2822};
2823
Tony Lindgren0eecc632017-10-10 14:23:43 -07002824static int sysc_probe(struct platform_device *pdev)
2825{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002826 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002827 struct sysc *ddata;
2828 int error;
2829
2830 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
2831 if (!ddata)
2832 return -ENOMEM;
2833
2834 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002835 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002836
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002837 error = sysc_init_soc(ddata);
2838 if (error)
2839 return error;
2840
Tony Lindgren70a65242017-12-15 09:41:09 -08002841 error = sysc_init_match(ddata);
2842 if (error)
2843 return error;
2844
Tony Lindgren566a9b052017-12-15 09:41:19 -08002845 error = sysc_init_dts_quirks(ddata);
2846 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002847 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002848
Tony Lindgren0eecc632017-10-10 14:23:43 -07002849 error = sysc_map_and_check_registers(ddata);
2850 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002851 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07002852
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002853 error = sysc_init_sysc_mask(ddata);
2854 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002855 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002856
2857 error = sysc_init_idlemodes(ddata);
2858 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002859 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002860
2861 error = sysc_init_syss_mask(ddata);
2862 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002863 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002864
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002865 error = sysc_init_pdata(ddata);
2866 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002867 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002868
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002869 sysc_init_early_quirks(ddata);
2870
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002871 error = sysc_check_disabled_devices(ddata);
2872 if (error)
2873 return error;
2874
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07002875 error = sysc_get_clocks(ddata);
2876 if (error)
2877 return error;
2878
Tony Lindgren50622362018-04-16 10:20:27 -07002879 error = sysc_init_resets(ddata);
2880 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05002881 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002882
2883 error = sysc_init_module(ddata);
2884 if (error)
2885 goto unprepare;
2886
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002887 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002888 error = pm_runtime_get_sync(ddata->dev);
2889 if (error < 0) {
2890 pm_runtime_put_noidle(ddata->dev);
2891 pm_runtime_disable(ddata->dev);
2892 goto unprepare;
2893 }
2894
Tero Kristocdc56c12019-10-07 15:29:31 +03002895 /* Balance use counts as PM runtime should have enabled these all */
2896 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
Tero Kristobb88b862019-08-07 15:46:05 +03002897 reset_control_assert(ddata->rsts);
2898
Tero Kristocdc56c12019-10-07 15:29:31 +03002899 if (!(ddata->cfg.quirks &
2900 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
2901 sysc_disable_main_clocks(ddata);
2902 sysc_disable_opt_clocks(ddata);
2903 sysc_clkdm_allow_idle(ddata);
2904 }
2905
Tony Lindgren0eecc632017-10-10 14:23:43 -07002906 sysc_show_registers(ddata);
2907
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002908 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07002909 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
2910 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002911 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07002912 if (error)
2913 goto err;
2914
Tony Lindgren76f0f772018-02-23 08:28:45 -08002915 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
2916
2917 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07002918 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2919 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08002920 SYSC_QUIRK_NO_RESET_ON_INIT)) {
2921 schedule_delayed_work(&ddata->idle_work, 3000);
2922 } else {
2923 pm_runtime_put(&pdev->dev);
2924 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07002925
2926 return 0;
2927
2928err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07002929 pm_runtime_put_sync(&pdev->dev);
2930 pm_runtime_disable(&pdev->dev);
2931unprepare:
2932 sysc_unprepare(ddata);
2933
2934 return error;
2935}
2936
Tony Lindgren684be5a2017-10-13 10:48:40 -07002937static int sysc_remove(struct platform_device *pdev)
2938{
2939 struct sysc *ddata = platform_get_drvdata(pdev);
2940 int error;
2941
Tony Lindgren76f0f772018-02-23 08:28:45 -08002942 cancel_delayed_work_sync(&ddata->idle_work);
2943
Tony Lindgren684be5a2017-10-13 10:48:40 -07002944 error = pm_runtime_get_sync(ddata->dev);
2945 if (error < 0) {
2946 pm_runtime_put_noidle(ddata->dev);
2947 pm_runtime_disable(ddata->dev);
2948 goto unprepare;
2949 }
2950
2951 of_platform_depopulate(&pdev->dev);
2952
Tony Lindgren684be5a2017-10-13 10:48:40 -07002953 pm_runtime_put_sync(&pdev->dev);
2954 pm_runtime_disable(&pdev->dev);
Tony Lindgren50622362018-04-16 10:20:27 -07002955 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07002956
2957unprepare:
2958 sysc_unprepare(ddata);
2959
2960 return 0;
2961}
2962
Tony Lindgren0eecc632017-10-10 14:23:43 -07002963static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08002964 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
2965 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
2966 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
2967 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
2968 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
2969 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
2970 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
2971 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
2972 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
2973 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
2974 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08002975 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08002976 { .compatible = "ti,sysc-usb-host-fs",
2977 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05302978 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Suman Annab2745d92020-02-27 16:28:34 -06002979 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07002980 { },
2981};
2982MODULE_DEVICE_TABLE(of, sysc_match);
2983
2984static struct platform_driver sysc_driver = {
2985 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07002986 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07002987 .driver = {
2988 .name = "ti-sysc",
2989 .of_match_table = sysc_match,
2990 .pm = &sysc_pm_ops,
2991 },
2992};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002993
2994static int __init sysc_init(void)
2995{
2996 bus_register_notifier(&platform_bus_type, &sysc_nb);
2997
2998 return platform_driver_register(&sysc_driver);
2999}
3000module_init(sysc_init);
3001
3002static void __exit sysc_exit(void)
3003{
3004 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3005 platform_driver_unregister(&sysc_driver);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003006 sysc_cleanup_soc();
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003007}
3008module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003009
3010MODULE_DESCRIPTION("TI sysc interconnect target driver");
3011MODULE_LICENSE("GPL v2");