blob: d43221f236a27ad7c5db0a518bed701f8fa8ce34 [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
Tony Lindgrene4a8fc02020-06-10 15:31:54 -070032#define MAX_MODULE_SOFTRESET_WAIT 10000
Faiz Abbas596e7952018-07-09 22:18:39 +053033
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 Lindgrend46f9fb2020-05-31 12:37:54 -0700224/* Poll on reset status */
225static int sysc_wait_softreset(struct sysc *ddata)
226{
227 u32 sysc_mask, syss_done, rstval;
228 int syss_offset, error = 0;
229
Tony Lindgrene7ae08d32020-10-26 10:08:47 +0200230 if (ddata->cap->regbits->srst_shift < 0)
231 return 0;
232
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700233 syss_offset = ddata->offsets[SYSC_SYSSTATUS];
234 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
235
236 if (ddata->cfg.quirks & SYSS_QUIRK_RESETDONE_INVERTED)
237 syss_done = 0;
238 else
239 syss_done = ddata->cfg.syss_mask;
240
241 if (syss_offset >= 0) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700242 error = readx_poll_timeout_atomic(sysc_read_sysstatus, ddata,
243 rstval, (rstval & ddata->cfg.syss_mask) ==
244 syss_done, 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700245
246 } else if (ddata->cfg.quirks & SYSC_QUIRK_RESET_STATUS) {
Tony Lindgren9f911392020-07-02 10:44:20 -0700247 error = readx_poll_timeout_atomic(sysc_read_sysconfig, ddata,
248 rstval, !(rstval & sysc_mask),
249 100, MAX_MODULE_SOFTRESET_WAIT);
Tony Lindgrend46f9fb2020-05-31 12:37:54 -0700250 }
251
252 return error;
253}
254
Tony Lindgrena54275f2019-03-21 11:00:21 -0700255static int sysc_add_named_clock_from_child(struct sysc *ddata,
256 const char *name,
257 const char *optfck_name)
258{
259 struct device_node *np = ddata->dev->of_node;
260 struct device_node *child;
261 struct clk_lookup *cl;
262 struct clk *clock;
263 const char *n;
264
265 if (name)
266 n = name;
267 else
268 n = optfck_name;
269
270 /* Does the clock alias already exist? */
271 clock = of_clk_get_by_name(np, n);
272 if (!IS_ERR(clock)) {
273 clk_put(clock);
274
275 return 0;
276 }
277
278 child = of_get_next_available_child(np, NULL);
279 if (!child)
280 return -ENODEV;
281
282 clock = devm_get_clk_from_child(ddata->dev, child, name);
283 if (IS_ERR(clock))
284 return PTR_ERR(clock);
285
286 /*
287 * Use clkdev_add() instead of clkdev_alloc() to avoid the MAX_DEV_ID
288 * limit for clk_get(). If cl ever needs to be freed, it should be done
289 * with clkdev_drop().
290 */
Zheng Yongjund995d3d2020-12-29 21:51:47 +0800291 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
Tony Lindgrena54275f2019-03-21 11:00:21 -0700292 if (!cl)
293 return -ENOMEM;
294
295 cl->con_id = n;
296 cl->dev_id = dev_name(ddata->dev);
297 cl->clk = clock;
298 clkdev_add(cl);
299
300 clk_put(clock);
301
302 return 0;
303}
304
305static int sysc_init_ext_opt_clock(struct sysc *ddata, const char *name)
306{
307 const char *optfck_name;
308 int error, index;
309
310 if (ddata->nr_clocks < SYSC_OPTFCK0)
311 index = SYSC_OPTFCK0;
312 else
313 index = ddata->nr_clocks;
314
315 if (name)
316 optfck_name = name;
317 else
318 optfck_name = clock_names[index];
319
320 error = sysc_add_named_clock_from_child(ddata, name, optfck_name);
321 if (error)
322 return error;
323
324 ddata->clock_roles[index] = optfck_name;
325 ddata->nr_clocks++;
326
327 return 0;
328}
329
Tony Lindgren09dfe582018-04-16 10:25:52 -0700330static int sysc_get_one_clock(struct sysc *ddata, const char *name)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700331{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700332 int error, i, index = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700333
Tony Lindgren09dfe582018-04-16 10:25:52 -0700334 if (!strncmp(clock_names[SYSC_FCK], name, 3))
335 index = SYSC_FCK;
336 else if (!strncmp(clock_names[SYSC_ICK], name, 3))
337 index = SYSC_ICK;
338
339 if (index < 0) {
340 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
Tony Lindgrenc97c8622018-05-18 07:54:44 -0700341 if (!ddata->clocks[i]) {
Tony Lindgren09dfe582018-04-16 10:25:52 -0700342 index = i;
343 break;
344 }
345 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700346 }
Tony Lindgren09dfe582018-04-16 10:25:52 -0700347
348 if (index < 0) {
349 dev_err(ddata->dev, "clock %s not added\n", name);
350 return index;
351 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700352
353 ddata->clocks[index] = devm_clk_get(ddata->dev, name);
354 if (IS_ERR(ddata->clocks[index])) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700355 dev_err(ddata->dev, "clock get error for %s: %li\n",
356 name, PTR_ERR(ddata->clocks[index]));
357
358 return PTR_ERR(ddata->clocks[index]);
359 }
360
361 error = clk_prepare(ddata->clocks[index]);
362 if (error) {
363 dev_err(ddata->dev, "clock prepare error for %s: %i\n",
364 name, error);
365
366 return error;
367 }
368
369 return 0;
370}
371
372static int sysc_get_clocks(struct sysc *ddata)
373{
Tony Lindgren09dfe582018-04-16 10:25:52 -0700374 struct device_node *np = ddata->dev->of_node;
375 struct property *prop;
376 const char *name;
377 int nr_fck = 0, nr_ick = 0, i, error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700378
Kees Cook20749052018-06-18 10:45:49 -0700379 ddata->clock_roles = devm_kcalloc(ddata->dev,
Tony Lindgren09dfe582018-04-16 10:25:52 -0700380 SYSC_MAX_CLOCKS,
Kees Cook20749052018-06-18 10:45:49 -0700381 sizeof(*ddata->clock_roles),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700382 GFP_KERNEL);
383 if (!ddata->clock_roles)
384 return -ENOMEM;
385
386 of_property_for_each_string(np, "clock-names", prop, name) {
387 if (!strncmp(clock_names[SYSC_FCK], name, 3))
388 nr_fck++;
389 if (!strncmp(clock_names[SYSC_ICK], name, 3))
390 nr_ick++;
391 ddata->clock_roles[ddata->nr_clocks] = name;
392 ddata->nr_clocks++;
393 }
394
395 if (ddata->nr_clocks < 1)
396 return 0;
397
Tony Lindgrena54275f2019-03-21 11:00:21 -0700398 if ((ddata->cfg.quirks & SYSC_QUIRK_EXT_OPT_CLOCK)) {
399 error = sysc_init_ext_opt_clock(ddata, NULL);
400 if (error)
401 return error;
402 }
403
Tony Lindgren09dfe582018-04-16 10:25:52 -0700404 if (ddata->nr_clocks > SYSC_MAX_CLOCKS) {
405 dev_err(ddata->dev, "too many clocks for %pOF\n", np);
406
407 return -EINVAL;
408 }
409
410 if (nr_fck > 1 || nr_ick > 1) {
411 dev_err(ddata->dev, "max one fck and ick for %pOF\n", np);
412
413 return -EINVAL;
414 }
415
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800416 /* Always add a slot for main clocks fck and ick even if unused */
417 if (!nr_fck)
418 ddata->nr_clocks++;
419 if (!nr_ick)
420 ddata->nr_clocks++;
421
Kees Cook20749052018-06-18 10:45:49 -0700422 ddata->clocks = devm_kcalloc(ddata->dev,
423 ddata->nr_clocks, sizeof(*ddata->clocks),
Tony Lindgren09dfe582018-04-16 10:25:52 -0700424 GFP_KERNEL);
425 if (!ddata->clocks)
426 return -ENOMEM;
427
Tony Lindgren7b4f8ac2018-11-15 14:46:52 -0800428 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
429 const char *name = ddata->clock_roles[i];
430
431 if (!name)
432 continue;
433
434 error = sysc_get_one_clock(ddata, name);
Tony Lindgren2783d062019-09-05 13:01:29 -0700435 if (error)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700436 return error;
437 }
438
439 return 0;
440}
441
Tony Lindgrend8789702019-03-21 11:00:21 -0700442static int sysc_enable_main_clocks(struct sysc *ddata)
443{
444 struct clk *clock;
445 int i, error;
446
447 if (!ddata->clocks)
448 return 0;
449
450 for (i = 0; i < SYSC_OPTFCK0; i++) {
451 clock = ddata->clocks[i];
452
453 /* Main clocks may not have ick */
454 if (IS_ERR_OR_NULL(clock))
455 continue;
456
457 error = clk_enable(clock);
458 if (error)
459 goto err_disable;
460 }
461
462 return 0;
463
464err_disable:
465 for (i--; i >= 0; i--) {
466 clock = ddata->clocks[i];
467
468 /* Main clocks may not have ick */
469 if (IS_ERR_OR_NULL(clock))
470 continue;
471
472 clk_disable(clock);
473 }
474
475 return error;
476}
477
478static void sysc_disable_main_clocks(struct sysc *ddata)
479{
480 struct clk *clock;
481 int i;
482
483 if (!ddata->clocks)
484 return;
485
486 for (i = 0; i < SYSC_OPTFCK0; i++) {
487 clock = ddata->clocks[i];
488 if (IS_ERR_OR_NULL(clock))
489 continue;
490
491 clk_disable(clock);
492 }
493}
494
495static int sysc_enable_opt_clocks(struct sysc *ddata)
496{
497 struct clk *clock;
498 int i, error;
499
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800500 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700501 return 0;
502
503 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
504 clock = ddata->clocks[i];
505
506 /* Assume no holes for opt clocks */
507 if (IS_ERR_OR_NULL(clock))
508 return 0;
509
510 error = clk_enable(clock);
511 if (error)
512 goto err_disable;
513 }
514
515 return 0;
516
517err_disable:
518 for (i--; i >= 0; i--) {
519 clock = ddata->clocks[i];
520 if (IS_ERR_OR_NULL(clock))
521 continue;
522
523 clk_disable(clock);
524 }
525
526 return error;
527}
528
529static void sysc_disable_opt_clocks(struct sysc *ddata)
530{
531 struct clk *clock;
532 int i;
533
Tony Lindgren2c81f0f2019-12-16 14:41:53 -0800534 if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
Tony Lindgrend8789702019-03-21 11:00:21 -0700535 return;
536
537 for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
538 clock = ddata->clocks[i];
539
540 /* Assume no holes for opt clocks */
541 if (IS_ERR_OR_NULL(clock))
542 return;
543
544 clk_disable(clock);
545 }
546}
547
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700548static void sysc_clkdm_deny_idle(struct sysc *ddata)
549{
550 struct ti_sysc_platform_data *pdata;
551
Tony Lindgren94f63452019-12-12 08:57:58 -0800552 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700553 return;
554
555 pdata = dev_get_platdata(ddata->dev);
556 if (pdata && pdata->clkdm_deny_idle)
557 pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
558}
559
560static void sysc_clkdm_allow_idle(struct sysc *ddata)
561{
562 struct ti_sysc_platform_data *pdata;
563
Tony Lindgren94f63452019-12-12 08:57:58 -0800564 if (ddata->legacy_mode || (ddata->cfg.quirks & SYSC_QUIRK_CLKDM_NOAUTO))
Tony Lindgren2b2f7de2019-05-27 04:51:53 -0700565 return;
566
567 pdata = dev_get_platdata(ddata->dev);
568 if (pdata && pdata->clkdm_allow_idle)
569 pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
570}
571
Tony Lindgren0eecc632017-10-10 14:23:43 -0700572/**
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700573 * sysc_init_resets - init rstctrl reset line if configured
Tony Lindgren50622362018-04-16 10:20:27 -0700574 * @ddata: device driver data
575 *
Tony Lindgrenb11c1ea2019-03-21 11:00:21 -0700576 * See sysc_rstctrl_reset_deassert().
Tony Lindgren50622362018-04-16 10:20:27 -0700577 */
578static int sysc_init_resets(struct sysc *ddata)
579{
Tony Lindgren50622362018-04-16 10:20:27 -0700580 ddata->rsts =
Tero Kristobb88b862019-08-07 15:46:05 +0300581 devm_reset_control_get_optional_shared(ddata->dev, "rstctrl");
Tony Lindgren50622362018-04-16 10:20:27 -0700582
zhengbin3f2c4202019-11-18 18:37:32 +0800583 return PTR_ERR_OR_ZERO(ddata->rsts);
Tony Lindgren50622362018-04-16 10:20:27 -0700584}
585
586/**
Tony Lindgren0eecc632017-10-10 14:23:43 -0700587 * sysc_parse_and_check_child_range - parses module IO region from ranges
588 * @ddata: device driver data
589 *
590 * In general we only need rev, syss, and sysc registers and not the whole
591 * module range. But we do want the offsets for these registers from the
592 * module base. This allows us to check them against the legacy hwmod
593 * platform data. Let's also check the ranges are configured properly.
594 */
595static int sysc_parse_and_check_child_range(struct sysc *ddata)
596{
597 struct device_node *np = ddata->dev->of_node;
598 const __be32 *ranges;
599 u32 nr_addr, nr_size;
600 int len, error;
601
602 ranges = of_get_property(np, "ranges", &len);
603 if (!ranges) {
604 dev_err(ddata->dev, "missing ranges for %pOF\n", np);
605
606 return -ENOENT;
607 }
608
609 len /= sizeof(*ranges);
610
611 if (len < 3) {
612 dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
613
614 return -EINVAL;
615 }
616
617 error = of_property_read_u32(np, "#address-cells", &nr_addr);
618 if (error)
619 return -ENOENT;
620
621 error = of_property_read_u32(np, "#size-cells", &nr_size);
622 if (error)
623 return -ENOENT;
624
625 if (nr_addr != 1 || nr_size != 1) {
626 dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
627
628 return -EINVAL;
629 }
630
631 ranges++;
632 ddata->module_pa = of_translate_address(np, ranges++);
633 ddata->module_size = be32_to_cpup(ranges);
634
Tony Lindgren0eecc632017-10-10 14:23:43 -0700635 return 0;
636}
637
Tony Lindgren4700a002021-03-08 11:35:07 +0200638/* Interconnect instances to probe before l4_per instances */
639static struct resource early_bus_ranges[] = {
640 /* am3/4 l4_wkup */
641 { .start = 0x44c00000, .end = 0x44c00000 + 0x300000, },
642 /* omap4/5 and dra7 l4_cfg */
643 { .start = 0x4a000000, .end = 0x4a000000 + 0x300000, },
644 /* omap4 l4_wkup */
645 { .start = 0x4a300000, .end = 0x4a300000 + 0x30000, },
646 /* omap5 and dra7 l4_wkup without dra7 dcan segment */
647 { .start = 0x4ae00000, .end = 0x4ae00000 + 0x30000, },
648};
649
650static atomic_t sysc_defer = ATOMIC_INIT(10);
651
652/**
653 * sysc_defer_non_critical - defer non_critical interconnect probing
654 * @ddata: device driver data
655 *
656 * We want to probe l4_cfg and l4_wkup interconnect instances before any
657 * l4_per instances as l4_per instances depend on resources on l4_cfg and
658 * l4_wkup interconnects.
659 */
660static int sysc_defer_non_critical(struct sysc *ddata)
661{
662 struct resource *res;
663 int i;
664
665 if (!atomic_read(&sysc_defer))
666 return 0;
667
668 for (i = 0; i < ARRAY_SIZE(early_bus_ranges); i++) {
669 res = &early_bus_ranges[i];
670 if (ddata->module_pa >= res->start &&
671 ddata->module_pa <= res->end) {
672 atomic_set(&sysc_defer, 0);
673
674 return 0;
675 }
676 }
677
678 atomic_dec_if_positive(&sysc_defer);
679
680 return -EPROBE_DEFER;
681}
682
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800683static struct device_node *stdout_path;
684
685static void sysc_init_stdout_path(struct sysc *ddata)
686{
687 struct device_node *np = NULL;
688 const char *uart;
689
690 if (IS_ERR(stdout_path))
691 return;
692
693 if (stdout_path)
694 return;
695
696 np = of_find_node_by_path("/chosen");
697 if (!np)
698 goto err;
699
700 uart = of_get_property(np, "stdout-path", NULL);
701 if (!uart)
702 goto err;
703
704 np = of_find_node_by_path(uart);
705 if (!np)
706 goto err;
707
708 stdout_path = np;
709
710 return;
711
712err:
713 stdout_path = ERR_PTR(-ENODEV);
714}
715
716static void sysc_check_quirk_stdout(struct sysc *ddata,
717 struct device_node *np)
718{
719 sysc_init_stdout_path(ddata);
720 if (np != stdout_path)
721 return;
722
723 ddata->cfg.quirks |= SYSC_QUIRK_NO_IDLE_ON_INIT |
724 SYSC_QUIRK_NO_RESET_ON_INIT;
725}
726
Tony Lindgren0eecc632017-10-10 14:23:43 -0700727/**
728 * sysc_check_one_child - check child configuration
729 * @ddata: device driver data
730 * @np: child device node
731 *
732 * Let's avoid messy situations where we have new interconnect target
733 * node but children have "ti,hwmods". These belong to the interconnect
734 * target node and are managed by this driver.
735 */
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530736static void sysc_check_one_child(struct sysc *ddata,
737 struct device_node *np)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700738{
739 const char *name;
740
741 name = of_get_property(np, "ti,hwmods", NULL);
Tony Lindgren7320fd32020-02-24 12:58:03 -0800742 if (name && !of_device_is_compatible(np, "ti,sysc"))
Tony Lindgren0eecc632017-10-10 14:23:43 -0700743 dev_warn(ddata->dev, "really a child ti,hwmods property?");
744
Tony Lindgren3bb37c82018-02-22 14:05:14 -0800745 sysc_check_quirk_stdout(ddata, np);
Tony Lindgren4014c082018-12-10 14:11:26 -0800746 sysc_parse_dts_quirks(ddata, np, true);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700747}
748
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530749static void sysc_check_children(struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -0700750{
751 struct device_node *child;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700752
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530753 for_each_child_of_node(ddata->dev->of_node, child)
754 sysc_check_one_child(ddata, child);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700755}
756
Tony Lindgrena7199e22017-12-15 09:41:14 -0800757/*
758 * So far only I2C uses 16-bit read access with clockactivity with revision
759 * in two registers with stride of 4. We can detect this based on the rev
760 * register size to configure things far enough to be able to properly read
761 * the revision register.
762 */
763static void sysc_check_quirk_16bit(struct sysc *ddata, struct resource *res)
764{
Tony Lindgrendd57ac12018-02-22 14:09:57 -0800765 if (resource_size(res) == 8)
Tony Lindgrena7199e22017-12-15 09:41:14 -0800766 ddata->cfg.quirks |= SYSC_QUIRK_16BIT | SYSC_QUIRK_USE_CLOCKACT;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800767}
768
Tony Lindgren0eecc632017-10-10 14:23:43 -0700769/**
770 * sysc_parse_one - parses the interconnect target module registers
771 * @ddata: device driver data
772 * @reg: register to parse
773 */
774static int sysc_parse_one(struct sysc *ddata, enum sysc_registers reg)
775{
776 struct resource *res;
777 const char *name;
778
779 switch (reg) {
780 case SYSC_REVISION:
781 case SYSC_SYSCONFIG:
782 case SYSC_SYSSTATUS:
783 name = reg_names[reg];
784 break;
785 default:
786 return -EINVAL;
787 }
788
789 res = platform_get_resource_byname(to_platform_device(ddata->dev),
790 IORESOURCE_MEM, name);
791 if (!res) {
Tony Lindgren0eecc632017-10-10 14:23:43 -0700792 ddata->offsets[reg] = -ENODEV;
793
794 return 0;
795 }
796
797 ddata->offsets[reg] = res->start - ddata->module_pa;
Tony Lindgrena7199e22017-12-15 09:41:14 -0800798 if (reg == SYSC_REVISION)
799 sysc_check_quirk_16bit(ddata, res);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700800
801 return 0;
802}
803
804static int sysc_parse_registers(struct sysc *ddata)
805{
806 int i, error;
807
808 for (i = 0; i < SYSC_MAX_REGS; i++) {
809 error = sysc_parse_one(ddata, i);
810 if (error)
811 return error;
812 }
813
814 return 0;
815}
816
817/**
818 * sysc_check_registers - check for misconfigured register overlaps
819 * @ddata: device driver data
820 */
821static int sysc_check_registers(struct sysc *ddata)
822{
823 int i, j, nr_regs = 0, nr_matches = 0;
824
825 for (i = 0; i < SYSC_MAX_REGS; i++) {
826 if (ddata->offsets[i] < 0)
827 continue;
828
829 if (ddata->offsets[i] > (ddata->module_size - 4)) {
830 dev_err(ddata->dev, "register outside module range");
831
832 return -EINVAL;
833 }
834
835 for (j = 0; j < SYSC_MAX_REGS; j++) {
836 if (ddata->offsets[j] < 0)
837 continue;
838
839 if (ddata->offsets[i] == ddata->offsets[j])
840 nr_matches++;
841 }
842 nr_regs++;
843 }
844
Tony Lindgren0eecc632017-10-10 14:23:43 -0700845 if (nr_matches > nr_regs) {
846 dev_err(ddata->dev, "overlapping registers: (%i/%i)",
847 nr_regs, nr_matches);
848
849 return -EINVAL;
850 }
851
852 return 0;
853}
854
855/**
856 * syc_ioremap - ioremap register space for the interconnect target module
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700857 * @ddata: device driver data
Tony Lindgren0eecc632017-10-10 14:23:43 -0700858 *
859 * Note that the interconnect target module registers can be anywhere
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700860 * within the interconnect target module range. For example, SGX has
861 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
862 * has them at offset 0x1200 in the CPSW_WR child. Usually the
863 * the interconnect target module registers are at the beginning of
864 * the module range though.
Tony Lindgren0eecc632017-10-10 14:23:43 -0700865 */
866static int sysc_ioremap(struct sysc *ddata)
867{
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700868 int size;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700869
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700870 if (ddata->offsets[SYSC_REVISION] < 0 &&
871 ddata->offsets[SYSC_SYSCONFIG] < 0 &&
872 ddata->offsets[SYSC_SYSSTATUS] < 0) {
873 size = ddata->module_size;
874 } else {
875 size = max3(ddata->offsets[SYSC_REVISION],
876 ddata->offsets[SYSC_SYSCONFIG],
877 ddata->offsets[SYSC_SYSSTATUS]);
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700878
Tony Lindgren4e23be42019-06-10 04:48:05 -0700879 if (size < SZ_1K)
880 size = SZ_1K;
881
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700882 if ((size + sizeof(u32)) > ddata->module_size)
Tony Lindgren4e23be42019-06-10 04:48:05 -0700883 size = ddata->module_size;
Tony Lindgrene4f50c82019-05-01 14:24:57 -0700884 }
Tony Lindgren0eecc632017-10-10 14:23:43 -0700885
Tony Lindgren0eecc632017-10-10 14:23:43 -0700886 ddata->module_va = devm_ioremap(ddata->dev,
887 ddata->module_pa,
Tony Lindgren0ef8e3b2018-08-08 01:07:05 -0700888 size + sizeof(u32));
Tony Lindgren0eecc632017-10-10 14:23:43 -0700889 if (!ddata->module_va)
890 return -EIO;
891
892 return 0;
893}
894
895/**
896 * sysc_map_and_check_registers - ioremap and check device registers
897 * @ddata: device driver data
898 */
899static int sysc_map_and_check_registers(struct sysc *ddata)
900{
Tony Lindgren29281352020-11-16 12:57:13 +0200901 struct device_node *np = ddata->dev->of_node;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700902 int error;
903
904 error = sysc_parse_and_check_child_range(ddata);
905 if (error)
906 return error;
907
Tony Lindgren4700a002021-03-08 11:35:07 +0200908 error = sysc_defer_non_critical(ddata);
909 if (error)
910 return error;
911
Nishka Dasguptac6e78d72019-08-15 11:16:47 +0530912 sysc_check_children(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700913
Tony Lindgren7bad5af2021-03-08 11:35:06 +0200914 if (!of_get_property(np, "reg", NULL))
915 return 0;
916
Tony Lindgren0eecc632017-10-10 14:23:43 -0700917 error = sysc_parse_registers(ddata);
918 if (error)
919 return error;
920
921 error = sysc_ioremap(ddata);
922 if (error)
923 return error;
924
925 error = sysc_check_registers(ddata);
926 if (error)
927 return error;
928
929 return 0;
930}
931
932/**
933 * sysc_show_rev - read and show interconnect target module revision
934 * @bufp: buffer to print the information to
935 * @ddata: device driver data
936 */
937static int sysc_show_rev(char *bufp, struct sysc *ddata)
938{
Tony Lindgren566a9b052017-12-15 09:41:19 -0800939 int len;
Tony Lindgren0eecc632017-10-10 14:23:43 -0700940
941 if (ddata->offsets[SYSC_REVISION] < 0)
942 return sprintf(bufp, ":NA");
943
Tony Lindgren566a9b052017-12-15 09:41:19 -0800944 len = sprintf(bufp, ":%08x", ddata->revision);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700945
946 return len;
947}
948
949static int sysc_show_reg(struct sysc *ddata,
950 char *bufp, enum sysc_registers reg)
951{
952 if (ddata->offsets[reg] < 0)
953 return sprintf(bufp, ":NA");
954
955 return sprintf(bufp, ":%x", ddata->offsets[reg]);
956}
957
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800958static int sysc_show_name(char *bufp, struct sysc *ddata)
959{
960 if (!ddata->name)
961 return 0;
962
963 return sprintf(bufp, ":%s", ddata->name);
964}
965
Tony Lindgren0eecc632017-10-10 14:23:43 -0700966/**
967 * sysc_show_registers - show information about interconnect target module
968 * @ddata: device driver data
969 */
970static void sysc_show_registers(struct sysc *ddata)
971{
972 char buf[128];
973 char *bufp = buf;
974 int i;
975
976 for (i = 0; i < SYSC_MAX_REGS; i++)
977 bufp += sysc_show_reg(ddata, bufp, i);
978
979 bufp += sysc_show_rev(bufp, ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -0800980 bufp += sysc_show_name(bufp, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -0700981
982 dev_dbg(ddata->dev, "%llx:%x%s\n",
983 ddata->module_pa, ddata->module_size,
984 buf);
985}
986
Tony Lindgrene8639e12020-02-24 12:58:03 -0800987/**
988 * sysc_write_sysconfig - handle sysconfig quirks for register write
989 * @ddata: device driver data
990 * @value: register value
991 */
992static void sysc_write_sysconfig(struct sysc *ddata, u32 value)
993{
994 if (ddata->module_unlock_quirk)
995 ddata->module_unlock_quirk(ddata);
996
997 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], value);
998
999 if (ddata->module_lock_quirk)
1000 ddata->module_lock_quirk(ddata);
1001}
1002
Roger Quadrosd59b6052019-04-08 12:52:39 +03001003#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001004#define SYSC_CLOCACT_ICK 2
Roger Quadrosd59b6052019-04-08 12:52:39 +03001005
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001006/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001007static int sysc_enable_module(struct device *dev)
1008{
1009 struct sysc *ddata;
1010 const struct sysc_regbits *regbits;
1011 u32 reg, idlemodes, best_mode;
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001012 int error;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001013
1014 ddata = dev_get_drvdata(dev);
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001015
1016 /*
1017 * Some modules like DSS reset automatically on idle. Enable optional
1018 * reset clocks and wait for OCP softreset to complete.
1019 */
1020 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET) {
1021 error = sysc_enable_opt_clocks(ddata);
1022 if (error) {
1023 dev_err(ddata->dev,
1024 "Optional clocks failed for enable: %i\n",
1025 error);
1026 return error;
1027 }
1028 }
Tony Lindgrene275d212020-10-26 10:08:47 +02001029 /*
1030 * Some modules like i2c and hdq1w have unusable reset status unless
1031 * the module reset quirk is enabled. Skip status check on enable.
1032 */
1033 if (!(ddata->cfg.quirks & SYSC_MODULE_QUIRK_ENA_RESETDONE)) {
1034 error = sysc_wait_softreset(ddata);
1035 if (error)
1036 dev_warn(ddata->dev, "OCP softreset timed out\n");
1037 }
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07001038 if (ddata->cfg.quirks & SYSC_QUIRK_OPT_CLKS_IN_RESET)
1039 sysc_disable_opt_clocks(ddata);
1040
1041 /*
1042 * Some subsystem private interconnects, like DSS top level module,
1043 * need only the automatic OCP softreset handling with no sysconfig
1044 * register bits to configure.
1045 */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001046 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1047 return 0;
1048
Roger Quadrosd59b6052019-04-08 12:52:39 +03001049 regbits = ddata->cap->regbits;
1050 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1051
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001052 /*
1053 * Set CLOCKACTIVITY, we only use it for ick. And we only configure it
1054 * based on the SYSC_QUIRK_USE_CLOCKACT flag, not based on the hardware
1055 * capabilities. See the old HWMOD_SET_DEFAULT_CLOCKACT flag.
1056 */
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001057 if (regbits->clkact_shift >= 0 &&
Tony Lindgren08b91dd2020-05-31 12:37:54 -07001058 (ddata->cfg.quirks & SYSC_QUIRK_USE_CLOCKACT))
Tony Lindgrenae9ae122019-05-27 04:51:54 -07001059 reg |= SYSC_CLOCACT_ICK << regbits->clkact_shift;
1060
Roger Quadrosd59b6052019-04-08 12:52:39 +03001061 /* Set SIDLE mode */
1062 idlemodes = ddata->cfg.sidlemodes;
1063 if (!idlemodes || regbits->sidle_shift < 0)
1064 goto set_midle;
1065
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001066 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_SIDLE |
1067 SYSC_QUIRK_SWSUP_SIDLE_ACT)) {
1068 best_mode = SYSC_IDLE_NO;
1069 } else {
1070 best_mode = fls(ddata->cfg.sidlemodes) - 1;
1071 if (best_mode > SYSC_IDLE_MASK) {
1072 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1073 return -EINVAL;
1074 }
Tony Lindgren6e09f492019-05-27 04:51:55 -07001075
1076 /* Set WAKEUP */
1077 if (regbits->enwkup_shift >= 0 &&
1078 ddata->cfg.sysc_val & BIT(regbits->enwkup_shift))
1079 reg |= BIT(regbits->enwkup_shift);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001080 }
1081
1082 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1083 reg |= best_mode << regbits->sidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001084 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001085
1086set_midle:
1087 /* Set MIDLE mode */
1088 idlemodes = ddata->cfg.midlemodes;
1089 if (!idlemodes || regbits->midle_shift < 0)
Tony Lindgreneec26552019-05-27 04:51:54 -07001090 goto set_autoidle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001091
1092 best_mode = fls(ddata->cfg.midlemodes) - 1;
1093 if (best_mode > SYSC_IDLE_MASK) {
1094 dev_err(dev, "%s: invalid midlemode\n", __func__);
1095 return -EINVAL;
1096 }
1097
Tony Lindgren03856e92019-10-21 13:36:09 -07001098 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_MSTANDBY)
1099 best_mode = SYSC_IDLE_NO;
1100
Roger Quadrosd59b6052019-04-08 12:52:39 +03001101 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1102 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001103 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001104
Tony Lindgreneec26552019-05-27 04:51:54 -07001105set_autoidle:
1106 /* Autoidle bit must enabled separately if available */
1107 if (regbits->autoidle_shift >= 0 &&
1108 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift)) {
1109 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001110 sysc_write_sysconfig(ddata, reg);
Tony Lindgreneec26552019-05-27 04:51:54 -07001111 }
1112
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001113 /* Flush posted write */
1114 sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1115
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001116 if (ddata->module_enable_quirk)
1117 ddata->module_enable_quirk(ddata);
1118
Roger Quadrosd59b6052019-04-08 12:52:39 +03001119 return 0;
1120}
1121
1122static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
1123{
1124 if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP))
1125 *best_mode = SYSC_IDLE_SMART_WKUP;
1126 else if (idlemodes & BIT(SYSC_IDLE_SMART))
1127 *best_mode = SYSC_IDLE_SMART;
Tony Lindgren6ee82412019-07-22 03:44:42 -07001128 else if (idlemodes & BIT(SYSC_IDLE_FORCE))
Roger Quadrosd59b6052019-04-08 12:52:39 +03001129 *best_mode = SYSC_IDLE_FORCE;
1130 else
1131 return -EINVAL;
1132
1133 return 0;
1134}
1135
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001136/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
Roger Quadrosd59b6052019-04-08 12:52:39 +03001137static int sysc_disable_module(struct device *dev)
1138{
1139 struct sysc *ddata;
1140 const struct sysc_regbits *regbits;
1141 u32 reg, idlemodes, best_mode;
1142 int ret;
1143
1144 ddata = dev_get_drvdata(dev);
1145 if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
1146 return 0;
1147
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001148 if (ddata->module_disable_quirk)
1149 ddata->module_disable_quirk(ddata);
1150
Roger Quadrosd59b6052019-04-08 12:52:39 +03001151 regbits = ddata->cap->regbits;
1152 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1153
1154 /* Set MIDLE mode */
1155 idlemodes = ddata->cfg.midlemodes;
1156 if (!idlemodes || regbits->midle_shift < 0)
1157 goto set_sidle;
1158
1159 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1160 if (ret) {
1161 dev_err(dev, "%s: invalid midlemode\n", __func__);
1162 return ret;
1163 }
1164
Tony Lindgren93c60482019-12-09 13:55:15 -08001165 if (ddata->cfg.quirks & (SYSC_QUIRK_SWSUP_MSTANDBY) ||
1166 ddata->cfg.quirks & (SYSC_QUIRK_FORCE_MSTANDBY))
Tony Lindgren03856e92019-10-21 13:36:09 -07001167 best_mode = SYSC_IDLE_FORCE;
1168
Roger Quadrosd59b6052019-04-08 12:52:39 +03001169 reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift);
1170 reg |= best_mode << regbits->midle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001171 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001172
1173set_sidle:
1174 /* Set SIDLE mode */
1175 idlemodes = ddata->cfg.sidlemodes;
1176 if (!idlemodes || regbits->sidle_shift < 0)
1177 return 0;
1178
Tony Lindgrenfb685f12019-05-27 04:51:55 -07001179 if (ddata->cfg.quirks & SYSC_QUIRK_SWSUP_SIDLE) {
1180 best_mode = SYSC_IDLE_FORCE;
1181 } else {
1182 ret = sysc_best_idle_mode(idlemodes, &best_mode);
1183 if (ret) {
1184 dev_err(dev, "%s: invalid sidlemode\n", __func__);
1185 return ret;
1186 }
Roger Quadrosd59b6052019-04-08 12:52:39 +03001187 }
1188
1189 reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift);
1190 reg |= best_mode << regbits->sidle_shift;
Tony Lindgreneec26552019-05-27 04:51:54 -07001191 if (regbits->autoidle_shift >= 0 &&
1192 ddata->cfg.sysc_val & BIT(regbits->autoidle_shift))
1193 reg |= 1 << regbits->autoidle_shift;
Tony Lindgrene8639e12020-02-24 12:58:03 -08001194 sysc_write_sysconfig(ddata, reg);
Roger Quadrosd59b6052019-04-08 12:52:39 +03001195
Tony Lindgren5ce8aee2020-05-27 06:49:29 -07001196 /* Flush posted write */
1197 sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1198
Roger Quadrosd59b6052019-04-08 12:52:39 +03001199 return 0;
1200}
1201
Tony Lindgrenff437282019-03-21 11:00:21 -07001202static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev,
1203 struct sysc *ddata)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001204{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001205 struct ti_sysc_platform_data *pdata;
Tony Lindgrenff437282019-03-21 11:00:21 -07001206 int error;
1207
1208 pdata = dev_get_platdata(ddata->dev);
1209 if (!pdata)
1210 return 0;
1211
1212 if (!pdata->idle_module)
1213 return -ENODEV;
1214
1215 error = pdata->idle_module(dev, &ddata->cookie);
1216 if (error)
1217 dev_err(dev, "%s: could not idle: %i\n",
1218 __func__, error);
1219
Tero Kristo4345f0d2019-08-07 15:46:04 +03001220 reset_control_assert(ddata->rsts);
Tony Lindgren8383e252019-05-27 04:51:56 -07001221
Tony Lindgrenff437282019-03-21 11:00:21 -07001222 return 0;
1223}
1224
1225static int __maybe_unused sysc_runtime_resume_legacy(struct device *dev,
1226 struct sysc *ddata)
1227{
1228 struct ti_sysc_platform_data *pdata;
1229 int error;
1230
1231 pdata = dev_get_platdata(ddata->dev);
1232 if (!pdata)
1233 return 0;
1234
1235 if (!pdata->enable_module)
1236 return -ENODEV;
1237
1238 error = pdata->enable_module(dev, &ddata->cookie);
1239 if (error)
1240 dev_err(dev, "%s: could not enable: %i\n",
1241 __func__, error);
1242
Tero Kristobf59ebb2019-10-07 15:29:29 +03001243 reset_control_deassert(ddata->rsts);
1244
Tony Lindgrenff437282019-03-21 11:00:21 -07001245 return 0;
1246}
1247
1248static int __maybe_unused sysc_runtime_suspend(struct device *dev)
1249{
Tony Lindgren0eecc632017-10-10 14:23:43 -07001250 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001251 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001252
1253 ddata = dev_get_drvdata(dev);
1254
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001255 if (!ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001256 return 0;
1257
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001258 sysc_clkdm_deny_idle(ddata);
1259
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001260 if (ddata->legacy_mode) {
Tony Lindgrenff437282019-03-21 11:00:21 -07001261 error = sysc_runtime_suspend_legacy(dev, ddata);
Tony Lindgren93de83a2019-03-21 11:00:21 -07001262 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001263 goto err_allow_idle;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001264 } else {
1265 error = sysc_disable_module(dev);
1266 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001267 goto err_allow_idle;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001268 }
1269
Tony Lindgrend8789702019-03-21 11:00:21 -07001270 sysc_disable_main_clocks(ddata);
Tony Lindgren09dfe582018-04-16 10:25:52 -07001271
Tony Lindgrend8789702019-03-21 11:00:21 -07001272 if (sysc_opt_clks_needed(ddata))
1273 sysc_disable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001274
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001275 ddata->enabled = false;
1276
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001277err_allow_idle:
Tero Kristob6036312019-08-07 15:46:03 +03001278 sysc_clkdm_allow_idle(ddata);
1279
Tony Lindgren4097c9a2020-11-16 12:57:13 +02001280 reset_control_assert(ddata->rsts);
1281
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001282 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001283}
1284
Arnd Bergmanna4a5d492017-10-13 11:25:32 +02001285static int __maybe_unused sysc_runtime_resume(struct device *dev)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001286{
1287 struct sysc *ddata;
Tony Lindgrend8789702019-03-21 11:00:21 -07001288 int error = 0;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001289
1290 ddata = dev_get_drvdata(dev);
1291
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001292 if (ddata->enabled)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001293 return 0;
1294
Tony Lindgren8383e252019-05-27 04:51:56 -07001295
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001296 sysc_clkdm_deny_idle(ddata);
1297
Tony Lindgrend8789702019-03-21 11:00:21 -07001298 if (sysc_opt_clks_needed(ddata)) {
1299 error = sysc_enable_opt_clocks(ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07001300 if (error)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001301 goto err_allow_idle;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001302 }
1303
Tony Lindgrend8789702019-03-21 11:00:21 -07001304 error = sysc_enable_main_clocks(ddata);
1305 if (error)
Tony Lindgren93de83a2019-03-21 11:00:21 -07001306 goto err_opt_clocks;
1307
Tero Kristobf59ebb2019-10-07 15:29:29 +03001308 reset_control_deassert(ddata->rsts);
1309
Tony Lindgren93de83a2019-03-21 11:00:21 -07001310 if (ddata->legacy_mode) {
1311 error = sysc_runtime_resume_legacy(dev, ddata);
1312 if (error)
1313 goto err_main_clocks;
Roger Quadrosd59b6052019-04-08 12:52:39 +03001314 } else {
1315 error = sysc_enable_module(dev);
1316 if (error)
1317 goto err_main_clocks;
Tony Lindgren93de83a2019-03-21 11:00:21 -07001318 }
Tony Lindgrend8789702019-03-21 11:00:21 -07001319
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001320 ddata->enabled = true;
1321
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001322 sysc_clkdm_allow_idle(ddata);
1323
Tony Lindgrend8789702019-03-21 11:00:21 -07001324 return 0;
1325
1326err_main_clocks:
Tony Lindgren93de83a2019-03-21 11:00:21 -07001327 sysc_disable_main_clocks(ddata);
1328err_opt_clocks:
Tony Lindgrend8789702019-03-21 11:00:21 -07001329 if (sysc_opt_clks_needed(ddata))
1330 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001331err_allow_idle:
1332 sysc_clkdm_allow_idle(ddata);
Tony Lindgrend8789702019-03-21 11:00:21 -07001333
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08001334 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07001335}
1336
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001337static int sysc_reinit_module(struct sysc *ddata, bool leave_enabled)
1338{
1339 struct device *dev = ddata->dev;
1340 int error;
1341
1342 /* Disable target module if it is enabled */
1343 if (ddata->enabled) {
1344 error = sysc_runtime_suspend(dev);
1345 if (error)
1346 dev_warn(dev, "reinit suspend failed: %i\n", error);
1347 }
1348
1349 /* Enable target module */
1350 error = sysc_runtime_resume(dev);
1351 if (error)
1352 dev_warn(dev, "reinit resume failed: %i\n", error);
1353
1354 if (leave_enabled)
1355 return error;
1356
1357 /* Disable target module if no leave_enabled was set */
1358 error = sysc_runtime_suspend(dev);
1359 if (error)
1360 dev_warn(dev, "reinit suspend failed: %i\n", error);
1361
1362 return error;
1363}
1364
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001365static int __maybe_unused sysc_noirq_suspend(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001366{
1367 struct sysc *ddata;
1368
1369 ddata = dev_get_drvdata(dev);
1370
Tony Lindgrena55de412020-07-02 13:57:14 -07001371 if (ddata->cfg.quirks &
1372 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001373 return 0;
1374
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001375 if (!ddata->enabled)
1376 return 0;
1377
1378 ddata->needs_resume = 1;
1379
1380 return sysc_runtime_suspend(dev);
Tony Lindgren62020f22018-02-22 13:59:44 -08001381}
1382
Tony Lindgrenf5e802032018-10-01 09:33:28 -07001383static int __maybe_unused sysc_noirq_resume(struct device *dev)
Tony Lindgren62020f22018-02-22 13:59:44 -08001384{
1385 struct sysc *ddata;
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001386 int error = 0;
Tony Lindgren62020f22018-02-22 13:59:44 -08001387
1388 ddata = dev_get_drvdata(dev);
Tony Lindgrene7420c22018-04-16 10:26:46 -07001389
Tony Lindgrena55de412020-07-02 13:57:14 -07001390 if (ddata->cfg.quirks &
1391 (SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_NO_IDLE))
Tony Lindgrene7420c22018-04-16 10:26:46 -07001392 return 0;
1393
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001394 if (ddata->cfg.quirks & SYSC_QUIRK_REINIT_ON_RESUME) {
1395 error = sysc_reinit_module(ddata, ddata->needs_resume);
1396 if (error)
1397 dev_warn(dev, "noirq_resume failed: %i\n", error);
1398 } else if (ddata->needs_resume) {
1399 error = sysc_runtime_resume(dev);
1400 if (error)
1401 dev_warn(dev, "noirq_resume failed: %i\n", error);
1402 }
1403
1404 ddata->needs_resume = 0;
1405
1406 return error;
Tony Lindgrene7420c22018-04-16 10:26:46 -07001407}
1408
Tony Lindgren0eecc632017-10-10 14:23:43 -07001409static const struct dev_pm_ops sysc_pm_ops = {
Tony Lindgrene7420c22018-04-16 10:26:46 -07001410 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_noirq_suspend, sysc_noirq_resume)
Tony Lindgren0eecc632017-10-10 14:23:43 -07001411 SET_RUNTIME_PM_OPS(sysc_runtime_suspend,
1412 sysc_runtime_resume,
1413 NULL)
1414};
1415
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001416/* Module revision register based quirks */
1417struct sysc_revision_quirk {
1418 const char *name;
1419 u32 base;
1420 int rev_offset;
1421 int sysc_offset;
1422 int syss_offset;
1423 u32 revision;
1424 u32 revision_mask;
1425 u32 quirks;
1426};
1427
1428#define SYSC_QUIRK(optname, optbase, optrev, optsysc, optsyss, \
1429 optrev_val, optrevmask, optquirkmask) \
1430 { \
1431 .name = (optname), \
1432 .base = (optbase), \
1433 .rev_offset = (optrev), \
1434 .sysc_offset = (optsysc), \
1435 .syss_offset = (optsyss), \
1436 .revision = (optrev_val), \
1437 .revision_mask = (optrevmask), \
1438 .quirks = (optquirkmask), \
1439 }
1440
1441static const struct sysc_revision_quirk sysc_revision_quirks[] = {
1442 /* These drivers need to be fixed to not use pm_runtime_irq_safe() */
Tony Lindgren3a3d8022018-09-27 13:33:58 -07001443 SYSC_QUIRK("gpio", 0, 0, 0x10, 0x114, 0x50600801, 0xffff00ff,
Tony Lindgren09dfe582018-04-16 10:25:52 -07001444 SYSC_QUIRK_LEGACY_IDLE | SYSC_QUIRK_OPT_CLKS_IN_RESET),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001445 SYSC_QUIRK("sham", 0, 0x100, 0x110, 0x114, 0x40000c03, 0xffffffff,
1446 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001447 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001448 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001449 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001450 SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001451 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1452 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001453 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001454 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001455 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001456 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001457 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001458 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001459 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001460
Tony Lindgrena54275f2019-03-21 11:00:21 -07001461 /* Quirks that need to be set based on the module address */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001462 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
Tony Lindgrena54275f2019-03-21 11:00:21 -07001463 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1464 SYSC_QUIRK_SWSUP_SIDLE),
1465
Tony Lindgren4e23be42019-06-10 04:48:05 -07001466 /* Quirks that need to be set based on detected module */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001467 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
Tony Lindgren020003f2019-11-14 08:25:28 -08001468 SYSC_MODULE_QUIRK_AESS),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001469 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001470 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001471 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001472 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001473 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001474 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001475 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001476 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001477 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001478 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001479 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001480 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001481 SYSC_QUIRK("gpmc", 0, 0, 0x10, 0x14, 0x00000060, 0xffffffff,
1482 SYSC_QUIRK_GPMC_DEBUG),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001483 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1484 SYSC_QUIRK_OPT_CLKS_NEEDED),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001485 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001486 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001487 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001488 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001489 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001490 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001491 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001492 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001493 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001494 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001495 SYSC_QUIRK("i2c", 0, 0, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
Tony Lindgrene275d212020-10-26 10:08:47 +02001496 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001497 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1498 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001499 SYSC_MODULE_QUIRK_SGX),
Tony Lindgrenaef067e2020-03-10 09:06:02 -07001500 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1501 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Peter Ujfalusi8122dc52021-07-17 15:09:24 +03001502 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff,
1503 SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgrene8639e12020-02-24 12:58:03 -08001504 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1505 SYSC_MODULE_QUIRK_RTC_UNLOCK),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001506 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1507 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1508 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1509 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrendb8e7122021-05-07 12:09:03 +03001510 SYSC_QUIRK("sata", 0, 0xfc, 0x1100, -ENODEV, 0x5e412000, 0xffffffff,
1511 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren42546322020-07-13 09:59:47 -07001512 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1513 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1514 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1515 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren03856e92019-10-21 13:36:09 -07001516 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1517 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001518 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001519 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1520 SYSC_QUIRK_REINIT_ON_RESUME),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001521 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1522 SYSC_MODULE_QUIRK_WDT),
Suman Annab2745d92020-02-27 16:28:34 -06001523 /* PRUSS on am3, am4 and am5 */
1524 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1525 SYSC_MODULE_QUIRK_PRUSS),
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001526 /* Watchdog on am3 and am4 */
1527 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1528 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001529
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001530#ifdef DEBUG
Tony Lindgren590e15c2020-02-24 12:58:03 -08001531 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1532 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1533 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1534 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001535 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001536 0xffff00f0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001537 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1538 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001539 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1540 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1541 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001542 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001543 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1544 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1545 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1546 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001547 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
Tony Lindgren7edd00f2019-08-14 05:18:16 -07001548 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1549 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001550 SYSC_QUIRK("elm", 0x48080000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1551 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x40441403, 0xffff0fff, 0),
1552 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x50440500, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001553 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1554 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1555 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001556 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001557 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001558 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001559 SYSC_QUIRK("keypad", 0x4a31c000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001560 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1561 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1562 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001563 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001564 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1565 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001566 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001567 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1568 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1569 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001570 SYSC_QUIRK("pcie", 0x51000000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1571 SYSC_QUIRK("pcie", 0x51800000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001572 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1573 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1574 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001575 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1576 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001577 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1578 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1579 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1580 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1581 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1582 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001583 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001584 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001585 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1586 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
1587 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1588 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
Tony Lindgren1a542812020-05-07 09:43:08 -07001589 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1590 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1591 /* Some timers on omap4 and later */
1592 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1593 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1594 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1595 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001596 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001597 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001598 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001599 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001600 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001601 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001602#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001603};
1604
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001605/*
1606 * Early quirks based on module base and register offsets only that are
1607 * needed before the module revision can be read
1608 */
1609static void sysc_init_early_quirks(struct sysc *ddata)
1610{
1611 const struct sysc_revision_quirk *q;
1612 int i;
1613
1614 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1615 q = &sysc_revision_quirks[i];
1616
1617 if (!q->base)
1618 continue;
1619
1620 if (q->base != ddata->module_pa)
1621 continue;
1622
Tony Lindgren590e15c2020-02-24 12:58:03 -08001623 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001624 continue;
1625
Tony Lindgren590e15c2020-02-24 12:58:03 -08001626 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001627 continue;
1628
Tony Lindgren590e15c2020-02-24 12:58:03 -08001629 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001630 continue;
1631
1632 ddata->name = q->name;
1633 ddata->cfg.quirks |= q->quirks;
1634 }
1635}
1636
1637/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001638static void sysc_init_revision_quirks(struct sysc *ddata)
1639{
1640 const struct sysc_revision_quirk *q;
1641 int i;
1642
1643 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1644 q = &sysc_revision_quirks[i];
1645
1646 if (q->base && q->base != ddata->module_pa)
1647 continue;
1648
Tony Lindgren590e15c2020-02-24 12:58:03 -08001649 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001650 continue;
1651
Tony Lindgren590e15c2020-02-24 12:58:03 -08001652 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001653 continue;
1654
Tony Lindgren590e15c2020-02-24 12:58:03 -08001655 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001656 continue;
1657
1658 if (q->revision == ddata->revision ||
1659 (q->revision & q->revision_mask) ==
1660 (ddata->revision & q->revision_mask)) {
1661 ddata->name = q->name;
1662 ddata->cfg.quirks |= q->quirks;
1663 }
1664 }
1665}
1666
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001667/*
1668 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1669 * enabled DSS interrupts. Eventually we may be able to do this on
1670 * dispc init rather than top-level DSS init.
1671 */
1672static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1673 bool disable)
1674{
1675 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1676 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1677 int manager_count;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001678 bool framedonetv_irq = true;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001679 u32 val, irq_mask = 0;
1680
1681 switch (sysc_soc->soc) {
1682 case SOC_2420 ... SOC_3630:
1683 manager_count = 2;
1684 framedonetv_irq = false;
1685 break;
1686 case SOC_4430 ... SOC_4470:
1687 manager_count = 3;
1688 break;
1689 case SOC_5430:
1690 case SOC_DRA7:
1691 manager_count = 4;
1692 break;
1693 case SOC_AM4:
1694 manager_count = 1;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001695 framedonetv_irq = false;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001696 break;
1697 case SOC_UNKNOWN:
1698 default:
1699 return 0;
Yang Li52fbb5a2021-02-02 15:00:05 +08001700 }
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001701
1702 /* Remap the whole module range to be able to reset dispc outputs */
1703 devm_iounmap(ddata->dev, ddata->module_va);
1704 ddata->module_va = devm_ioremap(ddata->dev,
1705 ddata->module_pa,
1706 ddata->module_size);
1707 if (!ddata->module_va)
1708 return -EIO;
1709
1710 /* DISP_CONTROL */
1711 val = sysc_read(ddata, dispc_offset + 0x40);
1712 lcd_en = val & lcd_en_mask;
1713 digit_en = val & digit_en_mask;
1714 if (lcd_en)
1715 irq_mask |= BIT(0); /* FRAMEDONE */
1716 if (digit_en) {
1717 if (framedonetv_irq)
1718 irq_mask |= BIT(24); /* FRAMEDONETV */
1719 else
1720 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1721 }
1722 if (disable & (lcd_en | digit_en))
1723 sysc_write(ddata, dispc_offset + 0x40,
1724 val & ~(lcd_en_mask | digit_en_mask));
1725
1726 if (manager_count <= 2)
1727 return irq_mask;
1728
1729 /* DISPC_CONTROL2 */
1730 val = sysc_read(ddata, dispc_offset + 0x238);
1731 lcd2_en = val & lcd_en_mask;
1732 if (lcd2_en)
1733 irq_mask |= BIT(22); /* FRAMEDONE2 */
1734 if (disable && lcd2_en)
1735 sysc_write(ddata, dispc_offset + 0x238,
1736 val & ~lcd_en_mask);
1737
1738 if (manager_count <= 3)
1739 return irq_mask;
1740
1741 /* DISPC_CONTROL3 */
1742 val = sysc_read(ddata, dispc_offset + 0x848);
1743 lcd3_en = val & lcd_en_mask;
1744 if (lcd3_en)
1745 irq_mask |= BIT(30); /* FRAMEDONE3 */
1746 if (disable && lcd3_en)
1747 sysc_write(ddata, dispc_offset + 0x848,
1748 val & ~lcd_en_mask);
1749
1750 return irq_mask;
1751}
1752
1753/* DSS needs child outputs disabled and SDI registers cleared for reset */
1754static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1755{
1756 const int dispc_offset = 0x1000;
1757 int error;
1758 u32 irq_mask, val;
1759
1760 /* Get enabled outputs */
1761 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1762 if (!irq_mask)
1763 return;
1764
1765 /* Clear IRQSTATUS */
Tony Lindgren69e60902020-03-03 07:17:43 -08001766 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001767
1768 /* Disable outputs */
1769 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1770
1771 /* Poll IRQSTATUS */
1772 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1773 val, val != irq_mask, 100, 50);
1774 if (error)
1775 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1776 __func__, val, irq_mask);
1777
1778 if (sysc_soc->soc == SOC_3430) {
1779 /* Clear DSS_SDI_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001780 sysc_write(ddata, 0x44, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001781
1782 /* Clear DSS_PLL_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001783 sysc_write(ddata, 0x48, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001784 }
1785
1786 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
Tony Lindgren69e60902020-03-03 07:17:43 -08001787 sysc_write(ddata, 0x40, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001788}
1789
Tony Lindgren4e23be42019-06-10 04:48:05 -07001790/* 1-wire needs module's internal clocks enabled for reset */
Tony Lindgrenaec551c2020-02-24 12:58:03 -08001791static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001792{
1793 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1794 u16 val;
1795
1796 val = sysc_read(ddata, offset);
1797 val |= BIT(5);
1798 sysc_write(ddata, offset, val);
1799}
1800
Tony Lindgren020003f2019-11-14 08:25:28 -08001801/* AESS (Audio Engine SubSystem) needs autogating set after enable */
1802static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1803{
1804 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1805
1806 sysc_write(ddata, offset, 1);
1807}
1808
Tony Lindgrene64c0212020-02-24 12:58:03 -08001809/* I2C needs to be disabled for reset */
Tony Lindgren4e23be42019-06-10 04:48:05 -07001810static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1811{
1812 int offset;
1813 u16 val;
1814
1815 /* I2C_CON, omap2/3 is different from omap4 and later */
1816 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1817 offset = 0x24;
1818 else
1819 offset = 0xa4;
1820
1821 /* I2C_EN */
1822 val = sysc_read(ddata, offset);
1823 if (enable)
1824 val |= BIT(15);
1825 else
1826 val &= ~BIT(15);
1827 sysc_write(ddata, offset, val);
1828}
1829
Tony Lindgrene64c0212020-02-24 12:58:03 -08001830static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001831{
1832 sysc_clk_quirk_i2c(ddata, false);
1833}
1834
Tony Lindgrene64c0212020-02-24 12:58:03 -08001835static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1836{
1837 sysc_clk_quirk_i2c(ddata, true);
1838}
1839
Tony Lindgrene8639e12020-02-24 12:58:03 -08001840/* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1841static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1842{
1843 u32 val, kick0_val = 0, kick1_val = 0;
1844 unsigned long flags;
1845 int error;
1846
1847 if (!lock) {
1848 kick0_val = 0x83e70b13;
1849 kick1_val = 0x95a4f1e0;
1850 }
1851
1852 local_irq_save(flags);
1853 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
Tony Lindgrenafe6f1e2020-07-02 10:41:02 -07001854 error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val,
1855 !(val & BIT(0)), 100, 50);
Tony Lindgrene8639e12020-02-24 12:58:03 -08001856 if (error)
1857 dev_warn(ddata->dev, "rtc busy timeout\n");
1858 /* Now we have ~15 microseconds to read/write various registers */
1859 sysc_write(ddata, 0x6c, kick0_val);
1860 sysc_write(ddata, 0x70, kick1_val);
1861 local_irq_restore(flags);
1862}
1863
1864static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1865{
1866 sysc_quirk_rtc(ddata, false);
1867}
1868
1869static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1870{
1871 sysc_quirk_rtc(ddata, true);
1872}
1873
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001874/* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1875static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1876{
1877 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1878 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1879
1880 sysc_write(ddata, offset, val);
1881}
1882
Tony Lindgren4e23be42019-06-10 04:48:05 -07001883/* Watchdog timer needs a disable sequence after reset */
1884static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1885{
1886 int wps, spr, error;
1887 u32 val;
1888
1889 wps = 0x34;
1890 spr = 0x48;
1891
1892 sysc_write(ddata, spr, 0xaaaa);
1893 error = readl_poll_timeout(ddata->module_va + wps, val,
1894 !(val & 0x10), 100,
1895 MAX_MODULE_SOFTRESET_WAIT);
1896 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001897 dev_warn(ddata->dev, "wdt disable step1 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001898
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001899 sysc_write(ddata, spr, 0x5555);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001900 error = readl_poll_timeout(ddata->module_va + wps, val,
1901 !(val & 0x10), 100,
1902 MAX_MODULE_SOFTRESET_WAIT);
1903 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001904 dev_warn(ddata->dev, "wdt disable step2 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001905}
1906
Suman Annab2745d92020-02-27 16:28:34 -06001907/* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
1908static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
1909{
1910 u32 reg;
1911
1912 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1913 reg |= SYSC_PRUSS_STANDBY_INIT;
1914 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1915}
1916
Tony Lindgren4e23be42019-06-10 04:48:05 -07001917static void sysc_init_module_quirks(struct sysc *ddata)
1918{
1919 if (ddata->legacy_mode || !ddata->name)
1920 return;
1921
1922 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001923 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001924
1925 return;
1926 }
1927
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001928#ifdef CONFIG_OMAP_GPMC_DEBUG
1929 if (ddata->cfg.quirks & SYSC_QUIRK_GPMC_DEBUG) {
1930 ddata->cfg.quirks |= SYSC_QUIRK_NO_RESET_ON_INIT;
1931
1932 return;
1933 }
1934#endif
1935
Tony Lindgren4e23be42019-06-10 04:48:05 -07001936 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001937 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
1938 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001939
1940 return;
1941 }
1942
Tony Lindgren020003f2019-11-14 08:25:28 -08001943 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
1944 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
1945
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001946 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
1947 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
1948
Tony Lindgrene8639e12020-02-24 12:58:03 -08001949 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
1950 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
1951 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
1952
1953 return;
1954 }
1955
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001956 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
1957 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
1958
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001959 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
Tony Lindgren4e23be42019-06-10 04:48:05 -07001960 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001961 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
1962 }
Suman Annab2745d92020-02-27 16:28:34 -06001963
1964 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
1965 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001966}
1967
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001968static int sysc_clockdomain_init(struct sysc *ddata)
1969{
1970 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1971 struct clk *fck = NULL, *ick = NULL;
1972 int error;
1973
1974 if (!pdata || !pdata->init_clockdomain)
1975 return 0;
1976
1977 switch (ddata->nr_clocks) {
1978 case 2:
1979 ick = ddata->clocks[SYSC_ICK];
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001980 fallthrough;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001981 case 1:
1982 fck = ddata->clocks[SYSC_FCK];
1983 break;
1984 case 0:
1985 return 0;
1986 }
1987
1988 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1989 if (!error || error == -ENODEV)
1990 return 0;
1991
1992 return error;
1993}
1994
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001995/*
1996 * Note that pdata->init_module() typically does a reset first. After
1997 * pdata->init_module() is done, PM runtime can be used for the interconnect
1998 * target module.
1999 */
2000static int sysc_legacy_init(struct sysc *ddata)
2001{
2002 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2003 int error;
2004
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002005 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002006 return 0;
2007
2008 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
2009 if (error == -EEXIST)
2010 error = 0;
2011
2012 return error;
2013}
2014
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002015/*
2016 * Note that the caller must ensure the interconnect target module is enabled
2017 * before calling reset. Otherwise reset will not complete.
2018 */
Faiz Abbas596e7952018-07-09 22:18:39 +05302019static int sysc_reset(struct sysc *ddata)
2020{
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002021 int sysc_offset, sysc_val, error;
2022 u32 sysc_mask;
Faiz Abbas596e7952018-07-09 22:18:39 +05302023
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002024 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002025
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002026 if (ddata->legacy_mode ||
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002027 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05302028 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
2029 return 0;
2030
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002031 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05302032
Tony Lindgrene64c0212020-02-24 12:58:03 -08002033 if (ddata->pre_reset_quirk)
2034 ddata->pre_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002035
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002036 if (sysc_offset >= 0) {
2037 sysc_val = sysc_read_sysconfig(ddata);
2038 sysc_val |= sysc_mask;
2039 sysc_write(ddata, sysc_offset, sysc_val);
2040 }
Faiz Abbas596e7952018-07-09 22:18:39 +05302041
Tony Lindgrene709ed72019-12-12 08:20:10 -08002042 if (ddata->cfg.srst_udelay)
2043 usleep_range(ddata->cfg.srst_udelay,
2044 ddata->cfg.srst_udelay * 2);
2045
Tony Lindgrene64c0212020-02-24 12:58:03 -08002046 if (ddata->post_reset_quirk)
2047 ddata->post_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002048
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002049 error = sysc_wait_softreset(ddata);
2050 if (error)
2051 dev_warn(ddata->dev, "OCP softreset timed out\n");
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002052
Tony Lindgren4e23be42019-06-10 04:48:05 -07002053 if (ddata->reset_done_quirk)
2054 ddata->reset_done_quirk(ddata);
2055
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002056 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05302057}
2058
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002059/*
2060 * At this point the module is configured enough to read the revision but
2061 * module may not be completely configured yet to use PM runtime. Enable
2062 * all clocks directly during init to configure the quirks needed for PM
2063 * runtime based on the revision register.
2064 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08002065static int sysc_init_module(struct sysc *ddata)
2066{
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002067 bool rstctrl_deasserted = false;
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002068 int error = 0;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002069
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002070 error = sysc_clockdomain_init(ddata);
2071 if (error)
2072 return error;
2073
Tony Lindgrend0989132019-09-05 07:37:22 -07002074 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002075
Tony Lindgrend0989132019-09-05 07:37:22 -07002076 /*
2077 * Always enable clocks. The bootloader may or may not have enabled
2078 * the related clocks.
2079 */
2080 error = sysc_enable_opt_clocks(ddata);
2081 if (error)
2082 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002083
Tony Lindgrend0989132019-09-05 07:37:22 -07002084 error = sysc_enable_main_clocks(ddata);
2085 if (error)
2086 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05302087
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002088 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
Tero Kristodf4f3452019-10-07 15:29:30 +03002089 error = reset_control_deassert(ddata->rsts);
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002090 if (error)
2091 goto err_main_clocks;
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002092 rstctrl_deasserted = true;
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002093 }
2094
Tony Lindgren566a9b052017-12-15 09:41:19 -08002095 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002096 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002097 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002098
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002099 if (ddata->legacy_mode) {
2100 error = sysc_legacy_init(ddata);
2101 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002102 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002103 }
2104
Tony Lindgrend0989132019-09-05 07:37:22 -07002105 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002106 error = sysc_enable_module(ddata->dev);
2107 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002108 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002109 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002110
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002111 error = sysc_reset(ddata);
2112 if (error)
2113 dev_err(ddata->dev, "Reset failed with %d\n", error);
2114
Tero Kristocdc56c12019-10-07 15:29:31 +03002115 if (error && !ddata->legacy_mode)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002116 sysc_disable_module(ddata->dev);
2117
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002118err_main_clocks:
Tero Kristocdc56c12019-10-07 15:29:31 +03002119 if (error)
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002120 sysc_disable_main_clocks(ddata);
2121err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07002122 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tero Kristocdc56c12019-10-07 15:29:31 +03002123 if (error) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002124 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002125 sysc_clkdm_allow_idle(ddata);
2126 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002127
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002128 if (error && rstctrl_deasserted &&
2129 !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
2130 reset_control_assert(ddata->rsts);
2131
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002132 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002133}
2134
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002135static int sysc_init_sysc_mask(struct sysc *ddata)
2136{
2137 struct device_node *np = ddata->dev->of_node;
2138 int error;
2139 u32 val;
2140
2141 error = of_property_read_u32(np, "ti,sysc-mask", &val);
2142 if (error)
2143 return 0;
2144
Tony Lindgrene212abd2019-07-22 03:44:52 -07002145 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002146
2147 return 0;
2148}
2149
2150static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
2151 const char *name)
2152{
2153 struct device_node *np = ddata->dev->of_node;
2154 struct property *prop;
2155 const __be32 *p;
2156 u32 val;
2157
2158 of_property_for_each_u32(np, name, prop, p, val) {
2159 if (val >= SYSC_NR_IDLEMODES) {
2160 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
2161 return -EINVAL;
2162 }
2163 *idlemodes |= (1 << val);
2164 }
2165
2166 return 0;
2167}
2168
2169static int sysc_init_idlemodes(struct sysc *ddata)
2170{
2171 int error;
2172
2173 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
2174 "ti,sysc-midle");
2175 if (error)
2176 return error;
2177
2178 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
2179 "ti,sysc-sidle");
2180 if (error)
2181 return error;
2182
2183 return 0;
2184}
2185
2186/*
2187 * Only some devices on omap4 and later have SYSCONFIG reset done
2188 * bit. We can detect this if there is no SYSSTATUS at all, or the
2189 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2190 * have multiple bits for the child devices like OHCI and EHCI.
2191 * Depends on SYSC being parsed first.
2192 */
2193static int sysc_init_syss_mask(struct sysc *ddata)
2194{
2195 struct device_node *np = ddata->dev->of_node;
2196 int error;
2197 u32 val;
2198
2199 error = of_property_read_u32(np, "ti,syss-mask", &val);
2200 if (error) {
2201 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2202 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2203 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2204 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2205
2206 return 0;
2207 }
2208
2209 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2210 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2211
2212 ddata->cfg.syss_mask = val;
2213
2214 return 0;
2215}
2216
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002217/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002218 * Many child device drivers need to have fck and opt clocks available
2219 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002220 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002221static int sysc_child_add_named_clock(struct sysc *ddata,
2222 struct device *child,
2223 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002224{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002225 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002226 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002227 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002228
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002229 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002230 return 0;
2231
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002232 clk = clk_get(child, name);
2233 if (!IS_ERR(clk)) {
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002234 error = -EEXIST;
2235 goto put_clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002236 }
2237
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002238 clk = clk_get(ddata->dev, name);
2239 if (IS_ERR(clk))
2240 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002241
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002242 l = clkdev_create(clk, name, dev_name(child));
2243 if (!l)
2244 error = -ENOMEM;
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002245put_clk:
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002246 clk_put(clk);
2247
2248 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002249}
2250
Tony Lindgren09dfe582018-04-16 10:25:52 -07002251static int sysc_child_add_clocks(struct sysc *ddata,
2252 struct device *child)
2253{
2254 int i, error;
2255
2256 for (i = 0; i < ddata->nr_clocks; i++) {
2257 error = sysc_child_add_named_clock(ddata,
2258 child,
2259 ddata->clock_roles[i]);
2260 if (error && error != -EEXIST) {
2261 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2262 ddata->clock_roles[i], error);
2263
2264 return error;
2265 }
2266 }
2267
2268 return 0;
2269}
2270
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002271static struct device_type sysc_device_type = {
2272};
2273
2274static struct sysc *sysc_child_to_parent(struct device *dev)
2275{
2276 struct device *parent = dev->parent;
2277
2278 if (!parent || parent->type != &sysc_device_type)
2279 return NULL;
2280
2281 return dev_get_drvdata(parent);
2282}
2283
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002284static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2285{
2286 struct sysc *ddata;
2287 int error;
2288
2289 ddata = sysc_child_to_parent(dev);
2290
2291 error = pm_generic_runtime_suspend(dev);
2292 if (error)
2293 return error;
2294
2295 if (!ddata->enabled)
2296 return 0;
2297
2298 return sysc_runtime_suspend(ddata->dev);
2299}
2300
2301static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2302{
2303 struct sysc *ddata;
2304 int error;
2305
2306 ddata = sysc_child_to_parent(dev);
2307
2308 if (!ddata->enabled) {
2309 error = sysc_runtime_resume(ddata->dev);
2310 if (error < 0)
2311 dev_err(ddata->dev,
2312 "%s error: %i\n", __func__, error);
2313 }
2314
2315 return pm_generic_runtime_resume(dev);
2316}
2317
2318#ifdef CONFIG_PM_SLEEP
2319static int sysc_child_suspend_noirq(struct device *dev)
2320{
2321 struct sysc *ddata;
2322 int error;
2323
2324 ddata = sysc_child_to_parent(dev);
2325
Tony Lindgrenef55f822018-04-16 10:27:15 -07002326 dev_dbg(ddata->dev, "%s %s\n", __func__,
2327 ddata->name ? ddata->name : "");
2328
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002329 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002330 if (error) {
2331 dev_err(dev, "%s error at %i: %i\n",
2332 __func__, __LINE__, error);
2333
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002334 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002335 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002336
2337 if (!pm_runtime_status_suspended(dev)) {
2338 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002339 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07002340 dev_dbg(dev, "%s busy at %i: %i\n",
2341 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002342
Tony Lindgren4f3530f2018-08-08 01:07:06 -07002343 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002344 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002345
2346 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002347 if (error) {
2348 dev_err(dev, "%s error at %i: %i\n",
2349 __func__, __LINE__, error);
2350
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002351 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002352 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002353
2354 ddata->child_needs_resume = true;
2355 }
2356
2357 return 0;
2358}
2359
2360static int sysc_child_resume_noirq(struct device *dev)
2361{
2362 struct sysc *ddata;
2363 int error;
2364
2365 ddata = sysc_child_to_parent(dev);
2366
Tony Lindgrenef55f822018-04-16 10:27:15 -07002367 dev_dbg(ddata->dev, "%s %s\n", __func__,
2368 ddata->name ? ddata->name : "");
2369
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002370 if (ddata->child_needs_resume) {
2371 ddata->child_needs_resume = false;
2372
2373 error = sysc_runtime_resume(ddata->dev);
2374 if (error)
2375 dev_err(ddata->dev,
2376 "%s runtime resume error: %i\n",
2377 __func__, error);
2378
2379 error = pm_generic_runtime_resume(dev);
2380 if (error)
2381 dev_err(ddata->dev,
2382 "%s generic runtime resume: %i\n",
2383 __func__, error);
2384 }
2385
2386 return pm_generic_resume_noirq(dev);
2387}
2388#endif
2389
Tony Lindgrenb7182b42019-03-21 11:00:21 -07002390static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002391 .ops = {
2392 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2393 sysc_child_runtime_resume,
2394 NULL)
2395 USE_PLATFORM_PM_SLEEP_OPS
2396 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2397 sysc_child_resume_noirq)
2398 }
2399};
2400
2401/**
2402 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2403 * @ddata: device driver data
2404 * @child: child device driver
2405 *
2406 * Allow idle for child devices as done with _od_runtime_suspend().
2407 * Otherwise many child devices will not idle because of the permanent
2408 * parent usecount set in pm_runtime_irq_safe().
2409 *
2410 * Note that the long term solution is to just modify the child device
2411 * drivers to not set pm_runtime_irq_safe() and then this can be just
2412 * dropped.
2413 */
2414static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2415{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002416 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2417 dev_pm_domain_set(child, &sysc_child_pm_domain);
2418}
2419
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002420static int sysc_notifier_call(struct notifier_block *nb,
2421 unsigned long event, void *device)
2422{
2423 struct device *dev = device;
2424 struct sysc *ddata;
2425 int error;
2426
2427 ddata = sysc_child_to_parent(dev);
2428 if (!ddata)
2429 return NOTIFY_DONE;
2430
2431 switch (event) {
2432 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07002433 error = sysc_child_add_clocks(ddata, dev);
2434 if (error)
2435 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002436 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002437 break;
2438 default:
2439 break;
2440 }
2441
2442 return NOTIFY_DONE;
2443}
2444
2445static struct notifier_block sysc_nb = {
2446 .notifier_call = sysc_notifier_call,
2447};
2448
Tony Lindgren566a9b052017-12-15 09:41:19 -08002449/* Device tree configured quirks */
2450struct sysc_dts_quirk {
2451 const char *name;
2452 u32 mask;
2453};
2454
2455static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2456 { .name = "ti,no-idle-on-init",
2457 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2458 { .name = "ti,no-reset-on-init",
2459 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002460 { .name = "ti,no-idle",
2461 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002462};
2463
Tony Lindgren4014c082018-12-10 14:11:26 -08002464static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2465 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002466{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002467 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002468 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002469
2470 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002471 const char *name = sysc_dts_quirks[i].name;
2472
2473 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002474 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002475 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002476
2477 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002478 if (is_child) {
2479 dev_warn(ddata->dev,
2480 "dts flag should be at module level for %s\n",
2481 name);
2482 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002483 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002484}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002485
Tony Lindgren4014c082018-12-10 14:11:26 -08002486static int sysc_init_dts_quirks(struct sysc *ddata)
2487{
2488 struct device_node *np = ddata->dev->of_node;
2489 int error;
2490 u32 val;
2491
2492 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2493
2494 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002495 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2496 if (!error) {
2497 if (val > 255) {
2498 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2499 val);
2500 }
2501
2502 ddata->cfg.srst_udelay = (u8)val;
2503 }
2504
2505 return 0;
2506}
2507
Tony Lindgren0eecc632017-10-10 14:23:43 -07002508static void sysc_unprepare(struct sysc *ddata)
2509{
2510 int i;
2511
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002512 if (!ddata->clocks)
2513 return;
2514
Tony Lindgren0eecc632017-10-10 14:23:43 -07002515 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2516 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2517 clk_unprepare(ddata->clocks[i]);
2518 }
2519}
2520
Tony Lindgren70a65242017-12-15 09:41:09 -08002521/*
2522 * Common sysc register bits found on omap2, also known as type1
2523 */
2524static const struct sysc_regbits sysc_regbits_omap2 = {
2525 .dmadisable_shift = -ENODEV,
2526 .midle_shift = 12,
2527 .sidle_shift = 3,
2528 .clkact_shift = 8,
2529 .emufree_shift = 5,
2530 .enwkup_shift = 2,
2531 .srst_shift = 1,
2532 .autoidle_shift = 0,
2533};
2534
2535static const struct sysc_capabilities sysc_omap2 = {
2536 .type = TI_SYSC_OMAP2,
2537 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2538 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2539 SYSC_OMAP2_AUTOIDLE,
2540 .regbits = &sysc_regbits_omap2,
2541};
2542
2543/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2544static const struct sysc_capabilities sysc_omap2_timer = {
2545 .type = TI_SYSC_OMAP2_TIMER,
2546 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2547 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2548 SYSC_OMAP2_AUTOIDLE,
2549 .regbits = &sysc_regbits_omap2,
2550 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2551};
2552
2553/*
2554 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2555 * with different sidle position
2556 */
2557static const struct sysc_regbits sysc_regbits_omap3_sham = {
2558 .dmadisable_shift = -ENODEV,
2559 .midle_shift = -ENODEV,
2560 .sidle_shift = 4,
2561 .clkact_shift = -ENODEV,
2562 .enwkup_shift = -ENODEV,
2563 .srst_shift = 1,
2564 .autoidle_shift = 0,
2565 .emufree_shift = -ENODEV,
2566};
2567
2568static const struct sysc_capabilities sysc_omap3_sham = {
2569 .type = TI_SYSC_OMAP3_SHAM,
2570 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2571 .regbits = &sysc_regbits_omap3_sham,
2572};
2573
2574/*
2575 * AES register bits found on omap3 and later, a variant of
2576 * sysc_regbits_omap2 with different sidle position
2577 */
2578static const struct sysc_regbits sysc_regbits_omap3_aes = {
2579 .dmadisable_shift = -ENODEV,
2580 .midle_shift = -ENODEV,
2581 .sidle_shift = 6,
2582 .clkact_shift = -ENODEV,
2583 .enwkup_shift = -ENODEV,
2584 .srst_shift = 1,
2585 .autoidle_shift = 0,
2586 .emufree_shift = -ENODEV,
2587};
2588
2589static const struct sysc_capabilities sysc_omap3_aes = {
2590 .type = TI_SYSC_OMAP3_AES,
2591 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2592 .regbits = &sysc_regbits_omap3_aes,
2593};
2594
2595/*
2596 * Common sysc register bits found on omap4, also known as type2
2597 */
2598static const struct sysc_regbits sysc_regbits_omap4 = {
2599 .dmadisable_shift = 16,
2600 .midle_shift = 4,
2601 .sidle_shift = 2,
2602 .clkact_shift = -ENODEV,
2603 .enwkup_shift = -ENODEV,
2604 .emufree_shift = 1,
2605 .srst_shift = 0,
2606 .autoidle_shift = -ENODEV,
2607};
2608
2609static const struct sysc_capabilities sysc_omap4 = {
2610 .type = TI_SYSC_OMAP4,
2611 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2612 SYSC_OMAP4_SOFTRESET,
2613 .regbits = &sysc_regbits_omap4,
2614};
2615
2616static const struct sysc_capabilities sysc_omap4_timer = {
2617 .type = TI_SYSC_OMAP4_TIMER,
2618 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2619 SYSC_OMAP4_SOFTRESET,
2620 .regbits = &sysc_regbits_omap4,
2621};
2622
2623/*
2624 * Common sysc register bits found on omap4, also known as type3
2625 */
2626static const struct sysc_regbits sysc_regbits_omap4_simple = {
2627 .dmadisable_shift = -ENODEV,
2628 .midle_shift = 2,
2629 .sidle_shift = 0,
2630 .clkact_shift = -ENODEV,
2631 .enwkup_shift = -ENODEV,
2632 .srst_shift = -ENODEV,
2633 .emufree_shift = -ENODEV,
2634 .autoidle_shift = -ENODEV,
2635};
2636
2637static const struct sysc_capabilities sysc_omap4_simple = {
2638 .type = TI_SYSC_OMAP4_SIMPLE,
2639 .regbits = &sysc_regbits_omap4_simple,
2640};
2641
2642/*
2643 * SmartReflex sysc found on omap34xx
2644 */
2645static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2646 .dmadisable_shift = -ENODEV,
2647 .midle_shift = -ENODEV,
2648 .sidle_shift = -ENODEV,
2649 .clkact_shift = 20,
2650 .enwkup_shift = -ENODEV,
2651 .srst_shift = -ENODEV,
2652 .emufree_shift = -ENODEV,
2653 .autoidle_shift = -ENODEV,
2654};
2655
2656static const struct sysc_capabilities sysc_34xx_sr = {
2657 .type = TI_SYSC_OMAP34XX_SR,
2658 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2659 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002660 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2661 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002662};
2663
2664/*
2665 * SmartReflex sysc found on omap36xx and later
2666 */
2667static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2668 .dmadisable_shift = -ENODEV,
2669 .midle_shift = -ENODEV,
2670 .sidle_shift = 24,
2671 .clkact_shift = -ENODEV,
2672 .enwkup_shift = 26,
2673 .srst_shift = -ENODEV,
2674 .emufree_shift = -ENODEV,
2675 .autoidle_shift = -ENODEV,
2676};
2677
2678static const struct sysc_capabilities sysc_36xx_sr = {
2679 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002680 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002681 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002682 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002683};
2684
2685static const struct sysc_capabilities sysc_omap4_sr = {
2686 .type = TI_SYSC_OMAP4_SR,
2687 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002688 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002689};
2690
2691/*
2692 * McASP register bits found on omap4 and later
2693 */
2694static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2695 .dmadisable_shift = -ENODEV,
2696 .midle_shift = -ENODEV,
2697 .sidle_shift = 0,
2698 .clkact_shift = -ENODEV,
2699 .enwkup_shift = -ENODEV,
2700 .srst_shift = -ENODEV,
2701 .emufree_shift = -ENODEV,
2702 .autoidle_shift = -ENODEV,
2703};
2704
2705static const struct sysc_capabilities sysc_omap4_mcasp = {
2706 .type = TI_SYSC_OMAP4_MCASP,
2707 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002708 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2709};
2710
2711/*
2712 * McASP found on dra7 and later
2713 */
2714static const struct sysc_capabilities sysc_dra7_mcasp = {
2715 .type = TI_SYSC_OMAP4_SIMPLE,
2716 .regbits = &sysc_regbits_omap4_simple,
2717 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002718};
2719
2720/*
2721 * FS USB host found on omap4 and later
2722 */
2723static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2724 .dmadisable_shift = -ENODEV,
2725 .midle_shift = -ENODEV,
2726 .sidle_shift = 24,
2727 .clkact_shift = -ENODEV,
2728 .enwkup_shift = 26,
2729 .srst_shift = -ENODEV,
2730 .emufree_shift = -ENODEV,
2731 .autoidle_shift = -ENODEV,
2732};
2733
2734static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2735 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2736 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2737 .regbits = &sysc_regbits_omap4_usb_host_fs,
2738};
2739
Faiz Abbas7f35e632018-07-09 22:18:38 +05302740static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2741 .dmadisable_shift = -ENODEV,
2742 .midle_shift = -ENODEV,
2743 .sidle_shift = -ENODEV,
2744 .clkact_shift = -ENODEV,
2745 .enwkup_shift = 4,
2746 .srst_shift = 0,
2747 .emufree_shift = -ENODEV,
2748 .autoidle_shift = -ENODEV,
2749};
2750
2751static const struct sysc_capabilities sysc_dra7_mcan = {
2752 .type = TI_SYSC_DRA7_MCAN,
2753 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2754 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002755 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302756};
2757
Suman Annab2745d92020-02-27 16:28:34 -06002758/*
2759 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2760 */
2761static const struct sysc_capabilities sysc_pruss = {
2762 .type = TI_SYSC_PRUSS,
2763 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2764 .regbits = &sysc_regbits_omap4_simple,
2765 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2766};
2767
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002768static int sysc_init_pdata(struct sysc *ddata)
2769{
2770 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002771 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002772
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002773 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002774 return 0;
2775
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002776 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2777 if (!mdata)
2778 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002779
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002780 if (ddata->legacy_mode) {
2781 mdata->name = ddata->legacy_mode;
2782 mdata->module_pa = ddata->module_pa;
2783 mdata->module_size = ddata->module_size;
2784 mdata->offsets = ddata->offsets;
2785 mdata->nr_offsets = SYSC_MAX_REGS;
2786 mdata->cap = ddata->cap;
2787 mdata->cfg = &ddata->cfg;
2788 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002789
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002790 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002791
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002792 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002793}
2794
Tony Lindgren70a65242017-12-15 09:41:09 -08002795static int sysc_init_match(struct sysc *ddata)
2796{
2797 const struct sysc_capabilities *cap;
2798
2799 cap = of_device_get_match_data(ddata->dev);
2800 if (!cap)
2801 return -EINVAL;
2802
2803 ddata->cap = cap;
2804 if (ddata->cap)
2805 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2806
2807 return 0;
2808}
2809
Tony Lindgren76f0f772018-02-23 08:28:45 -08002810static void ti_sysc_idle(struct work_struct *work)
2811{
2812 struct sysc *ddata;
2813
2814 ddata = container_of(work, struct sysc, idle_work.work);
2815
Tony Lindgrend0989132019-09-05 07:37:22 -07002816 /*
2817 * One time decrement of clock usage counts if left on from init.
2818 * Note that we disable opt clocks unconditionally in this case
2819 * as they are enabled unconditionally during init without
2820 * considering sysc_opt_clks_needed() at that point.
2821 */
2822 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2823 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
Tony Lindgrend0989132019-09-05 07:37:22 -07002824 sysc_disable_main_clocks(ddata);
2825 sysc_disable_opt_clocks(ddata);
2826 sysc_clkdm_allow_idle(ddata);
2827 }
2828
2829 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2830 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2831 return;
2832
2833 /*
2834 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2835 * and SYSC_QUIRK_NO_RESET_ON_INIT
2836 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002837 if (pm_runtime_active(ddata->dev))
2838 pm_runtime_put_sync(ddata->dev);
2839}
2840
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002841/*
2842 * SoC model and features detection. Only needed for SoCs that need
2843 * special handling for quirks, no need to list others.
2844 */
2845static const struct soc_device_attribute sysc_soc_match[] = {
2846 SOC_FLAG("OMAP242*", SOC_2420),
2847 SOC_FLAG("OMAP243*", SOC_2430),
2848 SOC_FLAG("OMAP3[45]*", SOC_3430),
2849 SOC_FLAG("OMAP3[67]*", SOC_3630),
2850 SOC_FLAG("OMAP443*", SOC_4430),
2851 SOC_FLAG("OMAP446*", SOC_4460),
2852 SOC_FLAG("OMAP447*", SOC_4470),
2853 SOC_FLAG("OMAP54*", SOC_5430),
2854 SOC_FLAG("AM433", SOC_AM3),
2855 SOC_FLAG("AM43*", SOC_AM4),
2856 SOC_FLAG("DRA7*", SOC_DRA7),
2857
2858 { /* sentinel */ },
2859};
2860
2861/*
2862 * List of SoCs variants with disabled features. By default we assume all
2863 * devices in the device tree are available so no need to list those SoCs.
2864 */
2865static const struct soc_device_attribute sysc_soc_feat_match[] = {
2866 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
2867 SOC_FLAG("AM3505", DIS_SGX),
2868 SOC_FLAG("OMAP3525", DIS_SGX),
2869 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
2870 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
2871
2872 /* OMAP3630/DM3730 variants with some accelerators disabled */
2873 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
2874 SOC_FLAG("DM3725", DIS_SGX),
2875 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
2876 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
2877 SOC_FLAG("OMAP3621", DIS_ISP),
2878
2879 { /* sentinel */ },
2880};
2881
2882static int sysc_add_disabled(unsigned long base)
2883{
2884 struct sysc_address *disabled_module;
2885
2886 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
2887 if (!disabled_module)
2888 return -ENOMEM;
2889
2890 disabled_module->base = base;
2891
2892 mutex_lock(&sysc_soc->list_lock);
2893 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
2894 mutex_unlock(&sysc_soc->list_lock);
2895
2896 return 0;
2897}
2898
2899/*
2900 * One time init to detect the booted SoC and disable unavailable features.
2901 * Note that we initialize static data shared across all ti-sysc instances
2902 * so ddata is only used for SoC type. This can be called from module_init
2903 * once we no longer need to rely on platform data.
2904 */
2905static int sysc_init_soc(struct sysc *ddata)
2906{
2907 const struct soc_device_attribute *match;
2908 struct ti_sysc_platform_data *pdata;
2909 unsigned long features = 0;
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002910 struct device_node *np;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002911
2912 if (sysc_soc)
2913 return 0;
2914
2915 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
2916 if (!sysc_soc)
2917 return -ENOMEM;
2918
2919 mutex_init(&sysc_soc->list_lock);
2920 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
2921 sysc_soc->general_purpose = true;
2922
2923 pdata = dev_get_platdata(ddata->dev);
2924 if (pdata && pdata->soc_type_gp)
2925 sysc_soc->general_purpose = pdata->soc_type_gp();
2926
2927 match = soc_device_match(sysc_soc_match);
2928 if (match && match->data)
2929 sysc_soc->soc = (int)match->data;
2930
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002931 /*
2932 * Check and warn about possible old incomplete dtb. We now want to see
2933 * simple-pm-bus instead of simple-bus in the dtb for genpd using SoCs.
2934 */
2935 switch (sysc_soc->soc) {
2936 case SOC_AM3:
2937 case SOC_AM4:
Tony Lindgren4adcf4c2021-03-12 10:23:48 +02002938 case SOC_4430 ... SOC_4470:
2939 case SOC_5430:
2940 case SOC_DRA7:
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002941 np = of_find_node_by_path("/ocp");
2942 WARN_ONCE(np && of_device_is_compatible(np, "simple-bus"),
2943 "ti-sysc: Incomplete old dtb, please update\n");
2944 break;
2945 default:
2946 break;
2947 }
2948
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002949 /* Ignore devices that are not available on HS and EMU SoCs */
2950 if (!sysc_soc->general_purpose) {
2951 switch (sysc_soc->soc) {
2952 case SOC_3430 ... SOC_3630:
2953 sysc_add_disabled(0x48304000); /* timer12 */
2954 break;
2955 default:
2956 break;
Yang Li52fbb5a2021-02-02 15:00:05 +08002957 }
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002958 }
2959
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002960 match = soc_device_match(sysc_soc_feat_match);
2961 if (!match)
2962 return 0;
2963
2964 if (match->data)
2965 features = (unsigned long)match->data;
2966
2967 /*
2968 * Add disabled devices to the list based on the module base.
2969 * Note that this must be done before we attempt to access the
2970 * device and have module revision checks working.
2971 */
2972 if (features & DIS_ISP)
2973 sysc_add_disabled(0x480bd400);
2974 if (features & DIS_IVA)
2975 sysc_add_disabled(0x5d000000);
2976 if (features & DIS_SGX)
2977 sysc_add_disabled(0x50000000);
2978
2979 return 0;
2980}
2981
2982static void sysc_cleanup_soc(void)
2983{
2984 struct sysc_address *disabled_module;
2985 struct list_head *pos, *tmp;
2986
2987 if (!sysc_soc)
2988 return;
2989
2990 mutex_lock(&sysc_soc->list_lock);
2991 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
2992 disabled_module = list_entry(pos, struct sysc_address, node);
2993 list_del(pos);
2994 kfree(disabled_module);
2995 }
2996 mutex_unlock(&sysc_soc->list_lock);
2997}
2998
2999static int sysc_check_disabled_devices(struct sysc *ddata)
3000{
3001 struct sysc_address *disabled_module;
3002 struct list_head *pos;
3003 int error = 0;
3004
3005 mutex_lock(&sysc_soc->list_lock);
3006 list_for_each(pos, &sysc_soc->disabled_modules) {
3007 disabled_module = list_entry(pos, struct sysc_address, node);
3008 if (ddata->module_pa == disabled_module->base) {
3009 dev_dbg(ddata->dev, "module disabled for this SoC\n");
3010 error = -ENODEV;
3011 break;
3012 }
3013 }
3014 mutex_unlock(&sysc_soc->list_lock);
3015
3016 return error;
3017}
3018
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003019/*
3020 * Ignore timers tagged with no-reset and no-idle. These are likely in use,
3021 * for example by drivers/clocksource/timer-ti-dm-systimer.c. If more checks
3022 * are needed, we could also look at the timer register configuration.
3023 */
3024static int sysc_check_active_timer(struct sysc *ddata)
3025{
3026 if (ddata->cap->type != TI_SYSC_OMAP2_TIMER &&
3027 ddata->cap->type != TI_SYSC_OMAP4_TIMER)
3028 return 0;
3029
3030 if ((ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) &&
3031 (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE))
Grygorii Strashko65fb7362020-11-18 16:19:00 +02003032 return -ENXIO;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003033
3034 return 0;
3035}
3036
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003037static const struct of_device_id sysc_match_table[] = {
3038 { .compatible = "simple-bus", },
3039 { /* sentinel */ },
3040};
3041
Tony Lindgren0eecc632017-10-10 14:23:43 -07003042static int sysc_probe(struct platform_device *pdev)
3043{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003044 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003045 struct sysc *ddata;
3046 int error;
3047
3048 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
3049 if (!ddata)
3050 return -ENOMEM;
3051
Tony Lindgren29281352020-11-16 12:57:13 +02003052 ddata->offsets[SYSC_REVISION] = -ENODEV;
3053 ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
3054 ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003055 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003056 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003057
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003058 error = sysc_init_soc(ddata);
3059 if (error)
3060 return error;
3061
Tony Lindgren70a65242017-12-15 09:41:09 -08003062 error = sysc_init_match(ddata);
3063 if (error)
3064 return error;
3065
Tony Lindgren566a9b052017-12-15 09:41:19 -08003066 error = sysc_init_dts_quirks(ddata);
3067 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003068 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003069
Tony Lindgren0eecc632017-10-10 14:23:43 -07003070 error = sysc_map_and_check_registers(ddata);
3071 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003072 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003073
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003074 error = sysc_init_sysc_mask(ddata);
3075 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003076 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003077
3078 error = sysc_init_idlemodes(ddata);
3079 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003080 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003081
3082 error = sysc_init_syss_mask(ddata);
3083 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003084 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003085
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003086 error = sysc_init_pdata(ddata);
3087 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003088 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003089
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003090 sysc_init_early_quirks(ddata);
3091
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003092 error = sysc_check_disabled_devices(ddata);
3093 if (error)
3094 return error;
3095
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003096 error = sysc_check_active_timer(ddata);
3097 if (error)
3098 return error;
3099
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003100 error = sysc_get_clocks(ddata);
3101 if (error)
3102 return error;
3103
Tony Lindgren50622362018-04-16 10:20:27 -07003104 error = sysc_init_resets(ddata);
3105 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003106 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003107
3108 error = sysc_init_module(ddata);
3109 if (error)
3110 goto unprepare;
3111
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07003112 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003113 error = pm_runtime_get_sync(ddata->dev);
3114 if (error < 0) {
3115 pm_runtime_put_noidle(ddata->dev);
3116 pm_runtime_disable(ddata->dev);
3117 goto unprepare;
3118 }
3119
Tero Kristocdc56c12019-10-07 15:29:31 +03003120 /* Balance use counts as PM runtime should have enabled these all */
Tero Kristocdc56c12019-10-07 15:29:31 +03003121 if (!(ddata->cfg.quirks &
3122 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
3123 sysc_disable_main_clocks(ddata);
3124 sysc_disable_opt_clocks(ddata);
3125 sysc_clkdm_allow_idle(ddata);
3126 }
3127
Tony Lindgren4097c9a2020-11-16 12:57:13 +02003128 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
3129 reset_control_assert(ddata->rsts);
3130
Tony Lindgren0eecc632017-10-10 14:23:43 -07003131 sysc_show_registers(ddata);
3132
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003133 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003134 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
3135 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003136 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003137 if (error)
3138 goto err;
3139
Tony Lindgren76f0f772018-02-23 08:28:45 -08003140 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
3141
3142 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07003143 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3144 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08003145 SYSC_QUIRK_NO_RESET_ON_INIT)) {
3146 schedule_delayed_work(&ddata->idle_work, 3000);
3147 } else {
3148 pm_runtime_put(&pdev->dev);
3149 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003150
3151 return 0;
3152
3153err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07003154 pm_runtime_put_sync(&pdev->dev);
3155 pm_runtime_disable(&pdev->dev);
3156unprepare:
3157 sysc_unprepare(ddata);
3158
3159 return error;
3160}
3161
Tony Lindgren684be5a2017-10-13 10:48:40 -07003162static int sysc_remove(struct platform_device *pdev)
3163{
3164 struct sysc *ddata = platform_get_drvdata(pdev);
3165 int error;
3166
Tony Lindgren76f0f772018-02-23 08:28:45 -08003167 cancel_delayed_work_sync(&ddata->idle_work);
3168
Tony Lindgren684be5a2017-10-13 10:48:40 -07003169 error = pm_runtime_get_sync(ddata->dev);
3170 if (error < 0) {
3171 pm_runtime_put_noidle(ddata->dev);
3172 pm_runtime_disable(ddata->dev);
3173 goto unprepare;
3174 }
3175
3176 of_platform_depopulate(&pdev->dev);
3177
Tony Lindgren684be5a2017-10-13 10:48:40 -07003178 pm_runtime_put_sync(&pdev->dev);
3179 pm_runtime_disable(&pdev->dev);
Tony Lindgrena7b5d7c2021-02-18 13:06:57 +02003180
3181 if (!reset_control_status(ddata->rsts))
3182 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003183
3184unprepare:
3185 sysc_unprepare(ddata);
3186
3187 return 0;
3188}
3189
Tony Lindgren0eecc632017-10-10 14:23:43 -07003190static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08003191 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
3192 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
3193 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
3194 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
3195 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
3196 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
3197 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
3198 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
3199 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
3200 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
3201 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08003202 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08003203 { .compatible = "ti,sysc-usb-host-fs",
3204 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05303205 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Suman Annab2745d92020-02-27 16:28:34 -06003206 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07003207 { },
3208};
3209MODULE_DEVICE_TABLE(of, sysc_match);
3210
3211static struct platform_driver sysc_driver = {
3212 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07003213 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07003214 .driver = {
3215 .name = "ti-sysc",
3216 .of_match_table = sysc_match,
3217 .pm = &sysc_pm_ops,
3218 },
3219};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003220
3221static int __init sysc_init(void)
3222{
3223 bus_register_notifier(&platform_bus_type, &sysc_nb);
3224
3225 return platform_driver_register(&sysc_driver);
3226}
3227module_init(sysc_init);
3228
3229static void __exit sysc_exit(void)
3230{
3231 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3232 platform_driver_unregister(&sysc_driver);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003233 sysc_cleanup_soc();
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003234}
3235module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003236
3237MODULE_DESCRIPTION("TI sysc interconnect target driver");
3238MODULE_LICENSE("GPL v2");