blob: f87783a5489a57092ec23d5d77e6c6e30c17ff6c [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 Lindgrenb6a53c42019-05-27 04:51:57 -07001447 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000046, 0xffffffff,
1448 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001449 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x00000052, 0xffffffff,
Tony Lindgrenb6a53c42019-05-27 04:51:57 -07001450 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrend708bb12018-04-16 10:25:32 -07001451 /* Uarts on omap4 and later */
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001452 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x50411e03, 0xffff00ff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001453 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgrenb82beef2018-09-24 12:16:59 -07001454 SYSC_QUIRK("uart", 0, 0x50, 0x54, 0x58, 0x47422e03, 0xffffffff,
Tony Lindgrenc8692ad2021-05-25 09:08:23 +03001455 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_LEGACY_IDLE),
Tony Lindgren7e27e5d2018-04-20 14:54:16 -07001456
Tony Lindgrena54275f2019-03-21 11:00:21 -07001457 /* Quirks that need to be set based on the module address */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001458 SYSC_QUIRK("mcpdm", 0x40132000, 0, 0x10, -ENODEV, 0x50000800, 0xffffffff,
Tony Lindgrena54275f2019-03-21 11:00:21 -07001459 SYSC_QUIRK_EXT_OPT_CLOCK | SYSC_QUIRK_NO_RESET_ON_INIT |
1460 SYSC_QUIRK_SWSUP_SIDLE),
1461
Tony Lindgren4e23be42019-06-10 04:48:05 -07001462 /* Quirks that need to be set based on detected module */
Tony Lindgren590e15c2020-02-24 12:58:03 -08001463 SYSC_QUIRK("aess", 0, 0, 0x10, -ENODEV, 0x40000000, 0xffffffff,
Tony Lindgren020003f2019-11-14 08:25:28 -08001464 SYSC_MODULE_QUIRK_AESS),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001465 SYSC_QUIRK("dcan", 0x48480000, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001466 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001467 SYSC_QUIRK("dss", 0x4832a000, 0, 0x10, 0x14, 0x00000020, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001468 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001469 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000040, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001470 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001471 SYSC_QUIRK("dss", 0x58000000, 0, -ENODEV, 0x14, 0x00000061, 0xffffffff,
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001472 SYSC_QUIRK_OPT_CLKS_IN_RESET | SYSC_MODULE_QUIRK_DSS_RESET),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001473 SYSC_QUIRK("dwc3", 0x48880000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001474 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001475 SYSC_QUIRK("dwc3", 0x488c0000, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff,
Tony Lindgren94f63452019-12-12 08:57:58 -08001476 SYSC_QUIRK_CLKDM_NOAUTO),
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001477 SYSC_QUIRK("gpmc", 0, 0, 0x10, 0x14, 0x00000060, 0xffffffff,
1478 SYSC_QUIRK_GPMC_DEBUG),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001479 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50030200, 0xffffffff,
1480 SYSC_QUIRK_OPT_CLKS_NEEDED),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001481 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x00000006, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001482 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001483 SYSC_QUIRK("hdq1w", 0, 0, 0x14, 0x18, 0x0000000a, 0xffffffff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001484 SYSC_MODULE_QUIRK_HDQ1W | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001485 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000036, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001486 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001487 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x0000003c, 0x000000ff,
Tony Lindgrene275d212020-10-26 10:08:47 +02001488 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001489 SYSC_QUIRK("i2c", 0, 0, 0x20, 0x10, 0x00000040, 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, 0x10, 0x90, 0x5040000a, 0xfffff0f0,
Tony Lindgrene275d212020-10-26 10:08:47 +02001492 SYSC_MODULE_QUIRK_I2C | SYSC_MODULE_QUIRK_ENA_RESETDONE),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001493 SYSC_QUIRK("gpu", 0x50000000, 0x14, -ENODEV, -ENODEV, 0x00010201, 0xffffffff, 0),
1494 SYSC_QUIRK("gpu", 0x50000000, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff,
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001495 SYSC_MODULE_QUIRK_SGX),
Tony Lindgrenaef067e2020-03-10 09:06:02 -07001496 SYSC_QUIRK("lcdc", 0, 0, 0x54, -ENODEV, 0x4f201000, 0xffffffff,
1497 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrene8639e12020-02-24 12:58:03 -08001498 SYSC_QUIRK("rtc", 0, 0x74, 0x78, -ENODEV, 0x4eb01908, 0xffff00f0,
1499 SYSC_MODULE_QUIRK_RTC_UNLOCK),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001500 SYSC_QUIRK("tptc", 0, 0, 0x10, -ENODEV, 0x40006c00, 0xffffefff,
1501 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1502 SYSC_QUIRK("tptc", 0, 0, -ENODEV, -ENODEV, 0x40007c00, 0xffffffff,
1503 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgrendb8e7122021-05-07 12:09:03 +03001504 SYSC_QUIRK("sata", 0, 0xfc, 0x1100, -ENODEV, 0x5e412000, 0xffffffff,
1505 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren42546322020-07-13 09:59:47 -07001506 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, 0x14, 0x50700100, 0xffffffff,
1507 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
1508 SYSC_QUIRK("usb_host_hs", 0, 0, 0x10, -ENODEV, 0x50700101, 0xffffffff,
1509 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren03856e92019-10-21 13:36:09 -07001510 SYSC_QUIRK("usb_otg_hs", 0, 0x400, 0x404, 0x408, 0x00000050,
1511 0xffffffff, SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001512 SYSC_QUIRK("usb_otg_hs", 0, 0, 0x10, -ENODEV, 0x4ea2080d, 0xffffffff,
Tony Lindgren4d7b3242021-05-18 09:47:23 +03001513 SYSC_QUIRK_SWSUP_SIDLE | SYSC_QUIRK_SWSUP_MSTANDBY |
1514 SYSC_QUIRK_REINIT_ON_RESUME),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001515 SYSC_QUIRK("wdt", 0, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1516 SYSC_MODULE_QUIRK_WDT),
Suman Annab2745d92020-02-27 16:28:34 -06001517 /* PRUSS on am3, am4 and am5 */
1518 SYSC_QUIRK("pruss", 0, 0x26000, 0x26004, -ENODEV, 0x47000000, 0xff000000,
1519 SYSC_MODULE_QUIRK_PRUSS),
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001520 /* Watchdog on am3 and am4 */
1521 SYSC_QUIRK("wdt", 0x44e35000, 0, 0x10, 0x14, 0x502a0500, 0xfffff0f0,
1522 SYSC_MODULE_QUIRK_WDT | SYSC_QUIRK_SWSUP_SIDLE),
Tony Lindgren4e23be42019-06-10 04:48:05 -07001523
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001524#ifdef DEBUG
Tony Lindgren590e15c2020-02-24 12:58:03 -08001525 SYSC_QUIRK("adc", 0, 0, 0x10, -ENODEV, 0x47300001, 0xffffffff, 0),
1526 SYSC_QUIRK("atl", 0, 0, -ENODEV, -ENODEV, 0x0a070100, 0xffffffff, 0),
1527 SYSC_QUIRK("cm", 0, 0, -ENODEV, -ENODEV, 0x40000301, 0xffffffff, 0),
1528 SYSC_QUIRK("control", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001529 SYSC_QUIRK("cpgmac", 0, 0x1200, 0x1208, 0x1204, 0x4edb1902,
Tony Lindgren23731ea2018-09-24 12:17:09 -07001530 0xffff00f0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001531 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0xa3170504, 0xffffffff, 0),
1532 SYSC_QUIRK("dcan", 0, 0x20, -ENODEV, -ENODEV, 0x4edb1902, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001533 SYSC_QUIRK("dispc", 0x4832a400, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1534 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1535 SYSC_QUIRK("dispc", 0x58001000, 0, 0x10, 0x14, 0x00000051, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001536 SYSC_QUIRK("dmic", 0, 0, 0x10, -ENODEV, 0x50010000, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001537 SYSC_QUIRK("dsi", 0x58004000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1538 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000030, 0xffffffff, 0),
1539 SYSC_QUIRK("dsi", 0x58005000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
1540 SYSC_QUIRK("dsi", 0x58009000, 0, 0x10, 0x14, 0x00000040, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001541 SYSC_QUIRK("dwc3", 0, 0, 0x10, -ENODEV, 0x500a0200, 0xffffffff, 0),
Tony Lindgren7edd00f2019-08-14 05:18:16 -07001542 SYSC_QUIRK("d2d", 0x4a0b6000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1543 SYSC_QUIRK("d2d", 0x4a0cd000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001544 SYSC_QUIRK("elm", 0x48080000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
1545 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x40441403, 0xffff0fff, 0),
1546 SYSC_QUIRK("emif", 0, 0, -ENODEV, -ENODEV, 0x50440500, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001547 SYSC_QUIRK("epwmss", 0, 0, 0x4, -ENODEV, 0x47400001, 0xffffffff, 0),
1548 SYSC_QUIRK("gpu", 0, 0x1fc00, 0x1fc10, -ENODEV, 0, 0, 0),
1549 SYSC_QUIRK("gpu", 0, 0xfe00, 0xfe10, -ENODEV, 0x40000000 , 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001550 SYSC_QUIRK("hdmi", 0, 0, 0x10, -ENODEV, 0x50031d00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001551 SYSC_QUIRK("hsi", 0, 0, 0x10, 0x14, 0x50043101, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001552 SYSC_QUIRK("iss", 0, 0, 0x10, -ENODEV, 0x40000101, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001553 SYSC_QUIRK("keypad", 0x4a31c000, 0, 0x10, 0x14, 0x00000020, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001554 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44306302, 0xffffffff, 0),
1555 SYSC_QUIRK("mcasp", 0, 0, 0x4, -ENODEV, 0x44307b02, 0xffffffff, 0),
1556 SYSC_QUIRK("mcbsp", 0, -ENODEV, 0x8c, -ENODEV, 0, 0, 0),
1557 SYSC_QUIRK("mcspi", 0, 0, 0x10, -ENODEV, 0x40300a0b, 0xffff00ff, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001558 SYSC_QUIRK("mcspi", 0, 0, 0x110, 0x114, 0x40300a0b, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001559 SYSC_QUIRK("mailbox", 0, 0, 0x10, -ENODEV, 0x00000400, 0xffffffff, 0),
1560 SYSC_QUIRK("m3", 0, 0, -ENODEV, -ENODEV, 0x5f580105, 0x0fff0f00, 0),
Tony Lindgrenc6eb4af2018-09-27 13:34:27 -07001561 SYSC_QUIRK("ocp2scp", 0, 0, 0x10, 0x14, 0x50060005, 0xfffffff0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001562 SYSC_QUIRK("ocp2scp", 0, 0, -ENODEV, -ENODEV, 0x50060007, 0xffffffff, 0),
1563 SYSC_QUIRK("padconf", 0, 0, 0x10, -ENODEV, 0x4fff0800, 0xffffffff, 0),
1564 SYSC_QUIRK("padconf", 0, 0, -ENODEV, -ENODEV, 0x40001100, 0xffffffff, 0),
Tony Lindgrenf2dc0752021-03-08 11:35:07 +02001565 SYSC_QUIRK("pcie", 0x51000000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
1566 SYSC_QUIRK("pcie", 0x51800000, -ENODEV, -ENODEV, -ENODEV, 0, 0, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001567 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000100, 0xffffffff, 0),
1568 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x00004102, 0xffffffff, 0),
1569 SYSC_QUIRK("prcm", 0, 0, -ENODEV, -ENODEV, 0x40000400, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001570 SYSC_QUIRK("rfbi", 0x4832a800, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
1571 SYSC_QUIRK("rfbi", 0x58002000, 0, 0x10, 0x14, 0x00000010, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001572 SYSC_QUIRK("scm", 0, 0, 0x10, -ENODEV, 0x40000900, 0xffffffff, 0),
1573 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4e8b0100, 0xffffffff, 0),
1574 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x4f000100, 0xffffffff, 0),
1575 SYSC_QUIRK("scm", 0, 0, -ENODEV, -ENODEV, 0x40000900, 0xffffffff, 0),
1576 SYSC_QUIRK("scrm", 0, 0, -ENODEV, -ENODEV, 0x00000010, 0xffffffff, 0),
1577 SYSC_QUIRK("sdio", 0, 0, 0x10, -ENODEV, 0x40202301, 0xffff0ff0, 0),
Tony Lindgren1ba30692018-09-24 12:17:05 -07001578 SYSC_QUIRK("sdio", 0, 0x2fc, 0x110, 0x114, 0x31010000, 0xffffffff, 0),
Tony Lindgren40d9f912018-09-24 12:16:54 -07001579 SYSC_QUIRK("sdma", 0, 0, 0x2c, 0x28, 0x00010900, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001580 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40000902, 0xffffffff, 0),
1581 SYSC_QUIRK("slimbus", 0, 0, 0x10, -ENODEV, 0x40002903, 0xffffffff, 0),
Tony Lindgrened4520d2021-08-09 11:27:47 -05001582 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x24, -ENODEV, 0x00000000, 0xffffffff, 0),
1583 SYSC_QUIRK("smartreflex", 0, -ENODEV, 0x38, -ENODEV, 0x00000000, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001584 SYSC_QUIRK("spinlock", 0, 0, 0x10, -ENODEV, 0x50020000, 0xffffffff, 0),
1585 SYSC_QUIRK("rng", 0, 0x1fe0, 0x1fe4, -ENODEV, 0x00000020, 0xffffffff, 0),
Tony Lindgren1a542812020-05-07 09:43:08 -07001586 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000013, 0xffffffff, 0),
1587 SYSC_QUIRK("timer", 0, 0, 0x10, 0x14, 0x00000015, 0xffffffff, 0),
1588 /* Some timers on omap4 and later */
1589 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x50002100, 0xffffffff, 0),
1590 SYSC_QUIRK("timer", 0, 0, 0x10, -ENODEV, 0x4fff1301, 0xffff00ff, 0),
1591 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000040, 0xffffffff, 0),
1592 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000011, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001593 SYSC_QUIRK("timer32k", 0, 0, 0x4, -ENODEV, 0x00000060, 0xffffffff, 0),
Tony Lindgren25bfaaa2020-03-03 09:31:00 -08001594 SYSC_QUIRK("tpcc", 0, 0, -ENODEV, -ENODEV, 0x40014c00, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001595 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000004, 0xffffffff, 0),
Tony Lindgrenf0106702018-11-15 14:46:53 -08001596 SYSC_QUIRK("usbhstll", 0, 0, 0x10, 0x14, 0x00000008, 0xffffffff, 0),
Tony Lindgren77dfece2020-02-24 12:58:03 -08001597 SYSC_QUIRK("venc", 0x58003000, 0, -ENODEV, -ENODEV, 0x00000002, 0xffffffff, 0),
Tony Lindgren590e15c2020-02-24 12:58:03 -08001598 SYSC_QUIRK("vfpe", 0, 0, 0x104, -ENODEV, 0x4d001200, 0xffffffff, 0),
Tony Lindgrendc4c85e2018-04-16 10:26:25 -07001599#endif
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001600};
1601
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001602/*
1603 * Early quirks based on module base and register offsets only that are
1604 * needed before the module revision can be read
1605 */
1606static void sysc_init_early_quirks(struct sysc *ddata)
1607{
1608 const struct sysc_revision_quirk *q;
1609 int i;
1610
1611 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1612 q = &sysc_revision_quirks[i];
1613
1614 if (!q->base)
1615 continue;
1616
1617 if (q->base != ddata->module_pa)
1618 continue;
1619
Tony Lindgren590e15c2020-02-24 12:58:03 -08001620 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001621 continue;
1622
Tony Lindgren590e15c2020-02-24 12:58:03 -08001623 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001624 continue;
1625
Tony Lindgren590e15c2020-02-24 12:58:03 -08001626 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07001627 continue;
1628
1629 ddata->name = q->name;
1630 ddata->cfg.quirks |= q->quirks;
1631 }
1632}
1633
1634/* Quirks that also consider the revision register value */
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001635static void sysc_init_revision_quirks(struct sysc *ddata)
1636{
1637 const struct sysc_revision_quirk *q;
1638 int i;
1639
1640 for (i = 0; i < ARRAY_SIZE(sysc_revision_quirks); i++) {
1641 q = &sysc_revision_quirks[i];
1642
1643 if (q->base && q->base != ddata->module_pa)
1644 continue;
1645
Tony Lindgren590e15c2020-02-24 12:58:03 -08001646 if (q->rev_offset != ddata->offsets[SYSC_REVISION])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001647 continue;
1648
Tony Lindgren590e15c2020-02-24 12:58:03 -08001649 if (q->sysc_offset != ddata->offsets[SYSC_SYSCONFIG])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001650 continue;
1651
Tony Lindgren590e15c2020-02-24 12:58:03 -08001652 if (q->syss_offset != ddata->offsets[SYSC_SYSSTATUS])
Tony Lindgrena885f0f2018-02-22 14:03:48 -08001653 continue;
1654
1655 if (q->revision == ddata->revision ||
1656 (q->revision & q->revision_mask) ==
1657 (ddata->revision & q->revision_mask)) {
1658 ddata->name = q->name;
1659 ddata->cfg.quirks |= q->quirks;
1660 }
1661 }
1662}
1663
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001664/*
1665 * DSS needs dispc outputs disabled to reset modules. Returns mask of
1666 * enabled DSS interrupts. Eventually we may be able to do this on
1667 * dispc init rather than top-level DSS init.
1668 */
1669static u32 sysc_quirk_dispc(struct sysc *ddata, int dispc_offset,
1670 bool disable)
1671{
1672 bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
1673 const int lcd_en_mask = BIT(0), digit_en_mask = BIT(1);
1674 int manager_count;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001675 bool framedonetv_irq = true;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001676 u32 val, irq_mask = 0;
1677
1678 switch (sysc_soc->soc) {
1679 case SOC_2420 ... SOC_3630:
1680 manager_count = 2;
1681 framedonetv_irq = false;
1682 break;
1683 case SOC_4430 ... SOC_4470:
1684 manager_count = 3;
1685 break;
1686 case SOC_5430:
1687 case SOC_DRA7:
1688 manager_count = 4;
1689 break;
1690 case SOC_AM4:
1691 manager_count = 1;
Tony Lindgren085bc0e2020-05-31 12:37:54 -07001692 framedonetv_irq = false;
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001693 break;
1694 case SOC_UNKNOWN:
1695 default:
1696 return 0;
Yang Li52fbb5a2021-02-02 15:00:05 +08001697 }
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001698
1699 /* Remap the whole module range to be able to reset dispc outputs */
1700 devm_iounmap(ddata->dev, ddata->module_va);
1701 ddata->module_va = devm_ioremap(ddata->dev,
1702 ddata->module_pa,
1703 ddata->module_size);
1704 if (!ddata->module_va)
1705 return -EIO;
1706
1707 /* DISP_CONTROL */
1708 val = sysc_read(ddata, dispc_offset + 0x40);
1709 lcd_en = val & lcd_en_mask;
1710 digit_en = val & digit_en_mask;
1711 if (lcd_en)
1712 irq_mask |= BIT(0); /* FRAMEDONE */
1713 if (digit_en) {
1714 if (framedonetv_irq)
1715 irq_mask |= BIT(24); /* FRAMEDONETV */
1716 else
1717 irq_mask |= BIT(2) | BIT(3); /* EVSYNC bits */
1718 }
1719 if (disable & (lcd_en | digit_en))
1720 sysc_write(ddata, dispc_offset + 0x40,
1721 val & ~(lcd_en_mask | digit_en_mask));
1722
1723 if (manager_count <= 2)
1724 return irq_mask;
1725
1726 /* DISPC_CONTROL2 */
1727 val = sysc_read(ddata, dispc_offset + 0x238);
1728 lcd2_en = val & lcd_en_mask;
1729 if (lcd2_en)
1730 irq_mask |= BIT(22); /* FRAMEDONE2 */
1731 if (disable && lcd2_en)
1732 sysc_write(ddata, dispc_offset + 0x238,
1733 val & ~lcd_en_mask);
1734
1735 if (manager_count <= 3)
1736 return irq_mask;
1737
1738 /* DISPC_CONTROL3 */
1739 val = sysc_read(ddata, dispc_offset + 0x848);
1740 lcd3_en = val & lcd_en_mask;
1741 if (lcd3_en)
1742 irq_mask |= BIT(30); /* FRAMEDONE3 */
1743 if (disable && lcd3_en)
1744 sysc_write(ddata, dispc_offset + 0x848,
1745 val & ~lcd_en_mask);
1746
1747 return irq_mask;
1748}
1749
1750/* DSS needs child outputs disabled and SDI registers cleared for reset */
1751static void sysc_pre_reset_quirk_dss(struct sysc *ddata)
1752{
1753 const int dispc_offset = 0x1000;
1754 int error;
1755 u32 irq_mask, val;
1756
1757 /* Get enabled outputs */
1758 irq_mask = sysc_quirk_dispc(ddata, dispc_offset, false);
1759 if (!irq_mask)
1760 return;
1761
1762 /* Clear IRQSTATUS */
Tony Lindgren69e60902020-03-03 07:17:43 -08001763 sysc_write(ddata, dispc_offset + 0x18, irq_mask);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001764
1765 /* Disable outputs */
1766 val = sysc_quirk_dispc(ddata, dispc_offset, true);
1767
1768 /* Poll IRQSTATUS */
1769 error = readl_poll_timeout(ddata->module_va + dispc_offset + 0x18,
1770 val, val != irq_mask, 100, 50);
1771 if (error)
1772 dev_warn(ddata->dev, "%s: timed out %08x !+ %08x\n",
1773 __func__, val, irq_mask);
1774
1775 if (sysc_soc->soc == SOC_3430) {
1776 /* Clear DSS_SDI_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001777 sysc_write(ddata, 0x44, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001778
1779 /* Clear DSS_PLL_CONTROL */
Tony Lindgren69e60902020-03-03 07:17:43 -08001780 sysc_write(ddata, 0x48, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001781 }
1782
1783 /* Clear DSS_CONTROL to switch DSS clock sources to PRCM if not */
Tony Lindgren69e60902020-03-03 07:17:43 -08001784 sysc_write(ddata, 0x40, 0);
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001785}
1786
Tony Lindgren4e23be42019-06-10 04:48:05 -07001787/* 1-wire needs module's internal clocks enabled for reset */
Tony Lindgrenaec551c2020-02-24 12:58:03 -08001788static void sysc_pre_reset_quirk_hdq1w(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001789{
1790 int offset = 0x0c; /* HDQ_CTRL_STATUS */
1791 u16 val;
1792
1793 val = sysc_read(ddata, offset);
1794 val |= BIT(5);
1795 sysc_write(ddata, offset, val);
1796}
1797
Tony Lindgren020003f2019-11-14 08:25:28 -08001798/* AESS (Audio Engine SubSystem) needs autogating set after enable */
1799static void sysc_module_enable_quirk_aess(struct sysc *ddata)
1800{
1801 int offset = 0x7c; /* AESS_AUTO_GATING_ENABLE */
1802
1803 sysc_write(ddata, offset, 1);
1804}
1805
Tony Lindgrene64c0212020-02-24 12:58:03 -08001806/* I2C needs to be disabled for reset */
Tony Lindgren4e23be42019-06-10 04:48:05 -07001807static void sysc_clk_quirk_i2c(struct sysc *ddata, bool enable)
1808{
1809 int offset;
1810 u16 val;
1811
1812 /* I2C_CON, omap2/3 is different from omap4 and later */
1813 if ((ddata->revision & 0xffffff00) == 0x001f0000)
1814 offset = 0x24;
1815 else
1816 offset = 0xa4;
1817
1818 /* I2C_EN */
1819 val = sysc_read(ddata, offset);
1820 if (enable)
1821 val |= BIT(15);
1822 else
1823 val &= ~BIT(15);
1824 sysc_write(ddata, offset, val);
1825}
1826
Tony Lindgrene64c0212020-02-24 12:58:03 -08001827static void sysc_pre_reset_quirk_i2c(struct sysc *ddata)
Tony Lindgren4e23be42019-06-10 04:48:05 -07001828{
1829 sysc_clk_quirk_i2c(ddata, false);
1830}
1831
Tony Lindgrene64c0212020-02-24 12:58:03 -08001832static void sysc_post_reset_quirk_i2c(struct sysc *ddata)
1833{
1834 sysc_clk_quirk_i2c(ddata, true);
1835}
1836
Tony Lindgrene8639e12020-02-24 12:58:03 -08001837/* RTC on am3 and 4 needs to be unlocked and locked for sysconfig */
1838static void sysc_quirk_rtc(struct sysc *ddata, bool lock)
1839{
1840 u32 val, kick0_val = 0, kick1_val = 0;
1841 unsigned long flags;
1842 int error;
1843
1844 if (!lock) {
1845 kick0_val = 0x83e70b13;
1846 kick1_val = 0x95a4f1e0;
1847 }
1848
1849 local_irq_save(flags);
1850 /* RTC_STATUS BUSY bit may stay active for 1/32768 seconds (~30 usec) */
Tony Lindgrenafe6f1e2020-07-02 10:41:02 -07001851 error = readl_poll_timeout_atomic(ddata->module_va + 0x44, val,
1852 !(val & BIT(0)), 100, 50);
Tony Lindgrene8639e12020-02-24 12:58:03 -08001853 if (error)
1854 dev_warn(ddata->dev, "rtc busy timeout\n");
1855 /* Now we have ~15 microseconds to read/write various registers */
1856 sysc_write(ddata, 0x6c, kick0_val);
1857 sysc_write(ddata, 0x70, kick1_val);
1858 local_irq_restore(flags);
1859}
1860
1861static void sysc_module_unlock_quirk_rtc(struct sysc *ddata)
1862{
1863 sysc_quirk_rtc(ddata, false);
1864}
1865
1866static void sysc_module_lock_quirk_rtc(struct sysc *ddata)
1867{
1868 sysc_quirk_rtc(ddata, true);
1869}
1870
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001871/* 36xx SGX needs a quirk for to bypass OCP IPG interrupt logic */
1872static void sysc_module_enable_quirk_sgx(struct sysc *ddata)
1873{
1874 int offset = 0xff08; /* OCP_DEBUG_CONFIG */
1875 u32 val = BIT(31); /* THALIA_INT_BYPASS */
1876
1877 sysc_write(ddata, offset, val);
1878}
1879
Tony Lindgren4e23be42019-06-10 04:48:05 -07001880/* Watchdog timer needs a disable sequence after reset */
1881static void sysc_reset_done_quirk_wdt(struct sysc *ddata)
1882{
1883 int wps, spr, error;
1884 u32 val;
1885
1886 wps = 0x34;
1887 spr = 0x48;
1888
1889 sysc_write(ddata, spr, 0xaaaa);
1890 error = readl_poll_timeout(ddata->module_va + wps, val,
1891 !(val & 0x10), 100,
1892 MAX_MODULE_SOFTRESET_WAIT);
1893 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001894 dev_warn(ddata->dev, "wdt disable step1 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001895
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001896 sysc_write(ddata, spr, 0x5555);
Tony Lindgren4e23be42019-06-10 04:48:05 -07001897 error = readl_poll_timeout(ddata->module_va + wps, val,
1898 !(val & 0x10), 100,
1899 MAX_MODULE_SOFTRESET_WAIT);
1900 if (error)
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001901 dev_warn(ddata->dev, "wdt disable step2 failed\n");
Tony Lindgren4e23be42019-06-10 04:48:05 -07001902}
1903
Suman Annab2745d92020-02-27 16:28:34 -06001904/* PRUSS needs to set MSTANDBY_INIT inorder to idle properly */
1905static void sysc_module_disable_quirk_pruss(struct sysc *ddata)
1906{
1907 u32 reg;
1908
1909 reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
1910 reg |= SYSC_PRUSS_STANDBY_INIT;
1911 sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg);
1912}
1913
Tony Lindgren4e23be42019-06-10 04:48:05 -07001914static void sysc_init_module_quirks(struct sysc *ddata)
1915{
1916 if (ddata->legacy_mode || !ddata->name)
1917 return;
1918
1919 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_HDQ1W) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001920 ddata->pre_reset_quirk = sysc_pre_reset_quirk_hdq1w;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001921
1922 return;
1923 }
1924
Tony Lindgrencfeeea62020-11-16 12:57:13 +02001925#ifdef CONFIG_OMAP_GPMC_DEBUG
1926 if (ddata->cfg.quirks & SYSC_QUIRK_GPMC_DEBUG) {
1927 ddata->cfg.quirks |= SYSC_QUIRK_NO_RESET_ON_INIT;
1928
1929 return;
1930 }
1931#endif
1932
Tony Lindgren4e23be42019-06-10 04:48:05 -07001933 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_I2C) {
Tony Lindgrene64c0212020-02-24 12:58:03 -08001934 ddata->pre_reset_quirk = sysc_pre_reset_quirk_i2c;
1935 ddata->post_reset_quirk = sysc_post_reset_quirk_i2c;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001936
1937 return;
1938 }
1939
Tony Lindgren020003f2019-11-14 08:25:28 -08001940 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_AESS)
1941 ddata->module_enable_quirk = sysc_module_enable_quirk_aess;
1942
Tony Lindgren7324a7a2020-02-24 12:58:03 -08001943 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_DSS_RESET)
1944 ddata->pre_reset_quirk = sysc_pre_reset_quirk_dss;
1945
Tony Lindgrene8639e12020-02-24 12:58:03 -08001946 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_RTC_UNLOCK) {
1947 ddata->module_unlock_quirk = sysc_module_unlock_quirk_rtc;
1948 ddata->module_lock_quirk = sysc_module_lock_quirk_rtc;
1949
1950 return;
1951 }
1952
Tony Lindgrend7f563d2019-08-14 05:18:16 -07001953 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_SGX)
1954 ddata->module_enable_quirk = sysc_module_enable_quirk_sgx;
1955
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001956 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_WDT) {
Tony Lindgren4e23be42019-06-10 04:48:05 -07001957 ddata->reset_done_quirk = sysc_reset_done_quirk_wdt;
Tony Lindgrenc7d86692019-10-17 11:21:44 -07001958 ddata->module_disable_quirk = sysc_reset_done_quirk_wdt;
1959 }
Suman Annab2745d92020-02-27 16:28:34 -06001960
1961 if (ddata->cfg.quirks & SYSC_MODULE_QUIRK_PRUSS)
1962 ddata->module_disable_quirk = sysc_module_disable_quirk_pruss;
Tony Lindgren4e23be42019-06-10 04:48:05 -07001963}
1964
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001965static int sysc_clockdomain_init(struct sysc *ddata)
1966{
1967 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
1968 struct clk *fck = NULL, *ick = NULL;
1969 int error;
1970
1971 if (!pdata || !pdata->init_clockdomain)
1972 return 0;
1973
1974 switch (ddata->nr_clocks) {
1975 case 2:
1976 ick = ddata->clocks[SYSC_ICK];
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001977 fallthrough;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07001978 case 1:
1979 fck = ddata->clocks[SYSC_FCK];
1980 break;
1981 case 0:
1982 return 0;
1983 }
1984
1985 error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
1986 if (!error || error == -ENODEV)
1987 return 0;
1988
1989 return error;
1990}
1991
Tony Lindgrena3e92e72019-03-21 11:00:21 -07001992/*
1993 * Note that pdata->init_module() typically does a reset first. After
1994 * pdata->init_module() is done, PM runtime can be used for the interconnect
1995 * target module.
1996 */
1997static int sysc_legacy_init(struct sysc *ddata)
1998{
1999 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
2000 int error;
2001
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002002 if (!pdata || !pdata->init_module)
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002003 return 0;
2004
2005 error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
2006 if (error == -EEXIST)
2007 error = 0;
2008
2009 return error;
2010}
2011
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002012/*
2013 * Note that the caller must ensure the interconnect target module is enabled
2014 * before calling reset. Otherwise reset will not complete.
2015 */
Faiz Abbas596e7952018-07-09 22:18:39 +05302016static int sysc_reset(struct sysc *ddata)
2017{
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002018 int sysc_offset, sysc_val, error;
2019 u32 sysc_mask;
Faiz Abbas596e7952018-07-09 22:18:39 +05302020
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002021 sysc_offset = ddata->offsets[SYSC_SYSCONFIG];
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002022
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002023 if (ddata->legacy_mode ||
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002024 ddata->cap->regbits->srst_shift < 0 ||
Faiz Abbas596e7952018-07-09 22:18:39 +05302025 ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
2026 return 0;
2027
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002028 sysc_mask = BIT(ddata->cap->regbits->srst_shift);
Faiz Abbas596e7952018-07-09 22:18:39 +05302029
Tony Lindgrene64c0212020-02-24 12:58:03 -08002030 if (ddata->pre_reset_quirk)
2031 ddata->pre_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002032
Tony Lindgrenab4d309d2020-02-24 12:58:03 -08002033 if (sysc_offset >= 0) {
2034 sysc_val = sysc_read_sysconfig(ddata);
2035 sysc_val |= sysc_mask;
2036 sysc_write(ddata, sysc_offset, sysc_val);
2037 }
Faiz Abbas596e7952018-07-09 22:18:39 +05302038
Tony Lindgrene709ed72019-12-12 08:20:10 -08002039 if (ddata->cfg.srst_udelay)
2040 usleep_range(ddata->cfg.srst_udelay,
2041 ddata->cfg.srst_udelay * 2);
2042
Tony Lindgrene64c0212020-02-24 12:58:03 -08002043 if (ddata->post_reset_quirk)
2044 ddata->post_reset_quirk(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002045
Tony Lindgrend46f9fb2020-05-31 12:37:54 -07002046 error = sysc_wait_softreset(ddata);
2047 if (error)
2048 dev_warn(ddata->dev, "OCP softreset timed out\n");
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002049
Tony Lindgren4e23be42019-06-10 04:48:05 -07002050 if (ddata->reset_done_quirk)
2051 ddata->reset_done_quirk(ddata);
2052
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002053 return error;
Faiz Abbas596e7952018-07-09 22:18:39 +05302054}
2055
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002056/*
2057 * At this point the module is configured enough to read the revision but
2058 * module may not be completely configured yet to use PM runtime. Enable
2059 * all clocks directly during init to configure the quirks needed for PM
2060 * runtime based on the revision register.
2061 */
Tony Lindgren566a9b052017-12-15 09:41:19 -08002062static int sysc_init_module(struct sysc *ddata)
2063{
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002064 bool rstctrl_deasserted = false;
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002065 int error = 0;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002066
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002067 error = sysc_clockdomain_init(ddata);
2068 if (error)
2069 return error;
2070
Tony Lindgrend0989132019-09-05 07:37:22 -07002071 sysc_clkdm_deny_idle(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002072
Tony Lindgrend0989132019-09-05 07:37:22 -07002073 /*
2074 * Always enable clocks. The bootloader may or may not have enabled
2075 * the related clocks.
2076 */
2077 error = sysc_enable_opt_clocks(ddata);
2078 if (error)
2079 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002080
Tony Lindgrend0989132019-09-05 07:37:22 -07002081 error = sysc_enable_main_clocks(ddata);
2082 if (error)
2083 goto err_opt_clocks;
Faiz Abbas596e7952018-07-09 22:18:39 +05302084
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002085 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT)) {
Tero Kristodf4f3452019-10-07 15:29:30 +03002086 error = reset_control_deassert(ddata->rsts);
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002087 if (error)
2088 goto err_main_clocks;
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002089 rstctrl_deasserted = true;
Tony Lindgrenea5a2e42019-05-27 04:51:56 -07002090 }
2091
Tony Lindgren566a9b052017-12-15 09:41:19 -08002092 ddata->revision = sysc_read_revision(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002093 sysc_init_revision_quirks(ddata);
Tony Lindgren4e23be42019-06-10 04:48:05 -07002094 sysc_init_module_quirks(ddata);
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002095
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002096 if (ddata->legacy_mode) {
2097 error = sysc_legacy_init(ddata);
2098 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002099 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002100 }
2101
Tony Lindgrend0989132019-09-05 07:37:22 -07002102 if (!ddata->legacy_mode) {
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002103 error = sysc_enable_module(ddata->dev);
2104 if (error)
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002105 goto err_main_clocks;
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002106 }
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002107
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002108 error = sysc_reset(ddata);
2109 if (error)
2110 dev_err(ddata->dev, "Reset failed with %d\n", error);
2111
Tero Kristocdc56c12019-10-07 15:29:31 +03002112 if (error && !ddata->legacy_mode)
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002113 sysc_disable_module(ddata->dev);
2114
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002115err_main_clocks:
Tero Kristocdc56c12019-10-07 15:29:31 +03002116 if (error)
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002117 sysc_disable_main_clocks(ddata);
2118err_opt_clocks:
Tony Lindgrend0989132019-09-05 07:37:22 -07002119 /* No re-enable of clockdomain autoidle to prevent module autoidle */
Tero Kristocdc56c12019-10-07 15:29:31 +03002120 if (error) {
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002121 sysc_disable_opt_clocks(ddata);
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002122 sysc_clkdm_allow_idle(ddata);
2123 }
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002124
Tony Lindgren4097c9a2020-11-16 12:57:13 +02002125 if (error && rstctrl_deasserted &&
2126 !(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
2127 reset_control_assert(ddata->rsts);
2128
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07002129 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002130}
2131
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002132static int sysc_init_sysc_mask(struct sysc *ddata)
2133{
2134 struct device_node *np = ddata->dev->of_node;
2135 int error;
2136 u32 val;
2137
2138 error = of_property_read_u32(np, "ti,sysc-mask", &val);
2139 if (error)
2140 return 0;
2141
Tony Lindgrene212abd2019-07-22 03:44:52 -07002142 ddata->cfg.sysc_val = val & ddata->cap->sysc_mask;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08002143
2144 return 0;
2145}
2146
2147static int sysc_init_idlemode(struct sysc *ddata, u8 *idlemodes,
2148 const char *name)
2149{
2150 struct device_node *np = ddata->dev->of_node;
2151 struct property *prop;
2152 const __be32 *p;
2153 u32 val;
2154
2155 of_property_for_each_u32(np, name, prop, p, val) {
2156 if (val >= SYSC_NR_IDLEMODES) {
2157 dev_err(ddata->dev, "invalid idlemode: %i\n", val);
2158 return -EINVAL;
2159 }
2160 *idlemodes |= (1 << val);
2161 }
2162
2163 return 0;
2164}
2165
2166static int sysc_init_idlemodes(struct sysc *ddata)
2167{
2168 int error;
2169
2170 error = sysc_init_idlemode(ddata, &ddata->cfg.midlemodes,
2171 "ti,sysc-midle");
2172 if (error)
2173 return error;
2174
2175 error = sysc_init_idlemode(ddata, &ddata->cfg.sidlemodes,
2176 "ti,sysc-sidle");
2177 if (error)
2178 return error;
2179
2180 return 0;
2181}
2182
2183/*
2184 * Only some devices on omap4 and later have SYSCONFIG reset done
2185 * bit. We can detect this if there is no SYSSTATUS at all, or the
2186 * SYSTATUS bit 0 is not used. Note that some SYSSTATUS registers
2187 * have multiple bits for the child devices like OHCI and EHCI.
2188 * Depends on SYSC being parsed first.
2189 */
2190static int sysc_init_syss_mask(struct sysc *ddata)
2191{
2192 struct device_node *np = ddata->dev->of_node;
2193 int error;
2194 u32 val;
2195
2196 error = of_property_read_u32(np, "ti,syss-mask", &val);
2197 if (error) {
2198 if ((ddata->cap->type == TI_SYSC_OMAP4 ||
2199 ddata->cap->type == TI_SYSC_OMAP4_TIMER) &&
2200 (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2201 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2202
2203 return 0;
2204 }
2205
2206 if (!(val & 1) && (ddata->cfg.sysc_val & SYSC_OMAP4_SOFTRESET))
2207 ddata->cfg.quirks |= SYSC_QUIRK_RESET_STATUS;
2208
2209 ddata->cfg.syss_mask = val;
2210
2211 return 0;
2212}
2213
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002214/*
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002215 * Many child device drivers need to have fck and opt clocks available
2216 * to get the clock rate for device internal configuration etc.
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002217 */
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002218static int sysc_child_add_named_clock(struct sysc *ddata,
2219 struct device *child,
2220 const char *name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002221{
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002222 struct clk *clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002223 struct clk_lookup *l;
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002224 int error = 0;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002225
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002226 if (!name)
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002227 return 0;
2228
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002229 clk = clk_get(child, name);
2230 if (!IS_ERR(clk)) {
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002231 error = -EEXIST;
2232 goto put_clk;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002233 }
2234
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002235 clk = clk_get(ddata->dev, name);
2236 if (IS_ERR(clk))
2237 return -ENODEV;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002238
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002239 l = clkdev_create(clk, name, dev_name(child));
2240 if (!l)
2241 error = -ENOMEM;
Markus Elfringcb6cfe22019-11-06 19:12:30 +01002242put_clk:
Tony Lindgren8b2830ba2018-04-16 10:26:09 -07002243 clk_put(clk);
2244
2245 return error;
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002246}
2247
Tony Lindgren09dfe582018-04-16 10:25:52 -07002248static int sysc_child_add_clocks(struct sysc *ddata,
2249 struct device *child)
2250{
2251 int i, error;
2252
2253 for (i = 0; i < ddata->nr_clocks; i++) {
2254 error = sysc_child_add_named_clock(ddata,
2255 child,
2256 ddata->clock_roles[i]);
2257 if (error && error != -EEXIST) {
2258 dev_err(ddata->dev, "could not add child clock %s: %i\n",
2259 ddata->clock_roles[i], error);
2260
2261 return error;
2262 }
2263 }
2264
2265 return 0;
2266}
2267
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002268static struct device_type sysc_device_type = {
2269};
2270
2271static struct sysc *sysc_child_to_parent(struct device *dev)
2272{
2273 struct device *parent = dev->parent;
2274
2275 if (!parent || parent->type != &sysc_device_type)
2276 return NULL;
2277
2278 return dev_get_drvdata(parent);
2279}
2280
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002281static int __maybe_unused sysc_child_runtime_suspend(struct device *dev)
2282{
2283 struct sysc *ddata;
2284 int error;
2285
2286 ddata = sysc_child_to_parent(dev);
2287
2288 error = pm_generic_runtime_suspend(dev);
2289 if (error)
2290 return error;
2291
2292 if (!ddata->enabled)
2293 return 0;
2294
2295 return sysc_runtime_suspend(ddata->dev);
2296}
2297
2298static int __maybe_unused sysc_child_runtime_resume(struct device *dev)
2299{
2300 struct sysc *ddata;
2301 int error;
2302
2303 ddata = sysc_child_to_parent(dev);
2304
2305 if (!ddata->enabled) {
2306 error = sysc_runtime_resume(ddata->dev);
2307 if (error < 0)
2308 dev_err(ddata->dev,
2309 "%s error: %i\n", __func__, error);
2310 }
2311
2312 return pm_generic_runtime_resume(dev);
2313}
2314
2315#ifdef CONFIG_PM_SLEEP
2316static int sysc_child_suspend_noirq(struct device *dev)
2317{
2318 struct sysc *ddata;
2319 int error;
2320
2321 ddata = sysc_child_to_parent(dev);
2322
Tony Lindgrenef55f822018-04-16 10:27:15 -07002323 dev_dbg(ddata->dev, "%s %s\n", __func__,
2324 ddata->name ? ddata->name : "");
2325
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002326 error = pm_generic_suspend_noirq(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002327 if (error) {
2328 dev_err(dev, "%s error at %i: %i\n",
2329 __func__, __LINE__, error);
2330
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002331 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002332 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002333
2334 if (!pm_runtime_status_suspended(dev)) {
2335 error = pm_generic_runtime_suspend(dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002336 if (error) {
Tony Lindgrenf9490782018-09-28 15:21:50 -07002337 dev_dbg(dev, "%s busy at %i: %i\n",
2338 __func__, __LINE__, error);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002339
Tony Lindgren4f3530f2018-08-08 01:07:06 -07002340 return 0;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002341 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002342
2343 error = sysc_runtime_suspend(ddata->dev);
Tony Lindgrenef55f822018-04-16 10:27:15 -07002344 if (error) {
2345 dev_err(dev, "%s error at %i: %i\n",
2346 __func__, __LINE__, error);
2347
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002348 return error;
Tony Lindgrenef55f822018-04-16 10:27:15 -07002349 }
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002350
2351 ddata->child_needs_resume = true;
2352 }
2353
2354 return 0;
2355}
2356
2357static int sysc_child_resume_noirq(struct device *dev)
2358{
2359 struct sysc *ddata;
2360 int error;
2361
2362 ddata = sysc_child_to_parent(dev);
2363
Tony Lindgrenef55f822018-04-16 10:27:15 -07002364 dev_dbg(ddata->dev, "%s %s\n", __func__,
2365 ddata->name ? ddata->name : "");
2366
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002367 if (ddata->child_needs_resume) {
2368 ddata->child_needs_resume = false;
2369
2370 error = sysc_runtime_resume(ddata->dev);
2371 if (error)
2372 dev_err(ddata->dev,
2373 "%s runtime resume error: %i\n",
2374 __func__, error);
2375
2376 error = pm_generic_runtime_resume(dev);
2377 if (error)
2378 dev_err(ddata->dev,
2379 "%s generic runtime resume: %i\n",
2380 __func__, error);
2381 }
2382
2383 return pm_generic_resume_noirq(dev);
2384}
2385#endif
2386
Tony Lindgrenb7182b42019-03-21 11:00:21 -07002387static struct dev_pm_domain sysc_child_pm_domain = {
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002388 .ops = {
2389 SET_RUNTIME_PM_OPS(sysc_child_runtime_suspend,
2390 sysc_child_runtime_resume,
2391 NULL)
2392 USE_PLATFORM_PM_SLEEP_OPS
2393 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sysc_child_suspend_noirq,
2394 sysc_child_resume_noirq)
2395 }
2396};
2397
2398/**
2399 * sysc_legacy_idle_quirk - handle children in omap_device compatible way
2400 * @ddata: device driver data
2401 * @child: child device driver
2402 *
2403 * Allow idle for child devices as done with _od_runtime_suspend().
2404 * Otherwise many child devices will not idle because of the permanent
2405 * parent usecount set in pm_runtime_irq_safe().
2406 *
2407 * Note that the long term solution is to just modify the child device
2408 * drivers to not set pm_runtime_irq_safe() and then this can be just
2409 * dropped.
2410 */
2411static void sysc_legacy_idle_quirk(struct sysc *ddata, struct device *child)
2412{
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002413 if (ddata->cfg.quirks & SYSC_QUIRK_LEGACY_IDLE)
2414 dev_pm_domain_set(child, &sysc_child_pm_domain);
2415}
2416
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002417static int sysc_notifier_call(struct notifier_block *nb,
2418 unsigned long event, void *device)
2419{
2420 struct device *dev = device;
2421 struct sysc *ddata;
2422 int error;
2423
2424 ddata = sysc_child_to_parent(dev);
2425 if (!ddata)
2426 return NOTIFY_DONE;
2427
2428 switch (event) {
2429 case BUS_NOTIFY_ADD_DEVICE:
Tony Lindgren09dfe582018-04-16 10:25:52 -07002430 error = sysc_child_add_clocks(ddata, dev);
2431 if (error)
2432 return error;
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002433 sysc_legacy_idle_quirk(ddata, dev);
Tony Lindgren2c355ff2018-02-22 13:58:03 -08002434 break;
2435 default:
2436 break;
2437 }
2438
2439 return NOTIFY_DONE;
2440}
2441
2442static struct notifier_block sysc_nb = {
2443 .notifier_call = sysc_notifier_call,
2444};
2445
Tony Lindgren566a9b052017-12-15 09:41:19 -08002446/* Device tree configured quirks */
2447struct sysc_dts_quirk {
2448 const char *name;
2449 u32 mask;
2450};
2451
2452static const struct sysc_dts_quirk sysc_dts_quirks[] = {
2453 { .name = "ti,no-idle-on-init",
2454 .mask = SYSC_QUIRK_NO_IDLE_ON_INIT, },
2455 { .name = "ti,no-reset-on-init",
2456 .mask = SYSC_QUIRK_NO_RESET_ON_INIT, },
Tony Lindgren386cb762019-03-22 07:49:30 -07002457 { .name = "ti,no-idle",
2458 .mask = SYSC_QUIRK_NO_IDLE, },
Tony Lindgren566a9b052017-12-15 09:41:19 -08002459};
2460
Tony Lindgren4014c082018-12-10 14:11:26 -08002461static void sysc_parse_dts_quirks(struct sysc *ddata, struct device_node *np,
2462 bool is_child)
Tony Lindgren566a9b052017-12-15 09:41:19 -08002463{
Tony Lindgren566a9b052017-12-15 09:41:19 -08002464 const struct property *prop;
Tony Lindgren4014c082018-12-10 14:11:26 -08002465 int i, len;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002466
2467 for (i = 0; i < ARRAY_SIZE(sysc_dts_quirks); i++) {
Tony Lindgren4014c082018-12-10 14:11:26 -08002468 const char *name = sysc_dts_quirks[i].name;
2469
2470 prop = of_get_property(np, name, &len);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002471 if (!prop)
Tony Lindgrend39b6ea2018-02-15 09:18:55 -08002472 continue;
Tony Lindgren566a9b052017-12-15 09:41:19 -08002473
2474 ddata->cfg.quirks |= sysc_dts_quirks[i].mask;
Tony Lindgren4014c082018-12-10 14:11:26 -08002475 if (is_child) {
2476 dev_warn(ddata->dev,
2477 "dts flag should be at module level for %s\n",
2478 name);
2479 }
Tony Lindgren566a9b052017-12-15 09:41:19 -08002480 }
Tony Lindgren4014c082018-12-10 14:11:26 -08002481}
Tony Lindgren566a9b052017-12-15 09:41:19 -08002482
Tony Lindgren4014c082018-12-10 14:11:26 -08002483static int sysc_init_dts_quirks(struct sysc *ddata)
2484{
2485 struct device_node *np = ddata->dev->of_node;
2486 int error;
2487 u32 val;
2488
2489 ddata->legacy_mode = of_get_property(np, "ti,hwmods", NULL);
2490
2491 sysc_parse_dts_quirks(ddata, np, false);
Tony Lindgren566a9b052017-12-15 09:41:19 -08002492 error = of_property_read_u32(np, "ti,sysc-delay-us", &val);
2493 if (!error) {
2494 if (val > 255) {
2495 dev_warn(ddata->dev, "bad ti,sysc-delay-us: %i\n",
2496 val);
2497 }
2498
2499 ddata->cfg.srst_udelay = (u8)val;
2500 }
2501
2502 return 0;
2503}
2504
Tony Lindgren0eecc632017-10-10 14:23:43 -07002505static void sysc_unprepare(struct sysc *ddata)
2506{
2507 int i;
2508
Tony Lindgrenaaa29bb2019-03-21 11:00:21 -07002509 if (!ddata->clocks)
2510 return;
2511
Tony Lindgren0eecc632017-10-10 14:23:43 -07002512 for (i = 0; i < SYSC_MAX_CLOCKS; i++) {
2513 if (!IS_ERR_OR_NULL(ddata->clocks[i]))
2514 clk_unprepare(ddata->clocks[i]);
2515 }
2516}
2517
Tony Lindgren70a65242017-12-15 09:41:09 -08002518/*
2519 * Common sysc register bits found on omap2, also known as type1
2520 */
2521static const struct sysc_regbits sysc_regbits_omap2 = {
2522 .dmadisable_shift = -ENODEV,
2523 .midle_shift = 12,
2524 .sidle_shift = 3,
2525 .clkact_shift = 8,
2526 .emufree_shift = 5,
2527 .enwkup_shift = 2,
2528 .srst_shift = 1,
2529 .autoidle_shift = 0,
2530};
2531
2532static const struct sysc_capabilities sysc_omap2 = {
2533 .type = TI_SYSC_OMAP2,
2534 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2535 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2536 SYSC_OMAP2_AUTOIDLE,
2537 .regbits = &sysc_regbits_omap2,
2538};
2539
2540/* All omap2 and 3 timers, and timers 1, 2 & 10 on omap 4 and 5 */
2541static const struct sysc_capabilities sysc_omap2_timer = {
2542 .type = TI_SYSC_OMAP2_TIMER,
2543 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY | SYSC_OMAP2_EMUFREE |
2544 SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_SOFTRESET |
2545 SYSC_OMAP2_AUTOIDLE,
2546 .regbits = &sysc_regbits_omap2,
2547 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT,
2548};
2549
2550/*
2551 * SHAM2 (SHA1/MD5) sysc found on omap3, a variant of sysc_regbits_omap2
2552 * with different sidle position
2553 */
2554static const struct sysc_regbits sysc_regbits_omap3_sham = {
2555 .dmadisable_shift = -ENODEV,
2556 .midle_shift = -ENODEV,
2557 .sidle_shift = 4,
2558 .clkact_shift = -ENODEV,
2559 .enwkup_shift = -ENODEV,
2560 .srst_shift = 1,
2561 .autoidle_shift = 0,
2562 .emufree_shift = -ENODEV,
2563};
2564
2565static const struct sysc_capabilities sysc_omap3_sham = {
2566 .type = TI_SYSC_OMAP3_SHAM,
2567 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2568 .regbits = &sysc_regbits_omap3_sham,
2569};
2570
2571/*
2572 * AES register bits found on omap3 and later, a variant of
2573 * sysc_regbits_omap2 with different sidle position
2574 */
2575static const struct sysc_regbits sysc_regbits_omap3_aes = {
2576 .dmadisable_shift = -ENODEV,
2577 .midle_shift = -ENODEV,
2578 .sidle_shift = 6,
2579 .clkact_shift = -ENODEV,
2580 .enwkup_shift = -ENODEV,
2581 .srst_shift = 1,
2582 .autoidle_shift = 0,
2583 .emufree_shift = -ENODEV,
2584};
2585
2586static const struct sysc_capabilities sysc_omap3_aes = {
2587 .type = TI_SYSC_OMAP3_AES,
2588 .sysc_mask = SYSC_OMAP2_SOFTRESET | SYSC_OMAP2_AUTOIDLE,
2589 .regbits = &sysc_regbits_omap3_aes,
2590};
2591
2592/*
2593 * Common sysc register bits found on omap4, also known as type2
2594 */
2595static const struct sysc_regbits sysc_regbits_omap4 = {
2596 .dmadisable_shift = 16,
2597 .midle_shift = 4,
2598 .sidle_shift = 2,
2599 .clkact_shift = -ENODEV,
2600 .enwkup_shift = -ENODEV,
2601 .emufree_shift = 1,
2602 .srst_shift = 0,
2603 .autoidle_shift = -ENODEV,
2604};
2605
2606static const struct sysc_capabilities sysc_omap4 = {
2607 .type = TI_SYSC_OMAP4,
2608 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2609 SYSC_OMAP4_SOFTRESET,
2610 .regbits = &sysc_regbits_omap4,
2611};
2612
2613static const struct sysc_capabilities sysc_omap4_timer = {
2614 .type = TI_SYSC_OMAP4_TIMER,
2615 .sysc_mask = SYSC_OMAP4_DMADISABLE | SYSC_OMAP4_FREEEMU |
2616 SYSC_OMAP4_SOFTRESET,
2617 .regbits = &sysc_regbits_omap4,
2618};
2619
2620/*
2621 * Common sysc register bits found on omap4, also known as type3
2622 */
2623static const struct sysc_regbits sysc_regbits_omap4_simple = {
2624 .dmadisable_shift = -ENODEV,
2625 .midle_shift = 2,
2626 .sidle_shift = 0,
2627 .clkact_shift = -ENODEV,
2628 .enwkup_shift = -ENODEV,
2629 .srst_shift = -ENODEV,
2630 .emufree_shift = -ENODEV,
2631 .autoidle_shift = -ENODEV,
2632};
2633
2634static const struct sysc_capabilities sysc_omap4_simple = {
2635 .type = TI_SYSC_OMAP4_SIMPLE,
2636 .regbits = &sysc_regbits_omap4_simple,
2637};
2638
2639/*
2640 * SmartReflex sysc found on omap34xx
2641 */
2642static const struct sysc_regbits sysc_regbits_omap34xx_sr = {
2643 .dmadisable_shift = -ENODEV,
2644 .midle_shift = -ENODEV,
2645 .sidle_shift = -ENODEV,
2646 .clkact_shift = 20,
2647 .enwkup_shift = -ENODEV,
2648 .srst_shift = -ENODEV,
2649 .emufree_shift = -ENODEV,
2650 .autoidle_shift = -ENODEV,
2651};
2652
2653static const struct sysc_capabilities sysc_34xx_sr = {
2654 .type = TI_SYSC_OMAP34XX_SR,
2655 .sysc_mask = SYSC_OMAP2_CLOCKACTIVITY,
2656 .regbits = &sysc_regbits_omap34xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002657 .mod_quirks = SYSC_QUIRK_USE_CLOCKACT | SYSC_QUIRK_UNCACHED |
2658 SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002659};
2660
2661/*
2662 * SmartReflex sysc found on omap36xx and later
2663 */
2664static const struct sysc_regbits sysc_regbits_omap36xx_sr = {
2665 .dmadisable_shift = -ENODEV,
2666 .midle_shift = -ENODEV,
2667 .sidle_shift = 24,
2668 .clkact_shift = -ENODEV,
2669 .enwkup_shift = 26,
2670 .srst_shift = -ENODEV,
2671 .emufree_shift = -ENODEV,
2672 .autoidle_shift = -ENODEV,
2673};
2674
2675static const struct sysc_capabilities sysc_36xx_sr = {
2676 .type = TI_SYSC_OMAP36XX_SR,
Tony Lindgren3267c082018-01-22 09:32:53 -08002677 .sysc_mask = SYSC_OMAP3_SR_ENAWAKEUP,
Tony Lindgren70a65242017-12-15 09:41:09 -08002678 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002679 .mod_quirks = SYSC_QUIRK_UNCACHED | SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002680};
2681
2682static const struct sysc_capabilities sysc_omap4_sr = {
2683 .type = TI_SYSC_OMAP4_SR,
2684 .regbits = &sysc_regbits_omap36xx_sr,
Tony Lindgrena885f0f2018-02-22 14:03:48 -08002685 .mod_quirks = SYSC_QUIRK_LEGACY_IDLE,
Tony Lindgren70a65242017-12-15 09:41:09 -08002686};
2687
2688/*
2689 * McASP register bits found on omap4 and later
2690 */
2691static const struct sysc_regbits sysc_regbits_omap4_mcasp = {
2692 .dmadisable_shift = -ENODEV,
2693 .midle_shift = -ENODEV,
2694 .sidle_shift = 0,
2695 .clkact_shift = -ENODEV,
2696 .enwkup_shift = -ENODEV,
2697 .srst_shift = -ENODEV,
2698 .emufree_shift = -ENODEV,
2699 .autoidle_shift = -ENODEV,
2700};
2701
2702static const struct sysc_capabilities sysc_omap4_mcasp = {
2703 .type = TI_SYSC_OMAP4_MCASP,
2704 .regbits = &sysc_regbits_omap4_mcasp,
Tony Lindgren2c63a832018-11-15 14:46:53 -08002705 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
2706};
2707
2708/*
2709 * McASP found on dra7 and later
2710 */
2711static const struct sysc_capabilities sysc_dra7_mcasp = {
2712 .type = TI_SYSC_OMAP4_SIMPLE,
2713 .regbits = &sysc_regbits_omap4_simple,
2714 .mod_quirks = SYSC_QUIRK_OPT_CLKS_NEEDED,
Tony Lindgren70a65242017-12-15 09:41:09 -08002715};
2716
2717/*
2718 * FS USB host found on omap4 and later
2719 */
2720static const struct sysc_regbits sysc_regbits_omap4_usb_host_fs = {
2721 .dmadisable_shift = -ENODEV,
2722 .midle_shift = -ENODEV,
2723 .sidle_shift = 24,
2724 .clkact_shift = -ENODEV,
2725 .enwkup_shift = 26,
2726 .srst_shift = -ENODEV,
2727 .emufree_shift = -ENODEV,
2728 .autoidle_shift = -ENODEV,
2729};
2730
2731static const struct sysc_capabilities sysc_omap4_usb_host_fs = {
2732 .type = TI_SYSC_OMAP4_USB_HOST_FS,
2733 .sysc_mask = SYSC_OMAP2_ENAWAKEUP,
2734 .regbits = &sysc_regbits_omap4_usb_host_fs,
2735};
2736
Faiz Abbas7f35e632018-07-09 22:18:38 +05302737static const struct sysc_regbits sysc_regbits_dra7_mcan = {
2738 .dmadisable_shift = -ENODEV,
2739 .midle_shift = -ENODEV,
2740 .sidle_shift = -ENODEV,
2741 .clkact_shift = -ENODEV,
2742 .enwkup_shift = 4,
2743 .srst_shift = 0,
2744 .emufree_shift = -ENODEV,
2745 .autoidle_shift = -ENODEV,
2746};
2747
2748static const struct sysc_capabilities sysc_dra7_mcan = {
2749 .type = TI_SYSC_DRA7_MCAN,
2750 .sysc_mask = SYSC_DRA7_MCAN_ENAWAKEUP | SYSC_OMAP4_SOFTRESET,
2751 .regbits = &sysc_regbits_dra7_mcan,
Tony Lindgrene0db94f2019-05-27 04:51:53 -07002752 .mod_quirks = SYSS_QUIRK_RESETDONE_INVERTED,
Faiz Abbas7f35e632018-07-09 22:18:38 +05302753};
2754
Suman Annab2745d92020-02-27 16:28:34 -06002755/*
2756 * PRUSS found on some AM33xx, AM437x and AM57xx SoCs
2757 */
2758static const struct sysc_capabilities sysc_pruss = {
2759 .type = TI_SYSC_PRUSS,
2760 .sysc_mask = SYSC_PRUSS_STANDBY_INIT | SYSC_PRUSS_SUB_MWAIT,
2761 .regbits = &sysc_regbits_omap4_simple,
2762 .mod_quirks = SYSC_MODULE_QUIRK_PRUSS,
2763};
2764
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002765static int sysc_init_pdata(struct sysc *ddata)
2766{
2767 struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002768 struct ti_sysc_module_data *mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002769
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002770 if (!pdata)
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002771 return 0;
2772
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002773 mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
2774 if (!mdata)
2775 return -ENOMEM;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002776
Tony Lindgren2b2f7de2019-05-27 04:51:53 -07002777 if (ddata->legacy_mode) {
2778 mdata->name = ddata->legacy_mode;
2779 mdata->module_pa = ddata->module_pa;
2780 mdata->module_size = ddata->module_size;
2781 mdata->offsets = ddata->offsets;
2782 mdata->nr_offsets = SYSC_MAX_REGS;
2783 mdata->cap = ddata->cap;
2784 mdata->cfg = &ddata->cfg;
2785 }
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002786
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002787 ddata->mdata = mdata;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002788
Tony Lindgrena3e92e72019-03-21 11:00:21 -07002789 return 0;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08002790}
2791
Tony Lindgren70a65242017-12-15 09:41:09 -08002792static int sysc_init_match(struct sysc *ddata)
2793{
2794 const struct sysc_capabilities *cap;
2795
2796 cap = of_device_get_match_data(ddata->dev);
2797 if (!cap)
2798 return -EINVAL;
2799
2800 ddata->cap = cap;
2801 if (ddata->cap)
2802 ddata->cfg.quirks |= ddata->cap->mod_quirks;
2803
2804 return 0;
2805}
2806
Tony Lindgren76f0f772018-02-23 08:28:45 -08002807static void ti_sysc_idle(struct work_struct *work)
2808{
2809 struct sysc *ddata;
2810
2811 ddata = container_of(work, struct sysc, idle_work.work);
2812
Tony Lindgrend0989132019-09-05 07:37:22 -07002813 /*
2814 * One time decrement of clock usage counts if left on from init.
2815 * Note that we disable opt clocks unconditionally in this case
2816 * as they are enabled unconditionally during init without
2817 * considering sysc_opt_clks_needed() at that point.
2818 */
2819 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
2820 SYSC_QUIRK_NO_IDLE_ON_INIT)) {
Tony Lindgrend0989132019-09-05 07:37:22 -07002821 sysc_disable_main_clocks(ddata);
2822 sysc_disable_opt_clocks(ddata);
2823 sysc_clkdm_allow_idle(ddata);
2824 }
2825
2826 /* Keep permanent PM runtime usage count for SYSC_QUIRK_NO_IDLE */
2827 if (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE)
2828 return;
2829
2830 /*
2831 * Decrement PM runtime usage count for SYSC_QUIRK_NO_IDLE_ON_INIT
2832 * and SYSC_QUIRK_NO_RESET_ON_INIT
2833 */
Tony Lindgren76f0f772018-02-23 08:28:45 -08002834 if (pm_runtime_active(ddata->dev))
2835 pm_runtime_put_sync(ddata->dev);
2836}
2837
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002838/*
2839 * SoC model and features detection. Only needed for SoCs that need
2840 * special handling for quirks, no need to list others.
2841 */
2842static const struct soc_device_attribute sysc_soc_match[] = {
2843 SOC_FLAG("OMAP242*", SOC_2420),
2844 SOC_FLAG("OMAP243*", SOC_2430),
2845 SOC_FLAG("OMAP3[45]*", SOC_3430),
2846 SOC_FLAG("OMAP3[67]*", SOC_3630),
2847 SOC_FLAG("OMAP443*", SOC_4430),
2848 SOC_FLAG("OMAP446*", SOC_4460),
2849 SOC_FLAG("OMAP447*", SOC_4470),
2850 SOC_FLAG("OMAP54*", SOC_5430),
2851 SOC_FLAG("AM433", SOC_AM3),
2852 SOC_FLAG("AM43*", SOC_AM4),
2853 SOC_FLAG("DRA7*", SOC_DRA7),
2854
2855 { /* sentinel */ },
2856};
2857
2858/*
2859 * List of SoCs variants with disabled features. By default we assume all
2860 * devices in the device tree are available so no need to list those SoCs.
2861 */
2862static const struct soc_device_attribute sysc_soc_feat_match[] = {
2863 /* OMAP3430/3530 and AM3517 variants with some accelerators disabled */
2864 SOC_FLAG("AM3505", DIS_SGX),
2865 SOC_FLAG("OMAP3525", DIS_SGX),
2866 SOC_FLAG("OMAP3515", DIS_IVA | DIS_SGX),
2867 SOC_FLAG("OMAP3503", DIS_ISP | DIS_IVA | DIS_SGX),
2868
2869 /* OMAP3630/DM3730 variants with some accelerators disabled */
2870 SOC_FLAG("AM3703", DIS_IVA | DIS_SGX),
2871 SOC_FLAG("DM3725", DIS_SGX),
2872 SOC_FLAG("OMAP3611", DIS_ISP | DIS_IVA | DIS_SGX),
2873 SOC_FLAG("OMAP3615/AM3715", DIS_IVA),
2874 SOC_FLAG("OMAP3621", DIS_ISP),
2875
2876 { /* sentinel */ },
2877};
2878
2879static int sysc_add_disabled(unsigned long base)
2880{
2881 struct sysc_address *disabled_module;
2882
2883 disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL);
2884 if (!disabled_module)
2885 return -ENOMEM;
2886
2887 disabled_module->base = base;
2888
2889 mutex_lock(&sysc_soc->list_lock);
2890 list_add(&disabled_module->node, &sysc_soc->disabled_modules);
2891 mutex_unlock(&sysc_soc->list_lock);
2892
2893 return 0;
2894}
2895
2896/*
2897 * One time init to detect the booted SoC and disable unavailable features.
2898 * Note that we initialize static data shared across all ti-sysc instances
2899 * so ddata is only used for SoC type. This can be called from module_init
2900 * once we no longer need to rely on platform data.
2901 */
2902static int sysc_init_soc(struct sysc *ddata)
2903{
2904 const struct soc_device_attribute *match;
2905 struct ti_sysc_platform_data *pdata;
2906 unsigned long features = 0;
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002907 struct device_node *np;
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002908
2909 if (sysc_soc)
2910 return 0;
2911
2912 sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL);
2913 if (!sysc_soc)
2914 return -ENOMEM;
2915
2916 mutex_init(&sysc_soc->list_lock);
2917 INIT_LIST_HEAD(&sysc_soc->disabled_modules);
2918 sysc_soc->general_purpose = true;
2919
2920 pdata = dev_get_platdata(ddata->dev);
2921 if (pdata && pdata->soc_type_gp)
2922 sysc_soc->general_purpose = pdata->soc_type_gp();
2923
2924 match = soc_device_match(sysc_soc_match);
2925 if (match && match->data)
2926 sysc_soc->soc = (int)match->data;
2927
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002928 /*
2929 * Check and warn about possible old incomplete dtb. We now want to see
2930 * simple-pm-bus instead of simple-bus in the dtb for genpd using SoCs.
2931 */
2932 switch (sysc_soc->soc) {
2933 case SOC_AM3:
2934 case SOC_AM4:
Tony Lindgren4adcf4c2021-03-12 10:23:48 +02002935 case SOC_4430 ... SOC_4470:
2936 case SOC_5430:
2937 case SOC_DRA7:
Tony Lindgren5f7259a2021-03-08 11:35:09 +02002938 np = of_find_node_by_path("/ocp");
2939 WARN_ONCE(np && of_device_is_compatible(np, "simple-bus"),
2940 "ti-sysc: Incomplete old dtb, please update\n");
2941 break;
2942 default:
2943 break;
2944 }
2945
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002946 /* Ignore devices that are not available on HS and EMU SoCs */
2947 if (!sysc_soc->general_purpose) {
2948 switch (sysc_soc->soc) {
2949 case SOC_3430 ... SOC_3630:
2950 sysc_add_disabled(0x48304000); /* timer12 */
2951 break;
2952 default:
2953 break;
Yang Li52fbb5a2021-02-02 15:00:05 +08002954 }
Tony Lindgren4bba9bf2020-05-07 09:59:31 -07002955 }
2956
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08002957 match = soc_device_match(sysc_soc_feat_match);
2958 if (!match)
2959 return 0;
2960
2961 if (match->data)
2962 features = (unsigned long)match->data;
2963
2964 /*
2965 * Add disabled devices to the list based on the module base.
2966 * Note that this must be done before we attempt to access the
2967 * device and have module revision checks working.
2968 */
2969 if (features & DIS_ISP)
2970 sysc_add_disabled(0x480bd400);
2971 if (features & DIS_IVA)
2972 sysc_add_disabled(0x5d000000);
2973 if (features & DIS_SGX)
2974 sysc_add_disabled(0x50000000);
2975
2976 return 0;
2977}
2978
2979static void sysc_cleanup_soc(void)
2980{
2981 struct sysc_address *disabled_module;
2982 struct list_head *pos, *tmp;
2983
2984 if (!sysc_soc)
2985 return;
2986
2987 mutex_lock(&sysc_soc->list_lock);
2988 list_for_each_safe(pos, tmp, &sysc_soc->disabled_modules) {
2989 disabled_module = list_entry(pos, struct sysc_address, node);
2990 list_del(pos);
2991 kfree(disabled_module);
2992 }
2993 mutex_unlock(&sysc_soc->list_lock);
2994}
2995
2996static int sysc_check_disabled_devices(struct sysc *ddata)
2997{
2998 struct sysc_address *disabled_module;
2999 struct list_head *pos;
3000 int error = 0;
3001
3002 mutex_lock(&sysc_soc->list_lock);
3003 list_for_each(pos, &sysc_soc->disabled_modules) {
3004 disabled_module = list_entry(pos, struct sysc_address, node);
3005 if (ddata->module_pa == disabled_module->base) {
3006 dev_dbg(ddata->dev, "module disabled for this SoC\n");
3007 error = -ENODEV;
3008 break;
3009 }
3010 }
3011 mutex_unlock(&sysc_soc->list_lock);
3012
3013 return error;
3014}
3015
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003016/*
3017 * Ignore timers tagged with no-reset and no-idle. These are likely in use,
3018 * for example by drivers/clocksource/timer-ti-dm-systimer.c. If more checks
3019 * are needed, we could also look at the timer register configuration.
3020 */
3021static int sysc_check_active_timer(struct sysc *ddata)
3022{
3023 if (ddata->cap->type != TI_SYSC_OMAP2_TIMER &&
3024 ddata->cap->type != TI_SYSC_OMAP4_TIMER)
3025 return 0;
3026
3027 if ((ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT) &&
3028 (ddata->cfg.quirks & SYSC_QUIRK_NO_IDLE))
Grygorii Strashko65fb7362020-11-18 16:19:00 +02003029 return -ENXIO;
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003030
3031 return 0;
3032}
3033
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003034static const struct of_device_id sysc_match_table[] = {
3035 { .compatible = "simple-bus", },
3036 { /* sentinel */ },
3037};
3038
Tony Lindgren0eecc632017-10-10 14:23:43 -07003039static int sysc_probe(struct platform_device *pdev)
3040{
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003041 struct ti_sysc_platform_data *pdata = dev_get_platdata(&pdev->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003042 struct sysc *ddata;
3043 int error;
3044
3045 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
3046 if (!ddata)
3047 return -ENOMEM;
3048
Tony Lindgren29281352020-11-16 12:57:13 +02003049 ddata->offsets[SYSC_REVISION] = -ENODEV;
3050 ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
3051 ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003052 ddata->dev = &pdev->dev;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003053 platform_set_drvdata(pdev, ddata);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003054
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003055 error = sysc_init_soc(ddata);
3056 if (error)
3057 return error;
3058
Tony Lindgren70a65242017-12-15 09:41:09 -08003059 error = sysc_init_match(ddata);
3060 if (error)
3061 return error;
3062
Tony Lindgren566a9b052017-12-15 09:41:19 -08003063 error = sysc_init_dts_quirks(ddata);
3064 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003065 return error;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003066
Tony Lindgren0eecc632017-10-10 14:23:43 -07003067 error = sysc_map_and_check_registers(ddata);
3068 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003069 return error;
Tony Lindgren0eecc632017-10-10 14:23:43 -07003070
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003071 error = sysc_init_sysc_mask(ddata);
3072 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003073 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003074
3075 error = sysc_init_idlemodes(ddata);
3076 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003077 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003078
3079 error = sysc_init_syss_mask(ddata);
3080 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003081 return error;
Tony Lindgrenc5a2de92017-12-15 09:41:23 -08003082
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003083 error = sysc_init_pdata(ddata);
3084 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003085 return error;
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003086
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003087 sysc_init_early_quirks(ddata);
3088
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003089 error = sysc_check_disabled_devices(ddata);
3090 if (error)
3091 return error;
3092
Tony Lindgren6cfcd552020-07-13 09:26:01 -07003093 error = sysc_check_active_timer(ddata);
3094 if (error)
3095 return error;
3096
Tony Lindgren42b9c5c2019-03-21 11:00:21 -07003097 error = sysc_get_clocks(ddata);
3098 if (error)
3099 return error;
3100
Tony Lindgren50622362018-04-16 10:20:27 -07003101 error = sysc_init_resets(ddata);
3102 if (error)
Suman Annaa304f482019-06-25 18:33:15 -05003103 goto unprepare;
Tony Lindgren566a9b052017-12-15 09:41:19 -08003104
3105 error = sysc_init_module(ddata);
3106 if (error)
3107 goto unprepare;
3108
Tony Lindgren1a5cd7c2019-03-21 11:00:21 -07003109 pm_runtime_enable(ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003110 error = pm_runtime_get_sync(ddata->dev);
3111 if (error < 0) {
3112 pm_runtime_put_noidle(ddata->dev);
3113 pm_runtime_disable(ddata->dev);
3114 goto unprepare;
3115 }
3116
Tero Kristocdc56c12019-10-07 15:29:31 +03003117 /* Balance use counts as PM runtime should have enabled these all */
Tero Kristocdc56c12019-10-07 15:29:31 +03003118 if (!(ddata->cfg.quirks &
3119 (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))) {
3120 sysc_disable_main_clocks(ddata);
3121 sysc_disable_opt_clocks(ddata);
3122 sysc_clkdm_allow_idle(ddata);
3123 }
3124
Tony Lindgren4097c9a2020-11-16 12:57:13 +02003125 if (!(ddata->cfg.quirks & SYSC_QUIRK_NO_RESET_ON_INIT))
3126 reset_control_assert(ddata->rsts);
3127
Tony Lindgren0eecc632017-10-10 14:23:43 -07003128 sysc_show_registers(ddata);
3129
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003130 ddata->dev->type = &sysc_device_type;
Tony Lindgrenc4bebea2018-04-16 10:24:54 -07003131 error = of_platform_populate(ddata->dev->of_node, sysc_match_table,
3132 pdata ? pdata->auxdata : NULL,
Tony Lindgrenef70b0b2018-02-22 14:00:25 -08003133 ddata->dev);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003134 if (error)
3135 goto err;
3136
Tony Lindgren76f0f772018-02-23 08:28:45 -08003137 INIT_DELAYED_WORK(&ddata->idle_work, ti_sysc_idle);
3138
3139 /* At least earlycon won't survive without deferred idle */
Tony Lindgrend0989132019-09-05 07:37:22 -07003140 if (ddata->cfg.quirks & (SYSC_QUIRK_NO_IDLE |
3141 SYSC_QUIRK_NO_IDLE_ON_INIT |
Tony Lindgren76f0f772018-02-23 08:28:45 -08003142 SYSC_QUIRK_NO_RESET_ON_INIT)) {
3143 schedule_delayed_work(&ddata->idle_work, 3000);
3144 } else {
3145 pm_runtime_put(&pdev->dev);
3146 }
Tony Lindgren0eecc632017-10-10 14:23:43 -07003147
3148 return 0;
3149
3150err:
Tony Lindgren0eecc632017-10-10 14:23:43 -07003151 pm_runtime_put_sync(&pdev->dev);
3152 pm_runtime_disable(&pdev->dev);
3153unprepare:
3154 sysc_unprepare(ddata);
3155
3156 return error;
3157}
3158
Tony Lindgren684be5a2017-10-13 10:48:40 -07003159static int sysc_remove(struct platform_device *pdev)
3160{
3161 struct sysc *ddata = platform_get_drvdata(pdev);
3162 int error;
3163
Tony Lindgren76f0f772018-02-23 08:28:45 -08003164 cancel_delayed_work_sync(&ddata->idle_work);
3165
Tony Lindgren684be5a2017-10-13 10:48:40 -07003166 error = pm_runtime_get_sync(ddata->dev);
3167 if (error < 0) {
3168 pm_runtime_put_noidle(ddata->dev);
3169 pm_runtime_disable(ddata->dev);
3170 goto unprepare;
3171 }
3172
3173 of_platform_depopulate(&pdev->dev);
3174
Tony Lindgren684be5a2017-10-13 10:48:40 -07003175 pm_runtime_put_sync(&pdev->dev);
3176 pm_runtime_disable(&pdev->dev);
Tony Lindgrena7b5d7c2021-02-18 13:06:57 +02003177
3178 if (!reset_control_status(ddata->rsts))
3179 reset_control_assert(ddata->rsts);
Tony Lindgren684be5a2017-10-13 10:48:40 -07003180
3181unprepare:
3182 sysc_unprepare(ddata);
3183
3184 return 0;
3185}
3186
Tony Lindgren0eecc632017-10-10 14:23:43 -07003187static const struct of_device_id sysc_match[] = {
Tony Lindgren70a65242017-12-15 09:41:09 -08003188 { .compatible = "ti,sysc-omap2", .data = &sysc_omap2, },
3189 { .compatible = "ti,sysc-omap2-timer", .data = &sysc_omap2_timer, },
3190 { .compatible = "ti,sysc-omap4", .data = &sysc_omap4, },
3191 { .compatible = "ti,sysc-omap4-timer", .data = &sysc_omap4_timer, },
3192 { .compatible = "ti,sysc-omap4-simple", .data = &sysc_omap4_simple, },
3193 { .compatible = "ti,sysc-omap3430-sr", .data = &sysc_34xx_sr, },
3194 { .compatible = "ti,sysc-omap3630-sr", .data = &sysc_36xx_sr, },
3195 { .compatible = "ti,sysc-omap4-sr", .data = &sysc_omap4_sr, },
3196 { .compatible = "ti,sysc-omap3-sham", .data = &sysc_omap3_sham, },
3197 { .compatible = "ti,sysc-omap-aes", .data = &sysc_omap3_aes, },
3198 { .compatible = "ti,sysc-mcasp", .data = &sysc_omap4_mcasp, },
Tony Lindgren2c63a832018-11-15 14:46:53 -08003199 { .compatible = "ti,sysc-dra7-mcasp", .data = &sysc_dra7_mcasp, },
Tony Lindgren70a65242017-12-15 09:41:09 -08003200 { .compatible = "ti,sysc-usb-host-fs",
3201 .data = &sysc_omap4_usb_host_fs, },
Faiz Abbas7f35e632018-07-09 22:18:38 +05303202 { .compatible = "ti,sysc-dra7-mcan", .data = &sysc_dra7_mcan, },
Suman Annab2745d92020-02-27 16:28:34 -06003203 { .compatible = "ti,sysc-pruss", .data = &sysc_pruss, },
Tony Lindgren0eecc632017-10-10 14:23:43 -07003204 { },
3205};
3206MODULE_DEVICE_TABLE(of, sysc_match);
3207
3208static struct platform_driver sysc_driver = {
3209 .probe = sysc_probe,
Tony Lindgren684be5a2017-10-13 10:48:40 -07003210 .remove = sysc_remove,
Tony Lindgren0eecc632017-10-10 14:23:43 -07003211 .driver = {
3212 .name = "ti-sysc",
3213 .of_match_table = sysc_match,
3214 .pm = &sysc_pm_ops,
3215 },
3216};
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003217
3218static int __init sysc_init(void)
3219{
3220 bus_register_notifier(&platform_bus_type, &sysc_nb);
3221
3222 return platform_driver_register(&sysc_driver);
3223}
3224module_init(sysc_init);
3225
3226static void __exit sysc_exit(void)
3227{
3228 bus_unregister_notifier(&platform_bus_type, &sysc_nb);
3229 platform_driver_unregister(&sysc_driver);
Tony Lindgrenfeaa8ba2020-02-24 12:58:03 -08003230 sysc_cleanup_soc();
Tony Lindgren2c355ff2018-02-22 13:58:03 -08003231}
3232module_exit(sysc_exit);
Tony Lindgren0eecc632017-10-10 14:23:43 -07003233
3234MODULE_DESCRIPTION("TI sysc interconnect target driver");
3235MODULE_LICENSE("GPL v2");